:root {
    /* Swiss Theme (Light Mode) - Monochrome Update */
    --primary-color: #171717;
    /* Neutral Black */
    --secondary-color: #525252;
    /* Dark Gray */
    --success-color: #059669;
    --warning-color: #d97706;
    --danger-color: #dc2626;

    --bg-color: #ffffff;
    --text-color: #262626;
    /* Neutral Dark text */
    --border-color: #e5e5e5;

    /* Sidebar Specifics - Swiss */
    --code-bg: #fafafa;
    --sidebar-width: 280px;
    --sidebar-text: #525252;
    --sidebar-title: #171717;
    --sidebar-border: 1px solid #e5e5e5;

    --nav-item-hover: #f5f5f5;
    --nav-item-active-bg: #171717;
    --nav-item-active-text: #ffffff;

    --header-gradient-start: #171717;
    --header-gradient-end: #525252;
}

[data-theme="dark"] {
    /* Obsidian Theme (Dark Mode) */
    --bg-color: #0f172a;
    /* Slate 900 */
    --text-color: #cbd5e1;
    /* Slate 300 */
    --border-color: #1e293b;

    /* Override Primary Colors for Visibility */
    --primary-color: #f8fafc;
    /* Slate 50 (White-ish) */
    --secondary-color: #94a3b8;
    /* Slate 400 */

    /* Sidebar Specifics - Obsidian */
    --code-bg: #020617;
    /* Slate 950 sidebar bg */
    --sidebar-text: #94a3b8;
    /* Slate 400 */
    --sidebar-title: #64748b;
    /* Slate 500 */
    --sidebar-border: 1px solid rgba(255, 255, 255, 0.05);

    --nav-item-hover: rgba(255, 255, 255, 0.08);
    --nav-item-active-bg: rgba(255, 255, 255, 0.12);
    --nav-item-active-text: #f8fafc;
    /* Slate 50 */

    --header-gradient-start: #f8fafc;
    --header-gradient-end: #94a3b8;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--code-bg);
    color: var(--sidebar-text);
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    padding: 20px 0;
    z-index: 100;
    border-right: var(--sidebar-border);
}

.sidebar-header {
    padding: 0 20px 20px;
    border-bottom: 1px solid transparent;
    /* Removed visible border for cleaner look */
}

.sidebar-header h1 {
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--header-gradient-start), var(--header-gradient-end));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 800;
    /* Bold for Swiss */
    letter-spacing: -0.5px;
}

.sidebar-nav {
    padding: 20px 0;
}

.nav-section {
    margin-bottom: 20px;
}

.nav-section-title {
    padding: 0 20px 10px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--sidebar-title);
    font-weight: 700;
    opacity: 0.9;
}

.nav-item {
    display: block;
    padding: 8px 16px;
    /* Slightly more compact/modern padding */
    margin: 2px 12px;
    /* Floating effect */
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s ease;
    border-radius: 6px;
    /* Rounded corners for chips */
    border-left: none;
    /* Removed the left border style */
    font-weight: 500;
}

.nav-item:hover {
    background: var(--nav-item-hover);
    color: var(--text-color);
}

[data-theme="dark"] .nav-item:hover {
    color: #e2e8f0;
}

.nav-item.active {
    background: var(--nav-item-active-bg);
    color: var(--nav-item-active-text);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Main Content Area */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 40px;
    max-width: 1200px;
}

/* Content Styles */
.content {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: rgba(0, 0, 0, 0.5);
    font-size: 1.1rem;
    margin-bottom: 40px;
}

[data-theme="dark"] .subtitle {
    color: rgba(255, 255, 255, 0.5);
}

h2 {
    font-size: 2rem;
    margin-top: 60px;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

h3 {
    font-size: 1.5rem;
    margin-top: 40px;
    margin-bottom: 15px;
    color: var(--primary-color);
}

h4 {
    font-size: 1.2rem;
    margin-top: 30px;
    margin-bottom: 10px;
}

p {
    margin-bottom: 15px;
}

/* Code Blocks */
.code-block {
    background: var(--code-bg);
    /* Uses same logic as sidebar in dark mode, but maybe need override? */
    border-radius: 10px;
    overflow: hidden;
    margin: 20px 0;
    border: 1px solid var(--border-color);
}

/* Ensure code block bg is dark in light mode if we want, or match theme? 
   Usually code blocks are dark. Let's force dark for code blocks in light mode.
*/
:root .code-block {
    background: #1e293b;
    border: none;
}

[data-theme="dark"] .code-block {
    background: #020617;
    /* Obsidian bg */
    border: 1px solid rgba(255, 255, 255, 0.1);
}


.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.code-language {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.6);
}

