/* The Secret Library — main.css
   Several blocks below are the library's own snippet entries, applied:
   fluid-type, focus-styles, reduced-motion, visually-hidden. */

/* ---------- fonts (self-hosted, latin subsets) ---------- */
@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('../fonts/bricolage-grotesque-latin-wght-normal.woff2') format('woff2-variations');
  font-weight: 200 800;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../fonts/atkinson-hyperlegible-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../fonts/atkinson-hyperlegible-latin-400-italic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../fonts/atkinson-hyperlegible-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../fonts/atkinson-hyperlegible-latin-700-italic.woff2') format('woff2');
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('../fonts/jetbrains-mono-latin-wght-normal.woff2') format('woff2-variations');
  font-weight: 100 800;
  font-display: swap;
}

/* ---------- category hue ramp ----------
   Ten evenly spaced hues (36° apart) at one fixed lightness/chroma per
   theme — see --cat-* below. Declared once here so the slug→hue mapping
   never drifts between the light and dark blocks; each theme block only
   supplies lightness and chroma. Regenerate by changing the starting hue
   below and re-deriving the rest at +36° per category, in this order —
   never hand-edit a single hue out of the ramp.
   Ramp starts at typography's original hue (290) so the nine pre-existing
   categories moved as little as possible when data-viz was added as the
   tenth. Verified: every adjacent pair in both themes lands at 92-100% of
   the ramp's theoretical OKLab step distance (checked via sRGB-gamut
   round-trip), so none read as confusable. */
:root {
  --hue-typography: 290;
  --hue-color: 326;
  --hue-layout-css: 2;
  --hue-accessibility: 38;
  --hue-ux-patterns: 74;
  --hue-design-tools: 110;
  --hue-snippets: 146;
  --hue-inspiration: 182;
  --hue-process: 218;
  --hue-data-viz: 254;
}

/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --bg: oklch(96.8% 0.005 250);
  --surface: oklch(99% 0.002 250);
  --surface-2: oklch(93.5% 0.006 250);
  --text: oklch(22% 0.02 250);
  --text-muted: oklch(45% 0.015 250);
  --accent: oklch(46% 0.09 165);
  --accent-strong: oklch(38% 0.09 165);
  --color-focus: oklch(50% 0.16 250);
  --border: oklch(86% 0.008 250);
  --edge: oklch(70% 0.01 250);

  --cat-typography: oklch(56% 0.11 var(--hue-typography));
  --cat-color: oklch(56% 0.11 var(--hue-color));
  --cat-layout-css: oklch(56% 0.11 var(--hue-layout-css));
  --cat-accessibility: oklch(56% 0.11 var(--hue-accessibility));
  --cat-ux-patterns: oklch(56% 0.11 var(--hue-ux-patterns));
  --cat-design-tools: oklch(56% 0.11 var(--hue-design-tools));
  --cat-snippets: oklch(56% 0.11 var(--hue-snippets));
  --cat-inspiration: oklch(56% 0.11 var(--hue-inspiration));
  --cat-process: oklch(56% 0.11 var(--hue-process));
  --cat-data-viz: oklch(56% 0.11 var(--hue-data-viz));

  /* Bookmark highlight marks. Each is also a distinct glyph shape, never
     color alone. Values checked at >=3:1 (WCAG 1.4.11 non-text contrast,
     the applicable SC for a ring/glyph rather than body text) against both
     --bg and --surface, in each theme. */
  --mark-amber: oklch(58% 0.105 80);
  --mark-rose: oklch(52% 0.17 10);
  --mark-violet: oklch(52% 0.17 300);
  --mark-jade: oklch(50% 0.115 155);

  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-body: 'Atkinson Hyperlegible', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --gutter: clamp(1rem, 3vw, 2rem);
  --radius: 6px;
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: oklch(21% 0.015 255);
  --surface: oklch(25% 0.015 255);
  --surface-2: oklch(29% 0.015 255);
  --text: oklch(92% 0.005 255);
  --text-muted: oklch(72% 0.01 255);
  --accent: oklch(78% 0.1 165);
  --accent-strong: oklch(85% 0.1 165);
  --color-focus: oklch(75% 0.12 250);
  --border: oklch(34% 0.015 255);
  --edge: oklch(48% 0.01 255);

  --cat-typography: oklch(72% 0.11 var(--hue-typography));
  --cat-color: oklch(72% 0.11 var(--hue-color));
  --cat-layout-css: oklch(72% 0.11 var(--hue-layout-css));
  --cat-accessibility: oklch(72% 0.11 var(--hue-accessibility));
  --cat-ux-patterns: oklch(72% 0.11 var(--hue-ux-patterns));
  --cat-design-tools: oklch(72% 0.11 var(--hue-design-tools));
  --cat-snippets: oklch(72% 0.11 var(--hue-snippets));
  --cat-inspiration: oklch(72% 0.11 var(--hue-inspiration));
  --cat-process: oklch(72% 0.11 var(--hue-process));
  --cat-data-viz: oklch(72% 0.11 var(--hue-data-viz));

  --mark-amber: oklch(78% 0.15 80);
  --mark-rose: oklch(72% 0.15 10);
  --mark-violet: oklch(74% 0.135 300);
  --mark-jade: oklch(72% 0.14 155);
}

