/* ═══════════════════════════════════════════════════════════
   plain.css — the spartan skin for the personal notes.

   These notes are for me, not for an audience, so the page is
   stripped back to text: no cards, no borders, no shading, no
   tags, no hero, no reading times. A heading, a paragraph, a
   list of links. Everything that survives — figures, widgets,
   math, cross-reference popovers — survives because it teaches
   something, not because it decorates.

   Shared by every notes series that opts in via
   <body class="plain">. reinforce_LLMs/ deliberately does not:
   it keeps rl-notes-style.css and its old look.

   Dark-mode rules live here rather than in css/theme.css, and
   are written as [data-theme="dark"] body.plain … so they beat
   theme.css's older two-class selectors no matter which file
   loads last.
   ═══════════════════════════════════════════════════════════ */

/* Imported here rather than in 31 <head>s: every page that opts
   into body.plain gets the annotation face for free, and there is
   exactly one place to remove it again. Handwriting is confined to
   things a person would actually write by hand — figure captions,
   chapters not yet written — never body text, headings, or math. */
@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@500;600&display=swap');

body.plain {
    /* Light-mode greys are set by measured contrast on white, not
       by eye. The real cause of washed-out text here was weight,
       not colour: 17px Fira Sans at 300 is a hairline on white
       however dark you make it, so the body runs at 400 and the
       greys were pulled in behind it. */
    --ink: #000000;
    --body: #1a1a1a;
    --muted: #4a4a4a;
    --faint: #5f5f5f;
    --rule: #dcdcdc;
    --link: #6e46be;
    --link-hover: #b088f9;
    --page: #ffffff;
    --wash: #fafafa;

    /* Paper. Two decorative tokens, kept as tokens so they can be
       switched off without hunting through rules: set --grain and
       --hand-rule to `none` and the page is spartan again.
       --grain is desaturated fractal noise, so the same tile reads
       as texture on white and on the dark flavors — only the
       opacity baked into the tile changes between them. */
    --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)' opacity='0.04'/%3E%3C/svg%3E");
    --hand-rule: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='8' viewBox='0 0 200 8' preserveAspectRatio='none'%3E%3Cpath d='M0 4.2 C 12 2.6, 26 5.6, 40 4.1 S 68 2.4, 82 4.4 S 110 6, 124 3.9 S 152 2.5, 166 4.6 S 190 5.4, 200 3.8' fill='none' stroke='%23d2d2d2' stroke-width='1.2' stroke-linecap='round'/%3E%3C/svg%3E");

    /* The annotation face, and the ruling for widget panels. Caveat
       sits small for its point size, so anything set in it is bumped
       ~1.2x to sit optically level with the surrounding text. */
    --hand-font: 'Caveat', 'Segoe Print', 'Bradley Hand', cursive;
    --grid: rgba(110, 70, 190, 0.07);

    /* The leaf. Real paper is never one flat tone: it is warm, it
       is lit unevenly, and its edge is soft. Each token below is one
       of those observations, so the sheet can be retuned without
       touching a single rule. --desk is the surface it lies on. */
    --desk: #f0eee9;
    --sheet: rgba(255, 255, 255, 0.14);
    --dot: rgba(104, 116, 140, 0.10);
    --margin-ink: rgba(196, 92, 88, 0.12);
    --punch-core: rgba(120, 112, 96, 0.12);

    margin: 0;
    /* The desk. Grain plus a slow pool of light from the upper
       left, so the board under the sheet is lit rather than filled. */
    background-color: var(--desk);
    /* The dot field is the page's texture, not the sheet's: it runs
       edge to edge behind everything, so the paper is a region of a
       dotted ground rather than a rectangle carrying its own ruling. */
    background-image:
        radial-gradient(circle at 1px 1px, var(--dot) 0 1.3px, transparent 1.7px),
        var(--grain);
    background-size: 22px 22px, 200px 200px;
    background-position: 8px 12px, left top;
    /* Desk visible above and below the leaf. Without this the sheet
       runs off both ends of the viewport and stops reading as an
       object lying on something. */
    padding: 46px 0 72px;
    color: var(--body);
    font-family: 'Fira Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-weight: 400;
    font-size: 17px;
    line-height: 1.75;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.plain strong,
body.plain b {
    font-weight: 600;
}

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

