/* ---------- CSS Custom Properties ---------- */
:root {
    --font-sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    --bg: #ffffff;
    --text: #0f172a;
    /* slate-900 */
    --muted: #475569;
    /* slate-600 */
    --border: #e2e8f0;
    /* slate-200 */
    --accent: #2563eb;
    /* blue-600 */
    --accent-contrast: #ffffff;
    --card: #ffffff;
    --code-bg: #0f172a08;
    --header-height: 56px;
    --content-max: 72ch;
    --radius: 14px;
    --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1020;
        /* deep slate */
        --text: #e5e7eb;
        /* gray-200 */
        --muted: #9aa4b2;
        /* gray-400 */
        --border: #1f2937;
        /* gray-800 */
        --accent: #60a5fa;
        /* blue-400 */
        --accent-contrast: #0b1020;
        --card: #0f172a;
        /* slate-900 */
        --code-bg: #111827;
        /* gray-900 */
        --shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
    }
}

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

html {
    scroll-behavior: smooth;
    hanging-punctuation: first last;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: var(--font-sans);
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    display: flex;
    flex-direction: column;
}

/* Constrain content width without extra wrappers */
body>h1,
body>h2,
body>h3,
body>h4,
body>p,
body>ul,
body>ol,
body>blockquote,
body>pre,
body>hr {
    width: min(var(--content-max), calc(100% - 2.5rem));
}

/* ---------- Typography ---------- */
h1,
h2,
h3,
h4 {
    line-height: 1.25;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: var(--text);
    scroll-margin-top: calc(var(--header-height) + 12px);
    /* offset for sticky header */
}

h1 {
    font-size: clamp(1.9rem, 2.4vw + 1.2rem, 2.6rem);
    margin: 1.25rem auto .75rem;
}

h2 {
    font-size: clamp(1.35rem, 1.1vw + 1rem, 1.6rem);
    margin: 2.2rem auto .6rem;
    padding-top: .2rem;
    border-top: 1px solid var(--border);
}

h3 {
    font-size: clamp(1.1rem, .7vw + .9rem, 1.25rem);
    margin: 1.6rem auto .4rem;
}

h4 {
    font-size: clamp(1rem, .7vw + .8rem, 1.15rem);
    margin: 1.6rem auto .4rem;
}

p, ul {
    margin: .75rem auto;
    color: var(--text);
}

strong {
    font-weight: 750;
}

em {
    font-style: italic;
}

li {
    margin: .25rem 0;
}

/* Long words and URLs wrap nicely */
p,
li {
    overflow-wrap: anywhere;
}

/* ---------- Links ---------- */
a {
    color: var(--accent);
    text-underline-offset: .18em;
    text-decoration-thickness: .08em;
}

a:hover {
    text-decoration: none;
}

a:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
    outline-offset: 2px;
    border-radius: 6px;
}

/* ---------- Cards / callouts (optional utility classes) ---------- */
.notice,
.warning {
    width: min(var(--content-max), calc(100% - 2.5rem));
    margin: 1rem auto;
    padding: .9rem 1rem;
    border-radius: var(--radius);
    background: var(--card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.warning {
    border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

/* ---------- Code / pre ---------- */
pre,
code,
kbd,
samp {
    font-family: var(--font-mono);
}

pre {
    width: min(var(--content-max), calc(100% - 2.5rem));
    background: var(--code-bg);
    padding: .9rem 1rem;
    border-radius: 12px;
    overflow: auto;
    border: 1px solid var(--border);
}

/* ---------- Horizontal rule ---------- */
hr {
    width: min(var(--content-max), calc(100% - 2.5rem));
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem auto;
}

/* ---------- Anchor target highlight (if linking to #ids) ---------- */
:target {
    animation: targetHighlight 2.2s ease-out 1;
}

@keyframes targetHighlight {
    0% {
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 35%, transparent);
    }

    40% {
        box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 18%, transparent);
    }

    100% {
        box-shadow: 0 0 0 0 transparent;
    }
}

/* ---------- Images (if any) ---------- */
img,
svg {
    max-width: 100%;
    height: auto;
}

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
    :root {
        --header-height: 52px;
    }

    .legal-nav {
        gap: .4rem;
    }

    .legal-link {
        padding: .35rem .6rem;
        font-weight: 650;
    }
}

/* ---------- Print styles ---------- */
@media print {

    /* Use clean type and margins */
    html,
    body {
        background: #fff !important;
        color: #000 !important;
    }

    .legal-bar {
        display: none !important;
    }

    body {
        align-items: stretch;
        margin: 0;
    }

    body>* {
        width: 100% !important;
        box-shadow: none !important;
    }

    h1 {
        font-size: 22pt;
        margin: 0 0 8pt 0;
        page-break-after: avoid;
    }

    h2 {
        font-size: 14pt;
        margin: 16pt 0 6pt 0;
        page-break-after: avoid;
        border: none;
    }

    h3 {
        font-size: 12pt;
        margin: 12pt 0 4pt 0;
        page-break-after: avoid;
    }

    h4 {
        font-size: 11pt;
        margin: 12pt 0 4pt 0;
        page-break-after: avoid;
    }

    p,
    li {
        font-size: 11pt;
    }

    /* Avoid orphan/widow lines */
    p,
    ul,
    h2,
    h3,
    h4 {
        orphans: 3;
        widows: 3;
    }

    /* Show URLs after links in print */
    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 9pt;
        color: #000;
    }

    /* Page margins */
    @page {
        size: A4;
        margin: 16mm 14mm;
    }
}

/* ---------- Helpers ---------- */
/* Subtle card container if needed: wrap long sections */
.section {
    width: min(var(--content-max), calc(100% - 2.5rem));
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.25rem;
    margin: 1rem auto;
}

/* Spacing utilities (optional) */
.mt-0 {
    margin-top: 0 !important;
}

.mt-1 {
    margin-top: .25rem !important;
}

.mt-2 {
    margin-top: .5rem !important;
}

.mt-3 {
    margin-top: .75rem !important;
}

.mt-4 {
    margin-top: 1rem !important;
}

/* Accessibility: higher contrast focus for keyboard users */
:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 40%, transparent);
    outline-offset: 2px;
    border-radius: 8px;
}