/* =========================================================================
   Knicks Heartbeat — web shell.
   Theme variables track the same palette as viz/_themes.py.
   Dark is default; [data-theme="light"] overrides.
   ========================================================================= */

:root {
  /* Dark theme (default).
     Wins / losses use the official Knicks palette across the whole piece:
       blue (#006BB6) for wins, orange (#F58426) for losses.
     Visual hierarchy across regular season → playoffs → silver run →
     championship is carried by halos and stroke width, not hue. */
  --bg:           #1B1814;
  --ink:          #F0EAD8;
  --subtle:       #7A7464;
  --grid:         #3A352A;
  --season-label: #9A9384;

  --knicks-blue:   #006BB6;
  --knicks-orange: #F58426;

  --win:          var(--knicks-blue);
  --loss:         var(--knicks-orange);
  --playoff:      var(--knicks-blue);     /* same family as wins; emphasis via stroke */
  --champ-run:    var(--knicks-orange);   /* row label color in champ rows */
  --champ-halo:   #3F2F18;
  --silver-run:   #8E9DBE;
  --silver-halo:  #2C2D2A;
  --dark-halo:    #161310;     /* barely-darker warm wash; was #0E0D0A which read as a hole */
  --three-pt:     #D5A33D;
  --trace-win:    var(--knicks-blue);
  --trace-loss:   var(--knicks-orange);
  --trace-zero:   #7A7464;

  /* Layout / type */
  --serif: 'Playfair Display', Georgia, serif;
  --sans:  'IBM Plex Sans', -apple-system, system-ui, sans-serif;
  --max-content: 1100px;
  --transition: 220ms ease-out;
}

[data-theme="light"] {
  --bg:           #F5F1E8;
  --ink:          #1A1A1A;
  --subtle:       #9B9484;
  --grid:         #D4CDB8;
  --season-label: #6E6657;

  --win:          var(--knicks-blue);
  --loss:         var(--knicks-orange);
  --playoff:      var(--knicks-blue);
  --champ-run:    var(--knicks-orange);
  --champ-halo:   #FAD9A8;
  --silver-run:   #5A6E92;
  --silver-halo:  #E5DBC8;
  --dark-halo:    #D2C8B2;
  --three-pt:     #B07A14;
  --trace-win:    var(--knicks-blue);
  --trace-loss:   var(--knicks-orange);
  --trace-zero:   #9B9484;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color var(--transition), color var(--transition);
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  body, .control { transition: none; }
}

/* =========================================================================
   Controls (top-right cluster)
   ========================================================================= */

.controls {
  position: fixed;
  top: max(1.25rem, env(safe-area-inset-top));
  right: max(1.25rem, env(safe-area-inset-right));
  display: flex;
  gap: 0.5rem;
  z-index: 100;
}

/* Icon-only square buttons. flex centering with a single child (the SVG)
   is foolproof — no optical alignment hacks needed. */
.control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--subtle);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  border-radius: 2px;
  transition: border-color var(--transition), color var(--transition),
              background-color var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.control:hover,
.control:focus-visible {
  border-color: var(--ink);
  outline: none;
}

.control[aria-pressed="true"] {
  border-color: var(--ink);
  background-color: color-mix(in srgb, var(--ink) 8%, transparent);
}

.control svg {
  display: block;
}

/* =========================================================================
   Main / viz container
   ========================================================================= */

main#viz {
  padding: 5.5rem 1.5rem 4rem;
  max-width: var(--max-content);
  margin: 0 auto;
}

/* =========================================================================
   Site header — "All Time Knicks"
   ========================================================================= */

.site-header {
  margin: 1.5rem 0 4rem;
  text-align: center;
}

.site-title {
  font-family: var(--serif);
  font-style: italic;        /* match the chapter sub treatment */
  font-size: clamp(2.5rem, 7vw, 4.75rem);
  font-weight: 400;
  letter-spacing: -0.005em;
  line-height: 1;
  margin: 0;
  color: var(--ink);
}

