/* ==========================================================================
   Ledger & Candle: "paper" theme (light only)
   A printed-textbook look: warm paper sheet on a desk, serif reading type,
   book-style tables, worked-example boxes, margin-note callouts.
   Every page uses only the classes below; restyle here, not in the HTML.
   ========================================================================== */

:root {
  color-scheme: light;
  /* paper & ink */
  --desk: #e9e3d6;          /* background around the sheet */
  --paper: #fcfaf4;         /* the page itself */
  --paper-2: #f5f0e4;       /* tinted panels, code */
  --paper-3: #efe8d8;       /* table header, hover */
  --ink: #23201b;           /* body text */
  --ink-2: #4b463e;         /* secondary text */
  --muted: #7a7366;         /* captions, meta */
  --rule: #ddd4c2;          /* hairlines */
  --rule-strong: #3a352d;   /* table top/bottom rules */
  /* accents */
  --accent: #8c2f1f;        /* oxblood: kickers, numbers, labels */
  --link: #1f4f8a;          /* blue-black ink for links */
  --up: #2c6e3f;
  --down: #a3301d;
  /* callout tints */
  --note: #2f5d8f;  --note-bg: #eef1f1;
  --tip: #3d7146;   --tip-bg: #edf2e5;
  --warn: #a8691b;  --warn-bg: #f8eedb;
  --danger: #a3301d; --danger-bg: #f6e5df;
  /* type */
  --serif: "Literata", "Iowan Old Style", Georgia, serif;          /* reading text: built for long-form screen reading */
  --display: "Newsreader", "Literata", Georgia, serif;             /* headings + wordmark */
  --sans: "Geist", -apple-system, "Segoe UI", sans-serif;          /* labels, tables, UI */
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --flame: #c98a1b;         /* brand: the candle flame */
  --measure: 720px;
  --sheet-pad: 64px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font: 17.5px/1.7 var(--serif);
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
}
::selection { background: #f1dfae; }

a { color: var(--link); text-decoration: underline; text-decoration-color: #1f4f8a55; text-underline-offset: 2px; }
a:hover { text-decoration-color: currentColor; }
img { max-width: 100%; height: auto; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 24px;
  background: rgba(252, 250, 244, .94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule);
  font: 500 13px/1.2 var(--sans);
  letter-spacing: .02em;
}
.topbar a { text-decoration: none; color: var(--ink-2); }
.topbar a:hover { color: var(--accent); }
.topbar .home { display: inline-flex; align-items: center; gap: 9px; font: 600 18px/1 var(--display); color: var(--ink); letter-spacing: -.005em; white-space: nowrap; }
.topbar .home img { display: block; flex: none; }
.topbar .home em, .colophon em, .amp { font-style: italic; font-weight: 500; color: var(--accent); }
.topbar a.home:hover { color: var(--ink); }
.topbar .navlinks { display: flex; align-items: center; gap: 20px; white-space: nowrap; }
/* the switch between the two halves of the app: the course and the research desk */
.topbar .navlinks .nav-app { padding-left: 18px; border-left: 1px solid var(--rule); color: var(--accent); font-weight: 600; }
.topbar .navlinks a[aria-current] { color: var(--ink); text-decoration: underline 2px var(--accent); text-underline-offset: 7px; }
.topbar .sublabel { font: 500 11px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  border-left: 1px solid var(--rule); padding-left: 10px; margin-left: 2px; }
.progress { position: absolute; left: 0; bottom: -1px; height: 2px; width: 0; background: var(--accent); transition: width .1s linear; }

/* ---------- the sheet ---------- */
main {
  position: relative;
  max-width: calc(var(--measure) + 2 * var(--sheet-pad));
  margin: 36px auto 64px;
  padding: 56px var(--sheet-pad) 72px;
  background: var(--paper);
  border: 1px solid #ddd5c4;
  border-radius: 3px;
  box-shadow: 0 1px 1px rgba(60, 45, 20, .06), 0 10px 34px -8px rgba(60, 45, 20, .18);
}

/* ---------- chapter head ---------- */
header.chapter-head { margin: 0 0 36px; padding-bottom: 28px; border-bottom: 1px solid var(--rule); }
.chapter-head .kicker {
  font: 600 12.5px/1 var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--accent);
}
h1, h2, h3, h4 { font-family: var(--display); color: var(--ink); font-optical-sizing: auto; }
h1 { font-size: 2.75rem; line-height: 1.08; font-weight: 600; letter-spacing: -.015em; margin: 14px 0 14px; }
.meta { font: italic 15px/1.5 var(--serif); color: var(--muted); margin: 0; }

h2 {
  font-size: 1.75rem; line-height: 1.2; font-weight: 600; letter-spacing: -.01em;
  margin: 64px 0 14px; padding-top: 22px; position: relative;
}
h2::before { /* short printer's rule above each section */
  content: ""; position: absolute; top: 0; left: 0; width: 44px; height: 3px; background: var(--accent);
}
h3 { font-size: 1.3rem; font-weight: 600; line-height: 1.3; margin: 38px 0 8px; }
h4 { font: 600 1.02rem/1.35 var(--sans); margin: 26px 0 6px; color: var(--ink); }
p { margin: 0 0 1.05em; hyphens: auto; }
ul, ol { padding-left: 1.4em; }
li { margin: .25em 0; }
li::marker { color: var(--muted); }
strong { font-weight: 650; }
em { font-style: italic; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 40px 0; }
sup, sub { line-height: 0; }

/* ---------- table of contents ---------- */
.toc {
  font: 14.5px/1.5 var(--sans);
  background: var(--paper-2);
  border-top: 2px solid var(--rule-strong);
  border-bottom: 1px solid var(--rule);
  padding: 16px 22px 14px;
  margin: 0 0 8px;
}
.toc strong { display: block; font: 600 11.5px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); margin-bottom: 10px; }
.toc ol { margin: 0; padding-left: 0; list-style: none; counter-reset: toc; columns: 2; column-gap: 32px; }
.toc li { counter-increment: toc; break-inside: avoid; padding-left: 28px; position: relative; margin: 4px 0; }
.toc li::before { content: counter(toc, decimal-leading-zero); position: absolute; left: 0; font: 500 12px/1.9 var(--mono); color: var(--muted); }
.toc li ol, .toc li ul { columns: 1; margin-top: 2px; }
.toc a { color: var(--ink-2); text-decoration: none; }
.toc a:hover, .toc a.active { color: var(--accent); }

