/* =============================================================================
   The AI Founder's Handbook — design system
   Editorial + modern polish. Warm paper, ink type, one restrained accent.
   Light is the default; dark is a first-class citizen.
   ============================================================================= */

/* ---------- Design tokens ---------- */
:root {
  /* palette — light (warm paper) */
  --paper:      #FAF7F0;
  --paper-2:    #F3ECDD;   /* asides, code, table zebra */
  --paper-3:    #ECE3D0;   /* hover, deeper fills */
  --ink:        #201C16;   /* body text (warm near-black) */
  --ink-2:      #48423A;   /* secondary text */
  --muted:      #6E675B;   /* labels, meta, captions */
  --rule:       #E4DAC6;   /* hairlines */
  --rule-2:     #D7CBB2;

  --accent:     #234B7A;   /* deep ink-blue — links, marks */
  --accent-ink: #1B3A60;
  --accent-bg:  #E9EEF5;

  --rust:       #A4472A;   /* warnings */
  --rust-bg:    #F6E7DF;
  --sage:       #4B6B4E;   /* definitions */
  --sage-bg:    #E6EDE2;
  --gold:       #8A6D1F;   /* founder's rule */
  --gold-bg:    #F3EAD2;

  /* type */
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans:  "Space Grotesk", ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono:  "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --measure: 40rem;        /* ~66 characters */
  --gutter: 16.5rem;       /* right margin reserved for sidenotes */
  --sidebar-w: 19rem;

  /* motion + depth */
  --shadow-1: 0 1px 2px rgba(32,28,22,.06), 0 4px 16px rgba(32,28,22,.06);
  --shadow-2: 0 8px 40px rgba(32,28,22,.16);
  --radius: 10px;
  --ease: cubic-bezier(.2,.6,.2,1);
}

:root[data-theme="dark"] {
  --paper:      #14120C;
  --paper-2:    #1D1A12;
  --paper-3:    #262117;
  --ink:        #F4EFE6;
  --ink-2:      #E8E1D2;
  --muted:      #CDC4B0;
  --rule:       #38331F;
  --rule-2:     #47412F;

  --accent:     #9CBDEC;
  --accent-ink: #BcD2F3;
  --accent-bg:  #1A2436;

  --rust:       #E39A7C;   --rust-bg: #2B1E17;
  --sage:       #9CC49B;   --sage-bg: #172219;
  --gold:       #D9BC6E;   --gold-bg: #241F12;

  --shadow-1: 0 1px 2px rgba(0,0,0,.4), 0 6px 22px rgba(0,0,0,.4);
  --shadow-2: 0 12px 48px rgba(0,0,0,.6);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:#14120C; --paper-2:#1D1A12; --paper-3:#262117;
    --ink:#F4EFE6; --ink-2:#E8E1D2; --muted:#CDC4B0;
    --rule:#38331F; --rule-2:#47412F;
    --accent:#9CBDEC; --accent-ink:#BCD2F3; --accent-bg:#1A2436;
    --rust:#E39A7C; --rust-bg:#2B1E17; --sage:#9CC49B; --sage-bg:#172219;
    --gold:#D9BC6E; --gold-bg:#241F12;
    --shadow-1:0 1px 2px rgba(0,0,0,.4),0 6px 22px rgba(0,0,0,.4);
    --shadow-2:0 12px 48px rgba(0,0,0,.6);
  }
}

