:root,
html[data-theme='light'] {
  color-scheme: light;
  --outside: #eee2d3;
  --bg: #f7efe3;
  --bg2: #f2e7d8;
  --fg: #2f281f;
  --soft: rgba(47, 40, 31, .66);
  --faint: rgba(47, 40, 31, .42);
  --line: rgba(72, 55, 39, .16);
  --panel: rgba(255, 250, 241, .62);
  --panel-2: rgba(88, 65, 45, .08);
  --accent: #7b5838;
  --inverse-bg: #2f281f;
  --inverse-fg: #fff7ea;
  --shadow: 0 28px 90px rgba(74, 51, 31, .16);
  --radius: 34px;
  --app-width: 430px;
  --ease: cubic-bezier(.2,.82,.18,1);
  --spring: cubic-bezier(.18,1.28,.24,1);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme='dark'] {
  color-scheme: dark;
  --outside: #0f0c09;
  --bg: #17130f;
  --bg2: #201a14;
  --fg: #fff1df;
  --soft: rgba(255, 241, 223, .70);
  --faint: rgba(255, 241, 223, .42);
  --line: rgba(255, 235, 208, .14);
  --panel: rgba(255, 241, 223, .055);
  --panel-2: rgba(255, 241, 223, .09);
  --accent: #d1a777;
  --inverse-bg: #fff1df;
  --inverse-fg: #21170f;
  --shadow: 0 28px 90px rgba(0, 0, 0, .42);
}

html[data-theme='auto'] { color-scheme: light dark; }
@media (prefers-color-scheme: dark) {
  html[data-theme='auto'] {
    --outside: #0f0c09;
    --bg: #17130f;
    --bg2: #201a14;
    --fg: #fff1df;
    --soft: rgba(255, 241, 223, .70);
    --faint: rgba(255, 241, 223, .42);
    --line: rgba(255, 235, 208, .14);
    --panel: rgba(255, 241, 223, .055);
    --panel-2: rgba(255, 241, 223, .09);
    --accent: #d1a777;
    --inverse-bg: #fff1df;
    --inverse-fg: #21170f;
    --shadow: 0 28px 90px rgba(0, 0, 0, .42);
  }
}

* { box-sizing: border-box; }
html, body { min-height: 100%; background: var(--outside); }
body {
  margin: 0;
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: .38; cursor: default; }

.noscript {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 40px;
  color: var(--fg);
  background: var(--bg);
  text-align: center;
}

.app-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: var(--outside);
}
.app {
  position: relative;
  width: min(100vw, var(--app-width));
  height: 100dvh;
  max-height: 940px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% -12%, color-mix(in srgb, var(--accent) 13%, transparent), transparent 36%),
    linear-gradient(180deg, var(--bg), var(--bg2));
  box-shadow: var(--shadow);
}
.app::-webkit-scrollbar { display: none; }
.screen {
  position: relative;
  min-height: 100%;
  padding: max(32px, env(safe-area-inset-top)) 32px max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 34px;
  animation: screenIn 520ms var(--ease) both;
}
.center { align-items: center; justify-content: center; text-align: center; }
.detail-screen { gap: 38px; }
.choice-screen { gap: 44px; }
.training-screen { padding: max(22px, env(safe-area-inset-top)) 22px max(24px, env(safe-area-inset-bottom)); gap: 20px; }

h1, h2, h3, p { margin-top: 0; }
h1 {
  margin: 0;
  font-size: clamp(62px, 19vw, 92px);
  line-height: .92;
  font-weight: 720;
  letter-spacing: -.04em;
}
h2 {
  margin: 0;
  font-size: clamp(40px, 12vw, 58px);
  line-height: 1;
  font-weight: 700;
  letter-spacing: -.03em;
}

