/* ============================================================
   CSS Variables — 极简双主题
   ============================================================ */
:root {
    --bg-body: #181818;
    --bg-sidebar: #1e1e1e;
    --bg-card: #222222;
    --bg-card-hover: #2a2a2a;
    --bg-code: #2a2a2a;
    --bg-code-block: #0d1117;
    --bg-table-stripe: #222222;
    --bg-blockquote: #2a2a2a;
    --bg-mark: #5b4b1a;
    --bg-example: #222222;

    --text-primary: #e6edf3;
    --text-secondary: #b0b8c7;
    --text-muted: #8b949e;
    --text-code: #f0888e;
    --text-code-block: #e6edf3;
    --text-link: #58a6ff;
    --text-link-hover: #79c0ff;
    --text-heading: #f0f6fc;

    --border-color: #30363d;
    --border-sidebar: #30363d;
    --border-table: #30363d;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);

    --radius: 8px;
    --radius-lg: 12px;

    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-light: #1c3a5a;

    --transition: 0.25s ease;

    --copy-btn-bg: rgba(30, 30, 30, 0.7);
    --copy-btn-color: #e6edf3;
    --copy-btn-hover: #2d333b;
    --copy-btn-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
    --bg-body: #f8fafc;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f5f9;
    --bg-code: #f1f5f9;
    --bg-code-block: #f1f5f9;
    --bg-table-stripe: #f8fafc;
    --bg-blockquote: #f0f7ff;
    --bg-mark: #fef08a;
    --bg-example: #fafbfc;

    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --text-code: #e11d48;
    --text-code-block: #0f172a;
    --text-link: #2563eb;
    --text-link-hover: #1d4ed8;
    --text-heading: #0f172a;

    --border-color: #e2e8f0;
    --border-sidebar: #e2e8f0;
    --border-table: #d1d5db;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.08);

    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-light: #dbeafe;

    --copy-btn-bg: rgba(255, 255, 255, 0.7);
    --copy-btn-color: #1e293b;
    --copy-btn-hover: #ffffff;
    --copy-btn-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* ===== 自定义代码字体：Cascadia Code ===== */
@font-face {
    font-family: 'Cascadia Code';
    src: url('https://learn.lanwane.top/fonts/code.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* ===== Reset & Base ===== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
html {
    scroll-behavior: smooth;
    font-size: 16px;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.7;
    transition: background var(--transition), color var(--transition);
    display: flex;
    min-height: 100vh;
}
a {
    color: var(--text-link);
    text-decoration: none;
    transition: color var(--transition);
}
a:hover {
    color: var(--text-link-hover);
    text-decoration: underline;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg-body);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 290px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-sidebar);
    overflow-y: auto;
    padding: 24px 16px 32px;
    z-index: 100;
    transition: background var(--transition), border-color var(--transition), transform 0.3s ease;
    display: flex;
    flex-direction: column;
}
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
    flex-shrink: 0;
}
.sidebar-logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.3px;
}
.sidebar-logo span {
    color: var(--accent);
}
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background var(--transition);
}
.sidebar-toggle:hover {
    background: var(--bg-code);
}

.nav {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
}
.nav::-webkit-scrollbar {
    width: 4px;
}

.nav-node {
    margin-bottom: 2px;
}
.nav-node>.nav-item-wrapper {
    display: flex;
    align-items: center;
    border-radius: 6px;
    transition: background var(--transition);
}
.nav-node>.nav-item-wrapper:hover {
    background: var(--bg-code);
}
.nav-node>.nav-item-wrapper .nav-item {
    flex: 1;
    padding: 5px 8px 5px 8px;
    font-size: 14px;
    color: var(--text-secondary);
    border-radius: 6px;
    transition: all var(--transition);
    cursor: pointer;
    text-decoration: none;
    line-height: 1.5;
    background: transparent;
    border: none;
    text-align: left;
    font-family: inherit;
}
.nav-node>.nav-item-wrapper .nav-item:hover {
    background: transparent;
    color: var(--text-primary);
    text-decoration: none;
}
.nav-node>.nav-item-wrapper .nav-item.active {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 500;
}
.nav-node.level-1>.nav-item-wrapper .nav-item {
    padding-left: 8px;
    font-weight: 500;
}
.nav-node.level-2>.nav-item-wrapper .nav-item {
    padding-left: 28px;
    font-size: 13px;
}
.nav-node.level-3>.nav-item-wrapper .nav-item {
    padding-left: 48px;
    font-size: 12.5px;
    color: var(--text-muted);
}
.nav-node.level-3>.nav-item-wrapper .nav-item:hover {
    color: var(--text-primary);
}

.toggle-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all var(--transition);
    flex-shrink: 0;
    margin-right: 2px;
}
.toggle-btn:hover {
    background: var(--bg-code);
    color: var(--text-primary);
}
.toggle-btn .arrow {
    display: inline-block;
    transition: transform 0.2s ease;
    font-size: 10px;
    line-height: 1;
}
.toggle-btn .arrow.collapsed {
    transform: rotate(-90deg);
}
.nav-node.no-children .toggle-btn {
    visibility: hidden;
}

