/* Components read tokens from app/ui/tokens.css only. No raw colors below this line. */
@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 700;
  font-stretch: 75%;
  font-display: swap;
  src: url("./assets/fonts/roboto-latin-700-condensed.woff2") format("woff2");
}

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

html, body {
  width: var(--stage-size);
  height: var(--stage-size);
  overflow: hidden;
  background: var(--color-stage);
  color: var(--color-text);
  font-family: var(--font-family);
  font-weight: 700;
  font-stretch: 75%;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button, input { font: inherit; color: inherit; }

/* ---------- Stage: fixed 600×600, nothing scrolls ---------- */
#stage {
  position: relative;
  isolation: isolate;
  width: var(--stage-size);
  height: var(--stage-size);
  overflow: hidden;
  background: var(--color-stage);
}

/* Ambient background: two soft glows, slow drift. steps() caps the animation at 30 FPS
   (22s × 30 = 660 steps) so the compositor does not repaint at 60/120 Hz for no gain. */
#bg { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
#bg::before, #bg::after {
  content: "";
  position: absolute;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  filter: blur(18px);
}
#bg::before { left: -110px; top: 330px; background: radial-gradient(closest-side, var(--color-glow-a), transparent); animation: bg-drift-a 22s steps(660, end) infinite; }
#bg::after { right: -120px; top: -90px; background: radial-gradient(closest-side, var(--color-glow-b), transparent); animation: bg-drift-b 26s steps(780, end) infinite; }
@keyframes bg-drift-a { 0%, 100% { transform: translate3d(0, 0, 0) scale(1); } 50% { transform: translate3d(14px, -10px, 0) scale(1.05); } }
@keyframes bg-drift-b { 0%, 100% { transform: translate3d(0, 0, 0) scale(1); } 50% { transform: translate3d(-12px, 12px, 0) scale(1.04); } }
body[data-app-visibility="hidden"] #bg::before, body[data-app-visibility="hidden"] #bg::after { animation-play-state: paused; }

/* ---------- App root and screen transitions ---------- */
#app {
  position: absolute;
  inset: 0 0 calc(var(--stage-size) - var(--safe-bottom)) 0; /* ends at y=576 */
  z-index: 1;
  display: flex;
  outline: none;
  --screen-dx: 0px;
  --screen-dy: 0px;
}
/* Directional screen change (UI Toolkit page transition, docs/MOTION.md; app/ui/motion/screen-transition.js). */
#app[data-nav-dir="forward"] { --screen-dx: calc(var(--screen-shift) * -1); }
#app[data-nav-dir="back"] { --screen-dx: var(--screen-shift); }
#app[data-nav-dir="down"] { --screen-dy: calc(var(--screen-shift) * -1); }
#app[data-nav-dir="up"] { --screen-dy: var(--screen-shift); }
#app[data-nav-phase="exit"] { opacity: 0; translate: var(--screen-dx) var(--screen-dy); transition: opacity 100ms cubic-bezier(.33, 0, .67, 1) 33ms, translate 167ms cubic-bezier(.33, 0, .67, 1); }
#app[data-nav-phase="enter"] { animation: screen-enter-move 267ms cubic-bezier(.33, 0, .2, 1) 63ms both, screen-enter-fade 167ms cubic-bezier(.33, 0, .67, 1) 97ms both; }
#app[data-nav-phase="enter"][data-nav-dir="back"] { animation-timing-function: cubic-bezier(.33, 0, .19, 1), cubic-bezier(.33, 0, .67, 1); }
@keyframes screen-enter-move { from { translate: calc(var(--screen-dx) * -1) calc(var(--screen-dy) * -1); } to { translate: 0 0; } }
@keyframes screen-enter-fade { from { opacity: 0; } to { opacity: 1; } }

/* Boot frame: static markup in index.html, painted from the boot stylesheet (scripts/boot-css.mjs)
   before the app loads. The first render replaces it. No motion, so it is safe under reduced motion. */
.boot-shell { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-3); padding: var(--safe-inset); text-align: center; }
.boot-shell-title { font-size: var(--font-size-display); line-height: var(--line-height-tight); color: var(--color-text); }
.boot-shell-sub { font-size: 20px; line-height: var(--line-height-body); color: var(--color-text-quiet); }

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--safe-inset);
  text-align: center;
}

/* ---------- Type ---------- */
.ui-title { font-size: var(--font-size-display); line-height: var(--line-height-tight); letter-spacing: 0; }
h2.ui-title { font-size: var(--font-size-title); }
.eyebrow { font-size: var(--font-size-body); color: var(--color-text-quiet); text-transform: uppercase; letter-spacing: 0.08em; }
.lede { max-width: 440px; font-size: 20px; line-height: var(--line-height-body); color: var(--color-text-muted); }
.footnote { font-size: var(--font-size-caption); color: var(--color-text-quiet); }
.hint { font-size: var(--font-size-body); color: var(--color-text-quiet); }

