/* Theme variables */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --border: #30363d;
    --code-bg: #1c2128;
    --tag-bg: #238636;
    --shadow: rgba(0, 0, 0, 0.3);
    --max-width: 1200px;
    --header-height: 70px;
    /* Typography */
    --font-xs: 0.75rem;    /* 12px */
    --font-sm: 0.875rem;   /* 14px */
    --font-base: 1rem;     /* 16px */
    --font-md: 1.125rem;   /* 18px */
    --font-lg: 1.25rem;    /* 20px */
    --font-xl: 1.5rem;     /* 24px */
    --font-2xl: 1.75rem;   /* 28px */
    --font-3xl: 2rem;      /* 32px */
    --font-4xl: 2.5rem;    /* 40px */
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fa;
    --bg-tertiary: #eaeef2;
    --text-primary: #1f2328;
    --text-secondary: #656d76;
    --text-muted: #8c959f;
    --accent: #0969da;
    --accent-hover: #0550ae;
    --border: #d0d7de;
    --code-bg: #f6f8fa;
    --tag-bg: #0969da;
    --shadow: rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-secondary);
    line-height: 1.7;
    font-size: var(--font-base);
    transition: background 0.3s, color 0.3s;
}

/* Navbar */
.navbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.navbar-content {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 32px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.navbar-brand {
    font-size: var(--font-xl);
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
    transition: color 0.2s;
}

.navbar-brand:hover { color: var(--accent); }

.navbar-menu {
    display: flex;
    align-items: center;
    gap: 24px;
}

.navbar-menu a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--font-sm);
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 8px;
    transition: all 0.2s;
}

.navbar-menu a:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.theme-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--accent);
    border-color: var(--accent);
}

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

/* Main Container */
.main-container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: calc(var(--header-height) + 48px) 32px 80px;
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 64px;
}

.content-area { min-width: 0; }

/* Page Header */
.page-header {
    margin-bottom: 48px;
    padding-bottom: 32px;
    border-bottom: 1px solid var(--border);
}

.page-title {
    font-size: var(--font-4xl);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    letter-spacing: -0.5px;
}

.page-subtitle {
    font-size: var(--font-md);
    color: var(--text-muted);
    font-weight: 400;
}

/* Posts Grid */
.posts-grid { display: grid; gap: 24px; }

.post-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 24px;
}

.post-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.post-item::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s;
}

.post-item:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 12px 24px var(--shadow);
}

.post-item:hover::before { transform: scaleX(1); }

.post-title {
    font-size: var(--font-lg);
    font-weight: 600;
    margin-bottom: 12px;
    line-height: 1.3;
}

.post-title a {
    color: var(--text-primary);
    text-decoration: none;
    transition: color 0.2s;
}

.post-title a:hover { color: var(--accent); }

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

.post-date {
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.post-date::before { content: '📅'; font-size: var(--font-sm); }

.article-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.article-tag {
    background: var(--tag-bg);
    color: #fff;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: var(--font-xs);
    font-weight: 500;
    transition: all 0.2s;
}

.article-tag:hover {
    transform: translateY(-2px);
    background: var(--accent);
    box-shadow: 0 4px 8px var(--shadow);
}

/* Sidebar */
.sidebar {
    position: sticky;
    top: calc(var(--header-height) + 24px);
    height: fit-content;
}

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

.article-title {
    font-size: var(--font-4xl);
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-primary);
    margin-bottom: 16px;
    letter-spacing: -0.5px;
}

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

.article-content {
    font-size: var(--font-md);
    line-height: 1.8;
    color: var(--text-secondary);
}

.article-content h1,
.article-content h2,
.article-content h3 {
    color: var(--text-primary);
    font-weight: 700;
    margin-top: 48px;
    margin-bottom: 20px;
}

.article-content h1 { font-size: var(--font-3xl); border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.article-content h2 { font-size: var(--font-2xl); }
.article-content h3 { font-size: var(--font-xl); }

.article-content p { margin-bottom: 24px; }

.article-content a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s;
    font-weight: 500;
}

.article-content a:hover { border-bottom-color: var(--accent); }

.article-content code {
    background: var(--code-bg);
    padding: 3px 8px;
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: var(--font-sm);
    color: var(--text-primary);
}

.article-content pre {
    background: var(--code-bg);
    border-radius: 12px;
    overflow: hidden;
    margin: 32px 0;
    border: 1px solid var(--border);
}

.article-content pre code {
    background: none;
    padding: 20px 24px;
    display: block;
    overflow-x: auto;
    line-height: 1.6;
}

.article-content pre.math-block {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    padding: 16px 24px;
    font-family: 'JetBrains Mono', monospace;
    font-size: var(--font-sm);
    color: var(--text-primary);
    overflow-x: auto;
}

/* KaTeX math display */
.katex-display {
    margin: 32px 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.katex-display .katex {
    font-size: 1.1em;
}

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

.article-content li { margin-bottom: 12px; }

.article-content blockquote {
    border-left: 4px solid var(--accent);
    padding: 20px 20px 20px 24px;
    margin: 32px 0;
    background: var(--bg-secondary);
    border-radius: 0 8px 8px 0;
    font-style: italic;
}

/* Table Styles */
.article-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 32px 0;
    font-size: var(--font-base);
    overflow-x: auto;
    display: block;
}

.article-content table thead { background: var(--bg-tertiary); }

.article-content table th,
.article-content table td {
    border: 1px solid var(--border);
    padding: 12px 16px;
    text-align: left;
}

.article-content table th {
    font-weight: 600;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.article-content table td { color: var(--text-secondary); }
.article-content table tr { border-bottom: 1px solid var(--border); }
.article-content table tr:hover { background: var(--bg-secondary); }
.article-content table tr:last-child { border-bottom: none; }

/* Footer */
.footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 48px 32px;
    text-align: center;
    color: var(--text-muted);
    font-size: var(--font-sm);
}

/* Back to Top */
.back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--text-primary);
    border: none;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    box-shadow: 0 4px 12px var(--shadow);
}

.back-to-top:hover {
    background: var(--accent-hover);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px var(--shadow);
}

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

.back-to-top svg { width: 22px; height: 22px; }

/* Responsive */
@media (max-width: 900px) {
    .main-container {
        grid-template-columns: 1fr;
        gap: 32px;
        padding: calc(var(--header-height) + 32px) 24px 64px;
    }
    .sidebar { position: static; }
    .article-title, .page-title { font-size: var(--font-3xl); }
    .navbar-content { padding: 0 24px; }
}

@media (max-width: 600px) {
    .article-title, .page-title { font-size: var(--font-2xl); }
    .post-title { font-size: var(--font-lg); }
    .navbar-menu { gap: 12px; }
}
