:root {
  --paper: #eceff3;
  --surface: #ffffff;
  --ink: #1c2140;
  --muted: #565d78;
  --line: #cdd3de;
  --accent: #3b3486;
  --accent-soft: #e3e0f6;
  --mark: #f3da5b;
  --good: #1f7a55;
  --good-soft: #dcefe5;
  --bad: #b3261e;
  --bad-soft: #f7dfdc;
  --blot: #1c2140;
  --radius-lg: 18px;
  --radius-sm: 8px;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Literata", Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #13162a; --surface: #1c2039; --ink: #e7e9f3; --muted: #a0a6c0; --line: #30355a;
    --accent: #aea2ff; --accent-soft: #2c2a55; --mark: #e6cc4a; --good: #62c79a; --good-soft: #1b3a2e;
    --bad: #f08a80; --bad-soft: #43201f; --blot: #d9dcf0; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #13162a; --surface: #1c2039; --ink: #e7e9f3; --muted: #a0a6c0; --line: #30355a;
  --accent: #aea2ff; --accent-soft: #2c2a55; --mark: #e6cc4a; --good: #62c79a; --good-soft: #1b3a2e;
  --bad: #f08a80; --bad-soft: #43201f; --blot: #d9dcf0; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
html { scroll-padding-top: calc(env(safe-area-inset-top, 0px) + 72px); }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--body); font-size: 1.0625rem; line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; }
a { color: var(--accent); }
h1, h2, h3, h4 { font-family: var(--display); line-height: 1.15; margin: 0 0 .5em; letter-spacing: -0.01em; }
h1 { font-size: clamp(2.2rem, 5.5vw, 3.6rem); font-weight: 700; letter-spacing: -0.03em; }
h2 { font-size: clamp(1.5rem, 3vw, 2rem); font-weight: 650; }
h3 { font-size: 1.2rem; font-weight: 600; }
p { margin: 0 0 1em; max-width: 68ch; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }

/* Header */
.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.bar-inner { max-width: 1120px; margin: 0 auto; display: flex; align-items: center; gap: 16px; padding: 10px 20px; }
.brand { font-family: var(--display); font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand-dot { width: 22px; height: 22px; }
.nav { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  font-family: var(--display); font-size: .95rem; text-decoration: none; color: var(--muted);
  padding: 7px 12px; border-radius: 999px; white-space: nowrap;
}
.nav a:hover { color: var(--ink); background: var(--accent-soft); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--mark); }
.icon-btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; width: 36px; height: 36px; cursor: pointer; font-size: 1rem; flex-shrink: 0; }

main { max-width: 1120px; margin: 0 auto; padding: 28px 20px 80px; }
.view[hidden] { display: none; }

