/* RASM docs: one stylesheet for the guides and the API reference. */

:root {
    --bg:           #fbfaf7;
    --bg-soft:      #f3f1eb;
    --bg-code:      #f0eee8;
    --bg-raised:    #ffffff;
    --fg:           #1d1d1b;
    --fg-soft:      #55534d;
    --fg-faint:     #8a877e;
    --line:         #dcd8ce;
    --link:         #1f5fbf;
    --accent:       #c2410c;
    --accent-fill:  #fde3d3;

    /* the color code shared by every diagram */
    --cpu:          #2563eb;   --cpu-fill:     #dbe7fd;
    --gpu:          #15803d;   --gpu-fill:     #d5f0dd;
    --mem:          #b45309;   --mem-fill:     #fbe8c8;
    --shader:       #7c3aed;   --shader-fill:  #e9defd;
    --muted-fill:   #ebe8e0;

    /* right / wrong, light rays, shadowed areas */
    --ok:           #0f7b6c;   --ok-fill:      #d3efe9;
    --bad:          #b91c1c;   --bad-fill:     #fbdcdc;
    --light:        #b8860b;   --light-fill:   #fdf0b5;
    --shade:        rgba(29, 29, 27, 0.4);

    --note:         #2563eb;
    --warn:         #b45309;
    --rule:         #b91c1c;

    /* syntax highlighting */
    --tok-kw:       #a626a4;
    --tok-type:     #0e7490;
    --tok-fn:       #1f5fbf;
    --tok-str:      #3f7d20;
    --tok-num:      #b45309;
    --tok-const:    #9a5b00;
    --tok-com:      #8a877e;
    --tok-pre:      #c2410c;
    --tok-ns:       #6b6860;

    --shadow:       0 1px 2px rgba(40, 30, 10, 0.06), 0 6px 20px rgba(40, 30, 10, 0.06);
    --radius:       10px;
    --sidebar:      280px;
    --toc:          230px;
    --content:      860px;
    --mono:         "JetBrains Mono", "Cascadia Code", Consolas, ui-monospace, monospace;
    --sans:         "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:           #15161a;
        --bg-soft:      #1c1e23;
        --bg-code:      #22252b;
        --bg-raised:    #1f2228;
        --fg:           #e8e6e1;
        --fg-soft:      #b3b0a8;
        --fg-faint:     #7f7d77;
        --line:         #33363d;
        --link:         #7fb0ff;
        --accent:       #fb923c;
        --accent-fill:  #40260f;
        --cpu:          #7fa8ff;   --cpu-fill:     #1c2a47;
        --gpu:          #5fd08a;   --gpu-fill:     #173326;
        --mem:          #f0b45a;   --mem-fill:     #3a2a12;
        --shader:       #b794ff;   --shader-fill:  #2c2147;
        --muted-fill:   #2a2c32;
        --ok:           #4fd1b8;   --ok-fill:      #12332e;
        --bad:          #f87171;   --bad-fill:     #401a1a;
        --light:        #f5cf4a;   --light-fill:   #3a3110;
        --shade:        rgba(0, 0, 0, 0.55);
        --note:         #7fa8ff;
        --warn:         #f0b45a;
        --rule:         #f87171;
        --tok-kw:       #c678dd;
        --tok-type:     #56b6c2;
        --tok-fn:       #61afef;
        --tok-str:      #98c379;
        --tok-num:      #d19a66;
        --tok-const:    #e5c07b;
        --tok-com:      #7f848e;
        --tok-pre:      #e06c75;
        --tok-ns:       #9da5b4;
        --shadow:       0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
    }
}

:root[data-theme="dark"] {
    --bg:           #15161a;
    --bg-soft:      #1c1e23;
    --bg-code:      #22252b;
    --bg-raised:    #1f2228;
    --fg:           #e8e6e1;
    --fg-soft:      #b3b0a8;
    --fg-faint:     #7f7d77;
    --line:         #33363d;
    --link:         #7fb0ff;
    --accent:       #fb923c;
    --accent-fill:  #40260f;
    --cpu:          #7fa8ff;   --cpu-fill:     #1c2a47;
    --gpu:          #5fd08a;   --gpu-fill:     #173326;
    --mem:          #f0b45a;   --mem-fill:     #3a2a12;
    --shader:       #b794ff;   --shader-fill:  #2c2147;
    --muted-fill:   #2a2c32;
    --ok:           #4fd1b8;   --ok-fill:      #12332e;
    --bad:          #f87171;   --bad-fill:     #401a1a;
    --light:        #f5cf4a;   --light-fill:   #3a3110;
    --shade:        rgba(0, 0, 0, 0.55);
    --note:         #7fa8ff;
    --warn:         #f0b45a;
    --rule:         #f87171;
    --tok-kw:       #c678dd;
    --tok-type:     #56b6c2;
    --tok-fn:       #61afef;
    --tok-str:      #98c379;
    --tok-num:      #d19a66;
    --tok-const:    #e5c07b;
    --tok-com:      #7f848e;
    --tok-pre:      #e06c75;
    --tok-ns:       #9da5b4;
    --shadow:       0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 24px; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font: 16px/1.65 var(--sans);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-fill); }

