/* DiffusionGemma-Lite documentation — "printed reader" design system.
   ---------------------------------------------------------------------
   These pages are read, not operated, and a full document here runs
   100 minutes. So the page is set like a textbook: cool white paper,
   blue-black printing ink, and a single reading face.

     • Literata sets headings and prose. It was drawn for long text on
       screen, which is exactly the job.
     • IBM Plex Mono is reserved for code, identifiers and measured
       values. It is never used for prose — mono as a costume for
       "technical" is the trap this design removes.

     • Three low-chroma marks, one job each:
         accent     the current thing — active nav, links, focus
         structure  quiet structural stamps — coords, keys, tags
         mark       the third categorical mark, for card families

     • No theme switch. This file is the single source of truth;
       `scripts/build_docs_html.py` copies it into
       `docs_html/assets/style.css` during the build. */



/* =====================================================================
   1. TOKENS
   ===================================================================== */

:root {
    /* Cool paper, three planes deep. A reading surface, so the ink is
       blue-black printing ink and every plane stays near-neutral. */
    --paper:         #FBFBFA;     /* page */
    --paper-2:       #F4F5F5;     /* card / sidebar plane */
    --paper-3:       #ECEEEE;     /* raised plane */
    --ink:           #16191D;     /* blue-black text ink */
    --ink-soft:      #4B5359;
    --ink-faint:     #78818A;

    /* Hairlines. Structure, never texture. */
    --rule:          #E4E7E8;     /* hairline */
    --rule-strong:   #D2D7D9;     /* the structural rule */
    --rule-fine:     #EDEFF0;     /* nested structure */
    --rule-fade:     rgba(210, 215, 217, 0.55);

    /* Three marks, low chroma, one job each. */
    --accent:         #1F4A73;    /* the current thing */
    --accent-tint:    rgba(31, 74, 115, 0.07);
    --accent-glow:    rgba(31, 74, 115, 0.18);
    --structure:      #5C6B5F;    /* quiet structural stamps */
    --structure-tint: rgba(92, 107, 95, 0.10);
    --mark:           #8A6A2E;    /* third categorical mark */

    /* Math/code surface — sunk one plane below the body paper. */
    --code-paper:    #F3F5F5;
    --code-rule:     #E1E5E6;

    /* Status callouts */
    --callout-note-bg:    rgba(138, 106, 46, 0.05);
    --callout-note-rule:  #8A6A2E;
    --callout-tip-bg:     rgba(31, 74, 115, 0.05);
    --callout-tip-rule:   #1F4A73;
    --callout-warn-bg:    rgba(150, 52, 52, 0.05);
    --callout-warn-rule:  #963434;

    /* Ink tints — hover, chips, table rows. One hue, four strengths. */
    --tint-ink-03:    rgba(22, 25, 29, 0.030);
    --tint-ink-05:    rgba(22, 25, 29, 0.048);
    --tint-ink-08:    rgba(22, 25, 29, 0.075);
    --tint-accent-06: rgba(31, 74, 115, 0.06);
    --tint-accent-14: rgba(31, 74, 115, 0.12);

    /* Inset paper — the recessed plane for figures, spec cells and code. */
    --paper-inset:    #F1F3F3;

    /* Depth. Soft and low-contrast: this surface is paper, not glass. */
    --shadow-1:  0 1px 2px rgba(22, 25, 29, 0.05);
    --shadow-2:  0 2px 8px rgba(22, 25, 29, 0.06);
    --shadow-3:  0 6px 20px rgba(22, 25, 29, 0.09);

    /* Motion: one consistent timing voice. Slow enough to feel deliberate,
       fast enough not to drag. */
    --t-fast:    140ms;
    --t-base:    200ms;
    --ease:      cubic-bezier(0.4, 0, 0.2, 1);

    /* Focus ring — explicit, never rely on the UA default. */
    --focus-ring:    0 0 0 2px var(--paper), 0 0 0 4px var(--accent);

    /* Type families. Literata sets prose; mono is for code and data only. */
    --font-mono:     'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --font-prose:    'Literata', Georgia, 'Iowan Old Style', serif;

    /* Reading measure — about 68 characters of Literata at 17px. */
    --measure:       41rem;

    /* Mono features shared by every label/number/coord role: tabular figures
       so columns line up, slashed zero so "0" doesn't read as "O". */
    --mono-feats: "tnum" 1, "zero" 1, "ss01" 1;
}



/* =====================================================================
   2. RESET
   ===================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background-color: var(--paper);
    color: var(--ink);
    font-family: var(--font-prose);
    font-size: 16px;
    line-height: 1.62;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "kern", "liga", "onum", "calt";
    text-rendering: optimizeLegibility;
}

/* Themed scrollbar — a UA scrollbar in its own greys breaks the page. */
* { scrollbar-width: thin; scrollbar-color: var(--rule-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: var(--rule-fade);
    border: 3px solid var(--paper);
    border-radius: 0;
}
*::-webkit-scrollbar-thumb:hover { background: var(--rule-strong); }

.site-header, .app-layout, .hero-banner, .toc-sidebar, .sidebar {
    position: relative;
    z-index: 2;
}

/* Boot overlay — a 350ms "loading weights" plate that fades on
   DOMContentLoaded. Respects prefers-reduced-motion (drops straight to
   invisible). Lives on every page so reloads feel coherent. */
#boot-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--paper);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    color: var(--ink);
    transition: opacity var(--t-fast) var(--ease), visibility var(--t-fast) var(--ease);
}
.boot-inner { text-align: center; }
.boot-wordmark {
    font-family: var(--font-prose);
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--ink);
    margin-bottom: 0.5rem;
}
.boot-line {
    font-family: var(--font-prose);
    font-size: 0.85rem;
    color: var(--ink-faint);
}
.boot-bar { color: var(--accent); font-weight: 600; }
.boot-fading { opacity: 0; pointer-events: none; }



/* =====================================================================
   3. TYPE
   ===================================================================== */

/* Data voice. Mono marks a machine token or a measured value — code,
   identifiers, coordinates, numbers — and nothing else. */
.hero-coords, .ascii-hero, .portal-section-mark, .portal-section-meta,
.card-tag, .card-label, .doc-meta, .meta-item,
.code-header, .code-lang, .copy-btn, .code-wrapper pre,
.inline-code, .math-block,
.spec-sheet-rule, .spec-key, .spec-val, .spec-val .unit,
.callout-header, .brand-badge, .sidebar-search input,
.fig-badge, .fig-btn, .fig-dim, .hud-corner, .probe-card,
.pass-badge, .pass-btn, .pass-hud-chip, .st-card,
.tc-badge, .tc-val, .msb-row, .mch-tag, .mch-stat-box,
.chunk-badge, .chunk-pipeline-box, .mimo-cell,
.breadcrumb, .toc-empty {
    font-family: var(--font-mono);
}

