:root {
    --font-note-display: "Newsreader", Georgia, serif;
}

main.note {
    width: min(100%, 780px);
    padding: clamp(2rem, 5vw, 3.35rem) clamp(1rem, 4vw, 1.7rem) 4.5rem;
    gap: 1.45rem;
    color: color-mix(in srgb, var(--text) 96%, var(--muted));
}

main.note h1 {
    max-width: 16ch;
    font-family: var(--font-note-display);
    font-size: clamp(2.05rem, 4.1vw, 2.95rem);
    font-weight: 500;
    letter-spacing: -0.018em;
    line-height: 1.08;
    text-wrap: balance;
}

main.note h2,
main.note h3 {
    font-family: var(--font-body);
    letter-spacing: -0.01em;
    text-wrap: balance;
}

main.note h2 {
    font-size: clamp(1.16rem, 1.05vw + 0.98rem, 1.44rem);
    font-weight: 600;
    color: color-mix(in srgb, var(--text) 92%, var(--muted));
}

main.note h3 {
    font-size: clamp(1rem, 0.6vw + 0.9rem, 1.08rem);
    font-weight: 600;
}

main.note p,
main.note li {
    font-size: clamp(0.99rem, 0.55vw + 0.9rem, 1.05rem);
    line-height: 1.78;
    color: color-mix(in srgb, var(--text) 96%, var(--muted));
}

main.note strong,
main.note dt,
main.note th {
    color: var(--text);
}

main.note section {
    gap: 0.82rem;
}

.note-back {
    position: relative;
    top: auto;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 86%, var(--page-bg));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 12px 28px rgba(16, 19, 26, 0.08);
    width: fit-content;
}

.note-back:hover {
    color: var(--accent-strong);
    border-color: var(--accent);
}

.note-box,
.note-figure,
table.note-table,
table.paper,
pre {
    width: 100%;
}

body.note-outline-enabled .note-layout {
    width: min(1180px, calc(100% - 2rem));
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(210px, 240px) minmax(0, 780px);
    gap: 2rem;
    /* No align-items: stretch is the default — required for sticky to work.
       align-items: start would collapse each cell to its content height,
       leaving the sidebar no room to scroll within its grid area. */
    align-items: stretch;
}

body.note-outline-enabled main.note {
    width: 100%;
    max-width: none;
    margin: 0;
    padding-inline: 0;
}

.note-outline {
    /* The grid item stretches to article height (align-items: stretch is default).
       Sticky must be on the CONTENT inside the grid item, not the item itself —
       that way the content sticks within a tall containing block. */
    padding-top: 1rem;
    z-index: 12;
    align-content: start;
    display: grid;
}

.note-outline-panel {
    position: sticky;
    top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    padding: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: color-mix(in srgb, var(--surface) 86%, var(--page-bg));
    box-shadow: var(--shadow-sm);
    /* Cap height to viewport so the track can scroll within */
    max-height: calc(100vh - 3rem);
    overflow: hidden;
}

.note-outline .note-back {
    margin-bottom: 0.2rem;
}

