/* =====================================================================
   legend-of-legaia-re — site stylesheet
   Three-column wiki layout: sidebar (collapsible) | content | TOC rail.
   Restrained palette: one accent (cyan) for emphasis, the rest is a
   neutral terminal grey. No animations, no gradients, no pulses.
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  --bg:            #0d1117;
  --bg-raised:     #11161e;
  --bg-card:       #131922;
  --bg-card-hi:    #19212d;
  --bg-code:       #0a0e15;

  --border:        #1f2630;
  --border-hi:     #2a323e;

  --text:          #c9d1d9;
  --text-muted:    #8b949e;
  --text-dim:      #636b76;

  --accent:        #58c4b3;     /* cyan, single emphasis colour */
  --accent-hi:     #7ad3c4;
  --accent-soft:   #1c2a2a;
  --done:          #58c4b3;
  --partial:       #c19a4d;
  --open:          #b56b6b;
  --planned:       #6e7681;

  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Menlo, monospace;

  --sidebar-w:     264px;
  --toc-w:         220px;
  --max-content-w: 780px;
  --transition:    0.12s ease;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 24px;
  -webkit-text-size-adjust: 100%;
  font-size: 15.5px;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

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

img, svg { max-width: 100%; height: auto; display: block; }

ul, ol { list-style: none; }

h1, h2, h3, h4 {
  color: #e6edf3;
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.3;
}

h1 { font-size: 1.65rem; }
h2 {
  font-size: 1.22rem;
  margin-top: 2.4rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  position: relative;
  scroll-margin-top: 24px;
}
h3 {
  font-size: 1.02rem;
  margin-top: 1.7rem;
  position: relative;
  scroll-margin-top: 24px;
}
h4 { font-size: 0.94rem; color: var(--text); margin-top: 1.1rem; }

/* Heading anchor links (clickable §) */
.h-anchor {
  position: absolute;
  left: -1.4rem;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  color: var(--text-dim);
  font-weight: 400;
  font-size: 0.85em;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition);
  text-decoration: none;
}
h2:hover .h-anchor,
h3:hover .h-anchor,
h4:hover .h-anchor { opacity: 1; }
.h-anchor:hover { color: var(--accent); text-decoration: none; }

p { margin: 0.7rem 0; }

code, pre {
  font-family: var(--font-mono);
}

code {
  background: var(--bg-code);
  border: 1px solid var(--border);
  padding: 0.05em 0.35em;
  border-radius: 3px;
  font-size: 0.86em;
  color: #b8d6cf;
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.85rem 1rem;
  overflow-x: auto;
  font-size: 0.84rem;
  line-height: 1.6;
  position: relative;
  margin: 0.9rem 0;
}

pre code {
  background: transparent;
  border: 0;
  padding: 0;
  font-size: inherit;
  color: var(--text);
}

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

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

::selection { background: var(--accent-soft); color: var(--text); }

/* ---------- App shell: 3-column grid ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  min-height: 100vh;
  align-items: start;
}

/* No TOC rail when not needed — fall back to 2-column */
.app.no-toc {
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  padding: 1rem 0.85rem 2rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  display: block;
  color: var(--text);
  font-weight: 700;
  font-size: 0.92rem;
  padding: 0.4rem 0.5rem 1rem;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
  flex-shrink: 0;
}

.sidebar-brand:hover { color: var(--text); text-decoration: none; }

.sidebar-brand .prompt {
  color: var(--accent);
  margin-right: 0.4rem;
}

/* Search trigger */
.sidebar-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.42rem 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  cursor: pointer;
  margin-bottom: 1rem;
  text-align: left;
  transition: border-color var(--transition), color var(--transition);
}
.sidebar-search:hover { border-color: var(--border-hi); color: var(--text); }
.sidebar-search .icon { color: var(--text-dim); }
.sidebar-search .label { flex: 1; }
.sidebar-search .kbd {
  font-size: 0.7rem;
  border: 1px solid var(--border-hi);
  border-radius: 3px;
  padding: 0 0.35rem;
  color: var(--text-dim);
}

