/* ==========================================================
   Inside the Black Box — shared styles
   ========================================================== */
:root {
  --bg: #fbfaf7;
  --bg-2: #f3f1ec;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --ink-2: #4a4a4f;
  --ink-3: #7b7b82;
  --rule: #e2dfd8;
  --accent: #c2410c;      /* burnt orange */
  --accent-soft: #fdeee4;
  --blue: #2563eb;
  --blue-soft: #e6eeff;
  --green: #15803d;
  --green-soft: #e3f4e8;
  --purple: #7c3aed;
  --purple-soft: #efe8fe;
  --red: #b91c1c;
  --red-soft: #fde8e8;
  --yellow: #b45309;
  --yellow-soft: #fdf3dc;
  --code-bg: #f1efe9;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --radius: 10px;
  --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --measure: 720px;
  --side: 16.25rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141416; --bg-2: #1b1b1e; --panel: #1f1f23; --ink: #ececef; --ink-2: #b9b9c0; --ink-3: #85858d;
    --rule: #2e2e33; --accent: #fb923c; --accent-soft: #3a2416; --blue: #7aa2ff; --blue-soft: #1c2640;
    --green: #4ade80; --green-soft: #15291c; --purple: #b794ff; --purple-soft: #261d3d; --red: #f87171;
    --red-soft: #3a1a1a; --yellow: #fbbf24; --yellow-soft: #33280f; --code-bg: #26262b;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg: #141416; --bg-2: #1b1b1e; --panel: #1f1f23; --ink: #ececef; --ink-2: #b9b9c0; --ink-3: #85858d;
  --rule: #2e2e33; --accent: #fb923c; --accent-soft: #3a2416; --blue: #7aa2ff; --blue-soft: #1c2640;
  --green: #4ade80; --green-soft: #15291c; --purple: #b794ff; --purple-soft: #261d3d; --red: #f87171;
  --red-soft: #3a1a1a; --yellow: #fbbf24; --yellow-soft: #33280f; --code-bg: #26262b;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
/* Scale typography from the default size at 960px to 1.5× at 2560px.
   Rem-based bounds preserve browser font preferences and zoom. */
html { font-size: clamp(1rem, calc(.7rem + .5vw), 1.5rem); scroll-behavior: smooth; scroll-padding-top: 4.5rem; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--serif); font-size: 1.1875rem; line-height: 1.65;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
img, svg { max-width: 100%; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50; height: 3.5rem;
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule); font-family: var(--sans); font-size: 0.875rem;
}
.topbar .brand { font-weight: 700; color: var(--ink); text-decoration: none; letter-spacing: -.01em; white-space: nowrap; }
.topbar .brand span { color: var(--accent); }
.topbar .brand .pre { color: inherit; }
.topbar .social { display: flex; align-items: center; gap: 2px; padding-left: 12px; border-left: 1px solid var(--rule); }
.topbar .social a { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; color: var(--ink-3); }
.topbar .social a:hover { color: var(--ink); background: var(--bg-2); }
.topbar .social svg { width: 16px; height: 16px; }
.topbar .crumb { color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.topbar button, .topbar a.btn {
  font: inherit; background: none; border: 1px solid var(--rule); color: var(--ink-2);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; text-decoration: none;
}
.topbar button:hover, .topbar a.btn:hover { background: var(--bg-2); }
.progress { position: absolute; left: 0; bottom: -1px; height: 2px; background: var(--accent); width: 0; }
#tocToggle { display: none; }

/* ---------- survey search ---------- */
.search-dialog { width: min(700px, calc(100% - 24px)); max-height: 80vh; padding: 22px; border: 1px solid var(--rule); border-radius: 14px; background: var(--bg); color: var(--ink); box-shadow: var(--shadow); font-family: var(--sans); font-size: 0.9375rem; }
.search-dialog::backdrop { background: rgb(0 0 0 / .45); backdrop-filter: blur(3px); }
.search-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 14px; font-weight: 700; }
#siteSearch { width: 100%; padding: 12px; border: 1px solid var(--rule); border-radius: 8px; background: var(--panel); color: var(--ink); font: inherit; }
.search-status { font-size: 0.75rem; color: var(--ink-3); margin: 12px 0; }
.search-results { display: grid; gap: 8px; }
.search-result { display: block; padding: 12px; border: 1px solid var(--rule); border-radius: 8px; color: var(--ink); text-decoration: none; }
.search-result strong { display: block; font-size: 0.8125rem; margin-bottom: 5px; color: var(--accent); }
.search-result span { font-size: 0.875rem; color: var(--ink-2); line-height: 1.5; }
.search-result:hover { background: var(--bg-2); }
.search-result:focus-visible, #siteSearch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.search-result mark { background: color-mix(in srgb, var(--accent) 22%, var(--bg)); color: var(--ink); }
.search-destination { outline: 2px solid var(--accent); outline-offset: 6px; border-radius: 3px; background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }
@media (max-width: 560px) {
  .topbar { gap: 7px; padding: 0 10px; }
  .topbar a.btn { display: none; }
  .topbar .social { padding-left: 6px; gap: 0; }
  .topbar .social a { width: 26px; }
  .topbar .brand .pre { display: none; }
  #searchBtn { font-size: 0; padding: 7px 9px; }
  #searchBtn::before { content: ""; display: block; width: 15px; height: 15px; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='M15.5 15.5 21 21'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='M15.5 15.5 21 21'/%3E%3C/svg%3E") center / contain no-repeat; }
  .search-dialog { padding: 16px; }
}

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); max-width: 1280px; margin: 0 auto; }
.sidebar {
  position: sticky; top: 3.5rem; align-self: start; height: calc(100vh - 3.5rem); overflow-y: auto;
  padding: 28px 18px 40px 24px; font-family: var(--sans); font-size: 0.84375rem; border-right: 1px solid var(--rule);
}
.sidebar h4 { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 0 0 8px; }
.sidebar ol, .sidebar ul { list-style: none; padding: 0; margin: 0 0 24px; }
.sidebar li a {
  display: block; padding: 4px 8px; border-radius: 6px; color: var(--ink-2); text-decoration: none; line-height: 1.35;
}
.sidebar li a:hover { background: var(--bg-2); color: var(--ink); }
.sidebar li a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.sidebar .chapters li a { display: flex; gap: 8px; }
.sidebar .chapters .n { color: var(--ink-3); font-variant-numeric: tabular-nums; min-width: 1.4em; }
.sidebar .chapters li a.current { color: var(--ink); font-weight: 600; }
.sidebar .onpage li a { padding-left: 14px; border-left: 2px solid var(--rule); border-radius: 0; }
.sidebar .onpage li a.active { border-left-color: var(--accent); background: none; }

