
/* ============================================================
   DESIGN TOKENS — ElevenLabs editorial dialect
   Off-white canvas · warm near-black ink · pastel orbs.
   Legacy variable names (--bg-base, --accent-cyan, ...) are
   preserved as aliases mapped onto editorial values so the
   inline `style="..."` references throughout the document and
   the JS-rendered charts inherit the new palette automatically.
   ============================================================ */
:root {
    /* — Editorial canon — */
    --canvas:               #f5f5f5;
    --canvas-soft:          #fafafa;
    --canvas-deep:          #0c0a09;
    --surface-card:         #ffffff;
    --surface-strong:       #f0efed;
    --surface-dark:         #0c0a09;
    --surface-dark-elev:    #1c1917;

    --hairline:             #e7e5e4;
    --hairline-soft:        #f0efed;
    --hairline-strong:      #d6d3d1;

    --ink:                  #0c0a09;
    --ink-soft:             #292524;
    --body:                 #4e4e4e;
    --muted:                #777169;
    --muted-soft:           #a8a29e;

    --on-ink:               #ffffff;
    --on-dark:              #ffffff;
    --on-dark-soft:         #a8a29e;

    /* — Pastel atmospheric orbs (decoration only) — */
    --orb-mint:             #a7e5d3;
    --orb-peach:            #f4c5a8;
    --orb-lavender:         #c8b8e0;
    --orb-sky:              #a8c8e8;
    --orb-rose:             #e8b8c4;

    /* — Deep ink-tinted accents (text-legible on white) — */
    --ink-sky:              #2c5282;
    --ink-peach:            #9c4221;
    --ink-mint:             #276749;
    --ink-lavender:         #553c9a;
    --ink-rose:             #9b2c5b;
    --ink-amber:            #92400e;

    /* — Legacy aliases · DO NOT REMOVE — */
    --bg-base:              #f5f5f5;          /* canvas */
    --bg-elev-1:            #ffffff;          /* card */
    --bg-elev-2:            #fafafa;          /* soft */
    --bg-elev-3:            #f0efed;          /* strong */
    --bg-code:              #0c0a09;          /* code surface stays dark — IDE legibility */
    --border-subtle:        #f0efed;
    --border-medium:        #e7e5e4;
    --border-strong:        #d6d3d1;

    --text-primary:         #0c0a09;
    --text-secondary:       #4e4e4e;
    --text-tertiary:        #777169;
    --text-muted:           #a8a29e;

    --accent-cyan:          #2c5282;   /* deep sky — text-safe */
    --accent-cyan-dim:      #3b6ea5;
    --accent-amber:         #9c4221;   /* deep peach */
    --accent-amber-dim:     #7b3417;
    --accent-green:         #276749;   /* deep mint */
    --accent-purple:        #553c9a;   /* deep lavender */
    --accent-red:           #9b2c5b;   /* deep rose */
    --accent-yellow:        #92400e;   /* deep amber */

    /* Pastel forms for backgrounds, swatches, diagram fills */
    --accent-cyan-soft:     #a8c8e8;
    --accent-amber-soft:    #f4c5a8;
    --accent-green-soft:    #a7e5d3;
    --accent-purple-soft:   #c8b8e0;
    --accent-red-soft:      #e8b8c4;
    --accent-yellow-soft:   #f4d8a8;

    --glow-cyan:            0 4px 16px rgba(44, 82, 130, 0.08);
    --glow-amber:           0 4px 16px rgba(156, 66, 33, 0.08);
    --drop-soft:            0 4px 16px rgba(12, 10, 9, 0.04);
    --drop-card:            0 1px 2px rgba(12, 10, 9, 0.04), 0 4px 24px rgba(12, 10, 9, 0.04);

    --font-display:         'EB Garamond', 'GT Sectra', 'Times New Roman', serif;
    --font-serif:           'EB Garamond', 'GT Sectra', Georgia, serif;
    --font-sans:            'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono:            'JetBrains Mono', 'Fira Code', Menlo, monospace;
    --font-code:            'JetBrains Mono', 'Fira Code', Menlo, monospace;

    --sidebar-w:            300px;
    --content-max:          880px;
    --radius-md:            8px;
    --radius-lg:            12px;
    --radius-xl:            16px;
    --radius-xxl:           24px;
    --radius-pill:          9999px;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0; padding: 0;
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
    letter-spacing: 0.16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}
::selection { background: var(--orb-peach); color: var(--ink); }

/* PROGRESS BAR — a slim ink line, no glow */
#progress-bar {
    position: fixed; top: 0; left: 0;
    height: 2px; width: 0%;
    background: var(--ink);
    z-index: 1000;
    transition: width 0.05s linear;
}

/* SIDEBAR — pure white panel, hairline divider */
#sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sidebar-w); height: 100vh;
    background: var(--surface-card);
    border-right: 1px solid var(--hairline);
    padding: 36px 24px 36px 32px;
    overflow-y: auto;
    z-index: 50;
}
#sidebar::-webkit-scrollbar { width: 6px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: var(--hairline-strong); border-radius: 3px; }