/* ---------- Buttons ---------- */
.ui-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 64px;
  min-width: 160px;
  padding: var(--space-3) var(--space-5);
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--surface-control-top), var(--surface-control-bottom));
  box-shadow: var(--shadow-raised);
  font-size: var(--font-size-control);
  line-height: var(--line-height-tight);
  cursor: pointer;
  outline: none;
  transition: transform var(--motion-focus-ms) var(--ease-focus), background var(--motion-focus-ms) var(--ease-focus), border-color var(--motion-focus-ms) var(--ease-focus), box-shadow var(--motion-focus-ms) var(--ease-focus);
}
/* Fast focus (toolkit): moves < 140 ms apart shorten the focus change until input slows down. */
#app[data-nav-fast] .ui-button { transition-duration: var(--motion-focus-fast-ms); }
/* Visible press on Select (the Band has no :active): quick press-in, spring release. `scale`
   composes with the focus `transform`, so the focused growth is kept. */
.focusable.nav-press { scale: var(--press-scale); transition: scale var(--motion-press-in-ms) var(--ease-press-in), transform var(--motion-focus-ms) var(--ease-focus); }
.focusable.nav-release { transition: scale var(--motion-release-ms) var(--ease-release), transform var(--motion-focus-ms) var(--ease-focus); }
.ui-button-detail { font-size: var(--font-size-body); color: var(--color-text-quiet); }
.ui-button--primary { background: linear-gradient(180deg, var(--surface-action-top), var(--surface-action-bottom)); }
.ui-button--danger { background: linear-gradient(180deg, var(--surface-danger-top), var(--surface-danger-bottom)); }
.ui-button[aria-disabled="true"] { opacity: 0.55; }

/* Focus: border + ring + scale, so selection never depends on color alone. */
.focusable.nav-on {
  border-color: var(--focus-border);
  background: linear-gradient(180deg, var(--focus-top), var(--focus-bottom));
  box-shadow: 0 0 0 4px var(--focus-ring), var(--shadow-raised);
  transform: scale(var(--focus-scale));
}
.ui-button--primary.nav-on { background: linear-gradient(180deg, var(--surface-action-top), var(--surface-action-bottom)); }
.ui-button--danger.nav-on { background: linear-gradient(180deg, var(--surface-danger-top), var(--surface-danger-bottom)); }
.ui-button .ui-button-detail { pointer-events: none; }

/* ---------- Menus ---------- */
.ui-menu { display: flex; flex-direction: column; gap: var(--space-3); width: 400px; }
.ui-menu .ui-button { width: 100%; min-height: 72px; }
.ui-menu--settings .ui-button { flex-direction: row; justify-content: space-between; min-height: 64px; }
.ui-button--setting .ui-button-detail { font-size: 20px; color: var(--color-text-muted); }
.ui-button--setting.nav-on .ui-button-detail::before { content: "‹  "; }
.ui-button--setting.nav-on .ui-button-detail::after { content: "  ›"; }

.screen-actions { display: flex; flex-direction: column; gap: var(--space-3); }
.screen-actions--row { flex-direction: row; }

/* ---------- Carousel: one card at a time inside a clipped viewport ----------
   Nothing crosses the display edge: the track slides inside .carousel-viewport,
   which sits within the safe inset. Chevrons say more content exists. */
.carousel-frame { display: flex; align-items: center; gap: var(--space-3); }
.carousel-chevron { width: 32px; font-size: var(--font-size-title); color: var(--color-text-quiet); text-align: center; }
.carousel-chevron[data-active="false"] { opacity: 0.2; }
.carousel-viewport { width: 380px; padding: var(--space-3) 0; overflow: hidden; }
.carousel {
  --card-width: 340px;
  --card-gap: 40px;
  --carousel-index: 0;
  display: flex;
  gap: var(--card-gap);
  padding-left: 20px;
  transform: translateX(calc(var(--carousel-index) * -1 * (var(--card-width) + var(--card-gap))));
  transition: transform var(--motion-base) var(--motion-ease-spring);
}
.ui-button--card {
  flex: 0 0 var(--card-width);
  min-height: 220px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--surface-panel-top), var(--surface-panel-bottom));
  font-size: 28px;
}
.ui-button--card .ui-button-detail { max-width: 280px; font-size: 18px; line-height: var(--line-height-body); }
.carousel-counter { font-size: var(--font-size-body); color: var(--color-text-quiet); }

