/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

:root {
    /* Transitions */
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s ease;
    
    /* Layout */
    --sidebar-width: 320px;
    --header-height: 70px;
}

/* Theme Variables */
.theme-dark {
    --bg-color: #0f1115;
    --panel-bg: rgba(22, 26, 33, 0.7);
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #484f58;
    --border-color: rgba(255, 255, 255, 0.08);
    --accent-color: #58a6ff;
    --accent-hover: #1f6feb;
    --scrollbar-thumb: #30363d;
    --scrollbar-bg: #0f1115;
    --active-item-bg: rgba(88, 166, 255, 0.15);
    --shadow-color: rgba(0, 0, 0, 0.3);
}

.theme-light {
    --bg-color: #f8f9fa;
    --panel-bg: rgba(255, 255, 255, 0.75);
    --text-primary: #1f2328;
    --text-secondary: #57606a;
    --text-muted: #8c959f;
    --border-color: rgba(0, 0, 0, 0.08);
    --accent-color: #0969da;
    --accent-hover: #0550ae;
    --scrollbar-thumb: #d0d7de;
    --scrollbar-bg: #f8f9fa;
    --active-item-bg: rgba(9, 105, 218, 0.1);
    --shadow-color: rgba(0, 0, 0, 0.05);
}

.theme-sepia {
    --bg-color: #f4ecd8;
    --panel-bg: rgba(250, 245, 230, 0.75);
    --text-primary: #433422;
    --text-secondary: #705e4c;
    --text-muted: #a3907c;
    --border-color: rgba(67, 52, 34, 0.1);
    --accent-color: #b85c00;
    --accent-hover: #8f4700;
    --scrollbar-thumb: #d9cdb0;
    --scrollbar-bg: #f4ecd8;
    --active-item-bg: rgba(184, 92, 0, 0.12);
    --shadow-color: rgba(67, 52, 34, 0.05);
}

/* Font Families */
.font-lora {
    --font-reading: 'Lora', Georgia, serif;
}
.font-inter {
    --font-reading: 'Inter', system-ui, sans-serif;
}
.font-playfair {
    --font-reading: 'Playfair Display', serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Inter', system-ui, sans-serif;
    overflow-x: hidden;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* Glassmorphism Styles */
.glass-effect {
    background-color: var(--panel-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px 0 var(--shadow-color);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: var(--scrollbar-bg);
}
::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 5px;
    border: 2px solid var(--scrollbar-bg);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

/* Progress Indicator */
#progress-bar-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: transparent;
    z-index: 1000;
}
#progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), #bc85ff);
    transition: width 0.1s ease-out;
}

/* Layout Container */
#app-container {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* Sidebar Navigation */
#sidebar {
    width: var(--sidebar-width);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-top: none;
    border-bottom: none;
    border-left: none;
}

#sidebar.collapsed {
    transform: translateX(-100%);
}

.sidebar-header {
    height: var(--header-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-accent {
    background: linear-gradient(135deg, var(--accent-color), #bc85ff);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 800;
}

.sidebar-novel-select {
    padding: 16px 20px 8px 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-novel-select label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 600;
}

.glass-select {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    transition: var(--transition-fast);
}

.glass-select option {
    background-color: var(--bg-color);
    color: var(--text-primary);
}

.glass-select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.15);
}

.sidebar-search {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

#chapter-search {
    width: 100%;
    padding: 12px 16px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition-fast);
}

#chapter-search:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.15);
}

.chapter-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
}

.chapter-item {
    display: block;
    width: 100%;
    padding: 14px 16px;
    margin-bottom: 6px;
    border-radius: 10px;
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.92rem;
    transition: var(--transition-fast);
    text-decoration: none;
}

.chapter-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
}

.theme-light .chapter-item:hover {
    background: rgba(0, 0, 0, 0.03);
}

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

.chapter-item .chap-no {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
    color: var(--text-muted);
}

.chapter-item.active .chap-no {
    color: var(--accent-color);
}

/* Main Content Wrapper */
#main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#main-content.sidebar-collapsed {
    margin-left: 0;
}

/* Controls Header */
#controls-header {
    position: fixed;
    top: 0;
    right: 0;
    left: var(--sidebar-width);
    height: var(--header-height);
    padding: 0 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 90;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-top: none;
    border-left: none;
    border-right: none;
}

