/* The documentation pages (/docs, How it works; /docs/capabilities, the
   capability cards). The app's brand header with a tab per page under it,
   an "On this page" rail on the left and one reading column: on the first
   page the flow chart (framed lanes joined by the app's own button names),
   on the second the cards. Colours are the app's tokens (style.css); the
   page script sets data-theme from fermi_theme. */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fb;
    --bg-panel: #ffffff;
    --bg-input: #f3f4f6;
    --bg-hover: #e9ecf0;
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --accent: #4f46e5;
    --accent-light: #eef2ff;
    --accent-border: #c7d2fe;
    --on-accent: #ffffff;
    --brand-from: #4f46e5;
    --brand-to: #9333ea;
    --code-fg: #475569;
    --code-bg: #f1f5f9;
    --code-border: #cbd5e1;
    --success: #16a34a;
    --warning: #d97706;
    --error: #dc2626;
    --radius: 8px;
    --radius-sm: 4px;
    --font-mono: 'Fira Code', 'Cascadia Code', 'JetBrains Mono', Consolas, monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    /* the names account.css reads */
    --panel: var(--bg-panel); --line: var(--border); --fg: var(--text-primary);
    --muted: var(--text-muted); --input: var(--bg-input);
    color-scheme: light;
}
:root[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #111827;
    --bg-panel: #1e293b;
    --bg-input: #273449;
    --bg-hover: #334155;
    --text-primary: #e5e7eb;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border: #334155;
    --accent: #818cf8;
    --accent-light: #272b4f;
    --accent-border: #4f46e5;
    --on-accent: #0f172a;
    --code-fg: #cbd5e1;
    --code-bg: #1a2536;
    --code-border: #475569;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 104px; }
body {
    margin: 0; background: var(--bg-secondary); color: var(--text-primary);
    font-family: var(--font-sans); font-size: 15px; line-height: 1.55;
}
a { color: var(--accent); }
code { font-family: var(--font-mono); font-size: 0.86em; background: var(--bg-input); padding: 1px 5px; border-radius: var(--radius-sm); }

/* Header: as the catalog page's, then the page tabs; the two stay at the
   top together (89px: 48 + 40 + the border, which the sticky offsets below
   assume). */
.head { position: sticky; top: 0; z-index: 5; background: var(--bg-panel); border-bottom: 1px solid var(--border); }
.top { display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 20px; }
.top .brand { display: flex; align-items: center; gap: 9px; text-decoration: none; flex-shrink: 0; }
.brand-mark { width: 30px; height: 30px; flex-shrink: 0; filter: drop-shadow(0 1px 2px rgba(79, 70, 229, 0.25)); }
:root[data-theme="dark"] .brand-mark.logo-l, :root:not([data-theme="dark"]) .brand-mark.logo-d { display: none; }
.brand-name {
    font-size: 22px; font-weight: 800; line-height: 1.05; letter-spacing: -0.02em; white-space: nowrap;
    color: var(--accent);
    background: linear-gradient(90deg, var(--brand-from), var(--brand-to));
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.page-sep { color: var(--text-muted); font-size: 22px; font-weight: 300; line-height: 1; }
.top .page-name { font-size: 18px; font-weight: 600; margin: 0; white-space: nowrap; color: var(--text-primary); min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.top-spacer { flex: 1; }
.top .back { color: var(--accent); text-decoration: none; font-size: 13px; white-space: nowrap; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 30px; height: 30px; font-size: 16px; line-height: 1;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: transparent; color: var(--text-secondary); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
nav.pages {
    display: flex; gap: 4px; height: 40px; max-width: 1100px; margin: 0 auto; padding: 0 20px;
    overflow-x: auto; scrollbar-width: none;
}
nav.pages::-webkit-scrollbar { display: none; }
nav.pages a {
    display: flex; align-items: center; padding: 0 12px; font-size: 14px; white-space: nowrap;
    color: var(--text-secondary); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
nav.pages a:hover { color: var(--text-primary); background: var(--bg-hover); }
nav.pages a[aria-current] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
nav.pages a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
nav.pages .short { display: none; }

/* Page layout */
.wrap {
    display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 40px;
    max-width: 1100px; margin: 0 auto; padding: 28px 20px 64px;
}
nav.toc { position: sticky; top: 117px; align-self: start; font-size: 14px; }
.toc-h { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin: 0 0 8px; font-weight: 600; }
.toc ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.toc a { display: flex; justify-content: space-between; gap: 8px; padding: 5px 10px; border-radius: 6px; text-decoration: none; color: var(--text-secondary); }
.toc a:hover { background: var(--bg-hover); color: var(--text-primary); }
.toc a[aria-current] { background: var(--accent-light); color: var(--accent); font-weight: 600; }
.toc .n { color: var(--text-muted); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; }

main { min-width: 0; max-width: 780px; }
main h1 { font-size: 30px; line-height: 1.2; letter-spacing: -0.015em; margin: 0 0 12px; text-wrap: balance; }
.lead { font-size: 17px; color: var(--text-secondary); margin: 0 0 28px; max-width: 64ch; }
h2.sec { font-size: 20px; margin: 44px 0 10px; }

/* Legend and the steps' switch */
.chart-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 0 0 16px; font-size: 13px; color: var(--text-secondary); }
.chart-bar .spacer { flex: 1; }
.chart-bar .pair { display: inline-flex; align-items: center; gap: 6px; }
.tag {
    display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
    text-transform: uppercase; border-radius: var(--radius-sm); padding: 1px 7px; border: 1px solid; white-space: nowrap;
}
.tag.model { color: var(--accent); background: var(--accent-light); border-color: var(--accent-border); }
.tag.code { color: var(--code-fg); background: var(--code-bg); border-color: var(--code-border); }
.linkbtn {
    background: var(--bg-panel); border: 1px solid var(--border); color: var(--text-secondary);
    border-radius: 6px; padding: 4px 10px; font: inherit; font-size: 13px; cursor: pointer;
}
.linkbtn:hover { background: var(--bg-hover); }
.linkbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The flow */
.flow { display: grid; }
.entry { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 260px); gap: 12px; }
.box { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.box h2, .box h3 { font-size: 15px; margin: 0 0 2px; }
.box p { margin: 0; font-size: 14px; }
.side { border-style: dashed; color: var(--text-secondary); }
.side h3 { color: var(--text-primary); font-size: 14px; }
.side p { font-size: 13px; }
.loop { border-color: var(--accent-border); background: var(--accent-light); }

.join { display: flex; flex-direction: column; align-items: center; padding: 6px 0; }
.join::before { content: ""; width: 2px; height: 12px; background: var(--code-border); }
.join::after { content: ""; width: 2px; height: 8px; background: var(--code-border); }
.join .arrow { order: 3; width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 7px solid var(--code-border); }
.action { font-size: 13px; font-weight: 600; color: var(--on-accent); background: var(--accent); border-radius: 6px; padding: 4px 12px; white-space: nowrap; }
.action.plain { background: var(--bg-panel); color: var(--text-secondary); border: 1px solid var(--border); font-weight: 500; }

.lane { border: 1px solid var(--border); border-radius: 10px; background: var(--bg-panel); overflow: hidden; }
.lane-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--bg-input); }
.lane-head h2 { margin: 0; font-size: 16px; }
.lane-head span:not(.tag) { font-size: 13px; color: var(--text-muted); }
.steps { list-style: none; margin: 0; padding: 0; }
.steps > li + li { border-top: 1px solid var(--border); }
.step summary {
    list-style: none; cursor: pointer; display: grid;
    grid-template-columns: 26px minmax(0, 1fr) auto 16px; gap: 4px 12px; align-items: start; padding: 12px 16px;
}
.step summary::-webkit-details-marker { display: none; }
.step summary:hover { background: var(--bg-hover); }
.step summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.num {
    width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
    font-size: 12px; font-weight: 700; background: var(--bg-input); color: var(--text-secondary);
    border: 1px solid var(--border); font-variant-numeric: tabular-nums;
}
.st-title { font-weight: 600; }
.st-sum { grid-column: 2 / 4; font-size: 14px; color: var(--text-secondary); }
.tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chev { width: 9px; height: 9px; border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted); transform: rotate(45deg); margin-top: 5px; transition: transform .15s; }
.step[open] .chev { transform: rotate(-135deg); margin-top: 9px; }
.detail { padding: 0 16px 14px 54px; font-size: 14px; color: var(--text-secondary); }
.detail p { margin: 0 0 8px; }
.detail ul { margin: 0 0 8px; padding-left: 18px; }
.detail p:last-child { margin-bottom: 0; }

.stages { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stage { padding: 12px 14px; border-left: 1px solid var(--border); font-size: 13px; color: var(--text-secondary); }
.stage:first-child { border-left: 0; }
.stage h3 { margin: 0 0 2px; color: var(--text-primary); font-size: 14px; }
.stage p { margin: 0; }
.stage code { font-size: 12px; }
.lane-foot { border-top: 1px solid var(--border); padding: 10px 16px; font-size: 13px; color: var(--text-secondary); }
.lane-foot p { margin: 0; }
.lane-foot.legend { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.dot.ok { background: var(--success); }
.dot.warn { background: var(--warning); }
.dot.bad { background: var(--error); }

/* Good to know */
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; font-size: 14px; color: var(--text-secondary); }
.card h3 { margin: 0 0 6px; font-size: 15px; color: var(--text-primary); }
.card ul { margin: 0; padding-left: 18px; }
.card p { margin: 0 0 6px; }

/* Capabilities: a filter bar that stays under the header, then a group per
   heading with its cards two by two. */
main.caps { max-width: none; }
.tools {
    position: sticky; top: 89px; z-index: 3; background: var(--bg-secondary);
    display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
    padding: 10px 0; margin-bottom: 8px; border-bottom: 1px solid var(--border);
}
.tools input {
    flex: 1 1 240px; min-width: 0; font: inherit; font-size: 14px; padding: 7px 12px;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-panel); color: var(--text-primary);
}
.tools input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.tools .count { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tools .linkbtn { padding: 6px 12px; }
.empty { color: var(--text-muted); padding: 24px 0; }
.group { margin-top: 30px; scroll-margin-top: 160px; }
.group-head h2 { font-size: 20px; margin: 0; }
.group-head p { margin: 2px 0 12px; color: var(--text-secondary); font-size: 14px; }
.cap-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
.cap { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 6px; min-width: 0; scroll-margin-top: 160px; }
.cap:target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); }
.cap-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.cap h3 { margin: 0; font-size: 15.5px; }
.cap .fp { color: var(--text-muted); font-size: 12px; }
.cap .line { margin: 4px 0 10px; font-size: 14px; color: var(--text-secondary); }
.ask { display: flex; align-items: flex-start; gap: 8px; font-size: 13.5px; background: var(--bg-input); border-radius: 6px; padding: 7px 8px 7px 10px; }
.ask-l { flex: none; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); padding-top: 2px; }
.ask q { flex: 1; min-width: 0; quotes: "\201C" "\201D"; }
.ask.open span:last-child { color: var(--text-secondary); }
.copy {
    flex: none; font: inherit; font-size: 12px; color: var(--text-secondary); background: var(--bg-panel);
    border: 1px solid var(--border); border-radius: 5px; padding: 1px 8px; cursor: pointer;
}
.copy:hover { background: var(--bg-hover); }
.copy.done { color: var(--accent); border-color: var(--accent-border); }
.copy:focus-visible, .cap summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cap details { margin-top: 4px; }
.cap summary { list-style: none; cursor: pointer; font-size: 13px; color: var(--accent); padding: 6px 0; display: inline-flex; align-items: center; gap: 6px; }
.cap summary::-webkit-details-marker { display: none; }
.cap summary::after {
    content: ""; width: 7px; height: 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg) translateY(-2px); transition: transform .15s;
}
.cap details[open] summary::after { transform: rotate(-135deg) translateX(-2px); }
.more { font-size: 14px; color: var(--text-secondary); padding-bottom: 8px; }
.more p { margin: 0 0 8px; }