/* The leaf. 892 = 780 measure + 72 left gutter + 40 right, so the
   line length the notes were tuned at is unchanged — the gutter is
   added around it, not taken out of it.

   Believability is mostly lighting, not detail. Four things do the
   work: the sheet is warm rather than white, it is lit unevenly, the
   ruled lines are far fainter than a real notebook's (drift against
   headings reads as age rather than as a bug at this alpha), and the
   shadow is offset and stacked so the paper sits on the desk instead
   of floating over it. */
/* The container is now just the column: it centres, and nothing
   else. The sheet lives on <main>, so the breadcrumb sits on the
   desk above the paper and the drawn rule and copyright sit on the
   desk below it — the page ends where the content ends. */
body.plain .container {
    box-sizing: border-box;
    max-width: 892px;
    margin: 0 auto;
    padding: 0;
}

/* Header and footer are off the paper, so they carry their own
   indents to stay aligned with the text column on it. */
body.plain .container>.site-header,
body.plain .container>.site-footer {
    padding-left: 72px;
    padding-right: 40px;
}

/* The leaf. 892 = 780 measure + 72 left gutter + 40 right, so the
   line length the notes were tuned at is unchanged.

   Believability is mostly lighting, not detail: the sheet is warm
   rather than white, lit unevenly, and its shadow is offset and
   stacked so the paper sits on the desk rather than floating. The
   value gap to the desk is deliberately tiny — the holes, the dot
   grid and the margin rule say "paper", not a change in brightness. */
body.plain .container>main {
    box-sizing: border-box;
    position: relative;
    padding: 34px 40px 44px 72px;
}

/* The paper is a masked layer behind the text rather than a fill on
   the element. A filled box has to end somewhere, and wherever it
   ends it draws a line — which is the hard rectangle and the bar
   across the top. On its own layer the whole sheet, holes and dots
   and margin rule included, can be feathered out at all four edges,
   so the page has no border to notice: it just stops being paper.

   z-index -1 keeps it under the text; main has no background of its
   own, so this composites straight onto the desk. */
