/* Site-wide stylesheet. Dark first; light is opt-in via html[data-theme="light"] or body.light.
   Every page links this file (scripts/build.mjs injects it); pages carry no styles of their own. */

/* ---------- Tokens ---------- */

:root {
  color-scheme: dark;
  --bg: #0e0f11;
  --bg-soft: #15171a;
  --bg-sunk: #1b1e22;
  --fg: #e4e4e1;
  --muted: #9a9da4;
  --faint: #686c74;
  --line: #24272c;
  --line-strong: #34383f;
  --accent: #8ab0f5;
  --accent-strong: #b4ccfa;
  --good: #6cc59a;
  --warn: #dfb05c;
  --bad: #ec7f7f;

  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 10px;
  --measure: 46rem;
  --wide: 72rem;
  --size: 17px;
}

:root[data-theme="light"],
:root:has(body.light) {
  color-scheme: light;
  --bg: #fbfbfa;
  --bg-soft: #f3f3f1;
  --bg-sunk: #ebebe8;
  --fg: #1d1e20;
  --muted: #5d6168;
  --faint: #8c9097;
  --line: #e2e2de;
  --line-strong: #cfcfca;
  --accent: #2c5fc4;
  --accent-strong: #1d4596;
  --good: #1f8a5b;
  --warn: #9a6a0c;
  --bad: #be3b3b;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
  scroll-behavior: smooth;
  scroll-padding-top: 4.5rem;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: var(--size)/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5 {
  line-height: 1.25;
  letter-spacing: -0.015em;
  font-weight: 640;
  margin: 2.2em 0 0.6em;
  text-wrap: balance;
}
h1 { font-size: clamp(1.9rem, 4.5vw, 2.8rem); letter-spacing: -0.03em; margin-top: 0.4em; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }

p { margin: 0.8em 0; text-wrap: pretty; }
strong, b { font-weight: 640; }

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
a:hover { color: var(--accent-strong); border-bottom-color: currentColor; }

ul, ol { padding-left: 1.4em; }
li { margin: 0.3em 0; }
li::marker { color: var(--faint); }

hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }

blockquote {
  margin: 1.2em 0;
  padding: 0.1em 1.1em;
  border-left: 2px solid var(--line-strong);
  color: var(--muted);
}

small, .small, .source-note, .detail-meta, .for, .edition, td small {
  font-size: 0.85rem;
  color: var(--muted);
}
td small { display: block; margin-top: 0.2em; }

code, kbd {
  font: 0.86em/1.5 var(--mono);
  background: var(--bg-sunk);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}
pre {
  font: 0.82rem/1.6 var(--mono);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  overflow-x: auto;
}
pre code { background: none; padding: 0; font-size: inherit; }

img, svg, video { max-width: 100%; height: auto; }
img { border-radius: 4px; }
/* Figures are mostly diagrams drawn for white paper. */
main img, figure img { background: #fff; }

figure { margin: 2rem 0; text-align: center; }
figure:has(> img + img) { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; align-items: center; }
figure:has(> img + img) > img { flex: 1 1 14rem; max-width: 48%; }
figcaption, caption { font-size: 0.85rem; color: var(--muted); margin-top: 0.6rem; caption-side: bottom; }

button {
  font: inherit;
  font-size: 0.85rem;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
}
button:hover { border-color: var(--accent); color: var(--accent); }

::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

/* ---------- Tables ---------- */

table {
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9rem;
  /* Wide tables scroll instead of overflowing the page. */
  display: block;
  max-width: 100%;
  overflow-x: auto;
}
th, td {
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th {
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom-color: var(--line-strong);
}
tr:last-child td { border-bottom: 0; }

/* Wrappers already scroll; let the table fill them. */
.table-wrap, .table-scroll, .snapshot { overflow-x: auto; margin: 1.5rem 0; }
:is(.table-wrap, .table-scroll, .snapshot) table { display: table; width: 100%; margin: 0; }

/* ---------- Page containers ---------- */

.page, .wrap, .shell {
  width: min(var(--wide), 100% - 3rem);
  margin-inline: auto;
}
.shell { padding: 2.5rem 0 4rem; }
.page { padding: 2.5rem 0 5rem; }

body > section, .page > section { padding: 3rem 0; border-top: 1px solid var(--line); }
body > section:first-of-type { border-top: 0; }

footer, .footer {
  margin-top: 3rem;
  padding: 2rem 0 3rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- Heroes and headers ---------- */

.hero {
  padding: 2.5rem 0 2rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--line);
}
body > .hero { padding-inline: 0; margin-bottom: 0; }
.hero h1 { margin-top: 0.3em; }

.eyebrow, .chapter-number, .mark, nav.toc h2, .index h2, .contents summary, .flow-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 0.8rem;
}
.eyebrow, .chapter-number { color: var(--accent); }

.subtitle, .lede, .hero > p, .hero .wrap > p {
  font-size: 1.1rem;
  color: var(--muted);
  max-width: 44rem;
}

.meta, .topbar, .nav, .island-jump, .repo-links, .flow-line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.topbar { justify-content: space-between; margin-bottom: 2rem; }

.section-head {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
  gap: 0.5rem 2rem;
  align-items: baseline;
  margin-bottom: 1.5rem;
}
.section-head h2 { margin: 0; }
.section-head p { margin: 0; color: var(--muted); }

/* ---------- Grids ---------- */

.grid, .cards, .hero-grid, .decision-grid, .plan-grid, .audit-grid, .verdicts,
.persona-grid, .risk-grid, .sources, .statline, .stats, .method, .repo-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}
.cards, .conference-grid, .method, .repo-body { grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); }
.conference-grid { display: grid; gap: 1rem; }
.hero-grid { align-items: start; }
.repo-panels, .matrix, .flow { display: grid; gap: 1rem; }
.flow { gap: 0.5rem; }