/* ---------- reset (after Andy Bell's modern reset, entry: modern-reset) ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -moz-text-size-adjust: none; -webkit-text-size-adjust: none; text-size-adjust: none; }
body { line-height: 1.55; -webkit-font-smoothing: antialiased; }
img, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, h4 { line-height: 1.15; text-wrap: balance; overflow-wrap: break-word; }
p { text-wrap: pretty; overflow-wrap: break-word; }
ul[class], ol[class] { list-style: none; padding: 0; }

/* ---------- fluid type scale (entry: fluid-type, generated with Utopia) ---------- */
:root {
  --step--1: clamp(0.8333rem, 0.7754rem + 0.2899vw, 1rem);
  --step-0: clamp(1rem, 0.913rem + 0.4348vw, 1.25rem);
  --step-1: clamp(1.2rem, 1.0739rem + 0.6304vw, 1.5625rem);
  --step-2: clamp(1.44rem, 1.2615rem + 0.8924vw, 1.9531rem);
  --step-3: clamp(1.728rem, 1.4799rem + 1.2407vw, 2.4414rem);
  --step-4: clamp(2.0736rem, 1.7334rem + 1.7011vw, 3.0518rem);
}

body {
  font-family: var(--font-body);
  font-size: var(--step-0);
  background: var(--bg);
  color: var(--text);
}
h1 { font-size: var(--step-3); }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }
h1, h2, h3, .wordmark { font-family: var(--font-display); font-weight: 560; }
code, pre, .mono { font-family: var(--font-mono); font-size: 0.875em; }
pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  overflow-x: auto;
  line-height: 1.5;
}
a { color: var(--accent); text-underline-offset: 0.15em; }
a:hover { color: var(--accent-strong); }

/* ---------- focus (entry: focus-styles) ---------- */
:focus-visible {
  outline: 2px solid var(--color-focus, currentColor);
  outline-offset: 2px;
  border-radius: 2px;
}
:focus:not(:focus-visible) { outline: 2px solid transparent; }

/* ---------- visually hidden (entry: visually-hidden) ---------- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -3rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  z-index: 100;
  transition: top 0.15s;
}
.skip-link:focus { top: 0.75rem; }

/* ---------- header ---------- */
.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  padding: 0.9rem var(--gutter);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.wordmark {
  font-size: var(--step-1);
  font-weight: 640;
  text-decoration: none;
  color: var(--text);
  letter-spacing: -0.01em;
}
.wordmark:hover { color: var(--text); }
.header-spacer { flex: 1; }
.header-nav { display: flex; gap: 1rem; font-size: var(--step--1); align-items: center; }

button {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: inherit;
  text-align: left;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.4rem 0.8rem;
  font-size: var(--step--1);
  color: var(--text);
}
.btn:hover { background: var(--surface-2); }

.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.view-toggle button {
  padding: 0.4rem 1rem;
  font-size: var(--step--1);
  font-family: var(--font-body);
  color: var(--text-muted);
}
.view-toggle button + button { border-left: 1px solid var(--border); }
.view-toggle button[aria-pressed='true'] {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
}

.search {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.4rem 0.75rem;
  font-size: var(--step--1);
  width: min(260px, 100%);
}
.search::placeholder { color: var(--text-muted); }