body.plain .container>main::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-color: var(--sheet);
    background-image:
        radial-gradient(circle at 26px 25px, var(--punch-core) 0 5.5px, transparent 6px),
        linear-gradient(to right, transparent 0 55px, var(--margin-ink) 55px 56px, transparent 56px);
    /* No grain here: the body already lays it across the whole page.
       Repeating it on this layer double-exposed the paper region and
       lifted it ~3 luminance off the desk — which read as the sheet
       "not blending" no matter how low --sheet went. */
    background-repeat: repeat-y, no-repeat;
    background-size: 100% 58px, 100% 100%;
    background-position: left top, left top;
    -webkit-mask-image:
        linear-gradient(to bottom, transparent 0, #000 210px, #000 calc(100% - 210px), transparent 100%),
        linear-gradient(to right, transparent 0, #000 130px, #000 calc(100% - 130px), transparent 100%);
    -webkit-mask-composite: source-in;
    mask-image:
        linear-gradient(to bottom, transparent 0, #000 210px, #000 calc(100% - 210px), transparent 100%),
        linear-gradient(to right, transparent 0, #000 130px, #000 calc(100% - 130px), transparent 100%);
    mask-composite: intersect;
}

@media (max-width: 900px) {

    /* Below the sheet width the furniture stops paying for itself:
       the gutter eats the measure and the holes crowd the text. */
    body.plain {
        padding: 0;
    }

    body.plain .container>.site-header,
    body.plain .container>.site-footer {
        padding-left: 22px;
        padding-right: 22px;
    }

    body.plain .container>main {
        max-width: none;
        padding: 20px 22px 40px;
    }

    body.plain .container>main::before {
        content: none;
    }
}

/* Breadcrumb. The only navigation on the page — with prev/next
   gone, the way out of a chapter is back up to the index. */
body.plain .site-header {
    padding: 40px 0 0;
    margin-bottom: 56px;
    font-size: 0.9rem;
    color: var(--muted);
}

body.plain .site-header a {
    color: var(--muted);
}

body.plain .site-header a:hover {
    color: var(--link);
}

body.plain .site-header .here {
    color: var(--ink);
}

body.plain .site-footer {
    margin-top: 88px;
    padding-top: 28px;
    /* A drawn line rather than a border: same job, less machined.
       Falls back to the old hairline if --hand-rule is set to none. */
    border-top: none;
    background-image: var(--hand-rule);
    background-repeat: repeat-x;
    background-position: left top;
    background-size: 200px 8px;
    font-size: 0.82rem;
    color: var(--faint);
}

/* A section break inside a chapter, for the rare place that wants
   one. Not applied anywhere by default — chapter `hr` stays zeroed. */
body.plain .hand-rule {
    height: 8px;
    margin: 44px 0;
    border: none;
    background-image: var(--hand-rule);
    background-repeat: repeat-x;
    background-position: left center;
    background-size: 200px 8px;
}

/* ── Links ──────────────────────────────────────────────── */

body.plain a {
    color: var(--link);
    text-decoration: none;
}

body.plain a:hover {
    color: var(--link-hover);
    text-decoration: underline;
}

/* ── Page title and lede ────────────────────────────────── */

body.plain h1 {
    font-size: 1.9rem;
    font-weight: 600;
    line-height: 1.25;
    color: var(--ink);
    margin: 0 0 20px;
    letter-spacing: -0.01em;
}

/* The chapter numeral, pencilled in the margin beside the title.
   Driven by data-ch on <main>, so no JS and no per-series markup
   beyond one attribute. It sits in the gutter the padding already
   reserves, so it costs nothing from the measure. */
body.plain main[data-ch] {
    position: relative;
}

body.plain main[data-ch]>h1 {
    position: relative;
}

body.plain main[data-ch]>h1::before {
    content: attr(data-ch);
    position: absolute;
    left: -54px;
    top: -0.16em;
    font-family: var(--hand-font);
    font-size: 2.9rem;
    font-weight: 600;
    line-height: 1;
    color: var(--margin-ink);
    pointer-events: none;
}

@media (max-width: 900px) {

    /* No gutter to sit in — the numeral goes inline above the title. */
    body.plain main[data-ch]>h1::before {
        position: static;
        display: block;
        margin: 0 0 2px;
        font-size: 2.1rem;
    }
}

/* ── The index: nested link lists, and nothing else ─────── */

body.plain .note-index h2 {
    font-size: 1.12rem;
    font-weight: 600;
    color: var(--ink);
    margin: 40px 0 10px;
    padding: 0;
    border: none;
}

body.plain .note-index h2:first-of-type {
    margin-top: 32px;
}

body.plain .note-index ul {
    list-style: none;
    margin: 0;
    padding: 0 0 0 2px;
}

body.plain .note-index ul ul {
    padding-left: 22px;
    margin: 2px 0 6px;
}

body.plain .note-index li {
    margin: 3px 0;
    position: relative;
    padding-left: 16px;
}

body.plain .note-index li::before {
    content: '·';
    position: absolute;
    left: 2px;
    color: var(--faint);
}

/* An entry with no link is a note I have not written yet. Same
   as the reference site: the gaps are part of the map — and now
   they look pencilled in beside the ones that are set, which is
   what they are. */
body.plain .note-index li.todo {
    color: var(--faint);
    font-family: var(--hand-font);
    font-size: 1.14rem;
    line-height: 1.5;
}

body.plain .note-index li.todo::before {
    content: '·';
    color: #d8d8d8;
}

/* A short trailing gloss, for when the title alone is opaque. */
body.plain .note-index .gloss {
    color: var(--muted);
    font-size: 0.88rem;
}

body.plain .note-index .gloss::before {
    content: ' · ';
}

/* ── Leaders ────────────────────────────────────────────────
   Opt in per list with <ul class="leaders">. The dots run from
   the title to a short trailing gloss — a date, a count, a
   venue — the way a printed contents page does, so the eye can
   cross the gap without a ruler. Only for glosses short enough
   to sit on one line; the series indexes carry sentence-length
   glosses and deliberately keep the inline ' · ' form. */

body.plain .note-index ul.leaders li {
    display: flex;
    align-items: baseline;
}

body.plain .note-index ul.leaders li>a {
    flex: 0 1 auto;
    order: 1;
}

/* order matters: the generated box is the last child in source, so
   without it the dots trail off past the gloss instead of bridging
   the gap between title and gloss. */
body.plain .note-index ul.leaders li::after {
    content: '';
    order: 2;
    flex: 1 1 auto;
    min-width: 20px;
    margin: 0 8px;
    border-bottom: 1px dotted var(--rule);
    position: relative;
    top: -0.3em;
}

body.plain .note-index ul.leaders .gloss {
    order: 3;
    flex: 0 0 auto;
    white-space: nowrap;
}

body.plain .note-index ul.leaders .gloss::before {
    content: none;
}

/* Display maths gets boxed, the way you'd rule a box round a result
   you intend to use again. Tagged equations keep their number outside
   the box, so the box is around the maths and not around the label. */
body.plain .chapter-content .katex-display {
    margin: 26px 0;
    padding: 14px 18px;
    background-color: var(--wash);
    border: 1px solid var(--rule);
    border-radius: 3px;
    overflow-x: auto;
    overflow-y: hidden;
}

body.plain .chapter-content .katex-display>.katex {
    text-align: center;
}

/* ── Chapter body ───────────────────────────────────────── */

body.plain .chapter-content {
    max-width: none;
}

body.plain .chapter-content h2 {
    font-size: 1.28rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.35;
    margin: 52px 0 14px;
    padding: 0;
    border: none;
}

body.plain .chapter-content h3 {
    font-size: 1.06rem;
    font-weight: 600;
    color: var(--ink);
    margin: 34px 0 10px;
    padding: 0;
    border: none;
}

body.plain .chapter-content h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--body);
    margin: 26px 0 8px;
}

body.plain .chapter-content p {
    margin: 0 0 18px;
}

body.plain .chapter-content ul,
body.plain .chapter-content ol {
    margin: 0 0 18px;
    padding-left: 26px;
}

body.plain .chapter-content li {
    margin: 6px 0;
}

/* Section breaks: whitespace, not a line. No margin of its own —
   the following h2 already brings 52px, and stacking the two left
   a gap you could lose a paragraph in. */
body.plain .chapter-content hr {
    border: none;
    height: 0;
    margin: 0;
}

body.plain .chapter-content blockquote {
    margin: 24px 0;
    padding: 0 0 0 20px;
    border-left: 2px solid var(--rule);
    color: var(--muted);
    font-style: italic;
}

/* The italic paragraph a chapter opens on. */
body.plain .chapter-content > p > em:only-child {
    color: var(--muted);
}

/* ── Code ───────────────────────────────────────────────── */

body.plain .chapter-content pre {
    position: relative;
    margin: 24px 0;
    padding: 16px 18px;
    background: var(--wash);
    border: none;
    border-radius: 0;
    overflow-x: auto;
    font-size: 0.83rem;
    line-height: 1.6;
}

body.plain .chapter-content code {
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

body.plain .chapter-content p code,
body.plain .chapter-content li code,
body.plain .chapter-content td code {
    font-size: 0.86em;
    background: var(--wash);
    padding: 1px 5px;
    color: var(--ink);
}

body.plain .code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 3px 9px;
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--muted);
    background: var(--page);
    border: 1px solid var(--rule);
    border-radius: 3px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}