#main-content.sidebar-collapsed #controls-header {
    left: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    overflow: hidden;
}

.chapter-label {
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
    font-size: 1rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Mode Buttons */
.mode-selector {
    display: flex;
    border-radius: 12px;
    padding: 2px;
    box-shadow: none;
}

.mode-btn {
    padding: 8px 16px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.mode-btn:hover {
    color: var(--text-primary);
}

.mode-btn.active {
    background: var(--accent-color);
    color: white;
}

/* Icon Buttons */
.icon-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-fast);
}

.icon-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    background: rgba(255, 255, 255, 0.02);
}

.theme-light .icon-btn:hover {
    background: rgba(0, 0, 0, 0.02);
}

/* Settings Drawer */
#settings-drawer {
    position: fixed;
    top: calc(var(--header-height) + 12px);
    right: 32px;
    width: 320px;
    border-radius: 16px;
    z-index: 95;
    padding: 24px;
    transform: translateY(-20px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#settings-drawer.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: all;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.drawer-header h3 {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 1.1rem;
}

.setting-group {
    margin-bottom: 20px;
}

.setting-group:last-child {
    margin-bottom: 0;
}

.setting-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.theme-options, .font-options, .line-height-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.theme-btn, .font-btn, .line-btn {
    padding: 10px 6px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}

.theme-btn:hover, .font-btn:hover, .line-btn:hover {
    border-color: var(--accent-color);
    color: var(--text-primary);
}

.theme-btn.active, .font-btn.active, .line-btn.active {
    background: var(--active-item-bg);
    border-color: var(--accent-color);
    color: var(--accent-color);
    font-weight: 600;
}

.font-options {
    grid-template-columns: 1fr;
}

.font-btn {
    text-align: left;
    padding: 12px 14px;
}

.size-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 4px;
}

.size-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    border-radius: 6px;
    transition: var(--transition-fast);
}

.size-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.theme-light .size-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

#size-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Reading Pane */
#reader-pane {
    flex: 1;
    padding: calc(var(--header-height) + 40px) 24px 60px 24px;
    display: flex;
    justify-content: center;
    width: 100%;
}

.reader-container {
    max-width: 720px;
    width: 100%;
}

.chapter-header {
    margin-bottom: 48px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 24px;
    text-align: center;
}

.chapter-header h1 {
    font-family: 'Cabinet Grotesk', 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 2.2rem;
    line-height: 1.25;
    margin-bottom: 12px;
    letter-spacing: -0.5px;
}

.cn-sub {
    font-size: 1.15rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-family: 'Inter', system-ui, sans-serif;
}

/* Reader Content Panel */
.chapter-content {
    font-family: var(--font-reading);
    font-size: 1.15rem; /* Will be scaled via JS */
    line-height: 1.8;
    color: var(--text-primary);
}

/* Dual Mode Layout */
.dual-paragraph-pair {
    margin-bottom: 2.2rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.04);
}

.theme-light .dual-paragraph-pair {
    border-bottom-color: rgba(0, 0, 0, 0.04);
}

.dual-para-cn {
    display: block;
    color: var(--text-secondary);
    font-size: 0.95em;
    margin-top: 8px;
    font-style: italic;
    font-family: 'Inter', system-ui, sans-serif;
}

.chapter-content p {
    margin-bottom: 1.8rem;
}

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

.nav-btn {
    flex: 1;
    padding: 16px 24px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition-smooth);
}

.nav-btn:hover {
    border-color: var(--accent-color);
    background: var(--active-item-bg);
    color: var(--accent-color);
    transform: translateY(-2px);
}

.nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    border-color: var(--border-color);
    background: transparent;
    color: var(--text-secondary);
}

/* Loading Spinner */
.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s infinite linear;
    margin: 40px auto;
}

.reader-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 100px 0;
    color: var(--text-secondary);
}

.reader-loading p {
    margin-top: 16px;
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
}

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

.fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

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