/* Wide screens: contents become a sticky margin column beside the sheet */
@media (min-width: 1300px) {
  .toc {
    position: fixed; top: 84px;
    left: max(8px, calc(50% - (var(--measure) / 2) - var(--sheet-pad) - 226px));
    width: 202px; max-height: calc(100vh - 110px); overflow-y: auto;
    background: transparent; border: 0; padding: 0 4px 24px 0; font-size: 13px;
    scrollbar-width: none;
  }
  .toc::-webkit-scrollbar { display: none; }
  .toc ol { columns: 1; }
  .toc li { padding-left: 26px; margin: 2px 0; }
  .toc a { display: block; padding: 3px 0 3px 0; border-left: 2px solid transparent; }
  .toc li::before { line-height: 2; }
  .toc a.active { color: var(--accent); font-weight: 600; }
}

/* ---------- callouts (margin-note style) ---------- */
.callout {
  margin: 26px 0; padding: 14px 20px 14px 20px;
  background: var(--note-bg);
  border-left: 3px solid var(--note);
  font-size: 16.5px; line-height: 1.62;
}
.callout-title {
  font: 600 11.5px/1.2 var(--sans); letter-spacing: .14em; text-transform: uppercase;
  color: var(--note); margin-bottom: 6px;
}
.callout.tip { background: var(--tip-bg); border-color: var(--tip); }
.callout.tip .callout-title { color: var(--tip); }
.callout.warn { background: var(--warn-bg); border-color: var(--warn); }
.callout.warn .callout-title { color: var(--warn); }
.callout.danger { background: var(--danger-bg); border-color: var(--danger); }
.callout.danger .callout-title { color: var(--danger); }
.callout > :last-child, .callout p:last-child { margin-bottom: 0; }

