/* Xc 主题 - 文章目录树（日间/夜间自动适配，颜色取自主题变量） */

.Xc_toc {
    --toc-line: var(--classC);
    position: relative;
    background: var(--background);
    border-radius: var(--radius-wrap);
    box-shadow: var(--box-shadow);
    overflow: hidden;
    font-size: 13px;
}

/* 侧边栏形态：滚动时吸顶悬浮 */
.Xc_toc--aside {
    margin-bottom: 20px;
    position: -webkit-sticky;
    position: sticky;
    top: var(--toc-top, 90px);
    max-height: calc(100vh - var(--toc-top, 90px) - 20px);
    display: flex;
    flex-direction: column;
    transition: top 0.35s;
    z-index: 9;
}

/* 目录本身不跟随页面滚走，长目录在面板内部滚动 */
.Xc_toc--aside .Xc_toc__body {
    max-height: none;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/**
 * 目录占用吸顶位置后，主题默认让侧边栏最后一项吸顶（.Xc_aside_item:last-child），
 * 两者会重叠，这里把最后一项的吸顶取消。
 */
.Xc_aside.Xc_aside--has-toc > .Xc_aside_item:last-child {
    position: static;
    top: auto;
}

/**
 * sticky 生效的前提：父容器（.Xc_aside）必须比目录高，滚动时才有“粘住”的空间。
 * .Xc_total 是 flex 容器，侧栏默认 align-self: stretch 已经会撑满整行高度，
 * 但若主题或其它样式覆盖成 flex-start，这里强制恢复。
 */
.Xc_aside.Xc_aside--has-toc {
    align-self: stretch;
}

/* 正文内嵌形态：同样吸顶，避免长文读到中段后失去导航 */
.Xc_toc--inline {
    margin-bottom: 20px;
    position: -webkit-sticky;
    position: sticky;
    top: var(--toc-top-inline, 72px);
    max-height: 50vh;
    display: flex;
    flex-direction: column;
    z-index: 8;
    /* 吸顶后会盖住正文，用近乎不透明的底色避免文字透出 */
    background: var(--background);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.Xc_toc--inline .Xc_toc__body {
    max-height: none;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.Xc_toc__head {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 45px;
    padding: 0 15px;
    border-bottom: 1px solid var(--classC);
    color: var(--main);
    font-size: 15px;
    font-weight: 500;
}

.Xc_toc__icon {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    color: var(--theme);
}

.Xc_toc__title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.Xc_toc__count {
    flex-shrink: 0;
    min-width: 20px;
    height: 18px;
    line-height: 18px;
    padding: 0 6px;
    border-radius: 9px;
    background: var(--classD);
    color: var(--minor);
    font-size: 11px;
    font-weight: 400;
    text-align: center;
}

.Xc_toc__action {
    flex-shrink: 0;
    border: none;
    background: none;
    padding: 0;
    color: var(--theme);
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    transition: opacity 0.25s;
}

.Xc_toc__action:hover {
    opacity: 0.75;
}

.Xc_toc__action[data-state='expanded'] {
    color: var(--minor);
}

/* 阅读进度条 */
.Xc_toc__progress {
    height: 2px;
    background: var(--classD);
    overflow: hidden;
}

.Xc_toc__progress > i {
    display: block;
    width: 0;
    height: 100%;
    background: var(--theme);
    transition: width 0.15s linear;
}

/* 列表 */
.Xc_toc__body {
    max-height: 60vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    padding: 8px 0;
}

.Xc_toc__body::-webkit-scrollbar {
    width: 6px;
}

.Xc_toc__body::-webkit-scrollbar-thumb {
    border-radius: 3px;
    background: var(--seat);
}

.Xc_toc__list,
.Xc_toc__list .Xc_toc__sub {
    margin: 0;
    padding: 0;
    list-style: none;
}

.Xc_toc__item {
    position: relative;
    list-style: none;
}

.Xc_toc__row {
    display: flex;
    align-items: flex-start;
    line-height: 1.5;
}

.Xc_toc__link {
    display: block;
    flex: 1;
    min-width: 0;
    padding: 6px 15px 6px 0;
    color: var(--routine);
    position: relative;
    word-break: break-word;
    transition: color 0.25s, background 0.25s;
}

.Xc_toc__link:hover {
    color: var(--theme);
}

/* 层级缩进 + 左侧引导线 */
.Xc_toc__list > .Xc_toc__item > .Xc_toc__row > .Xc_toc__link {
    padding-left: 15px;
}

.Xc_toc__sub {
    display: none;
    border-left: 1px solid var(--toc-line);
    margin-left: 15px;
}

.Xc_toc__item.is-open > .Xc_toc__sub {
    display: block;
}

.Xc_toc__sub > .Xc_toc__item > .Xc_toc__row > .Xc_toc__link {
    padding-left: 12px;
    font-size: 12.5px;
}

.Xc_toc__sub .Xc_toc__sub > .Xc_toc__item > .Xc_toc__row > .Xc_toc__link {
    padding-left: 12px;
    font-size: 12px;
    color: var(--minor);
}

/* 折叠箭头 */
.Xc_toc__toggle {
    flex-shrink: 0;
    width: 22px;
    height: 30px;
    margin-left: auto;
    border: none;
    background: none;
    padding: 0;
    color: var(--seat);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: color 0.25s;
}

.Xc_toc__item.has-child > .Xc_toc__row > .Xc_toc__toggle {
    display: flex;
}

.Xc_toc__toggle svg {
    width: 11px;
    height: 11px;
    transition: transform 0.3s;
}

.Xc_toc__item.is-open > .Xc_toc__row > .Xc_toc__toggle svg {
    transform: rotate(90deg);
}

.Xc_toc__toggle:hover {
    color: var(--theme);
}

/* 高亮当前节 */
.Xc_toc__link.is-active {
    color: var(--theme);
    font-weight: 500;
}

.Xc_toc__link.is-active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 0 2px 2px 0;
    background: var(--theme);
}

.Xc_toc__sub .Xc_toc__link.is-active::before {
    left: 0;
    top: 7px;
    bottom: 7px;
    width: 2px;
}

/* 文章较浅、节数不足时 */
.Xc_toc__empty {
    display: none;
    padding: 18px 15px;
    text-align: center;
    color: var(--minor);
}

.Xc_toc.is-empty .Xc_toc__empty {
    display: block;
}

.Xc_toc.is-empty .Xc_toc__body,
.Xc_toc.is-empty .Xc_toc__progress,
.Xc_toc.is-empty .Xc_toc__action {
    display: none;
}

/* JS 未执行前不闪现空壳 */
.Xc_toc--pending .Xc_toc__body {
    display: none;
}

/* 内嵌形态的标题栏吸顶（避免长文中滚动后丢失操作入口） */
.Xc_toc--inline .Xc_toc__head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--background);
    backdrop-filter: blur(6px);
}

