/* ==========================================================================
   Fonts (self-hosted)
   ========================================================================== */

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('./fonts/inter.ttf') format('truetype');
}

@font-face {
    font-family: 'Syne';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('./fonts/syne.ttf') format('truetype');
}

/* ==========================================================================
   Design tokens

   This is the only place where concrete values live. The utility builder
   references these variables by name; it never reads or writes them.

   The light palette, type scale and shape values follow the Mellivor
   Storybook (2026-10-29). The semantic colour scale and the dark theme are
   library extensions.

   Apps can override any token at :root or scope them to a subtree. A palette
   is application data, not a theme concern: put user/entity colors in a
   separate stylesheet or inline custom properties.
   ========================================================================== */

:root {
    color-scheme: light;

    /* ---- Neutral surfaces ------------------------------------------------- */
    --white: #ffffff;
    --black: #14181d;
    --background: #e9ebee;
    --surface: #ffffff;
    --raised: #dee1e6;
    --border: #c9ced6;
    --border-muted: #dee1e6;
    --grey: #c9ced6;
    --backdrop: rgb(20 24 29 / 0.28);

    /* ---- Text ------------------------------------------------------------- */
    --ink: #2a2f36;
    --ink-soft: #454c56;
    --annotation: #5a6371;
    --muted: #7b8490;
    --ink-inverse: #ffffff;

    /* ---- Semantic --------------------------------------------------------- */
    --accent: #2457a3;
    --success: #2f6b4f;
    --warn: #9a5b13;
    --danger: #c24a3f;
    --info: #31597f;
    --neutral: #5a6371;

    /* Derived tints. Uses the surface so they follow the active theme. */
    --accent-soft: color-mix(in oklch, var(--accent) 12%, var(--surface));
    --success-soft: color-mix(in oklch, var(--success) 14%, var(--surface));
    --warn-soft: color-mix(in oklch, var(--warn) 14%, var(--surface));
    --danger-soft: color-mix(in oklch, var(--danger) 14%, var(--surface));
    --info-soft: color-mix(in oklch, var(--info) 14%, var(--surface));
    --neutral-soft: color-mix(in oklch, var(--neutral) 14%, var(--surface));

    --ring: color-mix(in oklch, var(--accent) 38%, transparent);

    /* ---- Spacing + radius scale ------------------------------------------ */
    --space-0: 0;
    --space-2xs: 2px;
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --space-2xl: 36px;
    --space-3xl: 48px;

    /* ---- Type ------------------------------------------------------------- */
    /* Fonts are not bundled. Host apps load Space Grotesk and Inter; Syne is
       kept as a fallback for existing projects. */
    --tx-header: 'Space Grotesk', 'Syne', system-ui, sans-serif;
    --tx-body: 'Inter', system-ui, sans-serif;
    --tx-mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;

    --tx-2xs: 10px;
    --tx-xs: 11px;
    --tx-sm: 13px;
    --tx-md: 15px;
    --tx-lg: 19px;
    --tx-xl: 22px;
    --tx-2xl: clamp(24px, 3.4vw, 34px);
    --tx-3xl: clamp(32px, 5vw, 52px);

    --tx-thin: 100;
    --tx-light: 300;
    --tx-normal: 400;
    --tx-medium: 500;
    --tx-semi: 600;
    --tx-bold: 700;
    --tx-extra: 800;

    /* ---- Elevation -------------------------------------------------------- */
    --shadow-sm: rgba(20, 24, 29, 0.08) 0 1px 2px;
    --shadow-md: rgba(20, 24, 29, 0.12) 0 18px 40px;
    --shadow-lg: rgba(20, 24, 29, 0.16) 0 24px 56px;

    /* ---- Layout ----------------------------------------------------------- */
    --page-max-lg: 1024px;
    --page-max-xl: 1120px;
}

