/* ===== Dark Theme (default) ===== */
:root {
    --bg: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a28;
    --bg-hover: #22223a;
    --text: #e8e8f0;
    --text-secondary: #b0b0c8;
    --text-muted: #707088;
    --accent: #7c6aef;
    --accent-light: #9d8fff;
    --accent-dim: rgba(124, 106, 239, 0.1);
    --border: #2a2a40;
    --border-light: #35355a;
    --success: #4ade80;
    --warning: #fbbf24;
    --tag-bg: rgba(124, 106, 239, 0.12);
    --tag-text: #b0a4ff;
    --code-bg: #16162a;
    --code-text: #c8c8e0;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --gradient-hero: linear-gradient(135deg, #e8e8f0 30%, #9d8fff 100%);
    --gradient-title: linear-gradient(135deg, #e8e8f0 0%, #9d8fff 100%);
}

/* ===== Light Theme ===== */
[data-theme="light"] {
    --bg: #f8f9fc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #f0f1f5;
    --text: #1a1a2e;
    --text-secondary: #4a4a68;
    --text-muted: #8888a0;
    --accent: #6c5ce7;
    --accent-light: #7c6aef;
    --accent-dim: rgba(108, 92, 231, 0.08);
    --border: #e2e4ea;
    --border-light: #d0d2da;
    --success: #22c55e;
    --warning: #f59e0b;
    --tag-bg: rgba(108, 92, 231, 0.08);
    --tag-text: #6c5ce7;
    --code-bg: #f1f0f8;
    --code-text: #4a4a68;
    --shadow: 0 4px 24px rgba(0,0,0,0.06);
    --gradient-hero: linear-gradient(135deg, #1a1a2e 30%, #6c5ce7 100%);
    --gradient-title: linear-gradient(135deg, #1a1a2e 0%, #6c5ce7 100%);
}

/* ===== Reset ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

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

/* ===== Theme Toggle ===== */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.25s ease;
    box-shadow: var(--shadow);
}

.theme-toggle:hover {
    border-color: var(--accent);
    transform: scale(1.08);
}

.theme-toggle .icon-moon { display: block; }
.theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    --sidebar-width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.sidebar-header {
    padding: 32px 24px 24px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

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

.nav-list {
    list-style: none;
    padding: 12px 12px;
    flex: 1;
}

.nav-list li a {
    display: flex;
    flex-direction: column;
    padding: 14px 16px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 400;
    transition: all 0.2s ease;
    gap: 4px;
}

.nav-list li a:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.nav-list li a.active {
    background: var(--accent-dim);
    color: var(--accent-light);
}

.nav-list li a .nav-tag {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.nav-list li a.active .nav-tag {
    color: var(--accent);
    opacity: 0.7;
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

.sidebar-footer .updated {
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== Main Content ===== */
.content {
    margin-left: 300px;
    flex: 1;
    min-height: 100vh;
}

.content-inner {
    max-width: 860px;
    margin: 0 auto;
    padding: 48px 48px 96px;
}

/* ===== Article ===== */
.article-header {
    margin-bottom: 40px;
    padding-bottom: 32px;
    border-bottom: 1px solid var(--border);
}

.article-header h1 {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
    margin-bottom: 16px;
    background: var(--gradient-title);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.article-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
    color: var(--text-muted);
}

.article-meta .tag {
    background: var(--tag-bg);
    color: var(--tag-text);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.article-meta .date {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ===== Article Body ===== */
.article-body h2 {
    font-size: 24px;
    font-weight: 600;
    margin: 48px 0 16px;
    letter-spacing: -0.02em;
    color: var(--text);
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.article-body h3 {
    font-size: 18px;
    font-weight: 600;
    margin: 32px 0 12px;
    color: var(--text);
}

.article-body p {
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.article-body ul, .article-body ol {
    margin-bottom: 16px;
    padding-left: 24px;
}

.article-body li {
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.article-body strong {
    color: var(--text);
    font-weight: 600;
}

.article-body code {
    background: var(--code-bg);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'SF Mono', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
    color: var(--accent-light);
}

.article-body pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px 24px;
    overflow-x: auto;
    margin-bottom: 24px;
}

.article-body pre code {
    background: none;
    padding: 0;
    font-size: 13px;
    line-height: 1.6;
    color: var(--code-text);
}

.article-body blockquote {
    border-left: 3px solid var(--accent);
    padding: 12px 20px;
    margin-bottom: 20px;
    background: var(--accent-dim);
    border-radius: 0 8px 8px 0;
    color: var(--text-secondary);
}

.article-body table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
    font-size: 14px;
}

.article-body th {
    background: var(--bg-hover);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text);
    border-bottom: 2px solid var(--border);
}

.article-body td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}

.article-body tr:hover td {
    background: var(--bg-hover);
}

/* ===== Info Boxes ===== */
.info-box {
    padding: 20px 24px;
    border-radius: 8px;
    margin-bottom: 24px;
    border-left: 3px solid;
}

.info-box.tip {
    background: rgba(74, 222, 128, 0.06);
    border-color: var(--success);
}

[data-theme="light"] .info-box.tip {
    background: rgba(74, 222, 128, 0.08);
}

.info-box.warning {
    background: rgba(251, 191, 36, 0.06);
    border-color: var(--warning);
}

[data-theme="light"] .info-box.warning {
    background: rgba(251, 191, 36, 0.08);
}

.info-box.info {
    background: var(--accent-dim);
    border-color: var(--accent);
}

.info-box .box-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

.info-box p {
    font-size: 14px;
    margin-bottom: 0;
}

/* ===== Home ===== */
.home-hero {
    text-align: center;
    padding: 80px 0 60px;
}

.home-hero h1 {
    font-size: 48px;
    font-weight: 700;
    letter-spacing: -0.04em;
    background: var(--gradient-hero);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 16px;
}

.home-hero .tagline {
    font-size: 18px;
    color: var(--text-muted);
    font-weight: 300;
}

.articles-grid {
    display: grid;
    gap: 16px;
    margin-top: 40px;
}

.article-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    transition: all 0.2s ease;
    cursor: pointer;
    text-decoration: none;
    display: block;
    box-shadow: var(--shadow);
}

.article-card:hover {
    border-color: var(--border-light);
    background: var(--bg-hover);
    transform: translateY(-2px);
}

.article-card h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.article-card p {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.5;
}

.article-card .card-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
}

.article-card .card-meta .tag {
    background: var(--tag-bg);
    color: var(--tag-text);
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 500;
}

/* ===== Stage Badges ===== */
.stage-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 24px;
}

.stage-badge.beginner { background: rgba(74, 222, 128, 0.12); color: #22c55e; }
.stage-badge.intermediate { background: rgba(251, 191, 36, 0.12); color: #d97706; }
.stage-badge.advanced { background: rgba(239, 68, 68, 0.12); color: #ef4444; }

/* ===== Mobile ===== */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 200;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    cursor: pointer;
    font-size: 18px;
    box-shadow: var(--shadow);
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.active {
    display: block;
}

/* Scrollable wrapper for tables & code (injected by JS) */
.article-body .scroll-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -16px 24px;
    padding: 0 16px;
}
.article-body .scroll-wrap table {
    min-width: 100%;
    margin: 0;
}
.article-body .scroll-wrap pre {
    margin: 0;
    border-radius: 8px;
}

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 280px;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .content {
        margin-left: 0;
    }
    .content-inner {
        padding: 20px 16px 60px;
    }
    .mobile-toggle {
        display: flex !important;
    }
    .home-hero {
        padding: 60px 0 40px;
    }
    .home-hero h1 {
        font-size: 28px;
    }
    .home-hero .tagline {
        font-size: 15px;
    }
    .article-header h1 {
        font-size: 26px;
    }
    .article-header {
        margin-bottom: 28px;
        padding-bottom: 24px;
    }
    .article-body h2 {
        font-size: 20px;
        margin: 32px 0 12px;
    }
    .article-body h3 {
        font-size: 16px;
        margin: 24px 0 10px;
    }
    .article-body pre {
        padding: 14px 16px;
        border-radius: 8px;
        margin: 0 0 24px;
        font-size: 12px;
        border-left: none;
        border-right: none;
    }
    .article-body pre code {
        font-size: 12px;
        white-space: pre;
        word-break: normal;
        overflow-x: visible;
    }
    .article-body code {
        font-size: 12px;
        word-break: break-word;
    }
    .article-body table {
        font-size: 13px;
        border-collapse: collapse;
    }
    .article-body th,
    .article-body td {
        padding: 8px 10px;
    }
    .article-body blockquote {
        margin-left: -16px;
        margin-right: -16px;
        padding: 12px 16px;
        border-radius: 0 8px 0 0;
    }
    .article-card {
        padding: 18px;
    }
    .article-card h3 {
        font-size: 16px;
    }
    .article-card p {
        font-size: 13px;
    }
    .theme-toggle {
        top: 14px;
        right: 14px;
        width: 38px;
        height: 38px;
        font-size: 16px;
    }
    .article-meta {
        flex-wrap: wrap;
        gap: 8px;
    }
    .info-box {
        padding: 14px 16px;
        margin-bottom: 20px;
    }
}

/* Tablet */
@media (min-width: 901px) and (max-width: 1200px) {
    .content-inner {
        padding: 36px 32px 80px;
    }
    .home-hero h1 {
        font-size: 40px;
    }
}
