/* ============================================================================
   Flow documentation theme
   ----------------------------------------------------------------------------
   Token names are load-bearing: tutorial-runner.css and grammar-viewer.js read
   --surface / --border / --radius / --mono with fallbacks. Keep them stable.
   ========================================================================== */

:root,
html[data-theme="dark"] {
    color-scheme: dark;

    --bg: #080a0f;
    --bg-far: #05070b;
    --surface: #0d1017;
    --surface-2: #12161f;
    --surface-3: #181d29;
    --border: #1b2230;
    --border-light: #29323f;
    --border-strong: #3a4759;

    --text: #e9eef6;
    --text-muted: #a3aebf;
    /* De-emphasised, but still >= 4.5:1 on --surface-2. */
    --text-faint: #828e9f;

    --accent: #22d3ee;
    --accent-strong: #67e8f9;
    --accent-soft: rgba(34, 211, 238, 0.13);
    --accent-line: rgba(34, 211, 238, 0.35);
    --on-accent: #04222a;

    --purple: #b39dff;
    --purple-soft: rgba(179, 157, 255, 0.13);
    --green: #4ade80;
    --green-soft: rgba(74, 222, 128, 0.12);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, 0.12);
    --danger: #fb7185;
    --danger-soft: rgba(251, 113, 133, 0.12);

    --header-bg: rgba(8, 10, 15, 0.78);
    --overlay: rgba(3, 5, 9, 0.66);
    --row-hover: rgba(255, 255, 255, 0.025);
    --code-hover: rgba(255, 255, 255, 0.035);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 20px -6px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 24px 64px -12px rgba(0, 0, 0, 0.75);
    --ring: 0 0 0 3px rgba(34, 211, 238, 0.32);

    /* Syntax */
    --syn-comment: #7d8b9e;
    --syn-keyword: #c79cff;
    --syn-dsl: #22d3ee;
    --syn-type: #7dd3fc;
    --syn-string: #9ede6d;
    --syn-number: #ffb086;
    --syn-literal: #ff9e64;
    --syn-func: #82aaff;
    --syn-meta: #f7768e;
    --syn-op: #89ddff;
    --syn-var: #d8e2f0;
}

html[data-theme="light"] {
    color-scheme: light;

    --bg: #f7f8fa;
    --bg-far: #eef1f5;
    --surface: #ffffff;
    --surface-2: #f2f4f8;
    --surface-3: #e8ecf2;
    --border: #e0e5ec;
    --border-light: #d3dae3;
    --border-strong: #b6c0cd;

    --text: #131820;
    --text-muted: #505c6b;
    --text-faint: #5f6b7a;

    --accent: #0a6076;
    --accent-strong: #084c5e;
    --accent-soft: rgba(10, 96, 118, 0.09);
    --accent-line: rgba(10, 96, 118, 0.32);
    --on-accent: #ffffff;

    --purple: #7c3aed;
    --purple-soft: rgba(124, 58, 237, 0.08);
    --green: #066b32;
    --green-soft: rgba(6, 107, 50, 0.09);
    --warn: #b45309;
    --warn-soft: rgba(180, 83, 9, 0.09);
    --danger: #be123c;
    --danger-soft: rgba(190, 18, 60, 0.08);

    --header-bg: rgba(247, 248, 250, 0.8);
    --overlay: rgba(19, 24, 32, 0.34);
    --row-hover: rgba(19, 24, 32, 0.028);
    --code-hover: rgba(19, 24, 32, 0.035);

    --shadow-sm: 0 1px 2px rgba(19, 24, 32, 0.06);
    --shadow-md: 0 6px 20px -8px rgba(19, 24, 32, 0.18);
    --shadow-lg: 0 24px 64px -16px rgba(19, 24, 32, 0.26);
    --ring: 0 0 0 3px rgba(14, 116, 144, 0.22);

    --syn-comment: #5e6875;
    --syn-keyword: #8250df;
    --syn-dsl: #0e7490;
    --syn-type: #0550ae;
    --syn-string: #0a7d3f;
    --syn-number: #b35309;
    --syn-literal: #b35309;
    --syn-func: #0f5ecf;
    --syn-meta: #b91c4c;
    --syn-op: #0f766e;
    --syn-var: #131820;
}

:root {
    --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    --sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --header-h: 58px;
    --tabs-h: 42px;
    --chrome-h: calc(var(--header-h) + var(--tabs-h));
    --sidebar-w: 278px;
    --toc-w: 232px;
    --content-w: 45rem;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --fast: 0.14s var(--ease);
    --med: 0.24s var(--ease);
}

/* ── Reset ───────────────────────────────────────────────────────────────── */

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

/* `hidden` must beat component display rules (.version-banner is a flexbox). */
[hidden] { display: none !important; }

html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--chrome-h) + 1.5rem);
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    line-height: 1.65;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
}

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

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

/* Custom scrollbars — keeps the chrome from breaking the dark canvas. */
* { scrollbar-width: thin; scrollbar-color: var(--border-light) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 999px;
    border: 3px solid transparent;
    background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: content-box; }

.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;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

.site-header {
    position: sticky;
    top: 0;
    z-index: 200;
    background: var(--header-bg);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 1rem;
    height: var(--header-h);
    padding: 0 1.25rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    text-decoration: none;
    color: var(--text);
    flex-shrink: 0;
    border-radius: var(--radius-sm);
}

