/* CSS Variables for Theming */
:root {
    /* Light Theme */
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #fafafa;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --accent-primary: #3b82f6;
    --accent-secondary: #8b5cf6;
    --accent-code: #10b981;
    --border-color: #e5e5e5;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
    --code-bg: #f8f9fa;
    --code-text: #e83e8c;
    --sidebar-bg: #ffffff;
    --navbar-bg: rgba(255, 255, 255, 0.95);
    --backdrop-blur: blur(10px);
}

[data-theme="dark"] {
    /* Dark Theme */
    --bg-primary: #0a0a0a;
    --bg-secondary: #121212;
    --bg-tertiary: #1a1a1a;
    --text-primary: #e5e5e5;
    --text-secondary: #a3a3a3;
    --text-tertiary: #737373;
    --accent-primary: #60a5fa;
    --accent-secondary: #a78bfa;
    --accent-code: #34d399;
    --border-color: #262626;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
    --code-bg: #1a1a1a;
    --code-text: #f472b6;
    --sidebar-bg: #1a1a1a;
    --navbar-bg: rgba(18, 18, 18, 0.95);
}

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

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

body {
    font-family: 'Crimson Text', 'Georgia', serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.8;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

/* Navigation Bar */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--navbar-bg);
    backdrop-filter: var(--backdrop-blur);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    padding: 1rem 0;
    box-shadow: var(--shadow-sm);
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.code-bracket {
    color: var(--accent-code);
    font-weight: 600;
}

.brand-text {
    color: var(--text-primary);
}

.nav-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.nav-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
}

.nav-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.nav-btn svg {
    stroke: currentColor;
}

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 60px;
    width: 320px;
    height: calc(100vh - 60px);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-md);
}

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

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 10;
}

.sidebar-header h3 {
    font-family: 'Inter', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

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

.chapter-list {
    padding: 1rem;
}

.chapter-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.chapter-item:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
}

.chapter-item.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.chapter-item-title {
    font-weight: 500;
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}

.chapter-item-number {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    font-family: 'JetBrains Mono', monospace;
}

.chapter-item.active .chapter-item-number {
    color: rgba(255, 255, 255, 0.8);
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    position: sticky;
    bottom: 0;
}

.progress-info {
    margin-top: 1rem;
}

.progress-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-family: 'Inter', sans-serif;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
    text-align: center;
}

/* Main Content */
.main-content {
    margin-top: 60px;
    min-height: calc(100vh - 60px);
}