/* ---------- filter chips ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  padding: 0.75rem var(--gutter);
  border-bottom: 1px solid var(--border);
  font-size: var(--step--1);
}
.filter-group { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.filter-group .group-label { color: var(--text-muted); margin-right: 0.15rem; }
.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  background: var(--surface);
  color: var(--text-muted);
}
.chip:hover { background: var(--surface-2); color: var(--text); }
.chip[aria-pressed='true'] {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}
.mark-chip { display: inline-flex; align-items: center; gap: 0.35em; }
.mark-chip .glyph { color: var(--mark-color); }
.mark-chip[aria-pressed='true'] .glyph { color: var(--bg); }

/* ---------- shelf ---------- */
.shelf {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: var(--gutter);
  padding: var(--gutter);
  align-items: start;
}
.sidebar { position: sticky; top: 1rem; }
.sort-control { display: grid; gap: 0.3rem; margin-bottom: 1.25rem; }
.sort-control label { font-size: var(--step--1); font-weight: 700; color: var(--text-muted); text-transform: lowercase; letter-spacing: 0.03em; }
.sort-control select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  padding: 0.4rem 0.6rem;
  font-size: var(--step--1);
}
.sidebar h2 { font-size: var(--step--1); font-family: var(--font-body); font-weight: 700; color: var(--text-muted); text-transform: lowercase; letter-spacing: 0.03em; margin-bottom: 0.5rem; }
.sidebar ul { display: grid; gap: 2px; }
.sidebar button {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  font-size: var(--step--1);
  color: var(--text-muted);
}
.sidebar button:hover { background: var(--surface-2); color: var(--text); }
.sidebar button[aria-pressed='true'] { background: var(--surface-2); color: var(--text); font-weight: 700; }
.sidebar .count { font-family: var(--font-mono); font-size: 0.8em; align-self: center; }

.category-section { margin-bottom: 2.5rem; }
.category-section > h2 {
  font-size: var(--step-1);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.category-section > h2 .dot { width: 0.55em; height: 0.55em; border-radius: 50%; background: var(--spine); flex: none; }
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 0.9rem;
}
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem 0.9rem 1.15rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.card::before {
  content: '';
  position: absolute;
  inset-block: 0;
  left: 0;
  width: 4px;
  background: var(--spine);
}
.card:hover { border-color: var(--edge); }
.card-ribbon {
  position: absolute;
  top: 0;
  right: 1rem;
  width: 14px;
  height: 20px;
  background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%);
}
.card-ribbon[hidden] { display: none; }
.mark-indicator { display: inline-flex; align-items: center; }
.mark-indicator[hidden] { display: none; }
.mark-indicator .glyph { color: var(--mark-color); font-size: 0.9em; }
.card-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--step-0);
  line-height: 1.25;
  color: var(--text);
}
.card-title:hover { color: var(--accent); }
.card-title::after { content: ''; position: absolute; inset: 0; }
.card-author { font-size: var(--step--1); color: var(--text-muted); }
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.7rem;
  font-size: var(--step--1);
  color: var(--text-muted);
  align-items: center;
}
.badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 0.55em;
  font-size: 0.92em;
}
.status { display: inline-flex; align-items: center; gap: 0.3em; }
.status .glyph { font-size: 0.85em; }
.card-summary { font-size: var(--step--1); color: var(--text-muted); }
.card-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: auto; position: relative; z-index: 1; }
.card-tags button {
  font-family: var(--font-mono);
  font-size: calc(var(--step--1) * 0.88);
  color: var(--text-muted);
  border-radius: 3px;
  padding: 0 0.2em;
}
.card-tags button:hover { color: var(--accent); text-decoration: underline; }
.empty-state { color: var(--text-muted); padding: 2rem 0; }
.empty-state button { color: var(--accent); text-decoration: underline; }

/* A display value set by class (e.g. .shelf's grid) would otherwise
   override the UA rule for [hidden] and leave inactive views visible. */
#main > [hidden] { display: none !important; }