body.plain .chapter-content pre:hover .code-copy-btn {
    opacity: 1;
}

body.plain .code-copy-btn:hover {
    color: var(--ink);
}

body.plain .code-copy-btn.copied {
    color: #2f8a4c;
    opacity: 1;
}

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

body.plain .chapter-content table {
    width: 100%;
    margin: 24px 0;
    border-collapse: collapse;
    font-size: 0.9rem;
    display: block;
    overflow-x: auto;
}

body.plain .chapter-content thead th {
    text-align: left;
    font-weight: 600;
    color: var(--ink);
    background: none;
    padding: 8px 14px 8px 0;
    border-bottom: 1px solid #cfcfcf;
}

body.plain .chapter-content tbody td {
    padding: 8px 14px 8px 0;
    border-bottom: 1px solid var(--rule);
    vertical-align: top;
}

body.plain .chapter-content tbody tr:hover {
    background: none;
}

/* ── Figures ────────────────────────────────────────────── */

body.plain .chapter-content figure {
    margin: 34px 0;
    text-align: center;
}

body.plain .chapter-content figure img,
body.plain .chapter-content figure svg {
    max-width: 100%;
    height: auto;
}

/* Captions are the one place a figure gets annotated, so they are
   set in the hand rather than the body face — the label a person
   pencils under a diagram, not a typeset legend. Larger than the
   0.84rem it replaces because Caveat runs small at equal size. */