.viz-placeholder {
  text-align: center;
  color: var(--subtle);
  font-family: var(--serif);
  font-style: italic;
  margin-top: 25vh;
  font-size: 1.05rem;
}

/* =========================================================================
   Chapter sections
   ========================================================================= */

.chapter {
  margin: 0 0 5rem;
}

.chapter-header {
  margin: 0 0 1.75rem;
}

.chapter-title {
  font-family: var(--serif);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 400;
  line-height: 1.15;
  margin: 0 0 0.5rem;
  color: var(--ink);
}

.chapter-sub {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  margin: 0 0 0.75rem;
  color: var(--subtle);
}

.chapter-body {
  font-family: var(--sans);
  font-size: 0.92rem;
  line-height: 1.55;
  margin: 0;
  color: var(--ink);
  max-width: 60ch;
}

.chapter-chart {
  width: 100%;
  margin-top: 1rem;
}

.chart-placeholder {
  text-align: center;
  color: var(--subtle);
  font-style: italic;
  padding: 3rem 0;
}

/* =========================================================================
   Chapter hero illustrations — fade in/out as scrolled past
   ========================================================================= */

.chapter-hero {
  margin: 2.75rem auto;
  max-width: 100%;
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 700ms ease-out, transform 700ms ease-out;
}

.chapter-hero.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.chapter-hero img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 2px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.32);
}

[data-theme="light"] .chapter-hero img {
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}

.chapter-hero figcaption {
  margin-top: 0.7rem;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--subtle);
  text-align: center;
  max-width: 56ch;
  margin-left: auto;
  margin-right: auto;
}

@media (prefers-reduced-motion: reduce) {
  .chapter-hero {
    transition: none;
    opacity: 1;
    transform: none;
  }
}

/* =========================================================================
   Scroll-driven animations — wall sweep + heartbeat trace draw.

   Uses the modern Scroll-Driven Animations API (animation-timeline: view).
   ~95% browser support in 2026 (Chrome 115+, Firefox 121+, Safari 18+).
   Wrapped in @supports so unsupported browsers see static charts —
   indistinguishable from "no animation".
   ========================================================================= */

/* --- Per-row reveal driven by IntersectionObserver (set up in wall.js).
       The row-inner gets a fade; a curtain rect filled with var(--bg)
       sits on top of it and animates transform: scaleX(1 → 0) from its
       right edge, sliding away left-to-right to expose the content.

       Why a curtain rect rather than CSS clip-path on <g> or a clipPath:
       iOS WebKit ignores CSS clip-path transitions on SVG groups AND
       ignores CSS transforms on elements inside <clipPath> when
       computing the clip region. Animating a plain top-layer <rect>
       with a transform works on every browser we target.

       Why absolute user-space transform-origin (960px 0) rather than
       transform-box: fill-box + transform-origin: right: fill-box has
       patchy support on iOS WebKit for SVG elements. The hardcoded value
       matches the curtain's right edge (MARGIN.left + innerWidth +
       MARGIN.right - MARGIN.left = 960 in the inner coordinate space).

       Fallback: .wall.no-sweep hides the curtain entirely. --- */
.wall .row .row-inner {
  opacity: 0;
  transition: opacity 520ms ease-out;
}
.wall .row.is-revealed .row-inner {
  opacity: 1;
}

