/* A Tiny Rush — the whole look. The UI is light floating IN the tunnel, not
   a menu skinned over it: no boxed cards, no borders-around-everything. The
   idle scene stays visible behind every screen; type, glow and scrims do all
   the work.

   DOM contract: index.html provides #game / #flash / #ui; ui.js builds all
   menu/HUD DOM inside #ui; effects.js animates #flash inline.

   TYPE SYSTEM — one face stack (--font), ALL-CAPS hierarchy, five tiers:
     T1 MONUMENT   900 · ls 0.04-0.12em · white→hue gradient or white core,
                   triple hue glow. Titles: RUSH, level names, CLEAR, PAUSED.
     T2 IMPERATIVE 900 · ls 0.28-0.32em · white core + hue halo, breathing
                   glow, flanked by light beams. THE one action per screen.
     T3 KICKER     700 · ls 0.4-0.55em · accent ink + soft hue glow. Labels
                   above/below titles (A TINY, LEVEL 03, BREAKS).
     T4 SATELLITE  700 · 11px · ls 0.28em · dim ink, hover→white. Quiet
                   secondary actions orbiting the imperative.
     T5 WHISPER    700 · 9-11px · ls 0.25-0.3em · faint ink. Hints, dismiss
                   lines, key-cap rows.

   SCRIM TIERS — every floating text must read on the brightest tunnel frame:
     S1 HARD  text-shadow: 0 2px 4px #000e, 0 0 16px #000c   (HUD numerals)
     S2 SOFT  text-shadow: 0 1px 3px #000c, 0 0 12px #0009   (labels, hints)
     S3 POOL  ::before radial ink pool behind a floating cluster — light
              falloff, never a rectangle.

   MOTION — entrances/exits are light-based: opacity + blur + scale/rise,
   150-250ms (matIn / matUp). Idle life: beaconPulse (the imperative
   breathes). All killed under prefers-reduced-motion. */

:root {
  --font: 'Futura', 'Avenir Next', 'Avenir', 'Segoe UI', system-ui,
    -apple-system, sans-serif;
  --ink: #f2f3ff;
  --ink-dim: rgba(220, 224, 255, 0.5);
  --ink-faint: rgba(220, 224, 255, 0.24);
  /* Default accent (violet) — ui.js overrides per hue via --accent vars. */
  --accent: #7a5cff;
  --accent-glow: #ded6ff;
  --accent-dim: #4636a3;
  --danger: #ff2e44;
  --gold: #ffd76a;
  /* Race medal metals (gold reuses --gold). Silver stays a cool grey-blue,
     deliberately short of white — white is the lethal language. */
  --silver: #b9c4dd;
  --bronze: #d4854a;
  /* Scrim shadows as reusable values (S1/S2 of the system above). */
  --scrim-hard: 0 2px 4px rgba(0, 0, 0, 0.9), 0 0 16px rgba(0, 0, 0, 0.75);
  --scrim-soft: 0 1px 3px rgba(0, 0, 0, 0.78), 0 0 12px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  background: #04030a;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ------------------------------------------------------------ canvas/flash */

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
  touch-action: none;
  transition: filter 0.35s ease;
}

#flash {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  background: #fff;
  opacity: 0; /* effects.js animates opacity/background inline */
  will-change: opacity;
}

/* --------------------------------------------------------------- ui shell */

#ui {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s;
}

.screen.visible {
  opacity: 1;
  visibility: visible;
}

.screen.menu.visible,
.screen.complete.visible {
  pointer-events: auto;
}

/* ----------------------------------------------------------------- motion */
/* Light-based entrances: a thing condenses out of the glow (blur→sharp). */

@keyframes matIn {
  from { opacity: 0; filter: blur(10px); transform: scale(1.06); }
  to { opacity: 1; filter: blur(0); transform: scale(1); }
}

@keyframes matUp {
  from { opacity: 0; filter: blur(6px); transform: translateY(14px); }
  to { opacity: 1; filter: blur(0); transform: translateY(0); }
}

/* The imperative breathes — light, not box-shadow on a box. */
@keyframes beaconPulse {
  0%, 100% {
    filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 40%, transparent));
  }
  50% {
    filter: drop-shadow(0 0 20px color-mix(in srgb, var(--accent) 85%, transparent));
  }
}

/* ---------------------------------------------------------------- buttons */
/* No pills, no boxes: actions are TYPE. The base .btn is an invisible,
   touch-sized hit area around glowing words. */

.btn {
  pointer-events: auto;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.28em;
  text-indent: 0.28em; /* re-center letterspaced uppercase */
  text-transform: uppercase;
  color: var(--ink);
  background: none;
  border: none;
  padding: 12px 16px;
  cursor: pointer;
  transition: color 0.15s ease, text-shadow 0.15s ease, transform 0.15s ease,
    opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 10px;
}

/* T2 IMPERATIVE core: white word in a hue halo over a hard scrim. */
.btn-primary {
  color: #fff;
  text-shadow: var(--scrim-hard),
    0 0 14px var(--accent),
    0 0 48px color-mix(in srgb, var(--accent) 65%, transparent);
}

.btn.hidden {
  display: none !important; /* must beat .play-big/.next-chip display:flex */
}

/* THE one giant primary action — a glowing imperative floating in space,
   flanked by light beams. Reused on pause (RESUME) + finale (PLAY AGAIN). */

.btn.play-big {
  display: inline-flex;
  align-items: center;
  gap: clamp(14px, 2.4vw, 26px);
  font-size: clamp(20px, 3.4vw, 32px);
  font-weight: 900;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  white-space: nowrap;
  padding: clamp(12px, 2.2vh, 18px) 10px;
  animation: beaconPulse 2.4s ease-in-out infinite;
}

.btn.play-big::before,
.btn.play-big::after {
  content: '';
  flex: none;
  height: 2px;
  width: clamp(30px, 5.5vw, 72px);
  background: linear-gradient(90deg, transparent, var(--accent));
  box-shadow: 0 0 10px var(--accent);
}

.btn.play-big::after {
  background: linear-gradient(270deg, transparent, var(--accent));
}

.btn.play-big:hover {
  transform: scale(1.04);
}

.btn.play-big:active {
  transform: scale(0.98);
}

/* Imperatives signal focus with LIGHT, not an outline box: the word goes
   white-hot and the flanking beams burn brighter. */
.btn.play-big:focus-visible,
.btn.next-chip:focus-visible {
  outline: none;
  transform: scale(1.04);
  text-shadow: var(--scrim-hard), 0 0 10px rgba(255, 255, 255, 0.8),
    0 0 24px var(--accent), 0 0 70px var(--accent);
}

.btn.play-big:focus-visible::before,
.btn.play-big:focus-visible::after {
  box-shadow: 0 0 14px var(--accent), 0 0 30px var(--accent);
}

