/* tordnet portfolio – modern, dependency-free stylesheet.
   Served at /css/site.css (see app.js static config). */

/* Smooth cross-page transitions between pages that opt in (same origin). */
@view-transition { navigation: auto; }

/* ---- Design tokens ------------------------------------------------------- */

:root {
    color-scheme: light dark;

    --bg:             light-dark(#f7f7f8, #0f1115);
    --surface:        light-dark(#ffffff, #171a21);
    --surface-2:      light-dark(#eceef2, #232833);
    --text:           light-dark(#1b1d22, #e8eaef);
    --muted:          light-dark(#555b6a, #a3aab8);
    --border:         light-dark(#dcdfe6, #2c313c);
    --accent:         light-dark(#0b65c2, #6cb4ff);
    --accent-contrast: light-dark(#ffffff, #0b1220);
    --success:        light-dark(#1a7f37, #56d37a);
    --danger:         light-dark(#c62828, #ff8a80);

    --radius: 14px;
    --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 8px 24px rgb(0 0 0 / .07);
    --shadow-lift: 0 2px 4px rgb(0 0 0 / .08), 0 16px 40px rgb(0 0 0 / .12);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --max: 72rem;
}

/* The theme toggle sets data-theme; without it the OS preference wins. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

/* ---- Base ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

@media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
}

body {
    margin: 0;
    font-family: var(--font);
    line-height: 1.6;
    background: var(--bg);
    color: var(--text);
}

img { display: block; max-width: 100%; height: auto; }

a { color: var(--accent); }

h1, h2, h3 { line-height: 1.2; text-wrap: balance; }

p { text-wrap: pretty; }

:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
    border-radius: 4px;
}

/* Keep in-page targets clear of the sticky header. */
:target, section[id] { scroll-margin-top: 5rem; }

.container {
    width: min(100% - 2rem, var(--max));
    margin-inline: auto;
}

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: 1rem;
    top: -10rem;
    z-index: 100;
    padding: .6rem 1rem;
    background: var(--accent);
    color: var(--accent-contrast);
    border-radius: 8px;
    font-weight: 600;
}
.skip-link:focus { top: 1rem; }

.icon {
    width: 1em; height: 1em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: none;
}

/* ---- Header -------------------------------------------------------------- */

.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 4rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    color: inherit;
    font-weight: 700;
    text-decoration: none;
}
.brand img { width: 40px; height: 40px; border-radius: 50%; }

@media (max-width: 34rem) {
    .brand-name { display: none; }
}

.site-nav ul {
    display: flex;
    align-items: center;
    gap: .25rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.site-nav a {
    display: block;
    padding: .45rem .8rem;
    border-radius: 999px;
    color: inherit;
    text-decoration: none;
    font-weight: 500;
}
.site-nav a:hover { background: var(--surface-2); }

.theme-toggle {
    display: grid;
    place-items: center;
    width: 2.5rem; height: 2.5rem;
    margin-left: .25rem;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    font-size: 1.1rem;
    cursor: pointer;
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-toggle .icon-sun { display: none; }
.theme-toggle[aria-pressed="true"] .icon-sun { display: block; }
.theme-toggle[aria-pressed="true"] .icon-moon { display: none; }

/* ---- Hero ---------------------------------------------------------------- */

.hero { padding-block: clamp(1.5rem, 4vw, 2.75rem) clamp(1.5rem, 4vw, 3rem); }

.eyebrow {
    margin: 0 0 .5rem;
    color: var(--accent);
    font-size: .85rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.hero h1 {
    max-width: 20ch; /* keeps the slogan to two balanced lines on wide screens */
    margin: 0 0 1rem;
    font-size: clamp(2.2rem, 7vw, 4.25rem);
    letter-spacing: -.02em;
}

.lead {
    max-width: 62ch;
    margin: 0;
    color: var(--muted);
    font-size: clamp(1.05rem, 2vw, 1.25rem);
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    margin-top: 2rem;
}

/* ---- Buttons ------------------------------------------------------------- */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .7rem 1.3rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background-color .2s, transform .2s;
}
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .6; cursor: progress; }

.button-primary { background: var(--accent); color: var(--accent-contrast); }
.button-primary:hover { background: color-mix(in srgb, var(--accent) 85%, var(--text)); }

.button-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.button-secondary:hover { background: var(--surface-2); }

/* ---- Sections ------------------------------------------------------------ */

.section { padding-block: clamp(2.5rem, 6vw, 4.5rem); }

.section-header h2 {
    margin: 0 0 .5rem;
    font-size: clamp(1.6rem, 3.5vw, 2.2rem);
}
.section-header p { max-width: 60ch; margin: 0 0 1.5rem; color: var(--muted); }

/* ---- Project filters (radio buttons + :has(), no JS) --------------------- */

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin: 0 0 1.5rem;
    padding: 0;
    border: 0;
}

.filters label {
    position: relative;
    padding: .4rem .95rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-size: .95rem;
    font-weight: 500;
    cursor: pointer;
}
.filters label:hover { background: var(--surface-2); }

/* The real radio covers its label: invisible but still clickable and keyboard-focusable. */
.filters input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.filters label:has(:checked) {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}
.filters label:has(:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }

.projects:has(.filters [value="framework"]:checked) .card:not([data-tags~="framework"]),
.projects:has(.filters [value="cms"]:checked)       .card:not([data-tags~="cms"]),
.projects:has(.filters [value="design"]:checked)    .card:not([data-tags~="design"]),
.projects:has(.filters [value="personal"]:checked)  .card:not([data-tags~="personal"]) {
    display: none;
}

/* ---- Project cards ------------------------------------------------------- */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
    gap: 1.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* Each card is a size container, so its layout reacts to its own width. */
.card { container-type: inline-size; }

.card article {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: transform .2s ease, box-shadow .2s ease;
}

.card article:has(.card-link:hover),
.card article:has(.card-link:focus-visible) {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lift);
}
.card article:has(.card-link:focus-visible) { outline: 3px solid var(--accent); outline-offset: 3px; }

.card img {
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    background: var(--surface-2);
}

.card-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: .6rem;
    padding: 1.1rem 1.25rem 1.25rem;
}

.card h3 { margin: 0; font-size: 1.2rem; }

/* The link's ::after stretches over the whole card, so the card is one big click target
   while screen readers still hear a single, clearly named link. */
.card-link { color: inherit; text-decoration: none; }
.card-link::after { content: ""; position: absolute; inset: 0; }
.card-link:focus-visible { outline: none; }

.card p { margin: 0; color: var(--muted); }

.card .card-host {
    display: flex;
    align-items: center;
    gap: .3rem;
    margin-top: auto;
    padding-top: .25rem;
    color: var(--accent);
    font-size: .9rem;
    font-weight: 600;
}

.badges {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.badge {
    padding: .15rem .6rem;
    border-radius: 999px;
    background: var(--surface-2);
    font-size: .78rem;
    font-weight: 600;
}

/* Wide card (e.g. a single column on a tablet): image beside the text. */
@container (min-width: 32rem) {
    .card article { flex-direction: row; }
    .card img { width: 42%; aspect-ratio: auto; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
    .card article:has(.card-link:hover),
    .card article:has(.card-link:focus-visible) { transform: none; }
}

/* ---- Contact form -------------------------------------------------------- */

.contact-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
    gap: 1rem 3rem;
    align-items: start;
}

.form {
    display: grid;
    gap: 1.1rem;
    padding: clamp(1.25rem, 3vw, 1.75rem);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.field { display: grid; gap: .35rem; }
.field label,
.field-label { font-weight: 600; }
.optional { color: var(--muted); font-weight: 400; }

/* Text-like inputs only: sliders, colour pickers and checkboxes keep their native look. */
.field input:not([type="range"], [type="color"], [type="checkbox"], [type="radio"]),
.field select,
.field textarea {
    width: 100%;
    padding: .65rem .85rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: inherit;
    font: inherit;
}
.field textarea { min-height: 8rem; resize: vertical; field-sizing: content; }

.field input:focus-visible,
.field textarea:focus-visible { outline-offset: 0; border-color: var(--accent); }

/* :user-invalid only kicks in after the visitor has interacted with the field. */
.field :user-invalid { border-color: var(--danger); }
.field-error { display: none; margin: 0; color: var(--danger); font-size: .88rem; }
.field:has(:user-invalid) .field-error { display: block; }

/* Honeypot field: off-screen rather than display:none, which some bots detect. */
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; }

.form-status { margin: 0; font-weight: 500; }
.form-status[data-state="pending"] { color: var(--muted); }
.form-status[data-state="success"] { color: var(--success); }
.form-status[data-state="error"]   { color: var(--danger); }

/* ---- Inner pages --------------------------------------------------------- */

/* Keep the header in place while the rest of the page cross-fades between pages. */
.site-header { view-transition-name: site-header; }

.page-hero { padding-block: clamp(1.25rem, 3vw, 2.25rem) 0; }
.page-hero h1 {
    margin: 0 0 1rem;
    font-size: clamp(2.2rem, 6vw, 3.5rem);
    letter-spacing: -.02em;
}

.breadcrumb ol {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin: 0 0 1.25rem;
    padding: 0;
    list-style: none;
    font-size: .92rem;
}
.breadcrumb li + li::before { content: "/"; margin-right: .4rem; color: var(--muted); }
.breadcrumb a { color: var(--muted); }
.breadcrumb a[aria-current="page"] { color: var(--text); text-decoration: none; font-weight: 600; }

.prose { max-width: 65ch; }
.prose p { margin: 0 0 1rem; }
.prose p:not(.lead) { color: var(--muted); }

.banner {
    width: 100%;
    margin-top: 2rem;
    aspect-ratio: 1000 / 340;
    object-fit: cover;
    border-radius: var(--radius);
    background: var(--surface-2);
}

.accent { color: var(--accent); }

.cta { text-align: center; }
.cta h2 { margin: 0 0 .5rem; font-size: clamp(1.5rem, 3vw, 2rem); }
.cta p { max-width: 55ch; margin: 0 auto 1.5rem; color: var(--muted); }

/* ---- Screenshot gallery -------------------------------------------------- */

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 21rem), 1fr));
    gap: 1.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.shot {
    display: flex;
    flex-direction: column;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.shot a { display: block; overflow: hidden; border-radius: 0; }

.shot img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    object-position: top left;
    background: var(--surface-2);
    transition: transform .35s ease;
}
.shot a:hover img,
.shot a:focus-visible img { transform: scale(1.04); }
.shot a:focus-visible { outline-offset: -3px; }

.shot figcaption {
    padding: .9rem 1.1rem 1.1rem;
    color: var(--muted);
    font-size: .95rem;
}
.shot figcaption strong { display: block; margin-bottom: .2rem; color: var(--text); font-size: 1.02rem; }

/* ---- Lightbox (<dialog>) ------------------------------------------------- */

.lightbox {
    width: min(100% - 2rem, 1500px);
    max-width: none;
    max-height: calc(100dvh - 2rem);
    padding: 0;
    border: 0;
    background: transparent;
    color: #fff;
    overflow: visible;

    /* Fade + scale in and out; @starting-style gives the "before open" state. */
    opacity: 0;
    transform: scale(.97);
    transition: opacity .2s ease, transform .2s ease,
                overlay .2s ease allow-discrete, display .2s ease allow-discrete;
}
.lightbox[open] { opacity: 1; transform: none; }
@starting-style {
    .lightbox[open] { opacity: 0; transform: scale(.97); }
}

.lightbox::backdrop {
    background: rgb(0 0 0 / .85);
    transition: background-color .2s ease, overlay .2s ease allow-discrete, display .2s ease allow-discrete;
}
@starting-style {
    .lightbox[open]::backdrop { background: rgb(0 0 0 / 0); }
}

.lightbox figure { margin: 0; }
.lightbox img {
    width: auto;
    max-width: 100%;
    max-height: calc(100dvh - 8rem);
    margin-inline: auto;
    border-radius: 8px;
    background: #fff;
}
.lightbox figcaption {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .25rem 1rem;
    padding: .75rem 0 .25rem;
    text-align: center;
}
.lightbox-count { color: rgb(255 255 255 / .7); }

.lightbox-controls {
    display: flex;
    justify-content: center;
    gap: .75rem;
}
.lightbox-controls form { margin: 0; }

.icon-button {
    display: grid;
    place-items: center;
    width: 2.75rem; height: 2.75rem;
    border: 1px solid rgb(255 255 255 / .35);
    border-radius: 50%;
    background: rgb(255 255 255 / .1);
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
}
.icon-button:hover { background: rgb(255 255 255 / .22); }
.icon-button:focus-visible { outline-color: #fff; }

/* ---- DVD collection ------------------------------------------------------ */

.dvd-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1rem;
}
.dvd-toolbar .filters { margin: 0; }

.dvd-search { position: relative; flex: 1 1 16rem; max-width: 22rem; }
.dvd-search[hidden] { display: none; }
.dvd-search .icon {
    position: absolute;
    top: 50%;
    left: .9rem;
    translate: 0 -50%;
    color: var(--muted);
    pointer-events: none;
}
.dvd-search input {
    width: 100%;
    padding: .55rem 1rem .55rem 2.4rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: inherit;
    font: inherit;
}
.dvd-search input:focus-visible { outline-offset: 0; border-color: var(--accent); }

.dvd-status { min-height: 1.6em; margin: .75rem 0; color: var(--muted); font-size: .92rem; }

/* Native <details>; where supported, open/close animates to its natural height. */
.artist-index {
    interpolate-size: allow-keywords;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.artist-index summary { padding: .8rem 1.1rem; font-weight: 600; cursor: pointer; }
.artist-index::details-content {
    block-size: 0;
    overflow: hidden;
    transition: block-size .3s ease, content-visibility .3s ease allow-discrete;
}
.artist-index[open]::details-content { block-size: auto; }
.artist-index ol {
    margin: 0;
    padding: 0 1.1rem 1rem;
    list-style: none;
    columns: 12rem;
    column-gap: 1.5rem;
}
.artist-index li { padding-block: .15rem; break-inside: avoid; }
.artist-index a { color: var(--text); text-underline-offset: .2em; }
.artist-index a:hover { color: var(--accent); }

.genre { padding-top: 2.5rem; }
.genre h2 {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .25rem .75rem;
    margin: 0 0 1.25rem;
    font-size: clamp(1.4rem, 3vw, 1.9rem);
}
.genre .count { color: var(--muted); font-size: .95rem; font-weight: 500; }

.dvd-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 10.5rem), 1fr));
    gap: 1.5rem 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.dvd {
    display: flex;
    flex-direction: column;
    gap: .6rem;
    /* Off-screen cards skip rendering work until they scroll near the viewport. */
    content-visibility: auto;
    contain-intrinsic-size: auto 22rem;
}
.dvd[hidden] { display: none; }

.dvd img {
    width: 100%;
    aspect-ratio: 5 / 7;
    object-fit: cover;
    border-radius: 8px;
    background: var(--surface-2);
    box-shadow: var(--shadow);
}
.dvd:target img { outline: 3px solid var(--accent); outline-offset: 3px; }

.dvd-body { display: grid; gap: .15rem; }
.dvd-artist {
    margin: 0;
    color: var(--accent);
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.dvd-title { margin: 0; font-size: 1rem; line-height: 1.3; }
.dvd-note { margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.4; }

/* Genre filter (pure CSS) and search results (JS sets [hidden] on cards). */
.dvd-browser:has(.filters [value="blues"]:checked) .genre:not([data-genre="blues"]),
.dvd-browser:has(.filters [value="rock"]:checked)  .genre:not([data-genre="rock"]),
.dvd-browser:has(.filters [value="pop"]:checked)   .genre:not([data-genre="pop"]),
.dvd-browser:has(.filters [value="folk"]:checked)  .genre:not([data-genre="folk"]),
.dvd-browser:has(.filters [value="world"]:checked) .genre:not([data-genre="world"]),
.genre:not(:has(.dvd:not([hidden]))) {
    display: none;
}

.dvd-empty { padding: 3rem 0; color: var(--muted); text-align: center; }

/* Floating "back to top" button; fades in as you scroll (scroll-driven animation). */
.to-top {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 5;
    display: grid;
    place-items: center;
    width: 2.75rem; height: 2.75rem;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-contrast);
    font-size: 1.25rem;
    box-shadow: var(--shadow-lift);
}
@supports (animation-timeline: scroll()) {
    .to-top {
        animation: to-top-reveal linear both;
        animation-timeline: scroll();
        animation-range: 0 30rem;
    }
    @keyframes to-top-reveal {
        from { opacity: 0; visibility: hidden; translate: 0 1rem; }
        to   { opacity: 1; visibility: visible; translate: 0 0; }
    }
}

/* ---- HTML & CSS showcase (elements.html) --------------------------------- */

code, pre, kbd { font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace; }
:not(pre) > code {
    padding: .1em .35em;
    border-radius: 5px;
    background: var(--surface-2);
    font-size: .9em;
}
pre {
    overflow-x: auto;
    margin: .75rem 0 0;
    padding: 1rem 1.1rem;
    border-radius: 10px;
    background: var(--surface-2);
    font-size: .84rem;
    line-height: 1.55;
    tab-size: 2;
}
kbd {
    padding: .1em .45em;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 5px;
    background: var(--surface-2);
    font-size: .85em;
    white-space: nowrap;
}
mark {
    padding: 0 .15em;
    border-radius: 3px;
    background: light-dark(#ffe58a, #6b5a12);
    color: inherit;
}

.toc {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin: 1.75rem 0 0;
    padding: 0;
    list-style: none;
}
.toc a {
    display: block;
    padding: .35rem .85rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font-size: .92rem;
    text-decoration: none;
}
.toc a:hover { background: var(--surface-2); }

.demo {
    display: grid;
    gap: 1.25rem;
    padding-block: clamp(2.5rem, 6vw, 4rem);
    border-top: 1px solid var(--border);
}
.page-hero + .demo { margin-top: clamp(2rem, 5vw, 3rem); }
.demo-header h2 { margin: 0 0 .5rem; font-size: clamp(1.5rem, 3.2vw, 2rem); }
.demo-header > p { max-width: 68ch; margin: 0 0 .9rem; color: var(--muted); }
.badge-enh { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--accent); }

.demo-stage {
    padding: clamp(1rem, 3vw, 1.75rem);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.demo-stage > :first-child { margin-top: 0; }
.demo-stage > :last-child { margin-bottom: 0; }

.demo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
    gap: 1.25rem;
}
.button-row { display: flex; flex-wrap: wrap; gap: .75rem; }
.demo-output, .demo-hint { color: var(--muted); }
.demo-output { margin: 1rem 0 0; }
.demo-hint { margin: 0 0 1rem; font-size: .92rem; }

.source summary { color: var(--accent); font-weight: 600; cursor: pointer; }

/* Dialog + popover: both animate in and out of the top layer. */
.demo-dialog,
.demo-popover {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lift);
    opacity: 0;
    transition: opacity .2s ease, translate .2s ease, scale .2s ease,
                overlay .2s ease allow-discrete, display .2s ease allow-discrete;
}
.demo-dialog { width: min(100% - 2rem, 28rem); padding: 1.5rem; scale: .96; }
.demo-dialog[open] { opacity: 1; scale: 1; }
@starting-style { .demo-dialog[open] { opacity: 0; scale: .96; } }
.demo-dialog::backdrop {
    background: rgb(0 0 0 / .45);
    backdrop-filter: blur(3px);
}
.demo-dialog h3 { margin: 0 0 .5rem; }
.demo-dialog p { margin: 0; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.5rem; }

.demo-popover { width: min(100vw - 2rem, 20rem); padding: 1rem 1.1rem; translate: 0 -.4rem; }
.demo-popover:popover-open { opacity: 1; translate: 0 0; }
@starting-style { .demo-popover:popover-open { opacity: 0; translate: 0 -.4rem; } }
/* Without anchor positioning the popover stays centred (the browser default). */
@supports (anchor-name: --a) {
    .pop-trigger { anchor-name: --pop-trigger; }
    .demo-popover {
        position-anchor: --pop-trigger;
        inset: auto;
        top: anchor(bottom);
        left: anchor(left);
        margin: .5rem 0 0;
        position-try-fallbacks: flip-block, flip-inline;
    }
}
.popover-title { margin: 0 0 .5rem; font-weight: 700; }
.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: .4rem .9rem; margin: 0; }
.shortcuts dd { margin: 0; color: var(--muted); }

