/*
   Legal pages (agb.html, datenschutz.html, widerruf.html).

   Loaded after styles.css and scoped to the .legal-* class family so it never
   affects the quiz app. The long-form reading experience needs to override two
   global app rules: body{overflow:hidden} and .page{height:100dvh} both pin the
   viewport for the split-pane quiz, which would make a 11-section AGB
   unreadable.
*/

body:has(.legal-page) {
    overflow-y: auto;
    height: auto;
}

/* The decorative .bg-orbit is a fixed 520px circle parked off the top-right
   corner; once these pages scroll instead of clipping at the viewport, it
   becomes the scroll width and forces a horizontal scrollbar. */
html:has(.legal-page) {
    overflow-x: clip;
}

.legal-page {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-y: visible;
    padding: clamp(16px, 3vw, 40px);
    background:
        radial-gradient(90% 50% at 50% 0%, rgba(15, 111, 106, 0.06) 0%, transparent 60%);
}

.legal-card {
    max-width: 860px;
    margin: 0 auto;
    padding: clamp(28px, 4vw, 56px) clamp(22px, 5vw, 64px) clamp(36px, 5vw, 64px);
    border-radius: var(--r-2xl);
    border: 1px solid var(--line);
    background: var(--card);
    box-shadow: var(--sh-4);
    line-height: var(--leading-body);
    color: var(--ink);
    animation: fadeUp 0.45s var(--ease-out) both;
}

/* ---- Masthead ------------------------------------------------------------ */

.legal-card > a:first-of-type {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 28px;
    padding: 7px 14px 7px 11px;
    border-radius: var(--r-pill);
    border: 1px solid var(--line);
    background: var(--warm-paper);
    color: var(--ink-2);
    font-size: var(--text-sm);
    font-weight: 600;
    text-decoration: none;
    transition:
        color var(--t-base) var(--ease-out),
        border-color var(--t-base) var(--ease-out),
        background var(--t-base) var(--ease-out),
        transform var(--t-base) var(--ease-out);
}

.legal-card > a:first-of-type:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-tint);
    transform: translateX(-2px);
}

.legal-card > a:first-of-type:focus-visible {
    box-shadow: var(--focus-ring);
}

.legal-card h1 {
    font-family: var(--font-display);
    font-size: clamp(30px, 4.4vw, 46px);
    line-height: 1.08;
    letter-spacing: -0.02em;
    margin: 0 0 14px;
    color: var(--ink);
    text-wrap: balance;
}

