
.hud-toc {
    --hud-toc-cx: 70vw;
    --hud-toc-lane: calc(70vw + 12px);
    --hud-toc-x: calc(70vw + 30px);
    --hud-toc-panel-w: 160px;
    --hud-toc-y: 18%;
    --hud-toc-panel-h: 440px;
    --hud-toc-h: 505px;

    --toc-fs: calc(16px * var(--hud-s, 1));
    --toc-ls: 0.04em;

    --hud-toc-ink: rgba(234, 243, 255, 0.92);
    --hud-toc-dim: rgba(234, 243, 255, 0.7);
    --hud-toc-line: rgba(234, 243, 255, 0.22);
    --hud-toc-on: rgba(234, 243, 255, 0.62);
    --hud-toc-cyan: var(--mc-color, rgb(34, 211, 238));

    position: absolute;
    left: var(--hud-toc-x);
    top: var(--hud-toc-y);
    width: calc(100% - var(--hud-toc-x));
    height: var(--hud-toc-h);
    display: flex;
    align-items: center;
    pointer-events: none;
    /* ★ 盆栽(.hud-plants, z-index:1)与目录同在 .page-hud 内且 DOM
       序在前 —— 目录不设 z-index 时被盆栽盖住, 悬停/点击被
       pointer-events:auto 的盆栽 svg 劫走(bug#18)。目录提到 2。 */
    z-index: 2;
    font-family: var(--hud-font);
    color: var(--hud-toc-ink);
}

.hud-toc__lane {
    position: absolute;
    left: calc(var(--hud-toc-lane) - var(--hud-toc-x));
    top: 0;
    height: 100%;
    width: 0;
    display: flex;
    justify-content: center;
    pointer-events: none;
}

.hud-toc__prog {
    position: relative;
    align-self: center;
    flex: 0 0 auto;
    width: 2px;
    transform: translateY(-22px);       /* 和面板同心(回到顶部那枚占了下方 44px,见 JS 的 TOP_H)
                                           —— 这 22px = (TOP_H + TOP_GAP) / 2 */
    height: var(--hud-toc-panel-h);
    border-radius: 2px;
    background: var(--hud-toc-line);
    pointer-events: none;
}

.hud-toc__prog::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: calc(var(--hud-toc-p, 0) * 100%);
    border-radius: 2px;
    background: linear-gradient(to bottom, rgba(234, 243, 255, 0.1), var(--hud-toc-cyan));
}

.hud-toc__prog-thumb {
    position: absolute;
    left: 50%;
    top: calc(var(--hud-toc-p, 0) * 100%);
    width: calc(7px * var(--hud-s, 1));
    height: calc(7px * var(--hud-s, 1));
    margin: calc(-3.5px * var(--hud-s, 1)) 0 0 calc(-3.5px * var(--hud-s, 1));
    border-radius: 50%;
    background: #eaf3ff;
    box-shadow: 0 0 6px 1px var(--glow-dim, rgba(34, 211, 238, 0.45));
}

.hud-toc__box {
    position: absolute;
    left: calc(var(--hud-toc-lane) - var(--hud-toc-x) + 18px);
    top: 0;
    height: 100%;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 10px;
    pointer-events: auto;
}

.hud-toc__top {
    flex: 0 0 auto;
    width: calc(34px * var(--hud-s, 1));
    height: calc(34px * var(--hud-s, 1));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--hud-toc-line);
    border-radius: 50%;
    background: rgba(8, 12, 22, 0.78);
    backdrop-filter: blur(9px);
    color: var(--hud-toc-ink);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease;
}

.hud-toc__top.is-on {
    opacity: 1;
    pointer-events: auto;
}

.hud-toc__top:hover,
.hud-toc__top:focus-visible {
    border-color: var(--hud-toc-cyan);
    background: rgba(34, 211, 238, 0.14);
    color: #ffffff;
}

.hud-toc__top svg {
    width: calc(15px * var(--hud-s, 1));
    height: calc(15px * var(--hud-s, 1));
    display: block;
}

:root[data-theme].shell-page .top-link {
    opacity: 0 !important;
    pointer-events: none !important;
}

.hud-toc__panel {
    position: relative;
    width: var(--hud-toc-panel-w);
    flex: 0 0 auto;
    height: var(--hud-toc-panel-h);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--hud-toc-line);
    border-radius: 7px;
    background:
        linear-gradient(180deg, rgba(234, 243, 255, 0.045), rgba(234, 243, 255, 0) 42%),
        rgba(8, 12, 22, 0.72);
    backdrop-filter: blur(9px);
    transition: border-color 0.2s ease;
}

.hud-toc__deco {
    position: absolute;
    inset: 5px;
    pointer-events: none;
}