/* ---------- Stars: a filled star shape; lit ones turn bright and pop once ---------- */
.star-row { display: inline-flex; gap: var(--star-gap, 6px); }
.star {
  width: var(--star-size, 22px);
  height: var(--star-size, 22px);
  background: var(--color-star-unlit);
  clip-path: polygon(50% 0%, 61.8% 35.5%, 100% 35.5%, 69.1% 57.4%, 80.9% 92.7%, 50% 70.8%, 19.1% 92.7%, 30.9% 57.4%, 0% 35.5%, 38.2% 35.5%);
}
.star.is-lit { background: var(--color-star); }
.star.is-popping { animation: star-pop var(--motion-slow) var(--motion-ease-spring); }
@keyframes star-pop { 0% { scale: 0.4; } 60% { scale: 1.25; } 100% { scale: 1; } }
:root[data-motion="reduced"] .star.is-popping { animation: none; }
.result-stars { --star-size: 48px; --star-gap: 12px; }
.result-goal { font-size: var(--font-size-body); color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.result-goal.is-top { color: var(--color-star); }
.screen--level-play .ui-menu .ui-button { min-height: 64px; }
/* Title screen: name and one instruction. */
.screen--home { gap: var(--space-5); }
.title-name { font-size: 56px; }
.title-start { font-size: var(--font-size-control); color: var(--color-text-muted); }
.title-version { position: absolute; bottom: var(--space-4); }
.screen--home { position: relative; }

/* ---------- Calibration: a note falls onto a fixed ring, one per bar ----------
   The ring and the notes are positioned in stage pixels by calibration-screen.js
   (ring top = RING_Y, notes translate from y=0). Everything stays inside y=0..575. */
.screen--calibration { position: relative; display: block; padding: 0; }
.calib-header { position: absolute; top: var(--space-5); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.calib-instruction { font-size: 20px; line-height: var(--line-height-body); color: var(--color-text-muted); }
.calib-field { position: absolute; inset: 0; pointer-events: none; }
.calib-ring, .calib-note { position: absolute; left: 50%; border-radius: 50%; }
/* The ring's inside is exactly the note's size (--note-size), so a note on time fills it. */
.screen--calibration { --note-size: 60px; --ring-line: 5px; }
.calib-ring {
  width: calc(var(--note-size) + 2 * var(--ring-line));
  height: calc(var(--note-size) + 2 * var(--ring-line));
  margin: calc(var(--note-size) / -2 - var(--ring-line)) 0 0 calc(var(--note-size) / -2 - var(--ring-line));
  border: var(--ring-line) solid var(--color-ring);
  transition: border-color var(--motion-fast) ease;
}
/* A counted pinch: the ring only changes color (no size change). */
.calib-ring.is-hit { border-color: var(--color-ring-hit); }
.calib-note {
  top: 0;
  width: var(--note-size);
  height: var(--note-size);
  margin: calc(var(--note-size) / -2) 0 0 calc(var(--note-size) / -2);
  background: linear-gradient(180deg, var(--note-top), var(--note-bottom));
  opacity: 0;
  will-change: transform, opacity;
}
.calib-footer { position: absolute; top: 452px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: var(--space-3); }
.calib-progress { display: flex; gap: 10px; }
.calib-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--color-dot-empty); transition: background var(--motion-fast) ease, scale var(--motion-fast) var(--motion-ease-spring); }
.calib-dot.is-filled { background: var(--color-ring); scale: 1.15; }
.calib-status { font-size: 20px; }
.calib-result {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--safe-inset);
  background: var(--color-stage);
}
.calib-result[hidden] { display: none; }
.calib-result-value { font-size: var(--font-size-display); line-height: var(--line-height-tight); font-variant-numeric: tabular-nums; }
.calib-result-detail { font-size: 20px; color: var(--color-text-muted); margin-bottom: var(--space-3); }
.calib-result .screen-actions { width: 300px; }
.screen--calibration[data-state="done"] .calib-header,
.screen--calibration[data-state="done"] .calib-field,
.screen--calibration[data-state="done"] .calib-footer { visibility: hidden; }

/* ---------- Level selector: a vertical map, selected level centered ----------
   Stops sit at --stop-x/--stop-y from the map's center; the track slides one step
   from --slide-from on a move. Nothing crosses the stage edge: the map clips. */
