/*
 * An article's body, as the guide's pages and the app's Guide pane show it: one sheet for both,
 * so a piece reads in the pane as on the site. It reads as a structure.fi article (the site's
 * blog post and `.site-prose`): a large light title in Geist Sans, the summary as the site's
 * support line, Sans copy with hairlines over its headings, and Geist Mono for code, layouts and
 * tables, which stay at a data table's size wherever the article is. The prose sizes are
 * `--article-*` properties at the page's scale; the Guide pane sets them a step down. Every rule
 * is scoped to the article element, so the app's own views are untouched; the `--lp-*` tokens
 * supply every colour, light or dark by `data-st-theme` on the root.
 */
article[data-article] {
    --article-text: 400 17px/1.7 var(--lp-font-sans);
    --article-title: 400 clamp(32px, 1rem + 2.6vw, 52px) / 1.08 var(--lp-font-display);
    --article-summary: 400 clamp(17px, 0.9rem + 0.4vw, 20px) / 1.45 var(--lp-font-sans);
    --article-heading: 400 22px/1.3 var(--lp-font-sans);
    --article-subheading: 500 18px/1.35 var(--lp-font-sans);
    --article-space: 48px;
    font: var(--article-text);
    color: var(--lp-ink-2);
}

/*
 * Prose reads in the page's direction, also in the Guide pane inside the left-to-right dock.
 * Figures, tables and code are data and read from left to right; captions are prose again.
 */
[dir="rtl"] article[data-article],
[dir="rtl"] article[data-article] :is(figcaption, caption) {
    direction: rtl;
}

article[data-article] :is(figure, table, pre) {
    direction: ltr;
}

/* Letters of Arabic join, so they take no tracking; Arabic and Chinese have no italics. */
article[data-article]:lang(ar) :is(h1, h2, h3, th) {
    letter-spacing: 0;
}

article[data-article]:is(:lang(ar), :lang(zh)) :is(em, i) {
    font-style: normal;
}

/* On a phone the site sets its articles' copy a step down. */
@media (max-width: 640px) {
    article[data-article] {
        --article-text: 400 16px/1.7 var(--lp-font-sans);
    }
}

article[data-article] a:not(.lp-button) {
    color: var(--lp-ink);
    text-decoration: underline;
    text-decoration-color: var(--lp-rule-strong);
    text-underline-offset: var(--lp-link-underline-offset);
}

article[data-article] a:not(.lp-button):hover {
    text-decoration-color: var(--lp-ink);
}

/*
 * The query's words in the article: a tint of the ink behind them, the one stepped to in the
 * ink itself. A shadow and a background take no room, so no line moves.
 */