.brand-mark {
    position: relative;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    object-fit: cover;
    box-shadow: 0 2px 12px -2px var(--accent-line);
    transition: transform var(--med), box-shadow var(--med);
}

html[data-theme="light"] .brand-mark { color: #fff; }

.brand:hover .brand-mark {
    transform: translateY(-1px) rotate(-3deg);
    box-shadow: 0 6px 18px -4px var(--accent-line);
}

.brand-name {
    font-weight: 650;
    font-size: 1.08rem;
    letter-spacing: -0.025em;
}

.brand-tag {
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
    border: 1px solid var(--border-light);
    padding: 0.1rem 0.38rem;
    border-radius: 999px;
}

.version-picker {
    flex: 1;
    display: flex;
    justify-content: center;
    min-width: 0;
}

.version-select {
    appearance: none;
    background-color: var(--surface-2);
    border: 1px solid var(--border-light);
    color: var(--text);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.36rem 1.9rem 0.36rem 0.7rem;
    border-radius: 999px;
    cursor: pointer;
    max-width: 230px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12' fill='none' stroke='%2397a3b6' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    transition: border-color var(--fast), background-color var(--fast);
}

.version-select:hover { border-color: var(--border-strong); }
.version-select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.version-select option[disabled] { color: var(--text-faint); }

.header-tools {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.845rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--fast), color var(--fast), border-color var(--fast);
}

.btn:hover { background: var(--surface-2); color: var(--text); }

.btn-accent {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
    box-shadow: 0 1px 8px -2px var(--accent-line);
}

.btn-accent:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
    color: var(--on-accent);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px -4px var(--accent-line);
}

.btn-icon { display: none; padding: 0.4rem 0.55rem; font-size: 1rem; }

.btn-discord {
    border-color: rgba(88, 101, 242, 0.35);
    color: #cdd3ff;
}

html[data-theme="dark"] .btn-discord {
    background: rgba(88, 101, 242, 0.12);
}

html[data-theme="dark"] .btn-discord:hover {
    background: rgba(88, 101, 242, 0.22);
    border-color: rgba(88, 101, 242, 0.6);
    color: #e3e7ff;
    box-shadow: 0 6px 16px -6px rgba(88, 101, 242, 0.55);
}

html[data-theme="light"] .btn-discord {
    color: #4a56c7;
    border-color: rgba(88, 101, 242, 0.35);
    background: rgba(88, 101, 242, 0.06);
}

html[data-theme="light"] .btn-discord:hover {
    background: rgba(88, 101, 242, 0.13);
    color: #3d48ad;
}

.theme-toggle {
    width: 34px;
    height: 32px;
    padding: 0;
    justify-content: center;
    border: 1px solid var(--border-light);
    font-size: 0;
}

/* Icon is drawn in CSS so the button has no layout-shifting text label. */
.theme-toggle::before {
    content: '';
    width: 16px;
    height: 16px;
    background: currentColor;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-image: var(--icon-moon);
    mask-image: var(--icon-moon);
}

html[data-theme="light"] .theme-toggle::before {
    -webkit-mask-image: var(--icon-sun);
    mask-image: var(--icon-sun);
}

:root {
    --icon-moon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z'/%3E%3C/svg%3E");
    --icon-sun: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='4'/%3E%3Cpath d='M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M6.3 17.7l-1.4 1.4M19.1 4.9l-1.4 1.4'/%3E%3C/svg%3E");
}

/* ── Search trigger ──────────────────────────────────────────────────────── */

.search-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem 0.4rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--border-light);
    background: var(--surface-2);
    color: var(--text-faint);
    font-family: inherit;
    font-size: 0.84rem;
    cursor: pointer;
    min-width: 208px;
    transition: border-color var(--fast), color var(--fast), background var(--fast);
}

.search-trigger:hover {
    border-color: var(--accent);
    color: var(--text);
    background: var(--surface-3);
}

.search-icon { font-size: 0.95rem; opacity: 0.8; line-height: 1; }
.search-placeholder { flex: 1; text-align: left; }

.search-trigger kbd,
kbd.key {
    /* System UI first: the webfonts have no glyph for ⌘ and render tofu. */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI Symbol', var(--sans);
    font-size: 0.7rem;
    line-height: 1.5;
    padding: 0.1rem 0.4rem;
    border-radius: 5px;
    border: 1px solid var(--border-light);
    background: var(--surface);
    color: var(--text-faint);
    box-shadow: 0 1px 0 var(--border-light);
}

/* ── Tab bar ─────────────────────────────────────────────────────────────── */

.tab-bar {
    display: flex;
    gap: 0.15rem;
    padding: 0 1.25rem;
    overflow-x: auto;
    scrollbar-width: none;
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 80%, transparent);
    height: var(--tabs-h);
    align-items: stretch;
}

.tab-bar::-webkit-scrollbar { display: none; }

.tab-btn {
    position: relative;
    padding: 0 0.85rem;
    border: none;
    background: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--fast);
}

.tab-btn::after {
    content: '';
    position: absolute;
    left: 0.5rem;
    right: 0.5rem;
    bottom: 0;
    height: 2px;
    border-radius: 2px 2px 0 0;
    background: var(--accent);
    transform: scaleX(0);
    transition: transform var(--med);
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); font-weight: 600; }
.tab-btn.active::after { transform: scaleX(1); }

/* ── Reading progress ────────────────────────────────────────────────────── */