/* T4 SATELLITES: quiet words with a tiny diamond pip — the game's glyph. */

.btn.btn-quiet {
  font-size: 11px;
  font-weight: 700;
  padding: 10px 12px;
  color: var(--ink-dim);
  text-shadow: var(--scrim-soft);
}

.btn.btn-quiet::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  rotate: 45deg;
  margin-right: 9px;
  vertical-align: 1px;
  background: currentColor;
  opacity: 0.55;
  transition: background 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.btn.btn-quiet:hover {
  color: #fff;
  text-shadow: var(--scrim-soft), 0 0 12px var(--accent);
}

.levels-toggle.on {
  color: #fff;
  text-shadow: var(--scrim-soft), 0 0 12px var(--accent);
}

.levels-toggle.on::before {
  background: var(--accent);
  opacity: 1;
  box-shadow: 0 0 8px var(--accent);
}

.sound-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sound-btn::before {
  display: none; /* icon-only satellite — no pip */
}

.mute-dot {
  width: 8px;
  height: 8px;
  rotate: 45deg;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.sound-btn.muted .mute-dot {
  background: rgba(255, 255, 255, 0.22);
  box-shadow: none;
}

/* quiet clickable key-hints (pause + complete) — text, not buttons */

.link {
  pointer-events: auto;
  font: inherit;
  letter-spacing: inherit;
  background: none;
  border: none;
  padding: 0;
  color: var(--ink-dim);
  cursor: pointer;
  transition: color 0.15s ease;
}

.link:hover,
.link:focus-visible {
  color: var(--ink);
}

.link:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* T5 WHISPER row with key caps (caps stay — they're physical glyphs). */
.controls-hint {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: rgba(222, 226, 255, 0.62);
  text-shadow: var(--scrim-soft);
  text-align: center;
  line-height: 2.2;
}

.controls-hint b {
  display: inline-block;
  font-weight: 700;
  padding: 1px 7px;
  margin: 0 1px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--ink);
  background: rgba(10, 8, 22, 0.5);
}

.controls-hint .dot {
  margin: 0 10px;
  color: var(--ink-faint);
}

/* ------------------------------------------------------------------- menu */
/* The menu IS the idle tunnel — a moment of stillness. One small ink pool,
   no bigger than the type needs; the scene carries all atmosphere. The
   heavier scrim only returns while the levels rail is open (100 cards need
   the readability). */

.screen.menu {
  overflow-y: auto;
  background: radial-gradient(
    ellipse 44% 26% at 50% 50%,
    rgba(4, 3, 10, 0.5),
    transparent 70%
  );
}

.screen.menu.rail-open {
  background:
    radial-gradient(
      ellipse 74% 62% at 50% 44%,
      rgba(4, 3, 10, 0.52),
      transparent 72%
    ),
    radial-gradient(
      150% 150% at 50% 50%,
      transparent 38%,
      rgba(4, 3, 10, 0.88) 100%
    );
}

.menu-inner {
  width: min(720px, 96vw);
  margin: auto;
  padding: clamp(20px, 4vh, 48px) 0 calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(16px, 3.4vh, 34px);
}

/* Entrances: the imperative and its satellites condense out of the glow. */
.screen.menu.visible .play-big {
  animation: matUp 0.24s cubic-bezier(0.2, 0.9, 0.25, 1) both,
    beaconPulse 2.4s 0.4s ease-in-out infinite;
}

.screen.menu.visible .menu-secondary {
  animation: matUp 0.24s 0.08s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

/* quiet satellite row: LEVELS · HOW TO PLAY · sound */

.menu-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vw, 22px);
}

.screen.menu.rail-open .menu-inner {
  gap: clamp(12px, 2.6vh, 24px);
}

/* ------------------------------------------------------------ levels rail */
/* 10 worlds as glowing diamond SIGILS on a strip; the open world's levels
   materialize as a constellation row beneath. No gray cards anywhere. */

.levels-drawer {
  display: none;
  width: 100%;
}

.levels-drawer.open {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.8vh, 18px);
  animation: matUp 0.22s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

.world-rail {
  display: flex;
  justify-content: center;
  gap: clamp(2px, 1vw, 12px);
  max-width: 96vw;
}

.world-head {
  pointer-events: auto;
  flex: none;
  width: clamp(56px, 8.2vw, 86px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 6px 0;
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.sigil {
  position: relative;
  width: clamp(28px, 4vw, 40px);
  aspect-ratio: 1;
  margin: 6px;
  rotate: 45deg;
  border: 2px solid color-mix(in srgb, var(--accent) 70%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 30%, transparent),
    inset 0 0 8px color-mix(in srgb, var(--accent) 22%, transparent);
  transition: transform 0.18s ease, background 0.18s ease,
    box-shadow 0.18s ease, border-color 0.18s ease;
}

.world-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  rotate: -45deg;
  font-size: clamp(11px, 1.6vw, 15px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 0 8px var(--accent);
}

.world-head:hover:not(.locked) .sigil,
.world-head:focus-visible .sigil {
  transform: scale(1.12);
  border-color: var(--accent);
  box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 55%, transparent),
    inset 0 0 10px color-mix(in srgb, var(--accent) 30%, transparent);
}

.world-head:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 10px;
}

.world-head.open .sigil {
  transform: scale(1.16);
  background: color-mix(in srgb, var(--accent) 36%, transparent);
  border-color: var(--accent);
  box-shadow: 0 0 22px color-mix(in srgb, var(--accent) 70%, transparent),
    inset 0 0 12px color-mix(in srgb, var(--accent) 45%, transparent);
}

.world-name {
  max-width: 100%;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-indent: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--ink-dim);
  text-shadow: var(--scrim-soft);
  transition: color 0.18s ease, text-shadow 0.18s ease;
}

.world-head.open .world-name {
  color: #fff;
  text-shadow: var(--scrim-soft), 0 0 10px var(--accent);
}

.world-stars {
  font-size: 9px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: rgba(228, 231, 255, 0.6);
  text-shadow: var(--scrim-soft);
}

.world-stars.full {
  color: var(--gold);
  text-shadow: var(--scrim-soft), 0 0 8px rgba(255, 200, 90, 0.8);
}

.world-lock {
  position: absolute;
  inset: 0;
  rotate: -45deg;
  display: none;
  align-items: center;
  justify-content: center;
  color: rgba(230, 232, 255, 0.55);
}

.world-lock svg {
  width: 12px;
  height: 12px;
  display: block;
}

.world-head.locked {
  cursor: default;
  opacity: 0.32;
  filter: grayscale(0.85);
}

.world-head.locked .world-num {
  visibility: hidden;
}

.world-head.locked .world-stars {
  visibility: hidden;
}