.screen--levels { position: relative; display: block; padding: 0; }
.level-header {
  position: absolute;
  top: var(--space-5);
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}
.level-progress { font-size: var(--font-size-body); color: var(--color-text-quiet); font-variant-numeric: tabular-nums; }
.level-goals { font-size: var(--font-size-body); color: var(--color-star); font-variant-numeric: tabular-nums; }
.level-map {
  position: absolute;
  top: 120px;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  /* Stops fade out at the map's ends instead of being cut. */
  mask-image: linear-gradient(180deg, transparent, var(--color-stage) 40px, var(--color-stage) calc(100% - 40px), transparent);
}
.level-track { position: absolute; inset: 0; }
.level-track.is-sliding { animation: level-slide var(--motion-base) var(--motion-ease-out); }
@keyframes level-slide { from { transform: translateY(var(--slide-from)); } to { transform: none; } }
.level-stop {
  --circle: 76px;
  position: absolute;
  left: calc(50% + var(--stop-x));
  top: calc(50% + var(--stop-y));
  width: 140px;
  margin-left: -70px;
  margin-top: calc(var(--circle) / -2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border: none;
  background: none;
  outline: none;
}
.level-stop.focusable { --circle: 100px; cursor: pointer; }
.level-stop-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--circle);
  height: var(--circle);
  border: 3px solid transparent;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--surface-control-top), var(--surface-control-bottom));
  box-shadow: var(--shadow-raised);
  font-size: var(--font-size-title);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--motion-fast) ease, box-shadow var(--motion-fast) ease;
}
.level-stop.focusable .level-stop-number { font-size: var(--font-size-display); }
.level-stop[data-state="next"] .level-stop-number { background: linear-gradient(180deg, var(--surface-action-top), var(--surface-action-bottom)); }
.level-stop[data-state="locked"] .level-stop-number { background: var(--surface-locked); color: var(--color-text-quiet); box-shadow: none; }
.level-stop-state { font-size: var(--font-size-body); color: var(--color-text-muted); }
.level-stop[data-state="cleared"] .level-stop-state { color: var(--color-good); }
.level-stop[data-state="locked"] .level-stop-state { color: var(--color-text-quiet); }
.level-stop-stars { --star-size: 18px; --star-gap: 4px; }
.level-stop.focusable .level-stop-stars { --star-size: 22px; }
/* Focus lives on the circle: border + ring, so it never depends on color alone. */
.level-stop.nav-on { border: none; background: none; box-shadow: none; transform: none; }
.level-stop.nav-on .level-stop-number { border-color: var(--focus-border); box-shadow: 0 0 0 6px var(--focus-ring), var(--shadow-raised); }
.level-stop.is-unlocked .level-stop-number { animation: level-unlock var(--motion-slow) var(--motion-ease-spring) 200ms both; }
@keyframes level-unlock { 0% { scale: 0.6; } 60% { scale: 1.12; } 100% { scale: 1; } }
.level-path-dot {
  position: absolute;
  left: calc(50% + var(--stop-x));
  top: calc(50% + var(--stop-y));
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: var(--color-accent-soft);
}
.level-path-dot[data-state="locked"] { background: var(--surface-locked); }

/* ---------- Detail ---------- */
.detail-image { width: 96px; height: 96px; border-radius: var(--radius-md); }
.detail-image-fallback { font-size: var(--font-size-caption); color: var(--color-text-quiet); }

/* ---------- Composer field ---------- */
.composer-field {
  width: 440px;
  min-height: 72px;
  padding: 0 var(--space-5);
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--surface-field-top), var(--surface-field-bottom));
  font-size: 24px;
  text-align: center;
  outline: none;
}
.composer-field::placeholder { color: var(--color-text-quiet); }
.composer-result { min-height: 28px; font-size: 20px; color: var(--color-text-muted); }

/* ---------- Animation host (Rive or static fallback) ----------
   The fallback mirrors the standard Rive contract: data-rive-state (idle | attention |
   thinking | success | fail | celebrate), data-rive-pulse (react | nudge-<dir>). */
