/* Whitepaper layout: sticky TOC (desktop) + article column */

.whitepaper-layout {
    display: grid;
    gap: 2rem;
}

/*
 * Sticky TOC: any ancestor with non-visible overflow between here and the scrollport
 * breaks position:sticky (Chrome is strict about this). Layout.js wraps main children in #top.
 */
main.whitepaper-main,
main.whitepaper-main #top,
.whitepaper-layout,
.whitepaper-article-column {
    overflow-x: visible;
    overflow-y: visible;
}

@media (max-width: 1023px) {
    .whitepaper-layout {
        align-items: start;
    }
}

@media (min-width: 1024px) {
    .whitepaper-layout {
        grid-template-columns: minmax(0, 14.5rem) minmax(0, 1fr);
        gap: 3rem;
        align-items: start;
    }
}

.whitepaper-toc-aside {
    min-width: 0;
}

@media (min-width: 1024px) {
    .whitepaper-toc-aside {
        position: sticky;
        top: 6rem;
        max-height: calc(100vh - 7rem);
        overflow-y: auto;
        overflow-x: hidden;
        padding-right: 0.5rem;
        margin-right: -0.25rem;
        border-right: 1px solid var(--blog-slate-200, #e2e8f0);
        scrollbar-width: thin;
        scrollbar-color: var(--blog-scrollbar-thumb, #cbd5e1) transparent;
    }

    .whitepaper-toc-aside:hover {
        scrollbar-color: var(--blog-scrollbar-thumb, #cbd5e1) var(--blog-scrollbar-track, #f1f5f9);
    }
}

/* Notion / docs-style label: sentence case, quiet */
/* Extra scroll range so late TOC entries can sit near the middle of the column, not pinned to the bottom edge. */
@media (min-width: 1024px) {
    nav.whitepaper-toc--desktop {
        padding-bottom: min(42vh, 16rem);
    }
}

.whitepaper-toc-title {
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: none;
    color: var(--blog-slate-500, #64748b);
    margin: 0 0 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--blog-slate-100, #f1f5f9);
}

.whitepaper-toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Subsections: indent + lighter type only (no vertical rail). */
.whitepaper-toc-list--nested {
    margin-top: 0.12rem;
    margin-bottom: 0.35rem;
    margin-left: 0;
    padding-left: 0.875rem;
    border-left: none;
}

.whitepaper-toc-item {
    margin-bottom: 0.1rem;
}

.whitepaper-toc-item--h2 {
    margin-bottom: 0.15rem;
}

.whitepaper-toc-item--h2 > .whitepaper-toc-link {
    font-weight: 500;
}

.whitepaper-toc-item--h3 {
    margin-bottom: 0.05rem;
}

.whitepaper-toc-link {
    display: block;
    font-size: 1rem;
    line-height: 1.35;
    color: var(--blog-slate-600, #475569);
    text-decoration: none;
    border-radius: 0.25rem;
    padding: 0.35rem 0.5rem 0.35rem 0.5rem;
    margin-left: 0;
    border-left: 2px solid transparent;
    cursor: pointer;
    transition:
        color 0.12s ease,
        border-color 0.12s ease,
        background-color 0.12s ease;
}

.whitepaper-toc-link:hover {
    color: var(--blog-slate-900, #0f172a);
    background-color: rgba(248, 250, 252, 0.9);
}

/* Active section (scroll sync): left accent + stronger type (H2 and H3). */
.whitepaper-toc-link--active {
    color: var(--blog-slate-900, #0f172a);
    font-weight: 600;
    border-left-width: 2px;
    border-left-style: solid;
    border-left-color: var(--blog-indigo-600, #4f46e5);
    background-color: rgba(239, 246, 255, 0.55);
}

.whitepaper-toc-item--h3 .whitepaper-toc-link {
    font-size: 1rem;
    font-weight: 400;
    color: var(--blog-slate-500, #64748b);
    padding-top: 0.22rem;
    padding-bottom: 0.22rem;
    padding-left: 0.4rem;
}

.whitepaper-toc-item--h3 .whitepaper-toc-link:hover {
    color: var(--blog-slate-800, #1e293b);
}

.whitepaper-toc-item--h3 .whitepaper-toc-link.whitepaper-toc-link--active {
    font-size: 1rem;
    font-weight: 600;
    color: var(--blog-slate-900, #0f172a);
}

/*
 * Mobile TOC: sticky lives on a plain wrapper, not on <details>.
 * Chrome often mishandles sticky on <details> (and non-visible overflow on ancestors).
 */
@media (max-width: 1023px) {
    .whitepaper-toc-mobile-sticky {
        position: sticky;
        top: 4.25rem;
        z-index: 40;
        box-shadow: 0 1px 0 rgb(15 23 42 / 0.06);
        overflow: visible;
    }

    .whitepaper-toc-mobile {
        overflow: visible;
    }

    .whitepaper-toc-mobile[open] nav.whitepaper-toc--mobile {
        max-height: min(70vh, 28rem);
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
}

.whitepaper-toc-mobile summary.whitepaper-toc-mobile-summary {
    list-style: none;
}

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

.whitepaper-toc-mobile-chevron {
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.whitepaper-toc-mobile[open] .whitepaper-toc-mobile-chevron {
    transform: rotate(180deg);
}

.whitepaper-toc--mobile .whitepaper-toc-title {
    display: none;
}

.whitepaper-toc--mobile .whitepaper-toc-link {
    padding-left: 0.5rem;
    margin-left: 0;
}

.whitepaper-toc--mobile .whitepaper-toc-list--nested {
    padding-left: 0.75rem;
}

.whitepaper-toc--mobile .whitepaper-toc-item--h3 .whitepaper-toc-link {
    padding-left: 0.35rem;
}

.whitepaper-article-column {
    min-width: 0;
}

/* Offset anchor scroll for fixed header */
.whitepaper-body h2,
.whitepaper-body h3 {
    scroll-margin-top: 5.75rem;
}

/* Inline citations: [n] as button (source opens from panel) */
.whitepaper-body button.whitepaper-cite-ref {
    display: inline;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    font: inherit;
    text-decoration: none;
    color: var(--blog-indigo-600, #4f46e5);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    vertical-align: baseline;
}

.whitepaper-body button.whitepaper-cite-ref:hover,
.whitepaper-body button.whitepaper-cite-ref:focus-visible {
    text-decoration: underline;
    color: var(--blog-indigo-700, #4338ca);
}

.whitepaper-cite-tooltip {
    --whitepaper-cite-tip-left: 0px;
    --whitepaper-cite-tip-top: 0px;
    position: fixed;
    left: var(--whitepaper-cite-tip-left);
    top: var(--whitepaper-cite-tip-top);
    z-index: 80;
    max-width: min(20rem, calc(100vw - 1.5rem));
    box-sizing: border-box;
    padding: 0.875rem 1rem 0.9375rem;
    border-radius: 0.5rem;
    border: 1px solid rgb(51 65 85 / 0.85);
    background: var(--blog-slate-900, #0f172a);
    color: #f1f5f9;
    font-size: 0.8125rem;
    line-height: 1.4;
    letter-spacing: 0.01em;
    box-shadow:
        0 12px 24px -8px rgb(0 0 0 / 0.35),
        0 4px 8px -4px rgb(0 0 0 / 0.2);
    pointer-events: auto;
}

@media (max-width: 1023px) {
    .whitepaper-cite-tooltip.whitepaper-cite-tooltip--center-x {
        width: calc(100vw - 1.5rem) !important;
        max-width: calc(100vw - 1.5rem) !important;
        left: 0.75rem !important;
    }
}

.whitepaper-cite-tooltip-head {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.whitepaper-cite-tooltip-line {
    display: block;
    flex: 1;
    min-width: 0;
}

.whitepaper-cite-tooltip-num {
    color: #a5b4fc;
    font-weight: 600;
}

.whitepaper-cite-tooltip-title {
    font-weight: 500;
    color: #f8fafc;
}

.whitepaper-cite-tooltip-host {
    display: block;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgb(51 65 85 / 0.65);
    font-size: 0.75rem;
    line-height: 1.35;
    color: var(--blog-slate-400, #94a3b8);
    word-break: break-all;
}

.whitepaper-cite-tooltip-link {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: -0.2rem -0.15rem -0.2rem 0;
    padding: 0.2rem;
    color: #c7d2fe;
    text-decoration: none;
    cursor: pointer;
    border-radius: 0.25rem;
    transition:
        color 0.12s ease,
        background-color 0.12s ease;
}

.whitepaper-cite-tooltip-link:hover {
    color: #eef2ff;
    background-color: rgb(255 255 255 / 0.06);
    text-decoration: none;
}

.whitepaper-cite-tooltip-link:focus-visible {
    outline: none;
    color: #fff;
    background-color: rgb(255 255 255 / 0.08);
    box-shadow: 0 0 0 2px var(--blog-slate-900, #0f172a), 0 0 0 4px #818cf8;
}

.whitepaper-cite-tooltip-ext-icon {
    font-size: 1rem;
    line-height: 1;
    font-variation-settings:
        'FILL' 0,
        'wght' 400,
        'GRAD' 0,
        'opsz' 20;
    opacity: 0.88;
}

.whitepaper-cite-tooltip-link:hover .whitepaper-cite-tooltip-ext-icon,
.whitepaper-cite-tooltip-link:focus-visible .whitepaper-cite-tooltip-ext-icon {
    opacity: 1;
}
