:root {
    --background-color: #fff;
    --background-color-2: #f6f7f9;
    --background-color-3: hsl(240, 4%, 88%);
    --text-color: #23272f;
    --text-color-subtle: hsl(225, 8%, 46%);
    --blue: hsl(216, 74%, 46%);
    --accent-strong: hsl(216, 74%, 42%);
    --accent-strong-hover: hsl(216, 74%, 36%);
    --on-accent-strong: #fff;
    --string-color: #008000;
    --number-color: #a31515;
    --error-text: #c81e1e;
    --error-background-color: #fdd;
    --warning-background-color: #ffd;
    --radius-sm: 6px;
    --radius-md: 10px;
    --shadow-sm: 0 1px 2px rgba(20, 24, 33, 0.06);
    --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Droid Sans", "Helvetica Neue", Arial, sans-serif;
    --mono: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --background-color: hsl(220, 6%, 9%);
        --background-color-2: hsla(0, 0%, 100%, 0.04);
        --background-color-3: hsla(0, 0%, 100%, 0.12);
        --text-color: #e4e7ec;
        --text-color-subtle: hsla(230, 15%, 80%, 0.6);
        --blue: hsl(213, 70%, 66%);
        --accent-strong: hsl(213, 75%, 66%);
        --accent-strong-hover: hsl(213, 75%, 72%);
        --on-accent-strong: hsl(220, 45%, 12%);
        --string-color: hsl(0, 58%, 72%);
        --number-color: #b5cea8;
        --error-text: #ff7b72;
        --error-background-color: #ff000038;
        --warning-background-color: #ffff0021;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    }
}

* {
    box-sizing: border-box;
}

html {
    background: var(--background-color);
    color: var(--text-color);
}

body {
    position: relative;
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 24px;
    box-sizing: content-box;
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.65;
    display: grid;
    grid-column-gap: 48px;
}

@media screen and (min-width: 768px) {
    body {
        grid-template-columns: minmax(auto, max-content) minmax(0, 1fr);
    }
}

.top-nav + main {
    grid-column: 1 / -1;
}

main {
    margin: 24px 0 96px;
    min-width: 0;
}

::selection {
    background: hsla(216, 74%, 50%, 0.22);
}

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

h1, h2, h3, h4 {
    line-height: 1.3;
    letter-spacing: -0.015em;
    text-wrap: balance;
}

h1 {
    margin-top: 0;
    font-size: 1.9rem;
    letter-spacing: -0.025em;
}

main h2 {
    font-size: 1.35rem;
    margin: 2.2em 0 0.7em;
}

main h3 {
    font-size: 1.12rem;
    margin: 1.8em 0 0.6em;
}

main h4 {
    font-size: 1rem;
    margin: 1.6em 0 0.5em;
}

main h1, main h2, main h3, main h4 {
    scroll-margin-top: 84px;
}

/* API reference: each item's title stays in the left scanning column
   while its signatures and docs indent into a grouped body. */
.std main h2, .std main h3 {
    margin-bottom: 0.35em;
}

.member {
    margin: 0 0 0 1.25em;
}

.member > div.sourceCode, .member > pre, .member > p {
    margin-top: 0.6em;
    margin-bottom: 0.6em;
}

@media (max-width: 560px) {
    .member {
        margin-left: 0.75em;
    }
}

a, a:visited {
    text-decoration: none;
    color: var(--blue);
}

a:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.side-nav a.active {
    font-weight: 650;
    color: var(--text-color);
}

main ul, main ol {
    padding-left: 1.4em;
}

main li + li {
    margin-top: 0.3em;
}

hr {
    border: none;
    border-top: 1px solid var(--background-color-3);
    margin: 2.5em 0;
}

pre, code, .sourceCode {
    font-family: var(--mono);
}

:not(pre) > code {
    font-size: 0.85em;
    background: var(--background-color-2);
    border: 1px solid var(--background-color-3);
    border-radius: 4px;
    padding: 0.15em 0.4em;
    white-space: nowrap;
}

.sourceCode, pre code {
    font-size: 13px;
    line-height: 1.6;
}

/* Pandoc leaves unknown languages (```cx) as a bare pre without the
   div.sourceCode wrapper, so style that form identically. */
div.sourceCode, pre.cx {
    position: relative;
    background: var(--background-color-2);
    border: 1px solid var(--background-color-3);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin: 1.4em 0;
}

/* Static code blocks (reference-only snippets) keep pandoc's syntax
   highlighting instead of the CodeMirror editor. Map its token classes
   to the cx palette so both render identically. */
pre.sourceCode.cs code span.kw,
pre.sourceCode.cs code span.dt {
    color: var(--blue);
    font-weight: normal;
}
pre.sourceCode.cs code span.fu,
pre.sourceCode.cs code span.op {
    color: var(--text-color);
}
pre.sourceCode.cs code span.co {
    color: var(--text-color-subtle);
    font-style: normal;
}
pre.sourceCode.cs code span.dv,
pre.sourceCode.cs code span.fl {
    color: var(--number-color);
}
pre.sourceCode.cs code span.st,
pre.sourceCode.cs code span.ch {
    color: var(--string-color);
}

