/* ============ DESIGN TOKENS ============ */
:root,
[data-theme='dark'] {
  --color-bg: #0a0c14;
  --color-surface: #12141f;
  --color-surface-2: #171a28;
  --color-surface-offset: #1d2131;
  --color-border: #262b3d;
  --color-divider: #202437;

  --color-text: #eef0f8;
  --color-text-muted: #9298b3;
  --color-text-faint: #565d78;
  --color-text-inverse: #0a0c14;

  --color-primary: #7c5cff;
  --color-primary-hover: #9579ff;
  --color-primary-active: #6647e0;
  --color-primary-highlight: #23204a;

  --color-success: #2fd992;
  --color-success-highlight: #123326;
  --color-danger: #ff5c7a;
  --color-danger-highlight: #331a24;
  --color-accent-cyan: #22d3ee;

  --shadow-card: 0 20px 50px -20px rgba(0,0,0,0.55);
  --shadow-pop: 0 12px 30px -10px rgba(124,92,255,0.45);
}

[data-theme='light'] {
  --color-bg: #f4f5fb;
  --color-surface: #ffffff;
  --color-surface-2: #fbfbfe;
  --color-surface-offset: #edeef8;
  --color-border: #e1e3ef;
  --color-divider: #e8e9f3;

  --color-text: #171928;
  --color-text-muted: #62667d;
  --color-text-faint: #a3a7bd;
  --color-text-inverse: #ffffff;

  --color-primary: #6b46ff;
  --color-primary-hover: #7c5cff;
  --color-primary-active: #5836e0;
  --color-primary-highlight: #ece7ff;

  --color-success: #159a63;
  --color-success-highlight: #dff5ea;
  --color-danger: #e0335a;
  --color-danger-highlight: #fbe1e7;
  --color-accent-cyan: #0891b2;

  --shadow-card: 0 20px 50px -25px rgba(30,20,80,0.25);
  --shadow-pop: 0 12px 30px -12px rgba(107,70,255,0.35);
}

:root {
  --text-xs: clamp(0.75rem, 0.72rem + 0.15vw, 0.8125rem);
  --text-sm: clamp(0.875rem, 0.84rem + 0.2vw, 0.9375rem);
  --text-base: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  --text-lg: clamp(1.125rem, 1.05rem + 0.5vw, 1.375rem);
  --text-xl: clamp(1.5rem, 1.3rem + 1vw, 2rem);

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem; --space-4: 1rem;
  --space-5: 1.25rem; --space-6: 1.5rem; --space-8: 2rem; --space-10: 2.5rem;
  --space-12: 3rem; --space-16: 4rem;

  --radius-sm: 10px; --radius-md: 16px; --radius-lg: 22px; --radius-full: 999px;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; color: inherit; appearance: none; -webkit-appearance: none; background: none; border: none; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.screen {
  padding: var(--space-5) var(--space-5) var(--space-8);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  animation: fadeIn 0.25s ease;
}
.screen[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ============ HOME ============ */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: var(--space-4);
  margin-bottom: var(--space-6);
}
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand-mark { color: var(--color-primary); width: 34px; height: 34px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; }
.brand-title { font-family: var(--font-display); font-weight: 700; font-size: var(--text-base); line-height: 1.15; }
.brand-sub { font-size: var(--text-xs); color: var(--color-text-muted); }

.theme-toggle, .icon-btn {
  width: 40px; height: 40px; border-radius: var(--radius-full);
  border: 1px solid var(--color-border); background: var(--color-surface);
  color: var(--color-text); display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.theme-toggle:active, .icon-btn:active { transform: scale(0.94); }

.home-stats { display: flex; gap: var(--space-3); margin-bottom: var(--space-8); }
.stat-pill {
  flex: 1; background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-2);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.stat-pill strong { font-family: var(--font-display); font-size: var(--text-lg); color: var(--color-primary); }
.stat-pill span { font-size: var(--text-xs); color: var(--color-text-muted); text-align: center; }

.mode-grid { display: flex; flex-direction: column; gap: var(--space-4); margin-bottom: var(--space-6); }
.mode-card {
  border: 1px solid var(--color-border); background: var(--color-surface);
  border-radius: var(--radius-lg); padding: var(--space-6); text-align: left;
  display: flex; flex-direction: column; gap: var(--space-2); position: relative; overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.mode-card:active { transform: scale(0.98); }
.mode-card::after {
  content: ''; position: absolute; inset: 0; opacity: 0.08; pointer-events: none;
  background: radial-gradient(circle at 85% 15%, var(--color-primary), transparent 55%);
}
.mode-trivia::after { background: radial-gradient(circle at 85% 15%, var(--color-primary), transparent 55%); }
.mode-swipe::after { background: radial-gradient(circle at 85% 15%, var(--color-accent-cyan), transparent 55%); }
.mode-icon {
  width: 44px; height: 44px; border-radius: var(--radius-md);
  background: var(--color-primary-highlight); color: var(--color-primary);
  display: flex; align-items: center; justify-content: center; margin-bottom: var(--space-1);
}
.mode-swipe .mode-icon { color: var(--color-accent-cyan); }
.mode-name { font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg); }
.mode-desc { font-size: var(--text-sm); color: var(--color-text-muted); line-height: 1.4; }

.domain-filter { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: var(--space-2); margin-bottom: var(--space-4); scrollbar-width: none; }
.domain-filter::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; border: 1px solid var(--color-border); background: var(--color-surface);
  color: var(--color-text-muted); border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-4); font-size: var(--text-xs); font-weight: 600;
  white-space: nowrap;
}
.chip.is-active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

