/* ===== CSS Variables ===== */
:root {
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;

    /* Font sizes */
    --text-sm: 0.8rem;
    --text-base: 1rem;
    --text-lg: 1.1rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 2rem;

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-12: 3rem;
    --space-16: 4rem;
    --space-20: 5rem;

    /* Layout */
    --content-width: 720px;
    --content-padding: 20px;

    /* Light mode colors (default) */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --border: #e5e5e5;
    --shadow: rgba(0, 0, 0, 0.08);
    --placeholder-bg: #f0f0f0;
    --placeholder-border: #ddd;
}

/* Dark mode */
[data-theme="dark"] {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2a2a2a;
    --text-primary: #f5f5f5;
    --text-secondary: #a0a0a0;
    --text-tertiary: #666666;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --border: #2a2a2a;
    --shadow: rgba(0, 0, 0, 0.3);
    --placeholder-bg: #1a1a1a;
    --placeholder-border: #333;
}

/* ===== Base Styles ===== */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0;
    padding-top: 60px; /* Offset for fixed header */
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.7;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== Site Header ===== */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-6);
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.header-logo {
    height: 44px;
    width: auto;
    transition: filter 0.3s ease;
}

[data-theme="dark"] .header-logo {
    filter: invert(1);
}

.header-title {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.header-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: none;
    padding: var(--space-2) var(--space-3);
    border-radius: 6px;
    background-color: var(--bg-secondary);
    transition: color 0.2s ease, background-color 0.2s ease;
}

.header-btn svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

.header-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
    text-decoration: none;
}

/* ===== Sidebar Navigation ===== */
.sidebar {
    position: fixed;
    left: 0;
    top: 60px;
    width: 240px;
    height: calc(100vh - 60px);
    padding: var(--space-6) var(--space-4);
    background-color: var(--bg-primary);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: visible;
    z-index: 100;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.sidebar ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar li {
    margin-bottom: var(--space-2);
}

.sidebar ul a {
    display: block;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    color: var(--text-primary);
    text-decoration: none;
    border-left: 2px solid transparent;
    border-radius: 0 4px 4px 0;
    transition: all 0.2s ease;
}

.sidebar ul a:hover {
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    text-decoration: none;
}

.sidebar ul a.active {
    color: var(--accent);
    border-left-color: var(--accent);
    background-color: var(--bg-secondary);
}

.sidebar > .header-btn {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    justify-content: center;
    gap: var(--space-2);
}

/* ===== Layout ===== */
main {
    max-width: var(--content-width);
    margin: 0 auto;
    margin-left: calc(240px + (100% - 240px - var(--content-width)) / 2);
    padding: var(--space-8) var(--content-padding);
}

article {
    padding-bottom: var(--space-16);
}

/* ===== Typography ===== */
h1, h2, h3, h4 {
    font-weight: 600;
    line-height: 1.3;
    margin-top: var(--space-12);
    margin-bottom: var(--space-4);
    color: var(--text-primary);
}

h1 {
    font-size: var(--text-2xl);
    font-weight: 600;
    margin-top: var(--space-6);
    letter-spacing: -0.01em;
}

h2 {
    font-size: var(--text-xl);
    margin-top: var(--space-16);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--border);
}

h3 {
    font-size: var(--text-xl);
    margin-top: var(--space-8);
}

p {
    margin: 0 0 var(--space-6);
    color: var(--text-primary);
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

strong {
    font-weight: 600;
}

em {
    font-style: italic;
}

code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    padding: 0.15em 0.4em;
    background-color: var(--bg-secondary);
    border-radius: 4px;
}

/* ===== Header ===== */
.article-header {
    text-align: left;
    margin-bottom: var(--space-8);
}

.logo-container {
    margin-bottom: var(--space-6);
}

.logo {
    max-width: 180px;
    height: auto;
    transition: filter 0.3s ease;
}

/* Invert logo for dark mode */
[data-theme="dark"] .logo {
    filter: invert(1);
}

.subtitle {
    font-size: var(--text-xl);
    font-weight: 400;
    color: var(--text-secondary);
    margin-top: var(--space-2);
    margin-bottom: var(--space-4);
    padding-bottom: 0;
    border-bottom: none;
}

.meta {
    font-size: var(--text-base);
    color: var(--text-secondary);
    margin-bottom: var(--space-3);
}

.meta-block {
    font-size: var(--text-base);
    color: var(--text-secondary);
    text-align: left;
    margin-top: var(--space-6);
    margin-bottom: var(--space-8);
}

/* ===== CTA Buttons ===== */
.cta-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-3);
    margin: var(--space-8) 0;
}

.cta-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--bg-primary);
    background-color: var(--text-primary);
    border-radius: 50px;
    text-decoration: none;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px var(--shadow);
}