/* ---------- Reset ---------- */
*,*::before,*::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 5rem; }
@media (prefers-reduced-motion: reduce){ html{ scroll-behavior:auto; } }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.18rem;
  line-height: 1.7;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "kern" 1, "liga" 1, "onum" 1;
  transition: background .3s var(--ease), color .3s var(--ease);
}
img,svg { max-width: 100%; height: auto; }
::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* ---------- Reading progress ---------- */
.progress {
  position: fixed; inset: 0 auto auto 0; height: 3px; width: 0%;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb,var(--accent) 55%, var(--rust)));
  z-index: 60; transition: width .1s linear;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 1rem;
  height: 3.6rem; padding: 0 clamp(1rem,3vw,1.6rem);
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.topbar .brand {
  font-family: var(--sans); font-weight: 600; font-size: .82rem;
  letter-spacing: .14em; text-transform: uppercase; color: var(--ink);
  text-decoration: none; white-space: nowrap;
}
.topbar .brand b { color: var(--accent); }
.topbar .spacer { flex: 1; }
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  height: 2.2rem; min-width: 2.2rem; padding: 0 .7rem;
  border: 1px solid var(--rule-2); border-radius: 999px;
  background: var(--paper); color: var(--ink-2);
  font-family: var(--sans); font-size: .78rem; cursor: pointer;
  transition: border-color .2s, color .2s, background .2s;
}
.iconbtn:hover { color: var(--accent); border-color: var(--accent); }
.iconbtn kbd {
  font-family: var(--mono); font-size: .66rem; color: var(--muted);
  border: 1px solid var(--rule-2); border-radius: 4px; padding: .05rem .3rem;
}
.menu-toggle { display: none; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0,1fr); }
.sidebar {
  position: sticky; top: 3.6rem; align-self: start;
  max-height: calc(100vh - 3.6rem); overflow-y: auto; overscroll-behavior: contain;
  border-right: 1px solid var(--rule);
  padding: 1.6rem 1rem 4rem 1.4rem;
  background: color-mix(in srgb, var(--paper) 60%, var(--paper-2));
}
.content { min-width: 0; }

/* ---------- Sidebar navigation ---------- */
.toc-book {
  font-family: var(--sans); font-size: .7rem; letter-spacing: .16em;
  text-transform: uppercase; color: var(--muted); margin: 0 0 1rem .3rem;
}
.toc-part {
  font-family: var(--sans); font-size: .66rem; font-weight: 600; letter-spacing: .18em;
  text-transform: uppercase; color: var(--muted);
  margin: 1.5rem 0 .5rem .3rem; display: flex; gap: .5rem; align-items: baseline;
}
.toc-part .pnum { color: var(--accent); }
.toc a {
  display: block; text-decoration: none; color: var(--ink-2);
  font-family: var(--sans); font-size: .86rem; line-height: 1.3;
  padding: .34rem .5rem .34rem .55rem; border-radius: 7px;
  border-left: 2px solid transparent; transition: background .15s, color .15s;
}
.toc a .cnum { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: .5rem; font-size: .8em; }
.toc a:hover { background: var(--paper-3); color: var(--ink); }
.toc a.current { color: var(--accent); background: var(--accent-bg); border-left-color: var(--accent); font-weight: 600; }
.toc .subnav { margin: .1rem 0 .4rem .9rem; border-left: 1px solid var(--rule); display: none; }
.toc a.current + .subnav { display: block; }
.toc .subnav a { font-size: .78rem; color: var(--muted); padding: .2rem .5rem; border-left: 2px solid transparent; margin-left: -1px; }
.toc .subnav a:hover { color: var(--ink); background: transparent; }
.toc .subnav a.active { color: var(--accent); border-left-color: var(--accent); }

/* ---------- Reading column ---------- */
.reading { max-width: calc(var(--measure) + var(--gutter) + 3rem); margin: 0 auto; padding: 2.5rem clamp(1.1rem,5vw,3.5rem) 5rem; }
.prose { max-width: var(--measure); }
.prose > * { grid-column: 1; }

/* ---------- Chapter opener ---------- */
.chapter-head { max-width: var(--measure); margin-bottom: 2.6rem; }
.kicker {
  font-family: var(--sans); font-size: .72rem; font-weight: 600;
  letter-spacing: .2em; text-transform: uppercase; color: var(--accent);
  display: flex; align-items: center; gap: .8rem; margin-bottom: 1.4rem;
}
.kicker::after { content:""; flex:1; height:1px; background: var(--rule-2); }
.chapter-num {
  font-family: var(--sans); font-weight: 300; font-size: clamp(3.5rem,10vw,6rem);
  line-height: .9; color: var(--rule-2); letter-spacing: -.03em; margin: 0;
}
.chapter-title {
  font-family: var(--serif); font-weight: 600; font-size: clamp(2.1rem,5.5vw,3.2rem);
  line-height: 1.08; letter-spacing: -.015em; margin: .4rem 0 0;
  text-wrap: balance;
}
.chapter-dek {
  font-family: var(--serif); font-style: italic; font-size: 1.3rem;
  color: var(--ink-2); line-height: 1.5; margin: 1.1rem 0 0; max-width: 34rem;
  text-wrap: pretty;
}
.chapter-meta {
  font-family: var(--sans); font-size: .74rem; color: var(--muted);
  letter-spacing: .04em; margin-top: 1.3rem; display: flex; gap: 1.2rem; flex-wrap: wrap;
}