/* Sidebar sections — collapsible */
.sidebar-section {
  margin-bottom: 0.3rem;
}

.sidebar-section-toggle {
  display: flex;
  align-items: center;
  width: 100%;
  background: transparent;
  border: 0;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.66rem;
  color: var(--text-dim);
  font-weight: 600;
  font-family: inherit;
  padding: 0.45rem 0.5rem;
  border-radius: 3px;
  transition: background var(--transition), color var(--transition);
}
.sidebar-section-toggle:hover { background: var(--bg-card); color: var(--text-muted); }
.sidebar-section-toggle .arrow {
  margin-right: 0.4rem;
  font-size: 0.7rem;
  transition: transform var(--transition);
}
.sidebar-section.collapsed .sidebar-section-toggle .arrow { transform: rotate(-90deg); }
.sidebar-section.has-active .sidebar-section-toggle { color: var(--text); }
.sidebar-section.has-active .sidebar-section-toggle .arrow { color: var(--accent); }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  margin: 0.1rem 0 0.2rem;
}
.sidebar-section.collapsed .sidebar-nav { display: none; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.32rem 0.5rem 0.32rem 1.4rem;
  color: var(--text-muted);
  border-radius: 3px;
  border-left: 2px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  line-height: 1.4;
}

.sidebar-nav a:hover {
  color: var(--text);
  background: var(--bg-card);
  text-decoration: none;
}

.sidebar-nav a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--bg-card);
}

.sidebar-foot {
  margin-top: auto;
  padding: 1rem 0.5rem 0;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.74rem;
  line-height: 1.55;
}

.sidebar-foot a { color: var(--text-muted); }
.sidebar-foot a:hover { color: var(--accent); }

/* Mobile sidebar toggle */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 50;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  width: 38px;
  height: 38px;
  border-radius: 4px;
  font-size: 1.1rem;
  cursor: pointer;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(13, 17, 23, 0.6);
  z-index: 35;
}
.sidebar-overlay.show { display: block; }

@media (max-width: 1100px) {
  /* Drop TOC rail */
  .app, .app.no-toc {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }
  .toc-rail { display: none; }
}

@media (max-width: 880px) {
  .app, .app.no-toc {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: var(--sidebar-w);
    z-index: 40;
    transform: translateX(-100%);
    transition: transform var(--transition);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .content { padding-top: 64px; }
}

/* ---------- Content column ---------- */
.content {
  padding: 2rem 2.4rem 4rem;
  max-width: calc(var(--max-content-w) + 4.8rem);
  width: 100%;
  min-width: 0;
}

@media (max-width: 720px) {
  .content { padding: 1.4rem 1.2rem 3rem; }
}

/* ---------- Page header ---------- */
.page-header {
  padding-bottom: 1.4rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.6rem;
}

.page-header .breadcrumb {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
  text-transform: lowercase;
  letter-spacing: 0.04em;
}

.page-header .breadcrumb a { color: var(--text-muted); }
.page-header .breadcrumb a:hover { color: var(--accent); }

.page-header h1 {
  margin-bottom: 0.5rem;
}

.page-header .lede {
  color: var(--text-muted);
  font-size: 1.0rem;
  max-width: 720px;
  line-height: 1.6;
}

section.doc-section {
  scroll-margin-top: 24px;
  margin-bottom: 2rem;
}

section.doc-section > p {
  color: var(--text-muted);
  max-width: 720px;
}

.doc-section ul.bullets,
.doc-section ol.bullets {
  list-style: none;
  margin: 0.6rem 0;
  padding: 0;
}

.doc-section ul.bullets li,
.doc-section ol.bullets li {
  position: relative;
  padding-left: 1.2rem;
  margin: 0.3rem 0;
  color: var(--text-muted);
  line-height: 1.6;
  font-size: 0.95rem;
}

.doc-section ul.bullets li::before {
  content: "·";
  position: absolute;
  left: 0.3rem;
  color: var(--accent);
  font-weight: 700;
}

.doc-section ol.bullets {
  counter-reset: step;
}

.doc-section ol.bullets li {
  counter-increment: step;
  padding-left: 1.7rem;
}

.doc-section ol.bullets li::before {
  content: counter(step) ".";
  position: absolute;
  left: 0;
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 0.85rem;
}

/* Plain ul/ol inside .doc-section also gets nice styling */
.doc-section > ul:not(.bullets):not(.next-list):not(.fnref-list),
.doc-section > ol:not(.bullets) {
  margin: 0.7rem 0 0.7rem 0;
  padding-left: 0;
}
.doc-section > ul:not(.bullets):not(.next-list):not(.fnref-list) > li {
  position: relative;
  padding-left: 1.1rem;
  margin: 0.3rem 0;
  color: var(--text-muted);
  line-height: 1.6;
}
.doc-section > ul:not(.bullets):not(.next-list):not(.fnref-list) > li::before {
  content: "·";
  position: absolute;
  left: 0.25rem;
  color: var(--accent);
  font-weight: 700;
}

/* ---------- Status tag ---------- */
.tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.08rem 0.45rem;
  border-radius: 2px;
  border: 1px solid;
  background: transparent;
  vertical-align: middle;
  line-height: 1.5;
}

