/* The 3D Handbook — styles */
@font-face { font-family: "Source Serif"; src: url(fonts/serif-400.woff2) format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Source Serif"; src: url(fonts/serif-400i.woff2) format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Source Serif"; src: url(fonts/serif-600.woff2) format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "Source Serif"; src: url(fonts/serif-700.woff2) format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Inter"; src: url(fonts/sans-400.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Inter"; src: url(fonts/sans-600.woff2) format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --bg: #f5f6f4;
  --bg-elev: #ffffff;
  --bg-sunk: #eaece8;
  --ink: #181b1f;
  --ink-2: #434950;
  --ink-3: #6b7279;
  --rule: #dce0db;
  --rule-strong: #c3c9c3;
  --accent: #1f5d73;
  --accent-ink: #164a5c;
  --accent-soft: #e2edf0;
  --link: #1d5480;
  --planned: #8d949a;
  --fig-bg: #ffffff;
  --c-overview: #6d4aa8; --c-topic: #1f6f8b; --c-term: #b4410f; --c-guide: #2f7d4f; --c-reference: #7a6a2a; --c-exercise: #a83262; --c-special: #555;
  --box-example: #eef4f7; --box-views: #f3f0f8; --box-try: #edf6ef; --box-note: #eff1ee; --box-warning: #faf1e8;
  --serif: "Source Serif", "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --topbar: 56px;
  --sidebar: 288px;
  --measure: 70ch;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121416; --bg-elev: #1a1d20; --bg-sunk: #0e1012; --ink: #e5e8e6; --ink-2: #b9bfc0; --ink-3: #868d90; --rule: #282c30; --rule-strong: #3a3f44;
    --accent: #6fb7cc; --accent-ink: #9ccfdd; --accent-soft: #16272d; --link: #8cc3e6; --planned: #737b80; --fig-bg: #f2f4f2;
    --c-overview: #b49be0; --c-topic: #7fc0d6; --c-term: #f0864f; --c-guide: #7cc79a; --c-reference: #d3c27b; --c-exercise: #e58bb0; --c-special: #aaa;
    --box-example: #15212a; --box-views: #1e1a29; --box-try: #152319; --box-note: #1a1d20; --box-warning: #281d14;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121416; --bg-elev: #1a1d20; --bg-sunk: #0e1012; --ink: #e5e8e6; --ink-2: #b9bfc0; --ink-3: #868d90; --rule: #282c30; --rule-strong: #3a3f44;
  --accent: #6fb7cc; --accent-ink: #9ccfdd; --accent-soft: #16272d; --link: #8cc3e6; --planned: #737b80; --fig-bg: #f2f4f2;
  --c-overview: #b49be0; --c-topic: #7fc0d6; --c-term: #f0864f; --c-guide: #7cc79a; --c-reference: #d3c27b; --c-exercise: #e58bb0; --c-special: #aaa;
  --box-example: #15212a; --box-views: #1e1a29; --box-try: #152319; --box-note: #1a1d20; --box-warning: #281d14;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar) + 16px); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--serif); font-size: 19px; line-height: 1.65; font-kerning: normal; font-variant-ligatures: common-ligatures; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
img { max-width: 100%; height: auto; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: var(--bg); padding: 6px 12px; z-index: 100; }
.skip:focus { left: 8px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 30; height: var(--topbar); display: flex; align-items: center; gap: 16px; padding: 0 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--rule); font-family: var(--sans); font-size: 14px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 600; white-space: nowrap; }
.brand-mark { width: 22px; height: 22px; background: url(favicon.svg) center/contain no-repeat; }
.topnav { display: flex; gap: 4px; margin-left: 8px; }
.topnav a { color: var(--ink-2); text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.topnav a:hover, .topnav a[aria-current] { background: var(--bg-sunk); color: var(--ink); }
.search { position: relative; margin-left: auto; width: min(340px, 40vw); }
.search input { width: 100%; height: 34px; padding: 0 12px; border: 1px solid var(--rule-strong); border-radius: 8px; background: var(--bg-elev); color: var(--ink); font: inherit; }
.search-results { position: absolute; top: 40px; right: 0; width: min(460px, 92vw); max-height: 70vh; overflow: auto; margin: 0; padding: 6px; list-style: none; background: var(--bg-elev); border: 1px solid var(--rule-strong); border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.14); }
.search-results li a { display: block; padding: 8px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
.search-results li a:hover, .search-results li a.active { background: var(--bg-sunk); }
.search-results .sr-title { font-weight: 600; }
.search-results .sr-sum { display: block; color: var(--ink-3); font-size: 13px; line-height: 1.4; margin-top: 2px; }
.search-results .sr-empty { padding: 10px; color: var(--ink-3); }
.search-results .planned .sr-title { color: var(--planned); }
.theme-btn, .menu-btn { flex: none; width: 34px; height: 34px; border: 1px solid var(--rule-strong); border-radius: 8px; background: var(--bg-elev); color: var(--ink); cursor: pointer; display: grid; place-items: center; }
.theme-btn::before { content: ""; width: 16px; height: 16px; border-radius: 50%; background: linear-gradient(90deg, var(--ink) 50%, transparent 50%); border: 1.5px solid var(--ink); }
.menu-btn { display: none; }
.menu-btn span, .menu-btn span::before, .menu-btn span::after { display: block; width: 16px; height: 1.5px; background: var(--ink); position: relative; }
.menu-btn span::before, .menu-btn span::after { content: ""; position: absolute; left: 0; }
.menu-btn span::before { top: -5px; } .menu-btn span::after { top: 5px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: calc(100vh - var(--topbar)); }
@media (min-width: 1320px) { .shell { grid-template-columns: var(--sidebar) minmax(0, 1fr) 240px; } }
.sidebar { position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); overflow-y: auto; padding: 20px 12px 40px 16px; border-right: 1px solid var(--rule); font-family: var(--sans); font-size: 13.5px; line-height: 1.45; background: var(--bg); }
.sidebar-links { display: none; }
.nav-part { margin-bottom: 4px; }
.nav-part > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 6px; font-weight: 600; color: var(--ink); }
.nav-part > summary::-webkit-details-marker { display: none; }
.nav-part > summary::before { content: "›"; display: inline-block; width: 10px; color: var(--ink-3); transition: transform .15s; }
.nav-part[open] > summary::before { transform: rotate(90deg); }
.nav-part > summary span:first-of-type { flex: 1; }
.nav-part > summary:hover { background: var(--bg-sunk); }
.nav-count { font-weight: 400; font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.nav-part-link { display: block; margin: 2px 0 2px 18px; padding: 4px 8px; font-size: 12.5px; color: var(--ink-3); text-decoration: none; border-radius: 5px; }
.nav-part-link:hover, .nav-part-link.current { color: var(--accent-ink); background: var(--bg-sunk); }
a.nav-ch { display: flex; align-items: center; gap: 8px; margin: 12px 0 3px 18px; padding: 5px 8px; font-size: 11.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--accent-ink); text-decoration: none; border-radius: 5px; }
a.nav-ch::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
a.nav-ch:hover, a.nav-ch.current { background: var(--accent-soft); }
a.nav-ch:hover::after, a.nav-ch.current::after { background: transparent; }
.sidebar ul { list-style: none; margin: 0 0 4px; padding: 0 0 0 22px; border-left: 1px solid var(--rule); margin-left: 26px; }
.sidebar li a { margin-left: -1px; }
.sidebar li a { display: block; padding: 4px 8px; border-radius: 5px; color: var(--ink-2); text-decoration: none; border-left: 2px solid transparent; }
.sidebar li a:hover { background: var(--bg-sunk); color: var(--ink); }
.sidebar li a.current { background: var(--accent-soft); color: var(--accent-ink); border-left-color: var(--accent); font-weight: 600; }
.sidebar li a.planned { color: var(--planned); }
.sidebar li a[data-type="term"]::before { content: "·"; margin-right: 4px; color: var(--ink-3); }