/* ---------- formula ---------- */
.formula {
  margin: 26px 0; padding: 14px 8px 16px;
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
  text-align: center; overflow-x: auto; font-size: 1.05em;
}
.formula .label {
  display: block; text-align: left; margin: 0 0 6px 4px;
  font: 600 11px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--accent);
}
/* "where" list under a formula: one row per symbol, then an optional "how it works" note */
.formula > p, .formula .vars, .formula .how { text-align: left; font-size: .95em; margin-left: 4px; margin-right: 4px; }
.formula .vars {
  display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px;
  margin-top: 14px; margin-bottom: 0; padding-top: 12px; border-top: 1px dashed var(--rule);
}
.formula .vars::before {
  content: "where"; grid-column: 1 / -1;
  font: 600 11px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
}
.formula .vars dt { margin: 0; color: var(--ink); white-space: nowrap; }
.formula .vars dd { margin: 0; color: var(--ink-2); }
.formula .how { margin-top: 12px; margin-bottom: 0; color: var(--ink-2); }
.formula .how > strong:first-child { color: var(--ink); }
.formula ol.how { padding-left: 1.4em; }
@media (max-width: 600px) {
  .formula .vars { grid-template-columns: 1fr; gap: 2px; }
  .formula .vars dd { margin-bottom: 8px; }
}
.katex { font-size: 1.06em; }
.katex-display { margin: .5em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

/* ---------- worked example ---------- */
.example {
  margin: 34px 0; padding: 22px 26px 18px;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  box-shadow: 4px 4px 0 var(--paper-3);
  position: relative;
}
.example .tag {
  position: absolute; top: -10px; left: 18px;
  padding: 2px 10px; background: var(--paper);
  font: 600 11.5px/16px var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--accent);
}
.example > .tag + h3, .example > .tag + h4, .example > h3:first-child, .example > h4:first-child { margin-top: 4px; }
.example h4 { font: 600 1.15rem/1.3 var(--display); }
.example > :last-child { margin-bottom: 0; }

/* ---------- numbered steps ---------- */
.steps { counter-reset: s; list-style: none; padding-left: 0; margin: 14px 0; }
.steps > li { counter-increment: s; position: relative; padding-left: 40px; margin: 12px 0; }
.steps > li::before {
  content: counter(s); position: absolute; left: 0; top: 2px;
  width: 25px; height: 25px; border-radius: 50%;
  border: 1.5px solid var(--accent); color: var(--accent); background: var(--paper);
  font: 600 12.5px/22px var(--sans); text-align: center;
}

