:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --good: #059669;
  --good-soft: #ecfdf5;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --card: #131c2e;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #23304a;
    --accent: #818cf8;
    --accent-soft: #1e2547;
    --good: #34d399;
    --good-soft: #0c2a22;
    --bad: #f87171;
    --bad-soft: #2d1416;
    --code-bg: #060a14;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1 { font-size: 2rem; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 18px 0 10px; }
h2:first-child { margin-top: 0; }
p { margin: 0; }

.hero { padding: 12px 4px 4px; }
.hero p { color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.center { text-align: center; }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.row-between h2 { margin: 0; }
.top { min-height: 32px; }

.muted { color: var(--muted); font-size: 0.9rem; }
.small { font-size: 0.875rem; }

a { color: inherit; text-decoration: none; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.link { color: var(--accent); padding: 4px 0; font-weight: 500; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 0.9rem;
  transition: all 0.12s;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.primary, .secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 14px 20px;
  border-radius: 12px;
  font-weight: 600;
  min-height: 50px;
}
.primary { background: var(--accent); color: #fff; }
.primary:hover { filter: brightness(1.08); }
.primary.disabled { opacity: 0.45; }
.secondary { background: var(--card); border: 1px solid var(--border); }
.wide { width: 100%; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions a { flex: 1 1 140px; }

.progress { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress div { height: 100%; background: var(--accent); transition: width 0.25s; }

.meta { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.meta .muted { margin-left: auto; }
.tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.tag.easy { background: var(--good-soft); color: var(--good); }
.tag.medium { background: #fef3c7; color: #b45309; }
.tag.hard { background: var(--bad-soft); color: var(--bad); }
@media (prefers-color-scheme: dark) {
  .tag.medium { background: #33270b; color: #fbbf24; }
}

.prompt { font-size: 1.1rem; font-weight: 600; line-height: 1.45; }
.prompt.small { font-size: 1rem; }

pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 14px 16px;
  border-radius: 10px;
  overflow-x: auto;
  font: 0.85rem/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  margin: 14px 0 0;
}

.options { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-align: left;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  transition: border-color 0.12s, background 0.12s;
}
a.option:hover { border-color: var(--accent); }
a.option:active { background: var(--accent-soft); }
.letter {
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}
.option.correct { border-color: var(--good); background: var(--good-soft); }
.option.correct .letter { background: var(--good); color: #fff; }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.wrong .letter { background: var(--bad); color: #fff; }
.option.dim { opacity: 0.55; }

.verdict { margin-top: 16px; padding: 14px; border-radius: 12px; font-size: 0.95rem; }
.verdict.good { background: var(--good-soft); }
.verdict.good strong { color: var(--good); }
.verdict.bad { background: var(--bad-soft); }
.verdict.bad strong { color: var(--bad); }

.score { font-size: 3.5rem; font-weight: 800; letter-spacing: -0.03em; color: var(--accent); }
.headline { font-size: 1.15rem; font-weight: 600; margin-bottom: 4px; }

.topic-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  margin-bottom: 12px;
}
.bar { grid-column: 1 / -1; height: 6px; background: var(--bad-soft); border-radius: 999px; overflow: hidden; }
.bar div { height: 100%; background: var(--good); }

.review { padding: 14px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.review:first-of-type { border-top: none; padding-top: 0; }
.review pre { margin: 0; }
.answer { color: var(--good); font-weight: 600; }

.chip .count { margin-left: 6px; font-size: 0.75rem; opacity: 0.7; font-weight: 500; }

pre.diagram {
  background: var(--bg);
  color: var(--text);
  border: 1px dashed var(--border);
  font-size: 0.78rem;
  line-height: 1.35;
}

/* Phones: diagrams are up to 44 columns wide, so scale their font with the viewport and
   give cards a little less padding; wider figures still scroll inside their box. */
@media (max-width: 480px) {
  .card { padding: 16px 14px; }
  pre.diagram { padding: 10px; font-size: max(9.5px, 2.85vw); }
}

/* Top navigation between the quiz and the tutorials. */
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
.tab { flex: 1; text-align: center; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tab.on { background: var(--accent-soft); color: var(--accent); }

/* Tutorial list. */
.card.tutorial { display: flex; gap: 14px; align-items: flex-start; }
.card.tutorial:hover { border-color: var(--accent); }
.card.tutorial > span:last-child { display: flex; flex-direction: column; gap: 4px; }
.step {
  flex: none; width: 32px; height: 32px; display: grid; place-items: center;
  border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 700;
}

/* Flash card: <details> flips without JavaScript. */
.flashcard {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.flashcard summary {
  list-style: none;
  cursor: pointer;
  padding: 28px 20px;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  text-align: center;
}
.flashcard summary::-webkit-details-marker { display: none; }
.flashcard .hint { color: var(--accent); font-size: 0.85rem; font-weight: 600; }
.flashcard[open] .hint { display: none; }
.flashcard[open] summary { min-height: 0; padding-bottom: 12px; border-bottom: 1px dashed var(--border); }
.flashcard .back { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 12px; animation: reveal 0.2s ease-out; }
.flashcard .back pre { margin: 0; }
@keyframes reveal { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
/* Keep single line breaks inside a card paragraph (numbered steps, bullet lists). */
.flashcard .back p { white-space: pre-line; }
