:root {
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-hover: #25253d;
  --text: #e8e8f0;
  --text-dim: #8888aa;
  --accent: #6c63ff;
  --accent-glow: #7c73ff;
  --success: #4ade80;
  --error: #f87171;
  --warning: #fbbf24;
  --radius: 12px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  padding: 20px;
  display: flex;
  flex-direction: column;
}

/* Screens */
[data-screen] {
  display: none;
  flex-direction: column;
  flex: 1;
}

[data-screen].active {
  display: flex;
}

/* Landing Screen */
.landing-header {
  text-align: center;
  margin-top: 60px;
}

.landing-header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.landing-header .brain-emoji {
  font-size: 3rem;
  display: block;
  margin-bottom: 12px;
}

.landing-header .subtitle {
  color: var(--text-dim);
  font-size: 1rem;
  margin-bottom: 8px;
}

.landing-header .day-label {
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
}

.landing-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 24px;
}

.how-it-works {
  width: 100%;
  padding: 20px;
  background: var(--bg-card);
  border-radius: var(--radius);
}

.how-it-works h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.how-it-works ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.how-it-works li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
}

.how-it-works .icon {
  font-size: 1.2rem;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: white;
  width: 100%;
}

.btn-primary:hover {
  background: var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 2px solid var(--accent);
}

/* Game Screen */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.game-header h2 {
  font-size: 1.1rem;
}

#game-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Instruction overlay */
.instruction-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 26, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.instruction-overlay[hidden] {
  display: none;
}

.instruction-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  max-width: 360px;
  width: 100%;
}