/* Computations (/docs/helpers): one helper per row, its signature, the
   method, and its code folded (spans from helpers_doc.highlight). */
.intro { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; margin: 0 0 8px; font-size: 14.5px; color: var(--text-secondary); }
.intro h2 { font-size: 17px; margin: 0 0 6px; color: var(--text-primary); }
.intro p { margin: 0 0 8px; }
.intro p:last-child { margin-bottom: 0; }
.tools-spacer { flex: 1; }
a.linkbtn { text-decoration: none; display: inline-block; }
.cap-grid.one { grid-template-columns: minmax(0, 1fr); }
.helper h3 code { background: none; padding: 0; font-size: 14.5px; overflow-wrap: anywhere; }
.helper .method { margin: 0 0 10px; font-size: 14px; color: var(--text-secondary); }
.helper .ask { margin-bottom: 4px; }
.helper .uses { margin: 8px 0 0; font-size: 13px; color: var(--text-muted); }
.helper .uses code { font-size: 12px; }
.helper.minor .line { margin-bottom: 4px; }
.src summary { gap: 8px; }
.src-at { color: var(--text-muted); font-size: 12px; }
.privs { margin: 2px 0 0 14px; padding-left: 12px; border-left: 2px solid var(--border); }
.privs-h { margin: 6px 0 0; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.privs .src { margin-top: 0; }
.privs summary code { font-size: 12.5px; }
pre.code {
    margin: 0 0 10px; padding: 10px 12px; overflow-x: auto; font-size: 12.5px; line-height: 1.5;
    background: var(--code-bg); border: 1px solid var(--border); border-radius: 6px; tab-size: 4;
}
pre.code code { background: none; padding: 0; font-size: inherit; color: var(--text-primary); }
pre.code .k { color: #7c3aed; }
pre.code .s { color: #047857; }
pre.code .c { color: var(--text-muted); font-style: italic; }
pre.code .n { color: #b45309; }
pre.code .f { color: #2563eb; font-weight: 600; }
:root[data-theme="dark"] pre.code .k { color: #c4b5fd; }
:root[data-theme="dark"] pre.code .s { color: #6ee7b7; }
:root[data-theme="dark"] pre.code .n { color: #fcd34d; }
:root[data-theme="dark"] pre.code .f { color: #93c5fd; }

/* Prose pages (/docs/sessions): sections with lists, a nested diagram of
   project > session > setup chains, definition cards, a two-column
   comparison and fact tables. */
.prose section { margin: 0 0 8px; }
.prose section > h2, .prose h2.sec { font-size: 20px; margin: 40px 0 10px; scroll-margin-top: 104px; }
.prose section:first-of-type > h2 { margin-top: 8px; }
.prose p, .prose li { color: var(--text-secondary); }
.prose ul { padding-left: 20px; margin: 0 0 12px; }
.prose li { margin-bottom: 6px; }
.prose li b, .prose p b { color: var(--text-primary); }
.note { font-size: 14px; border-left: 3px solid var(--warning); background: var(--bg-panel); padding: 8px 12px; border-radius: 0 6px 6px 0; }
.nest { margin: 4px 0 16px; font-size: 13px; }
.nest-box { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-panel); padding: 10px 12px; }
.nest-box.project { border-style: dashed; background: transparent; }
.nest-box.session { margin-top: 8px; }
.nest-box.dim { opacity: 0.65; }
.nest-l { margin: 0; font-weight: 600; color: var(--text-primary); }
.nest-l .kind { font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--accent); margin-right: 6px; }
.nest-note { font-weight: 400; color: var(--text-muted); margin-left: 6px; }
.chain { margin-top: 8px; padding: 8px 10px; border-radius: 6px; background: var(--bg-input); }
.chain-l { margin: 0 0 6px; font-size: 12px; color: var(--text-muted); }
.chain-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chain-row + .chain-row { margin-top: 6px; }
.chain-row.branch { padding-left: 24px; }
.tk { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 5px; padding: 2px 8px; white-space: nowrap; color: var(--text-primary); }
.tk.fit { border-color: var(--accent-border); background: var(--accent-light); }
.to { width: 14px; height: 0; border-top: 2px solid var(--code-border); position: relative; }
.to::after { content: ""; position: absolute; right: -2px; top: -5px; border-left: 6px solid var(--code-border); border-top: 4px solid transparent; border-bottom: 4px solid transparent; }
.from { font-size: 12px; color: var(--text-muted); }
.from::before { content: "↳ "; }
.defs, .compare { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 0 0 8px; }
.compare { grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 4px 0 14px; }
.def, .compare .col { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; }
.def h3, .compare h3 { margin: 0 0 4px; font-size: 15px; }
.def p { margin: 0; }
.compare ul { margin: 0; padding-left: 18px; }
.compare li { margin-bottom: 4px; }
.table-wrap { overflow-x: auto; margin: 4px 0 14px; }
table.facts { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); }
table.facts th, table.facts td { text-align: left; vertical-align: top; padding: 8px 12px; border-bottom: 1px solid var(--border); }
table.facts th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); background: var(--bg-input); }
table.facts td { color: var(--text-secondary); }
table.facts td:first-child { color: var(--text-primary); white-space: nowrap; }
table.facts tr:last-child td { border-bottom: 0; }

@media (max-width: 900px) {
    .wrap { grid-template-columns: minmax(0, 1fr); gap: 16px; padding-top: 20px; }
    nav.toc { position: static; }
    .toc ol { display: flex; flex-wrap: wrap; gap: 4px; }
    .cards { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 700px) {
    .cap-grid, .defs, .compare { grid-template-columns: minmax(0, 1fr); }
    table.facts td:first-child { white-space: normal; }
}
@media (max-width: 600px) {
    .top { padding: 0 16px; }
    nav.pages { padding: 0 6px; gap: 0; }
    nav.pages a { padding: 0 9px; font-size: 13.5px; }
    nav.pages .long { display: none; }
    nav.pages .short { display: inline; }
    .brand-name { font-size: 18px; }
    .top .page-name { font-size: 15px; }
    .page-sep { display: none; }
    .top .back { display: none; }
    .wrap { padding-left: 16px; padding-right: 16px; }
    main h1 { font-size: 25px; }
    .entry { grid-template-columns: minmax(0, 1fr); }
    .stages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stage:nth-child(3) { border-left: 0; }
    .stage:nth-child(n+3) { border-top: 1px solid var(--border); }
    .step summary { grid-template-columns: 26px minmax(0, 1fr) 16px; }
    .tags { grid-column: 2; grid-row: 2; justify-content: flex-start; }
    .st-sum { grid-column: 2; grid-row: 3; }
    .chev { grid-column: 3; grid-row: 1; }
    .detail { padding-left: 16px; }
}
@media (prefers-reduced-motion: reduce) { .chev, .cap summary::after { transition: none; } }
.intro ul { margin: 0 0 8px; padding-left: 18px; }
.intro li { margin-bottom: 4px; }
.intro .table-wrap { margin: 6px 0 10px; }