article[data-article] mark {
    background: color-mix(in oklab, var(--lp-ink) 16%, transparent);
    box-shadow: 0 0 0 2px color-mix(in oklab, var(--lp-ink) 16%, transparent);
    border-radius: 2px;
    color: inherit;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

article[data-article] mark[data-current] {
    background: var(--lp-ink);
    box-shadow: 0 0 0 2px var(--lp-ink);
    color: var(--lp-canvas);
}

article[data-article] strong {
    color: var(--lp-ink);
    font-weight: 500;
}

article[data-article] p {
    margin: 0 0 16px;
    text-wrap: pretty;
}

article[data-article] h1 {
    margin: calc(var(--article-space) / 2) 0 16px;
    font: var(--article-title);
    letter-spacing: -0.03em;
    color: var(--lp-ink);
    text-wrap: balance;
}

/* A section's title over a hairline, as the site's long pages. */
article[data-article] h2 {
    margin: var(--article-space) 0 16px;
    padding-top: 20px;
    border-top: 1px solid var(--lp-rule);
    font: var(--article-heading);
    letter-spacing: -0.012em;
    color: var(--lp-ink);
}

article[data-article] h3 {
    margin: 32px 0 12px;
    font: var(--article-subheading);
    letter-spacing: -0.01em;
    color: var(--lp-ink);
}

article[data-article] .summary {
    margin-bottom: 24px;
    font: var(--article-summary);
    color: var(--lp-ink-2);
    text-wrap: pretty;
}

article[data-article] ul {
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
}

/* The site's list marker: a small square in the tertiary ink. */
article[data-article] ul > li {
    position: relative;
    margin-block: 6px;
    padding-inline-start: 20px;
}

article[data-article] ul > li::before {
    content: "";
    position: absolute;
    top: 0.7em;
    inset-inline-start: 2px;
    width: 5px;
    height: 5px;
    background: var(--lp-ink-3);
}

article[data-article] ol {
    margin: 0 0 16px;
    padding-inline-start: 1.6em;
}

article[data-article] ol > li::marker {
    color: var(--lp-ink-3);
    font: 500 0.85em var(--lp-font-mono);
}

article[data-article] .review {
    margin-top: var(--article-space);
    padding-top: 16px;
    border-top: 1px solid var(--lp-rule);
    font: var(--lp-type-small);
    color: var(--lp-ink-3);
}

/* Code in a sentence is one left-to-right word, whatever the sentence's direction. */
article[data-article] code {
    font-family: var(--lp-font-mono);
    font-size: 0.88em;
    background: var(--lp-well);
    padding: 1px 4px;
    direction: ltr;
    unicode-bidi: isolate;
}

article[data-article] figure {
    margin: 24px 0;
    overflow-x: auto;
}

/* A table's or figure's caption: the site's small copy over it. */
article[data-article] figcaption,
article[data-article] caption {
    font: var(--lp-type-small);
    color: var(--lp-ink-3);
    text-align: start;
    padding: 0 0 8px;
}

/* Tables are data: mono at the app's density, the header row in the site's eyebrow on the well. */
article[data-article] table {
    border-collapse: collapse;
    font: 400 12px/20px var(--lp-font-mono);
    color: var(--lp-ink);
}

article[data-article] th {
    font: 500 10px/16px var(--lp-font-mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-align: left;
    color: var(--lp-ink-3);
    background: var(--lp-well);
    border-bottom: 1px solid var(--lp-rule-2);
}

article[data-article] th,
article[data-article] td {
    padding: 3px 10px;
    white-space: nowrap;
}

article[data-article] tbody tr {
    border-bottom: 1px solid var(--lp-rule);
}

article[data-article] td.number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* One indent step per level of the layout's tree: the text view's indent of one block. */
article[data-article] td.name {
    padding-inline-start: calc(10px + var(--depth) * 2ch);
}

/*
 * A declaration and a frame's byte dump: the text view's lines and colours (`code-colors.css`),
 * in the well, as the site's code blocks.
 */
article[data-article] pre.declaration,
article[data-article] pre.byte-dump {
    font: 400 12px/20px var(--lp-font-mono);
    color: var(--lp-ink);
    background: var(--lp-well);
    padding: 16px 20px;
    margin: 0;
    overflow-x: auto;
}

article[data-article] pre.declaration code,
article[data-article] pre.byte-dump code {
    font: inherit;
    background: none;
    padding: 0;
}

/*
 * Bytes as boxes, one per byte, in the tables' mono: the hex, and under it the byte's character
 * where a block shows text. Neighbouring boxes share their hairline.
 */
article[data-article] .cells {
    display: inline-flex;
    flex-wrap: wrap;
    padding-left: 1px;
}

article[data-article] .cell {
    display: inline-grid;
    justify-items: center;
    min-width: 2.6ch;
    margin-left: -1px;
    padding: 0 2px;
    border: 1px solid var(--lp-rule-strong);
    font: 400 12px/18px var(--lp-font-mono);
    color: var(--lp-ink);
}

article[data-article] .cell-char {
    color: var(--lp-ink-3);
}

/*
 * A bar as long as its bytes, the count beside it. One figure keeps one scale (`--figure-byte`
 * per byte), so bars compare across its rows; a hairline of the canvas marks each byte.
 */
article[data-article] .size {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

article[data-article] .size-bar {
    display: inline-block;
    height: 10px;
    width: calc(var(--bytes) * var(--figure-byte));
    background-color: var(--lp-ink);
    background-image: linear-gradient(to right, transparent calc(var(--figure-byte) - 1px), var(--lp-canvas) 0);
    background-size: var(--figure-byte) 100%;
}

article[data-article] .size-bar.json {
    background-color: var(--lp-ink-3);
}

/* Padding carries nothing: hatched, as the byte map draws it. */
article[data-article] .size-bar.padding {
    background-color: transparent;
    background-image: repeating-linear-gradient(135deg, var(--lp-ink-3) 0 1px, transparent 1px 4px);
    background-size: auto;
    outline: 1px solid var(--lp-ink-3);
    outline-offset: -1px;
}

/* Data after a block has no size of its own: an open outline, as long as a few bytes. */
article[data-article] .size-bar.data {
    width: calc(6 * var(--figure-byte));
    background: none;
    border: 1px dashed var(--lp-ink-3);
}

article[data-article] .size-count {
    color: var(--lp-ink-2);
    font-variant-numeric: tabular-nums;
}

/*
 * A message as JSON beside its bytes: a row per field, its name, then the JSON's text over the
 * binary's boxes, each with its bar. The bars are solid: at this scale a hairline per byte would
 * leave no bar. On a narrow figure the name takes a line of its own and the scale halves, so the
 * whole message's bars still fit.
 */
article[data-article] figure.compare {
    --figure-byte: 3px;
    container-type: inline-size;
}

article[data-article] figure.compare .size-bar {
    background-image: none;
}

article[data-article] figure.compare .cells,
article[data-article] figure.compare .size {
    justify-self: start;
}

article[data-article] figure.compare ol {
    list-style: none;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--lp-rule-2);
}

article[data-article] figure.compare li {
    display: grid;
    grid-template-columns: minmax(7em, 10em) 4em minmax(0, 1fr) 9em;
    column-gap: 12px;
    row-gap: 4px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--lp-rule);
    font: 400 12px/20px var(--lp-font-mono);
    color: var(--lp-ink);
}

article[data-article] figure.compare .compare-name {
    grid-row: span 2;
    align-self: start;
}

article[data-article] figure.compare .compare-side {
    font: 500 10px/16px var(--lp-font-mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--lp-ink-3);
}

article[data-article] figure.compare code.compare-json {
    font: inherit;
    background: none;
    padding: 0;
    overflow-wrap: anywhere;
}

article[data-article] figure.compare .compare-none {
    color: var(--lp-ink-4);
}

/* The totals' bars are longer than any field's: each takes the rest of its line. */
article[data-article] figure.compare li.compare-total {
    font-weight: 500;
}

article[data-article] figure.compare li.compare-total .size {
    grid-column: 3 / -1;
}

@container (max-width: 520px) {
    article[data-article] figure.compare ol {
        --figure-byte: 2px;
    }

    /* Each row is a grid of its own: a fixed size column starts every row's bars at one line. */
    article[data-article] figure.compare li {
        grid-template-columns: 4em minmax(0, 1fr) 7.5em;
    }

    article[data-article] figure.compare .compare-name {
        grid-row: auto;
        grid-column: 1 / -1;
    }

    article[data-article] figure.compare li.compare-total .size {
        grid-column: 2 / -1;
    }
}

/* Layouts side by side: each field's offset, then its bar, at a scale a block of 64 bytes fits. */
article[data-article] figure.layouts {
    --figure-byte: 6px;
}

article[data-article] figure.layouts .slot {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

article[data-article] figure.layouts .slot-offset {
    min-width: 3ch;
    text-align: right;
    color: var(--lp-ink-3);
    font-variant-numeric: tabular-nums;
}

article[data-article] figure.layouts .size-bar.field {
    background-color: color-mix(in srgb, var(--pv-series-1) 70%, var(--lp-ink));
}

article[data-article] figure.layouts tr.layouts-padding td:first-child,
article[data-article] figure.layouts tr.layouts-data td:first-child {
    color: var(--lp-ink-3);
}

/* Bytes written for an example: groups under their title and size, a row per part: offset, name, boxes, note. */
article[data-article] figure.cells-figure .cells-group + .cells-group {
    margin-top: 16px;
}

article[data-article] figure.cells-figure .cells-title {
    margin: 0 0 6px;
    font: var(--article-text);
    color: var(--lp-ink);
}

article[data-article] figure.cells-figure .cells-size {
    margin-left: 6px;
    font: 400 12px/20px var(--lp-font-mono);
    color: var(--lp-ink-3);
}

/* The rows of a group share their columns, so every row's boxes start at one line. */
article[data-article] figure.cells-figure ol {
    display: grid;
    grid-template-columns: 3ch minmax(6em, max-content) max-content minmax(10em, 1fr);
    column-gap: 12px;
    list-style: none;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--lp-rule-2);
}

article[data-article] figure.cells-figure li {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--lp-rule);
    font: 400 12px/20px var(--lp-font-mono);
    color: var(--lp-ink);
}

