:root {
    --toc-sticky-top: 5.75rem;
}

.post-body-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
    gap: 3.5rem;
    align-items: start;
    width: 100%;
}

.post-body-layout--no-toc {
    display: block;
}

.post-body-layout .post-content {
    max-width: none;
}

/* Sticky on the grid item so it tracks the full post height */
.post-toc {
    position: sticky;
    top: var(--toc-sticky-top);
    align-self: start;
    z-index: 10;
}

.post-toc-desktop {
    position: relative;
    max-height: calc(100vh - var(--toc-sticky-top) - 1.5rem);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.98) 0%, rgba(247, 246, 243, 0.95) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow:
        0 1px 2px rgba(17, 17, 24, 0.04),
        0 12px 40px rgba(17, 17, 24, 0.07);
    backdrop-filter: blur(12px);
}

.post-toc-desktop::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    background: linear-gradient(180deg, var(--accent) 0%, rgba(91, 92, 246, 0.35) 100%);
    pointer-events: none;
}

.post-toc-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1.15rem 1.25rem 0.85rem 1.35rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.post-toc-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--accent-light);
    color: var(--accent);
    flex-shrink: 0;
}

.post-toc-title {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--text);
}

.post-toc-nav {
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.85rem 0.75rem 1.1rem 1rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(91, 92, 246, 0.35) transparent;
}

.post-toc-nav::-webkit-scrollbar {
    width: 5px;
}

.post-toc-nav::-webkit-scrollbar-thumb {
    background: rgba(91, 92, 246, 0.3);
    border-radius: 999px;
}

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

.post-toc-item {
    margin: 0.15rem 0;
}

.post-toc-item a {
    display: block;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
    color: var(--muted);
    text-decoration: none;
    border-radius: 8px;
    border-left: 2px solid transparent;
    transition: color 0.2s, background 0.2s, border-color 0.2s, transform 0.15s;
}

.post-toc-item a:hover {
    color: var(--text);
    background: rgba(91, 92, 246, 0.06);
}

.post-toc-item a.is-active {
    color: var(--accent);
    background: var(--accent-light);
    border-left-color: var(--accent);
    font-weight: 600;
}

.post-toc-level-2 a {
    font-weight: 600;
    color: var(--text);
}

.post-toc-level-3 a {
    padding-left: 1.35rem;
    font-size: 0.84rem;
}

.post-toc-level-4 a {
    padding-left: 1.85rem;
    font-size: 0.8rem;
}

.post-toc-level-5 a,
.post-toc-level-6 a {
    padding-left: 2.25rem;
    font-size: 0.78rem;
}

/* Inline shortcode insert */
.post-toc-inline {
    margin: 2rem 0 2.5rem;
}

.post-toc-inline .post-toc-desktop {
    max-height: none;
}

/* Mobile */
.post-toc-mobile {
    display: none;
    margin-bottom: 1.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.post-toc-mobile-summary {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1rem 1.25rem;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    list-style: none;
    color: var(--text);
}

.post-toc-mobile-summary::before {
    content: "";
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--accent);
    border-bottom: 2px solid var(--accent);
    transform: rotate(45deg);
    transition: transform 0.2s;
    margin-right: 0.15rem;
}

.post-toc-mobile[open] .post-toc-mobile-summary::before {
    transform: rotate(-135deg);
    margin-top: 4px;
}

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

.post-toc-mobile .post-toc-nav {
    padding: 0.5rem 0.75rem 1rem 1rem;
    border-top: 1px solid var(--border);
    max-height: 50vh;
}

.post-content h2[id],
.post-content h3[id],
.post-content h4[id],
.post-content h5[id],
.post-content h6[id] {
    scroll-margin-top: var(--toc-sticky-top);
}

@media (max-width: 1024px) {
    .post-body-layout {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .post-toc {
        position: static;
        order: -1;
        margin-bottom: 0.5rem;
    }

    .post-toc-desktop {
        display: none;
    }

    .post-toc-mobile {
        display: block;
    }
}
