.sf-terms-reader {
    display: flex;
    border-top: 1px solid var(--sf-color-border);
    background: var(--sf-color-canvas-soft);
    text-align: left;
}
.sf-terms-toc {
    flex: 0 0 220px;
    box-sizing: border-box;
    max-height: 400px;
    overflow-y: auto;
    padding: 14px 10px;
    border-right: 1px solid var(--sf-color-border);
}
.sf-terms-toc-label {
    margin: 0 8px 8px;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--sf-color-text-muted);
}
.sf-terms-toc ol {
    list-style: none;
    margin: 0;
    padding: 0;
}
.sf-terms-reader .sf-terms-toc a.sf-terms-toc-link {
    display: block;
    padding: 6px 8px;
    border-radius: 7px;
    font-size: .78rem;
    line-height: 1.35;
    font-weight: 500;
    color: var(--sf-color-text-muted);
    text-decoration: none;
}
.sf-terms-reader .sf-terms-toc a.sf-terms-toc-link:hover,
.sf-terms-reader .sf-terms-toc a.sf-terms-toc-link:focus-visible,
.sf-terms-reader .sf-terms-toc a.sf-terms-toc-link[aria-current] {
    background: var(--sf-accent-soft);
    color: var(--sf-accent-ink);
}
.sf-terms-text {
    flex: 1 1 auto;
    min-width: 0;
    box-sizing: border-box;
    max-height: 400px;
    overflow-y: auto;
    padding: 18px 24px 20px;
    font-size: .9rem;
    line-height: 1.65;
    color: var(--sf-color-text);
    scroll-behavior: smooth;
}
.sf-terms-text:focus-visible {
    outline: 2px solid var(--sf-accent);
    outline-offset: -2px;
}
.sf-terms-text h2:focus { outline: none; }
.sf-terms-text h2 {
    margin: 20px 0 8px;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--sf-color-text);
}
.sf-terms-text h3 {
    margin: 16px 0 6px;
    font-size: .92rem;
    font-weight: 700;
}
.sf-terms-text p,
.sf-terms-text ul,
.sf-terms-text ol { margin: 0 0 12px; }
.sf-terms-version {
    font-size: .8rem;
    color: var(--sf-color-text-muted);
}
.sf-terms-fullpage {
    margin-top: 18px;
    padding-top: 12px;
    border-top: 1px solid var(--sf-color-border);
    font-size: .82rem;
}

.sf-legal-sheet {
    width: min(860px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    padding: 0;
    border: 1px solid var(--sf-color-border);
    border-radius: 16px;
    background: var(--sf-color-surface);
    color: var(--sf-color-text);
    box-shadow: var(--sf-shadow-xl);
    overflow: hidden;
}
.sf-legal-sheet[open] {
    display: flex;
    flex-direction: column;
}
.sf-legal-sheet::backdrop { background: var(--sf-color-scrim); }
.sf-legal-sheet-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 24px 16px;
    text-align: left;
}
.sf-legal-sheet-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--sf-color-text);
}
.sf-legal-sheet-meta {
    margin: 4px 0 0;
    font-size: .82rem;
    color: var(--sf-color-text-muted);
}
.sf-legal-sheet-close {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border: 1px solid var(--sf-color-border);
    border-radius: 10px;
    background: var(--sf-color-surface);
    color: var(--sf-color-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.sf-legal-sheet-close:hover { border-color: var(--sf-accent); }
.sf-legal-sheet .sf-terms-reader {
    flex: 1 1 auto;
    min-height: 0;
}
.sf-legal-sheet .sf-terms-toc,
.sf-legal-sheet .sf-terms-text { max-height: calc(100vh - 220px); }
.sf-legal-sheet-foot {
    display: flex;
    justify-content: flex-end;
    padding: 14px 24px;
    border-top: 1px solid var(--sf-color-border);
}
.sf-legal-sheet-done {
    min-height: 44px;
    padding: 0 22px;
    border: 0;
    border-radius: 10px;
    background: var(--sf-brand, var(--sf-color-primary-fill));
    color: var(--sf-color-on-fill);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}
.sf-legal-sheet-done:hover { background: color-mix(in srgb, var(--sf-brand, var(--sf-color-primary-fill)) 85%, black); }

@media (prefers-reduced-motion: reduce) {
    .sf-terms-text { scroll-behavior: auto; }
}

@media (max-width: 640px) {
    .sf-terms-reader { flex-direction: column; }
    .sf-terms-toc {
        flex: none;
        max-height: none;
        overflow-x: auto;
        padding: 10px 12px;
        border-right: 0;
        border-bottom: 1px solid var(--sf-color-border);
        scrollbar-width: none;
    }
    .sf-terms-toc::-webkit-scrollbar { display: none; }
    .sf-terms-toc-label { display: none; }
    .sf-terms-toc ol {
        display: flex;
        gap: 6px;
        width: max-content;
    }
    .sf-terms-reader .sf-terms-toc a.sf-terms-toc-link {
        white-space: nowrap;
        padding: 6px 10px;
        border: 1px solid var(--sf-color-border);
        border-radius: var(--sf-radius-pill, 999px);
        background: var(--sf-color-surface);
    }
    .sf-terms-text {
        max-height: 320px;
        padding: 14px;
    }
    .sf-legal-sheet {
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        margin: 0;
        border: 0;
        border-radius: 0;
    }
    .sf-legal-sheet-head { padding: 16px; }
    .sf-legal-sheet .sf-terms-text { max-height: none; }
    .sf-legal-sheet .sf-terms-reader { overflow: hidden; }
    .sf-legal-sheet-foot { padding: 12px 16px 16px; }
    .sf-legal-sheet-done { width: 100%; }
}