:root.dark,
[data-theme='dark'] {
    color-scheme: dark;

    --white: #14181d;
    --black: #ffffff;
    --background: #171a1f;
    --surface: #1e2229;
    --raised: #262b33;
    --border: #3b424c;
    --border-muted: #2c323a;
    --grey: #3b424c;
    --backdrop: rgb(0 0 0 / 0.56);

    --ink: #e8ebef;
    --ink-soft: #c6ccd4;
    --annotation: #9aa3b0;
    --muted: #76808d;
    --ink-inverse: #14181d;

    --accent: #6f9fdf;
    --success: #6ec08e;
    --warn: #e0a44a;
    --danger: #e2766b;
    --info: #8ab4dd;
    --neutral: #a8b0ba;

    --shadow-sm: rgba(0, 0, 0, 0.32) 0 1px 2px;
    --shadow-md: rgba(0, 0, 0, 0.42) 0 18px 40px;
    --shadow-lg: rgba(0, 0, 0, 0.5) 0 24px 56px;
}

/* Static pages follow the visitor's system preference. */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;

        --white: #14181d;
        --black: #ffffff;
        --background: #171a1f;
        --surface: #1e2229;
        --raised: #262b33;
        --border: #3b424c;
        --border-muted: #2c323a;
        --grey: #3b424c;
        --backdrop: rgb(0 0 0 / 0.56);

        --ink: #e8ebef;
        --ink-soft: #c6ccd4;
        --annotation: #9aa3b0;
        --muted: #76808d;
        --ink-inverse: #14181d;

        --accent: #6f9fdf;
        --success: #6ec08e;
        --warn: #e0a44a;
        --danger: #e2766b;
        --info: #8ab4dd;
        --neutral: #a8b0ba;

        --shadow-sm: rgba(0, 0, 0, 0.32) 0 1px 2px;
        --shadow-md: rgba(0, 0, 0, 0.42) 0 18px 40px;
        --shadow-lg: rgba(0, 0, 0, 0.5) 0 24px 56px;
    }
}

/* ==========================================================================
   Base / reset
   ========================================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body,
#root {
    min-height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--background);
    color: var(--ink);
    font-family: var(--tx-body);
    font-size: var(--tx-md);
    font-weight: var(--tx-normal);
    line-height: 1.3;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

::selection {
    background: var(--accent-soft);
    color: var(--accent);
}

:where(a, button, [tabindex]):focus-visible {
    outline: 3px solid var(--ring);
    outline-offset: 2px;
}

a {
    color: inherit;
}

/* The default text role. More specific utilities can override it. */
.tx-main {
    color: var(--ink);
    font-family: var(--tx-body);
    font-size: var(--tx-md);
    font-weight: var(--tx-normal);
    line-height: 1.3;
}

/* ==========================================================================
   Shared static components
   ========================================================================== */

html {
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
}

a {
    text-decoration: none;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    color: inherit;
}

svg.icon {
    width: 18px;
    height: 18px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: fixed;
    top: var(--space-sm);
    left: var(--space-sm);
    z-index: 1000;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--space-xs);
    background: var(--accent);
    color: var(--ink-inverse);
    font-size: var(--tx-sm);
    font-weight: var(--tx-semi);
    transform: translateY(-160%);
    transition: transform 0.15s ease;
}

.skip-link:focus {
    transform: translateY(0);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    height: 32px;
    padding: 0 var(--space-lg);
    border: 0;
    border-radius: var(--space-xs);
    background: transparent;
    color: var(--ink);
    font-size: var(--tx-md);
    font-weight: var(--tx-medium);
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition:
        background 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease;
}

.button svg.icon {
    width: 16px;
    height: 16px;
}

.button-primary {
    background: var(--accent);
    color: var(--ink-inverse);
}

.button-primary:hover {
    background: color-mix(in oklch, var(--accent) 88%, black);
}

.button-border {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
}

.button-border:hover {
    background: var(--raised);
}

.button-ghost {
    color: var(--ink);
}

.button-ghost:hover {
    background: var(--raised);
}

.button-inverse {
    border: 1px solid var(--ink-inverse);
    color: var(--ink-inverse);
}

.button-inverse:hover {
    background: color-mix(in oklch, var(--ink-inverse) 12%, transparent);
}

.button-sm {
    height: 28px;
    padding: 0 var(--space-md);
    font-size: var(--tx-sm);
}

.button-lg {
    height: 40px;
    padding: 0 var(--space-xl);
    font-size: var(--tx-lg);
}

.button-lg svg.icon {
    width: 20px;
    height: 20px;
}

