/* Paulblish — Cyberpunk Brutalist Theme */

/* === Palette === */
:root {
    --bg: #0a0a0f;
    --surface: #14141f;
    --text: #b8b8c0;
    --text-bright: #e0dfd5;
    --accent-teal: #5e9e91;
    --accent-amber: #b89c4a;
    --accent-rose: #7a3b4e;
    --border: #2a2a35;
    --highlight: #1a2a28;
    --font-heading: "JetBrains Mono", "Fira Code", "Courier New", monospace;
    --font-body: "Inter", "system-ui", sans-serif;
}

/* === Reset === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* === Base === */
html {
    font-size: 17px;
    line-height: 1.65;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* === Typography === */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-heading);
    color: var(--text-bright);
    line-height: 1.3;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

h1 {
    font-size: 1.8rem;
}
h2 {
    font-size: 1.4rem;
}
h3 {
    font-size: 1.15rem;
}

p {
    margin-bottom: 1em;
}

/* === Links === */
a {
    color: var(--accent-teal);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

a:visited {
    color: #4e8a7e;
}

/* === Dead wikilinks === */
.wikilink-dead {
    color: var(--accent-rose);
    text-decoration: underline;
    text-decoration-style: dashed;
}

/* === Navigation === */
.site-nav {
    font-family: var(--font-heading);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.site-nav a {
    color: var(--text);
    font-size: 0.9rem;
}

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

.site-nav .nav-title {
    color: var(--text-bright);
    font-size: 1rem;
    font-weight: bold;
}

/* === Article metadata === */
.article-meta {
    border-bottom: 1px solid var(--border);
    padding-bottom: 1.5rem;
    margin-bottom: 2rem;
}

.article-meta h1 {
    margin-top: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.copy-url-btn {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: #fff;
    opacity: 0.35;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.copy-url-btn:hover,
.copy-url-btn.copied {
    opacity: 0.9;
}

.article-meta time {
    display: block;
    font-family: var(--font-heading);
    font-size: 0.85rem;
    color: var(--text);
    margin-top: 0.25rem;
}

.reading-time {
    display: inline-block;
    font-family: var(--font-heading);
    font-size: 0.85rem;
    color: var(--text);
    margin-left: 0.75rem;
}

.article-meta .description {
    margin-top: 0.75rem;
    font-style: italic;
    color: var(--text);
}

/* === Tags === */
.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.tag {
    font-family: var(--font-heading);
    font-size: 0.75rem;
    color: var(--accent-amber);
    border: 1px solid var(--accent-amber);
    padding: 0.15em 0.5em;
    text-decoration: none;
}

.tag:hover {
    background: var(--highlight);
    text-decoration: none;
}

.tag:visited {
    color: var(--accent-amber);
}

/* === Article body === */
.article-body {
    line-height: 1.7;
}

.article-body h2,
.article-body h3,
.article-body h4 {
    margin-top: 2em;
}

.article-body ul,
.article-body ol {
    padding-left: 1.5em;
    margin-bottom: 1em;
}

.article-body li {
    margin-bottom: 0.25em;
}

.article-body blockquote {
    border-left: 3px solid var(--accent-teal);
    padding-left: 1em;
    margin: 1em 0;
    color: var(--text);
    background: var(--surface);
    padding: 0.75em 1em;
}

.article-body img {
    max-width: 100%;
    height: auto;
}

.article-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
}

.article-body th,
.article-body td {
    border: 1px solid var(--border);
    padding: 0.5em 0.75em;
    text-align: left;
}

.article-body th {
    background: var(--surface);
    color: var(--text-bright);
    font-family: var(--font-heading);
    font-size: 0.85rem;
}

/* === Inline code === */
code {
    font-family: var(--font-heading);
    font-size: 0.9em;
    background: var(--surface);
    padding: 0.15em 0.35em;
}

/* Plain pre/code blocks (no language specified) */
pre {
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 1em;
    overflow-x: auto;
    margin: 1.5rem 0;
}

pre code {
    background: none;
    padding: 0;
}

/* === Diagrams (Pele renders ```mermaid blocks into div.diagram) === */
/* Pele reads these variables live, so diagrams follow the site palette without re-rendering. */
.diagram {
    --pele-bg: var(--bg);
    --pele-fg: var(--text-bright);
    --pele-muted: var(--text);
    --pele-line: var(--text);
    --pele-surface: var(--surface);
    --pele-surface-alt: var(--highlight);
    --pele-border: var(--accent-teal);
    --pele-accent: var(--accent-amber);
    --pele-critical: var(--accent-rose);
    --pele-font: var(--font-heading);
    --pele-font-mono: var(--font-heading);
    --pele-radius: 0;
    /* Pele's zoom buttons default to a column over the top-right corner, which covers the end of
       wide LR diagrams. Put them in a row in a strip under the diagram instead. */
    --pele-zoom-top: auto;
    --pele-zoom-bottom: 0;
    --pele-zoom-right: 0;
    margin: 1.5rem 0;
}

.diagram:has(.pele-zoom) {
    padding-bottom: 2.5rem;
}

/* Pele sets flex-direction inline, so this needs !important to win. */
.diagram .pele-zoom {
    flex-direction: row !important;
}

/* === Fenced code block wrapper (language-highlighted blocks) === */
.code-block {
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    margin: 1.5rem 0;
    background: var(--surface);
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0.75rem;
    background: color-mix(in srgb, var(--surface) 50%, var(--border));
    border-bottom: 1px solid var(--border);
    font-family: var(--font-heading);
    font-size: 0.75rem;
}

.code-lang {
    color: var(--text);
    opacity: 0.6;
}

.code-copy-btn {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: #fff;
    opacity: 0.35;
    transition: opacity 0.15s;
}

.code-copy-btn:hover,
.code-copy-btn.copied {
    opacity: 0.9;
}

/* Pygments .highlight inside .code-block — wrapper handles border/bg */
.code-block .highlight {
    background: none;
    border: none;
    padding: 1em;
    overflow-x: auto;
    margin: 0;
}

.code-block .highlight pre {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    border-radius: 0;
}

/* === Line numbers (Pygments linenos="table") === */
.highlighttable {
    width: 100%;
    border-collapse: collapse;
}

.highlighttable .linenos {
    user-select: none;
    padding: 1em 0.75em 1em 1em;
    text-align: right;
    vertical-align: top;
    border-right: 1px solid var(--border);
    width: 1%;
    white-space: nowrap;
}

.highlighttable .linenos .linenodiv pre {
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    color: var(--text);
    opacity: 0.35;
}

.highlighttable .code {
    padding: 0;
    width: 100%;
}

.highlighttable .code .highlight {
    padding: 1em;
}

/* === Pygments token colours (CP2077-aligned) === */
.highlight .k,
.highlight .kn,
.highlight .kd,
.highlight .kc {
    color: var(--accent-teal);
} /* keywords */
.highlight .s,
.highlight .s1,
.highlight .s2,
.highlight .sa {
    color: var(--accent-amber);
} /* strings */
.highlight .c,
.highlight .c1,
.highlight .cm {
    color: #555566;
    font-style: italic;
} /* comments */
.highlight .n {
    color: var(--text);
} /* names */
.highlight .nf,
.highlight .nb {
    color: var(--text-bright);
} /* functions, builtins */
.highlight .o,
.highlight .p {
    color: var(--text);
} /* operators, punctuation */
.highlight .mi,
.highlight .mf {
    color: var(--accent-rose);
} /* numbers */
.highlight .nn {
    color: var(--accent-teal);
} /* module names */

/* === Home page === */
.ascii-banner {
    font-family: var(--font-heading);
    color: var(--accent-teal);
    font-size: 1rem;
    line-height: 1.2;
    margin-bottom: 1.5rem;
    background: none;
    border: none;
    padding: 0;
}

.home-avatar {
    margin-bottom: 1.5rem;
}

.home-avatar .avatar {
    width: 120px;
    height: 120px;
    border: 1px solid var(--accent-teal);
    display: block;
}

/* === Listings === */
.listing h1 {
    margin-top: 0;
}

.listing h2 {
    font-size: 1rem;
    color: var(--text);
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

.article-list {
    list-style: none;
    padding: 0;
}

.article-list li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.4em 0;
    border-bottom: 1px solid var(--border);
}

.article-list time {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    color: var(--text);
    white-space: nowrap;
    margin-left: 1rem;
}

/* === Article prev/next nav === */
.article-nav {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    margin-top: 2rem;
}

.article-nav-prev,
.article-nav-next {
    flex: 1;
}

.article-nav-next {
    text-align: right;
}

/* === Recent posts (home page) === */
.recent-posts {
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    margin-bottom: 2rem;
}

.recent-posts h2 {
    margin-top: 0;
}

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

.recent-posts li {
    margin-bottom: 0.4rem;
}

/* === Social icons === */
.social-icons {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.site-nav .social-icons {
    margin-left: auto;
}

.social-icon {
    color: var(--text);
    display: flex;
    align-items: center;
    line-height: 1;
}

.social-icon:hover {
    color: var(--accent-teal);
    text-decoration: none;
}

.social-icon svg {
    display: block;
}

/* === Mobile nav === */
.nav-toggle-input {
    display: none;
}

.nav-toggle-label {
    display: none;
    cursor: pointer;
    color: var(--text);
    line-height: 1;
    align-items: center;
}

.nav-toggle-label:hover {
    color: var(--accent-teal);
}

@media (max-width: 640px) {
    .site-nav {
        flex-wrap: wrap;
    }

    .nav-links {
        display: none;
        order: 10;
        width: 100%;
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.75rem 0;
        border-top: 1px solid var(--border);
    }

    .nav-toggle-input:checked ~ .nav-links {
        display: flex;
    }

    .nav-toggle-label {
        display: flex;
    }
}

.site-footer .social-icons {
    justify-content: center;
    margin-top: 0.5rem;
}

/* === Footer === */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 1rem 1.5rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text);
    font-family: var(--font-heading);
}

.site-footer a {
    color: var(--accent-teal);
}

.footer-links {
    margin-top: 0.4rem;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

/* === Callouts === */
.callout {
    border-left: 4px solid var(--accent-teal);
    background: color-mix(in srgb, var(--accent-teal) 8%, var(--surface));
    border-radius: 0 4px 4px 0;
    margin: 1.5rem 0;
    padding: 0;
    overflow: hidden;
}

.callout-title {
    padding: 0.5rem 1rem;
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: color-mix(in srgb, var(--accent-teal) 15%, var(--surface));
    color: var(--accent-teal);
}

.callout-body {
    padding: 0.75rem 1rem;
}

.callout-body p:first-child {
    margin-top: 0;
}
.callout-body p:last-child {
    margin-bottom: 0;
}

.callout-warning {
    border-left-color: #f0c040;
}
.callout-warning .callout-title {
    background: color-mix(in srgb, #f0c040 15%, var(--surface));
    color: #f0c040;
}

.callout-danger,
.callout-caution {
    border-left-color: var(--accent-pink);
}
.callout-danger .callout-title,
.callout-caution .callout-title {
    background: color-mix(in srgb, var(--accent-pink) 15%, var(--surface));
    color: var(--accent-pink);
}

.callout-tip,
.callout-success {
    border-left-color: #6bcb77;
}
.callout-tip .callout-title,
.callout-success .callout-title {
    background: color-mix(in srgb, #6bcb77 15%, var(--surface));
    color: #6bcb77;
}

/* === Collapsible callouts === */
.callout-collapsible details {
    /* reset browser default padding/margin on details */
    margin: 0;
}

.callout-collapsible summary.callout-title {
    cursor: pointer;
    user-select: none;
    list-style: none; /* Firefox */
    display: flex;
    align-items: center;
    gap: 0.4em;
}

/* Remove the default disclosure triangle in all browsers */
.callout-collapsible summary.callout-title::-webkit-details-marker {
    display: none;
}
.callout-collapsible summary.callout-title::marker {
    display: none;
}

/* Chevron icon — rotates when open */
.callout-fold {
    display: inline-block;
    width: 0.6em;
    height: 0.6em;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg); /* points right (collapsed) */
    transition: transform 0.2s ease;
    flex-shrink: 0;
    margin-top: 1px; /* optical alignment */
}

.callout-collapsible details[open] .callout-fold {
    transform: rotate(45deg); /* points down (expanded) */
}

/* === Highlights === */
mark {
    background: color-mix(in srgb, #f0c040 35%, transparent);
    color: inherit;
    border-radius: 2px;
    padding: 0 2px;
}

/* === HTML embeds (```html embed): a sketch pad for little tools === */
.html-embed {
    --pad-line: color-mix(in srgb, var(--accent-teal) 10%, transparent);
    --pad-edge: #3a3a48;
    --pad-shadow: color-mix(in srgb, var(--accent-amber) 40%, transparent);
    /* --accent-rose is too dark to read on --bg */
    --pad-error: #d0607a;
    margin: 2rem 0;
    border: 2px solid var(--pad-edge);
    border-radius: 6px;
    background-color: var(--surface);
    /* graph paper */
    background-image:
        linear-gradient(var(--pad-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--pad-line) 1px, transparent 1px);
    background-size: 22px 22px;
    background-position: -1px -1px;
    box-shadow: 6px 6px 0 var(--pad-shadow);
    overflow: hidden;
}

/* Binding strip: label on the left, punched holes filling the rest */
.html-embed-bar {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    min-height: 2.25rem;
    padding: 0 0.75rem;
    background: color-mix(in srgb, var(--surface) 55%, var(--pad-edge));
    border-bottom: 2px solid var(--pad-edge);
}

.html-embed-bar::after {
    content: "";
    flex: 1;
    /* "space" only ever draws whole holes, so none get clipped at the edges */
    background: radial-gradient(circle, var(--bg) 0 4px, transparent 5px) 0 50% / 26px 100% space no-repeat;
}

.html-embed-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-heading);
    font-size: 0.8rem;
    color: var(--accent-amber);
}

.html-embed-label::before {
    content: "✎";
}

.html-embed-body {
    display: flow-root;
    padding: 1.25rem 1.5rem 1.5rem;
}

/*
 * Base styles for whatever the author puts in the pad. :where() keeps specificity at
 * zero so any class or id selector in the embed's own <style> wins without a fight.
 */
.html-embed-body :where(h2, h3, h4):first-child {
    margin-top: 0;
}

.html-embed-body :where(p):last-child,
.html-embed-body :where(form, div) > :where(p):last-child {
    margin-bottom: 0;
}

.html-embed-body :where(label) {
    display: block;
    margin: 1rem 0 0.4rem;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: var(--text-bright);
}

.html-embed-body
    :where(
        input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="button"], [type="submit"], [type="reset"]),
        select,
        textarea
    ) {
    display: block;
    width: 100%;
    max-width: 22rem;
    min-height: 3.25rem;
    margin: 0.4rem 0;
    padding: 0.6rem 0.9rem;
    font-family: var(--font-heading);
    font-size: 1.15rem; /* >= 16px so iOS doesn't zoom on focus */
    color: var(--text-bright);
    background: var(--bg);
    border: 2px solid var(--pad-edge);
    border-radius: 4px;
}

.html-embed-body :where(input, select, textarea)::placeholder {
    color: var(--text);
    opacity: 0.55;
}

.html-embed-body :where(input, select, textarea):focus-visible {
    outline: 3px solid var(--accent-amber);
    outline-offset: 2px;
    border-color: var(--accent-amber);
}

.html-embed-body :where(input[type="checkbox"], input[type="radio"]) {
    width: 1.4rem;
    height: 1.4rem;
    accent-color: var(--accent-amber);
    vertical-align: middle;
}

/* --value (0-100) is kept in sync by the tools helper in _tools.html */
.html-embed-body :where(input[type="range"]) {
    appearance: none;
    display: block;
    width: 100%;
    max-width: 22rem;
    height: 2.5rem;
    margin: 0.4rem 0;
    background: transparent;
    cursor: pointer;
}

/* Vendor pseudo-elements can't share a rule: one unknown selector drops the whole rule */
.html-embed-body :where(input[type="range"])::-webkit-slider-runnable-track {
    height: 0.75rem;
    border-radius: 2px;
    background: linear-gradient(to right, var(--accent-amber) calc(var(--value, 0) * 1%), var(--bg) 0);
    box-shadow: inset 0 0 0 2px var(--pad-edge);
}

.html-embed-body :where(input[type="range"])::-moz-range-track {
    height: 0.75rem;
    border-radius: 2px;
    background: linear-gradient(to right, var(--accent-amber) calc(var(--value, 0) * 1%), var(--bg) 0);
    box-shadow: inset 0 0 0 2px var(--pad-edge);
}

.html-embed-body :where(input[type="range"])::-webkit-slider-thumb {
    appearance: none;
    width: 1.25rem;
    height: 2rem;
    margin-top: -0.625rem;
    background: var(--accent-amber);
    border: 2px solid var(--bg);
    border-radius: 2px;
    box-shadow: 3px 3px 0 var(--accent-rose);
}

.html-embed-body :where(input[type="range"])::-moz-range-thumb {
    width: 1.25rem;
    height: 2rem;
    background: var(--accent-amber);
    border: 2px solid var(--bg);
    border-radius: 2px;
    box-shadow: 3px 3px 0 var(--accent-rose);
}

.html-embed-body :where(button, input[type="button"], input[type="submit"], input[type="reset"]) {
    min-height: 3.25rem;
    min-width: 10rem;
    margin: 1rem 0.5rem 1rem 0;
    padding: 0.75rem 1.5rem;
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: bold;
    color: var(--bg);
    background: var(--accent-amber);
    border: 2px solid var(--accent-amber);
    border-radius: 4px;
    box-shadow: 4px 4px 0 var(--accent-rose);
    cursor: pointer;
    touch-action: manipulation; /* no double-tap zoom delay */
}

.html-embed-body :where(button, input[type="button"], input[type="submit"], input[type="reset"]):hover {
    filter: brightness(1.1);
}

.html-embed-body :where(button, input[type="button"], input[type="submit"], input[type="reset"]):active {
    transform: translate(3px, 3px);
    box-shadow: 1px 1px 0 var(--accent-rose);
}

.html-embed-body :where(button, input[type="button"], input[type="submit"], input[type="reset"]):focus-visible {
    outline: 3px solid var(--text-bright);
    outline-offset: 3px;
}

@media (prefers-reduced-motion: no-preference) {
    .html-embed-body :where(button, input[type="button"], input[type="submit"], input[type="reset"]) {
        transition:
            transform 0.08s ease-out,
            box-shadow 0.08s ease-out;
    }
}

/* Results: use <output> (screen readers announce changes) or class="result" */
.html-embed-body :where(output, .result) {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--accent-amber);
}