/* first paragraph: drop cap + no indent */
.prose .lede::first-letter {
  float: left; font-family: var(--serif); font-weight: 600;
  font-size: 3.9em; line-height: .78; padding: .06em .09em 0 0; color: var(--accent);
}
.prose .lede { font-size: 1.22rem; }

/* ---------- Headings ---------- */
.prose h2, .prose h3, .prose h4 { font-family: var(--sans); letter-spacing: -.01em; scroll-margin-top: 5rem; }
.prose h2 {
  font-size: 1.7rem; font-weight: 600; line-height: 1.2;
  margin: 3.2rem 0 1rem; padding-top: 1.4rem; border-top: 1px solid var(--rule);
  position: relative;
}
.prose h2 .secnum, .prose h3 .secnum {
  color: var(--accent); font-variant-numeric: tabular-nums;
  margin-right: .6rem; font-weight: 500;
}
.prose h3 { font-size: 1.28rem; font-weight: 600; margin: 2.3rem 0 .7rem; }
.prose h4 {
  font-size: .82rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); margin: 1.8rem 0 .6rem;
}
.anchor {
  opacity: 0; margin-left: .4rem; color: var(--muted); text-decoration: none;
  font-family: var(--sans); font-weight: 400; transition: opacity .15s;
}
.prose h2:hover .anchor, .prose h3:hover .anchor { opacity: 1; }
.anchor:hover { color: var(--accent); }

/* ---------- Body elements ---------- */
.prose p { margin: 0 0 1.15rem; }
.prose a { color: var(--accent); text-decoration: none; background-image: linear-gradient(var(--rule-2),var(--rule-2)); background-size: 100% 1px; background-repeat: no-repeat; background-position: 0 1.12em; transition: background-size .2s, color .2s; }
.prose a:hover { color: var(--accent-ink); background-image: linear-gradient(var(--accent),var(--accent)); }
.prose strong { font-weight: 600; }
.prose em { font-style: italic; }
.prose ul, .prose ol { margin: 0 0 1.2rem; padding-left: 1.4rem; }
.prose li { margin: .3rem 0; padding-left: .2rem; }
.prose li::marker { color: var(--accent); }
.prose ul li::marker { content: "\2013\00a0"; }
.prose hr { border: none; border-top: 1px solid var(--rule-2); margin: 2.6rem auto; width: 40%; }
.prose blockquote {
  margin: 1.6rem 0; padding: .2rem 0 .2rem 1.4rem; border-left: 3px solid var(--accent);
  font-style: italic; color: var(--ink-2);
}
.pullquote {
  font-family: var(--serif); font-weight: 500; font-style: normal;
  font-size: 1.7rem; line-height: 1.28; color: var(--ink);
  margin: 2.2rem 0; padding: 0; border: none; text-wrap: balance;
}
.pullquote::before { content: "\201C"; color: var(--accent); }

/* ---------- Sidenotes (Tufte-style margin notes) ---------- */
.sidenote-ref {
  font-family: var(--sans); font-size: .68em; font-weight: 600; color: var(--accent);
  vertical-align: super; line-height: 0; cursor: pointer; padding: 0 .1em;
}
.sidenote {
  float: right; clear: right; width: var(--gutter);
  margin-right: calc(-1 * var(--gutter) - 2.2rem); margin-bottom: 1.1rem;
  font-family: var(--sans); font-size: .78rem; line-height: 1.45; color: var(--ink-2);
  position: relative; padding-left: .9rem; border-left: 1px solid var(--rule-2);
}
.sidenote .sn-num { color: var(--accent); font-weight: 600; margin-right: .35em; }
.sidenote.case { border-left-color: var(--accent); }
.sidenote .sn-label {
  display: block; font-size: .62rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent); font-weight: 600; margin-bottom: .25rem;
}
.sidenote a { font-size: inherit; }
.sidenote-toggle { display: none; }

