/*
  Programming Without Borders: the coding site's only stylesheet.

  The colours are English News Korea's (/ENK/): slate panels, purple links and the star gold for
  the pin pads that mark a post's place in its series. (The token names --mask and --copper are
  from the old circuit-board palette.) Headings use
  Bahnschrift (the DIN face that ships with Windows); everything else is the reader's own system
  font. No web fonts are downloaded.

  Colours are custom properties, so dark mode only swaps the tokens: the OS setting decides,
  unless the reader picked a theme with the toggle (stored as <html data-theme="...">).
*/

:root {
    --paper: #f4f5f8;
    --surface: #ffffff;
    --ink: #1c1d22;
    --muted: #5b5f6a;
    --rule: #dcdfe6;
    --mask: #5b43d6;
    --mask-strong: #4632b0;
    --copper: #b07d00;
    --copper-soft: #f6e7b8;
    --code-bg: #eef0f5;
    --on-mask: #ffffff;

    --tok-keyword: #5b43d6;
    --tok-type: #1f5f8b;
    --tok-string: #9a4f12;
    --tok-number: #b0306a;
    --tok-comment: #6b7080;
    --tok-pre: #0f7f72;

    --font-display: Bahnschrift, "DIN Alternate", "D-DIN", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
    --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
    --font-mono: "Cascadia Code", "Cascadia Mono", ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

    --measure: 46rem;
    --wide: 72rem;
    --gutter: 16px;
    --radius: 6px;

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --paper: #20232a;
        --surface: #2b2f38;
        --ink: #ffffff;
        --muted: #b8bfcc;
        --rule: #3a3f4b;
        --mask: #b9abff;
        --mask-strong: #d6ceff;
        --copper: #f5b301;
        --copper-soft: #4a3d12;
        --code-bg: #252830;
        --on-mask: #20232a;

        --tok-keyword: #b9abff;
        --tok-type: #7cc0ec;
        --tok-string: #f0b27a;
        --tok-number: #f28fb8;
        --tok-comment: #8b92a0;
        --tok-pre: #33d6c0;

        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --paper: #20232a;
    --surface: #2b2f38;
    --ink: #ffffff;
    --muted: #b8bfcc;
    --rule: #3a3f4b;
    --mask: #b9abff;
    --mask-strong: #d6ceff;
    --copper: #f5b301;
    --copper-soft: #4a3d12;
    --code-bg: #252830;
    --on-mask: #20232a;

    --tok-keyword: #b9abff;
    --tok-type: #7cc0ec;
    --tok-string: #f0b27a;
    --tok-number: #f28fb8;
    --tok-comment: #8b92a0;
    --tok-pre: #33d6c0;

    color-scheme: dark;
}

/* ---------- Base ---------- */

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

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

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 1.0625rem/1.65 var(--font-body);
    overflow-wrap: break-word;
}

a { color: var(--mask); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--mask-strong); text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--copper); outline-offset: 2px; border-radius: 2px; }

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.005em;
    margin: 2rem 0 0.75rem;
}
h1 { font-size: clamp(1.9rem, 1.4rem + 2.2vw, 2.6rem); line-height: 1.1; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.3rem; }
h4, h5, h6 { font-size: 1.1rem; }

p, ul, ol, dl, table, blockquote { margin: 0 0 1rem; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2rem 0; }
small { font-size: 0.875rem; }

.visually-hidden {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: -999px; top: 0; padding: 0.5rem 1rem; background: var(--surface); }
.skip:focus { left: var(--gutter); z-index: 10; }

/* ---------- Header and footer ---------- */

.site-header { border-bottom: 1px solid var(--rule); }
.bar {
    max-width: var(--wide);
    margin: 0 auto;
    padding: 0.75rem var(--gutter);
    display: flex;
    align-items: center;
    gap: 0.5rem 1.5rem;
    flex-wrap: wrap;
}
.brand {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.2rem;
    color: var(--ink);
    text-decoration: none;
    margin-right: auto;
}
.brand:hover { color: var(--mask); }
.site-nav { display: flex; gap: 0.25rem 1.25rem; flex-wrap: wrap; }
.site-nav a {
    color: var(--muted);
    text-decoration: none;
    padding: 0.35rem 0;
    border-bottom: 2px solid transparent;
}
.site-nav a:hover { color: var(--ink); }
.site-nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--copper); }