/* ---------- layout: sidebar | page | "on this page" ---------- */

.layout {
    display: grid;
    grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--toc);
    min-height: 100vh;
}

#progress {
    position: fixed;
    z-index: 20;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    background: var(--accent);
}

#sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    padding: 22px 16px 40px;
    border-right: 1px solid var(--line);
    background: var(--bg-soft);
    font-size: 14px;
    scrollbar-width: thin;
}

#sidebar .brand {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 0 6px 16px;
    color: var(--fg);
    font-weight: 800;
    font-size: 21px;
    letter-spacing: 0.05em;
}
#sidebar .brand:hover { text-decoration: none; }
#sidebar .brand img {
    align-self: center;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    margin-right: 2px;
}
#sidebar .brand small { color: var(--fg-faint); font-weight: 400; font-size: 13px; letter-spacing: 0; }

#sidebar .search { position: relative; margin: 0 0 6px; }
#sidebar .search input {
    width: 100%;
    font: inherit;
    padding: 7px 34px 7px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    color: var(--fg);
}
#sidebar .search input::placeholder { color: var(--fg-faint); }
#sidebar .search kbd {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--fg-faint);
    font-size: 11px;
    pointer-events: none;
}
#sidebar .no-match { display: none; margin: 14px 8px; color: var(--fg-faint); }
#sidebar.filtering .no-match.show { display: block; }

#sidebar h4 {
    margin: 20px 0 6px 8px;
    color: var(--fg-faint);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

#sidebar ul { list-style: none; margin: 0; padding: 0; }
#sidebar li a {
    display: flex;
    gap: 2px;
    padding: 4px 8px;
    border-radius: 6px;
    color: var(--fg-soft);
    line-height: 1.4;
}
#sidebar li a:hover { background: var(--muted-fill); text-decoration: none; color: var(--fg); }
#sidebar li a.current {
    background: var(--accent-fill);
    color: var(--fg);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--accent);
}
#sidebar .num { flex: none; width: 24px; color: var(--fg-faint); font-variant-numeric: tabular-nums; font-weight: 400; }
#sidebar [hidden] { display: none; }

#sidebar .tools { margin: 26px 6px 0; display: flex; gap: 8px; }
#sidebar button, .menu-button {
    font: inherit;
    font-size: 13px;
    padding: 5px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    color: var(--fg-soft);
    cursor: pointer;
}
#sidebar button:hover { color: var(--fg); border-color: var(--fg-faint); }

main {
    width: 100%;
    max-width: var(--content);
    margin: 0 auto;
    padding: 52px 40px 80px;
}

#toc {
    position: sticky;
    top: 0;
    align-self: start;
    max-height: 100vh;
    overflow-y: auto;
    padding: 58px 20px 40px 0;
    font-size: 13px;
    scrollbar-width: thin;
}
#toc h4 {
    margin: 0 0 10px 12px;
    color: var(--fg-faint);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}
#toc ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
#toc li { max-width: none; }
#toc a {
    display: block;
    margin-left: -2px;
    padding: 4px 0 4px 12px;
    border-left: 2px solid transparent;
    color: var(--fg-faint);
    line-height: 1.35;
}
#toc a:hover { color: var(--fg); text-decoration: none; }
#toc a.active { color: var(--fg); border-left-color: var(--accent); font-weight: 600; }
#toc a.in-rasm { color: var(--accent); }
#toc .top { display: inline-block; margin: 16px 0 0 12px; color: var(--fg-faint); }

.menu-button { display: none; }

/* sidebar + content + toc = 1370px: below that the toc would squeeze the reading column */
@media (max-width: 1369px) {
    .layout { grid-template-columns: var(--sidebar) minmax(0, 1fr); }
    #toc { display: none; }
}