.tag-done    { color: var(--done);    border-color: var(--done); }
.tag-partial { color: var(--partial); border-color: var(--partial); }
.tag-open    { color: var(--open);    border-color: var(--open); }
.tag-planned { color: var(--planned); border-color: var(--planned); }
.tag-stub    { color: var(--text-dim); border-color: var(--border-hi); font-weight: 500; }

/* ---------- Tables ---------- */
.table-wrap, table {
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: auto;
  margin: 0.9rem 0;
  background: var(--bg-card);
  display: block;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  display: table;
}

thead { background: var(--bg-raised); }

th, td {
  padding: 0.6rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.5;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg-card-hi); }

th {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

td { color: var(--text-muted); }
td code { font-size: 0.82rem; padding: 0.05em 0.3em; }
td strong { color: var(--text); }

td.col-addr { font-family: var(--font-mono); color: var(--text); white-space: nowrap; font-size: 0.83rem; }
td.col-status { white-space: nowrap; }
td.col-crate { font-family: var(--font-mono); color: var(--text-muted); font-size: 0.82rem; white-space: nowrap; }

/* ---------- Definition list ---------- */
dl.kv {
  display: grid;
  grid-template-columns: minmax(140px, max-content) 1fr;
  gap: 0.45rem 1rem;
  font-size: 0.92rem;
  margin: 0.7rem 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
}

dl.kv dt {
  font-family: var(--font-mono);
  color: var(--text-dim);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  align-self: center;
}

dl.kv dd { color: var(--text); line-height: 1.55; }

/* ---------- Pipeline / flow diagram ---------- */
.flow {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 0.45rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem 1.2rem;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  align-items: center;
}

.flow .num { color: var(--text-dim); text-align: right; font-size: 0.78rem; }
.flow .layer { color: var(--text); font-weight: 500; }
.flow .desc { color: var(--text-muted); font-size: 0.82rem; }
.flow .crate { color: var(--accent); font-size: 0.78rem; text-align: right; }
.flow .layer::before { content: "→ "; color: var(--text-dim); }

@media (max-width: 720px) {
  .flow { grid-template-columns: 1fr; gap: 0.15rem 0; padding: 0.9rem 1rem; }
  .flow .num, .flow .crate { text-align: left; }
  .flow .num::after { content: "."; }
  .flow .desc { padding-bottom: 0.4rem; }
}

/* ---------- Pills strip ---------- */
.pills { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.pill {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.18rem 0.55rem;
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 3px;
}

/* ---------- Notice / hint / callout ---------- */
.notice {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--bg-card);
  border-radius: 3px;
  padding: 0.8rem 1rem;
  font-size: 0.92rem;
  color: var(--text-muted);
  margin: 1rem 0;
}

.notice .notice-title {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.notice.warn { border-left-color: var(--partial); }
.notice.warn .notice-title { color: var(--partial); }

.hint {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  padding: 0.7rem 1rem;
  margin: 0.85rem 0;
  font-size: 0.92rem;
  color: var(--text-muted);
  border-radius: 0 3px 3px 0;
}
.hint code { background: rgba(13, 17, 23, 0.6); }

/* ---------- Code copy button ---------- */
.copy-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  background: var(--bg-raised);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition);
}

pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--accent); }

/* ---------- Stub block ---------- */
.stub-block {
  border: 1px dashed var(--border-hi);
  border-radius: 4px;
  padding: 0.85rem 1rem;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.88rem;
  font-style: italic;
  margin: 0.6rem 0;
}

.stub-block::before {
  content: "stub: ";
  font-family: var(--font-mono);
  font-style: normal;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-right: 0.4rem;
}

/* ---------- Function reference entry ---------- */
.func-entry {
  border-top: 1px solid var(--border);
  padding: 0.7rem 0;
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 0.4rem 1rem;
  font-size: 0.9rem;
}

.func-entry:first-of-type { border-top: 0; }

.func-entry .func-addr {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 500;
}

.func-entry .func-body strong { color: var(--text); font-weight: 600; }
.func-entry .func-body { color: var(--text-muted); line-height: 1.55; }

/* ---------- Caption ---------- */
.caption {
  font-family: var(--font-mono);
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-top: 0.3rem;
  letter-spacing: 0.02em;
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ---------- Skip link ---------- */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--accent);
  color: var(--bg);
  padding: 0.4rem 0.8rem;
  z-index: 1000;
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.skip-link:focus { top: 0; }

/* ===================================================================
   Cards (used heavily across home, formats, subsystems, reference)
   =================================================================== */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.85rem;
  margin: 1rem 0 1.5rem;
}

.card {
  display: block;
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 0.95rem 1.15rem;
  border-radius: 4px;
  text-decoration: none;
  color: var(--text);
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
  position: relative;
}

.card:hover {
  border-color: var(--accent);
  background: var(--bg-card-hi);
  text-decoration: none;
  color: var(--text);
}

.card:hover .card-title { color: var(--accent); }

