/* --- Global Styles & Variables --- */
:root {
    --bg-color: #ffffff;
    --text-color: #333333;
    --primary-color: #007bff;
    --border-color: #e0e0e0;
    --sidebar-bg: #f8f9fa;
    --code-bg: #f1f1f1;
    --header-bg: #ffffff;
    --shadow-color: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --primary-color: #3b82f6;
    --border-color: #444444;
    --sidebar-bg: #2c2f3a;
    --code-bg: #252525;
    --header-bg: #2c2f3a;
    --shadow-color: rgba(0, 0, 0, 0.4);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    display: grid;
    grid-template-columns: 260px 1fr 240px;
    gap: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
}

/* --- Sidebar Navigation --- */
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.sidebar-header h2 {
    font-size: 1.2rem;
}

#theme-switcher {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 5px;
    font-size: 1rem;
}

.sidebar nav ul {
    list-style: none;
}

.sidebar nav ul li a {
    display: block;
    color: var(--text-color);
    text-decoration: none;
    padding: 0.75rem 1rem;
    border-radius: 5px;
    margin-bottom: 0.5rem;
    transition: background-color 0.2s, color 0.2s;
}

.sidebar nav ul li a:hover,
.sidebar nav ul li a.active {
    background-color: var(--primary-color);
    color: #fff;
}

/* --- Main Content --- */
.main-content {
    padding-top: 1.5rem;
}

.main-content section {
    margin-bottom: 4rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 2rem;
}

.main-content section:last-of-type {
    border-bottom: none;
}

.main-content h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.5rem;
    display: inline-block;
}

.main-content h2 {
    font-size: 1.8rem;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
}

.main-content p, .main-content ul, .main-content ol {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.main-content ul, .main-content ol {
    padding-left: 1.5rem;
}

.main-content a {
    color: var(--primary-color);
    text-decoration: none;
}

.main-content a:hover {
    text-decoration: underline;
}

.content-image {
    max-width: 100%;
    border-radius: 8px;
    margin: 1.5rem 0;
    box-shadow: 0 4px 15px var(--shadow-color);
}

.edit-link {
    float: right;
    font-size: 0.9rem;
    color: #888;
}

/* --- Code Blocks --- */
pre {
    background-color: var(--code-bg);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    position: relative;
    border: 1px solid var(--border-color);
}

code {
    font-family: "Fira Code", "Courier New", monospace;
    font-size: 0.95rem;
}

pre[class*="language-"] {
    padding-right: 40px; /* Space for copy button */
}

.copy-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--primary-color);
    color: #fff;
    border: none;
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
}

pre:hover .copy-btn {
    opacity: 1;
}

/* --- Table of Contents --- */
.toc-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 1.5rem;
    overflow-y: auto;
}

.toc-sidebar h3 {
    margin-bottom: 1rem;
}

#toc-list {
    list-style: none;
}

#toc-list li a {
    color: var(--text-color);
    text-decoration: none;
    display: block;
    padding: 0.5rem 0;
    font-size: 0.9rem;
    border-left: 2px solid transparent;
    padding-left: 10px;
}

#toc-list li a.active {
    border-left: 2px solid var(--primary-color);
    color: var(--primary-color);
    font-weight: bold;
}

/* --- Responsive Design --- */
@media (max-width: 1200px) {
    .container {
        grid-template-columns: 240px 1fr;
    }
    .toc-sidebar {
        display: none;
    }
}

@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
    }
    .sidebar {
        position: static;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
}