.world-head.locked .world-lock {
  display: flex;
}

/* the open world's ten levels — a constellation strip on a faint light line */

.level-strips {
  position: relative;
  width: 100%;
  min-height: 74px;
  display: flex;
  justify-content: center;
}

.level-strip {
  display: none;
}

.level-strip.open {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: clamp(2px, 0.8vw, 10px);
  animation: matUp 0.2s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

.level-strip.open::before {
  content: '';
  position: absolute;
  left: 4px;
  right: 4px;
  top: 22px;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    color-mix(in srgb, var(--accent) 50%, transparent) 18%,
    color-mix(in srgb, var(--accent) 50%, transparent) 82%,
    transparent
  );
  box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 35%, transparent);
}

.level-card {
  pointer-events: auto;
  position: relative;
  flex: none;
  width: clamp(42px, 6vw, 58px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 0 8px;
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
  transition: transform 0.16s ease;
}

.level-card:hover:not(.locked) {
  transform: translateY(-3px);
}

.level-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 10px;
}

.card-num {
  font-size: clamp(16px, 2.3vw, 22px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 32px;
  margin-top: -6px;
  color: #fff;
  text-shadow: var(--scrim-soft), 0 0 10px var(--accent),
    0 0 26px color-mix(in srgb, var(--accent) 55%, transparent);
  transition: text-shadow 0.16s ease;
}

.level-card:hover:not(.locked) .card-num {
  text-shadow: var(--scrim-soft), 0 0 14px var(--accent),
    0 0 40px var(--accent);
}

.card-stars {
  display: flex;
  gap: 3px;
  font-size: 8px;
  line-height: 1;
}

.card-stars .pip {
  color: var(--ink-faint);
  text-shadow: var(--scrim-soft);
  transition: color 0.2s ease, text-shadow 0.2s ease;
}

.card-stars .pip.lit {
  color: var(--gold);
  text-shadow: var(--scrim-soft), 0 0 6px rgba(255, 200, 90, 0.9);
}

.card-lock {
  display: none;
  position: absolute;
  top: 4px;
  left: 0;
  right: 0;
  height: 32px;
  align-items: center;
  justify-content: center;
  color: rgba(230, 232, 255, 0.45);
}

.card-lock svg {
  width: 13px;
  height: 13px;
}

.level-card.locked {
  cursor: default;
  opacity: 0.3;
}

.level-card.locked .card-num,
.level-card.locked .card-stars {
  visibility: hidden;
}

.level-card.locked .card-lock {
  display: flex;
}

/* ------------------------------------------------------------ race drawer */
/* The rival lineup diamond — shared by the intro card's THE FIELD row
   (intro-rival chips set --accent per rival hue). The cup drawer that once
   also used this was removed: the campaign IS the single racing ladder. */
.rival-dia {
  flex: none;
  width: 7px;
  height: 7px;
  rotate: 45deg;
  background: var(--accent);
  box-shadow: 0 0 7px var(--accent);
}

/* ------------------------------------------------------------------ intro */

.screen.intro {
  transition-duration: 0.15s;
}

.screen.intro::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    70% 58% at 50% 46%,
    color-mix(in srgb, var(--wash, var(--accent)) 22%, transparent),
    transparent 72%
  );
  opacity: 0;
}

.screen.intro.visible::before {
  animation: introWash 1.15s ease forwards;
}

@keyframes introWash {
  0% { opacity: 0; }
  16% { opacity: 1; }
  72% { opacity: 1; }
  100% { opacity: 0; }
}

.intro-card {
  text-align: center;
  opacity: 0;
}

.intro-card.run {
  animation: introCard 1.15s cubic-bezier(0.2, 0.9, 0.25, 1) forwards;
}

@keyframes introCard {
  0% { opacity: 0; transform: scale(0.94); filter: blur(8px); }
  16% { opacity: 1; transform: scale(1); filter: blur(0); }
  74% { opacity: 1; transform: scale(1.015); filter: blur(0); }
  100% { opacity: 0; transform: scale(1.05); filter: blur(2px); }
}

/* T3 KICKER */
.intro-level {
  font-size: clamp(12px, 1.8vw, 15px);
  font-weight: 700;
  letter-spacing: 0.55em;
  text-indent: 0.55em;
  color: var(--accent);
  text-shadow: var(--scrim-soft), 0 0 12px var(--accent);
}

/* T1 MONUMENT */
.intro-name {
  margin-top: 12px;
  font-size: clamp(36px, 7.5vw, 76px);
  font-weight: 900;
  letter-spacing: 0.1em;
  text-indent: 0.1em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 0 14px var(--accent-glow),
    0 0 44px color-mix(in srgb, var(--accent) 65%, transparent),
    0 0 110px color-mix(in srgb, var(--accent) 40%, transparent);
}

.intro-rule {
  margin: 22px auto 0;
  width: min(300px, 50vw);
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--accent),
    transparent
  );
  box-shadow: 0 0 10px var(--accent);
}

/* Goal line on the onboarding level cards — rides the card's animation. */
.intro-goal {
  margin: 16px auto 0;
  max-width: min(560px, 86vw);
  font-size: clamp(13px, 2vw, 17px);
  font-weight: 800;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
  text-transform: uppercase;
  line-height: 1.7;
  color: var(--ink);
  text-shadow: var(--scrim-soft),
    0 0 10px color-mix(in srgb, var(--accent) 60%, transparent),
    0 0 30px color-mix(in srgb, var(--accent) 30%, transparent);
}

.intro-goal.hidden {
  display: none;
}

/* 'RACE · vs k' banner on the campaign card — every level is a race, so the
   card names the contest above the lineup. Quiet kicker weight; the lineup
   below carries the who. */
.intro-race {
  margin: 14px auto 0;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: var(--scrim-soft), 0 0 10px var(--accent);
}

.intro-race.hidden {
  display: none;
}

/* race intro: the rival lineup under the rule — diamonds + the names the
   player is about to be beaten by, each in its rival's hue accent */
.intro-field {
  margin: 14px auto 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
}

.intro-field.hidden {
  display: none;
}

.intro-rival {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  text-shadow: var(--scrim-soft),
    0 0 8px color-mix(in srgb, var(--accent) 60%, transparent);
}

/* Races count at 600 ms beats (2.4 s of grid ceremony vs the campaign's
   1.05): the card + wash stretch so the lineup is still on screen when GO
   lands instead of dying after the campaign-tuned 1.15 s. */
.screen.intro.race.visible::before {
  animation-duration: 2.3s;
}

.screen.intro.race .intro-card.run {
  animation-duration: 2.3s;
}

/* -------------------------------------------------------------------- hud */
/* Diegetic-leaning: floating glyph clusters in the level hue, each over its
   own S3 ink pool. No bars with borders. */

.hud {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s;
}

