/* ===== 设计令牌 ===== */
:root {
    /* 深色主题（默认）*/
    --bg: #0b0f17;
    --bg-panel: #10151f;
    --bg-hover: #161d2a;
    --bg-active: #1a2333;
    --card: #121826;
    --topbar-bg: rgba(13, 18, 28, 0.78);
    --text: #e6ebf2;
    --text-dim: #8d9ab0;
    --border: #212b3d;
    --border-strong: #2d3a52;
    --accent: #4da3ff;
    --accent-soft: rgba(77, 163, 255, 0.12);
    --accent2: #8b7cf7;
    --gold: #f5a623;
    --gold-grad: linear-gradient(135deg, #f79533 0%, #f5a623 45%, #ffd166 100%);
    --up: #34d399;
    --down: #f87171;
    --early: #fbbf24;
    --late: #818cf8;
    --sc: #2dd4bf;
    --sc-soft: rgba(45, 212, 191, 0.12);
    --code-bg: #18202f;
    --quote-bg: rgba(77, 163, 255, 0.06);
    --table-header: #16202e;
    --table-alt: rgba(255, 255, 255, 0.02);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --glow-a: rgba(245, 166, 35, 0.05);
    --glow-b: rgba(77, 163, 255, 0.05);
}

html[data-theme="light"] {
    --bg: #f4f6fa;
    --bg-panel: #ffffff;
    --bg-hover: #eef2f8;
    --bg-active: #e6eefb;
    --card: #ffffff;
    --topbar-bg: rgba(255, 255, 255, 0.82);
    --text: #17202e;
    --text-dim: #64748b;
    --border: #e2e8f1;
    --border-strong: #cbd5e3;
    --accent: #2563eb;
    --accent-soft: rgba(37, 99, 235, 0.08);
    --accent2: #7c3aed;
    --gold: #d97706;
    --gold-grad: linear-gradient(135deg, #f79533 0%, #f5a623 45%, #ffd166 100%);
    --up: #059669;
    --down: #dc2626;
    --early: #b45309;
    --late: #6366f1;
    --sc: #0d9488;
    --sc-soft: rgba(13, 148, 136, 0.09);
    --code-bg: #edf1f7;
    --quote-bg: rgba(37, 99, 235, 0.04);
    --table-header: #eef2f8;
    --table-alt: rgba(15, 23, 42, 0.018);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.12);
    --glow-a: rgba(245, 166, 35, 0.07);
    --glow-b: rgba(37, 99, 235, 0.05);
}

/* ===== 基础 ===== */
* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
}

html {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.75;
    -webkit-font-smoothing: antialiased;
}