/*
 * Tool widgets. Each needs at most one class. Same zero-specificity rule as above, so a
 * tool's own <style> can restyle any of them.
 */

.html-embed-body :where(small) {
    font-size: 0.85rem;
    color: var(--text);
    opacity: 0.8;
}

/* A <small> on its own line is a hint under a control; inside running text it stays inline */
.html-embed-body :where(:not(p, li, td, th, label, span) > small) {
    display: block;
    margin: 0.25rem 0 0.75rem;
}

.html-embed-body :where(fieldset) {
    margin: 1rem 0;
    padding: 0.75rem 1rem 1rem;
    border: 2px solid var(--pad-edge);
    border-radius: 4px;
}

.html-embed-body :where(legend) {
    padding: 0 0.4rem;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: var(--text-bright);
}

/* Inline labels: <label><input type="checkbox"> Text</label> */
.html-embed-body :where(label:has(> input[type="checkbox"], > input[type="radio"])) {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
}

/* :user-invalid waits for the reader to interact, so untouched required fields aren't red */
.html-embed-body :where(input, select, textarea):user-invalid {
    border-color: var(--pad-error);
}

.html-embed-body :where(.error, input:user-invalid + small) {
    color: var(--pad-error);
    opacity: 1;
}

.html-embed-body :where(input, select, textarea, button):disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.html-embed-body :where(button, input[type="button"], input[type="submit"], input[type="reset"]):disabled {
    filter: none;
    transform: none;
    box-shadow: none;
}

