/* 博客园文章目录：粘贴到「页面定制 CSS 代码」中 */

#uprightsideBar,
#uprightsideBar * {
    box-sizing: border-box;
}

#uprightsideBar {
    --toc-accent: #2563eb;
    --toc-accent-soft: #eff6ff;
    --toc-text: #172033;
    --toc-muted: #758096;
    --toc-border: rgba(148, 163, 184, 0.28);
    --toc-panel: rgba(255, 255, 255, 0.96);

    position: fixed;
    top: clamp(76px, 12vh, 120px);
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-start;
    color: var(--toc-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    text-align: left;
}

/* 收起状态下的目录按钮 */
#sideBarTab {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    min-width: 46px;
    height: 46px;
    min-height: 46px;
    padding: 0;
    border: 1px solid rgba(148, 163, 184, 0.34);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.96);
    box-shadow:
        0 6px 18px rgba(15, 23, 42, 0.10),
        0 1px 3px rgba(15, 23, 42, 0.08);
    color: #667085;
    font: inherit;
    cursor: pointer;
    transition: border-color 160ms ease, box-shadow 160ms ease,
        background-color 160ms ease, color 160ms ease, transform 160ms ease;
}

#sideBarTab:hover,
#sideBarTab:focus-visible,
#uprightsideBar.is-open #sideBarTab {
    border-color: rgba(37, 99, 235, 0.28);
    background: var(--toc-accent);
    box-shadow: 0 8px 22px rgba(37, 99, 235, 0.24);
    color: #ffffff;
    outline: none;
    transform: translateY(-2px);
}

/* 三行列表图标，避免使用突兀的竖排“目录”文字。 */
.toc-trigger-icon {
    position: relative;
    display: block;
    width: 20px;
    height: 16px;
    background:
        linear-gradient(currentColor, currentColor) 6px 1px / 14px 2px no-repeat,
        linear-gradient(currentColor, currentColor) 6px 7px / 11px 2px no-repeat,
        linear-gradient(currentColor, currentColor) 6px 13px / 14px 2px no-repeat;
}

.toc-trigger-icon::before {
    position: absolute;
    top: 1px;
    left: 0;
    width: 2px;
    height: 2px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 6px 0 currentColor, 0 12px 0 currentColor;
    content: "";
}

/* 桌面端悬停提示。 */
#sideBarTab::after {
    position: absolute;
    top: 50%;
    right: 56px;
    padding: 6px 9px;
    border-radius: 7px;
    background: rgba(15, 23, 42, 0.88);
    color: #ffffff;
    content: "题目目录";
    font-size: 12px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate(4px, -50%);
    transition: opacity 140ms ease, visibility 140ms ease,
        transform 140ms ease;
}

#sideBarTab:hover::after,
#sideBarTab:focus-visible::after {
    opacity: 1;
    visibility: visible;
    transform: translate(0, -50%);
}

#uprightsideBar.is-open #sideBarTab::after {
    display: none;
}

.toc-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 展开后的目录卡片 */
#sideBarContents {
    width: min(306px, calc(100vw - 92px));
    max-height: min(68vh, 620px);
    margin-right: 12px;
    overflow: hidden;
    border: 1px solid var(--toc-border);
    border-radius: 16px;
    background: var(--toc-panel);
    box-shadow:
        0 18px 48px rgba(15, 23, 42, 0.14),
        0 2px 8px rgba(15, 23, 42, 0.06);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(10px) scale(0.985);
    transform-origin: top right;
    transition: opacity 180ms ease, visibility 180ms ease,
        transform 180ms ease;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

#uprightsideBar.is-open #sideBarContents {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0) scale(1);
}

.toc-panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 56px;
    padding: 0 14px 0 17px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.20);
}

.toc-panel-title {
    flex: 1;
    margin: 0;
    color: var(--toc-text);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.toc-count {
    color: var(--toc-muted);
    font-size: 12px;
    white-space: nowrap;
}

.toc-close {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: #8a94a6;
    font: 20px/1 Arial, sans-serif;
    cursor: pointer;
}

.toc-close:hover,
.toc-close:focus-visible {
    background: #f1f5f9;
    color: #334155;
    outline: none;
}

.toc-nav {
    max-height: calc(min(68vh, 620px) - 57px);
    padding: 10px 9px 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.toc-nav::-webkit-scrollbar {
    width: 6px;
}

.toc-nav::-webkit-scrollbar-track {
    background: transparent;
}

.toc-nav::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: #cbd5e1;
}

.toc-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.toc-item {
    margin: 1px 0;
    padding: 0;
}

.toc-link {
    position: relative;
    display: block;
    margin: 0;
    padding: 7px 10px 7px 14px;
    overflow: hidden;
    border-radius: 9px;
    color: #536076;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.45;
    text-decoration: none !important;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: background-color 150ms ease, color 150ms ease;
}

.toc-level-0 > .toc-link {
    margin-top: 4px;
    color: #25324a;
    font-weight: 680;
}

.toc-level-1 > .toc-link {
    padding-left: 26px;
}

.toc-level-2 > .toc-link {
    padding-left: 40px;
    color: #69758a;
    font-size: 12.5px;
}

.toc-level-3 > .toc-link,
.toc-level-4 > .toc-link {
    padding-left: 52px;
    color: #7d8798;
    font-size: 12px;
}

.toc-link:hover,
.toc-link:focus-visible {
    background: #f6f8fb;
    color: var(--toc-accent);
    outline: none;
}

.toc-link.is-active {
    background: var(--toc-accent-soft);
    color: var(--toc-accent);
    font-weight: 650;
}

.toc-link.is-active::before {
    position: absolute;
    top: 8px;
    bottom: 8px;
    left: 4px;
    width: 3px;
    border-radius: 999px;
    background: var(--toc-accent);
    content: "";
}

/* 点击目录后，标题不会贴住浏览器顶部。 */
#cnblogs_post_body h2,
#cnblogs_post_body h3,
#cnblogs_post_body h4,
#cnblogs_post_body h5,
#cnblogs_post_body h6 {
    scroll-margin-top: 24px;
}

/* 窄屏时改成右下角按钮，避免遮挡正文。 */
@media (max-width: 900px) {
    #uprightsideBar {
        top: auto;
        right: 12px;
        bottom: 18px;
    }

    #sideBarTab {
        width: 50px;
        min-width: 50px;
        height: 50px;
        min-height: 50px;
        padding: 0;
        border-radius: 50%;
    }

    #sideBarTab::after {
        display: none;
    }

    #sideBarContents {
        position: absolute;
        right: 0;
        bottom: 62px;
        width: min(340px, calc(100vw - 24px));
        max-height: min(68vh, 560px);
        margin: 0;
        transform: translateY(10px) scale(0.985);
        transform-origin: bottom right;
    }

    #uprightsideBar.is-open #sideBarContents {
        transform: translateY(0) scale(1);
    }

    .toc-nav {
        max-height: calc(min(68vh, 560px) - 57px);
    }
}

@media (prefers-reduced-motion: reduce) {
    #sideBarTab,
    #sideBarContents,
    .toc-link {
        transition: none;
    }
}

@media print {
    #uprightsideBar {
        display: none !important;
    }
}