.home-screen {
  justify-content: space-between;
  gap: 0;
  padding: max(34px, env(safe-area-inset-top)) 32px max(30px, env(safe-area-inset-bottom));
}
.first-start { justify-content: center; align-items: center; }
.home-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
}
.tiny-brand {
  margin: 0;
  color: var(--faint);
  font-size: 12px;
  letter-spacing: .20em;
  text-transform: uppercase;
}
.quiet-pill {
  margin: 0;
  color: var(--soft);
  font-size: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.home-stats {
  flex: 1;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 34px;
  padding: 40px 0 48px;
}
.home-stats span { display: grid; gap: 8px; }
.home-stats b {
  color: var(--fg);
  font-size: clamp(58px, 18vw, 86px);
  line-height: .82;
  font-weight: 710;
  letter-spacing: -.055em;
}
.home-stats em {
  color: var(--faint);
  font-style: normal;
  font-size: 14px;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.home-actions, .dual-actions {
  display: grid;
  grid-template-columns: 1.35fr .95fr;
  gap: 12px;
  width: 100%;
  animation: rise 660ms var(--spring) 90ms both;
}
.dual-actions { grid-template-columns: 1fr 1fr; max-width: 320px; }

.bare-start,
.start-button,
.settings-button,
.primary-action,
.secondary-action {
  border: 0;
  border-radius: 999px;
  min-height: 70px;
  display: grid;
  place-items: center;
  text-align: center;
  font-weight: 650;
  transition: transform 260ms var(--spring), background 260ms var(--ease), color 260ms var(--ease), box-shadow 260ms var(--ease);
}
.bare-start {
  width: min(72vw, 274px);
  min-height: 84px;
  background: var(--inverse-bg);
  color: var(--inverse-fg);
  font-size: 22px;
  box-shadow: 0 26px 80px color-mix(in srgb, var(--inverse-bg) 16%, transparent);
  animation: rise 760ms var(--spring) both;
}
.bare-start.muted { opacity: .76; }
.start-button, .primary-action {
  background: var(--inverse-bg);
  color: var(--inverse-fg);
  font-size: 18px;
  box-shadow: 0 20px 60px color-mix(in srgb, var(--inverse-bg) 12%, transparent);
}
.settings-button, .secondary-action {
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  color: var(--fg);
  border: 1px solid var(--line);
  font-size: 15px;
}
.start-button.compact, .settings-button.compact { min-height: 62px; padding: 0 28px; }
.primary-action.wide, .secondary-action.wide { width: 100%; min-height: 66px; }
.bare-start:active, .start-button:active, .settings-button:active, .primary-action:active, .secondary-action:active { transform: scale(.975); }

.top-bar {
  min-height: 44px;
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  color: var(--faint);
  font-size: 13px;
}
.top-bar a { justify-self: start; color: var(--soft); }
.top-bar span { justify-self: center; color: var(--soft); letter-spacing: .12em; text-transform: uppercase; font-size: 12px; }
.top-bar em { justify-self: end; color: var(--faint); font-style: normal; font-size: 12px; }
.training-top { grid-template-columns: 70px 1fr 70px; }
.micro-label {
  margin: 0;
  color: var(--faint);
  font-size: 12px;
  letter-spacing: .20em;
  text-transform: uppercase;
}
.spaced-words {
  margin: 0;
  color: var(--soft);
  font-size: 16px;
  letter-spacing: .08em;
  line-height: 1.8;
}
.choice-stack { display: grid; gap: 18px; }
.word-choice {
  width: 100%;
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 72%, transparent);
  color: var(--fg);
  font-size: clamp(24px, 7vw, 34px);
  font-weight: 650;
  text-align: left;
  padding: 0 30px;
  transition: transform 260ms var(--spring), background 260ms var(--ease), color 260ms var(--ease), border-color 260ms var(--ease);
  animation: rise 540ms var(--spring) both;
}
.word-choice:nth-child(2) { animation-delay: 30ms; }
.word-choice:nth-child(3) { animation-delay: 60ms; }
.word-choice:nth-child(4) { animation-delay: 90ms; }
.word-choice:nth-child(5) { animation-delay: 120ms; }
.word-choice:active { transform: scale(.985); }
.word-choice.selected { background: var(--inverse-bg); color: var(--inverse-fg); border-color: transparent; }

.thin-progress {
  height: 3px;
  width: 100%;
  background: color-mix(in srgb, var(--fg) 9%, transparent);
  overflow: hidden;
  border-radius: 8px;
}
.thin-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: inherit;
  transition: width 720ms var(--ease);
}
.engine-holder { flex: 1; min-height: 0; display: flex; }
.engine-mount { width: 100%; display: flex; }