/* .row: controls side by side, e.g. a number and its unit select */
.html-embed-body :where(.row) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    margin: 0.4rem 0;
}

.html-embed-body :where(.row) > :where(*) {
    margin: 0;
}

.html-embed-body :where(.row) > :where(input:not([type="checkbox"], [type="radio"]), select) {
    flex: 1 1 8rem;
    width: auto;
    min-width: 0;
}

/* After an input, a select is a unit picker: keep it to its content width */
.html-embed-body :where(.row) > :where(input + select) {
    flex: none;
}

.html-embed-body :where(.row) > :where(span) {
    font-family: var(--font-heading);
    color: var(--text-bright);
}

/* .fields: label/control pairs in a two-column grid that stacks on phones */
.html-embed-body :where(.fields) {
    display: grid;
    grid-template-columns: minmax(8rem, max-content) minmax(0, 1fr);
    align-items: center;
    gap: 0.75rem 1rem;
    margin: 1rem 0;
}

.html-embed-body :where(.fields) > :where(*) {
    margin: 0;
    max-width: none;
}

/* .panel: a box for results */
.html-embed-body :where(.panel) {
    margin: 1rem 0;
    padding: 0.85rem 1rem;
    background: var(--bg);
    border-left: 4px solid var(--accent-amber);
}

