/* ===== 全局重置 & 基础 ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #818cf8;
    --secondary: #7c3aed;
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --text: #0f172a;
    --text-secondary: #475569;
    --border: #e2e8f0;
    --code-bg: #0f172a;
    --code-text: #e2e8f0;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    --radius: 12px;
    --transition: 0.25s ease;
    --header-height: 64px;
    --toc-width: 260px;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ===== 滚动条美化 ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-light);
    border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* ===== 头部 ===== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1000;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    backdrop-filter: blur(12px);
    background: rgba(255, 255, 255, 0.92);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
    color: var(--primary);
    text-decoration: none;
    letter-spacing: -0.3px;
}

.header-brand svg {
    width: 28px;
    height: 28px;
}

.header-brand span {
    color: var(--text);
    font-weight: 400;
}

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

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 26px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    color: var(--text);
    transition: background var(--transition);
    line-height: 1;
}

.menu-toggle:hover {
    background: var(--bg);
}

/* ===== 布局 ===== */
.app-wrapper {
    display: flex;
    margin-top: var(--header-height);
    flex: 1;
    min-height: calc(100vh - var(--header-height));
}

/* ===== 侧边目录 (TOC) ===== */
.toc-sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--toc-width);
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    padding: 28px 16px 32px;
    overflow-y: auto;
    z-index: 100;
    transition: transform var(--transition), opacity var(--transition);
}

.toc-sidebar .toc-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.toc-sidebar .toc-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.toc-sidebar .toc-list li a {
    display: block;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all var(--transition);
    font-weight: 450;
    border-left: 3px solid transparent;
}

.toc-sidebar .toc-list li a:hover {
    background: var(--bg);
    color: var(--text);
    border-left-color: var(--primary-light);
}

.toc-sidebar .toc-list li a.active {
    background: rgba(79, 70, 229, 0.08);
    color: var(--primary);
    font-weight: 600;
    border-left-color: var(--primary);
}

/* ===== 主内容 ===== */
.main-content {
    flex: 1;
    margin-left: var(--toc-width);
    padding: 40px 48px 80px;
    max-width: 960px;
}

/* ===== 移动端 TOC 遮罩 ===== */
.toc-overlay {
    display: none;
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.35);
    z-index: 99;
    backdrop-filter: blur(2px);
    animation: fadeIn 0.25s ease;
}

.toc-overlay.open {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ===== 章节卡片 ===== */
.section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 32px 36px 40px;
    margin-bottom: 32px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    scroll-margin-top: calc(var(--header-height) + 24px);
}

.section:last-child {
    margin-bottom: 0;
}

.section h2 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.4px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section h2 .badge {
    font-size: 14px;
    font-weight: 600;
    background: var(--primary);
    color: #fff;
    padding: 0 12px;
    border-radius: 20px;
    line-height: 28px;
    letter-spacing: 0;
}

.section .section-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 16px;
}

.section p {
    margin-bottom: 18px;
    color: var(--text);
    font-size: 16px;
}

.section p:last-child {
    margin-bottom: 0;
}

/* ===== 示意图 ===== */
.demo-box {
    background: #f8fafc;
    border-radius: 10px;
    padding: 20px;
    margin: 20px 0 24px;
    border: 1px solid var(--border);
    overflow: auto;
}

.demo-box .demo-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: block;
}

.demo-container {
    display: flex;
    background: #eef2ff;
    border-radius: 8px;
    padding: 16px;
    min-height: 100px;
    gap: 8px;
    border: 2px dashed #c7d2fe;
    transition: all 0.3s ease;
    position: relative;
    flex-wrap: wrap;
}