/* ---------- Callouts ---------- */
.callout {
  margin: 1.7rem 0; padding: 1.1rem 1.3rem 1.15rem; border-radius: var(--radius);
  border: 1px solid var(--rule-2); background: var(--paper-2);
  position: relative; font-size: 1.02rem; line-height: 1.6;
}
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout .co-label {
  font-family: var(--sans); font-size: .7rem; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; display: flex; align-items: center; gap: .5rem; margin-bottom: .55rem;
}
.callout .co-label svg { width: 1rem; height: 1rem; }
.callout.rule       { background: var(--gold-bg); border-color: color-mix(in srgb,var(--gold) 40%,var(--rule-2)); }
.callout.rule .co-label { color: var(--gold); }
.callout.takeaways  { background: var(--accent-bg); border-color: color-mix(in srgb,var(--accent) 34%,var(--rule-2)); }
.callout.takeaways .co-label { color: var(--accent); }
.callout.warning    { background: var(--rust-bg); border-color: color-mix(in srgb,var(--rust) 40%,var(--rule-2)); }
.callout.warning .co-label { color: var(--rust); }
.callout.definition { background: var(--sage-bg); border-color: color-mix(in srgb,var(--sage) 38%,var(--rule-2)); }
.callout.definition .co-label { color: var(--sage); }
.callout.takeaways ul { padding-left: 1.2rem; margin-bottom: 0; }
.callout.takeaways li { margin: .35rem 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 1.8rem 0; border: 1px solid var(--rule); border-radius: var(--radius); }
.prose table {
  border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .84rem;
  line-height: 1.4; background: var(--paper);
}
.prose thead th {
  text-align: left; font-weight: 600; font-size: .7rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted);
  padding: .7rem .9rem; border-bottom: 2px solid var(--rule-2); white-space: nowrap;
  background: color-mix(in srgb, var(--paper) 40%, var(--paper-2));
}
.prose tbody td { padding: .62rem .9rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
.prose tbody tr:last-child td { border-bottom: none; }
.prose tbody tr:nth-child(even) { background: color-mix(in srgb, var(--paper) 55%, var(--paper-2)); }
.prose tbody td:first-child { font-weight: 600; color: var(--ink); font-family: var(--serif); font-size: .98rem; }
.prose table code { font-size: .82em; }
.cell-yes { color: var(--sage); font-weight: 600; }
.cell-no  { color: var(--rust);  font-weight: 600; }
.cell-mid { color: var(--gold);  font-weight: 600; }

/* ---------- Code ---------- */
.prose code {
  font-family: var(--mono); font-size: .84em; background: var(--paper-2);
  padding: .12em .38em; border-radius: 5px; border: 1px solid var(--rule);
  font-feature-settings: normal;
}
.codeblock { position: relative; margin: 1.7rem 0; }
.codeblock .codehead {
  display: flex; align-items: center; gap: .6rem;
  font-family: var(--sans); font-size: .68rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); padding: .5rem .9rem; background: var(--paper-3);
  border: 1px solid var(--rule); border-bottom: none; border-radius: var(--radius) var(--radius) 0 0;
}
.codeblock .codehead .lang { color: var(--accent); font-weight: 600; }
.codeblock .copy {
  margin-left: auto; cursor: pointer; border: 1px solid var(--rule-2); background: var(--paper);
  color: var(--muted); font-family: var(--sans); font-size: .64rem; letter-spacing: .08em;
  padding: .18rem .5rem; border-radius: 5px; transition: color .15s, border-color .15s;
}
.codeblock .copy:hover { color: var(--accent); border-color: var(--accent); }
.codeblock pre {
  margin: 0; overflow-x: auto; background: var(--paper-2);
  border: 1px solid var(--rule); border-radius: 0 0 var(--radius) var(--radius);
  padding: 1rem 1.1rem; font-size: .82rem; line-height: 1.6;
}
.codeblock.plain pre { border-radius: var(--radius); }
.prose pre code { background: none; border: none; padding: 0; font-size: 1em; }

/* ---------- Figures / diagrams ---------- */
figure { margin: 2rem 0; }
figure.diagram { text-align: center; }
figure.diagram svg { max-width: 100%; height: auto; }
figure figcaption {
  font-family: var(--sans); font-size: .74rem; color: var(--muted);
  margin-top: .8rem; line-height: 1.4; text-align: left;
}
figure figcaption .fig-label { color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: .1em; margin-right: .4rem; }