.animation-host { position: relative; width: 200px; height: 200px; display: grid; place-items: center; }
.animation-state { font-size: 20px; color: var(--color-text-muted); }
.rive-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.rive-host[data-rive="available"] .fallback-glyph { display: none; }
.fallback-glyph { width: 160px; height: 160px; transition: transform var(--motion-base) var(--motion-ease-spring); }
.fallback-glyph-body { fill: var(--surface-panel-bottom); stroke: var(--color-accent); stroke-width: 6; transition: stroke var(--motion-base) ease; }
.fallback-glyph-core { fill: var(--color-accent-soft); transform-origin: 50px 50px; transition: transform var(--motion-base) var(--motion-ease-spring), fill var(--motion-base) ease; }
.rive-host:not([data-rive-state]) .fallback-glyph,
.rive-host[data-rive-state="idle"] .fallback-glyph { animation: glyph-breathe 3.2s steps(96, end) infinite; }
.rive-host[data-rive-state="attention"] .fallback-glyph-core { transform: scale(1.25); }
.rive-host[data-rive-state="attention"] .fallback-glyph { animation: glyph-breathe 1.6s steps(48, end) infinite; }
.rive-host[data-rive-state="thinking"] .fallback-glyph-body { stroke-dasharray: 24 12; }
.rive-host[data-rive-state="thinking"] .fallback-glyph { animation: glyph-spin 2.4s steps(72, end) infinite; }
.rive-host[data-rive-state="success"] .fallback-glyph-body { stroke: var(--color-good); }
.rive-host[data-rive-state="success"] .fallback-glyph-core { fill: var(--color-good); transform: scale(1.15); }
.rive-host[data-rive-state="fail"] .fallback-glyph-body { stroke: var(--color-warn); }
.rive-host[data-rive-state="fail"] .fallback-glyph-core { fill: var(--color-warn); transform: scale(0.8); }
.rive-host[data-rive-state="celebrate"] .fallback-glyph-body { stroke: var(--color-accent-soft); }
.rive-host[data-rive-state="celebrate"] .fallback-glyph { animation: glyph-pulse var(--motion-slow) var(--motion-ease-spring) 2; }
.rive-host[data-rive-visible="false"] .fallback-glyph { transform: scale(0.6); opacity: 0; }
.rive-host[data-rive-pulse="react"] .fallback-glyph-core { animation: glyph-pulse var(--motion-slow) var(--motion-ease-spring); }
.rive-host[data-rive-pulse="nudge-up"] .fallback-glyph { animation: nudge-up 320ms ease-out; }
.rive-host[data-rive-pulse="nudge-down"] .fallback-glyph { animation: nudge-down 320ms ease-out; }
.rive-host[data-rive-pulse="nudge-left"] .fallback-glyph { animation: nudge-left 320ms ease-out; }
.rive-host[data-rive-pulse="nudge-right"] .fallback-glyph { animation: nudge-right 320ms ease-out; }
@keyframes glyph-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
@keyframes glyph-spin { to { transform: rotate(360deg); } }
@keyframes glyph-pulse { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* ---------- Feedback: rubberband + toast ---------- */
/* UI Toolkit discrete rubberband (docs/MOTION.md; app/ui/motion/rubberband.js): one push toward the
   rejected direction and back; Select on a blocked target pulses inward. The nudge-* keyframes below
   stay for the Rive fallback glyph. */
[data-rubberband] { animation: rubberband var(--rubberband-ms); }
[data-rubberband="left"] { --rb-x: calc(var(--rubberband-distance) * -1); --rb-y: 0px; }
[data-rubberband="right"] { --rb-x: var(--rubberband-distance); --rb-y: 0px; }
[data-rubberband="up"] { --rb-x: 0px; --rb-y: calc(var(--rubberband-distance) * -1); }
[data-rubberband="down"] { --rb-x: 0px; --rb-y: var(--rubberband-distance); }
[data-rubberband="pulse"] { animation-name: rubberband-pulse; }
@keyframes rubberband { 0% { translate: 0 0; animation-timing-function: cubic-bezier(.33, 1, .68, 1); } 50% { translate: var(--rb-x, 0px) var(--rb-y, 0px); animation-timing-function: cubic-bezier(.11, 0, .5, 0); } 100% { translate: 0 0; } }
@keyframes rubberband-pulse { 0% { scale: 1; animation-timing-function: cubic-bezier(.33, 1, .68, 1); } 50% { scale: .97; animation-timing-function: cubic-bezier(.11, 0, .5, 0); } 100% { scale: 1; } }
/* Value crossfade (toolkit TextSwitcher; app/ui/motion/text-switch.js). */
[data-text-switch] { transition: opacity 300ms ease-in-out; }
[data-text-switch][data-text-switch-speed="fast"] { transition-duration: 150ms; }
[data-text-switch="out"] { opacity: 0; }
@keyframes nudge-left { 0%, 100% { translate: 0 0; } 24% { translate: calc(var(--motion-nudge-distance) * -1) 0; } 43% { translate: 4px 0; } 62% { translate: -3px 0; } 80% { translate: 1px 0; } }
@keyframes nudge-right { 0%, 100% { translate: 0 0; } 24% { translate: var(--motion-nudge-distance) 0; } 43% { translate: -4px 0; } 62% { translate: 3px 0; } 80% { translate: -1px 0; } }
@keyframes nudge-up { 0%, 100% { translate: 0 0; } 24% { translate: 0 calc(var(--motion-nudge-distance) * -1); } 43% { translate: 0 4px; } 62% { translate: 0 -3px; } 80% { translate: 0 1px; } }
@keyframes nudge-down { 0%, 100% { translate: 0 0; } 24% { translate: 0 var(--motion-nudge-distance); } 43% { translate: 0 -4px; } 62% { translate: 0 3px; } 80% { translate: 0 -1px; } }

.toast {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: calc(var(--stage-size) - var(--safe-bottom) + var(--space-4)); /* stays above y=576 */
  max-width: 480px;
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-pill);
  background: linear-gradient(180deg, var(--surface-panel-top), var(--surface-panel-bottom));
  font-size: 18px;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity var(--motion-base) ease, transform var(--motion-base) var(--motion-ease-out);
  pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast[data-tone="good"] { color: var(--color-good); }
.toast[data-tone="warn"] { color: var(--color-warn); }

/* ---------- Production FPS meter (passive) ---------- */
.performance-overlay {
  position: absolute; z-index: 9; top: var(--space-3); left: 50%; transform: translateX(-50%);
  display: flex; gap: var(--space-2); padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill); background: var(--surface-panel-bottom);
  font-size: var(--font-size-caption); pointer-events: none;
}