.wall .row-curtain {
  fill: var(--bg);
  transform-origin: 960px 0;
  transform: scaleX(1);
  transition: transform 700ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
.wall .row.is-revealed .row-curtain {
  transform: scaleX(0);
}

.wall.no-sweep .row-curtain {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .wall .row .row-inner {
    transition: none;
    opacity: 1;
  }
  .wall .row-curtain {
    display: none;
  }
}

@supports (animation-timeline: view()) {

  /* --- Heartbeat traces: stroke draws left-to-right --- */
  @keyframes hb-draw {
    from { stroke-dashoffset: 1; }
    to   { stroke-dashoffset: 0; }
  }
  .hb-line {
    /* pathLength="1" is set by JS so dasharray:1 = full path length */
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    animation: hb-draw linear both;
    animation-timeline: view();
    animation-range: entry 10% cover 35%;
  }

  /* Endpoint dot pops in just as the line finishes drawing */
  @keyframes hb-end-fade {
    from { opacity: 0; transform: scale(0.4); }
    to   { opacity: 1; transform: scale(1); }
  }
  .hb-end {
    transform-origin: center;
    transform-box: fill-box;
    animation: hb-end-fade linear both;
    animation-timeline: view();
    animation-range: entry 30% cover 35%;
  }

  /* --- 3-pt-line transition arc: shot draws across, dot pops at rim ---
     The --arc-len custom property is set by inline script in index.html
     after measuring the path with getTotalLength(). We can't use
     pathLength="1" here because preserveAspectRatio="none" stretches
     the user-space coords non-uniformly and breaks dasharray
     normalization — measuring the actual length is the reliable path. */
  @keyframes ts-arc-draw {
    from { stroke-dashoffset: var(--arc-len, 200); }
    to   { stroke-dashoffset: 0; }
  }
  .ts-arc-path {
    stroke-dasharray: var(--arc-len, 200);
    stroke-dashoffset: var(--arc-len, 200);
    animation: ts-arc-draw linear both;
    animation-timeline: view();
    animation-range: entry 15% cover 45%;
  }

  /* The rim dot rides along the arc path so it tracks the leading edge
     of the draw — a basketball following the shot. cx/cy on the circle
     are zeroed out by inline script when offset-path is supported, so
     the path traversal positions the dot from the start point onward.
     scaleX compensation (--ts-inv-x) keeps it circular under the SVG's
     non-uniform horizontal stretch. */
  @supports (offset-path: path('M 0 0')) {
    @keyframes ts-arc-fly {
      from { offset-distance: 0%; }
      to   { offset-distance: 100%; }
    }
    .ts-arc-dot {
      offset-path: path('M 2 28 Q 50 -25 96 22');
      offset-distance: 100%;
      offset-rotate: 0deg;
      animation: ts-arc-fly linear both;
      animation-timeline: view();
      animation-range: entry 15% cover 45%;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .hb-line, .hb-end,
    .ts-arc-path, .ts-arc-dot {
      animation: none;
      stroke-dashoffset: 0;
      opacity: 1;
    }
    .ts-arc-dot {
      offset-distance: 100%;
    }
  }
}

/* =========================================================================
   Wall (D3 SVG) — theme via CSS variables so toggling is instant
   ========================================================================= */

.wall {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;     /* let row labels extend past the inner viewBox */
}

/* Halos (drawn first, behind everything) */
.halo                 { stroke: none; }
.halo-champ_halo      { fill: var(--champ-halo); }
.halo-silver_halo     { fill: var(--silver-halo); }
.halo-dark_halo       { fill: var(--dark-halo); }

/* Faint baseline rule per row */
.baseline {
  stroke: var(--grid);
  stroke-width: 0.5;
}

/* Game bars — Knicks blue for wins, Knicks orange for losses, throughout.
   Stroke width signals tier: regular < playoff < silver run < champ run. */
.game             { stroke-linecap: butt; }
.game-w           { stroke: var(--win);  stroke-width: 1.4; }
.game-l           { stroke: var(--loss); stroke-width: 1.4; }
.game-playoff-w   { stroke: var(--win);  stroke-width: 1.6; }
.game-playoff-l   { stroke: var(--loss); stroke-width: 1.6; }
.game-silver-w    { stroke: var(--win);  stroke-width: 1.8; }
.game-silver-l    { stroke: var(--loss); stroke-width: 1.8; }
.game-champ-w     { stroke: var(--win);  stroke-width: 1.9; }
.game-champ-l     { stroke: var(--loss); stroke-width: 1.9; }

/* Three-point dots */
.threept {
  fill: var(--three-pt);
  stroke: none;
  opacity: 0.85;
}

/* Month axis (Oct → Jun, above the wall) */
.month-label {
  fill: var(--season-label);
  font-family: var(--sans);
  font-size: 7.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
}
.month-boundary {
  stroke: var(--grid);
  stroke-width: 0.5;
}

/* Season labels (left margin) */
.season-label {
  fill: var(--season-label);
  font-family: var(--serif);
  font-size: 9px;
}

/* Row labels (right margin) */
.row-label-top {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.04em;
  fill: var(--ink);
}
.row-label-top.color-champ_run  { fill: var(--champ-run); }
.row-label-top.color-silver_run { fill: var(--silver-run); }
.row-label-top.color-ink        { fill: var(--ink); }

.row-label-flavor {
  font-family: var(--serif);
  font-style: italic;
  font-size: 9px;
  fill: var(--ink);
}

/* Season notes (italic flavor in empty parts of anomalous-season rows) */
.season-note {
  font-family: var(--serif);
  font-style: italic;
  font-size: 11px;
  fill: var(--ink);
}
.season-note-leader {
  stroke: var(--ink);
  stroke-width: 0.7;
  stroke-dasharray: 2 2;
  opacity: 0.7;
}

/* =========================================================================
   Chapter 2 transition strip — "OCT 12, 1979 — THE THREE-POINT LINE ARRIVES"
   ========================================================================= */

.transition-strip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 1.25rem 0 0.5rem;
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}
.ts-date  { color: var(--ink); white-space: nowrap; }
.ts-label { color: var(--three-pt); white-space: nowrap; }

/* Three-point shot arc: connects the date to the gold rim dot. The
   viewBox is 100×30 with the apex (Q control point at y=-25) sitting
   well above the box, so overflow: visible lets it peek up into the
   margin above the strip. preserveAspectRatio="none" lets the arc
   stretch with the available flex width; vector-effect keeps the
   stroke a uniform thickness regardless of stretch. */
.ts-arc {
  flex: 1;
  min-width: 4rem;
  height: 30px;
  overflow: visible;
  display: block;
}
.ts-arc-path {
  fill: none;
  stroke: var(--three-pt);
  stroke-width: 0.8;
  stroke-linecap: round;
  opacity: 0.75;
}
.ts-arc-dot {
  fill: var(--three-pt);
}

/* =========================================================================
   Heartbeat grid (Chapters 3 + 4)
   Auto-fit lays out 5–6 cells per row on desktop, fewer as width drops,
   and stacks on mobile. minmax(200px, 1fr) gives each cell enough room
   for the trace to read.
   ========================================================================= */

.heartbeat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.85rem;
  margin: 1rem 0 1.5rem;
}