/* Accordion */
.accordion { padding-block: .25rem; }
.accordion details {
    interpolate-size: allow-keywords;
    border-bottom: 1px solid var(--border);
}
.accordion details:last-child { border-bottom: 0; }
.accordion summary { padding: .9rem 0; font-weight: 600; cursor: pointer; }
.accordion details p { margin: 0 0 1rem; color: var(--muted); }
.accordion details::details-content {
    block-size: 0;
    overflow: hidden;
    transition: block-size .3s ease, content-visibility .3s ease allow-discrete;
}
.accordion details[open]::details-content { block-size: auto; }

/* Forms demo */
.demo-form { accent-color: var(--demo-accent, var(--accent)); }
.demo-form .button-primary { background: var(--demo-accent, var(--accent)); }
.demo-form textarea { min-height: 3.2rem; }
.field-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
    gap: 1.1rem;
}
.range-row { display: flex; align-items: center; gap: .75rem; min-height: 2.8rem; }
.range-row input { flex: 1; }
.range-value { min-width: 2ch; font-weight: 700; font-variant-numeric: tabular-nums; }
.field input[type="color"] {
    width: 3.5rem; height: 2.8rem;
    padding: .2rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    cursor: pointer;
}
.checks { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; min-height: 2.8rem; align-items: center; }
.checks label { display: flex; align-items: center; gap: .45rem; font-weight: 400; }
.demo-form:has(:invalid) .when-valid,
.demo-form:not(:has(:invalid)) .when-invalid { display: none; }
.demo-form .when-valid { color: var(--success); }
.demo-form .when-invalid { color: var(--muted); }