/* ---------- Panels ---------- */

.card, .island, .decision-grid > .decision, .audit, .micro-plan, .stat, .hero-metric, .verdict,
.repo-panel, .persona, .risk, .note, .source-card, .conference, .toc-panel, .index,
.diagram, .formula, details, .matrix-row {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  min-width: 0;
}
:is(.card, .island, .decision, .audit, .micro-plan, .verdict, .persona, .risk, .note, .source-card, .callout) > :first-child { margin-top: 0; }
:is(.card, .island, .decision, .audit, .micro-plan, .verdict, .persona, .risk, .note, .source-card, .callout) > :last-child { margin-bottom: 0; }
:is(.card, .island, .audit, .micro-plan, .verdict, .persona, .risk, .note, .source-card) h3,
:is(.card, .island, .micro-plan) h4 { margin: 0 0 0.5rem; font-size: 1.05rem; }

.repo-panel, .conference, .island, .matrix-row { padding: 0; overflow: hidden; }

.island-head, .detail-topline, .repo-header, .conference header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem 1.5rem;
}
.island-head, .repo-header, .conference header { padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); }
.island-head h3, .repo-header h3, .conference h2, .detail-topline h3 { margin: 0 0 0.3rem; }
.conference h2 { font-size: 1.05rem; }
.conference header span { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.repo-header p, .island-head p { margin: 0; color: var(--muted); }
.island-body, .repo-copy, .repo-side { padding: 1rem 1.2rem; }
.repo-body { margin: 0; gap: 0; }
.repo-side { border-left: 1px solid var(--line); }
.repo-copy h4, .repo-side h4 { margin: 0 0 0.5rem; font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

.detail-block { padding: 2rem 0; border-top: 1px solid var(--line); scroll-margin-top: 4.5rem; }
.detail-block:first-of-type { border-top: 0; }
.itinerary { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.itinerary > b, .plan-row strong { display: block; font-size: 0.8rem; color: var(--muted); }
.plan-row { margin-top: 0.6rem; font-size: 0.92rem; }

.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 0.75rem; margin: 1rem 0; }
.quick > div { border-left: 2px solid var(--line-strong); padding-left: 0.7rem; }
.quick b { display: block; font-size: 0.75rem; font-weight: 500; color: var(--muted); }
.quick span { font-size: 0.92rem; overflow-wrap: anywhere; }

.matrix-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); }
.matrix-row > div { padding: 0.9rem 1rem; border-left: 1px solid var(--line); }
.matrix-row > div:first-child { border-left: 0; font-weight: 600; }
.matrix p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.flow-row { display: grid; grid-template-columns: 7rem 1fr; gap: 0.6rem; align-items: center; }
.flow-label { margin: 0; }
.flow-arrow { color: var(--faint); }

