/* ==========================================================================
   opencode — a Ghost theme with the visual language of a docs site
   No build step. Single stylesheet, custom properties, flat chrome.
   ========================================================================== */

/* ---------- Fonts ---------------------------------------------------------
   Self-hosted IBM Plex, latin subset. Same faces the reference uses.
   -------------------------------------------------------------------------- */

@font-face {
    font-family: "Plex Mono";
    src: url("../fonts/IBMPlexMono-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Plex Mono";
    src: url("../fonts/IBMPlexMono-Medium.woff2") format("woff2");
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Plex Mono";
    src: url("../fonts/IBMPlexMono-SemiBold.woff2") format("woff2");
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Plex Sans";
    src: url("../fonts/IBMPlexSans-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Plex Sans";
    src: url("../fonts/IBMPlexSans-SemiBold.woff2") format("woff2");
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

/* ---------- Tokens ------------------------------------------------------- */

:root {
    --font-mono: "Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --font-body: "Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    /* Layout constants lifted from Starlight */
    --nav-h: 3.5rem;
    --rail-w: 18.75rem;
    --content-w: 45rem;
    --toc-w: 15.5rem;

    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;

    /* Ghost injects --ghost-accent-color from Design → Brand → Accent colour.
       That is the single source of truth for the accent; the fallback only
       applies if the site somehow has no accent set. */
    --accent: var(--ghost-accent-color, hsl(224, 100%, 60%));
}

/* Dark — the default surface, and also the base palette. Declaring it on bare
   :root means the page is styled even when the preference script never runs;
   [data-theme="light"] below is the only override that matters. */
:root,
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: hsl(224, 10%, 10%);
    --bg-nav: hsl(224, 10%, 10%);
    --bg-raise: hsl(224, 14%, 16%);
    --bg-code: hsl(224, 14%, 16%);
    --bg-inset: hsl(224, 12%, 13%);
    --bg-hover: hsl(224, 12%, 15%);

    --text: hsl(224, 20%, 94%);
    --text-strong: hsl(0, 0%, 100%);
    --text-2: hsl(224, 6%, 66%);
    /* 4.68:1 on the page background, so meta text clears AA */
    --text-3: hsl(224, 8%, 53%);

    --border: hsl(224, 6%, 23%);
    --border-soft: hsl(224, 10%, 18%);
    /* 3.04:1 — for borders that define an interactive control */
    --border-strong: hsl(224, 7%, 41%);

    /* Links and text sit on the dark surface, so the accent is lightened. */
    --accent-text: color-mix(in srgb, var(--accent) 72%, white);

    /* code tokens */
    --tok-keyword: hsl(224, 100%, 74%);
    --tok-string: hsl(152, 45%, 62%);
    --tok-number: hsl(28, 80%, 68%);
    --tok-comment: var(--text-3);
    --tok-fn: hsl(45, 85%, 70%);
    --tok-type: hsl(190, 70%, 70%);
    --tok-punct: hsl(224, 10%, 72%);
}

/* Light — mirrored from the reference's own light palette */
:root[data-theme="light"] {
    color-scheme: light;
    --bg: hsl(0, 0%, 100%);
    --bg-nav: hsl(0, 0%, 100%);
    --bg-raise: hsl(224, 19%, 97%);
    --bg-code: hsl(224, 19%, 97%);
    --bg-inset: hsl(224, 19%, 97%);
    --bg-hover: hsl(224, 20%, 95%);

    --text: hsl(224, 10%, 18%);
    --text-strong: hsl(224, 10%, 10%);
    /* 8.32:1 — kept distinct from tertiary after lifting it to AA */
    --text-2: hsl(224, 9%, 32%);
    /* 4.87:1 on white */
    --text-3: hsl(224, 7%, 46%);

    --border: hsl(224, 20%, 88%);
    --border-soft: hsl(224, 20%, 93%);
    /* 3.03:1 — for borders that define an interactive control */
    --border-strong: hsl(224, 10%, 60%);

    /* Same accent on a white surface needs darkening, not lightening. */
    --accent-text: color-mix(in srgb, var(--accent) 82%, black);

    --tok-keyword: hsl(234, 80%, 50%);
    --tok-string: hsl(152, 55%, 32%);
    --tok-number: hsl(20, 80%, 42%);
    --tok-comment: var(--text-3);
    --tok-fn: hsl(38, 85%, 35%);
    --tok-type: hsl(192, 80%, 30%);
    --tok-punct: hsl(224, 10%, 35%);
}

/* ---------- Typographic features ----------------------------------------- */

/* Slashed zero wherever Plex Mono is used: unambiguous dates, IDs and code. */
.nav,
.rail,
.toc,
.foot,
.btn,
.chip,
.search,
.pagination,
.content__title,
.content__kicker,
.content__meta,
.content__count,
.index-row__title,
.index-row__meta,
.search-result,
.post-nav__dir,
.post-nav__title,
.post-hero__caption,
.code-block,
.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6,
.prose th,
.prose code,
.prose kbd {
    font-feature-settings: "zero" 1;
}

/* Even out heading breaks and avoid orphans in running text. Browsers that do
   not support these simply ignore them. */
.content__title,
.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
    text-wrap: balance;
}

.prose p,
.content__lede,
.index-row__excerpt,
.post-hero__caption {
    text-wrap: pretty;
}

/* ---------- Reset -------------------------------------------------------- */

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

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

img, svg { max-width: 100%; height: auto; }
img { display: block; }

a {
    color: var(--accent-text);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    text-decoration-color: color-mix(in srgb, var(--accent-text) 45%, transparent);
}
a:hover { text-decoration-color: currentColor; }

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

::selection {
    background: color-mix(in srgb, var(--accent) 35%, transparent);
    color: var(--text-strong);
}

.skip-link {
    position: absolute;
    left: 0.5rem;
    top: -3rem;
    z-index: 100;
    padding: 0.5rem 0.75rem;
    background: var(--bg-raise);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    text-decoration: none;
    color: var(--text-strong);
    transition: top 0.15s ease;
}
.skip-link:focus { top: 0.5rem; }

/* ---------- Nav ---------------------------------------------------------- */

.nav {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 1rem;
    height: var(--nav-h);
    padding-inline: 1rem;
    background: var(--bg-nav);
    border-bottom: 1px solid var(--border);
}

.nav__side {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1 1 0;
    min-width: 0;
}
.nav__side--right { justify-content: flex-end; }

.nav__burger {
    display: none;
    place-items: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    cursor: pointer;
}
.nav__burger:hover { color: var(--text-strong); border-color: var(--text-3); }

.nav__brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    font-family: var(--font-mono);
    font-size: 0.9375rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-strong);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nav__brand:hover { color: var(--accent-text); }

