:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-2: #f2eee6;
  --ink: #1d1b18;
  --ink-2: #5b5750;
  --line: #e3ddd2;
  --accent: #d9480f;
  --accent-soft: #fde8dc;
  --proton: #e03131;
  --neutron: #868e96;
  --electron: #1c7ed6;
  --good: #2b8a3e;
  --good-soft: #e3f5e6;
  --bad: #c92a2a;
  --bad-soft: #fde2e2;
  --gold: #e8b923;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1d2024;
    --surface-2: #262a2f;
    --ink: #eceae6;
    --ink-2: #a6a39d;
    --line: #33373d;
    --accent: #ff8a4c;
    --accent-soft: #3a261b;
    --proton: #ff6b6b;
    --neutron: #adb5bd;
    --electron: #4dabf7;
    --good: #69db7c;
    --good-soft: #1e3324;
    --bad: #ff8787;
    --bad-soft: #3b1f1f;
    --gold: #f2c94c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.65 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: "Fraunces", Georgia, serif; line-height: 1.2; font-weight: 600; }
h1 { font-size: clamp(2rem, 5vw, 3rem); margin: .2em 0 .3em; }
h2 { font-size: 1.7rem; margin: 0 0 .6em; }
h3 { font-size: 1.2rem; margin: 1.4em 0 .4em; }
a { color: var(--accent); }
code, .mono { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .92em; }

.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 12px; }
.brand { font-family: "Fraunces", serif; font-weight: 600; color: var(--ink); text-decoration: none; font-size: 1.1rem; }
.brand span { color: var(--accent); }
.nav-links { display: flex; gap: 16px; font-size: .9rem; overflow-x: auto; }
.nav-links a { color: var(--ink-2); text-decoration: none; white-space: nowrap; }
.nav-links a:hover { color: var(--accent); }

/* Hero */
.hero { padding: 40px 0 8px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .78rem; font-weight: 600; color: var(--accent); }
.lede { font-size: 1.15rem; color: var(--ink-2); max-width: 640px; }

/* Steps indicator */
.steps { display: flex; gap: 8px; flex-wrap: wrap; margin: 20px 0 8px; }
.steps a {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--ink); text-decoration: none; font-size: .9rem;
}
.steps a b { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: .75rem; }

section.block { padding: 36px 0; border-bottom: 1px solid var(--line); scroll-margin-top: 60px; }
section.block:last-of-type { border-bottom: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin: 20px 0;
}
.card.tight { padding: 16px 20px; }