.sidebar-title {
    font-family: var(--font-display);
    font-size: 22px; font-weight: 300;
    color: var(--ink); letter-spacing: -0.44px;
    margin: 0 0 6px 0; line-height: 1.15;
}
.sidebar-subtitle {
    font-family: var(--font-sans); font-size: 11px;
    color: var(--muted); text-transform: uppercase;
    font-weight: 500;
    letter-spacing: 0.88px; margin: 0 0 26px 0;
}
.sidebar-divider { height: 1px; background: var(--hairline); margin: 18px 0; }
.sidebar-nav { list-style: none; padding: 0; margin: 0; }
.sidebar-nav > li { margin-bottom: 2px; }
.sidebar-nav a.chapter-link {
    display: flex; align-items: baseline;
    text-decoration: none; color: var(--body);
    font-family: var(--font-sans); font-size: 13px;
    font-weight: 500;
    padding: 9px 12px;
    border-radius: var(--radius-md);
    transition: background-color 0.18s ease, color 0.18s ease;
    line-height: 1.4;
    border-bottom: none;
}
.sidebar-nav a.chapter-link:hover {
    color: var(--ink); background: var(--canvas);
}
.sidebar-nav a.chapter-link.active {
    color: var(--ink); background: var(--surface-strong);
}
.ch-num {
    color: var(--muted-soft); font-weight: 500;
    margin-right: 10px; min-width: 22px; font-size: 11px;
    font-feature-settings: "tnum" 1;
    letter-spacing: 0.6px;
}
.sidebar-nav a.chapter-link.active .ch-num { color: var(--ink); }
.sidebar-sublist {
    list-style: none; padding: 4px 0 6px 22px; margin: 4px 0 8px 16px;
    border-left: 1px solid var(--hairline);
}
.sidebar-sublist a {
    display: block; color: var(--muted);
    text-decoration: none; font-family: var(--font-sans);
    font-weight: 400;
    font-size: 12px; padding: 5px 10px; border-radius: 6px;
    transition: color 0.18s ease, background-color 0.18s ease;
    line-height: 1.4;
    border-bottom: none;
}
.sidebar-sublist a:hover { color: var(--ink); background: var(--canvas); }
.sidebar-sublist a.active { color: var(--ink); font-weight: 500; }

.gpu-badge {
    margin-top: 32px; padding: 14px 16px;
    background: var(--canvas);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    font-family: var(--font-sans);
}
.gpu-badge-label {
    font-size: 10px; color: var(--muted);
    text-transform: uppercase; font-weight: 600;
    letter-spacing: 0.96px; margin-bottom: 6px;
}
.gpu-badge-value {
    font-size: 13px; color: var(--ink);
    font-weight: 500; letter-spacing: 0.13px;
}

/* CONTENT — generous editorial pacing on off-white canvas */
#content {
    margin-left: var(--sidebar-w);
    padding: 96px 80px 160px 80px;
    max-width: calc(var(--content-max) + var(--sidebar-w) + 160px);
}

/* COVER — editorial hero with peach atmospheric orb */
.cover {
    position: relative;
    margin-bottom: 96px;
    padding: 56px 0 80px 0;
    border-bottom: 1px solid var(--hairline);
    overflow: hidden;
}
.cover::before {
    content: '';
    position: absolute;
    top: -120px; right: -120px;
    width: 520px; height: 520px;
    background: radial-gradient(circle at center, var(--orb-peach) 0%, rgba(244,197,168,0.45) 35%, rgba(244,197,168,0) 68%);
    filter: blur(6px);
    pointer-events: none;
    z-index: 0;
}
.cover::after {
    content: '';
    position: absolute;
    top: 220px; left: -200px;
    width: 460px; height: 460px;
    background: radial-gradient(circle at center, var(--orb-mint) 0%, rgba(167,229,211,0.4) 38%, rgba(167,229,211,0) 70%);
    filter: blur(8px);
    pointer-events: none;
    z-index: 0;
}
.cover > * { position: relative; z-index: 1; }
.cover-eyebrow {
    font-family: var(--font-sans); font-size: 12px;
    color: var(--muted); text-transform: uppercase;
    font-weight: 600; letter-spacing: 0.96px;
    margin-bottom: 28px;
}
.cover-title {
    font-family: var(--font-display);
    font-size: 72px; font-weight: 300;
    line-height: 1.05;
    margin: 0 0 20px 0;
    letter-spacing: -2.16px;
    color: var(--ink);
    background: none;
    -webkit-text-fill-color: var(--ink);
}
.cover-subtitle {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 22px; font-weight: 300;
    color: var(--body);
    margin: 0 0 40px 0;
    letter-spacing: -0.22px;
    line-height: 1.35;
    max-width: 640px;
}
.cover-meta {
    display: flex; flex-wrap: wrap;
    gap: 48px; margin-top: 56px;
    padding-top: 32px;
    border-top: 1px solid var(--hairline);
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--body);
}
.cover-meta-item { display: flex; flex-direction: column; gap: 6px; }
.cover-meta-label {
    font-size: 11px; text-transform: uppercase;
    font-weight: 600; letter-spacing: 0.88px;
    color: var(--muted);
}
.cover-meta-value { color: var(--ink); font-weight: 500; letter-spacing: 0.13px; }