@media (max-width: 900px) {
    .layout { display: block; }
    #sidebar {
        position: fixed;
        z-index: 10;
        left: 0;
        width: min(300px, 85vw);
        transform: translateX(-100%);
        transition: transform 0.2s;
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.25);
    }
    body.nav-open #sidebar { transform: none; }
    main { padding: 64px 16px 64px; }
    .menu-button {
        display: block;
        position: fixed;
        z-index: 11;
        top: 12px;
        left: 12px;
        background: var(--bg-soft);
        color: var(--fg);
    }
}

/* ---------- text ---------- */

.eyebrow {
    display: inline-block;
    margin: 0 0 12px;
    padding: 2px 10px;
    border-radius: 20px;
    background: var(--accent-fill);
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

h1 { margin: 0 0 14px; font-size: 40px; line-height: 1.15; letter-spacing: -0.02em; font-weight: 800; }
h2 {
    position: relative;
    margin: 64px 0 16px;
    padding-top: 22px;
    border-top: 1px solid var(--line);
    font-size: 26px;
    line-height: 1.3;
    letter-spacing: -0.01em;
}
h3 { position: relative; margin: 34px 0 10px; font-size: 19px; }
h2 .n {
    display: inline-block;
    min-width: 30px;
    margin-right: 12px;
    padding: 0 7px;
    border-radius: 8px;
    background: var(--accent);
    color: var(--bg);
    font-size: 0.68em;
    font-weight: 700;
    line-height: 30px;
    text-align: center;
    vertical-align: 3px;
    font-variant-numeric: tabular-nums;
}
h2#in-rasm { border-top: 3px solid var(--accent); }

.anchor {
    margin-left: 8px;
    color: var(--fg-faint);
    font-weight: 400;
    opacity: 0;
    transition: opacity 0.15s;
}
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; }
.anchor:hover { color: var(--accent); text-decoration: none; }

.lead { font-size: 19px; line-height: 1.6; color: var(--fg-soft); margin: 0 0 22px; }

.read-time { margin: -8px 0 22px; color: var(--fg-faint); font-size: 13px; }

p, li { max-width: 72ch; }
var { font-family: Georgia, "Times New Roman", serif; font-size: 1.05em; }

code, kbd, pre, samp { font-family: var(--mono); font-size: 0.88em; }
code, samp { background: var(--bg-code); padding: 1px 5px; border-radius: 4px; }
pre {
    position: relative;
    background: var(--bg-code);
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow-x: auto;
    line-height: 1.5;
}
pre code { background: none; padding: 0; font-size: 1em; }

.code-wrap { position: relative; }
.copy {
    position: absolute;
    top: 8px;
    right: 8px;
    font: 12px var(--sans);
    padding: 2px 9px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--bg);
    color: var(--fg-soft);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}
.code-wrap:hover .copy, .copy:focus { opacity: 1; }
.tok-kw    { color: var(--tok-kw); }
.tok-type  { color: var(--tok-type); }
.tok-fn    { color: var(--tok-fn); }
.tok-str   { color: var(--tok-str); }
.tok-num   { color: var(--tok-num); }
.tok-const { color: var(--tok-const); }
.tok-com   { color: var(--tok-com); font-style: italic; }
.tok-pre   { color: var(--tok-pre); }
.tok-attr  { color: var(--tok-pre); }
.tok-ns    { color: var(--tok-ns); }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }

.c-cpu    { color: var(--cpu); font-weight: 600; }
.c-gpu    { color: var(--gpu); font-weight: 600; }
.c-mem    { color: var(--mem); font-weight: 600; }
.c-shader { color: var(--shader); font-weight: 600; }
.c-ok     { color: var(--ok); font-weight: 600; }
.c-bad    { color: var(--bad); font-weight: 600; }

/* ---------- blocks ---------- */

.tldr {
    margin: 26px 0;
    padding: 18px 22px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    background: var(--bg-raised);
    box-shadow: var(--shadow);
}
.tldr h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.tldr ul, .tldr ol { margin: 0; padding-left: 20px; }
.tldr li { margin: 5px 0; }
.tldr li::marker { color: var(--accent); }

.callout {
    margin: 22px 0;
    padding: 14px 18px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--note);
    border-radius: var(--radius);
    background: var(--bg-soft);
}
.callout > strong:first-child { display: block; margin-bottom: 2px; }
.callout p { margin: 4px 0; }
.callout ul { margin: 6px 0; padding-left: 20px; }
.callout.warn { border-left-color: var(--warn); }
.callout.rule { border-left-color: var(--rule); }
.callout.rule > strong:first-child { color: var(--rule); }
.callout.warn > strong:first-child { color: var(--warn); }

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--fg-soft);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1.5px solid var(--fg-faint);
    background: var(--muted-fill);
}
.legend .cpu    { background: var(--cpu-fill);    border-color: var(--cpu); }
.legend .gpu    { background: var(--gpu-fill);    border-color: var(--gpu); }
.legend .mem    { background: var(--mem-fill);    border-color: var(--mem); }
.legend .shader { background: var(--shader-fill); border-color: var(--shader); }
.legend .hot    { background: var(--accent-fill); border-color: var(--accent); }
.legend .ok     { background: var(--ok-fill);     border-color: var(--ok); }
.legend .bad    { background: var(--bad-fill);    border-color: var(--bad); }
.legend .light  { background: var(--light-fill);  border-color: var(--light); }
.legend .shade  { background: var(--shade);       border-color: var(--fg-faint); }