.hud-toc__deco i {
    position: absolute;
    width: 9px;
    height: 9px;
    border: 1px solid var(--hud-toc-cyan);
    opacity: 0.5;
}

.hud-toc__deco i:nth-child(1) { left: 0; top: 0; border-right: 0; border-bottom: 0; }
.hud-toc__deco i:nth-child(2) { right: 0; top: 0; border-left: 0; border-bottom: 0; }
.hud-toc__deco i:nth-child(3) { left: 0; bottom: 0; border-right: 0; border-top: 0; }
.hud-toc__deco i:nth-child(4) { right: 0; bottom: 0; border-left: 0; border-top: 0; }

.hud-toc__toggle {
    display: none;
    flex: 0 0 auto;
    width: 22px;
    height: 48px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--hud-toc-line);
    border-radius: 5px;
    background: rgba(8, 12, 22, 0.78);
    backdrop-filter: blur(9px);
    color: var(--hud-toc-ink);
    cursor: pointer;
}

.hud-toc__toggle:not([hidden]) {
    display: inline-flex;
}

.hud-toc__toggle:hover {
    background: rgba(234, 243, 255, 0.16);
    border-color: var(--hud-toc-on);
}

.hud-toc__toggle svg {
    width: 14px;
    height: 14px;
    display: block;
}

.hud-toc__head {
    flex: 0 0 auto;
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 13px 15px 10px;
    border-bottom: 1px solid var(--hud-toc-line);
}

.hud-toc__title {
    font-family: "Pixel CN", var(--hud-font);
    font-size: calc(21px * var(--hud-s, 1));
    letter-spacing: 0.08em;
    white-space: nowrap;
}

.hud-toc__en {
    font-size: calc(11px * var(--hud-s, 1));
    letter-spacing: 0.26em;
    color: var(--hud-toc-dim);
    text-transform: uppercase;
}

.hud-toc__list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px 0 12px;
    scrollbar-width: none;
}

.hud-toc__list::-webkit-scrollbar { width: 0; height: 0; }

.hud-toc__item {
    display: block;
    padding: 6px 14px 6px 14px;
    border-left: 2px solid transparent;
    color: var(--hud-toc-dim);
    font-size: var(--toc-fs);
    letter-spacing: var(--toc-ls);
    line-height: 1.55;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
    transition: color 0.16s ease, border-color 0.16s ease, background-color 0.16s ease;
}

/* 层级缩进:h1(lvl 1)最顶, h2(lvl 2)次级缩进, h3/h4 逐级加深 */
.hud-toc__item[data-hud-toc-lvl="2"] { padding-left: 14px; font-size: calc(var(--toc-fs) - 0.5px); }
.hud-toc__item[data-hud-toc-lvl="3"] { padding-left: 28px; font-size: calc(var(--toc-fs) - 1.5px); }
.hud-toc__item[data-hud-toc-lvl="4"] { padding-left: 42px; font-size: calc(var(--toc-fs) - 1.5px); }

.hud-toc__item:hover {
    color: var(--hud-toc-ink);
    background: rgba(234, 243, 255, 0.06);
}

.hud-toc__item.is-current {
    border-left-color: var(--hud-toc-cyan);
    color: #ffffff;
    background: linear-gradient(90deg, color-mix(in srgb, var(--hud-toc-cyan) 16%, transparent), transparent 72%);
}

.hud-toc__size {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 26px auto auto auto;
    align-items: center;
    justify-content: start;
    gap: 6px 5px;
    padding: 9px 11px 10px;
    border-top: 1px solid var(--hud-toc-line);
    font-size: calc(13px * var(--hud-s, 1));
    white-space: nowrap;
    overflow: hidden;
}

.hud-toc__size-lab {
    color: var(--hud-toc-dim);
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.hud-toc__step {
    width: calc(20px * var(--hud-s, 1));
    height: calc(20px * var(--hud-s, 1));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--hud-toc-line);
    border-radius: 4px;
    background: rgba(234, 243, 255, 0.06);
    color: var(--hud-toc-ink);
    font-family: var(--hud-font);
    font-size: calc(14px * var(--hud-s, 1));
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.16s ease, border-color 0.16s ease;
}

.hud-toc__step:hover {
    background: rgba(234, 243, 255, 0.2);
    border-color: var(--hud-toc-on);
}

.hud-toc__size-val {
    color: rgba(234, 243, 255, 0.62);
    font-size: calc(12px * var(--hud-s, 1));
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.hud-toc.is-tight {
    display: none;
}

@media (prefers-reduced-motion: reduce) {
    .hud-toc__panel,
    .hud-toc__item,
    .hud-toc__step { transition: none; }
}
