/* AI Alignment: a book. One stylesheet for every page.
   Colors are tokens on :root, redefined for the dark theme, so the build-time
   SVG of every figure follows the reader's theme without script. */

/* The palette is Latere's ink ladder (the platform's palette.css), as on
   changkun.de's other pages: neutral grays with no hue, navy for links and
   little else, and every text tone at 4.5:1 or more on the surfaces it is set
   on (tools/contrast.py computes it). Figure series and callout labels take
   Latere's muted capability tones, so color marks a role and the ink stays the
   loudest thing on the page. */
:root {
  --bg: #ffffff;
  --bg-2: #f4f4f4;
  --bg-3: #ebebeb;
  --ink: #0d0d0d;
  --prose: #262626;
  --ink-2: #525252;
  --ink-3: #666666;
  --rule: #e6e6e6;
  --rule-strong: #d6d6d6;
  --accent: #38538f;
  --accent-ink: #2b4171;
  --accent-soft: #edf0f6;
  --warm: #80571d;
  --cover-art-filter: none;

  --font-ui: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --font-body: var(--font-ui);
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --col: 720px;
  --side: clamp(260px, 20vw, 300px);
  --toc: 212px;
  --top: 69px;

  /* figure tokens */
  --fig-ink: #0d0d0d;
  --fig-ink-2: #525252;
  --fig-ink-3: #666666;
  --fig-grid: #ececec;
  --fig-rule: #8a8a8a;
  --fig-paper: #ffffff;
  --fig-panel: #f4f4f4;
  --fig-c1: #315f91;
  --fig-c2: #a85512;
  --fig-c3: #22626a;
  --fig-c4: #7a6412;
  --fig-c5: #8a3d79;
  --fig-c6: #2a614b;
  --fig-c7: #5b4391;
  --fig-c8: #943843;
  --fig-good: #356342;
  --fig-warn: #7d5019;
  --fig-bad: #96372e;
  --fig-band: rgba(49, 95, 145, 0.15);
  --fig-proxy-fill: rgba(168, 85, 18, 0.14);

  /* callouts */
  --c-def: #315f91;
  --c-thm: #5b4391;
  --c-ex: #22626a;
  --c-exr: #2a614b;
  --c-der: #525252;
  --c-note: #666666;
  --c-aside: #80571d;
  --c-pit: #943843;
  --c-key: #a85512;
  --c-frontier: #8a3d79;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161616; --bg-2: #262626; --bg-3: #2e2e2e; --ink: #ececec; --prose: #d4d4d4; --ink-2: #b4b4b4; --ink-3: #9a9a9a;
    --rule: #2a2a2a; --rule-strong: #3a3a3a; --accent: #9bb0e4; --accent-ink: #b8c8ee; --accent-soft: #262d3b; --warm: #d1a56b;
    --fig-ink: #ececec; --fig-ink-2: #b4b4b4; --fig-ink-3: #9a9a9a; --fig-grid: #262626; --fig-rule: #737373;
    --fig-paper: #161616; --fig-panel: #1e1e1e;
    --fig-c1: #a5c8ef; --fig-c2: #e8a56a; --fig-c3: #9dd2d6; --fig-c4: #d9c27a; --fig-c5: #e6addb; --fig-c6: #9bceb3; --fig-c7: #c9b8f2; --fig-c8: #f1a9ae;
    --fig-good: #86ba93; --fig-warn: #d1a56b; --fig-bad: #e99a90;
    --fig-band: rgba(165, 200, 239, 0.18); --fig-proxy-fill: rgba(232, 165, 106, 0.16);
    --c-def: #a5c8ef; --c-thm: #c9b8f2; --c-ex: #9dd2d6; --c-exr: #9bceb3; --c-der: #b4b4b4; --c-note: #9a9a9a; --c-aside: #d1a56b; --c-pit: #f1a9ae; --c-key: #e8a56a; --c-frontier: #e6addb;
    --cover-art-filter: invert(1) hue-rotate(180deg);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161616; --bg-2: #262626; --bg-3: #2e2e2e; --ink: #ececec; --prose: #d4d4d4; --ink-2: #b4b4b4; --ink-3: #9a9a9a;
  --rule: #2a2a2a; --rule-strong: #3a3a3a; --accent: #9bb0e4; --accent-ink: #b8c8ee; --accent-soft: #262d3b; --warm: #d1a56b;
  --fig-ink: #ececec; --fig-ink-2: #b4b4b4; --fig-ink-3: #9a9a9a; --fig-grid: #262626; --fig-rule: #737373;
  --fig-paper: #161616; --fig-panel: #1e1e1e;
  --fig-c1: #a5c8ef; --fig-c2: #e8a56a; --fig-c3: #9dd2d6; --fig-c4: #d9c27a; --fig-c5: #e6addb; --fig-c6: #9bceb3; --fig-c7: #c9b8f2; --fig-c8: #f1a9ae;
  --fig-good: #86ba93; --fig-warn: #d1a56b; --fig-bad: #e99a90;
  --fig-band: rgba(165, 200, 239, 0.18); --fig-proxy-fill: rgba(232, 165, 106, 0.16);
  --c-def: #a5c8ef; --c-thm: #c9b8f2; --c-ex: #9dd2d6; --c-exr: #9bceb3; --c-der: #b4b4b4; --c-note: #9a9a9a; --c-aside: #d1a56b; --c-pit: #f1a9ae; --c-key: #e8a56a; --c-frontier: #e6addb;
  --cover-art-filter: invert(1) hue-rotate(180deg);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--top) + 16px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16.5px/1.7 var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration-thickness: 1px; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