body.plain .chapter-content figcaption {
    margin-top: 10px;
    font-family: var(--hand-font);
    font-size: 1.08rem;
    /* 600, not 500: Caveat's strokes are thinner than Fira's at the
       same optical size, and a caption that is hard to read is not a
       caption. */
    font-weight: 600;
    color: var(--muted);
    line-height: 1.45;
    text-align: left;
}

/* Math, code and anything tagged as data stay in the typeset faces
   even inside a caption — a handwritten variable name is a bug. */
body.plain .chapter-content figcaption :is(code, kbd, samp, .katex, var) {
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.8em;
}

body.plain .chapter-content .fig-row {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    margin: 34px 0;
}

body.plain .chapter-content .fig-row .fig-cell {
    flex: 1 1 260px;
    background: none;
    border: none;
    padding: 0;
}

body.plain .chapter-content img.pixelated {
    image-rendering: pixelated;
}

/* ── Figure palette ─────────────────────────────────────────
   The SVGs reference these as var(--fig-ink, #1a1a1a) and so on,
   always with the original colour as the fallback. That means a
   figure opened on its own, or still sitting in an <img> before
   notes JS inlines it, renders exactly as it always did; only an
   inlined figure inside the page picks the theme up.

   Tokens are semantic, not literal: "ink" is whatever text should
   be, which is near-black on a light page and near-white on a dark
   one. Inverting them here is what makes the figures theme-aware
   rather than painting a light panel behind dark line art. */

body.plain {
    --fig-ink: #1a1a1a;
    --fig-ink-2: #4a4a4a;
    --fig-muted: #6a6a6a;
    --fig-muted-2: #8a8a8a;
    --fig-faint: #b0b0b0;
    --fig-line: #d8d8d8;
    --fig-wash: #f6f6f6;
    --fig-paper: #ffffff;
    --fig-solid: #1c1c1c;

    --fig-teal: #0e7490;
    --fig-teal-2: #4a9b9b;
    --fig-teal-bg: #dfe8ea;
    --fig-amber: #d97706;
    --fig-amber-2: #a35f05;
    --fig-amber-bg: #e8e2d5;
    --fig-purple: #7c3aed;
    --fig-purple-bg: #fcfaff;
    --fig-red: #c0392b;
    --fig-red-bg: #e8d5d5;
    --fig-blue: #1a4f7a;
    --fig-blue-bg: #e8f0fe;
    --fig-green: #2f7a3f;
    --fig-green-bg: #e8f5e9;
}

[data-theme="dark"] body.plain {
    --fig-ink: #e8e8e8;
    --fig-ink-2: #c2c2c2;
    --fig-muted: #a0a0a0;
    --fig-muted-2: #8a8a8a;
    --fig-faint: #6a6a6a;
    --fig-line: #3c3c3c;
    --fig-wash: #1b1b1b;
    --fig-paper: #121212;
    --fig-solid: #d0d0d0;

    /* Accents lifted until they carry on a dark ground; the hue is
       kept so a figure reads the same in either theme. */
    --fig-teal: #4fb3cc;
    --fig-teal-2: #6fc4c4;
    --fig-teal-bg: #10323c;
    --fig-amber: #e5a544;
    --fig-amber-2: #c9902f;
    --fig-amber-bg: #332a1a;
    --fig-purple: #a98bf0;
    --fig-purple-bg: #1f1a2e;
    --fig-red: #e8756a;
    --fig-red-bg: #33201e;
    --fig-blue: #5fa3d8;
    --fig-blue-bg: #16243a;
    --fig-green: #5fbf6f;
    --fig-green-bg: #16301c;
}

/* An inlined figure fills its figure box the way the <img> did. */
body.plain .chapter-content figure svg,
body.plain .note-index figure svg {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* ── Math ───────────────────────────────────────────────── */

body.plain .katex {
    font-size: 1.02em;
}

body.plain .katex-display {
    margin: 22px 0;
    padding: 2px 0;
    overflow-x: auto;
    overflow-y: hidden;
}

/* ── Callouts, flattened ────────────────────────────────────
   These were tinted boxes. A note is still worth marking off,
   but a hairline rule and a small label does the job without
   turning the page into a set of trays. */

body.plain .note-box {
    margin: 26px 0;
    padding: 2px 0 2px 20px;
    background: none !important;
    border: none;
    border-left: 2px solid #cfcfcf !important;
    border-radius: 0;
}

body.plain .note-box .note-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--muted) !important;
    margin-bottom: 6px;
}

