/* === 黑白主题 · 响应式 === */
:root {
    --bg: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #eaeaea;
    --text: #1a1a1a;
    --text-secondary: #555555;
    --text-muted: #888888;
    --border: #d0d0d0;
    --accent: #000000;
    --accent-hover: #333333;
    --code-bg: #f0f0f0;
    --mark-bg: #ffffb3;
    --sidebar-width: 280px;
    --header-height: 0px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1e1e1e;
        --bg-secondary: #252526;
        --bg-tertiary: #2d2d2d;
        --text: #d4d4d4;
        --text-secondary: #9b9b9b;
        --text-muted: #6e6e6e;
        --border: #3c3c3c;
        --accent: #007acc;
        --accent-hover: #1a8ad4;
        --code-bg: #1e1e1e;
        --mark-bg: #5a5a00;
    }
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.8;
    overflow-x: hidden;
}

/* ── 布局 ── */
.app {
    display: flex;
    min-height: 100vh;
}

/* ── 侧边栏 ── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 24px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.sidebar-home {
    text-decoration: none;
    color: inherit;
    display: block;
}

.sidebar-home:hover h2 {
    opacity: 0.7;
}

.sidebar-header p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.theme-toggle {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 6px 12px;
    font-size: 0.8rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.theme-toggle:hover {
    background: var(--border);
}

.sidebar nav ul {
    list-style: none;
    padding: 8px 0;
}

.sidebar nav ul li a {
    display: flex;
    flex-direction: column;
    padding: 10px 20px;
    color: var(--text);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
}

.sidebar nav ul li a:hover {
    background: var(--bg-tertiary);
    border-left-color: var(--accent);
}

.sidebar nav ul li a.active {
    background: var(--bg-tertiary);
    border-left-color: var(--accent);
    font-weight: 600;
}

.stage-num {
    font-size: 0.85rem;
    font-weight: 600;
}

.stage-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── 主内容区 ── */
.main {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 40px 48px;
    max-width: 960px;
}

/* ── 移动端侧栏切换按钮 ── */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 40px;
    height: 40px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px;
}

.sidebar-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.sidebar-toggle.open span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.sidebar-toggle.open span:nth-child(2) {
    opacity: 0;
}
.sidebar-toggle.open span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 99;
}

/* ── 首页样式 ── */
.landing {
    padding: 40px 0;
}

.landing-hero {
    padding: 60px 0 40px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 40px;
}

.landing-hero h1 {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.3;
}

.landing-hero p {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-top: 12px;
    max-width: 600px;
}

.landing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.landing-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    text-decoration: none;
    color: var(--text);
    transition: all 0.2s ease;
}

.landing-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.landing-card .card-num {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.landing-card h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.landing-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ── 阶段页面 ── */
.stage-header {
    padding-bottom: 24px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 32px;
}

.stage-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
}

.stage-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.stage-content {
    font-size: 1rem;
    line-height: 2;
}

/* ── 标题 ── */
.stage-content h1 { font-size: 1.6rem; font-weight: 700; margin: 36px 0 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.stage-content h2 { font-size: 1.35rem; font-weight: 700; margin: 28px 0 12px; }
.stage-content h3 { font-size: 1.15rem; font-weight: 600; margin: 24px 0 10px; }
.stage-content h4 { font-size: 1.05rem; font-weight: 600; margin: 20px 0 8px; }
.stage-content h5,
.stage-content h6 { font-size: 1rem; font-weight: 600; margin: 16px 0 6px; }

/* ── 段落 ── */
.stage-content p {
    margin-bottom: 12px;
}

/* ── 列表 ── */
.stage-content ul,
.stage-content ol {
    margin: 8px 0 12px 24px;
}

.stage-content li {
    margin-bottom: 6px;
}

.stage-content li > ul,
.stage-content li > ol {
    margin: 4px 0 4px 20px;
}

/* ── 代码 ── */
.stage-content code {
    font-family: "JetBrains Mono", "Fira Code", "Consolas", "Courier New", monospace;
    font-size: 0.88em;
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
}

.stage-content pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
    margin: 16px 0;
    overflow-x: auto;
    font-size: 0.88rem;
    line-height: 1.6;
}

.stage-content pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

/* ── 表格 ── */
.stage-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 0.95rem;
}

.stage-content th,
.stage-content td {
    border: 1px solid var(--border);
    padding: 8px 14px;
    text-align: left;
}

.stage-content th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.stage-content tr:nth-child(even) td {
    background: var(--bg-secondary);
}