/* ---------- tables (booktabs) ---------- */
.table-wrap { overflow-x: auto; margin: 24px 0; -webkit-overflow-scrolling: touch; }
table {
  width: 100%; border-collapse: collapse;
  font: 14.5px/1.45 var(--sans); font-variant-numeric: tabular-nums lining-nums;
  border-top: 2px solid var(--rule-strong); border-bottom: 2px solid var(--rule-strong);
  background: transparent;
}
th, td { padding: 7px 10px; text-align: left; vertical-align: top; border: 0; }
th {
  font-weight: 600; font-size: 12.5px; letter-spacing: .03em; color: var(--ink);
  background: var(--paper-2); border-bottom: 1px solid var(--rule-strong);
}
td { border-bottom: 1px solid var(--rule); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td, table tr:hover td { background: #faf5e8; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.num { font-size: 14px; }
.up { color: var(--up); } .down { color: var(--down); }
td.up, td.down { font-weight: 500; }

/* ---------- figures ---------- */
figure { margin: 34px 0; }
figure img {
  display: block; width: 100%; height: auto;
  border: 1px solid var(--rule); border-radius: 2px; background: var(--paper);
}
figcaption {
  margin-top: 10px; padding-left: 12px; border-left: 2px solid var(--rule);
  font: 14px/1.5 var(--serif); font-style: italic; color: var(--muted);
}
figcaption strong, figcaption b { font-style: normal; color: var(--ink-2); }
@media (min-width: 1100px) { /* let charts and wide tables breathe a little wider than the text */
  figure { margin-left: -24px; margin-right: -24px; }
  .table-wrap { margin-left: calc(-1 * var(--sheet-pad) + 16px); margin-right: calc(-1 * var(--sheet-pad) + 16px); }
  figcaption { margin-left: 24px; margin-right: 24px; }
}

/* ---------- code ---------- */
code { font: 0.84em/1 var(--mono); background: var(--paper-2); padding: 2px 5px; border-radius: 3px; color: #5a2a1a; }
pre {
  margin: 22px 0; padding: 16px 18px; overflow-x: auto;
  background: var(--paper-2); border: 1px solid var(--rule); border-left: 3px solid var(--rule-strong);
  font: 13px/1.6 var(--mono); color: var(--ink);
}
pre code { background: none; padding: 0; font-size: inherit; color: inherit; }

/* ---------- KPI strip ---------- */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  margin: 26px 0; border-top: 1px solid var(--rule-strong); border-bottom: 1px solid var(--rule-strong);
}
.kpi { padding: 14px 16px; border-right: 1px solid var(--rule); background: transparent; }
.kpi:last-child { border-right: 0; }
.kpi .v { font: 600 1.6rem/1.1 var(--display); color: var(--ink); font-variant-numeric: tabular-nums lining-nums; }
.kpi .l { margin-top: 6px; font: 600 11px/1.3 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

/* ---------- key takeaways ---------- */
.takeaways {
  margin: 30px 0; padding: 20px 26px 12px;
  background: var(--paper-2);
  border-top: 3px double var(--rule-strong); border-bottom: 3px double var(--rule-strong);
}
.takeaways > strong:first-child {
  display: block; margin-bottom: 8px;
  font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--accent);
}
.takeaways li { margin: .45em 0; }

/* ---------- quiz ---------- */
details.quiz {
  margin: 0; padding: 14px 4px 14px 0;
  border-top: 1px dashed var(--rule); background: transparent;
}
details.quiz + :not(details.quiz) { margin-top: 24px; }
details.quiz:last-of-type { border-bottom: 1px dashed var(--rule); }
details.quiz summary {
  cursor: pointer; list-style: none; position: relative; padding-left: 30px;
  font: 600 16.5px/1.5 var(--serif); color: var(--ink);
}
details.quiz summary::-webkit-details-marker { display: none; }
details.quiz summary::before {
  content: "+"; position: absolute; left: 0; top: 1px;
  width: 20px; height: 20px; border: 1px solid var(--rule-strong); border-radius: 2px;
  font: 600 14px/18px var(--sans); text-align: center; color: var(--ink-2);
}
details.quiz[open] summary::before { content: "−"; background: var(--ink); color: var(--paper); }
details.quiz summary:hover { color: var(--accent); }
details.quiz .answer {
  margin: 12px 0 2px 30px; padding: 10px 16px;
  border-left: 2px solid var(--tip); background: var(--tip-bg); font-size: 16.5px;
}
details.quiz .answer > :last-child { margin-bottom: 0; }

/* ---------- checklist ---------- */
.checklist { list-style: none; padding-left: 0; }
.checklist li { position: relative; padding-left: 30px; margin: 8px 0; }
.checklist li::before {
  content: ""; position: absolute; left: 2px; top: .42em;
  width: 13px; height: 13px; border: 1.5px solid var(--ink-2); border-radius: 2px;
}

/* ---------- misc ---------- */
.pill { display: inline-block; font: 500 12px/1.4 var(--sans); padding: 1px 8px; border: 1px solid var(--rule-strong); border-radius: 99px; color: var(--ink-2); }
.sources {
  margin-top: 30px; padding-top: 14px; border-top: 1px solid var(--rule);
  font: 14px/1.6 var(--sans); color: var(--muted);
}
.sources a { color: var(--ink-2); }

.chapter-nav {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  margin-top: 64px; padding-top: 22px; border-top: 2px solid var(--rule-strong);
  font: 600 14px/1.3 var(--sans);
}
.chapter-nav a {
  display: block; padding: 14px 18px; text-decoration: none; color: var(--ink);
  border: 1px solid var(--rule-strong); border-radius: 2px; background: var(--paper);
  box-shadow: 3px 3px 0 var(--paper-3); transition: transform .12s, box-shadow .12s;
}
.chapter-nav a:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--rule); color: var(--accent); }
.chapter-nav a:last-child { text-align: right; }
.chapter-nav a:only-child { grid-column: 2; }
.chapter-nav a span { display: block; margin-top: 4px; font: 500 15px/1.3 var(--display); color: var(--ink-2); }

