:root {
    /* ================= 字体设置 ================= */
    --font-sans-serif: 'Ubuntu', 'Source Sans Pro', sans-serif !important;
    --font-monospace: 'Fira Code', 'Roboto Mono', monospace !important;
    --topnav-height: 4vh;

    /* ================= 亮色模式 (默认) ================= */
    /* 背景色 */
    --bg-body: #ffffff;
    --bg-nav: rgba(238, 238, 238, 0.85);
    --bg-sidebar: #fff;
    --bg-toc: #f3f3f3;           /* 目录背景 */
    --bg-toc-hover: #e0e0e0;     /* 目录悬停 */
    --bg-toc-active: #e0edff;    /* 目录激活 */
    --bg-code-block: #f8f8f8;
    --bg-quote: rgba(66, 127, 185, 0.1);
    --bg-table-stripe: #fafafa;  /* 表格隔行变色 */
    --bg-button: #dfe2e5e0;
    --bg-button-hover: #dfe2e54b;
    --bg-selection: rgba(6, 162, 253, 0.2);

    /* 文字颜色 */
    --text-main: #34495e;        /* 正文 */
    --text-heading: #2c3e50;     /* 标题 */
    --text-muted: #777777;       /* 次要文字/注释 */
    --text-control: #777;        /* 控件/按钮文字 */

    /* 强调色 */
    --color-accent: #f3f3f3;
    --color-accent-hover: rgba(53, 121, 247, 0.824);
    --color-link-active: #1d4ed8;

    /* 边框与分割线 */
    --border-color: #dfe2e5;
    --border-light: #e7e7e7;
    --border-dashed: #cfd1d4;
    --border-quote: #1676f5;

    /* 阴影 */
    --shadow-nav: -4px 4px 15px rgba(53, 53, 53, 0.3);
    --shadow-toc: 0 4px 16px 4px rgba(15, 23, 42, 0.12);
}

/* ================= 暗色模式 (Dark Mode) ================= */
/* 当系统设置为深色 或 body 拥有 .dark-mode 类时生效 */
@media (prefers-color-scheme: dark) {
    :root {
        /* 覆盖为暗色变量 */
        --bg-body: #1a1b1e;           /* 深灰背景，非纯黑，更护眼 */
        --bg-nav: rgba(32, 33, 36, 0.85);
        --bg-sidebar: #25262b;
        --bg-toc: #25262b;
        --bg-toc-hover: #34353a;
        --bg-toc-active: #1e3a5f;     /* 暗色下的激活态深蓝 */
        --bg-code-block: #2c2e33;
        --bg-quote: rgba(66, 127, 185, 0.15);
        --bg-table-stripe: #25262b;
        --bg-button: #2c2e33;
        --bg-button-hover: #373a40;
        --bg-selection: rgba(69, 133, 250, 0.3);

        --text-main: #c1c2c5;         /* 灰白文字 */
        --text-heading: #e7e7e7;      /* 亮白标题 */
        --text-muted: #909296;        /* 浅灰注释 */
        --text-control: #a0a0a0;

        --color-accent: #74c0fc;      /* 暗色模式下蓝色需要更亮 */
        --color-accent-hover: #a5d8ff;
        --color-link-active: #a5d8ff;

        --border-color: #373a40;      /* 深色边框 */
        --border-light: #2c2e33;
        --border-dashed: #5c5f66;
        --border-quote: #4585fa;

        --shadow-nav: -4px 4px 15px rgba(0, 0, 0, 0.5);
        --shadow-toc: 0 4px 16px 4px rgba(0, 0, 0, 0.4);
    }
}

/* 手动切换支持：如果给body加了 class="dark-mode"，强制应用暗色 */
body.dark-mode {
    --bg-body: #1a1b1e;
    --bg-nav: rgba(32, 33, 36, 0.85);
    --bg-sidebar: #25262b;
    --bg-toc: #25262b;
    --bg-toc-hover: #34353a;
    --bg-toc-active: #1e3a5f;
    --bg-code-block: #2c2e33;
    --bg-quote: rgba(66, 127, 185, 0.15);
    --bg-table-stripe: #25262b;
    --bg-button: #2c2e33;
    --bg-button-hover: #373a40;
    --bg-selection: rgba(69, 133, 250, 0.3);

    --text-main: #c1c2c5;
    --text-heading: #e7e7e7;
    --text-muted: #dadada;
    --text-control: #a0a0a0;

    --color-accent: #74c0fc;
    --color-accent-hover: #a5d8ff;
    --color-link-active: #a5d8ff;

    --border-color: #373a40;
    --border-light: #2c2e33;
    --border-dashed: #5c5f66;
    --border-quote: #4585fa;

    --shadow-nav: -4px 4px 15px rgba(0, 0, 0, 0.5);
    --shadow-toc: 0 4px 16px 4px rgba(0, 0, 0, 0.4);
}