.button-block {
    width: 100%;
}

.button:disabled,
.button[aria-disabled='true'] {
    cursor: not-allowed;
    opacity: 0.5;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    width: fit-content;
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid transparent;
    border-radius: var(--space-xs);
    font-size: var(--tx-sm);
    font-weight: var(--tx-semi);
    line-height: 1.3;
}

.badge svg.icon {
    width: 14px;
    height: 14px;
}

.badge-accent-soft {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}

.badge-success-soft {
    border-color: var(--success);
    background: var(--success-soft);
    color: var(--success);
}

.badge-warn-soft {
    border-color: var(--warn);
    background: var(--warn-soft);
    color: var(--warn);
}

.list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin: 0;
    padding-left: var(--space-lg);
}

.list li::marker {
    color: var(--accent);
}

.list li > p {
    margin: 0;
}

.note {
    --note-color: var(--info);
    --note-bg: var(--info-soft);
    padding: var(--space-md) var(--space-lg);
    border-left: 3px solid var(--note-color);
    background: var(--note-bg);
}

.note-neutral {
    --note-color: var(--neutral);
    --note-bg: var(--neutral-soft);
}

.note-warn {
    --note-color: var(--warn);
    --note-bg: var(--warn-soft);
}

.note-title {
    margin-bottom: var(--space-2xs);
    color: var(--note-color);
    font-weight: var(--tx-semi);
}

.note-body > :last-child {
    margin-bottom: 0;
}

.figure {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin: 0;
}

.figure-content {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80px;
    padding: var(--space-md);
    overflow: auto;
    border: 1px solid var(--border);
    background: var(--surface);
}

.figure-flush .figure-content {
    min-height: 0;
    padding: 0;
    overflow: visible;
    border: 0;
    background: transparent;
}

.figure-caption {
    color: var(--annotation);
    font-size: var(--tx-xs);
}

.code-block-shell {
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--raised);
}

.code-block-label {
    display: flex;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-xs) var(--space-md);
    border-bottom: 1px solid var(--border);
    color: var(--annotation);
    font-family: var(--tx-mono);
    font-size: var(--tx-xs);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.code-block {
    margin: 0;
    padding: var(--space-md);
    overflow: auto;
    color: var(--ink);
    font-family: var(--tx-mono);
    font-size: var(--tx-sm);
    line-height: 1.55;
    tab-size: 4;
}

.code-block code {
    font: inherit;
    white-space: pre;
}

.accordion {
    border-top: 1px solid var(--border);
}

.accordion-item {
    border-bottom: 1px solid var(--border);
}

.accordion-trigger {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-md) var(--space-sm);
    border: 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: var(--tx-sm);
    font-weight: var(--tx-semi);
    text-align: left;
    cursor: pointer;
    list-style: none;
}

.accordion-trigger::-webkit-details-marker {
    display: none;
}

.accordion-trigger:hover {
    background: var(--raised);
}

.accordion-trigger:focus-visible {
    outline: 3px solid var(--ring);
    outline-offset: -1px;
}

.accordion-trigger-label {
    flex: 1;
    min-width: 0;
}

.accordion-trigger .icon {
    flex: none;
    color: var(--accent);
}

.accordion-chevron {
    margin-left: auto;
    color: var(--annotation) !important;
    transition: transform 0.15s ease;
}

.accordion-item[open] .accordion-chevron {
    transform: rotate(180deg);
}

.accordion-panel {
    padding: 0 var(--space-sm) var(--space-lg);
    color: var(--ink-soft);
    font-size: var(--tx-sm);
    line-height: 1.55;
}

.accordion-panel > :last-child {
    margin-bottom: 0;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .accordion-chevron {
        transition: none;
    }
}

/* ==========================================================================
   Static toast
   ========================================================================== */

.site-toast {
    position: fixed;
    right: var(--space-lg);
    bottom: var(--space-lg);
    z-index: 1000;
    max-width: min(360px, calc(100vw - 32px));
    padding: var(--space-md) var(--space-lg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--space-xs);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    color: var(--ink);
    font-size: var(--tx-sm);
    line-height: 1.45;
}

.site-toast[hidden] {
    display: none;
}