/* Responsive Design */
@media (max-width: 992px) {
    #sidebar {
        transform: translateX(-100%);
    }
    
    #sidebar.open {
        transform: translateX(0);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.4);
    }
    
    #main-content {
        margin-left: 0;
    }
    
    #controls-header {
        left: 0;
        padding: 0 20px;
    }
    
    #settings-drawer {
        right: 20px;
        width: calc(100% - 40px);
        max-width: 340px;
    }
    
    #reader-pane {
        padding: calc(var(--header-height) + 20px) 16px 40px 16px;
    }
    
    .chapter-header h1 {
        font-size: 1.8rem;
    }
}

@media (max-width: 480px) {
    .header-right {
        gap: 8px;
    }
    
    .mode-btn {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
    
    .chapter-label {
        font-size: 0.85rem;
        max-width: 140px;
    }
    
    .chapter-nav-footer {
        flex-direction: column;
    }
    
    .nav-btn {
        width: 100%;
    }
}

/* Floating Bottom Navigation Bar */
#floating-nav {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    border-radius: 30px;
    z-index: 95;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    opacity: 1;
}

.theme-light #floating-nav {
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

#floating-nav.hidden {
    transform: translateX(-50%) translateY(100px);
    opacity: 0;
    pointer-events: none;
}

.float-nav-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.float-nav-btn:hover {
    background: var(--active-item-bg);
    color: var(--accent-color);
}

.float-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#float-chapter-indicator {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
    user-select: none;
    white-space: nowrap;
}

/* Typography / Bold Text Styling */
.chapter-content strong {
    font-weight: 700;
    color: var(--text-primary);
}

.theme-dark .chapter-content strong {
    color: #ffffff;
    text-shadow: 0 0 1px rgba(255, 255, 255, 0.2);
}

/* Headers within text styling */
.chapter-content h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.35rem;
    margin: 2rem 0 1rem 0;
    color: var(--accent-color);
    font-weight: 600;
}

.chapter-content h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.55rem;
    margin: 2.5rem 0 1.2rem 0;
    color: var(--accent-color);
    font-weight: 700;
}

/* TTS Player Panel */
#tts-player {
    margin-bottom: 32px;
    padding: 16px 20px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: var(--transition-smooth);
}

.tts-player-main {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.tts-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-fast);
    box-shadow: 0 4px 12px rgba(88, 166, 255, 0.2);
}

.tts-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.tts-btn:disabled {
    background: var(--text-muted);
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

#tts-stop-btn {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: none;
}

#tts-stop-btn:hover:not(:disabled) {
    background: rgba(255, 0, 0, 0.15);
    color: #ff4d4d;
    border-color: rgba(255, 0, 0, 0.2);
}

.tts-progress-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

#tts-status {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--text-primary);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

#tts-progress {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.tts-btn-small {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-fast);
}

.tts-btn-small:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    background: var(--active-item-bg);
}

.tts-btn-small.active {
    background: var(--active-item-bg);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

/* Settings Expandable Panel */
#tts-settings-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    transition: all 0.3s ease;
    max-height: 200px;
    opacity: 1;
    overflow: hidden;
}

#tts-settings-panel.tts-settings-hidden {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    border-top: none;
    pointer-events: none;
}

.tts-setting-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tts-setting-row label, .tts-slider-col label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tts-select {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

.theme-light .tts-select {
    background: rgba(255, 255, 255, 0.8);
}

.tts-setting-row-sliders {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.tts-slider-col {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tts-slider-col input[type="range"] {
    width: 100%;
    accent-color: var(--accent-color);
    cursor: pointer;
}

/* Paragraph Speaking Highlight */
.chapter-content p, .chapter-content .dual-paragraph-pair {
    transition: background-color 0.3s ease, border-left 0.3s ease, padding-left 0.3s ease;
    border-left: 3px solid transparent;
}

.chapter-content p.speaking-highlight {
    background: rgba(88, 166, 255, 0.08);
    border-left: 3px solid var(--accent-color);
    padding-left: 12px;
    border-radius: 0 8px 8px 0;
}

.theme-sepia .chapter-content p.speaking-highlight {
    background: rgba(184, 92, 0, 0.08);
}

.chapter-content .dual-paragraph-pair.speaking-highlight {
    background: rgba(88, 166, 255, 0.08);
    border-left: 3px solid var(--accent-color);
    padding-left: 12px;
    border-radius: 0 8px 8px 0;
}

.theme-sepia .chapter-content .dual-paragraph-pair.speaking-highlight {
    background: rgba(184, 92, 0, 0.08);
}