/* ---------- Exercises ---------- */
.exercise {
  margin: 2.4rem 0 0; padding: 1.6rem 1.6rem 1.2rem; border: 1px dashed var(--rule-2);
  border-radius: var(--radius); background: color-mix(in srgb,var(--paper) 55%, var(--paper-2));
}
.exercise .co-label { font-family: var(--sans); font-size: .72rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); margin-bottom: .7rem; }

/* ---------- Footnotes / citations ---------- */
.footnotes { margin-top: 3.5rem; padding-top: 1.4rem; border-top: 1px solid var(--rule-2); font-size: .86rem; color: var(--ink-2); }
.footnotes ol { padding-left: 1.2rem; }
.footnotes li { margin: .4rem 0; }
.footnote-ref a, a.footnote-backref { color: var(--accent); text-decoration: none; background: none; }

/* ---------- Prev / next ---------- */
.prevnext { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 3.5rem; max-width: var(--measure); }
.prevnext a {
  display: block; padding: 1rem 1.2rem; border: 1px solid var(--rule-2); border-radius: var(--radius);
  text-decoration: none; color: var(--ink); background: var(--paper); transition: border-color .2s, box-shadow .2s, transform .2s;
}
.prevnext a:hover { border-color: var(--accent); box-shadow: var(--shadow-1); transform: translateY(-2px); }
.prevnext .dir { font-family: var(--sans); font-size: .66rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.prevnext .t { font-family: var(--serif); font-size: 1.05rem; font-weight: 600; margin-top: .3rem; }
.prevnext .next { text-align: right; }
.prevnext .next:only-child { grid-column: 2; }

/* ---------- Search modal ---------- */
.search-modal { position: fixed; inset: 0; z-index: 100; display: none; }
.search-modal[open], .search-modal.open { display: block; }
.search-modal .scrim { position: absolute; inset: 0; background: rgba(20,18,12,.45); backdrop-filter: blur(3px); }
.search-box {
  position: relative; max-width: 40rem; margin: 8vh auto 0; background: var(--paper);
  border: 1px solid var(--rule-2); border-radius: 14px; box-shadow: var(--shadow-2); overflow: hidden;
}
.search-box input {
  width: 100%; border: none; background: none; color: var(--ink);
  font-family: var(--serif); font-size: 1.25rem; padding: 1.1rem 1.3rem; outline: none;
  border-bottom: 1px solid var(--rule);
}
.search-results { max-height: 55vh; overflow-y: auto; }
.search-results a { display: block; padding: .8rem 1.3rem; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--rule); }
.search-results a:hover, .search-results a.sel { background: var(--accent-bg); }
.search-results .r-ch { font-family: var(--sans); font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.search-results .r-t { font-weight: 600; margin: .1rem 0; }
.search-results .r-x { font-size: .85rem; color: var(--muted); line-height: 1.4; }
.search-results mark { background: color-mix(in srgb,var(--gold) 40%, transparent); color: inherit; border-radius: 2px; }
.search-empty { padding: 2rem 1.3rem; color: var(--muted); font-family: var(--sans); font-size: .9rem; text-align: center; }

/* ---------- Cover / index ---------- */
.cover { max-width: 52rem; margin: 0 auto; padding: 5vh clamp(1.2rem,5vw,3rem) 6rem; }
.cover .series { font-family: var(--sans); font-size: .78rem; letter-spacing: .28em; text-transform: uppercase; color: var(--accent); }
.cover h1 { font-family: var(--serif); font-weight: 600; font-size: clamp(2.8rem,8vw,5rem); line-height: 1.02; letter-spacing: -.02em; margin: 1.2rem 0 0; text-wrap: balance; }
.cover .sub { font-family: var(--serif); font-style: italic; font-size: 1.5rem; color: var(--ink-2); margin: 1.2rem 0 0; }
.cover .tagline { font-family: var(--sans); font-size: .8rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-top: 2rem; }
.cover .byline { font-family: var(--sans); font-size: .82rem; color: var(--ink-2); margin-top: .5rem; }
.cover .byline a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--rule-2); }
.cover .byline a:hover { border-color: var(--accent); }

