/*
  DataDeep Research Library, read.datadeep.tech.

  THR tokens first. Night mode redefines the page tokens, never the components,
  and its colours arrive from boot.js as --night-* so a reader can choose any.
  Colour literals live in the token block and nowhere below it, apart from the
  figure plate and print, which are white by definition.
*/

:root {
  --thr-ink: #1B2330;
  --thr-royal: #10398C;
  --thr-royal-hover: #2E59B8;
  --thr-royal-tint: #EAF0FA;
  --thr-paper: #FFFFFF;
  --thr-surface: #F6F8FB;
  --thr-line: #E2E6EC;
  --thr-line-strong: #C9D0DA;
  --thr-muted: #6B7480;
  --thr-hover-row: #ECEFF4;
  --thr-highlight: #FFF1B8;
  --labs-night: #1E2023;
  --labs-night-raised: #24272B;

  --font-serif: "Lora", Georgia, "Times New Roman", serif;
  --font-sans: "TeX Gyre Heros", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace;

  --bg: var(--thr-paper);
  --raised: var(--thr-surface);
  --text: var(--thr-ink);
  --muted: var(--thr-muted);
  --line: var(--thr-line);
  --line-strong: var(--thr-line-strong);
  --accent: var(--thr-royal);
  --accent-hover: var(--thr-royal-hover);
  --accent-tint: var(--thr-royal-tint);
  --accent-ink: var(--thr-paper);
  --focus: var(--thr-royal);
  --hit: var(--thr-highlight);
  --cover-bg: var(--thr-ink);
  --cover-text: var(--thr-paper);
  --shadow-md: 0 4px 12px rgba(27, 35, 48, 0.08);
  --shadow-lg: 0 12px 32px rgba(27, 35, 48, 0.12);
  --glow: none;

  --bar-h: 56px;
  --dock-h: 0px;
  --size: 1;
  --leading: 1.7;
  --measure: 68ch;
  --text-size: calc(1.125rem * var(--size));
  --ease: cubic-bezier(0.2, 0, 0, 1);
  color-scheme: light;
}