a:hover { color: var(--accent-ink); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; z-index: 100; background: var(--bg); padding: 6px 10px; }

/* ------------------------------------------------------------ top bar */
/* The top bar, the sidebar, and the outline are fixed to the window, not
   sticky in the page, so macOS elastic scrolling bounces only the text. */
body { padding-top: var(--top); }
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  height: var(--top);
  display: flex; align-items: center; gap: 16px;
  /* The blog's header: 16px about the 36px buttons puts the theme button
     where the home page has it. */
  padding: 16px 16px 16px clamp(16px, 2vw, 24px);
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-ui);
}
.brand { font-weight: 600; font-size: 16px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.crumbs { flex: 1; min-width: 0; font-size: 14.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs::before { content: "/"; margin-right: 10px; color: var(--ink-3); }
.crumbs:empty::before { content: none; }
.crumbs a { color: var(--ink-2); text-decoration: none; }
.crumbs a:hover { color: var(--ink); }
.topbar-tools { display: flex; gap: 8px; margin-left: auto; }
/* The search, language, and theme buttons: the home page's button. */
.search-btn, .theme-btn, .lang-btn { flex: none; width: 36px; height: 36px; padding: 0; border: 1px solid var(--rule-strong); border-radius: 8px; background: none; color: var(--ink-2); cursor: pointer; display: grid; place-items: center; transition: color 0.2s, background-color 0.2s; }
.search-btn:hover, .theme-btn:hover, .lang-btn:hover { background: var(--bg-2); color: var(--ink); }
.menu-btn { flex: none; width: 36px; height: 36px; margin-left: -6px; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--ink-2); cursor: pointer; place-items: center; }
.menu-btn:hover { background: var(--bg-2); color: var(--ink); }
.menu-btn { display: none !important; }
/* The moon in the light theme, the sun in the dark, as on the other pages. */
.theme-btn .icon-sun { display: none; }
:root[data-theme="dark"] .theme-btn .icon-moon { display: none; }
:root[data-theme="dark"] .theme-btn .icon-sun { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .icon-moon { display: none; }
  :root:not([data-theme="light"]) .theme-btn .icon-sun { display: block; }
}
.menu-btn span, .menu-btn span::before, .menu-btn span::after { display: block; width: 16px; height: 1.6px; background: currentColor; position: relative; content: ""; }
.menu-btn span::before { position: absolute; top: -5px; }
.menu-btn span::after { position: absolute; top: 5px; }

/* ------------------------------------------------------------- layout */
.layout {
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr) var(--toc);
}
[data-no-toc] .layout { grid-template-columns: var(--side) minmax(0, 1fr); }
.sidebar {
  position: fixed; top: var(--top); bottom: 0;
  left: 0; width: var(--side);
  overflow-y: auto;
  padding: 28px 20px;
  font: 400 14px/1.5 var(--font-ui);
  border-right: 1px solid var(--rule);
  scrollbar-width: thin;
}
.main { grid-column: 2; min-width: 0; padding: 0 32px; }
.article { max-width: var(--col); margin: 0 auto; padding: 24px 0 16px; overflow-wrap: break-word; } /* a bare URL breaks rather than widen the page on a phone */
.page-index { max-width: 1000px; }
[data-no-toc] .article { max-width: 1000px; }
[data-no-toc] .article > p, [data-no-toc] .article > ul, [data-no-toc] .article > ol:not([class]) { max-width: var(--col); }
[data-no-toc] .pager, [data-no-toc] .site-footer { max-width: 1000px; }
.toc {
  position: fixed; top: var(--top); bottom: 0;
  right: 0; width: var(--toc);
  overflow-y: auto;
  padding: 28px 12px 32px 0;
  font: 400 12.5px/1.35 var(--font-ui);
  scrollbar-width: thin;
}

/* sidebar: as An Unverifiable World's, the book's contents in plain text,
   parts as quiet labels over their chapters, the current page in ink. A
   part folds away, since there are ten. */
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list li { margin: 1px 0; }
.nav-list a { display: flex; align-items: baseline; padding: 4px 0; color: var(--ink-2); text-decoration: none; }
.nav-list a:hover { color: var(--ink); }
.nav-list a[aria-current] { color: var(--ink); font-weight: 600; }
.nav-num { flex: none; margin-right: 0.35em; font-variant-numeric: tabular-nums; }
.nav-num::after { content: "."; }
.nav-title { flex: 1; min-width: 0; }
.nav-status { flex: none; width: 5px; height: 5px; margin-left: 6px; border-radius: 50%; align-self: center; border: 1.2px solid var(--ink-3); }
.nav-part > summary { list-style: none; cursor: pointer; margin: 18px 0 6px; font-size: 13px; font-weight: 500; color: var(--ink-3); display: flex; align-items: baseline; }
.nav-part > summary::-webkit-details-marker { display: none; }
.nav-part > summary:hover, .nav-part-link:hover { color: var(--ink); }
.nav-part-link { color: inherit; text-decoration: none; flex: 1; }
.nav-part-link[aria-current] { color: var(--ink); font-weight: 600; }
.nav-part > summary::after { content: "›"; font-size: 14px; line-height: 1; transition: transform 0.15s; margin-left: 4px; }
.nav-part[open] > summary::after { transform: rotate(90deg); }
.nav-part:not([open]) > summary { margin-bottom: 0; }
.nav-back { margin-top: 18px; }

