/*
 * The guide's pages around an article, as structure.fi's pages: a header bar with the
 * wordmark and the theme toggle (on structure.fi the site's own header takes its place), the
 * breadcrumbs as an eyebrow, a large light title with its tools beside it, copy in
 * Geist Sans, buttons and fields the site's own (`site.css`), a hairline footer. The article's
 * body has its own sheet (`article.css`), which the app's Guide pane shares. The site's tokens
 * (`landing/landing.css`, `--lp-*`) supply every colour and font. The one length that is not the
 * site's is the reading column's width, `--guide-measure`: the site's narrow pages' 760 px, about
 * 75 characters of the body's 17 px copy, the upper end of a comfortable line length; layout
 * tables and declarations may run wider and scroll.
 */
:root {
    --guide-measure: 760px;
    /* The site's header bar's height. */
    --guide-header-height: 52px;
    /* The site's form errors (site.css `--site-error`), which `.site-input` reads. */
    --site-error: var(--lp-error);
    /* A heading a link or the search opens stops under the sticky header, not behind it. */
    scroll-padding-top: var(--guide-header-height);
    color-scheme: light;
}

[data-st-theme="dark"] {
    color-scheme: dark;
}

/* The site's header: sticky, the raised canvas a little see-through under a blur, a hairline under it. */
header.site {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: var(--guide-header-height);
    padding: 0 max(var(--lp-gutter), calc((100% - var(--lp-container)) / 2));
    background: color-mix(in oklab, var(--lp-canvas-raised) 78%, transparent);
    backdrop-filter: blur(16px) saturate(1.1);
    border-bottom: 1px solid var(--lp-rule-2);
}

header.site a.home {
    color: var(--lp-ink);
    text-decoration: none;
}

/* The site's wordmark: Structure's mark and name lead, the tool's name follows, smaller. */
header.site a.home {
    display: inline-flex;
    align-items: center;
    gap: var(--lp-wordmark-gap);
    font: var(--lp-type-wordmark);
    letter-spacing: var(--lp-tracking-wordmark);
    color: var(--lp-ink);
}

header.site a.home svg {
    height: var(--lp-wordmark-mark);
    width: auto;
}

/* The tool's name after Structure's, smaller and quieter, as a product's name follows its maker's. */
header.site a.home .tool {
    font-size: 0.72em;
    font-weight: 500;
    letter-spacing: 0;
    color: var(--lp-ink-3);
}

/* Shown by its script only: the site's icon button sets a display, which `hidden` alone would lose to. */
header.site [data-theme-toggle][hidden] {
    display: none;
}

main {
    max-width: calc(var(--guide-measure) + 2 * var(--lp-gutter));
    margin: 0 auto;
    padding: clamp(40px, 6vw, 80px) var(--lp-gutter) clamp(56px, 8vw, 112px);
}

/*
 * An article's page: the article and, beside it, the guide's sidebar listing every article. The
 * sidebar stays in view while the article scrolls and scrolls on its own when the list is taller
 * than the window. Its width holds the longest titles on two lines at the site's small copy.
 */
.guide-page {
    --guide-nav-width: 16rem;
    /* Between the sidebar and the article, once the sidebar sits beside it. */
    --guide-gap: clamp(24px, 3vw, 48px);
}

nav.guide-nav {
    font: 400 14px/1.4 var(--lp-font-sans);
}

nav.guide-nav section + section {
    margin-top: 20px;
}

nav.guide-nav h2 {
    margin: 0 0 6px;
}

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

/* Each title in the ink's second step, on a hairline that the article shown turns to the ink. */
nav.guide-nav a {
    display: block;
    padding-block: 4px;
    padding-inline: 12px 0;
    border-inline-start: 1px solid var(--lp-rule);
    color: var(--lp-ink-2);
    text-decoration: none;
}

nav.guide-nav a:hover {
    color: var(--lp-ink);
    border-inline-start-color: var(--lp-rule-strong);
}

nav.guide-nav a[aria-current="page"] {
    color: var(--lp-ink);
    font-weight: 500;
    border-inline-start-color: var(--lp-ink);
}

/* The search, and on a narrow screen the Close button beside it. */
nav.guide-nav .guide-nav-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 20px;
}