.home-footnote { font-size: var(--text-xs); color: var(--color-text-faint); line-height: 1.5; margin-top: auto; padding-top: var(--space-4); }

/* ============ GAME HEADER (shared) ============ */
.game-header { display: flex; align-items: center; gap: var(--space-3); padding-top: var(--space-4); margin-bottom: var(--space-6); }
.game-progress { flex: 1; height: 8px; border-radius: var(--radius-full); background: var(--color-surface-offset); overflow: hidden; }
.game-progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--color-primary), var(--color-accent-cyan)); transition: width 0.3s ease; border-radius: var(--radius-full); }
.game-score {
  font-family: var(--font-display); font-weight: 700; font-size: var(--text-base);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-full); padding: var(--space-1) var(--space-4); min-width: 44px; text-align: center;
}

/* ============ TRIVIA ============ */
.timer-ring { position: relative; width: 64px; height: 64px; margin: 0 auto var(--space-4); }
.timer-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--color-surface-offset); stroke-width: 3; }
.ring-fg { fill: none; stroke: var(--color-primary); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 119.4; stroke-dashoffset: 0; transition: stroke-dashoffset 1s linear, stroke 0.2s ease; }
.timer-ring.is-urgent .ring-fg { stroke: var(--color-danger); }
#timer-num { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 700; font-size: var(--text-base); }

.streak-badge {
  align-self: center; margin-bottom: var(--space-4); font-size: var(--text-sm); font-weight: 700;
  background: var(--color-primary-highlight); color: var(--color-primary);
  padding: var(--space-1) var(--space-4); border-radius: var(--radius-full);
}

.q-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: var(--space-6); box-shadow: var(--shadow-card);
  display: flex; flex-direction: column; gap: var(--space-4);
}
.q-domain {
  align-self: flex-start; font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.02em;
  color: var(--color-primary); background: var(--color-primary-highlight);
  padding: var(--space-1) var(--space-3); border-radius: var(--radius-full);
}
.q-text { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 600; line-height: 1.35; margin: 0; }
.q-options { display: flex; flex-direction: column; gap: var(--space-3); }
.q-option {
  text-align: left; border: 1.5px solid var(--color-border); background: var(--color-surface-2);
  border-radius: var(--radius-md); padding: var(--space-4); font-size: var(--text-sm); font-weight: 500;
  color: var(--color-text); display: flex; align-items: center; gap: var(--space-3); transition: transform 0.1s ease;
}
.q-option:active { transform: scale(0.98); }
.q-option .opt-letter {
  width: 26px; height: 26px; border-radius: var(--radius-full); background: var(--color-surface-offset);
  display: flex; align-items: center; justify-content: center; font-size: var(--text-xs); font-weight: 700; flex-shrink: 0;
}
.q-option.is-correct { border-color: var(--color-success); background: var(--color-success-highlight); }
.q-option.is-correct .opt-letter { background: var(--color-success); color: #06251a; }
.q-option.is-wrong { border-color: var(--color-danger); background: var(--color-danger-highlight); }
.q-option.is-wrong .opt-letter { background: var(--color-danger); color: #2a0510; }
.q-option[disabled] { opacity: 0.55; }
.q-option.is-correct, .q-option.is-wrong { opacity: 1; }

.q-explain {
  margin-top: var(--space-5); background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4);
}
.q-explain p { margin: 0; font-size: var(--text-sm); color: var(--color-text-muted); line-height: 1.55; }

/* ============ RESULTS ============ */
.screen-results, .screen-swipe-results { align-items: center; justify-content: center; }
.results-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--space-2); width: 100%; }
.results-emoji { font-size: 2.5rem; }
.results-title { font-family: var(--font-display); font-size: var(--text-xl); margin: 0; }
.results-sub { color: var(--color-text-muted); margin: 0 0 var(--space-2); }
.results-score { font-family: var(--font-display); font-size: 3.5rem; font-weight: 700; color: var(--color-primary); margin-bottom: var(--space-4); }
.results-stats { display: flex; gap: var(--space-8); margin-bottom: var(--space-8); }
.results-stats div { display: flex; flex-direction: column; align-items: center; }
.results-stats strong { font-family: var(--font-display); font-size: var(--text-lg); }
.results-stats span { font-size: var(--text-xs); color: var(--color-text-muted); }
.results-actions { display: flex; flex-direction: column; gap: var(--space-3); width: 100%; max-width: 280px; }