/* ---------- Reduced motion ---------- */
:root[data-motion="reduced"] *, :root[data-motion="reduced"] *::before, :root[data-motion="reduced"] *::after {
  animation-duration: 1ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 1ms !important;
}
/* ---------- Pinch Punch: objects fly from the top onto the ring, the boxer punches ----------
   Positions are stage pixels set by punch-screen.js (target ring at 300,352). */
.screen--punch { position: relative; display: block; padding: 0; }
.punch-field { position: absolute; inset: 0; pointer-events: none; }
.punch-floor { position: absolute; left: 0; right: 0; top: 470px; bottom: 24px; border-radius: 40px 40px 0 0; background: linear-gradient(180deg, var(--punch-floor-top), var(--punch-floor-bottom)); }
.punch-ring, .punch-pow { position: absolute; }
.screen--punch { --punch-ring-size: 84px; }
.punch-ring {
  width: var(--punch-ring-size);
  height: var(--punch-ring-size);
  margin: calc(var(--punch-ring-size) / -2) 0 0 calc(var(--punch-ring-size) / -2);
  border: 5px solid var(--color-ring);
  border-radius: 50%;
  transition: border-color var(--motion-fast) ease;
}
.punch-ring.is-hit { border-color: var(--color-ring-hit); }
.punch-object {
  position: absolute;
  left: 0;
  top: 0;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  opacity: 0;
  will-change: transform, opacity;
}
.punch-object[data-kind="ball"] { border-radius: 50%; background: radial-gradient(circle at 35% 30%, var(--punch-pow), var(--punch-ball) 60%); }
.punch-object[data-kind="crate"] { border-radius: 10px; background: linear-gradient(180deg, var(--punch-crate-top), var(--punch-crate-bottom)); box-shadow: inset 0 0 0 6px var(--punch-crate-bottom); }
.punch-object[data-kind="melon"] { border-radius: 50% / 42%; width: 72px; margin-left: -36px; background: repeating-linear-gradient(90deg, var(--punch-melon-top) 0 12px, var(--punch-melon-bottom) 12px 18px); }
.punch-boxer { position: absolute; left: 210px; top: 400px; width: 180px; height: 153px; }
.boxer-body { fill: var(--punch-boxer-body); }
.boxer-head { fill: var(--punch-boxer-head); }
.boxer-visor { fill: var(--punch-boxer-visor); }
.boxer-eye, .boxer-antenna-tip { fill: var(--punch-boxer-eye); }
.boxer-belt, .boxer-antenna { fill: var(--punch-boxer-belt); }
/* Gloves rest at the boxer's sides; a punch drives one into the ring. */
.punch-glove {
  position: absolute;
  top: 470px;
  width: 62px;
  height: 62px;
  margin: -31px 0 0 -31px;
  border-radius: 46% 46% 40% 40%;
  background: linear-gradient(180deg, var(--punch-glove-top), var(--punch-glove-bottom));
  transition: transform 120ms ease-out;
}
.punch-glove--left { left: 222px; }
.punch-glove--right { left: 378px; }
.punch-glove.is-punching { transition-duration: 50ms; }
.punch-glove--left.is-punching { transform: translate(78px, -118px) scale(1.18); }
.punch-glove--right.is-punching { transform: translate(-78px, -118px) scale(1.18); }
.punch-pow {
  margin: -70px 0 0 -60px;
  width: 120px;
  padding: 6px 0;
  border-radius: 20px;
  background: var(--punch-pow);
  color: var(--punch-pow-text);
  font-size: 28px;
  text-align: center;
  opacity: 0;
  scale: 0.7;
  transition: opacity 120ms ease, scale 120ms ease;
}
.punch-pow.is-on { opacity: 1; scale: 1; transition-duration: 40ms; }
.punch-counter { position: absolute; top: var(--space-4); right: var(--space-5); font-size: 20px; font-variant-numeric: tabular-nums; color: var(--color-text-muted); }
.punch-intro {
  position: absolute;
  left: 80px;
  right: 80px;
  top: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5);
  border-radius: 28px;
  background: linear-gradient(180deg, var(--surface-panel-top), var(--surface-panel-bottom));
  text-align: center;
}
.punch-intro-line { font-size: 20px; }
.punch-intro-start { font-size: var(--font-size-control); }
.screen--punch[data-state="running"] .punch-intro,
.screen--punch[data-state="done"] .punch-intro { display: none; }
.screen--punch[data-state="intro"] .punch-counter { visibility: hidden; }