nav.guide-nav .guide-search {
    flex: 1;
}

/*
 * The count of the query's marks in the article, then Highlight, pressed while they show, and
 * the steps from mark to mark: one row under the field, as close to it as the field's own row
 * is to the list. The count takes the room the buttons leave, so a count of another width
 * moves no button.
 */
nav.guide-nav .guide-search-marks {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: -12px 0 20px;
}

nav.guide-nav .guide-search-count {
    flex: 1;
    min-width: 0;
    font: var(--lp-type-small);
    font-variant-numeric: tabular-nums;
    color: var(--lp-ink-2);
    white-space: nowrap;
}

nav.guide-nav .guide-search-marks [aria-pressed="true"] {
    background: var(--lp-ink);
    border-color: var(--lp-ink);
    color: var(--lp-canvas);
}

/*
 * What the search finds, in the sidebar and on the home page, in rows of the sidebar's list's
 * shape: an article's title, then, for one found by its text, its sections indented under it,
 * each its heading over the words around the match. Matched words in the ink, a row the keys
 * reach outlined as the field is.
 */
[data-guide-search] .guide-search-results > li + li {
    margin-top: 4px;
}

nav.guide-nav a.guide-search-section {
    padding-inline-start: 24px;
}

[data-guide-search] .guide-search-heading {
    display: block;
}

[data-guide-search] .guide-search-snippet {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    font: var(--lp-type-small);
    color: var(--lp-ink-3);
    overflow-wrap: anywhere;
}

[data-guide-search] .guide-search-results mark {
    background: none;
    color: var(--lp-ink);
    font-weight: 600;
}

[data-guide-search] .guide-search-results a:focus-visible {
    outline: 1px solid var(--lp-ink);
    outline-offset: -1px;
    color: var(--lp-ink);
}

nav.guide-nav [hidden],
main.home [data-guide-search] [hidden] {
    display: none;
}

[data-guide-search] .guide-search-none {
    margin: 0;
    color: var(--lp-ink-3);
}

@media (min-width: 64rem) {
    .guide-page {
        display: grid;
        grid-template-columns: var(--guide-nav-width) minmax(0, 1fr);
        column-gap: var(--guide-gap);
        max-width: var(--lp-container);
        margin: 0 auto;
        padding-inline: var(--lp-gutter);
    }

    .guide-page > main {
        grid-column: 2;
        grid-row: 1;
        max-width: var(--guide-measure);
        margin: 0 auto;
        padding-inline: 0;
    }

    nav.guide-nav {
        grid-column: 1;
        grid-row: 1;
        align-self: start;
        position: sticky;
        top: var(--guide-header-height);
        max-height: calc(100vh - var(--guide-header-height));
        overflow-y: auto;
        padding-block: clamp(40px, 6vw, 80px) 32px;
        padding-inline: 0 4px;
    }

    .guide-nav-toggle,
    nav.guide-nav .guide-nav-close {
        display: none;
    }
}

/*
 * On a narrow screen the sidebar waits behind the All articles button over the breadcrumbs and
 * opens over the page, under the header. Without scripts it lists the articles after the article.
 */
@media (max-width: 63.99rem) {
    nav.guide-nav {
        max-width: calc(var(--guide-measure) + 2 * var(--lp-gutter));
        margin: 0 auto;
        padding: 0 var(--lp-gutter) 48px;
    }

    :root[data-guide-nav="closed"] nav.guide-nav {
        display: none;
    }

    :root[data-guide-nav="open"] nav.guide-nav {
        position: fixed;
        inset: var(--guide-header-height) 0 0;
        z-index: 9;
        max-width: none;
        overflow-y: auto;
        padding: 24px var(--lp-gutter) 48px;
        background: var(--lp-canvas);
    }

    .guide-nav-toggle {
        margin: 0 0 20px;
    }
}

.guide-nav-toggle[hidden] {
    display: none;
}

/* A link or inline code with no break in it (a source's URL, a file path) breaks anywhere rather than widening a phone's page. */
main a,
main :not(pre) > code {
    overflow-wrap: anywhere;
}