/* Stats */
.stat, .hero-metric { text-align: left; }
.stat .num, .stat strong, .hero-metric b {
  display: block;
  font-size: 1.6rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--fg);
}
.stat .lbl, .stat span, .hero-metric span {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
}

/* hrm-style definition grid (label / value pairs). */
.decision:has(> div) {
  display: grid;
  grid-template-columns: minmax(0, 12rem) minmax(0, 1fr);
  margin: 1.5rem 0;
  border-top: 1px solid var(--line);
}
.decision:has(> div) > div { padding: 0.7rem 1rem 0.7rem 0; border-bottom: 1px solid var(--line); }
.decision:has(> div) > div:nth-child(odd) { color: var(--muted); font-size: 0.9rem; }
.decision-grid > .decision strong { display: block; margin-bottom: 0.3rem; }
.decision-grid > .decision p { margin: 0; color: var(--muted); font-size: 0.92rem; }

/* ---------- Callouts ---------- */

.callout, .cred-note, .hero-note, .review-note, .island .note {
  margin: 1.2rem 0;
  padding: 0.8rem 1.1rem;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--bg-soft);
  font-size: 0.95rem;
}
.callout.good { border-left-color: var(--good); }
.callout.warn { border-left-color: var(--warn); }
.callout.bad { border-left-color: var(--bad); }
.hero-note strong { display: block; margin-bottom: 0.3rem; }
.hero-note p { margin: 0; color: var(--muted); }

/* ---------- Pills ---------- */

.chip, .tag, .pill, .plan-label, .grade, .flow-chip, .island-jump a, .back-top, nav.nav a, .nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.15em 0.65em;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.6;
  color: var(--muted);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}
.flow-chip { border-radius: 6px; font-family: var(--mono); font-size: 0.75rem; }
.plan-label { width: fit-content; }
.grade { min-width: 4.5rem; justify-content: center; margin-bottom: 0.5rem; }
a:is(.pill, .back-top), .island-jump a, .nav a { color: var(--fg); }
a:is(.pill, .back-top):hover, .island-jump a:hover, .nav a:hover { color: var(--accent); border-color: var(--accent); }