.nav__logo {
    width: 20px;
    height: 20px;
    border-radius: var(--radius-sm);
}

.nav__menu {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex: 0 0 auto;
}

.nav__link {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--text-2);
    text-decoration: none;
    white-space: nowrap;
}
.nav__link:hover,
.nav__link.is-active { color: var(--text-strong); }

.nav__progress {
    position: absolute;
    left: 0;
    bottom: -1px;
    height: 1px;
    width: 100%;
    transform: scaleX(0);
    transform-origin: 0 50%;
    background: var(--accent);
    opacity: 0;
    transition: opacity 0.2s ease;
}
.nav__progress.is-live { opacity: 1; }

/* Search button — wired to Ghost's native modal via data-ghost-search */
.search-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    height: 2rem;
    padding: 0 0.5rem;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    text-decoration: none;
    cursor: pointer;
}
.search-btn:hover {
    color: var(--text-strong);
    border-color: var(--text-3);
    background: var(--bg-hover);
}
.search-btn__kbd {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--text-3);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0.0625rem 0.25rem;
    line-height: 1.2;
}

/* Theme picker */
.picker { position: relative; }

.picker__summary {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    cursor: pointer;
    list-style: none;
}
.picker__summary::-webkit-details-marker { display: none; }
.picker__summary:hover { color: var(--text-strong); border-color: var(--text-3); }

