/* ═══════════════════════════════════════════════════════════════
   VoxEdu PDF Reader - Web Version
   Premium textbook PDF viewer with elegant design
   ═══════════════════════════════════════════════════════════════ */

/* CSS Variables for Themes */
:root {
    /* Ivory Theme (Default) */
    --bg-primary: #f5f0e8;
    --bg-secondary: #ebe4d8;
    --bg-tertiary: #ddd4c4;
    --accent: #8b7355;
    --accent-hover: #6b5a45;
    --text-primary: #2d2a26;
    --text-secondary: #5c5650;
    --text-muted: #8a847a;
    --page-bg: #fffef9;
    --page-shadow: rgba(0, 0, 0, 0.15);
    --border: rgba(139, 115, 85, 0.3);
}

.theme-ivory {
    --bg-primary: #f5f0e8;
    --bg-secondary: #ebe4d8;
    --bg-tertiary: #ddd4c4;
    --accent: #8b7355;
    --accent-hover: #6b5a45;
    --text-primary: #2d2a26;
    --text-secondary: #5c5650;
    --text-muted: #8a847a;
    --page-bg: #fffef9;
    --page-shadow: rgba(0, 0, 0, 0.15);
    --border: rgba(139, 115, 85, 0.3);
}

.theme-midnight {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a24;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #475569;
    --page-bg: #fefdfb;
    --page-shadow: rgba(0, 0, 0, 0.4);
    --border: rgba(99, 102, 241, 0.2);
}

.theme-sepia {
    --bg-primary: #1a1410;
    --bg-secondary: #261e18;
    --bg-tertiary: #332820;
    --accent: #d4a574;
    --accent-hover: #e8c49a;
    --text-primary: #f5ebe0;
    --text-secondary: #c9b99a;
    --text-muted: #8a7a60;
    --page-bg: #faf6f0;
    --page-shadow: rgba(0, 0, 0, 0.35);
    --border: rgba(212, 165, 116, 0.25);
}

/* ═══════════════════════════════════════════════════════════════
   Base Styles
   ═══════════════════════════════════════════════════════════════ */

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