.to-top {
  position: fixed; right: 22px; bottom: 22px; z-index: 15;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--rule-strong); background: var(--paper); color: var(--ink);
  font: 600 16px/38px var(--sans); text-align: center; text-decoration: none;
  box-shadow: 0 4px 14px rgba(60, 45, 20, .15);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.to-top.show { opacity: 1; pointer-events: auto; }

/* ---------- home page (title page + contents) ---------- */
.title-page { text-align: center; padding: 22px 0 34px; border-bottom: 1px solid var(--rule); margin-bottom: 30px; }
.title-page .kicker { font: 600 12px/1 var(--sans); letter-spacing: .2em; text-transform: uppercase; color: var(--accent); line-height: 1.5; text-wrap: balance; }
.title-page .brand-mark { display: block; margin: 0 auto 22px; }
.title-page h1 { font-size: 3.9rem; margin: 18px 0 12px; letter-spacing: -.02em; }
.title-page .subtitle { font: italic 1.2rem/1.5 var(--serif); color: var(--ink-2); max-width: 560px; margin: 0 auto 18px; }
.title-page .ornament { color: var(--accent); letter-spacing: .6em; font-size: 14px; }
.stats { display: flex; justify-content: center; flex-wrap: wrap; gap: 0; margin-top: 22px; }
.stats div { padding: 0 22px; border-right: 1px solid var(--rule); font: 13px/1.3 var(--sans); color: var(--muted); }
.stats div:last-child { border-right: 0; }
.stats b { display: block; font: 600 1.5rem/1.2 var(--display); color: var(--ink); }

.contents { margin: 10px 0 0; }
.contents .part {
  margin: 38px 0 6px; padding-bottom: 6px; border-bottom: 1px solid var(--rule-strong);
  font: 600 12px/1 var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--accent);
}
.contents a.entry {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 4px 12px; align-items: baseline;
  padding: 14px 6px; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--rule);
}
.contents a.entry:hover { background: var(--paper-2); }
.contents a.entry:hover .t { color: var(--accent); }
.contents .n { font: 500 15px/1 var(--mono); color: var(--accent); }
.contents .t { font: 600 1.22rem/1.3 var(--display); }
.contents .time { font: 13px/1 var(--sans); color: var(--muted); white-space: nowrap; }
.contents .d { grid-column: 2 / 4; font-size: 15.5px; line-height: 1.5; color: var(--ink-2); }

/* legacy card grid (kept in case any page uses it) */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.card { display: block; background: var(--paper); border: 1px solid var(--rule-strong); padding: 16px; text-decoration: none; color: var(--ink); box-shadow: 3px 3px 0 var(--paper-3); }
.card .num { font: 600 13px var(--mono); color: var(--accent); }
.card h3 { margin: 6px 0; font-size: 1.1rem; }
.card p { margin: 0; font-size: 14.5px; color: var(--muted); }