.note-outline-label {
    margin: 0;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.note-outline-track {
    display: grid;
    gap: 0.22rem;
    overflow-y: auto;
    padding-right: 0.25rem;
    /* Allow this flex child to shrink so it scrolls instead of overflowing the panel */
    flex: 1;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.note-outline-link {
    display: block;
    padding: 0.46rem 0.62rem;
    border: 1px solid transparent;
    border-radius: 12px;
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.3;
    transition: color 180ms ease, background-color 180ms ease, border-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.note-outline-link[data-depth="3"] {
    padding-left: 0.95rem;
    font-size: 0.84rem;
    font-weight: 500;
}

.note-outline-link:hover {
    color: var(--text);
    background: color-mix(in srgb, var(--surface) 78%, var(--surface-muted));
}

.note-outline-link.is-active {
    color: var(--text);
    border-color: var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transform: translateX(5px);
}

.pull-mode .note-back {
    background: color-mix(in srgb, #fffdf7 88%, #fff0be);
    border-color: rgba(43, 86, 164, 0.35);
}

.pull-mode .note-box,
.pull-mode .note-figure,
.pull-mode pre,
.pull-mode table.note-table,
.pull-mode table.paper {
    box-shadow: var(--shadow-sm);
}

.pull-mode .note-outline-panel {
    border: 2px solid rgba(43, 86, 164, 0.34);
    background:
        radial-gradient(circle at top right, rgba(255, 220, 110, 0.18), transparent 28%),
        linear-gradient(160deg, rgba(255, 255, 255, 0.98), rgba(255, 247, 215, 0.95) 60%, rgba(229, 239, 255, 0.92));
}

.pull-mode .note-outline-link.is-active {
    border-color: rgba(43, 86, 164, 0.4);
    background: rgba(255, 255, 255, 0.9);
}

/* ── Mobile bottom-sheet nav ────────────────────────────────── */

/* Backdrop (shared between mobile and wider) */
.note-outline-backdrop {
    position: fixed;
    inset: 0;
    z-index: 49;
    background: rgba(15, 20, 28, 0.44);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 280ms ease;
}
.note-outline-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
}

/* Floating trigger pill — hidden on desktop */
.note-outline-mobile-btn {
    display: none;
}

body.note-nav-open {
    overflow: hidden;
}

@media (max-width: 1040px) {
    body.note-outline-enabled .note-layout {
        width: min(100% - 1.5rem, 1180px);
        grid-template-columns: 1fr;
        /* no gap — outline is fixed out of flow */
    }

    /* Restore inline padding that the desktop rule zeroed out */
    body.note-outline-enabled main.note {
        padding-inline: clamp(1rem, 4vw, 1.7rem);
    }

    /* Outline: fixed at bottom, zero height so it doesn't push content */
    .note-outline {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 50;
        height: 0;
        overflow: visible;
        padding: 0;
        pointer-events: none;
    }

    /* Panel: slides up from bottom as a sheet */
    .note-outline-panel {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        max-height: 72vh;
        overflow-y: auto;
        padding: 1rem 1rem 1.75rem;
        border-radius: 20px 20px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        box-shadow: 0 -6px 32px rgba(0, 0, 0, 0.12);
        transform: translateY(100%);
        transition: transform 330ms cubic-bezier(0.22, 1, 0.36, 1);
        pointer-events: all;
    }

    .note-outline.is-open .note-outline-panel {
        transform: translateY(0);
    }

    /* Track: vertical list inside the sheet */
    .note-outline-track {
        display: grid;
        gap: 0.25rem;
        max-height: none;
        overflow-x: hidden;
        overflow-y: visible;
        padding: 0;
        scrollbar-width: none;
    }

    .note-outline-link {
        white-space: normal;
    }

    /* Show h3 items in the sheet */
    .note-outline-link[data-depth="3"] {
        display: block;
    }

    .note-outline-link.is-active {
        transform: translateX(4px);
    }

    /* Floating trigger pill */
    .note-outline-mobile-btn {
        display: inline-flex;
        align-items: center;
        gap: 0.45rem;
        position: fixed;
        bottom: 1.25rem;
        left: 50%;
        transform: translateX(-50%);
        z-index: 51;
        height: 2.4rem;
        padding: 0 1.15rem;
        border: 1px solid var(--border-strong);
        border-radius: 999px;
        background: color-mix(in srgb, var(--surface) 92%, transparent);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        color: var(--text);
        font-size: 0.8rem;
        font-weight: 700;
        font-family: inherit;
        cursor: pointer;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.13);
        white-space: nowrap;
        max-width: calc(100vw - 3rem);
        overflow: hidden;
        text-overflow: ellipsis;
        transition: background 160ms, border-color 160ms, box-shadow 160ms, transform 200ms;
    }

    .note-outline-mobile-btn:hover {
        background: var(--surface);
        border-color: var(--accent);
        box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
    }

    .note-outline-mobile-icon {
        font-size: 1rem;
        line-height: 1;
        flex-shrink: 0;
        transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
    }

    .note-outline-mobile-btn[aria-expanded="true"] {
        border-color: var(--accent);
    }

    .note-outline-mobile-btn[aria-expanded="true"] .note-outline-mobile-icon {
        transform: rotate(90deg);
    }
}

@media (max-width: 720px) {
    main.note {
        padding-top: 2.3rem;
        padding-bottom: 3.6rem;
    }

    main.note h1 {
        max-width: none;
    }
}

@media (max-width: 640px) {
    main.note {
        padding-inline: 1rem;
        gap: 1.1rem;
    }

    .note-back {
        max-width: calc(100vw - 2rem);
    }

    main.note p,
    main.note li {
        line-height: 1.72;
    }
}