article[data-article] figure.cells-figure .cells-offset {
    text-align: right;
    color: var(--lp-ink-3);
    font-variant-numeric: tabular-nums;
}

article[data-article] figure.cells-figure .cells-note {
    font: var(--lp-type-small);
    color: var(--lp-ink-2);
}

/* In a narrow column (a phone, the app's Guide pane) the note goes under the bytes. */
article[data-article] figure.cells-figure {
    container-type: inline-size;
}

@container (max-width: 520px) {
    article[data-article] figure.cells-figure ol {
        grid-template-columns: 3ch minmax(0, 1fr);
    }

    article[data-article] figure.cells-figure li {
        row-gap: 4px;
    }

    article[data-article] figure.cells-figure li > :nth-child(n + 3) {
        grid-column: 2;
    }
}

/* A table written for an example: its cells are words, so they wrap as copy does. */
article[data-article] figure.written td {
    white-space: normal;
}

/*
 * A frame's bytes, tinted by what they belong to: the stream's length prefix, the message header,
 * the root block, a group, a data field. The tints are the tool's series (`code-colors.css`), as
 * the byte map's blocks, since the site's tokens have no hue.
 */
article[data-article] .b-prefix {
    background: color-mix(in srgb, var(--pv-series-4) 30%, transparent);
}

article[data-article] .b-header {
    background: color-mix(in srgb, var(--pv-series-7) 28%, transparent);
}

article[data-article] .b-root {
    background: color-mix(in srgb, var(--pv-series-1) 25%, transparent);
}

article[data-article] .b-group {
    background: color-mix(in srgb, var(--pv-series-3) 25%, transparent);
}

/* Green, not the teal of the series: beside the root's blue, teal reads as the same part. */
article[data-article] .b-data {
    background: color-mix(in srgb, var(--pv-series-2) 30%, transparent);
}

/* Bytes of fields a block does not name stay in place, faint. */
article[data-article] .b-other {
    opacity: 0.4;
}

article[data-article] pre.byte-dump .gutter,
article[data-article] pre.byte-dump .dump-text {
    color: var(--lp-ink-3);
}

/*
 * The field pointed at or chosen in a frame's blocks: its row and its bytes outlined in the ink,
 * the other bytes of the dump faded as the byte map fades the runs outside its selection. An
 * outline takes no room, so nothing moves.
 */
article[data-article] figure.bytes .lit {
    outline: 1px solid var(--lp-ink);
    outline-offset: -1px;
}

article[data-article] figure.bytes[data-lit] pre.byte-dump [data-field]:not(.lit, .b-other) {
    opacity: 0.65;
}

article[data-article] figure.bytes pre.byte-dump .b-other.lit {
    opacity: 1;
}

article[data-article] figure.bytes tr[data-field]:focus-visible {
    outline: 2px solid var(--lp-ink);
    outline-offset: -2px;
}

/*
 * A frame's field table has six columns, wider unwrapped than the article column: names, meanings
 * and runs of bytes wrap so the value columns come closer to view; what still does not fit
 * scrolls inside the figure.
 */
article[data-article] figure.bytes td {
    white-space: normal;
}

article[data-article] figure.bytes .byte-group {
    white-space: nowrap;
}

article[data-article] figure.stream ol {
    list-style: none;
    padding: 0;
    margin: 0;
}

/*
 * A stream's frames: one per row between hairlines, as a table's rows. A frame's bytes read as a
 * table's mono cells, not inline code; where it starts leads them, and what it holds follows on its
 * own line in the site's small copy.
 */
article[data-article] figure.stream li {
    padding: 8px 0;
    border-bottom: 1px solid var(--lp-rule);
    font: 400 12px/20px var(--lp-font-mono);
    color: var(--lp-ink);
}

article[data-article] figure.stream li:first-child {
    border-top: 1px solid var(--lp-rule-2);
}

article[data-article] figure.stream .stream-offset {
    color: var(--lp-ink-3);
}

article[data-article] figure.stream code.stream-bytes {
    font: inherit;
    background: none;
    padding: 0;
    overflow-wrap: anywhere;
}

article[data-article] figure.stream .stream-more {
    color: var(--lp-ink-3);
}

article[data-article] figure.stream .stream-note {
    display: block;
    font: var(--lp-type-small);
    color: var(--lp-ink-3);
}

/* The text view's gutter: start and size, each as wide as the widest the guide's samples need. */
article[data-article] pre.declaration .gutter {
    display: inline-grid;
    grid-template-columns: 4ch 4ch;
    gap: 1ch;
    margin-right: 2ch;
    color: var(--lp-ink-3);
    text-align: right;
    user-select: none;
}