/* Reading voice. Everything a person reads as language. */
.brand-name, .doc-title, .hero-title,
.portal-section-title, .card-heading, .card-title,
.nav-group-title, .nav-link, .toc-title, .toc-link,
.heading-anchor, .hero-subtitle, .callout-title,
.header-link, .mobile-toggle, .doc-footer-nav, .mch-action-btn,
.card-desc, .card-body, .tc-desc, .mch-title, .mch-explainer,
.markdown-body p, .markdown-body li, .markdown-body blockquote {
    font-family: var(--font-prose);
}

p { margin: 0 0 1.1em 0; }

a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    text-decoration-color: var(--rule-strong);
    transition: color var(--t-fast) var(--ease), text-decoration-color var(--t-fast) var(--ease);
}
a:hover { color: var(--ink); text-decoration-color: var(--accent); }

::selection { background: var(--tint-accent-14); color: var(--ink); }

/* Global focus ring — never rely on the UA default. */
:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: 1px;
}
/* The nav links already have their own border-left; keep the ring on the
   outer edge so the active tick stays the dominant affordance. */
.nav-link:focus-visible,
.toc-link:focus-visible,
.header-link:focus-visible,
.mobile-toggle:focus-visible,
.copy-btn:focus-visible {
    box-shadow: 0 0 0 2px var(--paper), 0 0 0 3px var(--accent);
}

/* Visually hidden, but available to screen readers and search engines. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}



/* =====================================================================
   4. HEADER CHROME
   ===================================================================== */

.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7rem 1.6rem;
    background: var(--paper);
    border-bottom: 1px solid var(--rule);
    box-shadow: var(--shadow-1);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.2rem;
}

.brand-logo {
    display: flex;
    align-items: baseline;
    gap: 0.7rem;
    text-decoration: none;
    color: var(--ink);
    position: relative;
}
.brand-name {
    font-family: var(--font-prose);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.012em;
}

.brand-badge {
    font-size: 0.66rem;
    padding: 2px 8px;
    border: 1px solid var(--rule);
    color: var(--ink-faint);
    font-weight: 400;
    border-radius: 2px;
    background: transparent;
    position: relative;
    top: -1px;
}

.header-right { display: flex; align-items: center; gap: 1.1rem; }

.header-link {
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 0.86rem;
    font-weight: 400;
    padding: 4px 2px;
    border-bottom: 1px solid transparent;
    transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.header-link:hover { color: var(--accent); border-bottom-color: var(--accent); }

.mobile-toggle {
    background: transparent;
    border: 1px solid var(--rule-strong);
    color: var(--ink-soft);
    padding: 5px 11px;
    border-radius: 2px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 400;
    font-family: var(--font-prose);
    transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.mobile-toggle:hover {
    color: var(--ink);
    border-color: var(--accent);
    background: var(--tint-ink-05);
}

.mobile-toggle { display: none; }



/* =====================================================================
   5. APP LAYOUT
   ===================================================================== */

.app-layout {
    display: grid;
    grid-template-columns: 264px minmax(0, 1fr) 232px;
    max-width: 1560px;
    margin: 0 auto;
    min-height: calc(100vh - 50px);
}

.index-portal .app-layout,
.app-layout:not(:has(.toc-sidebar)) {
    grid-template-columns: 264px minmax(0, 1fr);
    max-width: 1560px;
    margin: 0 auto;
}

.index-portal .content-container {
    max-width: 860px;
    margin: 0 auto;
    width: 100%;
}

.index-portal .main-content {
    padding: 2.5rem 3rem 4rem;
}

.sidebar {
    border-right: 1px solid var(--rule);
    background: var(--paper-2);
    position: sticky;
    top: 50px;
    height: calc(100vh - 50px);
    overflow-y: auto;
}

.sidebar-inner { padding: 1.3rem 1.1rem; }

.sidebar-search {
    position: relative;
    margin-bottom: 1.5rem;
}
.sidebar-search::before {
    /* magnifier glyph drawn in CSS so we don't need an icon font */
    content: "";
    position: absolute;
    left: 10px;
    top: 50%;
    width: 8px;
    height: 8px;
    border: 1.4px solid var(--ink-faint);
    border-radius: 50%;
    transform: translateY(-65%) translateX(0);
    pointer-events: none;
    opacity: 0.7;
}
.sidebar-search::after {
    content: "";
    position: absolute;
    left: 17px;
    top: 50%;
    width: 4px;
    height: 1.4px;
    background: var(--ink-faint);
    transform: translateY(2px) rotate(45deg);
    transform-origin: left center;
    pointer-events: none;
    opacity: 0.7;
}
.sidebar-search input {
    width: 100%;
    padding: 7px 11px 7px 28px;
    background: var(--paper);
    border: 1px solid var(--rule-strong);
    border-radius: 0;
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-feature-settings: var(--mono-feats);
    outline: none;
    transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.sidebar-search input:focus { border-color: var(--mark); background: var(--paper-inset); }
.sidebar-search input::placeholder { color: var(--ink-faint); }

.nav-group { margin-bottom: 1.6rem; }

.nav-group-title {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ink-soft);
    margin-bottom: 0.5rem;
    padding: 0 0 0 10px;
}

.nav-list { list-style: none; margin: 0; padding: 0; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 5px 8px 5px 9px;
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 0.86rem;
    font-weight: 400;
    line-height: 1.4;
    border-left: 1px solid transparent;
    transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
    min-width: 0;
}
.nav-link-text {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nav-link:hover { color: var(--ink); background: var(--tint-ink-05); }

.nav-link.active {
    color: var(--ink);
    border-left-color: var(--accent);
    background: var(--tint-accent-06);
    font-weight: 500;
}

.toc-sidebar {
    border-left: 1px solid var(--rule);
    background: var(--paper-2);
    padding: 1.4rem 1rem 1.5rem;
    position: sticky;
    top: 50px;
    height: calc(100vh - 50px);
    overflow-y: auto;
}
.toc-inner { position: relative; }
.toc-title {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ink-soft);
    margin-bottom: 0.7rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--rule);
}
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list li { margin-bottom: 1px; }
.toc-link {
    color: var(--ink-faint);
    text-decoration: none;
    font-size: 0.82rem;
    line-height: 1.45;
    display: block;
    padding: 3px 0 3px 9px;
    border-left: 1px solid transparent;
    transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.toc-link:hover { color: var(--ink); background: var(--tint-ink-05); }
.toc-link.active {
    color: var(--ink);
    border-left-color: var(--accent);
    background: var(--tint-accent-06);
    font-weight: 500;
}
.toc-h3 { padding-left: 0.9rem; }
.toc-h3 .toc-link { color: var(--ink-faint); font-size: 0.79rem; }
.toc-h3 .toc-link.active { color: var(--ink); }
.toc-empty {
    font-family: var(--font-prose);
    font-size: 0.82rem;
    color: var(--ink-faint);
    font-style: italic;
    padding: 0.4rem 0 0.2rem;
}

.main-content {
    padding: 2.75rem 3rem 4rem;
    overflow-x: hidden;
    background: var(--paper);
}

.content-container {
    max-width: var(--measure);
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.breadcrumb {
    font-family: var(--font-prose);
    font-size: 0.8rem;
    color: var(--ink-faint);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0;
}
.breadcrumb a {
    color: var(--ink-faint);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.breadcrumb a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.breadcrumb .current { color: var(--ink); font-weight: 500; }
.breadcrumb span + span::before {
    content: "›";
    margin: 0 0.45rem;
    color: var(--ink-faint);
    font-weight: 400;
}



/* =====================================================================
   6. DOC TITLE BLOCK
   ===================================================================== */

.doc-header {
    padding: 0 0 1.5rem;
    margin-bottom: 2.5rem;
    border-bottom: 1px solid var(--rule);
}

.doc-title {
    font-size: 2.4rem;
    font-weight: 600;
    line-height: 1.16;
    letter-spacing: -0.02em;
    margin: 0 0 0.9rem;
    color: var(--ink);
    text-wrap: balance;
}

.doc-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 1.4rem;
    font-family: var(--font-prose);
    font-size: 0.8rem;
    color: var(--ink-faint);
}
.doc-meta .meta-item {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 3px 9px 3px 0;
}
.doc-meta .meta-mark {
    color: var(--structure);
    font-weight: 600;
    font-size: 0.78rem;
}
.doc-meta .meta-item:last-child { border-right: none; padding-right: 0; }
.doc-meta .meta-label { color: var(--ink-faint); opacity: 0.75; }
.doc-meta .meta-val { color: var(--ink-soft); font-weight: 500; }

.doc-anchor { display: block; height: 0; scroll-margin-top: 80px; }



/* =====================================================================
   7. HERO (INDEX ONLY)
   ===================================================================== */

.hero-banner {
    padding: 0 0 2.2rem;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--rule);
    margin-bottom: 2.4rem;
}

.hero-title {
    font-size: 3rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.08;
    margin: 0 0 1rem;
    color: var(--ink);
}

.hero-subtitle {
    font-size: 1.12rem;
    color: var(--ink-soft);
    line-height: 1.62;
    max-width: var(--measure);
    margin: 0 0 2rem;
}

/* ----- FIG. A0 — Complex State-Space Dynamics (Precision Instrument) - */
.hero-figure {
    margin: 0.8rem 0 1.8rem;
    border: 1px solid var(--rule);
    background: var(--paper);
    position: relative;
    box-shadow: var(--shadow-2);
}

.hero-figure-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 0.9rem;
    background: var(--paper-2);
    border-bottom: 1px solid var(--rule);
}


.fig-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.fig-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--structure);
    animation: figDotPulse 2.4s infinite ease-in-out;
}