.read-progress {
    position: absolute;
    left: 0;
    bottom: -1px;
    height: 2px;
    width: 100%;
    transform-origin: 0 50%;
    transform: scaleX(0);
    background: linear-gradient(90deg, var(--accent), var(--purple));
    z-index: 1;
    pointer-events: none;
}

/* ── Search overlay ──────────────────────────────────────────────────────── */

.search-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: var(--overlay);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    padding: 11vh 1rem 1rem;
    animation: fade-in 0.14s var(--ease);
}

.search-panel {
    width: min(620px, 100%);
    max-height: 74vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: pop-in 0.18s var(--ease);
}

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(-8px) scale(0.985); } }

.search-input {
    width: 100%;
    padding: 1.05rem 1.25rem;
    border: none;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 1.02rem;
    outline: none;
}

.search-input::placeholder { color: var(--text-faint); }
.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }

.search-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
}

.search-filter {
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--border-light);
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--fast);
}

.search-filter:hover { border-color: var(--border-strong); color: var(--text); }

.search-filter.active {
    background: var(--accent-soft);
    border-color: var(--accent-line);
    color: var(--accent);
}

.search-results {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    padding: 0.4rem;
}

.search-results li button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.6rem 0.8rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
    transition: background var(--fast), border-color var(--fast);
}

.search-results li button:hover,
.search-results li button.focused {
    background: var(--accent-soft);
    border-color: var(--accent-line);
}

.search-results .result-cat {
    display: inline-block;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 0.05rem 0.35rem;
    border-radius: 4px;
    margin-right: 0.45rem;
    vertical-align: 1px;
}

.search-results .result-title { font-weight: 600; font-size: 0.9rem; }
.search-results .result-path {
    display: block;
    font-size: 0.72rem;
    color: var(--text-faint);
    font-family: var(--mono);
    margin-top: 0.1rem;
}
.search-results .result-excerpt {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    line-height: 1.45;
}
.search-results .result-excerpt mark {
    background: var(--accent-soft);
    color: var(--accent);
    padding: 0 0.15em;
    border-radius: 3px;
    font-weight: 600;
}

.search-hint {
    display: flex;
    gap: 1rem;
    padding: 0.55rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 0.72rem;
    color: var(--text-faint);
}

.search-hint span { display: inline-flex; align-items: center; gap: 0.3rem; }

.search-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-faint);
    font-size: 0.88rem;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */

.layout {
    display: flex;
    flex: 1;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
}

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    position: sticky;
    top: var(--chrome-h);
    height: calc(100vh - var(--chrome-h));
    overflow-y: auto;
    overscroll-behavior: contain;
    border-right: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 55%, transparent);
    padding: 1rem 0 2rem;
}

.sidebar-section { margin-bottom: 0.35rem; }

.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.45rem 1.15rem;
    border: none;
    background: none;
    color: var(--text-faint);
    font-family: inherit;
    font-size: 0.67rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    cursor: pointer;
    text-align: left;
    transition: color var(--fast);
}

.sidebar-section-header:hover { color: var(--text); }

.sidebar-section-header .chevron {
    font-size: 0.5rem;
    opacity: 0.6;
    transition: transform var(--med);
}

.sidebar-section.collapsed .sidebar-section-header .chevron { transform: rotate(-90deg); }
.sidebar-section.collapsed .sidebar-items { display: none; }

.sidebar-items { list-style: none; padding: 0 0.7rem 0.4rem; }

.sidebar-items a {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.32rem 0.6rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.845rem;
    line-height: 1.4;
    transition: background var(--fast), color var(--fast);
}

.sidebar-items a::before {
    content: '';
    position: absolute;
    left: -0.7rem;
    top: 50%;
    width: 2px;
    height: 0;
    border-radius: 0 2px 2px 0;
    background: var(--accent);
    transform: translateY(-50%);
    transition: height var(--med);
}

.sidebar-items a:hover { background: var(--surface-2); color: var(--text); }

.sidebar-items a.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.sidebar-items a.active::before { height: 60%; }

.item-badge {
    font-size: 0.62rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--purple-soft);
    color: var(--purple);
    font-weight: 700;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.main-column {
    flex: 1;
    min-width: 0;
    max-width: calc(var(--content-w) + 6rem);
    padding: 2rem 3rem 4rem;
}

/* ── Breadcrumb + doc header ─────────────────────────────────────────────── */

.breadcrumb {
    font-size: 0.78rem;
    color: var(--text-faint);
    margin-bottom: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    align-items: center;
}

.breadcrumb a { color: var(--text-muted); text-decoration: none; transition: color var(--fast); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { opacity: 0.35; }

.doc-header {
    margin-bottom: 1.75rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.doc-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.doc-title {
    font-size: clamp(1.9rem, 1.3rem + 1.8vw, 2.45rem);
    font-weight: 700;
    letter-spacing: -0.033em;
    line-height: 1.15;
    color: var(--text);
    text-wrap: balance;
}

.doc-lead {
    margin-top: 0.65rem;
    font-size: 1.06rem;
    line-height: 1.6;
    color: var(--text-muted);
    max-width: 60ch;
    text-wrap: pretty;
}

.doc-edit-link {
    flex-shrink: 0;
    margin-top: 0.4rem;
    font-size: 0.76rem;
    color: var(--text-faint);
    text-decoration: none;
    white-space: nowrap;
    border: 1px solid var(--border-light);
    border-radius: 999px;
    padding: 0.22rem 0.7rem;
    transition: all var(--fast);
}

.doc-edit-link:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.proof-badge,
.grammar-badge,
.spec-badge {
    display: inline-block;
    margin-left: 0.6rem;
    vertical-align: 0.35em;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    padding: 0.18rem 0.5rem;
    border-radius: 999px;
}

.proof-badge { background: var(--purple-soft); color: var(--purple); border: 1px solid color-mix(in srgb, var(--purple) 30%, transparent); }
.grammar-badge { background: var(--green-soft); color: var(--green); border: 1px solid color-mix(in srgb, var(--green) 30%, transparent); }
.spec-badge { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line); }

/* ── Version banner ──────────────────────────────────────────────────────── */

.version-banner {
    margin-bottom: 1.25rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
    background: var(--warn-soft);
    color: var(--text-muted);
    font-size: 0.86rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
}

.version-banner strong { color: var(--warn); }
.version-banner a { color: var(--accent); text-decoration: none; font-weight: 500; }
.version-banner a:hover { text-decoration: underline; }

.version-banner .banner-action {
    margin-left: auto;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    background: var(--surface);
    color: var(--text);
    font-size: 0.78rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--fast);
}