@media (max-width: 700px) {
    /* Phones: name and theme button on one line, the menu below as one row that scrolls sideways. */
    .bar { display: grid; grid-template-columns: 1fr auto; padding-bottom: 0; }
    .brand { grid-column: 1; grid-row: 1; }
    .theme-toggle { grid-column: 2; grid-row: 1; }
    .site-nav {
        grid-column: 1 / -1;
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        margin: 0 calc(-1 * var(--gutter));
        padding: 0 var(--gutter);
        white-space: nowrap;
    }
    .site-nav::-webkit-scrollbar { display: none; }
    .site-nav a { padding: 0.55rem 0; }
}

.theme-toggle {
    display: inline-grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--rule);
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--muted); }
.theme-toggle svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .sun { display: inline; }
    :root:not([data-theme="light"]) .theme-toggle .moon { display: none; }
}

main { max-width: var(--wide); margin: 0 auto; padding: 0 var(--gutter) 3rem; }

.site-footer {
    max-width: var(--wide);
    margin: 0 auto;
    padding: 1.5rem var(--gutter) 2.5rem;
    border-top: 1px solid var(--rule);
    color: var(--muted);
    font-size: 0.9rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5rem 2rem;
}
.site-footer p { margin: 0; }
.site-footer a { color: var(--muted); margin-left: 1rem; }
.site-footer a:first-child { margin-left: 0; }

/* ---------- Shared pieces ---------- */

.page-header { max-width: var(--measure); margin: 2.5rem 0 2rem; }
.page-header h1 { margin-top: 0; }
.lede { font-size: 1.15rem; color: var(--muted); max-width: 40rem; }
.prose { max-width: var(--measure); }
.prose h2 { font-size: 1.35rem; margin-top: 2.25rem; }

/* Pin pads: one per post in a series, the current one filled with copper. */
.pins { display: inline-flex; flex-wrap: wrap; gap: 4px; vertical-align: middle; }
.pins .pad {
    width: 11px;
    height: 11px;
    border: 1.5px solid var(--copper);
    border-radius: 2px;
    background: transparent;
}
.pins a.pad:hover { background: var(--copper-soft); }
.pins .pad.on { background: var(--copper); }

/* Lists of posts: title, date, summary. */
.post-list { list-style: none; padding: 0; margin: 0 0 1.5rem; max-width: var(--measure); }
.post-item { padding: 0.9rem 0; border-top: 1px solid var(--rule); }
.post-item:first-child { border-top: 0; }
.post-item-title { font-weight: 600; font-size: 1.08rem; }
.post-item-meta { display: block; color: var(--muted); font-size: 0.9rem; margin-top: 0.15rem; }
.post-item-meta a { color: var(--muted); }
.post-item-summary { margin: 0.35rem 0 0; }
.post-list.numbered { counter-reset: part; }
.post-list.numbered .post-item { counter-increment: part; padding-left: 2.6rem; position: relative; }
.post-list.numbered .post-item::before {
    content: counter(part);
    position: absolute;
    left: 0;
    top: 0.95rem;
    width: 1.8rem;
    height: 1.8rem;
    display: grid;
    place-items: center;
    border: 1.5px solid var(--copper);
    border-radius: 3px;
    font: 600 0.85rem/1 var(--font-display);
    color: var(--copper);
}

/* ---------- Home ---------- */

.hero { padding: 3.5rem 0 2.5rem; max-width: 52rem; }
.hero h1 { font-size: clamp(2.3rem, 1.5rem + 4vw, 4rem); line-height: 1.02; letter-spacing: -0.02em; margin: 0 0 1.25rem; max-width: 16ch; }
.hero .lede { font-size: 1.25rem; max-width: 38rem; }
.elsewhere { margin-top: 3rem; max-width: var(--measure); padding: 1.25rem 1.5rem; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); }
.elsewhere h2 { margin-top: 0; font-size: 1.35rem; }
.elsewhere p { margin: 0; }

/* ---------- The guide (home page) and the archive ---------- */

.toc { display: flex; flex-wrap: wrap; gap: 0.4rem 0.5rem; margin-top: 2rem; }
.toc a {
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--rule);
    border-radius: 999px;
    text-decoration: none;
    font-size: 0.92rem;
    background: var(--surface);
}
.toc a:hover { border-color: var(--mask); }
.guide-section { padding-top: 0.5rem; scroll-margin-top: 1rem; }
.guide-section h2 { margin-bottom: 0.25rem; }
.guide-blurb { color: var(--muted); max-width: var(--measure); }
.year h2 { font-size: 1.4rem; border-bottom: 1px solid var(--rule); padding-bottom: 0.4rem; max-width: var(--measure); }

