/* Layout: one reading column (about 68ch) with figures allowed to run wider;
   the seven roadmap steps are a real sequence, so they carry numbers. */
:root {
  --paper: #ffffff;
  --ink: #142235;
  --muted: #4b5767;
  --line: #d8dee6;
  --wash: #f2f5f9;
  --navy: #17365d;
  --teal: #0b6b66;
  --teal-wash: #e6f2f1;
  --caution: #a83a10;
  --caution-wash: #fbefe8;
  --causal: #2a78d6;
  --predictive: #eb6834;
  --truth: #142235;
  --blue: #1f5fae; --green: #1f7a46; --green-wash: #e7f4ec; --red: #b03a2e; --red-wash: #fbecea;
  --display: "Newsreader", "Iowan Old Style", Georgia, serif;
  --body: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --col: 60rem;
  --wide: 60rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12161c; --ink: #e7ecf2; --muted: #a4aebb; --line: #2c3541; --wash: #1a2029;
    --navy: #9dbbe6; --teal: #5cc4ba; --teal-wash: #15302e; --caution: #f29467; --caution-wash: #2b1d16;
    --causal: #3987e5; --predictive: #d95926; --truth: #e7ecf2; color-scheme: dark;
    --blue: #7fb0f0; --green: #6fcf97; --green-wash: #16301f; --red: #f08a7e; --red-wash: #33201d;
  }
}
:root[data-theme="dark"] {
  --paper: #12161c; --ink: #e7ecf2; --muted: #a4aebb; --line: #2c3541; --wash: #1a2029;
  --navy: #9dbbe6; --teal: #5cc4ba; --teal-wash: #15302e; --caution: #f29467; --caution-wash: #2b1d16;
  --causal: #3987e5; --predictive: #d95926; --truth: #e7ecf2; color-scheme: dark;
  --blue: #7fb0f0; --green: #6fcf97; --green-wash: #16301f; --red: #f08a7e; --red-wash: #33201d;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--body); font-size: 20px; line-height: 1.7;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
a { color: var(--teal); text-underline-offset: 3px; }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid var(--teal); outline-offset: 2px;
}
h1, h2, h3 { font-family: var(--display); font-weight: 500; text-wrap: balance; color: var(--ink); }
h1 { font-size: clamp(2.3rem, 5.5vw, 3.6rem); line-height: 1.05; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: clamp(1.7rem, 3.4vw, 2.3rem); line-height: 1.15; letter-spacing: -0.01em; margin: 0 0 0.6em; color: var(--blue); }
h3 { font-size: 1.3rem; line-height: 1.3; margin: 1.6em 0 0.4em; }
p { margin: 0 0 1em; }
.wrap { max-width: var(--col); margin-inline: auto; }
.wide { max-width: var(--wide); margin-inline: auto; }
.eyebrow { font-family: var(--mono); font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 0.6rem; }
.cite { font-size: 0.75em; vertical-align: super; line-height: 0; text-decoration: none; }
code, .num { font-family: var(--mono); font-size: 0.9em; font-variant-numeric: tabular-nums; }

/* Header */
.masthead { padding-block: 56px 32px; border-bottom: 1px solid var(--line); }
.masthead .dek { font-size: 1.25rem; line-height: 1.55; color: var(--ink); margin-top: 1.1rem; }
.byline { font-size: 0.9rem; color: var(--muted); margin-top: 1.4rem; }
.companion { margin-top: 1.4rem; padding: 14px 18px; background: var(--teal-wash); border-radius: 4px; font-size: 0.95rem; }

/* Roadmap overview */
.roadmap { padding-block: 40px 8px; }
.roadmap ol { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 10px; }
.roadmap li a { display: grid; grid-template-columns: 2.2rem minmax(0, 1fr); gap: 4px 10px; align-items: baseline; padding: 12px 14px; border: 1px solid var(--line); border-radius: 4px; text-decoration: none; color: var(--ink); min-height: 100%; }
.roadmap li a:hover { border-color: var(--teal); }
.roadmap .n { font-family: var(--mono); font-size: 0.85rem; color: var(--teal); }
.roadmap .t { font-weight: 600; }
.roadmap .s { grid-column: 2; font-size: 0.88rem; color: var(--muted); line-height: 1.45; }

section.part { padding-block: 64px 16px; border-top: 1px solid var(--line); }
section.part:first-of-type { border-top: 0; }
.stepnum { font-family: var(--mono); color: var(--teal); }