.result-screen h1,
.done-screen h1 { font-size: clamp(82px, 27vw, 124px); }
.plan-screen { gap: 24px; }
.large-stat { display: grid; justify-items: start; gap: 8px; }
.large-stat b { font-size: clamp(84px, 28vw, 130px); line-height: .82; font-weight: 700; letter-spacing: -.06em; }
.large-stat span { color: var(--faint); font-size: 13px; letter-spacing: .18em; text-transform: uppercase; }
.large-stat.small b { font-size: clamp(58px, 17vw, 86px); }
.quiet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.quiet-grid span {
  min-height: 118px;
  display: grid;
  align-content: center;
  gap: 10px;
  padding: 20px 12px;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: var(--panel);
}
.quiet-grid b { font-size: 32px; line-height: 1; letter-spacing: -.04em; overflow: hidden; text-overflow: ellipsis; }
.quiet-grid em { color: var(--faint); font-style: normal; font-size: 11px; letter-spacing: .15em; text-transform: uppercase; }
.history {
  height: 130px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 24px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.history span, .history em {
  flex: 1;
  min-height: 10px;
  border-radius: 999px 999px 2px 2px;
  background: var(--accent);
  opacity: .78;
  animation: growBar 860ms var(--ease) both;
}
.history em { opacity: .14; height: 20%; }
.bars { display: grid; gap: 20px; }
.bar-row { display: grid; grid-template-columns: 76px 1fr 34px; align-items: center; gap: 14px; font-size: 13px; color: var(--soft); }
.bar-row i { height: 4px; background: color-mix(in srgb, var(--fg) 10%, transparent); border-radius: 999px; overflow: hidden; }
.bar-row b { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.bar-row strong { justify-self: end; font-size: 12px; color: var(--faint); }

.setting-block { display: grid; gap: 16px; }
.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
}
.theme-switch button {
  min-height: 52px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--soft);
  font-size: 14px;
}
.theme-switch button.selected { background: var(--inverse-bg); color: var(--inverse-fg); }
.minimal-list { display: grid; gap: 14px; }
.minimal-list button, .minimal-list a, .file-row {
  width: 100%;
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
  color: var(--fg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 0 22px;
  text-align: left;
}
.minimal-list span, .file-row span { font-size: 18px; font-weight: 600; }
.minimal-list em, .file-row em { color: var(--faint); font-style: normal; font-size: 12px; letter-spacing: .08em; }
.file-row input { display: none; }
.fineprint { margin-top: auto; color: var(--faint); font-size: 12px; line-height: 1.8; }

.toast-region {
  position: fixed;
  inset: auto 0 max(28px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 100;
}
.toast {
  min-width: 92px;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--inverse-bg);
  color: var(--inverse-fg);
  font-size: 13px;
  font-weight: 650;
  text-align: center;
  animation: toastIn 1.8s var(--ease) both;
}

/* Training engines: large, sparse, phone-native controls. */
.engine-card {
  width: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 10px 0 0;
  animation: screenIn 460ms var(--ease) both;
}
.engine-topline {
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.domain-pill { color: var(--soft); }
.engine-card h2 { text-align: left; max-width: 10ch; }
.engine-instructions {
  color: var(--soft);
  font-size: 15px;
  line-height: 1.75;
  margin: -8px 0 0;
  max-width: 28ch;
}
.engine-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 24px;
  padding-bottom: 8px;
}
.round-meter, .microcopy {
  color: var(--faint);
  font-size: 12px;
  line-height: 1.7;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.microcopy { text-transform: none; letter-spacing: .01em; }
.reaction-pad {
  width: 100%;
  min-height: min(48dvh, 380px);
  border: 1px solid var(--line);
  border-radius: 44px;
  background: var(--panel);
  color: var(--soft);
  font-size: clamp(32px, 10vw, 48px);
  font-weight: 680;
  transition: background 220ms var(--ease), color 220ms var(--ease), transform 220ms var(--spring), border-color 220ms var(--ease);
}
.reaction-pad.go {
  background: var(--inverse-bg);
  color: var(--inverse-fg);
  border-color: transparent;
  animation: signalPulse 900ms var(--ease) infinite alternate;
}
.memory-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-size, 3), 1fr);
  gap: 14px;
}
.memory-cell, .symbol-cell, .trail-node, .premium-choice {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--fg);
  border-radius: 24px;
  transition: background 180ms var(--ease), color 180ms var(--ease), transform 180ms var(--spring), border-color 180ms var(--ease);
}
.memory-cell { aspect-ratio: 1; }
.memory-cell.active, .memory-cell.selected,
.symbol-cell.correct, .trail-node.correct,
.premium-choice.correct { background: var(--inverse-bg); color: var(--inverse-fg); border-color: transparent; transform: scale(.98); }
.symbol-cell.wrong, .trail-node.wrong, .premium-choice.wrong { border-color: var(--accent); opacity: .50; transform: scale(.96); }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.choice-grid.compact { grid-template-columns: repeat(2, minmax(0,1fr)); }
.premium-choice { min-height: 76px; padding: 0 14px; font-weight: 620; font-size: 18px; }
.premium-choice.large-symbol { min-height: 90px; font-size: 34px; }
.stroop-word {
  min-height: 164px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 38px;
  background: var(--panel);
  font-size: clamp(40px, 14vw, 68px);
  font-weight: 720;
  letter-spacing: -.03em;
}
.ink-outline { color: transparent; -webkit-text-stroke: 1px var(--fg); text-stroke: 1px var(--fg); }
.ink-solid { color: var(--fg); }
.ink-underline { text-decoration: underline; text-decoration-thickness: 4px; text-underline-offset: 10px; }
.ink-dashed { border-style: dashed; }
.ink-large { font-size: clamp(54px, 18vw, 88px); }
.visual-field { display: grid; grid-template-columns: repeat(var(--field-cols), 1fr); gap: 9px; }
.symbol-cell { aspect-ratio: 1; font-size: 20px; }
.pattern-strip {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 36px;
  background: var(--panel);
  font-size: 34px;
}
.pattern-strip span { min-width: 30px; text-align: center; }
.missing { color: var(--faint); }
.breath-orb {
  width: min(66vw, 260px);
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin: 0 auto;
  color: var(--soft);
  background: var(--panel);
  animation: breathe 4.8s var(--ease) infinite;
}
.breath-orb.target-window { background: var(--inverse-bg); color: var(--inverse-fg); border-color: transparent; }
.equation-card, .question-card, .story-card, .rotation-reference, .nback-token {
  min-height: 128px;
  display: grid;
  place-items: center;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 36px;
  background: var(--panel);
  text-align: center;
  font-size: clamp(25px, 8vw, 38px);
  font-weight: 640;
  line-height: 1.28;
}
.story-card { font-size: 18px; line-height: 1.75; text-align: left; }
.nback-token { min-height: 174px; font-size: clamp(78px, 28vw, 118px); }
.rotation-reference { font-size: 54px; }
.rotate-symbol span { display: inline-block; font-size: 42px; }
.trail-board {
  position: relative;
  min-height: min(54dvh, 430px);
  border: 1px solid var(--line);
  border-radius: 38px;
  background: var(--panel);
  overflow: hidden;
}
.trail-node {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 56px;
  height: 56px;
  font-weight: 650;
}
.rhythm-row { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; }
.rhythm-row span {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  transition: background 160ms var(--ease), transform 160ms var(--spring);
}
.rhythm-row span.active { background: var(--inverse-bg); transform: scale(.9); }
.target-token { display: grid; place-items: center; font-size: 34px; color: var(--soft); }
.engine-flash {
  position: fixed;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--inverse-bg);
  color: var(--inverse-fg);
  z-index: 60;
  animation: flashOut 620ms var(--ease) both;
}