.tag-cloud { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; max-width: var(--measure); }
.tag-cloud a { display: inline-block; padding: 0.3rem 0.75rem; border: 1px solid var(--rule); border-radius: 999px; text-decoration: none; background: var(--surface); }
.tag-cloud span { color: var(--muted); font-size: 0.85rem; }

/* ---------- Search and the register index ---------- */

.search-form { display: flex; gap: 0.5rem; margin: 1rem 0 0.75rem; max-width: 36rem; }
.search-form input, .reg-filter input {
    flex: 1; min-width: 0; font: inherit; color: var(--ink); background: var(--surface);
    border: 1px solid var(--rule); border-radius: 4px; padding: 0.55rem 0.8rem;
}
.search-form input:focus-visible, .reg-filter input:focus-visible { outline: 2px solid var(--mask); outline-offset: 0; border-color: var(--mask); }
.search-form button { font: 600 1rem var(--font-body); padding: 0.55rem 1.1rem; border-radius: 4px; border: 1px solid var(--mask); background: var(--mask); color: var(--on-mask); cursor: pointer; }
.search-status { color: var(--muted); font-size: 0.95rem; margin: 0; }
.search-results { list-style: none; padding: 0; margin: 0 0 1.5rem; max-width: var(--measure); }
.search-results li { padding: 1rem 0; border-top: 1px solid var(--rule); }
.search-results li:first-child { border-top: 0; }
.search-title { font-weight: 600; font-size: 1.1rem; }
.search-meta { display: block; color: var(--muted); font-size: 0.9rem; margin-top: 0.1rem; }
.search-results p { margin: 0.4rem 0 0; }
.search-heads, .search-regs { font-size: 0.92rem; color: var(--muted); }
.search-regs code { margin-right: 0.15rem; }
mark { background: var(--copper-soft); color: inherit; border-radius: 2px; padding: 0 0.1em; }

.reg-filter { margin: 1rem 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.7rem; max-width: 36rem; }
.reg-filter input { flex: 1 1 10rem; font-family: var(--font-mono); font-size: 0.95rem; }
.reg-list { list-style: none; padding: 0; margin: 0 0 2.5rem; max-width: 60rem; }
.reg-list li { display: grid; grid-template-columns: 11rem minmax(0, 1fr); gap: 0.1rem 1.25rem; padding: 0.45rem 0; border-top: 1px solid var(--rule); align-items: baseline; }
.reg-list li[hidden] { display: none; }
.reg-list code { justify-self: start; font-weight: 600; scroll-margin-top: 1rem; }
.reg-posts { grid-column: 2; font-size: 0.95rem; }
.reg-bits { grid-column: 2; font: 0.82rem/1.5 var(--font-mono); color: var(--muted); overflow-wrap: anywhere; }
@media (max-width: 600px) {
    .reg-list li { grid-template-columns: 1fr; }
    .reg-posts, .reg-bits { grid-column: 1; }
}

/* ---------- Calculators (/tools/ and inside posts) ---------- */

