/* nerd.ac — one stylesheet for every page. Colours are tokens; dark mode follows the
   system unless the reader picked a theme (html[data-theme]). */

:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --ink: #1f1e1b;
  --muted: #5f5e5a;
  --faint: #8a8880;
  --line: #e4e1d8;
  --edge: #b4b2a9;
  --edge-lit: #1f1e1b;
  --link: #3c3489;
  --backdrop: rgb(31 30 27 / 0.35);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px rgb(0 0 0 / 0.08);

  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #161614;
    --surface: #1f1f1c;
    --ink: #edebe4;
    --muted: #b4b2a9;
    --faint: #8a8880;
    --line: #34332f;
    --edge: #5f5e5a;
    --edge-lit: #edebe4;
    --link: #afa9ec;
    --backdrop: rgb(0 0 0 / 0.55);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #161614;
  --surface: #1f1f1c;
  --ink: #edebe4;
  --muted: #b4b2a9;
  --faint: #8a8880;
  --line: #34332f;
  --edge: #5f5e5a;
  --edge-lit: #edebe4;
  --link: #afa9ec;
  --backdrop: rgb(0 0 0 / 0.55);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.4);
  color-scheme: dark;
}

/* Colour ramps. Light: 50 fill / 600 stroke / 800 title / 600 subtitle.
   Dark: 800 fill / 200 stroke / 100 title / 200 subtitle. */
