/* Deliberately minimal: a wireframe to design on later. */

/*
 * Fonts, served from fonts/ (Latin only), each under the SIL Open Font
 * License 1.1 (licence files beside them): M PLUS Rounded 1c bold for
 * headings, Copyright 2016 The Rounded M+ Project Authors; Atkinson
 * Hyperlegible Next for text, Copyright 2020-2024 The Atkinson Hyperlegible
 * Next Project Authors (Braille Institute).
 * font-display: swap shows text in the fallback font until they load.
 */
@font-face {
    font-family: "M PLUS Rounded 1c";
    font-weight: 700;
    font-display: swap;
    src: url("fonts/m-plus-rounded-1c-latin-700.1688f14412.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "Atkinson Hyperlegible Next";
    font-weight: 400;
    font-display: swap;
    src: url("fonts/atkinson-hyperlegible-next-latin-400.5cb240a4d9.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "Atkinson Hyperlegible Next";
    font-weight: 700;
    font-display: swap;
    src: url("fonts/atkinson-hyperlegible-next-latin-700.0dbe07ed76.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    color-scheme: light dark;
    /* The page, raised surfaces on it (popovers, menus, tooltips), and text: 11:1 or more in light and dark. */
    --bg: light-dark(#efe5d5, #1e2026);
    --main-bg: light-dark(#faf6f0, #121316);
    --fg: light-dark(#3c2116, #f4f4f6);
    /* Links, focus and highlighted buttons: 6:1 or more against --bg and --main-bg, both ways round. */
    --action: light-dark(#9e2a0b, #38bdf8);
    /* Decoration and "on" states: 3.5:1 or more on --bg, enough for a filled shape or a mark but not for text on the page. */
    --highlight: light-dark(#c4500a, #dc1f78);
    /* Text and icons on --highlight: 4.67:1 on the orange, 4.66:1 on the pink (near-black is under 4:1 on both). */
    --on-highlight: #ffffff;
    accent-color: var(--action);
    background: var(--bg);
    color: var(--fg);
    font-family: "Atkinson Hyperlegible Next", system-ui, sans-serif;
    line-height: 1.5;
}

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

body {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    /* minmax(0, …): wide content (a long line of HTML) scrolls inside its box instead of widening the page. */
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
    min-block-size: 100dvh;
    margin: 0;
    padding: 1rem;

    /*
     * The page is centred, --site-min wide (75rem, or 80% of a very wide
     * window), or the whole window when that's narrower. When the previews
     * need more room and would scroll sideways, app.js adds data-full and the
     * page fills the window.
     */
    --site-min: max(75rem, 80vw);
    inline-size: min(100%, var(--site-min));
    margin-inline: auto;

    &[data-full] {
        inline-size: 100%;
    }
}

h1,
h2,
p {
    margin: 0;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: "M PLUS Rounded 1c", "Atkinson Hyperlegible Next", system-ui, sans-serif;
}

a {
    color: var(--action);
}

:focus-visible {
    outline: 2px solid var(--action);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

main {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-inline-size: 0;
}

/* Only in the side-by-side layout below. */
#divider {
    display: none;
}

/* An iframe swallows pointer events; ignore them while a drag is running. */
[data-dragging] iframe {
    pointer-events: none;
}

.bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

/* The "Beta" label above the title. */
.badge {
    display: inline-block;
    padding: 0 0.5rem;
    border: 1px solid var(--highlight);
    background: var(--highlight);
    color: var(--on-highlight);
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* Above the title, tilted and nudged over its corner. */
.eyebrow .badge {
    rotate: -10deg;
    translate: -1em 0.5em;
}

/* The copyright line at the bottom of every page, on the right. */
footer {
    text-align: end;
}

/* The site's name in the header of every page (not a heading: each page has its own h1). */
.site-name {
    font-family: "M PLUS Rounded 1c", "Atkinson Hyperlegible Next", system-ui, sans-serif;
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;

    & a {
        color: inherit;
        text-decoration: none;

        &:hover {
            text-decoration: underline;
        }
    }
}

/* Said by screen readers, not shown. */
.visually-hidden {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* The page you're on, in the header's links. */
.site-links [aria-current="page"] {
    color: inherit;
    font-weight: 700;
    text-decoration: none;
}

/* The links under the tagline: the colour contrast checker and the docs. */
.site-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.5rem;
}

/* An empty space for a 728 × 90 banner, shrinking to fit narrow screens. */
.ad-slot {
    inline-size: 728px;
    max-inline-size: 100%;
    aspect-ratio: 728 / 90;
    outline: 1px dashed;
    outline-offset: -1px;
}

label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

/*
 * The code panel: the textarea's text is transparent, over a copy of it in a
 * <pre> that shows the syntax colours. The two must lay text out identically:
 * same font, padding, border, wrapping and scrollbar room. Always dark,
 * whatever the page's theme (user, 2026-11-03).
 */
.code {
    position: relative;
    display: flex;
    flex-direction: column;
    background: #1e1e1e;
    color: #e6edf3;

    textarea,
    pre {
        margin: 0;
        padding: 0.5rem;
        border: 1px solid;
        font: 0.8rem/1.5 ui-monospace, monospace;
        letter-spacing: normal;
        tab-size: 4;
        white-space: pre-wrap;
        overflow-wrap: break-word;
        scrollbar-gutter: stable;
    }

    pre {
        position: absolute;
        inset: 0;
        overflow: hidden;
        border-color: transparent;
    }

    textarea {
        position: relative;
        min-block-size: 60dvh;
        overflow: auto;
        resize: vertical;
        background: transparent;
        color: transparent;
        caret-color: #e6edf3;
        border-color: #8b949e;
        /* Dark scrollbars without color-scheme, which would switch the page's light-dark() tokens (the focus outline) here. */
        scrollbar-color: #8b949e #1e1e1e;

        &::placeholder {
            color: #8b949e;
        }

        /* See-through, so the coloured text behind shows. */
        &::selection {
            background: rgb(138 180 248 / 0.35);
            color: transparent;
        }
    }
}

/* Forced colours (e.g. Windows high contrast) override the transparent text: show the textarea alone. */
@media (forced-colors: active) {
    .code pre {
        display: none;
    }
}

/*
 * The syntax colours, at least 4.5:1 against the code panel's dark
 * background. ::highlight() takes few properties and doesn't reliably
 * inherit custom properties, so the colours are written out. One rule per
 * highlight: Chrome drops a rule whose selector list has more than one.
 */
::highlight(emu-punctuation) {
    color: #8b949e;
}

::highlight(emu-tag) {
    color: #7ee787;
}

::highlight(emu-attribute) {
    color: #79c0ff;
}

::highlight(emu-value) {
    color: #a5d6ff;
}

::highlight(emu-comment) {
    color: #8b949e;
}

::highlight(emu-doctype) {
    color: #ff7b72;
}

::highlight(emu-entity) {
    color: #d2a8ff;
}

#url-form label:has(#url),
#url {
    flex: 1;
    min-inline-size: 0;
}

#code-hint {
    margin-block-start: -0.25rem;
}

#url-status:empty {
    display: none;
}

/* The headings and links lists: centred popovers that scroll inside. */
.menu {
    inline-size: min(40rem, 100% - 2rem);
    max-block-size: min(40rem, 100dvh - 2rem);
    overflow: auto;
    padding: 1rem;
    border: 1px solid;
    background: var(--main-bg);
    color: var(--fg);

    /* The page behind it fades, dims and blurs while it's open. */
    &::backdrop {
        backdrop-filter: saturate(0.3) brightness(0.9) blur(5px);
    }

    /* Between the title and the list. */
    hr {
        margin-block: 0.75rem;
        border: 0;
        border-block-start: 1px solid;
    }

    ul {
        margin: 0;
        padding: 0;
        list-style: none;
    }

    li {
        padding-block: 0.25rem;
    }

    /* The items (not the close button, which keeps the page's button style). */
    li button {
        display: block;
        inline-size: 100%;
        padding: 0.25rem;
        border: 0;
        background: none;
        color: inherit;
        font: inherit;
        text-align: start;
        cursor: pointer;

        &:hover {
            text-decoration: underline;
        }
    }

    /* The heading level. */
    small {
        display: block;
        font-weight: normal;
    }

    details {
        padding-inline-start: 0.25rem;
        font-size: 0.875rem;
        overflow-wrap: anywhere;
    }
}

/* Rows of buttons and controls that sit together, rather than spread out. */
.tools {
    justify-content: start;
}

/* A preview's title bar and toolbar: below 544px (34em) wide, their buttons show only their icons. */
.preview > .bar:first-child,
.tools:has(> .option-button) {
    container-type: inline-size;
}

/* A button with an icon before its label. Holds hidden text (the label, "(changed)"), which would otherwise be placed against the page and widen it. */
.icon-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
}

/*
 * Rounded (a squircle where corner-shape is supported), with a half-strength
 * border in the text colour: the icon buttons, the buttons in the toolbar
 * popovers, and those popovers' checkboxes, whose labels look like buttons
 * (the box stays visible inside, so the state isn't shown by colour alone).
 */
button.icon-button,
.options button,
.options label:has(> input[type="checkbox"]) {
    padding: 0.7em 1em;
    border: 1px solid color-mix(in srgb, currentColor 50%, transparent);
    border-radius: 1em;
    corner-shape: squircle;
    /* One font for all of them (buttons don't inherit it by default). */
    font: inherit;
    font-size: 0.875rem;
    line-height: 1.15;
}

.options label:has(> input[type="checkbox"]) {
    gap: 0.5em;
    cursor: pointer;

    /* The focus ring goes round the whole button, not just the box. */
    &:has(:focus-visible) {
        outline: 2px solid var(--action);
        outline-offset: 2px;
    }

    & input:focus-visible {
        outline: none;
    }

    /* Ticked: filled like a changed toolbar button; the box takes the same white so it shows on the fill. */
    &:has(:checked) {
        border-color: var(--highlight);
        background: var(--highlight);
        color: var(--on-highlight);
        accent-color: var(--on-highlight);
    }

    /* Ticked and fixed by another option (Images implies External assets). */
    &:has(:disabled) {
        cursor: default;
        opacity: 0.6;
    }

    & input {
        margin: 0;
    }
}

/* Icon only: as wide as it is tall. */
button.icon-only {
    padding: 0.7em;
}

/* Add preview and Sync scrolling, at the end of the first preview's title bar. */
#preview-tools {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Lucide's stroke settings, for the icons in the sprite at the top of index.html. */
.icon {
    flex: none;
    inline-size: 1.25em;
    block-size: 1.25em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* A narrower toolbar shows short labels ("Colour", "Blocked"); the rest stays in the accessible name and the tooltip. */
@container (width < 40.5em) {
    .icon-button .label-more {
        position: absolute;
        inline-size: 1px;
        block-size: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

/* The label stays the button's accessible name; it's only hidden from view. */
@container (width < 34em) {
    button.icon-button:has(.label) {
        padding: 0.7em;
    }

    .icon-button .label {
        position: absolute;
        inline-size: 1px;
        block-size: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

/* A toolbar button whose options aren't all at their defaults, and Sync scrolling or Semantic view while it's on. */
.option-button[data-changed],
#sync-scroll[aria-pressed="true"],
.options button[aria-pressed="true"] {
    border-color: var(--highlight);
    background: var(--highlight);
    color: var(--on-highlight);
}

/* Not said until the button's options change. */
.option-button:not([data-changed]) .changed {
    display: none;
}

/* Said by screen readers, not shown (an .icon-only button's label shows in its tooltip). */
.changed,
.icon-only .label {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* A toolbar button's options: a popover under the button (centred where anchor positioning isn't supported). */
.options {
    gap: 0.75rem;
    max-inline-size: min(32rem, 100vw - 2rem);
    padding: 0.75rem;
    border: 1px solid;
    background: var(--main-bg);
    color: var(--fg);

}

/* Its options in one column, and its reset button in another, centred on the first row of options. */
.options:popover-open {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    justify-items: start;
    align-items: center;
}

.options > * {
    grid-column: 1;
}

.options > .reset-options {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
}

/* Blocked content's Custom selectors, and what they did (nothing shown until there's something to say). The field wraps below its label when the popover is narrow. */
.options .custom {
    flex-wrap: wrap;
    max-inline-size: 100%;
}

.options .custom input {
    inline-size: 16rem;
    max-inline-size: 100%;
}

.options [role="status"]:empty {
    display: none;
}

@supports (position-area: block-end) {
    .options {
        inset: auto;
        margin: 0.25rem 0;
        position-area: block-end span-inline-end;
        position-try-fallbacks: flip-inline, flip-block;
    }
}

/* A preview heading's full text, when it's cut short. */
.tooltip {
    max-inline-size: min(32rem, 100vw - 2rem);
    padding: 0.25rem 0.5rem;
    border: 1px solid;
    background: var(--main-bg);
    color: var(--fg);
    font-size: 0.875rem;
}

@supports (position-area: block-end) {
    .tooltip {
        inset: auto;
        margin: 0.25rem 0;
        position-area: block-end span-inline-end;
        position-try-fallbacks: flip-inline, flip-block;
    }
}

/* A preview's heading, and the width its email is laid out at. */
.title {
    display: flex;
    flex: 1;
    align-items: baseline;
    gap: 0.5rem;
    min-inline-size: 0;

    /* One line; with several previews it lists what's applied, cut short with an ellipsis (hover for all of it). */
    & h2 {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    & small {
        flex: none;
    }
}

#preview-row {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Only in the side-by-side layout below. */
.pane-divider {
    display: none;
}

/*
 * Headings: a level's font size steps down gently from level 1, and a run of
 * dashes (one per level below 1) starts every line at the same place, so the
 * text is indented by level. The dashes are monospace at a fixed size, so each
 * level indents by the same amount, and a long heading wraps under its text.
 * They're silent for screen readers (the "/ ''" alt text), which hear
 * "Level N" instead; browsers without alt text in content use the first
 * declaration.
 */
#headings-menu li {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: first baseline;

    &::before {
        grid-column: 1;
        font: 1rem / 1 ui-monospace, monospace;
        white-space: pre;
    }

    > * {
        grid-column: 2;
    }

    &[data-level="1"] { font-size: 1.25rem; }
    &[data-level="2"] { font-size: 1.15rem; }
    &[data-level="3"] { font-size: 1.05rem; }
    &[data-level="4"] { font-size: 1rem; }
    &[data-level="5"] { font-size: 0.95rem; }
    &[data-level="6"] { font-size: 0.9rem; }

    &[data-level="2"]::before { content: "- "; content: "- " / ""; }
    &[data-level="3"]::before { content: "-- "; content: "-- " / ""; }
    &[data-level="4"]::before { content: "--- "; content: "--- " / ""; }
    &[data-level="5"]::before { content: "---- "; content: "---- " / ""; }
    &[data-level="6"]::before { content: "----- "; content: "----- " / ""; }

    small {
        font-size: 0.8rem;
    }

    /* Problems don't follow the heading's size. */
    .problem {
        font-size: 1rem;
    }
}

/* The links list is bulleted. */
#links-menu ul {
    padding-inline-start: 1.25rem;
    list-style: disc;
}

/* At least 4.5:1 against --bg, both ways round. */
.problem {
    color: light-dark(#b3261e, #f2b8b5);
}

input[type="number"] {
    inline-size: 6ch;
}

.stage {
    display: flex;
    flex-direction: column;
    /* safe: a frame wider than the stage scrolls from its start instead of being cut off. */
    align-items: safe center;
    gap: 0.75rem;
    overflow-x: auto;

    /* Room for the resize handles. */
    .preview:not([data-viewport="desktop"]) > & {
        padding: 0 1rem 1rem;
    }
}

/* The box the iframe fills: full width for Fit to size, a set width for Desktop and a set size for phones (set inline). */
.frame-box {
    position: relative;
    flex: none;
    inline-size: 100%;
    block-size: 75dvh;
}

/*
 * Zoom, as browser zoom does it: the email is laid out in a viewport smaller
 * (or larger) by the zoom factor, so its media queries react, then scaled to
 * fill the box. --zoom is set on .frame-box.
 */
iframe {
    display: block;
    inline-size: calc(100% / var(--zoom, 1));
    block-size: calc(100% / var(--zoom, 1));
    transform: scale(var(--zoom, 1));
    transform-origin: 0 0;
    border: 0;
    /* Emails without their own background assume white, whatever the page theme. */
    background: #fff;
    /* The default; the colour scheme control overrides it inline. */
    color-scheme: light;
    /* Colour blindness: url(#vision-…), a filter in index.html, set on .frame-box. */
    filter: var(--vision, none);
}

/* The colour blindness filters' <svg>: takes no space, but not display: none. */
.filters {
    position: absolute;
    inline-size: 0;
    block-size: 0;
    overflow: hidden;
}

/* Over the white preview, so a fixed dark colour. */
.empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #333;
    pointer-events: none;
}

[data-axis] {
    position: absolute;
    display: none;
    touch-action: none;

    .preview:not([data-viewport="desktop"]) & {
        display: block;
    }

    /* Desktop's height follows the space: only its width can be dragged. */
    [data-viewport="fixed"] &:not([data-axis="x"]) {
        display: none;
    }
}

[data-axis="x"] {
    inset-block: 0;
    inset-inline-end: -0.75rem;
    inline-size: 0.75rem;
    cursor: ew-resize;
}

[data-axis="y"] {
    inset-inline: 0;
    inset-block-end: -0.75rem;
    block-size: 0.75rem;
    cursor: ns-resize;
}

/* A visible grip, so it's clear the frame can be resized. */
[data-axis="xy"] {
    inset-inline-end: -0.75rem;
    inset-block-end: -0.75rem;
    inline-size: 0.75rem;
    block-size: 0.75rem;
    background: var(--action);
    cursor: nwse-resize;
}

/*
 * Wide and tall enough: the page fills the window exactly, with the code and
 * the preview side by side, each scrolling inside itself. Smaller windows (and
 * high zoom) keep the stacked layout above, where the page scrolls, because a
 * fixed-height page there leaves too little room to work in.
 */
@media (width >= 48rem) and (height >= 30rem) {
    body {
        block-size: 100dvh;
    }

    main {
        flex-direction: row;
        gap: 0;
    }

    /* Its width comes from the divider (--code-width, set on main); the preview takes the rest. */
    #source {
        flex: none;
        inline-size: var(--code-width, 40%);
        min-inline-size: 16rem;
    }

    /* With the code hidden, its column is just the "Show code" button, turned 90° anti-clockwise and centred. */
    #code-rail {
        flex: none;
        display: flex;
        align-items: center;

        button {
            writing-mode: vertical-rl;
            rotate: 180deg;
        }
    }

    /* Fills the gap between the panels, with a line down its middle. */
    #divider,
    .pane-divider {
        display: block;
        flex: none;
        inline-size: 1.5rem;
        position: relative;
        background: linear-gradient(currentColor, currentColor) center / 1px 100% no-repeat;
        cursor: col-resize;
        touch-action: none;

        /*
         * Two small triangles, pointing left and right either side of the line
         * at its vertical centre, to show it can be dragged. One box, clipped
         * to both shapes (joined by a line of no width).
         */
        &::before {
            content: "";
            position: absolute;
            inset-inline: 0.2rem;
            inset-block-start: 50%;
            block-size: 0.75rem;
            translate: 0 -50%;
            background: var(--highlight);
            clip-path: polygon(0 50%, 35% 0, 35% 100%, 0 50%, 100% 50%, 65% 100%, 65% 0, 100% 50%);
        }
    }

    .code {
        flex: 1;
        min-block-size: 0;
    }

    .code textarea {
        flex: 1;
        min-block-size: 0;
        resize: none;
    }

    #previews {
        flex: 1;
    }

    /*
     * The previews side by side, scrolling sideways when they don't fit. A
     * mobile preview is as wide as its frame, plus room for the resize handles
     * and a scrollbar (or 20rem for its controls);
     * desktop previews share the rest, but not below 20rem. With no desktop
     * preview, the mobile ones share the space instead.
     */
    #preview-row {
        flex: 1;
        flex-direction: row;
        gap: 0;
        min-block-size: 0;
        overflow-x: auto;
    }

    .preview {
        flex: 1 0 20rem;

        &:not([data-viewport="desktop"]) {
            flex: 0 0 max(20rem, var(--frame-width) + 3rem);
        }

        #preview-row:not(:has([data-viewport="desktop"])) & {
            flex-grow: 1;
        }

        /* A width set with the divider after it (the last preview has none, and fills the rest). */
        #preview-row &[data-pane-width]:not(:last-child) {
            flex: 0 0 max(20rem, var(--pane-width));

            &:not([data-viewport="desktop"]) {
                flex-basis: max(20rem, var(--frame-width) + 3rem, var(--pane-width));
            }
        }
    }

    .stage {
        flex: 1;
        min-block-size: 0;
        overflow: auto;
        /* So a scrollbar appearing doesn't take width from a frame with a set width. */
        scrollbar-gutter: stable;

        /* Fit to size and Desktop take the height of the space. */
        :is([data-viewport="desktop"], [data-viewport="fixed"]) > & .frame-box {
            flex: 1;
            block-size: auto;
        }
    }
}

/* ---------- The docs page (docs/index.html) ---------- */

/* A normal scrolling page in every window size: undoes the app's fixed-height, side-by-side layout. */
body.docs {
    block-size: auto;
    grid-template-rows: auto;
    gap: 1.5rem;
    /* The same width as the app (see body), so the header and banner line up on every page; the text keeps its own reading width. */

    & main {
        flex-direction: column;
        gap: 2.5rem;
        max-inline-size: 48rem;
    }

    /*
     * Each section's heading stays at the top of the window while its section
     * is on screen, and each subheading stays just below it while its own
     * subsection is (the next one pushes it away). Opaque, so the text scrolls
     * underneath. --docs-h2 is the h2's height (one line: 1.5rem × 1.5 line
     * height, 0.75rem padding, 0.15rem border), so
     * a link to a subheading lands below the h2 rather than under it.
     */
    --docs-h2: 3.15rem;

    & main > section > h2 {
        position: sticky;
        inset-block-start: 0;
        z-index: 2;
        min-block-size: var(--docs-h2);
        padding-block: 0.375rem;
        border-block-end: 0.1em solid var(--highlight);
        background: var(--bg);
        line-height: 1.5;
    }

    & main > section > section > h3 {
        position: sticky;
        inset-block-start: var(--docs-h2);
        z-index: 1;
        margin-block: 0.75rem 0;
        padding-block: 0.25rem;
        border-block-end: 0.1em solid var(--highlight);
        background: var(--bg);
        scroll-margin-block-start: var(--docs-h2);
    }

    & :is(ul, ol, dl, dd) {
        margin: 0;
    }

    & dt {
        font-weight: bold;
    }

    & nav ol ol {
        padding-inline-start: 1.25rem;
    }

    /* Scrolls sideways on its own on narrow screens, so the page doesn't. */
    & .table {
        overflow-x: auto;
    }

    & table {
        border-collapse: collapse;
    }

    & caption {
        font-weight: bold;
        text-align: start;
        padding-block-end: 0.25rem;
    }

    & :is(th, td) {
        padding: 0.25rem 0.75rem;
        border: 1px solid;
        text-align: start;
    }

    & td {
        text-align: end;
        font-variant-numeric: tabular-nums;
    }

    /* "Not tested yet" across the number columns. */
    & td[colspan] {
        text-align: start;
    }

    /*
     * Wide screens: the site header across the top, then two columns, the
     * contents list on the left and the text and footer on the right. The list
     * starts below the header and stays in view once the page scrolls past it,
     * scrolling on its own if it's taller than the window.
     */
    @media (width >= 60rem) {
        grid-template-columns: 16rem minmax(0, 1fr);
        grid-template-areas:
            "header header"
            "nav main"
            "nav footer";
        column-gap: 2rem;

        & > header { grid-area: header; }
        & > main { grid-area: main; }
        & > footer { grid-area: footer; }

        & > nav {
            grid-area: nav;
            align-self: start;
            position: sticky;
            inset-block-start: 0;
            max-block-size: 100dvh;
            margin-block-start: -1rem;
            padding-block: 1rem;
            overflow-y: auto;
            overscroll-behavior: contain;
        }
    }
}

/* ---------- Tool pages (contrast/index.html) ---------- */

/* A normal scrolling page, the same width as the app (see body). */
body.tool {
    block-size: auto;
    grid-template-rows: auto;
    gap: 1.5rem;

    & main {
        flex-direction: column;
        gap: 1rem;
    }

    & ul {
        margin: 0;
    }

    /* The three colours, side by side when there's room. */
    & .colour-inputs {
        display: flex;
        flex-wrap: wrap;
        gap: 1rem 2rem;
    }

    & .colour-field {
        display: grid;
        gap: 0.25rem;
    }

    & .colour-pair {
        display: flex;
        align-items: center;
        gap: 0.5rem;

        & input[type="color"] {
            inline-size: 2.75rem;
            block-size: 2.25rem;
            padding: 0.125rem;
        }

        & input[type="text"] {
            inline-size: 10rem;
            font: inherit;
            padding: 0.375rem 0.5rem;
        }
    }

    & .colour-error {
        font-weight: bold;
    }

    /* Share this, with what happened beside it. */
    & .share {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.5rem 1rem;

        & [role="status"] {
            overflow-wrap: anywhere;
        }
    }

    & .hint {
        font-size: 0.875rem;
    }

    /* Scrolls sideways on its own on narrow screens, so the page doesn't. */
    & .table {
        overflow-x: auto;
    }

    & table {
        border-collapse: collapse;
        inline-size: 100%;
    }

    & caption {
        font-weight: bold;
        text-align: start;
        padding-block-end: 0.25rem;
    }

    & :is(th, td) {
        padding: 0.25rem 0.5rem;
        border: 1px solid;
        text-align: start;
        vertical-align: middle;
    }

    & .ratio {
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }

    & .result {
        font-weight: bold;
        white-space: nowrap;
    }

    /* Green for a pass, red for a fail, each 5:1 or more on the page in light and dark (the ✓ and ✗ say it too). */
    & .pass {
        color: light-dark(#1b6e31, #7fd99a);
    }

    & .fail {
        color: light-dark(#b3261e, #ff9b90);
    }

    /* Each mode's colours, drawn as they come out. */
    & .sample {
        min-inline-size: 11rem;
        padding: 0.5rem 0.75rem;
        border: 2px solid;
        font-family: Arial, sans-serif;

        & .sample-normal {
            font-size: 16px;
        }

        & .sample-large {
            font-size: 24px;
        }
    }

    & .colour-list {
        display: grid;
        grid-template-columns: auto auto;
        gap: 0 0.5rem;
        margin: 0;
        font-size: 0.875rem;

        & dd {
            display: flex;
            align-items: center;
            gap: 0.35em;
            margin: 0;
            font-family: ui-monospace, monospace;
        }

        /* A small square of the colour, outlined so pale and dark colours still show. */
        & .swatch {
            flex: none;
            inline-size: 0.75em;
            block-size: 0.75em;
            outline: 1px solid color-mix(in srgb, currentColor 50%, transparent);
        }
    }

    /* Where each mode's sample email is rendered and measured, out of sight. */
    & #render {
        position: absolute;
        inset-block-start: 0;
        inset-inline-start: -10000px;
        inline-size: 400px;
        visibility: hidden;

        & iframe {
            inline-size: 400px;
            block-size: 100px;
            border: 0;
        }
    }
}