.copy-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    padding: 5px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.3s;
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.copy-btn.copied {
    background: var(--success-color);
}

pre {
    padding: 20px;
    overflow-x: auto;
    margin: 0;
    color: #f1f5f9;
    /* Force light text in code blocks */
}

code {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Inline Code */
p code,
li code {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary-color);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* Lists */
ul,
ol {
    margin-bottom: 15px;
    padding-left: 25px;
}

li {
    margin-bottom: 8px;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    background: var(--bg-color);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

th,
td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background: rgba(59, 130, 246, 0.1);
    font-weight: 600;
}

tr:hover {
    background: rgba(59, 130, 246, 0.05);
}

/* Alerts / Callouts */
.tip,
.warning,
.note,
.practice {
    padding: 15px 20px;
    margin: 20px 0;
    border-radius: 10px;
    border-left: 4px solid;
}

.tip {
    background: rgba(16, 185, 129, 0.1);
    border-left-color: var(--success-color);
}

.warning {
    background: rgba(245, 158, 11, 0.1);
    border-left-color: var(--warning-color);
}

.note {
    background: rgba(59, 130, 246, 0.1);
    border-left-color: var(--primary-color);
}

.practice {
    background: rgba(139, 92, 246, 0.1);
    border-left-color: var(--secondary-color);
}

.tip::before,
.warning::before,
.note::before,
.practice::before {
    content: attr(data-label);
    font-weight: 600;
    display: block;
    margin-bottom: 8px;
}

.tip::before {
    content: "💡 提示";
}

.warning::before {
    content: "⚠️ 警告";
}

.note::before {
    content: "📝 注意";
}

.practice::before {
    content: "✏️ 练习";
}

/* Exercise Section */
.exercise-section {
    background: rgba(139, 92, 246, 0.05);
    border-radius: 10px;
    padding: 30px;
    margin-top: 40px;
}

.exercise-section h3 {
    margin-top: 0;
}

.question {
    margin-bottom: 20px;
}

.question-title {
    font-weight: 600;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.question-type {
    background: var(--secondary-color);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
}

.options {
    display: grid;
    gap: 10px;
    margin-top: 10px;
}

.option {
    background: var(--bg-color);
    padding: 12px 15px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s;
}

.option:hover {
    border-color: var(--primary-color);
}

.option.correct {
    border-color: var(--success-color);
    background: rgba(16, 185, 129, 0.1);
}

.option.incorrect {
    border-color: var(--danger-color);
    background: rgba(239, 68, 68, 0.1);
}

/* Mermaid */
.mermaid {
    background: var(--bg-color);
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
    text-align: center;
}

/* Comparison Table */
.comparison-table {
    margin: 30px 0;
}

.comparison-table th {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.comparison-table td:first-child {
    font-weight: 600;
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin: 20px 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transition: width 0.3s;
}

/* Chapter Nav */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 60px;
    padding-top: 30px;
    border-top: 1px solid var(--border-color);
}

.chapter-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 25px;
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary-color);
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.3s;
}

.chapter-nav a:hover {
    background: rgba(59, 130, 246, 0.2);
    transform: translateX(-5px);
}

.chapter-nav a.next:hover {
    transform: translateX(5px);
}

/* Theme Toggle */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--code-bg);
    border: none;
    color: white;
    /* Always white icon for visibility */
    padding: 10px 15px;
    border-radius: 10px;
    cursor: pointer;
    z-index: 1000;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Mobile & Print */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
        z-index: 1000;
        border-right: none;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: 20px;
    }

    h1 {
        font-size: 1.8rem;
    }

    h2 {
        font-size: 1.5rem;
    }
}

.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1001;
    background: var(--code-bg);
    border: none;
    color: white;
    padding: 10px 15px;
    border-radius: 10px;
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: block;
    }
}

@media print {

    .sidebar,
    .theme-toggle,
    .mobile-menu-btn,
    .copy-btn,
    .back-to-top {
        display: none;
    }

    .main-content {
        margin-left: 0;
    }

    .code-block {
        page-break-inside: avoid;
    }

    h2 {
        page-break-after: avoid;
    }
}

/* Back to Top Button */
.back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 45px;
    height: 45px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}