/* ================= 通用样式重构 ================= */

html {
    font-size: 16px;
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--topnav-height) + 1rem);
}

body {
    font-family: var(--font-sans-serif);
    color: var(--text-main); /* 变量替换 */
    background-color: var(--bg-body); /* 变量替换 */
    -webkit-font-smoothing: antialiased;
    line-height: 1.6rem;
    letter-spacing: 0;
    margin: 0;
    overflow-x: hidden;
    padding: 5vh 20vw 5vh 20vw;
    margin-top: 4vh;
    transition: background-color 0.3s ease, color 0.3s ease; /* 添加平滑过渡 */
}

::selection {
    background-color: var(--bg-selection); /* 变量替换 */
}

img {
    width: 100%;
}

table {
    width: 100%;
}

/* 顶部导航栏 */
#topNav {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    height: var(--topnav-height);
    min-height: 36px;
    width: 100%;

    display: flex;
    flex-direction: row;
    align-items: center;

    background-color: var(--bg-nav); /* 变量替换 */
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-nav); /* 变量替换 */
    border-bottom: 1px solid var(--border-light); /* 增加微弱边框提升质感 */
}

#topNav button {
    height: 100%;
    font-size: 100%;
    background-color: var(--bg-button); /* 变量替换 */
    color: var(--text-control); /* 变量替换 */
    border: 0;
    min-width: 52px;
    transition: background-color 0.3s;
}

#topNav button:hover {
    cursor: pointer;
    background-color: var(--bg-button-hover); /* 变量替换 */
    color: var(--text-heading);
}

#topNav p {
    font-size: 85%;
    margin: 0;
    padding: 0;
    color: var(--text-main);
}

#topNav .topTitle {
    white-space: nowrap;
    margin-left: 16px;
    font-weight: bolder;
    color: var(--text-heading);
}

/* 信息区域 */
#infoArea {
    padding: 4px;
    padding-left: 0;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-content: space-between;
    user-select: none;
    gap: 4px;
}

#infoArea span {
    margin-bottom: 0.5%;
    user-select: none;
    /* color: var(--text-muted); 补充颜色 */
}

#infoArea span:hover {
    cursor: pointer;
    color: var(--color-accent);
}

#bottom {
    font-size: 14px;
    text-align: center;
    bottom: 0;
    left: 0;
    width: 100%;
    margin-top: 7vh;
    font-weight: lighter;
    color: #727272; /* 变量替换 */
}

@media (max-width: 768px) {
    body {
        padding: 5vh 5vw 5vh 5vw;
    }
    #topNav {
        height: 5vh;
    }
}

body>*:first-child { margin-top: 0 !important; }
body>*:last-child { margin-bottom: 0 !important; }

/* 链接样式 */
a {
    color: var(--color-accent); /* 变量替换 */
    font-weight: 600;
    padding: 0 2px;
    text-decoration: none;
    transition: color 0.2s;
}
a:hover {
    color: var(--color-accent-hover); /* 变量替换 */
}

/* 标题样式 */
h1, h2, h3, h4, h5, h6 {
    position: relative;
    margin-top: 1rem;
    margin-bottom: 1rem;
    font-weight: bold;
    line-height: 1.4;
    cursor: text;
    color: var(--text-heading); /* 变量替换，确保标题颜色正确 */
}

h1:hover a.anchor,
h2:hover a.anchor,
h3:hover a.anchor,
h4:hover a.anchor,
h5:hover a.anchor,
h6:hover a.anchor {
    text-decoration: none;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, 
h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
    font-size: inherit !important;
}

h2 a, h3 a {
    color: var(--text-heading); /* 变量替换 */
}
h2 a:hover, h3 a:hover {
    color: var(--color-accent);
}

h1 {
    padding-bottom: .4rem;
    font-size: 2.2rem;
    line-height: 1.3;
}

h2 {
    font-size: 1.75rem;
    line-height: 1.225;
    margin: 35px 0 15px;
    padding-bottom: 0.5em;
    border-bottom: 1px solid var(--border-color); /* 变量替换 */
}

h3 {
    font-size: 1.4rem;
    line-height: 1.43;
    margin: 20px 0 7px;
}
h4 { font-size: 1.2rem; }
h5 { font-size: 1rem; }

h6 {
    font-size: 1rem;
    color: var(--text-muted); /* 变量替换 */
}

p, blockquote, ul, ol, dl, table {
    margin: 0.8em 0;
}

li>ol, li>ul { margin: 0 0; }