.main { min-width: 0; padding: 32px clamp(16px, 5vw, 64px) 64px; }
.toc { position: sticky; top: calc(var(--topbar) + 24px); align-self: start; max-height: calc(100vh - var(--topbar) - 48px); overflow-y: auto; padding: 0 16px 0 0; font-family: var(--sans); font-size: 13px; line-height: 1.4; display: none; }
@media (min-width: 1320px) { .toc { display: block; } }
.toc-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin: 0 0 8px; }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--rule); }
.toc li a { display: block; padding: 4px 0 4px 12px; color: var(--ink-3); text-decoration: none; margin-left: -1px; border-left: 2px solid transparent; }
.toc li.d3 a { padding-left: 24px; }
.toc li a:hover { color: var(--ink); }
.toc li a.active { color: var(--accent-ink); border-left-color: var(--accent); }

/* ---------- page ---------- */
.page { max-width: var(--measure); margin: 0 auto; }
.crumbs { font-family: var(--sans); font-size: 13px; color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.crumb-pos { margin-left: auto; }
.crumb-pos a { color: inherit; }
.page-head { margin: 18px 0 28px; padding-bottom: 24px; border-bottom: 1px solid var(--rule); }
.page-head h1 { font-size: clamp(2rem, 4.5vw, 2.75rem); line-height: 1.12; margin: 10px 0 12px; font-weight: 700; letter-spacing: -.01em; text-wrap: balance; }
.lede { font-size: 1.15em; color: var(--ink-2); margin: 0; line-height: 1.5; }
.type-chip { display: inline-block; font-family: var(--sans); font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; padding: 2px 8px; border-radius: 99px; color: var(--c, var(--ink-3)); border: 1px solid currentColor; line-height: 1.6; vertical-align: middle; white-space: nowrap; }
.type-chip[data-type="overview"] { --c: var(--c-overview); } .type-chip[data-type="topic"] { --c: var(--c-topic); } .type-chip[data-type="term"] { --c: var(--c-term); }
.type-chip[data-type="guide"] { --c: var(--c-guide); } .type-chip[data-type="reference"] { --c: var(--c-reference); } .type-chip[data-type="exercise"] { --c: var(--c-exercise); } .type-chip[data-type="special"] { --c: var(--c-special); }
.tags { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-family: var(--sans); font-size: 12px; color: var(--ink-3); background: var(--bg-sunk); padding: 2px 8px; border-radius: 4px; }

.prose > *:first-child { margin-top: 0; }
.prose h2 { font-size: 1.55rem; line-height: 1.25; margin: 2.2em 0 .6em; font-weight: 700; text-wrap: balance; }
.prose h3 { font-size: 1.2rem; line-height: 1.3; margin: 1.8em 0 .5em; font-weight: 600; }
.prose h4 { font-size: 1rem; margin: 1.5em 0 .4em; font-family: var(--sans); font-weight: 600; }
h1, h2, h3, h4 { position: relative; }
.anchor { position: absolute; left: -1.1em; color: var(--rule-strong); text-decoration: none; opacity: 0; font-weight: 400; }
h2:hover .anchor, h3:hover .anchor { opacity: 1; }
.prose p, .prose ul, .prose ol { margin: 0 0 1em; }
.prose li { margin: .25em 0; }
.prose li > ul, .prose li > ol { margin: .25em 0; }
.prose strong { font-weight: 700; }
.prose blockquote { margin: 1.4em 0; padding: .2em 0 .2em 1.2em; border-left: 3px solid var(--accent); color: var(--ink-2); font-style: italic; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.4em 0; }
.prose code { font-family: var(--mono); font-size: .85em; background: var(--bg-sunk); padding: .1em .35em; border-radius: 4px; }
.prose pre { background: var(--bg-sunk); padding: 14px 16px; border-radius: 8px; overflow-x: auto; font-size: 15px; line-height: 1.5; }
.prose pre code { background: none; padding: 0; }
a.wl { color: var(--link); text-decoration-style: solid; }
a.wl.planned { color: var(--ink-2); text-decoration-style: dashed; text-decoration-color: var(--planned); }
a.wl.planned:hover { color: var(--accent-ink); }
a.ext::after { content: "↗"; font-family: var(--sans); font-size: .7em; margin-left: 2px; vertical-align: super; line-height: 0; color: var(--ink-3); }
span.cite { font-family: var(--sans); font-size: .72em; color: var(--ink-3); letter-spacing: .005em; white-space: normal; }
span.cite a { color: var(--ink-3); text-decoration: underline; text-decoration-style: dotted; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
span.cite a:hover { color: var(--accent-ink); text-decoration-color: currentColor; }

.table-wrap { overflow-x: auto; margin: 1.4em 0; border: 1px solid var(--rule); border-radius: 8px; background: var(--bg-elev); }
.table-wrap table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: 14.5px; line-height: 1.45; }
.table-wrap th, .table-wrap td { text-align: left; vertical-align: top; padding: 9px 12px; border-bottom: 1px solid var(--rule); }
.table-wrap th { background: var(--bg-sunk); font-weight: 600; white-space: nowrap; }
.table-wrap tr:last-child td { border-bottom: 0; }
.table-wrap td span.cite { font-size: .88em; }

/* boxes */
.box { margin: 1.6em 0; border-radius: 10px; padding: 16px 20px 6px; border: 1px solid var(--rule); background: var(--box-note); }
.box-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; margin-bottom: 8px; font-family: var(--sans); }
.box-kind { font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); }
.box-title { font-weight: 600; font-size: 15.5px; color: var(--ink); }
.box-body { font-size: .95em; }
.box-body > :last-child { margin-bottom: 10px; }
.box-example { background: var(--box-example); border-color: color-mix(in srgb, var(--c-topic) 30%, var(--rule)); }
.box-example .box-kind { color: var(--c-topic); }
.box-views { background: var(--box-views); border-color: color-mix(in srgb, var(--c-overview) 30%, var(--rule)); }
.box-views .box-kind { color: var(--c-overview); }
.box-try { background: var(--box-try); border-color: color-mix(in srgb, var(--c-guide) 35%, var(--rule)); }
.box-try .box-kind { color: var(--c-guide); }
.box-try ul:has(input) { list-style: none; padding-left: 0; }
.box-try li:has(> input) { display: flex; gap: 10px; align-items: baseline; }
.box-try input.goal { width: 17px; height: 17px; accent-color: var(--c-guide); flex: none; transform: translateY(2px); cursor: pointer; }
.box-warning { background: var(--box-warning); border-color: color-mix(in srgb, var(--accent) 30%, var(--rule)); }
.box-warning .box-kind { color: var(--accent-ink); }