/* cards on index pages */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin: 18px 0 8px; }
.card {
    display: block;
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-raised);
    color: var(--fg);
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow); }
.card b { display: block; margin-bottom: 4px; }
.card span { color: var(--fg-soft); font-size: 14px; line-height: 1.5; display: block; }
.card .num {
    display: inline-block;
    margin-bottom: 8px;
    padding: 0 8px;
    border-radius: 10px;
    background: var(--muted-fill);
    color: var(--fg-soft);
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* home page */
.hero { margin: 0 0 28px; }
.hero h1 { font-size: 52px; }
.hero h1 span { color: var(--accent); }
.hero .cards { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.hero .card { padding: 20px 22px; border-top: 4px solid var(--accent); }
.hero .card b { font-size: 18px; }
#catalog h3 { display: flex; align-items: baseline; gap: 10px; margin-top: 36px; }
#catalog h3 small { color: var(--fg-faint); font-weight: 400; font-size: 14px; }

/* tables */
table { width: 100%; border-collapse: collapse; margin: 18px 0; font-size: 15px; }
th, td { text-align: left; vertical-align: top; padding: 9px 14px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; color: var(--fg-soft); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.table-wrap {
    margin: 20px 0;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-raised);
}
.table-wrap table { margin: 0; }
.table-wrap th { background: var(--bg-soft); }
.table-wrap tr:last-child td { border-bottom: 0; }
.table-wrap tr:hover td { background: var(--bg-soft); }

/* "Where it lives in code" */
.code-map td:first-child { white-space: nowrap; font-weight: 600; }

/* numbered step list with a rail */
ol.steps { list-style: none; counter-reset: step; padding: 0; margin: 20px 0; }
ol.steps > li { position: relative; padding: 0 0 18px 46px; counter-increment: step; }
ol.steps > li::before {
    content: counter(step);
    position: absolute;
    left: 0;
    top: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    display: grid;
    place-items: center;
    font-size: 14px;
    font-weight: 700;
}
ol.steps > li::after {
    content: "";
    position: absolute;
    left: 14px;
    top: 32px;
    bottom: 2px;
    width: 2px;
    background: var(--line);
}
ol.steps > li:last-child::after { display: none; }
ol.steps > li > b:first-child { display: block; }

/* two columns: "before / after", "CPU / GPU". Add class "bad" / "good" to a column for a wrong / right pair. */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 18px 0; }
.split > div { padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-raised); }
.split h4 { margin: 0 0 6px; }
.split > .bad  { border-top: 4px solid var(--bad); }
.split > .good { border-top: 4px solid var(--ok); }
.split > .bad  > h4 { color: var(--bad); }
.split > .good > h4 { color: var(--ok); }
.split > .bad  > h4::before { content: "✗ "; }
.split > .good > h4::before { content: "✓ "; }
.split svg { display: block; width: 100%; height: auto; margin-bottom: 8px; }
.split p { margin: 6px 0 0; font-size: 15px; }
@media (max-width: 640px) { .split { grid-template-columns: 1fr; } }

/* picture cards: one small drawing + a title + one or two lines. For variants, options, fixes, pitfalls.
   <div class="vgrid"><div class="vcard"><svg viewBox="0 0 240 130">…</svg><h4>Title</h4><p>…</p></div>…</div> */
.vgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); gap: 14px; margin: 20px 0; }
.vgrid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.vgrid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 760px) { .vgrid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.vcard {
    display: flex;
    flex-direction: column;
    padding: 12px 14px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-raised);
}
.vcard > svg {
    display: block;
    width: 100%;
    height: auto;
    margin-bottom: 10px;
    border-radius: 6px;
    background: var(--bg-soft);
}
.vcard h4 { margin: 0 0 4px; font-size: 15px; }
.vcard p { margin: 0; color: var(--fg-soft); font-size: 14px; line-height: 1.5; }
.vcard p + p { margin-top: 6px; }
.vcard .cost { margin-top: auto; padding-top: 8px; font-size: 13px; color: var(--fg-faint); }
.vcard .cost b { color: var(--warn); font-weight: 600; }
.vcard.good { border-top: 4px solid var(--ok); }
.vcard.bad  { border-top: 4px solid var(--bad); }
.vcard.pick { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.vcard .tag { align-self: flex-start; margin-bottom: 6px; }
@media (max-width: 640px) { .vgrid.two { grid-template-columns: 1fr; } }

/* a horizontal chain of steps in HTML, for short pipelines:
   <ol class="flow"><li class="cpu"><b>Step</b><span>detail</span></li>…</ol> */
ol.flow { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 26px; list-style: none; margin: 20px 0; padding: 0; }
ol.flow > li {
    position: relative;
    max-width: none;
    padding: 10px 12px;
    border: 1.5px solid var(--fg-faint);
    border-radius: 8px;
    background: var(--muted-fill);
    font-size: 14px;
    line-height: 1.4;
}
ol.flow > li { overflow-wrap: anywhere; }
ol.flow > li b { display: block; }
ol.flow > li span { color: var(--fg-soft); font-size: 13px; }
ol.flow > li:not(:last-child)::after {
    content: "→";
    position: absolute;
    right: -22px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--fg-faint);
    font-size: 18px;
}
@media (max-width: 640px) {
    ol.flow { grid-auto-flow: row; }
    ol.flow > li:not(:last-child)::after { content: "↓"; right: auto; left: 50%; top: auto; bottom: -25px; transform: none; }
}
ol.flow > .cpu    { background: var(--cpu-fill);    border-color: var(--cpu); }
ol.flow > .gpu    { background: var(--gpu-fill);    border-color: var(--gpu); }
ol.flow > .mem    { background: var(--mem-fill);    border-color: var(--mem); }
ol.flow > .shader { background: var(--shader-fill); border-color: var(--shader); }

/* big numbers: <div class="stats"><div><b>16 MiB</b><span>map memory</span></div>…</div> */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 20px 0; }
.stats > div {
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-raised);
}
.stats b { display: block; font-size: 24px; line-height: 1.2; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stats span { display: block; margin-top: 4px; color: var(--fg-soft); font-size: 13px; line-height: 1.4; }
.stats small { display: block; margin-top: 4px; color: var(--fg-faint); font-family: var(--mono); font-size: 12px; }

/* a formula with its terms explained beside it:
   <div class="formula"><p class="eq">lit = d ≥ stored</p><dl><dt>d</dt><dd>…</dd>…</dl></div> */
.formula {
    margin: 20px 0;
    padding: 16px 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-raised);
}
.formula .eq { margin: 0 0 10px; font-family: var(--mono); font-size: 17px; font-weight: 600; max-width: none; overflow-x: auto; white-space: nowrap; }
.formula .eq + .eq { margin-top: -4px; }
.formula dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 14px; }
.formula dt { font-family: var(--mono); color: var(--accent); font-weight: 600; }
.formula dd { margin: 0; color: var(--fg-soft); }

/* symptom → cause list: <dl class="pitfalls"><div><dt>What you see</dt><dd>Why, and the fix</dd></div>…</dl> */
dl.pitfalls { display: grid; gap: 10px; margin: 20px 0; }
dl.pitfalls > div {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-raised);
    overflow: hidden;
}
dl.pitfalls dt { padding: 10px 14px 10px 40px; position: relative; background: var(--bad-fill); font-weight: 600; font-size: 15px; }
dl.pitfalls dt::before { content: "!"; position: absolute; left: 12px; top: 11px; width: 18px; height: 18px; border-radius: 50%; background: var(--bad); color: var(--bg); font-size: 12px; line-height: 18px; text-align: center; }
dl.pitfalls dd { margin: 0; padding: 10px 14px; color: var(--fg-soft); font-size: 15px; }
@media (max-width: 640px) { dl.pitfalls > div { grid-template-columns: 1fr; } }

/* ---------- figures ---------- */

main { counter-reset: fig; }
figure { margin: 26px 0; }
figure.diagram {
    position: relative;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-raised);
    box-shadow: var(--shadow);
    overflow-x: auto;
}
figure.diagram > figcaption { counter-increment: fig; }
figure svg { display: block; width: 100%; height: auto; margin: 0 auto; }
figcaption { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); color: var(--fg-soft); font-size: 14px; }
figure.diagram > figcaption::before { content: "Fig. " counter(fig) "  "; color: var(--accent); font-weight: 700; white-space: pre; }