/* Callouts by role */
.trap, .key { padding: 16px 20px; border-radius: 4px; margin: 1.4rem 0; }
.trap { background: var(--caution-wash); }
.trap > strong:first-child, .key > strong:first-child { display: block; font-family: var(--mono); font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 4px; }
.trap > strong:first-child { color: var(--caution); }
.key { background: var(--green-wash); border-left: 4px solid var(--green); }
.key > strong:first-child { color: var(--green); }
.trap p:last-child, .key p:last-child { margin-bottom: 0; }

/* Tables */
.table-scroll { overflow-x: auto; margin-block: 1.2rem 1.6rem; }
.wide.table-scroll { margin-inline: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; line-height: 1.5; }
th, td { text-align: left; vertical-align: top; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { font-weight: 600; background: var(--wash); }
td:first-child, th:first-child { min-width: 9rem; }
.table-scroll table { min-width: 40rem; }

/* Collapsible details: main points stay visible, the rest opens on click */
details.more { margin: 0.9rem 0; border: 1px solid var(--line); border-left: 4px solid var(--blue); border-radius: 4px; background: var(--paper); }
details.more > summary { cursor: pointer; padding: 12px 16px; font-weight: 600; color: var(--blue); list-style: none; display: flex; gap: 10px; align-items: baseline; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "▸"; transition: transform .15s ease; display: inline-block; }
details.more[open] > summary::before { transform: rotate(90deg); }
details.more > summary:hover { background: var(--wash); }
details.more > .more-body { padding: 4px 18px 10px; }
details.more.wide { margin-inline: auto; }
details.more.trap-box { border-left-color: var(--red); }
details.more.trap-box > summary { color: var(--red); }
details.more.sim > summary { color: var(--causal); }
details.inner { margin: 1rem 0; border: 1px solid var(--line); border-radius: 4px; }
details.inner > summary { cursor: pointer; padding: 10px 14px; font-weight: 600; }
details.inner > div { padding: 0 14px 8px; }
@media (prefers-reduced-motion: reduce) { details.more > summary::before { transition: none; } }
.lede { font-size: 1.08em; }
.kw { color: var(--blue); font-weight: 600; }
.good { color: var(--green); font-weight: 600; }
.bad { color: var(--red); font-weight: 600; }
.goal { margin-top: 1.4rem; padding: 14px 18px; background: var(--green-wash); border-left: 4px solid var(--green); border-radius: 4px; }
.goal > strong:first-child { display: block; font-family: var(--mono); font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--green); margin-bottom: 4px; }
.goal p:last-child { margin: 0; }
.nav-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
.nav-head .eyebrow { margin: 0; }
.nav-foot { font-size: 0.9rem; color: var(--muted); margin-top: 12px; }
.timeline, .people { padding-left: 1.2rem; }
.timeline li, .people li { margin-bottom: 8px; }
.small-print { font-size: 0.85rem; color: var(--muted); }
.answer .lean { font-size: 1.05em; }
.answer .arg-h { font-weight: 600; color: var(--blue); margin: 0.8em 0 0.2em; }
.answer ul { margin: 0 0 0.4em; padding-left: 1.2rem; }

/* Quiz */
.quiz { display: grid; gap: 10px; margin: 1.2rem 0; padding: 0; list-style: none; }
.quiz li { border: 1px solid var(--line); border-radius: 4px; padding: 12px 14px; }
.quiz .q { margin-bottom: 8px; }
.quiz .opts { display: flex; flex-wrap: wrap; gap: 8px; }
.quiz button, .btn { font: inherit; font-size: 0.92rem; min-height: 40px; padding: 6px 14px; border: 1px solid var(--line); border-radius: 4px; background: var(--paper); color: var(--ink); cursor: pointer; }
.quiz button:hover, .btn:hover { border-color: var(--teal); }
.quiz button[aria-pressed="true"].right { background: var(--teal-wash); border-color: var(--teal); }
.quiz button[aria-pressed="true"].wrong { background: var(--caution-wash); border-color: var(--caution); }
.quiz .why { margin-top: 8px; font-size: 0.92rem; color: var(--muted); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: var(--paper); }