.legal-updated {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: 0 0 30px;
    padding: 5px 13px;
    border-radius: var(--r-pill);
    background: var(--accent-wash);
    color: var(--accent);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.legal-updated::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ---- Section headings ---------------------------------------------------- */

.legal-card h2 {
    font-family: var(--font-display);
    font-size: clamp(21px, 2.6vw, 27px);
    line-height: 1.2;
    letter-spacing: -0.01em;
    margin: 2.4em 0 0.7em;
    padding-left: 18px;
    border-left: 3px solid var(--accent);
    color: var(--ink);
    /* Clears the sticky TOC so an anchored heading is never hidden under it. */
    scroll-margin-top: 32px;
}

.legal-card h3 {
    font-size: var(--text-md);
    font-weight: 700;
    color: var(--ink);
    margin: 1.8em 0 0.5em;
    scroll-margin-top: 32px;
}

.legal-card p,
.legal-card li {
    max-width: 70ch;
    font-size: 16px;
    line-height: var(--leading-body);
    color: var(--ink-2);
}

.legal-card strong {
    color: var(--ink);
    font-weight: 700;
}

.legal-card ul,
.legal-card ol {
    max-width: 70ch;
    padding-left: 1.3em;
}

.legal-card li {
    margin: 0.5em 0;
}

.legal-card li::marker {
    color: var(--accent);
    font-weight: 700;
}

.legal-card a {
    color: var(--accent);
    text-underline-offset: 3px;
    text-decoration-thickness: 1.5px;
    transition: color var(--t-base) var(--ease-out);
}

.legal-card a:hover {
    color: var(--accent-hover);
}

.legal-card :is(h1, h2, h3):focus-visible {
    box-shadow: var(--focus-ring);
}

/* ---- Table of contents --------------------------------------------------- */

.legal-toc {
    position: sticky;
    top: 16px;
    z-index: 5;
    margin: 0 0 34px;
    padding: 20px 24px;
    border-radius: var(--r-lg);
    border: 1px solid var(--line);
    background: var(--warm-soft);
    box-shadow: var(--sh-1);
}

.legal-toc h2 {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 0 0 12px;
    padding: 0;
    border: 0;
    font-family: var(--font-body);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: var(--tracking-eyebrow);
    text-transform: uppercase;
    color: var(--accent);
}

.legal-toc h2::before {
    content: "";
    width: 14px;
    height: 2px;
    background: currentColor;
    border-radius: 2px;
}

/* Two explicit grid columns rather than CSS multi-column: multi-column splits
   the list at an arbitrary point and left a ragged gap mid-card. The sticky
   panel is pinned while reading, so its height has to stay well under half the
   viewport. */
.legal-toc ol {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2px 20px;
    max-height: min(52vh, 420px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
}

.legal-toc a {
    display: block;
    padding: 6px 10px;
    margin-left: -10px;
    border-radius: var(--r-xs);
    font-size: var(--text-base);
    color: var(--ink-2);
    text-decoration: none;
    border-left: 2px solid transparent;
    transition:
        color var(--t-base) var(--ease-out),
        background var(--t-base) var(--ease-out),
        border-color var(--t-base) var(--ease-out),
        padding-left var(--t-base) var(--ease-out);
}

.legal-toc a:hover,
.legal-toc a.is-active {
    color: var(--accent);
    background: var(--accent-tint);
    border-left-color: var(--accent);
    padding-left: 14px;
}

/* ---- Definition / FAQ card ----------------------------------------------- */

.legal-faq {
    margin: 0 0 30px;
    padding: 20px 24px;
    border-radius: var(--r-lg);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent-2);
    background: var(--accent-2-tint);
}

.legal-faq dt {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 700;
    line-height: 1.3;
    color: var(--ink);
    margin: 0 0 8px;
}

.legal-faq dd {
    margin: 0;
    max-width: 68ch;
    font-size: var(--text-base);
    line-height: var(--leading-body);
    color: var(--ink-2);
}

/* ---- Address block ------------------------------------------------------- */

.legal-address {
    font-style: normal;
    background: var(--warm-soft);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 18px 22px;
    margin: 1.2em 0;
    max-width: 70ch;
    font-size: var(--text-base);
    line-height: 1.7;
    color: var(--ink-2);
}

/* ---- Footer -------------------------------------------------------------- */

.legal-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 44px;
    padding-top: 22px;
    border-top: 1px solid var(--line-soft);
    font-size: var(--text-sm);
}

.legal-footer a {
    display: inline-block;
    padding: 6px 14px;
    border-radius: var(--r-pill);
    border: 1px solid transparent;
    color: var(--ink-3);
    text-decoration: none;
    transition:
        color var(--t-base) var(--ease-out),
        background var(--t-base) var(--ease-out),
        border-color var(--t-base) var(--ease-out);
}

.legal-footer a:hover {
    color: var(--accent);
    background: var(--accent-tint);
    border-color: var(--accent);
}

.legal-footer a:focus-visible {
    box-shadow: var(--focus-ring);
}

/* ---- Responsive ---------------------------------------------------------- */

@media (max-width: 760px) {
    .legal-card h2 {
        padding-left: 14px;
        scroll-margin-top: 16px;
    }

    .legal-toc {
        position: static;
        padding: 16px 18px;
    }

    .legal-toc ol {
        grid-template-columns: 1fr;
        max-height: none;
    }

    .legal-card p,
    .legal-card li {
        font-size: 15px;
    }
}

@media (max-width: 420px) {
    .legal-toc a {
        font-size: var(--text-sm);
        padding: 5px 8px;
    }

    .legal-footer a {
        padding: 5px 10px;
    }
}

/* ---- Print --------------------------------------------------------------- */

@media print {
    body:has(.legal-page) {
        background: #fff;
    }

    .legal-page {
        padding: 0;
        background: none;
    }

    .legal-card {
        max-width: none;
        padding: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        animation: none;
    }

    .legal-card > a:first-of-type,
    .legal-toc,
    .legal-footer {
        display: none;
    }

    .legal-card h1 {
        font-size: 26pt;
    }

    .legal-card h2 {
        font-size: 15pt;
        break-after: avoid-page;
        page-break-after: avoid;
        margin-top: 1.6em;
    }

    .legal-card h3 {
        font-size: 12pt;
        break-after: avoid-page;
        page-break-after: avoid;
    }

    .legal-card p,
    .legal-card li {
        font-size: 10.5pt;
        color: #000;
        orphans: 3;
        widows: 3;
    }

    .legal-card a {
        color: #000;
        text-decoration: underline;
    }

    .legal-faq,
    .legal-address {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}