.version-banner .banner-action:hover { border-color: var(--accent); color: var(--accent); }

/* ── Markdown body ───────────────────────────────────────────────────────── */

.markdown-body {
    font-size: 1rem;
    line-height: 1.75;
    color: var(--text);
    max-width: var(--content-w);
}

.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }

/* The rendered H1 is promoted into .doc-title, except on the home hero. */
.markdown-body h1 { display: none; }

.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    position: relative;
    scroll-margin-top: calc(var(--chrome-h) + 1.5rem);
    text-wrap: balance;
    color: var(--text);
}

.markdown-body h2 {
    font-size: 1.5rem;
    font-weight: 650;
    letter-spacing: -0.024em;
    line-height: 1.3;
    margin: 2.75rem 0 1rem;
    padding-bottom: 0.45rem;
    border-bottom: 1px solid var(--border);
}

.markdown-body h3 {
    font-size: 1.175rem;
    font-weight: 650;
    letter-spacing: -0.018em;
    margin: 2rem 0 0.7rem;
}

.markdown-body h4 {
    font-size: 1rem;
    font-weight: 650;
    margin: 1.6rem 0 0.55rem;
    color: var(--text-muted);
}

.markdown-body h5,
.markdown-body h6 {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-faint);
    margin: 1.4rem 0 0.5rem;
}

/* Hover anchor links */
.heading-anchor {
    position: absolute;
    left: -1.35rem;
    width: 1.35rem;
    top: 0;
    bottom: 0;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    color: var(--text-faint);
    text-decoration: none;
    font-weight: 400;
    opacity: 0;
    transition: opacity var(--fast), color var(--fast);
}

.markdown-body h2:hover .heading-anchor,
.markdown-body h3:hover .heading-anchor,
.markdown-body h4:hover .heading-anchor,
.heading-anchor:focus-visible { opacity: 1; }

.heading-anchor:hover { color: var(--accent); }

.markdown-body p { margin-bottom: 1.15rem; text-wrap: pretty; }

.markdown-body a {
    color: var(--accent);
    text-decoration: none;
    text-decoration-color: var(--accent-line);
    text-underline-offset: 0.18em;
    transition: text-decoration-color var(--fast);
}

.markdown-body a:hover { text-decoration: underline; text-decoration-color: currentColor; }

/* Anchors that are really controls must outrank the generic link colour above. */
.markdown-body a.wiki-cta { color: var(--text); text-decoration: none; }
.markdown-body a.wiki-cta:hover { color: var(--accent); text-decoration: none; }
.markdown-body a.wiki-cta-primary,
.markdown-body a.wiki-cta-primary:hover { color: var(--on-accent); text-decoration: none; }
.markdown-body a.heading-anchor { color: var(--text-faint); text-decoration: none; }
.markdown-body a.heading-anchor:hover { color: var(--accent); }

.markdown-body strong { font-weight: 650; color: var(--text); }

/* ── Inline code + code blocks ───────────────────────────────────────────── */

.markdown-body code {
    font-family: var(--mono);
    font-size: 0.855em;
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 0.1rem 0.35rem;
    border-radius: 5px;
    word-break: break-word;
}

.markdown-body a code { color: inherit; border-color: var(--accent-line); }

.markdown-body pre {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    overflow-x: auto;
    margin: 1.4rem 0;
    font-size: 0.855rem;
    line-height: 1.65;
    tab-size: 4;
}

.markdown-body pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: 1em;
}

/* Code block shell (language label + copy button), built by wiki.js */
.code-block {
    position: relative;
    margin: 1.4rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.code-block > pre {
    margin: 0;
    border: none;
    border-radius: 0;
    background: transparent;
}

.code-block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.42rem 0.7rem 0.42rem 0.95rem;
    background: color-mix(in srgb, var(--surface-3) 60%, transparent);
    border-bottom: 1px solid var(--border);
}

.code-lang {
    font-family: var(--mono);
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
}

.code-copy {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-faint);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    opacity: 0;
    transition: all var(--fast);
}

.code-block:hover .code-copy,
.code-copy:focus-visible { opacity: 1; }

.code-copy:hover { background: var(--surface); border-color: var(--border-light); color: var(--text); }
.code-copy.copied { color: var(--green); border-color: color-mix(in srgb, var(--green) 40%, transparent); opacity: 1; }

/* Flow code gets a signature accent rail. */
.code-block[data-lang="flow"] { border-left: 2px solid var(--accent-line); }
.markdown-body pre.language-block { border-left: 3px solid var(--green); }