@keyframes figDotPulse {
    0%, 100% { opacity: 0.35; }
    50% { opacity: 1; }
}

.fig-tag {
    color: var(--structure);
    font-weight: 700;
}

.fig-sep {
    color: var(--ink-faint);
    opacity: 0.5;
}

.fig-title {
    color: var(--ink);
    font-weight: 600;
}

.fig-dim {
    color: var(--ink-faint);
    font-size: 0.6rem;
    letter-spacing: 0.08em;
}

.fig-controls {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.fig-btn {
    background: var(--paper-3);
    border: 1px solid var(--rule);
    color: var(--ink-soft);
    font-family: var(--font-mono);
    font-size: 0.58rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    padding: 0.22rem 0.55rem;
    border-radius: 2px;
    cursor: pointer;
    transition: all var(--t-fast) var(--ease);
    user-select: none;
}

.fig-btn:hover {
    background: var(--tint-accent-06);
    color: var(--ink);
    border-color: var(--mark);
}

.fig-btn.active {
    background: var(--tint-accent-14);
    color: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 8px var(--accent-tint);
}

.fig-btn-icon {
    padding: 0.22rem 0.45rem;
    font-size: 0.52rem;
}

/* Canvas Container & Viewport */
.fig-canvas-wrap {
    position: relative;
    width: 100%;
    height: 360px;
    background: var(--paper-inset);
    overflow: hidden;
    cursor: crosshair;
}
.hero-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Corner HUD Telemetry Overlay */
.fig-overlay-hud {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.hud-corner {
    position: absolute;
    padding: 0.45rem 0.7rem;
    background: var(--paper);
    border: 1px solid var(--rule);
    font-family: var(--font-mono);
    line-height: 1.35;
    border-radius: 2px;
}

.hud-corner.top-left { top: 8px; left: 8px; }
.hud-corner.top-right { top: 8px; right: 8px; text-align: right; }
.hud-corner.bottom-left { bottom: 8px; left: 8px; }
.hud-corner.bottom-right { bottom: 8px; right: 8px; text-align: right; }

.hud-lbl {
    display: block;
    color: var(--ink-soft);
    font-size: 0.60rem;
    font-weight: 600;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.hud-val {
    display: block;
    color: var(--ink);
    font-size: 0.72rem;
    font-weight: 600;
    font-feature-settings: var(--mono-feats);
}

.hud-val .num {
    color: var(--accent);
    font-weight: 700;
}

/* Floating Probe Inspection Card */
.hud-probe {
    position: absolute;
    pointer-events: none;
    transition: opacity 0.12s ease;
    z-index: 10;
}

.probe-card {
    background: var(--paper);
    border: 1px solid var(--mark);
    box-shadow: var(--shadow-2);
    padding: 0.45rem 0.75rem;
    border-radius: 2px;
    font-family: var(--font-mono);
    line-height: 1.35;
    white-space: nowrap;
}

.probe-tag {
    display: block;
    color: var(--mark);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.probe-val {
    display: block;
    color: var(--ink);
    font-size: 0.72rem;
    font-weight: 600;
    font-feature-settings: var(--mono-feats);
}

.probe-sub {
    display: block;
    color: var(--structure);
    font-size: 0.64rem;
    margin-top: 2px;
    letter-spacing: 0.04em;
}
/* Footer: Formula & Legend */
.hero-figure-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    padding: 0.48rem 0.9rem;
    background: var(--paper-2);
    border-top: 1px solid var(--rule);
    font-family: var(--font-mono);
    font-size: 0.70rem;
}

.fig-formula {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--ink);
    letter-spacing: 0.04em;
    font-size: 0.74rem;
}

.fig-formula .formula-sym { color: var(--ink); font-weight: 600; }
.fig-formula .formula-op { color: var(--ink-faint); margin: 0 0.1rem; }
.fig-formula .formula-term { color: var(--mark); font-weight: 500; }
.fig-formula .term-a { color: var(--structure); font-weight: 600; }
.fig-formula .term-b { color: var(--accent); font-weight: 600; }
.fig-formula .formula-dot { color: var(--ink-faint); }
.fig-formula .f-sub, .fig-legend .f-sub {
    font-size: 0.58rem;
    vertical-align: sub;
    color: var(--ink-soft);
    font-feature-settings: var(--mono-feats);
}
.fig-legend {
    display: inline-flex;
    align-items: center;
    gap: 0.85rem;
    flex-wrap: wrap;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--ink-soft);
    font-size: 0.65rem;
}

.legend-swatch {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.legend-swatch.olive {
    background: var(--structure);
    box-shadow: 0 0 5px var(--structure);
}

.legend-swatch.terra {
    background: var(--accent);
}

.legend-swatch.core {
    background: var(--ink);
}

.legend-hint {
    color: var(--ink-faint);
    font-size: 0.52rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
/* ----- FIG. A1 — Full Training Step Pipeline (Precision Instrument) --- */
.pass-widget {
    margin-top: 1.8rem;
    border: 1px solid var(--rule-strong);
    background: var(--paper-inset);
    position: relative;
    box-shadow: var(--shadow-2);
}

.pass-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.6rem 1rem;
    padding: 0.55rem 0.9rem;
    background: var(--paper-2);
    border-bottom: 1px solid var(--rule);
}

.pass-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.pass-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
    animation: passDotPulse 2.4s infinite ease-in-out;
}

@keyframes passDotPulse {
    0%, 100% { opacity: 0.4; transform: scale(0.9); }
    50% { opacity: 1.0; transform: scale(1.15); filter: drop-shadow(0 0 3px var(--accent)); }
}

.pass-tag {
    color: var(--accent);
    font-weight: 700;
}

.pass-sep {
    color: var(--ink-faint);
    opacity: 0.5;
}

.pass-title {
    color: var(--ink);
    font-weight: 600;
}

.pass-dim {
    color: var(--ink-faint);
    font-size: 0.6rem;
    letter-spacing: 0.08em;
}

.pass-controls {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.pass-btn {
    background: var(--paper-3);
    border: 1px solid var(--rule);
    color: var(--ink-soft);
    font-family: var(--font-mono);
    font-size: 0.58rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    padding: 0.22rem 0.55rem;
    border-radius: 2px;
    cursor: pointer;
    transition: all var(--t-fast) var(--ease);
    user-select: none;
}

.pass-btn:hover {
    background: var(--tint-accent-06);
    color: var(--ink);
    border-color: var(--mark);
}

.pass-btn.active {
    background: var(--tint-accent-14);
    color: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 8px var(--accent-tint);
}

.pass-btn-icon {
    padding: 0.22rem 0.45rem;
    font-size: 0.52rem;
}

/* Canvas Container */
.pass-canvas-wrap {
    position: relative;
    width: 100%;
    height: 270px;
    background: var(--paper-inset);
    overflow: hidden;
    cursor: crosshair;
}
.pass-canvas {
    display: block;
    width: 100%;
    height: 100%;
}
/* HUD Overlay */
.pass-overlay-hud {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.pass-hud-chip {
    position: absolute;
    padding: 0.45rem 0.7rem;
    background: var(--paper);
    border: 1px solid var(--rule);
    font-family: var(--font-mono);
    line-height: 1.35;
    border-radius: 2px;
}

.pass-hud-chip.top-left { top: 8px; left: 8px; }
.pass-hud-chip.top-right { top: 8px; right: 8px; text-align: right; }

.ph-lbl {
    display: block;
    color: var(--ink-soft);
    font-size: 0.60rem;
    font-weight: 600;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.ph-val {
    display: block;
    color: var(--ink);
    font-size: 0.72rem;
    font-weight: 600;
    font-feature-settings: var(--mono-feats);
}

/* Stage Tooltip */
.pass-stage-tooltip {
    position: absolute;
    pointer-events: none;
    transition: opacity 0.12s ease;
    z-index: 10;
}

.st-card {
    background: var(--paper);
    border: 1px solid var(--mark);
    box-shadow: var(--shadow-3);
    padding: 0.6rem 0.95rem;
    border-radius: 2px;
    font-family: var(--font-mono);
    line-height: 1.35;
    white-space: nowrap;
}

.st-tag {
    display: block;
    color: var(--mark);
    font-size: 0.70rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.st-op {
    display: block;
    color: var(--ink);
    font-size: 0.78rem;
    font-weight: 600;
    font-feature-settings: var(--mono-feats);
    text-shadow: none;
}

.st-shape {
    display: block;
    color: var(--accent);
    font-size: 0.68rem;
    font-weight: 600;
    margin-top: 3px;
}

.st-desc {
    display: block;
    color: var(--structure);
    font-size: 0.62rem;
    margin-top: 2px;
    letter-spacing: 0.02em;
}
/* Footer: Ticker & Legend */
.pass-widget-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    padding: 0.48rem 0.9rem;
    background: var(--paper-2);
    border-top: 1px solid var(--rule);
    font-family: var(--font-mono);
    font-size: 0.70rem;
}

.pass-status-ticker {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--ink);
    letter-spacing: 0.04em;
    font-size: 0.68rem;
}

.ticker-beacon {
    color: var(--accent);
    font-size: 1.1em;
}

.ticker-text {
    color: var(--ink);
    font-weight: 500;
}

.pass-legend {
    display: inline-flex;
    align-items: center;
    gap: 0.85rem;
    flex-wrap: wrap;
}

.legend-swatch.gold {
    background: var(--mark);
    box-shadow: 0 0 5px var(--mark);
}
/* ----- The datasheet / spec sheet ------------------------------------- */
.spec-sheet { margin-top: 0; }
.spec-sheet-rule {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 1px solid var(--rule);
    padding-bottom: 0.5rem;
    margin-bottom: 0.9rem;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    position: relative;
    font-feature-settings: var(--mono-feats);
}
.spec-sheet-rule::before {
    /* a small terracotta tick at the left end of the rule — marks the
       sheet as "checked" in the same printer's-tick language as the
       nav active state. */
    content: "✓";
    color: var(--accent);
    margin-right: 0.5rem;
    font-weight: 600;
}
.spec-rule-key { color: var(--structure); font-weight: 600; }
.spec-rule-meta { color: var(--ink-faint); font-size: 0.64rem; font-weight: 400; }

.spec-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border: 1px solid var(--rule-strong);
    border-radius: 0;
    margin: 0;
    background: var(--rule-strong);
    /* the gap is the rule color, so the cells appear to share hairlines. */
    gap: 1px;
}


.spec-cell {
    padding: 0.9rem 1rem 1rem;
    margin: 0;
    background: var(--paper);
    position: relative;
    transition: background var(--t-base) var(--ease);
}
.spec-cell:hover { background: var(--paper-inset); }
.spec-cell::before {
    /* a small olive tick in the upper-left of every cell — the
       "checked-off" stamp, scaled down. */
    content: "·";
    position: absolute;
    top: 4px;
    left: 5px;
    color: var(--structure);
    font-family: var(--font-mono);
    font-size: 0.85em;
    opacity: 0;
    transition: opacity var(--t-fast) var(--ease);
}
.spec-cell:hover::before { opacity: 0.6; }

.spec-key {
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--ink-faint);
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-feature-settings: var(--mono-feats);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.spec-val {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.01em;
    font-feature-settings: var(--mono-feats);
    display: flex;
    align-items: baseline;
    gap: 2px;
}
.spec-val .unit { color: var(--ink-faint); font-size: 0.75em; font-weight: 400; margin-left: 2px; letter-spacing: 0; }



/* =====================================================================
   8. PORTAL — section grids (index only)
   ===================================================================== */

.portal-section { margin-bottom: 3.5rem; }

.portal-section-head {
    display: flex;
    align-items: baseline;
    gap: 0.9rem;
    border-bottom: 1px solid var(--rule-strong);
    padding-bottom: 0.6rem;
    margin-bottom: 1.4rem;
    position: relative;
}
.portal-section-head {
    display: flex;
    align-items: baseline;
    gap: 0.9rem;
    border-bottom: 1px solid var(--rule);
    padding-bottom: 0.55rem;
    margin-bottom: 1.5rem;
}

.portal-section-mark {
    font-size: 0.68rem;
    font-weight: 400;
    color: var(--ink-faint);
}

.portal-section-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.014em;
    margin: 0;
}

.portal-section-meta {
    margin-left: auto;
    font-size: 0.72rem;
    color: var(--ink-faint);
}

.portal-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1px;
    background: var(--rule-strong);
    border: 1px solid var(--rule-strong);
}