/* :has() demos */
.plans {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 7.5rem), 1fr));
    gap: .75rem;
    margin: 0;
    padding: 0;
    border: 0;
}
.plans-legend { margin-bottom: .75rem; padding: 0; font-weight: 700; }
.plan {
    position: relative;
    display: grid;
    gap: .15rem;
    padding: 1rem;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    cursor: pointer;
    transition: border-color .2s, background-color .2s;
}
.plan input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.plan:has(:checked) {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 9%, var(--surface));
}
.plan:has(:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.plan-name { font-weight: 600; }
.plan-price { font-size: 1.5rem; font-weight: 700; }
.plan-note { margin: 1rem 0 0; color: var(--muted); }
.plan-note span { display: none; }
.has-plans:has([value="starter"]:checked) .note-starter,
.has-plans:has([value="pro"]:checked) .note-pro,
.has-plans:has([value="team"]:checked) .note-team { display: inline; }

.checklist { counter-reset: done; }
.checklist-title { margin: 0 0 .75rem; font-weight: 700; }
.checklist ul { display: grid; gap: .55rem; margin: 0; padding: 0; list-style: none; }
.checklist label { display: flex; align-items: center; gap: .6rem; cursor: pointer; }
.checklist input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.checklist input:checked { counter-increment: done; }
.checklist li:has(:checked) label { color: var(--muted); text-decoration: line-through; }
.checklist-count { margin: 1rem 0 0; color: var(--muted); font-size: .92rem; }
.checklist-count::after { content: counter(done) " of 4 done"; }
.checklist-done { display: none; margin: .25rem 0 0; color: var(--success); font-weight: 700; }
.checklist:not(:has(input:not(:checked))) .checklist-done { display: block; }

/* Subgrid */
.subgrid-demo {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
    gap: 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}
.sub-card {
    display: grid;
    grid-row: span 3;
    grid-template-rows: subgrid;
    gap: .6rem;
    padding: 1.1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
}
.sub-card h3 { margin: 0; font-size: 1.05rem; }
.sub-card p { margin: 0; color: var(--muted); }
.sub-card .button { justify-self: start; align-self: end; }

/* Container queries */
.cq-slider { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; font-weight: 600; }
.cq-slider input { flex: 1; max-width: 20rem; }
.cq-frame {
    container-type: inline-size;
    width: 100%;
    min-width: 14rem;
    max-width: 100%;
    padding: 1.1rem;
    overflow: auto;
    resize: horizontal;
    border: 2px dashed var(--border);
    border-radius: 12px;
}
.profile {
    display: grid;
    gap: 1rem;
    align-items: center;
    justify-items: center;
    text-align: center;
}
.profile-avatar {
    display: grid;
    place-items: center;
    width: 4.5rem;
    aspect-ratio: 1;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), color-mix(in oklch, var(--accent), #e0479e 65%));
    color: #fff;
    font-size: 1.4rem;
    font-weight: 700;
}
.profile h3 { margin: 0; font-size: clamp(1.05rem, 4cqi, 1.4rem); }
.profile-text p { margin: 0; color: var(--muted); }
.profile-stats { display: none; gap: 1.5rem; margin: 0; }
.profile-stats dt { color: var(--muted); font-size: .8rem; }
.profile-stats dd { margin: 0; font-size: 1.4rem; font-weight: 700; }
.cq-label { margin: 1rem 0 0; color: var(--muted); font-size: .9rem; text-align: center; }
.cq-medium, .cq-wide { display: none; }
.cq-label span { color: var(--accent); font-weight: 700; }

@container (min-width: 26rem) {
    .profile { grid-template-columns: auto 1fr; justify-items: start; text-align: start; }
    .cq-narrow { display: none; }
    .cq-medium { display: inline; }
}
@container (min-width: 40rem) {
    .profile { grid-template-columns: auto 1fr auto; }
    .profile-stats { display: flex; }
    .cq-medium { display: none; }
    .cq-wide { display: inline; }
}

/* Colour */
.swatch-label { margin: 0 0 .6rem; color: var(--muted); font-size: .9rem; }
.swatches {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: .35rem;
    margin: 0 0 1.25rem;
    padding: 0;
    list-style: none;
}
.swatches li {
    aspect-ratio: 1;
    border-radius: 8px;
    background: color-mix(in oklch, var(--accent) var(--p), white);
}
.swatches.shades li { background: color-mix(in oklch, var(--accent) var(--p), black); }

/* light-dark() tokens resolve against each panel's own color-scheme. */
.scheme-panel {
    padding: 1.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}
.scheme-light { color-scheme: light; }
.scheme-dark  { color-scheme: dark; }
.scheme-panel p { margin: 0 0 1rem; color: var(--muted); }
.scheme-panel .scheme-name { color: var(--text); font-weight: 600; }

.wrap-sample {
    max-width: 17rem;
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.25;
    outline: 1px dashed var(--border);
    outline-offset: 4px;
}
.wrap-sample.wrap-normal { text-wrap: wrap; }
.wrap-sample.wrap-balance { text-wrap: balance; }

/* Motion */
.read-progress { display: none; }
@supports (animation-timeline: scroll()) {
    .read-progress {
        position: fixed;
        inset: 0 0 auto;
        z-index: 20;
        display: block;
        height: 3px;
        background: var(--accent);
        transform-origin: 0 50%;
        animation: read-progress linear both;
        animation-timeline: scroll(root);
    }
    @keyframes read-progress {
        from { transform: scaleX(0); }
        to   { transform: scaleX(1); }
    }
}

.reveal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr));
    gap: 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}