/* ---------- colophon (site footer) ---------- */
.colophon {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  max-width: calc(var(--measure) + 2 * var(--sheet-pad)); margin: -40px auto 48px; padding: 0 16px;
  font: 13px/1.5 var(--sans); color: var(--muted); text-align: left;
}
.colophon img { flex: none; }
.colophon b { font: 600 15px/1 var(--display); color: var(--ink-2); }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  :root { --sheet-pad: 28px; }
  main { margin: 0 auto; border-left: 0; border-right: 0; border-radius: 0; box-shadow: none; padding-top: 34px; }
  body { background: var(--paper); }
  .toc ol { columns: 1; }
  .colophon { margin-top: 0; padding: 18px 16px 28px; border-top: 1px solid var(--rule); align-items: flex-start; }
}
@media (max-width: 600px) {
  :root { --sheet-pad: 16px; }
  body { font-size: 17px; }
  h1 { font-size: 2.05rem; }
  h2 { font-size: 1.45rem; margin-top: 48px; }
  .title-page h1 { font-size: 2.6rem; }
  .topbar { padding: 10px 16px; }
  .topbar .navlinks { gap: 14px; }
  .topbar .navlinks .nav-opt { display: none; }
  .topbar .navlinks .nav-app { padding-left: 14px; }
  .example { padding: 20px 16px 14px; box-shadow: none; }
  .callout { padding: 12px 14px; }
  .chapter-nav { grid-template-columns: 1fr; }
  .chapter-nav a:only-child { grid-column: 1; }
  .chapter-nav a:last-child { text-align: left; }
  .contents a.entry { grid-template-columns: 34px 1fr; }
  .contents .time { grid-column: 2; }
  .contents .d { grid-column: 2; }
  .stats div { padding: 6px 12px; }
}

/* ---------- print: it is paper, after all ---------- */
@media print {
  body { background: #fff; font-size: 11pt; }
  .topbar, .to-top, .progress, .chapter-nav { display: none !important; }
  .colophon { margin: 24px 0 0; }
  main { box-shadow: none; border: 0; margin: 0; padding: 0; max-width: none; }
  .toc { position: static; columns: 2; }
  details.quiz .answer { display: block; }
  figure, .example, table, .formula { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}

/* tables too wide for the sheet get a compact setting (class added by site.js) */
table.dense { font-size: 12.5px; }
table.dense th { font-size: 11.5px; }
table.dense th, table.dense td { padding: 5px 7px; }
table.dense td.num { font-size: 12.5px; }

/* inline formula wider than the column (class added by site.js) */
.katex.katex-wide { display: block; max-width: 100%; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
main { overflow-wrap: break-word; }
/* KaTeX's hidden MathML copy is absolutely positioned; keep it inside its scroll container */
.table-wrap, .formula, .katex-display, .katex { position: relative; }

/* ---------- reading aids added by site.js ---------- */
/* keyboard focus */
a:focus-visible, button:focus-visible, summary:focus-visible, img.zoomable:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px;
}

/* short table cells (dates, numbers) stay on one line */
td.nw, th.nw { white-space: nowrap; }
/* wide tables: soft shadows at the edge that still has more columns to scroll to */
.table-wrap.scrolls {
  background:
    linear-gradient(to right, var(--paper) 30%, rgba(252, 250, 244, 0)) left / 36px 100% no-repeat local,
    linear-gradient(to left, var(--paper) 30%, rgba(252, 250, 244, 0)) right / 36px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(60, 45, 20, .22), transparent) left / 12px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(60, 45, 20, .22), transparent) right / 12px 100% no-repeat scroll;
}
.table-wrap.scrolls::after {
  content: "Scroll sideways for more columns →"; display: block; position: sticky; left: 0;
  padding-top: 6px; font: italic 12.5px/1.3 var(--serif); color: var(--muted);
}

/* charts open full size */
img.zoomable { cursor: zoom-in; }
body.lb-open { overflow: hidden; }
.lightbox {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column;
  background: rgba(35, 32, 27, .92);
}
.lightbox .lb-scroll { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; background: var(--paper); cursor: zoom-in; border-radius: 2px; }
.lightbox.zoomed .lb-scroll { display: block; }
.lightbox.zoomed img { max-width: none; max-height: none; width: auto; cursor: zoom-out; }
.lightbox .lb-bar {
  display: flex; align-items: center; gap: 14px; padding: 10px 16px;
  background: var(--paper); font: 13px/1.4 var(--sans); color: var(--ink-2);
}
.lightbox .lb-bar > span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lightbox .lb-hint { color: var(--muted); white-space: nowrap; }
.lightbox .lb-close {
  flex: none; width: 34px; height: 34px; border: 1px solid var(--rule-strong); border-radius: 50%;
  background: var(--paper); color: var(--ink); font: 500 20px/1 var(--sans); cursor: pointer;
}

