/**
 * ThreadToc 帖子文章目录 - 样式（帖子页，手动模式）
 * ------------------------------------------------------------------
 * 目录卡片由服务端把正文里的 [toc] 块渲染而来（.honor-toc--inline），
 * 仅保留内嵌卡片所需样式；所有类名以 honor-toc 为前缀避免冲突，
 * 颜色通过 .honor-toc 上的 CSS 变量定义，主题可覆盖微调。
 * 无 JS 时目录照常可用：原生锚点跳转 + :target 高亮（优雅降级）。
 */

.honor-toc {
    /* 主题可覆盖的样式变量 */
    --htoc-primary: #3672c4;
    --htoc-primary-soft: #eaf2fc;
    --htoc-bg: #ffffff;
    --htoc-border: #e5e5e5;
    --htoc-text: #333333;
    --htoc-muted: #888888;
    --htoc-hover-bg: #f5f7fa;
    --htoc-radius: 8px;
    --htoc-flash: #fff3c4;
    --htoc-scroll-offset: 56px;

    box-sizing: border-box;
    font-size: 13px;
    line-height: 1.5;
    color: var(--htoc-text);
}

.honor-toc *,
.honor-toc *::before,
.honor-toc *::after {
    box-sizing: border-box;
}

/* ===================== 内嵌卡片（正文流内，随 [toc] 块位置展示） ===================== */

.honor-toc--inline {
    background: var(--htoc-bg);
    border: 1px solid var(--htoc-border);
    border-radius: var(--htoc-radius);
    margin: 0 0 16px;
    overflow: hidden;
}

/* ===================== 头部（标题 + 折叠按钮，点击整行切换） ===================== */

.honor-toc__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    border-bottom: 1px solid var(--htoc-border);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}

.honor-toc__toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--htoc-muted);
    cursor: pointer;
}

.honor-toc__toggle:hover {
    background: var(--htoc-hover-bg);
    color: var(--htoc-text);
}

.honor-toc__toggle-icon {
    display: inline-block;
    transition: transform 0.2s ease;
    font-size: 12px;
}

.honor-toc.is-collapsed .honor-toc__toggle-icon {
    transform: rotate(-90deg);
}

/* 折叠态：隐藏目录体 */
.honor-toc.is-collapsed .honor-toc__panel {
    display: none;
}

.honor-toc.is-collapsed .honor-toc__header {
    border-bottom-color: transparent;
}

/* ===================== 目录列表 ===================== */

.honor-toc__panel {
    max-height: min(56vh, 420px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.honor-toc__panel::-webkit-scrollbar {
    width: 6px;
}

.honor-toc__panel::-webkit-scrollbar-thumb {
    background: #d5d9de;
    border-radius: 3px;
}

.honor-toc__list,
.honor-toc__sublist {
    list-style: none !important;
    margin: 0 !important;
    padding: 4px 0 !important;
}

/* 长标题截断：单行省略，完整文本见 title 属性 */
.honor-toc__link {
    display: block;
    padding: 5px 12px;
    color: var(--htoc-text);
    text-decoration: none !important;
    border-left: 2px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.honor-toc__link:hover {
    background: var(--htoc-hover-bg);
    color: var(--htoc-primary);
}

/* scrollspy / 点击后的当前章节高亮 */
.honor-toc__link.is-active {
    background: var(--htoc-primary-soft);
    border-left-color: var(--htoc-primary);
    color: var(--htoc-primary);
    font-weight: 600;
}

/* 自定义条目：面板中手动添加的纯文字节点，不可点击 */
.honor-toc__nolink {
    color: var(--htoc-muted);
    cursor: default;
}

.honor-toc__nolink:hover {
    background: transparent;
    color: var(--htoc-muted);
}

/* 多级缩进（lv1~lv6），配合"层级钳位"最多逐级 +1 */
.honor-toc__item--lv2 .honor-toc__link { padding-left: 24px; }
.honor-toc__item--lv3 .honor-toc__link { padding-left: 36px; }
.honor-toc__item--lv4 .honor-toc__link { padding-left: 48px; }
.honor-toc__item--lv5 .honor-toc__link { padding-left: 60px; }
.honor-toc__item--lv6 .honor-toc__link { padding-left: 72px; }

/* ===================== 正文标题：定位与高亮 ===================== */

/* 平滑滚动/原生锚点跳转时为吸顶导航预留空间 */
#floor-1 .thread-body h1, #floor-1 .thread-body h2, #floor-1 .thread-body h3, #floor-1 .thread-body h4, #floor-1 .thread-body h5, #floor-1 .thread-body h6,
#floor-1 .classic-post-content h1, #floor-1 .classic-post-content h2, #floor-1 .classic-post-content h3, #floor-1 .classic-post-content h4, #floor-1 .classic-post-content h5, #floor-1 .classic-post-content h6,
.m-thread-body h1, .m-thread-body h2, .m-thread-body h3, .m-thread-body h4, .m-thread-body h5, .m-thread-body h6 {
    scroll-margin-top: var(--htoc-scroll-offset);
}

/* JS 跳转后的短暂高亮 */
@keyframes honor-toc-flash {
    0%   { background-color: var(--htoc-flash); }
    70%  { background-color: var(--htoc-flash); }
    100% { background-color: transparent; }
}

.honor-toc-flash {
    animation: honor-toc-flash 1.6s ease-out 1;
}

/* 无 JS 降级：浏览器原生锚点跳转时用 :target 高亮 */
[id^="toc-"]:target {
    animation: honor-toc-flash 2s ease-out 1;
}

/* ===================== 移动端 ===================== */

@media (max-width: 768px) {
    .honor-toc--inline {
        margin-bottom: 12px;
        border-radius: 6px;
    }

    .honor-toc__panel {
        max-height: 46vh;
    }
}

/* 用户偏好减少动态效果时关闭动画 */
@media (prefers-reduced-motion: reduce) {
    .honor-toc-flash,
    [id^="toc-"]:target {
        animation: none;
        background-color: var(--htoc-flash);
    }

    .honor-toc__toggle-icon {
        transition: none;
    }
}