/* Eliminate blank space blocks: odd trailing cards span full width */
.portal-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
}

.portal-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 1.5rem 1.4rem;
    background: var(--paper);
    text-decoration: none;
    color: var(--ink);
    transition: background var(--t-base) var(--ease);
    border: 1px solid transparent;
}
.portal-card:hover { background: var(--paper-2); border-color: var(--rule); }
.portal-card:focus-visible { outline: none; box-shadow: var(--focus-ring); outline-offset: -1px; }

.card-heading {
    font-family: var(--font-prose);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--ink);
    margin: 0 0 4px 0;
    letter-spacing: -0.014em;
    line-height: 1.3;
    transition: color var(--t-fast) var(--ease);
}
.portal-card:hover .card-heading { color: var(--accent); }

.card-desc {
    font-size: 0.9rem;
    color: var(--ink-soft);
    line-height: 1.55;
    margin: 0;
}



/* =====================================================================
   9. PROSE — markdown body
   ===================================================================== */

.markdown-body { font-size: 1.06rem; }
.markdown-body > *:first-child { margin-top: 0; }

/* Headings carry their own weight: more space above than below, and a
   step down in size that tracks the step in the outline. */
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 {
    font-family: var(--font-prose);
    color: var(--ink);
    font-weight: 600;
    line-height: 1.24;
    margin-top: 2.6rem;
    margin-bottom: 0.7rem;
    scroll-margin-top: 80px;
    text-wrap: balance;
}