/* ── Syntax tokens (theme-aware; replaces the fixed github-dark sheet) ───── */

.hljs { color: var(--syn-var); background: transparent; }
.hljs-comment, .hljs-quote { color: var(--syn-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-doctag, .hljs-formula { color: var(--syn-keyword); }
.hljs-built_in, .hljs-class .hljs-title { color: var(--syn-dsl); font-weight: 500; }
.hljs-type, .hljs-tag, .hljs-selector-class, .hljs-selector-attr, .hljs-selector-pseudo { color: var(--syn-type); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute, .hljs-meta .hljs-string { color: var(--syn-string); }
.hljs-number, .hljs-literal, .hljs-variable, .hljs-template-variable { color: var(--syn-number); }
.hljs-symbol, .hljs-bullet, .hljs-link { color: var(--syn-literal); }
.hljs-title, .hljs-section, .hljs-name, .hljs-title.function_ { color: var(--syn-func); }
.hljs-attr, .hljs-property, .hljs-params { color: var(--syn-var); }
.hljs-meta, .hljs-meta .hljs-keyword { color: var(--syn-meta); }
.hljs-operator, .hljs-punctuation { color: var(--syn-op); }
.hljs-deletion { color: var(--danger); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }

/* ── Blockquote + admonitions ────────────────────────────────────────────── */

.markdown-body blockquote {
    border-left: 3px solid var(--border-strong);
    padding: 0.15rem 0 0.15rem 1.15rem;
    margin: 1.4rem 0;
    color: var(--text-muted);
    font-style: italic;
}

.markdown-body blockquote p:last-child { margin-bottom: 0; }

.admonition {
    position: relative;
    margin: 1.5rem 0;
    padding: 0.9rem 1.1rem 0.9rem 3rem;
    border-radius: var(--radius);
    border: 1px solid var(--accent-line);
    background: var(--accent-soft);
}

.admonition::before {
    content: '';
    position: absolute;
    left: 1rem;
    top: 1.05rem;
    width: 1.15rem;
    height: 1.15rem;
    background: var(--accent);
    -webkit-mask: var(--adm-icon) no-repeat center / contain;
    mask: var(--adm-icon) no-repeat center / contain;
    --adm-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4M12 8h.01'/%3E%3C/svg%3E");
}

.admonition-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 0.35rem;
    color: var(--accent);
}

.admonition-body { font-size: 0.95rem; color: var(--text-muted); }
.admonition-body > :last-child { margin-bottom: 0; }
.admonition-body a { font-weight: 500; }

.admonition-note { border-color: var(--accent-line); background: var(--accent-soft); }

.admonition-tip {
    border-color: color-mix(in srgb, var(--green) 32%, transparent);
    background: var(--green-soft);
}
.admonition-tip .admonition-title { color: var(--green); }
.admonition-tip::before {
    background: var(--green);
    --adm-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 18h6M10 22h4M12 2a7 7 0 0 0-4 12.7V17h8v-2.3A7 7 0 0 0 12 2z'/%3E%3C/svg%3E");
}

.admonition-warning {
    border-color: color-mix(in srgb, var(--warn) 32%, transparent);
    background: var(--warn-soft);
}
.admonition-warning .admonition-title { color: var(--warn); }
.admonition-warning::before {
    background: var(--warn);
    --adm-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0z'/%3E%3Cpath d='M12 9v4M12 17h.01'/%3E%3C/svg%3E");
}

.admonition-important {
    border-color: color-mix(in srgb, var(--purple) 32%, transparent);
    background: var(--purple-soft);
}
.admonition-important .admonition-title { color: var(--purple); }
.admonition-important::before {
    background: var(--purple);
    --adm-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M12 2 2 20h20L12 2z'/%3E%3Cpath d='M12 9v4M12 17h.01'/%3E%3C/svg%3E");
}

.admonition-caution {
    border-color: color-mix(in srgb, var(--danger) 32%, transparent);
    background: var(--danger-soft);
}
.admonition-caution .admonition-title { color: var(--danger); }
.admonition-caution::before {
    background: var(--danger);
    --adm-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='m15 9-6 6M9 9l6 6'/%3E%3C/svg%3E");
}

/* ── Lists ───────────────────────────────────────────────────────────────── */

.markdown-body ul,
.markdown-body ol { margin: 0.85rem 0 1.15rem; padding-left: 1.35rem; }

.markdown-body li { margin: 0.35rem 0; padding-left: 0.2rem; }
.markdown-body li::marker { color: var(--text-faint); }
.markdown-body ul li::marker { color: var(--accent); }
.markdown-body li > p { margin-bottom: 0.4rem; }
.markdown-body li > ul,
.markdown-body li > ol { margin: 0.35rem 0; }

.markdown-body input[type="checkbox"] { margin-right: 0.4rem; accent-color: var(--accent); }

/* ── Tables ──────────────────────────────────────────────────────────────── */

.table-wrap {
    margin: 1.5rem 0;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.table-wrap > table { margin: 0; border: none; }

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.885rem;
    line-height: 1.55;
}

.markdown-body th,
.markdown-body td {
    padding: 0.6rem 0.9rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}

.markdown-body th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    font-weight: 650;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    border-bottom: 1px solid var(--border-light);
}

.markdown-body tbody tr:last-child td { border-bottom: none; }
.markdown-body tbody tr { transition: background var(--fast); }
.markdown-body tbody tr:hover { background: var(--row-hover); }
.markdown-body td code { white-space: nowrap; }

.markdown-body img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.markdown-body hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, var(--border), transparent);
    margin: 2.5rem 0;
}