@keyframes screenIn { from { opacity: 0; transform: translateY(18px) scale(.992); filter: blur(10px); } to { opacity: 1; transform: none; filter: blur(0); } }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toastIn { 0% { opacity: 0; transform: translateY(18px) scale(.96); } 14%,78% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes growBar { from { height: 4%; opacity: .22; } }
@keyframes signalPulse { from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 24%, transparent); } to { box-shadow: 0 0 0 20px transparent; } }
@keyframes breathe { 0%,100% { transform: scale(.84); } 50% { transform: scale(1); } }
@keyframes flashOut { 0% { opacity: 0; transform: translate(-50%, -44%) scale(.96); } 18%,72% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -56%) scale(.98); } }

@media (min-width: 700px) {
  .app { border-radius: 42px; height: min(920px, calc(100dvh - 36px)); }
}

@media (max-width: 360px) {
  .screen { padding-left: 24px; padding-right: 24px; }
  .training-screen { padding-left: 18px; padding-right: 18px; }
  .home-actions { grid-template-columns: 1fr; }
}

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

/* Full 30-training refinements. */
.ghosted { opacity: .24; pointer-events: none; }
.large-token {
  min-height: 156px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 38px;
  background: var(--panel);
  font-size: clamp(64px, 22vw, 106px);
  font-weight: 700;
  letter-spacing: -.04em;
}
.word-rack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.word-rack span {
  min-height: 72px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  font-size: 18px;
  font-weight: 620;
}
.trace-board {
  min-height: min(48dvh, 390px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.trace-node {
  border: 1px solid var(--line);
  border-radius: 30px;
  background: var(--panel);
  color: var(--fg);
  font-size: 28px;
  font-weight: 680;
  transition: background 180ms var(--ease), color 180ms var(--ease), transform 180ms var(--spring), opacity 180ms var(--ease);
}
.trace-node.correct { background: var(--inverse-bg); color: var(--inverse-fg); border-color: transparent; transform: scale(.98); }
.trace-node.wrong { opacity: .46; transform: scale(.96); }
.keyboard-output {
  min-height: 76px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--panel);
  font-size: clamp(26px, 8vw, 38px);
  font-weight: 690;
  letter-spacing: .08em;
}
.virtual-keyboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.key-button {
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  color: var(--fg);
  font-size: 18px;
  font-weight: 680;
  transition: background 160ms var(--ease), color 160ms var(--ease), transform 160ms var(--spring);
}
.key-button:active { transform: scale(.96); }
.wide-key { grid-column: span 2; color: var(--soft); }
.map-card {
  min-height: 180px;
  display: grid;
  place-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 38px;
  background: var(--panel);
}
.map-card span, .map-card em { color: var(--faint); font-style: normal; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; }
.map-card b { font-size: 74px; line-height: .8; }
.breath-orb.mini { width: min(46vw, 178px); }
.nback-token.dual { letter-spacing: .02em; }
.hazard-field .symbol-cell { font-size: 18px; }
.reset-screen h1 { font-size: clamp(70px, 22vw, 108px); }