body {
    font-family: "Avenir Next", "Helvetica Neue", -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Background Image */
.background-image {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('resource/bg2.jpg');
    background-size: cover;
    background-position: center;
    opacity: 0.5;
    z-index: -1;
    pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════
   Header
   ═══════════════════════════════════════════════════════════════ */

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

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.logo {
    height: 45px;
    width: auto;
}

.filename {
    color: var(--text-muted);
    font-size: 12px;
}

/* Book Selector */
.book-selector {
    display: flex;
    flex-direction: row;
    gap: 8px;
}

.book-title {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    padding: 4px 12px;
    cursor: pointer;
    text-align: left;
    border-radius: 6px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    letter-spacing: 0.3px;
}

.book-title:hover {
    color: var(--text-primary);
    transform: scale(1.05);
    background: var(--bg-tertiary);
}

.book-title.active {
    color: var(--accent);
    font-weight: 600;
    background: var(--bg-tertiary);
}

.book-title.active::before {
    content: '▸';
    position: absolute;
    left: 2px;
    font-size: 10px;
}

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

/* Theme Selectors */
.theme-selectors {
    display: flex;
    gap: 8px;
}

.theme-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    position: relative;
    padding: 0;
}

.theme-btn .theme-outer {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.theme-btn.active .theme-outer {
    border-color: var(--accent);
}

.theme-btn .theme-inner {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
}

.theme-btn .theme-accent {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* Ivory theme button */
.theme-btn[data-theme="ivory"] .theme-inner { background: #f5f0e8; }
.theme-btn[data-theme="ivory"] .theme-accent { background: #8b7355; }

/* Midnight theme button */
.theme-btn[data-theme="midnight"] .theme-inner { background: #0a0a0f; }
.theme-btn[data-theme="midnight"] .theme-accent { background: #6366f1; }

/* Sepia theme button */
.theme-btn[data-theme="sepia"] .theme-inner { background: #1a1410; }
.theme-btn[data-theme="sepia"] .theme-accent { background: #d4a574; }

/* Open Button */
.open-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 8px 16px;
    font-size: 30px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s;
}

.open-btn:hover {
    color: var(--accent);
}

/* ═══════════════════════════════════════════════════════════════
   Book Area
   ═══════════════════════════════════════════════════════════════ */

.book-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: stretch;
    padding: 4px 24px 4px;
    gap: 0;
    min-height: 0;
    overflow: hidden;
}

/* Page Container */
.page-container {
    flex: 1;
    max-width: 50%;
    min-width: 250px;
    min-height: 0;
    background: var(--page-bg);
    border-radius: 3px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 4px;
    box-shadow: 0 8px 30px var(--page-shadow);
}

.left-page {
    box-shadow: 6px 10px 40px rgba(0, 0, 0, 0.25);
    background: linear-gradient(to right, var(--page-bg), color-mix(in srgb, var(--page-bg) 98%, black));
}

.right-page {
    box-shadow: -6px 10px 40px rgba(0, 0, 0, 0.25);
    background: linear-gradient(to left, var(--page-bg), color-mix(in srgb, var(--page-bg) 98%, black));
}

/* Page Content */
.page-content {
    width: calc(100% - 20px);
    height: calc(100% - 20px);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    overflow: hidden;
}

/* Image mode: enable scrolling when zoomed */
.page-content.image-mode {
    overflow: auto;
    align-items: flex-start;
    justify-content: flex-start;
}

/* Scrollbar styling */
.page-content::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.page-content::-webkit-scrollbar-track {
    background: transparent;
}

.page-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.page-content::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

.page-content canvas {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.page-content .page-image {
    width: auto;
    height: auto;
    object-fit: contain;
    display: none;
    transition: max-width 0.2s ease, max-height 0.2s ease;
    /* Center image when smaller than container */
    margin: auto;
}

/* Image mode: hide canvas, show image */
.page-content.image-mode canvas {
    display: none;
}

.page-content.image-mode .page-image {
    display: block;
}

/* Page Fold Effect */
.page-fold {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 25px;
    pointer-events: none;
    z-index: 2;
}

.left-page .page-fold {
    right: 0;
    background: linear-gradient(to right, 
        transparent 0%, 
        rgba(0, 0, 0, 0.02) 70%, 
        rgba(0, 0, 0, 0.06) 100%
    );
}

.right-page .page-fold {
    left: 0;
    background: linear-gradient(to left, 
        transparent 0%, 
        rgba(0, 0, 0, 0.02) 70%, 
        rgba(0, 0, 0, 0.06) 100%
    );
}

/* Spine */
.spine {
    width: 8px;
    min-width: 8px;
    background: linear-gradient(to right,
        var(--bg-tertiary),
        color-mix(in srgb, var(--bg-tertiary) 90%, white) 30%,
        color-mix(in srgb, var(--bg-tertiary) 85%, white) 50%,
        color-mix(in srgb, var(--bg-tertiary) 90%, white) 70%,
        var(--bg-tertiary)
    );
    border-radius: 2px;
    align-self: stretch;
    margin: 8px 0;
}

/* Page Overlay */
.page-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 60px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
    border-radius: 3px;
}

.page-container:hover .page-overlay {
    opacity: 1;
}

/* Overlay Buttons */
.overlay-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    transition: transform 0.2s ease;
}

.overlay-btn img {
    width: 100%;
    min-width: 300px;
    max-width: 500px;
    height: auto;
    transition: transform 0.2s ease;
}

.overlay-btn:hover img {
    transform: scale(1.1);
}

/* TTS Playing State */
.overlay-btn.playing {
    position: relative;
}

/* ═══════════════════════════════════════════════════════════════
   Controls
   ═══════════════════════════════════════════════════════════════ */

.controls-container {
    flex-shrink: 0;
    padding: 0 24px 4px;
}

/* Audio Controls */
.audio-controls {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 20px;
    margin-bottom: 8px;
}

.audio-player-ui {
    display: flex;
    align-items: center;
    gap: 12px;
}

.audio-btn {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.audio-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.1);
}

.audio-time {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    min-width: 40px;
    text-align: center;
}

.audio-progress {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.audio-progress::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
}

.audio-progress::-webkit-slider-thumb:hover {
    width: 16px;
    height: 16px;
    background: var(--accent-hover);
}

.audio-progress::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.audio-progress::-moz-range-thumb:hover {
    width: 16px;
    height: 16px;
    background: var(--accent-hover);
}

.controls {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    gap: 16px;
}

/* Navigation Buttons */
.nav-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 10px 24px;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: color 0.2s;
    font-family: inherit;
}

.nav-btn:hover:not(:disabled) {
    color: var(--accent);
}

.nav-btn:active:not(:disabled) {
    color: var(--accent-hover);
}

.nav-btn:disabled {
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Page Info */
.page-info {
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-align: center;
    flex: 1;
}

/* Zoom Controls */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.icon-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 20px;
    padding: 4px 8px;
    font-size: 18px;
    min-width: 40px;
    min-height: 36px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

/* Zoom Slider */
.zoom-slider {
    width: 100px;
    height: 3px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: 1px;
    outline: none;
}

.zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
}

.zoom-slider::-webkit-slider-thumb:hover {
    width: 18px;
    height: 18px;
    background: var(--accent-hover);
}

.zoom-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.zoom-slider::-moz-range-thumb:hover {
    width: 18px;
    height: 18px;
    background: var(--accent-hover);
}

/* Progress Bar */
.progress-bar {
    height: 3px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s ease;
}

/* Hint */
.hint {
    color: var(--text-primary);
    font-size: 10px;
    letter-spacing: 0.5px;
    text-align: center;
    height: 20px;
    line-height: 20px;
}

/* ═══════════════════════════════════════════════════════════════
   Empty State
   ═══════════════════════════════════════════════════════════════ */

.page-container.empty::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60%;
    height: 80%;
    background: repeating-linear-gradient(
        0deg,
        var(--bg-tertiary) 0px,
        var(--bg-tertiary) 1px,
        transparent 1px,
        transparent 24px
    );
    opacity: 0.3;
    pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════
   Responsive Design
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 1200px) {
    .book-area {
        padding: 6px 20px 8px;
    }
    
    .page-container {
        min-width: 300px;
    }
    
    .nav-btn {
        padding: 10px 20px;
        font-size: 16px;
    }
    
    .page-info {
        font-size: 16px;
    }
}

@media (max-width: 900px) {
    .book-area {
        flex-direction: column;
        align-items: center;
    }
    
    .page-container {
        max-width: 100%;
        width: 100%;
    }
    
    .spine {
        width: 100%;
        height: 8px;
        min-height: 8px;
        margin: 0 8px;
        background: linear-gradient(to bottom,
            var(--bg-tertiary),
            color-mix(in srgb, var(--bg-tertiary) 90%, white) 30%,
            color-mix(in srgb, var(--bg-tertiary) 85%, white) 50%,
            color-mix(in srgb, var(--bg-tertiary) 90%, white) 70%,
            var(--bg-tertiary)
        );
    }
    
    .left-page .page-fold,
    .right-page .page-fold {
        display: none;
    }
}

/* ═══════════════════════════════════════════════════════════════
   Print Styles
   ═══════════════════════════════════════════════════════════════ */

@media print {
    .header,
    .controls-container,
    .page-overlay,
    .background-image {
        display: none !important;
    }
    
    body {
        background: white;
    }
    
    .page-container {
        box-shadow: none;
        page-break-after: always;
    }
}
