/* Stuff, from the bottom up: shared styles */

:root {
  --bg: #fcfcfa;
  --fg: #1c1c1e;
  --muted: #6a6a70;
  --line: #e2e2dc;
  --panel: #f4f4f0;
  --accent: #2c64d6;
  --accent-soft: #e6eefc;
  --warm: #d4602a;
  --warm-soft: #fbece4;
  --green: #2f8a57;
  --kid: #7a4fc0;
  --kid-soft: #f3eefb;
  --atom-a: #3b78e7;
  --atom-b: #e2703a;
  --atom-c: #8a8f98;
  --plot-grid: #e6e6e0;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  /* categorical chart series, fixed order (validated for colour-vision deficiency) */
  --series-1: #3b78e7; --series-2: #e2703a; --series-3: #7a4fc0; --series-4: #2f8a57;

  --serif: "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141416;
    --fg: #e8e8ea;
    --muted: #9a9aa2;
    --line: #2c2c31;
    --panel: #1c1c20;
    --accent: #6d9cff;
    --accent-soft: #1b2640;
    --warm: #f08a55;
    --warm-soft: #33221a;
    --green: #5cc58a;
    --kid: #b28cf0;
    --kid-soft: #241c33;
    --atom-a: #6d9cff;
    --atom-b: #f08a55;
    --atom-c: #9097a3;
    --plot-grid: #2a2a30;
    --shadow: none;
    --series-1: #4f86e8; --series-2: #d9733d; --series-3: #9670dc; --series-4: #35a466;
  }
}
:root[data-theme="dark"] {
  --bg: #141416; --fg: #e8e8ea; --muted: #9a9aa2; --line: #2c2c31; --panel: #1c1c20;
  --accent: #6d9cff; --accent-soft: #1b2640; --warm: #f08a55; --warm-soft: #33221a;
  --green: #5cc58a; --kid: #b28cf0; --kid-soft: #241c33;
  --atom-a: #6d9cff; --atom-b: #f08a55; --atom-c: #9097a3; --plot-grid: #2a2a30; --shadow: none;
  --series-1: #4f86e8; --series-2: #d9733d; --series-3: #9670dc; --series-4: #35a466;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 19px/1.62 var(--serif);
}

main { max-width: 720px; margin: 0 auto; padding: 32px 16px 96px; }

h1, h2, h3, nav, figure, .sim, .box-label, button, input, label, .readout, .kicker, .chapter-list, .glossary-tip {
  font-family: var(--sans);
}
h1 { font-size: 2.1rem; line-height: 1.15; margin: 0.2em 0 0.3em; letter-spacing: -0.01em; }
h2 { font-size: 1.35rem; margin: 2.4em 0 0.6em; letter-spacing: -0.005em; }
h3 { font-size: 1.05rem; margin: 1.6em 0 0.4em; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.kicker { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; }
.lede { font-size: 1.12rem; color: var(--fg); }
.muted { color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--line); margin: 3em 0; }

nav.top {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  font-size: 0.85rem; color: var(--muted); margin-bottom: 28px;
}
nav.top a { color: var(--muted); text-decoration: none; }
nav.top a:hover { color: var(--accent); }
nav.bottom {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-top: 64px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 0.95rem;
}

blockquote {
  margin: 1.4em 0; padding: 0 0 0 18px; border-left: 3px solid var(--line); color: var(--fg);
  font-style: italic;
}
blockquote cite { display: block; font-style: normal; font-size: 0.85rem; color: var(--muted); margin-top: 6px; font-family: var(--sans); }

/* equations */
.eq {
  font-family: var(--serif);
  font-size: 1.1rem;
  text-align: center;
  margin: 1.2em 0;
  padding: 12px 8px;
  overflow-x: auto;
}
.eq var, var { font-style: italic; }
sub, sup { line-height: 0; }

/* boxes */
.box { margin: 2em 0; padding: 18px 20px; border-radius: 10px; }
.box > :last-child { margin-bottom: 0; }
.box-label { font-size: 0.75rem; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 8px; }

.bridge { background: var(--accent-soft); }
.bridge .box-label { color: var(--accent); }
.bridge .caveat { font-size: 0.9rem; color: var(--muted); margin-top: 10px; }
.bridge .caveat::before { content: "Where it breaks: "; font-family: var(--sans); font-weight: 600; font-size: 0.8rem; color: var(--fg); }

.myth { background: var(--warm-soft); }
.myth .box-label { color: var(--warm); }

