:root {
    --primary-color: #003366;
    --secondary-color: #006699;
    --accent-color: #0066cc;
    --bg-color: #ffffff;
    --sidebar-bg: #f8f9fa;
    --text-color: #333;
    --border-color: #e0e0e0;
    --hover-color: #f0f4f8;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --code-bg: #f5f5f5;
}

[data-theme="dark"] {
    --primary-color: #4a9eff;
    --secondary-color: #66b3ff;
    --accent-color: #3d8bfd;
    --bg-color: #1a1a1a;
    --sidebar-bg: #2d2d2d;
    --text-color: #e0e0e0;
    --border-color: #404040;
    --hover-color: #3a3a3a;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --code-bg: #2a2a2a;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background: var(--bg-color);
    overflow-x: hidden;
}

#app {
    display: flex;
    height: 100vh;
}

/* Sidebar Styles */
.sidebar {
    width: 320px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    padding: 1.5rem;
    background: var(--primary-color);
    color: white;
    position: sticky;
    top: 0;
    z-index: 10;
}

.sidebar-header h1 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
}

.search-box {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.toolbar {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.search-box {
    flex: 1;
    padding: 0;
    border: none;
}

.search-box input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.95rem;
    background: var(--bg-color);
    color: var(--text-color);
}

.theme-toggle {
    padding: 0.75rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    background: var(--hover-color);
    transform: scale(1.1);
}

.chapter-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.chapter-group {
    margin-bottom: 1.5rem;
}

.part-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
    padding: 0.5rem 0;
}

.chapter-item {
    padding: 0.75rem 1rem;
    margin: 0.25rem 0;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.chapter-item:hover {
    background: var(--hover-color);
    transform: translateX(4px);
}

.chapter-item.active {
    background: var(--accent-color);
    color: white;
    font-weight: 600;
}

/* Main Content Styles */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content-wrapper {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
}

#chapter-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 3rem 2rem;
}

/* Welcome Screen */
.welcome {
    text-align: center;
    padding: 3rem 2rem;
}

.welcome h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.subtitle {
    font-size: 1.3rem;
    color: var(--secondary-color);
    margin-bottom: 2rem;
}

.welcome-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin: 2rem 0;
    flex-wrap: wrap;
}

.welcome-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 1.75rem;
    text-decoration: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.welcome-btn.primary {
    background: var(--primary-color);
    color: white;
}

.welcome-btn.primary:hover {
    background: var(--accent-color);
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 102, 204, 0.3);
}

.welcome-btn.secondary {
    background: white;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.welcome-btn.secondary:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 51, 102, 0.2);
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-top: 3rem;
    text-align: left;
}

.feature {
    padding: 1.5rem;
    background: var(--sidebar-bg);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.feature h3 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

/* Chapter Content Styles */
#chapter-content h1 {
    font-size: 2.2rem;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    border-bottom: 3px solid var(--accent-color);
    padding-bottom: 0.5rem;
}

#chapter-content h2 {
    font-size: 1.8rem;
    color: var(--secondary-color);
    margin-top: 2rem;
    margin-bottom: 1rem;
}

#chapter-content h3 {
    font-size: 1.4rem;
    color: var(--secondary-color);
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}

#chapter-content p {
    margin-bottom: 1rem;
    line-height: 1.8;
}

#chapter-content ul, #chapter-content ol {
    margin-left: 2rem;
    margin-bottom: 1rem;
}

#chapter-content li {
    margin-bottom: 0.5rem;
}

#chapter-content code {
    background: var(--code-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: var(--text-color);
}

#chapter-content pre {
    background: var(--code-bg);
    padding: 1rem;
    border-radius: 4px;
    overflow-x: auto;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}

/* Math rendering styles */
.equation {
    margin: 1rem 0;
    overflow-x: auto;
    text-align: center;
}

.definition, .theorem, .example, .keypoint {
    padding: 1rem;
    margin: 1rem 0;
    border-radius: 4px;
    border-left: 4px solid var(--accent-color);
}

.definition {
    background: rgba(76, 175, 80, 0.1);
    border-left-color: #4caf50;
}

.theorem {
    background: rgba(33, 150, 243, 0.1);
    border-left-color: #2196f3;
}

.example {
    background: rgba(255, 152, 0, 0.1);
    border-left-color: #ff9800;
}

