:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #17211d;
  --muted: #5b6862;
  --border: #dde3e0;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #d5efeb;
  --good: #15803d;
  --good-soft: #dcfce7;
  --warn: #a16207;
  --warn-soft: #fef3c7;
  --graph-axis: #8a958f;
  --graph-grid: #e7ebe9;
  --curve-1: #0f766e;
  --curve-2: #c2410c;
  --curve-3: #6d28d9;
  --curve-4: #0369a1;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412; --surface: #18201d; --surface-2: #1f2925; --text: #e6ece9; --muted: #9aa8a1;
    --border: #2b3732; --accent: #2dd4bf; --accent-text: #062a26; --accent-soft: #123b36;
    --good: #4ade80; --good-soft: #10331f; --warn: #fbbf24; --warn-soft: #3a2c0b;
    --graph-axis: #74817b; --graph-grid: #24302b;
    --curve-1: #2dd4bf; --curve-2: #fb923c; --curve-3: #a78bfa; --curve-4: #38bdf8;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --surface: #18201d; --surface-2: #1f2925; --text: #e6ece9; --muted: #9aa8a1;
  --border: #2b3732; --accent: #2dd4bf; --accent-text: #062a26; --accent-soft: #123b36;
  --good: #4ade80; --good-soft: #10331f; --warn: #fbbf24; --warn-soft: #3a2c0b;
  --graph-axis: #74817b; --graph-grid: #24302b;
  --curve-1: #2dd4bf; --curve-2: #fb923c; --curve-3: #a78bfa; --curve-4: #38bdf8;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 640px; margin: 0 auto; padding: 16px 16px 96px; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 8px 0 4px; }