body.plain .note-box p:last-child {
    margin-bottom: 0;
}

/* Part markers: a rule and a line of text, not a banner. */
body.plain .chapter-content .part-marker {
    margin: 64px 0 34px;
    padding-top: 26px;
    /* Same drawn line as the footer, so a part break and a page
       end are visibly the same gesture. */
    border-top: none;
    background-color: transparent;
    background-image: var(--hand-rule);
    background-repeat: repeat-x;
    background-position: left top;
    background-size: 200px 8px;
    border-radius: 0;
}

body.plain .chapter-content .part-marker .part-label {
    display: inline;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    background: none;
    padding: 0;
    text-transform: none;
    letter-spacing: 0;
}

body.plain .chapter-content .part-marker .part-label::after {
    content: ' · ';
    color: var(--faint);
}

body.plain .chapter-content .part-marker .part-name {
    display: inline;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
}

body.plain .chapter-content .part-marker .part-sub {
    display: block;
    margin-top: 6px;
    font-size: 0.88rem;
    color: var(--muted);
    line-height: 1.6;
}

body.plain .chapter-content details.collapsible {
    margin: 24px 0;
    border: none;
    border-left: 2px solid var(--rule);
    padding-left: 20px;
    background: none;
}

body.plain .chapter-content details.collapsible summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--ink);
}

/* ── Cross-references and their hover previews ──────────────
   Kept in full. Not having to leave the page to check what
   "§10" said is the single most useful thing on these pages. */

body.plain .chapter-content .ref-link,
body.plain .chapter-content a.chapter-link {
    color: var(--link);
    border: none;
    background: none;
    cursor: pointer;
}

body.plain .chapter-content .ref-link:hover,
body.plain .chapter-content .ref-link:focus,
body.plain .chapter-content a.chapter-link:hover {
    color: var(--link-hover);
    text-decoration: underline;
}

body.plain .ref-pop {
    background: var(--page);
    border: 1px solid var(--rule);
    border-radius: 3px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.09);
}

body.plain .ref-pop-label {
    color: var(--muted);
    background: var(--wash);
    border-bottom: 1px solid var(--rule);
}

body.plain .ref-pop-body {
    color: var(--body);
}

/* ── Widgets ────────────────────────────────────────────────
   The one place a frame is allowed. A widget is a different
   kind of object from prose and needs to read as one, but it
   gets a hairline and neutral chrome rather than the old tinted
   panel. dgm-widgets.js is untouched. */

/* Widgets are the things you'd work out on squared paper, so they
   sit on some. The ruling is faint enough to read as texture under
   text and controls, and is drawn with gradients rather than an
   image so it scales and re-themes with the tokens. */
body.plain :is(.dgm-widget, .note-widget) {
    margin: 34px 0;
    padding: 20px 22px;
    background-color: var(--wash);
    background-image:
        repeating-linear-gradient(to right, var(--grid) 0 1px, transparent 1px 22px),
        repeating-linear-gradient(to bottom, var(--grid) 0 1px, transparent 1px 22px);
    border: 1px solid var(--rule);
    border-radius: 3px;
    font-size: 0.92rem;
}

body.plain :is(.dgm-widget, .note-widget) .w-title {
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 14px;
}

body.plain :is(.dgm-widget, .note-widget) button {
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 400;
    color: var(--ink);
    background: var(--page);
    border: 1px solid #cfcfcf;
    border-radius: 3px;
    padding: 5px 13px;
    cursor: pointer;
    margin: 0 8px 8px 0;
    transition: border-color 0.15s, color 0.15s;
}

body.plain :is(.dgm-widget, .note-widget) button:hover {
    border-color: var(--ink);
}

body.plain :is(.dgm-widget, .note-widget) button.secondary {
    color: var(--muted);
}

body.plain :is(.dgm-widget, .note-widget) canvas {
    max-width: 100%;
    background: var(--page);
}

body.plain :is(.dgm-widget, .note-widget) :is(.w-note, .verdict) {
    font-size: 0.86rem;
    color: var(--muted);
}

/* ── Dark ───────────────────────────────────────────────────
   Same rules, inverted tokens. Selectors are deliberately
   three-deep so they out-specify the older [data-theme="dark"]
   .chapter-content … rules still sitting in css/theme.css. */