.markdown-body h2 {
    font-size: 1.5rem;
    letter-spacing: -0.015em;
    padding-bottom: 0.45rem;
    border-bottom: 1px solid var(--rule);
    margin-top: 3rem;
}
.markdown-body h3 {
    font-size: 1.16rem;
    letter-spacing: -0.008em;
}
.markdown-body h4 {
    font-size: 1rem;
    color: var(--ink);
}

.heading-anchor .anchor-link {
    opacity: 0;
    margin-left: 0.4rem;
    color: var(--ink-faint);
    text-decoration: none;
    font-weight: 400;
    transition: opacity var(--t-base) var(--ease), color var(--t-base) var(--ease);
    font-size: 0.78em;
    padding: 0 4px;
    border: 1px solid transparent;
    border-radius: 0;
}
.heading-anchor:hover .anchor-link { opacity: 1; }
.heading-anchor .anchor-link:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.markdown-body p {
    margin: 0 0 1.1rem;
    color: var(--ink);
    line-height: 1.68;
    hyphens: auto;
    text-wrap: pretty;
}
.markdown-body ul, .markdown-body ol {
    padding-left: 1.5rem;
    margin: 0 0 1.25rem;
}
.markdown-body li {
    margin-bottom: 0.42rem;
    line-height: 1.62;
    padding-left: 0.15rem;
}
.markdown-body li::marker {
    color: var(--mark);
    font-family: var(--font-mono);
    font-feature-settings: var(--mono-feats);
}
.markdown-body li > p { margin-bottom: 0.4rem; }

.markdown-body strong { color: var(--ink); font-weight: 600; }
.markdown-body em { font-style: italic; color: var(--ink); }