/* ---------- graph ---------- */
.graph-wrap { position: relative; }
.graph-stage {
  position: relative;
  height: max(480px, calc(100dvh - 190px));
  cursor: grab;
}
.graph-stage:active { cursor: grabbing; }
.graph-stage svg { width: 100%; height: 100%; }
.graph-stage .edge-line { stroke: var(--edge); stroke-width: 1; }
.graph-stage .node circle { fill: var(--node-color); stroke: var(--bg); stroke-width: 1.5; }
.graph-stage .node { cursor: pointer; }
.graph-stage .node:focus-visible circle,
.graph-stage .node.hovered circle { stroke: var(--color-focus); stroke-width: 3; }
.graph-stage .node circle.ring { stroke-width: 2.5; pointer-events: none; }
.graph-stage .node-label {
  font-family: var(--font-body);
  font-size: 11.5px;
  fill: var(--text-muted);
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.graph-legend {
  position: absolute;
  top: 1rem;
  left: var(--gutter);
  display: grid;
  gap: 2px;
  background: color-mix(in oklab, var(--bg) 82%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  font-size: var(--step--1);
  max-width: 200px;
}
.graph-legend button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  color: var(--text-muted);
}
.graph-legend button:hover { background: var(--surface-2); color: var(--text); }
.graph-legend button[aria-pressed='true'] { color: var(--text); font-weight: 700; }
.graph-legend .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.graph-hint {
  padding: 0.5rem var(--gutter) 1rem;
  font-size: var(--step--1);
  color: var(--text-muted);
}
.graph-tooltip {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.6rem;
  font-size: var(--step--1);
  pointer-events: none;
  z-index: 60;
  max-width: 260px;
}
.graph-tooltip .tip-cat { color: var(--text-muted); font-size: 0.85em; }
.graph-tooltip .tip-mark { color: var(--text-muted); font-size: 0.85em; }
.graph-list { display: none; padding: var(--gutter); }
.graph-list h3 { display: flex; align-items: center; gap: 0.5rem; margin: 1.25rem 0 0.5rem; }
.graph-list h3 .dot { width: 0.5em; height: 0.5em; border-radius: 50%; background: var(--spine); }
.graph-list li button { padding: 0.3rem 0; color: var(--text); width: 100%; }
.graph-list li button:hover { color: var(--accent); }
.graph-list li .meta { color: var(--text-muted); font-size: var(--step--1); margin-left: 0.5rem; }


/* ---------- tree (skill tree) ---------- */
.tree-wrap { position: relative; }
.tree-stage {
  position: relative;
  height: max(480px, calc(100dvh - 190px));
  cursor: grab;
  overflow: hidden;
}
.tree-stage:active { cursor: grabbing; }
.tree-stage svg { width: 100%; height: 100%; }
.tree-edge {
  fill: none;
  stroke: var(--edge);
  stroke-width: 1.5;
}
.tree-edge-root { stroke-dasharray: 1 5; stroke-linecap: round; }
.tree-xlink {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 3 4;
  opacity: 0.8;
  pointer-events: none;
}
.tree-node { cursor: pointer; }
.tree-node circle {
  fill: var(--surface);
  stroke: var(--node-color, var(--text-muted));
  stroke-width: 2;
}
.tree-root circle { fill: var(--accent); stroke: var(--accent-strong); }
.tree-cat circle { fill: var(--node-color); stroke: var(--bg); }
.tree-cat[aria-pressed='true'] circle { stroke: var(--text); stroke-width: 2.5; }
/* Unlock states (status): seedling = outline, growing = half, evergreen = filled + glow */
.tree-entry.st-seedling circle { fill: transparent; stroke-dasharray: 4 3; }
.tree-entry.st-growing circle { fill: color-mix(in oklab, var(--node-color) 40%, var(--surface)); }
.tree-entry.st-evergreen circle {
  fill: var(--node-color);
  stroke: color-mix(in oklab, var(--node-color) 55%, var(--bg));
}
.tree-entry.st-evergreen .halo {
  fill: var(--node-color);
  stroke: none;
  opacity: 0.22;
  animation: tree-halo 3.2s ease-in-out infinite alternate;
}
@keyframes tree-halo {
  from { opacity: 0.12; }
  to { opacity: 0.32; }
}
.tree-node:focus-visible circle:not(.halo),
.tree-node.hovered circle:not(.halo) { stroke: var(--color-focus); stroke-width: 3; }
.tree-node circle.ring { stroke-width: 2.5; pointer-events: none; }
.tree-label {
  font-family: var(--font-body);
  font-size: 11.5px;
  fill: var(--text-muted);
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.tree-label-cat { font-weight: 700; fill: var(--text); font-size: 12.5px; }
.tree-label-root { font-family: var(--font-display); font-size: 14px; fill: var(--text); }

/* ---------- book ---------- */
.book-wrap { padding: var(--gutter); display: grid; gap: 0.5rem; }
.book-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1rem; }
.book-page-count { font-size: var(--step--1); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.book-bookmarks {
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  padding: 0.4rem 0.6rem;
  font-size: var(--step--1);
}
.book-bookmarks:disabled { color: var(--text-muted); }

.book-stage {
  position: relative;
  height: max(480px, calc(100dvh - 230px));
  perspective: 1600px;
}
.book-spread {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1px;
  transform-origin: center center;
  will-change: transform;
}
.book-page {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.book-page-inner { height: 100%; overflow-y: auto; padding: 1.5rem var(--gutter) 2rem; }
#book-page-left { display: none; }
.book-blank { color: var(--text-muted); }

.page-ribbon {
  position: absolute;
  top: 0;
  right: 1.25rem;
  width: 16px;
  height: 24px;
  background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%);
}
.page-ribbon[hidden] { display: none; }

.book-cover-title { font-size: var(--step-4); margin-top: 2rem; }
.book-cover-sub { color: var(--text-muted); margin-top: 0.75rem; max-width: 30ch; }

.book-toc-list { display: grid; gap: 0.2rem; margin-top: 1rem; }
.book-toc-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.4rem 0.2rem;
  border-bottom: 1px dotted var(--border);
}
.book-toc-link:hover { color: var(--accent); }
.book-toc-link .dot { width: 0.55em; height: 0.55em; border-radius: 50%; flex: none; }
.book-toc-page { margin-left: auto; font-family: var(--font-mono); color: var(--text-muted); font-size: 0.85em; }

/* Bookmarks list on the contents page: same link style as the chapter
   list, plus a small remove button per row. Empty state is one line of
   text, not an absent section, so the feature is discoverable even with
   nothing saved yet. */
.book-toc-bookmarks { margin-top: 1.25rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.book-toc-bookmarks h3 { font-size: var(--step-0); }
.book-toc-empty { color: var(--text-muted); font-size: var(--step--1); margin-top: 0.5rem; }
.book-toc-bookmark-list { display: grid; gap: 0.2rem; margin-top: 0.5rem; }
.book-toc-bookmark-list li { display: flex; align-items: center; gap: 0.4rem; }
.book-toc-bookmark-list .book-toc-link { border-bottom: 1px dotted var(--border); flex: 1; }
.book-toc-bookmark-remove {
  /* Same reasoning as .book-bookmark-toggle: clears the page-edge click zone. */
  position: relative;
  z-index: 3;
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
}
.book-toc-bookmark-remove:hover { color: var(--text); background: var(--surface-2); }

/* Category hue as an accent only: a top rule and the dot, never a fill. */
.book-divider { padding-top: 2.5rem; border-top: 3px solid var(--spine); margin-top: 1rem; }
.book-divider-count { color: var(--text-muted); margin-top: 0.5rem; }

.book-entry-titlerow { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.5rem; }
.book-entry-titlerow h2 { margin-bottom: 0; }
.book-bookmark-toggle {
  /* Sits above .book-edge-next/.book-edge-prev (z-index: 2), which stretch
     the full height of the outer 8% of each page for the mouse-only
     click-to-turn convenience — without this, the toggle on the right-hand
     page would be visually present but unclickable, sitting under that
     strip. */
  position: relative;
  z-index: 3;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  background: var(--surface);
  color: var(--text-muted);
  font-size: var(--step--1);
}
.book-bookmark-toggle:hover { background: var(--surface-2); color: var(--text); }
.book-bookmark-toggle[aria-pressed='true'] { background: var(--text); border-color: var(--text); color: var(--bg); font-weight: 700; }
.book-bookmark-toggle .glyph { font-size: 1.05em; }
.book-entry-meta { display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; font-size: var(--step--1); color: var(--text-muted); align-items: center; }
.book-entry-meta .cat { display: inline-flex; align-items: center; gap: 0.35em; }
.book-entry-meta .dot { width: 0.6em; height: 0.6em; border-radius: 50%; background: var(--spine); }
.book-entry-summary { margin: 0.85rem 0; }
.book-see-also { display: grid; gap: 0.15rem; margin-top: 0.5rem; }
.book-see-also button { color: var(--accent); }
.book-see-also button:hover { text-decoration: underline; color: var(--accent-strong); }
.book-see-also-page { color: var(--text-muted); font-size: var(--step--1); margin-left: 0.3em; }

.book-edge {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8%;
  min-width: 28px;
  background: none;
  z-index: 2;
}
.book-edge-prev { left: 0; cursor: w-resize; }
.book-edge-next { right: 0; cursor: e-resize; }

@media (min-width: 880px) {
  .book-spread { grid-template-columns: 1fr 1fr; }
  #book-page-left { display: block; }
}

/* ---------- index view ---------- */
.index-view { padding: var(--gutter); display: grid; gap: 0.5rem; }
.index-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.index-table { width: 100%; border-collapse: collapse; min-width: 640px; }
.index-table th, .index-table td { padding: 0.6rem 0.75rem; text-align: left; }
.index-table thead th { border-bottom: 1px solid var(--border); background: var(--surface-2); }
.index-table thead th button {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  min-height: 44px;
  font-weight: 700;
  color: var(--text);
}
.index-table thead th button:hover { color: var(--accent); }
/* Sorted column gets a visible tint beyond the arrow glyph, so the state
   survives a glance, not just a close look at aria-sort. */
.index-table th[aria-sort='ascending'],
.index-table th[aria-sort='descending'] { background: color-mix(in oklab, var(--accent) 12%, var(--surface-2)); }
.index-table th[aria-sort='ascending'] .sort-icon::after { content: '↑'; }
.index-table th[aria-sort='descending'] .sort-icon::after { content: '↓'; }
.index-table tbody tr { border-bottom: 1px solid var(--border); }
.index-table tbody tr:last-child { border-bottom: none; }
.index-row-title {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text);
}
.index-row-title:hover { color: var(--accent); }
.index-external { margin-left: 0.5em; font-size: 0.85em; }
.index-table td.cat { border-left: 3px solid var(--spine); }
.index-table td.cat .dot { display: inline-block; width: 0.6em; height: 0.6em; border-radius: 50%; background: var(--spine); margin-right: 0.4em; }
.index-table td.status .glyph { margin-right: 0.35em; font-size: 0.85em; }
.index-table td.num, .index-table td.num time {
  font-family: var(--font-mono);
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
}
.index-empty { text-align: left; padding: 1.5rem 0.75rem; color: var(--text-muted); }
.index-empty button { color: var(--accent); text-decoration: underline; }

/* ---------- detail panel ---------- */
.detail {
  position: fixed;
  inset-block: 0;
  right: 0;
  width: min(460px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 50;
  overflow-y: auto;
  padding: 1.25rem var(--gutter) 2.5rem;
}
.detail[hidden] { display: none; }
.detail-head { display: flex; justify-content: space-between; gap: 1rem; align-items: start; margin-bottom: 0.5rem; }
.detail h2 { font-size: var(--step-2); }
/* Bibliographic line for book entries (entry.meta), shared with the book
   view's entry-head — empty and collapses to nothing when there's no meta. */
.detail-biblio { font-size: var(--step--1); color: var(--text-muted); margin: -0.25rem 0 0.75rem; }
.detail-biblio:empty { margin: 0; }
.detail .close { flex: none; }
.detail-marks { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; margin-bottom: 0.85rem; }
.detail-marks .mark-bookmark[aria-pressed='true'] { background: var(--surface-2); font-weight: 700; }
.mark-picker { display: flex; flex-wrap: wrap; gap: 0.6rem; border: none; padding: 0; margin: 0; }
.mark-picker label { display: inline-flex; align-items: center; gap: 0.3em; font-size: var(--step--1); font-weight: 400; cursor: pointer; }
.mark-swatch { font-size: 0.95em; color: var(--mark-color, var(--text-muted)); line-height: 1; }
.mark-swatch.mark-none {
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  border: 1.5px solid var(--text-muted);
  border-radius: 50%;
}
.detail .detail-meta { display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; font-size: var(--step--1); color: var(--text-muted); align-items: center; margin-bottom: 1rem; }
.detail .detail-meta .cat { display: inline-flex; align-items: center; gap: 0.35em; }
.detail .detail-meta .dot { width: 0.6em; height: 0.6em; border-radius: 50%; background: var(--spine); }
.detail-summary { margin-bottom: 1rem; }
.detail-body { font-size: var(--step--1); }
.detail-body h1, .detail-body h2, .detail-body h3 { font-size: var(--step-0); margin: 1.25rem 0 0.5rem; }
.detail-body p, .detail-body ul, .detail-body ol { margin-bottom: 0.75rem; }
.detail-body ul, .detail-body ol { padding-left: 1.25rem; }
.detail-body li { margin-bottom: 0.35rem; }
.detail-body pre { margin: 0.75rem 0; }
/* Inline structure/nav diagrams (entries: site-structures, navigation-patterns).
   Ink is currentColor, so figures inherit body text color in both themes with
   no extra rules; only the accent needs mapping. --accent (the spruce hue used
   for links and highlighted nodes) checks at 6.6:1 light / 8.3:1 dark against
   --surface, well past AA, so it's used directly rather than falling back to
   a category token. */
.entry-figure { margin: 0.75rem 0 1rem; }
.entry-figure svg { display: block; width: 100%; height: auto; max-width: 200px; --diagram-accent: var(--accent); }
.detail-url { display: inline-block; margin: 0.25rem 0 1rem; }
.detail h3.connected { font-size: var(--step-0); margin: 1.5rem 0 0.5rem; }
.connected-list li { padding: 0.15rem 0; }
.connected-list button { color: var(--accent); }
.connected-list button:hover { text-decoration: underline; color: var(--accent-strong); }
.detail-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(15% 0.01 255 / 0.35);
  z-index: 49;
}
.detail-backdrop[hidden] { display: none; }

/* ---------- forms (add page) ---------- */
.page { max-width: 760px; margin: 0 auto; padding: var(--gutter); }
.page > h1 { margin-bottom: 0.5rem; }
.page .lede { color: var(--text-muted); margin-bottom: 2rem; }
.form-grid { display: grid; gap: 1.1rem; }
.field { display: grid; gap: 0.3rem; }
.field label { font-weight: 700; font-size: var(--step--1); }
.field .help { font-size: var(--step--1); color: var(--text-muted); }
.field input, .field textarea, .field select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.5rem 0.7rem;
  font-size: var(--step--1);
  width: 100%;
}
.field textarea { min-height: 5.5rem; resize: vertical; }
.field .error { color: oklch(45% 0.16 25); font-size: var(--step--1); }
:root[data-theme='dark'] .field .error { color: oklch(75% 0.13 25); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem; }
legend { font-weight: 700; font-size: var(--step--1); padding: 0 0.4rem; }
.radio-row { display: flex; flex-wrap: wrap; gap: 0.4rem 1.25rem; font-size: var(--step--1); }
.radio-row label { display: inline-flex; gap: 0.4em; align-items: center; font-weight: 400; }
.tag-suggest { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.4rem; }
.links-picker { max-height: 14rem; overflow-y: auto; display: grid; gap: 0.15rem; margin-top: 0.5rem; }
.links-picker label { display: flex; gap: 0.5em; font-size: var(--step--1); font-weight: 400; align-items: baseline; }
.links-picker .lp-id { font-family: var(--font-mono); color: var(--text-muted); font-size: 0.85em; }
.output-block { margin-top: 2rem; }
.output-block pre { max-height: 24rem; overflow: auto; }
.dev-banner {
  background: oklch(88% 0.08 80);
  color: oklch(30% 0.06 80);
  padding: 0.6rem var(--gutter);
  font-size: var(--step--1);
}

