/* ─────────────────────────────────────────────────────────────────────────
   Open Brain — Documentation handbook stylesheet
   Shares the design language of the Open Brain shell (app.html) so the docs
   read as one system: system-UI body, editorial system-serif display heads,
   calm hairline rules over heavy cards, one cobalt accent used sparingly,
   muted grays, tabular figures. Self-contained — no external fonts.
   ───────────────────────────────────────────────────────────────────────── */

:root {
  /* Light editorial theme — the shell's own tokens (app.html :root). */
  --ground:  #f8f8f7;   /* page background            */
  --panel:   #ffffff;   /* raised surfaces (rail, cards) */
  --sunk:    #efefee;   /* recessed (code, hovers)    */
  --ink:     #111113;   /* primary text               */
  --ink-2:   #35363a;   /* body prose                 */
  --muted:   #63656a;   /* secondary text             */
  /* --faint carries real text (eyebrows, table heads, captions, the doc footer), all of it under
     13px — normal text, so it owes 4.5:1, not 3:1. It was #8e9095, which is 2.78:1 on --sunk and
     3.01:1 on --ground: a fail on every surface, in both themes. These two values are the CLOSEST
     points on the same gray's own hue line that clear 4.5:1 against the WORST background in their
     theme (--sunk light, --panel dark). Darkening/lightening further is unnecessary; going back
     one step fails. Keep the two stylesheets and app.html in step — same token, three surfaces. */
  --faint:   #6b6d72;   /* labels, captions — 4.50:1 on --sunk, 4.87 on --ground, 5.18 on --panel */
  --rule:    #e4e4e2;   /* hairline                   */
  --rule-2:  #cfcfcc;   /* stronger hairline          */
  --accent:  #1b4de4;   /* the one cobalt accent      */
  --on-accent: #ffffff;
  --good:    #2e7346;
  --warn:    #8a6410;
  --crit:    #a8332a;

  --ff-display: "Hoefler Text", "Iowan Old Style", "Palatino Linotype", Palatino, Charter, Cambria, Georgia, serif;
  --ff-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ff-num: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Mono", "Liberation Mono", Menlo, Consolas, monospace;

  --sidebar-w: 258px;
  --content-max: 760px;
  --topbar-h: 54px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0c0d10; --panel: #15171b; --sunk: #111318;
    --ink: #e9eaee; --ink-2: #c3c5cb; --muted: #8b8e96; --faint: #7d8088;
    --rule: #22252b; --rule-2: #333740;
    --accent: #7e9bff; --on-accent: #0c0d10;
    --good: #4fa96d; --warn: #c79a3e; --crit: #de6a60;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--ff-ui);
  font-size: 15px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* The neon radial belonged to the dark theme — gone in the light editorial look. */
.glow-bg { display: none; }

a {
  color: var(--accent); text-decoration: none;
  text-decoration-thickness: 1px; text-underline-offset: 2px;
}
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

code, .num { font-family: var(--ff-num); font-variant-numeric: tabular-nums; }

/* ── Top bar ─────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 1.4rem;
  min-height: var(--topbar-h); padding: 0 1.6rem;
  background: var(--ground);
  border-bottom: 1px solid var(--rule);
}
.topbar .logo {
  font-family: var(--ff-display); font-weight: 600;
  font-size: 1.04rem; letter-spacing: -.012em; color: var(--ink);
}
.topbar .logo .neon { color: var(--ink); }
.topbar .logo .tag {
  font-family: var(--ff-num); font-size: 0.58rem; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  border: 1px solid var(--rule-2); color: var(--faint);
  padding: 0.14rem 0.42rem; border-radius: 2px; margin-left: 0.45rem; vertical-align: middle;
}
.topbar .toplinks { display: flex; gap: 0.15rem; margin-left: auto; flex-wrap: wrap; }
.topbar .toplinks a {
  color: var(--muted); font-size: 0.82rem;
  padding: 0.35rem 0.62rem; border-radius: 2px; text-decoration: none;
}
.topbar .toplinks a:hover { color: var(--ink); background: var(--sunk); }
.topbar .toplinks a.active { color: var(--accent); }

/* ── Layout: sidebar + content ───────────────────────────────────────── */
.shell { display: flex; align-items: flex-start; max-width: 1320px; margin: 0 auto; }

.sidebar {
  position: sticky; top: var(--topbar-h); align-self: flex-start;
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  padding: 1.6rem 1rem 3rem 1.4rem;
  border-right: 1px solid var(--rule); background: var(--panel);
}
.sidebar h4 {
  font-family: var(--ff-num); font-size: 0.64rem; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--faint); margin: 1.5rem 0 0.5rem 0.55rem;
}
.sidebar h4:first-child { margin-top: 0; }
.sidebar a {
  display: block; color: var(--ink-2); font-size: 0.865rem;
  padding: 0.34rem 0.55rem; text-decoration: none;
  border-left: 2px solid transparent;
}
.sidebar a:hover { color: var(--ink); background: var(--sunk); }
.sidebar a.active {
  color: var(--ink); font-weight: 600; background: var(--sunk);
  border-left-color: var(--accent);
}