main { padding: 48px 32px 120px; min-width: 0; }
.article { max-width: var(--measure); margin: 0 auto; }
.wide { max-width: 1000px; margin-left: 50%; transform: translateX(-50%); width: min(1000px, calc(100vw - var(--side) - 64px)); }

/* ---------- headings ---------- */
.kicker { font-family: var(--sans); font-size: 0.8125rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
h1 { font-size: 2.875rem; line-height: 1.1; letter-spacing: -.02em; margin: 8px 0 16px; font-weight: 700; }
.lede { font-size: 1.375rem; line-height: 1.5; color: var(--ink-2); margin: 0 0 28px; }
h2 { font-size: 1.9375rem; line-height: 1.2; letter-spacing: -.01em; margin: 72px 0 16px; padding-top: 24px; border-top: 1px solid var(--rule); }
h3 { font-family: var(--sans); font-size: 1.25rem; margin: 40px 0 10px; letter-spacing: -.01em; }
h4 { font-family: var(--sans); font-size: 1rem; margin: 28px 0 6px; }
p { margin: 0 0 18px; }
ul, ol { padding-left: 1.3em; margin: 0 0 18px; }
li { margin-bottom: 6px; }
strong { font-weight: 650; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 40px 0; }
code { font-family: var(--mono); font-size: .82em; background: var(--code-bg); padding: 2px 5px; border-radius: 4px; }
pre { font-family: var(--mono); font-size: 0.875rem; line-height: 1.55; background: var(--code-bg); padding: 16px 18px; border-radius: var(--radius); overflow-x: auto; }
pre code { background: none; padding: 0; font-size: inherit; }
.math { font-family: var(--mono); font-size: .9em; white-space: nowrap; }
.mathblock { font-family: var(--mono); font-size: 0.9375rem; background: var(--bg-2); border-radius: var(--radius); padding: 14px 18px; margin: 0 0 20px; overflow-x: auto; text-align: center; }

.meta { font-family: var(--sans); font-size: 0.875rem; color: var(--ink-3); display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 32px; }
.meta b { color: var(--ink-2); font-weight: 600; }

/* ---------- callouts ---------- */
.callout {
  border-radius: var(--radius); padding: 16px 20px; margin: 24px 0; font-size: 1.09375rem; line-height: 1.6;
  background: var(--bg-2); border-left: 4px solid var(--ink-3);
}
.callout > :last-child { margin-bottom: 0; }
.callout .label { display: block; font-family: var(--sans); font-size: 0.75rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; margin-bottom: 6px; }
.callout.key { background: var(--accent-soft); border-color: var(--accent); }
.callout.key .label { color: var(--accent); }
.callout.example { background: var(--blue-soft); border-color: var(--blue); }
.callout.example .label { color: var(--blue); }
.callout.warn { background: var(--yellow-soft); border-color: var(--yellow); }
.callout.warn .label { color: var(--yellow); }
.callout.limit { background: var(--red-soft); border-color: var(--red); }
.callout.limit .label { color: var(--red); }
.callout.analogy { background: var(--purple-soft); border-color: var(--purple); }
.callout.analogy .label { color: var(--purple); }
.callout.good { background: var(--green-soft); border-color: var(--green); }
.callout.good .label { color: var(--green); }

/* TL;DR box at chapter top */
.tldr { border: 1px solid var(--rule); background: var(--panel); border-radius: var(--radius); padding: 18px 22px; margin: 0 0 36px; box-shadow: var(--shadow); font-size: 1.0625rem; }
.tldr h3 { margin: 0 0 8px; font-size: 0.8125rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); }
.tldr ul { margin: 0; }