.hud.visible {
  opacity: 1;
  visibility: visible;
}

/* progress — a thin world-hue ARC cresting the top of the frame */

.progress {
  position: absolute;
  top: calc(4px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(620px, 72vw);
  height: 52px;
}

.progress svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.progress path {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
}

.progress .arc-bg {
  stroke: color-mix(in srgb, var(--accent) 30%, rgba(6, 6, 16, 0.66));
  stroke-width: 5;
}

.progress .arc-fg {
  stroke: var(--accent);
  stroke-width: 3.5;
  filter: drop-shadow(0 0 4px var(--accent))
    drop-shadow(0 0 10px color-mix(in srgb, var(--accent) 45%, transparent));
  transition: stroke-dashoffset 0.2s linear;
}

/* rival ticks (race mode): 7 pooled diamonds riding the arc. Plain divs —
   the svg is preserveAspectRatio:none, so svg children would skew. ui.js
   writes left/top (% of the viewBox) and color; currentColor carries both
   the fill and the glow in one write. The PB ghost gets no tick. */
.progress .race-tick {
  position: absolute;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  rotate: 45deg;
  background: currentColor;
  box-shadow: 0 0 6px;
  opacity: 0.95;
  pointer-events: none;
}

/* score — top right: glyph cluster over an ink pool */

.score-wrap {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: calc(20px + env(safe-area-inset-right));
  text-align: right;
}

.score-wrap::before {
  content: '';
  position: absolute;
  inset: -24px -36px -40px -56px;
  z-index: -1;
  background: radial-gradient(
    ellipse 60% 55% at 68% 42%,
    rgba(4, 3, 10, 0.66),
    transparent 78%
  );
}

.score-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.42em;
  color: rgba(238, 240, 255, 0.85);
  text-shadow: var(--scrim-hard);
}

.score-label::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  rotate: 45deg;
  margin-right: 9px;
  vertical-align: 1px;
  background: var(--accent);
  box-shadow: 0 0 7px var(--accent);
}

.score-value {
  font-size: clamp(30px, 4vw, 42px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: var(--scrim-hard),
    0 0 10px color-mix(in srgb, var(--accent) 75%, transparent),
    0 0 34px color-mix(in srgb, var(--accent) 40%, transparent);
}

/* near-miss '+15' floaters — pooled spans animated via WAAPI in ui.js */

.float-wrap {
  position: absolute;
  top: 100%;
  right: 0;
  width: 140px;
  height: 0;
  pointer-events: none;
}

.floater {
  position: absolute;
  top: 4px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: var(--scrim-hard), 0 0 8px var(--accent),
    0 0 22px color-mix(in srgb, var(--accent) 50%, transparent);
  opacity: 0;
  will-change: transform, opacity;
}

/* combo — right side: number + draining window ring over an ink pool */

.combo-wrap {
  position: absolute;
  right: clamp(16px, 4.5vw, 52px);
  top: 50%;
  width: 88px;
  height: 88px;
  transform: translateY(-50%) scale(var(--tier-scale, 1));
  transform-origin: center;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.combo-wrap::before {
  content: '';
  position: absolute;
  inset: -22px;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(4, 3, 10, 0.6),
    transparent 72%
  );
}

.combo-wrap.visible {
  opacity: 1;
}

.combo-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.combo-ring circle {
  fill: none;
}

.combo-ring .ring-bg {
  stroke: rgba(8, 8, 18, 0.55);
  stroke-width: 4;
}

.combo-ring .ring-fg {
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  filter: drop-shadow(0 0 5px var(--accent));
}

.combo-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 29px;
  font-weight: 900;
  color: #fff;
  text-shadow: var(--scrim-hard), 0 0 10px var(--accent-glow),
    0 0 30px color-mix(in srgb, var(--accent) 65%, transparent);
}

.combo-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -17px;
  text-align: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  color: rgba(238, 240, 255, 0.85);
  text-shadow: var(--scrim-hard);
}

.combo-wrap.hot .combo-ring {
  animation: comboHot 0.42s ease-in-out infinite alternate;
}

@keyframes comboHot {
  from { filter: drop-shadow(0 0 4px var(--accent)); }
  to {
    filter: drop-shadow(0 0 12px var(--accent))
      drop-shadow(0 0 26px var(--accent));
  }
}

/* race position — the combo cluster's LEFT mirror: rank ordinal over its
   own ink pool, one NAMED gap line beneath. Gold at 1ST; a rank loss
   borrows --danger for 600 ms (ui.js timer), faded back by the rank
   element's own color transition. Pops/slams are WAAPI (ui.js). */

.race-wrap {
  position: absolute;
  left: clamp(16px, 4.5vw, 52px);
  top: 50%;
  width: 88px;
  transform: translateY(-50%);
  text-align: center;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.race-wrap::before {
  content: '';
  position: absolute;
  inset: -22px;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(4, 3, 10, 0.6),
    transparent 72%
  );
}

.race-wrap.visible {
  opacity: 1;
}

.race-rank {
  font-size: 30px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: var(--scrim-hard), 0 0 10px var(--accent-glow),
    0 0 30px color-mix(in srgb, var(--accent) 65%, transparent);
  transition: color 0.2s ease, text-shadow 0.2s ease;
}

.race-wrap.lead .race-rank {
  color: var(--gold);
  text-shadow: var(--scrim-hard), 0 0 12px rgba(255, 200, 90, 0.95),
    0 0 36px rgba(255, 170, 40, 0.5);
}

.race-wrap.lost .race-rank {
  color: var(--danger);
  text-shadow: var(--scrim-hard), 0 0 12px rgba(255, 46, 68, 0.9),
    0 0 36px rgba(255, 20, 48, 0.5);
}

/* the cast-learning line: '▲ VEX +0.8s' chasing / '▼ PYRE +1.2s' leading */
.race-delta {
  margin-top: 2px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: rgba(238, 240, 255, 0.85);
  text-shadow: var(--scrim-hard);
}

.race-delta.lead {
  color: var(--gold);
  text-shadow: var(--scrim-hard), 0 0 8px rgba(255, 200, 90, 0.7);
}

/* '{NAME} DOWN' floaters off the chip — pooled spans, WAAPI-risen 1.2 s */
.race-float-wrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 0;
  pointer-events: none;
}

.race-floater {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  text-align: center;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  color: var(--accent);
  text-shadow: var(--scrim-hard), 0 0 8px var(--accent);
  opacity: 0;
  will-change: transform, opacity;
}

/* boost — bottom center: a tapered light BEAM, not a browser bar */

.boost-wrap {
  position: absolute;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, 64vw);
  text-align: center;
}

.boost-wrap::before {
  content: '';
  position: absolute;
  inset: -22px -60px -16px;
  z-index: -1;
  background: radial-gradient(
    ellipse 60% 70% at 50% 62%,
    rgba(4, 3, 10, 0.6),
    transparent 76%
  );
}

