/* ==========================================================================
   Animation

   Two rules govern everything here:

   1. Motion carries meaning or it doesn't ship. Markers cascade because the
      map is filling with real places; report pins pulse because they are the
      live, human part of the data; charts grow from zero because that is what
      a count does.

   2. Every effect has an honest resting state. Elements animate *from* an
      offset *to* their real position, so if the animation never runs — reduced
      motion, JS disabled, an old browser — the page is still correct. Nothing
      is hidden waiting for a script to reveal it, except where JS explicitly
      opts in with .reveal, which motion.js always resolves.

   The reduced-motion block at the foot of this file is the master switch.
   ========================================================================== */

/* --------------------------------------------------------------------------
   The motion scale

   The base scale lives in tokens.css — fast 140ms / base 320ms / slow 620ms /
   hero 1100ms, stagger 45ms, and the three easings. These extend it for the
   cases the base scale has no word for, so a duration is never invented at
   the point of use again. If a number in this file is not one of these
   custom properties, it is part of one specific choreography (the hero
   timeline), not a speed anything else may borrow.
   -------------------------------------------------------------------------- */

:root {
  /* Things arriving: markers dropping, popups, page furniture entering. */
  --duration-enter: 460ms;
  /* Ambient loops that repeat while the page sits still: the report pulse,
     the skeleton sheen. Slow on purpose — a loop faster than this nags. */
  --duration-loop: 2600ms;
  /* One revolution of the spinner. */
  --duration-spin: 700ms;
  /* Dense sequences — hundreds of map markers or hero dots — where the
     45ms base stagger would take half a minute to finish. */
  --stagger-fine: 7ms;
}