.picker__icon { display: none; }
.picker__icon--moon { display: block; }
:root[data-theme="light"] .picker__icon--moon { display: none; }
:root[data-theme="light"] .picker__icon--sun { display: block; }

.picker__menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.375rem);
    min-width: 8rem;
    padding: 0.25rem;
    background: var(--bg-raise);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: none;
    z-index: 50;
}

.picker__item {
    display: block;
    width: 100%;
    padding: 0.375rem 0.5rem;
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    text-align: left;
    cursor: pointer;
}
.picker__item:hover { background: var(--bg-hover); color: var(--text-strong); }
.picker__item[aria-checked="true"] { color: var(--text-strong); }
.picker__item[aria-checked="true"]::after {
    content: "\2713";
    float: right;
    color: var(--accent-text);
}

/* ---------- Shell -------------------------------------------------------- */

.shell {
    position: relative;
    display: grid;
    /* Two columns by default. The TOC track is reserved only on post and page,
       where something actually fills it — reserving it everywhere left a
       quarter of the viewport blank on the index, tag, search and error pages. */
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
    align-items: start;
    max-width: 110rem;
    margin-inline: auto;
}

.shell--toc {
    grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--toc-w);
}

/* The rail divider belongs to the shell rather than the rail: drawn on the
   rail itself it stops at one viewport height and leaves every page taller
   than the fold without a hairline. */
.shell::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--rail-w);
    border-right: 1px solid var(--border);
    pointer-events: none;
}

.main {
    min-width: 0;
    padding: 2rem 0 5rem;
}

/* ---------- Rail --------------------------------------------------------- */

.rail {
    position: sticky;
    top: var(--nav-h);
    height: calc(100vh - var(--nav-h));
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.rail__inner {
    padding: 1.5rem 1rem 3rem;
}

.rail__head {
    display: none;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.rail__title {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
}

.rail__close {
    display: grid;
    place-items: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    cursor: pointer;
}

.rail__group + .rail__group { margin-top: 1.75rem; }

/* The drawer carries the site menu on small screens; the top bar already
   shows it on desktop, so the group stays hidden there. */
.rail__group--menu { display: none; }

.rail__label {
    margin: 0 0 0.5rem 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
}

.rail__list,
.rail__sublist {
    margin: 0;
    padding: 0;
    list-style: none;
}

.rail__link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.3125rem 0.5rem;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.5;
    text-decoration: none;
}
.rail__link:hover { color: var(--text-strong); background: var(--bg-hover); }
.rail__link.is-active {
    color: var(--text-strong);
    background: var(--bg-hover);
    font-weight: 500;
}

.rail__count {
    font-size: 0.6875rem;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

.rail__topic { position: relative; }
.rail__topic-link { min-height: 2.75rem; padding-right: 2.75rem; }
.rail__toggle {
    position: absolute;
    top: 0;
    right: 0;
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    list-style: none;
}
.rail__toggle:hover { background: var(--bg-hover); }
.rail__details > summary::-webkit-details-marker { display: none; }

.rail__caret {
    flex: 0 0 auto;
    color: var(--text-3);
    transition: transform 0.15s ease;
}
.rail__details[open] > summary .rail__caret { transform: rotate(90deg); }

.rail__sublist {
    margin: 0.125rem 0 0.25rem 0.75rem;
    padding-left: 0.5rem;
    border-left: 1px solid var(--border);
}

.rail__sublink {
    display: block;
    padding: 0.1875rem 0.5rem;
    border-radius: var(--radius-sm);
    color: var(--text-3);
    font-family: var(--font-mono);
    font-size: 0.78125rem;
    line-height: 1.5;
    text-decoration: none;
}
.rail__sublink:hover { color: var(--text-strong); }
.rail__sublink.is-active { color: var(--accent-text); }
.rail__view-all { color: var(--accent-text); }

/* ---------- Content column ---------------------------------------------- */

.content {
    max-width: var(--content-w);
    margin-inline: auto;
    padding: 0 2rem;
}

.content__head { margin-bottom: 2.5rem; }

.content__title {
    margin: 0 0 0.75rem;
    font-family: var(--font-mono);
    font-size: 2.5rem;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.02em;
    color: var(--text-strong);
}

.content__kicker {
    margin: 0 0 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
}

.content__lede {
    margin: 0;
    font-size: 1.0625rem;
    line-height: 1.65;
    color: var(--text-2);
    max-width: 38rem;
}

.content__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--text-3);
}