/* header byline + github link */
.hide-sm { display: inline; }
.byline-top { font-family: var(--sans); font-size: .74rem; color: var(--muted); letter-spacing: .01em; margin-right: .3rem; }
.byline-top a { color: var(--ink-2); text-decoration: none; border-bottom: 1px solid var(--rule-2); }
.byline-top a:hover { color: var(--accent); border-color: var(--accent); }

/* site footer */
.site-footer { border-top: 1px solid var(--rule); background: color-mix(in srgb, var(--paper) 55%, var(--paper-2)); }
.foot-inner { max-width: 72rem; margin: 0 auto; padding: 1.5rem clamp(1rem,4vw,2.5rem);
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  font-family: var(--sans); font-size: .82rem; color: var(--muted); }
.foot-inner a { color: var(--ink-2); text-decoration: none; }
.foot-curated a { border-bottom: 1px solid var(--rule-2); }
.foot-inner a:hover { color: var(--accent); }
.foot-gh { display: inline-flex; align-items: center; gap: .45rem; }
.foot-right { display: inline-flex; align-items: center; gap: 1.3rem; flex-wrap: wrap; }
.foot-dl { border-bottom: 1px solid var(--rule-2); }
@media print { .site-footer { display: none; } }
.cover-rule { height: 1px; background: var(--rule-2); margin: 3rem 0; }
.part-block { margin: 2.5rem 0; }
.part-block .p-h { font-family: var(--sans); font-size: .72rem; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); display: flex; gap: .6rem; align-items: baseline; margin-bottom: .3rem; }
.part-block .p-h .pn { color: var(--accent); }
.part-block .p-h::after { content:""; flex:1; height:1px; background: var(--rule); }
.toc-grid a { display: flex; gap: 1rem; align-items: baseline; text-decoration: none; color: var(--ink); padding: .55rem .6rem; border-radius: 8px; }
.toc-grid a:hover { background: var(--paper-2); }
.toc-grid .n { font-family: var(--sans); font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; min-width: 1.6rem; }
.toc-grid .ct { font-family: var(--serif); font-size: 1.12rem; font-weight: 600; }
.toc-grid .cx { font-family: var(--sans); font-size: .78rem; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  :root { --gutter: 0rem; }
  .sidenote {
    float: none; width: auto; margin: 1rem 0; padding: .9rem 1rem;
    background: var(--paper-2); border: 1px solid var(--rule); border-left: 3px solid var(--accent);
    border-radius: 8px; font-size: .82rem;
  }
  .reading { max-width: 46rem; }
}
@media (max-width: 860px) {
  .menu-toggle { display: inline-flex; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 3.6rem; left: 0; width: min(88vw, 22rem); z-index: 45;
    transform: translateX(-102%); transition: transform .28s var(--ease);
    box-shadow: var(--shadow-2);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content:""; position: fixed; inset: 3.6rem 0 0; background: rgba(20,18,12,.4); z-index: 44; }
  body { font-size: 1.1rem; }
  .hide-sm, .byline-top { display: none; }
}

/* ---------- Print ---------- */
@media print {
  .topbar, .sidebar, .progress, .prevnext, .search-modal, .copy, .anchor, .menu-toggle { display: none !important; }
  .callout, .exercise, .codeblock pre, .prose thead th, .prose tbody tr:nth-child(even), figure .diagram {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  body { background: #fff; color: #000; font-size: 11pt; }
  .layout { display: block; }
  .reading { max-width: none; padding: 0; }
  .sidenote { float: none !important; clear: none !important; display: block; width: auto !important; max-width: none !important;
    margin: .5rem 0 !important; border-left: 2px solid #bbb; padding: .25rem 0 .25rem .7rem; font-size: 9.5pt; background: none !important; }
  .callout, .table-wrap, .codeblock pre, figure { break-inside: avoid; }
  .prose h2, .prose h3 { break-after: avoid; }
  a { color: #000; text-decoration: none; background: none; }
  .chapter-head { break-after: avoid; }
}

/* social links: header icons on wider screens, footer on phones */
@media (max-width: 600px) {
  .top a.iconbtn[href*="github.com"], .top a.iconbtn[href*="linkedin.com"],
  header a.iconbtn[href*="github.com"], header a.iconbtn[href*="linkedin.com"] { display: none; }
  .topbar { gap: .6rem; }
  .topbar .brand { min-width: 0; overflow: hidden; text-overflow: ellipsis; letter-spacing: .08em; }
}