/* Figures */
figure { margin: 1.8rem 0; }
figcaption { font-size: 0.9rem; color: var(--muted); margin-top: 10px; line-height: 1.5; }
.sim-controls { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; margin: 8px 0 14px; font-size: 0.92rem; }
.sim-controls label { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; min-width: 0; }
.sim-controls input[type="range"] { width: min(16rem, 100%); accent-color: var(--teal); }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 18px; }
.chart { min-width: 0; }
.chart h4 { font-size: 0.95rem; font-weight: 600; margin: 0 0 6px; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart svg text { fill: var(--muted); font-family: var(--body); font-size: 13px; }
.chart svg .lab { fill: var(--ink); font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.88rem; margin-top: 10px; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; background: var(--c); }
.readout { font-size: 0.95rem; background: var(--wash); border-radius: 4px; padding: 12px 14px; margin-top: 14px; }
.readout p:last-child { margin: 0; }
.tip { position: fixed; pointer-events: none; z-index: 20; background: var(--ink); color: var(--paper); font-size: 0.82rem; padding: 6px 9px; border-radius: 4px; max-width: 16rem; line-height: 1.35; }

/* DAG */
.dag svg { width: 100%; min-width: 40rem; height: auto; display: block; }
.dag-scroll { overflow-x: auto; }
.dag text { font-family: var(--body); font-size: 15px; fill: var(--ink); }
.dag .small { font-size: 13px; fill: var(--muted); }

/* Optional section on causal diagrams */
section.part.optional { background: var(--wash); }
.mini-dags svg { width: 100%; max-width: 46rem; height: auto; display: block; margin: 0 auto; }
.mini-dags text { font-family: var(--body); }
.pc-set { border: 1px solid var(--line); border-radius: 6px; padding: 10px 16px 12px; margin: 14px 0; }
.pc-set legend { font-weight: 600; padding: 0 4px; }
.pc-set label { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; }
.pc-paths { list-style: none; padding: 0; margin: 10px 0 0; font-size: 0.95rem; }
.pc-paths li { padding: 3px 0; }
.pc-kind { color: var(--muted); }
#dag-checker .answer { background: var(--teal-wash); border-radius: 4px; padding: 14px 16px; }
#dag-checker .answer p { margin: 0 0 8px; }
dl.gloss dt { font-weight: 600; margin-top: 10px; }
dl.gloss dd { margin: 2px 0 0 0; }

/* Chooser */
.chooser { border: 1px solid var(--line); border-radius: 6px; padding: 18px; margin: 1.8rem 0; }
.chooser fieldset { border: 0; padding: 0; margin: 0 0 14px; }
.chooser legend { font-weight: 600; margin-bottom: 6px; }
.chooser label { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; }
.chooser .answer { background: var(--teal-wash); border-radius: 4px; padding: 14px 16px; }
.chooser .answer p:last-child { margin: 0; }

/* Worksheet */
.sheet { display: grid; gap: 14px; margin: 1.2rem 0; }
.sheet label { display: grid; gap: 4px; font-weight: 600; font-size: 0.95rem; }
.sheet .hint { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.sheet textarea { font: inherit; font-size: 0.95rem; font-weight: 400; line-height: 1.45; padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--paper); color: var(--ink); min-height: 3.2em; resize: vertical; width: 100%; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.sheet-out { white-space: pre-wrap; font-family: var(--mono); font-size: 0.82rem; background: var(--wash); padding: 14px; border-radius: 4px; max-height: 22rem; overflow: auto; }
.status { font-size: 0.9rem; color: var(--teal); }

/* References */
.refs { font-size: 0.9rem; line-height: 1.5; padding-left: 1.6rem; }
.refs li { margin-bottom: 8px; overflow-wrap: anywhere; }
.refs li:target { background: var(--teal-wash); }

footer.site { padding-block: 40px 56px; border-top: 1px solid var(--line); margin-top: 48px; font-size: 0.88rem; color: var(--muted); }

@media (max-width: 520px) {
  body { font-size: 18px; }
  .masthead { padding-block: 36px 24px; }
  section.part { padding-block: 44px 8px; }
  .chooser { padding: 14px; }
  details.more > .more-body { padding: 4px 12px 10px; }
}

/* Printing: open every collapsible section (app.mjs opens them before print),
   drop interactive chrome, and use the full page width. */
@media print {
  body { font-size: 12pt; padding: 0; }
  :root { --col: 100%; --wide: 100%; }
  #expand-all, .sim-controls, .sheet-actions, .tip { display: none !important; }
  details.more { break-inside: auto; border-left-width: 3px; }
  details.more > summary::before { content: ""; }
  section.part { padding-block: 18pt 6pt; }
  .masthead { padding-block: 0 12pt; }
  a { color: inherit; }
}