/* Hero */
.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 32px; align-items: center; padding: 20px 0 36px; }
.hero p.lede { font-size: 1.2rem; color: var(--muted); }
.blot-wrap { position: relative; }
.blot { width: 100%; aspect-ratio: 1.25 / 1; display: block; }
.blot path, .blot circle, .blot ellipse { fill: var(--blot); }
.blot-caption { font-family: var(--display); font-size: .9rem; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 6px; }
.blot-caption em { font-style: italic; }
.blot-enter { animation: blotIn 1.1s cubic-bezier(.2,.7,.2,1) both; transform-origin: center; }
@keyframes blotIn { from { opacity: 0; transform: scaleX(.2); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
@media (prefers-reduced-motion: reduce) { .blot-enter { animation: none; } * { scroll-behavior: auto !important; } }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.btn {
  font-family: var(--display); font-weight: 600; font-size: 1rem; cursor: pointer;
  border-radius: 999px; padding: 11px 20px; border: 1.5px solid var(--ink);
  background: var(--ink); color: var(--paper); text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--accent-soft); color: var(--ink); border-color: var(--ink); }
.btn.small { padding: 7px 14px; font-size: .9rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* Subject rows */
.subjects { border-top: 2px solid var(--ink); margin-top: 8px; }
.subject-row {
  display: grid; grid-template-columns: 1fr 180px auto; gap: 20px; align-items: center;
  padding: 18px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit;
}
.subject-row:hover h3 { color: var(--accent); }
.subject-row p { margin: 0; color: var(--muted); font-size: .95rem; }
.meter { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s; }
.meter-label { font-family: var(--display); font-size: .85rem; color: var(--muted); margin-top: 4px; }
.chev { font-family: var(--display); font-size: 1.4rem; color: var(--muted); }

.section-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 44px 0 12px; flex-wrap: wrap; }
.section-head p { margin: 0; color: var(--muted); }

/* Roadmap */
.steps { list-style: none; padding: 0; margin: 0; counter-reset: step; }
.step { position: relative; padding: 0 0 30px 64px; }
.step::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 0; top: -2px; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; font-family: var(--display); font-weight: 700;
  background: var(--surface); border: 2px solid var(--ink);
}
.step::after { content: ""; position: absolute; left: 20px; top: 42px; bottom: 0; width: 2px; background: var(--line); }
.step:last-child::after { display: none; }
.step h3 { margin-bottom: 2px; }
.step .when { font-family: var(--display); font-size: .9rem; color: var(--accent); margin-bottom: 8px; }
.step.done::before { content: "✓"; background: var(--ink); color: var(--paper); }
.step-done { font-family: var(--display); font-size: .9rem; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--muted); }
.asklist { margin: 8px 0 12px; padding-left: 1.2em; color: var(--muted); }
.asklist li { margin-bottom: 4px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.check input { margin-top: 6px; width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
.check.on span { text-decoration: line-through; color: var(--muted); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 22px 24px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.defs { margin: 0; }
.defs div { padding: 10px 0; border-bottom: 1px solid var(--line); }
.defs div:last-child { border-bottom: 0; }
.defs dt { font-family: var(--display); font-weight: 600; }
.defs dd { margin: 0; color: var(--muted); }
.note { border-left: 4px solid var(--mark); padding: 6px 0 6px 14px; color: var(--ink); }

/* Subject page */
.crumbs { font-family: var(--display); font-size: .9rem; margin-bottom: 10px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.tabs { display: flex; gap: 6px; border-bottom: 2px solid var(--ink); margin: 18px 0 24px; overflow-x: auto; }
.tabs button {
  font-family: var(--display); font-size: 1rem; font-weight: 600; border: 0; background: none; color: var(--muted);
  padding: 10px 14px; cursor: pointer; border-radius: 10px 10px 0 0; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--paper); background: var(--ink); }
.topic { margin-bottom: 28px; }
.topic h3 { padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.topic ul { padding-left: 1.2em; margin: 0; }
.topic li { margin-bottom: 8px; max-width: 72ch; }
mark { background: var(--mark); color: #1c2140; border-radius: 3px; padding: 0 2px; }
.search { width: 100%; max-width: 480px; font: inherit; font-family: var(--display); padding: 11px 16px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); }
.search:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.hit { padding: 12px 0; border-bottom: 1px solid var(--line); }
.hit small { font-family: var(--display); color: var(--accent); display: block; }
.empty { color: var(--muted); padding: 24px 0; }

/* Flashcards */
.fc-wrap { max-width: 640px; margin: 0 auto; }
.fc { perspective: 1400px; cursor: pointer; }
.fc-inner { position: relative; min-height: 260px; transition: transform .5s cubic-bezier(.2,.7,.2,1); transform-style: preserve-3d; }
.fc.flipped .fc-inner { transform: rotateY(180deg); }
@media (prefers-reduced-motion: reduce) { .fc-inner { transition: none; } }
.fc-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 28px;
  border-radius: var(--radius-lg); border: 2px solid var(--ink); background: var(--surface);
}
.fc-face.back { transform: rotateY(180deg); background: var(--accent-soft); }
.fc-term { font-family: var(--display); font-size: clamp(1.5rem, 4vw, 2.1rem); font-weight: 700; }
.fc-def { font-size: 1.15rem; max-width: 46ch; }
.fc-hint { font-family: var(--display); font-size: .85rem; color: var(--muted); position: absolute; bottom: 14px; }
.fc-controls { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.count { font-family: var(--display); color: var(--muted); font-size: .95rem; }

/* Quiz */
.quiz { max-width: 760px; }
.q-meta { display: flex; justify-content: space-between; font-family: var(--display); color: var(--muted); font-size: .95rem; margin-bottom: 8px; gap: 12px; flex-wrap: wrap; }
.q-text { font-size: 1.3rem; line-height: 1.45; margin-bottom: 18px; font-weight: 500; }
.opts { display: grid; gap: 10px; }
.opt {
  text-align: left; font: inherit; padding: 14px 16px 14px 52px; position: relative; cursor: pointer;
  background: var(--surface); color: var(--ink); border: 1.5px solid var(--line); border-radius: 12px;
}
.opt:hover:not(:disabled) { border-color: var(--ink); }
.opt::before {
  content: attr(data-key); position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--line);
  display: grid; place-items: center; font-family: var(--display); font-size: .85rem; font-weight: 600;
}
.opt.picked { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.right::before { background: var(--good); color: #fff; border-color: var(--good); content: "✓"; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong::before { background: var(--bad); color: #fff; border-color: var(--bad); content: "✕"; }
.opt:disabled { cursor: default; }
.explain { margin-top: 16px; padding: 14px 18px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.explain strong { font-family: var(--display); }
.q-nav { display: flex; justify-content: space-between; margin-top: 20px; gap: 10px; }
.setup { display: grid; gap: 18px; max-width: 640px; }
.field label, .field legend { font-family: var(--display); font-weight: 600; display: block; margin-bottom: 6px; }
.field fieldset { border: 0; padding: 0; margin: 0; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { position: relative; }
.pill input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.pill span { display: inline-block; font-family: var(--display); padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); }
.pill input:checked + span { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.pill input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.timer { font-variant-numeric: tabular-nums; }
.timer.low { color: var(--bad); font-weight: 700; }

.score-big { font-family: var(--display); font-size: clamp(3rem, 10vw, 5.5rem); font-weight: 800; letter-spacing: -0.04em; line-height: 1; }
.verdict { font-family: var(--display); font-size: 1.2rem; margin: 8px 0 20px; }
.breakdown { display: grid; gap: 10px; margin: 20px 0; max-width: 520px; }
.breakdown .row { display: grid; grid-template-columns: 130px 1fr 52px; gap: 12px; align-items: center; font-family: var(--display); font-size: .95rem; }
.review-item { padding: 16px 0; border-bottom: 1px solid var(--line); }
.review-item .ans { font-size: .95rem; }
.review-item .ans.bad { color: var(--bad); }
.review-item .ans.good { color: var(--good); }

/* Progress */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin: 16px 0 24px; }
.stat { padding: 18px 20px; border-top: 3px solid var(--ink); background: var(--surface); border-radius: 0 0 12px 12px; }
.stat b { font-family: var(--display); font-size: 2rem; display: block; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .95rem; }
.history { width: 100%; border-collapse: collapse; font-size: .95rem; }
.history th, .history td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.history th { font-family: var(--display); font-weight: 600; color: var(--muted); }
.table-wrap { overflow-x: auto; }

footer { border-top: 1px solid var(--line); margin-top: 40px; padding-top: 18px; color: var(--muted); font-size: .9rem; }
footer p { max-width: 80ch; }

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; gap: 12px; }
  .blot-wrap { order: -1; max-width: 420px; margin: 0 auto; width: 100%; }
  .two-col { grid-template-columns: 1fr; }
  .subject-row { grid-template-columns: 1fr auto; }
  .subject-row .prog { grid-column: 1 / -1; grid-row: 2; }
  .subject-row .chev { grid-row: 1; grid-column: 2; }
  .bar-inner { flex-wrap: wrap; gap: 8px; }
  .nav { order: 3; width: 100%; margin-left: 0; }
  .icon-btn { margin-left: auto; order: 2; }
  .step { padding-left: 56px; }
  .breakdown .row { grid-template-columns: 100px 1fr 48px; }
}
