/* =====================================================================
   Legal page (templates/legal.html), web redesign Task 11; SCREENS.md 14.

   A 68px top bar, a 320px contents column whose list stays in view beside
   the text (max 800), numbered sections. Every word on the page is as it
   was: the section and list numbers, the dash markers and the back arrow are
   drawn here (alt text "" so screen readers skip them; the plain content
   line before each is the fallback for browsers without alt text).

   Loaded after design-system.css, so its rules win ties with the
   components. Tokens from theme.css.
   ===================================================================== */

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

/* Contents links and Back to top jump natively (hash, :target, Back and
   focus all work); smooth only for those who have not asked for less
   motion. */
@media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
}

body.legal-page {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--surface-page);
    color: var(--text-primary);
    font-family: var(--font-sans);
}

.legal-page a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ----- Top bar ----- */
.legal-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 68px;
    padding: 0 40px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-page);
}
.legal-logo { height: 36px; }
.legal-logo img { height: 36px; width: auto; }
.legal-back {
    font-family: var(--font-mono);
    font-size: 13px;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-primary);
    text-decoration: none;
    white-space: nowrap;
}
.legal-back::before {
    content: "\2190\00a0";
    content: "\2190\00a0" / "";
}
.legal-back:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ----- Layout: the contents beside the text ----- */
.legal-layout {
    flex: 1;
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    align-items: start;
}

/* The column runs the full height (its rule beside the text); the list
   inside it is what stays in view while the text scrolls. */
.legal-toc {
    align-self: stretch;
    padding: 48px 32px 48px 40px;
    border-right: 1px solid var(--border);
}
.legal-toc__inner {
    position: sticky;
    top: 24px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
/* The contents' disclosure (legal.html): open and its label plain beside
   the text; up to 900px wide a 48px row that folds the list. */
/* Spaced by margins: a <details>' own children are not its flex items in
   every browser. */
.legal-toc__details > summary {
    margin-bottom: 14px;
    list-style: none;
}
.legal-toc__details .legal-toc__mail {
    display: inline-block;
    margin-top: 14px;
}
.legal-toc__details > summary::-webkit-details-marker { display: none; }
.legal-toc__title { margin: 0; }
.legal-toc__list {
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: legal-toc;
    border-top: 1px solid var(--border);
}
.legal-toc__list li {
    counter-increment: legal-toc;
    border-bottom: 1px solid var(--border);
}
.legal-toc__list a {
    display: grid;
    grid-template-columns: 32px 1fr;
    padding: 10px 0;
    font-size: 14px;
    line-height: 1.35;
    color: var(--text-primary);
    text-decoration: none;
}
.legal-toc__list a::before {
    content: counter(legal-toc, decimal-leading-zero);
    content: counter(legal-toc, decimal-leading-zero) / "";
    padding-top: 1px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent);
}
.legal-toc__list a:hover { text-decoration: underline; text-underline-offset: 3px; }
.legal-toc__mail {
    align-self: flex-start;
    font-size: 14px;
    color: var(--accent);
    text-decoration: none;
}
.legal-toc__mail:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ----- Content ----- */
.legal-main {
    max-width: 800px;
    padding: 48px 56px 72px;
    counter-reset: legal-section;
}
.legal-head {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 28px;
    border-bottom: 1px solid var(--border-strong);
}
.legal-head h1 {
    margin: 0;
    font-size: 48px;
    font-weight: 500;
    line-height: 1.05;
    letter-spacing: -0.03em;
}

.legal-main > section {
    counter-increment: legal-section;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 36px 0;
    border-bottom: 1px solid var(--border);
}
.legal-main > section:last-child { border-bottom: 0; }

.legal-main h2 {
    display: flex;
    align-items: baseline;
    gap: 14px;
    margin: 0;
    font-size: 28px;
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: -0.02em;
}
.legal-main h2::before {
    content: counter(legal-section, decimal-leading-zero);
    content: counter(legal-section, decimal-leading-zero) / "";
    flex: none;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0;
    color: var(--accent);
}
.legal-main h3 {
    margin: 14px 0 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
}
.legal-main p {
    margin: 0;
    font-size: 16px;
    line-height: 1.7;
    text-wrap: pretty;
}
.legal-main strong { font-weight: 600; }
.legal-main em { font-style: italic; }
.legal-main a { color: var(--accent); text-decoration: none; }
.legal-main a:hover { text-decoration: underline; }