/* The breadcrumbs: the site's eyebrow, the meta line over an article's title. */
.breadcrumbs ol {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.breadcrumbs li + li::before {
    content: "/";
    margin-inline-end: 8px;
    color: var(--lp-ink-4);
}

.breadcrumbs a {
    color: inherit;
    text-decoration: none;
}

.breadcrumbs a:hover {
    color: var(--lp-ink);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin: 24px 0 32px;
}

.actions [hidden] {
    display: none;
}

/* The home page: copy at the article's size, titles as the site's pages and long documents. */
main.home {
    font: 400 17px/1.7 var(--lp-font-sans);
    color: var(--lp-ink-2);
}

main.home h1,
main > .page-title h1 {
    margin: 0;
    font: 400 clamp(36px, 1rem + 3.4vw, 64px) / 1.08 var(--lp-font-display);
    letter-spacing: -0.03em;
    color: var(--lp-ink);
    text-wrap: balance;
}

main:not(.home) > .page-title h1 {
    font-size: clamp(32px, 1rem + 2.4vw, 52px);
}

/*
 * A page's title with its tools at the row's end (the tool's *Open the app*, the language
 * switcher), and an article's breadcrumbs with the switcher: on a narrow screen the tools wrap
 * under the title.
 */
.page-title,
.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
}

.page-title {
    margin: 0 0 20px;
}

.page-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}

main.home a:not(.lp-button),
main > p a,
footer.site a {
    color: var(--lp-ink);
    text-decoration: underline;
    text-decoration-color: var(--lp-rule-strong);
    text-underline-offset: var(--lp-link-underline-offset);
}

main.home a:not(.lp-button):hover,
main > p a:hover,
footer.site a:hover {
    text-decoration-color: var(--lp-ink);
}

main.home strong {
    color: var(--lp-ink);
    font-weight: 500;
}

main.home p {
    margin: 0 0 16px;
    text-wrap: pretty;
}

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

/* The app on the CME sample (`ToolPicture_html`): the screenshot of the page's theme only. */
.tool-picture {
    display: block;
    margin: 24px 0;
    border: 1px solid var(--lp-rule);
}

.tool-picture picture,
.tool-picture img {
    display: block;
}

.tool-picture img {
    width: 100%;
    height: auto;
}

:root:not([data-st-theme="dark"]) .tool-picture picture[data-theme-picture="dark"],
[data-st-theme="dark"] .tool-picture picture[data-theme-picture="light"] {
    display: none;
}

main.home h2 {
    margin: 48px 0 16px;
    padding-top: 20px;
    border-top: 1px solid var(--lp-rule);
    font: 400 22px/1.3 var(--lp-font-sans);
    letter-spacing: -0.012em;
    color: var(--lp-ink);
}

main.home h3 {
    margin: 40px 0 8px;
}

/* The home page's lists of what the tool does and how to check it: the site's square markers. */
main.home section > ul:not(.articles, .guide-search-results) {
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
}

main.home section > ul:not(.articles, .guide-search-results) li {
    position: relative;
    margin-block: 8px;
    padding-inline-start: 20px;
}

main.home section > ul:not(.articles, .guide-search-results) li::before {
    content: "";
    position: absolute;
    top: 0.7em;
    inset-inline-start: 2px;
    width: 5px;
    height: 5px;
    background: var(--lp-ink-3);
}

/* The articles: one per row between hairlines, its title in the ink, its summary under it. */
ul.articles {
    list-style: none;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--lp-rule);
}

ul.articles li {
    padding: 14px 0;
    border-bottom: 1px solid var(--lp-rule);
}

ul.articles li[hidden] {
    display: none;
}

main ul.articles a {
    font: 500 17px/1.4 var(--lp-font-sans);
    letter-spacing: -0.01em;
    color: var(--lp-ink);
    text-decoration: none;
}

main ul.articles a:hover {
    text-decoration: underline;
    text-decoration-color: var(--lp-rule-strong);
}

ul.articles p {
    margin: 4px 0 0;
    font: 400 15px/1.5 var(--lp-font-sans);
    color: var(--lp-ink-2);
}

.section-description {
    color: var(--lp-ink-2);
    margin: 0 0 16px;
}

