:root {
    --bg: #fff;
    --text: #2d3748;
    --text-light: #4a5568;
    --border: #e2e8f0;
    --accent: #4299e1;
    --accent-hover: #3182ce;
    --sidebar-bg: #f7fafc;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --font-main: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --content-max-width: 1200px; /* 定义内容最大宽度 */
    --sidebar-width: 250px; /* 定义侧边栏宽度 */
    --content-gap: 1rem; /* 定义主内容和侧边栏之间的间距 */
    --header-padding-v: 1.5rem; /* 定义 header 垂直内边距 */
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
    color: var(--text);
    line-height: 1.7;
    background: var(--bg);
}

/* 关键修改：定义容器 */
.container {
    width: 100%;
    /* padding: 0 20px; 移除，由内部元素控制 */
}

/* 关键修改：让 header 内容、content-wrapper、footer 内容居中并限制宽度 */
.header-content,
.content-wrapper,
.footer-content {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: 0 20px; /* 内边距移到这里 */
}


header {
    padding: var(--header-padding-v) 0; /* 使用变量 */
    border-bottom: 1px solid var(--border);
    /* 移除之前的 max-width 和 margin */
}

/* --- 关键修改：header-content 使用 Flexbox 布局 --- */
.header-content {
    display: flex;
    flex-wrap: wrap; /* 允许在小屏幕上换行 */
    /* justify-content: space-between;  注释掉这个，不再使用两端对齐 */
    align-items: center; /* 垂直居中 */
    gap: 1rem; /* 元素间的最小间距 */
}
/* --- 修改结束 --- */

header h1 {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 600;
    flex-shrink: 0; /* 防止标题在空间不足时被压缩 */
}

header h1 a {
    color: var(--text);
    text-decoration: none;
}

/* --- 关键修改：水平主导航样式 --- */
header nav {
    flex-grow: 1; /* 导航占据剩余空间 */
    min-width: 200px; /* 给导航一个最小宽度 */
    margin: 0 25px; /* 根据要求设置 nav 的外边距 */
}
header nav ul {
    list-style: none;
    padding: 0;
    margin: 0; /* 重置 margin */
    display: flex; /* 水平排列 */
    flex-wrap: wrap; /* 允许换行 */
    /* gap: 1.5rem; */ /* 移除 gap，改用 margin-left */
    justify-content: flex-start; /* 关键修改：在导航区域左对齐 */
}

header nav li {
    /* 可以添加一些基础样式 */
    margin-left: 1.5rem; /* 关键修改：使用 margin-left 控制间距 */
}

/* 移除第一个 li 的左边距 */
header nav li:first-child {
    margin-left: 0;
}

header nav a {
    color: var(--text-light);
    text-decoration: none;
    font-size: 1.2rem; /* 根据要求设置字体大小为 1.2rem */
    font-weight: 500;
    transition: color 0.2s;
    display: block; /* 使整个区域可点击 */
    padding: 0.5rem 0; /* 上下内边距 */
    border-bottom: 2px solid transparent; /* 为活动状态预留空间 */
}

header nav a:hover {
    color: var(--accent);
}

header nav li.active a {
    color: var(--accent);
    font-weight: 600;
    border-bottom-color: var(--accent); /* 活动状态底部边框 */
}
/* --- 水平主导航样式结束 --- */


/* --- 关键修改：语言切换器样式 --- */
.lang-switch {
    display: flex;
    gap: 0.8rem; /* 语言项之间的间距 */
    align-items: center;
    font-size: 0.9rem;
    flex-shrink: 0; /* 防止被压缩 */
}

.lang-switch a {
    color: var(--text-light);
    text-decoration: none;
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    transition: all 0.2s ease;
    border: 1px solid transparent; /* 为活动状态预留边框 */
}

.lang-switch a:hover {
    color: var(--accent);
    background-color: rgba(66, 153, 225, 0.1); /* 悬停时的浅色背景 */
}

.lang-switch a.active {
    color: var(--accent);
    font-weight: 600;
    background-color: rgba(66, 153, 225, 0.1);
    border-color: var(--accent); /* 活动状态的边框 */
}
/* --- 语言切换器样式结束 --- */



/* 关键修改：调整 content-wrapper 样式 */
.content-wrapper {
    display: flex;
    /* 关键修改：调整 gap */
    gap: var(--content-gap);
    padding: 2rem 0; /* padding 移到 .header-content 等 */
    min-height: 60vh;
    /* 移除之前的 max-width 和 margin */
}

/* 关键修改：基础 main-content 样式 */
.main-content {
    /* 默认占据所有可用空间 */
    flex: 1;
    min-width: 0; /* 防止 flex 项目溢出 */
}

/* 关键修改：当有侧边栏时，main-content 占据 3 份，侧边栏固定宽度 */
.content-wrapper:not(.content-wrapper--no-sidebar) .main-content {
    flex: 3;
}
.content-wrapper:not(.content-wrapper--no-sidebar) .toc-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0; /* 防止侧边栏在空间不足时缩小 */
}