.cta-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
    text-decoration: none;
    color: var(--bg-primary);
}

.cta-btn svg {
    width: 18px;
    height: 18px;
}

/* ===== TL;DR Section ===== */
.tldr {
    background-color: var(--bg-secondary);
    border-radius: 12px;
    padding: var(--space-6) var(--space-8);
    margin: var(--space-8) 0;
    border-left: 4px solid var(--accent);
}

.tldr h2 {
    margin-top: 0;
    font-size: var(--text-xl);
    border-bottom: none;
    padding-bottom: 0;
}

.tldr ul {
    margin: 0;
    padding-left: var(--space-6);
}

.tldr li {
    margin-bottom: var(--space-4);
}

.tldr li:last-child {
    margin-bottom: 0;
}

/* ===== Content Sections ===== */
.content-section {
    margin-top: var(--space-16);
}

.content-section h2:first-child {
    margin-top: 0;
}

/* ===== Figures ===== */
figure {
    margin: var(--space-8) 0;
}

figure img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: 8px;
}

figcaption {
    max-width: 75%;
    margin: var(--space-4) auto 0;
    text-align: center;
}

.figure-half {
    max-width: 50%;
    margin: var(--space-8) 0;
}

.figure-half img {
    max-width: 100%;
}

.figure-pair {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    justify-content: center;
    align-items: center;
}

.figure-pair img {
    flex: 0 1 auto;
    max-width: calc(50% - var(--space-2));
    height: auto;
    object-fit: contain;
}

@media (max-width: 600px) {
    .figure-pair img {
        max-width: 100%;
    }
}

.figure-placeholder {
    text-align: center;
}

.placeholder-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    background-color: var(--placeholder-bg);
    border: 2px dashed var(--placeholder-border);
    border-radius: 12px;
    padding: var(--space-8);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.placeholder-box span {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.placeholder-box small {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
}

.table-placeholder {
    min-height: 150px;
}

figcaption {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-top: var(--space-3);
    text-align: center;
}

/* ===== Design Principles ===== */
.principle {
    background-color: var(--bg-secondary);
    border-radius: 8px;
    padding: var(--space-4) var(--space-6);
    margin: var(--space-4) 0;
}

.principle h3 {
    margin-top: 0;
    margin-bottom: var(--space-2);
    font-size: var(--text-lg);
}

.principle p {
    margin-bottom: 0;
    color: var(--text-secondary);
}

/* ===== Footer ===== */
.article-footer {
    margin-top: var(--space-16);
    padding-top: var(--space-8);
    border-top: 1px solid var(--border);
    text-align: center;
}

.footer-links {
    margin-bottom: var(--space-8);
}

.footer-links p {
    margin-bottom: var(--space-2);
    color: var(--text-secondary);
}

.authors {
    color: var(--text-secondary);
}

.authors p {
    margin-bottom: var(--space-2);
}

/* ===== Dark Mode Toggle ===== */
#theme-toggle {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background-color: var(--bg-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
    font-size: 18px;
}

#theme-toggle:hover {
    background-color: var(--bg-tertiary);
}

/* Show/hide icons based on theme */
[data-theme="light"] .moon-icon,
[data-theme="dark"] .sun-icon {
    display: none;
}

[data-theme="light"] .sun-icon,
[data-theme="dark"] .moon-icon {
    display: inline;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    html {
        font-size: 15px;
    }

    body {
        padding-top: 56px;
    }

    .site-header {
        height: 56px;
        padding: 0 var(--space-4);
    }

    .header-title {
        display: none;
    }

    .header-btn {
        padding: var(--space-2);
        font-size: 0;
        gap: 0;
    }

    .header-btn svg {
        width: 20px;
        height: 20px;
    }

    .header-right {
        gap: var(--space-2);
    }

    /* Hide sidebar on mobile */
    .sidebar {
        display: none;
    }

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    main {
        margin-left: auto;
        padding: var(--space-4) var(--content-padding);
    }

    .tldr {
        padding: var(--space-4) var(--space-6);
    }

    .tldr ul {
        padding-left: var(--space-4);
    }

    .placeholder-box {
        min-height: 150px;
        padding: var(--space-6);
    }

    .principle {
        padding: var(--space-3) var(--space-4);
    }
}

@media (max-width: 480px) {
    html {
        font-size: 14px;
    }

    h1 {
        font-size: 1.75rem;
    }

    .article-header {
        padding: 0 var(--space-2);
    }

    .meta {
        font-size: var(--text-sm);
    }
}

/* ===== Print Styles ===== */
@media print {
    #theme-toggle {
        display: none;
    }

    body {
        background: white;
        color: black;
    }

    .cta-buttons {
        display: none;
    }

    .placeholder-box {
        border: 1px solid #ccc;
    }
}