::selection {
    background: var(--accent-soft);
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 999px;
    border: 3px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-track {
    background: transparent;
}

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ===== 顶栏 ===== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 58px;
    background: var(--topbar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.brand {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 11px;
    font-size: 16px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(160deg, #1a2330, #0c1119);
    border: 1px solid rgba(255, 255, 255, 0.09);
    box-shadow: 0 2px 10px rgba(245, 166, 35, 0.35);
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.brand-title {
    font-size: 15.5px;
    font-weight: 650;
    letter-spacing: 0.3px;
}

.brand-sub {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 2.4px;
    color: var(--text-dim);
}

.theme-toggle {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-hover);
    color: var(--text);
    font-size: 16px;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.theme-toggle {
    display: grid;
    place-items: center;
}

.theme-toggle svg {
    grid-area: 1 / 1;
}

.theme-toggle .icon-moon {
    display: none;
}

html[data-theme="light"] .theme-toggle .icon-sun {
    display: none;
}

html[data-theme="light"] .theme-toggle .icon-moon {
    display: block;
}

.theme-toggle:hover {
    border-color: var(--accent);
    transform: rotate(15deg);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 字号调节：胶囊分段控件 */
.font-controls {
    display: flex;
    align-items: center;
    gap: 1px;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-panel);
}

.font-controls button {
    min-width: 30px;
    height: 24px;
    padding: 0 7px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--text-dim);
    font-size: 11.5px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.font-controls button:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text);
}

.font-controls button:disabled {
    opacity: 0.35;
    cursor: default;
}

.font-label {
    min-width: 42px;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

/* ===== 布局 ===== */
.layout {
    display: flex;
    height: calc(100% - 58px);
}

.sidebar {
    width: 296px;
    min-width: 296px;
    overflow-y: auto;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
}

.report-list {
    padding: 14px 12px 40px;
}

.date-head {
    margin: 18px 6px 8px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-dim);
    letter-spacing: 1.2px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-head::after {
    content: "";
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, var(--border), transparent);
}

.day-group {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.report-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    border: 1px solid transparent;
    border-radius: 11px;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    text-align: left;
    transition: background 0.14s ease, border-color 0.14s ease;
}

.report-item:hover {
    background: var(--bg-hover);
    border-color: var(--border);
}

.report-item.active {
    background: var(--bg-active);
    border-color: var(--border-strong);
    box-shadow: inset 3px 0 0 var(--accent);
}

.item-label {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    white-space: nowrap;
}

.item-label::before {
    content: "";
    flex: none;
    width: 7px;
    height: 7px;
    border-radius: 999px;
}

.session-early .item-label::before {
    background: var(--early);
    box-shadow: 0 0 6px var(--early);
}

.session-late .item-label::before {
    background: var(--late);
    box-shadow: 0 0 6px var(--late);
}

.badge {
    flex: none;
    padding: 1.5px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.4px;
}

.badge-sc {
    color: var(--sc);
    background: var(--sc-soft);
    border: 1px solid transparent;
}

.item-size {
    flex: none;
    font-size: 11.5px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

/* ===== 阅读区 ===== */
.content {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    background:
        radial-gradient(720px 340px at 88% -120px, var(--glow-a), transparent 65%),
        radial-gradient(820px 420px at -140px 20%, var(--glow-b), transparent 62%),
        var(--bg);
}

.reader {
    padding: 34px 292px 90px 44px;
}

.hint,
.error {
    color: var(--text-dim);
    padding: 24px 8px;
}

.error {
    color: var(--down);
}

/* ===== Markdown 正文 ===== */
.md-body {
    font-size: var(--reader-font, 17px);
    animation: rise 0.28s ease both;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.md-body h1 {
    font-size: calc(var(--reader-font, 17px) * 1.47);
    font-weight: 700;
    letter-spacing: -0.2px;
    line-height: 1.4;
    margin: 0 0 20px;
}

.md-body h2 {
    /* 章节标题保持普通文档流；滚动固定展示由单一 .md-titlebar 承担 */
    font-size: calc(var(--reader-font, 17px) * 1.09);
    font-weight: 650;
    margin: 26px 0 14px -12px;
    padding: 8px 10px 10px 12px;
    border-bottom: 1px solid var(--border);
}

.md-body h2::before {
    content: "";
    display: inline-block;
    width: 4px;
    height: 17px;
    margin-right: 10px;
    border-radius: 2px;
    vertical-align: -2.5px;
    background: linear-gradient(180deg, var(--accent), var(--accent2));
}

/* 单一固定标题条：滚动监听驱动文字。sticky 标题被滚过后会「骑」在父节末尾，
   污染目录跳转的坐标计算，故改为独立 DOM 承担固定展示 */
.md-titlebar {
    position: sticky;
    top: -1px;
    z-index: 5;
    margin: -14px 0 14px -12px;
    padding: 8px 10px 10px 12px;
    font-size: calc(var(--reader-font, 17px) * 1.09);
    font-weight: 650;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.md-titlebar.hidden {
    display: none;
}

.md-body h3 {
    font-size: calc(var(--reader-font, 17px) * 0.94);
    font-weight: 650;
    margin: 24px 0 10px;
}

.md-body p {
    margin: 10px 0;
}

.md-body strong {
    font-weight: 650;
}

/* 元信息块：引用 → 信息卡 */
.md-body blockquote {
    margin: 16px 0;
    padding: 12px 18px;
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    background: var(--quote-bg);
    border-radius: 12px;
    color: var(--text-dim);
    font-size: calc(var(--reader-font, 17px) * 0.9);
}

.md-body blockquote p {
    margin: 4px 0;
}

.md-body blockquote strong {
    color: var(--text);
}

/* 表格：数据面板风 */
.md-body table {
    display: block;
    overflow-x: auto;
    max-width: 100%;
    width: fit-content;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: calc(var(--reader-font, 17px) * 0.95);
    line-height: 1.6;
    font-variant-numeric: tabular-nums;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.md-body th,
.md-body td {
    padding: 7px 13px;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}

.md-body th {
    background: var(--table-header);
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.2px;
}

.md-body tr:last-child td {
    border-bottom: none;
}

.md-body tr:nth-child(2n) td {
    background: var(--table-alt);
}

.md-body tbody tr {
    transition: background 0.12s ease;
}

.md-body tbody tr:hover td {
    background: var(--bg-hover);
}

.md-body code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 6px;
    font-family: ui-monospace, "JetBrains Mono", Consolas, monospace;
    font-size: calc(var(--reader-font, 17px) * 0.8);
    border: 1px solid var(--border);
}

.md-body pre {
    background: var(--code-bg);
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow-x: auto;
}

.md-body pre code {
    padding: 0;
    background: none;
    border: none;
}

.md-body img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    cursor: zoom-in;
    transition: filter 0.15s ease;
}

.md-body img:hover {
    filter: brightness(1.06);
}

.md-body ul,
.md-body ol {
    padding-left: 22px;
}

.md-body li {
    margin: 4px 0;
}

.md-body li::marker {
    color: var(--accent);
}

.md-body hr {
    border: none;
    height: 1px;
    margin: 26px 0;
    background: linear-gradient(90deg, transparent, var(--border-strong), transparent);
}

.md-body a {
    color: var(--accent);
    text-decoration: none;
}

.md-body a:hover {
    text-decoration: underline;
}

/* ===== 灯箱 ===== */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    background: rgba(5, 8, 14, 0.86);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: zoom-out;
}

.lightbox.open {
    display: flex;
}

.lightbox img {
    max-width: 97vw;
    max-height: 90vh;
    width: auto;
    height: auto;
    border-radius: 10px;
    box-shadow: 0 12px 60px rgba(0, 0, 0, 0.55);
}

.lightbox .caption {
    margin: 0;
    padding: 5px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.09);
    color: #fff;
    font-size: 13px;
}

.lightbox .caption.hidden {
    display: none;
}

/* ===== 章节目录：桌面右侧悬浮，窄屏改为 FAB 唤出 ===== */
.toc-panel {
    position: fixed;
    top: 78px;
    right: 18px;
    width: 248px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 156px);
    overflow-y: auto;
    padding: 12px 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-panel);
    background: color-mix(in srgb, var(--bg-panel) 92%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--shadow-sm);
    z-index: 20;
}