h2 { font-size: 1.05rem; margin: 24px 0 10px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.loading { color: var(--muted); padding: 48px 0; text-align: center; }
button { font: inherit; color: inherit; cursor: pointer; }
.katex { font-size: 1.05em; }
.katex-display { overflow-x: auto; overflow-y: hidden; }

/* ---- home ---- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .8rem; color: var(--muted); }
.topics { display: grid; gap: 10px; }
.topic {
  display: block; width: 100%; text-align: left; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
}
.topic:hover, .topic:focus-visible { border-color: var(--accent); outline: none; }
.topic.mixed { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.topic.mixed .muted { color: inherit; opacity: .85; }
.topic-row { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.topic-name { font-weight: 600; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; margin-top: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.footnote { margin-top: 28px; font-size: .8rem; color: var(--muted); }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; }

/* ---- practice ---- */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.back { background: none; border: 0; padding: 8px 8px 8px 0; color: var(--accent); font-weight: 600; }
.topbar .title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { font-size: .78rem; background: var(--surface-2); border-radius: 99px; padding: 2px 10px; color: var(--muted); }
.chip.marks { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.context { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: .94rem; }
.context-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 4px; }
.qtext { font-size: 1.05rem; }
figure { margin: 4px 0 14px; }
figure svg { width: 100%; height: auto; display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
figcaption { font-size: .78rem; color: var(--muted); margin-top: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .8rem; margin-top: 6px; }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 3px; border-radius: 2px; background: var(--c); vertical-align: middle; margin-right: 6px; }
.diagram-note { font-size: .88rem; border-left: 3px solid var(--border); padding: 4px 10px; margin-bottom: 12px; color: var(--muted); }
.hint { font-size: .88rem; color: var(--muted); margin: 14px 0 0; }

.actions {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.actions-inner { max-width: 608px; margin: 0 auto; display: flex; gap: 8px; }
.btn {
  flex: 1; border: 0; border-radius: 12px; padding: 14px 16px; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}
.btn.secondary { flex: 0 0 auto; background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn:disabled { opacity: .5; cursor: default; }

.memo { margin-top: 14px; }
.answer { background: var(--good-soft); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; }
.answer-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--good); font-weight: 700; margin-bottom: 2px; }
.criteria { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.criteria label {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); cursor: pointer;
}
.criteria input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.criteria .c-text { flex: 1; }
.criteria .c-marks { color: var(--muted); font-size: .85rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.criteria label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.score { display: flex; justify-content: space-between; align-items: baseline; margin: 12px 0 4px; font-weight: 600; }
.score b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.note { font-size: .88rem; background: var(--surface-2); border-radius: 10px; padding: 8px 12px; margin-top: 10px; }
.note.warn { background: var(--warn-soft); }
.badge { font-size: .78rem; color: var(--good); margin-top: 10px; }

/* ---- summary ---- */
.summary-score { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 8px 0 0; }
.results { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 6px; }
.results li { display: flex; justify-content: space-between; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font-size: .9rem; }
.results .r-marks { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.topic.mixed .bar { background: rgba(255, 255, 255, .25); }
.topic.mixed .bar i { background: var(--accent-text); }
.topic-row .muted { white-space: nowrap; }

.crumb { display: inline-block; color: var(--accent); text-decoration: none; font-weight: 600; font-size: .9rem; margin: 4px 0 4px; }

/* ---- per-type answering, resources, working ---- */
.resource { margin: 4px 0 14px; }
.resource img { display: block; max-width: 100%; height: auto; background: #fff; border-radius: 10px; padding: 4px; border: 1px solid var(--border); }
.resource-data_sheet img { max-height: 70vh; object-fit: contain; }
.choices { display: grid; gap: 8px; margin: 14px 0 4px; }
.choice { display: flex; gap: 12px; align-items: flex-start; text-align: left; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px; font: inherit; color: inherit; cursor: pointer; }
.choice:hover, .choice:focus-visible { border-color: var(--accent); outline: none; }
.choice-letter { font-weight: 800; min-width: 1.4em; }
.choice img { max-width: min(100%, 240px); background: #fff; border-radius: 6px; }
.answer-row { display: flex; gap: 8px; margin: 14px 0 4px; }
.answer-input { flex: 1; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.btn.small { flex: none; padding: 10px 16px; }
.result { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-weight: 700; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.result.right { background: var(--good-soft); color: var(--good); }
.result.wrong { background: var(--warn-soft); color: var(--warn); }
.result .linkish { font-weight: 600; }
.working { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 8px 0; overflow-x: auto; }
.working > div { margin: 2px 0; }
.alt { margin: 6px 0; font-size: .92rem; } .alt summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.guide { margin: 0 0 8px; padding-left: 18px; font-size: .92rem; }
.must { font-size: .72rem; font-weight: 700; background: var(--accent-soft); border-radius: 99px; padding: 1px 8px; white-space: nowrap; }
.datasheet { margin: 0 0 12px; } .datasheet summary { cursor: pointer; font-weight: 600; color: var(--accent); font-size: .92rem; }

/* "Uses your answer to Q8.1": the earlier part and its memo answer, on demand */
.dep { margin: 14px 0 0; font-size: .9rem; }
.dep summary { cursor: pointer; color: var(--muted); }
.dep .dep-show { color: var(--accent); font-weight: 600; }
.dep[open] .dep-show { display: none; }
.dep-part { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-top: 8px; }
.dep-text { margin-bottom: 6px; }
.dep-answer .answer-label { display: inline; }
.dep-part img { max-width: 100%; margin-top: 6px; }

/* colour theme toggle (theme.js) */
.theme-toggle { background: none; border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px;
  color: var(--muted); font: inherit; font-size: .82rem; cursor: pointer; white-space: nowrap; }
.theme-toggle:hover { color: var(--text); }
.crumb-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
/* free set vs logged-in learner */
.access { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin: 12px 0; }
.access p { margin: 0; }
.access.free { background: var(--accent-soft); border-color: var(--accent); }
.access-btn { font-weight: 700; color: var(--accent); }
.access .small { font-size: .85rem; }