/* 折叠时限制高度，避免目录过长顶掉正文 */
.Xc_toc--inline .Xc_toc__body {
    max-height: 45vh;
}

/* 移动端抽屉 */
.Xc_toc_mobile {
    display: none;
}

.Xc_toc_mobile.is-off {
    display: none !important;
}

/* 抽屉打开时锁定背景滚动 */
html.Xc_toc_lock,
html.Xc_toc_lock body {
    overflow: hidden;
}

.Xc_toc_fab {
    position: fixed;
    right: 16px;
    bottom: 90px;
    z-index: 998;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--background);
    color: var(--main);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.25s, color 0.25s;
}

.Xc_toc_fab:active {
    transform: scale(0.94);
}

.Xc_toc_fab.is-hidden {
    display: none;
}

.Xc_toc_drawer {
    position: fixed;
    inset: 0;
    z-index: 1200;
    visibility: hidden;
    pointer-events: none;
}

.Xc_toc_drawer.is-open {
    visibility: visible;
    pointer-events: auto;
}

.Xc_toc_drawer__mask {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    transition: opacity 0.3s;
}

.Xc_toc_drawer.is-open .Xc_toc_drawer__mask {
    opacity: 1;
}

.Xc_toc_drawer__panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 82%;
    max-width: 360px;
    background: var(--background);
    box-shadow: -6px 0 24px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    transform: translate3d(100%, 0, 0);
    transition: transform 0.3s;
}

.Xc_toc_drawer.is-open .Xc_toc_drawer__panel {
    transform: translate3d(0, 0, 0);
}

.Xc_toc_drawer__panel .Xc_toc__body {
    flex: 1;
    max-height: none;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.Xc_toc__close {
    flex-shrink: 0;
    border: none;
    background: none;
    padding: 4px;
    color: var(--minor);
    cursor: pointer;
    display: flex;
    align-items: center;
}

.Xc_toc__close:hover {
    color: var(--theme);
}

/* 桌面端隐藏移动入口；移动端隐藏内嵌/侧栏面板，只保留抽屉 */
@media (max-width: 992px) {
    .Xc_toc_mobile {
        display: block;
    }

    .Xc_toc_mobile.is-off {
        display: none !important;
    }

    .Xc_toc--aside,
    .Xc_toc--inline {
        display: none !important;
    }
}

@media (max-width: 768px) {
    .Xc_toc_fab {
        right: 12px;
        bottom: 78px;
        width: 40px;
        height: 40px;
    }

    .Xc_toc_drawer__panel .Xc_toc__head {
        height: 48px;
    }

    .Xc_toc_drawer__panel .Xc_toc__link {
        padding-top: 8px;
        padding-bottom: 8px;
    }
}

/* 打印时不需要目录 */
@media print {
    .Xc_toc,
    .Xc_toc_mobile {
        display: none !important;
    }
}