.html-embed-body :where(.panel) > :where(:last-child) {
    margin-bottom: 0;
}

/* .switch: a checkbox drawn as a toggle */
.html-embed-body :where(input.switch) {
    appearance: none;
    position: relative;
    flex: none;
    width: 3.25rem;
    height: 1.75rem;
    margin: 0;
    background: var(--bg);
    border: 2px solid var(--pad-edge);
    border-radius: 2px;
    cursor: pointer;
}

.html-embed-body :where(input.switch)::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 1.25rem;
    height: calc(100% - 4px);
    background: var(--text);
    border-radius: 1px;
}

.html-embed-body :where(input.switch:checked) {
    background: color-mix(in srgb, var(--accent-amber) 25%, var(--bg));
    border-color: var(--accent-amber);
}

.html-embed-body :where(input.switch:checked)::before {
    left: calc(100% - 1.25rem - 2px);
    background: var(--accent-amber);
}

@media (prefers-reduced-motion: no-preference) {
    .html-embed-body :where(input.switch)::before {
        transition: left 0.12s ease-out;
    }
}

/* .segmented: a fieldset of radio labels drawn as a button bar */
.html-embed-body :where(fieldset.segmented) {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    padding: 0;
    border: 0;
}

.html-embed-body :where(fieldset.segmented) > :where(legend) {
    width: 100%;
    margin: 1rem 0 0.4rem;
    padding: 0;
}

