/*
 * The hero — layout, signage type, the departure board, the map panel.
 *
 * Loaded after site.css and scoped under .hero at two classes deep, so it
 * wins over the single-class hero rules there without !important. The page
 * around this block is daylight (white ground, ink plates) and the canvas
 * is the game's own daylight map: the --hm-* tokens below are the poster
 * palette in site/tools/bake-hero.mjs plus THEMES.light in
 * src/render/map.ts, read at layout time by js/hero.js, so the live canvas
 * and its no-JS poster are the same drawing. In the dark scheme the page is
 * night and the tokens are THEMES.dark. The panel behind the canvas is the
 * same ground (--map-ground), so there is never a flash or a layout shift
 * if the pack is late.
 *
 * Motion lives in three places and nowhere else:
 *   1. the canvas (hero.js): entrance 1.8 s (city, lines, trains), then
 *      vehicles on headway, a 60 s drift, and a fine-pointer look
 *   2. the headline: ink rules draw under each line, keyed on
 *      .hero[data-entrance="play"] — the words themselves are never clipped
 *      or faded, so LCP is the first paint and no-JS still reads the plate
 *   3. the board digits: a flip, driven by the Web Animations API from hero.js
 */

.hero {
  /* Daylight map: the poster palette (bake-hero.mjs PAL) on --map-ground,
     white casing and stations with ink rings, ink-shelled white cars. */
  --hm-ground: var(--map-ground, #F7F8FA);
  --hm-water: #CBDFEE;
  --hm-water-edge: #A9C6DD;
  --hm-freeway: #C6CED6;
  --hm-tract-edge: #E6EAEE;
  --hm-casing: #FFFFFF;
  --hm-station: #FFFFFF;
  --hm-ink: #12161B;
  --hm-body: #FFFFFF;
  --hm-shell: #12161B;
  /* A consist at the platform, doors open; its headlamp; the shadow it throws. */
  --hm-lit: #FFE27A;
  --hm-lamp: #FFF8DC;
  --hm-shadow: #12161B;
  /* Light cool ramp, same five stops as THEMES.light.rampCool. */
  --hm-wash-0: #EEF3F8;
  --hm-wash-1: #D2E1EE;
  --hm-wash-2: #A6C6DF;
  --hm-wash-3: #5F98C2;
  --hm-wash-4: #2A6896;

  --hero-ink: var(--ink, #12161B);
  --hero-ink-2: var(--ink-2, #59626E);
  --hero-rule: var(--rule, #D9DEE3);
  --hero-accent: var(--accent, #14548F);
  --hero-on-ink: var(--ground, #FFFFFF);
  --hero-paper: var(--ground, #FFFFFF);
  --hero-display: var(--display, 'Barlow Condensed', 'Oswald', 'Arial Narrow', sans-serif);
  --hero-ui: var(--ui, 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
  --hero-mono: var(--mono, 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace);
  --hero-tick: var(--plate-accent, var(--line-red, #C60C30));

  position: relative;
  background: var(--hero-paper);
  border-bottom: 2px solid var(--hero-ink);
  padding-block: clamp(2rem, 5vw, 3.75rem) clamp(1.5rem, 4vw, 3rem);
  overflow: hidden;
}

.hero .hero__grid {
  display: grid;
  gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: start;
}
@media (min-width: 1000px) {
  .hero .hero__grid { grid-template-columns: minmax(0, 32rem) minmax(0, 1fr); }
}

/* ── the headline: signage, never a whisper ──────────────────────────── */

.hero .hero__title {
  font-family: var(--hero-display);
  font-weight: 600;
  font-size: clamp(2.7rem, 7.2vw, 4.75rem);
  line-height: 0.94;
  letter-spacing: -0.012em;
  color: var(--hero-ink);
  margin: 0 0 1.15rem;
  text-wrap: balance;
}
.hero .hero__title .line {
  display: block;
  position: relative;
  padding-bottom: 0.1em;
  margin-bottom: 0.12em;
}
.hero .hero__title em {
  font-style: normal;
  color: var(--hero-accent);
}

/*
 * An ink rule under each line, like a destination-blind plate. At rest the
 * rule is fully drawn (no-JS, reduced motion). During the entrance it draws
 * from the left; the words are not clipped, faded, or translated.
 */
.hero .hero__title .line::after {
  content: '';
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  height: 3px;
  background: var(--hero-ink);
  transform-origin: 0 50%;
}
.hero .hero__title .line:last-child::after { background: var(--hero-accent); }
@keyframes hero-rule-draw {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}
.hero[data-entrance="play"] .hero__title .line::after {
  animation: hero-rule-draw 600ms var(--ease-land) both;
}
.hero[data-entrance="play"] .hero__title .line:nth-child(2)::after { animation-delay: 180ms; }

/* The rest of the column rises in behind the headline: board, lede, actions. */
@keyframes hero-rise {
  from { opacity: 0; transform: translateY(0.45rem); }
  to   { opacity: 1; transform: none; }
}
.hero[data-entrance="play"] .hero__lede,
.hero[data-entrance="play"] .hero__cta,
.hero[data-entrance="play"] .hero__meta,
.hero[data-entrance="play"] .board {
  animation: hero-rise 540ms var(--ease-land) both;
}
.hero[data-entrance="play"] .board { animation-delay: 280ms; }
.hero[data-entrance="play"] .hero__lede { animation-delay: 480ms; }
.hero[data-entrance="play"] .hero__cta { animation-delay: 600ms; }
.hero[data-entrance="play"] .hero__meta { animation-delay: 720ms; }
@media (max-width: 700px) {
  .hero[data-entrance="play"] .board { animation-delay: 220ms; }
  .hero[data-entrance="play"] .hero__lede { animation-delay: 360ms; }
  .hero[data-entrance="play"] .hero__cta { animation-delay: 440ms; }
  .hero[data-entrance="play"] .hero__meta { animation-delay: 520ms; }
}

/* One column (under 1000px): words, the map in its frame, then the board
   under the map it describes. */
@media (max-width: 999.98px) {
  .hero .hero__grid { gap: 0; }
  .hero .hero__grid > div:first-child { display: contents; }
  .hero .hero__kicker { order: 1; justify-self: start; }
  .hero .hero__title { order: 2; }
  .hero .hero__lede { order: 3; }
  .hero .hero__cta { order: 4; }
  .hero .hero__meta { order: 5; }
  .hero .hero__map { order: 6; margin-top: 1.5rem; }
  .hero .board { order: 7; margin: 1rem 0 0; }
}

.hero .hero__lede {
  font-family: var(--hero-ui);
  font-size: clamp(1.0625rem, 1.5vw, 1.1875rem);
  line-height: 1.55;
  color: var(--hero-ink-2);
  max-width: 36ch;
  margin: 0 0 0.25rem;
}

.hero .hero__cta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.4rem;
}

.hero .hero__meta {
  margin: 1.1rem 0 0;
  font-family: var(--hero-ui);
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--hero-ink-2);
  max-width: 44ch;
}

/* Dark scheme: the page is night, so the map is THEMES.dark. */
@media (prefers-color-scheme: dark) {
  .hero {
    --hm-ground: var(--map-ground, #0A0D12);
    --hm-water: #1A5C82;
    --hm-water-edge: #4AA3CC;
    --hm-freeway: #5C7690;
    --hm-tract-edge: #0C131C;
    --hm-casing: var(--map-ground, #0A0D12);
    --hm-station: #F2F5F8;
    --hm-ink: #0B0E13;
    --hm-body: #F2F5F8;
    --hm-shell: #0A0F16;
    --hm-lit: #FFD65C;
    --hm-lamp: #FFF3C4;
    --hm-shadow: #000000;
    --hm-wash-0: #141A22;
    --hm-wash-1: #213243;
    --hm-wash-2: #34536B;
    --hm-wash-3: #4B7795;
    --hm-wash-4: #74A3C2;
  }
}

/* ── the departure board: an ink plate ───────────────────────────────── */

.hero .board {
  display: grid;
  grid-template-columns: repeat(4, auto);
  justify-content: start;
  gap: 0;
  margin: 0 0 1.25rem;
  background: var(--hero-ink);
  color: var(--hero-on-ink);
  border-inline-start: 4px solid var(--hero-tick);
}
.hero .board__cell {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 1rem 0.45rem 0.9rem;
  border-inline-start: 1px solid color-mix(in srgb, var(--hero-on-ink) 22%, transparent);
  min-inline-size: 5.2rem;
}
.hero .board__cell:first-child { border-inline-start: 0; }
.hero .board dt {
  font-family: var(--hero-display);
  font-weight: 600;
  font-size: 0.8125rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.72;
  margin: 0;
}
.hero .board dd {
  margin: 0;
  display: flex;
  font-family: var(--hero-display);
  font-weight: 600;
  font-size: 1.75rem;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  perspective: 180px;
}
.hero .board .board__cell--clock dd {
  min-inline-size: 5ch; /* room for a wider fallback digit: the cell had 0 px of slack at 390 */
  font-family: var(--hero-mono);
  font-weight: 500;
  font-size: 1.5rem;
  padding-top: 0.1rem;
  color: var(--line-yellow, #FCCC0A);
}
.hero .board__digit {
  display: inline-block;
  min-inline-size: 0.56em;
  text-align: center;
  transform-origin: 50% 50%;
  backface-visibility: hidden;
}
@media (max-width: 420px) {
  .hero .board { grid-template-columns: repeat(2, 1fr); }
  .hero .board__cell:nth-child(3) { border-inline-start: 0; border-top: 1px solid color-mix(in srgb, var(--hero-on-ink) 22%, transparent); }
  .hero .board__cell:nth-child(4) { border-top: 1px solid color-mix(in srgb, var(--hero-on-ink) 22%, transparent); }
}

/* ── the map panel: the game's map in an ink frame on the ledger ─────── */

.hero .hero__map {
  position: relative;
  margin: 0;
  border: 1px solid var(--hero-ink);
  border-top: 4px solid var(--hero-ink);
  background: var(--hero-paper);
  border-radius: 0;
}
.hero .hero__stage {
  position: relative;
  background: var(--hm-ground);
  isolation: isolate;
}
.hero .hero__canvas {
  display: block;
  position: relative;
  z-index: 1;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--hm-ground);
}
@media (max-width: 700px) { .hero .hero__canvas { aspect-ratio: 4 / 3; } }

/*
 * No-JS poster: same box as the canvas, laid OVER the empty panel (the
 * canvas paints its own opaque ground, so the poster must stack above it:
 * same z-index, later in the document) so a reader without script sees the
 * drawing rather than a blank. With JS the noscript block is gone and the
 * canvas is the map. object-fit keeps the reserved aspect-ratio; nothing
 * below the stage reflows.
 */
.hero .hero__poster {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--hm-ground);
}

.hero .hero-toggle {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  /* A plate, like every other control on the page: ink with the page's
     own type on it, inverted on hover. */
  background: var(--hero-ink);
  border: 1px solid var(--hero-ink);
  color: var(--hero-on-ink);
  font-family: var(--hero-display);
  font-weight: 600;
  font-size: 0.8125rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.3rem 0.6rem;
  border-radius: 0;
  cursor: pointer;
}
.hero .hero-toggle:hover {
  background: var(--hero-paper);
  color: var(--hero-ink);
}
/* The button ships hidden and js/hero.js reveals it; display above would
   otherwise beat the UA's [hidden] rule and show a dead control without script. */
.hero .hero-toggle[hidden] { display: none; }
.hero .hero-toggle:focus-visible { outline: 2px solid var(--hero-accent); outline-offset: 2px; }

/* ── the legend: the ledger under the map ────────────────────────────── */

.hero .legend__head,
.hero .legend__row {
  display: grid;
  grid-template-columns: 0.75rem 1fr 3.2rem 3.6rem 2.4rem;
  gap: 0.6rem;
  align-items: center;
}
.hero .legend__head {
  padding: 0.55rem 0.85rem 0.3rem;
  border-top: 1px solid var(--hero-rule);
  font-family: var(--hero-display);
  font-weight: 600;
  font-size: 0.8125rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--hero-ink);
}
.hero .legend {
  list-style: none;
  margin: 0;
  padding: 0 0.85rem 0.4rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0 1.5rem;
  background: var(--hero-paper);
}
/* js/hero.js writes the rows; without script the ledger is empty and its
   column heads would label nothing, so both go. */
.hero .legend:empty,
.hero .legend__head:has(+ .legend:empty) { display: none; }
.hero .legend__row {
  font-family: var(--hero-ui);
  font-size: 0.8125rem;
  color: var(--hero-ink-2);
  padding-block: 0.22rem;
  border-top: 1px solid var(--hero-rule);
}
.hero .legend__swatch {
  width: 0.75rem; height: 0.75rem;
  border-radius: 0;
  background: var(--line);
  transform-origin: 0 50%;
}
.hero .legend__name { color: var(--hero-ink); font-weight: 500; }
/*
 * The ledger ticks in with the map: while the entrance plays, a line's row
 * waits in the ledger's grey with its swatch undrawn, and lands the frame
 * its sweep finishes (js/hero.js adds .is-built). Resting state is built;
 * with the script off, or motion refused, every row is simply there.
 */
.hero[data-entrance="play"] .legend__row:not(.is-built) { color: var(--hero-ink-2); }
.hero[data-entrance="play"] .legend__row:not(.is-built) .legend__name,
.hero[data-entrance="play"] .legend__row:not(.is-built) .legend__count { color: var(--hero-ink-2); opacity: 0.55; }
.hero[data-entrance="play"] .legend__row:not(.is-built) .legend__swatch { transform: scaleX(0); }
.hero[data-entrance="play"] .legend__row .legend__swatch { transition: transform 300ms var(--ease-land); }
.hero[data-entrance="play"] .legend__row .legend__name,
.hero[data-entrance="play"] .legend__row .legend__count { transition: opacity 300ms var(--ease-land), color 300ms var(--ease-land); }
.hero .legend__year,
.hero .legend__headway,
.hero .legend__count {
  font-family: var(--hero-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.hero .legend__count { color: var(--hero-ink); font-weight: 500; }
.hero .legend__head span:nth-child(3),
.hero .legend__head span:nth-child(4),
.hero .legend__head span:nth-child(5) { text-align: right; }

.hero .hero__caption {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1.25rem;
  align-items: baseline;
  border-top: 1px solid var(--hero-rule);
  padding: 0.6rem 0.85rem 0.7rem;
  font-family: var(--hero-ui);
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--hero-ink-2);
}
.hero .hero__caption strong { color: var(--hero-ink); font-weight: 600; }

/* ── reduced motion ──────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .hero[data-entrance="play"] .hero__title .line::after,
  .hero[data-entrance="play"] .hero__lede,
  .hero[data-entrance="play"] .hero__cta,
  .hero[data-entrance="play"] .hero__meta,
  .hero[data-entrance="play"] .board { animation: none; }
  .hero[data-entrance="play"] .legend__row:not(.is-built) { color: inherit; }
  .hero[data-entrance="play"] .legend__row:not(.is-built) .legend__name,
  .hero[data-entrance="play"] .legend__row:not(.is-built) .legend__count { color: var(--hero-ink); opacity: 1; }
  .hero[data-entrance="play"] .legend__row:not(.is-built) .legend__swatch { transform: none; }
  .hero[data-entrance="play"] .legend__row .legend__swatch,
  .hero[data-entrance="play"] .legend__row .legend__name,
  .hero[data-entrance="play"] .legend__row .legend__count { transition: none; }
}

@media print {
  .hero .hero__map, .hero .board { display: none !important; }
}