.content__dot { color: var(--border); }

.content__count {
    margin-left: 0.35em;
    font-size: 0.45em;
    font-weight: 400;
    letter-spacing: 0;
    color: var(--text-3);
    white-space: nowrap;
}

.content__head--index { margin-bottom: 3rem; }
.content__head--index .content__title { font-size: 2.25rem; }

/* ---------- Feature image hero ------------------------------------------ */

.post-hero {
    margin: 0 0 2rem;
}

.post-hero__img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-raise);
}

.post-hero__caption {
    margin: 0.5rem 0 0;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--text-3);
}

/* ---------- Prose -------------------------------------------------------- */

.prose {
    font-size: 1rem;
    line-height: 1.75;
    color: var(--text);
}

.prose > * + * { margin-top: 1.375rem; }

.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
    font-family: var(--font-mono);
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -0.01em;
    color: var(--text-strong);
    scroll-margin-top: calc(var(--nav-h) + 1rem);
}

/* Four clear steps below the 2.5rem article title. h1 used to match h2, and
   h2 was loud enough to compete with the title it sits under. */
.prose h1 { font-size: 2rem; margin-top: 3rem; }
.prose h2 { font-size: 1.75rem; margin-top: 3.25rem; margin-bottom: 1rem; }
.prose h3 { font-size: 1.375rem; margin-top: 2.5rem; margin-bottom: 0.75rem; }
.prose h4 { font-size: 1.125rem; margin-top: 2rem; margin-bottom: 0.5rem; }
.prose h5 { font-size: 1rem; margin-top: 1.75rem; }
.prose h6 { font-size: 0.875rem; margin-top: 1.5rem; color: var(--text-2); }

.prose p { margin: 0; }
.prose > h2 + *,
.prose > h3 + *,
.prose > h4 + * { margin-top: 0; }

/* The reference separates sections with a hairline, not white space alone */
.prose hr {
    margin: 2.5rem 0;
    border: 0;
    border-top: 1px solid var(--border);
}

.prose a { color: var(--accent-text); }

.prose strong { font-weight: 600; color: var(--text-strong); }
.prose em { font-style: italic; }

.prose ul,
.prose ol { padding-left: 1.5rem; }
.prose li + li { margin-top: 0.375rem; }
.prose li::marker { color: var(--text-3); }
.prose ul ul,
.prose ol ol,
.prose ul ol,
.prose ol ul { margin-top: 0.375rem; }

.prose blockquote {
    margin: 1.5rem 0;
    padding: 0.125rem 0 0.125rem 1rem;
    border-left: 1px solid var(--border);
    color: var(--text-2);
}
.prose blockquote > * + * { margin-top: 0.75rem; }

.prose img {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin: 1.75rem 0;
}

.prose figure { margin: 1.75rem 0; }
.prose figcaption {
    margin-top: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-3);
    text-align: center;
}

/* Tables */
.prose table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    margin: 1.75rem 0;
}
.prose th {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-3);
    text-align: left;
}
.prose th,
.prose td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.prose tr:first-child td { border-top: 1px solid var(--border); }