/* Video */
.video { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: #000; box-shadow: var(--shadow); }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-note { font-size: .9rem; color: var(--ink-2); margin-top: 8px; }

/* Concept figures */
figure { margin: 20px 0; }
figure svg { width: 100%; height: auto; display: block; }
figcaption { font-size: .9rem; color: var(--ink-2); margin-top: 8px; text-align: center; }

.callout {
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  padding: 14px 18px; border-radius: 0 10px 10px 0; margin: 20px 0;
}
.callout strong { color: var(--accent); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }

.particle-card { text-align: center; padding: 20px 16px; }
.particle-card .dot { width: 48px; height: 48px; border-radius: 50%; margin: 0 auto 10px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 1.2rem; }
.particle-card h3 { margin: 0 0 6px; }
.particle-card dl { margin: 0; font-size: .92rem; display: grid; grid-template-columns: auto auto; justify-content: center; gap: 2px 10px; text-align: left; }
.particle-card dt { color: var(--ink-2); }
.particle-card dd { margin: 0; font-weight: 600; }

.btn {
  font: inherit; font-size: .95rem; cursor: pointer;
  padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }

/* Atom builder */
.builder { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; align-items: center; }
@media (max-width: 640px) { .builder { grid-template-columns: 1fr; } }
.builder svg { width: 100%; max-width: 340px; margin: 0 auto; display: block; }
.counter { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.counter:last-of-type { border-bottom: 0; }
.counter .lbl { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.counter .lbl i { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.counter .ctl { display: flex; align-items: center; gap: 6px; }
.counter .ctl button { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font-size: 1.1rem; cursor: pointer; }
.counter .ctl output { min-width: 28px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.readout { margin-top: 12px; background: var(--surface-2); border-radius: 10px; padding: 14px; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .95rem; }
.readout dt { color: var(--ink-2); }
.readout dd { margin: 0; font-weight: 600; }
.notation { font-family: "Fraunces", serif; font-size: 2.4rem; display: inline-flex; align-items: center; gap: 4px; line-height: 1; }
.notation .stack { display: inline-flex; flex-direction: column; font-size: .45em; text-align: right; line-height: 1.15; font-family: "Inter", sans-serif; font-weight: 600; }

/* Dot grid (weighted average) */
.dotgrid { display: grid; grid-template-columns: repeat(20, 1fr); gap: 4px; max-width: 420px; margin: 0 auto; }
.dotgrid span { aspect-ratio: 1; border-radius: 50%; }
.legend { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; font-size: .9rem; margin-top: 10px; }
.legend i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: -1px; }

.math { background: var(--surface-2); border-radius: 10px; padding: 14px 16px; font-family: "JetBrains Mono", monospace; font-size: .9rem; overflow-x: auto; white-space: nowrap; }

/* Button row (pick one of several options) */
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 12px; }

/* Slider with label and value */
.slider-row { display: flex; align-items: center; gap: 12px; margin: 12px 0 4px; font-weight: 600; }
.slider-row input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.slider-row output { min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }

/* Data tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: right; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--ink-2); font-weight: 600; }
table.data tr.group td { text-align: left; font-weight: 700; color: var(--accent); padding-top: 12px; }
table.data tr.total td { font-weight: 700; background: var(--surface-2); }
table.data .muted { color: var(--ink-2); font-size: .85em; }

/* Quiz */
.q { margin: 18px 0; }
.q .qnum { font-size: .8rem; font-weight: 600; letter-spacing: .08em; color: var(--accent); text-transform: uppercase; }
.q .prompt { font-weight: 600; margin: 4px 0 12px; }
.q .options { display: grid; gap: 8px; }
.q .options button {
  text-align: left; font: inherit; padding: 10px 14px; border-radius: 10px; cursor: pointer;
  background: var(--surface-2); color: var(--ink); border: 2px solid transparent;
}
.q .options button:hover:not(:disabled) { border-color: var(--line); }
.q .options button.correct { background: var(--good-soft); border-color: var(--good); }
.q .options button.wrong { background: var(--bad-soft); border-color: var(--bad); }
.q .options button:disabled { cursor: default; }
.q .numeric { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.q .numeric input { font: inherit; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); width: 140px; }
.q .feedback { margin-top: 10px; padding: 10px 14px; border-radius: 10px; font-size: .95rem; display: none; }
.q .feedback.show { display: block; }
.q .feedback.good { background: var(--good-soft); }
.q .feedback.bad { background: var(--bad-soft); }
.q .hint { margin-top: 8px; font-size: .9rem; }
.q .hint summary { cursor: pointer; color: var(--ink-2); }
.score { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.score .bar { flex: 1; min-width: 160px; height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.score .bar i { display: block; height: 100%; width: 0; background: var(--good); transition: width .4s; }

/* Chapter list (home) */
.chapters { list-style: none; padding: 0; margin: 20px 0; display: grid; gap: 10px; }
.chapters li a, .chapters li > div {
  display: flex; gap: 14px; align-items: center; padding: 12px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink); text-decoration: none;
}
.chapters li a:hover { border-color: var(--accent); }
.chapters .n { font-family: "Fraunces", serif; font-weight: 600; font-size: 1.2rem; min-width: 34px; color: var(--accent); }
.chapters .t { flex: 1; min-width: 0; }
.chapters .tag { font-size: .75rem; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.chapters .tag.ready { background: var(--good-soft); color: var(--good); font-weight: 600; }
.chapters li.soon > div { opacity: .6; }

.pager { display: flex; justify-content: space-between; gap: 12px; padding: 30px 0 60px; }
footer { color: var(--ink-2); font-size: .85rem; padding: 30px 0 50px; text-align: center; }

/* SVG helpers */
.svg-ink { fill: var(--ink); }
.svg-ink2 { fill: var(--ink-2); }
.svg-line { stroke: var(--line); }
.svg-text { fill: var(--ink); font-family: "Inter", sans-serif; }
.svg-muted { fill: var(--ink-2); font-family: "Inter", sans-serif; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