.html-embed-body :where(fieldset.segmented) > :where(label) {
    flex: 1 1 auto;
    position: relative;
    display: block;
    margin: 0 0 0 -2px;
    padding: 0.6rem 1rem;
    text-align: center;
    background: var(--bg);
    border: 2px solid var(--pad-edge);
}

.html-embed-body :where(fieldset.segmented) > :where(label:first-of-type) {
    margin-left: 0;
}

.html-embed-body :where(fieldset.segmented) :where(input) {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

/* z-index lifts the highlight over the neighbour it overlaps by 2px */
.html-embed-body :where(fieldset.segmented) > :where(label:has(:checked)) {
    z-index: 1;
    color: var(--bg);
    background: var(--accent-amber);
    border-color: var(--accent-amber);
}

.html-embed-body :where(fieldset.segmented) > :where(label:has(:focus-visible)) {
    z-index: 2;
    outline: 3px solid var(--text-bright);
    outline-offset: 2px;
}

/* .knob: a range input the tools helper turns into a draggable dial */
.html-embed-body :where(input.knob) {
    appearance: none;
    display: block;
    width: 7rem;
    height: 7rem;
    margin: 0.75rem 0;
    border-radius: 50%;
    background:
        radial-gradient(circle closest-side, var(--surface) 0 66%, transparent 67%),
        conic-gradient(
            from 225deg,
            var(--accent-amber) calc(var(--value, 0) * 2.7deg),
            var(--bg) 0 270deg,
            transparent 0
        );
    box-shadow: 0 0 0 2px var(--pad-edge);
    cursor: grab;
    touch-action: none; /* dragging the dial must not scroll the page */
}

/* Hide the slider track/thumb so only the dial shows */
.html-embed-body :where(input.knob)::-webkit-slider-runnable-track {
    background: none;
    box-shadow: none;
}

.html-embed-body :where(input.knob)::-moz-range-track {
    background: none;
    box-shadow: none;
}

.html-embed-body :where(input.knob)::-webkit-slider-thumb {
    opacity: 0;
}

.html-embed-body :where(input.knob)::-moz-range-thumb {
    opacity: 0;
}

.html-embed-body :where(input.knob):active {
    cursor: grabbing;
}

/* <meter> and <progress>: low/high/optimum on <meter> pick the colour */
.html-embed-body :where(meter, progress) {
    appearance: none;
    display: block;
    width: 100%;
    max-width: 22rem;
    height: 0.9rem;
    margin: 0.4rem 0;
    background: var(--bg);
    border: 2px solid var(--pad-edge);
    border-radius: 2px;
}

.html-embed-body :where(meter)::-webkit-meter-bar {
    height: 100%;
    background: var(--bg);
    border: 0;
    border-radius: 0;
}

.html-embed-body :where(meter)::-webkit-meter-optimum-value {
    background: var(--accent-teal);
}

.html-embed-body :where(meter)::-webkit-meter-suboptimum-value {
    background: var(--accent-amber);
}

.html-embed-body :where(meter)::-webkit-meter-even-less-good-value {
    background: var(--pad-error);
}

.html-embed-body :where(meter):-moz-meter-optimum::-moz-meter-bar {
    background: var(--accent-teal);
}

.html-embed-body :where(meter):-moz-meter-sub-optimum::-moz-meter-bar {
    background: var(--accent-amber);
}

.html-embed-body :where(meter):-moz-meter-sub-sub-optimum::-moz-meter-bar {
    background: var(--pad-error);
}

.html-embed-body :where(progress)::-webkit-progress-bar {
    background: var(--bg);
}

.html-embed-body :where(progress)::-webkit-progress-value {
    background: var(--accent-amber);
}

.html-embed-body :where(progress)::-moz-progress-bar {
    background: var(--accent-amber);
}

/* .gauge: a read-only dial. Text inside is the value; set style="--value: 0-100" */
.html-embed-body :where(.gauge) {
    display: grid;
    place-items: center;
    width: 8rem;
    aspect-ratio: 1;
    margin: 1rem 0;
    border-radius: 50%;
    background:
        radial-gradient(circle closest-side, var(--surface) 0 76%, transparent 77%),
        conic-gradient(
            from 225deg,
            var(--accent-amber) calc(var(--value, 0) * 2.7deg),
            var(--bg) 0 270deg,
            transparent 0
        );
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--text-bright);
}