.card[href*="github.com"]::after {
  content: "↗";
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.card-title {
  font-weight: 600;
  font-size: 0.98rem;
  margin-bottom: 0.4rem;
  line-height: 1.35;
  transition: color var(--transition);
}

.card-body {
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.card-body code {
  font-size: 0.84em;
  padding: 0.02em 0.3em;
}

/* ---------- Status grid (home page) ---------- */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}
.status-card {
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 1rem 1.25rem;
  border-left-width: 3px;
  border-radius: 4px;
}
.status-card-title { font-weight: 600; margin-bottom: 0.4rem; color: var(--text); }
.status-card-body  { color: var(--text-muted); font-size: 0.92rem; line-height: 1.55; }
.status-card.status-done    { border-left-color: var(--done); }
.status-card.status-partial { border-left-color: var(--partial); }
.status-card.status-open    { border-left-color: var(--open); }

dd.status-done    { color: var(--done); }
dd.status-partial { color: var(--partial); }
dd.status-open    { color: var(--open); }
.status-done    { color: var(--done); }
.status-partial { color: var(--partial); }
.status-open    { color: var(--open); }

/* ---------- Layers diagram (architecture page) ---------- */
.layers-diagram {
  display: flex; flex-direction: column; align-items: center;
  margin: 2rem 0; gap: 0;
}
.layers-diagram .layer {
  width: 100%;
  max-width: 720px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 1rem 1.25rem;
  text-decoration: none;
  color: var(--text);
  display: block;
  border-radius: 4px;
  transition: border-color var(--transition), background var(--transition);
}
.layers-diagram .layer:hover {
  border-color: var(--accent);
  background: var(--bg-card-hi);
}
.layers-diagram .layer-engine { border-color: var(--accent); }
.layers-diagram .layer-head {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 0.4rem;
}
.layers-diagram .layer-num {
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
  font-weight: 600;
}
.layers-diagram .layer-title { font-weight: 600; font-size: 1.05rem; color: var(--text); }
.layers-diagram .layer-body  { padding-left: 2.5rem; }
.layers-diagram .layer-crate {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--accent);
  margin-bottom: 0.3rem;
}
.layers-diagram .layer-desc { color: var(--text-muted); font-size: 0.92rem; line-height: 1.55; }
.layers-diagram .layer-arrow {
  color: var(--text-dim);
  font-size: 1.1rem;
  font-family: var(--font-mono);
  padding: 0.25rem 0;
}
.layers-diagram .layer-fanout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.5rem;
  width: 100%;
  max-width: 720px;
}
.layers-diagram .leaf {
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  border-radius: 3px;
  transition: border-color var(--transition), color var(--transition);
}
.layers-diagram .leaf:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.layers-diagram .leaf small {
  display: block;
  color: var(--text-dim);
  font-size: 0.72rem;
  margin-top: 0.2rem;
}

/* ---------- VM cards ---------- */
.vm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}
.vm-card {
  display: block;
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 1rem 1.25rem;
  text-decoration: none;
  color: var(--text);
  border-radius: 4px;
  transition: border-color var(--transition), background var(--transition);
}
.vm-card:hover { border-color: var(--accent); background: var(--bg-card-hi); }
.vm-card-num {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}
.vm-card-title { font-weight: 600; margin-bottom: 0.6rem; color: var(--text); }
.vm-card dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 0.75rem;
  font-size: 0.88rem;
}
.vm-card dt { color: var(--text-muted); font-size: 0.82rem; }
.vm-card dd { font-family: var(--font-mono); font-size: 0.85rem; color: var(--text); }

/* ---------- Function reference grid ---------- */
.fnref-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.fnref-block {
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 1rem 1.25rem;
  border-radius: 4px;
}
.fnref-block h3 {
  color: var(--accent);
  font-size: 0.95rem;
  margin: 0 0 0.6rem 0;
  font-family: var(--font-body);
}
.fnref-list {
  list-style: none;
  padding: 0;
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--text-muted);
}
.fnref-list li {
  padding: 0.1rem 0;
}
.fnref-list code {
  background: var(--bg-code);
  padding: 0.05rem 0.3rem;
  border-radius: 2px;
  font-size: 0.82rem;
  color: var(--accent);
}

/* ---------- next-list (used on quickstart) ---------- */
.next-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
}
.next-list li {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.92rem;
}
.next-list li:last-child { border-bottom: none; }
.next-list a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.next-list a:hover { text-decoration: underline; }

/* ---------- CTA link ---------- */
.cta {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.5rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  text-decoration: none;
  border-radius: 3px;
  transition: background var(--transition), color var(--transition);
}
.cta:hover { background: var(--accent); color: var(--bg); text-decoration: none; }

/* ---------- kbd ---------- */
kbd {
  font-family: var(--font-mono);
  background: var(--bg-code);
  border: 1px solid var(--border-hi);
  border-bottom-width: 2px;
  padding: 0.05rem 0.4rem;
  font-size: 0.82rem;
  color: var(--text);
  border-radius: 3px;
}

/* ===================================================================
   Right-rail in-page TOC
   =================================================================== */

