/* 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; }

/* ---------- Areas: each has a color and an icon, never color alone ---------- */
[data-area] { --area: var(--color-accent-soft); }
[data-area="memory"] { --area: var(--area-memory); }
[data-area="math"] { --area: var(--area-math); }
[data-area="patterns"] { --area: var(--area-patterns); }
[data-area="focus"] { --area: var(--area-focus); }
[data-area="multitask"] { --area: var(--area-multitask); }
.area-chip {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--surface-tile);
  color: var(--area);
}
.area-chip svg { width: 24px; height: 24px; fill: currentColor; }
.area-chip--large { width: 72px; height: 72px; border-radius: var(--radius-md); }
.area-chip--large svg { width: 40px; height: 40px; }
.chevron, .mark, .arrow, .wide-arrow, .cell-figure { display: block; fill: currentColor; }

/* ---------- Home, games, progress, result ---------- */
.workout-icons { display: flex; gap: var(--space-3); margin-top: var(--space-2); }
.screen--home .ui-button--primary { min-height: 80px; }
.area-pager { display: flex; align-items: center; gap: var(--space-5); color: var(--color-text-quiet); }
.area-pager .chevron { width: 28px; height: 28px; }
.pager-dots { display: flex; gap: var(--space-2); }
.pager-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-locked); }
.pager-dot[data-active="true"] { width: 28px; border-radius: var(--radius-pill); background: var(--area); }
.progress-list { width: 480px; }
.progress-list .ui-button { display: grid; grid-template-columns: 44px 128px 1fr 48px; align-items: center; gap: var(--space-3); min-height: 68px; padding: var(--space-2) var(--space-4); text-align: left; }
.area-bar { height: 18px; border-radius: var(--radius-pill); background: var(--surface-locked); overflow: hidden; }
.area-bar-fill { display: block; height: 100%; border-radius: inherit; background: var(--area); transform: scaleX(var(--value)); transform-origin: left; }
.area-value { text-align: right; font-variant-numeric: tabular-nums; }
.result-score { font-size: 112px; line-height: 1; color: var(--area); font-variant-numeric: tabular-nums; }
.result-best { color: var(--color-star); }
.screen--result .ui-button, .screen--intro .ui-button { min-width: 260px; }

/* ---------- Play: a prompt in the middle, one tile per swipe around it ---------- */
.screen--play { gap: var(--space-4); padding: var(--space-5) var(--safe-inset); }
.play-header { display: flex; align-items: center; justify-content: center; gap: var(--space-4); }
.play-level { width: 76px; font-size: 18px; color: var(--color-text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.time-bar { width: 220px; height: 18px; margin-right: 92px; border-radius: var(--radius-pill); background: var(--surface-locked); overflow: hidden; }
.time-bar-fill { width: 100%; height: 100%; background: var(--area); transform: scaleX(var(--left, 1)); transform-origin: left; }
.board {
  --side: 144px;
  --edge: 108px;
  flex: 1;
  width: 100%;
  display: grid;
  grid-template-columns: var(--side) 1fr var(--side);
  grid-template-rows: var(--edge) 1fr var(--edge);
  grid-template-areas: ". up ." "left prompt right" ". down .";
  gap: var(--space-3);
  place-items: center;
}
.board[data-layout="compact"] { --side: 64px; --edge: 64px; }
.tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  height: 100%;
  border: 3px solid transparent;
  border-radius: var(--radius-md);
  background: var(--surface-tile);
  font-size: 34px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.tile[hidden] { display: none; }
.tile[data-side="up"] { grid-area: up; flex-direction: column; }
.tile[data-side="down"] { grid-area: down; flex-direction: column-reverse; }
.tile[data-side="left"] { grid-area: left; max-height: 144px; }
.tile[data-side="right"] { grid-area: right; max-height: 144px; flex-direction: row-reverse; }
.tile .chevron { flex: none; width: 22px; height: 22px; color: var(--color-text-quiet); }
.tile-content:empty { display: none; }
.cell-figure { width: 66px; height: 66px; color: var(--area); }
.tile[data-lit="true"], .board-prompt[data-lit="true"] { background: var(--area); border-color: var(--color-text); }
.tile[data-lit="true"] .chevron { color: var(--color-stage); }
.tile[data-mark="picked"], .board-prompt[data-mark="picked"] { border-color: var(--area); }
.tile[data-mark="right"], .board-prompt[data-mark="right"] { border-color: var(--color-good); background: var(--surface-right); }
.tile[data-mark="wrong"], .board-prompt[data-mark="wrong"] { border-color: var(--color-bad); background: var(--surface-wrong); }
.mark { width: 28px; height: 28px; }
.tile .mark, .board-prompt .mark { position: absolute; top: var(--space-2); right: var(--space-2); }
.tile[data-mark="right"] .mark, .board-prompt[data-mark="right"] .mark { color: var(--color-good); }
.tile[data-mark="wrong"] .mark, .board-prompt[data-mark="wrong"] .mark { color: var(--color-bad); }
/* Compact tiles have no room for both: the mark takes the chevron's place. */
.board[data-layout="compact"] .tile[data-mark] .chevron { display: none; }
.board[data-layout="compact"] .tile .mark { position: static; }

.board-prompt, .board-prompt.nav-on {
  position: relative;
  grid-area: prompt;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  width: 100%;
  height: 100%;
  border: 3px solid transparent;
  border-radius: var(--radius-md);
  background: none;
  box-shadow: none;
  outline: none;
  transform: none;
}
.board-prompt[data-tile="true"] { background: var(--surface-tile); font-size: 40px; }
.board-prompt[data-hidden="true"] > * { visibility: hidden; }
.prompt-text { font-size: 48px; line-height: var(--line-height-tight); white-space: nowrap; font-variant-numeric: tabular-nums; }
.prompt-small { max-width: 200px; font-size: 28px; line-height: var(--line-height-tight); }
.prompt-label { font-size: 22px; color: var(--color-text-muted); }
.board[data-paused="true"] .tile { visibility: hidden; }
.series { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2) var(--space-4); max-width: 200px; font-size: 44px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.series :last-child { color: var(--area); }
.arrows { display: flex; gap: var(--space-2); }
.arrows .arrow { width: 60px; height: 60px; }
.arrows[data-formation="column"] { flex-direction: column; gap: var(--space-1); }
.arrows[data-formation="column"] .arrow { width: 52px; height: 52px; }
.arrows[data-formation="wave"] .arrow:nth-child(even) { translate: 0 48px; }
.word-arrow { position: relative; display: grid; place-items: center; width: 250px; height: 250px; }
.wide-arrow { position: absolute; inset: 0; color: var(--surface-figure); }
.word-arrow-word { position: relative; font-size: 44px; }
.slot { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-1); width: 100%; flex: 1; border-radius: var(--radius-md); background: var(--surface-locked); }
.slot[data-active="true"] { background: var(--surface-figure); }
.slot-text { font-size: 52px; line-height: 1; }
.board-prompt[data-kind="slots"] { grid-row: 1 / -1; }

/* Sort and Spot */
.shape-figure { display: block; width: 150px; height: 150px; fill: none; stroke: var(--area); stroke-width: 2.6; stroke-linejoin: round; }
.shape-figure[data-full="true"] { fill: var(--area); }
.target-row { display: flex; gap: var(--space-3); }
.target-row .shape-figure { width: 88px; height: 88px; }

/* ---------- 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;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
