:root {
  --bg: #f5f5f5;
  --fg: #222;
  --card-bg: #ffffff;
  --primary: #36c;
  --primary-hover: #2a4d8f;
  --correct: #2e7d32;
  --correct-bg: #e8f5e9;
  --wrong: #c62828;
  --wrong-bg: #ffebee;
  --muted: #666;
  --border: #ddd;
  --radius: 8px;
  --option-hover-bg: #f0f4ff;
  --blank-bg: #fff3cd;
  --blank-border: #f0c040;
  --blank-fg: #856404;
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --fg: #e0e0e0;
  --card-bg: #16213e;
  --primary: #5b9aff;
  --primary-hover: #4a80d9;
  --correct: #66bb6a;
  --correct-bg: #1b2e1b;
  --wrong: #ef5350;
  --wrong-bg: #2e1b1b;
  --muted: #999;
  --border: #2a2a4a;
  --option-hover-bg: #1e2a4a;
  --blank-bg: #3a3520;
  --blank-border: #8a7730;
  --blank-fg: #e0c860;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 24px 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  text-align: center;
  margin-bottom: 32px;
  position: relative;
}

header h1 {
  font-size: 1.8rem;
  color: var(--primary);
  margin-bottom: 4px;
}

header p {
  color: var(--muted);
  font-size: 0.95rem;
}

/* ── Theme switcher ────────────────────────── */

.theme-switcher {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
}

.theme-btn {
  background: none;
  border: none;
  border-radius: 4px;
  padding: 4px 4px;
  font-size: 0.8rem;
  cursor: pointer;
  line-height: 1;
  opacity: 0.5;
  transition: opacity 0.2s, background 0.2s;
}

.theme-btn:hover { opacity: 0.8; }
.theme-btn.active { opacity: 1; background: var(--bg); }

/* ── Screens ───────────────────────────────── */

.screen { display: none; }
.screen.active { display: block; }

/* ── Start screen ──────────────────────────── */

#start-screen { text-align: center; padding-top: 60px; }

#start-screen p {
  font-size: 1.1rem;
  margin-bottom: 24px;
  color: var(--muted);
}

/* ── Buttons ───────────────────────────────── */

.btn {
  display: inline-block;
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s;
  color: #fff;
  background: var(--primary);
}

.btn:hover { background: var(--primary-hover); }

/* ── Progress bar ──────────────────────────── */

.progress {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
}

.progress-dot {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  transition: background 0.3s;
}

.progress-dot.current { background: var(--primary); }
.progress-dot.correct { background: var(--correct); }
.progress-dot.wrong { background: var(--wrong); }

/* ── Question card ─────────────────────────── */

.question-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  padding: 28px 24px;
  margin-bottom: 20px;
  transition: background 0.3s;
}

.question-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.snippet {
  font-size: 1.15rem;
  line-height: 1.6;
  margin-bottom: 8px;
}

.snippet .blank {
  display: inline-block;
  background: var(--blank-bg);
  border: 2px dashed var(--blank-border);
  border-radius: 4px;
  padding: 2px 12px;
  font-weight: 700;
  color: var(--blank-fg);
  min-width: 80px;
  text-align: center;
}

.snippet a {
  color: var(--primary);
  text-decoration: none;
  pointer-events: none;
}

.date-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 8px;
}

/* ── Options ───────────────────────────────── */

.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  width: 100%;
  padding: 14px 18px;
  font-size: 1rem;
  text-align: left;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--option-hover-bg);
}

.option-btn:disabled { cursor: default; }

.option-btn.correct {
  border-color: var(--correct);
  background: var(--correct-bg);
  font-weight: 600;
}

.option-btn.wrong {
  border-color: var(--wrong);
  background: var(--wrong-bg);
}

.option-btn.dimmed {
  opacity: 0.5;
}

/* ── Option details (revealed after answer) ── */

.option-details {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.4s ease, opacity 0.4s ease, margin-top 0.4s ease;
}

.option-btn.revealed .option-details {
  max-height: 80px;
  opacity: 1;
  margin-top: 8px;
}

.option-details img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.option-desc {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.3;
}

/* ── Feedback / Next ───────────────────────── */

.feedback {
  display: none;
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
}

.feedback.show { display: block; }
.feedback.correct { background: var(--correct-bg); color: var(--correct); }
.feedback.wrong { background: var(--wrong-bg); color: var(--wrong); }

.feedback a {
  color: inherit;
  text-decoration: underline;
}

.next-area {
  text-align: center;
  margin-top: 20px;
  display: none;
}

.next-area.show { display: block; }

/* ── Results screen ────────────────────────── */

#results-screen { text-align: center; padding-top: 40px; }

.score-display {
  font-size: 3.5rem;
  font-weight: 700;
  color: var(--primary);
  margin: 16px 0;
}

.score-label {
  font-size: 1.1rem;
  color: var(--muted);
  margin-bottom: 32px;
}

/* ── Loading ───────────────────────────────── */

.loading {
  text-align: center;
  padding: 60px 0;
  color: var(--muted);
  font-size: 1.1rem;
}

.spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Footer ─────────────────────────────────── */

.footer {
  text-align: center;
  padding: 32px 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: auto;
}