/* Lists: a 28px marker column, an em dash for bullets, 01... numbered */
.legal-main ul,
.legal-main ol {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.legal-main ol { counter-reset: legal-item; }
.legal-main li {
    position: relative;
    padding-left: 28px;
    font-size: 16px;
    line-height: 1.65;
    text-wrap: pretty;
}
.legal-main li::before {
    position: absolute;
    left: 0;
    top: 4px;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.65;
    color: var(--accent);
}
.legal-main ul > li::before {
    content: "\2014";
    content: "\2014" / "";
}
.legal-main ol > li { counter-increment: legal-item; }
.legal-main ol > li::before {
    content: counter(legal-item, decimal-leading-zero);
    content: counter(legal-item, decimal-leading-zero) / "";
}

/* The Controlled Testing Agreement's draft status: a caution .c-state */
.legal-status {
    max-width: none;
    padding: 14px 16px;
}
.legal-status p {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
}

/* ----- Footer: the right padding keeps Back to top off the last link ----- */
.legal-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 12px 24px;
    padding: 18px 80px 18px 40px;
    border-top: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-muted);
}
.legal-footer p { margin: 0; }
.legal-footer__links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
}
.legal-footer__links a {
    color: var(--text-muted);
    text-decoration: none;
}
.legal-footer__links a:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

/* Back to top: a square button, shown after 300px of scrolling */
.back-to-top {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: var(--z-header);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-1);
    background: var(--accent);
    color: var(--accent-ink);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--dur-fast) var(--ease-standard), visibility var(--dur-fast) var(--ease-standard);
}
.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}
.back-to-top:hover { filter: brightness(1.1); }

/* ----- Narrow screens: the contents above the text ----- */
@media (max-width: 900px) {
    .legal-topbar { padding: 0 16px; }
    .legal-layout { grid-template-columns: minmax(0, 1fr); }
    .legal-toc {
        padding: 28px 16px 8px;
        border-right: 0;
    }
    .legal-toc__inner {
        position: static;
        max-height: none;
        overflow: visible;
    }
    .legal-toc__details {
        border: 1px solid var(--border);
        background: var(--surface-card);
    }
    .legal-toc__details > summary {
        margin-bottom: 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-height: 48px;
        padding: 0 14px;
        cursor: pointer;
        color: var(--text-primary);
    }
    .legal-toc__details > summary::after {
        content: "\25B8";
        content: "\25B8" / "";
        font-family: var(--font-mono);
        color: var(--text-muted);
    }
    .legal-toc__details[open] > summary::after { transform: rotate(90deg); }
    .legal-toc__details > summary:focus-visible {
        outline: 2px solid var(--accent);
        outline-offset: -2px;
    }
    .legal-toc__details .legal-toc__list { padding: 0 14px; }
    .legal-toc__details .legal-toc__list li:last-child { border-bottom: 0; }
    .legal-toc__details .legal-toc__list a { min-height: 44px; align-items: center; padding: 0; }
    .legal-toc__details .legal-toc__mail {
        display: flex;
        align-items: center;
        min-height: 44px;
        margin-top: 0;
        padding: 0 14px;
        border-top: 1px solid var(--border);
    }
    .legal-main { padding: 28px 16px 56px; }
    .legal-head h1 { font-size: 36px; }
    .legal-main h2 { font-size: 24px; }
    .legal-footer { padding: 18px 80px 18px 16px; }
}

/* ----- Print: the text alone, one column, light ----- */
@media print {
    /* The light tokens already apply (theme.css's dark mode is screen
       only); the page is white on paper. */
    :root {
        --surface-page: #FFFFFF;
    }
    body.legal-page { background: #FFFFFF; }
    .legal-toc,
    .legal-back,
    .back-to-top,
    .legal-footer__links { display: none; }
    .legal-topbar { height: auto; padding: 0 0 12px; }
    .legal-layout { display: block; }
    .legal-main { max-width: none; padding: 24px 0 0; }
    .legal-footer { padding: 12px 0 0; }
    h2, h3 { break-after: avoid; }
    li { break-inside: avoid; }
}