/* page outline: weight and color mark the current section, no rules */
.toc-head { font-weight: 600; font-size: 12.5px; color: var(--ink); margin-bottom: 6px; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc a { display: block; padding: 2.5px 0; color: var(--ink-3); text-decoration: none; }
.toc a:hover { color: var(--ink); }
.toc a.active { color: var(--ink); font-weight: 600; }
.toc-l3 a { padding-left: 12px; font-size: 12px; }
.toc-num { font-variant-numeric: tabular-nums; margin-right: 2px; }
.toc .katex { font-size: 1em; }

/* ------------------------------------------------------------- article */
.article h1, .article h2, .article h3, .article h4 { font-family: var(--font-ui); color: var(--ink); line-height: 1.25; letter-spacing: -0.015em; }
.article h1 { font-size: 1.95rem; font-weight: 600; margin: 0.1em 0 0.6em; letter-spacing: -0.025em; }
.article h1 .chapter-num { display: block; font-size: 0.95rem; font-weight: 500; letter-spacing: 0; color: var(--ink-3); margin-bottom: 0.4em; }
.article h2 { font-size: 1.36rem; font-weight: 600; margin: 1.9em 0 0.55em; }
.article h3 { font-size: 1.1rem; font-weight: 600; margin: 1.5em 0 0.4em; }
.article h4 { font-size: 0.98rem; font-weight: 600; margin: 1.3em 0 0.35em; }
.sec-num { color: var(--ink-3); font-weight: 600; margin-right: 0.35em; font-variant-numeric: tabular-nums; }
.anchor { opacity: 0; margin-left: 0.3em; color: var(--ink-3); text-decoration: none; font-weight: 400; }
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; }
.article { color: var(--prose); }
.article p { margin: 0 0 0.9em; }
.article ul, .article ol { padding-left: 1.3em; margin: 0 0 0.9em; }
.article li { margin: 0.18em 0; }
.article li > p { margin-bottom: 0.4em; }
.article strong { font-weight: 600; color: var(--ink); }
.article blockquote { margin: 1.1em 0 1.1em 1.6em; padding: 0; color: var(--ink-2); font-style: italic; }
.article hr { border: 0; border-top: 1px solid var(--rule); margin: 1.8em 0; }
.lead { font-size: 1.13em; color: var(--ink-2); }

code { font-family: var(--font-mono); font-size: 0.84em; background: var(--bg-2); padding: 0.1em 0.35em; border-radius: 4px; }
pre { font: 400 13.5px/1.5 var(--font-mono); background: var(--bg-2); border: 1px solid var(--rule); border-radius: 6px; padding: 10px 14px; overflow-x: auto; margin: 1em 0; }
pre code { background: none; padding: 0; font-size: inherit; }

