.legal-hero {
    padding: 150px 0 50px;
}

.legal-hero h1 {
    font-size: clamp(30px, 4.4vw, 44px);
    margin-bottom: 14px;
}

.legal-hero .dates {
    color: var(--ink-muted);
    font-size: 14px;
}

.legal-layout {
    display: grid;
    grid-template-columns:230px 1fr;
    gap: 56px;
    /*padding: 20px 0 120px;*/
    align-items: start;
}

.toc {
    position: sticky;
    top: 100px;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
}

.toc summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ink-muted);
    font-weight: 700;
    margin-bottom: 14px;
    padding: 2px 0;
}

.toc summary::-webkit-details-marker {
    display: none;
}

.toc summary .chev {
    transition: transform .2s ease;
    color: var(--coral);
    font-size: 14px;
}

.toc[open] summary .chev {
    transform: rotate(90deg);
}

.toc a {
    display: block;
    font-size: 13.5px;
    color: var(--ink-muted);
    padding: 6px 0;
    border-left: 2px solid transparent;
    padding-left: 12px;
}

.toc a:hover {
    color: var(--ink);
    border-left-color: var(--coral);
}

.legal-body {
    max-width: 680px;
}

.legal-body .lede {
    font-size: 16.5px;
    color: var(--ink-muted);
    margin-bottom: 44px;
    padding-bottom: 36px;
    border-bottom: 1px solid var(--line);
}

.legal-body section {
    margin-bottom: 44px;
    scroll-margin-top: 100px;
}

.legal-body h2 {
    font-size: 19px;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    margin-bottom: 14px;
    display: flex;
    gap: 10px;
    align-items: baseline;
}

.legal-body h2 .num {
    color: var(--coral);
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: 16px;
}

.legal-body h3 {
    font-size: 15px;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    margin: 20px 0 8px;
}

.legal-body p {
    font-size: 14.5px;
    color: var(--ink-muted);
    margin-bottom: 12px;
}

.legal-body ul {
    margin: 8px 0 12px 20px;
}

.legal-body li {
    font-size: 14.5px;
    color: var(--ink-muted);
    margin-bottom: 6px;
}

.legal-body a.inline {
    color: var(--coral);
    text-decoration: underline;
}

.placeholder {
    background: #FBF0E4;
    color: #8A5A15;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 13px;
}

@media (max-width: 860px) {
    .legal-layout {
        grid-template-columns:1fr;
    }

    .toc {
        position: static;
        max-height: none;
        margin-bottom: 24px;
        border: 1px solid var(--line);
        border-radius: 12px;
        padding: 14px 16px;
    }

    .toc summary {
        margin-bottom: 0;
    }

    .toc[open] summary {
        margin-bottom: 10px;
    }

    .toc a {
        padding-left: 8px;
    }
}

/* Active state for the on-page ToC, driven by IntersectionObserver */
.toc a.is-active {
    color: var(--coral-deep);
    border-left-color: var(--coral);
    font-weight: 600;
}

.toc a:focus-visible {
    outline: 2px solid var(--coral);
    outline-offset: 2px;
    border-radius: 3px;
}

/* Quick topics + search */
.legal-quickbar {
    padding: 28px 0 20px;
}

.legal-quickbar .search-field {
    position: relative;
    max-width: 420px;
    margin-bottom: 18px;
}

.legal-quickbar .search-field label {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ink-muted);
    font-weight: 700;
    margin-bottom: 8px;
}

.legal-search-input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 11px 14px;
    font-family: 'Inter', sans-serif;
    font-size: 14.5px;
    background: #fff;
    color: var(--ink);
}

.legal-search-input:focus-visible {
    outline: 2px solid var(--coral);
    outline-offset: 1px;
}

.legal-search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 8px 24px rgba(20, 15, 10, .1);
    z-index: 20;
    max-height: 320px;
    overflow-y: auto;
}

.legal-search-results[hidden] {
    display: none;
}

.legal-search-results button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-radius: 8px;
    padding: 9px 10px;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
}

.legal-search-results button:hover,
.legal-search-results button:focus-visible {
    background: var(--surface);
    outline: none;
}

.legal-search-results .result-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

.legal-search-results .result-blurb {
    font-size: 12.5px;
    color: var(--ink-muted);
    margin-top: 2px;
}

.legal-search-empty {
    font-size: 13px;
    color: var(--ink-muted);
    padding: 10px 8px;
}

.legal-topics {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    list-style: none;
    padding: 0;
    margin: 0;
}