/* figures and videos */
.fig, .video { margin: 1.8em 0; }
.fig-media { background: var(--fig-bg); border: 1px solid var(--rule); border-radius: 10px; padding: 12px; display: flex; justify-content: center; }
.fig-media img { display: block; max-height: 560px; width: auto; }
figcaption { font-family: var(--sans); font-size: 13.5px; line-height: 1.5; color: var(--ink-2); margin-top: 8px; }
figcaption .credit { display: block; color: var(--ink-3); font-size: 12.5px; margin-top: 2px; }
.video-frame { position: relative; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: #111; }
.video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-play { position: absolute; inset: 0; width: 100%; border: 0; cursor: pointer; color: #fff; text-align: left; padding: clamp(16px, 4vw, 32px); display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; font-family: var(--sans); background: radial-gradient(120% 90% at 20% 10%, #3a2a20 0%, #141210 60%); }
.video-play:hover .play-icon { transform: translate(-50%, -50%) scale(1.06); background: var(--accent); }
.play-icon { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); width: 68px; height: 68px; border-radius: 50%; background: rgba(255,255,255,.14); border: 1.5px solid rgba(255,255,255,.6); transition: transform .15s, background .15s; }
.play-icon::after { content: ""; position: absolute; left: 27px; top: 21px; border-left: 20px solid #fff; border-top: 13px solid transparent; border-bottom: 13px solid transparent; }
.video-title { font-size: clamp(15px, 2.4vw, 19px); font-weight: 600; line-height: 1.3; }
.video-channel { font-size: 13px; opacity: .8; }
.video-consent { font-size: 11.5px; opacity: .55; margin-top: 4px; }

/* references, backlinks, prevnext */
.references, .backlinks { margin-top: 3em; padding-top: 1.2em; border-top: 1px solid var(--rule); font-family: var(--sans); font-size: 14px; line-height: 1.5; }
.references h2, .backlinks h2 { font-family: var(--serif); font-size: 1.25rem; margin: 0 0 .8em; }
.references h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); margin: 1.4em 0 .5em; }
.references ol { padding-left: 1.8em; }
.references li, .bib-list li { margin: .4em 0; color: var(--ink-2); }
.references li:target { background: var(--accent-soft); border-radius: 4px; }
.s-title { color: var(--ink); }
.s-type, .s-acc { color: var(--ink-3); font-size: .92em; }
.backlinks ul { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; }
.updated { font-family: var(--sans); font-size: 12.5px; color: var(--ink-3); margin-top: 2.4em; }
.prevnext { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; font-family: var(--sans); }
.pn { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border: 1px solid var(--rule); border-radius: 10px; text-decoration: none; color: var(--ink); background: var(--bg-elev); }
.pn:hover { border-color: var(--accent); color: var(--ink); }
.pn-next { text-align: right; }
.pn-dir { font-size: 12px; color: var(--ink-3); }
.pn-title { font-weight: 600; font-size: 15px; }
.pn-planned { font-size: 11.5px; color: var(--planned); }