.markdown-body .katex { font-size: 1em; }
.markdown-body .katex-display {
    margin: 1.5rem 0;
    padding: 0.85rem 0;
    overflow-x: auto;
    overflow-y: hidden;
}

/* ── TOC column ──────────────────────────────────────────────────────────── */

.toc-column {
    width: var(--toc-w);
    flex-shrink: 0;
    position: sticky;
    top: var(--chrome-h);
    padding: 2rem 1.5rem 2rem 0;
    max-height: calc(100vh - var(--chrome-h));
    overflow-y: auto;
    overscroll-behavior: contain;
}

.toc-label {
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-faint);
    margin-bottom: 0.7rem;
    padding-left: 0.8rem;
}

#pageToc { list-style: none; border-left: 1px solid var(--border); }

#pageToc a {
    display: block;
    padding: 0.28rem 0 0.28rem 0.8rem;
    margin-left: -1px;
    font-size: 0.79rem;
    color: var(--text-muted);
    text-decoration: none;
    border-left: 2px solid transparent;
    line-height: 1.45;
    transition: color var(--fast), border-color var(--fast);
}

#pageToc a:hover { color: var(--text); border-left-color: var(--border-strong); }

#pageToc a.active {
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 550;
}

#pageToc .toc-h3 a { padding-left: 1.6rem; font-size: 0.755rem; }

/* ── Pager ───────────────────────────────────────────────────────────────── */

.doc-pager {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 3.5rem;
    padding-top: 1.75rem;
    border-top: 1px solid var(--border);
}

.pager-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.85rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    background: var(--surface);
    transition: all var(--fast);
    max-width: 49%;
}

.pager-link:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.pager-link.next { text-align: right; margin-left: auto; }

.pager-label {
    font-size: 0.68rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}

.pager-title { font-size: 0.9rem; font-weight: 550; }
.pager-link:hover .pager-title { color: var(--accent); }

/* ── States ──────────────────────────────────────────────────────────────── */

.loading {
    color: var(--text-faint);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.loading::before {
    content: '';
    width: 12px;
    height: 12px;
    border: 2px solid var(--border-light);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
    color: var(--danger);
    padding: 1rem;
    background: var(--danger-soft);
    border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
    border-radius: var(--radius);
}

.not-found-panel {
    padding: 3rem 2rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--surface);
    text-align: center;
}

.not-found-panel h2 { font-size: 1.6rem; margin-bottom: 0.5rem; border: none; padding: 0; }
.not-found-panel p { color: var(--text-muted); margin-bottom: 1.5rem; }

.not-found-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

/* ── Home hero ───────────────────────────────────────────────────────────── */

.wiki-hero {
    position: relative;
    margin: 0 0 2.5rem;
    padding: 2.75rem 2.5rem 2.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    background:
        radial-gradient(ellipse 70% 90% at 88% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
        radial-gradient(ellipse 60% 70% at 0% 110%, color-mix(in srgb, var(--purple) 14%, transparent), transparent 70%),
        linear-gradient(180deg, var(--surface-2), var(--surface));
    overflow: hidden;
}

/* Faint grid — reads as a phase plane, matching Flow's dynamics identity. */
.wiki-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(to right, color-mix(in srgb, var(--text) 5%, transparent) 1px, transparent 1px),
        linear-gradient(to bottom, color-mix(in srgb, var(--text) 5%, transparent) 1px, transparent 1px);
    background-size: 34px 34px;
    -webkit-mask-image: radial-gradient(ellipse 75% 75% at 50% 0%, #000, transparent 75%);
    mask-image: radial-gradient(ellipse 75% 75% at 50% 0%, #000, transparent 75%);
    pointer-events: none;
}

.wiki-hero > * { position: relative; }

.markdown-body h1.wiki-hero-brand,
.wiki-hero-brand {
    display: block;
    margin: 0 0 0.55rem;
    font-size: clamp(2.6rem, 1.4rem + 4vw, 3.75rem);
    font-weight: 700;
    letter-spacing: -0.055em;
    line-height: 0.95;
    color: var(--text);
}

.wiki-hero-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid var(--accent-line);
    padding: 0.22rem 0.7rem;
    border-radius: 999px;
    margin-bottom: 1.1rem;
}

.markdown-body p.wiki-hero-title,
.wiki-hero-title {
    display: block;
    font-size: clamp(1.55rem, 1.05rem + 1.8vw, 2.15rem);
    font-weight: 650;
    letter-spacing: -0.03em;
    line-height: 1.15;
    margin: 0 0 1rem;
    color: var(--text-muted);
    text-wrap: balance;
}

.wiki-hero-lead {
    font-size: 1.08rem;
    color: var(--text-muted);
    max-width: 54ch;
    line-height: 1.62;
    margin-bottom: 1.75rem;
    text-wrap: pretty;
}

.wiki-hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 1.85rem;
}

.wiki-cta {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.58rem 1.1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    background: var(--surface);
    color: var(--text);
    font-size: 0.885rem;
    font-weight: 550;
    text-decoration: none;
    transition: all var(--fast);
}

.wiki-cta:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
    transform: translateY(-1px);
}

.wiki-cta-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 650;
    box-shadow: 0 2px 14px -3px var(--accent-line);
}