article[data-article] .tv-name {
    color: var(--lp-ink);
}

article[data-article] .tv-keyword {
    color: var(--pv-syntax-keyword);
}

article[data-article] .tv-presence {
    color: var(--pv-syntax-presence);
}

article[data-article] .tv-type {
    color: var(--pv-syntax-type);
}

article[data-article] .tv-tag {
    color: var(--pv-syntax-tag);
}

article[data-article] .tv-value {
    color: var(--pv-syntax-value);
}

article[data-article] .tv-comment {
    color: var(--pv-syntax-comment);
}

article[data-article] .tv-punctuation {
    color: var(--pv-syntax-punctuation);
}

/*
 * A type's own declaration line, under its name in a declaration while the pointer rests on the
 * name or the name has the focus, as the app's type card shows it: the raised canvas in a
 * hairline with the site's overlay shadow. The article places it, not the declaration, which
 * scrolls sideways and would cut it at its edges; with no offsets it starts where the name
 * starts, and its margin moves it one line down.
 */
article[data-article] {
    position: relative;
}

article[data-article] .declared-type {
    cursor: help;
    text-decoration: underline dotted;
    text-decoration-color: var(--lp-rule-strong);
    text-underline-offset: 0.2em;
}

article[data-article] .declared-type-line {
    display: none;
    position: absolute;
    z-index: 1;
    margin-top: calc(1lh + 4px);
    max-width: min(60ch, 90%);
    padding: 6px 10px;
    white-space: normal;
    background: var(--lp-canvas-raised);
    color: var(--lp-ink);
    border: 1px solid var(--lp-rule-2);
    box-shadow: var(--lp-overlay-shadow);
    font: 400 12px/20px var(--lp-font-mono);
    text-decoration: none;
    cursor: auto;
}

article[data-article] .declared-type:hover > .declared-type-line,
article[data-article] .declared-type:focus > .declared-type-line {
    display: inline-block;
}

/* A link into the viewer: the site's label type, with an arrow. */
article[data-article] p.open a {
    font: var(--lp-type-label);
    text-decoration: none;
}

article[data-article] p.open a::after {
    content: " →";
}

article[data-article] p.open a:hover {
    text-decoration: underline;
}

/* A finger's target: the whole line's height, as tall as a tap needs. */
@media (pointer: coarse) {
    article[data-article] p.open a {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
    }
}

/*
 * The protocol directory: cells hold words, so they wrap and take the site's small copy, unlike
 * a layout's. Where the article is narrower than the table reads (a phone, a narrow Guide
 * pane), each row becomes a card of labelled lines; the label comes from the cell's column.
 */
article[data-article] figure.directory {
    container-type: inline-size;
    overflow: visible;
}

article[data-article] figure.directory tr[hidden] {
    display: none;
}

article[data-article] figure.directory table {
    font: var(--lp-type-small);
}

article[data-article] figure.directory td {
    padding-block: 6px;
    white-space: normal;
    vertical-align: top;
}

@container (max-width: 40rem) {
    article[data-article] figure.directory thead {
        display: none;
    }

    article[data-article] figure.directory table,
    article[data-article] figure.directory caption,
    article[data-article] figure.directory tbody,
    article[data-article] figure.directory tr,
    article[data-article] figure.directory td {
        display: block;
    }

    article[data-article] figure.directory tr {
        padding: 8px 0;
    }

    article[data-article] figure.directory td {
        padding: 0 10px;
    }

    article[data-article] figure.directory td::before {
        content: attr(data-label) ": ";
        color: var(--lp-ink-3);
    }

    article[data-article] figure.directory td[data-column="Venue"] {
        font: var(--lp-type-label);
        color: var(--lp-ink);
    }

    article[data-article] figure.directory td[data-column="Venue"]::before {
        content: none;
    }
}

/*
 * The market data reference table: the directory's cells of words, each row's name and what it
 * is in columns of their own, the row a link lands on tinted. Its Filter row's completions and syntax open over the
 * rows, so the figure does not clip them. Narrower than its eight columns read, each row is a
 * card of labelled lines, as the directory's; an empty cell (no size) is left out.
 */
article[data-article] figure.sources {
    container-type: inline-size;
    overflow: visible;
}

/* Each column's width is set by its heading, so a long description cannot squeeze the name. */
article[data-article] figure.sources table {
    width: 100%;
    table-layout: fixed;
    font: var(--lp-type-small);
}

/* Words wrap between words, and a word wider than its column breaks. */
article[data-article] figure.sources th,
article[data-article] figure.sources td {
    padding: 6px 6px;
    white-space: normal;
    overflow-wrap: break-word;
    vertical-align: top;
}

article[data-article] figure.sources [data-column="Name"] {
    width: 14%;
    overflow-wrap: anywhere;
}

article[data-article] figure.sources [data-column="Description"] {
    width: 24%;
}

article[data-article] figure.sources [data-column="Kind"],
article[data-article] figure.sources [data-column="Get it"] {
    width: 11%;
}

article[data-article] figure.sources [data-column="Venue"] {
    width: 12%;
}

article[data-article] figure.sources [data-column="Size"] {
    width: 6%;
}

/* Wide enough for "on request" on one line. */
article[data-article] figure.sources [data-column="Access"] {
    width: 8%;
}

article[data-article] figure.sources [data-column="Terms"] {
    width: 14%;
}

article[data-article] figure.sources .source-name {
    display: block;
    font: var(--lp-type-label);
}

article[data-article] figure.sources .source-note {
    display: block;
    color: var(--lp-ink-2);
}

/* View after a publisher's file: the file's action, kept with it on one line. */
article[data-article] figure.sources .source-action {
    font-weight: 600;
    white-space: nowrap;
}