/* special pages */
.route-legend, .az-filter { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 24px; font-family: var(--sans); font-size: 14px; }
.route-part h2 { font-size: 1.5rem; margin: 2em 0 .2em; }
.route-part h2 a, .ch-block h2 a { color: var(--ink); text-decoration: none; }
.route-part h2 a:hover, .ch-block h2 a:hover { color: var(--accent-ink); }
.route-part h3 { margin: 1.6em 0 .5em; }
.route-part h3 a { display: inline-flex; align-items: center; gap: 8px; font-family: var(--sans); font-size: 12.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--accent-ink); text-decoration: none; padding: 4px 10px; border-radius: 99px; background: var(--accent-soft); }
.route-part h3 a::after { content: "→"; letter-spacing: 0; }
.route-part h3 a:hover { background: var(--accent); color: var(--bg-elev); }
.route-list, .az-list { margin: 0; padding-left: 2.4em; }
.az-list { list-style: none; padding-left: 0; }
.az-letters { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 16px; font-family: var(--sans); font-size: 14px; position: sticky; top: var(--topbar); background: var(--bg); padding: 8px 0; z-index: 2; border-bottom: 1px solid var(--rule); }
.az-letters a { padding: 3px 9px; border-radius: 5px; text-decoration: none; }
.az-letters a:hover { background: var(--bg-sunk); }
.az-group h2 { font-size: 1.6rem; margin: 1.4em 0 .3em; }
.az-filter button { font: inherit; padding: 5px 12px; border: 1px solid var(--rule-strong); background: var(--bg-elev); color: var(--ink-2); border-radius: 99px; cursor: pointer; }
.az-filter button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.az-written { margin-left: 8px; color: var(--ink-2); display: flex; gap: 6px; align-items: center; }
.bib-tools input { width: 100%; max-width: 420px; height: 38px; padding: 0 12px; border: 1px solid var(--rule-strong); border-radius: 8px; background: var(--bg-elev); color: var(--ink); font-family: var(--sans); font-size: 15px; margin-bottom: 12px; }
.bib-list { list-style: none; padding: 0; font-family: var(--sans); font-size: 14px; line-height: 1.5; }
.bib-list li { padding: 10px 0; border-bottom: 1px solid var(--rule); margin: 0; }
.bib-used { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; }
.bib-group h2 { font-size: 1.4rem; margin: 1.8em 0 .4em; }
.planned-page .lede { color: var(--ink-3); }