.demo-container .demo-item {
    padding: 12px 20px;
    border-radius: 6px;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    text-align: center;
    min-width: 48px;
    flex-shrink: 0;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.demo-item:nth-child(1) {
    background: #3b82f6;
}

.demo-item:nth-child(2) {
    background: #8b5cf6;
}

.demo-item:nth-child(3) {
    background: #ec4899;
}

.demo-item:nth-child(4) {
    background: #f59e0b;
}

.demo-item:nth-child(5) {
    background: #10b981;
}

.demo-item:nth-child(6) {
    background: #ef4444;
}

.demo-container .demo-item.small {
    padding: 8px 14px;
    font-size: 12px;
}

.demo-container .demo-item.tall {
    padding: 24px 20px;
}

.demo-container .demo-item.short {
    padding: 6px 20px;
}

/* 各属性演示 */
.demo-row {
    flex-direction: row;
}

.demo-row-reverse {
    flex-direction: row-reverse;
}

.demo-column {
    flex-direction: column;
    min-height: 160px;
}

.demo-column-reverse {
    flex-direction: column-reverse;
    min-height: 160px;
}

.demo-wrap {
    flex-wrap: wrap;
    width: 100%;
}

.demo-wrap .demo-item {
    min-width: 70px;
}

.demo-justify-start {
    justify-content: flex-start;
}

.demo-justify-center {
    justify-content: center;
}

.demo-justify-end {
    justify-content: flex-end;
}

.demo-justify-between {
    justify-content: space-between;
}

.demo-justify-around {
    justify-content: space-around;
}

.demo-align-start {
    align-items: flex-start;
    min-height: 130px;
}

.demo-align-center {
    align-items: center;
    min-height: 130px;
}

.demo-align-end {
    align-items: flex-end;
    min-height: 130px;
}

.demo-align-stretch {
    align-items: stretch;
    min-height: 130px;
}

.demo-align-stretch .demo-item {
    padding: 12px 20px;
    min-height: auto;
}

.demo-grow .demo-item:nth-child(1) {
    flex-grow: 1;
}

.demo-grow .demo-item:nth-child(2) {
    flex-grow: 2;
}

.demo-grow .demo-item:nth-child(3) {
    flex-grow: 1;
}

.demo-grow-2 .demo-item:nth-child(1) {
    flex-grow: 0;
}

.demo-grow-2 .demo-item:nth-child(2) {
    flex-grow: 3;
}

.demo-grow-2 .demo-item:nth-child(3) {
    flex-grow: 1;
}

/* ===== 代码块 ===== */
.code-wrapper {
    position: relative;
    margin: 20px 0 0;
    border-radius: 10px;
    overflow: hidden;
    background: var(--code-bg);
    border: 1px solid #1e293b;
}

.code-wrapper .code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: #1e293b;
    border-bottom: 1px solid #334155;
}

.code-wrapper .code-header .lang {
    font-size: 12px;
    font-weight: 500;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.code-wrapper .code-header .copy-btn {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition);
    opacity: 0;
    pointer-events: none;
}

.code-wrapper .code-header .copy-btn svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.code-wrapper:hover .code-header .copy-btn {
    opacity: 1;
    pointer-events: auto;
}

.code-wrapper .code-header .copy-btn:hover {
    color: #e2e8f0;
    background: #334155;
}

.code-wrapper .code-header .copy-btn.copied {
    color: #34d399;
}

.code-wrapper .code-header .copy-btn.copied svg {
    stroke: #34d399;
}

.code-wrapper pre {
    padding: 20px 24px;
    margin: 0;
    overflow-x: auto;
    background: var(--code-bg);
    color: var(--code-text);
    font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
    font-size: 14px;
    line-height: 1.8;
    tab-size: 2;
    white-space: pre;
    max-width: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
}

.code-wrapper pre code {
    font-family: inherit;
    color: inherit;
    background: none;
    padding: 0;
}

/* 代码高亮（简单） */
.code-wrapper pre .hl-comment {
    color: #64748b;
}

.code-wrapper pre .hl-keyword {
    color: #c084fc;
}

.code-wrapper pre .hl-string {
    color: #34d399;
}

.code-wrapper pre .hl-property {
    color: #60a5fa;
}

.code-wrapper pre .hl-value {
    color: #fbbf24;
}

.code-wrapper pre .hl-selector {
    color: #f472b6;
}

.code-wrapper pre .hl-punctuation {
    color: #94a3b8;
}

/* ===== 外部链接 ===== */
.resource-links {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.resource-links h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text);
}

.resource-links ul {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
}