/* Chapters 3 and 4 each have 6 featured games — force a 3×2 layout
   instead of letting auto-fit produce a lopsided 4+2 or 5+1 wrap.
   Falls back to 2 columns on tablet and 1 on phone. */
#chapter3-grid,
#chapter4-grid {
  grid-template-columns: repeat(3, 1fr);
}
@media (max-width: 720px) {
  #chapter3-grid,
  #chapter4-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 480px) {
  #chapter3-grid,
  #chapter4-grid {
    grid-template-columns: 1fr;
  }
}

.hb-cell {
  display: flex;
  flex-direction: column;
}

.heartbeat .hb-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.hb-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 0.95rem;
  margin: 0;
  color: var(--ink);
  line-height: 1.1;
}

.hb-margin {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.25rem;
  line-height: 1;
}
.hb-margin.is-win  { color: var(--trace-win); }
.hb-margin.is-loss { color: var(--trace-loss); }

.hb-flavor {
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--subtle);
  margin: 0.25rem 0 0.15rem;
  line-height: 1.35;
}

.hb-date {
  font-family: var(--sans);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--subtle);
  opacity: 0.75;
  margin: 0 0 0.4rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hb-trace {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* Trace internals — colors follow theme variables */
.hb-period       { stroke: var(--grid); stroke-width: 0.5; }
.hb-period-label { fill: var(--subtle); font-family: var(--sans); font-size: 7px; }
.hb-zero         { stroke: var(--trace-zero); stroke-width: 0.6; }

.hb-fill-win    { fill: var(--trace-win);  opacity: 0.18; stroke: none; }
.hb-fill-loss   { fill: var(--trace-loss); opacity: 0.18; stroke: none; }

.hb-line             { fill: none; stroke-width: 1.4; }
.hb-line.is-win      { stroke: var(--trace-win); }
.hb-line.is-loss     { stroke: var(--trace-loss); }

.hb-end              { stroke: var(--bg); stroke-width: 0.6; }
.hb-end.is-win       { fill: var(--trace-win); }
.hb-end.is-loss      { fill: var(--trace-loss); }

/* Hover scrubber — dashed vertical line + small dot follow the cursor
   along the trace; cell.is-scrubbing fades them in (and swaps the
   .hb-date text for the score at the hovered moment, driven by JS). */
.hb-scrub-line {
  stroke: var(--ink);
  stroke-width: 0.6;
  stroke-dasharray: 2 2;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease-out;
}
.hb-scrub-dot {
  fill: var(--ink);
  stroke: var(--bg);
  stroke-width: 0.6;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease-out;
}
.heartbeat.is-scrubbing .hb-scrub-line,
.heartbeat.is-scrubbing .hb-scrub-dot {
  opacity: 0.85;
}
.heartbeat.is-scrubbing .hb-date {
  opacity: 1;
  color: var(--ink);
}
.hb-scrub-overlay {
  cursor: crosshair;
  touch-action: pan-y;
}

/* =========================================================================
   Game tooltip — floats near the cursor on desktop, pins on tap on mobile
   ========================================================================= */

.game-tooltip {
  /* --tt-scale is set by tooltip.js to 1/visualViewport.scale on mobile so
     the tooltip stays at a consistent physical size when the user is
     pinch-zoomed in. Defaults to 1 (no scale) on desktop and when
     visualViewport is unavailable. transform-origin: top left so the
     bounding rect grows down/right from (left, top) — keeps the JS-side
     edge clamping math straightforward. */
  --tt-scale: 1;
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;       /* tooltip never absorbs cursor itself */
  z-index: 200;
  min-width: 12rem;
  max-width: 16rem;
  padding: 0.7rem 0.85rem;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--subtle);
  border-radius: 3px;
  font-family: var(--sans);
  font-size: 0.78rem;
  line-height: 1.35;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: translateY(-2px) scale(var(--tt-scale));
  transform-origin: top left;
  transition: opacity 120ms ease-out, transform 120ms ease-out;
}
.game-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0) scale(var(--tt-scale));
}