/* --------------------------------------------------------------------------
   Keyframes
   -------------------------------------------------------------------------- */

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Headlines wipe up from behind a mask, the way type is set. */
@keyframes type-set {
  from {
    opacity: 0;
    transform: translateY(0.5em);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Map markers arrive by dropping onto the map and settling. */
@keyframes marker-drop {
  0% {
    opacity: 0;
    transform: translateY(-14px) scale(0.4);
  }
  60% {
    opacity: 1;
    transform: translateY(0) scale(1.15);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Community reports are the living data — a slow ring breathes out of them. */
@keyframes pulse-ring {
  0% {
    transform: scale(0.75);
    opacity: 0.55;
  }
  70% {
    transform: scale(2.4);
    opacity: 0;
  }
  100% {
    transform: scale(2.4);
    opacity: 0;
  }
}

@keyframes marker-bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  35% {
    transform: translateY(-9px);
  }
  70% {
    transform: translateY(-3px);
  }
}

@keyframes popup-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* The county outline draws itself. stroke-dasharray is set inline by
   hero-map.js to the measured path length. */
@keyframes draw-path {
  to {
    stroke-dashoffset: 0;
  }
}

/* Facility dots land on the hero county map. */
@keyframes dot-land {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  70% {
    opacity: 1;
    transform: scale(1.5);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes wash-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes bar-grow {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

@keyframes bar-rise {
  from {
    transform: scaleY(0);
  }
  to {
    transform: scaleY(1);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --------------------------------------------------------------------------
   Scroll reveal

   motion.js adds .is-visible when the element enters the viewport. The
   .reveal class is only ever applied BY JavaScript (never in the HTML), so a
   page with scripting disabled shows everything immediately.
   -------------------------------------------------------------------------- */

.reveal {
  opacity: 0;
  transform: translateY(20px);
}

.reveal.is-visible {
  animation: fade-up var(--duration-slow) var(--ease-out) both;
  animation-delay: calc(var(--stagger-index, 0) * var(--stagger-step));
}

/* Children cascade rather than arriving as a block. */
.reveal-group.is-visible > * {
  animation: fade-up var(--duration-slow) var(--ease-out) both;
  animation-delay: calc(var(--stagger-index, 0) * var(--stagger-step));
}

.reveal-group > * {
  opacity: 0;
}

.reveal-group.is-visible > * {
  opacity: 1;
}

/* Focus must survive the reveal. If keyboard focus lands inside an element
   the observer has not reached yet, show it at once — an outline around an
   invisible card is worse than a skipped animation. motion.js also resolves
   the queue entry on focusin; this rule is the zero-latency backstop. */
.reveal:focus-within,
.reveal-group > *:focus-within {
  opacity: 1;
  transform: none;
}

/* --------------------------------------------------------------------------
   Hero
   -------------------------------------------------------------------------- */

.hero__eyebrow,
.hero__title,
.hero__lead,
.hero__actions {
  animation: type-set var(--duration-slow) var(--ease-out) both;
}

.hero__eyebrow {
  animation-delay: 60ms;
}
.hero__title {
  animation-delay: 140ms;
}
.hero__lead {
  animation-delay: 300ms;
}
.hero__actions {
  animation-delay: 420ms;
}

/* The county figure. Paths get their dasharray set inline by hero-map.js. */
.hero-figure__outline {
  animation: draw-path var(--duration-hero) var(--ease-in-out) both;
}

.hero-figure__district {
  animation: wash-in var(--duration-base) var(--ease-out) both;
  animation-delay: calc(760ms + var(--stagger-index, 0) * 60ms);
}

.hero-figure__dot {
  transform-box: fill-box;
  transform-origin: center;
  animation: dot-land var(--duration-enter) var(--ease-spring) both;
  /* Ordered east-to-west by hero-map.js, so the viewer watches Data Center
     Alley fill in before the rest of the county. */
  animation-delay: calc(1150ms + var(--stagger-index, 0) * var(--stagger-fine));
}

.hero-figure__label {
  animation: fade-in var(--duration-base) var(--ease-out) both;
  animation-delay: calc(1000ms + var(--stagger-index, 0) * 50ms);
}

/* --------------------------------------------------------------------------
   Page enter

   Interior pages get the same settle the hero gives the front page: the
   page-header cascades in with the type-set wipe. Pure CSS, no class needed,
   so every existing page has it without being edited. The elements animate
   from an offset to their real position — scripting off or reduced motion
   leaves them simply present. Delays stay short enough that the header is
   fully set before a reader could reach for anything below it, and focus is
   unaffected: opacity does not remove an element from the tab order, and
   nothing here moves more than half a line of type.
   -------------------------------------------------------------------------- */

.page-header .kicker,
.page-header h1,
.page-header p {
  animation: type-set var(--duration-slow) var(--ease-out) both;
}

.page-header .kicker {
  animation-delay: 60ms;
}
.page-header h1 {
  animation-delay: 140ms;
}
.page-header p {
  animation-delay: 260ms;
}

/* --------------------------------------------------------------------------
   Map
   -------------------------------------------------------------------------- */

/* Applied to the marker's inner span so Leaflet's own transform on the parent
   is never disturbed. */
.pin--enter {
  animation: marker-drop var(--duration-enter) var(--ease-spring) both;
  animation-delay: calc(var(--stagger-index, 0) * var(--stagger-fine));
}

.pin--bounce {
  animation: marker-bounce var(--duration-slow) var(--ease-out);
}

/* The pulsing ring behind a community report pin. */
.pin--report {
  position: relative;
}

.pin--report::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  border: 2px solid var(--status-reported);
  animation: pulse-ring var(--duration-loop) var(--ease-out) infinite;
  pointer-events: none;
}

.leaflet-popup {
  animation: popup-in var(--duration-base) var(--ease-out) both;
}

/* Layers fade rather than snapping when toggled off. */
.leaflet-marker-pane .leaflet-marker-icon,
.leaflet-marker-pane .leaflet-cluster-anim {
  transition: opacity var(--duration-base) var(--ease-out);
}

.marker-cluster-custom span {
  transition: transform var(--duration-fast) var(--ease-spring),
    box-shadow var(--duration-fast) var(--ease-out);
}

.marker-cluster-custom:hover span {
  transform: scale(1.14);
}

/* --------------------------------------------------------------------------
   Charts — bars grow from nothing when scrolled into view
   -------------------------------------------------------------------------- */

.chart__bar {
  transform-origin: left center;
}

.is-visible .chart__bar {
  animation: bar-grow var(--duration-slow) var(--ease-out) both;
  animation-delay: calc(var(--stagger-index, 0) * 55ms);
}

.timeline-chart__bar {
  transform-origin: bottom center;
}

.is-visible .timeline-chart__bar {
  animation: bar-rise var(--duration-slow) var(--ease-out) both;
  animation-delay: calc(var(--stagger-index, 0) * 45ms);
}

/* --------------------------------------------------------------------------
   Interaction
   -------------------------------------------------------------------------- */

.card--link {
  transition: transform var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out);
}

.card--link:hover {
  transform: translateY(-3px);
}

.report-card {
  transition: background var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

.report-card:hover {
  background: var(--bg-tint);
}

.btn {
  transition: background var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.stat {
  transition: background var(--duration-fast) var(--ease-out);
}

/* Numbers are animated by motion.js countUp(); this keeps the glyph box from
   reflowing as the digits change. */
.stat__value {
  font-variant-numeric: tabular-nums;
}

.spinner {
  animation: spin var(--duration-spin) linear infinite;
}

/* Faint county watermark behind section breaks. Parallax offset is written to
   --parallax by motion.js. */
.watermark {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  opacity: 0.035;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.watermark svg {
  width: min(60%, 520px);
  height: auto;
  color: var(--text);
  transform: translateY(var(--parallax, 0px));
  will-change: transform;
}

.watermark + * {
  position: relative;
  z-index: 1;
}

/* --------------------------------------------------------------------------
   Skeletons — loading states shaped like what they become

   Built by ui.js while a list or a chart is fetching. Each skeleton reuses
   the real component's classes (.report-card, .news-item, .activity-item,
   .chart__label…) so its frame, padding and rules come from components.css
   and cannot drift from the content that replaces it — that is what keeps
   the swap from jumping.

   Two honesty rules: skeleton bars are grey, never a status colour, and they
   are uniform — no varied widths or heights that could be mistaken for a
   glimpse of real data. A skeleton says "loading", not "roughly this much".

   The sheen animates background-position, not layout, and stops dead under
   reduced motion (the master switch below), leaving a static grey bar.
   -------------------------------------------------------------------------- */

@keyframes skeleton-sheen {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

.skeleton__line {
  display: block;
  /* .85em tall with .35em either side is one 1.55em line — the body text
     line-height — so N bars occupy the height of N lines of copy. */
  height: 0.85em;
  margin-block: 0.35em;
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--bg-sunken) 35%,
    var(--bg-raised) 50%,
    var(--bg-sunken) 65%
  );
  background-size: 200% 100%;
  animation: skeleton-sheen var(--duration-loop) linear infinite;
}

.skeleton__line--inline {
  display: inline-block;
  vertical-align: middle;
}

/* For headline contexts set at --leading-snug (1.22): .85 + .18 × 2 ≈ 1.21em
   per bar, so a two-bar headline stands as tall as a two-line one. */
.skeleton__line--snug {
  margin-block: 0.18em;
}

.skeleton__pill {
  display: inline-block;
  vertical-align: middle;
  width: 88px;
  height: 22px;
  border-radius: var(--radius-pill);
  background: linear-gradient(
    90deg,
    var(--bg-sunken) 35%,
    var(--bg-raised) 50%,
    var(--bg-sunken) 65%
  );
  background-size: 200% 100%;
  animation: skeleton-sheen var(--duration-loop) linear infinite;
}

/* A big statistic that has not arrived yet. Applied to the value node itself
   (the "—" placeholder), so the box keeps its exact metrics and nothing
   reflows when the number lands; ui.js removes the class the moment the text
   changes. The doubled class beats the .stat--* colour selectors without
   resorting to !important. */
.skeleton-value,
.stat__value.skeleton-value {
  color: transparent;
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--bg-sunken) 35%,
    var(--bg-raised) 50%,
    var(--bg-sunken) 65%
  );
  background-size: 200% 100%;
  animation: skeleton-sheen var(--duration-loop) linear infinite;
  user-select: none;
}

/* --------------------------------------------------------------------------
   Reduced motion — the master switch

   Everything above collapses to its final state. Note `animation: none` rather
   than a near-zero duration: several of the effects above use `both` fill
   mode, and a 0.01ms animation would still apply the from-state for a frame.
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }

  .reveal,
  .reveal-group > * {
    opacity: 1;
    transform: none;
  }

  .hero-figure__outline {
    stroke-dashoffset: 0 !important;
  }

  .chart__bar,
  .timeline-chart__bar {
    transform: none;
  }

  .pin--report::after {
    display: none;
  }

  .watermark svg {
    transform: none;
  }
}