/* .bars: a <dl> bar chart. Each <dd> holds the value text; set style="--value: 0-100" */
.html-embed-body :where(dl.bars) {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    align-items: center;
    gap: 0.5rem 0.75rem;
    margin: 1rem 0;
}

.html-embed-body :where(dl.bars) > :where(dt) {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: var(--text-bright);
}

.html-embed-body :where(dl.bars) > :where(dd) {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

.html-embed-body :where(dl.bars) > :where(dd)::before {
    content: "";
    flex: none;
    width: calc(var(--value, 0) * (100% - 5rem) / 100);
    height: 1.1rem;
    background: var(--accent-amber);
    border-radius: 0 4px 4px 0;
}

/* .stats: a row of figures. Each child is a <div> with a <strong> value and a caption */
.html-embed-body :where(.stats) {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: 0.75rem;
    margin: 1rem 0;
}

.html-embed-body :where(.stats) > :where(*) {
    margin: 0;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border: 2px solid var(--pad-edge);
    font-size: 0.85rem;
}

.html-embed-body :where(.stats) :where(strong, output) {
    display: block;
    font-family: var(--font-heading);
    font-size: 1.6rem;
    line-height: 1.2;
    color: var(--text-bright);
}

@media (max-width: 640px) {
    .html-embed {
        margin: 1.5rem 0;
        box-shadow: 4px 4px 0 var(--pad-shadow);
    }

    .html-embed-body {
        padding: 1rem 1rem 1.25rem;
    }

    .html-embed-body
        :where(
            input:not([type="checkbox"], [type="radio"], [type="color"], [type="button"], [type="submit"], [type="reset"]),
            select,
            textarea,
            button,
            input[type="button"],
            input[type="submit"],
            input[type="reset"]
        ) {
        width: 100%;
        max-width: none;
        margin-right: 0;
    }

    /* Undo the full-width rule above: a row's children share the line */
    .html-embed-body :where(.row) > :where(*) {
        width: auto;
    }

    .html-embed-body :where(input.knob) {
        width: 7rem;
    }

    .html-embed-body :where(.fields) {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.4rem;
    }
}