.inline-code {
    background: var(--code-paper);
    border: 1px solid var(--code-rule);
    padding: 1px 5px;
    font-size: 0.86em;
    color: var(--ink);
    border-radius: 2px;
    font-family: var(--font-mono);
    font-feature-settings: var(--mono-feats);
    transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.markdown-body .inline-code:hover { border-color: var(--rule-strong); }

.doc-link {
    color: var(--mark);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    text-decoration-color: var(--rule);
    transition: color var(--t-fast) var(--ease), text-decoration-color var(--t-fast) var(--ease);
}
.doc-link:hover { color: var(--accent); text-decoration-color: var(--accent); }

.doc-hr {
    border: none;
    border-top: 1px solid var(--rule);
    margin: 2.5rem auto;
    width: 30%;
}

blockquote {
    border-left: 1px solid var(--rule-strong);
    padding: 0.2rem 0 0.2rem 1.15rem;
    margin: 1.6rem 0;
    color: var(--ink-soft);
    font-style: italic;
    background: transparent;
    font-size: 1.02rem;
    line-height: 1.62;
}
blockquote p:last-child { margin-bottom: 0; }

/* Code blocks */
.code-wrapper {
    background: var(--code-paper);
    border: 1px solid var(--code-rule);
    border-radius: 0;
    margin: 1.5rem 0;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 0 0 1px var(--tint-ink-05);
}
.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 14px 6px 12px;
    background: var(--paper-2);
    border-bottom: 1px solid var(--code-rule);
    font-size: 0.7rem;
    color: var(--ink-faint);
    position: relative;
}
.code-lang {
    font-weight: 500;
    color: var(--ink-soft);
    background: transparent;
    border: none;
    padding: 0;
    font-size: 0.68rem;
}
.copy-btn {
    background: transparent;
    border: 1px solid var(--code-rule);
    color: var(--ink-soft);
    padding: 3px 10px;
    border-radius: 2px;
    cursor: pointer;
    font-size: 0.72rem;
    font-family: var(--font-prose);
    font-weight: 400;
    transition: border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.copy-btn:hover, .expand-btn:hover { border-color: var(--accent); color: var(--ink); background: var(--tint-ink-05); }
.copy-btn.copied { border-color: var(--accent); color: var(--accent); background: var(--tint-accent-06); }

/* Long-block collapse: a faded cutoff with an expand affordance. */
.code-actions { display: inline-flex; align-items: center; gap: 6px; }
.expand-btn {
    background: transparent;
    border: 1px solid var(--code-rule);
    color: var(--ink-soft);
    padding: 3px 10px;
    border-radius: 2px;
    cursor: pointer;
    font-size: 0.72rem;
    font-family: var(--font-prose);
    font-weight: 400;
    transition: border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.code-wrapper.collapsed pre {
    max-height: 15.5em;
    overflow: hidden;
}
.code-wrapper.collapsed::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4.5em;
    background: linear-gradient(to bottom, transparent, var(--code-paper));
    pointer-events: none;
}
.code-wrapper pre {
    margin: 0;
    padding: 0.95rem 1.1rem 1rem;
    overflow-x: auto;
    font-size: 0.82rem;
    line-height: 1.6;
    background: var(--code-paper);
}
.code-wrapper pre code { font-family: var(--font-mono); }
.code-wrapper pre code .line {
    display: inline-block;
    width: 100%;
}

/* KaTeX display blocks */
.math-block {
    overflow-x: auto;
    margin: 1.6rem 0;
    padding: 1.3rem 1rem 1.2rem;
    background: var(--paper-2);
    border: 1px solid var(--rule);
    text-align: center;
    font-family: var(--font-prose);
}
.math-inline { font-size: 1.02em; }

/* Tables */
.table-container {
    overflow-x: auto;
    margin: 1.5rem 0;
    border: 1px solid var(--rule);
    border-radius: 0;
    background: var(--paper);
}
.doc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    font-family: var(--font-prose);
    font-variant-numeric: tabular-nums;
    text-align: left;
    background: var(--paper);
}
.doc-table thead { border-bottom: 1px solid var(--rule-strong); }
.doc-table th {
    background: var(--paper-2);
    padding: 9px 14px;
    font-weight: 600;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--rule);
    color: var(--ink-soft);
}
.doc-table td {
    padding: 9px 14px;
    border-bottom: 1px solid var(--rule-fine);
    color: var(--ink);
    transition: background var(--t-fast) var(--ease);
    vertical-align: top;
}
.doc-table tbody tr:last-child td { border-bottom: none; }
.doc-table tbody tr { transition: background var(--t-fast) var(--ease); }
.doc-table tbody tr:hover td { background: var(--tint-ink-03); }

/* Callouts */
.callout {
    padding: 1rem 1.2rem;
    border: 1px solid var(--rule);
    border-left: 1px solid;
    border-radius: 2px;
    margin: 1.7rem 0;
    background: var(--paper-2);
}
.callout-note { background: var(--callout-note-bg); border-color: var(--callout-note-rule); }
.callout-tip  { background: var(--callout-tip-bg);  border-color: var(--callout-tip-rule); }
.callout-warn, .callout-warning { background: var(--callout-warn-bg); border-color: var(--callout-warn-rule); }
.callout-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 0.45rem;
    color: var(--ink);
}
.callout-icon { display: none; }
.callout-body {
    font-family: var(--font-prose);
    color: var(--ink-soft);
    line-height: 1.6;
    font-size: 0.98rem;
}
.callout-body strong { color: var(--ink); }
.callout-body p:last-child { margin-bottom: 0; }
.callout-body p:first-child { margin-top: 0; }



/* =====================================================================
   10. FOOTER NAV
   ===================================================================== */

.doc-footer-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--rule-strong);
    border: 1px solid var(--rule-strong);
    margin-top: 4rem;
    position: relative;
}
.nav-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 1.05rem 1.2rem;
    background: var(--paper);
    text-decoration: none;
    color: var(--ink);
    transition: background var(--t-fast) var(--ease);
    position: relative;
    border-left: 2px solid transparent;
    border-right: 2px solid transparent;
}
.nav-card:hover { background: var(--paper-2); border-color: var(--rule-strong); }
.nav-card:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }
.nav-card.next-card { text-align: right; align-items: flex-end; }

.card-label {
    font-size: 0.72rem;
    color: var(--ink-faint);
    font-weight: 400;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.prev-card .card-label::before { content: "←"; color: var(--accent); font-size: 0.9em; }
.next-card .card-label::after { content: "→"; color: var(--accent); font-size: 0.9em; }
.card-title {
    font-size: 0.92rem;
    color: var(--ink);
    font-weight: 600;
    letter-spacing: -0.003em;
    transition: color var(--t-fast) var(--ease);
}
.nav-card:hover .card-title { color: var(--accent); }



/* =====================================================================
   MAMBA-3 ARCHITECTURAL TELEMETRY RIBBON & MECHANISM EXPLODER SUITE
   ===================================================================== */

/* Live Telemetry Ribbon */
.mamba-telemetry-ribbon {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--rule-strong);
    border: 1px solid var(--rule-strong);
    margin: 1.4rem 0 1.8rem;
}

.telemetry-card {
    background: var(--paper-2);
    padding: 1rem 1.1rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 5px;
    position: relative;
    overflow: hidden;
    min-height: 5.5rem;
}

.telemetry-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--rule);
}

.telemetry-card::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 24px;
    background: linear-gradient(to top, var(--tint-ink-03), transparent);
    pointer-events: none;
}

.telemetry-card.terra::before { background: var(--accent); }
.telemetry-card.olive::before { background: var(--structure); }
.telemetry-card.gold::before { background: var(--mark); }
.telemetry-card.ink::before { background: var(--ink-soft); }

.tc-badge {
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--ink-faint);
    display: flex;
    align-items: center;
    gap: 5px;
    font-feature-settings: var(--mono-feats);
}

.tc-badge-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--ink-faint);
    flex-shrink: 0;
}

.telemetry-card.terra .tc-badge-dot { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }
.telemetry-card.olive .tc-badge-dot { background: var(--structure); box-shadow: 0 0 6px var(--structure-tint); }
.telemetry-card.gold .tc-badge-dot { background: var(--mark); }
.telemetry-card.ink .tc-badge-dot { background: var(--ink-soft); }