.wiki-cta-primary:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
    color: var(--on-accent);
    box-shadow: 0 8px 22px -5px var(--accent-line);
}

.wiki-hero-code {
    margin: 0;
    padding: 1.15rem 1.3rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg-far) 82%, transparent);
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 0.83rem;
    line-height: 1.65;
    box-shadow: var(--shadow-md);
}

.wiki-hero-code code { background: none; border: none; padding: 0; }

/* ── Home path strip (not cards — navigation with one job) ─────────────── */

.markdown-body nav.wiki-paths,
.wiki-paths {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    margin: 1.25rem 0 2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--surface);
}

.markdown-body a.wiki-path,
.wiki-path {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 1.25rem 1.35rem 1.35rem;
    text-decoration: none !important;
    color: var(--text);
    border-right: 1px solid var(--border);
    transition: background var(--fast), color var(--fast);
}

.markdown-body a.wiki-path:last-child,
.wiki-path:last-child {
    border-right: none;
}

.markdown-body a.wiki-path:hover,
.wiki-path:hover {
    background: var(--accent-soft);
    color: var(--text);
}

.wiki-path-kicker {
    font-family: var(--mono);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent);
}

.markdown-body a.wiki-path strong,
.wiki-path strong {
    font-size: 1.02rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    color: var(--text);
}

.markdown-body a.wiki-path span:not(.wiki-path-kicker),
.wiki-path span:not(.wiki-path-kicker) {
    font-size: 0.86rem;
    line-height: 1.5;
    color: var(--text-muted);
}

.wiki-section-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.45rem 0.65rem;
    margin: 0.35rem 0 1.75rem;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.wiki-section-foot a {
    font-weight: 600;
}

.wiki-dot {
    color: var(--text-faint);
}

/* ── Card grid (legacy / rare use) ───────────────────────────────────────── */

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

.wiki-card {
    position: relative;
    padding: 1.15rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    overflow: hidden;
    transition: border-color var(--med), transform var(--med), box-shadow var(--med);
}

.wiki-card::after {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--purple));
    transform: scaleX(0);
    transform-origin: 0 50%;
    transition: transform var(--med);
}

.wiki-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.wiki-card:hover::after { transform: scaleX(1); }

.wiki-card strong {
    display: block;
    font-size: 0.95rem;
    font-weight: 650;
    margin-bottom: 0.4rem;
    color: var(--text);
}

.wiki-card p {
    margin: 0;
    font-size: 0.865rem;
    color: var(--text-muted);
    line-height: 1.55;
}

/* ── Demo reel ───────────────────────────────────────────────────────────── */

.wiki-demo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    margin: 1.25rem 0;
}

.markdown-body .wiki-demo {
    margin: 0;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    overflow: hidden;
}

.markdown-body .wiki-demo img {
    display: block;
    width: 100%;
    height: auto;
    margin: 0;
    border: none;
    border-radius: 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg-far);
}

.markdown-body .wiki-demo figcaption {
    padding: 0.7rem 0.9rem;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-muted);
}

.markdown-body .wiki-demo figcaption p { margin: 0; }
.markdown-body .wiki-demo figcaption strong { color: var(--text); }

.markdown-body .wiki-demo {
    transition: border-color var(--med), transform var(--med), box-shadow var(--med);
}

.markdown-body .wiki-demo:hover {
    transform: translateY(-3px);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-md), 0 0 0 1px var(--accent-line);
}

.markdown-body .wiki-demo img {
    transition: filter var(--med), transform var(--med);
}

.markdown-body .wiki-demo:hover img {
    filter: saturate(1.15) brightness(1.03);
}

/* Gallery jump list */
.markdown-body .wiki-demo-links {
    margin: 1rem 0 1.5rem;
    border: 1px dashed var(--border-light);
    border-radius: var(--radius);
    padding: 0.6rem 1.1rem;
    background: color-mix(in srgb, var(--surface-2) 55%, transparent);
}

.markdown-body .wiki-demo-links summary {
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text-muted);
    user-select: none;
    list-style: none;
}

.markdown-body .wiki-demo-links summary::-webkit-details-marker { display: none; }
.markdown-body .wiki-demo-links summary:hover { color: var(--accent); }

/* ── Grammar / EBNF viewer ───────────────────────────────────────────────── */

.grammar-page { margin: 0; }

.grammar-legend {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
}

.grammar-legend h2 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    margin-bottom: 0.75rem;
    font-weight: 700;
    border: none;
    padding: 0;
}

.legend-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem 1.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.legend-grid code { font-size: 0.8rem; }

.grammar-meta { margin-top: 0.85rem; font-size: 0.82rem; color: var(--text-faint); }
.grammar-meta a { color: var(--accent); }

.grammar-layout {
    display: grid;
    grid-template-columns: 210px 1fr;
    gap: 1.25rem;
    align-items: start;
}

