:root {
  --bg: #EBF3F7;
  --surface: #ffffff;
  --surface2: #d8eaf2;
  --border: #b8d4e0;
  --text: #2b3a4a;
  --muted: #5a7a8a;
  --hint: #ccdde6;
  --accent: #3d7a9a;
  --accent-dim: rgba(61, 122, 154, 0.10);
  --accent-text: #2b5f7a;
  --danger: #c0404a;
  --success: #2e7d5e;
  --radius: 10px;
  --radius-lg: 16px;
  --mono: 'DM Mono', monospace;
  --sans: 'Neuton', serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* NAV */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.nav-logo {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.nav-right { font-size: 12px; color: var(--muted); font-family: var(--mono); }

/* HOME */
.home { flex: 1; padding: 2.5rem 1.5rem; max-width: 640px; margin: 0 auto; width: 100%; }
.home-eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 1rem;
}
.home-title {
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  font-weight: 300;
  line-height: 1.05;
  letter-spacing: -0.01em;
  margin-bottom: 1rem;
  color: var(--text);
}
.home-title strong { font-weight: 700; }
.home-desc { font-size: 18px; color: var(--muted); line-height: 1.7; margin-bottom: 2.5rem; }

.game-cards { display: flex; flex-direction: column; gap: 12px; }
.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  text-align: left;
  width: 100%;
}
.game-card:hover { border-color: var(--accent); background: var(--surface2); }
.game-card-left { flex: 1; }
.game-card-tag {
  font-family: var(--mono);
  font-size: 12px;
  color: #005b96;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.game-card-title { font-size: 19px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.game-card-desc { font-size: 14px; color: var(--muted); line-height: 1.5; }
.game-card-arrow { color: var(--accent); font-size: 20px; flex-shrink: 0; }

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 2.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.strip-stat { }
.strip-label { font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 4px; }
.strip-val { font-family: var(--mono); font-size: 22px; font-weight: 500; color: var(--text); }
.strip-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* GAME SHELL */
.game-shell { flex: 1; display: flex; flex-direction: column; max-width: 640px; margin: 0 auto; width: 100%; padding: 1.5rem; }
.game-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 2rem; }
.back-btn {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: var(--radius); padding: 6px 12px; font-size: 13px;
  cursor: pointer; transition: border-color 0.15s, color 0.15s; font-family: var(--sans);
}
.back-btn:hover { border-color: var(--text); color: var(--text); }
.game-title-bar { flex: 1; }
.game-name { font-size: 14px; font-weight: 500; }
.game-sub { font-size: 12px; color: var(--muted); font-family: var(--mono); }

/* SETUP */
.setup { max-width: 480px; }
.setup-section { margin-bottom: 1.5rem; }
.setup-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.opt-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.opt-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--sans);
}
.opt-btn:hover { border-color: var(--hint); color: var(--text); }
.opt-btn.sel { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); }

.start-btn {
  margin-top: 2rem;
  padding: 14px 32px;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  font-family: var(--sans);
  letter-spacing: -0.01em;
}
.start-btn:hover { opacity: 0.88; }

/* HUD */
.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 1.5rem;
}
.hud-cell { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.hud-label { font-family: var(--mono); font-size: 9px; color: var(--muted); letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 4px; }
.hud-val { font-family: var(--mono); font-size: 22px; font-weight: 500; color: var(--text); }

.progress-wrap { height: 3px; background: var(--border); border-radius: 2px; margin-bottom: 2rem; }
.progress-fill { height: 3px; background: var(--accent); border-radius: 2px; transition: width 0.1s linear; }

/* STIMULUS */
.stimulus-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  margin-bottom: 1.5rem;
}
.stimulus-word {
  font-size: clamp(48px, 12vw, 80px);
  font-weight: 500;
  letter-spacing: -0.03em;
  transition: opacity 0.08s;
}
.stimulus-letter {
  font-family: var(--mono);
  font-size: clamp(60px, 15vw, 100px);
  font-weight: 400;
  color: var(--accent);
}
.stimulus-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 280px;
}
.nback-cell {
  aspect-ratio: 1;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: background 0.1s, border-color 0.1s;
}
.nback-cell.active { background: var(--accent); border-color: var(--accent); }

.switch-number {
  font-family: var(--mono);
  font-size: clamp(64px, 16vw, 108px);
  font-weight: 400;
  color: var(--text);
}
.switch-rule {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  text-align: center;
  margin-bottom: 0.5rem;
  letter-spacing: 0.05em;
}

/* ANSWER BUTTONS */
.answer-btns { display: grid; gap: 8px; }
.answer-btns.cols-2 { grid-template-columns: 1fr 1fr; }
.answer-btns.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.answer-btns.cols-4 { grid-template-columns: 1fr 1fr; }
.ans-btn {
  padding: 16px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.08s, background 0.1s, border-color 0.1s;
  font-family: var(--sans);
  letter-spacing: -0.01em;
}
.ans-btn:active { transform: scale(0.97); }
.ans-btn.flash-ok { background: rgba(77, 204, 136, 0.2); border-color: var(--success); }
.ans-btn.flash-bad { background: rgba(255, 92, 92, 0.2); border-color: var(--danger); }

.nback-btns { display: flex; gap: 10px; }
.nback-btn {
  flex: 1;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.1s;
  font-family: var(--sans);
}
.nback-btn:hover { border-color: var(--hint); }
.nback-btn.match-btn { border-color: var(--accent); color: var(--accent); }
.nback-btn.flash-ok { background: rgba(77, 204, 136, 0.2); border-color: var(--success); }
.nback-btn.flash-bad { background: rgba(255, 92, 92, 0.2); border-color: var(--danger); }

.hint-text { font-size: 12px; color: var(--muted); text-align: center; margin-top: 1rem; font-family: var(--mono); }

/* RESULTS */
.results { }
.results-heading { font-size: 11px; font-family: var(--mono); color: var(--muted); letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 1rem; }
.results-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 2rem; }
.res-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.res-label { font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 6px; }
.res-val { font-family: var(--mono); font-size: 26px; font-weight: 500; color: var(--text); }
.res-unit { font-size: 12px; color: var(--muted); margin-top: 2px; }

.history-label { font-size: 11px; font-family: var(--mono); color: var(--muted); letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 8px; }
.history-list { margin-bottom: 1.5rem; }
.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-family: var(--mono);
}
.history-row:last-child { border-bottom: none; }
.h-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; margin-right: 8px; flex-shrink: 0; }
.h-dot.ok { background: var(--success); }
.h-dot.bad { background: var(--danger); }
.h-rt { color: var(--muted); font-size: 12px; }

.again-btn {
  width: 100%;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-family: var(--sans);
}
.again-btn:hover { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

@media (max-width: 480px) {
  .nav { padding: 0.875rem 1rem; }
  .home { padding: 1.5rem 1rem; }
  .game-shell { padding: 1rem; }
}

.opt-btn.locked {
  opacity: 0.4;
  cursor: not-allowed;
}