/* ---------- about ---------- */
.about-list { display: grid; gap: 1rem; margin: 1rem 0 2rem; }
.about-list li strong { font-weight: 700; }
.about-list li { padding-left: 1rem; border-left: 3px solid var(--border); }

/* ---------- reduced motion (entry: reduced-motion) ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- front page ---------- */
.hero {
  position: relative;
  overflow: hidden;
  min-height: min(560px, 80vh);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gutter);
  text-align: center;
}
/* Decorative-only: the real, interactive instance is the brain view
   (graph.js's initGraph). This one is aria-hidden, pointer-events: none,
   and never gains a tabindex — see graph.js's initHeroGraph. */
.hero-graph {
  position: absolute;
  inset: 0;
  opacity: 0.85;
  pointer-events: none;
}
.hero-graph svg { width: 100%; height: 100%; }
.hero-graph .edge-line { stroke: var(--edge); stroke-width: 1; }
.hero-graph .hero-node { fill: var(--node-color); }
/* Solid --bg at high opacity over the (already dimmed) graph so hero text
   keeps full-strength contrast in both themes — see contrast check in the
   front-page acceptance notes rather than eyeballing it. */
.hero-scrim {
  position: absolute;
  inset: 0;
  background: var(--bg);
  opacity: 0.85;
}
.hero-content {
  position: relative;
  z-index: 1;
  max-width: 40rem;
  display: grid;
  gap: 1.25rem;
  justify-items: center;
}
.hero-content h1 { font-size: var(--step-4); }
.hero-premise { font-size: var(--step-1); max-width: 34ch; }
.hero-actions { display: grid; gap: 0.75rem; }
.hero-actions-row { display: flex; flex-wrap: wrap; gap: 0.75rem; justify-content: center; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 700;
}
/* Explicit color here beats the global a:hover rule (a:hover is more
   specific than a bare .btn-primary), which otherwise repainted the label
   var(--accent-strong) on top of this same hover background — same hue,
   unreadable. */
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--bg); }