.grammar-index {
    position: sticky;
    top: 1rem;
    max-height: 70vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.grammar-index-label {
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    padding: 0.7rem 0.8rem 0.4rem;
}

.grammar-rule-search {
    margin: 0 0.6rem 0.5rem;
    padding: 0.4rem 0.55rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 0.78rem;
}

.grammar-rule-search:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

.grammar-rule-list { list-style: none; overflow-y: auto; flex: 1; padding: 0 0.4rem 0.5rem; }

.grammar-rule-list a {
    display: block;
    padding: 0.22rem 0.5rem;
    font-family: var(--mono);
    font-size: 0.725rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 4px;
}

.grammar-rule-list a:hover { background: var(--accent-soft); color: var(--accent); }

.ebnf-section { margin-bottom: 2rem; }

.ebnf-section h2 {
    font-size: 1rem;
    font-weight: 650;
    color: var(--text-muted);
    margin-bottom: 0.65rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
}

.ebnf-block {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0;
    overflow-x: auto;
    margin: 0;
    font-family: var(--mono);
    font-size: 0.795rem;
    line-height: 1.6;
}

.ebnf-line { display: flex; padding: 0.05rem 1rem 0.05rem 0; }
.ebnf-line:hover { background: var(--code-hover); }

.ebnf-ln {
    width: 2.75rem;
    flex-shrink: 0;
    text-align: right;
    padding-right: 1rem;
    color: var(--text-faint);
    user-select: none;
    opacity: 0.5;
}

.ebnf-content { flex: 1; white-space: pre; }

.ebnf-rule-name { color: var(--syn-func); font-weight: 550; }
.ebnf-def { color: var(--text-faint); }
.ebnf-terminal { color: var(--syn-string); }
.ebnf-nt { color: var(--syn-keyword); }
.ebnf-alt { color: var(--syn-op); }
.ebnf-comment { color: var(--syn-comment); font-style: italic; }
.ebnf-rhs { color: var(--text); }

.code-panel {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.15rem;
    overflow-x: auto;
    font-size: 0.855rem;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */

.site-footer {
    padding: 1.5rem 2rem;
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 50%, transparent);
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-faint);
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.site-footer a { color: var(--text-muted); text-decoration: none; transition: color var(--fast); }
.site-footer a:hover { color: var(--accent); }
.footer-sep { opacity: 0.3; }

/* ── Home page tweaks ────────────────────────────────────────────────────── */

body.page-home .doc-title,
body.page-home .doc-lead,
body.page-home .doc-header { display: none; }

body.page-home .breadcrumb { display: none; }

/* Reference views (EBNF grammar) need the full column, not the reading measure. */
body.page-wide .main-column { max-width: none; }
body.page-wide .markdown-body { max-width: none; }

/* ── Mobile sidebar ──────────────────────────────────────────────────────── */

.sidebar-backdrop { display: none; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 1240px) {
    :root { --toc-w: 200px; }
    .main-column { padding: 2rem 2rem 4rem; }
}

@media (max-width: 1080px) {
    .toc-column { display: none; }
    .main-column { max-width: none; }
}

@media (max-width: 860px) {
    :root { --sidebar-w: 290px; }

    .version-picker { display: none; }
    .search-trigger { min-width: auto; padding: 0.4rem 0.55rem; }
    .search-trigger .search-placeholder,
    .search-trigger kbd { display: none; }
    .btn:not(.btn-icon):not(.btn-accent):not(.theme-toggle) { display: none; }
    .btn-icon { display: inline-flex; }
    .header-inner { gap: 0.5rem; padding: 0 0.9rem; }
    .tab-bar { padding: 0 0.9rem; }

    .sidebar {
        position: fixed;
        left: 0;
        top: var(--chrome-h);
        z-index: 150;
        background: var(--surface);
        transform: translateX(-100%);
        transition: transform var(--med);
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open { transform: translateX(0); }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: var(--chrome-h) 0 0 0;
        z-index: 140;
        background: var(--overlay);
        backdrop-filter: blur(2px);
    }

    body.sidebar-open { overflow: hidden; }

    .main-column { padding: 1.5rem 1.15rem 3rem; }
    .doc-header-row { flex-direction: column; gap: 0.5rem; }
    .doc-edit-link { margin-top: 0; }

    .wiki-hero { padding: 2rem 1.35rem 1.75rem; border-radius: var(--radius); }
    .wiki-hero-actions { gap: 0.5rem; }
    .wiki-cta { flex: 1 1 auto; justify-content: center; }
    .wiki-card-grid { grid-template-columns: 1fr; }
    .markdown-body nav.wiki-paths,
    .wiki-paths {
        grid-template-columns: 1fr;
    }
    .markdown-body a.wiki-path,
    .wiki-path {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .markdown-body a.wiki-path:last-child,
    .wiki-path:last-child {
        border-bottom: none;
    }

    .doc-pager { flex-direction: column; }
    .pager-link { max-width: none; }
    .pager-link.next { text-align: left; }

    .markdown-body pre,
    .code-block { border-radius: var(--radius-sm); }
    .search-overlay { padding-top: 5vh; }
}

/* ── Motion / print ──────────────────────────────────────────────────────── */

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

@media print {
    .site-header,
    .sidebar,
    .toc-column,
    .doc-pager,
    .site-footer,
    .search-overlay,
    .breadcrumb,
    .doc-edit-link,
    .code-copy { display: none !important; }

    body { background: #fff; color: #000; }
    .layout { display: block; }
    .main-column { max-width: none; padding: 0; }
    .markdown-body { max-width: none; font-size: 11pt; }
    .markdown-body a { color: #000; text-decoration: underline; }
    .markdown-body pre,
    .code-block { border: 1px solid #ccc; background: #f6f6f6; page-break-inside: avoid; }
    .markdown-body h2, .markdown-body h3 { page-break-after: avoid; }
}

/* Links into the repository (source files, not docs pages) open on GitHub.
   The marker makes it clear the click leaves the site. */
.repo-source-link::after {
    content: " ↗";
    opacity: 0.55;
    font-size: 0.85em;
}
