/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #f0f4f8;
  --surface:      #ffffff;
  --primary:      #3b82f6;
  --primary-dk:   #2563eb;
  --success:      #16a34a;
  --success-bg:   #dcfce7;
  --error:        #dc2626;
  --error-bg:     #fee2e2;
  --text:         #0f172a;
  --muted:        #64748b;
  --border:       #e2e8f0;
  --radius:       0.75rem;
  --shadow:       0 1px 3px rgba(0,0,0,.1), 0 4px 12px rgba(0,0,0,.06);
  color-scheme: light;
}


/* Manual dark override */
:root[data-theme="dark"] {
  --bg:           #0f172a;
  --surface:      #1e293b;
  --primary:      #60a5fa;
  --primary-dk:   #3b82f6;
  --success:      #22c55e;
  --success-bg:   #14532d;
  --error:        #f87171;
  --error-bg:     #450a0a;
  --text:         #f1f5f9;
  --muted:        #94a3b8;
  --border:       #334155;
  --shadow:       0 1px 3px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.2);
  color-scheme: dark;
}

/* Manual light override */
:root[data-theme="light"] {
  color-scheme: light;
}

html { font-size: 16px; }

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.site-header a.back-link {
  font-size: 1.25rem;
  text-decoration: none;
  color: var(--primary);
  line-height: 1;
}

.site-header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
}

/* ── Theme toggle button ──────────────────────────────────────────────────── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  flex-shrink: 0;
  background: none;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--muted);
  transition: background 0.15s;
  margin-left: auto;
}
.theme-toggle:hover { background: var(--border); color: var(--text); }

.main {
  flex: 1;
  padding: 1.25rem 1rem;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

/* ── Game index grid ─────────────────────────────────────────────────────── */
.game-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.875rem;
}

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

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1rem;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: box-shadow 0.15s, transform 0.1s;
  cursor: pointer;
  min-height: 7rem;
}

.game-card:hover,
.game-card:focus-visible {
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  transform: translateY(-1px);
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.game-card .game-icon {
  font-size: 1.75rem;
  line-height: 1;
}

.game-card .game-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.game-card .game-desc {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── Score bar ───────────────────────────────────────────────────────────── */
.score-bar {
  display: flex;
  gap: 1.5rem;
  font-size: 0.875rem;
  color: var(--muted);
  padding: 0.5rem 0;
}

.score-bar span strong {
  color: var(--text);
  font-size: 1rem;
}

/* ── Question display ────────────────────────────────────────────────────── */
.question-card {
  text-align: center;
  padding: 2rem 1.25rem;
}

.question-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.question-display {
  font-size: clamp(2rem, 10vw, 3.5rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
}

.question-sub {
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

/* ── Input area ──────────────────────────────────────────────────────────── */
.input-area {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
}

.btn-mic {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 9999px;
  padding: 0.875rem 2rem;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  min-width: 10rem;
  min-height: 3rem;
  transition: background 0.15s;
  touch-action: manipulation;
}

.btn-mic:hover { background: var(--primary-dk); }

.btn-mic.listening {
  background: var(--error);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.75; }
}

.answer-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  width: 100%;
  max-width: 380px;
}

.answer-input {
  flex: 1;
  min-width: 9rem;  /* triggers wrap on very narrow screens */
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  min-height: 2.75rem;
}

.answer-input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 0;
  border-color: transparent;
}

.btn-submit {
  flex-shrink: 0;
  padding: 0.75rem 1.25rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 2.75rem;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn-submit:hover { background: var(--primary-dk); }

.voice-unavailable {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  max-width: 340px;
}

/* ── Audio mode toggle ───────────────────────────────────────────────────── */
.audio-toggle {
  margin-left: auto;
  padding: 0.3rem 0.8rem;
  border-radius: 9999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.audio-toggle.on {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── Voice / keyboard mode toggle (inside input UI) ─────────────────────── */
.voice-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.btn-mode {
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  transition: color 0.12s, border-color 0.12s;
}
.btn-mode:hover {
  color: var(--text);
  border-color: var(--text);
}

/* ── Audio mode status indicator ─────────────────────────────────────────── */
.audio-status {
  font-size: 0.875rem;
  color: var(--muted);
  padding: 0.6rem 1.25rem;
  text-align: center;
  border: 1.5px dashed var(--border);
  border-radius: 0.5rem;
  min-width: 8rem;
  letter-spacing: 0.03em;
}
.audio-status.listening {
  color: var(--primary);
  border-color: var(--primary);
  animation: pulse 1.2s ease-in-out infinite;
}

/* ── Feedback ────────────────────────────────────────────────────────────── */
.feedback {
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  font-size: 1rem;
  font-weight: 500;
  text-align: center;
  display: none;
}

.feedback.correct {
  background: var(--success-bg);
  color: var(--success);
  display: block;
}

.feedback.wrong {
  background: var(--error-bg);
  color: var(--error);
  display: block;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s;
}

.btn:hover { opacity: 0.85; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost   { background: transparent; color: var(--primary); border: 1px solid var(--border); }

/* ── Settings / config ───────────────────────────────────────────────────── */
.settings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.875rem;
}

.settings-row label { color: var(--muted); }

.settings-row select,
.settings-row input[type="file"] {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  font-size: 0.875rem;
  background: var(--surface);
  color: var(--text);
}

.chip-group {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.chip {
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.825rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.chip.active,
.chip:focus-visible {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-muted  { color: var(--muted); font-size: 0.875rem; }
.hidden      { display: none !important; }