:is(.tag, .grade).safe, .grade.high, .grade.max { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
:is(.tag, .grade).edge, .grade.mid { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
:is(.tag, .grade).stretch, .grade.low { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.tag.source { color: var(--accent); }

.rank {
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  font-weight: 650;
  color: var(--accent);
}

/* ---------- Lists ---------- */

.source-list, .team-list, nav.toc ol, .contents ol, nav#toc ul { list-style: none; padding: 0; margin: 0; }
.source-list li { margin-bottom: 0.8rem; }
.checklist { columns: 2 18rem; column-gap: 2rem; }
.checklist li { break-inside: avoid; }

.team-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); }
.team-list li { margin: 0; padding: 0.45rem 1.2rem; font-size: 0.88rem; border-top: 1px solid var(--line); overflow-wrap: anywhere; }

/* ---------- Monospace blocks ---------- */

.diagram { font: 0.78rem/1.5 var(--mono); white-space: pre-wrap; overflow-x: auto; color: var(--muted); }
.formula { text-align: center; font-size: 1.2rem; font-family: "Cambria Math", Georgia, serif; overflow-x: auto; }
.formula .sub { font-size: 0.7em; vertical-align: sub; }
.formula .big { font-size: 1.4em; vertical-align: middle; }

details { margin: 1rem 0; }
summary { cursor: pointer; font-weight: 600; }
details[open] > summary { margin-bottom: 0.5rem; }

/* ---------- Sticky top bars ---------- */

/* Horizontal section nav that sits directly under <body> (e.g. trip plans). */
body > nav:not(#toc) {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
body > nav:not(#toc) .wrap { display: flex; gap: 1.2rem; overflow-x: auto; white-space: nowrap; padding: 0.7rem 0; }
body > nav:not(#toc) a { color: var(--muted); border: 0; font-size: 0.85rem; }
body > nav:not(#toc) a:hover { color: var(--fg); }

/* Reader toolbar (font size / theme / print). */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1.5rem;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
}
.toolbar .label { color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.tools { display: flex; gap: 0.35rem; }
.skip { position: absolute; top: -5rem; }
.skip:focus { top: 1rem; left: 1rem; z-index: 20; background: var(--bg); padding: 0.5rem 1rem; }

/* Floating theme switch. */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(8px);
  color: var(--muted);
}
.theme-toggle svg { width: 1.1rem; height: 1.1rem; }
.theme-toggle .icon-sun { display: inline-flex; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: inline-flex; }

/* ---------- Two-column layouts with a sticky side index ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 14rem) minmax(0, 1fr);
  gap: 3rem;
  align-items: start;
  max-width: var(--wide);
  margin: 2rem auto 0;
}
body > .layout { padding: 1rem 1.5rem 6rem; }
.layout > main { min-width: 0; max-width: var(--measure); }

nav.toc, .contents, .index {
  position: sticky;
  top: 1.5rem;
  max-height: calc(100vh - 3rem);
  overflow: auto;
  font-size: 0.84rem;
  line-height: 1.45;
}
.toolbar ~ .layout .contents { top: 4rem; max-height: calc(100vh - 5.5rem); }
.index { padding: 1rem; }
.index nav { display: grid; gap: 0.1rem; }

:is(nav.toc, .contents, .index) a {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.25rem 0 0.25rem 0.8rem;
  border: 0;
  border-left: 1px solid var(--line);
  color: var(--muted);
}
:is(nav.toc, .contents, .index) a:hover { color: var(--fg); border-left-color: var(--faint); }
:is(nav.toc, .contents) a:is(.active, [aria-current]) { color: var(--accent); border-left-color: var(--accent); }
.index strong { font-weight: 500; color: var(--faint); }
.contents li { margin: 0; }
.contents .sub a { padding-left: 1.6rem; }
.contents .deep a { padding-left: 2.4rem; font-size: 0.78rem; }
.contents details { padding: 0; border: 0; background: none; margin: 0; }

/* ---------- Long-form reading (books, papers) ---------- */

main { min-width: 0; }
.book-title { margin-top: 0; }
header.chapter { margin: 4rem 0 2rem; padding-top: 2rem; border-top: 1px solid var(--line-strong); }
header.chapter h1 { margin-top: 0; }
.page-marker {
  font: 0.65rem/1 var(--mono);
  color: var(--faint);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 4px;
  margin: 0 0.3rem;
  vertical-align: super;
  user-select: none;
}
.footnotes { font-size: 0.85rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 1rem; margin-top: 2rem; }

/* Paper reader: fixed sidebar TOC that auto-hides on desktop (toggled by the page script). */
nav#toc {
  position: fixed;
  inset: 0 auto 0 0;
  width: 19rem;
  z-index: 10;
  overflow-y: auto;
  padding: 1.5rem 1rem 3rem;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  font-size: 0.84rem;
  line-height: 1.45;
}
nav#toc .book-title { font-weight: 640; font-size: 0.92rem; margin: 0 0 1rem; }
nav#toc a { display: block; padding: 0.2rem 0.5rem; border: 0; border-radius: 5px; color: var(--fg); }
nav#toc a:hover { background: var(--bg-sunk); }
nav#toc a.active { color: var(--accent); }
nav#toc ul ul { display: none; margin: 0.2rem 0 0.4rem 0.7rem; padding-left: 0.5rem; border-left: 1px solid var(--line); }
nav#toc ul ul a { color: var(--muted); font-size: 0.8rem; }
nav#toc li.open > ul { display: block; }
nav#toc ~ main { padding: 2rem 3rem 6rem; }
section.chapter { max-width: var(--measure); margin: 0 auto 3rem; padding-bottom: 3rem; border-bottom: 1px solid var(--line); }
.chapter-title { font-size: 1.9rem; margin: 1rem 0 1.5rem; }
#toc-toggle, #toc-edge { display: none; }

@media (hover: hover) and (min-width: 901px) {
  nav#toc { transition: transform 0.35s cubic-bezier(.16, 1, .3, 1), opacity 0.3s ease; }
  body.toc-hidden nav#toc { transform: translateX(-100%); opacity: 0; pointer-events: none; }
  #toc-edge { display: block; position: fixed; inset: 0 auto 0 0; width: 1rem; z-index: 9; pointer-events: none; }
  #toc-edge::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 5px;
    width: 3px;
    height: 3.5rem;
    margin-top: -1.75rem;
    border-radius: 2px;
    background: var(--faint);
    opacity: 0;
    transition: opacity 0.4s ease 0.2s;
  }
  body.toc-hidden #toc-edge::after { opacity: 0.5; }
}

/* ---------- Solution reader ---------- */

.solution-guide main a { overflow-wrap: anywhere; }
.solution-guide main > h3 {
  padding-top: 2rem;
  border-top: 1px solid var(--line);
}

/* Highlight.js tokens share the site's palette in both themes. */
pre .hljs-comment, pre .hljs-quote { color: var(--muted); font-style: italic; }
pre .hljs-keyword, pre .hljs-selector-tag, pre .hljs-literal { color: var(--accent); }
pre .hljs-string, pre .hljs-doctag, pre .hljs-regexp { color: var(--good); }
pre .hljs-number, pre .hljs-built_in, pre .hljs-type { color: var(--warn); }
pre .hljs-title, pre .hljs-function, pre .hljs-params { color: var(--fg); }
pre .hljs-meta { color: var(--faint); }

/* ---------- Math (KaTeX layout itself lives in /styles/katex) ---------- */

.katex { font-size: 1.08em; }
.math-display, .katex-display { display: block; overflow-x: auto; overflow-y: hidden; padding: 0.25rem 0; }
.katex-display { margin: 0.6em 0; }
:is(p, li, td) > .katex { display: inline-block; max-width: 100%; overflow-x: auto; overflow-y: hidden; vertical-align: middle; }

/* ---------- Generated directory listings ---------- */

.listing-page { width: min(56rem, 100% - 3rem); margin: 0 auto; padding: 3.5rem 0 5rem; }
.crumbs { font: 0.95rem/1.4 var(--mono); color: var(--muted); margin: 0 0 2rem; overflow-wrap: anywhere; }
.crumbs a { color: var(--muted); border: 0; }
.crumbs a:hover { color: var(--fg); }
.crumbs .here { color: var(--fg); }
.listing { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.listing li { margin: 0; border-bottom: 1px solid var(--line); }
.listing a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.2rem 1.5rem;
  padding: 0.75rem 0.25rem;
  border: 0;
  color: var(--fg);
}
.listing a:hover { background: var(--bg-soft); }
.listing a:hover .name { color: var(--accent); }
.listing .name { grid-column: 1; font-weight: 500; overflow-wrap: anywhere; }
.listing .dir .name::before {
  content: "";
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  margin-right: 0.55em;
  vertical-align: -0.17em;
  background: var(--faint);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.listing .dir a:hover .name::before { background: var(--accent); }
.listing .file { grid-column: 1; font: 0.75rem var(--mono); color: var(--faint); overflow-wrap: anywhere; }
.listing .info { grid-column: 2; grid-row: 1 / span 2; align-self: center; text-align: right; font: 0.75rem/1.5 var(--mono); color: var(--faint); white-space: nowrap; }
.listing-empty { color: var(--muted); }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 1rem; }
  nav.toc, .contents, .index { position: static; max-height: none; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
  .index { border: 1px solid var(--line); }
  .index nav { grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); }
  .repo-side { border-left: 0; border-top: 1px solid var(--line); }

  nav#toc { width: 85vw; transform: translateX(-100%); transition: transform 0.2s; }
  body.toc-open nav#toc { transform: none; }
  nav#toc ~ main { padding: 3.5rem 1.25rem 4rem; }
  #toc-toggle { display: block; position: fixed; top: 0.75rem; left: 0.75rem; z-index: 11; background: var(--bg-soft); }
}

@media (max-width: 640px) {
  :root { --size: 16px; }
  .decision:has(> div) { grid-template-columns: 1fr; }
  .decision:has(> div) > div:nth-child(odd) { padding-bottom: 0; border-bottom: 0; }
  .flow-row { grid-template-columns: 1fr; }
  .toolbar { padding: 0.5rem 1rem; }
  body > .layout { padding-inline: 1rem; }
  .listing .info { grid-column: 1; grid-row: auto; text-align: left; }
  .listing a { grid-template-columns: 1fr; }
}

@media print {
  :root { --bg: #fff; --bg-soft: #fff; --bg-sunk: #f2f2f2; --fg: #000; --muted: #444; --faint: #666; --line: #ccc; --line-strong: #999; --accent: #000; }
  .toolbar, .theme-toggle, .contents, nav.toc, nav#toc, #toc-toggle, #toc-edge, body > nav, .skip { display: none !important; }
  .layout { display: block; }
  nav#toc ~ main { padding: 0; }
  a { border: 0; }
  pre, .card, .callout, table, figure { break-inside: avoid; }
}