/* Rhythm result (every game): one grade, one score line. */
.screen--result { gap: var(--space-3); }
.rhythm-grade { font-size: 64px; line-height: var(--line-height-tight); }
.rhythm-grade[data-grade="fail"] { color: var(--grade-fail); }
.rhythm-grade[data-grade="pass"] { color: var(--grade-pass); }
.rhythm-grade[data-grade="great"] { color: var(--grade-great); }
.rhythm-grade[data-grade="perfect"], .rhythm-grade[data-grade="cleared"] { color: var(--grade-perfect); }
.rhythm-score { font-size: var(--font-size-control); font-variant-numeric: tabular-nums; margin-bottom: var(--space-3); }
.screen--result .screen-actions { width: 300px; }
.rhythm-drift { margin-top: calc(-1 * var(--space-2)); }

/* ---------- Swipe Steps: arrows rise in four lanes to a row of outlined targets ----------
   Positions are stage pixels set by steps-screen.js (targets at y=108, lanes 174…426). */
.screen--steps { position: relative; display: block; padding: 0; }
.steps-field { position: absolute; inset: 0; pointer-events: none; }
.steps-target, .steps-note {
  position: absolute;
  left: 0;
  top: 0;
  width: 72px;
  height: 72px;
  margin: -36px 0 0 -36px;
  overflow: visible;
}
.steps-target polygon { fill: var(--steps-target-fill); stroke: var(--steps-target-line); stroke-width: 6px; stroke-linejoin: round; transition: fill var(--motion-fast) ease; }
.steps-target.is-press polygon { fill: var(--steps-target-press); }
.steps-note { opacity: 0; will-change: transform, opacity; }
.steps-note polygon { stroke: var(--steps-target-line); stroke-width: 3px; stroke-linejoin: round; }
/* Direction by rotation (the shape points up); color per lane on top. */
[data-lane="left"] polygon { transform: rotate(-90deg); }
[data-lane="down"] polygon { transform: rotate(180deg); }
[data-lane="right"] polygon { transform: rotate(90deg); }
.steps-target polygon, .steps-note polygon { transform-origin: 50px 50px; }
.steps-note[data-lane="left"] polygon, .steps-target.is-hit[data-lane="left"] polygon { fill: var(--steps-lane-left); }
.steps-note[data-lane="down"] polygon, .steps-target.is-hit[data-lane="down"] polygon { fill: var(--steps-lane-down); }
.steps-note[data-lane="up"] polygon, .steps-target.is-hit[data-lane="up"] polygon { fill: var(--steps-lane-up); }
.steps-note[data-lane="right"] polygon, .steps-target.is-hit[data-lane="right"] polygon { fill: var(--steps-lane-right); }
.steps-note.is-missed polygon { fill: var(--steps-missed); }
.steps-call, .steps-combo { position: absolute; left: 0; right: 0; text-align: center; }
.steps-call { top: 168px; font-size: 32px; opacity: 0; transition: opacity 200ms ease; }
.steps-call.is-on { opacity: 1; transition-duration: 40ms; }
.steps-call[data-call="perfect"] { color: var(--steps-perfect); }
.steps-call[data-call="good"] { color: var(--steps-good); }
.steps-call[data-call="miss"] { color: var(--steps-miss); }
.steps-combo { top: 212px; font-size: 20px; color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.steps-counter { position: absolute; top: var(--space-4); right: var(--space-5); font-size: 20px; font-variant-numeric: tabular-nums; color: var(--color-text-muted); }
.steps-intro {
  position: absolute;
  left: 70px;
  right: 70px;
  top: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5);
  border-radius: 28px;
  background: linear-gradient(180deg, var(--surface-panel-top), var(--surface-panel-bottom));
  text-align: center;
}
.steps-intro-line { font-size: 20px; }
.steps-intro-start { font-size: var(--font-size-control); }
.screen--steps[data-state="running"] .steps-intro,
.screen--steps[data-state="done"] .steps-intro { display: none; }
.screen--steps[data-state="intro"] .steps-counter { visibility: hidden; }

