:root {
    --bg: #ffffff;
    --bg-sidebar: #f8f9fa;
    --bg-code: #f4f5f7;
    --text: #1a1a2e;
    --text-muted: #6c757d;
    --border: #e2e6ea;
    --accent: #2563eb;
    --accent-light: #eff6ff;
    --heading: #0f172a;
    --link: #2563eb;
    --sidebar-w: 260px;
    --table-stripe: #f8fafc;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --bg-sidebar: #1e293b;
        --bg-code: #1e293b;
        --text: #e2e8f0;
        --text-muted: #94a3b8;
        --border: #334155;
        --accent: #60a5fa;
        --accent-light: #1e3a5f;
        --heading: #f1f5f9;
        --link: #60a5fa;
        --table-stripe: #1e293b;
    }
}

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

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    padding: 24px 0;
    position: fixed;
    top: 0;
    left: 0;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 0 20px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}

.sidebar-header h2 {
    font-size: 16px;
    color: var(--heading);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.sidebar-header p {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.sidebar nav a {
    display: block;
    padding: 8px 20px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all 0.15s;
}

.sidebar nav a:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.sidebar nav a.active {
    background: var(--accent-light);
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 600;
}

/* Mobile toggle */
.menu-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 18px;
    color: var(--text);
}

/* Content */
.content {
    margin-left: var(--sidebar-w);
    flex: 1;
    max-width: 900px;
    padding: 40px 48px 80px;
}

.content h1 {
    font-size: 28px;
    color: var(--heading);
    font-weight: 800;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border);
    letter-spacing: -0.03em;
}

.content h2 {
    font-size: 22px;
    color: var(--heading);
    font-weight: 700;
    margin-top: 40px;
    margin-bottom: 12px;
    letter-spacing: -0.02em;
}

.content h3 {
    font-size: 18px;
    color: var(--heading);
    font-weight: 600;
    margin-top: 28px;
    margin-bottom: 8px;
}

.content h4 {
    font-size: 15px;
    color: var(--heading);
    font-weight: 600;
    margin-top: 20px;
    margin-bottom: 6px;
}

.content p {
    margin-bottom: 12px;
}

.content a {
    color: var(--link);
    text-decoration: none;
}

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

.content ul, .content ol {
    margin: 8px 0 12px 24px;
}

.content li {
    margin-bottom: 4px;
}

.content strong {
    font-weight: 600;
    color: var(--heading);
}

/* Code */
.content code {
    font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
    font-size: 13px;
    background: var(--bg-code);
    padding: 2px 6px;
    border-radius: 4px;
}

.content pre {
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
    overflow-x: auto;
    margin: 12px 0 16px;
    font-size: 13px;
    line-height: 1.6;
}

.content pre code {
    background: none;
    padding: 0;
}

/* Mermaid */
.mermaid {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin: 16px 0;
    text-align: center;
    overflow-x: auto;
}

/* Tables */
.content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0 16px;
    font-size: 14px;
}

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

.content th {
    background: var(--bg-code);
    font-weight: 600;
    color: var(--heading);
    white-space: nowrap;
}

.content tr:nth-child(even) {
    background: var(--table-stripe);
}

/* Blockquotes */
.content blockquote {
    border-left: 4px solid var(--accent);
    background: var(--accent-light);
    padding: 12px 16px;
    margin: 12px 0;
    border-radius: 0 6px 6px 0;
}

/* Horizontal rule */
.content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 32px 0;
}

/* Back to top */
.back-to-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 18px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 50;
}

.back-to-top.visible {
    opacity: 1;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .menu-toggle {
        display: block;
    }
    .content {
        margin-left: 0;
        padding: 60px 20px 60px;
    }
}

/* Index cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 16px;
    margin-top: 24px;
}

.card {
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px 24px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.card:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 12px rgba(37, 99, 235, 0.08);
}

.card h3 {
    margin: 0 0 8px;
    font-size: 17px;
}

.card h3 a {
    color: var(--accent);
    text-decoration: none;
}

.card p {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
    margin: 0;
}