/* ---------- paper card ---------- */
.paper {
  display: grid; grid-template-columns: 64px 1fr; gap: 14px; align-items: start;
  border: 1px solid var(--rule); background: var(--panel); border-radius: var(--radius);
  padding: 14px 16px; margin: 20px 0; font-family: var(--sans); font-size: 0.90625rem; line-height: 1.5;
}
.paper .yr { font-weight: 800; font-size: 1.25rem; color: var(--accent); font-variant-numeric: tabular-nums; }
.paper .t { font-weight: 650; color: var(--ink); font-size: 0.96875rem; }
.paper .t a { color: inherit; text-decoration: none; }
.paper .t a:hover { color: var(--accent); }
.paper .a { color: var(--ink-3); font-size: 0.8125rem; margin-bottom: 4px; }
.paper .s { color: var(--ink-2); }

/* ---------- figures ---------- */
figure { margin: 32px 0; }
figure.panel, .widget {
  background: var(--panel); border: 1px solid var(--rule); border-radius: 14px; padding: 22px; box-shadow: var(--shadow);
}
figcaption { font-family: var(--sans); font-size: 0.875rem; color: var(--ink-3); margin-top: 12px; line-height: 1.5; }
figcaption b { color: var(--ink-2); }
.widget { margin: 36px 0; font-family: var(--sans); font-size: 0.9375rem; }
.widget-title { font-family: var(--sans); font-weight: 700; font-size: 0.8125rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.widget-title::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.widget-sub { color: var(--ink-2); margin-bottom: 16px; font-size: 0.90625rem; }
.controls { display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: center; margin: 12px 0; }
.controls label { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 0.875rem; }
.controls input[type=range] { accent-color: var(--accent); width: 150px; }
.controls output { font-variant-numeric: tabular-nums; color: var(--ink); min-width: 3em; font-weight: 600; }
.btn {
  font-family: var(--sans); font-size: 0.875rem; background: var(--panel); color: var(--ink); border: 1px solid var(--rule);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--bg-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 0.84375rem; border: 0; background: var(--panel); color: var(--ink-2); padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--rule); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; }
.readout { font-family: var(--mono); font-size: 0.8125rem; color: var(--ink-2); background: var(--bg-2); border-radius: 8px; padding: 10px 12px; margin-top: 12px; }

/* svg defaults */
svg text { font-family: var(--sans); }
/* default ink colour for SVG text, but never override a fill attribute (on the text or its group) */
:where(svg text:not([fill]):not(g[fill] text)) { fill: var(--ink); }
svg .muted { fill: var(--ink-3); }
svg .stroke { stroke: var(--ink-2); }
svg .rule { stroke: var(--rule); }

.widget.wide, figure.wide { margin-left: 50%; margin-right: 0; }