/* Inline code */
.prose :not(pre) > code,
.prose code:not(pre code) {
    font-family: var(--font-mono);
    font-size: 0.875em;
    padding: 0.125rem 0.3125rem;
    background: var(--bg-raise);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    color: var(--text-strong);
    white-space: break-spaces;
}

.prose kbd {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    padding: 0.125rem 0.375rem;
    background: var(--bg-raise);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
}

/* Ghost's own content cards need a little breathing room */
.prose .kg-card { margin: 1.75rem 0; }

/* Required by gscan / Ghost cards for wide and full-bleed content */
.prose .kg-width-wide {
    width: min(60rem, calc(100vw - 4rem));
    margin-inline: calc(50% - min(30rem, 50vw - 2rem));
}
.prose .kg-width-full {
    width: 100vw;
    max-width: 100vw;
    margin-inline: calc(50% - 50vw);
    border-radius: 0;
}
.prose .kg-width-wide img,
.prose .kg-width-full img {
    width: 100%;
    border-radius: 0;
}
.prose .kg-embed-card iframe { border-radius: var(--radius-md); }
.prose .kg-bookmark-card a {
    display: flex;
    gap: 1rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: inherit;
}
.prose .kg-callout-card {
    padding: 1rem 1.25rem;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
}

/* Deep links on section headings, revealed on hover or keyboard focus.
   Injected by opencode.js at the same time as the heading ids. */
.prose h2,
.prose h3 { position: relative; }

.heading-anchor {
    position: absolute;
    left: -1.1rem;
    top: 0.15em;
    color: var(--text-3);
    font-weight: 400;
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.heading-anchor:hover { color: var(--accent-text); }

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

/* ---------- Code blocks --------------------------------------------------
   JS wraps each <pre> so we can render a label row + copy button.
   -------------------------------------------------------------------------- */

.code-block {
    margin: 1.75rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-code);
    overflow: hidden;
}

.code-block__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.375rem 0.5rem 0.375rem 0.75rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-inset);
}

.code-block__lang {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
}

.code-block__copy {
    display: inline-flex;
    align-items: center;
    gap: 0.3125rem;
    padding: 0.125rem 0.375rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-3);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.code-block__copy:hover {
    color: var(--text-strong);
    border-color: var(--border);
}
.code-block__copy.is-done { color: var(--tok-string); }

.code-block pre {
    margin: 0;
    padding: 0.875rem 1rem;
    overflow-x: auto;
    background: transparent;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.7;
    tab-size: 2;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.code-block code {
    font-family: inherit;
    font-size: inherit;
    background: none;
    border: 0;
    padding: 0;
    color: var(--text);
    white-space: pre;
}

/* highlight.js token map, derived from the reference palette */
.hljs-comment,
.hljs-quote { color: var(--tok-comment); font-style: italic; }

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-doctag,
.hljs-meta .hljs-keyword { color: var(--tok-keyword); }

.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute,
.hljs-meta .hljs-string { color: var(--tok-string); }

.hljs-number,
.hljs-symbol,
.hljs-bullet,
.hljs-link,
.hljs-selector-attr,
.hljs-selector-pseudo { color: var(--tok-number); }

.hljs-title,
.hljs-title.function_,
.hljs-section { color: var(--tok-fn); }

.hljs-type,
.hljs-class .hljs-title,
.hljs-title.class_,
.hljs-built_in,
.hljs-builtin-name { color: var(--tok-type); }

.hljs-attr,
.hljs-variable,
.hljs-template-variable,
.hljs-property,
.hljs-params,
.hljs-selector-class,
.hljs-selector-id { color: var(--tok-punct); }

.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }
.hljs-deletion { color: hsl(0, 70%, 68%); }

/* ---------- TOC rail ----------------------------------------------------- */