.btn { border: none; border-radius: var(--radius-full); padding: var(--space-4) var(--space-6); font-size: var(--text-sm); font-weight: 700; width: 100%; }
.btn-primary { background: var(--color-primary); color: #fff; box-shadow: var(--shadow-pop); }
.btn-primary:active { background: var(--color-primary-active); }
.btn-ghost { background: transparent; color: var(--color-text-muted); border: 1px solid var(--color-border); }

/* ============ SWIPE ============ */
.swipe-stage { position: relative; flex: 1; min-height: 380px; margin-bottom: var(--space-4); display: flex; align-items: center; justify-content: center; }
.swipe-hint {
  position: absolute; top: var(--space-6); z-index: 1; font-size: var(--text-xs); font-weight: 700;
  padding: var(--space-1) var(--space-3); border-radius: var(--radius-full); opacity: 0; transition: opacity 0.15s ease;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.swipe-hint-left { left: var(--space-2); color: var(--color-danger); border: 1.5px solid var(--color-danger); background: var(--color-danger-highlight); }
.swipe-hint-right { right: var(--space-2); color: var(--color-success); border: 1.5px solid var(--color-success); background: var(--color-success-highlight); }

.flash-card {
  position: absolute; width: 100%; max-width: 340px; height: 380px;
  border-radius: var(--radius-lg); background: var(--color-surface); border: 1px solid var(--color-border);
  box-shadow: var(--shadow-card); display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--space-8); text-align: center; touch-action: none; user-select: none;
  transition: transform 0.35s cubic-bezier(.2,.8,.2,1), opacity 0.35s ease;
  perspective: 1200px;
}
.flash-card .card-face {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--space-8); backface-visibility: hidden; border-radius: var(--radius-lg);
  transition: transform 0.4s ease;
}
.flash-card .card-front { background: var(--color-surface); }
.flash-card .card-back { background: var(--color-primary-highlight); transform: rotateY(180deg); }
.flash-card.is-flipped .card-front { transform: rotateY(180deg); }
.flash-card.is-flipped .card-back { transform: rotateY(360deg); }
.card-domain-tag { font-size: var(--text-xs); font-weight: 700; color: var(--color-primary); background: var(--color-primary-highlight); padding: var(--space-1) var(--space-3); border-radius: var(--radius-full); margin-bottom: var(--space-4); }
.card-back .card-domain-tag { background: rgba(0,0,0,0.12); }
.card-term { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 700; line-height: 1.3; }
.card-def { font-size: var(--text-sm); line-height: 1.55; color: var(--color-text); }
.card-flip-affordance { position: absolute; bottom: var(--space-4); font-size: var(--text-xs); color: var(--color-text-faint); }

.swipe-tap-hint { text-align: center; font-size: var(--text-xs); color: var(--color-text-faint); margin: 0 0 var(--space-6); }

.swipe-actions { display: flex; align-items: center; justify-content: center; gap: var(--space-6); margin-top: auto; padding-bottom: var(--space-4); }
.fab { width: 56px; height: 56px; border-radius: var(--radius-full); border: none; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; font-weight: 700; box-shadow: var(--shadow-card); }
.fab-no { background: var(--color-danger-highlight); color: var(--color-danger); }
.fab-yes { background: var(--color-success-highlight); color: var(--color-success); }
.fab-flip { width: 48px; height: 48px; background: var(--color-surface); border: 1px solid var(--color-border); color: var(--color-text-muted); }
.fab:active { transform: scale(0.92); }

/* ============ RESPONSIVE ============ */
@media (min-width: 540px) {
  .app { border-left: 1px solid var(--color-border); border-right: 1px solid var(--color-border); }
}