[data-theme="dark"] body.plain {
    /* Tokens are aliases onto the shared --dk-* flavor variables
       (css/theme.css) rather than fixed hex, so switching GitHub
       Dark / Dimmed / High Contrast in the theme picker re-themes
       the notes pages too, instead of leaving them pinned to one
       look. --link stays the site's violet regardless of flavor,
       matching --dk-link. */
    --ink: var(--dk-heading);
    --body: var(--dk-text);
    --muted: var(--dk-muted);
    --faint: var(--dk-faint);
    --rule: var(--dk-border);
    --link: var(--dk-link);
    --link-hover: var(--dk-link-hover);
    --page: var(--dk-bg);
    --wash: var(--dk-surface);

    /* Same noise tile, lifted a little: on a dark ground the grey
       specks read as grain rather than dirt. The drawn rule is
       restruck in the flavor's border colour. */
    --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)' opacity='0.055'/%3E%3C/svg%3E");
    --hand-rule: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='8' viewBox='0 0 200 8' preserveAspectRatio='none'%3E%3Cpath d='M0 4.2 C 12 2.6, 26 5.6, 40 4.1 S 68 2.4, 82 4.4 S 110 6, 124 3.9 S 152 2.5, 166 4.6 S 190 5.4, 200 3.8' fill='none' stroke='%234a515b' stroke-width='1.2' stroke-linecap='round'/%3E%3C/svg%3E");

    --grid: rgba(169, 139, 240, 0.07);

    /* Dark paper gets its own palette rather than borrowing
       --dk-surface. The theme surface is tuned for panels sitting on
       the page; a sheet of card needs to be warmer and further from
       the desk than that, or it just looks like a grey box. These are
       fixed values on purpose — the text tokens above still follow
       the GitHub flavour, only the paper itself is pinned. */
    --desk: var(--dk-bg);
    --sheet: rgba(255, 255, 255, 0.005);
    --dot: rgba(173, 186, 199, 0.065);
    --margin-ink: rgba(214, 116, 110, 0.13);
    --punch-core: rgba(0, 0, 0, 0.12);

    /* Longhand, not the `background` shorthand: the shorthand would
       reset background-image and take the grain with it. */
    /* Restated, not inherited: css/theme.css carries
       [data-theme="dark"] body { background: ... } — a shorthand at
       higher specificity than body.plain, which resets
       background-image and takes the dot field with it. The image
       has to be re-declared at this weight to survive. */
    background-color: var(--desk);
    background-image:
        radial-gradient(circle at 1px 1px, var(--dot) 0 1.3px, transparent 1.7px),
        var(--grain);
    background-size: 22px 22px, 200px 200px;
    background-position: 8px 12px, left top;
    color: var(--body);
}

[data-theme="dark"] body.plain h1,
[data-theme="dark"] body.plain .note-index h2,
[data-theme="dark"] body.plain .chapter-content h2,
[data-theme="dark"] body.plain .chapter-content h3,
[data-theme="dark"] body.plain .chapter-content h4 {
    color: var(--ink);
    border: none;
    background: none;
}

[data-theme="dark"] body.plain .chapter-content p,
[data-theme="dark"] body.plain .chapter-content li,
[data-theme="dark"] body.plain .lede {
    color: var(--body);
}

[data-theme="dark"] body.plain .chapter-content blockquote {
    color: var(--muted);
    border-left-color: var(--rule);
}

[data-theme="dark"] body.plain .chapter-content pre {
    background: var(--wash);
    border: none;
}

[data-theme="dark"] body.plain .chapter-content p code,
[data-theme="dark"] body.plain .chapter-content li code,
[data-theme="dark"] body.plain .chapter-content td code {
    background: var(--wash);
    color: var(--ink);
}

[data-theme="dark"] body.plain .code-copy-btn {
    background: var(--page);
    border: 1px solid var(--rule);
    color: var(--muted);
    box-shadow: none;
}

[data-theme="dark"] body.plain .chapter-content thead th {
    color: var(--ink);
    background: none;
    border-bottom: 1px solid var(--rule);
}

[data-theme="dark"] body.plain .chapter-content tbody td {
    border-bottom: 1px solid var(--rule);
}

[data-theme="dark"] body.plain .chapter-content figcaption {
    /* --muted is tuned for the sans; the hand face needs the lift */
    color: var(--dk-text);
    opacity: 0.82;
}