.stats-strip {
  text-align: center;
  padding: 0.75rem var(--gutter);
  color: var(--text-muted);
  font-size: var(--step--1);
  border-bottom: 1px solid var(--border);
}

.prose { max-width: 42rem; margin: 0 auto; padding: 2.5rem var(--gutter) 0; }
.prose:last-of-type { padding-bottom: 2.5rem; }
.prose h2 { margin-bottom: 0.85rem; }
.prose p { margin-bottom: 0.85rem; }
.prose p:last-child { margin-bottom: 0; }
.status-legend .glyph { margin-right: 0.05em; }

/* Front-page orientation figures ("How to read it"). Same convention as the
   entry-body diagrams above: ink is currentColor so figures inherit body
   text color in both themes, --diagram-accent maps to --accent for the one
   highlighted element per figure, and nothing animates, so no
   prefers-reduced-motion handling is needed here either. Each figure has a
   visible list or definition list right after it repeating the same
   information as plain text, so the SVG is illustration, not the only copy
   of the content. */
.orientation h3 { margin: 1.75rem 0 0.6rem; }
.orientation-figure { margin: 0.75rem 0 1rem; }
.orientation-figure svg { display: block; width: 100%; height: auto; --diagram-accent: var(--accent); }
.view-legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.6rem 1rem;
  font-size: var(--step--1);
  margin: 0 0 1.5rem;
}
.view-legend dt { font-weight: 700; }
.view-legend dd { margin: 0; color: var(--text-muted); }
.entry-anatomy-list, .find-paths {
  font-size: var(--step--1);
  color: var(--text-muted);
  margin: 0 0 1.5rem;
}
.entry-anatomy-list li, .find-paths li { margin-bottom: 0.35rem; }
.entry-anatomy-list strong, .find-paths strong { color: var(--text); }

/* Specificity matches the reset's ol[class] rule (which zeroes list-style
   and padding on any classed list) so the numbering the copy relies on
   actually renders. */
ol.borrowed-list { display: grid; gap: 0.85rem; list-style: decimal; padding-left: 1.4rem; }
.borrowed-list li { padding-left: 0.35rem; }

.site-footer {
  text-align: center;
  padding: 2rem var(--gutter);
  color: var(--text-muted);
  font-size: var(--step--1);
  border-top: 1px solid var(--border);
}

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .shelf { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .sidebar ul { display: flex; flex-wrap: wrap; gap: 0.3rem; }
  .sidebar button { width: auto; gap: 0.4rem; border: 1px solid var(--border); }
}
@media (max-width: 767px) {
  .graph-stage, .graph-legend, .graph-hint, .tree-stage { display: none; }
  .graph-list { display: block; }
}