.toc-rail {
    position: sticky;
    top: var(--nav-h);
    max-height: calc(100vh - var(--nav-h));
    overflow-y: auto;
    padding: 2rem 1.5rem 3rem 0;
    border-left: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.toc-rail__label {
    margin: 0 0 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--text-2);
}

.toc {
    margin: 0;
    padding: 0;
    list-style: none;
    border-left: 1px solid var(--border);
}

.toc__item { margin: 0; }

.toc__link {
    display: block;
    padding: 0.1875rem 0 0.1875rem 0.75rem;
    margin-left: -1px;
    border-left: 1px solid transparent;
    color: var(--text-3);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.5;
    text-decoration: none;
}
.toc__link:hover { color: var(--text-2); }
.toc__link.is-active {
    color: var(--text-strong);
    border-left-color: var(--accent);
}
.toc__item--h3 .toc__link { padding-left: 1.5rem; font-size: 0.71875rem; }

.toc-inline { display: none; margin-bottom: 2rem; }
.toc-inline[hidden], .toc-rail[hidden] { display: none; }
.toc-inline__details {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-inset);
}
.toc-inline__details > summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0.5rem 0.875rem;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--text-strong);
    cursor: pointer;
}
.toc-inline__details > summary::after {
    content: "⌄";
    margin-left: auto;
    color: var(--text-2);
}
.toc-inline__details[open] > summary::after { transform: rotate(180deg); }
.toc-inline__count { color: var(--text-3); }
.toc-inline__list {
    margin: 0;
    padding: 0.375rem 0.875rem 0.75rem;
    border-top: 1px solid var(--border);
    list-style: none;
    max-height: 16rem;
    overflow-y: auto;
}
.toc-inline .toc__link { min-height: 2.5rem; padding-top: 0.5rem; padding-bottom: 0.5rem; }

/* ---------- Index list -------------------------------------------------- */

.index-list__heading {
    margin: 0 0 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-2);
}

.index-list {
    margin: 0;
    padding: 0;
    list-style: none;
    border-top: 1px solid var(--border);
}

/* The pagination below draws the closing rule, so the last row would
   otherwise stack two hairlines into a 2px line. */
.index-list > li:last-child { border-bottom: 0; }

.index-row {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: 0 1.25rem;
    padding: 1.25rem 0;
    border-bottom: 1px solid var(--border-soft);
}

/* A feature image sits beside the text rather than above it. Full-bleed 16:9
   per row made every post 470px tall, which left one and a half rows on
   screen and buried the titles. The thumbnail goes on the trailing edge so
   every title starts on the same left edge whether or not there is artwork. */
.index-row--media {
    grid-template-columns: minmax(0, 1fr) 13rem;
}
.index-row--lead {
    padding: 1.5rem 1rem;
    margin-inline: -1rem;
    background: var(--bg-inset);
}
.index-row--lead .index-row__title { font-size: 1.5rem; line-height: 1.3; }
.index-row--lead .index-row__excerpt { -webkit-line-clamp: 3; line-clamp: 3; }

.index-row--media .index-row__media {
    grid-column: 2;
    grid-row: 1;
}

.index-row--media .index-row__body {
    grid-column: 1;
    grid-row: 1;
}

.index-row__media { margin: 0; }

.index-row__img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-raise);
    transition: border-color 0.15s ease;
}

.index-row__line { min-width: 0; }

.index-row__title {
    display: block;
    color: var(--text-strong);
    font-family: var(--font-mono);
    font-size: 1.0625rem;
    font-weight: 500;
    line-height: 1.4;
    text-decoration: none;
}

/* Stretch the title link over the whole row: one click target, but the
   accessible name stays the post title. */
.index-row__title::after {
    content: "";
    position: absolute;
    inset: 0;
}

.index-row:hover .index-row__title { color: var(--accent-text); }
.index-row:hover .index-row__img { border-color: var(--text-3); }

.index-row:focus-within {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
    border-radius: var(--radius-sm);
}