/*
 * The row a link lands on (`:target` on the guide's pages, `data-landed` from the page's script
 * and the Guide pane): a strong tint of the accent that settles to a light one, which stays until
 * a link lands elsewhere. It stops clear of the site's header and the sticky heading row.
 */
article[data-article] figure[data-filter-fields] tbody tr {
    scroll-margin-top: calc(var(--guide-header-height, 0px) + 40px);
}

article[data-article] figure[data-filter-fields] tr:target,
article[data-article] figure[data-filter-fields] tr[data-landed] {
    background: color-mix(in srgb, var(--pv-series-1) 14%, transparent);
    box-shadow: inset 3px 0 0 var(--pv-series-1);
    animation: row-landed 1.6s ease-out;
}

@keyframes row-landed {
    from {
        background: color-mix(in srgb, var(--pv-series-1) 40%, transparent);
    }
}

@media (prefers-reduced-motion: reduce) {
    article[data-article] figure[data-filter-fields] tr:target,
    article[data-article] figure[data-filter-fields] tr[data-landed] {
        animation: none;
    }
}

/*
 * The heading row of a filtered table stays in view while its rows scroll, under the site's header
 * on the guide's pages (`--guide-header-height`) and at the top of the Guide pane in the app.
 * The figures do not clip (`overflow: visible`), so the rows scroll under the page's own scroll.
 */
article[data-article] figure[data-filter-fields] thead th {
    position: sticky;
    top: var(--guide-header-height, 0);
    z-index: 1;
}

/* A heading the page's script made a button: it sorts the rows by its column, its arrow the order. */
article[data-article] figure[data-filter-fields] th button.table-sort {
    padding: 0;
    border: none;
    background: none;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
}

article[data-article] figure[data-filter-fields] th[aria-sort="ascending"] button.table-sort::after {
    content: " ↑";
}

article[data-article] figure[data-filter-fields] th[aria-sort="descending"] button.table-sort::after {
    content: " ↓";
}

article[data-article] figure[data-filter-fields] .guide-filter-row {
    margin-bottom: 8px;
    border: 1px solid var(--lp-rule);
}

@container (max-width: 48rem) {
    article[data-article] figure.sources thead {
        display: none;
    }

    article[data-article] figure.sources table,
    article[data-article] figure.sources caption,
    article[data-article] figure.sources tbody,
    article[data-article] figure.sources tr,
    article[data-article] figure.sources td {
        display: block;
    }

    article[data-article] figure.sources tr {
        padding: 8px 0;
        border-bottom: 1px solid var(--lp-rule);
    }

    article[data-article] figure.sources tr[hidden] {
        display: none;
    }

    article[data-article] figure.sources td {
        padding: 0 10px;
        border: none;
    }

    /* A card's lines take the card's width, not their column's. */
    article[data-article] figure.sources td[data-column] {
        width: auto;
    }

    article[data-article] figure.sources td:empty {
        display: none;
    }

    article[data-article] figure.sources td::before {
        content: attr(data-label) ": ";
        color: var(--lp-ink-3);
    }

    article[data-article] figure.sources td[data-column="Name"]::before {
        content: none;
    }
}

/*
 * A `ladder` figure: the book pane's ladder as the app draws it, in its colours: asks in the
 * purple-red series, bids in the teal, each block its hue tinted toward the canvas, fills in the
 * orange. The grid keeps the pane's proportions; a narrow page scrolls it sideways. A `queue`
 * figure draws in the same colours.
 */
article[data-article] figure.ladder,
article[data-article] figure.queue {
    --ladder-bid: color-mix(in srgb, var(--pv-series-5) 30%, var(--lp-canvas));
    --ladder-ask: color-mix(in srgb, var(--pv-series-3) 30%, var(--lp-canvas));
    --ladder-bid-edge: color-mix(in srgb, var(--pv-series-5) 70%, var(--lp-canvas));
    --ladder-ask-edge: color-mix(in srgb, var(--pv-series-3) 70%, var(--lp-canvas));
    --ladder-trade: var(--pv-series-4);
    margin-inline: 0;
    overflow-x: auto;
    font: 400 11px/14px var(--lp-font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--lp-ink);
}

article[data-article] figure.ladder {
    --ladder-row: 20px;
}

article[data-article] figure.ladder .ladder-grid {
    display: grid;
    grid-auto-rows: var(--ladder-row);
    min-width: 560px;
    border: 1px solid var(--lp-rule);
    background: var(--lp-canvas);
}

article[data-article] figure.ladder .ladder-row {
    display: contents;
}

article[data-article] figure.ladder .ladder-label,
article[data-article] figure.ladder .ladder-cell,
article[data-article] figure.ladder .ladder-price {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 6px;
    overflow: hidden;
    white-space: nowrap;
}

article[data-article] figure.ladder .ladder-label {
    height: 16px;
    color: var(--lp-ink-3);
    border-bottom: 1px solid var(--lp-rule);
}

article[data-article] figure.ladder .ladder-head {
    display: contents;
}

article[data-article] figure.ladder .ladder-price,
article[data-article] figure.ladder .ladder-label[data-cell="price"] {
    justify-content: center;
}

article[data-article] figure.ladder .ladder-price {
    color: var(--lp-ink-2);
    background: color-mix(in srgb, var(--lp-ink) 3%, var(--lp-canvas));
}

article[data-article] figure.ladder .ladder-cell[data-cell$="Orders"],
article[data-article] figure.ladder .ladder-cell[data-cell$="Implied"] {
    color: var(--lp-ink-3);
}

/* Each side's sizes in its colour mixed 70% with the ink: the most of the hue that keeps 4.5:1 on the canvas in both themes. */
article[data-article] figure.ladder .ladder-row[data-zone="ask"] .ladder-cell[data-cell^="ask"]:not([data-cell$="Implied"]) {
    color: color-mix(in srgb, var(--pv-series-3) 70%, var(--lp-ink));
}