.content {
  flex: 1 1 auto; min-width: 0;
  padding: 2.4rem clamp(1.2rem, 4vw, 3.4rem) 5rem;
}
.content-inner { max-width: var(--content-max); margin: 0 auto; }

/* ── Typography ──────────────────────────────────────────────────────── */
.eyebrow {
  font-family: var(--ff-num); color: var(--faint);
  font-size: 0.68rem; font-weight: 600;
  letter-spacing: 0.16em; text-transform: uppercase; margin-bottom: 0.7rem;
}
h1 {
  font-family: var(--ff-display); font-weight: 600;
  font-size: clamp(1.9rem, 4vw, 2.55rem); line-height: 1.1;
  letter-spacing: -0.022em; margin: 0 0 0.85rem; color: var(--ink);
}
.lede {
  font-size: 1.14rem; line-height: 1.55; color: var(--ink-2);
  font-weight: 400; margin: 0 0 1.7rem; max-width: 64ch;
}
h2 {
  font-family: var(--ff-display); font-weight: 600;
  font-size: 1.46rem; line-height: 1.18; letter-spacing: -0.018em;
  color: var(--ink); margin: 2.8rem 0 0.9rem;
  padding-top: 1.15rem; border-top: 1px solid var(--rule);
  scroll-margin-top: 72px;
}
h3 {
  font-family: var(--ff-display); font-weight: 600;
  font-size: 1.16rem; letter-spacing: -0.012em; color: var(--ink);
  margin: 1.8rem 0 0.5rem; scroll-margin-top: 72px;
}
p { margin: 0.75rem 0; color: var(--ink-2); }
strong { color: var(--ink); font-weight: 600; }
em { color: var(--ink-2); }
hr { border: none; border-top: 1px solid var(--rule); margin: 2.4rem 0; }

ul, ol { padding-left: 1.3rem; color: var(--ink-2); }
li { margin: 0.35rem 0; }

/* ── Cards & callouts ────────────────────────────────────────────────── */
.card {
  background: var(--panel); border: 1px solid var(--rule);
  border-radius: 3px; padding: 1.25rem 1.4rem; margin: 1.3rem 0;
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); margin: 1.3rem 0; }
.grid .card { margin: 0; }

/* "Why it matters" — a quiet positive callout, not a glass slab */
.benefit {
  border: 1px solid var(--rule);
  border-left: 2px solid var(--good);
  background: color-mix(in srgb, var(--good) 5%, var(--panel));
  border-radius: 0 3px 3px 0; padding: 0.85rem 1.1rem; margin: 1.2rem 0;
}
.benefit .label {
  display: inline-block; font-family: var(--ff-num);
  font-size: 0.62rem; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--good); margin-bottom: 0.25rem;
}
.benefit p { margin: 0.15rem 0 0; color: var(--ink-2); }

.note {
  border-left: 3px solid var(--accent); background: var(--sunk);
  border-radius: 0 3px 3px 0; padding: 0.8rem 1.1rem; margin: 1.2rem 0;
  color: var(--ink-2); font-size: 0.95rem;
}
.note.warn {
  border-left-color: var(--warn);
  background: color-mix(in srgb, var(--warn) 6%, var(--panel));
}

/* inline code + file:line path chips */
code, .path {
  font-family: var(--ff-num); font-variant-numeric: tabular-nums;
  font-size: 0.85em; background: var(--sunk); color: var(--ink-2);
  padding: 0.08rem 0.36rem; border-radius: 2px; border: 1px solid var(--rule);
  white-space: nowrap;
}
a code, a .path { color: var(--accent); }
pre {
  background: var(--sunk); border: 1px solid var(--rule);
  border-radius: 3px; padding: 1rem 1.1rem; overflow-x: auto; margin: 1.2rem 0;
}
pre code {
  background: none; border: none; color: var(--ink);
  white-space: pre; padding: 0; font-size: 0.82rem;
}

/* ── Step / pipeline list ────────────────────────────────────────────── */
.steps { counter-reset: step; list-style: none; padding: 0; margin: 1.5rem 0; }
.steps > li {
  position: relative; padding: 0.25rem 0 1.1rem 3rem; margin: 0 0 0 1rem;
  border-left: 1px solid var(--rule);
  color: var(--ink-2);
}
.steps > li:last-child { border-left: 1px solid transparent; }
.steps > li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: -1rem; top: 0; width: 2rem; height: 2rem;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--accent); color: var(--accent);
  font-family: var(--ff-num); font-variant-numeric: tabular-nums;
  font-size: 0.82rem; font-weight: 600;
}
.steps > li .step-title { font-weight: 600; color: var(--ink); }