.index-row__meta {
    display: flex;
    align-items: baseline;
    gap: 0.375rem;
    margin-top: 0.3125rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.index-row__dot { color: var(--border); }

.index-row__excerpt {
    margin: 0.375rem 0 0;
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--text-2);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.index-empty {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--text-3);
}

/* Ghost injects its own iframe-based search UI on every page. This theme
   replaces it with /search/, so the portal stays hidden if the shortcut ever
   slips past the theme's capture handler. */
#sodo-search-root { display: none !important; }

/* ---------- Search page ------------------------------------------------- */

.search { margin-top: 0; }

.search__field {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    height: 2.75rem;
    padding: 0 0.75rem;
    background: var(--bg-inset);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    transition: border-color 0.15s ease;
}
.search__field:focus-within { border-color: var(--accent); }

.search__icon { flex: 0 0 auto; color: var(--text-3); }

.search__input {
    flex: 1 1 auto;
    min-width: 0;
    background: transparent;
    border: 0;
    outline: none;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.9375rem;
    line-height: 1.5;
    appearance: none;
}
.search__input::placeholder { color: var(--text-3); }
.search__input::-webkit-search-cancel-button { -webkit-appearance: none; }

.search__hint {
    margin: 0.625rem 0 0;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-3);
}

.search__status {
    margin: 1rem 0 -0.5rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-2);
}
.search__status:empty { display: none; }

.search__empty {
    margin: 1.5rem 0 0;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--text-3);
}

.search-results {
    margin: 1.5rem 0 0;
    padding: 0;
    list-style: none;
    border-top: 1px solid var(--border);
}

.search-result {
    position: relative;
    padding: 1rem 0.5rem;
    margin-inline: -0.5rem;
    border-bottom: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
}

.search-result.is-selected { background: var(--bg-hover); }

.search-result__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.25rem 1rem;
}

.search-result__title {
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.9375rem;
    line-height: 1.5;
    text-decoration: none;
}

.search-result__title::after {
    content: "";
    position: absolute;
    inset: 0;
}

.search-result:hover .search-result__title,
.search-result.is-selected .search-result__title { color: var(--accent-text); }

.search-result__meta {
    display: inline-flex;
    align-items: baseline;
    gap: 0.5rem;
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-3);
    flex-wrap: wrap;
}
.search-result__meta time { white-space: nowrap; }

.search-result__excerpt {
    margin: 0.375rem 0 0;
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--text-2);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.search mark {
    background: transparent;
    color: var(--accent-text);
    font-weight: 600;
}

/* ---------- Chips, buttons, post footer --------------------------------- */

.chip {
    display: inline-flex;
    align-items: center;
    padding: 0.0625rem 0.4375rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    line-height: 1.6;
    text-decoration: none;
}
.chip:hover { color: var(--text-strong); border-color: var(--text-3); }

.post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: 2.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.post-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 2.5rem;
}

.post-nav__link {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    text-decoration: none;
}
.post-nav__link:hover { border-color: var(--text-3); background: var(--bg-hover); }
.post-nav__link--next { text-align: right; align-items: flex-end; }

.post-nav__dir {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
}
.post-nav__title {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--text-strong);
    line-height: 1.4;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.4375rem 0.75rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: hsl(224, 40%, 8%);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }

.btn--ghost {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--text);
}
.btn--ghost:hover { border-color: var(--text-3); filter: none; }

/* ---------- Error page -------------------------------------------------- */

.content--error {
    padding-top: 3rem;
    max-width: 34rem;
}

.error__code {
    margin: 0 0 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    letter-spacing: 0.08em;
    color: var(--accent-text);
}

.error__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1.75rem;
}

/* ---------- Pagination -------------------------------------------------- */

.pagination {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
    margin-top: 0;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
}

.pagination__link {
    color: var(--text-2);
    text-decoration: none;
    white-space: nowrap;
}
.pagination__link:hover { color: var(--accent-text); }
.pagination__link--next { justify-self: end; }