.tt-date {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.78rem;
  color: var(--subtle);
  margin-bottom: 0.25rem;
}
.tt-matchup {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}
.tt-vs {
  font-weight: 400;
  color: var(--subtle);
  font-size: 0.78rem;
}
.tt-score {
  margin-top: 0.5rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-family: var(--sans);
}
.tt-result {
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
}
.tt-score.tt-win  .tt-result, .tt-score.tt-win  .tt-margin { color: var(--win); }
.tt-score.tt-loss .tt-result, .tt-score.tt-loss .tt-margin { color: var(--loss); }
.tt-numbers {
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
  color: var(--ink);
}
.tt-margin {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.tt-threes {
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--subtle);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.tt-threes .tt-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--three-pt);
}
.tt-tag {
  display: inline-block;
  margin-top: 0.4rem;
  padding: 0.05rem 0.4rem;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  border: 1px solid var(--subtle);
  color: var(--subtle);
  border-radius: 2px;
  text-transform: uppercase;
}

/* =========================================================================
   Chart legend — compact key strip above each wall.
   Items wrap to a second line on narrow screens. Swatches mirror the
   wall's visual language (vertical bars for W/L, gold dot for 3PT, rounded
   rect halos for silver/champ runs).
   ========================================================================= */

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 1.1rem;
  margin: 0.6rem 0 0.4rem;
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  opacity: 0.85;
}
.lg-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}
.lg-sw {
  display: inline-block;
  flex-shrink: 0;
}
.lg-sw-bar {
  width: 2px;
  height: 14px;
  border-radius: 1px;
}
.lg-sw-bar.lg-sw-win  { background: var(--win); }
.lg-sw-bar.lg-sw-loss { background: var(--loss); }
.lg-sw-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--three-pt);
  opacity: 0.9;
}
.lg-sw-halo {
  width: 20px;
  height: 11px;
  border-radius: 2px;
  border: 1px solid var(--grid);
}
.lg-sw-halo.lg-sw-silver { background: var(--silver-halo); }
.lg-sw-halo.lg-sw-champ  { background: var(--champ-halo); }
.lg-text {
  color: var(--subtle);
  font-family: var(--serif);
  font-style: italic;
}

