/* Post TOC — 居中正文 + 响应式右侧目录 */

.toc-layout {
    --case-toc-sidebar-width: 260px;
    --case-toc-accent: #0052d9;
    --case-toc-sticky-top: 96px;
    position: relative;
    display: flex;
    align-items: start;
    width: 100%;
    max-width: 100%;
    margin: 0;
}

.toc-layout-content {
    width: 100%;
    min-width: 0;
    padding: 0;
    box-sizing: border-box;
    flex: 1;
    margin-inline: auto;
}

.toc-layout-content :is(h1, h2, h3, h4, h5)[id] {
    scroll-margin-top: var(--case-toc-sticky-top);
}
.toc-layout-content :is(h1, h2, h3, h4, h5)[id]:first-child {
    margin-top: 0;
}

.toc-layout-sidebar {
    position: sticky;
    isolation: isolate;
    z-index: 20;
    top: var(--case-toc-sticky-top);
    max-width: min(var(--case-toc-sidebar-width), calc(100% - 24px));
    margin-left: 24px;
    max-height: calc(100vh - var(--case-toc-sticky-top) - 24px);
}

.case-toc {
    box-sizing: border-box;
    width: 100%;
    max-height: calc(100vh - var(--case-toc-sticky-top) - 24px);
    padding: 16px 18px;
    overflow-y: auto;
    overscroll-behavior: contain;
    color: #333;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.1);
    scrollbar-width: thin;
}

.case-toc__heading {
    display: flex;
    align-items: center;
    min-width: 0;
    margin-bottom: 10px;
    padding-left: 36px;
}

.case-toc__title {
    display: block;
    min-width: 0;
    overflow: hidden;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.4;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.case-toc__toggle {
    position: absolute;
    z-index: 2;
    top: 14px;
    left: 12px;
    display: grid;
    flex: 0 0 28px;
    place-items: center;
    width: 28px;
    height: 28px;
    padding: 4px 0 0;
    color: var(--case-toc-accent);
    background: rgba(0, 82, 217, 0.08);
    cursor: pointer;
    box-sizing: border-box;
    border: 0;
    border-radius: 5px;
    transition: color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.case-toc__toggle:hover,
.case-toc__toggle:focus-visible {
    color: var(--case-toc-accent);
    background: rgba(0, 82, 217, 0.2);
}

.case-toc__toggle:focus-visible {
    outline: 2px solid rgba(0, 82, 217, 0.35);
    outline-offset: 1px;
}

.case-toc__toggle-icon {
    font-size: 22px;
    font-weight: 400;
    line-height: 1;
}

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

.case-toc .case-toc__item {
    padding: 6px 0;
    margin: 0;
    overflow: hidden;
    font-size: 12px;
    line-height: 1.5;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-left: 2px solid #b8b8b8;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.case-toc .case-toc__item--level-1 {
    font-size: 16px;
    font-weight: 700;
}

.case-toc .case-toc__item--level-2 {
    padding-left: 14px;
    font-size: 14px;
}

.case-toc .case-toc__item--level-3 {
    padding-left: 28px;
}

.case-toc .case-toc__item--level-4 {
    padding-left: 42px;
}

.case-toc .case-toc__item--level-5 {
    padding-left: 56px;
}

.case-toc .case-toc__link {
    display: block;
    overflow: hidden;
    color: inherit;
    text-decoration: none;
    text-overflow: ellipsis;
    transition: color 0.2s ease;
}

.case-toc .case-toc__link:hover,
.case-toc .case-toc__link:focus-visible {
    color: var(--case-toc-accent);
}

.case-toc .case-toc__item--active {
    border-color: var(--case-toc-accent);
    background: rgba(0, 82, 217, 0.06);
}

.case-toc .case-toc__item--active .case-toc__link {
    color: var(--case-toc-accent);
    font-weight: 600;
}

.case-toc__screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (min-width: 1280px) {
    .toc-layout:not(.toc-layout--open) .case-toc {
        display: none;
    }
}

/* M：目录以右侧抽屉显示，不占据正文宽度。 */
@media (max-width: 1279px) {
    .toc-layout {
        display: block;
    }

    .toc-layout-sidebar {
        position: fixed;
        z-index: 1001;
        top: 96px;
        right: 16px;
        bottom: auto;
        width: min(360px, calc(100vw - 48px));
        max-height: min(70vh, 560px);
        margin: 0;
        pointer-events: none;
    }

    .case-toc {
        height: auto;
        max-height: min(70vh, 560px);
        border-radius: 10px;
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
        visibility: hidden;
        transform: translateX(102%);
        opacity: 0;
        pointer-events: none;
        transition: transform 0.22s ease, opacity 0.18s ease, visibility 0s linear 0.22s;
    }

    .case-toc__toggle {
        z-index: 1002;
        top: 14px;
        right: auto;
        left: 14px;
        pointer-events: auto;
    }

    .toc-layout:not(.toc-layout--open) .case-toc__toggle {
        top: 0;
        right: 0;
        left: auto;
        /* width: 44px;
        height: 44px; */
        color: #fff;
        background: var(--case-toc-accent);
        /* border-radius: 22px; */
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
    }

    .toc-layout.toc-layout--open .case-toc {
        visibility: visible;
        transform: translateX(0);
        opacity: 1;
        pointer-events: auto;
        transition-delay: 0s;
    }

}

/* S：悬浮按钮 + 小型 popover；鼠标 hover、键盘 focus 和触摸点击均可用。 */
@media (max-width: 767px) {
    .toc-layout-sidebar {
        top: 50%;
        right: 12px;
        bottom: auto;
        width: 44px;
        height: 44px;
        max-height: none;
    }

    .toc-layout.toc-layout--open .toc-layout-sidebar {
        width: min(320px, calc(100vw - 24px));
        height: min(60vh, 492px);
    }

    .case-toc__toggle {
        top: 0;
        right: 0;
        left: auto;
    }

    .case-toc {
        position: absolute;
        top: 52px;
        right: 0;
        width: min(320px, calc(100vw - 24px));
        height: auto;
        max-height: min(60vh, 440px);
        border-radius: 10px;
        box-shadow: 0 8px 28px rgba(0, 0, 0, 0.2);
        transform: translateX(12px) scale(0.98);
        transform-origin: top right;
        transition: transform 0.16s ease, opacity 0.16s ease, visibility 0s linear 0.18s;
    }

    .toc-layout.toc-layout--open .case-toc,
    .toc-layout-sidebar:focus-within .case-toc {
        visibility: visible;
        transform: translateX(0) scale(1);
        opacity: 1;
        pointer-events: auto;
        transition-delay: 0s;
    }

}

@media (max-width: 767px) and (hover: hover) {
    .toc-layout-sidebar:hover .case-toc {
        visibility: visible;
        transform: translateX(0) scale(1);
        opacity: 1;
        pointer-events: auto;
        transition-delay: 0s;
    }
}

@media (prefers-reduced-motion: reduce) {
    .case-toc,
    .case-toc .case-toc__item,
    .case-toc .case-toc__link {
        scroll-behavior: auto;
        transition: none;
    }
}