article[data-article] figure.ladder .ladder-row[data-zone="bid"] .ladder-cell[data-cell^="bid"]:not([data-cell$="Implied"]) {
    color: color-mix(in srgb, var(--pv-series-5) 70%, var(--lp-ink));
}

/* The best ask and bid: the price in its side's colour, a rule on the spread's side. */
article[data-article] figure.ladder .ladder-row[data-best="ask"] .ladder-price {
    color: var(--lp-ink);
    background: color-mix(in srgb, var(--pv-series-3) 18%, var(--lp-canvas));
}

article[data-article] figure.ladder .ladder-row[data-best="bid"] .ladder-price {
    color: var(--lp-ink);
    background: color-mix(in srgb, var(--pv-series-5) 18%, var(--lp-canvas));
}

article[data-article] figure.ladder .ladder-row[data-best="ask"] > :not(.ladder-queue) {
    box-shadow: inset 0 -1px 0 var(--lp-rule-strong);
}

article[data-article] figure.ladder .ladder-row[data-best="bid"] > :not(.ladder-queue) {
    box-shadow: inset 0 1px 0 var(--lp-rule-strong);
}

/*
 * The level book's depth: a dashed rule past its deepest level on each side, and the prices
 * beyond it faded, where only the orders say what rests.
 */
article[data-article] figure.ladder .ladder-row[data-depth="beyond"] > :not(.ladder-price) {
    opacity: 0.35;
}

article[data-article] figure.ladder .ladder-row[data-depth="last"] > * {
    background-image: linear-gradient(to right, var(--lp-ink-2) 50%, transparent 50%);
    background-repeat: repeat-x;
    background-size: 6px 1px;
}

article[data-article] figure.ladder .ladder-row[data-depth="last"][data-zone="bid"] > * {
    background-position: left bottom;
}

article[data-article] figure.ladder .ladder-row[data-depth="last"][data-zone="ask"] > * {
    background-position: left top;
}

/* A queue: its blocks placed by their shares of the column, the front at the price. */
article[data-article] figure.ladder .ladder-queue {
    position: relative;
    overflow: hidden;
}

article[data-article] figure.ladder .ladder-block,
article[data-article] figure.ladder .ladder-mark {
    position: absolute;
    top: 1px;
    bottom: 1px;
    display: flex;
    align-items: center;
    overflow: hidden;
    white-space: nowrap;
}

article[data-article] figure.ladder .ladder-block {
    padding: 0 3px;
    background-color: var(--ladder-ask);
    --ladder-edge: var(--ladder-ask-edge);
}

article[data-article] figure.ladder .ladder-queue[data-side="bid"] .ladder-block {
    justify-content: flex-end;
    background-color: var(--ladder-bid);
    --ladder-edge: var(--ladder-bid-edge);
}

/* Contracts resting since before the capture: hatched; the folded back of a queue: striped. */
article[data-article] figure.ladder .ladder-block[data-kind="beforeCapture"] {
    background-image: repeating-linear-gradient(135deg, var(--ladder-edge) 0 1px, transparent 1px 4px);
}

article[data-article] figure.ladder .ladder-block[data-kind="folded"] {
    background-image: repeating-linear-gradient(90deg, var(--ladder-edge) 0 1px, transparent 1px 4px);
}

/* A fill of the step: the traded part solid, the rest in its side's colour, the whole outlined. */
article[data-article] figure.ladder .ladder-mark {
    box-shadow: inset 0 0 0 2px var(--ladder-trade);
    background: var(--ladder-ask);
}

article[data-article] figure.ladder .ladder-queue[data-side="bid"] .ladder-mark {
    flex-direction: row-reverse;
    background: var(--ladder-bid);
}

article[data-article] figure.ladder .ladder-traded {
    flex: none;
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--ladder-trade);
}

article[data-article] figure.ladder .ladder-rest,
article[data-article] figure.ladder .ladder-mark-label {
    padding: 0 3px;
    overflow: hidden;
}

/* An order the fill took out of the book: hatched in the trade colour, its outline dashed. */
article[data-article] figure.ladder .ladder-mark[data-left="left"] {
    box-shadow: none;
    outline: 2px dashed var(--ladder-trade);
    outline-offset: -2px;
    background: var(--lp-canvas) repeating-linear-gradient(135deg, var(--ladder-trade) 0 2px, transparent 2px 8px);
}

article[data-article] figure.ladder .ladder-mark[data-kind="fold"] {
    background-image: repeating-linear-gradient(90deg, var(--ladder-trade) 0 1px, transparent 1px 4px);
}

article[data-article] figure.ladder .ladder-fills {
    min-width: 560px;
    border: 1px solid var(--lp-rule);
    border-top: 0;
}

article[data-article] figure.ladder .ladder-fills-title {
    margin: 0;
    padding: 3px 8px;
    color: var(--lp-ink-3);
}

/* A walk's price impact, worked out under its fills. */
article[data-article] figure.ladder .book-impact {
    margin: 0;
    padding: 3px 8px;
    color: var(--lp-ink-2);
}

article[data-article] figure.ladder .ladder-fills ol {
    display: grid;
    grid-template-columns: repeat(5, max-content) 1fr;
    column-gap: 16px;
    margin: 0;
    padding: 0 8px 4px;
    list-style: none;
}

article[data-article] figure.ladder .ladder-fills li {
    display: contents;
}

article[data-article] figure.ladder .ladder-fills .number {
    text-align: right;
}

article[data-article] figure.ladder .ladder-fills .filled {
    color: color-mix(in srgb, var(--pv-series-4) 70%, var(--lp-ink));
}

article[data-article] figure.ladder .ladder-fills-more span {
    grid-column: 1 / -1;
    color: var(--lp-ink-3);
}

/*
 * A `message` figure: the message's number and linked name over a table of its entries, the
 * entries of the block's instrument tinted in their side's ladder colour (a trade's in the ink).
 */
