/* ============================================================
   Lex Prep — Legal documents reader
   Standalone surface. Does NOT include main.css (that file sets
   html, body { overflow: hidden } and body { display: flex }, both
   of which break a long-form reader).
   Inherits the Lex Prep palette + type system via fonts.css and the
   CSS custom properties redeclared below — kept in sync with
   main.css so light/dark switch via [data-theme] still works.
   ============================================================ */

:root {
    --bg: #f5f0e8;
    --bg-subtle: #ebe5d9;
    --card: #faf7f2;
    --border: rgba(120,90,50,0.12);
    --border-strong: rgba(120,90,50,0.22);
    --accent: #7c3aed;
    --accent-soft: rgba(124,58,237,0.08);
    --accent-hover: #6d28d9;
    --text: #2c2417;
    --text-secondary: rgba(44,36,23,0.62);
    --text-muted: rgba(44,36,23,0.42);
    --rule: rgba(120,90,50,0.18);

    --font-display: "Instrument Serif", "Cormorant Garamond", Georgia, serif;
    --font-body:    "Inter Tight", ui-sans-serif, system-ui, sans-serif;
    --font-mono:    "JetBrains Mono", ui-monospace, Menlo, monospace;

    --measure: 64ch;
    --gutter: clamp(20px, 5vw, 56px);
}

[data-theme="dark"] {
    --bg: #13111a;
    --bg-subtle: #17151f;
    --card: rgba(255,255,255,0.04);
    --border: rgba(255,255,255,0.08);
    --border-strong: rgba(255,255,255,0.16);
    --accent: #8b5cf6;
    --accent-soft: rgba(139,92,246,0.12);
    --accent-hover: #a78bfa;
    --text: #f0f0f5;
    --text-secondary: rgba(255,255,255,0.55);
    --text-muted: rgba(255,255,255,0.32);
    --rule: rgba(255,255,255,0.14);
}

* { box-sizing: border-box; }

html {
    background: var(--bg);
    color: var(--text);
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.7;
    font-feature-settings: 'ss01';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

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

/* ── Top bar ───────────────────────────────────────────────── */
/* Slim header that pins back-link left, cross-doc nav right.
   Flex with `gap` and `flex-wrap` so neither child crowds the
   other at any viewport — fixes the word-per-line wrapping. */
.legal-topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
    padding: 18px var(--gutter);
    border-bottom: 1px solid var(--rule);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(140%) blur(8px);
    -webkit-backdrop-filter: saturate(140%) blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.legal-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px 6px 6px;
    margin-left: -6px;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.01em;
    white-space: nowrap;            /* never wrap "Back to Lex Prep" */
    transition: color 0.15s ease, background 0.15s ease;
}
.legal-back:hover,
.legal-back:focus-visible {
    color: var(--text);
    background: var(--accent-soft);
    outline: none;
}
.legal-back-arrow {
    display: inline-block;
    transition: transform 0.15s ease;
}
.legal-back:hover .legal-back-arrow,
.legal-back:focus-visible .legal-back-arrow {
    transform: translateX(-2px);
}

.legal-brand {
    font-family: var(--font-display);
    font-size: 18px;
    letter-spacing: -0.01em;
    color: var(--text);
    white-space: nowrap;
    flex: 0 1 auto;
}
.legal-brand em {
    font-style: italic;
    color: var(--accent);
}

.legal-doctabs {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 0;
}
.legal-doctab {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s ease, background 0.15s ease;
}
.legal-doctab:hover,
.legal-doctab:focus-visible {
    color: var(--text);
    background: var(--accent-soft);
    outline: none;
}
.legal-doctab[aria-current="page"] {
    background: var(--accent);
    color: #fff;
}
[data-theme="dark"] .legal-doctab[aria-current="page"] {
    background: var(--accent);
    color: #0f0d16;
}

/* ── Article ───────────────────────────────────────────────── */
.legal-article {
    max-width: var(--measure);
    margin: 0 auto;
    padding: clamp(40px, 8vw, 88px) var(--gutter) clamp(48px, 10vw, 120px);
    position: relative;
}

/* Eyebrow above the H1 — sets the document apart from the rest of
   the app without leaning on a giant brand mark. */
.legal-eyebrow {
    display: block;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    margin: 0 0 18px;
}

/* ── Markdown content ──────────────────────────────────────── */
.legal-article h1 {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(38px, 5vw, 56px);
    line-height: 1.04;
    letter-spacing: -0.015em;
    margin: 0 0 6px;
    color: var(--text);
}
.legal-article h1 + p strong:first-child {
    color: var(--text);
}