/* CHAPTER — print-magazine pacing, single atmospheric orb */
.chapter {
    position: relative;
    margin-bottom: 128px;
    padding-top: 48px;
}
.chapter-header {
    position: relative;
    margin-bottom: 72px;
    padding: 56px 0 40px 0;
    border-bottom: 1px solid var(--hairline);
    overflow: hidden;
}
.chapter-num-bg {
    position: absolute; top: -40px; right: -32px;
    font-family: var(--font-display);
    font-size: 220px; font-weight: 300;
    color: var(--surface-strong);
    line-height: 1; pointer-events: none; z-index: 0;
    letter-spacing: -8px;
    user-select: none;
}
.chapter-eyebrow {
    font-family: var(--font-sans); font-size: 12px;
    color: var(--muted); text-transform: uppercase;
    font-weight: 600; letter-spacing: 0.96px;
    margin-bottom: 16px;
    position: relative; z-index: 1;
}
.chapter-title {
    font-family: var(--font-display);
    font-size: 56px; font-weight: 300;
    margin: 0 0 28px 0; line-height: 1.08;
    letter-spacing: -1.12px;
    color: var(--ink);
    position: relative; z-index: 1;
}
.chapter-goal {
    font-family: var(--font-display);
    font-style: italic;
    color: var(--body);
    font-size: 19px;
    font-weight: 400;
    line-height: 1.55;
    letter-spacing: -0.19px;
    border-left: 2px solid var(--ink);
    padding: 4px 0 4px 22px;
    margin: 32px 0 0 0;
    position: relative; z-index: 1;
    max-width: 740px;
}
.chapter-goal strong { color: var(--ink); font-weight: 500; font-style: normal; }

/* SECTIONS */
.section { margin-bottom: 80px; scroll-margin-top: 48px; }
h2.section-title {
    font-family: var(--font-display);
    font-size: 36px; font-weight: 300;
    color: var(--ink);
    margin: 0 0 12px 0;
    letter-spacing: -0.36px;
    line-height: 1.17;
}
h2.section-title .sec-num {
    font-family: var(--font-sans);
    color: var(--muted);
    font-weight: 500;
    font-size: 16px;
    letter-spacing: 0.16px;
    margin-right: 16px;
    display: inline-block;
    transform: translateY(-6px);
    text-transform: uppercase;
}
.section-subtitle {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 18px;
    color: var(--muted);
    font-weight: 400;
    margin: 0 0 36px 0;
    letter-spacing: -0.18px;
    line-height: 1.4;
    text-transform: none;
}
h3 {
    font-family: var(--font-display);
    font-size: 26px; font-weight: 300;
    color: var(--ink);
    margin: 48px 0 18px 0;
    letter-spacing: -0.26px;
    line-height: 1.2;
}
h4 {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    margin: 32px 0 12px 0;
    text-transform: uppercase;
    letter-spacing: 1.04px;
}

p {
    margin: 0 0 18px 0;
    color: var(--ink);
    font-size: 16px;
    line-height: 1.65;
    letter-spacing: 0.16px;
}
strong { color: var(--ink-soft); font-weight: 600; }
em { color: var(--ink); font-style: italic; font-family: var(--font-display); font-size: 1.02em; }
.inline-code, p code, li code, td code {
    font-family: var(--font-mono);
    font-size: 0.86em;
    background: var(--surface-strong);
    color: var(--ink);
    padding: 1px 7px;
    border-radius: 4px;
    border: 1px solid var(--hairline);
    letter-spacing: 0;
}
ul, ol { margin: 0 0 18px 0; padding-left: 24px; }
li {
    margin-bottom: 8px;
    color: var(--ink);
    font-size: 16px;
    line-height: 1.6;
    letter-spacing: 0.16px;
}
li::marker { color: var(--muted-soft); }
a {
    color: var(--ink);
    text-decoration: none;
    border-bottom: 1px solid var(--hairline-strong);
    transition: border-color 0.18s ease, color 0.18s ease;
}
a:hover { color: var(--ink); border-bottom-color: var(--ink); }

/* TABLES — quiet white surfaces, hairline ruling */
.table-wrap {
    margin: 32px 0; overflow-x: auto;
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    background: var(--surface-card);
}
table {
    width: 100%; border-collapse: collapse;
    font-family: var(--font-sans); font-size: 14px;
}
th {
    background: var(--canvas);
    color: var(--muted);
    text-align: left;
    padding: 14px 18px;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.88px;
    border-bottom: 1px solid var(--hairline);
}
td {
    padding: 14px 18px;
    color: var(--ink);
    border-bottom: 1px solid var(--hairline-soft);
    vertical-align: top;
    letter-spacing: 0.14px;
    line-height: 1.5;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--canvas-soft); }
