/* ============ NeuroPlay design tokens ============ */
:root {
  --bg: #0f1226;
  --bg-soft: #181c38;
  --surface: #1f2447;
  --surface-raised: #272d59;
  --text: #eef0ff;
  --text-dim: #9aa0c7;
  --accent-memory: #7c6cff;
  --accent-math: #2dd4a7;
  --accent-stroop: #ff7a59;
  --accent-digits: #4cc3ff;
  --accent-reaction: #ffe066;
  --accent-simon: #ff5c7a;
  --accent-odd: #64dfdf;
  --accent-flanker: #f28c4c;
  --accent-nback: #b388ff;
  --accent-logic: #80ed99;
  --gold: #ffd166;
  --danger: #ff5c7a;
  --radius-lg: 22px;
  --radius-md: 14px;
  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(124, 108, 255, 0.18), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(45, 212, 167, 0.12), transparent 60%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  /* iOS: no rubber-band scroll chaining, no callout/selection on game taps */
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  /* disables the double-tap-to-zoom gesture site-wide, not just on buttons */
  touch-action: manipulation;
}

input { -webkit-user-select: text; user-select: text; }

button { touch-action: manipulation; }

#app {
  max-width: 860px;
  margin: 0 auto;
  /* safe-area insets keep content clear of the notch and home indicator */
  padding: calc(24px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right))
           calc(60px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
}

.screen { display: none; animation: fadeIn 0.35s ease; }
.screen.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ============ Home / hero ============ */
.hero { text-align: center; padding: 28px 0 8px; }

.hero-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2.5px;
  color: var(--gold);
  border: 1px solid rgba(255, 209, 102, 0.4);
  border-radius: 999px;
  padding: 6px 14px;
  margin-bottom: 18px;
}

.hero-title {
  font-size: clamp(2.6rem, 8vw, 4.2rem);
  font-weight: 800;
  letter-spacing: -1.5px;
  line-height: 1;
}

.hero-title span {
  background: linear-gradient(90deg, var(--accent-memory), var(--accent-digits));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-sub {
  color: var(--text-dim);
  margin-top: 12px;
  font-size: 1.05rem;
}

.brain-score-card {
  margin: 26px auto 8px;
  max-width: 300px;
  background: linear-gradient(160deg, var(--surface-raised), var(--surface));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  padding: 18px 24px;
  box-shadow: var(--shadow-card);
}

.bs-label { font-size: 11px; letter-spacing: 2.5px; color: var(--text-dim); font-weight: 700; }
.bs-value { font-size: 3rem; font-weight: 800; color: var(--gold); line-height: 1.15; }
.bs-streak { font-size: 0.9rem; color: var(--text-dim); }

.save-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 0 auto 8px;
}
.save-actions .btn-ghost { font-size: 0.85rem; }

/* ============ Game cards ============ */
.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-top: 34px;
}

@media (max-width: 620px) {
  .game-grid { grid-template-columns: 1fr; }
}

.game-card {
  text-align: left;
  font-family: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius-lg);
  padding: 22px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  position: relative;
  overflow: hidden;
}

.game-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--card-accent, var(--accent-memory));
}

/* Category tabs */
.category-tabs {
  display: flex;
  gap: 8px;
  margin-top: 30px;
  overflow-x: auto;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar { display: none; }

.cat-tab {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.cat-tab.active {
  color: var(--text);
  border-color: var(--tab-accent, var(--gold));
  box-shadow: inset 0 -3px 0 var(--tab-accent, var(--gold));
}

.game-card:hover, .game-card:focus-visible {
  transform: translateY(-4px);
  box-shadow: var(--shadow-card);
  border-color: rgba(255, 255, 255, 0.18);
  outline: none;
}

.game-card:active { transform: translateY(-1px); }

.gc-icon { font-size: 2rem; margin-bottom: 10px; }
.gc-name { font-size: 1.25rem; font-weight: 700; margin-bottom: 6px; }
.gc-desc { color: var(--text-dim); font-size: 0.92rem; line-height: 1.45; min-height: 2.7em; }
.gc-skill { margin-top: 12px; font-size: 10px; font-weight: 700; letter-spacing: 1.8px; color: var(--text-dim); }

.game-card .gc-skill { color: var(--card-accent, var(--accent-memory)); }

.gc-best { margin-top: 6px; font-size: 0.85rem; color: var(--gold); font-weight: 600; }

/* ============ Game screen ============ */
.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 20px;
}

.topbar-stats { display: flex; gap: 20px; }

.stat { display: flex; flex-direction: column; align-items: center; min-width: 60px; }
.stat-label { font-size: 10px; letter-spacing: 1.8px; color: var(--text-dim); font-weight: 700; }
.stat-value { font-size: 1.2rem; font-weight: 700; }

#game-stage {
  background: var(--bg-soft);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-lg);
  min-height: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
  gap: 18px;
}