/* Book Cover */
.book-cover {
    max-width: 1200px;
    margin: 0 auto;
    padding: 4rem 2rem;
    min-height: calc(100vh - 60px);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.cover-content {
    text-align: center;
    z-index: 2;
    max-width: 700px;
}

/* Terminal Window */
.terminal-window {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    margin-bottom: 3rem;
    text-align: left;
    display: inline-block;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    max-width: 100%;
    width: 100%;
    max-width: 700px;
}

.terminal-header {
    background: var(--bg-tertiary);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    gap: 1rem;
}

.terminal-buttons {
    display: flex;
    gap: 0.5rem;
}

.terminal-btn {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.terminal-btn.close {
    background: #ff5f56;
}

.terminal-btn.minimize {
    background: #ffbd2e;
}

.terminal-btn.maximize {
    background: #27c93f;
}

.terminal-title {
    flex: 1;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
}

.terminal-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-code);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.terminal-body {
    padding: 1.5rem;
    background: var(--code-bg);
    min-height: 280px;
}

.terminal-line {
    margin-bottom: 0.75rem;
    line-height: 1.6;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.terminal-prompt {
    color: var(--accent-code);
    font-weight: 600;
    user-select: none;
}

.terminal-prompt.blinking {
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.terminal-command {
    color: var(--text-primary);
}

.terminal-line.output {
    margin-left: 1.5rem;
}

.output-text {
    color: var(--accent-code);
}

.code-block {
    margin: 1rem 0;
    padding-left: 0.5rem;
}

.code-line {
    line-height: 1.8;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

.code-line.indent {
    padding-left: 1.5rem;
}

.code-line.comment {
    color: var(--text-tertiary);
}

.code-line .keyword {
    color: var(--accent-primary);
    font-weight: 600;
}

.code-line .code-var {
    color: var(--accent-secondary);
}

.code-line .code-operator {
    color: var(--text-secondary);
}

.code-line .code-bracket {
    color: var(--text-primary);
}

.code-line .code-property {
    color: var(--accent-code);
}

.code-line .code-string {
    color: var(--accent-code);
}

.code-line .code-number {
    color: var(--accent-primary);
}

.cover-title {
    font-size: 3.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
    line-height: 1.2;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.cover-author {
    font-size: 1.3rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-style: italic;
}

.cover-meta {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: 3rem;
    flex-wrap: wrap;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.meta-item {
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.meta-icon {
    font-size: 1rem;
}

.meta-divider {
    color: var(--text-tertiary);
}

.start-reading-btn {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border: none;
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    font-family: 'Inter', sans-serif;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.start-reading-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.start-reading-btn:hover::before {
    left: 100%;
}

.start-reading-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.start-reading-btn:active {
    transform: translateY(0);
}

.btn-code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    opacity: 0.9;
}

.btn-text {
    font-family: 'Inter', sans-serif;
}

.cover-pattern {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.03;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 2px, var(--text-primary) 2px, var(--text-primary) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, var(--text-primary) 2px, var(--text-primary) 4px);
    pointer-events: none;
}

.code-grid {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.02;
    background-image: 
        linear-gradient(var(--accent-code) 1px, transparent 1px),
        linear-gradient(90deg, var(--accent-code) 1px, transparent 1px);
    background-size: 50px 50px;
    pointer-events: none;
    z-index: 1;
}

/* Reader Container */
.reader-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem;
}

.book-page {
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 3rem 4rem;
    min-height: calc(100vh - 140px);
    position: relative;
    border: 1px solid var(--border-color);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.nav-chapter-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
}

.nav-chapter-btn:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.nav-chapter-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.chapter-info {
    text-align: center;
    flex: 1;
}

.chapter-number {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-tertiary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.chapter-title {
    display: block;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
}

.book-content {
    font-size: 1.15rem;
    line-height: 1.9;
    color: var(--text-primary);
    max-width: 100%;
}

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

.book-content h2 {
    font-size: 1.8rem;
    margin: 2.5rem 0 1.5rem 0;
    color: var(--text-primary);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.book-content code,
.book-content pre {
    font-family: 'JetBrains Mono', monospace;
    background: var(--code-bg);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9em;
    border: 1px solid var(--border-color);
}

.book-content pre {
    padding: 1rem;
    margin: 1.5rem 0;
    overflow-x: auto;
    border-radius: 8px;
    line-height: 1.6;
}

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

.page-footer {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
}

.page-numbers {
    font-family: 'JetBrains Mono', monospace;
}

/* Loading States */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    color: var(--text-secondary);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .book-page {
        padding: 2rem 3rem;
    }
    
    .cover-title {
        font-size: 2.5rem;
    }
}

@media (max-width: 768px) {
    .nav-container {
        padding: 0 1rem;
    }
    
    .nav-brand {
        font-size: 0.9rem;
    }
    
    .sidebar {
        width: 100%;
        max-width: 320px;
    }
    
    .book-cover {
        padding: 2rem 1rem;
    }
    
    .cover-title {
        font-size: 2rem;
    }
    
    .terminal-window {
        font-size: 0.8rem;
    }
    
    .terminal-body {
        padding: 1rem;
        min-height: 240px;
    }
    
    .reader-container {
        padding: 1rem;
    }
    
    .book-page {
        padding: 2rem 1.5rem;
        border-radius: 8px;
    }
    
    .page-header {
        flex-direction: column;
        gap: 1rem;
    }
    
    .nav-chapter-btn {
        width: 100%;
        justify-content: center;
    }
    
    .chapter-info {
        order: -1;
    }
    
    .book-content {
        font-size: 1.05rem;
    }
    
    .page-footer {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .cover-title {
        font-size: 1.75rem;
    }
    
    .cover-meta {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .meta-divider {
        display: none;
    }
    
    .book-content {
        font-size: 1rem;
    }
    
    .book-content h2 {
        font-size: 1.4rem;
    }
}

/* Print Styles */
@media print {
    .navbar,
    .sidebar,
    .overlay,
    .page-header,
    .page-footer {
        display: none;
    }
    
    .main-content {
        margin-top: 0;
    }
    
    .book-page {
        box-shadow: none;
        border: none;
        padding: 0;
    }
}