.reveal-grid li {
    padding: 1.6rem 1rem;
    border-radius: 12px;
    background: color-mix(in srgb, var(--accent) 12%, var(--surface));
    font-weight: 700;
    text-align: center;
}
@supports (animation-timeline: view()) {
    @media (prefers-reduced-motion: no-preference) {
        .reveal-grid li {
            animation: reveal linear both;
            animation-timeline: view();
            animation-range: entry 0% cover 35%;
        }
        @keyframes reveal {
            from { opacity: 0; scale: .8; translate: 0 2rem; }
        }
    }
}

.toast-list { display: grid; gap: .5rem; margin: 1rem 0; padding: 0; list-style: none; }
.toast-list:empty { margin: 0; }
.toast-list li {
    padding: .7rem 1rem;
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    background: var(--surface-2);
    transition: opacity .4s ease, translate .4s ease;
}
@starting-style {
    .toast-list li { opacity: 0; translate: -1rem 0; }
}

/* Semantics */
.table-wrap {
    max-height: 26rem;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.table-wrap table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table-wrap caption { padding: .9rem 1rem; font-weight: 700; text-align: start; }
.table-wrap th,
.table-wrap td { padding: .6rem 1rem; border-top: 1px solid var(--border); text-align: start; }
.table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-2);
    font-size: .85rem;
    letter-spacing: .03em;
    text-transform: uppercase;
}
.table-wrap tbody th { font-weight: 600; }
.table-wrap tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.support { font-weight: 600; white-space: nowrap; }
.support-baseline { color: var(--success); }
.support-enh { color: var(--accent); }

.semantics-grid { margin-top: .25rem; }
.meter-label { display: block; margin: 1rem 0 .3rem; font-weight: 600; }
.meter-label span { color: var(--muted); font-weight: 400; }
meter, progress { width: 100%; height: 1.1rem; accent-color: var(--accent); }

.quote-figure { display: grid; align-content: center; gap: 1rem; margin: 0; }
.quote-figure blockquote {
    margin: 0;
    padding: .25rem 0 .25rem 1.25rem;
    border-left: 4px solid var(--accent);
    font-size: 1.2rem;
    font-style: italic;
}
.quote-figure blockquote p { margin: 0; }
.quote-figure figcaption { color: var(--muted); font-size: .92rem; }

/* ---- Footer -------------------------------------------------------------- */

.site-footer {
    padding-block: 2rem;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: .92rem;
}
.site-footer p { margin: 0; }