.tc-val {
    font-size: 1.22rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.02em;
    display: flex;
    align-items: baseline;
    gap: 5px;
    font-feature-settings: var(--mono-feats);
    margin: 2px 0 1px;
}

.tc-val .unit {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--ink-soft);
    letter-spacing: 0.04em;
}

.tc-desc {
    font-size: 0.64rem;
    color: var(--ink-faint);
    line-height: 1.4;
    margin-top: auto;
}

/* Mechanism Exploder Section */
.mechanism-section {
    margin: 2.5rem 0 2rem;
}

.mechanism-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--rule);
    padding-bottom: 0.55rem;
    margin-bottom: 1.4rem;
}

.mechanism-section-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--ink);
}

.mechanism-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 1.8rem;
    align-items: stretch;
}

.mechanism-card {
    background: var(--paper-inset);
    border: 1px solid var(--rule-strong);
    border-radius: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-1);
    transition: border-color var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease);
}

.mechanism-card:hover {
    border-color: var(--mark);
    box-shadow: var(--shadow-2);
}

/* Per-card accent bar — top edge coloured by card type */
.mechanism-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    z-index: 1;
}
.mechanism-card.card-ssd::before, .mechanism-card.card-gqa::before { background: var(--accent); }
.mechanism-card.card-mimo::before, .mechanism-card.card-chunkce::before { background: var(--structure); }
.mechanism-card.card-chunk::before, .mechanism-card.card-rope::before { background: var(--mark); }

.mechanism-card-head {
    padding: 0.7rem 0.9rem;
    background: var(--paper-2);
    border-bottom: 1px solid var(--rule);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
}

.mch-tag {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--accent);
}
.mechanism-card.card-mimo .mch-tag, .mechanism-card.card-chunkce .mch-tag { color: var(--structure); }
.mechanism-card.card-chunk .mch-tag, .mechanism-card.card-rope .mch-tag { color: var(--mark); }

.mch-title {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.3;
}

.mechanism-card-body {
    padding: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

.mch-explainer {
    font-size: 0.86rem;
    color: var(--ink-soft);
    line-height: 1.55;
    margin: 0;
}

/* Calculator & Controls Inside Mechanism Cards */
.mch-control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.66rem;
    color: var(--ink-faint);
}
.mch-control-row strong {
    color: var(--ink-soft);
    font-weight: 600;
}

.mch-slider {
    width: 100%;
    margin: 4px 0 8px;
    accent-color: var(--accent);
    cursor: pointer;
    height: 4px;
}

.mch-canvas {
    width: 100%;
    height: 130px;
    background: var(--paper);
    border: 1px solid var(--rule);
    display: block;
}

.mch-stat-box {
    background: var(--paper-2);
    border: 1px solid var(--rule);
    padding: 0.6rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-family: var(--font-mono);
    margin-top: auto;
}

.msb-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    font-size: 0.72rem;
    color: var(--ink-soft);
    font-feature-settings: var(--mono-feats);
    padding: 1px 0;
}
.msb-row > span:last-child {
    white-space: nowrap;
    text-align: right;
}

.msb-row.highlight {
    color: var(--accent);
    font-weight: 700;
    border-top: 1px dashed var(--rule);
    padding-top: 4px;
    margin-top: 3px;
}

.mch-action-btn {
    background: var(--paper-2);
    border: 1px solid var(--rule);
    color: var(--ink);
    font-family: var(--font-prose);
    font-size: 0.8rem;
    font-weight: 400;
    padding: 0.45rem 0.75rem;
    cursor: pointer;
    transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    border-radius: 2px;
}

.mch-action-btn:hover {
    background: var(--tint-accent-06);
    border-color: var(--accent);
    color: var(--accent);
}
.mechanism-card.card-mimo .mch-action-btn:hover, .mechanism-card.card-chunkce .mch-action-btn:hover {
    border-color: var(--structure);
    color: var(--structure);
    background: var(--structure-tint);
}
.mechanism-card.card-chunk .mch-action-btn:hover, .mechanism-card.card-rope .mch-action-btn:hover {
    border-color: var(--mark);
    color: var(--mark);
    background: var(--callout-note-bg);
}

/* MIMO Live Mini Matrix (16×16) */
.mimo-matrix-grid {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 1px;
    margin: 6px 0;
    background: var(--rule);
    border: 1px solid var(--rule);
    padding: 1px;
}