pre {
    padding: 14px 18px;
}

blockquote {
    margin: 1.6em 0;
    padding: 12px 20px;
    background: var(--background-color-2);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-color);
}

blockquote p {
    margin: 0.6em 0;
}

blockquote p:first-child {
    margin-top: 0;
}

blockquote p:last-child {
    margin-bottom: 0;
}

table {
    display: table;
    width: 100%;
    margin: 1.6em 0;
    border-collapse: collapse;
    font-size: 0.93rem;
}

thead {
    border-bottom: 1px solid var(--background-color-3);
}

tbody {
    margin-top: 0;
    border-top: none;
    border-bottom: 1px solid var(--background-color-3);
}

th, td {
    padding: 8px 12px;
    text-align: left;
    vertical-align: top;
}

tbody td {
    border-top: 1px solid var(--background-color-3);
}

th {
    font-weight: 650;
    border-top: none; /* pandoc puts a dark top border on th by default */
}

.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px 24px;
    flex-wrap: wrap;
    padding: 16px 24px;
    margin: 0 -24px;
    /* Tallest item (the logo) plus padding: the bar keeps this height
       on pages without the search box too. */
    min-height: 64px;
    grid-column: 1 / -1;
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--background-color);
    border-bottom: 1px solid var(--background-color-3);
}

.top-nav h1 {
    font-family: var(--sans);
    font-weight: 800;
    font-size: 2rem;
    letter-spacing: -0.03em;
    line-height: 1;
    margin: 0;
    /* Lowercase glyphs sit below the line box center; nudge up so the
       wordmark looks centered against the nav links. */
    transform: translateY(-0.08em);
}

.top-nav h1 a {
    color: var(--text-color);
    text-decoration: none;
}

.top-nav h1 a:hover {
    text-decoration: none;
}

.links {
    white-space: nowrap;
}

.links a {
    color: var(--text-color);
    font-weight: 500;
    font-size: 0.95rem;
    text-decoration: none;
}

.links a:hover {
    color: var(--blue);
    text-decoration: none;
}

.links a + a {
    margin-left: 20px;
}

.search {
    position: relative;
    flex: 0 1 300px;
    min-width: 120px;
    margin-left: auto;
}

.frontpage .search {
    display: none;
}

#site-search {
    width: 100%;
    font: inherit;
    font-size: 0.9rem;
    /* Single-line input: must not inherit the body prose line-height,
       which would make the search box the tallest nav item. */
    line-height: 1;
    color: var(--text-color);
    background: var(--background-color-2);
    border: 1px solid var(--background-color-3);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
}

#site-search::placeholder {
    color: var(--text-color-subtle);
}

.search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    min-width: 260px;
    max-height: 60vh;
    overflow: auto;
    background: var(--background-color);
    border: 1px solid var(--background-color-3);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    z-index: 60;
}

.search-results[hidden] {
    display: none;
}

.search-results a {
    display: block;
    padding: 8px 12px;
    color: var(--text-color);
}

.search-results a:hover {
    background: var(--background-color-2);
    text-decoration: none;
}

.search-results .result-title {
    font-weight: 600;
    font-size: 0.9rem;
}

.search-results .result-snippet {
    font-size: 0.8rem;
    color: var(--text-color-subtle);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-results mark {
    background: var(--background-color-3);
    color: inherit;
    border-radius: 2px;
}

.search-results .search-empty,
.search-results .search-failure {
    padding: 8px 12px;
    font-size: 0.9rem;
    color: var(--text-color-subtle);
}

@media (max-width: 560px) {
    .search {
        flex-basis: 100%;
        order: 3;
    }
}

.side-nav {
    font-size: 0.9rem;
    line-height: 1.5;
    margin: 24px 0;
}

.side-nav > ul {
    margin: 0;
    padding: 0;
    list-style-type: none;
    display: flex;
    flex-wrap: wrap;
    gap: 2px 18px;
}

.side-nav ul ul {
    margin: 0;
    padding-left: 1em;
    list-style-type: none;
}

.side-nav a {
    color: var(--text-color-subtle);
    padding: 2px 0;
}

.side-nav a:hover {
    color: var(--text-color);
    text-decoration: none;
}

@media screen and (min-width: 768px) {
    .side-nav {
        position: sticky;
        top: 78px;
        align-self: start;
        max-height: calc(100vh - 102px);
        overflow: auto;
        scrollbar-gutter: stable;
        margin: 32px 0 48px;
        padding-right: 8px;
    }

    .side-nav > ul {
        display: block;
    }

    .side-nav a {
        display: block;
        padding: 3px 0;
    }

    main {
        margin-top: 32px;
    }
}

section {
    margin: 30px 0;
}

.intro {
    margin-top: 0;
}

.intro-grid {
    display: grid;
    grid-gap: 32px;
    grid-template-rows: auto auto;
}

@media screen and (min-width: 900px) {
    .intro-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr);
        grid-template-rows: none;
        align-items: start;
    }
}