/* ── 引用 ── */
.stage-content blockquote {
    border-left: 4px solid var(--accent);
    padding: 8px 16px;
    margin: 16px 0;
    background: var(--bg-secondary);
    border-radius: 0 6px 6px 0;
    color: var(--text-secondary);
}

/* ── 高亮 ── */
.stage-content mark {
    background: var(--mark-bg);
    color: inherit;
    padding: 1px 4px;
    border-radius: 3px;
}

/* ── 水平线 ── */
.stage-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 24px 0;
}

/* ── 响应式 ── */
/* ── 图片自适应（含移动端） ── */
.stage-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 16px auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-sizing: border-box;
}

/* 大图在移动端减小边距 */
@media (max-width: 480px) {
    .stage-content img {
        margin: 12px -4px;
        border-radius: 4px;
        max-width: calc(100% + 8px);
    }
}

/* ── 响应式 ── */
@media (max-width: 768px) {
    .sidebar-toggle {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .main {
        margin-left: 0;
        padding: 60px 16px 32px;
    }

    .landing-hero h1 {
        font-size: 1.6rem;
    }

    .landing-grid {
        grid-template-columns: 1fr;
    }

    .stage-header h1 {
        font-size: 1.3rem;
    }

    .stage-content {
        font-size: 0.95rem;
        line-height: 1.85;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    .stage-content pre {
        font-size: 0.78rem;
        padding: 12px 14px;
        margin: 12px -8px;
        border-radius: 4px;
        max-width: calc(100% + 16px);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .stage-content table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 0.85rem;
    }

    .stage-content th,
    .stage-content td {
        padding: 6px 10px;
        white-space: nowrap;
    }

    .stage-content blockquote {
        margin: 12px 0;
        padding: 6px 12px;
    }

    .stage-content ul,
    .stage-content ol {
        margin-left: 18px;
        padding-left: 0;
    }

    /* 目录折叠面板在移动端默认收起 */
    .toc {
        padding: 8px 12px;
    }
    .toc-list a {
        font-size: 0.82rem;
        padding: 2px 4px;
    }
}

/* 小平板 */
@media (min-width: 769px) and (max-width: 1024px) {
    .main {
        padding: 36px 32px;
    }
    .stage-content {
        font-size: 1rem;
    }
    .stage-content pre {
        font-size: 0.85rem;
    }
}

@media (min-width: 1200px) {
    .main {
        padding: 48px 64px;
    }
}

/* ── 滚动条 ── */
.sidebar::-webkit-scrollbar {
    width: 4px;
}
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* ── 打印优化 ── */
@media print {
    .sidebar, .sidebar-toggle, .sidebar-overlay {
        display: none !important;
    }
    .main {
        margin-left: 0 !important;
        padding: 20px !important;
    }
}

/* ── 目录 (TOC) ── */
.toc {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 24px;
}

.toc-title {
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    user-select: none;
    padding: 4px 0;
}

.toc-list {
    list-style: none;
    margin: 8px 0 0 !important;
    padding: 0 !important;
}

.toc-list li {
    margin: 2px 0 !important;
    padding: 0 !important;
}

.toc-list a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.88rem;
    display: block;
    padding: 3px 6px;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.toc-list a:hover {
    color: var(--accent);
    background: var(--bg-tertiary);
}

/* ── 返回顶部 ── */
.back-to-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 40px;
    height: 40px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--text);
    z-index: 50;
    opacity: 0.7;
    transition: opacity 0.2s ease;
    text-decoration: none;
}

.back-to-top:hover {
    opacity: 1;
}

.back-to-top.show {
    display: flex;
}

@media (max-width: 768px) {
    .back-to-top {
        bottom: 16px;
        right: 16px;
        width: 36px;
        height: 36px;
    }
}