.zoom {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--bg);
    color: var(--fg-soft);
    font-size: 15px;
    line-height: 1;
    cursor: zoom-in;
    opacity: 0;
    transition: opacity 0.15s;
}
figure.diagram:hover .zoom, .zoom:focus { opacity: 1; }
/* touch screens have no hover: keep both buttons visible */
@media (hover: none) { .zoom, .copy { opacity: 1; } }

#lightbox {
    position: fixed;
    z-index: 30;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(10, 10, 12, 0.8);
    cursor: zoom-out;
}
#lightbox > div {
    width: min(1500px, 100%);
    max-height: 100%;
    overflow: auto;
    padding: 24px;
    border-radius: var(--radius);
    background: var(--bg-raised);
}
#lightbox svg { display: block; width: 100%; height: auto; }

/* SVG vocabulary: use these classes inside diagrams so every guide looks the same */
svg { font-family: var(--sans); font-size: 13px; }
svg text { fill: var(--fg); }
svg text.small { font-size: 11px; fill: var(--fg-soft); }
svg text.title { font-weight: 700; }
svg text.big { font-size: 16px; font-weight: 700; }
svg text.mono { font-family: var(--mono); font-size: 12px; }
svg text.mid { text-anchor: middle; }
svg text.end { text-anchor: end; }
/* text that sits on top of lines: a background-colored outline keeps it readable */
svg text.halo { paint-order: stroke; stroke: var(--bg-raised); stroke-width: 4px; stroke-linejoin: round; }

svg .box     { fill: var(--muted-fill);  stroke: var(--fg-faint); stroke-width: 1.5; }
svg .cpu     { fill: var(--cpu-fill);    stroke: var(--cpu);      stroke-width: 1.5; }
svg .gpu     { fill: var(--gpu-fill);    stroke: var(--gpu);      stroke-width: 1.5; }
svg .mem     { fill: var(--mem-fill);    stroke: var(--mem);      stroke-width: 1.5; }
svg .shader  { fill: var(--shader-fill); stroke: var(--shader);   stroke-width: 1.5; }
svg .ghost   { fill: none; stroke: var(--fg-faint); stroke-width: 1.2; stroke-dasharray: 5 4; }
svg .hot     { fill: none; stroke: var(--accent); stroke-width: 2.5; }
svg .zone    { fill: var(--bg-soft); stroke: var(--line); stroke-width: 1; }
/* drawing real things: surfaces, solid objects, light, shadow, right and wrong */
svg .accent  { fill: var(--accent-fill); stroke: var(--accent);   stroke-width: 1.5; }
svg .ok      { fill: var(--ok-fill);     stroke: var(--ok);       stroke-width: 1.5; }
svg .bad     { fill: var(--bad-fill);    stroke: var(--bad);      stroke-width: 1.5; }
svg .light   { fill: var(--light-fill);  stroke: var(--light);    stroke-width: 1.5; }
svg .shade   { fill: var(--shade);       stroke: none; }
svg .lit     { fill: var(--light-fill);  stroke: none; }
svg .solid   { fill: var(--fg-faint);    stroke: var(--fg-soft);  stroke-width: 1.5; }
svg .paper   { fill: var(--bg-raised);   stroke: var(--line);     stroke-width: 1; }
svg .surface { fill: none; stroke: var(--fg); stroke-width: 3; stroke-linecap: round; }
svg .grid    { fill: none; stroke: var(--line); stroke-width: 1; }
svg .thick   { stroke-width: 3; }
svg .thin    { stroke-width: 1; }
svg .nofill  { fill: none; }
svg .o-25    { opacity: 0.25; }
svg .o-50    { opacity: 0.5; }
svg .o-75    { opacity: 0.75; }
/* a numbered marker: <circle r="10" class="badge"/><text class="badge-n">1</text> */
svg .badge   { fill: var(--accent); stroke: none; }
svg text.badge-n { fill: var(--bg-raised); font-size: 12px; font-weight: 700; text-anchor: middle; }