.resource-links ul li a {
    color: var(--primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: color var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.resource-links ul li a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.resource-links ul li a::after {
    content: "→";
    transition: transform var(--transition);
    display: inline-block;
}

.resource-links ul li a:hover::after {
    transform: translateX(4px);
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 28px 24px;
    border-top: 1px solid var(--border);
    margin-top: 12px;
    color: var(--text-secondary);
    font-size: 14px;
    background: var(--card-bg);
}

.footer a {
    color: var(--primary);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* ===== 响应式 ===== */

/* 平板 & 小屏幕 */
@media (max-width: 1024px) {
    .main-content {
        padding: 28px 28px 60px;
    }
}

/* 移动端 */
@media (max-width: 820px) {
    :root {
        --toc-width: 280px;
    }

    .menu-toggle {
        display: block;
    }

    .toc-sidebar {
        transform: translateX(-110%);
        opacity: 0;
        width: var(--toc-width);
        padding: 20px 16px 32px;
        box-shadow: 4px 0 32px rgba(0, 0, 0, 0.08);
        transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease;
    }

    .toc-sidebar.open {
        transform: translateX(0);
        opacity: 1;
    }

    .main-content {
        margin-left: 0;
        padding: 20px 16px 48px;
    }

    .section {
        padding: 20px 18px 28px;
        border-radius: 10px;
    }

    .section h2 {
        font-size: 21px;
    }

    .section h2 .badge {
        font-size: 12px;
        line-height: 24px;
        padding: 0 10px;
    }

    /* ===== 移动端关键修复：强制演示容器换行，防止溢出 ===== */
    .demo-container {
        flex-wrap: wrap !important;
    }

    .demo-container .demo-item {
        flex-shrink: 1 !important;
        min-width: 40px !important;
    }

    .code-wrapper pre {
        font-size: 13px;
        padding: 14px 16px;
        line-height: 1.7;
    }

    .code-wrapper .code-header .copy-btn {
        opacity: 1;
        pointer-events: auto;
        padding: 4px 8px;
        font-size: 12px;
    }

    .resource-links ul {
        flex-direction: column;
        gap: 6px;
    }

    .header {
        padding: 0 16px;
    }

    .header-brand {
        font-size: 16px;
    }

    .header-brand svg {
        width: 24px;
        height: 24px;
    }

    .toc-overlay.open {
        display: block;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 12px 10px 40px;
    }

    .section {
        padding: 16px 14px 22px;
    }

    .section h2 {
        font-size: 18px;
        flex-wrap: wrap;
    }

    .demo-container {
        padding: 10px;
        min-height: 64px;
    }

    .demo-container .demo-item {
        min-width: 28px !important;
        padding: 6px 8px !important;
        font-size: 11px !important;
    }

    .code-wrapper pre {
        font-size: 12px;
        padding: 12px 14px;
    }

    .code-wrapper .code-header .lang {
        font-size: 10px;
    }

    .code-wrapper .code-header .copy-btn {
        font-size: 11px;
    }

    .header-brand {
        font-size: 14px;
    }

    .menu-toggle {
        font-size: 22px;
    }

    /* 打赏二维码在超小屏上的间距优化 */
    .donate-cards {
        gap: 16px !important;
    }

    .donate-cards .card img {
        width: 120px !important;
        height: 120px !important;
    }
}

/* ===== 工具类 ===== */
.text-center {
    text-align: center;
}

.mt-8 {
    margin-top: 8px;
}

.mt-16 {
    margin-top: 16px;
}

.mb-8 {
    margin-bottom: 8px;
}

.flex {
    display: flex;
}

.gap-2 {
    gap: 8px;
}

.items-center {
    align-items: center;
}

/* ===== 视频容器 ===== */
.video-wrapper {
    position: relative;
    padding-bottom: 56.25%;
    /* 16:9 宽高比 */
    height: 0;
    overflow: hidden;
    border-radius: 10px;
    margin: 16px 0 8px;
    background: #0f172a;
}

.video-wrapper video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
}

/* ===== 打赏卡片 ===== */
.donate-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
    justify-content: center;
    margin: 24px 0 8px;
}

.donate-cards .card {
    text-align: center;
    background: #f8fafc;
    padding: 20px 24px 24px;
    border-radius: 12px;
    border: 1px solid var(--border);
    min-width: 140px;
    flex: 0 1 auto;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.donate-cards .card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

.donate-cards .card .icon {
    font-size: 22px;
    margin-bottom: 6px;
    display: block;
}

.donate-cards .card .title {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 10px;
    color: var(--text);
}

.donate-cards .card img {
    width: 150px;
    height: 150px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #fff;
    display: block;
    margin: 0 auto;
}

.donate-cards .card .hint {
    margin-top: 10px;
    font-size: 13px;
    color: var(--text-secondary);
}

/* ===== Toast 提示 ===== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #0f172a;
    color: #e2e8f0;
    padding: 10px 24px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: all 0.4s ease;
    z-index: 9999;
    pointer-events: none;
    border: 1px solid #334155;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    border-color: #34d399;
    color: #34d399;
}

img {
    width: 100%;
    border: 4px solid #4A90D9;
    /* 边框：宽度、样式、颜色 */
    border-radius: 12px;
    /* 圆角，让边框和阴影更柔和 */
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
    /* 阴影：水平偏移 垂直偏移 模糊半径 颜色 */
    display: block;
    /* 避免行内元素带来的额外间距 */
    max-width: 100%;
    height: auto;
}

a {
    text-decoration: none;
}

.card .icon svg {
    height: 40px;
}