.toc-rail {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  padding: 2rem 1rem 2rem 0.5rem;
  font-size: 0.82rem;
  border-left: 1px solid var(--border);
}

.toc-title {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
  padding-left: 0.6rem;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-left: 1px solid var(--border);
}

.toc-list a {
  display: block;
  padding: 0.22rem 0.7rem;
  color: var(--text-muted);
  font-size: 0.83rem;
  line-height: 1.45;
  border-left: 2px solid transparent;
  margin-left: -1px;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
  text-decoration: none;
}

.toc-list a:hover {
  color: var(--text);
  text-decoration: none;
}

.toc-list a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--bg-card);
}

.toc-list a.h3 {
  padding-left: 1.4rem;
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ===================================================================
   Prev/next navigation footer
   =================================================================== */

.page-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin: 3rem 0 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.page-nav a {
  display: block;
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 0.85rem 1rem;
  border-radius: 4px;
  color: var(--text);
  text-decoration: none;
  transition: border-color var(--transition), background var(--transition);
}

.page-nav a:hover {
  border-color: var(--accent);
  background: var(--bg-card-hi);
  text-decoration: none;
}

.page-nav .pn-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
}

.page-nav .pn-title {
  color: var(--accent);
  font-weight: 500;
  font-size: 0.95rem;
}

.page-nav .pn-prev { text-align: left; }
.page-nav .pn-next { text-align: right; grid-column: 2; }
.page-nav .pn-prev::before { content: "← "; color: var(--text-dim); }
.page-nav .pn-next::after { content: " →"; color: var(--text-dim); }
.page-nav .pn-prev:only-child { grid-column: 1; }

@media (max-width: 540px) {
  .page-nav { grid-template-columns: 1fr; }
  .page-nav .pn-next { grid-column: 1; text-align: left; }
  .page-nav .pn-next::after { content: ""; }
  .page-nav .pn-next::before { content: "→ "; color: var(--text-dim); }
}

/* ===================================================================
   Search overlay
   =================================================================== */

.search-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(13, 17, 23, 0.75);
  z-index: 100;
  align-items: flex-start;
  justify-content: center;
  padding-top: 8vh;
}
.search-overlay.open { display: flex; }

.search-box {
  width: min(640px, 92vw);
  background: var(--bg-raised);
  border: 1px solid var(--border-hi);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
}

.search-input-wrap .icon { color: var(--text-dim); font-size: 0.95rem; }

.search-input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 0.2rem 0;
}

.search-close {
  background: transparent;
  border: 1px solid var(--border-hi);
  color: var(--text-dim);
  border-radius: 3px;
  padding: 0.1rem 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  cursor: pointer;
}
.search-close:hover { color: var(--text); }

.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 65vh;
  overflow-y: auto;
}

.search-results li {
  border-bottom: 1px solid var(--border);
}

.search-results li:last-child { border-bottom: none; }

.search-results a {
  display: block;
  padding: 0.7rem 1rem;
  color: var(--text-muted);
  text-decoration: none;
}

.search-results a:hover,
.search-results li.active a {
  background: var(--bg-card-hi);
  color: var(--text);
  text-decoration: none;
}

.search-results .res-title {
  color: var(--accent);
  font-weight: 500;
  font-size: 0.95rem;
}

.search-results li.active .res-title,
.search-results a:hover .res-title { color: var(--accent-hi); }

.search-results .res-section {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-right: 0.5rem;
}

.search-results .res-snippet {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-results .res-snippet mark,
.search-results .res-title mark {
  background: var(--accent-soft);
  color: var(--accent-hi);
  padding: 0 0.15rem;
  border-radius: 2px;
}

.search-empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.search-foot {
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.search-foot kbd {
  font-size: 0.7rem;
  padding: 0.05rem 0.3rem;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text-muted);
}

@media (max-width: 540px) {
  .search-overlay { padding-top: 4vh; }
}