svg .arrow        { fill: none; stroke: var(--fg-soft); stroke-width: 1.6; }
svg .arrow.cpu    { stroke: var(--cpu); fill: none; }
svg .arrow.gpu    { stroke: var(--gpu); fill: none; }
svg .arrow.mem    { stroke: var(--mem); fill: none; }
svg .arrow.shader { stroke: var(--shader); fill: none; }
svg .arrow.hot    { stroke: var(--accent); fill: none; }
svg .arrow.ok     { stroke: var(--ok); fill: none; }
svg .arrow.bad    { stroke: var(--bad); fill: none; }
svg .arrow.light  { stroke: var(--light); fill: none; }
svg .arrow.thick  { stroke-width: 3; }
svg .dashed       { stroke-dasharray: 6 4; }
svg :where(line.dashed, path.dashed, rect.dashed, circle.dashed, polygon.dashed, polyline.dashed) { stroke: var(--fg-faint); fill: none; }
/* data moving along an arrow */
svg .flowing { stroke-dasharray: 6 5; animation: flowing 1.2s linear infinite; }
@keyframes flowing { to { stroke-dashoffset: -22; } }
@media (prefers-reduced-motion: reduce) { svg .flowing { animation: none; } html { scroll-behavior: auto; } }

svg .head         { fill: var(--fg-soft); }
svg .head.cpu     { fill: var(--cpu); stroke: none; }
svg .head.gpu     { fill: var(--gpu); stroke: none; }
svg .head.mem     { fill: var(--mem); stroke: none; }
svg .head.shader  { fill: var(--shader); stroke: none; }
svg .head.hot     { fill: var(--accent); stroke: none; }
svg .head.ok      { fill: var(--ok); stroke: none; }
svg .head.bad     { fill: var(--bad); stroke: none; }
svg .head.light   { fill: var(--light); stroke: none; }
/* "svg text.x" so a color also wins over "svg text.small" */
svg .t-cpu,    svg text.t-cpu    { fill: var(--cpu); }
svg .t-gpu,    svg text.t-gpu    { fill: var(--gpu); }
svg .t-mem,    svg text.t-mem    { fill: var(--mem); }
svg .t-shader, svg text.t-shader { fill: var(--shader); }
svg .t-hot,    svg text.t-hot    { fill: var(--accent); }
svg .t-ok,     svg text.t-ok     { fill: var(--ok); }
svg .t-bad,    svg text.t-bad    { fill: var(--bad); }
svg .t-light,  svg text.t-light  { fill: var(--light); }
svg .t-faint,  svg text.t-faint  { fill: var(--fg-faint); }

svg a:hover rect, svg a:hover circle { stroke-width: 2.5; }
svg a:hover text { text-decoration: underline; }

/* ---------- stepper: click through the states of one diagram ---------- */

.stepper { margin: 26px 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg-raised); box-shadow: var(--shadow); }
.stepper .stepper-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--bg-soft);
    font-size: 14px;
}
.stepper .stepper-bar .label { flex: 1; font-weight: 600; }
.stepper .stepper-bar .count { color: var(--fg-faint); font-variant-numeric: tabular-nums; }
.stepper .dots { display: flex; gap: 5px; }
.stepper .dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); cursor: pointer; }
.stepper .dots i.on { background: var(--accent); }
.stepper button {
    font: inherit;
    padding: 3px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--bg);
    color: var(--fg);
    cursor: pointer;
}
.stepper button:hover:not(:disabled) { border-color: var(--accent); }
.stepper button:disabled { opacity: 0.4; cursor: default; }
.stepper .step { padding: 18px; }
.stepper.js .step { display: none; }
.stepper.js .step.active { display: block; }
.stepper .step > p { margin: 12px 0 0; color: var(--fg-soft); font-size: 15px; }
.stepper .step > h4 { margin: 0 0 10px; }
.stepper.js .step > h4 { display: none; }
.stepper .step > svg { display: block; width: 100%; height: auto; }

/* ---------- lab: an interactive picture, built by docs/assets/lab.js ----------
   <figure class="lab" data-lab="name" data-title="Title"><figcaption>What to try.</figcaption></figure> */

figure.lab {
    margin: 26px 0;
    border: 1px solid var(--line);
    border-top: 3px solid var(--accent);
    border-radius: var(--radius);
    background: var(--bg-raised);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.lab-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--bg-soft); font-size: 15px; }
.lab-badge {
    padding: 1px 9px;
    border-radius: 20px;
    background: var(--accent);
    color: var(--bg);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}