.toc-panel.hidden {
    display: none;
}

.toc-title {
    margin: 0 10px 8px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 1.2px;
    color: var(--text-dim);
}

.toc-panel ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.toc-panel a {
    display: block;
    padding: 8px 12px;
    border-left: 2px solid transparent;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.55;
    color: var(--text-dim);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.13s ease, color 0.13s ease, border-color 0.13s ease;
}

.toc-panel a:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.toc-panel a.active {
    border-left-color: var(--accent);
    background: var(--bg-active);
    color: var(--accent);
    font-weight: 600;
}

.toc-fab {
    position: fixed;
    right: 16px;
    bottom: 18px;
    display: none;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--bg-panel);
    color: var(--text);
    cursor: pointer;
    box-shadow: var(--shadow-md);
    z-index: 21;
}

@media (max-width: 1179px) {
    .reader {
        padding-right: 44px;
    }

    .toc-fab {
        display: flex;
    }

    .toc-panel {
        top: auto;
        bottom: 74px;
        max-height: 52vh;
        opacity: 0;
        transform: translateY(10px);
        pointer-events: none;
        transition: opacity 0.16s ease, transform 0.16s ease;
    }

    body.toc-open .toc-panel {
        opacity: 1;
        transform: none;
        pointer-events: auto;
    }
}

/* ===== 响应式与偏好 ===== */
@media (max-width: 720px) {
    .layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: 0;
        max-height: 38vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .reader {
        padding: 18px 16px 64px;
    }

    .brand-sub {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