/* ---------- Pinch Dash: the world scrolls under a fixed runner ----------
   Positions are stage pixels set by dash-screen.js (ground at y=430, runner at x=150).
   The field fades out at both sides so nothing crosses the display's edge. */
.screen--dash { position: relative; display: block; padding: 0; }
.dash-field {
  position: absolute;
  inset: 0 0 24px 0;
  overflow: hidden;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, var(--color-ring) 48px, var(--color-ring) calc(100% - 64px), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, var(--color-ring) 48px, var(--color-ring) calc(100% - 64px), transparent 100%);
}
.dash-world { position: absolute; left: 0; top: 0; will-change: transform; }
.dash-ground {
  position: absolute;
  height: 122px;
  border-top: 4px solid var(--dash-ground-edge);
  background: repeating-linear-gradient(90deg, var(--dash-ground-top) 0 40px, var(--dash-ground-stripe) 40px 80px);
}
.dash-block {
  position: absolute;
  border-radius: 6px;
  background: linear-gradient(180deg, var(--dash-block-top), var(--dash-block-bottom));
  box-shadow: inset 0 4px 0 var(--dash-block-edge);
}
.dash-spike { position: absolute; width: 40px; height: 40px; background: var(--dash-spike); clip-path: polygon(50% 4%, 92% 100%, 8% 100%); }
.dash-finish { position: absolute; width: 12px; height: 160px; border-radius: 6px; background: var(--dash-finish); }
.dash-runner {
  position: absolute;
  left: 0;
  top: 0;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(180deg, var(--dash-runner-top), var(--dash-runner-bottom));
  will-change: transform;
}
.dash-runner-eye { position: absolute; right: 5px; top: 8px; width: 11px; height: 11px; border-radius: 50%; background: var(--dash-runner-eye); }
.dash-burst { position: absolute; top: 0; width: 0; height: 0; visibility: hidden; }
.dash-shard { position: absolute; left: -6px; top: -6px; width: 12px; height: 12px; border-radius: 3px; background: var(--dash-runner-top); opacity: 0; }
.screen--dash[data-state="crashed"] .dash-runner { visibility: hidden; }
.screen--dash[data-state="crashed"] .dash-burst { visibility: visible; }
.screen--dash[data-state="crashed"] .dash-shard { animation: dash-shard 600ms ease-out forwards; }
.dash-shard:nth-child(1) { --shard-x: -46px; --shard-y: -40px; }
.dash-shard:nth-child(2) { --shard-x: 0px; --shard-y: -58px; }
.dash-shard:nth-child(3) { --shard-x: 46px; --shard-y: -40px; }
.dash-shard:nth-child(4) { --shard-x: -52px; --shard-y: 6px; }
.dash-shard:nth-child(5) { --shard-x: 52px; --shard-y: 6px; }
.dash-shard:nth-child(6) { --shard-x: 10px; --shard-y: 20px; }
@keyframes dash-shard {
  from { opacity: 1; transform: translate(0, 0) scale(1); }
  to { opacity: 0; transform: translate(var(--shard-x), var(--shard-y)) scale(0.5); }
}
.dash-progress { position: absolute; top: 22px; left: 150px; right: 150px; height: 10px; border-radius: 5px; background: var(--dash-progress-track); overflow: hidden; }
.dash-progress-fill { width: 100%; height: 100%; background: var(--dash-progress-fill); transform-origin: 0 50%; transform: scaleX(0); }
.dash-attempt { position: absolute; top: 52px; left: 0; right: 0; text-align: center; font-size: 22px; opacity: 0; transition: opacity 300ms ease; }
.dash-attempt.is-on { opacity: 1; }
.dash-intro {
  position: absolute;
  left: 80px;
  right: 80px;
  top: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5);
  border-radius: 28px;
  background: linear-gradient(180deg, var(--surface-panel-top), var(--surface-panel-bottom));
  text-align: center;
}
.dash-intro-line { font-size: 20px; }
.dash-intro-start { font-size: var(--font-size-control); }
.screen--dash[data-state="running"] .dash-intro,
.screen--dash[data-state="crashed"] .dash-intro,
.screen--dash[data-state="halted"] .dash-intro,
.screen--dash[data-state="done"] .dash-intro { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