/* =========================================================================
   Chapter rail — slim vertical navigation along the left margin.
   Dots only by default; full era label slides in on hover/focus and on
   the currently-active chapter. Hidden below 900px (no room next to the
   centered max-width content).
   ========================================================================= */

.chapter-rail {
  position: fixed;
  top: 50%;
  left: max(1.1rem, env(safe-area-inset-left));
  transform: translateY(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.rail-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--subtle);
  text-decoration: none;
  font-family: var(--sans);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color var(--transition);
}
.rail-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--subtle);
  transition: background-color var(--transition), transform var(--transition);
}
.rail-label {
  opacity: 0;
  transform: translateX(-3px);
  transition: opacity var(--transition), transform var(--transition);
  pointer-events: none;
}
.rail-item:hover,
.rail-item:focus-visible {
  color: var(--ink);
  outline: none;
}
.rail-item:hover .rail-dot,
.rail-item:focus-visible .rail-dot {
  background: var(--ink);
}
.rail-item:hover .rail-label,
.rail-item:focus-visible .rail-label {
  opacity: 1;
  transform: translateX(0);
}
.rail-item.is-active {
  color: var(--ink);
}
.rail-item.is-active .rail-dot {
  background: var(--ink);
  transform: scale(1.35);
}
.rail-item.is-active .rail-label {
  opacity: 1;
  transform: translateX(0);
}
@media (max-width: 900px) {
  .chapter-rail { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .rail-item, .rail-dot, .rail-label { transition: none; }
}

/* =========================================================================
   Control labels — small label under each chrome button.
   Visible on hover/focus, and visible for the first ~4 seconds of the
   session (.controls.is-fresh) so users discover the buttons exist.
   "Armed" state is the music button after a prior visit had music
   enabled — autoplay is browser-blocked, so the button shows a distinct
   gold outline meaning "tap to resume" rather than the solid pressed state.
   ========================================================================= */

.control {
  position: relative;
}
.control-label {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  font-family: var(--sans);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--subtle);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity var(--transition), transform var(--transition);
}
.controls.is-fresh .control-label,
.control:hover .control-label,
.control:focus-visible .control-label {
  opacity: 1;
  transform: translateY(0);
}
.control.is-armed {
  border-color: var(--three-pt);
  color: var(--three-pt);
}
.control.is-armed:hover,
.control.is-armed:focus-visible {
  border-color: var(--three-pt);
  color: var(--three-pt);
  background-color: color-mix(in srgb, var(--three-pt) 10%, transparent);
}
.control.is-armed .control-label {
  color: var(--three-pt);
}
@media (prefers-reduced-motion: reduce) {
  .control-label { transition: none; }
}

/* =========================================================================
   Wall bar highlight on hover/scrub — bumps stroke-width on the active
   bar and adds a soft glow so users can see which bar the floating
   tooltip refers to among ~80+ per row.
   ========================================================================= */

.game.is-active {
  stroke-width: 3;
  filter: drop-shadow(0 0 1.6px var(--ink));
}