/* The home page's sections, as a row of the site's eyebrow links that wraps on a narrow screen. */
nav.sections ul {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    list-style: none;
    margin: 24px 0 0;
    padding: 0;
}

main.home nav.sections a {
    font: var(--lp-type-eyebrow);
    letter-spacing: var(--lp-tracking-eyebrow);
    text-transform: uppercase;
    color: var(--lp-ink-2);
    text-decoration: none;
}

main.home nav.sections a:hover {
    color: var(--lp-ink);
}

/*
 * The home page's search over its articles: the sidebar's field and rows, at the page's width
 * and the type of its list of articles.
 */
main.home form.guide-search {
    margin: 24px 0 0;
}

main.home .guide-search-results,
main.home .guide-search-results ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

main.home .guide-search-results,
main.home .guide-search-none {
    margin-top: 24px;
}

main.home .guide-search-results a {
    display: block;
    padding-block: 6px;
    padding-inline: 12px 0;
    border-inline-start: 1px solid var(--lp-rule);
    font: 500 17px/1.4 var(--lp-font-sans);
    letter-spacing: -0.01em;
    color: var(--lp-ink);
    text-decoration: none;
}

main.home .guide-search-results a.guide-search-section {
    padding-inline-start: 24px;
    font: 400 15px/1.5 var(--lp-font-sans);
    letter-spacing: normal;
    color: var(--lp-ink-2);
}

main.home .guide-search-results a:hover {
    border-inline-start-color: var(--lp-rule-strong);
}

/* Under the page: the guide's name and who made it, then, on a page that sends, what it sends. */
footer.site {
    max-width: calc(var(--guide-measure) + 2 * var(--lp-gutter));
    margin: 0 auto;
    padding: 24px var(--lp-gutter) 48px;
    border-top: 1px solid var(--lp-rule);
    font: var(--lp-type-small);
    color: var(--lp-ink-3);
}

footer.site p {
    margin: 0 0 8px;
}

/* The script shows it only on a page that sends. */
div.usage[hidden] {
    display: none;
}

/*
 * A button inside the footer's line of small text (Review) is the site's button at the line's own
 * size: the text's font, one line high, a hairline and a little padding, so it sits on the line
 * with the words instead of a 32 px control standing over them.
 */
div.usage > p .lp-button {
    height: 1lh;
    margin-inline-start: 8px;
    padding: 0 8px;
    font: inherit;
    color: var(--lp-ink);
    vertical-align: baseline;
}

/* The 404 page's search: shown by its script, the label as the site's form labels over the site's field. */
form.not-found-search {
    display: grid;
    gap: 8px;
    margin: 24px 0;
}

form.not-found-search label {
    font: var(--lp-type-label);
    color: var(--lp-ink);
}

form.not-found-search[hidden] {
    display: none;
}

/* A search field and, at its right, the `/` key that focuses it, gone while the field has the focus or text. */
.search-field {
    position: relative;
    display: block;
}

.search-field .site-input {
    padding-right: 36px;
}

.search-field .search-key {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    padding: 0 6px;
    border: 1px solid var(--lp-rule-strong);
    color: var(--lp-ink-3);
    font: 500 11px/18px var(--lp-font-mono);
    pointer-events: none;
}

.search-field .site-input:focus + .search-key,
.search-field .site-input:not(:placeholder-shown) + .search-key {
    display: none;
}

/* What the pages send and the choice, over the page; small and centered, as the site's overlays. */
dialog.usage {
    max-width: min(32rem, 100vw - 2 * var(--lp-gutter));
    padding: 24px;
    background: var(--lp-canvas-raised);
    color: var(--lp-ink-2);
    border: 1px solid var(--lp-rule-2);
    box-shadow: var(--lp-overlay-shadow);
    font: 400 15px/1.5 var(--lp-font-sans);
}

dialog.usage::backdrop {
    background: color-mix(in srgb, var(--lp-inverse-canvas) 40%, transparent);
}

dialog.usage h2 {
    margin: 0 0 12px;
    font: 400 22px/1.3 var(--lp-font-sans);
    letter-spacing: -0.012em;
    color: var(--lp-ink);
}

dialog.usage p {
    margin: 0 0 12px;
}

dialog.usage .choices {
    display: flex;
    gap: 8px;
}