.mimo-cell {
    background: var(--paper);
    padding: 3px 1px;
    text-align: center;
    font-size: 0.46rem;
    color: var(--ink-faint);
    transition: background 0.22s ease, color 0.18s ease;
    font-family: var(--font-mono);
    line-height: 1;
    min-height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mimo-cell.diagonal {
    background: rgba(138, 106, 46, 0.10) !important;
    color: var(--mark);
    font-weight: 700;
    font-size: 0.50rem;
}

.mimo-cell.active {
    color: var(--ink);
    font-weight: 700;
}

/* Chunkwise Pipeline Visualizer */
.chunk-pipeline-box {
    background: var(--paper-2);
    border: 1px solid var(--rule);
    padding: 0.65rem 0.7rem;
    font-size: 0.60rem;
    line-height: 1.45;
    font-family: var(--font-mono);
}

.chunk-stage {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0;
    color: var(--ink-soft);
    transition: opacity 0.3s ease;
    padding: 3px 0;
}
.chunk-stage + .chunk-stage {
    border-top: 1px solid var(--rule-fine);
}

.chunk-badge {
    padding: 2px 6px;
    border-radius: 2px;
    font-size: 0.54rem;
    font-weight: 700;
    font-feature-settings: var(--mono-feats);
    flex-shrink: 0;
    min-width: 42px;
    text-align: center;
}

.chunk-badge.scan {
    background: var(--tint-ink-08);
    color: var(--ink);
    border: 1px solid var(--rule);
}

.chunk-badge.chunk {
    background: var(--structure-tint);
    color: var(--structure);
    border: 1px solid var(--structure);
}

.chunk-badge.state {
    background: var(--tint-accent-06);
    color: var(--accent);
    border: 1px solid var(--accent);
}

@media (max-width: 1024px) {
    .mamba-telemetry-ribbon { grid-template-columns: repeat(2, 1fr); }
    .mechanism-grid { grid-template-columns: 1fr; }
}



/* =====================================================================
   11. MARKDOWN PASS-THROUGH — images, disclosures, centered blocks
   ===================================================================== */

/* Figure and badge images from raw markdown HTML / ![alt](src).
   `align="center"` is a presentational HTML attribute, so it needs a
   matching rule here; without one the figure inherits left alignment
   inside an otherwise centered block. */
.markdown-body img,
.markdown-body .md-img {
    max-width: 100%;
    height: auto;
    vertical-align: middle;
}

.markdown-body p > img.md-img:only-child,
.markdown-body [align="center"] > img,
.markdown-body [align="center"] > a > img {
    display: block;
    margin: 0 auto;
}

/* Badges arrive one per markdown line, so each lands in its own paragraph.
   Collapse badge paragraphs into a single inline row — four stacked badges
   read as a list, one row reads as a badge bar. Scoped by the shields.io
   host so ordinary figure paragraphs keep their block layout. */
.markdown-body p:has(> a > img[src*="shields.io"]),
.markdown-body p:has(> img[src*="shields.io"]) {
    display: inline-block;
    margin: 0.1rem 0.15rem;
}

/* The centered header block that holds the badge row. */
.markdown-body [align="center"] { text-align: center; }

.markdown-body .md-img[src*="shields.io"] {
    display: inline-block;
    margin: 0.2rem 0.25rem;
    vertical-align: middle;
}

/* A figure image is the page's one large visual: give it the paper-inset
   plane and a hairline so it reads as a plate, not floating chrome. */
.markdown-body [align="center"] > a > img,
.markdown-body figure img {
    border: 1px solid var(--rule);
    border-radius: 2px;
    background: var(--paper-inset);
    margin-top: 0.6rem;
}

.markdown-body [align="center"] > p,
.markdown-body figcaption {
    color: var(--ink-faint);
    font-size: 0.8rem;
    line-height: 1.55;
    margin: 0.7rem auto 1.5rem;
    max-width: 62ch;
}

/* <details> disclosure — the same recessed plane as code blocks, with a
   terracotta marker so it reads as interactive. */
.markdown-body details {
    margin: 1.6rem 0;
    background: var(--paper-2);
    border: 1px solid var(--rule);
    border-radius: 2px;
}

.markdown-body summary {
    cursor: pointer;
    padding: 0.7rem 1rem;
    color: var(--ink);
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.markdown-body summary::-webkit-details-marker { display: none; }

.markdown-body summary::before {
    /* the disclosure triangle, drawn so it can rotate on [open] */
    content: "▸";
    color: var(--accent);
    font-size: 0.9em;
    transition: transform var(--t-base) var(--ease);
    display: inline-block;
}

.markdown-body details[open] > summary::before { transform: rotate(90deg); }
.markdown-body summary:hover { background: var(--tint-ink-05); color: var(--accent); }
.markdown-body summary:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.markdown-body details > *:not(summary) {
    padding: 0 1rem;
}

.markdown-body details > *:not(summary):last-child { padding-bottom: 0.9rem; }
.markdown-body details > p:first-of-type { padding-top: 0.2rem; }
.markdown-body details ol, .markdown-body details ul { padding-left: 1.9rem; }



/* =====================================================================
   12. RESPONSIVE
   ===================================================================== */

@media (max-width: 1180px) {
    .app-layout,
    .index-portal .app-layout,
    .app-layout:not(:has(.toc-sidebar)) {
        grid-template-columns: 232px minmax(0, 1fr);
    }
    .toc-sidebar { display: none; }
}

@media (max-width: 880px) {
    .app-layout,
    .index-portal .app-layout,
    .app-layout:not(:has(.toc-sidebar)) {
        grid-template-columns: 1fr;
    }
    .sidebar {
        display: none;
        position: fixed;
        left: 0; top: 50px;
        width: 280px;
        z-index: 60;
        background: var(--paper-2);
        border-right: 1px solid var(--rule);
        height: calc(100vh - 50px);
        box-shadow: var(--shadow-3);
    }
    .sidebar.open { display: block; }
    .mobile-toggle { display: inline-block; }

    .main-content,
    .index-portal .main-content {
        padding: 1.6rem 1.25rem 3rem;
        width: 100%;
        max-width: 100%;
    }
    .main-content::before { left: 14px; }
    .hero-banner { padding: 1.8rem 1.3rem; }
    .hero-title { font-size: 1.95rem; }
    .fig-canvas-wrap { height: 280px; }
    .pass-canvas-wrap { height: 200px; }
    .fig-dim, .pass-dim { display: none; }
    .legend-hint { display: none; }
    .doc-title { font-size: 1.65rem; }
    .hero-coords { font-size: 0.64rem; }
    .spec-grid { grid-template-columns: repeat(2, 1fr); }
    .portal-grid { grid-template-columns: 1fr; }
    .portal-card:last-child:nth-child(odd) {
        flex-direction: column;
        gap: 6px;
    }
    .spec-cell:nth-child(4n) { border-right: 1px solid var(--rule); }
    .spec-cell:nth-child(2n) { border-right: none; }
    .spec-cell:nth-last-child(-n+4) { border-bottom: 1px solid var(--rule); }
    .spec-cell:nth-last-child(-n+2) { border-bottom: none; }
    .mamba-telemetry-ribbon { grid-template-columns: repeat(2, 1fr); }
    .mimo-matrix-grid { grid-template-columns: repeat(8, 1fr); }
    .doc-meta .meta-item { border-right: none; padding-right: 0; }
    .portal-card::after { display: none; }
    .portal-card:hover .card-heading { color: var(--ink); }
}
@media (max-width: 560px) {
    /* The brand + right-hand links together exceed a 390px viewport and push
       the document into horizontal scroll. Let the header wrap and drop the
       badge rather than letting either clip. */
    .site-header {
        flex-wrap: wrap;
        row-gap: 0.5rem;
        padding: 0.6rem 1rem;
    }
    .header-left { gap: 0.7rem; min-width: 0; }
    .header-right { gap: 0.8rem; }
    .brand-badge { display: none; }
    .hero-figure-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .fig-badge {
        justify-content: flex-start;
    }
    .fig-controls {
        display: flex;
        width: 100%;
    }
    .fig-controls .fig-btn:not(.fig-btn-icon) {
        flex: 1;
        text-align: center;
        padding: 0.25rem 0.2rem;
        font-size: 0.52rem;
    }
    .hud-corner, .pass-hud-chip {
        display: none;
    }
    .hero-figure-footer, .pass-widget-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.4rem;
    }
    .pass-widget-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .pass-badge {
        justify-content: flex-start;
    }
    .pass-controls {
        display: flex;
        width: 100%;
    }
    .pass-controls .pass-btn:not(.pass-btn-icon) {
        flex: 1;
        text-align: center;
        padding: 0.25rem 0.2rem;
        font-size: 0.52rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}


/* Mobile overflow guard: wide tables and ASCII diagrams scroll inside
   their own box instead of pushing the whole page sideways. */
@media (max-width: 760px) {
    .doc-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .markdown-body > pre,
    .markdown-body pre:not(.code-wrapper pre) {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}