/* Root Variables */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-sidebar: #1a1a2e;
    --text-primary: #2c3e50;
    --text-secondary: #555555;
    --text-light: #ffffff;
    --accent-primary: #3498db;
    --accent-secondary: #2c3e50;
    --border-color: #e1e4e8;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-heavy: 0 4px 16px rgba(0, 0, 0, 0.15);
    --sidebar-width: 320px;
    --transition: 0.3s ease;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-sidebar: #0f1419;
    --text-primary: #e8e8e8;
    --text-secondary: #b8b8b8;
    --accent-primary: #64b5f6;
    --accent-secondary: #90caf9;
    --border-color: #2d3748;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-heavy: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Georgia', 'Times New Roman', serif;
    line-height: 1.8;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    transition: background-color var(--transition), color var(--transition);
}

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

/* Sidebar Styles */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    color: var(--text-light);
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    box-shadow: var(--shadow-heavy);
    z-index: 1000;
    transition: transform var(--transition);
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-width) + 40px));
}

.sidebar-header {
    padding: 2rem 1.5rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    background-color: var(--bg-sidebar);
    z-index: 10;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.theme-toggle {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-light);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background var(--transition);
    margin-top: 0.5rem;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.toc {
    padding: 0 1.5rem;
}

.toc-item {
    display: block;
    padding: 0.5rem 0.75rem;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    border-radius: 4px;
    margin-bottom: 0.25rem;
    transition: all var(--transition);
    font-size: 0.95rem;
}

.toc-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-light);
    padding-left: 1rem;
}

.toc-item.active {
    background: var(--accent-primary);
    color: var(--text-light);
    font-weight: 600;
}

.toc-item.level-2 {
    padding-left: 1.5rem;
    font-size: 0.9rem;
}

.toc-item.level-3 {
    padding-left: 2.5rem;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.6);
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.toggle-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-light);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
    transition: background var(--transition);
}

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

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left var(--transition);
    position: relative;
}

.sidebar.collapsed ~ .main-content {
    margin-left: 40px;
}

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

/* Loading State */
.loading {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* Book Content Styles */
.book-content {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.book-content h1 {
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    color: var(--accent-secondary);
    line-height: 1.3;
    font-weight: 700;
}

.book-content h2 {
    font-size: 2rem;
    margin: 3rem 0 1.5rem;
    color: var(--accent-secondary);
    padding-top: 1rem;
    border-top: 2px solid var(--border-color);
    font-weight: 600;
}

.book-content h3 {
    font-size: 1.5rem;
    margin: 2rem 0 1rem;
    color: var(--text-primary);
    font-weight: 600;
}

.book-content h4 {
    font-size: 1.25rem;
    margin: 1.5rem 0 0.75rem;
    color: var(--text-primary);
    font-weight: 600;
}

.book-content p {
    margin-bottom: 1.5rem;
    text-align: justify;
    hyphens: auto;
}

.book-content em {
    font-style: italic;
    color: var(--text-primary);
}

.book-content strong {
    font-weight: 700;
    color: var(--text-primary);
}

.book-content ul,
.book-content ol {
    margin: 1.5rem 0;
    padding-left: 2rem;
}

.book-content li {
    margin-bottom: 0.75rem;
}

.book-content blockquote {
    border-left: 4px solid var(--accent-primary);
    padding: 1rem 1.5rem;
    margin: 2rem 0;
    background: var(--bg-secondary);
    font-style: italic;
    color: var(--text-secondary);
}

.book-content pre {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 2rem 0;
    border: 1px solid var(--border-color);
}

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

.book-content pre code {
    background: none;
    padding: 0;
}

.book-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
    font-size: 0.95rem;
}

.book-content th,
.book-content td {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    text-align: left;
}

.book-content th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.book-content hr {
    border: none;
    border-top: 2px solid var(--border-color);
    margin: 3rem 0;
}

.book-content a {
    color: var(--accent-primary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color var(--transition);
}

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

/* Scroll to Top Button */
.scroll-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--accent-primary);
    color: var(--text-light);
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: var(--shadow-heavy);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
    z-index: 999;
}

.scroll-top.visible {
    opacity: 1;
    visibility: visible;
}

.scroll-top:hover {
    background: var(--accent-secondary);
    transform: translateY(-3px);
}

/* Responsive Design */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }

    .sidebar {
        transform: translateX(calc(-1 * var(--sidebar-width)));
    }

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

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

    .content-wrapper {
        padding: 2rem 1rem;
    }

    .book-content h1 {
        font-size: 2rem;
    }

    .book-content h2 {
        font-size: 1.75rem;
    }

    .book-content h3 {
        font-size: 1.5rem;
    }

    .toggle-btn {
        position: fixed;
        top: 1rem;
        left: 1rem;
        z-index: 1001;
        width: auto;
        padding: 0.75rem 1rem;
        background: var(--accent-primary);
        border-radius: 50%;
    }
}

/* Print Styles */
@media print {
    .sidebar,
    .scroll-top,
    .theme-toggle {
        display: none;
    }

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

    .book-content {
        font-size: 12pt;
    }

    .book-content h2 {
        page-break-before: always;
    }

    .book-content h3,
    .book-content h4 {
        page-break-after: avoid;
    }
}

/* Scrollbar Styling */
.sidebar::-webkit-scrollbar,
.sidebar-content::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track,
.sidebar-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

.sidebar::-webkit-scrollbar-thumb,
.sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}