[data-theme="dark"] body.plain .note-box {
    background: none !important;
    border: none;
    border-left: 2px solid var(--rule) !important;
}

[data-theme="dark"] body.plain .note-box .note-label {
    color: var(--muted) !important;
}

[data-theme="dark"] body.plain .chapter-content .part-marker {
    /* longhand: `background: none` here would take --hand-rule with it */
    border-top: none;
    background-color: transparent;
    background-image: var(--hand-rule);
}

[data-theme="dark"] body.plain .chapter-content .part-marker .part-name {
    color: var(--ink);
}

[data-theme="dark"] body.plain .chapter-content .part-marker .part-label,
[data-theme="dark"] body.plain .chapter-content .part-marker .part-sub {
    color: var(--muted);
}

[data-theme="dark"] body.plain .chapter-content .fig-row .fig-cell {
    background: none;
    border: none;
}

/* A figure that has not been inlined yet (no JS, file:// preview)
   still carries its original light-page colours, so it keeps the
   light backing. Inlined SVGs are theme-aware and get nothing. */
[data-theme="dark"] body.plain .chapter-content figure img[src$=".svg"] {
    background: #f7f7f7;
    border-radius: 3px;
    padding: 10px;
}

[data-theme="dark"] body.plain :is(.dgm-widget, .note-widget) {
    /* longhand for the same reason: the shorthand resets the ruling */
    background-color: var(--wash);
    background-image:
        repeating-linear-gradient(to right, var(--grid) 0 1px, transparent 1px 22px),
        repeating-linear-gradient(to bottom, var(--grid) 0 1px, transparent 1px 22px);
    border-color: var(--rule);
}

[data-theme="dark"] body.plain :is(.dgm-widget, .note-widget) button {
    background: var(--page);
    border-color: var(--rule);
    color: var(--ink);
}

[data-theme="dark"] body.plain :is(.dgm-widget, .note-widget) button:hover {
    border-color: var(--ink);
}

/* Widget canvases are drawn with dark ink, same as the SVGs. */
[data-theme="dark"] body.plain :is(.dgm-widget, .note-widget) canvas {
    background: #f7f7f7;
    border-radius: 3px;
}

[data-theme="dark"] body.plain .ref-pop {
    background: var(--wash);
    border-color: var(--rule);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] body.plain .ref-pop-label {
    background: var(--wash);
    border-bottom-color: var(--rule);
    color: var(--muted);
}

/* ── Small screens ──────────────────────────────────────── */

@media (max-width: 640px) {
    body.plain {
        font-size: 16px;
    }

    body.plain .container {
        padding: 0 18px 64px;
    }

    body.plain h1 {
        font-size: 1.55rem;
    }

    body.plain .chapter-content h2 {
        font-size: 1.16rem;
        margin-top: 40px;
    }

    body.plain .site-header {
        padding-top: 28px;
        margin-bottom: 40px;
    }
}

/* ── Print ──────────────────────────────────────────────── */

@media print {

    body.plain .site-header,
    body.plain .site-footer,
    body.plain .code-copy-btn,
    body.plain .theme-picker,
    body.plain :is(.dgm-widget, .note-widget) {
        display: none;
    }

    body.plain .container {
        max-width: none;
    }
}


/* ═══════════════════════════════════════════════════════════
   Turning it off.

   The leaf is furniture, and furniture should be removable.
   Uncomment this block and the notes collapse back to the plain
   column this file was written as: no desk, no sheet, no holes,
   no margin rule, no ruling, no numerals, no grain, no hand face.

   body.plain {
       --grain: none;
       --hand-rule: none;
       --hand-font: inherit;
       --grid: transparent;
       --desk: var(--page);
       --sheet: var(--page);
                --rule-line: transparent;
       --margin-ink: transparent;
          --punch-core: transparent;
                  }
   body.plain { background-image: none; }
   body.plain .container { max-width: 780px; padding: 0 24px 96px; }
   body.plain .container > main {
       padding: 0; background-image: none; box-shadow: none;
   }
   body.plain .container > main::before,
   body.plain .container > main::after { content: none; }
   body.plain .container > .site-header,
   body.plain .container > .site-footer { padding-left: 0; padding-right: 0; }
   body.plain main[data-ch] > h1::before { content: none; }
   body.plain .chapter-content .katex-display {
       background: none; border: none; padding: 0;
   }
   ═══════════════════════════════════════════════════════════ */
