/* Article TOC styles - glass card, capsule, drawer */

:root {
    --toc-panel-bg: var(--bg);
    --toc-panel-width: 220px;
}

[data-theme='dark'] {
    --toc-panel-bg: var(--bg);
}

.article-toc {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    z-index: calc(var(--z-dock, 10000) + 10);
    pointer-events: none;
}

.article-toc__panel {
    pointer-events: auto;
    border-radius: var(--radius-xl);
    background: var(--bg);
    border: 1px solid var(--panel-border);
    box-shadow: var(--panel-shadow);
    color: var(--fg);
    font-family: var(--font-ui);
    overflow-x: hidden;
}

.article-toc__panel--fixed {
    position: fixed;
    top: 50%;
    left: var(--toc-panel-left, 0);
    width: var(--toc-panel-width, 240px);
    max-height: calc(100vh - 180px);
    max-height: calc(100dvh - 180px);
    overflow-y: auto;
    transform: translateY(-50%);
    z-index: var(--z-float, 1500);
}

.toc-panel-enter-from,
.toc-panel-leave-to {
    opacity: 0;
    transform: translateY(-50%) translateX(20px);
}

.toc-panel-enter-to,
.toc-panel-leave-from {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.toc-panel-enter-active,
.toc-panel-leave-active {
    transition:
        transform 0.25s var(--curve-snap),
        opacity 0.25s var(--curve-snap);
}

.article-toc__header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg);
    border-bottom: 1px solid color-mix(in srgb, var(--panel-border) 50%, transparent);
}

.article-toc__title {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}

.article-toc__close {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--fg);
    cursor: pointer;
    transition: background-color 0.2s var(--curve-snap);
}

.article-toc__close::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 44px;
    height: 44px;
    transform: translate(-50%, -50%);
    pointer-events: auto;
}

.article-toc__close:hover {
    background: color-mix(in srgb, var(--fg) 8%, transparent);
}

.article-toc__list {
    position: relative;
    list-style: none;
    padding: 10px 14px 14px;
    margin: 0;
}

.article-toc__active-marker {
    display: none;
}

.article-toc__item {
    position: relative;
    z-index: 1;
    padding: 3px 0 3px 12px;
    font-size: 0.9rem;
    line-height: 1.35;
    border-radius: var(--radius-sm);
    opacity: var(--toc-item-opacity, 1);
    transition:
        opacity 0.2s var(--curve-snap),
        background-color 0.2s var(--curve-snap);
}

.article-toc__item:hover {
    background: color-mix(in srgb, var(--fg) 4%, transparent);
    opacity: 1;
}

.article-toc__item--level-3 {
    padding-left: 22px;
    font-size: 0.84rem;
}

/* Scroll-driven section accordion. max-height animates the list's actual flow,
 * while the short translate/fade masks text reflow. The asymmetric easing is
 * deliberately fast at the start and soft at rest, avoiding a mechanical feel. */
.toc-subitem-enter-active,
.toc-subitem-leave-active {
    overflow: hidden;
    transform-origin: top left;
    transition:
        max-height 220ms var(--curve-snap),
        padding-top 220ms var(--curve-snap),
        padding-bottom 220ms var(--curve-snap),
        opacity 140ms var(--curve-press),
        transform 220ms var(--curve-snap);
    will-change: max-height, opacity, transform;
}

.toc-subitem-enter-active {
    max-height: 48px;
}

.toc-subitem-leave-active {
    max-height: 48px;
}

.toc-subitem-enter-from,
.toc-subitem-leave-to {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    transform: translate3d(0, -6px, 0) scale(0.985);
}

/* Vue's FLIP move phase keeps surrounding rows gliding into their new places
 * while one section closes and the next opens. */
.toc-subitem-move {
    transition: transform 240ms var(--curve-snap);
}

.article-toc__item--active {
    background: color-mix(in srgb, var(--accent-blue) 12%, transparent);
    opacity: 1;
}

.article-toc__item--active::before {
    content: '';
    position: absolute;
    left: 2px;
    top: 4px;
    bottom: 4px;
    width: 3px;
    border-radius: 2px;
    background: var(--accent-blue);
}

.article-toc__item--active .article-toc__link {
    font-weight: 700;
    color: var(--accent-blue);
}

.article-toc__link {
    display: flex;
    align-items: center;
    min-height: 34px;
    margin: -2px 0;
    padding: 2px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-decoration: none;
    color: inherit;
    transition: color 0.18s var(--curve-snap);
}