.instruction-card .counter {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.instruction-card h2 {
  font-size: 1.5rem;
  margin-bottom: 16px;
}

.instruction-card p {
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 24px;
}

/* Game: Speed Math */
.game-speed-math {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.game-progress {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.timer-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  overflow: hidden;
}

.timer-fill {
  width: 100%;
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}

.math-question {
  font-size: 2rem;
  font-weight: 700;
  padding: 20px 0;
}

.math-question.correct {
  color: var(--success);
}

.math-question.incorrect {
  color: var(--error);
}

.math-input {
  width: 160px;
  padding: 12px 16px;
  font-size: 1.5rem;
  text-align: center;
  background: var(--bg-card);
  color: var(--text);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  outline: none;
  -moz-appearance: textfield;
}

.math-input::-webkit-outer-spin-button,
.math-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Game: Memory Grid */
.memory-grid-game {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.memory-grid {
  display: grid;
  gap: 6px;
  justify-content: center;
}

.memory-cell {
  width: 56px;
  height: 56px;
  background: var(--bg-card);
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.memory-cell.highlighted {
  background: var(--accent);
}

.memory-cell.selected {
  border-color: var(--accent);
  background: var(--accent);
  opacity: 0.8;
}

.memory-cell.correct-reveal {
  background: var(--success);
}

.memory-cell.wrong-reveal {
  background: var(--error);
}

.memory-cell.missed-reveal {
  background: var(--warning);
  opacity: 0.5;
}

/* Game: Attention Filter */
.attention-game {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.attention-rule {
  font-size: 1.1rem;
  font-weight: 600;
  padding: 10px 20px;
  background: var(--bg-card);
  border-radius: var(--radius);
  text-align: center;
}

.attention-item {
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.5rem;
  border-radius: var(--radius);
  background: var(--bg-card);
  cursor: pointer;
  user-select: none;
  transition: transform 0.1s;
}

.attention-item:active {
  transform: scale(0.95);
}

.attention-feedback {
  font-size: 1.2rem;
  font-weight: 600;
  min-height: 30px;
}

/* Game: Pattern Snap */
.pattern-game {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.pattern-sequence {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 1.6rem;
  font-weight: 700;
}

.pattern-sequence .missing {
  width: 48px;
  height: 48px;
  border: 3px dashed var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: var(--text-dim);
}

.pattern-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 300px;
}

.pattern-choice {
  padding: 14px;
  font-size: 1.3rem;
  font-weight: 700;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.pattern-choice:hover {
  border-color: var(--accent);
}

.pattern-choice.correct-choice {
  background: var(--success);
  color: #111;
}

.pattern-choice.wrong-choice {
  background: var(--error);
  color: #111;
}

/* Game: Color Match (Stroop) */
.stroop-game {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.stroop-word {
  font-size: 3rem;
  font-weight: 800;
  padding: 20px;
}

.stroop-instruction {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.stroop-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 300px;
}

.stroop-choice {
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  color: white;
  transition: transform 0.1s;
}

.stroop-choice:active {
  transform: scale(0.95);
}

/* Game: Word Scramble */
.scramble-game {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.scramble-letters {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--accent);
  padding: 16px;
}

.scramble-input {
  width: 220px;
  padding: 12px 16px;
  font-size: 1.3rem;
  text-align: center;
  background: var(--bg-card);
  color: var(--text);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  outline: none;
  text-transform: uppercase;
}

/* Results Screen */
.results-header {
  text-align: center;
  margin-top: 40px;
}

.result-score-display {
  margin: 24px 0;
  text-align: center;
}

.result-score-display .score {
  font-size: 4rem;
  font-weight: 800;
}

.result-score-display .out-of {
  font-size: 1.5rem;
  color: var(--text-dim);
}

.result-score-display .rating {
  display: block;
  font-size: 1.3rem;
  color: var(--accent);
  font-weight: 700;
  margin-top: 4px;
}

.result-score-display .emoji {
  display: block;
  font-size: 2rem;
  margin-top: 8px;
}

.result-breakdown {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}

.result-breakdown h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.result-game-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.result-game-row:last-child {
  border-bottom: none;
}

.result-game-name {
  font-weight: 500;
}

.result-game-score {
  font-weight: 700;
  color: var(--accent);
}

.streak-display {
  text-align: center;
  padding: 16px;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.streak-display .streak-num {
  color: var(--text);
  font-weight: 700;
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
  padding-bottom: 32px;
}

/* Game: Reaction Time */
.reaction-game {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.reaction-zone {
  width: 100%;
  max-width: 300px;
  height: 280px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.reaction-zone.waiting {
  background: #2a2a3e;
}

.reaction-zone.ready {
  background: var(--success);
}

.reaction-zone.early {
  background: var(--error);
}

.reaction-zone.tapped {
  background: #2563eb;
}

.reaction-label {
  font-size: 2rem;
  font-weight: 800;
  color: white;
  pointer-events: none;
}

.reaction-feedback {
  font-size: 1.1rem;
  font-weight: 600;
  min-height: 24px;
}

/* Game: Visual Search */
.visual-search-game {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.search-hint {
  font-size: 1rem;
  color: var(--text-dim);
  text-align: center;
}

.search-grid {
  display: grid;
  gap: 6px;
  justify-content: center;
  width: 100%;
  max-width: 320px;
}

.search-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 700;
  background: var(--bg-card);
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, border-color 0.15s;
}

.search-cell:hover {
  border-color: var(--accent);
}

.search-cell.search-correct {
  background: var(--success);
  border-color: var(--success);
  color: #111;
}

.search-cell.search-wrong {
  background: var(--error);
  border-color: var(--error);
  color: #111;
}

/* History Screen */
.history-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.history-header h2 {
  font-size: 1.3rem;
}

.history-back {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.history-stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.history-streak-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.history-streak-emoji {
  font-size: 2rem;
}

.history-streak-num {
  font-size: 2.5rem;
  font-weight: 800;
}

.history-streak-label {
  font-size: 1rem;
  color: var(--text-dim);
}

.history-streak-max {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.history-trend-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
}

.history-trend-card[hidden] {
  display: none;
}

.history-trend-arrow {
  font-size: 1.3rem;
}

.history-trend-card.trend-up {
  color: var(--success);
}

.history-trend-card.trend-down {
  color: var(--error);
}

.history-trend-card.trend-neutral {
  color: var(--text-dim);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  flex: 1;
  padding-bottom: 20px;
}

.history-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.history-item-date {
  font-weight: 600;
}

.history-item-score {
  font-weight: 700;
  font-size: 0.95rem;
}

.history-score-bar-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.history-score-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.history-item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.history-item-rating {
  font-weight: 500;
}

.history-item-games {
  text-align: right;
}

/* Rating tier colors */
.rating-genius { color: #a78bfa; }
.rating-brilliant { color: var(--success); }
.rating-sharp { color: var(--accent); }
.rating-warming { color: var(--warning); }
.rating-sleepy { color: var(--text-dim); }

.history-score-bar.rating-genius { background: #a78bfa; }
.history-score-bar.rating-brilliant { background: var(--success); }
.history-score-bar.rating-sharp { background: var(--accent); }
.history-score-bar.rating-warming { background: var(--warning); }
.history-score-bar.rating-sleepy { background: var(--text-dim); }

.history-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Practice Mode */
.practice-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.practice-header h2 {
  font-size: 1.3rem;
}

.practice-back {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.practice-game-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.practice-game-grid[hidden] {
  display: none;
}

.practice-game-btn {
  padding: 20px 12px;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.practice-game-btn:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.practice-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 32px 0;
}

.practice-result[hidden] {
  display: none;
}

.practice-score-display {
  text-align: center;
}

.practice-score-display .score {
  font-size: 3.5rem;
  font-weight: 800;
}

.practice-score-display .out-of {
  font-size: 1.3rem;
  color: var(--text-dim);
}

.practice-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 300px;
}

/* Responsive */
@media (max-width: 400px) {
  .math-question {
    font-size: 1.6rem;
  }

  .memory-cell {
    width: 44px;
    height: 44px;
  }

  .stroop-word {
    font-size: 2.4rem;
  }

  .reaction-zone {
    height: 220px;
  }

  .search-cell {
    font-size: 1.3rem;
  }
}