article[data-article] figure.message .message-head {
    margin: 0 0 6px;
    font: 400 12px/20px var(--lp-font-mono);
    color: var(--lp-ink);
}

article[data-article] figure.message .message-number,
article[data-article] figure.message .message-note,
article[data-article] figure.message .message-index {
    color: var(--lp-ink-3);
}

article[data-article] figure.message .message-number {
    margin-inline-end: 1ch;
}

/* The heads are the schema's field names, written as the schema writes them. */
article[data-article] figure.message th {
    text-transform: none;
    letter-spacing: 0;
    font-size: 11px;
}

article[data-article] figure.message th,
article[data-article] figure.message td {
    padding-inline: 8px;
}

article[data-article] figure.message tr[data-picked="bid"] {
    background: color-mix(in srgb, var(--pv-series-5) 18%, var(--lp-canvas));
}

article[data-article] figure.message tr[data-picked="ask"] {
    background: color-mix(in srgb, var(--pv-series-3) 18%, var(--lp-canvas));
}

article[data-article] figure.message tr[data-picked="entry"] {
    background: color-mix(in srgb, var(--lp-ink) 6%, var(--lp-canvas));
}

/*
 * A `queue` figure: one price's queue as a row of the ladder's ask blocks, the front on the left,
 * and a trade's fills in the ladder's marks, each step of the rule in its own shade of the trade
 * colour: the top order's toward the ink, pro rata's toward the canvas, first in, first out the
 * ladder's own.
 */
article[data-article] figure.queue {
    --queue-rule: 88px;
    --queue-top: color-mix(in srgb, var(--ladder-trade) 60%, var(--lp-ink));
    --queue-pro-rata: color-mix(in srgb, var(--ladder-trade) 45%, var(--lp-canvas));
    --queue-fifo: var(--ladder-trade);
}

/*
 * A label on a solid step takes the ink or the canvas, whichever stands out on that shade: the top
 * order's shade leans to the ink and pro rata's to the canvas in both themes, and the trade colour
 * itself is light in the dark theme and dark in the light one. Each pair is 4.5:1 or more.
 */
article[data-article] figure.queue [data-step="top"] {
    --queue-step: var(--queue-top);
    --queue-step-ink: var(--lp-canvas);
}

article[data-article] figure.queue [data-step="proRata"] {
    --queue-step: var(--queue-pro-rata);
    --queue-step-ink: var(--lp-ink);
}

article[data-article] figure.queue [data-step="fifo"] {
    --queue-step: var(--queue-fifo);
    --queue-step-ink: var(--lp-ink);
}

[data-st-theme="dark"] article[data-article] figure.queue [data-step="fifo"] {
    --queue-step-ink: var(--lp-canvas);
}

article[data-article] figure.queue .queue-box {
    min-width: 560px;
    padding: 4px 8px 6px;
    border: 1px solid var(--lp-rule);
    background: var(--lp-canvas);
}

article[data-article] figure.queue .queue-row {
    display: grid;
    grid-template-columns: var(--queue-rule) 1fr;
}

article[data-article] figure.queue .queue-rule {
    align-self: center;
    overflow: hidden;
    white-space: nowrap;
    color: var(--lp-ink-2);
}

article[data-article] figure.queue .queue-front {
    grid-column: 2;
    color: var(--lp-ink-3);
}

/* A queue: each order placed by its share of the row, a pixel apart from the next. */
article[data-article] figure.queue .queue-track {
    grid-column: 2;
    position: relative;
    height: 22px;
}

article[data-article] figure.queue .queue-fills .queue-track {
    height: 14px;
    margin-bottom: 6px;
}

article[data-article] figure.queue .queue-order,
article[data-article] figure.queue .queue-fill {
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(var(--start) + 1px);
    width: calc(var(--width) - 2px);
    display: flex;
    overflow: hidden;
    white-space: nowrap;
}

article[data-article] figure.queue .queue-order {
    background: var(--ladder-ask);
}

article[data-article] figure.queue .queue-traded,
article[data-article] figure.queue .queue-step,
article[data-article] figure.queue .queue-rest {
    flex: 1 1 0;
    min-width: 0;
}

article[data-article] figure.queue .queue-traded {
    display: flex;
}

article[data-article] figure.queue .queue-step {
    color: var(--queue-step-ink);
    background: var(--queue-step);
}

/* Each step's part of a fill is labelled in its own shade, as the fills under the blocks add them up. */
article[data-article] figure.queue .queue-step,
article[data-article] figure.queue .queue-rest,
article[data-article] figure.queue .queue-fill {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* An order that rests on: the traded part solid, the whole outlined in the trade colour. */
article[data-article] figure.queue .queue-order[data-left="rests"] {
    box-shadow: inset 0 0 0 2px var(--ladder-trade);
}

/* An order the trade took out of the book: hatched in its steps' shades, its outline dashed. */
article[data-article] figure.queue .queue-order[data-left="left"] {
    outline: 2px dashed var(--ladder-trade);
    outline-offset: -2px;
    background: var(--lp-canvas);
}

article[data-article] figure.queue .queue-order[data-left="left"] .queue-step {
    background: repeating-linear-gradient(135deg, var(--queue-step) 0 2px, transparent 2px 8px);
}

article[data-article] figure.queue .queue-order[data-left="left"] .queue-step span {
    padding: 0 2px;
    color: var(--lp-ink);
    background: var(--lp-canvas);
}

article[data-article] figure.queue .queue-fill {
    color: color-mix(in srgb, var(--pv-series-4) 70%, var(--lp-ink));
}

article[data-article] figure.queue .queue-fill[data-left="untouched"] {
    color: var(--lp-ink-3);
}

article[data-article] :is(figure.queue, figure.ladder) .queue-key {
    display: flex;
    gap: 14px;
    margin: 0;
    color: var(--lp-ink-2);
}

article[data-article] :is(figure.queue, figure.ladder) .queue-key span::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 5px;
    vertical-align: -1px;
    background: var(--queue-step);
}