.boost-label {
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.52em;
  text-indent: 0.52em;
  color: rgba(238, 240, 255, 0.85);
  text-shadow: var(--scrim-hard);
  transition: color 0.2s ease;
}

.boost-label::before,
.boost-label::after {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  rotate: 45deg;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  vertical-align: 2px;
  opacity: 0.8;
}

.boost-label::before {
  margin-right: 14px;
}

.boost-label::after {
  margin-left: 8px; /* the wrap's text-indent already pads the right side */
}

.boost-bar {
  position: relative;
  height: 7px;
  background: rgba(4, 4, 12, 0.62);
  clip-path: polygon(
    0 50%, 12px 0, calc(100% - 12px) 0, 100% 50%,
    calc(100% - 12px) 100%, 12px 100%
  );
  overflow: hidden;
}

.boost-fill {
  position: absolute;
  inset: 0;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(
    90deg,
    var(--accent-dim),
    var(--accent) 72%,
    var(--accent-glow)
  );
  box-shadow: 0 0 14px var(--accent);
  transition: transform 0.1s linear, background 0.3s ease,
    box-shadow 0.3s ease;
}

/* Near the cap the rush visibly burns. */
.boost-wrap.hot .boost-label {
  color: var(--accent-glow);
  text-shadow: var(--scrim-hard), 0 0 12px var(--accent);
}

.boost-wrap.hot .boost-fill {
  animation: boostBurn 0.5s ease-in-out infinite;
}

@keyframes boostBurn {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.45); }
}

/* ------------------------------------------------------------------ pause */
/* A held breath: the scene dims and blurs, PAUSED hangs in it. No card. */

.screen.pause {
  transition-duration: 0.12s;
  background: rgba(4, 3, 10, 0.55);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  /* Above toast/death-tip (z 4): pause is a modal held breath — a live
     death-tip pill (4 s life, outlives the respawn) must dim/blur under
     it, not float sharp on top of the PAUSED monument. */
  z-index: 5;
}

.screen.pause.visible {
  pointer-events: auto;
}

.pause-card {
  text-align: center;
}

.screen.pause.visible .pause-card {
  animation: matIn 0.2s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

.pause-title {
  font-size: clamp(34px, 7vw, 64px);
  font-weight: 900;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  color: #fff;
  text-shadow: var(--scrim-soft), 0 0 14px var(--accent-glow),
    0 0 44px color-mix(in srgb, var(--accent) 50%, transparent);
}

.pause-card .resume-btn {
  margin-top: 26px;
}

.pause-hints {
  margin-top: 22px;
}

/* -------------------------------------------------------------- countdown */

.countdown {
  position: absolute;
  left: 50%;
  top: 67%;
  z-index: 3;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-size: clamp(40px, 8vw, 80px);
  font-weight: 900;
  letter-spacing: 0.12em;
  text-indent: 0.12em;
  color: #fff;
  text-shadow: var(--scrim-soft), 0 0 16px var(--accent-glow),
    0 0 50px color-mix(in srgb, var(--accent) 60%, transparent);
  opacity: 0;
}

.countdown.beat {
  animation: countBeat 0.36s ease-out forwards;
}

.countdown.go.beat {
  animation: countGo 0.55s cubic-bezier(0.2, 0.9, 0.25, 1) forwards;
}

@keyframes countBeat {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
  22% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0.3; transform: translate(-50%, -50%) scale(0.94); }
}

@keyframes countGo {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.22); }
  60% { opacity: 1; transform: translate(-50%, -50%) scale(1.18); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
}

/* ------------------------------------------------------------------ toast */
/* One-time onboarding hints. Pooled single element (ui.js queues), top-center
   under the progress arc, pointer-events none — gameplay input is never
   blocked. Mid-action readability NEEDS the dark pill scrim; the hue rim
   keeps it in the world. Keep toastLife's 2.2s in sync with TOAST_MS. */

.toast {
  position: absolute;
  top: calc(68px + env(safe-area-inset-top));
  left: 50%;
  z-index: 4;
  transform: translateX(-50%);
  pointer-events: none;
  max-width: min(620px, 88vw);
  padding: 10px 26px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  background: rgba(7, 5, 16, 0.8);
  font-size: clamp(13px, 1.9vw, 15px);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
  white-space: nowrap;
  color: var(--ink);
  text-shadow: var(--scrim-soft),
    0 0 10px color-mix(in srgb, var(--accent) 65%, transparent);
  box-shadow: 0 0 22px color-mix(in srgb, var(--accent) 25%, transparent);
  opacity: 0;
  will-change: transform, opacity;
}

.toast.show {
  animation: toastLife 2.2s ease forwards;
}

@keyframes toastLife {
  0% { opacity: 0; transform: translateX(-50%) translateY(-12px); }
  9% { opacity: 1; transform: translateX(-50%) translateY(0); }
  85% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-8px); }
}

@media (max-width: 700px) {
  .toast {
    white-space: normal;
    border-radius: 16px;
  }
}

/* -------------------------------------------------------------- death tip */
/* Contextual cause tip: appears with the death beat and deliberately
   OUTLIVES it (~4 s), persisting through the 1 s respawn into the fresh run.
   Non-blocking danger-rimmed pill below the toast slot. */

.death-tip {
  position: absolute;
  top: calc(120px + env(safe-area-inset-top));
  left: 50%;
  z-index: 4;
  transform: translateX(-50%);
  pointer-events: none;
  max-width: min(620px, 88vw);
  padding: 10px 26px;
  border-radius: 999px;
  border: 1px solid rgba(255, 70, 90, 0.5);
  background: rgba(16, 4, 8, 0.84);
  font-size: clamp(13px, 2vw, 16px);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
  white-space: nowrap;
  color: var(--ink);
  text-shadow: var(--scrim-soft), 0 0 10px rgba(255, 60, 80, 0.6);
  box-shadow: 0 0 22px rgba(255, 46, 68, 0.25);
  opacity: 0;
  will-change: transform, opacity;
}

.death-tip.show {
  animation: tipLife 4s ease forwards;
}

@keyframes tipLife {
  0% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  6% { opacity: 1; transform: translateX(-50%) translateY(0); }
  88% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-6px); }
}

@media (max-width: 700px) {
  .death-tip {
    white-space: normal;
    border-radius: 16px;
  }
}

/* ------------------------------------------------------------- steer hint */
/* First-run steer glyphs: pulsing ← → key caps low-center (keyboard) or
   left/right hold-zones (coarse pointers). Pointer-events none; fades on the
   first steer (main) or ui's 6 s timeout. */

.steer-hint {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.45s ease;
}

.steer-hint.on {
  opacity: 1;
}