/* ---------- steps / tabs ---------- */
.stepper { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.stepper button { font-family: var(--sans); font-size: 0.8125rem; border: 1px solid var(--rule); background: var(--panel); color: var(--ink-2); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.stepper button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.step-body { min-height: 60px; }

.tabs { margin: 28px 0; }
.tabs .tab-buttons { display: flex; gap: 4px; border-bottom: 1px solid var(--rule); overflow-x: auto; }
.tabs .tab-buttons button { font-family: var(--sans); font-size: 0.875rem; background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 14px; color: var(--ink-3); cursor: pointer; white-space: nowrap; }
.tabs .tab-buttons button.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .tab-panel { display: none; padding-top: 16px; }
.tabs .tab-panel.on { display: block; }

/* ---------- details / quiz ---------- */
details { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--panel); margin: 18px 0; font-size: 1.0625rem; }
details > summary { cursor: pointer; padding: 12px 16px; font-family: var(--sans); font-weight: 600; font-size: 0.9375rem; list-style: none; display: flex; gap: 10px; align-items: center; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "+"; font-family: var(--mono); color: var(--accent); width: 1em; }
details[open] > summary::before { content: "−"; }
details > .body { padding: 0 18px 16px 42px; }

.quiz { border: 1px solid var(--rule); border-radius: 14px; background: var(--panel); padding: 20px 22px; margin: 36px 0; font-family: var(--sans); font-size: 0.96875rem; box-shadow: var(--shadow); }
.quiz .q { font-weight: 650; margin-bottom: 12px; font-size: 1rem; }
.quiz .opts { display: grid; gap: 8px; }
.quiz .opts button { text-align: left; font: inherit; background: var(--bg); border: 1px solid var(--rule); border-radius: 8px; padding: 10px 14px; cursor: pointer; color: var(--ink); }
.quiz .opts button:hover { border-color: var(--ink-3); }
.quiz .opts button.right { background: var(--green-soft); border-color: var(--green); }
.quiz .opts button.wrong { background: var(--red-soft); border-color: var(--red); }
.quiz .why { display: none; margin-top: 12px; color: var(--ink-2); font-size: 0.9375rem; }
.quiz.done .why { display: block; }
.quiz-head { font-size: 0.75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 700; margin-bottom: 8px; }

/* ---------- glossary term tooltip ---------- */
.term { border-bottom: 1.5px dotted var(--accent); cursor: help; position: relative; }
.tip {
  position: absolute; z-index: 100; max-width: 320px; background: var(--ink); color: var(--bg);
  font-family: var(--sans); font-size: 0.84375rem; line-height: 1.45; padding: 10px 12px; border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,.25); pointer-events: none; opacity: 0; transition: opacity .12s;
}
.tip.show { opacity: 1; }
.tip b { color: var(--bg); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 24px 0; }
table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: 0.90625rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 700; }
tr:hover td { background: var(--bg-2); }

/* ---------- chips & grid cards ---------- */
.chip { display: inline-block; font-family: var(--sans); font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--bg-2); color: var(--ink-2); border: 1px solid var(--rule); margin: 0 4px 4px 0; }
.chip.vision { background: var(--green-soft); color: var(--green); border-color: transparent; }
.chip.lm { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.chip.method { background: var(--purple-soft); color: var(--purple); border-color: transparent; }
.chip.theory { background: var(--yellow-soft); color: var(--yellow); border-color: transparent; }
.chip.safety { background: var(--red-soft); color: var(--red); border-color: transparent; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin: 24px 0; }
.card { border: 1px solid var(--rule); background: var(--panel); border-radius: 12px; padding: 16px; font-family: var(--sans); font-size: 0.90625rem; line-height: 1.5; }
.card h4 { margin: 0 0 6px; font-size: 0.96875rem; }
.card p { margin: 0; color: var(--ink-2); }
a.card { text-decoration: none; color: inherit; transition: transform .15s, box-shadow .15s, border-color .15s; display: block; }
a.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }

/* ---------- chapter footer nav ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 80px; font-family: var(--sans); }
.pager a { border: 1px solid var(--rule); border-radius: 12px; padding: 14px 18px; text-decoration: none; color: var(--ink); background: var(--panel); }
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; color: var(--ink-3); font-size: 0.75rem; text-transform: uppercase; letter-spacing: .08em; }
.pager .next { text-align: right; grid-column: 2; }

/* ---------- references ---------- */
.refs { font-family: var(--sans); font-size: 0.875rem; color: var(--ink-2); }
.refs li { margin-bottom: 8px; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: 3.5rem; left: 0; width: 290px; background: var(--bg); z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  body.toc-open .sidebar { transform: none; }
  #tocToggle { display: inline-block; }
  .wide, .widget.wide, figure.wide { width: auto; max-width: 100%; margin-left: 0; transform: none; }
  main { padding: 32px 16px 80px; }
  h1 { font-size: 2.125rem; }
  .lede { font-size: 1.1875rem; }
  body { font-size: 1.125rem; }
  .topbar .crumb { display: none; }
}
@media (max-width: 560px) {
  .paper { grid-template-columns: 1fr; gap: 4px; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
}

/* ---------- overflow guards ---------- */
.widget, figure.panel { overflow-x: auto; }
.widget:not(.wide), figure.panel:not(.wide) { max-width: 100%; }
@media (max-width: 960px) { .widget.wide, figure.panel.wide { max-width: 100%; } }
p.math { white-space: normal; }
@media (max-width: 960px) { .article { overflow-wrap: break-word; } }

/* dated "Update" boxes added during review */
.callout.update { background: var(--green-soft); border-color: var(--green); }
.callout.update .label { color: var(--green); }

/* Full-width layout: content fills the viewport on any screen size */
.layout { max-width: none; }
.article { max-width: none; }
.wide, .widget.wide, figure.wide, figure.panel.wide { width: auto; max-width: 100%; margin-left: 0; transform: none; }