.legal-topics li {
    margin: 0;
}

.legal-topics a {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 14px;
    text-decoration: none;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.legal-topics a:hover {
    border-color: var(--coral);
    color: var(--coral-deep);
}

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

.legal-topics a.is-active {
    background: var(--coral);
    border-color: var(--coral);
    color: #fff;
}

@media (max-width: 760px) {
    .legal-topics {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 6px;
        margin: 0 -20px;
        padding-left: 20px;
        padding-right: 20px;
    }

    .legal-topics a {
        flex-shrink: 0;
    }
}

/* "Stays on device / may leave device" comparison (privacy page only) */
.legal-device-summary {
    padding: 0 0 30px;
}

.device-summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 10px;
}

.device-summary-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px 22px;
    background: var(--surface);
}

.device-summary-card h3 {
    font-size: 12.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 10px;
}

.device-summary-card.stays h3 {
    color: #1F6E5E;
}

.device-summary-card.leaves h3 {
    color: var(--coral-deep);
}

.device-summary-card ul {
    margin: 0;
    padding-left: 18px;
}

.device-summary-card li {
    font-size: 13.5px;
    color: var(--ink-muted);
    margin-bottom: 6px;
}

@media (max-width: 700px) {
    .device-summary-grid {
        grid-template-columns: 1fr;
    }
}

/* Plain-language "In simple terms" callouts inside legal sections */
.legal-tldr {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 16px;
}

.legal-tldr .tldr-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--coral-deep);
    margin-bottom: 4px;
}

.legal-tldr p {
    font-size: 13.5px;
    color: var(--ink);
    margin: 0;
}

/* Smooth scrolling for in-page ToC / quick topic / search navigation is
   applied via JS (scrollIntoView), not CSS `scroll-behavior: smooth` on
   <html> — that global rule fights the browser's native on-load fragment
   scroll (e.g. #face-analysis in the URL) once web fonts finish loading
   and reflow the page, sometimes cancelling the jump entirely. Leaving the
   initial fragment navigation as native/instant avoids that, while clicks
   made after the page has settled still animate smoothly. */

/* Zero-height marker placed right after the quickbar. Once it scrolls out
   of view the user has left the intro area, so the Back to Top control
   appears — no scroll-position math needed. */
.back-to-top-sentinel {
    height: 0;
}

/* Back to top. Icon-only up to 1100px: the two-column ToC + content grid
   (.legal-layout, 230px + content, gap 56px) only gains a comfortable side
   margin once the centered .wrap (max-width 1100px) has room to breathe
   past that width — below it, a labeled pill would risk sitting over the
   text column on tablet / narrow-desktop widths. A compact circular icon
   button stays clear of the content at every width in between. */
.back-to-top {
    position: fixed;
    right: 18px;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    z-index: 40;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 999px;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--ink-muted);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(20, 15, 10, .1);
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease, border-color .15s ease, color .15s ease;
}

.back-to-top.is-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.back-to-top:hover,
.back-to-top:focus-visible {
    border-color: var(--coral);
    color: var(--coral-deep);
}

.back-to-top:focus-visible {
    outline: 2px solid var(--coral);
    outline-offset: 2px;
}

.back-to-top svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.back-to-top .label {
    display: none;
}

/* The labeled pill only fits once the centered .wrap (max-width 1100px) has
   gained enough outer margin to clear it — verified empirically clear
   (~32px) from 1280px up; below that, right up to 1100px, .wrap still has
   little to no outer margin and a ~130px-wide pill would sit over the text
   column. */
@media (min-width: 1280px) {
    .back-to-top {
        right: 28px;
        bottom: 28px;
        width: auto;
        height: auto;
        padding: 12px 20px 12px 16px;
    }

    .back-to-top .label {
        display: inline;
        white-space: nowrap;
    }
}

/* Between the .legal-layout single-column breakpoint (860px) and 1100px,
   the two-column ToC + content grid fills the viewport almost edge to
   edge — confirmed empirically down to ~30px of overlap at 1024px, even
   with the compact icon-only button. There's no safe gutter here for a
   floating control at any reasonable size, so it's hidden for this band
   rather than risk sitting over legal text. From 1101px the compact icon
   is clear again (verified ~40px+ clearance), widening further until the
   labeled pill takes over at 1280px. */
@media (min-width: 861px) and (max-width: 1100px) {
    .back-to-top {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .back-to-top {
        transition: opacity .01ms linear, transform .01ms linear;
    }
}
