﻿/*******************************************************************************
TOC + READING PROGRESS
文首目录卡片（默认折叠）
*******************************************************************************/

:root {
    --toc-bg: rgba(255, 255, 248, 0.9);
    --toc-border: rgba(96, 96, 96, 0.22);
    --toc-text: #333;
    --toc-muted: #666;
    --toc-hover: rgba(118, 118, 118, 0.11);
    --toc-active: rgba(120, 120, 120, 0.14);
    --toc-accent: #7a7a7a;
    --toc-accent-soft: rgba(122, 122, 122, 0.2);
    --toc-shadow: 0 8px 22px rgba(15, 15, 15, 0.055), 0 1px 3px rgba(15, 15, 15, 0.06);
    --toc-chip-bg: rgba(122, 122, 122, 0.085);
    --reading-progress: linear-gradient(90deg, #6f8fb8 0%, #6ea78e 100%);
}

html[data-theme="dark"] {
    --toc-bg: rgba(30, 30, 30, 0.9);
    --toc-border: rgba(178, 178, 178, 0.22);
    --toc-text: #d2d2d2;
    --toc-muted: #a8a8a8;
    --toc-hover: rgba(188, 188, 188, 0.12);
    --toc-active: rgba(168, 168, 168, 0.2);
    --toc-accent: #a8a8a8;
    --toc-accent-soft: rgba(168, 168, 168, 0.22);
    --toc-shadow: 0 10px 24px rgba(0, 0, 0, 0.22), 0 1px 4px rgba(0, 0, 0, 0.24);
    --toc-chip-bg: rgba(176, 176, 176, 0.12);
    --reading-progress: linear-gradient(90deg, #7ea9df 0%, #7bc49e 100%);
}

.reading-progress {
    position: fixed;
    top: calc(var(--nav-divider-y, 0px) + 1px);
    left: 0;
    right: 0;
    height: 2px;
    z-index: 140;
    pointer-events: none;
}

.reading-progress__bar {
    width: 100%;
    height: 100%;
    transform: scaleX(0);
    transform-origin: left center;
    background: var(--reading-progress);
    opacity: 0.88;
    transition: transform 120ms linear, opacity 220ms ease;
}

.article-toc {
    position: relative;
    width: 55%;
    max-width: 55%;
    margin: 0.8rem 0 1.35rem;
    border-radius: 12px;
    border: 1px solid var(--toc-border);
    background: var(--toc-bg);
    box-shadow: var(--toc-shadow);
    overflow: hidden;
    box-sizing: border-box;
    float: none;
    clear: none;
    left: 0;
    animation: toc-card-in 320ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.article-toc::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--toc-accent-soft);
    opacity: 1;
}

.article-toc__toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    border: 0;
    background: transparent;
    color: var(--toc-text);
    cursor: pointer;
    min-height: 2.75rem;
    padding: 0.72rem 0.8rem 0.72rem;
    text-align: left;
    transition: background-color 180ms ease, color 180ms ease;
}

.article-toc__toggle:hover,
.article-toc__toggle:focus-visible {
    background: var(--toc-hover);
    outline: none;
}

.article-toc__title-wrap {
    display: flex;
    align-items: center;
    gap: 0.56rem;
    min-width: 0;
}

.article-toc__title {
    margin: 0;
    font-size: 0.78rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--toc-muted);
    font-weight: 700;
    white-space: nowrap;
}

.article-toc__meta {
    color: var(--toc-text);
    font-size: 0.72rem;
    line-height: 1;
    opacity: 0.88;
    white-space: nowrap;
    border: 1px solid var(--toc-border);
    background: var(--toc-chip-bg);
    border-radius: 999px;
    padding: 0.2rem 0.44rem;
}

.article-toc__chevron {
    width: 1.35rem;
    height: 1.35rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 1px solid var(--toc-border);
    background: var(--toc-chip-bg);
    font-size: 0.76rem;
    color: var(--toc-muted);
    transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1), background-color 180ms ease, border-color 180ms ease;
}

.article-toc__panel {
    display: grid;
    grid-template-rows: 1fr;
    opacity: 1;
    transition: grid-template-rows 300ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 220ms ease;
}

.article-toc__panel-inner {
    overflow: hidden;
    padding: 0.08rem 0.62rem 0.62rem;
    border-top: 1px solid rgba(127, 127, 127, 0.16);
    transition: padding 220ms ease, border-color 220ms ease;
}

.article-toc.is-collapsed .article-toc__panel {
    grid-template-rows: 0fr;
    opacity: 0;
    pointer-events: none;
}

.article-toc.is-collapsed .article-toc__panel-inner {
    padding-top: 0;
    padding-bottom: 0;
    border-top-color: transparent;
}

.article-toc.is-collapsed .article-toc__chevron {
    transform: rotate(-90deg);
}

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

.article-toc__item {
    margin: 0;
    padding: 0.06rem 0;
}

.article-toc__link {
    position: relative;
    display: block;
    border-radius: 8px;
    color: var(--toc-text);
    text-decoration: none !important;
    padding: 0.34rem 0.52rem 0.36rem 0.78rem;
    line-height: 1.34;
    font-size: 0.88rem;
    transition: background-color 180ms ease, color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.article-toc__link::before {
    content: "";
    position: absolute;
    left: 0.36rem;
    top: 50%;
    width: 0.28rem;
    height: 0.28rem;
    border-radius: 999px;
    background: rgba(126, 126, 126, 0.5);
    transform: translateY(-50%) scale(0.85);
    transition: transform 180ms ease, background-color 180ms ease, opacity 180ms ease;
    opacity: 0.9;
}

.article-toc__link:hover,
.article-toc__link:focus-visible {
    background: var(--toc-hover);
    transform: translateX(2px);
    outline: none;
    box-shadow: inset 0 0 0 1px rgba(132, 132, 132, 0.16);
}

.article-toc__link.is-active {
    background: var(--toc-active);
    color: var(--toc-text);
    font-weight: 600;
}

.article-toc__link.is-active::before {
    background: rgba(110, 110, 110, 0.95);
    transform: translateY(-50%) scale(1);
    opacity: 1;
}

.article-toc__link[data-level="4"] {
    padding-left: 1.22rem;
    font-size: 0.86rem;
}

.article-toc__link[data-level="4"]::before {
    left: 0.72rem;
}

.article-toc__link[data-level="5"] {
    padding-left: 1.62rem;
    font-size: 0.85rem;
}

.article-toc__link[data-level="5"]::before {
    left: 1.12rem;
}

@media (max-width: 760px) {
    .article-toc {
        width: 100%;
        max-width: 100%;
        border-radius: 10px;
        margin-bottom: 1.1rem;
    }

    .article-toc__toggle {
        padding: 0.66rem 0.7rem 0.6rem;
    }

    .article-toc__panel-inner {
        padding: 0.06rem 0.52rem 0.56rem;
    }

    .article-toc__link {
        padding-right: 0.45rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .article-toc,
    .article-toc__panel,
    .article-toc__chevron,
    .article-toc__link,
    .reading-progress__bar {
        animation: none !important;
        transition: none !important;
    }
}

@keyframes toc-card-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

article section h2,
article section h3,
article section h4,
article section h5 {
    scroll-margin-top: calc(var(--nav-divider-y, 0px) + 16px);
}