.pagination__count {
    color: var(--text-3);
    font-size: 0.75rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.pagination__link.is-disabled {
    color: var(--text-3);
    cursor: default;
    opacity: 0.45;
}

/* ---------- Footer ------------------------------------------------------ */

.foot {
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}

.foot__inner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    max-width: 90rem;
    margin-inline: auto;
    padding: 1.25rem 2rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-3);
}
.foot__inner a { color: var(--text-3); text-decoration: none; }
.foot__inner a:hover { color: var(--text-2); }
.foot__sep { color: var(--border); }

/* ---------- Drawer backdrop --------------------------------------------- */

.drawer-backdrop {
    position: fixed;
    inset: var(--nav-h) 0 0 0;
    z-index: 55;
    background: hsl(224, 20%, 4%);
    opacity: 0;
    transition: opacity 0.18s ease;
}
.drawer-backdrop.is-open { opacity: 0.55; }

body.rail-open { overflow: hidden; }

/* ---------- Responsive -------------------------------------------------- */

/* TOC is the first thing to go, matching the reference's breakpoints */
@media (max-width: 1279px) {
    .shell,
    .shell--toc { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
    .toc-rail { display: none; }
    .toc-inline:not([hidden]) { display: block; }
}

@media (max-width: 1023px) {
    .shell,
    .shell--toc { grid-template-columns: minmax(0, 1fr); }

    /* The rail is a drawer now, so the shell no longer owns a divider. */
    .shell::before { display: none; }

    .nav { gap: 0.5rem; }
    .nav__menu { display: none; }
    .search-btn__label { display: none; }
    .search-btn__kbd { display: none; }
    .search-btn, .picker__summary { width: 2.75rem; height: 2.75rem; justify-content: center; }
    .js .nav__burger { display: grid; width: 2.75rem; height: 2.75rem; }

    /* Without JS the rail remains in the document, so navigation is usable. */
    .rail {
        position: static;
        height: auto;
        overflow: visible;
        border-bottom: 1px solid var(--border);
    }
    .rail__inner { padding: 1rem 1.25rem; }
    .rail__head { display: flex; }
    .rail__close { display: none; }
    .rail__group--menu { display: block; }
    .rail__link, .rail__sublink { padding-block: 0.75rem; }

    /* With JS, the same rail becomes a slide-out drawer. */
    .js .rail {
        position: fixed;
        top: var(--nav-h);
        left: 0;
        bottom: 0;
        z-index: 60;
        width: min(19rem, 85vw);
        overflow-y: auto;
        background: var(--bg);
        border-right: 1px solid var(--border);
        border-bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        visibility: hidden;
    }
    .js .rail.is-open {
        transform: translateX(0);
        visibility: visible;
    }
    .js .rail__close { display: grid; width: 2.75rem; height: 2.75rem; }
    .heading-anchor { display: none; }

    .main { padding-top: 1.5rem; }
    .content { padding: 0 1.25rem; }
    .content__title { font-size: 2rem; }
    .prose h2 { font-size: 1.5rem; }
    .prose h3 { font-size: 1.25rem; }
    .post-nav { grid-template-columns: 1fr; }
    .index-row--media { grid-template-columns: minmax(0, 1fr) 8rem; gap: 0 1rem; }
    .index-row { padding: 1.125rem 0; }
    .foot__inner { padding-inline: 1.25rem; flex-wrap: wrap; }
}

@media (max-width: 480px) {
    .index-row--media { grid-template-columns: minmax(0, 1fr) 5.5rem; gap: 0 0.75rem; }
    .index-row--lead.index-row--media { grid-template-columns: minmax(0, 1fr); }
    .index-row--lead .index-row__body { grid-column: 1; grid-row: 1; }
    .index-row--lead .index-row__media { grid-column: 1; grid-row: 2; margin-top: 1rem; }
    .index-row--lead .index-row__title { font-size: 1.25rem; }
}