hr {
    height: 2px;
    padding: 0;
    margin: 16px 0;
    background-color: var(--border-light); /* 变量替换 */
    border: 0 none;
    overflow: hidden;
    box-sizing: content-box;
}

/* 标题间距修正 (保持原逻辑) */
body>h2:first-child { margin-top: 0; padding-top: 0; }
body>h1:first-child { margin-top: 0; padding-top: 0; }
body>h1:first-child+h2 { margin-top: 0; padding-top: 0; }
body>h3:first-child, body>h4:first-child, 
body>h5:first-child, body>h6:first-child { margin-top: 0; padding-top: 0; }
a:first-child h1, a:first-child h2, a:first-child h3,
a:first-child h4, a:first-child h5, a:first-child h6 { margin-top: 0; padding-top: 0; }
h1 p, h2 p, h3 p, h4 p, h5 p, h6 p { margin-top: 0; }

li p.first { display: inline-block; }

ul, ol { padding-left: 30px; }
ul:first-child, ol:first-child { margin-top: 0; }
ul:last-child, ol:last-child { margin-bottom: 0; }

/* 引用块 */
blockquote {
    border-radius: 4px;
    border-left: 4px solid var(--border-quote); /* 变量替换 */
    padding: 10px 15px;
    color: var(--text-muted); /* 变量替换 */
    background-color: var(--bg-quote); /* 变量替换 */
}

/* 表格 */
table {
    padding: 0;
    word-break: initial;
    border-collapse: collapse; /* 建议添加 */
}

table tr {
    border-top: 1px solid var(--border-color); /* 变量替换 */
    margin: 0;
    padding: 0;
    background-color: transparent;
}

/* 隔行变色 */
table tr:nth-child(2n),
thead {
    background-color: var(--bg-table-stripe); /* 变量替换 */
}

table tr th {
    font-weight: bold;
    border: 1px solid var(--border-color); /* 变量替换 */
    border-bottom: 0;
    text-align: left;
    margin: 0;
    padding: 6px 13px;
    color: var(--text-heading); /* 表头文字颜色 */
}

table tr td {
    border: 1px solid var(--border-color); /* 变量替换 */
    text-align: left;
    margin: 0;
    padding: 6px 13px;
}

table tr th:first-child, table tr td:first-child { margin-top: 0; }
table tr th:last-child, table tr td:last-child { margin-bottom: 0; }

tt { margin: 0 2px; }
.hidden { display: none; }

/* ================= 目录区域 (TOC) ================= */
#tocArea {
    position: fixed;
    top: 0%;
    left: 0%;
    margin-top: calc(var(--topnav-height) + 2vh);
    margin-left: 1vw;
    max-height: 90vh;

    border-radius: 24px;
    border: var(--border-dashed) 1px solid; /* 变量替换 */
    overflow-y: auto;
    background-color: var(--bg-body); /* 保持和背景一致或使用--bg-sidebar */
    z-index: 999;
    box-shadow: var(--shadow-toc); /* 变量替换 */
}

.toc {
    max-width: 260px;
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-main);

    background: var(--bg-toc); /* 变量替换 */
    border-radius: 8px;
    padding: 12px 16px;
    box-sizing: border-box;
}

/* 顶部标题 */
.toc::before {
    content: "目录";
    display: block;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted); /* 变量替换 */
    margin-bottom: 6px;
}

.toc ul {
    list-style: none;
    margin: 0;
    padding-left: 0;
}

.toc > ul { padding-left: 0; }

.toc ul ul {
    margin-top: 4px;
    margin-bottom: 4px;
    padding-left: 14px;
    border-left: 1px dashed var(--border-dashed); /* 变量替换 */
}

.toc li {
    margin: 2px 0;
    position: relative;
}

/* 目录链接样式 */
.toc a {
    display: block;
    padding: 3px 4px;
    border-radius: 4px;

    font-size: 14px;
    color: var(--text-main); /* 变量替换 */
    text-decoration: none;

    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    transition: all 0.2s;
}

/* 悬停效果 */
.toc a:hover {
    color: var(--text-heading);
    background-color: var(--bg-toc-hover); /* 变量替换 */
    padding-left: 7px;
}

/* 当前激活项 */
.toc a.active {
    color: var(--color-link-active); /* 变量替换 */
    background-color: var(--bg-toc-active); /* 变量替换 */
    font-weight: 600;
}

.toc li > ul { margin-left: 6px; }

#contentArea, .topTitle {
    word-wrap: break-word;     /* 长单词或连续字符也能换行 */
    word-break: break-word;  /* 兼容旧浏览器 */
    overflow-wrap: break-word; /* 标准写法 */
    white-space: normal;       /* 确保允许自动换行 */
}