/* ── 代码语法高亮配色（VS Code 风格） ── */
/* 亮色模式 — 类似 VS Code Light */
.hljs {
    color: #1a1a1a !important;
    background: transparent !important;
}
.hljs-comment,
.hljs-quote {
    color: #008000 !important;   /* 绿色 */
    font-style: italic !important;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-section,
.hljs-link {
    color: #0000ff !important;   /* 蓝色 */
    font-weight: 600 !important;
}
.hljs-type {
    color: #267f99 !important;   /* 青蓝 */
    font-weight: 500 !important;
}
.hljs-built_in {
    color: #0070c1 !important;   /* 天蓝 */
    font-weight: 500 !important;
}
.hljs-number {
    color: #098658 !important;   /* 深绿 */
}
.hljs-string,
.hljs-meta .hljs-string {
    color: #a31515 !important;   /* 暗红 */
}
.hljs-title,
.hljs-title.class_,
.hljs-title.function_ {
    color: #795e26 !important;   /* 棕黄 */
    font-weight: 500 !important;
}
.hljs-attr,
.hljs-attribute,
.hljs-variable {
    color: #001080 !important;   /* 深蓝 */
}
.hljs-template-tag,
.hljs-template-variable {
    color: #0451a5 !important;
}
.hljs-addition { font-weight: 600 !important; }
.hljs-deletion { font-weight: 600 !important; }
.hljs-meta {
    color: #643820 !important;   /* 棕色（预处理器） */
    font-weight: 500 !important;
}
.hljs-tag { color: #267f99 !important; }
.hljs-name { font-weight: 600 !important; }

/* 暗色模式 — 类似 VS Code Dark  */
@media (prefers-color-scheme: dark) {
    .hljs { color: #d4d4d4 !important; }
    .hljs-comment, .hljs-quote {
        color: #6a9955 !important;  /* 草绿 */
        font-style: italic !important;
    }
    .hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-section, .hljs-link {
        color: #569cd6 !important;  /* 亮蓝 */
        font-weight: 600 !important;
    }
    .hljs-type {
        color: #4ec9b0 !important;  /* 青绿 */
        font-weight: 500 !important;
    }
    .hljs-built_in {
        color: #569cd6 !important;  /* 亮蓝 */
        font-weight: 500 !important;
    }
    .hljs-number {
        color: #b5cea8 !important;  /* 浅绿 */
    }
    .hljs-string,
    .hljs-meta .hljs-string {
        color: #ce9178 !important;  /* 橙红 */
    }
    .hljs-title,
    .hljs-title.class_,
    .hljs-title.function_ {
        color: #dcdcaa !important;  /* 浅黄 */
        font-weight: 500 !important;
    }
    .hljs-attr, .hljs-attribute, .hljs-variable {
        color: #9cdcfe !important;  /* 亮青 */
    }
    .hljs-template-tag, .hljs-template-variable {
        color: #9cdcfe !important;
    }
    .hljs-meta {
        color: #c586c0 !important;  /* 淡紫（预处理器） */
        font-weight: 500 !important;
    }
    .hljs-tag { color: #4ec9b0 !important; }
    .hljs-name { font-weight: 600 !important; }
}

/* ── 手动暗色模式（Visual Studio 2022 深色主题） ── */
html.dark {
    --bg: #1e1e1e;
    --bg-secondary: #252526;
    --bg-tertiary: #2d2d2d;
    --text: #d4d4d4;
    --text-secondary: #9b9b9b;
    --text-muted: #6e6e6e;
    --border: #3c3c3c;
    --accent: #007acc;
    --accent-hover: #1a8ad4;
    --code-bg: #1e1e1e;
    --mark-bg: #5a5a00;
}

html.dark .hljs { color: #d4d4d4 !important; }
html.dark .hljs-comment,
html.dark .hljs-quote { color: #6a9955 !important; font-style: italic !important; }
html.dark .hljs-keyword,
html.dark .hljs-selector-tag,
html.dark .hljs-literal,
html.dark .hljs-section,
html.dark .hljs-link { color: #569cd6 !important; font-weight: 600 !important; }
html.dark .hljs-type { color: #4ec9b0 !important; font-weight: 500 !important; }
html.dark .hljs-built_in { color: #569cd6 !important; font-weight: 500 !important; }
html.dark .hljs-number { color: #b5cea8 !important; }
html.dark .hljs-string,
html.dark .hljs-meta .hljs-string { color: #ce9178 !important; }
html.dark .hljs-title,
html.dark .hljs-title.class_,
html.dark .hljs-title.function_ { color: #dcdcaa !important; font-weight: 500 !important; }
html.dark .hljs-attr,
html.dark .hljs-attribute,
html.dark .hljs-variable { color: #9cdcfe !important; }
html.dark .hljs-template-tag,
html.dark .hljs-template-variable { color: #9cdcfe !important; }
html.dark .hljs-addition { font-weight: 600 !important; }
html.dark .hljs-deletion { font-weight: 600 !important; }
html.dark .hljs-meta { color: #c586c0 !important; font-weight: 500 !important; }
html.dark .hljs-tag { color: #4ec9b0 !important; }
html.dark .hljs-name { font-weight: 600 !important; }