.crumb { margin: 0 0 0.3rem; font-size: 0.95rem; }
.calc { display: grid; grid-template-columns: minmax(0, 20rem) minmax(0, 1fr); gap: 1.5rem 2.5rem; align-items: start; max-width: 60rem; margin-bottom: 2rem; }
.calc-form { display: grid; grid-template-columns: minmax(0, 1fr) 8rem; gap: 0.7rem 1rem; align-items: center; }
.calc-form label { font-size: 0.95rem; }
.calc-form input, .calc-form select { width: 100%; min-width: 0; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--rule); border-radius: 4px; padding: 0.45rem 0.6rem; }
.calc-form input:disabled { color: var(--muted); }
.calc-form input:focus-visible, .calc-form select:focus-visible { outline: 2px solid var(--mask); outline-offset: 0; border-color: var(--mask); }
.calc-out { min-width: 0; padding: 1.1rem 1.25rem; background: var(--surface); border: 1px solid var(--rule); border-left: 3px solid var(--copper); border-radius: var(--radius); }
.calc-result { margin: 0 0 0.5rem; font: 600 1.9rem/1.1 var(--font-display); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.calc-working { margin: 0 0 0.4rem; }
.calc-check { margin: 0 0 1rem; font-size: 0.95rem; font-weight: 600; color: var(--muted); }
.calc-check.bad { color: #c2410c; }
:root[data-theme="dark"] .calc-check.bad { color: #ffa36b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .calc-check.bad { color: #ffa36b; } }
.calc-code pre { margin: 0 0 0.6rem; }
.calc-code button { font: 600 0.9rem var(--font-body); padding: 0.4rem 0.9rem; border-radius: 4px; border: 1px solid var(--mask); background: transparent; color: var(--mask); cursor: pointer; }
.calc-code button:hover { background: var(--paper); }
@media (max-width: 760px) { .calc { grid-template-columns: minmax(0, 1fr); } }
.tool-list .post-item-title { font-size: 1.15rem; }
.tool-list li { padding: 0.9rem 0; border-top: 1px solid var(--rule); }
.tool-list li:first-child { border-top: 0; }

.post-tool { margin: 3rem 0 0; padding-top: 1.5rem; border-top: 1px solid var(--rule); }
.post-tool h2 { margin-top: 0; font-size: 1.35rem; }
.post-tool .calc { grid-template-columns: minmax(0, 1fr); gap: 1.25rem; margin-bottom: 0.75rem; }
.post-tool-more { font-size: 0.95rem; margin: 0; }

/* ---------- Post ---------- */

.post { max-width: var(--measure); margin: 0 auto; }
.post-header { margin: 2.5rem 0 1.5rem; }
.post-header h1 { margin: 0.4rem 0 0.75rem; }
.post-series { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.8rem; margin: 0; color: var(--muted); font-size: 0.95rem; }
.post-series > a { font-weight: 600; }
.post-meta { color: var(--muted); font-size: 0.95rem; display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; margin: 0; }
.tags { display: inline-flex; flex-wrap: wrap; gap: 0.4rem; }
.tags a { font-size: 0.85rem; padding: 0.05rem 0.55rem; border: 1px solid var(--rule); border-radius: 999px; text-decoration: none; color: var(--muted); }
.tags a:hover { color: var(--mask); border-color: var(--mask); }

/* Beside the post on wide screens: the series list and "On this page". On narrow screens the
   same lists are boxes under the title that open. */
.post-rail { display: none; }
.post-boxes { display: grid; gap: 0.6rem; margin-bottom: 1.75rem; }
.post-box { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); }
.post-box summary { cursor: pointer; padding: 0.7rem 1rem; font: 600 1rem/1.3 var(--font-display); }
.post-box ol { margin: 0; padding: 0 1rem 0.9rem 2.4rem; font-size: 0.95rem; }
.post-box ul { list-style: none; margin: 0; padding: 0 1rem 0.9rem; font-size: 0.95rem; }
.post-box li, .post-rail li { padding: 0.2rem 0; }
.post-box li[aria-current="page"], .post-rail li[aria-current="page"] { font-weight: 600; }
.post-box li[aria-current="page"]::marker, .post-rail li[aria-current="page"]::marker { color: var(--copper); }
.post-box .toc-3, .post-rail .toc-3 { padding-left: 1rem; }

@media (min-width: 1100px) {
    .post.has-rail {
        max-width: calc(var(--measure) + 18rem);
        display: grid;
        grid-template-columns: minmax(0, var(--measure)) 15rem;
        column-gap: 3rem;
        align-items: start;
    }
    .post.has-rail > * { grid-column: 1; }
    .post.has-rail > .post-rail {
        display: block;
        grid-column: 2;
        grid-row: 1 / span 8;
        position: sticky;
        top: 1.5rem;
        max-height: calc(100vh - 3rem);
        overflow-y: auto;
        scrollbar-width: thin;
        margin-top: 2.5rem;
        padding-left: 1rem;
        border-left: 2px solid var(--rule);
        font-size: 0.92rem;
        line-height: 1.4;
    }
    .post-rail nav + nav { margin-top: 1.75rem; }
    .rail-title { font: 600 1rem/1.3 var(--font-display); margin: 0 0 0.6rem; }
    .rail-title a { color: var(--ink); text-decoration: none; }
    .post-rail ol { margin: 0; padding-left: 1.3rem; }
    .post-rail ul { list-style: none; margin: 0; padding: 0; }
    .post-rail li a { color: var(--muted); text-decoration: none; }
    .post-rail li a:hover { color: var(--mask); }
    .post-rail li a.here { color: var(--ink); font-weight: 600; }
    .post.has-rail > .post-boxes { display: none; }
}

/* The downloads of a post, under its title. */
.code-box { border: 1px solid var(--rule); border-left: 3px solid var(--copper); border-radius: var(--radius); background: var(--surface); padding: 0.8rem 1rem; margin-bottom: 1.75rem; }
.code-box h2 { font-size: 1rem; margin: 0 0 0.4rem; }
.code-box ul { list-style: none; margin: 0; padding: 0; }
.code-box li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.1rem 0.9rem; padding: 0.2rem 0; }
.code-file { font-family: var(--font-mono); font-size: 0.92rem; font-weight: 600; overflow-wrap: anywhere; }
.code-about { color: var(--muted); font-size: 0.9rem; }
.code-github { font-size: 0.9rem; margin-left: auto; }

/* Body text of a post */
.post-body { min-width: 0; }
.post-body h2, .post-body h3 { scroll-margin-top: 1rem; }
.post-body h2 { border-bottom: 1px solid var(--rule); padding-bottom: 0.3rem; margin-top: 2.75rem; }
.post-body > h2:first-child { margin-top: 0; }
.post-body h2 + h3 { margin-top: 1.25rem; }
/* The link to a heading: shown when the heading is pointed at, or reached with the keyboard. */
.heading-link { margin-left: 0.4rem; color: var(--muted); text-decoration: none; font-weight: 400; opacity: 0; }
.post-body :is(h2, h3):hover .heading-link, .heading-link:focus-visible { opacity: 1; }
@media (hover: none) { .heading-link { opacity: 0.6; } }

/* An aside: the author's "TL;DR" and "Note" digressions, which can be skipped. */
.aside { margin: 1.5rem 0; padding: 0.9rem 1.1rem 0.1rem; background: var(--surface); border: 1px solid var(--rule); border-left: 3px solid var(--mask); border-radius: var(--radius); font-size: 0.97rem; }
.aside > p:first-child { margin-bottom: 0.4rem; }
.aside > p:first-child strong { font: 600 0.82rem/1 var(--font-display); letter-spacing: 0.08em; text-transform: uppercase; color: var(--mask); }
.post-body img {
    display: block;
    max-width: 100%;
    max-height: 85vh;
    width: auto;
    height: auto;
    margin: 1.5rem auto;
    border-radius: 4px;
}
.post-body a:has(> img) { display: block; }
.post-body img.can-enlarge { cursor: zoom-in; }

/* A picture opened full size: it fits the window first, and a click shows every pixel. */
.lightbox { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: rgb(12 13 16 / 0.94); overflow: auto; }
.lightbox::backdrop { background: rgb(12 13 16 / 0.94); }
.lightbox-stage { min-width: 100%; min-height: 100%; display: grid; place-items: center; padding: 3.25rem 1rem 1rem; }
.lightbox img { display: block; max-width: 100%; max-height: calc(100vh - 4.25rem); width: auto; height: auto; background: #fff; border-radius: 4px; cursor: zoom-in; }
.lightbox.actual .lightbox-stage { width: max-content; height: max-content; }
.lightbox.actual img { max-width: none; max-height: none; cursor: zoom-out; }
.lightbox-close { position: fixed; top: 0.6rem; right: 0.9rem; font: 600 0.95rem var(--font-body); padding: 0.45rem 0.9rem; border-radius: 4px; border: 1px solid #5b5f6a; background: #2b2f38; color: #fff; cursor: pointer; }
.lightbox-close:hover { border-color: #fff; }
.post-body blockquote { margin: 1.5rem 0; padding: 0.25rem 1.25rem; border-left: 3px solid var(--copper); color: var(--muted); }
.post-body table { display: block; overflow-x: auto; border-collapse: collapse; font-size: 0.95rem; }
.post-body th, .post-body td { border: 1px solid var(--rule); padding: 0.4rem 0.7rem; text-align: left; }
.post-body li { margin-bottom: 0.3rem; }

/* Code */
code, pre, kbd, samp { font-family: var(--font-mono); font-size: 0.9em; font-variant-ligatures: none; }
:not(pre) > code {
    background: var(--code-bg);
    border: 1px solid var(--rule);
    border-radius: 4px;
    padding: 0.05em 0.35em;
    overflow-wrap: anywhere;
}
pre {
    margin: 0 0 1.25rem;
    padding: 1rem 1.1rem;
    overflow-x: auto;
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
    tab-size: 4;
    background: var(--code-bg);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    font-size: 0.86rem;
    line-height: 1.55;
}
pre code { font-size: inherit; background: none; border: 0; padding: 0; }

.code-block { position: relative; margin: 0 0 1.25rem; }
.code-block pre { margin: 0; padding-top: 2.1rem; }
.code-tools {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0.5rem 0 1.1rem;
    font-size: 0.78rem;
    color: var(--muted);
    pointer-events: none;
}
.code-tools button {
    pointer-events: auto;
    font: inherit;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: 4px;
    padding: 0.15rem 0.6rem;
    cursor: pointer;
}
.code-tools button:hover { color: var(--ink); border-color: var(--muted); }

.tok-keyword { color: var(--tok-keyword); font-weight: 600; }
.tok-type { color: var(--tok-type); }
.tok-string { color: var(--tok-string); }
.tok-number { color: var(--tok-number); }
.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-pre { color: var(--tok-pre); }

/* Previous / next within the series */
.series-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 3rem 0 2rem; }
.series-nav a {
    display: block;
    padding: 0.9rem 1.1rem;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    text-decoration: none;
    font-weight: 600;
    line-height: 1.35;
}
.series-nav a:hover { border-color: var(--mask); }
.series-nav span { display: block; color: var(--muted); font-weight: 400; font-size: 0.85rem; margin-bottom: 0.25rem; }
.series-nav .next { grid-column: 2; text-align: right; }
@media (max-width: 600px) {
    .series-nav { grid-template-columns: 1fr; }
    .series-nav .next { grid-column: 1; }
}

.comments { margin: 2rem 0; padding-top: 1.5rem; border-top: 1px solid var(--rule); }
.load-comments {
    font: 600 1rem var(--font-body);
    padding: 0.6rem 1.1rem;
    border-radius: 4px;
    border: 1px solid var(--mask);
    background: transparent;
    color: var(--mask);
    cursor: pointer;
}
.load-comments:hover { background: var(--surface); }
.comments-note { color: var(--muted); font-size: 0.9rem; margin-top: 0.5rem; }
.comments.loaded .load-comments, .comments.loaded .comments-note, .comments.loaded .old-comments { display: none; }

/* The comments from Disqus, kept in the page. Replies sit inside the comment they answer. */
.old-comments { margin-bottom: 1.5rem; }
.old-comments > summary { cursor: pointer; font: 600 1.35rem/1.3 var(--font-display); padding: 0.3rem 0; }
.old-comments-list { list-style: none; margin: 0; padding: 0; }
.old-comments-list li { margin-top: 1.25rem; min-width: 0; }
.old-comments-list .old-comments-list { margin-left: 0.25rem; padding-left: 1rem; border-left: 2px solid var(--rule); }
.old-comments-list.depth-4 .old-comments-list { margin-left: 0; padding-left: 0; border-left: 0; }
.old-comment-by { margin: 0 0 0.3rem; font-size: 0.92rem; color: var(--muted); display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.7rem; }
.old-comment-by strong { color: var(--ink); font-size: 1rem; }
.old-comment-author { font: 600 0.72rem/1 var(--font-display); letter-spacing: 0.08em; text-transform: uppercase; color: var(--on-mask); background: var(--mask); border-radius: 3px; padding: 0.2rem 0.4rem; }
.old-comment-text { font-size: 0.97rem; overflow-wrap: anywhere; }
.old-comment-text p { margin: 0 0 0.6rem; }
.old-comment-text blockquote { margin: 0 0 0.6rem; padding: 0 0 0 0.9rem; border-left: 3px solid var(--rule); color: var(--muted); }

@media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
}

/* Printing a post: just the article, black on white, code that wraps instead of being cut off,
   and the address of every outside link written after it. */
@media print {
    .site-header, .site-footer, .post-rail, .post-boxes, .series-nav, .load-comments, .comments-note, .code-tools, .post-tool,
    .theme-toggle, .skip, .post-series .pins, .heading-link, .code-github { display: none !important; }
    :root, :root[data-theme] { --paper: #fff; --ink: #000; --muted: #444; --line: #bbb; }
    html, body { background: #fff; color: #000; }
    body { font-size: 11pt; }
    main, .post, .post.has-rail { display: block; max-width: none; margin: 0; padding: 0; }
    a { color: #000; }
    .post-body a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.85em; color: #444; word-break: break-all; }
    pre { white-space: pre-wrap; overflow: visible; border: 1px solid #bbb; background: #fff !important; break-inside: auto; }
    pre code, code { color: #000 !important; font-size: 9pt; }
    [class^="tok-"] { color: #000 !important; font-weight: normal; }
    .tok-comment { font-style: italic; }
    img { max-height: 60vh; break-inside: avoid; }
    h1, h2, h3 { break-after: avoid; }
}