.article-toc__capsule {
    position: fixed;
    right: max(20px, env(safe-area-inset-right));
    /* 目录胶囊排布在文章 dock（Aa + 返回顶部）上方，与 dock 组成一个右下角堆叠。 */
    bottom: calc(
        var(--article-dock-bottom, max(20px, env(safe-area-inset-bottom))) + var(--article-dock-height, 98px) +
            var(--article-dock-gap, 10px)
    );
    z-index: calc(var(--z-dock, 10000) + 10);
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 44px;
    padding: 0 16px;
    border-radius: 22px;
    border: 1px solid color-mix(in srgb, var(--fg) 14%, transparent);
    background: var(--bg);
    box-shadow: var(--article-dock-shadow, var(--panel-shadow));
    color: var(--fg);
    font-family: var(--font-ui);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    max-width: 260px;
}

.toc-capsule-enter-from,
.toc-capsule-leave-to {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
}

.toc-capsule-enter-to,
.toc-capsule-leave-from {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.toc-capsule-enter-active,
.toc-capsule-leave-active {
    transition:
        transform 0.25s var(--curve-snap),
        opacity 0.25s var(--curve-snap);
}

.article-toc__capsule-text {
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.article-toc__overlay {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-dock, 10000) + 5);
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(2px);
    pointer-events: auto;
    opacity: 1;
}

.toc-overlay-enter-from,
.toc-overlay-leave-to {
    opacity: 0;
}

.toc-overlay-enter-to,
.toc-overlay-leave-from {
    opacity: 1;
}

.toc-overlay-enter-active,
.toc-overlay-leave-active {
    transition: opacity 0.2s var(--curve-snap);
}

.article-toc__panel--drawer {
    position: fixed;
    top: env(safe-area-inset-top, 0);
    right: env(safe-area-inset-right, 0);
    bottom: env(safe-area-inset-bottom, 0);
    width: min(360px, 82vw);
    max-width: 360px;
    max-height: 100dvh;
    overflow-y: auto;
    border-radius: 0;
    border-right: none;
    border-top: none;
    border-bottom: none;
    z-index: calc(var(--z-dock, 10000) + 10);
    transform: translateX(0);
}

.article-toc__panel--drawer::-webkit-scrollbar,
.article-toc__panel--fixed::-webkit-scrollbar {
    display: none;
}

.article-toc__panel--drawer,
.article-toc__panel--fixed {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.toc-drawer-enter-from,
.toc-drawer-leave-to {
    transform: translateX(100%);
}

.toc-drawer-enter-to,
.toc-drawer-leave-from {
    transform: translateX(0);
}

.toc-drawer-enter-active,
.toc-drawer-leave-active {
    transition: transform 0.25s var(--curve-snap);
}

.article-toc__capsule:focus-visible,
.article-toc__close:focus-visible,
.article-toc__link:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .article-toc__panel,
    .article-toc__capsule,
    .article-toc__link,
    .article-toc__item,
    .article-toc__active-marker,
    .toc-subitem-enter-active,
    .toc-subitem-leave-active,
    .toc-subitem-move {
        transition: none;
        animation: none;
        will-change: auto;
    }

    .toc-panel-enter-active,
    .toc-panel-leave-active,
    .toc-capsule-enter-active,
    .toc-capsule-leave-active,
    .toc-overlay-enter-active,
    .toc-overlay-leave-active,
    .toc-drawer-enter-active,
    .toc-drawer-leave-active {
        transition: none;
    }
}

/* ===== h2 折叠/展开切换 ===== */
.article-toc__item.has-children .article-toc__link {
    padding-right: 26px;
}

.article-toc__toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted, #666);
    cursor: pointer;
    opacity: 0.65;
    transition:
        opacity 0.2s var(--curve-snap),
        background-color 0.2s var(--curve-snap);
}

/* 扩展触控热区至 44px 避免误触标题链接 */
.article-toc__toggle::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 44px;
    height: 44px;
    transform: translate(-50%, -50%);
    pointer-events: auto;
}

.article-toc__toggle:hover,
.article-toc__toggle:focus-visible {
    opacity: 1;
    background: color-mix(in srgb, var(--fg) 8%, transparent);
    outline: none;
}

.article-toc__item--active .article-toc__toggle {
    color: var(--accent-blue, #3e59ff);
    opacity: 0.95;
}

.article-toc__toggle svg {
    transition: transform 0.2s var(--curve-snap);
}

/* Collapsed: chevron points right (▾ rotates to ▸). */
.article-toc__toggle--collapsed svg {
    transform: rotate(-90deg);
}

.article-toc__toggle:focus-visible {
    outline: 2px solid var(--accent-blue, #3e59ff);
    outline-offset: 1px;
}