.steer-box {
  position: absolute;
  left: 50%;
  bottom: calc(17% + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.steer-keys {
  display: flex;
  /* Wide gap: the keys FLANK the spark's comet trail (dead center-bottom)
     instead of sitting in its bloom. */
  gap: clamp(120px, 22vw, 220px);
}

.key-glyph {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-bottom-width: 3px;
  border-radius: 10px;
  background: rgba(10, 8, 22, 0.5);
  font-size: 21px;
  font-weight: 800;
  color: var(--ink);
  text-shadow: 0 0 10px var(--accent-glow);
  box-shadow: 0 0 16px color-mix(in srgb, var(--accent) 25%, transparent),
    inset 0 0 10px color-mix(in srgb, var(--accent) 10%, transparent);
}

.steer-hint.on .key-glyph {
  animation: keyPulse 1.15s ease-in-out infinite;
}

.steer-hint.on .key-glyph:last-child {
  animation-delay: 0.575s;
}

@keyframes keyPulse {
  0%, 100% {
    transform: translateY(0);
    background: rgba(10, 8, 22, 0.5);
  }
  50% {
    transform: translateY(3px);
    background: color-mix(in srgb, var(--accent) 22%, transparent);
    box-shadow: 0 0 22px color-mix(in srgb, var(--accent) 45%, transparent);
  }
}

.steer-cap {
  /* Dark pill so the microcopy stays legible over the trail's bloom. */
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  background: rgba(7, 5, 16, 0.72);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  text-transform: uppercase;
  color: var(--ink);
  text-shadow: 0 0 10px color-mix(in srgb, var(--accent) 50%, transparent);
}

.steer-hint .hold-zone {
  position: absolute;
  bottom: calc(11% + env(safe-area-inset-bottom));
  width: clamp(64px, 15vw, 100px);
  height: clamp(110px, 26vh, 170px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px dashed rgba(255, 255, 255, 0.4);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
}

.steer-hint.on .hold-zone {
  animation: keyPulse 1.15s ease-in-out infinite;
}

.steer-hint .hold-zone.left {
  left: 5%;
}

.steer-hint .hold-zone.right {
  right: 5%;
}

.steer-hint.on .hold-zone.right {
  animation-delay: 0.575s;
}

.zone-arrow {
  font-size: 22px;
  color: var(--ink);
  text-shadow: 0 0 10px var(--accent-glow);
}

.zone-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  color: var(--ink-dim);
}

/* touch variant: keep the caption clear of the hold zones */
.steer-hint.touch .steer-box {
  bottom: calc(5% + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------ how to play */
/* The material language floating over the dimmed scene — four glowing words,
   one controls line, one boost line. No card, no chips-in-boxes. */

.screen.howto {
  transition-duration: 0.15s;
  background:
    radial-gradient(
      ellipse 70% 60% at 50% 48%,
      rgba(4, 3, 10, 0.66),
      rgba(4, 3, 10, 0.4) 70%
    ),
    rgba(4, 3, 10, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.screen.howto.visible {
  pointer-events: auto;
}

/* While HOW TO floats, the menu type underneath yields the stage. */
#ui.howto-open .screen.menu {
  opacity: 0;
}

.howto-card {
  width: min(560px, 94vw);
  text-align: center;
}

.screen.howto.visible .howto-card {
  animation: matIn 0.2s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

/* T3 KICKER */
.howto-title {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: rgba(238, 240, 255, 0.9);
  text-shadow: var(--scrim-soft), 0 0 14px var(--accent-glow),
    0 0 36px color-mix(in srgb, var(--accent) 50%, transparent);
}

.howto-chips {
  margin-top: clamp(18px, 3.6vh, 34px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(16px, 3vh, 28px) clamp(14px, 3vw, 34px);
}

.howto-chip {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.chip-word {
  font-size: clamp(16px, 2.6vw, 21px);
  font-weight: 900;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
}

.howto-chip.bright .chip-word {
  color: var(--accent);
  text-shadow: var(--scrim-soft), 0 0 12px var(--accent);
}

.howto-chip.dark .chip-word {
  color: rgba(165, 170, 205, 0.95);
  text-shadow: var(--scrim-soft);
}

.howto-chip.spark .chip-word {
  color: var(--accent-glow);
  text-shadow: var(--scrim-soft), 0 0 12px var(--accent);
}

.howto-chip.jump .chip-word {
  color: #fff;
  text-shadow: var(--scrim-soft), 0 0 12px rgba(255, 255, 255, 0.6);
}

.chip-sub {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
  text-shadow: var(--scrim-soft);
}

.howto-controls {
  margin-top: clamp(16px, 3vh, 26px);
}

.howto-boost {
  margin-top: 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.7;
  color: var(--ink-dim);
  text-shadow: var(--scrim-soft);
}

/* T5 WHISPER */
.howto-dismiss {
  margin-top: clamp(14px, 2.6vh, 22px);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ------------------------------------------------------------------ death */

.screen.death {
  transition-duration: 0.1s;
}

.death-wash {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: radial-gradient(
    circle at 50% 50%,
    rgba(255, 30, 50, 0.26),
    rgba(110, 0, 12, 0.55)
  );
}

.screen.death.run .death-wash {
  animation: deathWash 0.9s ease-out forwards;
}

@keyframes deathWash {
  0% { opacity: 0; }
  12% { opacity: 1; }
  60% { opacity: 0.7; }
  100% { opacity: 0; }
}

.death-stack {
  position: relative;
  text-align: center;
}

.death-word {
  position: relative;
  /* 8vw, not 9 — at 800px the word must clear the combo cluster's slot */
  font-size: clamp(36px, 8vw, 92px);
  font-weight: 900;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  color: #ff3348;
  text-shadow: 0 0 18px rgba(255, 40, 64, 0.9),
    0 0 70px rgba(255, 20, 48, 0.5);
  opacity: 0;
}

.screen.death.run .death-word {
  animation: deathWord 0.9s cubic-bezier(0.2, 0.9, 0.2, 1) forwards;
}

@keyframes deathWord {
  0% { opacity: 0; transform: scale(1.7); filter: blur(10px); }
  16% { opacity: 1; transform: scale(1); filter: blur(0); }
  70% { opacity: 1; transform: scale(1.02); }
  100% { opacity: 0; transform: scale(1.04); }
}

/* --------------------------------------------------------------- complete */
/* The stats materialize IN the scene: hue pool + vignette on the screen,
   stars slam onto the big word, BREAKS is the hero number, NEXT is a beacon.
   No rectangle anywhere. */

.screen.complete,
.screen.podium {
  background:
    radial-gradient(
      ellipse 72% 64% at 50% 46%,
      rgba(4, 3, 10, 0.62),
      transparent 74%
    ),
    radial-gradient(
      150% 150% at 50% 50%,
      transparent 36%,
      rgba(4, 3, 10, 0.86) 100%
    );
}

.complete-stack {
  pointer-events: auto;
  width: min(620px, 94vw);
  text-align: center;
}

.screen.complete.visible .complete-stack,
.screen.podium.visible .complete-stack {
  animation: matIn 0.25s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

/* T3 KICKER */
.complete-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.45em;
  text-indent: 0.45em;
  color: var(--accent);
  text-shadow: var(--scrim-soft), 0 0 10px var(--accent);
}

/* T1 MONUMENT — the big word, not a report. */
.complete-title {
  margin-top: 8px;
  font-size: clamp(50px, 10vw, 96px);
  font-weight: 900;
  letter-spacing: 0.12em;
  text-indent: 0.12em;
  text-transform: uppercase;
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 14px var(--accent-glow),
    0 0 44px color-mix(in srgb, var(--accent) 55%, transparent),
    0 0 110px color-mix(in srgb, var(--accent) 35%, transparent);
}

/* The word SLAMS in, then the stars land on top of it. */
.screen.complete.visible .complete-title,
.screen.podium.visible .complete-title {
  animation: clearSlam 0.45s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

@keyframes clearSlam {
  0% { opacity: 0; transform: scale(1.6); filter: blur(8px); }
  55% { opacity: 1; transform: scale(0.97); filter: blur(0); }
  100% { opacity: 1; transform: scale(1); }
}

/* finale's two-word title must fit the frame */
.complete-title.long {
  font-size: clamp(28px, 6vw, 52px);
  line-height: 1.15;
}

.stars {
  margin-top: clamp(10px, 2.4vh, 20px);
  display: flex;
  justify-content: center;
  gap: clamp(14px, 3.4vw, 26px);
  font-size: clamp(40px, 7.5vw, 62px);
  line-height: 1;
}

.star {
  color: rgba(255, 255, 255, 0.12);
  text-shadow: var(--scrim-soft);
  transition: color 0.2s ease;
}

.star.earned {
  color: var(--gold);
  text-shadow: 0 0 16px rgba(255, 200, 80, 0.95),
    0 0 50px rgba(255, 170, 40, 0.55);
  animation: starPop 0.55s cubic-bezier(0.3, 1.6, 0.4, 1) backwards;
}

.star.earned:nth-child(1) { animation-delay: 0.18s; }
.star.earned:nth-child(2) { animation-delay: 0.46s; }
.star.earned:nth-child(3) { animation-delay: 0.74s; }

@keyframes starPop {
  0% { opacity: 0; transform: scale(0) rotate(-40deg); }
  60% { opacity: 1; transform: scale(1.3) rotate(6deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

/* THE HERO — finishing POSITION leads the campaign complete screen (every
   level is a race). The big ordinal reuses .complete-title; .place adds the
   "/ N" suffix treatment and .win tints it gold. */

/* The place ordinal: gold on a win (overrides the white title glow). The
   suffix sits just beneath, dim, so "1ST" stays the monument. */
.complete-title.win {
  color: var(--gold);
  text-shadow: 0 0 16px rgba(255, 200, 80, 0.95),
    0 0 50px rgba(255, 170, 40, 0.55),
    0 0 120px rgba(255, 150, 30, 0.35);
}

.place-suffix {
  margin-top: 2px;
  font-size: clamp(13px, 2.4vw, 18px);
  font-weight: 800;
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  color: var(--ink-dim);
  text-shadow: var(--scrim-soft);
}

.place-suffix.hidden {
  display: none;
}

/* THE PAYOFF — the field finish order on the complete screen, the podium
   ladder reused at a tighter scale. Backing pool so the rows read cleanly
   over the concentric tunnel rings. */
.result-ladder {
  margin: clamp(10px, 2.2vh, 18px) auto 0;
  width: min(420px, 90vw);
  padding: clamp(8px, 1.6vh, 14px) clamp(10px, 2.4vw, 18px);
  /* backing pool: the ladder rows read cleanly over the concentric rings */
  background: radial-gradient(
    ellipse 90% 120% at 50% 50%,
    rgba(4, 3, 10, 0.55),
    transparent 78%
  );
  border-radius: 12px;
}

.result-ladder.hidden {
  display: none;
}

/* the ladder rows reveal top-down on the complete screen too (the podium
   rule only covers .screen.podium) */
.screen.complete.visible .result-ladder .podium-row {
  animation: matUp 0.25s cubic-bezier(0.2, 0.9, 0.25, 1) both;
  animation-delay: calc(0.05s * var(--row-i, 0));
}

/* SECONDARY STATS — stars + BREAKS + SCORE, demoted under the payoff into one
   quiet row so the racing result owns the top of the screen. */
.result-stats {
  margin-top: clamp(10px, 2.2vh, 18px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.4vh, 12px);
}

/* the stars, now a secondary beat: smaller, still starPop on reveal */
.stats-stars {
  margin-top: 0;
  font-size: clamp(24px, 4.4vw, 36px);
  gap: clamp(10px, 2.4vw, 18px);
}

.stat-tallies {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: clamp(18px, 5vw, 40px);
}

.stat-item {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}

.stat-value {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: clamp(15px, 2.6vw, 21px);
  color: var(--ink);
  text-shadow: var(--scrim-soft),
    0 0 10px color-mix(in srgb, var(--accent) 45%, transparent);
}

.stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4em;
  color: var(--ink-dim);
  text-shadow: var(--scrim-soft);
}

/* score — the quiet flavor line under the hero */

.score-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
}

.score-row.secondary {
  margin-top: clamp(8px, 1.8vh, 14px);
}

.result-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4em;
  color: var(--ink-dim);
  text-shadow: var(--scrim-soft);
}

.result-value {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: clamp(15px, 2.6vw, 21px);
  color: var(--ink-dim);
  text-shadow: var(--scrim-soft);
}

/* finale only: the whole run's star haul */

.total-stars {
  display: none;
  margin-top: 12px;
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-indent: 0.14em;
  color: var(--gold);
  text-shadow: var(--scrim-soft), 0 0 14px rgba(255, 200, 80, 0.9),
    0 0 44px rgba(255, 170, 40, 0.45);
}

.total-stars.visible {
  display: block;
}

/* NEXT — a pulsing beacon with the auto-advance ring beside the word */

.next-chip {
  margin-top: clamp(14px, 3vh, 24px);
  display: inline-flex;
  align-items: center;
  gap: 14px;
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 900;
  letter-spacing: 0.3em;
  text-indent: 0;
  padding: 12px 18px;
  animation: beaconPulse 2.4s ease-in-out infinite;
}

.next-chip:hover {
  transform: scale(1.05);
}

.next-chip .chip-ring {
  width: 28px;
  height: 28px;
  flex: none;
}

.chip-ring circle {
  fill: none;
}

.chip-ring .ring-bg {
  stroke: rgba(255, 255, 255, 0.18);
  stroke-width: 3.5;
}

.chip-ring .ring-fg {
  stroke: var(--accent-glow);
  stroke-width: 3.5;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  filter: drop-shadow(0 0 4px var(--accent));
}

.again-btn {
  margin-top: clamp(14px, 3vh, 24px);
  white-space: nowrap;
  font-size: clamp(17px, 2.8vw, 24px);
}

.complete-hint {
  margin-top: clamp(8px, 2vh, 16px);
}

.new-best {
  display: none;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--gold);
  text-shadow: var(--scrim-soft), 0 0 10px rgba(255, 200, 80, 0.9);
  animation: bestGlow 1.2s ease-in-out infinite;
}

.new-best.visible {
  display: inline-block;
}

@keyframes bestGlow {
  0%, 100% { opacity: 0.75; }
  50% { opacity: 1; }
}

/* ----------------------------------------------------------------- podium */
/* Race results — the complete screen's racing sibling (docs/RACE.md §5).
   Same scene-materialized look (shared selectors above); only the ladder
   and the cleared/haul lines are new. The ladder IS the scoreboard. */

.screen.podium.visible {
  pointer-events: auto;
}

/* CUP CLEARED — lights under the kicker when the trophy just went ≥ 1 */
.podium-cleared {
  display: none;
  margin-top: 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  color: var(--gold);
  text-shadow: var(--scrim-soft), 0 0 10px rgba(255, 200, 90, 0.8);
}

.podium-cleared.visible {
  display: block;
}

.podium-ladder {
  margin: clamp(10px, 2.4vh, 20px) auto 0;
  width: min(460px, 92vw);
  display: flex;
  flex-direction: column;
  gap: clamp(3px, 0.8vh, 7px);
}

/* rank · diamond · name · medal · M:SS.t · +gap — one racer per row */
.podium-row {
  display: grid;
  grid-template-columns: 40px 12px 1fr 18px 64px 52px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  font-variant-numeric: tabular-nums;
  color: var(--ink-dim);
  text-shadow: var(--scrim-soft);
}

.podium-row.hidden {
  display: none;
}

/* rows materialize top-down — the ladder reads as a reveal, not a table */
.screen.podium.visible .podium-row {
  animation: matUp 0.25s cubic-bezier(0.2, 0.9, 0.25, 1) both;
  animation-delay: calc(0.06s * var(--row-i, 0));
}

.row-rank {
  text-align: right;
}

.row-diamond {
  width: 8px;
  height: 8px;
  rotate: 45deg;
  background: currentColor; /* ui.js writes the rival hue as color */
  box-shadow: 0 0 7px;
}

.row-name {
  text-align: left;
  letter-spacing: 0.2em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-time {
  text-align: right;
}

.row-gap {
  text-align: right;
  font-size: 10px;
  color: var(--ink-faint);
}

/* YOU: lit in the player glow — the race hue's pale light, the same tint
   family as the PB ghost. Winner gold beats it when both apply. */
.podium-row.you {
  color: var(--accent-glow);
  text-shadow: var(--scrim-soft),
    0 0 10px color-mix(in srgb, var(--accent) 80%, transparent),
    0 0 26px color-mix(in srgb, var(--accent) 40%, transparent);
}

.podium-row.win {
  color: var(--gold);
  text-shadow: var(--scrim-soft), 0 0 10px rgba(255, 200, 90, 0.7);
}

.podium-row.dnf {
  opacity: 0.5;
}

/* the player's medal — a star in medal metal, starPop'd on improvement
   only (.quiet = already held: lands lit, no fanfare) */
.row-medal {
  font-size: 13px;
  line-height: 1;
  visibility: hidden;
}

.row-medal.earned {
  visibility: visible;
}

.row-medal.earned.m1 {
  color: var(--bronze);
  text-shadow: 0 0 10px rgba(212, 133, 74, 0.9);
}

.row-medal.earned.m2 {
  color: var(--silver);
  text-shadow: 0 0 10px rgba(185, 196, 221, 0.9);
}

/* m3 keeps .star.earned's gold */

.row-medal.quiet {
  animation: none;
}

/* finale haul line reuses the .total-stars slot; just tighten tracking */
.podium-haul {
  letter-spacing: 0.18em;
  text-indent: 0.18em;
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 560px) {
  .btn.play-big {
    font-size: 15px;
    gap: 10px;
  }

  .btn.play-big::before,
  .btn.play-big::after {
    width: 22px;
  }

  .world-rail {
    flex-wrap: wrap;
    row-gap: 2px;
  }

  .world-head {
    width: 17vw;
  }

  .world-name {
    display: none;
  }

  .level-strip.open {
    flex-wrap: wrap;
    justify-content: center;
    max-width: 96vw;
  }

  .level-strip.open::before {
    display: none; /* the light line can't follow a wrapped strip */
  }

  .boost-wrap {
    width: 76vw;
  }

  .combo-wrap {
    right: 8px;
    width: 68px;
    height: 68px;
  }

  .combo-num {
    font-size: 20px;
  }

  .controls-hint {
    padding: 0 16px;
  }

  .btn.next-chip {
    font-size: 16px;
  }

  /* race chip mirrors the combo cluster's mobile squeeze */
  .race-wrap {
    left: 8px;
    width: 68px;
  }

  .race-rank {
    font-size: 22px;
  }

  .podium-row {
    grid-template-columns: 34px 10px 1fr 14px 56px 44px;
    gap: 6px;
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .screen.menu.visible .play-big,
  .screen.menu.visible .menu-secondary,
  .levels-drawer.open,
  .level-strip.open,
  .screen.pause.visible .pause-card,
  .screen.howto.visible .howto-card,
  .screen.complete.visible .complete-stack,
  .screen.complete.visible .complete-title,
  .screen.podium.visible .complete-stack,
  .screen.podium.visible .complete-title,
  .screen.podium.visible .podium-row,
  /* the complete screen's field ladder reveals the same way — join the list */
  .screen.complete.visible .result-ladder .podium-row,
  /* the player-row medal inherits .star.earned's starPop (scale 0→1.3 +
     rotate) — a new race surface bound by the §5 'new animations join the
     kill list' law. Visibility rides .row-medal.earned, not the fill, so
     killing the pop leaves the medal lit and still. */
  .screen.podium.visible .row-medal.earned,
  .btn.play-big,
  .btn.next-chip,
  .steer-hint.on .key-glyph,
  .steer-hint.on .hold-zone,
  .combo-wrap.hot .combo-ring,
  .boost-wrap.hot .boost-fill,
  .new-best {
    animation: none;
  }
}