/* chapter contents toggle (folds on narrow screens) */
.toc-toggle {
  display: flex; align-items: baseline; justify-content: space-between; width: 100%;
  margin: 0 0 10px; padding: 0; border: 0; background: none; cursor: default; text-align: left;
  font: 600 11.5px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--accent);
}
.toc-toggle .toc-count { display: none; }
@media (max-width: 820px) {
  .toc-toggle { margin: 0; padding: 4px 0; cursor: pointer; }
  .toc-toggle .toc-count { display: inline; font-weight: 500; letter-spacing: .04em; text-transform: none; color: var(--muted); font-size: 13px; }
  .toc-toggle .toc-count::after { content: " ▾"; }
  .toc.open .toc-toggle .toc-count::after { content: " ▴"; }
  .toc > ol { display: none; margin-top: 10px; }
  .toc.open > ol { display: block; }
  .lightbox .lb-hint { display: none; }
}

/* reading progress on the contents page */
.contents .status { display: block; margin-top: 6px; font: 600 11.5px/1 var(--sans); letter-spacing: .04em; color: var(--muted); text-align: right; }
.contents .status.done { color: var(--up); }
.title-page .continue {
  display: inline-block; margin-top: 26px; padding: 12px 20px; text-decoration: none;
  border: 1px solid var(--rule-strong); border-radius: 2px; background: var(--paper);
  box-shadow: 3px 3px 0 var(--paper-3); font: 600 15px/1.3 var(--display); color: var(--ink);
}
.title-page .continue small { display: block; font: 600 11px/1.4 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.title-page .continue:hover { color: var(--accent); }

/* "resume where you left off" prompt */
.resume {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 16;
  display: flex; align-items: center; gap: 4px; padding: 4px 4px 4px 6px;
  background: var(--ink); border-radius: 99px; box-shadow: 0 6px 20px rgba(60, 45, 20, .25);
  font: 500 13.5px/1 var(--sans);
}
.resume button { border: 0; background: none; color: var(--paper); font: inherit; padding: 8px 12px; cursor: pointer; }
.resume .resume-x { padding: 8px 10px; font-size: 16px; opacity: .7; }

@media print {
  .resume, .lightbox, .toc-toggle .toc-count { display: none !important; }
  .toc > ol { display: block !important; }
  .table-wrap.scrolls::after { content: none; }
}

/* ---------- sub-chapters: one section of a chapter at a time (site.js) ---------- */
body.subchapters:not(.one-page) section.sub:not(.current) { display: none; }
body.subchapters:not(.one-page) main > .chapter-nav { display: none; }   /* the pager links chapters at either end */
body.subchapters:not(.one-page) section.sub { padding-top: 40px; }
body.subchapters:not(.one-page) section.sub > h2 { margin-top: 0; scroll-margin-top: 68px; } /* a #s5 link lands with the kicker in view */
.sub-kicker { font: 600 11.5px/1.4 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; }
.one-page .sub-kicker, .one-page .sub-nav { display: none; }
.sub-nav a span { overflow-wrap: anywhere; }

/* the contents block becomes a section bar: current section, a rail of sections, the list */
.sec-toggle {
  display: flex; align-items: baseline; gap: 10px; width: 100%;
  margin: 0; padding: 0; border: 0; background: none; text-align: left; color: var(--ink);
  font: 500 14px/1.35 var(--sans); cursor: default;
}
.sec-label { font: 600 11.5px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.sec-count { margin-left: auto; font: 500 12px/1 var(--sans); color: var(--muted); white-space: nowrap; }
.sec-now { display: none; flex: 1; min-width: 0; }
.sec-now b { font: 500 12.5px/1 var(--mono); color: var(--accent); margin-right: 8px; }
.sec-now span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail { display: flex; gap: 2px; margin: 10px 0 12px; }
.rail i { flex: 1; height: 4px; border-radius: 1px; background: var(--rule); }
.rail i.read { background: var(--tip); }
.rail i.cur { background: var(--accent); }
.toc li.read::before { content: "✓"; color: var(--tip); font-family: var(--sans); font-weight: 600; }
.toc a[aria-current] { color: var(--accent); font-weight: 600; }
.view-toggle {
  display: block; margin: 12px 0 0; padding: 0; border: 0; background: none; cursor: pointer; text-align: left;
  font: 500 12.5px/1.4 var(--sans); color: var(--link); text-decoration: underline; text-decoration-color: #1f4f8a55; text-underline-offset: 2px;
}
.view-toggle:hover { text-decoration-color: currentColor; }

/* below the margin-column width the bar sticks under the top bar and the list drops down */
@media (max-width: 1299px) {
  body.subchapters .toc {
    position: sticky; top: var(--topbar-h, 49px); z-index: 18;
    margin: 0 calc(-1 * var(--sheet-pad)) 8px; padding: 0 var(--sheet-pad);
    border-top: 0; border-bottom: 1px solid var(--rule);
    box-shadow: 0 6px 12px -10px rgba(60, 45, 20, .35);
  }
  body.subchapters .sec-toggle { padding: 12px 0 0; cursor: pointer; align-items: center; }
  body.subchapters .sec-label, body.subchapters .sec-count { display: none; }
  body.subchapters .sec-now { display: flex; align-items: baseline; }
  body.subchapters .sec-toggle::after { content: "▾"; flex: none; color: var(--muted); font-size: 13px; }
  body.subchapters .toc.open .sec-toggle::after { content: "▴"; }
  body.subchapters .rail { margin: 9px 0 0; padding-bottom: 10px; }
  body.subchapters .toc > ol, body.subchapters .toc .view-toggle { display: none; }
  body.subchapters .toc.open > ol {
    display: block; columns: auto; max-height: min(60vh, 480px); overflow: hidden auto; overscroll-behavior: contain;
    margin: 0; padding: 4px 0 4px; border-top: 1px solid var(--rule);
  }
  body.subchapters .toc.open > ol a { display: block; padding: 4px 0; }
  body.subchapters .toc.open .view-toggle { display: block; margin: 0; padding: 10px 0 12px; border-top: 1px solid var(--rule); width: 100%; text-align: left; }
}

/* contents page: progress meter under each chapter's time */
.contents .status .meter { display: block; width: 64px; height: 3px; margin: 5px 0 0 auto; background: var(--rule); border-radius: 1px; overflow: hidden; }
.contents .status .meter::before { content: ""; display: block; height: 100%; width: var(--p, 0); background: var(--tip); }
.title-page .continue .where { display: block; margin-top: 4px; font: 13px/1.4 var(--sans); color: var(--muted); }

@media print {
  body.subchapters section.sub { display: block !important; padding-top: 0; }
  body.subchapters section.sub > h2 { margin-top: 64px; }
  .sub-kicker, .sub-nav, .sec-toggle, .rail, .view-toggle { display: none !important; }
  body.subchapters .toc { position: static; margin: 0 0 8px; padding: 16px 0; box-shadow: none; }
}

/* margin column: one line per section so a 20-odd section list fits the screen;
   the full title shows on hover (title attribute set by site.js) */
@media (min-width: 1300px) {
  body.subchapters .toc li { margin: 0; }
  body.subchapters .toc a { padding: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body.subchapters .toc a[aria-current] { white-space: normal; }
  body.subchapters .toc li::before { line-height: 1.85; }
  body.subchapters .toc {
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent);
  }
  body.subchapters .sec-toggle { align-items: center; }
  body.subchapters .sec-label { white-space: nowrap; }
  body.subchapters .toc {    /* use the spare margin on big screens, so fewer titles are cut short */
    --toc-w: clamp(202px, calc(50vw - 470px), 300px);
    width: var(--toc-w);
    left: max(12px, calc(50% - (var(--measure) / 2) - var(--sheet-pad) - 24px - var(--toc-w)));
  }
}