:root[data-theme="night"] {
  --bg: var(--labs-night);
  --raised: var(--labs-night-raised);
  --text: var(--night-text, #39FF14);
  --muted: var(--night-muted, #2FC316);
  --line: var(--night-line, rgba(57, 255, 20, 0.18));
  --line-strong: var(--night-line, rgba(57, 255, 20, 0.18));
  --accent: var(--night-text, #39FF14);
  --accent-hover: var(--night-text, #39FF14);
  --accent-tint: var(--night-faint, rgba(57, 255, 20, 0.08));
  --accent-ink: var(--labs-night);
  --focus: var(--night-text, #39FF14);
  --hit: var(--night-mark, rgba(57, 255, 20, 0.28));
  --cover-bg: var(--labs-night-raised);
  --cover-text: var(--night-text, #39FF14);
  --shadow-md: 0 0 0 1px var(--line);
  --shadow-lg: 0 0 0 1px var(--line), 0 12px 32px rgba(0, 0, 0, 0.45);
  --glow: 0 0 10px var(--night-glow, rgba(57, 255, 20, 0.35));
  color-scheme: dark;
}

:root[data-leading="compact"] { --leading: 1.5; }
:root[data-leading="airy"] { --leading: 1.9; }
:root[data-measure="narrow"] { --measure: 56ch; }
:root[data-measure="wide"] { --measure: 82ch; }

/* ---------------------------------------------------------------- base -- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--bar-h) + 16px); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-sans); font-size: 1rem; line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  padding-bottom: var(--dock-h);
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
button, input, select { font: inherit; color: inherit; }
img, svg { max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 16px; top: -64px; z-index: 100; background: var(--accent); color: var(--accent-ink); padding: 10px 16px; border-radius: 6px; }
.skip:focus { top: 8px; }
.over {
  margin: 0; font-family: var(--font-sans); font-size: 12px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { display: block; flex: none; }

.btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px;
  font-family: var(--font-sans); font-size: 15px; font-weight: 500; text-decoration: none;
  color: var(--text); background: var(--bg); border: 1px solid var(--line-strong); border-radius: 6px; cursor: pointer;
  transition: border-color 120ms var(--ease), color 120ms var(--ease), background 120ms var(--ease);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
[data-theme="night"] .btn.primary { box-shadow: var(--glow); }

.tool {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 40px; min-height: 40px; padding: 0 10px;
  background: none; border: 1px solid transparent; border-radius: 6px; color: var(--text); cursor: pointer; font-size: 14px;
}
.tool:hover { border-color: var(--line-strong); color: var(--accent); }
.tool[aria-expanded="true"] { background: var(--accent-tint); color: var(--accent); }

/* ------------------------------------------------------------- top bar -- */

.progress { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 41; pointer-events: none; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); box-shadow: var(--glow); }

.bar {
  position: sticky; top: 0; z-index: 40; height: var(--bar-h);
  display: flex; align-items: center; gap: 16px; padding: 0 16px 0 20px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  transition: transform 200ms var(--ease);
}
.bar.is-hidden { transform: translateY(-100%); }
.brand { display: inline-flex; align-items: center; flex: none; border-radius: 4px; }
.logo { display: block; height: 26px; width: auto; mix-blend-mode: multiply; }
[data-theme="night"] .logo { filter: invert(1) hue-rotate(180deg) brightness(1.15); mix-blend-mode: screen; }
.bar-label {
  font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); text-decoration: none;
  padding-left: 16px; border-left: 1px solid var(--line); line-height: 20px;
}
.bar-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 12px; padding-left: 16px; border-left: 1px solid var(--line); }
.bar-book { font-family: var(--font-serif); font-weight: 600; font-size: 16px; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.bar-ch { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.bar-tools { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.is-library .bar-tools .tool-label { position: static; width: auto; height: auto; clip: auto; }
.tool-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (min-width: 1400px) {
  .is-book .tool-label { position: static; width: auto; height: auto; clip: auto; }
}
.goto { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); padding: 0 8px; }
.goto input {
  width: 4.2em; min-height: 36px; padding: 0 8px; text-align: right; font-variant-numeric: tabular-nums;
  background: var(--bg); color: var(--text); border: 1px solid var(--line-strong); border-radius: 6px;
}
.goto span { font-variant-numeric: tabular-nums; white-space: nowrap; }

.preview-note {
  padding: 10px 20px; font-size: 14px; background: var(--accent-tint); color: var(--text); border-bottom: 1px solid var(--line);
}

/* -------------------------------------------------------------- layout -- */

.layout { display: grid; grid-template-columns: minmax(0, 1fr); }
.toc {
  position: fixed; z-index: 45; top: 0; bottom: 0; left: 0; width: min(88vw, 360px);
  background: var(--bg); border-right: 1px solid var(--line); overflow-y: auto; overscroll-behavior: contain;
  transform: translateX(-102%); transition: transform 220ms var(--ease); visibility: hidden;
  padding: 0 0 48px;
}
.toc.is-open { transform: none; visibility: visible; box-shadow: var(--shadow-lg); }
.toc-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 20px; background: var(--bg); border-bottom: 1px solid var(--line); }
.scrim { position: fixed; inset: 0; z-index: 44; background: rgba(27, 35, 48, 0.32); }
[data-theme="night"] .scrim { background: rgba(0, 0, 0, 0.55); }

@media (min-width: 1200px) {
  .is-book .layout { grid-template-columns: 300px minmax(0, 1fr); }
  .is-book .toc {
    position: sticky; top: var(--bar-h); height: calc(100vh - var(--bar-h)); width: auto; transform: none; visibility: visible;
    box-shadow: none; z-index: 1;
  }
  .is-book .toc .toc-head [data-close] { display: none; }
  .is-book.toc-closed .layout { grid-template-columns: 0 minmax(0, 1fr); }
  .is-book.toc-closed .toc { visibility: hidden; overflow: hidden; border: 0; }
  .is-book .scrim { display: none; }
}

.toc-list, .toc-sec { list-style: none; margin: 0; padding: 0; }
.toc-list { padding: 8px 8px 0; }
.toc-list a {
  display: flex; align-items: baseline; gap: 10px; padding: 7px 12px; border-radius: 6px;
  color: var(--text); text-decoration: none; font-size: 14px; line-height: 1.35;
}
.toc-list a:hover { background: var(--accent-tint); color: var(--accent); }
.toc-n { flex: none; min-width: 1.6em; font-variant-numeric: tabular-nums; color: var(--muted); }
.toc-t { flex: 1; min-width: 0; }
.toc-p { flex: none; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.toc-ch > a { font-weight: 500; }
.toc-front > a { color: var(--muted); }
.toc-sec a { padding-left: 42px; font-size: 13px; color: var(--muted); }
.toc-sec .lvl-4 a { padding-left: 58px; }
.toc-sec { display: none; }
.toc-ch.is-current .toc-sec, .toc-ch.is-expanded .toc-sec { display: block; }
.toc-list .is-current > a { color: var(--accent); background: var(--accent-tint); }
.toc-sec .is-current > a { background: none; font-weight: 500; }
.is-hidden-ch > a .toc-t::after { content: " (hidden)"; color: var(--muted); font-weight: 400; }

/* ---------------------------------------------------------------- book -- */

.book { min-width: 0; padding: 0 20px 64px; }
.book, .front, .ch { container-type: inline-size; }

.front {
  max-width: 64rem; margin: 0 auto; padding: 48px 0 40px; border-bottom: 1px solid var(--line);
  display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); gap: 32px 40px; align-items: start;
}
.front-text h1 {
  font-family: var(--font-serif); font-weight: 600; font-size: clamp(2rem, 1.2rem + 3vw, 3rem);
  line-height: 1.12; letter-spacing: -0.01em; margin: 8px 0 12px; text-wrap: balance;
}
.front-sub { font-family: var(--font-serif); font-size: 1.25rem; line-height: 1.45; margin: 0 0 12px; color: var(--text); }
.front-by { margin: 0 0 16px; color: var(--muted); font-size: 15px; }
.front-summary { font-family: var(--font-serif); font-size: 1.05rem; line-height: 1.65; margin: 0 0 20px; max-width: 62ch; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: 12px 24px; margin: 0 0 24px; }
.facts div { border-top: 1px solid var(--line); padding-top: 8px; }
.facts dt { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-size: 16px; font-variant-numeric: tabular-nums; }
.front-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.front-license { font-size: 14px; color: var(--muted); margin: 16px 0 0; }
.front .disclosure, .front-toc { grid-column: 1 / -1; }
.disclosure {
  margin: 0; padding: 12px 16px; font-size: 13px; line-height: 1.55; color: var(--muted);
  border: 1px solid var(--line); border-radius: 8px; background: var(--raised);
}
.front-toc h2 { margin-bottom: 8px; }
.front-toc ol { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.front-toc li { border-bottom: 1px solid var(--line); }
.front-toc a { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr) auto; gap: 16px; padding: 12px 4px; color: var(--text); text-decoration: none; align-items: baseline; }
.front-toc a:hover { background: var(--accent-tint); }
.ft-label { font-size: 13px; color: var(--muted); }
.ft-title { font-family: var(--font-serif); font-size: 1.05rem; }
.ft-page { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.front-toc .empty { padding: 16px 4px; color: var(--muted); }
@media (max-width: 720px) {
  .front { grid-template-columns: 1fr; padding-top: 28px; }
  .front-cover { max-width: 180px; }
  .front-toc a { grid-template-columns: minmax(0, 1fr) auto; }
  .ft-label { grid-column: 1 / -1; }
}

/* Every chapter is laid out only when it comes near the screen, so 340 pages
   cost what a few pages cost. Find in page, links and printing still reach it. */
.ch {
  content-visibility: auto; contain-intrinsic-size: auto 6000px;
  display: grid; grid-template-columns: minmax(0, 1fr) min(var(--measure), 100%) minmax(0, 1fr);
  font-family: var(--font-serif); font-size: var(--text-size); line-height: var(--leading);
  padding: 32px 0 16px;
}
[data-face="sans"] .ch { font-family: var(--font-sans); }
.ch > * { grid-column: 2; }
.ch > .fig, .ch > .tbl, .ch > .ch-nav { grid-column: 1 / -1; justify-self: center; width: min(100%, 60rem); }

.ch-head { padding: 24px 0 8px; }
.ch-label { margin: 0; font-family: var(--font-sans); font-size: 13px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.ch-head h2 {
  font-family: var(--font-serif); font-weight: 600; font-size: calc(2.3em * min(1, 1.25 / var(--size) + 0.2));
  line-height: 1.15; letter-spacing: -0.01em; margin: 8px 0 24px; text-wrap: balance;
}
[data-theme="night"] .ch-head h2 { text-shadow: var(--glow); }
.ch-hidden { font-family: var(--font-sans); font-size: 14px; color: var(--accent); background: var(--accent-tint); border-radius: 6px; padding: 8px 12px; margin: 0 0 16px; }

.ch p, .ch ul, .ch ol, .ch blockquote, .ch pre { margin: 0 0 1em; }
.ch h3, .ch h4, .ch h5 { font-family: var(--font-serif); line-height: 1.3; text-wrap: balance; }
.ch h3 { font-size: 1.45em; font-weight: 600; margin: 1.8em 0 0.6em; }
.ch h4 { font-size: 1.18em; font-weight: 600; margin: 1.5em 0 0.5em; }
.ch h5 { font-family: var(--font-sans); font-size: 0.9em; font-weight: 600; margin: 1.4em 0 0.4em; }
.hn { color: var(--accent); margin-right: 0.3em; font-variant-numeric: tabular-nums; }
.ch ul, .ch ol { padding-left: 1.4em; }
.ch li { margin: 0.25em 0; }
.ch li > p { margin: 0 0 0.5em; }
.ch blockquote { padding: 0.1em 0 0.1em 1.1em; border-left: 2px solid var(--accent); color: var(--text); }
.ch blockquote p:last-child { margin-bottom: 0; }
.ch code { font-family: var(--font-mono); font-size: 0.85em; background: var(--raised); border-radius: 4px; padding: 0.1em 0.3em; }
.ch pre { font-size: 0.8em; line-height: 1.5; background: var(--raised); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; overflow-x: auto; }
.ch pre code { background: none; padding: 0; }
.ch hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.ch sup.cite { font-family: var(--font-sans); font-size: 0.62em; line-height: 0; margin-left: 0.1em; }
.ch sup.cite a { text-decoration: none; }
.ch .refs { font-size: 0.86em; }
.ch .ref:target, .ch .ref.is-target { background: var(--accent-tint); border-radius: 4px; }
.task { font-family: var(--font-sans); }

/* Tables */
.tbl { margin: 1.4em 0 1.6em; overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.tbl table { width: 100%; border-collapse: collapse; font-family: var(--font-sans); font-size: calc(0.95rem * var(--size)); line-height: 1.45; }
.tbl th {
  text-align: left; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
  background: var(--raised); padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: bottom;
}
.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .mid { text-align: center; }

/* Page markers: a hairline and the number, where a printed page would turn. */
.pg {
  display: flex; justify-content: flex-end; align-items: center; margin: 1.2em 0 0.8em;
  border-top: 1px dashed var(--line-strong); font-family: var(--font-sans); font-size: 12px; line-height: 1;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.pg span { padding: 4px 0 0 8px; }
.pg span::before { content: "Page "; }
.ch > .pg:first-child { border-top: 0; margin: 0; }
[data-page-numbers="off"] .pg { border: 0; margin: 0; height: 0; overflow: hidden; }

/* Paragraph numbers, in the margin, where there is one. They are generated
   content, so they are never copied, searched or translated with the text. */
.b { position: relative; }
@media (min-width: 900px) {
  /* Keep a margin wide enough for the numbers, however large the text. */
  [data-para-numbers="on"] .ch { grid-template-columns: minmax(4.8rem, 1fr) min(var(--measure), 100% - 9.6rem) minmax(4.8rem, 1fr); }
  [data-para-numbers="on"] .ch .b::before {
    content: attr(data-n); position: absolute; left: -4.6rem; width: 3.6rem; top: 0.15em;
    font-family: var(--font-sans); font-size: 11px; line-height: calc(var(--text-size) * var(--leading)); text-align: right;
    color: var(--muted); opacity: 0.55; cursor: pointer; font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
  }
  [data-para-numbers="on"] .ch .b:hover::before { opacity: 1; color: var(--accent); }
}

.is-target { animation: target 2.6s var(--ease); }
@keyframes target {
  0%, 35% { background: var(--accent-tint); box-shadow: 0 0 0 10px var(--accent-tint); }
  100% { background: transparent; box-shadow: 0 0 0 10px transparent; }
}
::highlight(search) { background-color: var(--hit); color: inherit; }
::highlight(search-current) { background-color: var(--accent); color: var(--accent-ink); }
mark.search-hit { background: var(--hit); color: inherit; }
mark.search-hit.is-current { background: var(--accent); color: var(--accent-ink); }

/* Figures */
.fig { margin: 2em 0 2.2em; font-family: var(--font-sans); }
.fig-art {
  position: relative; overflow: hidden; background: var(--thr-paper); border: 1px solid var(--line); border-radius: 8px;
  padding: clamp(8px, 2cqi, 20px); max-height: none;
}
.fig-art > img, .fig-art > svg { display: block; width: 100%; height: auto; }
.fig-art > svg { overflow: visible; }
[data-theme="night"][data-figures="tint"] .fig-art,
[data-theme="night"][data-figures="invert"] .fig-art { background: transparent; }
[data-theme="night"][data-figures="tint"] .fig-art > * { filter: url(#night-tint); }
[data-theme="night"][data-figures="invert"] .fig-art > * { filter: invert(1) hue-rotate(180deg); }
.fig figcaption { margin: 10px 2px 0; font-size: 14px; line-height: 1.5; color: var(--muted); max-width: 72ch; }
.fig-n { font-weight: 600; color: var(--text); margin-right: 0.35em; }
.fig-tools { display: flex; flex-wrap: wrap; gap: 4px 2px; margin: 6px 0 0 -8px; }
.fig-tool {
  display: inline-flex; align-items: center; min-height: 32px; padding: 0 8px; font-size: 13px;
  color: var(--muted); background: none; border: 0; border-radius: 4px; text-decoration: none; cursor: pointer;
}
.fig-tool:hover { color: var(--accent); background: var(--accent-tint); }
.fig-text { margin: 4px 2px 0; font-size: 13px; color: var(--muted); }
.fig-text summary { cursor: pointer; min-height: 32px; display: inline-flex; align-items: center; }
.fig-text p { margin: 4px 0 0; line-height: 1.5; }
.fig-missing { font-family: var(--font-sans); font-size: 14px; color: var(--accent); background: var(--accent-tint); border-radius: 6px; padding: 10px 14px; }

.ch-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 48px auto 0; font-family: var(--font-sans); }
.ch-nav a {
  display: block; padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none;
  color: var(--text); font-size: 15px; line-height: 1.4;
}
.ch-nav a:hover { border-color: var(--accent); color: var(--accent); }
.ch-nav span { display: block; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.ch-next { text-align: right; }
@media (max-width: 560px) { .ch-nav { grid-template-columns: 1fr; } }

.book-end { max-width: var(--measure); margin: 32px auto 0; padding: 32px 0; border-top: 1px solid var(--line); font-size: 15px; }
.book-end p { margin: 8px 0; }

/* ---------------------------------------------------------------- covers -- */

.cover {
  display: flex; flex-direction: column; aspect-ratio: 3 / 4; width: 100%; padding: 14% 12% 10%;
  background: var(--cover-bg); color: var(--cover-text); border-radius: 8px; overflow: hidden;
  font-family: var(--font-serif); box-shadow: var(--shadow-md);
}
[data-theme="night"] .cover { border: 1px solid var(--line); }
.cover-topic { font-family: var(--font-sans); font-size: 10px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.72; }
.cover-title { margin-top: 12%; font-size: clamp(1rem, 0.7rem + 1.1vw, 1.35rem); font-weight: 600; line-height: 1.2; text-wrap: balance; overflow-wrap: anywhere; }
.cover.is-large .cover-title { font-size: clamp(1.1rem, 0.8rem + 1.2vw, 1.6rem); }
.cover-mark { margin-top: auto; width: 100%; height: 22%; color: var(--thr-royal-hover); }
[data-theme="night"] .cover-mark { color: var(--cover-text); }
.cover-foot { margin-top: 8%; font-family: var(--font-sans); font-size: 10px; letter-spacing: 0.04em; opacity: 0.72; }

/* -------------------------------------------------------------- library -- */

.library { max-width: 72rem; margin: 0 auto; padding: 48px 20px 72px; }
.lib-head { max-width: 46rem; margin-bottom: 32px; }
.lib-head h1, .notfound h1 {
  font-family: var(--font-serif); font-weight: 600; font-size: clamp(2rem, 1.3rem + 2.5vw, 2.75rem);
  letter-spacing: -0.01em; line-height: 1.15; margin: 8px 0 12px;
}
[data-theme="night"] .lib-head h1 { text-shadow: var(--glow); }
.lede { font-family: var(--font-serif); font-size: 1.15rem; line-height: 1.6; margin: 0; }
.lib-filter { margin: 0 0 24px; }
.lib-filter input {
  width: min(100%, 28rem); min-height: 44px; padding: 0 14px; font-size: 15px;
  background: var(--bg); color: var(--text); border: 1px solid var(--line-strong); border-radius: 6px;
}
.shelf { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 31rem), 1fr)); gap: 24px; }
.card { display: grid; grid-template-columns: 9.5rem minmax(0, 1fr); gap: 20px; padding: 20px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.card:hover { border-color: var(--line-strong); }
.card-cover { display: block; text-decoration: none; }
.card-title { font-family: var(--font-serif); font-weight: 600; font-size: 1.35rem; line-height: 1.25; margin: 6px 0 6px; }
.card-title a { color: var(--text); text-decoration: none; }
.card-title a:hover { color: var(--accent); text-decoration: underline; }
.card-title a::after { content: ""; position: absolute; inset: 0; }
.card { position: relative; }
.card-sub { font-family: var(--font-serif); margin: 0 0 8px; line-height: 1.45; }
.card-summary { margin: 0 0 10px; font-size: 14px; line-height: 1.55; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.card-facts { margin: 4px 0 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card-continue { margin: 10px 0 0; font-size: 14px; color: var(--accent); position: relative; z-index: 1; }
.empty { color: var(--muted); }
@media (max-width: 520px) { .card { grid-template-columns: 6.5rem minmax(0, 1fr); gap: 14px; padding: 14px; } .card-summary { display: none; } }

.site-foot { border-top: 1px solid var(--line); background: var(--raised); }
.site-foot-in { max-width: 72rem; margin: 0 auto; padding: 24px 20px 40px; font-size: 14px; color: var(--muted); }
.site-foot p { margin: 8px 0; }
.site-foot .disclosure { background: var(--bg); }
.notfound { max-width: 46rem; }

/* -------------------------------------------------------------- panels -- */

.panel {
  position: fixed; z-index: 60; top: 0; right: 0; bottom: 0; width: min(420px, 100vw);
  display: flex; flex-direction: column; background: var(--bg); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg);
  animation: panel-in 180ms var(--ease);
}
@keyframes panel-in { from { transform: translateX(24px); opacity: 0; } }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px 10px 20px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-family: var(--font-serif); font-weight: 600; font-size: 1.2rem; }
.panel-body { padding: 16px 20px 32px; overflow-y: auto; overscroll-behavior: contain; }
.panel-body h3 { margin: 20px 0 8px; }
.panel-body h3:first-child { margin-top: 4px; }
@media (max-width: 700px) {
  .panel { top: auto; left: 0; width: auto; max-height: 86vh; border-left: 0; border-top: 1px solid var(--line); border-radius: 12px 12px 0 0; animation-name: sheet-in; padding-bottom: env(safe-area-inset-bottom); }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
}

.seg-field { border: 0; margin: 0 0 18px; padding: 0; min-width: 0; }
.seg-field legend { padding: 0; margin-bottom: 8px; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.seg { display: flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 8px; font-size: 14px; text-align: center; border-left: 1px solid var(--line-strong); }
.seg label:first-child span { border-left: 0; }
.seg input:checked + span { background: var(--accent-tint); color: var(--accent); font-weight: 500; }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -3px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px 0 8px; border: 1px solid var(--line-strong); border-radius: 6px; font-size: 14px; cursor: pointer; }
.swatch > input[type="radio"] { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.swatch > span { width: 20px; height: 20px; border-radius: 50%; background: var(--sw); border: 1px solid var(--thr-ink); box-shadow: inset 0 0 0 2px var(--labs-night); }
.swatch:has(input[type="radio"]:checked) { border-color: var(--accent); background: var(--accent-tint); color: var(--accent); }
.swatch:has(input[type="radio"]:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.swatch-custom input[type="color"] { position: relative; z-index: 1; width: 28px; height: 28px; padding: 0; border: 1px solid var(--line-strong); border-radius: 50%; background: none; cursor: pointer; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper input[type="range"] { flex: 1; accent-color: var(--accent); }
.stepper output { min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 36px; font-size: 15px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.keys { margin: 16px 0; font-size: 14px; }
.keys summary { cursor: pointer; min-height: 36px; display: flex; align-items: center; }
.keys dl { display: grid; grid-template-columns: 4em 1fr; gap: 6px 12px; margin: 8px 0 0; }
.keys dt { font-family: var(--font-mono); font-size: 13px; color: var(--accent); }
.keys dd { margin: 0; }

.search-form input {
  width: 100%; min-height: 44px; padding: 0 14px; font-size: 16px;
  background: var(--bg); color: var(--text); border: 1px solid var(--line-strong); border-radius: 6px;
}
.search-nav { display: flex; align-items: center; gap: 4px; margin: 8px 0; }
.search-nav p { flex: 1; margin: 0; font-size: 13px; color: var(--muted); }
.search-results { list-style: none; margin: 0; padding: 0; }
.search-results li { border-top: 1px solid var(--line); }
.search-results button {
  display: block; width: 100%; text-align: left; padding: 10px 6px; background: none; border: 0; cursor: pointer; color: var(--text); border-radius: 4px;
}
.search-results button:hover, .search-results .is-current button { background: var(--accent-tint); }
.sr-where { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; font-variant-numeric: tabular-nums; }
.sr-snip { display: block; font-family: var(--font-serif); font-size: 15px; line-height: 1.45; }
.sr-snip mark { background: var(--hit); color: inherit; }

.dl-list { list-style: none; margin: 0; padding: 0; }
.dl-list li { padding: 10px 0; border-top: 1px solid var(--line); }
.dl-list a { font-size: 16px; font-weight: 500; }
.dl-list a span { font-weight: 400; color: var(--muted); font-size: 14px; }
.dl-list p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.share-list { list-style: none; margin: 0 0 12px; padding: 0; }
.share-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 8px; padding: 10px 0; border-top: 1px solid var(--line); align-items: center; }
.share-label { grid-column: 1 / -1; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.share-list input { min-width: 0; min-height: 40px; padding: 0 10px; font-size: 14px; background: var(--raised); color: var(--text); border: 1px solid var(--line); border-radius: 6px; }
.cite-text { font-family: var(--font-serif); font-size: 15px; line-height: 1.55; padding: 12px 14px; background: var(--raised); border: 1px solid var(--line); border-radius: 8px; margin: 0 0 10px; user-select: all; }

/* ------------------------------------------------------ floating pieces -- */

.pop {
  position: absolute; z-index: 55; display: flex; gap: 2px; padding: 4px; background: var(--thr-ink); border-radius: 6px; box-shadow: var(--shadow-lg);
}
[data-theme="night"] .pop { background: var(--labs-night-raised); border: 1px solid var(--line); }
.pop button { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 10px; background: none; border: 0; border-radius: 4px; color: var(--thr-paper); font-size: 14px; cursor: pointer; }
[data-theme="night"] .pop button { color: var(--text); }
.pop button:hover { background: rgba(255, 255, 255, 0.12); }

.toast {
  position: fixed; z-index: 70; left: 50%; bottom: calc(24px + var(--dock-h)); transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px); padding: 10px 16px; background: var(--thr-ink); color: var(--thr-paper); border-radius: 6px; font-size: 14px;
  transition: opacity 160ms var(--ease), transform 160ms var(--ease);
}
[data-theme="night"] .toast { background: var(--labs-night-raised); color: var(--text); border: 1px solid var(--line); }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

.update-note {
  position: fixed; z-index: 50; right: 16px; bottom: calc(16px + var(--dock-h)); display: flex; align-items: center; gap: 12px;
  padding: 10px 10px 10px 16px; background: var(--bg); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: var(--shadow-lg); font-size: 14px;
}

.zoom { position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; background: var(--bg); }
.zoom-bar { display: flex; align-items: center; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.zoom-title { flex: 1; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zoom-stage { flex: 1; overflow: auto; padding: 16px; touch-action: pan-x pan-y pinch-zoom; }
.zoom-stage .fig-art { margin: 0 auto; transform-origin: top left; }

.dock { display: none; }
@media (max-width: 899px) {
  :root { --dock-h: calc(56px + env(safe-area-inset-bottom)); --bar-h: 52px; }
  .is-book .bar-tools > .tool { display: none; }
  .is-book .bar { padding: 0 8px 0 12px; gap: 10px; }
  .is-book .bar-title { padding-left: 10px; }
  .is-book .bar-ch { display: none; }
  .is-book .bar-book { max-width: none; }
  .logo { height: 22px; }
  .goto label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .is-book .dock {
    position: fixed; z-index: 42; left: 0; right: 0; bottom: 0; height: var(--dock-h); padding-bottom: env(safe-area-inset-bottom);
    display: grid; grid-template-columns: repeat(5, 1fr); background: var(--bg); border-top: 1px solid var(--line);
  }
  .dock button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    background: none; border: 0; color: var(--text); font-size: 11px; cursor: pointer;
  }
  .dock button[aria-expanded="true"] { color: var(--accent); }
  .is-library { --dock-h: 0px; }
  .book { padding: 0 16px 48px; }
}
@media (max-width: 380px) { .goto span { display: none; } }

/* --------------------------------------------------------------- motion -- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .is-target { animation: none; background: var(--accent-tint); }
}

/* ---------------------------------------------------------------- print -- */

@media print {
  :root, :root[data-theme="night"] {
    --bg: #FFFFFF; --raised: #FFFFFF; --text: #000000; --muted: #444444; --line: #BBBBBB; --line-strong: #BBBBBB;
    --accent: #000000; --accent-tint: transparent; --glow: none; --cover-bg: #1B2330; --cover-text: #FFFFFF;
    --text-size: 11pt; --leading: 1.5; --measure: 100%;
    color-scheme: light;
  }
  body { padding: 0; background: #FFFFFF; }
  .bar, .progress, .toc, .dock, .panel, .pop, .toast, .update-note, .zoom, .skip, .fig-tools, .ch-nav, .front-actions, .preview-note, .site-foot, .scrim, .lib-filter { display: none !important; }
  .layout { display: block; }
  .book { padding: 0; }
  .ch { content-visibility: visible; display: block; break-before: page; padding-top: 0; }
  .ch-head h2 { text-shadow: none; }
  .fig { break-inside: avoid; }
  .fig-art { border: 0; padding: 0; background: #FFFFFF; }
  .fig-art > * { filter: none !important; }
  .fig-text { display: none; }
  .b::before { display: none; }
  .pg { break-after: avoid; }
  a { color: inherit; text-decoration: none; }
  .front { display: block; border: 0; }
  .front-cover { display: none; }
  .front-toc { break-after: page; }
  h3, h4, h5 { break-after: avoid; }
  p { orphans: 3; widows: 3; }
}