.table-wrap {
  overflow-x: auto; margin: 1.5em 0;
  /* Scroll shadows: a soft edge appears on the side where more of the table is hidden. */
  background:
    linear-gradient(to right, var(--surface, var(--bg)) 30%, transparent) left / 40px 100% no-repeat local,
    linear-gradient(to left, var(--surface, var(--bg)) 30%, transparent) right / 40px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.16), transparent) left / 14px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.16), transparent) right / 14px 100% no-repeat scroll;
}
table { border-collapse: collapse; width: 100%; font: 400 14px/1.4 var(--font-ui); }
th, td { padding: 6px 9px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
th { font-weight: 600; color: var(--ink); border-bottom: 1.5px solid var(--ink-3); }
td .katex { font-size: 1.02em; }

/* math */
.katex { font-size: 1.07em; }
.math-display { display: flex; align-items: center; gap: 12px; margin: 0.9em 0; }
.math-body { flex: 1; min-width: 0; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.math-body .katex-display { margin: 0; }
.eq-num { flex: none; font: 400 15px var(--font-ui); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.math-error { color: var(--fig-bad); }

/* status: one quiet line above the title */
.status-line { font: 400 12.5px/1.4 var(--font-ui); color: var(--ink-3); margin: 0 0 10px !important; }
.status-pill { display: inline-block; font-weight: 500; font-size: 11.5px; padding: 1px 7px; border-radius: 9px; background: var(--bg-3); color: var(--ink-2); margin-right: 4px; }
.status-draft .status-pill { background: color-mix(in srgb, var(--fig-c4) 26%, var(--bg)); }

/* ------------------------------------------------------------ callouts */
.callout { --surface: color-mix(in srgb, var(--c, var(--c-note)) 4%, var(--bg)); margin: 1.2em 0; padding: 10px 14px 1px; border: 1px solid color-mix(in srgb, var(--c, var(--c-note)) 22%, var(--rule)); background: var(--surface); border-radius: 7px; }
.callout-head { font: 600 13px/1.4 var(--font-ui); margin-bottom: 5px; color: var(--c, var(--ink-2)); }
.callout-title { color: var(--ink); font-size: 14.5px; }
.callout-title::before { content: "· "; color: var(--ink-3); }
.callout-body > :last-child { margin-bottom: 9px; }
.callout-definition { --c: var(--c-def); }
.callout-theorem, .callout-lemma, .callout-proposition, .callout-corollary { --c: var(--c-thm); }
.callout-example { --c: var(--c-ex); }
.callout-exercise { --c: var(--c-exr); }
.callout-algorithm { --c: var(--c-def); background: var(--bg-2); }
.callout-derivation { --c: var(--c-der); }
.callout-proof { --c: var(--c-der); background: transparent; border-color: var(--rule); }
.callout-proof .callout-body > :last-child::after { content: " ∎"; color: var(--ink-3); }
.callout-note, .callout-recap { --c: var(--c-note); }
.callout-aside { --c: var(--c-aside); }
.callout-aside .callout-label::after { content: " · optional"; font-weight: 400; color: var(--ink-3); }
.callout-pitfall { --c: var(--c-pit); }
.callout-keyidea { --c: var(--c-key); }
.callout-frontier { --c: var(--c-frontier); }
.callout-code { --c: var(--c-der); }
.callout-solution { --c: var(--c-exr); margin: 0.6em 0 0.5em; padding: 7px 12px 1px; background: var(--bg); }
details.callout > summary { cursor: pointer; list-style: none; }
details.callout > summary::-webkit-details-marker { display: none; }
details.callout > summary::before { content: "▸ "; }
details.callout[open] > summary::before { content: "▾ "; }
.callout .math-display { margin: 0.8em 0; }

/* the brief at the top of a chapter, a part page, and the landing page: one row each for
   ideas, evidence, and what is open, every bullet ending with the section it points to */
.brief { margin: 0.4em 0 1.7em; padding: 9px 16px 3px; border: 1px solid var(--rule); border-radius: 7px; background: var(--bg-2); font: 400 14.5px/1.5 var(--font-ui); }
.article .brief-head { font: 600 13px/1.4 var(--font-ui); color: var(--ink); margin: 0 0 7px; }
.brief-rows { display: grid; grid-template-columns: 5.4em minmax(0, 1fr); column-gap: 12px; margin: 0; }
.brief-rows dt { font: 600 12.5px/1.6 var(--font-ui); color: var(--ink-2); }
.brief-rows dd { margin: 0; }
.article .brief-rows ul { margin: 0 0 9px; padding-left: 1.05em; }
.article .brief-rows li { margin: 0 0 3px; hyphens: none; }
.brief .xref { color: var(--ink-3); white-space: nowrap; }
.brief .xref:hover { color: var(--accent-ink); }

/* ------------------------------------------------------------- figures */
.figure { margin: 1.5em -20px; }
.figure figcaption { font: 400 13.5px/1.45 var(--font-ui); color: var(--ink-2); margin: 7px 20px 0; }
.fig-num { font-weight: 600; color: var(--ink); margin-right: 0.25em; }
.fig { container-type: inline-size; background: var(--fig-paper); border: 1px solid var(--rule); border-radius: 7px; padding: 10px 12px 8px; }
.fig-svg { display: block; width: 100%; height: auto; overflow: visible; font-family: var(--font-ui); }
.fig-v-narrow { display: none; }
@container (max-width: 480px) {
  .fig-v-wide { display: none; }
  .fig-v-narrow { display: block; }
}
.fig-img { display: block; max-width: 100%; margin: 0 auto; }
/* The default size is set on the root and inherited, so a figure's own
   font-size attribute on a text element wins. */
.fig-svg { font-size: 12px; }
.fig-svg text { fill: var(--fig-ink); }
.fig-t-glyph { font-family: KaTeX_Main, "Times New Roman", serif; }
.fig-t-strong { font-weight: 600; }
.fig-t-muted { fill: var(--fig-ink-2) !important; }
.fig-t-faint { fill: var(--fig-ink-3) !important; }
.fig-t-num { font-variant-numeric: tabular-nums; }
.fig-t-halo { paint-order: stroke; stroke: var(--fig-paper); stroke-width: 3.5px; stroke-linejoin: round; }
.fig-t-math { font-family: KaTeX_Math, KaTeX_Main, "Times New Roman", serif; font-style: italic; }
.fig-top { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: flex-end; justify-content: space-between; margin-bottom: 6px; }
.fig-controls { display: flex; flex-wrap: wrap; gap: 8px 20px; font: 400 13px/1.3 var(--font-ui); color: var(--ink-2); flex: 1 1 320px; }
.fig-ctl { display: flex; align-items: center; gap: 8px; min-width: 0; }
.fig-range { flex: 1 1 220px; }
.fig-range input { flex: 1; min-width: 80px; accent-color: var(--accent); }
.fig-ctl-name { white-space: nowrap; color: var(--ink-2); }
.fig-ctl-value { min-width: 3.4em; font-variant-numeric: tabular-nums; color: var(--ink); text-align: right; }
.fig-seg { border: 0; padding: 0; margin: 0; }
.fig-seg legend { float: left; margin-right: 8px; padding: 0; line-height: 28px; }
.fig-seg-options { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--rule); border-radius: 7px; overflow: hidden; }
.fig-seg-option { position: relative; }
.fig-seg-option input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.fig-seg-option span { display: block; padding: 4px 10px; cursor: pointer; border-right: 1px solid var(--rule); }
.fig-seg-option:last-child span { border-right: 0; }
.fig-seg-option input:checked + span { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.fig-seg-option input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.fig-seg-chips .fig-seg-options { border: 0; gap: 4px; }
.fig-seg-chips .fig-seg-option span { border: 1px solid var(--rule); border-radius: 6px; }
.fig-select select { font: inherit; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--rule); background: var(--bg); color: var(--ink); }
.fig-toggle input { accent-color: var(--accent); }
.fig-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.fig-btn { font: 500 13px/1 var(--font-ui); padding: 7px 12px; border-radius: 7px; border: 1px solid var(--accent); background: var(--accent); color: var(--bg); cursor: pointer; }
.fig-btn:hover:not(:disabled) { filter: brightness(1.08); }
.fig-btn:disabled { opacity: 0.45; cursor: default; }
.fig-btn-quiet { background: transparent; color: var(--ink-2); border-color: var(--rule); }
.fig-hint { font: italic 400 12.5px/1.4 var(--font-ui); color: var(--ink-3); margin: 2px 0 4px !important; }
.fig-stage { position: relative; touch-action: pan-y; }
.fig-interactive { cursor: crosshair; }
.fig-interactive [data-fig-hit] { cursor: pointer; }
.fig-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.fig-error { color: var(--fig-bad); font-size: 13px; }
[data-fig-set] { cursor: pointer; }

.fig-transport { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; font: 400 12.5px/1.3 var(--font-ui); color: var(--ink-2); margin: 4px 0 6px; }
.fig-tr-buttons { display: flex; gap: 2px; }
.fig-tr-btn { width: 30px; height: 28px; border: 1px solid var(--rule); background: var(--bg); color: var(--ink); border-radius: 6px; cursor: pointer; font-size: 12px; line-height: 1; }
.fig-tr-btn:hover { background: var(--bg-2); }
.fig-tr-play { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.fig-tr-scrub { position: relative; }
.fig-tr-scrub input { width: 100%; accent-color: var(--accent); }
.fig-tr-ticks { position: absolute; left: 8px; right: 8px; top: 0; height: 4px; pointer-events: none; }
.fig-tr-tick { position: absolute; width: 2px; height: 5px; background: var(--ink-3); transform: translateX(-1px); }
.fig-tr-info { grid-column: 1 / -1; display: flex; gap: 12px; }
.fig-tr-readout { font-variant-numeric: tabular-nums; color: var(--ink-3); }
.fig-tr-key { color: var(--ink); font-weight: 500; }

/* ------------------------------------------------------- citations, refs */
.cite { white-space: normal; }
.cite-link { color: inherit; text-decoration: underline dotted color-mix(in srgb, var(--ink-3) 70%, transparent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.cite-link:hover { color: var(--accent-ink); text-decoration-style: solid; }
.cite-card {
  position: absolute; z-index: 60; opacity: 0; pointer-events: none; transform: translateY(4px);
  transition: opacity 0.12s, transform 0.12s;
  background: var(--bg); color: var(--ink-2); border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.14);
  padding: 12px 14px; font: 400 13.5px/1.5 var(--font-ui);
}
.cite-card.on { opacity: 1; pointer-events: auto; transform: none; }
.xref { text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--ink-3) 55%, transparent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.xref-missing { color: var(--fig-bad); }

.sec-refs { margin: 1.6em 0 0.4em; font: 400 13.5px/1.5 var(--font-ui); color: var(--ink-2); border-top: 1px solid var(--rule); padding-top: 8px; }
.sec-refs > summary { cursor: pointer; color: var(--ink-3); list-style: none; }
.sec-refs > summary::-webkit-details-marker { display: none; }
.sec-refs > summary::before { content: "▸ "; }
.sec-refs[open] > summary::before { content: "▾ "; }
.sec-refs-n { display: inline-block; min-width: 1.6em; text-align: center; padding: 0 5px; border-radius: 9px; background: var(--bg-2); font-size: 12px; color: var(--ink-2); }
.sec-refs ol { margin: 6px 0 0; padding-left: 1.4em; }
.sec-refs li { margin: 2px 0; }

.references h2 { margin-top: 2.2em; }
.ref-list { list-style: none; padding: 0 !important; font: 400 13.5px/1.45 var(--font-ui); color: var(--ink-2); }
.ref-list li { padding-left: 1.5em; text-indent: -1.5em; margin: 0 0 0.45em; }
.ref-list li:target { background: var(--accent-soft); border-radius: 6px; }
.ref-authors { color: var(--ink); }
.ref-title { color: var(--ink); }
a.ref-title { color: var(--ink); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--ink-3) 55%, transparent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a.ref-title:hover { text-decoration: underline; }
.ref-venue { font-style: italic; }
.ref-badge { display: inline-block; text-indent: 0; font-size: 11px; font-weight: 500; padding: 1px 7px; border-radius: 9px; background: var(--bg-3); color: var(--ink-2); vertical-align: 1px; }
.ref-badge-preprint { background: color-mix(in srgb, var(--fig-c4) 22%, var(--bg)); }
.ref-badge-software { background: color-mix(in srgb, var(--fig-c3) 18%, var(--bg)); }
.ref-badge-other { background: color-mix(in srgb, var(--fig-c8) 14%, var(--bg)); }
.ref-back { font-size: 12.5px; color: var(--ink-3); margin-left: 4px; }
.ref-back a { color: var(--ink-3); }
.refs-note { font: 400 14px/1.5 var(--font-ui); color: var(--ink-3); }

/* part pages: a compact list of chapters */
.part-chapters { list-style: none; padding: 0 !important; margin: 0 0 1em !important; columns: 2 380px; column-gap: 32px; }
.part-chapters > li { padding: 7px 0; border-top: 1px solid var(--rule); margin: 0; break-inside: avoid; }
.page-part h2 { font-size: 1.1rem; color: var(--ink); font-weight: 600; margin: 1.6em 0 0.5em; }
.page-part h2 .anchor { display: none; }
.page-part .ref-list, .ref-list-all { columns: 2 400px; column-gap: 32px; }
.page-part .ref-list li, .ref-list-all li { break-inside: avoid; }
.part-chapters a { font: 600 15px/1.3 var(--font-ui); color: var(--ink); text-decoration: none; }
.part-chapters a:hover { color: var(--accent-ink); }
.part-ch-num { display: inline-block; min-width: 1.6em; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.part-chapters p { margin: 2px 0 0 1.75em !important; color: var(--ink-2); font: 400 13.5px/1.45 var(--font-ui); hyphens: none; }
.badge { font: 500 11px/1 var(--font-ui); padding: 2px 6px; border-radius: 9px; background: var(--bg-3); color: var(--ink-2); margin-left: 6px; vertical-align: 2px; }
.badge-draft { background: color-mix(in srgb, var(--fig-c4) 26%, var(--bg)); }

/* cover: text beside the live figure, then the whole table of contents */
.page-index h1 { font-size: clamp(30px, 5vw, 38px); line-height: 1.15; letter-spacing: -0.02em; margin-bottom: 0.25em; }
.page-index h2 { font-size: 1.1rem; color: var(--ink); font-weight: 600; margin: 1.8em 0 0.7em; padding-top: 0.9em; border-top: 1px solid var(--rule); }
.page-index h2 .anchor { display: none; }
.book-subtitle { font: 400 1.15rem/1.4 var(--font-ui); color: var(--ink-2); margin: 0 0 1.1em !important; }
.cover-top { display: grid; grid-template-columns: 228px minmax(0, 1fr); gap: 30px; align-items: start; margin-top: 4px; }
.cover-text h1 { margin-top: 0; }
.cover-text p, .cover-live-text p { font-size: 16px; line-height: 1.55; }
.cover-text > :last-child, .cover-live-text > :last-child { margin-bottom: 0; }
/* The art is an image (assets/cover-art.svg, from src/cover.ts); the words
   are text laid over it, sized to the cover's width. Light-paper covers
   follow the reader's theme; only the artwork is filtered in dark mode,
   retaining the warm accent while turning the paper dark and strokes light. */
.book-cover { position: relative; aspect-ratio: 2 / 3; container-type: inline-size; overflow: hidden; border-radius: 3px; background: #0f1d31;
  box-shadow: 0 1px 2px rgba(10, 20, 35, 0.25), 0 10px 28px -6px rgba(10, 20, 35, 0.35); }
.book-cover img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.book-cover .bc-art, .book-cover .bc-layer { position: absolute; inset: 0; }
.book-cover .bc-layer { opacity: 0; transition: opacity 0.8s ease; }
.book-cover .bc-layer.is-shown { opacity: 1; }
.book-cover .bc-layer svg { width: 100%; height: 100%; display: block; }
.book-cover.is-live { cursor: crosshair; }
.book-cover .bc-new-dot { transform-box: fill-box; transform-origin: center; animation: bc-pop 0.6s ease-out 0.3s both; }
.book-cover .bc-new-arc { stroke-dasharray: 1; stroke-dashoffset: 1; animation: bc-draw 1.1s ease-out 0.5s forwards; }
@keyframes bc-pop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes bc-draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) {
  .book-cover .bc-layer { transition: none; }
  .book-cover .bc-new-dot, .book-cover .bc-new-arc { animation: none; stroke-dashoffset: 0; }
}
.bc-text { position: absolute; top: 7.5%; left: 9%; right: 8%; display: flex; flex-direction: column; color: #f4ecdc; }
/* A cover drawn on light paper (src/cover.ts coverTone) adapts to the theme. */
.book-cover.bc-light { background: var(--bg-2); }
.book-cover.bc-light img { filter: var(--cover-art-filter); }
.book-cover.bc-light .bc-text { color: var(--ink); }
.bc-author { font: 500 4.4cqw/1 var(--font-ui); opacity: 0.7; margin-bottom: 8.5cqw; }
.bc-title { font: 600 11cqw/1.05 var(--font-ui); letter-spacing: -0.025em; }
.bc-sub { font: 400 4.6cqw/1.35 var(--font-ui); opacity: 0.8; margin-top: 5cqw; max-width: 22ch; }
.cover-live { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 30px; align-items: center; margin: 26px 0 8px; }
.cover-fig .figure { margin: 0; }
.cover-fig .fig { border: 0; background: transparent; padding: 0; }
.cover-fig figcaption { margin: 4px 0 0; font-size: 12.5px; color: var(--ink-3); }
.book-toc { columns: 3 250px; column-gap: 26px; font: 400 13.5px/1.32 var(--font-ui); }
.bt-part { break-inside: avoid; margin: 0 0 14px; }
.bt-part h3 { font: 600 14px/1.3 var(--font-ui); margin: 0 0 3px; letter-spacing: 0; }
.bt-part h3 a { color: var(--ink); text-decoration: none; }
.bt-part h3 a:hover { color: var(--accent-ink); }
.bt-num { display: block; font-size: 12px; font-weight: 500; color: var(--ink-3); }
.bt-part ol { list-style: none; margin: 0 !important; padding: 0 !important; }
.bt-part li { margin: 0; }
.bt-part li a { display: flex; gap: 7px; padding: 2px 0; color: var(--ink-2); text-decoration: none; }
.bt-part li a:hover { color: var(--accent-ink); }
.bt-n { flex: none; width: 1.5em; text-align: right; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.paths { display: grid; grid-template-columns: repeat(3, 1fr); gap: 26px; margin: 0 0 1.4em; }
.path-name { font: 600 14px/1.3 var(--font-ui); margin: 0 0 2px !important; }
.path-who { font: 400 12.5px/1.4 var(--font-ui); color: var(--ink-3); margin: 0 0 6px !important; hyphens: none !important; }
.path ul { list-style: none; padding: 0 !important; margin: 0 !important; }
.path li { margin: 0; font: 400 13.5px/1.32 var(--font-ui); }
.xref-titled { display: flex; gap: 7px; padding: 2px 0; text-decoration: none; color: var(--ink-2); }
.xref-titled:hover .xref-title { color: var(--accent-ink); }
.xref-num { flex: none; width: 1.5em; text-align: right; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.page-index .figure.map { margin: 0.6em 0 0; }

/* pager and footer: one quiet row each */
.pager { max-width: var(--col); margin: 28px auto 0; padding-top: 12px; border-top: 1px solid var(--rule); display: flex; justify-content: space-between; gap: 20px; font: 500 13.5px/1.35 var(--font-ui); }
[data-page-kind="index"] .pager, [data-page-kind="index"] .site-footer { max-width: 1000px; }
.pager a { display: flex; gap: 7px; align-items: baseline; text-decoration: none; color: var(--ink-2); max-width: 48%; }
.pager a:hover { color: var(--accent-ink); }
.pager-next { text-align: right; margin-left: auto; }
.pager-dir { color: var(--ink-3); }
.site-footer { max-width: var(--col); margin: 14px auto 0; padding: 0 0 28px; font: 400 12px/1.5 var(--font-ui); color: var(--ink-3); }
.site-footer a { color: var(--ink-3); }
/* Page views and visitors, filled in by urlstat on the published site. */
.site-footer .page-stat { font-variant-numeric: tabular-nums; }
.site-footer .page-stat:has(#urlstat-page-pv:empty) { display: none; }

/* search */
.search-panel { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,0.28); display: flex; justify-content: center; align-items: flex-start; padding: 10vh 16px 0; }
.search-panel[hidden] { display: none; }
.search-box { width: min(640px, 100%); background: var(--bg); border: 1px solid var(--rule); border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,0.2); overflow: hidden; font-family: var(--font-ui); }
.search-box input { width: 100%; border: 0; border-bottom: 1px solid var(--rule); padding: 16px 18px; font: 400 17px var(--font-ui); background: transparent; color: var(--ink); outline: none; }
.search-results { list-style: none; margin: 0; padding: 6px; max-height: 60vh; overflow-y: auto; }
.search-results a { display: block; padding: 10px 12px; border-radius: 8px; text-decoration: none; color: var(--ink); }
.search-results a:hover, .search-results a:focus { background: var(--bg-2); }
.sr-title { display: block; font-weight: 600; font-size: 14px; }
.sr-snip { display: block; font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.sr-none { padding: 12px; color: var(--ink-3); font-size: 14px; }

/* ---------------------------------------------------------- responsive */
@media (max-width: 1240px) {
  .layout { grid-template-columns: var(--side) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 960px) {
  .layout, [data-no-toc] .layout { grid-template-columns: minmax(0, 1fr); }
  .main { grid-column: 1; }
  .menu-btn { display: grid !important; }
  .sidebar {
    position: fixed; top: var(--top); left: 0; bottom: 0; width: min(320px, 86vw); height: auto; z-index: 50;
    background: var(--bg); transform: translateX(-105%); transition: transform 0.2s ease, box-shadow 0.2s ease;
  }
  /* The shadow only on the open drawer: closed, it would show at the window's edge. */
  .nav-open .sidebar { transform: none; box-shadow: 8px 0 30px rgba(0,0,0,0.12); }
  .main { padding: 0 16px; }
  .figure { margin: 1.4em 0; }
  .figure figcaption { margin: 7px 2px 0; }
  .cover-top { grid-template-columns: 1fr; gap: 18px; }
  .book-cover { width: min(200px, 56vw); }
  .cover-live { grid-template-columns: 1fr; gap: 10px; }
  .paths { grid-template-columns: 1fr; gap: 14px; }
}
@media (max-width: 600px) {
  body { font-size: 16.5px; }
  table { font-size: 13px; }
  th, td { padding: 6px 7px; }
  td { min-width: 6.5em; }
  .callout .table-wrap { margin-left: -6px; margin-right: -8px; }
  .article h1 { font-size: 1.65rem; }
  .article h2 { font-size: 1.24rem; }
  .crumbs { display: none; }
  .fig { padding: 10px 8px 8px; border-radius: 8px; }
  .callout { padding: 9px 11px 1px; }
  .brief { padding: 9px 12px 3px; }
  .brief-rows { grid-template-columns: minmax(0, 1fr); }
  .brief-rows dt { margin-bottom: 2px; }
  .pager { flex-direction: column; gap: 6px; }
  .pager a { max-width: 100%; }
}
@media print {
  .topbar, .sidebar, .toc, .pager, .fig-top, .fig-transport, .fig-hint, .search-panel { display: none !important; }
  body { padding-top: 0; }
  .layout { display: block; }
  .main { padding: 0; }
  details { display: block; }
  details > :not(summary) { display: block !important; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* step-through derivations */
.deriv-bar { display: inline-flex; gap: 6px; align-items: center; margin-left: 10px; vertical-align: 1px; }
.deriv-btn { font: 500 12px/1 var(--font-ui); padding: 4px 9px; border-radius: 6px; border: 1px solid var(--rule); background: var(--bg); color: var(--ink-2); cursor: pointer; }
.deriv-btn:hover:not(:disabled) { border-color: var(--c, var(--accent)); color: var(--ink); }
.deriv-btn:disabled { opacity: 0.4; cursor: default; }
.deriv-next { background: var(--c, var(--accent)); border-color: var(--c, var(--accent)); color: var(--bg); }
.deriv-count { font: 400 12px var(--font-ui); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.callout li { transition: opacity 0.2s, filter 0.2s; }
.deriv-future { opacity: 0.12; filter: blur(2.5px); user-select: none; }
@media (prefers-reduced-motion: reduce) { .deriv-future { filter: none; opacity: 0.08; } }


/* code highlighting (build time, highlight.js classes) */
:root { --hl-kw: #5b4a8f; --hl-str: #356342; --hl-num: #7d5019; --hl-com: #666666; --hl-fn: #38538f; --hl-built: #8a3d79; }
:root[data-theme="dark"] { --hl-kw: #b8a9ea; --hl-str: #86ba93; --hl-num: #d1a56b; --hl-com: #9a9a9a; --hl-fn: #9bb0e4; --hl-built: #e6addb; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --hl-kw: #b8a9ea; --hl-str: #86ba93; --hl-num: #d1a56b; --hl-com: #9a9a9a; --hl-fn: #9bb0e4; --hl-built: #e6addb; } }
.hljs-keyword, .hljs-meta .hljs-keyword { color: var(--hl-kw); }
.hljs-string, .hljs-regexp { color: var(--hl-str); }
.hljs-number, .hljs-literal { color: var(--hl-num); }
.hljs-comment { color: var(--hl-com); font-style: italic; }
.hljs-title.function_, .hljs-title { color: var(--hl-fn); }
.hljs-built_in, .hljs-type { color: var(--hl-built); }
.hljs-params { color: inherit; }

/* Controls never push the page wider than the column: a long label wraps,
   and a slider row breaks onto two lines in a narrow figure. */
.fig-controls > * { max-width: 100%; }
.fig-ctl-name { min-width: 0; }
/* A slider's name keeps its full width; the slider shrinks instead. */
.fig-range .fig-ctl-name { flex-shrink: 0; }
@container (max-width: 480px) {
  .fig-range { flex-wrap: wrap; flex-basis: 100%; }
  .fig-range .fig-ctl-name { white-space: normal; flex: 1 1 100%; }
  .fig-range input { flex: 1 1 auto; }
  .fig-seg legend { float: none; line-height: 1.4; margin-bottom: 4px; }
}

/* bibliography: jump bar, filter, letter groups */
.bib-tools { position: sticky; top: var(--top); z-index: 5; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 8px 0; margin: 0 0 4px; background: var(--bg); border-bottom: 1px solid var(--rule); font: 400 13px/1.3 var(--font-ui); }
.bib-filter { flex: 1 1 280px; min-width: 0; font: inherit; padding: 6px 10px; border: 1px solid var(--rule); border-radius: 6px; background: var(--bg); color: var(--ink); }
.bib-filter:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.bib-az { display: flex; flex-wrap: wrap; gap: 1px; }
.bib-az a { min-width: 1.5em; text-align: center; padding: 2px 3px; border-radius: 4px; color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: 12px; }
.bib-az a:hover { background: var(--bg-2); color: var(--accent-ink); }
.bib-count { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.article h2.bib-letter { font-size: 0.95rem; margin: 1.2em 0 0.4em; color: var(--ink-3); scroll-margin-top: calc(var(--top) + 56px); }
.bib-letter .anchor { display: none; }
.bib-group[hidden], .ref-list-all li[hidden] { display: none; }

/* ---------------------------------------------------------- Chinese edition */
/* Latin letters and digits are set in Inter; Chinese characters fall through
   to the system's sans, as on the other pages. Chinese has no italic, so
   emphasis is set in weight. */
:root[lang="zh"] body { line-height: 1.8; }
:root[lang="zh"] .article, :root[lang="zh"] .article p { hyphens: none; -webkit-hyphens: none; }
:root[lang="zh"] .article em, :root[lang="zh"] .article i { font-style: normal; font-weight: 600; }
:root[lang="zh"] .article h1, :root[lang="zh"] .article h2, :root[lang="zh"] .article h3 { letter-spacing: 0; }
:root[lang="zh"] .cover-text p, :root[lang="zh"] .cover-live-text p { line-height: 1.75; }
.status-untranslated { color: var(--ink-3); }
.lang-btn { width: auto; min-width: 36px; padding: 0 8px; font: 500 13px/1 var(--font-ui); text-decoration: none; }