.nav-children {
    overflow: hidden;
    transition: max-height 0.25s ease;
    max-height: 2000px;
}
.nav-children.collapsed {
    max-height: 0;
}

.theme-toggle-wrap {
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    margin-top: 8px;
}
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-code);
    border: none;
    border-radius: 40px;
    padding: 6px 14px 6px 10px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
    width: fit-content;
}
.theme-toggle:hover {
    background: var(--border-color);
    color: var(--text-primary);
}
.theme-toggle .icon {
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
}
.theme-toggle .label {
    font-size: 13px;
}

/* ===== Mobile header ===== */
#mobileHeader {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 54px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    z-index: 60;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    transition: background var(--transition), border-color var(--transition);
    box-shadow: var(--shadow-sm);
}
#mobileHeader .menu-btn {
    background: none;
    border: none;
    font-size: 26px;
    line-height: 1;
    color: var(--text-primary);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    transition: background var(--transition);
}
#mobileHeader .menu-btn:hover {
    background: var(--bg-code);
}
#mobileHeader .brand {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.3px;
    flex: 1;
}
#mobileHeader .brand span {
    color: var(--accent);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 99;
    backdrop-filter: blur(2px);
    transition: opacity 0.3s ease;
}
.sidebar-overlay.active {
    display: block;
}

/* ===== Main ===== */
.main {
    margin-left: 290px;
    flex: 1;
    min-height: 100vh;
    padding: 48px 56px 80px;
    max-width: 1100px;
    transition: background var(--transition), color var(--transition), padding var(--transition);
}
.main-inner {
    max-width: 840px;
    margin: 0 auto;
}

/* ===== Typography ===== */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-heading);
    font-weight: 600;
    line-height: 1.3;
    margin-top: 2em;
    margin-bottom: 0.6em;
    scroll-margin-top: 20px;
    transition: color var(--transition);
}
h1 {
    font-size: 2.2rem;
    margin-top: 0.2em;
    margin-bottom: 0.4em;
    letter-spacing: -0.5px;
}
h2 {
    font-size: 1.65rem;
    margin-top: 2.2em;
    padding-bottom: 0.3em;
    border-bottom: 2px solid var(--border-color);
}
h3 {
    font-size: 1.3rem;
    margin-top: 1.8em;
}
h4 {
    font-size: 1.1rem;
    margin-top: 1.4em;
    font-weight: 600;
}
p {
    margin-bottom: 1em;
}

/* ===== Code ===== */
code,
pre code,
.hljs {
    font-family: 'Cascadia Code', 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Menlo', monospace;
    font-feature-settings:
        "calt" 1, "ss02" 1, "ss03" 1, "ss04" 1,
        "ss19" 1, "zero" 1, "cv01" 1, "cv02" 1;
}

code {
    font-size: 0.88em;
    padding: 0.2em 0.5em;
    border-radius: 4px;
    background: var(--bg-code);
    color: var(--text-code);
    transition: background var(--transition), color var(--transition);
}
pre {
    position: relative;
    background: var(--bg-code-block);
    border-radius: var(--radius);
    padding: 18px 20px;
    overflow-x: auto;
    margin: 1.2em 0;
    border: 1px solid var(--border-color);
    transition: background var(--transition), border-color var(--transition);
}
pre code {
    background: transparent;
    color: var(--text-code-block);
    padding: 0;
    font-size: 0.85rem;
    line-height: 1.6;
    font-weight: 400;
    white-space: pre;
}
.hljs {
    background: transparent !important;
    color: inherit !important;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--copy-btn-bg);
    backdrop-filter: blur(4px);
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--copy-btn-color);
    box-shadow: var(--copy-btn-shadow);
    cursor: pointer;
    transition: all var(--transition);
    z-index: 5;
    line-height: 1.6;
    opacity: 0;
    pointer-events: none;
    font-family: inherit;
}
pre:hover .copy-btn {
    opacity: 1;
    pointer-events: auto;
}
.copy-btn:hover {
    background: var(--copy-btn-hover);
    transform: scale(1.02);
}
.copy-btn.copied {
    background: var(--accent);
    color: #fff;
    opacity: 1;
}
@media (max-width:600px) {
    .copy-btn {
        opacity: 1;
        pointer-events: auto;
        top: 4px;
        right: 4px;
        padding: 2px 8px;
        font-size: 11px;
    }
}

/* ===== Blockquote ===== */
blockquote {
    margin: 1.4em 0;
    padding: 0.8em 1.2em 0.8em 1.2em;
    border-left: 4px solid var(--accent);
    background: var(--bg-blockquote);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-secondary);
    transition: background var(--transition), border-color var(--transition);
}
blockquote p {
    margin-bottom: 0.4em;
}
blockquote p:last-child {
    margin-bottom: 0;
}
blockquote blockquote {
    margin: 0.6em 0 0.4em 1.2em;
    border-left-color: var(--text-muted);
}