/* cover */
.is-cover .main { padding-top: 0; }
.cover { max-width: 1040px; margin: 0 auto; }
.cover-hero { padding: clamp(40px, 8vw, 96px) 0 40px; border-bottom: 1px solid var(--rule); }
.cover-kicker { font-family: var(--sans); font-size: 13px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent-ink); margin: 0 0 14px; }
.cover h1 { font-size: clamp(2.4rem, 7vw, 4.4rem); line-height: 1.02; margin: 0 0 18px; letter-spacing: -.02em; max-width: 14ch; }
.cover-sub { font-size: clamp(1.1rem, 2.2vw, 1.35rem); color: var(--ink-2); max-width: 46ch; margin: 0 0 28px; line-height: 1.45; }
.cover-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.btn { font-family: var(--sans); font-size: 15px; font-weight: 600; padding: 10px 18px; border-radius: 8px; border: 1px solid var(--rule-strong); background: var(--bg-elev); color: var(--ink); text-decoration: none; }
.btn:hover { border-color: var(--accent); color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--bg-elev); }
.btn-primary:hover { background: var(--accent-ink); color: var(--bg-elev); }
.cover-parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 14px; padding: 32px 0 16px; }

.site-footer { border-top: 1px solid var(--rule); padding: 18px 16px; font-family: var(--sans); font-size: 12.5px; color: var(--ink-3); text-align: center; }
.site-footer a { color: inherit; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: grid; }
  .topnav { display: none; }
  .sidebar { position: fixed; top: var(--topbar); left: 0; bottom: 0; width: min(320px, 86vw); height: auto; z-index: 40; transform: translateX(-102%); transition: transform .2s ease; box-shadow: 4px 0 24px rgba(0,0,0,.15); }
  .sidebar.open { transform: none; }
  .sidebar-links { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--rule); }
  .sidebar-links a { padding: 5px 10px; border: 1px solid var(--rule-strong); border-radius: 99px; color: var(--ink); text-decoration: none; font-size: 13px; }
  .scrim { position: fixed; inset: var(--topbar) 0 0 0; background: rgba(0,0,0,.3); z-index: 35; }
  .anchor { display: none; }
}
@media (max-width: 640px) {
  body { font-size: 17.5px; }
  .brand-text { display: none; }
  .search { width: auto; flex: 1; }
  .main { padding: 20px 16px 48px; }
  .crumb-pos { margin-left: 0; width: 100%; }
  .prevnext { grid-template-columns: 1fr; }
  .pn-next { text-align: left; }
  .box { padding: 14px 14px 4px; }
}
@media print {
  .topbar, .sidebar, .toc, .prevnext, .site-footer, .scrim, .skip, .lightbox, .rthumb, .yt-play, .ext-frame button, .backlinks, #preview-toggle { display: none !important; }
  :root, :root[data-theme="dark"] { color-scheme: light; }
  .shell { display: block; } .main { padding: 0; max-width: none; }
  body { background: #fff !important; color: #000 !important; font-size: 10.5pt; }
  .prose a { color: #000; text-decoration: underline; }
  a.ext::after, .rtitle a::after { content: " (" attr(href) ")"; font-size: 8pt; word-break: break-all; color: #444; }
  .box, figure, table, .rcard, pre { break-inside: avoid; }
  h2, h3 { break-after: avoid; }
  .rgrid { display: block; } .rcard { border: 0; border-left: 2px solid #999; border-radius: 0; margin: 0 0 8px; padding-left: 8px; box-shadow: none; }
  img { max-width: 100% !important; }
}
/* link back to the portfolio (set portfolioUrl in handbook.config.json) */
.back-home { color: var(--ink-2); text-decoration: none; white-space: nowrap; padding: 6px 10px 6px 0; margin-right: 2px; border-right: 1px solid var(--rule); }
.back-home:hover { color: var(--accent); }
@media (max-width: 640px) { .back-label { display: none; } .back-home { padding-right: 8px; } }
.site-footer > div + div { margin-top: 4px; }

/* clickable rows in route, A–Z, part and chapter lists */
.route-list, .az-list, .row-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.route-list li, .az-list li, .row-list li { margin: 0; }
.row-list.numbered, .route-list { counter-reset: row var(--start, 0); }
.row-link { display: block; padding: 10px 14px; border: 1px solid var(--rule); border-radius: 10px; background: var(--bg-elev); text-decoration: none; color: var(--ink); transition: border-color .12s, background .12s; }
.row-link:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.row-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.row-title { font-weight: 700; font-size: 1.02rem; line-height: 1.3; }
.row-sum { display: block; margin-top: 3px; color: var(--ink-2); font-size: .86em; line-height: 1.45; }
.row-planned { font-family: var(--sans); font-size: 11.5px; color: var(--planned); }
li.planned .row-link { background: transparent; border-style: dashed; }
li.planned .row-title { color: var(--planned); font-weight: 600; }
.ch-block h2 { font-size: 1.3rem; margin: 1.8em 0 .6em; }

/* lightbox */
.fig-media img, .prose > p img { cursor: zoom-in; }
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(10,12,14,.985); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); display: flex; flex-direction: column; padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px)); }
.lightbox[hidden] { display: none; }
.lb-bar { display: flex; justify-content: flex-end; gap: 8px; flex: none; }
.lb-bar button { font: 600 13px var(--sans); color: #fff; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.3); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.lb-bar button:hover { background: rgba(255,255,255,.22); }
.lb-stage { flex: 1; min-height: 0; overflow: auto; display: flex; align-items: center; justify-content: center; margin: 10px 0; }
.lb-stage img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 6px; cursor: zoom-in; touch-action: pinch-zoom; }
.lightbox.zoomed .lb-stage { align-items: flex-start; justify-content: flex-start; }
.lightbox.zoomed .lb-stage img { max-width: none; max-height: none; width: var(--zw, auto); cursor: zoom-out; }
.lb-cap { flex: none; color: #e6e8e6; font: 13.5px/1.5 var(--sans); max-width: 80ch; margin: 0 auto; text-align: center; }
.lb-cap .credit { display: block; color: #a9b0b3; font-size: 12px; }
.lb-cap a { color: #9ccfdd; }
@media (prefers-reduced-motion: reduce) { .row-link { transition: none; } }

/* click-to-load external media */
.ext-embed { margin: 1.8em 0; }
.ext-frame { position: relative; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: var(--bg-sunk); border: 1px solid var(--rule); }
.ext-frame.is-img { aspect-ratio: auto; min-height: 220px; display: flex; justify-content: center; align-items: center; background: var(--fig-bg); }
.ext-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.ext-frame img { display: block; max-width: 100%; max-height: 600px; cursor: zoom-in; }
.ext-load { position: absolute; inset: 0; width: 100%; border: 0; cursor: pointer; background: repeating-linear-gradient(135deg, var(--bg-sunk) 0 14px, var(--bg) 14px 28px); color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 20px; text-align: center; font-family: var(--sans); }
.ext-load:hover .ext-kind { background: var(--accent); color: var(--bg-elev); }
.ext-kind { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; padding: 5px 12px; border-radius: 99px; background: var(--accent-soft); color: var(--accent-ink); }
.ext-title { font-family: var(--serif); font-size: 1.05rem; font-weight: 600; max-width: 46ch; }
.ext-note { font-size: 12.5px; color: var(--ink-3); max-width: 50ch; }
.ext-fail { font-family: var(--sans); font-size: 14px; color: var(--ink-2); padding: 20px; text-align: center; }
.ext-pref { display: flex; gap: 6px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--ink-3); cursor: pointer; }

/* ---------- resource cards ---------- */
.rgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin: 1.2em 0 1.6em; }
.rcard { display: flex; flex-direction: column; background: var(--bg-elev); border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; transition: border-color .15s, transform .15s, box-shadow .15s; }
.rcard:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.08); }
.rthumb { position: relative; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; aspect-ratio: 16 / 9; padding: 10px 12px; text-decoration: none; color: #fff; background: var(--rk, #46525a); background-size: cover; background-position: center; font-family: var(--sans); }
.rthumb::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgba(0,0,0,.55), rgba(0,0,0,0) 55%); pointer-events: none; }
.rthumb > span { position: relative; z-index: 1; }
.rkind { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.rhost { font-size: 12px; opacity: .85; }
.rplay { position: absolute !important; top: 50%; left: 50%; width: 46px; height: 32px; transform: translate(-50%, -50%); border-radius: 8px; background: rgba(0,0,0,.6); }
.rplay::before { content: ""; position: absolute; left: 50%; top: 50%; transform: translate(-35%, -50%); border-style: solid; border-width: 8px 0 8px 13px; border-color: transparent transparent transparent #fff; }
.rcard:hover .rplay { background: #c4302b; }
.rthumb.is-loaded { background-color: #222; }
.rcard[data-kind="video"] .rthumb { --rk: #3b2a2a; }
.rcard[data-kind="breakdown"] .rthumb { --rk: #1d3b4a; }
.rcard[data-kind="talk"] .rthumb { --rk: #4a3a1d; }
.rcard[data-kind="course"] .rthumb { --rk: #2f4a2a; }
.rcard[data-kind="article"] .rthumb { --rk: #3e3550; }
.rcard[data-kind="docs"] .rthumb { --rk: #1f5d73; }
.rcard[data-kind="forum"] .rthumb { --rk: #5a4632; }
.rcard[data-kind="paper"] .rthumb, .rcard[data-kind="book"] .rthumb { --rk: #4b4b4b; }
.rbody { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px 12px; flex: 1; }
.rtitle { font-family: var(--sans); font-weight: 600; font-size: 14.5px; line-height: 1.35; color: var(--ink); text-decoration: none; }
.rtitle:hover { color: var(--accent); text-decoration: underline; }
.rnote { font-size: 13.5px; line-height: 1.45; color: var(--ink-2); }
.rnote .cite { display: none; }
.rmeta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; padding-top: 4px; }
.rb { font-family: var(--sans); font-size: 11px; padding: 2px 7px; border-radius: 99px; border: 1px solid var(--rule); color: var(--ink-3); }
.rb-free { color: #2e7d32; border-color: rgba(46,125,50,.4); }
.rb-paid { color: #b45309; border-color: rgba(180,83,9,.4); }
.rused { font-family: var(--sans); font-size: 12px; color: var(--ink-3); border-top: 1px solid var(--rule); padding-top: 6px; margin-top: 4px; }
.rplain { margin-top: .4em; }
.rnotice { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; font-family: var(--sans); font-size: 13px; color: var(--ink-3); border: 1px dashed var(--rule); border-radius: 8px; padding: 8px 12px; margin: 1em 0 0; }
.rnotice button, .res-chips .chip { font: inherit; font-size: 13px; padding: 5px 11px; border-radius: 99px; border: 1px solid var(--rule); background: transparent; color: var(--ink); cursor: pointer; }
.rnotice button { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.res-tools { display: flex; flex-direction: column; gap: 10px; margin: 1.2em 0; }
.res-tools input { font: inherit; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--rule); background: transparent; color: var(--ink); }
.res-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.res-chips .chip span { opacity: .6; margin-left: 2px; }
.res-chips .chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.page.wide { max-width: min(1180px, 100%); }
.video-frame.is-loaded .video-play { background-size: cover !important; background-position: center !important; }
.video-frame.is-loaded .video-play::before { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgba(0,0,0,.75), rgba(0,0,0,.1) 60%); }
.video-frame.is-loaded .video-play > span { position: relative; }
.rthumb:hover, .rthumb:focus { color: #fff; text-decoration: none; }
/* cards without a preview image: compact header strip instead of an empty 16:9 block */
.rthumb:not(.has-thumb) { aspect-ratio: auto; min-height: 58px; padding: 10px 12px; flex-direction: row; align-items: center; justify-content: space-between; }
.rthumb:not(.has-thumb)::after { display: none; }
.rthumb:not(.has-thumb) .rhost { opacity: .9; }
@media (max-width: 640px) {
  .rgrid { grid-template-columns: 1fr; gap: 10px; }
  .rthumb.has-thumb { aspect-ratio: 21 / 9; }
}

/* cover: outline of parts and chapters */
.part-card { display: flex; flex-direction: column; gap: 8px; padding: 18px 18px 16px; border: 1px solid var(--rule); border-radius: 12px; background: var(--bg-elev); color: var(--ink); }
.part-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--rule)); }
.part-title { font-weight: 700; font-size: 1.12rem; line-height: 1.25; color: var(--ink); text-decoration: none; }
.part-title:hover { color: var(--accent); text-decoration: underline; }
.part-sum { margin: 0; font-size: .92rem; line-height: 1.5; color: var(--ink-2); }
.part-chapters { list-style: none; margin: 4px 0 0; padding: 10px 0 0; border-top: 1px solid var(--rule); display: flex; flex-wrap: wrap; gap: 6px; font-family: var(--sans); font-size: 12.5px; }
.part-chapters a { display: inline-block; padding: 3px 9px; border: 1px solid var(--rule); border-radius: 99px; color: var(--ink-2); text-decoration: none; background: var(--bg); }
.part-chapters a:hover { border-color: var(--accent); color: var(--accent); }

/* monochrome logo: follows the text colour (black in light mode, white in dark mode) */
.brand-svg { width: 22px; height: 22px; flex: none; color: var(--ink); }

/* ── Accent from one base colour ──
   All accent shades (links, highlights, soft backgrounds) come from --accent-base. On
   martinfleisch.com, Portfolio Maker writes the portfolio's highlight colour into the marked value
   below when it exports the site, so the handbook always matches it. Keep the marker comment. */
:root { --accent-base: /*pm-accent*/#8f5bb5; }
:root {
  --accent: var(--accent-base);
  --accent-ink: color-mix(in srgb, var(--accent-base) 78%, #000);
  --accent-soft: color-mix(in srgb, var(--accent-base) 13%, #fff);
  --link: color-mix(in srgb, var(--accent-base) 86%, #000);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: color-mix(in srgb, var(--accent-base) 68%, #fff);
    --accent-ink: color-mix(in srgb, var(--accent-base) 48%, #fff);
    --accent-soft: color-mix(in srgb, var(--accent-base) 22%, #121416);
    --link: color-mix(in srgb, var(--accent-base) 55%, #fff);
  }
}
:root[data-theme="dark"] {
  --accent: color-mix(in srgb, var(--accent-base) 68%, #fff);
  --accent-ink: color-mix(in srgb, var(--accent-base) 48%, #fff);
  --accent-soft: color-mix(in srgb, var(--accent-base) 22%, #121416);
  --link: color-mix(in srgb, var(--accent-base) 55%, #fff);
}
.lb-cap a { color: color-mix(in srgb, var(--accent-base) 48%, #fff); }
.rcard[data-kind="docs"] .rthumb { --rk: color-mix(in srgb, var(--accent-base) 70%, #000); }