/* The key's marks, drawn as the blocks draw them: traded solid, an order that left hatched and dashed. */
article[data-article] :is(figure.queue, figure.ladder) .queue-key [data-mark="traded"]::before {
    background: var(--ladder-trade);
}

article[data-article] :is(figure.queue, figure.ladder) .queue-key [data-mark="left"]::before {
    outline: 1px dashed var(--ladder-trade);
    background: repeating-linear-gradient(135deg, var(--ladder-trade) 0 2px, transparent 2px 5px);
}

/* The queue before the trade sits apart from the rows of fills under it. */
article[data-article] figure.queue .queue-before {
    margin-bottom: 10px;
}

/* A row's pro rata arithmetic, one line per order. */
article[data-article] figure.queue .queue-calc {
    min-width: 560px;
    margin-top: 8px;
    font-variant-numeric: tabular-nums;
}

article[data-article] figure.queue .queue-calc caption {
    text-align: left;
}

/*
 * A playground's controls: a line that says what to try, then rows of named groups over the
 * figure they change, what the reader tries first on the first row, in the figure's small code
 * font; a choice of one is a row of segments, the chosen one inked.
 */
article[data-article] figure.playground .playground-controls:not([hidden]) {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 560px;
    margin-bottom: 6px;
}

article[data-article] figure.playground .pg-hint {
    margin: 0;
    color: var(--lp-ink-2);
}

article[data-article] figure.playground .pg-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
}

article[data-article] figure.playground .pg-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

article[data-article] figure.playground .pg-name {
    margin-right: 2px;
    color: var(--lp-ink-3);
}

article[data-article] figure.playground .pg-order {
    display: inline-flex;
}

article[data-article] figure.playground .playground-controls :is(input[type="number"], select, button),
article[data-article] figure.playground .pg-choice {
    height: 22px;
    padding: 0 5px;
    border: 1px solid var(--lp-rule-2);
    border-radius: 0;
    background: var(--lp-canvas-raised);
    color: var(--lp-ink);
    font: inherit;
}

/* Three digits wide, without the spinner: the arrow keys still step the number. */
article[data-article] figure.playground .playground-controls input[type="number"] {
    width: 5ch;
    padding: 0 4px;
    text-align: right;
    appearance: textfield;
}

article[data-article] figure.playground .playground-controls input[type="number"]::-webkit-inner-spin-button,
article[data-article] figure.playground .playground-controls input[type="number"]::-webkit-outer-spin-button {
    margin: 0;
    appearance: none;
}

/* The trade is dragged: a slider wide enough to aim with, beside the number it keeps in step. */
article[data-article] figure.playground .playground-controls input[type="range"] {
    width: 180px;
    accent-color: var(--ladder-trade);
    cursor: ew-resize;
}

article[data-article] figure.playground .playground-controls button {
    cursor: pointer;
}

article[data-article] figure.playground .playground-controls button:disabled,
article[data-article] figure.playground .playground-controls input:disabled {
    cursor: default;
    color: var(--lp-ink-4);
}

article[data-article] figure.playground .pg-remove {
    border-left: 0;
    color: var(--lp-ink-3);
}

article[data-article] figure.playground .pg-choice {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

article[data-article] figure.playground .pg-choice + .pg-choice {
    margin-left: -4px;
    border-left: 0;
}

/* The radio button itself is the segment: out of sight, kept in the tab order. */
article[data-article] figure.playground .pg-choice input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

article[data-article] figure.playground .pg-choice:has(input:checked) {
    background: var(--lp-ink);
    color: var(--lp-canvas);
}

article[data-article] figure.playground .playground-controls button.pg-send {
    border-color: var(--lp-ink);
    background: var(--lp-ink);
    color: var(--lp-canvas);
}

article[data-article] figure.playground :is(input, select, button):focus-visible,
article[data-article] figure.playground .pg-choice:has(input:focus-visible) {
    outline: 2px solid var(--ladder-trade);
    outline-offset: 1px;
}

article[data-article] figure.playground .pg-failure {
    color: var(--lp-error);
}

/* The price a walk is taking: its row tinted in the trade colour, the price cell as well. */
article[data-article] figure.ladder.playground .ladder-row[data-taking] > *,
article[data-article] figure.ladder.playground .ladder-row[data-taking] .ladder-price {
    background-color: color-mix(in srgb, var(--ladder-trade) 22%, var(--lp-canvas));
}

/* What of the incoming order joined the book: its side's block outlined in the trade colour. */
article[data-article] figure.ladder .ladder-block[data-kind="joined"] {
    box-shadow: inset 0 0 0 2px var(--ladder-trade);
}

article[data-article] figure.ladder .queue-key [data-mark="joined"]::before {
    background: var(--ladder-ask);
    box-shadow: inset 0 0 0 2px var(--ladder-trade);
}

/* A walk's lines: one per price taken, then where the order ended, over its price impact. */
article[data-article] figure.ladder .ladder-fills ol.book-steps {
    display: block;
    padding: 3px 8px 0;
}

article[data-article] figure.ladder .ladder-fills ol.book-steps li {
    display: block;
}

article[data-article] figure.ladder .book-end {
    margin: 0;
    padding: 3px 8px 0;
}

article[data-article] figure.ladder .book-best {
    display: flex;
    gap: 16px;
    min-width: 560px;
    margin: 0;
    padding: 3px 8px;
    border: 1px solid var(--lp-rule);
    border-top: 0;
    color: var(--lp-ink-3);
}

article[data-article] figure.ladder .book-best b {
    margin-left: 6px;
    font-weight: 400;
    color: var(--lp-ink);
}

article[data-article] figure.ladder .ladder-fills .queue-key {
    padding: 0 8px 4px;
}