.ramp-coral  { --fill: #faece7; --stroke: #993c1d; --title: #712b13; --sub: #993c1d; }
.ramp-amber  { --fill: #faeeda; --stroke: #854f0b; --title: #633806; --sub: #854f0b; }
.ramp-green  { --fill: #eaf3de; --stroke: #3b6d11; --title: #27500a; --sub: #3b6d11; }
.ramp-teal   { --fill: #e1f5ee; --stroke: #0f6e56; --title: #085041; --sub: #0f6e56; }
.ramp-blue   { --fill: #e6f1fb; --stroke: #185fa5; --title: #0c447c; --sub: #185fa5; }
.ramp-purple { --fill: #eeedfe; --stroke: #534ab7; --title: #3c3489; --sub: #534ab7; }
.ramp-pink   { --fill: #fbeaf0; --stroke: #993556; --title: #72243e; --sub: #993556; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .ramp-coral  { --fill: #712b13; --stroke: #f0997b; --title: #f5c4b3; --sub: #f0997b; }
  :root:not([data-theme='light']) .ramp-amber  { --fill: #633806; --stroke: #ef9f27; --title: #fac775; --sub: #ef9f27; }
  :root:not([data-theme='light']) .ramp-green  { --fill: #27500a; --stroke: #97c459; --title: #c0dd97; --sub: #97c459; }
  :root:not([data-theme='light']) .ramp-teal   { --fill: #085041; --stroke: #5dcaa5; --title: #9fe1cb; --sub: #5dcaa5; }
  :root:not([data-theme='light']) .ramp-blue   { --fill: #0c447c; --stroke: #85b7eb; --title: #b5d4f4; --sub: #85b7eb; }
  :root:not([data-theme='light']) .ramp-purple { --fill: #3c3489; --stroke: #afa9ec; --title: #cecbf6; --sub: #afa9ec; }
  :root:not([data-theme='light']) .ramp-pink   { --fill: #72243e; --stroke: #ed93b1; --title: #f4c0d1; --sub: #ed93b1; }
}
:root[data-theme='dark'] .ramp-coral  { --fill: #712b13; --stroke: #f0997b; --title: #f5c4b3; --sub: #f0997b; }
:root[data-theme='dark'] .ramp-amber  { --fill: #633806; --stroke: #ef9f27; --title: #fac775; --sub: #ef9f27; }
:root[data-theme='dark'] .ramp-green  { --fill: #27500a; --stroke: #97c459; --title: #c0dd97; --sub: #97c459; }
:root[data-theme='dark'] .ramp-teal   { --fill: #085041; --stroke: #5dcaa5; --title: #9fe1cb; --sub: #5dcaa5; }
:root[data-theme='dark'] .ramp-blue   { --fill: #0c447c; --stroke: #85b7eb; --title: #b5d4f4; --sub: #85b7eb; }
:root[data-theme='dark'] .ramp-purple { --fill: #3c3489; --stroke: #afa9ec; --title: #cecbf6; --sub: #afa9ec; }
:root[data-theme='dark'] .ramp-pink   { --fill: #72243e; --stroke: #ed93b1; --title: #f4c0d1; --sub: #ed93b1; }

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

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
}
a { color: var(--link); text-underline-offset: 0.15em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 640px) { .wrap { padding: 0 32px; } }

.site-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 20px;
  padding-bottom: 20px;
  font-family: var(--sans);
  font-size: 15px;
}
.brand { font-family: var(--sans); font-weight: 700; font-size: 20px; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.brand span { color: var(--faint); }
.site-nav { display: flex; align-items: center; gap: 18px; }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a[aria-current='page'], .site-nav a:hover { color: var(--ink); }
.theme-toggle {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--muted);
}
.theme-toggle:hover { color: var(--ink); border-color: var(--muted); }
.theme-toggle svg { width: 16px; height: 16px; }
@media (max-width: 520px) { .site-nav .nav-subject { display: none; } }

h1, h2, h3 { font-family: var(--sans); font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
.eyebrow { font: 500 13px/1.4 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); margin: 0 0 8px; }

.site-foot {
  margin-top: 64px;
  padding-top: 24px;
  padding-bottom: 40px;
  border-top: 1px solid var(--line);
  font: 14px/1.6 var(--sans);
  color: var(--muted);
}

/* --------------------------------------------------------------- landing */

.hero { padding: 48px 0 32px; max-width: 720px; }
.hero h1 { font-size: clamp(40px, 8vw, 64px); margin: 0 0 12px; letter-spacing: -0.03em; }
.hero h1 span { color: var(--faint); }
.hero p { font-size: 19px; color: var(--muted); margin: 0; }

.subjects { display: grid; gap: 20px; grid-template-columns: 1fr; margin-top: 16px; }
@media (min-width: 760px) { .subjects { grid-template-columns: 1fr 1fr; } }

.subject-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.subject-card:hover { border-color: var(--muted); box-shadow: var(--shadow); transform: translateY(-1px); }
.subject-card h2 { margin: 0; font-size: 26px; }
.subject-card p { margin: 0; color: var(--muted); }
.subject-card .basis { font: 14px/1.5 var(--sans); color: var(--faint); }
.subject-card .go { font: 500 15px var(--sans); color: var(--link); margin-top: auto; }

.mini { display: grid; gap: 5px; margin-bottom: 4px; }
.mini-row { display: flex; gap: 5px; }
.mini-row i { display: block; height: 12px; flex: 0 0 36px; border-radius: 3px; background: var(--fill); border: 1px solid var(--stroke); }

/* --------------------------------------------------------------- subject */

.subject-head { padding: 24px 0 8px; max-width: 760px; }
.subject-head h1 { font-size: clamp(32px, 6vw, 46px); margin: 0 0 12px; letter-spacing: -0.02em; }
.lede { font-size: 18px; color: var(--muted); margin: 0 0 16px; }
.story { margin: 0 0 8px; padding-left: 1.2em; color: var(--muted); }
.story li { margin: 4px 0; }
.story strong { color: var(--ink); font-weight: 600; }
.hint { font: 14px/1.5 var(--sans); color: var(--faint); margin: 16px 0 0; }

.map-shell { margin-top: 24px; }
.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 12px;
  font: 14px/1.4 var(--sans);
}
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; margin: 0; padding: 0; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--fill); border: 1px solid var(--stroke); }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--surface); }
.seg { border: 0; background: transparent; padding: 4px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); font: 500 13px var(--sans); }
.seg[aria-pressed='true'] { background: var(--bg); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }

.map-shell[data-view='map'] .map-list, .map-shell[data-view='list'] .map-canvas { display: none; }

.map-canvas {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow-x: auto;
  padding: 8px;
}
.map-svg { display: block; width: 100%; max-width: 100%; height: auto; margin: 0 auto; font-family: var(--sans); }

.row-label { font: 600 12px var(--sans); fill: var(--faint); letter-spacing: 0.04em; }

.edge { fill: none; stroke: var(--edge); stroke-width: 1.25; marker-end: var(--arrow); transition: opacity 0.15s, stroke 0.15s; }
.map-svg marker path { fill: var(--edge); }
.map-svg marker:last-of-type path { fill: var(--edge-lit); }

.node { cursor: pointer; transition: opacity 0.15s; }
.node rect { fill: var(--fill); stroke: var(--stroke); stroke-width: 0.75; transition: stroke-width 0.15s; }
.node .t { font-size: 14px; font-weight: 600; fill: var(--title); }
.node .s { font-size: 12px; fill: var(--sub); }
.node:hover rect, .node:focus-visible rect { stroke-width: 2; }
.node:focus { outline: none; }
.node:focus-visible rect { stroke-width: 2.5; }

.spotlit .node:not(.lit) { opacity: 0.35; }
.spotlit .edge:not(.lit) { opacity: 0.2; }
.spotlit .edge.lit { stroke: var(--edge-lit); stroke-width: 1.75; marker-end: var(--arrow-lit); }

/* list view */
.map-list { display: grid; gap: 24px; }
.list-group h3 { font-size: 18px; margin: 0 0 10px; color: var(--ink); }
.list-group { display: grid; gap: 8px; }
.card {
  display: grid;
  gap: 2px;
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: var(--fill);
  cursor: pointer;
  font-family: var(--sans);
}
.card-t { font-weight: 600; font-size: 16px; color: var(--title); }
.card-s { font-size: 14px; color: var(--sub); }
.card-next { font-size: 13px; color: var(--sub); opacity: 0.85; margin-top: 4px; }

.map-error { padding: 16px; border: 1px solid var(--line); border-radius: 10px; font-family: var(--sans); }

/* sources */
.sources-block h2 { font-size: 22px; margin: 48px 0 8px; }
.sources-block > p { color: var(--muted); max-width: 760px; }
.sources { padding-left: 1.2em; max-width: 860px; }
.sources li { margin: 10px 0; }
.source-note { color: var(--muted); }

/* ------------------------------------------------------------- sheet */

.sheet {
  border: 0;
  padding: 0;
  margin: 0 0 0 auto;
  height: 100dvh;
  max-height: 100dvh;
  /* --sheet-w is set by map.js from the stored width; the clamp there keeps it sane. */
  width: min(var(--sheet-w, 480px), calc(100vw - 48px));
  max-width: 100vw;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.sheet::backdrop { background: var(--backdrop); }

/* Drag handle on the sheet's left edge (desktop only). */
.sheet-resize {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 14px;
  cursor: ew-resize;
  touch-action: none;
  z-index: 2;
  /* the sheet's coloured edge stripe lives here, so all of it is grabbable */
  background: linear-gradient(to right, var(--stroke) 0 4px, transparent 4px);
}
.sheet-resize::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 50%;
  width: 4px;
  height: 48px;
  margin-top: -24px;
  border-radius: 2px;
  background: var(--stroke);
  opacity: 0;
  transition: opacity 0.15s;
}
.sheet-resize:hover::after, .sheet-resize:focus-visible::after, .resizing-sheet .sheet-resize::after { opacity: 0.9; }
.sheet-resize:focus-visible { outline: none; }
.resizing-sheet, .resizing-sheet * { cursor: ew-resize !important; user-select: none !important; }
.sheet[open] { animation: slide-in 0.18s ease-out; }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }

@media (max-width: 640px) {
  .sheet {
    margin: auto 0 0;
    width: 100vw;
    height: 88dvh;
    max-height: 88dvh;
    border-left: 0;
    border-top: 4px solid var(--stroke);
    border-radius: 16px 16px 0 0;
  }
  .sheet-resize { display: none; }
  @keyframes slide-in { from { transform: translateY(24px); opacity: 0; } }
}
@media (prefers-reduced-motion: reduce) { .sheet[open] { animation: none; } * { transition: none !important; } }

.sheet-inner { height: 100%; overflow-y: auto; padding: 20px 24px 40px; overscroll-behavior: contain; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.chip {
  font: 500 12px/1 var(--sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--title);
  border: 1px solid var(--stroke);
}
.close { border: 0; background: transparent; font-size: 28px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.close:hover { color: var(--ink); background: var(--bg); }
.sheet h2 { font-size: 28px; margin: 16px 0 4px; }
.sheet-sub { margin: 0 0 16px; color: var(--muted); font: 15px/1.5 var(--sans); }
.sheet h3 { font: 600 13px/1.4 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); margin: 24px 0 8px; }
.prose p { margin: 0 0 12px; }
.ideas { padding-left: 1.2em; margin: 0; }
.ideas li { margin: 6px 0; }
.check { margin-top: 24px; padding: 4px 16px 12px; border-radius: 10px; background: var(--fill); color: var(--title); }
.check h3 { color: var(--sub); margin-top: 12px; }
.check p { margin: 0; }
.rel { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.rel li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.rel-btn {
  border: 1px solid var(--stroke);
  background: var(--fill);
  color: var(--title);
  border-radius: 999px;
  padding: 3px 12px;
  cursor: pointer;
  font: 500 14px var(--sans);
}
.rel-note { font: 14px/1.4 var(--sans); color: var(--muted); }
.refs { padding-left: 1.2em; margin: 0; font: 15px/1.5 var(--sans); }
.refs li { margin: 4px 0; }
.page { color: var(--faint); }

var { font-style: italic; }

/* Figures inside the detail sheet. Inline SVG styled by class so they follow the
   theme and the node's colour ramp. */
.fig { margin: 20px 0; padding: 12px 12px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.fig-art svg { display: block; width: 100%; height: auto; overflow: visible; }
.fig figcaption { margin-top: 8px; font-size: 14px; line-height: 1.5; color: var(--muted); }
.fig text { fill: var(--ink); font: 14px var(--sans); }
.fig .t-vec { fill: var(--title); }
.fig .t-muted { fill: var(--muted); font-size: 12px; }
.fig .axis { stroke: var(--ink); stroke-width: 1.25; fill: none; }
.fig .fibre { stroke: var(--stroke); stroke-width: 1.25; opacity: 0.7; }
.fig .fibre-faint { stroke: var(--edge); stroke-width: 1; stroke-dasharray: 3 4; opacity: 0.6; }
.fig .vec { stroke: var(--stroke); stroke-width: 3; stroke-linecap: round; }
.fig marker path { fill: var(--stroke); }
.fig .pt { fill: var(--ink); }