td.num {
    text-align: right;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--ink-peach);
    font-weight: 500;
}

/* CODE — dark IDE surface (the brand's allowed dark moment) */
.code-block {
    position: relative; margin: 32px 0;
    background: var(--canvas-deep);
    border: 1px solid var(--canvas-deep);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--drop-card);
}
.code-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 18px;
    background: var(--surface-dark-elev);
    border-bottom: 1px solid rgba(12, 10, 9, 0.05);
    font-family: var(--font-sans); font-size: 11px;
}
.code-title {
    color: var(--on-dark-soft);
    text-transform: uppercase;
    letter-spacing: 0.88px;
    font-size: 10px;
    font-weight: 600;
}
.code-actions { display: flex; gap: 10px; align-items: center; }
.code-lang {
    color: var(--on-dark);
    font-weight: 500;
    background: rgba(255,255,255,0.07);
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
}
.code-copy {
    background: transparent;
    border: 1px solid rgba(12, 10, 9, 0.12);
    color: var(--on-dark-soft);
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    transition: color 0.18s ease, border-color 0.18s ease;
}
.code-copy:hover { color: var(--on-dark); border-color: rgba(255,255,255,0.4); }
.code-copy.copied { color: #a7e5d3; border-color: #a7e5d3; }
.code-body {
    display: grid; grid-template-columns: auto 1fr;
    overflow-x: auto;
    font-family: var(--font-mono); font-size: 13px;
    line-height: 1.6;
}
.code-linenums {
    background: rgba(12, 10, 9, 0.04);
    color: rgba(255,255,255,0.28);
    padding: 16px 14px;
    user-select: none; text-align: right;
    border-right: 1px solid rgba(12, 10, 9, 0.06);
    font-size: 12px;
}
.code-linenums div { line-height: 1.6; }
.code-pre {
    margin: 0; padding: 16px 20px; overflow-x: auto;
    color: #e7e5e4; white-space: pre;
}

/* Syntax tokens — muted pastel-tinted on dark surface */
.tok-kw    { color: #e8b8c4; font-weight: 500; }   /* rose pastel */
.tok-cuda  { color: #a8c8e8; font-weight: 500; }   /* sky pastel */
.tok-type  { color: #f4c5a8; }                     /* peach */
.tok-fn    { color: #c8b8e0; }                     /* lavender */
.tok-str   { color: #f4d8a8; }                     /* warm yellow */
.tok-num   { color: #ffffff; }
.tok-com   { color: #a7e5d3; font-style: italic; } /* mint */
.tok-ptx   { color: #a8c8e8; font-weight: 500; }
.tok-preproc { color: #f4c5a8; }

/* CALLOUTS — quiet hairlined card, single soft pastel bar */
.callout {
    margin: 32px 0; padding: 24px 28px;
    border-radius: var(--radius-xl);
    background: var(--surface-card);
    border: 1px solid var(--hairline);
    border-left: 3px solid var(--orb-sky);
    position: relative;
}
.callout.warn   { border-left-color: var(--orb-peach); }
.callout.danger { border-left-color: var(--orb-rose); }
.callout.tip    { border-left-color: var(--orb-mint); }
.callout-label {
    font-family: var(--font-sans); font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.88px;
    margin-bottom: 8px; color: var(--ink-sky);
    font-weight: 600;
}
.callout.warn .callout-label   { color: var(--ink-peach); }
.callout.danger .callout-label { color: var(--ink-rose); }
.callout.tip .callout-label    { color: var(--ink-mint); }
.callout p:last-child { margin-bottom: 0; }

/* CHECKPOINT — soft canvas card, ink-bullet rule */
.checkpoint {
    margin: 72px 0 32px 0; padding: 36px 40px;
    background: var(--surface-card);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-xl);
    box-shadow: var(--drop-card);
    position: relative;
    overflow: hidden;
}
.checkpoint::before {
    content: '';
    position: absolute;
    top: -80px; right: -80px;
    width: 260px; height: 260px;
    background: radial-gradient(circle at center, var(--orb-peach) 0%, rgba(244,197,168,0) 70%);
    opacity: 0.35;
    pointer-events: none;
}
.checkpoint > * { position: relative; z-index: 1; }
.checkpoint-header {
    font-family: var(--font-sans); font-size: 11px;
    color: var(--muted); text-transform: uppercase;
    letter-spacing: 0.96px; margin-bottom: 6px; font-weight: 600;
}
.checkpoint-sub {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 18px;
    color: var(--ink);
    margin-bottom: 24px;
    font-weight: 400;
    letter-spacing: -0.18px;
}
.checkpoint ul { list-style: none; padding: 0; margin: 0; }
.checkpoint li {
    padding: 12px 0 12px 36px;
    position: relative; cursor: pointer;
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 15px; line-height: 1.55;
    letter-spacing: 0.15px;
    user-select: none;
    border-bottom: 1px solid var(--hairline-soft);
}
.checkpoint li:last-child { border-bottom: none; }
.checkpoint li::before {
    content: '';
    position: absolute;
    left: 0; top: 16px;
    width: 18px; height: 18px;
    border: 1px solid var(--hairline-strong);
    border-radius: 4px;
    background: var(--surface-card);
    transition: background-color 0.18s ease, border-color 0.18s ease;
}
.checkpoint li.checked::before {
    background: var(--ink);
    border-color: var(--ink);
}
.checkpoint li.checked::after {
    content: '';
    position: absolute;
    left: 5px; top: 19px;
    width: 9px; height: 5px;
    border-left: 1.5px solid var(--on-ink);
    border-bottom: 1.5px solid var(--on-ink);
    transform: rotate(-45deg);
}
.checkpoint li.checked { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--muted-soft); }

/* FIGURE — clean white plate with hairline rule */
.figure {
    margin: 40px 0; padding: 32px;
    background: var(--surface-card);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-xl);
    position: relative;
}
.figure-label {
    font-family: var(--font-sans); font-size: 11px;
    color: var(--muted); text-transform: uppercase;
    letter-spacing: 0.88px; margin-bottom: 6px;
    font-weight: 600;
}
.figure-title {
    font-family: var(--font-display);
    font-size: 22px;
    color: var(--ink);
    margin-bottom: 22px;
    font-weight: 300;
    letter-spacing: -0.22px;
    line-height: 1.25;
}
.figure-caption {
    margin-top: 18px;
    font-size: 14px;
    color: var(--muted);
    font-style: italic;
    font-family: var(--font-display);
    font-weight: 400;
    line-height: 1.55;
    letter-spacing: -0.14px;
}
.figure svg { display: block; max-width: 100%; height: auto; }
.figure svg [data-tip],
.figure svg .hov-region { cursor: help; }
.figure svg [data-tip]:hover > rect:first-of-type,
.figure svg .hov-region:hover > rect:first-of-type {
    stroke-width: 2;
    filter: brightness(0.97) saturate(1.08);
}
.figure svg [data-tip] > rect:first-of-type,
.figure svg .hov-region > rect:first-of-type {
    transition: stroke-width 0.16s ease, filter 0.16s ease;
}
/* Dense diagrams (viewBox wider than ~860) get a horizontal-scroll fallback on narrow screens */
.figure-dense { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.figure-dense > svg { min-width: 640px; }

/* Floating SVG tooltip — one element, reused */
.svg-tip {
    position: fixed; pointer-events: none; z-index: 9999;
    background: var(--ink); color: var(--on-ink);
    padding: 9px 13px; border-radius: 8px;
    font-family: var(--font-sans); font-size: 12px; line-height: 1.5;
    max-width: 280px;
    box-shadow: 0 10px 28px rgba(12,10,9,0.22);
    opacity: 0; transform: translateY(4px);
    transition: opacity 0.12s ease, transform 0.12s ease;
}
.svg-tip.show { opacity: 1; transform: translateY(0); }
.svg-tip b { color: #f4d8a8; font-weight: 600; }

/* CHART */
.chart-container { position: relative; width: 100%; height: 380px; margin: 16px 0; padding: 0; }
.chart-controls {
    display: flex; flex-wrap: wrap; gap: 18px; align-items: center;
    margin: 18px 0 24px 0; padding: 18px 22px;
    background: var(--canvas);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
}
.ctrl-group { display: flex; flex-direction: column; gap: 6px; min-width: 110px; flex: 0 1 auto; }
@media (max-width: 720px) {
    .figure { padding: 22px 18px; margin: 28px 0; }
    .chart-controls { padding: 14px 16px; gap: 12px; }
    .ctrl-group { min-width: 96px; }
    .chart-container { height: 300px !important; }
}
.ctrl-label {
    font-family: var(--font-sans); font-size: 10px;
    color: var(--muted); text-transform: uppercase;
    font-weight: 600; letter-spacing: 0.8px;
}
.ctrl-value {
    font-family: var(--font-mono); font-size: 13px;
    color: var(--ink); font-weight: 500;
}
.ctrl-input {
    background: var(--surface-card);
    border: 1px solid var(--hairline-strong);
    color: var(--ink);
    padding: 8px 12px;
    font-family: var(--font-sans); font-size: 13px;
    border-radius: var(--radius-md); width: 100%;
}
.ctrl-input[type=range] { padding: 0; height: 4px; -webkit-appearance: none; appearance: none; background: var(--hairline-strong); border: none; }
.ctrl-input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 14px; height: 14px; background: var(--ink); border-radius: 50%; cursor: pointer; }
.ctrl-input[type=range]::-moz-range-thumb { width: 14px; height: 14px; background: var(--ink); border-radius: 50%; border: 0; cursor: pointer; }
.ctrl-btn {
    background: transparent;
    border: 1px solid var(--hairline-strong);
    color: var(--ink);
    padding: 8px 16px;
    cursor: pointer;
    font-family: var(--font-sans); font-size: 12px;
    font-weight: 500;
    border-radius: var(--radius-pill);
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}
.ctrl-btn:hover { border-color: var(--ink); }
.ctrl-btn.active { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }

/* CHAPTER NAV — outline pill pair */
.chapter-nav {
    display: flex; justify-content: space-between;
    margin-top: 80px; padding-top: 36px;
    border-top: 1px solid var(--hairline);
    gap: 20px;
}
.chapter-nav a {
    flex: 1; padding: 22px 28px;
    background: var(--surface-card);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-xl);
    font-family: var(--font-sans); font-size: 15px;
    color: var(--ink); font-weight: 500;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
    letter-spacing: 0.15px;
}
.chapter-nav a:hover {
    border-color: var(--hairline-strong);
    box-shadow: var(--drop-soft);
}
.chapter-nav .label {
    display: block; font-size: 11px;
    text-transform: uppercase; color: var(--muted);
    font-weight: 600; letter-spacing: 0.88px;
    margin-bottom: 6px;
}
.chapter-nav .next { text-align: right; }

/* FORMULA */
.formula {
    margin: 24px 0; padding: 22px 28px;
    background: var(--canvas);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    font-family: var(--font-mono); font-size: 14px;
    color: var(--ink); overflow-x: auto;
    white-space: pre; line-height: 1.75;
}
.formula .var { color: var(--ink-peach); font-weight: 500; }
.formula .op  { color: var(--muted); }
.formula .num { color: var(--ink-mint); font-weight: 500; }
.formula .res { color: var(--ink); font-weight: 600; }

/* REFERENCES */
.refs {
    margin: 40px 0; padding: 28px 32px;
    background: var(--canvas);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
}
.refs-label {
    font-family: var(--font-sans); font-size: 11px;
    color: var(--muted); text-transform: uppercase;
    letter-spacing: 0.88px; margin-bottom: 12px;
    font-weight: 600;
}
.refs ol { list-style: decimal; padding-left: 24px; margin: 0; }
.refs li {
    font-size: 13px;
    color: var(--body);
    font-family: var(--font-sans);
    margin-bottom: 8px;
    line-height: 1.55;
    letter-spacing: 0.13px;
}
.refs li::marker { color: var(--muted-soft); }
.refs li a { font-size: 13px; word-break: break-all; color: var(--ink); border-bottom-color: var(--hairline-strong); }

/* RESPONSIVE */
@media (max-width: 1100px) { #content { padding: 80px 48px 120px 48px; } }
@media (max-width: 900px) {
    #sidebar { transform: translateX(-100%); transition: transform 0.25s ease; box-shadow: 0 12px 32px rgba(0,0,0,0.12); }
    #sidebar.open { transform: translateX(0); }
    #content { margin-left: 0; padding: 80px 24px 100px 24px; }
    .cover-title { font-size: 44px; letter-spacing: -1.32px; }
    .chapter-title { font-size: 36px; letter-spacing: -0.72px; }
    .chapter-num-bg { font-size: 140px; }
    h2.section-title { font-size: 28px; }
    #menu-toggle { display: flex; }
}
#menu-toggle {
    display: none;
    position: fixed; top: 16px; right: 18px; z-index: 200;
    background: var(--ink); border: none;
    color: var(--on-ink);
    width: 44px; height: 44px;
    font-family: var(--font-sans); font-size: 18px;
    border-radius: var(--radius-pill); cursor: pointer;
    box-shadow: var(--drop-card);
    align-items: center; justify-content: center;
}

/* ============================================================
   ATOMIC NOTES — concept cards, ID badges, relation chips,
   knowledge-graph blocks, reading paths, glossary highlights.
   Added in the v2 expansion: every atomic concept gets its own
   card with a stable [[id]] and explicit prereq / builds-on /
   related-to / used-by links so the conceptual graph is visible.
   ============================================================ */

/* ATOMIC NOTE — quiet white card with lavender atmospheric edge */
.atomic {
    position: relative;
    margin: 40px 0;
    padding: 32px 36px 28px 36px;
    background: var(--surface-card);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-xl);
    box-shadow: var(--drop-soft);
    overflow: hidden;
}
.atomic::after {
    content: '';
    position: absolute;
    top: -60px; right: -60px;
    width: 200px; height: 200px;
    background: radial-gradient(circle at center, var(--orb-lavender) 0%, rgba(200,184,224,0) 70%);
    opacity: 0.5;
    pointer-events: none;
    z-index: 0;
}
.atomic > * { position: relative; z-index: 1; }
.atomic::before {
    content: 'Atomic note';
    position: absolute; top: 24px; right: 28px;
    background: transparent;
    color: var(--muted);
    font-family: var(--font-sans);
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.88px;
    padding: 0;
    border: none;
    border-radius: 0;
    z-index: 2;
}
.atomic-head {
    display: flex; flex-wrap: wrap;
    align-items: baseline; gap: 16px;
    margin: 0 0 18px 0;
    padding-right: 100px;
}
.atomic-id {
    font-family: var(--font-mono);
    font-size: 11px; color: var(--ink);
    background: var(--surface-strong);
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    border: none;
    letter-spacing: 0.55px;
    font-weight: 500;
}
.atomic-title {
    font-family: var(--font-display);
    font-size: 26px; font-weight: 300;
    color: var(--ink);
    margin: 0; letter-spacing: -0.26px;
    line-height: 1.2;
    flex: 1;
}
.atomic-tag {
    font-family: var(--font-sans);
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.8px;
    padding: 3px 10px;
    border: 1px solid var(--hairline);
    border-radius: var(--radius-pill);
    background: var(--canvas);
}
.atomic-body {
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.65;
    color: var(--ink);
    letter-spacing: 0.15px;
}
.atomic-body p { margin-bottom: 12px; }
.atomic-body p:last-child { margin-bottom: 0; }

.atomic-rel {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--hairline);
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    font-family: var(--font-sans);
    font-size: 12px;
}
.rel-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.rel-label {
    color: var(--muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.7px;
    font-size: 10px;
    min-width: 96px;
    padding-top: 4px;
}
.rel-chip {
    display: inline-block;
    padding: 4px 11px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid transparent;
    transition: background-color 0.18s ease, border-color 0.18s ease;
    line-height: 1.5;
    letter-spacing: 0.12px;
    border-bottom: none;
}
.rel-chip:hover { border-bottom: none; }
.rel-prereq    { background: var(--orb-rose);     color: var(--ink-rose);     }
.rel-prereq:hover    { background: #d99fb0; }
.rel-builds    { background: var(--orb-sky);      color: var(--ink-sky);      }
.rel-builds:hover    { background: #8db0d8; }
.rel-related   { background: var(--orb-lavender); color: var(--ink-lavender); }
.rel-related:hover   { background: #b09fce; }
.rel-usedby    { background: var(--orb-mint);     color: var(--ink-mint);     }
.rel-usedby:hover    { background: #8ed4be; }
.rel-contrast  { background: var(--orb-peach);    color: var(--ink-peach);    }
.rel-contrast:hover  { background: #e8b08e; }

/* Inline atomic-note pointer used inside running prose */
a.note-ref {
    font-family: var(--font-mono);
    font-size: 0.82em;
    color: var(--ink);
    background: var(--surface-strong);
    padding: 1px 8px;
    border-radius: var(--radius-pill);
    border: none;
    margin: 0 2px;
    transition: background-color 0.18s ease;
    font-weight: 500;
    letter-spacing: 0;
}
a.note-ref::before { content: ''; }
a.note-ref::after  { content: ''; }
a.note-ref:hover { color: var(--ink); background: var(--orb-lavender); border-bottom: none; }

/* Reading-path / learning-track banner */
.learning-path {
    margin: 40px 0;
    padding: 28px 32px;
    background: var(--surface-card);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-xl);
    box-shadow: var(--drop-soft);
}
.learning-path-label {
    font-family: var(--font-sans);
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.88px;
    margin-bottom: 14px;
    font-weight: 600;
}
.learning-path-track { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.learning-path-step {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink);
    background: var(--canvas);
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--hairline);
    text-decoration: none;
    transition: background-color 0.18s ease, border-color 0.18s ease;
    letter-spacing: 0.13px;
}
.learning-path-step:hover { background: var(--surface-strong); border-color: var(--hairline-strong); border-bottom: 1px solid var(--hairline-strong); }
.learning-path-arrow { color: var(--muted-soft); font-family: var(--font-sans); font-size: 14px; }

/* Concept-cluster opener — sky-pastel notice */
.cluster {
    margin: 40px 0 24px 0;
    padding: 20px 26px;
    background: var(--canvas-soft);
    border: 1px solid var(--hairline);
    border-left: 2px solid var(--orb-sky);
    border-radius: var(--radius-lg);
    font-family: var(--font-display);
    font-size: 17px;
    color: var(--body);
    line-height: 1.55;
    font-style: italic;
    font-weight: 400;
    letter-spacing: -0.17px;
}
.cluster strong { color: var(--ink); font-style: normal; font-family: var(--font-sans); font-size: 11px; text-transform: uppercase; letter-spacing: 0.88px; font-weight: 600; display: block; margin-bottom: 6px; }

/* Definition list */
.def-list { margin: 14px 0; padding: 0; list-style: none; font-family: var(--font-sans); }
.def-list li { padding: 8px 0; border-bottom: 1px solid var(--hairline-soft); margin-bottom: 0; color: var(--ink); }
.def-list li:last-child { border-bottom: none; }
.def-term {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--ink);
    background: var(--surface-strong);
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
    margin-right: 12px;
}

/* Knowledge-graph node + edge list (rendered as SVG inline) */
.kg-wrap {
    margin: 40px 0; padding: 32px;
    background: var(--surface-card);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-xl);
}
.kg-wrap svg { width: 100%; height: auto; display: block; overflow: visible; }
.kg-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.kg-wrap svg { min-width: 640px; }
.kg-wrap svg .kg-node { cursor: pointer; transition: transform 0.18s ease; transform-box: fill-box; transform-origin: center; }
.kg-wrap svg .kg-node > circle { transition: fill 0.18s ease, stroke-width 0.18s ease; }
.kg-wrap svg .kg-node:hover > circle { fill: #fff5e6; stroke-width: 2.5; }
.kg-wrap svg .kg-node:hover { transform: scale(1.08); }
.kg-legend {
    display: flex; flex-wrap: wrap; gap: 22px;
    margin-top: 20px; padding-top: 18px;
    border-top: 1px solid var(--hairline-soft);
    font-family: var(--font-sans); font-size: 12px; color: var(--muted);
}
.kg-legend-item { display: flex; align-items: center; gap: 8px; }
.kg-swatch { width: 18px; height: 4px; border-radius: 2px; }

/* "In one sentence" summary — italic editorial pull-quote */
.tldr {
    margin: 20px 0;
    padding: 16px 24px;
    background: var(--canvas);
    border-left: 2px solid var(--orb-peach);
    border-radius: 4px;
    font-family: var(--font-display);
    font-size: 17px;
    font-style: italic;
    font-weight: 400;
    color: var(--ink);
    line-height: 1.5;
    letter-spacing: -0.17px;
}
.tldr::before {
    content: 'TL;DR · ';
    font-family: var(--font-sans);
    font-style: normal;
    font-weight: 600;
    color: var(--ink-peach);
    font-size: 11px;
    letter-spacing: 0.88px;
    text-transform: uppercase;
    margin-right: 4px;
}

/* Worked-example */
.worked {
    margin: 32px 0;
    padding: 28px 32px;
    background: var(--surface-card);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-xl);
    border-left: 3px solid var(--orb-peach);
}
.worked-label {
    font-family: var(--font-sans);
    font-size: 11px;
    color: var(--ink-peach);
    text-transform: uppercase;
    letter-spacing: 0.88px;
    margin-bottom: 10px;
    font-weight: 600;
}

/* Pitfall — rose accent */
.pitfall {
    margin: 32px 0;
    padding: 24px 28px;
    background: var(--surface-card);
    border: 1px solid var(--hairline);
    border-left: 3px solid var(--orb-rose);
    border-radius: var(--radius-xl);
}
.pitfall-label {
    font-family: var(--font-sans);
    font-size: 11px;
    color: var(--ink-rose);
    text-transform: uppercase;
    letter-spacing: 0.88px;
    margin-bottom: 8px;
    font-weight: 600;
}

/* Bit-layout grid for IEEE 754, FP16, BF16, FP8 */
.bitlayout {
    display: grid; grid-template-columns: repeat(32, 1fr);
    gap: 3px; margin: 18px 0;
    font-family: var(--font-mono); font-size: 11px;
}
.bitlayout .bit {
    background: var(--canvas);
    border: 1px solid var(--hairline);
    padding: 7px 2px;
    text-align: center;
    color: var(--muted);
    border-radius: 3px;
    font-weight: 500;
}
.bitlayout .bit.sign { background: var(--orb-rose);     color: var(--ink-rose);     border-color: transparent; }
.bitlayout .bit.exp  { background: var(--orb-sky);      color: var(--ink-sky);      border-color: transparent; }
.bitlayout .bit.mant { background: var(--orb-mint);     color: var(--ink-mint);     border-color: transparent; }
.bitlayout-legend {
    display: flex; flex-wrap: wrap; gap: 18px;
    font-family: var(--font-sans); font-size: 12px;
    color: var(--muted); margin-top: 12px;
    font-weight: 500;
}

@media (max-width: 900px) {
    .bitlayout { grid-template-columns: repeat(16, 1fr); }
    .atomic { padding: 24px 20px 20px 20px; }
    .atomic-head { padding-right: 0; }
    .atomic::before { position: static; display: inline-block; margin-bottom: 12px; }
}


                        .kgn { font-family: 'JetBrains Mono', monospace; font-size: 11px; fill: #0c0a09; }
                        .kgn-sm { font-size: 9px; fill: #4e4e4e; }
                        .kge-prereq { stroke: #9b2c5b; stroke-width: 1.4; opacity: 0.6; fill: none; marker-end: url(#kg-arrow); }
                        .kge-builds { stroke: #2c5282; stroke-width: 1.4; opacity: 0.55; fill: none; marker-end: url(#kg-arrow); }
                        .kge-usedby { stroke: #276749; stroke-width: 1.2; opacity: 0.5; fill: none; marker-end: url(#kg-arrow); stroke-dasharray: 3 3; }
                    