.intro-grid section,
.intro-grid .sourceCode {
    margin: 0;
}

.intro-grid div.sourceCode {
    margin: 0;
}

.intro h1 {
    font-size: clamp(1.7rem, 1.2rem + 2vw, 2.3rem);
    font-weight: 450;
    line-height: 1.25;
    letter-spacing: -0.02em;
    margin: 8px 0 18px;
}

.intro h1 strong {
    font-weight: 750;
}

.intro p {
    font-size: 1.03rem;
    line-height: 1.7;
    max-width: 58ch;
    margin: 0;
}

.intro .CodeMirror-scroll {
    max-height: 400px;
}

.features {
    display: grid;
    grid-template-columns: 1fr;
    grid-gap: 28px;
    margin: 56px 0;
}

.features .block {
    border-top: 1px solid var(--background-color-3);
    padding-top: 18px;
    font-size: 0.94rem;
    line-height: 1.65;
}

.features h2 {
    color: var(--text-color);
    font-size: 1.05rem;
    font-weight: 650;
    letter-spacing: -0.01em;
    margin: 0 0 8px;
}

.features .block p {
    margin: 0;
}

.features .block p + p {
    margin-top: 0.7em;
}

@media screen and (min-width: 768px) {
    .features {
        grid-template-columns: 1fr 1fr 1fr;
    }

    /* On desktop the columns stand on their own; the top rules only serve
       as delimiters in the stacked mobile layout. */
    .features .block {
        border-top: none;
        padding-top: 0;
    }
}

.block {
    margin: 0;
}

.block.wide {
    grid-column: 1 / -1;
}

button, a.button {
    border: 1px solid var(--background-color-3);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-color);
    padding: 9px 18px;
    cursor: pointer;
    font: inherit;
    font-size: 0.95rem;
    font-weight: 550;
    line-height: 1.4;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

a.button {
    display: inline-block;
    text-decoration: none;
}

a.button:hover, button:hover {
    background: var(--background-color-2);
    border-color: var(--text-color-subtle);
    text-decoration: none;
}

.button.primary {
    background: var(--accent-strong);
    border-color: transparent;
    color: var(--on-accent-strong);
}

.button.primary:hover {
    background: var(--accent-strong-hover);
    border-color: transparent;
    color: var(--on-accent-strong);
}

.editor {
    overflow: auto;
    tab-size: 4;
}

#example-selector {
    display: block;
    margin-bottom: 12px;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-color);
    background: var(--background-color) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="6"><path d="M1 1l4 4 4-4" stroke="%23888" stroke-width="1.5" fill="none" stroke-linecap="round"/></svg>') no-repeat right 10px center;
    border: 1px solid var(--background-color-3);
    border-radius: var(--radius-sm);
    padding: 6px 30px 6px 10px;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    max-width: 100%;
}

#example-selector:hover {
    border-color: var(--text-color-subtle);
}

#example-selector option {
    padding: 2px 8px;
}

.CodeMirror {
    font-family: inherit;
    background: transparent !important;
    color: var(--text-color);
    height: auto;
    width: 100%;
    font-size: 13px;
    line-height: 1.6;
}

.CodeMirror-lines {
    padding: 12px 0 !important;
}

.CodeMirror-line,
.CodeMirror-linewidget .diagnostic {
    padding: 0 18px !important;
}

.diagnostic {
    color: var(--text-color);
    padding: 0 4px;
    white-space: pre-wrap;
    font-family: var(--mono);
    /* Inherits the code size: the caret column only lines up when the
       indent advances match the code lines exactly. */
    font-size: inherit;
}

.diagnostic.error {
    background-color: var(--error-background-color);
}

.diagnostic.warning {
    background-color: var(--warning-background-color);
}

button.run {
    position: absolute;
    right: 14px;
    top: 10px;
    z-index: 10;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    width: 32px;
    height: 32px;
}

button.run::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--background-color-3);
    background-image: url("lib/play-button.svg");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    transition: transform 0.15s ease, filter 0.15s ease;
}

button.run:hover {
    background: transparent;
    border: none;
}

button.run:hover::before {
    filter: brightness(0.94);
}

button.run:active::before {
    transform: scale(0.9);
}

.output {
    display: none;
    width: 100%;
    padding: 12px 18px;
    border-top: 1px solid var(--background-color-3);
    white-space: pre-wrap;
    overflow: auto;
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.6;
}

.stderr {
    color: var(--error-text);
}

.bottom-links {
    margin: 56px auto 24px;
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.bottom-links a {
    width: fit-content;
}

.site-footer {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    gap: 8px 24px;
    flex-wrap: wrap;
    border-top: 1px solid var(--background-color-3);
    padding: 22px 0 48px;
    font-size: 13px;
    color: var(--text-color-subtle);
}

.page-links {
    white-space: nowrap;
}

.page-links a + a {
    margin-left: 16px;
}

.next-page {
    margin: 0 0 48px;
    text-align: right;
}

@media screen and (min-width: 768px) {
    .next-page {
        grid-column: 2;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition: none !important;
    }
}