.stage-message { font-size: 1.3rem; font-weight: 700; text-align: center; }
.stage-submessage { color: var(--text-dim); text-align: center; margin-top: -8px; }

/* Memory grid — fluid tiles so 6×6 still fits a 375px phone screen */
.mem-grid { display: grid; gap: 10px; width: 100%; }

.mem-tile {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.mem-tile:hover { transform: scale(1.05); }
.mem-tile:active { transform: scale(0.94); }
.mem-tile.lit { background: var(--accent-memory); box-shadow: 0 0 18px rgba(124, 108, 255, 0.6); }
.mem-tile.correct { background: var(--accent-math); }
.mem-tile.wrong { background: var(--danger); }
.mem-tile.locked { pointer-events: none; }


/* Math sprint */
.math-problem { font-size: clamp(2.2rem, 9vw, 3.4rem); font-weight: 800; letter-spacing: 1px; }

.answer-row { display: flex; gap: 10px; }

.answer-btn {
  font-family: inherit;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: 14px 26px;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.12s ease;
}

.answer-btn:hover { transform: translateY(-3px); background: #323870; }
.answer-btn:active { transform: scale(0.96); background: #323870; }
.answer-btn.correct { background: var(--accent-math); color: #06281e; }
.answer-btn.wrong { background: var(--danger); }

.timer-bar-wrap {
  width: 100%;
  max-width: 420px;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.timer-bar { height: 100%; background: var(--accent-math); border-radius: 999px; transition: width 0.2s linear; }
.timer-bar.low { background: var(--danger); }

/* Stroop */
.stroop-word { font-size: clamp(2.6rem, 11vw, 4rem); font-weight: 800; letter-spacing: 2px; }

.stroop-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

.stroop-btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 16px 22px;
  cursor: pointer;
  min-width: 96px;
  transition: transform 0.1s ease, filter 0.1s ease;
}

.stroop-btn:hover { transform: translateY(-3px); filter: brightness(1.15); }
.stroop-btn:active { transform: scale(0.96); filter: brightness(1.2); }

/* Quick Tap (reaction) */
.reaction-pad {
  width: min(320px, 80vw);
  height: 220px;
  border: none;
  border-radius: var(--radius-lg);
  font-family: inherit;
  font-size: 1.8rem;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
  transition: background 0.1s ease;
}

.reaction-pad.wait { background: var(--danger); }
.reaction-pad.go { background: var(--accent-math); color: #06281e; }
.reaction-pad.early { background: #6b7280; }

/* Simon Echo */
.simon-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: min(300px, 80vw);
}

.simon-tile {
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.simon-tile.lit { opacity: 1; transform: scale(1.04); box-shadow: 0 0 22px rgba(255, 255, 255, 0.35); }
.simon-tile:active { transform: scale(0.95); }
.simon-grid.locked .simon-tile { pointer-events: none; }

/* Odd One Out */
.odd-grid { display: grid; gap: 10px; width: 100%; }

.odd-tile {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.odd-tile:active { transform: scale(0.94); }

/* Arrow Focus (flanker) */
.flanker-display {
  font-size: clamp(2.4rem, 11vw, 4rem);
  font-weight: 800;
  letter-spacing: 6px;
}

/* Flash Back (n-back) */
.nback-symbol { font-size: clamp(3.4rem, 16vw, 5.5rem); min-height: 1.2em; }

/* Pattern Quest */
.seq-text {
  font-size: clamp(1.5rem, 6.5vw, 2.4rem);
  font-weight: 800;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* Canvas games (arcade / reflex) */
.game-canvas {
  width: 100%;
  max-width: 360px;
  border-radius: var(--radius-md);
  touch-action: none;
  background: var(--bg-soft);
}

/* 2048 */
.cell-2048 {
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 800;
  color: #fff;
}

/* Pair Up */
.pair-card {
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: var(--radius-md);
  background: #3a4180;
  font-size: 1.7rem;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.pair-card.open { background: var(--surface-raised); }
.pair-card.matched { opacity: 0.45; pointer-events: none; }
.pair-card:active { transform: scale(0.94); }

/* Slide / Schulte / Sudoku tiles */
.slide-tile {
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 1.4rem;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
}

.slide-tile:active { transform: scale(0.95); }

/* Minesweeper */
.mine-cell {
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  color: #eef0ff;
  cursor: pointer;
}

/* Color Sort tubes / pegs */
.tube-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

.tube {
  width: 46px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: transparent;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top: none;
  border-radius: 0 0 14px 14px;
  cursor: pointer;
}

.tube.selected { border-color: var(--gold); }

.tube-seg { width: 100%; height: 30px; border-radius: 4px; }

.peg {
  width: 96px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
  justify-content: flex-end;
  background: transparent;
  border: none;
  border-bottom: 4px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  padding-bottom: 2px;
}

.peg.selected { border-bottom-color: var(--gold); }

.disk { height: 16px; border-radius: 6px; }

/* Nonogram */
.nono-wrap { overflow-x: auto; max-width: 100%; }

.nono-grid { display: grid; gap: 4px; }

.nono-clue {
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
}

.nono-cell {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

/* Keyboards (Wordle / Hangman / Scramble) */
.kb-wrap { display: flex; flex-direction: column; gap: 6px; align-items: center; }

.kb-row { display: flex; gap: 5px; justify-content: center; flex-wrap: wrap; }

.kb-key {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-raised);
  border: none;
  border-radius: 8px;
  min-width: 30px;
  padding: 10px 6px;
  cursor: pointer;
}

.kb-key.big { min-width: 44px; font-size: 1.2rem; padding: 12px 8px; }
.kb-key.hit { background: var(--accent-math); color: #06281e; }
.kb-key.absent { background: #1a1e3d; color: #8b91c4; }
.kb-key:disabled { opacity: 0.55; }

/* Wordle grid */
.wordle-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  width: min(300px, 85vw);
}

.wordle-cell {
  aspect-ratio: 1 / 1;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 800;
}

.wordle-cell.hit { background: var(--accent-math); border-color: var(--accent-math); color: #06281e; }
.wordle-cell.near { background: var(--gold); border-color: var(--gold); color: #4a3800; }
.wordle-cell.absent { background: #1a1e3d; border-color: #1a1e3d; color: #8b91c4; }

/* Reflex fields (aim / balloons) */
.reflex-field {
  position: relative;
  width: 100%;
  max-width: 380px;
  height: 340px;
  background: var(--bg-soft);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.aim-target {
  position: absolute;
  font-size: 2.6rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.balloon {
  position: absolute;
  font-size: 2.2rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
}

/* Shell game */
.shell-row { position: relative; width: 270px; height: 90px; }

.shell-cup {
  position: absolute;
  top: 0;
  width: 80px;
  height: 80px;
  font-size: 2.6rem;
  background: none;
  border: none;
  cursor: pointer;
  transition: left 0.28s ease;
}

/* Rhythm */
.pulse-pad {
  width: 170px;
  height: 170px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.2);
  background: var(--surface-raised);
  font-size: 3.4rem;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease;
}

.pulse-pad.beat { transform: scale(1.12); border-color: var(--accent-math); }

/* Whack-a-mole */
.mole-hole {
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 50%;
  background: #12152c;
  font-size: 2.1rem;
  cursor: pointer;
}

/* Letter tiles (Letter Spy / Word Hunt) */
.letter-tile {
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 8px;
  background: #3a4180;
  color: var(--text);
  font-family: inherit;
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
}

/* Number recall */
.digits-display {
  font-size: clamp(2.4rem, 10vw, 3.6rem);
  font-weight: 800;
  letter-spacing: 8px;
  font-variant-numeric: tabular-nums;
  min-height: 1.3em;
}

.digits-input {
  font-family: inherit;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 6px;
  text-align: center;
  color: var(--text);
  background: var(--surface-raised);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  width: min(340px, 90%);
  outline: none;
}

.digits-input:focus { border-color: var(--accent-digits); }

/* ============ Buttons ============ */
.btn-primary {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f1226;
  background: linear-gradient(90deg, var(--gold), #ffb84d);
  border: none;
  border-radius: 999px;
  padding: 14px 34px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 6px 18px rgba(255, 209, 102, 0.25);
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(255, 209, 102, 0.35); }

.btn-ghost {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  padding: 10px 20px;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}

.btn-ghost:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.35); }

/* ============ Results ============ */
.results-card {
  max-width: 460px;
  margin: 8vh auto 0;
  text-align: center;
  background: linear-gradient(160deg, var(--surface-raised), var(--surface));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  padding: 40px 30px;
  box-shadow: var(--shadow-card);
}

.results-emoji { font-size: 3.4rem; }

.results-card h2 { font-size: 1.8rem; margin: 10px 0 22px; }

.rs-label { font-size: 11px; letter-spacing: 2.5px; color: var(--text-dim); font-weight: 700; }
.rs-value { font-size: 3.4rem; font-weight: 800; color: var(--gold); line-height: 1.15; }
.rs-record { font-size: 0.95rem; color: var(--accent-math); font-weight: 700; min-height: 1.4em; }

.results-tip { color: var(--text-dim); font-size: 0.95rem; line-height: 1.55; margin: 18px 0 26px; }

.results-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* Feedback flash */
.flash-good { animation: flashGood 0.35s ease; }
.flash-bad { animation: flashBad 0.35s ease; }

@keyframes flashGood {
  0% { box-shadow: inset 0 0 0 3px var(--accent-math); }
  100% { box-shadow: inset 0 0 0 0 transparent; }
}

@keyframes flashBad {
  0% { box-shadow: inset 0 0 0 3px var(--danger); }
  100% { box-shadow: inset 0 0 0 0 transparent; }
}

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