.kidbox { background: var(--kid-soft); border: 1px solid transparent; }
.kidbox .box-label { color: var(--kid); }
.kidbox dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; }
.kidbox dt { font-family: var(--sans); font-weight: 650; font-size: 0.85rem; color: var(--kid); padding-top: 3px; }
.kidbox dd { margin: 0; }
.kidbox .footnote { font-size: 0.88rem; color: var(--muted); border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }
.kidbox .footnote::before { content: "For the grown-up: "; font-family: var(--sans); font-weight: 600; font-size: 0.8rem; color: var(--fg); }
@media (max-width: 520px) { .kidbox dl { grid-template-columns: 1fr; } .kidbox dt { padding-top: 6px; } }

.honest {
  font-size: 0.88rem; color: var(--muted); margin: -0.4em 0 1.4em;
  padding-left: 22px; position: relative;
}
.honest::before { content: "≈"; position: absolute; left: 2px; top: -1px; font-family: var(--sans); font-weight: 700; color: var(--muted); }

.further { font-size: 0.95rem; }
.further li { margin-bottom: 6px; }

/* predict prompts */
.predict {
  margin: 1.6em 0 0.8em; padding: 14px 16px; border: 1px dashed var(--line); border-radius: 10px;
  font-family: var(--sans); font-size: 0.95rem;
}
.predict .q { font-weight: 600; margin-bottom: 10px; }
.predict .q::before { content: "Predict first. "; color: var(--accent); }
.predict .choices { display: flex; flex-wrap: wrap; gap: 8px; }
.predict .answer { display: none; margin-top: 12px; font-family: var(--serif); font-size: 1rem; }
.predict.revealed .answer { display: block; }
.predict.revealed button.picked { border-color: var(--accent); color: var(--accent); }

/* sims */
.sim {
  margin: 1.6em 0 2em; padding: 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); box-shadow: var(--shadow);
}
.sim canvas { display: block; width: 100%; border-radius: 8px; background: var(--bg); touch-action: none; }
.sim .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin-top: 12px; font-size: 0.9rem; }
.sim .controls label { display: flex; align-items: center; gap: 8px; }
.sim .controls label.big { flex: 1 1 260px; font-weight: 600; }
.sim .controls label.big input[type=range] { flex: 1; }
.sim .readout { margin-top: 10px; font: 0.82rem/1.5 var(--mono); color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 18px; }
.sim .readout b { color: var(--fg); font-weight: 600; }
.sim figcaption { margin-top: 10px; font-size: 0.85rem; color: var(--muted); line-height: 1.5; }
.sim .status { font-family: var(--sans); font-size: 0.9rem; font-weight: 600; min-height: 1.4em; margin-top: 8px; color: var(--accent); }

input[type=range] { accent-color: var(--accent); min-width: 120px; }
button {
  font-size: 0.88rem; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg); cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button + button { border-left: 1px solid var(--line); }

/* glossary */
dfn[data-g] {
  font-style: normal; border-bottom: 1px dotted var(--muted); cursor: help;
}
.glossary-tip {
  position: absolute; z-index: 50; max-width: 300px; padding: 10px 12px; border-radius: 8px;
  background: var(--fg); color: var(--bg); font-size: 0.82rem; line-height: 1.45;
  box-shadow: 0 6px 24px rgba(0,0,0,.18); pointer-events: none; opacity: 0; transition: opacity .12s;
}
.glossary-tip.show { opacity: 1; }
.glossary-tip b { display: block; margin-bottom: 2px; }

/* index */
.chapter-list { list-style: none; padding: 0; margin: 0; }
.chapter-list .part { margin: 28px 0 8px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.chapter-list li.ch { display: grid; grid-template-columns: 2.2em 1fr; gap: 4px 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.chapter-list .num { color: var(--muted); font-variant-numeric: tabular-nums; }
.chapter-list .title { font-weight: 600; }
.chapter-list .blurb { grid-column: 2; font-size: 0.88rem; color: var(--muted); }
.chapter-list li.soon .title { color: var(--muted); font-weight: 500; }
.chapter-list li.soon .title::after { content: " · soon"; font-weight: 400; font-size: 0.8rem; }
.legend { display: grid; gap: 10px; margin: 1.4em 0; }
.legend .box { margin: 0; padding: 10px 14px; font-size: 0.95rem; }

/* chart tooltip and table view */
.chart-tip {
  position: absolute; pointer-events: none; z-index: 40; padding: 6px 9px; border-radius: 6px;
  background: var(--fg); color: var(--bg); font: 0.8rem/1.35 var(--sans); white-space: nowrap;
  opacity: 0; transition: opacity .1s;
}
.chart-tip.show { opacity: 1; }
.sim details { margin-top: 10px; font: 0.85rem var(--sans); }
.sim details summary { cursor: pointer; color: var(--muted); }
.sim table { border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.sim th, .sim td { padding: 3px 10px; border-bottom: 1px solid var(--line); text-align: right; }
.sim th:first-child, .sim td:first-child { text-align: left; }
.sim { position: relative; }

[hidden] { display: none !important; }
.seg { flex-wrap: wrap; max-width: 100%; }
