* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --accent: #4f6ef7;
    --accent-soft: #eef2ff;
    --bg: #f5f7fb;
    --panel-bg: #ffffff;
    --sidebar-bg: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --code-bg: #f6f8fa;
    --sidebar-width: 280px;
    --toc-width: 270px;
}

body {
    font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 30;
}

.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    z-index: 2;
}

.sidebar-header a {
    font-size: 0.8rem;
    color: var(--accent);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.sidebar-header a:hover { text-decoration: underline; }

.sidebar-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    margin-top: 10px;
}

.sidebar-nav {
    padding: 14px 10px 24px;
}

.nav-tree,
.nav-children {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-folder {
    border-radius: 10px;
    overflow: hidden;
}

.nav-folder-title {
    list-style: none;
    cursor: pointer;
    user-select: none;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 12px 10px 6px 10px;
}

.nav-folder-title::-webkit-details-marker { display: none; }

.nav-children {
    padding-left: 8px;
    border-left: 1px dashed #dbe1f0;
    margin-left: 10px;
}

.nav-link {
    display: block;
    color: var(--text);
    text-decoration: none;
    border-radius: 10px;
    padding: 9px 12px;
    margin-left: calc(var(--depth, 0) * 8px);
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
    font-size: 0.92rem;
    line-height: 1.4;
}

.nav-link:hover {
    background: #f3f6ff;
    color: var(--accent);
    transform: translateX(2px);
}

.nav-link.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

#menu-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 1.1rem;
    cursor: pointer;
}

#content-wrap {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    padding: 28px 28px 40px;
}

#content-grid {
    width: min(100%, 1540px);
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--toc-width);
    gap: 32px;
    align-items: start;
}

#markdown-body {
    min-width: 0;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 42px 52px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.04);
}

#toc-panel {
    position: sticky;
    top: 24px;
    align-self: start;
}

.toc-card {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px 16px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.04);
}

.toc-title {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--muted);
    text-transform: uppercase;
    margin-bottom: 12px;
}

#toc-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

.toc-link {
    text-decoration: none;
    color: var(--muted);
    border-left: 2px solid transparent;
    padding: 7px 8px 7px 12px;
    font-size: 0.88rem;
    line-height: 1.4;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
    border-radius: 8px;
}

.toc-link:hover {
    color: var(--accent);
    background: #f8faff;
}

.toc-link.active {
    color: var(--accent);
    border-left-color: var(--accent);
    background: var(--accent-soft);
}

.toc-level-2 { padding-left: 24px; }
.toc-level-3 { padding-left: 36px; }

.toc-empty {
    color: var(--muted);
    font-size: 0.88rem;
    line-height: 1.5;
}

#markdown-body h1,
#markdown-body h2,
#markdown-body h3,
#markdown-body h4,
#markdown-body h5,
#markdown-body h6 {
    scroll-margin-top: 24px;
}

#markdown-body h1 { font-size: 2.15rem; margin-bottom: 12px; border-bottom: 2px solid var(--border); padding-bottom: 12px; }
#markdown-body h2 { font-size: 1.6rem; margin: 40px 0 14px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
#markdown-body h3 { font-size: 1.2rem; margin: 30px 0 10px; }
#markdown-body p { line-height: 1.82; margin-bottom: 16px; }
#markdown-body ul, #markdown-body ol { padding-left: 1.5em; margin-bottom: 16px; }
#markdown-body li { line-height: 1.82; margin-bottom: 4px; }
#markdown-body a { color: var(--accent); text-decoration: none; }
#markdown-body a:hover { text-decoration: underline; }

#markdown-body img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    margin: 16px 0 20px;
}

#markdown-body code {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 0.875em;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

#markdown-body pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 22px;
    overflow-x: auto;
    margin-bottom: 22px;
}

#markdown-body pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.92rem;
}

#markdown-body .mermaid {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 22px;
    overflow-x: auto;
}

#markdown-body blockquote {
    border-left: 4px solid var(--accent);
    background: #f5f8ff;
    padding: 14px 16px;
    margin-bottom: 18px;
    border-radius: 0 8px 8px 0;
    color: var(--muted);
}

#markdown-body table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 22px;
    font-size: 0.92rem;
}

#markdown-body th,
#markdown-body td {
    border: 1px solid var(--border);
    padding: 10px 14px;
    text-align: left;
}

#markdown-body th { background: var(--code-bg); font-weight: 600; }
#markdown-body tr:nth-child(even) { background: #fafafa; }
#markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 34px 0; }

#markdown-body .task-list-item {
    list-style: none;
    margin-left: -1.5em;
    padding-left: 1.75em;
    position: relative;
}

#markdown-body .task-list-item input {
    position: absolute;
    left: 0;
    top: 0.35em;
}

#markdown-body .footnotes {
    margin-top: 36px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    color: var(--muted);
}

#markdown-body .footnote-ref,
#markdown-body .footnote-backref {
    font-size: 0.8em;
}

#markdown-body .header-anchor {
    margin-left: 8px;
    opacity: 0;
    font-size: 0.85em;
}

#markdown-body h1:hover .header-anchor,
#markdown-body h2:hover .header-anchor,
#markdown-body h3:hover .header-anchor,
#markdown-body h4:hover .header-anchor,
#markdown-body h5:hover .header-anchor,
#markdown-body h6:hover .header-anchor {
    opacity: 1;
}

#markdown-body .md-alert {
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 18px;
    background: #fff;
}

#markdown-body .md-alert-title {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 6px;
}

#markdown-body .md-alert > :last-child {
    margin-bottom: 0;
}

#markdown-body .md-alert-note {
    border-left-color: #4f6ef7;
    background: #f4f7ff;
}

#markdown-body .md-alert-tip {
    border-left-color: #0f9d58;
    background: #f1fbf5;
}

#markdown-body .md-alert-warning {
    border-left-color: #d97706;
    background: #fff8eb;
}

#markdown-body .md-alert-danger {
    border-left-color: #dc2626;
    background: #fff4f4;
}

#markdown-body details.md-details {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    padding: 12px 14px;
    margin-bottom: 18px;
}

#markdown-body details.md-details summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 10px;
}

.loading {
    color: var(--muted);
    font-size: 0.95rem;
    padding: 40px 0;
}

@media (max-width: 1200px) {
    #content-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    #toc-panel {
        display: none;
    }

    #markdown-body {
        padding: 36px 34px;
    }
}

@media (max-width: 768px) {
    #menu-toggle { display: block; }

    #sidebar {
        left: -100%;
        transition: left 0.25s ease;
        z-index: 100;
    }

    #sidebar.open { left: 0; }

    #content-wrap {
        margin-left: 0;
        padding: 64px 16px 28px;
    }

    #markdown-body {
        padding: 26px 18px;
        border-radius: 16px;
    }
}