/* 关键修改：当没有侧边栏时，main-content 占据全部空间 */
.main-content--full-width {
    flex: 1 !important; /* 覆盖默认的 flex 值 */
}


/* 样式化页面描述 */
.page-description {
    font-size: 1.1rem;
    color: var(--text-light);
    margin-top: -0.5rem;
    margin-bottom: 1.5rem;
    font-weight: 400;
    font-style: italic;
    border-bottom: 1px dashed var(--border);
    padding-bottom: 0.5rem;
}

.markdown-content h1 {
    font-size: 2rem;
    margin: 0 0 1.5rem 0;
    font-weight: 600;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.markdown-content h2,
.markdown-content h3,
.markdown-content h4 {
    scroll-margin-top: calc(var(--header-padding-v) * 2 + 50px); /* 考虑 header 高度 */
}

/* 关键修改：调整 h2 字体大小 */
.markdown-content h2 {
    font-size: 1.4rem; /* 从 1.6rem 调整为 1.4rem */
    margin: 1.8em 0 0.8em;
    font-weight: 600;
    color: var(--text);
    border-left: 4px solid var(--accent);
    padding-left: 12px;
}

/* 关键修改：调整 h3 字体大小 */
.markdown-content h3 {
    font-size: 1.2rem; /* 从 1.3rem 调整为 1.2rem */
    margin: 1.5em 0 0.6em;
    color: var(--text-light);
}

.markdown-content p {
    margin: 0.8em 0;
}

.markdown-content pre {
    background: #f1f3f5;
    padding: 1rem;
    border-radius: 8px;
    overflow: auto;
    font-size: 0.95rem;
    border: 1px solid var(--border);
}

.markdown-content code {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    background: #f3f4f6;
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 0.95em;
    color: #d73a49;
}


.toc-sticky {
    position: sticky;
    top: 100px;
    background: var(--sidebar-bg);
    padding: 1.2rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.toc-sidebar h3 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    color: var(--text-light);
    font-weight: 600;
}

.toc-sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.95rem;
}

.toc-sidebar li {
    margin: 0.4em 0;
    padding-left: 0.2em;
}

.toc-sidebar li a {
    color: var(--text-light);
    text-decoration: none;
    display: block;
    transition: color 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toc-sidebar li a:hover,
.toc-sidebar li.active > a {
    color: var(--accent);
    font-weight: 500;
}

.toc-sidebar ul ul {
    margin-left: 1rem;
    margin-top: 0.2em;
}

footer {
    text-align: center;
    padding: 2rem 0;
    color: var(--text-light);
    font-size: 0.9rem;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
    /* 移除之前的 max-width 和 margin */
}

/* 关键修改：为 #content 添加左侧内边距 */
#content {
    padding-left: 20px;
}

/* --- 新增：长英文单词自动换行 --- */
/* 应用于 .markdown-content 内的所有块级元素，以处理段落、列表项等 */
.markdown-content {
    /* overflow-wrap: break-word; 是现代标准，更推荐 */
    overflow-wrap: break-word;
    /* word-break: break-word; 是旧的 WebKit 特有属性，但有时效果更佳，尤其是在处理连续字符时 */
    /* word-break: break-word; */
    /* 为了兼容性，可以同时使用两者，但 overflow-wrap: break-word 通常已足够 */
    /* hyphens: auto; */ /* 可选：添加连字符，但需要 lang 属性支持且效果依赖浏览器 */
}·
/* --- 新增样式结束 --- */


@media (max-width: 900px) {
    .content-wrapper {
        flex-direction: column;
    }

    .toc-sidebar {
        width: auto; /* 在小屏幕上恢复自适应宽度 */
        order: 1;
        margin-top: 2rem;
    }

    .main-content {
        order: 0;
    }

    .toc-sticky {
        position: static;
        box-shadow: none;
    }

    /* 在小屏幕上可能也需要调整 #content 的内边距 */
    #content {
        padding-left: 0; /* 移动端可能不需要左侧内边距 */
    }

    /* 关键修改：移动端导航垂直堆叠 */
    header nav ul {
        flex-direction: column;
        gap: 0.2rem;
        justify-content: flex-start; /* 在垂直方向上靠左对齐 */
    }
    header nav a {
       padding: 0.4rem 0;
    }
    /* 移动端简化子菜单显示 */
    header nav ul ul {
        position: static;
        box-shadow: none;
        border: none;
        padding-left: 1rem;
        margin-top: 0.2rem;
    }

    /* --- 关键修改：移动端 header 布局调整 --- */
    .header-content {
        flex-direction: column;
        align-items: flex-start; /* 子元素靠左对齐 */
        gap: 0.8rem;
    }

    header nav ul {
        justify-content: flex-start; /* 子菜单项靠左对齐 */
    }

    .lang-switch {
        align-self: flex-end; /* 语言切换器靠右对齐自身 */
        margin-top: 0.5rem; /* 与上方元素的间距 */
    }
    /* --- 移动端 header 布局调整结束 --- */

}