/* ============================================================
   深色模式 + 全局浮动按钮样式
   在浅色样式之后加载，用 html.dark 覆盖变量与局部色。
   首页变量：--bg/--soft/--ink/--ink-2/--muted/--line/--blue...
   文档页变量：--bg/--surface/--ink/--ink-2/--muted/--line/--accent...
   两套变量都覆盖，一处通吃。
   ============================================================ */

html.dark {
    color-scheme: dark;
    /* 首页变量 */
    --blue: #60a5fa;
    --blue-dark: #93c5fd;
    --blue-soft: #1e293b;
    --blue-line: #3b4a63;
    --ink: #e8edf5;
    --ink-2: #c3ccda;
    --muted: #8b96a8;
    --line: #2b3646;
    --line-strong: #3a4759;
    --bg: #0f172a;
    --soft: #172033;
    --radius: 12px;
    --shadow: 0 8px 24px rgba(0, 0, 0, .34);
    /* 文档页变量 */
    --surface: #162032;
    --accent: #60a5fa;
    --accent-soft: #1e293b;
    --shadow-hover: 0 16px 36px -20px rgba(0, 0, 0, .7);
}

html.dark body {
    background: var(--bg);
    color: var(--ink);
}

/* 首页顶栏/侧栏/卡片等硬编码白底的地方 */
html.dark .sidebar,
html.dark .topbar,
html.dark .modal,
html.dark .card,
html.dark .spot,
html.dark .sec-head,
html.dark .code-box,
html.dark .chip,
html.dark .badge,
html.dark .btn-ghost,
html.dark .modal-url,
html.dark .modal-code {
    background-color: var(--soft);
}

html.dark .card.is-flat {
    background: var(--soft);
}

html.dark .topbar {
    background: rgba(15, 23, 42, .92);
    border-bottom-color: var(--line);
}

html.dark .sidebar {
    border-right-color: var(--line);
}

html.dark .secnav,
html.dark .side-scroll {
    background: transparent;
}

html.dark .spot-1 { background: linear-gradient(135deg, #1e3a8a, #1e40af); }
html.dark .spot-2 { background: linear-gradient(135deg, #5b21b6, #6d28d9); }
html.dark .spot-3 { background: linear-gradient(135deg, #0e7490, #0891b2); }

html.dark .code-box {
    background: var(--bg);
}

html.dark .btn-ghost {
    color: var(--ink-2);
    border-color: var(--line-strong);
}

html.dark .foot {
    border-top-color: var(--line);
}

html.dark .notice {
    background: #3b3218;
    border-color: #6b5a24;
    color: #fde68a;
}

/* 文档页硬编码白底/浅色块 */
html.dark .doc-toc,
html.dark .doc-index-item,
html.dark .doc-fig,
html.dark .doc-end,
html.dark .doc-extnote {
    background: var(--surface);
}

html.dark blockquote {
    background: var(--surface);
    border-left-color: var(--accent);
}

html.dark pre,
html.dark code {
    background: var(--soft);
    color: var(--ink);
}

html.dark table th {
    background: var(--soft);
}

html.dark table td,
html.dark table th {
    border-color: var(--line);
}

html.dark img {
    /* 图片在深色下略微压暗，避免刺眼 */
    opacity: .92;
}

/* ---------- 全局浮动按钮 ---------- */

.ui-fab {
    position: fixed;
    right: 20px;
    bottom: 24px;
    z-index: 60;
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    padding: 10px;
    border: 1px solid var(--line-strong, #d7dde7);
    border-radius: 12px;
    background: var(--soft, #f7f9fc);
    color: var(--ink-2, #4b5563);
    box-shadow: 0 4px 14px rgba(31, 41, 55, .12);
    cursor: pointer;
    transition: transform .2s var(--ease, ease), opacity .2s, background-color .2s, color .2s;
}

.ui-fab:hover {
    transform: translateY(-2px);
    color: var(--blue, #2563eb);
    border-color: var(--blue, #2563eb);
}

.ui-theme-toggle {
    bottom: 76px;
}

.ui-backtop {
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    pointer-events: none;
}

.ui-backtop.show {
    opacity: 1;
    visibility: visible;
    transform: none;
    pointer-events: auto;
}

@media (max-width: 620px) {
    .ui-fab {
        right: 14px;
        width: 38px;
        height: 38px;
        padding: 9px;
    }

    .ui-theme-toggle {
        bottom: 66px;
    }
}

/* ---------- 文档页回到上次阅读位置 ---------- */

.readpos-bar {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 70;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 9px 7px 14px;
    border: 1px solid var(--line-strong, #d7dde7);
    border-radius: 999px;
    background: var(--soft, #f7f9fc);
    color: var(--ink-2, #4b5563);
    box-shadow: 0 8px 26px rgba(15, 23, 42, .16);
    font-size: 12px;
    white-space: nowrap;
    transform: translateX(-50%);
    animation: readpos-in .3s ease;
}

@keyframes readpos-in {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.readpos-go {
    padding: 6px 13px;
    border: 0;
    border-radius: 999px;
    background: var(--blue, #2563eb);
    color: #fff;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.readpos-go:hover {
    filter: brightness(1.08);
}

.readpos-close {
    padding: 2px 6px;
    border: 0;
    background: transparent;
    color: var(--muted, #6b7280);
    font-family: inherit;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

@media (max-width: 620px) {
    .readpos-bar {
        bottom: 14px;
        font-size: 11px;
        padding-left: 11px;
    }

    .readpos-go {
        padding: 5px 10px;
        font-size: 11px;
    }
}