.keypoint {
    background: rgba(156, 39, 176, 0.1);
    border-left-color: #9c27b0;
}

/* MathJax output styling */
mjx-container {
    overflow-x: auto;
    overflow-y: hidden;
}

mjx-container[display="true"] {
    margin: 1rem 0;
}

/* Navigation Controls */
.nav-controls {
    display: flex;
    justify-content: space-between;
    padding: 1rem 2rem;
    border-top: 1px solid var(--border-color);
    background: var(--sidebar-bg);
}

.nav-btn {
    padding: 0.75rem 1.5rem;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.nav-btn:hover:not(:disabled) {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.nav-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.5;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 2rem;
    color: #666;
}

.loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-color), var(--secondary-color));
    transition: width 0.3s ease;
    z-index: 9999;
}

.loading-bar.active {
    width: 100%;
}

/* Mobile menu button (always visible on mobile) */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    width: 50px;
    height: 50px;
    border-radius: 8px;
    background: var(--primary-color);
    color: white;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 999;
    transition: all 0.3s ease;
}

.mobile-menu-btn:hover {
    background: var(--accent-color);
    transform: scale(1.05);
}

.mobile-menu-btn:active {
    transform: scale(0.95);
}

.sidebar-footer {
    padding: 1rem;
    text-align: center;
    border-top: 1px solid var(--border-color);
    color: #666;
    font-size: 0.85rem;
}

.footer-links {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.footer-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.footer-link:hover {
    background: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.footer-link:active {
    transform: translateY(0);
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Show mobile menu button */
    .mobile-menu-btn {
        display: block;
    }
    
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1000;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        transform: translateX(0);
    }
    
    /* Overlay when sidebar is open */
    .sidebar.open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 280px;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }

    /* Hide the sidebar toggle button (inside sidebar) on mobile */
    .sidebar-toggle {
        display: none;
    }
    
    .main-content {
        margin-left: 0;
        width: 100%;
    }

    #chapter-content {
        padding: 2rem 1rem;
    }

    .features {
        grid-template-columns: 1fr;
    }

    .chapter-toc {
        right: 1rem;
        left: 1rem;
        width: auto;
        bottom: 7rem;
    }

    .toc-toggle {
        right: 1rem;
        bottom: 4.5rem;
    }
    
    .welcome h1 {
        font-size: 1.8rem;
    }
    
    .subtitle {
        font-size: 1.1rem;
    }
    
    .welcome-actions {
        flex-direction: column;
        align-items: stretch;
    }
    
    .welcome-btn {
        width: 100%;
        justify-content: center;
    }
}

/* Smooth scrolling for chapter navigation */
html {
    scroll-behavior: smooth;
}

/* Table of Contents Toggle */
.toc-toggle {
    position: fixed;
    bottom: 5rem;
    right: 2rem;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--accent-color);
    color: white;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    z-index: 50;
}

.toc-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Chapter TOC Overlay */
.chapter-toc {
    position: fixed;
    right: 2rem;
    bottom: 8rem;
    width: 300px;
    max-height: 60vh;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    overflow: hidden;
    transition: all 0.3s ease;
    z-index: 60;
}

.chapter-toc.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
}

.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--primary-color);
    color: white;
}

.toc-header h3 {
    margin: 0;
    font-size: 1rem;
}

.toc-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.toc-close:hover {
    background: rgba(255,255,255,0.2);
}

.toc-content {
    padding: 1rem;
    overflow-y: auto;
    max-height: calc(60vh - 60px);
}

.toc-content a {
    display: block;
    padding: 0.5rem 0;
    color: var(--text-color);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    padding-left: 0.5rem;
}

.toc-content a:hover {
    color: var(--accent-color);
    border-left-color: var(--accent-color);
    padding-left: 1rem;
}

.toc-content .toc-h2 {
    font-weight: 600;
    font-size: 0.95rem;
}

.toc-content .toc-h3 {
    font-size: 0.85rem;
    padding-left: 1rem;
    color: var(--secondary-color);
}

/* Smooth scrolling for chapter navigation */
html {
    scroll-behavior: smooth;
}

/* Print styles */
@media print {
    .sidebar, .nav-controls {
        display: none;
    }
    
    .main-content {
        width: 100%;
    }
}