.lab-stage { padding: 16px 16px 6px; }
.lab-stage svg { display: block; width: 100%; height: auto; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.lab-stage canvas { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 6px; }
.lab-stage:has(> canvas + svg), .lab-stage:has(> svg + canvas) { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; align-items: center; }

.lab-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; padding: 10px 16px; border-top: 1px dashed var(--line); font-size: 14px; }
.lab-control { display: flex; align-items: center; gap: 8px; color: var(--fg-soft); }
.lab-control > span { white-space: nowrap; }
.lab-control input[type="range"] { width: 150px; accent-color: var(--accent); cursor: pointer; }
.lab-control input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.lab-control output { min-width: 46px; color: var(--fg); font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.lab-check { cursor: pointer; }
.lab-seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lab-seg button, .lab-button {
    font: inherit;
    font-size: 13px;
    padding: 4px 12px;
    border: 0;
    background: var(--bg);
    color: var(--fg-soft);
    cursor: pointer;
}
.lab-seg button + button { border-left: 1px solid var(--line); }
.lab-seg button:hover, .lab-button:hover { color: var(--fg); }
.lab-seg button[aria-pressed="true"] { background: var(--accent-fill); color: var(--accent); font-weight: 600; }
.lab-button { border: 1px solid var(--line); border-radius: 8px; color: var(--fg); }
.lab-button:hover { border-color: var(--accent); }
.lab-play { min-width: 86px; }

.lab-readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 1px; border-top: 1px solid var(--line); background: var(--line); }
.lab-readouts > div { padding: 9px 16px; background: var(--bg-raised); }
.lab-readouts b { display: block; font-size: 19px; line-height: 1.25; font-variant-numeric: tabular-nums; }
.lab-readouts span { display: block; color: var(--fg-soft); font-size: 12px; line-height: 1.35; }

.lab-note { margin: 0; max-width: none; padding: 9px 16px; border-top: 1px solid var(--line); background: var(--bg-soft); font-size: 14px; }
figure.lab > figcaption { margin: 0; padding: 10px 16px 12px; border-top: 1px dashed var(--line); }
figure.lab > figcaption::before { content: "Try  "; color: var(--accent); font-weight: 700; white-space: pre; }
.lab-error-text { margin: 0; padding: 10px 16px; background: var(--bad-fill); color: var(--bad); font-size: 14px; }

/* parts of a lab picture that the reader moves or clicks */
svg .handle { fill: var(--accent); stroke: var(--bg-raised); stroke-width: 2.5; cursor: grab; touch-action: none; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35)); }
svg .handle:hover, svg .handle:focus-visible { stroke: var(--fg); outline: none; }
svg .handle.dragging { cursor: grabbing; }
svg .pick { cursor: pointer; }
svg .pick:hover, svg .pick:focus-visible { stroke-width: 3; outline: none; }
svg g.pick:hover > :is(rect, circle, polygon), svg g.pick:focus-visible > :is(rect, circle, polygon) { stroke-width: 3; }
svg g.pick text { pointer-events: none; }
svg .off { opacity: 0.28; }
svg .hide { display: none; }

@media print { .lab-controls, .lab-badge { display: none; } figure.lab { box-shadow: none; break-inside: avoid; } }

/* ---------- API reference ---------- */

.api { margin: 18px 0 28px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg-raised); scroll-margin-top: 24px; }
.api:target { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.api > .sig {
    margin: 0;
    padding: 10px 14px;
    background: var(--bg-code);
    font-family: var(--mono);
    font-size: 14px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    overflow-x: auto;
    white-space: pre;
}
.api > .body { padding: 10px 16px 6px; }
.api > .body p { margin: 6px 0 10px; }
.api dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 8px 0 10px; font-size: 15px; }
.api dt { font-family: var(--mono); font-size: 14px; color: var(--fg); }
.api dd { margin: 0; color: var(--fg-soft); }

.tag {
    display: inline-block;
    padding: 0 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    vertical-align: 2px;
    background: var(--muted-fill);
    color: var(--fg-soft);
}
.tag.main-thread { background: var(--cpu-fill); color: var(--cpu); }
.tag.async       { background: var(--gpu-fill); color: var(--gpu); }
.tag.low-level   { background: var(--shader-fill); color: var(--shader); }
.tag.good        { background: var(--ok-fill); color: var(--ok); }
.tag.bad         { background: var(--bad-fill); color: var(--bad); }

/* ---------- footer ---------- */

.page-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 64px; }
.page-nav a {
    display: block;
    padding: 14px 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-raised);
    color: var(--fg);
    font-weight: 600;
}
.page-nav a:hover { border-color: var(--accent); text-decoration: none; }
.page-nav small { display: block; color: var(--fg-faint); font-weight: 400; }
.page-nav .next { text-align: right; grid-column: 2; }

.sync-stamp { margin-top: 26px; color: var(--fg-faint); font-size: 13px; }

@media print {
    #sidebar, #toc, #progress, .menu-button, .zoom, .copy, .page-nav { display: none; }
    .layout { display: block; }
    main { max-width: none; padding: 0; }
    figure.diagram, .stepper, .tldr { box-shadow: none; break-inside: avoid; }
    .stepper.js .step { display: block; }
    .stepper.js .step > h4 { display: block; }
}