/* ===== Lists ===== */
ul,
ol {
    padding-left: 1.6em;
    margin-bottom: 1em;
}
li {
    margin-bottom: 0.2em;
}
li>ul,
li>ol {
    margin-top: 0.2em;
    margin-bottom: 0.2em;
}

/* ===== Tables ===== */
.table-wrap {
    overflow-x: auto;
    margin: 1.4em 0;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    transition: border-color var(--transition);
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}
th,
td {
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    text-align: left;
    transition: border-color var(--transition);
}
th {
    background: var(--bg-code);
    font-weight: 600;
    color: var(--text-heading);
}
tr:nth-child(even) {
    background: var(--bg-table-stripe);
}
tr:hover {
    background: var(--bg-code);
}
.table-wrap table {
    border: none;
}
.table-wrap th,
.table-wrap td {
    border-color: var(--border-color);
}
.table-wrap th:first-child,
.table-wrap td:first-child {
    border-left: none;
}
.table-wrap th:last-child,
.table-wrap td:last-child {
    border-right: none;
}

/* ===== Example block ===== */
.example-block {
    margin: 1.6em 0 2em;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-example);
    transition: background var(--transition), border-color var(--transition);
}
.example-block .example-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    padding: 8px 18px;
    background: var(--bg-code);
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition), border-color var(--transition);
}
.example-block .example-source {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-color);
}
.example-block .example-source pre {
    margin: 0;
    border: none;
    border-radius: 0;
    padding: 12px 16px;
    background: var(--bg-code-block);
}
.example-block .example-source pre code {
    color: var(--text-code-block);
}
.example-block .example-render {
    padding: 16px 20px;
    background: var(--bg-content);
    transition: background var(--transition);
}

/* ===== HR ===== */
hr {
    border: none;
    height: 1px;
    background: var(--border-color);
    margin: 2.4em 0;
    transition: background var(--transition);
}

/* ===== Footnotes ===== */
.footnotes {
    margin-top: 2.4em;
    padding-top: 1.2em;
    border-top: 2px solid var(--border-color);
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.footnotes ol {
    padding-left: 1.6em;
}
.footnotes li {
    margin-bottom: 0.4em;
}
.footnote-ref {
    font-size: 0.75em;
    vertical-align: super;
    line-height: 1;
    color: var(--text-link);
}

/* ===== Mark ===== */
mark {
    background: var(--bg-mark);
    color: var(--text-primary);
    padding: 0.1em 0.3em;
    border-radius: 3px;
    transition: background var(--transition), color var(--transition);
}

/* ===== Image placeholder ===== */
.img-placeholder {
    display: inline-block;
    background: var(--bg-code);
    color: var(--text-muted);
    padding: 2px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    border: 1px dashed var(--border-color);
    font-family: monospace;
}
.img-demo {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.text-muted {
    color: var(--text-muted);
}
.text-small {
    font-size: 0.9rem;
}

/* ===== Mermaid 图表容器 ===== */
.mermaid-wrapper {
    background: var(--bg-code-block);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin: 1.2em 0;
    border: 1px solid var(--border-color);
    overflow-x: auto;
}
.mermaid-wrapper .mermaid {
    text-align: center;
    background: transparent;
}

/* ===== Responsive ===== */
@media (max-width:900px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        box-shadow: var(--shadow-lg);
        padding-top: 16px;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-toggle {
        display: block;
    }
    .main {
        margin-left: 0;
        padding: 68px 24px 60px;
    }
    #mobileHeader {
        display: flex;
    }
    .sidebar-overlay.active {
        display: block;
    }
    h1 {
        font-size: 1.8rem;
    }
    h2 {
        font-size: 1.4rem;
    }
}
@media (max-width:600px) {
    .main {
        padding: 68px 16px 50px;
    }
    .example-block .example-source pre {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    th,
    td {
        padding: 6px 10px;
        font-size: 0.85rem;
    }
    .sidebar {
        width: 260px;
        padding: 16px 12px 24px;
    }
}
@media (min-width:901px) {
    .sidebar-toggle {
        display: none !important;
    }
    #mobileHeader {
        display: none !important;
    }
    .sidebar-overlay {
        display: none !important;
    }
    .sidebar {
        transform: translateX(0) !important;
        box-shadow: none;
    }
}

@media print {
    .sidebar {
        display: none;
    }
    .main {
        margin-left: 0;
        padding: 20px 30px;
    }
    .example-block {
        break-inside: avoid;
        border: 1px solid #ccc;
    }
    .theme-toggle-wrap,
    .sidebar-toggle,
    #mobileHeader,
    .sidebar-overlay {
        display: none !important;
    }
    body {
        background: #fff;
        color: #000;
    }
    pre {
        background: #f4f4f4 !important;
        border: 1px solid #ddd !important;
    }
    code {
        background: #f4f4f4 !important;
        color: #c7254e !important;
    }
    blockquote {
        background: #f9f9f9 !important;
        border-left-color: #2563eb !important;
    }
    .table-wrap {
        border: 1px solid #ddd !important;
    }
    th,
    td {
        border-color: #ddd !important;
    }
    th {
        background: #f0f0f0 !important;
    }
    .copy-btn {
        display: none !important;
    }
}