/* ── Tables ──────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; margin: 1.3rem 0; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 440px; }
th, td {
  text-align: left; padding: 0.55rem 0.85rem 0.55rem 0;
  border-bottom: 1px solid var(--rule); vertical-align: top;
}
th {
  font-family: var(--ff-num); color: var(--faint); font-weight: 500;
  font-size: 0.7rem; letter-spacing: 0.11em; text-transform: uppercase;
  border-bottom: 1px solid var(--rule-2); white-space: nowrap;
}
td { color: var(--ink-2); }
tbody tr:hover { background: var(--sunk); }

/* ── Pills / tags ────────────────────────────────────────────────────── */
.pill {
  display: inline-block; font-family: var(--ff-num);
  font-size: 0.66rem; font-weight: 600; letter-spacing: 0.04em;
  padding: 0.14rem 0.5rem; border-radius: 2px;
  border: 1px solid var(--rule-2); color: var(--muted);
  margin: 0 0.2rem 0.2rem 0;
}
.pill.on { color: var(--good); border-color: color-mix(in srgb, var(--good) 34%, var(--rule)); }
.pill.live { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--rule)); }
.pill.partial { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 34%, var(--rule)); }

/* ── Feature cards on the overview ───────────────────────────────────── */
.feature { display: block; text-decoration: none; color: inherit; transition: border-color .15s; }
.feature:hover { border-color: var(--accent); text-decoration: none; }
.feature .ico { font-size: 1.4rem; line-height: 1; }
.feature h3 { margin: 0.55rem 0 0.3rem; color: var(--ink); }
.feature:hover h3 { color: var(--accent); }
.feature p { margin: 0; color: var(--muted); font-size: 0.9rem; }

/* ── Page footer / prev-next ─────────────────────────────────────────── */
.pagenav { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; flex-wrap: wrap; }
.pagenav a {
  flex: 1 1 220px; border: 1px solid var(--rule); border-radius: 3px;
  padding: 0.85rem 1.1rem; text-decoration: none; color: var(--ink);
}
.pagenav a:hover { border-color: var(--accent); text-decoration: none; }
.pagenav .dir {
  font-family: var(--ff-num); font-size: 0.68rem; color: var(--faint);
  text-transform: uppercase; letter-spacing: 0.1em;
}
.pagenav .ttl { color: var(--accent); font-weight: 600; }
.pagenav a.next { text-align: right; }

.docfoot {
  margin-top: 3.5rem; padding-top: 1.4rem; border-top: 1px solid var(--rule);
  color: var(--faint); font-size: 0.8rem;
}

/* ── Mobile ──────────────────────────────────────────────────────────── */
.menu-toggle { display: none; }
@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; z-index: 30;
    width: 82%; max-width: 320px; height: calc(100vh - var(--topbar-h));
    background: var(--panel); transform: translateX(-102%); transition: transform .2s;
    border-right: 1px solid var(--rule-2);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle {
    display: inline-grid; place-items: center; width: 38px; height: 38px;
    background: var(--sunk); border: 1px solid var(--rule-2); border-radius: 2px;
    color: var(--accent); font-size: 1.05rem; cursor: pointer;
  }
  .topbar .toplinks { display: none; }
}

/* ── Load-process diagram figure ─────────────────────────────────────── */
/* The SVG is drawn light-on-dark (a blueprint figure), so the scroll panel
   stays dark on the light page — an intentional inset, not a leftover. */
figure.diagram {
  position: relative;
  margin: 1.8rem 0 2.2rem;
  /* break out of the text column to fill the whole reading area */
  width: calc(min(100vw, 1320px) - var(--sidebar-w) - 2 * clamp(1.2rem, 4vw, 3.4rem));
  margin-left: 50%;
  transform: translateX(-50%);
}
.diagram-scroll {
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  background: #12141c;
  padding: 0.6rem;
}
.diagram-scroll svg { display: block; min-width: 960px; width: 100%; height: auto; cursor: zoom-in; }
.diagram-hint {
  position: absolute; top: 12px; right: 14px; z-index: 3;
  font-family: var(--ff-num); font-size: 0.7rem; letter-spacing: 0.02em;
  color: #cfd5de;
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.16);
  border-radius: 2px; padding: 0.2rem 0.6rem; pointer-events: none;
}
figure.diagram figcaption {
  color: var(--muted); font-size: 0.9rem; line-height: 1.55;
  margin-top: 0.9rem; padding: 0 0.2rem; max-width: 76ch;
}
figure.diagram figcaption strong { color: var(--ink); }

/* fullscreen lightbox — overlays the whole document */
.diagram-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: none; align-items: center; justify-content: center;
  padding: 3vmin;
  background: rgba(6,7,11,0.94);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.diagram-overlay.open { display: flex; }
.diagram-overlay-inner {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
}
.diagram-overlay svg {
  width: 100%; height: 100%; max-width: 100%; max-height: 100%;
  min-width: 0; cursor: zoom-out;
}
.diagram-close {
  position: fixed; top: 14px; right: 16px; z-index: 210;
  width: 40px; height: 40px; border-radius: 3px;
  display: grid; place-items: center; cursor: pointer;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
  color: #ffffff; font-size: 1.15rem; line-height: 1;
}
.diagram-close:hover { border-color: rgba(255,255,255,0.5); }

@media (max-width: 900px) {
  figure.diagram { width: 100%; margin-left: 0; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