/* The choice in effect: the site's primary button. */
dialog.usage button[aria-pressed="true"] {
    color: var(--lp-canvas);
    background: var(--lp-ink);
    border-color: var(--lp-ink);
}

dialog.usage .close {
    display: flex;
    justify-content: flex-end;
    margin: 0;
}

/* A draft: a notice in the well inside a hairline, as the site's notices. */
.draft {
    margin: 0 0 24px;
    padding: 12px 14px;
    color: var(--lp-ink-2);
    background: var(--lp-well);
    border: 1px solid var(--lp-rule-2);
    font: var(--lp-type-alert);
}

/* A draft's mark beside its title in a list: a small mono tag in a hairline. */
.badge {
    display: inline-block;
    margin-inline-start: 8px;
    padding: 0 6px;
    border: 1px solid var(--lp-rule-strong);
    color: var(--lp-ink-2);
    font: 500 10px/18px var(--lp-font-mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    vertical-align: 2px;
}

/* Letters of Arabic join, so they take no tracking; Arabic and Chinese have no italics. */
:root:lang(ar) {
    --lp-tracking-title: 0;
    --lp-tracking-button: 0;
    --lp-tracking-eyebrow: 0;
}

:lang(ar) :is(main > .page-title h1, main.home h2, main ul.articles a, main.home .guide-search-results a, dialog.usage h2, .lp-eyebrow, .lp-button) {
    letter-spacing: 0;
}

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

/*
 * The protocol directory's and the files table's rows read best wider than the reading column:
 * on a screen with room, the table takes up to one and a half times the column's width, centred
 * on it, but never more than the room the article has: the window less its gutters, and less
 * the sidebar and its gap once the sidebar sits beside the article. The reading column is
 * centred in that room, so a table centred on the column stays inside it.
 */
main figure.directory,
main figure.sources {
    --guide-room: calc(100vw - 2 * var(--lp-gutter));
    --guide-wide: min(var(--guide-room), 1.5 * var(--guide-measure));
}

@media (min-width: 64rem) {
    main figure.directory,
    main figure.sources {
        --guide-room: calc(
            min(100vw, var(--lp-container)) - 2 * var(--lp-gutter) - var(--guide-nav-width) - var(--guide-gap)
        );
    }
}

@media (min-width: 70rem) {
    main figure.directory,
    main figure.sources {
        width: var(--guide-wide);
        margin-inline: calc((100% - var(--guide-wide)) / 2);
    }
}

/* The focused field's border of a filtered table's Filter row, the app's focus colour (`styles.css`). */
main figure[data-filter-fields] {
    --pv-card-focus: var(--pv-series-1);
}

/*
 * Chinese and Arabic pages in the system's fonts: Geist has neither script, and no CJK or Arabic
 * web font is downloaded. Geist stays first, so Latin names keep it; set on the body, so code
 * keeps its own font. The switcher names each language in its own script.
 */
:root:lang(zh) body,
.language-switch [lang|="zh"] {
    font-family: Geist, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

:root:lang(ar) body,
.language-switch [lang|="ar"] {
    font-family: Geist, "Geeza Pro", "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif;
}

/* The page's language switcher: a menu of the same page in each language, without scripts. */
.language-switch {
    position: relative;
}

.language-switch > summary {
    cursor: pointer;
    list-style: none;
}

.language-switch > summary::-webkit-details-marker {
    display: none;
}

.language-switch > ul {
    position: absolute;
    inset-inline-end: 0;
    z-index: 10;
    margin: 4px 0 0;
    padding: 4px 0;
    list-style: none;
    background: var(--st-background, Canvas);
    border: 1px solid var(--st-border, GrayText);
    border-radius: 6px;
    min-width: 10em;
}

.language-switch a {
    display: block;
    padding: 4px 12px;
    text-decoration: none;
    color: inherit;
}

.language-switch a[aria-current="true"] {
    font-weight: 600;
}

/* The notes over a page whose text is not yet a reviewed translation of the English original. */
.language-note,
.translation-note {
    margin: 0 0 16px;
    padding: 8px 12px;
    border-inline-start: 3px solid var(--pv-series-1, currentColor);
    font-size: 0.9em;
}