.legal-article h2 {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(24px, 2.4vw, 30px);
    line-height: 1.2;
    letter-spacing: -0.005em;
    margin: 56px 0 14px;
    color: var(--text);
    /* tiny tick mark to demarcate sections without a heavy rule */
    padding-left: 0;
    position: relative;
}
.legal-article h2::before {
    content: "§";
    position: absolute;
    left: -28px;
    top: 6px;
    color: var(--accent);
    font-size: 18px;
    font-family: var(--font-mono);
    font-weight: 500;
    opacity: 0.55;
}
@media (max-width: 600px) {
    .legal-article h2::before { display: none; }
}

.legal-article h3 {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 16px;
    line-height: 1.4;
    letter-spacing: -0.005em;
    margin: 32px 0 10px;
    color: var(--text);
}

.legal-article p {
    margin: 0 0 18px;
    color: var(--text);
}
.legal-article p:has(> strong:only-child) {
    /* "Last updated: ..." and similar attribution lines */
    color: var(--text-secondary);
    font-size: 14px;
}

.legal-article ul,
.legal-article ol {
    margin: 0 0 22px;
    padding-left: 26px;
}
.legal-article li {
    margin: 0 0 8px;
    color: var(--text);
}
.legal-article li::marker {
    color: var(--text-muted);
}

.legal-article strong { color: var(--text); font-weight: 600; }
.legal-article em { font-style: italic; }

.legal-article a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    transition: color 0.15s ease;
}
.legal-article a:hover { color: var(--accent-hover); }

.legal-article hr {
    border: 0;
    height: 1px;
    background: var(--rule);
    margin: 40px 0;
}

.legal-article blockquote {
    margin: 22px 0;
    padding: 4px 0 4px 18px;
    border-left: 2px solid var(--accent);
    color: var(--text-secondary);
    font-style: italic;
}

.legal-article code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
}

.legal-article pre {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    padding: 16px 18px;
    border-radius: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    overflow-x: auto;
}
.legal-article pre code {
    padding: 0;
    border: 0;
    background: transparent;
    font-size: inherit;
}

/* Tables — used in cookie-policy.md. Clean, editorial, theme-aware. */
.legal-article table {
    width: 100%;
    border-collapse: collapse;
    margin: 26px 0;
    font-size: 14.5px;
    line-height: 1.5;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.legal-article thead th {
    background: var(--card);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-secondary);
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-strong);
}
.legal-article tbody td {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    vertical-align: top;
    color: var(--text);
}
.legal-article tbody tr:first-child td {
    border-top: 0;
}
.legal-article tbody tr:nth-child(even) td {
    background: color-mix(in srgb, var(--card) 60%, transparent);
}

@media (max-width: 540px) {
    /* Tables get a horizontal scroll wrapper feel without extra markup. */
    .legal-article table {
        display: block;
        overflow-x: auto;
        white-space: normal;
    }
    .legal-article thead th,
    .legal-article tbody td {
        font-size: 13.5px;
        padding: 10px 12px;
    }
}

/* ── Footer ───────────────────────────────────────────────── */
.legal-footer {
    max-width: var(--measure);
    margin: 0 auto;
    padding: 32px var(--gutter) 80px;
    border-top: 1px solid var(--rule);
    color: var(--text-muted);
    font-size: 13px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 12px 24px;
}
.legal-footer a {
    color: var(--text-secondary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.legal-footer a:hover {
    color: var(--text);
    border-color: var(--accent);
}

/* ── Small viewports ─────────────────────────────────────── */
@media (max-width: 540px) {
    .legal-topbar {
        padding: 14px 18px;
    }
    .legal-brand {
        order: 0;
        font-size: 16px;
    }
    .legal-back {
        font-size: 12px;
    }
    .legal-doctabs {
        order: 3;
        width: 100%;
        justify-content: flex-start;
        gap: 4px 6px;
    }
    .legal-doctab {
        font-size: 12px;
        padding: 5px 10px;
    }
    .legal-article h1 {
        font-size: clamp(30px, 8vw, 40px);
    }
    body { font-size: 16px; line-height: 1.65; }
}

/* ── Reduced motion ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* ── Focus visible (a11y) ─────────────────────────────────── */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ── Print ────────────────────────────────────────────────── */
@media print {
    :root {
        --bg: #fff;
        --text: #000;
        --text-secondary: #444;
        --text-muted: #777;
        --rule: #ccc;
        --border: #ccc;
        --accent: #000;
    }
    body { font-family: 'Iowan Old Style', 'Times New Roman', Georgia, serif; font-size: 11pt; line-height: 1.55; color: #000; }
    .legal-topbar,
    .legal-footer { display: none !important; }
    .legal-article { max-width: none; padding: 0; }
    .legal-article h1 { font-size: 22pt; }
    .legal-article h2 { font-size: 14pt; margin-top: 28pt; }
    .legal-article h2::before { display: none; }
    .legal-article h3 { font-size: 12pt; }
    .legal-article a { color: #000; text-decoration: underline; }
    .legal-article table { font-size: 10pt; }
}
