/* ==========================================
   MODERN FLIPBOOK STYLES
   ========================================== */

/* ==========================================
   CSS VARIABLES & THEME SYSTEM
   ========================================== */
:root {
    /* Light Theme (Default) */
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary-color: #ec4899;
    --background: #ffffff;
    --surface: #f8fafc;
    --surface-elevated: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --blur-background: rgba(255, 255, 255, 0.8);
    
    /* Spacing */
    --header-height: 70px;
    --footer-height: 80px;
    
    /* Typography */
    --font-primary: 'Poppins', sans-serif;
    --font-reading: 'Merriweather', serif;
    --font-size-base: 16px;
    
    /* Animation */
    --transition-speed: 0.3s;
    --page-flip-duration: 0.6s;
}



/* ==========================================
   GLOBAL STYLES
   ========================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: var(--font-size-base);
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-primary);
    background: var(--background);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

/* ==========================================
   LOADING SCREEN
   ========================================== */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    transition: opacity 0.5s, visibility 0.5s;
}

.loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
}

.loader-container {
    text-align: center;
}

.book-loader {
    perspective: 1000px;
    margin-bottom: 20px;
}

.book {
    position: relative;
    width: 60px;
    height: 80px;
    margin: 0 auto;
    transform-style: preserve-3d;
}

.page {
    position: absolute;
    width: 30px;
    height: 80px;
    background: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 0 4px 4px 0;
    transform-origin: left center;
    animation: flipPage 1.5s ease-in-out infinite;
}

.page:nth-child(2) {
    animation-delay: 0.5s;
}

.page:nth-child(3) {
    animation-delay: 1s;
}

@keyframes flipPage {
    0%, 20% {
        transform: rotateY(0deg);
    }
    50% {
        transform: rotateY(-180deg);
    }
    100%, 80% {
        transform: rotateY(-180deg);
    }
}

.loading-text {
    color: white;
    font-size: 1.1rem;
    font-weight: 500;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* ==========================================
   MAIN CONTAINER
   ========================================== */
.flipbook-container {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* ==========================================
   HEADER
   ========================================== */
.flipbook-header {
    height: var(--header-height);
    background: var(--surface-elevated);
    border-bottom: 1px solid var(--border-color);
    position: relative;
    z-index: 100;
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-sm);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    height: calc(var(--header-height) - 4px);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.logo i {
    font-size: 1.75rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    width: 42px;
    height: 42px;
    border: none;
    background: var(--surface);
    color: var(--text-secondary);
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-speed);
    font-size: 1.1rem;
}

.btn-icon:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-icon:active {
    transform: translateY(0);
}

.progress-bar {
    height: 4px;
    background: var(--surface);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transition: width var(--transition-speed) ease;
    width: 0%;
}

/* ==========================================
   MAIN CONTENT AREA
   ========================================== */
.flipbook-main {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--surface);
}

.book-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    overflow-x: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y pinch-zoom; /* Allow vertical scroll, enable horizontal swipe detection */
}

/* ==========================================
   CHAPTER STYLES
   ========================================== */
.chapter {
    min-width: 100%;
    width: 100%;
    height: 100%;
    position: relative;
    background: var(--background);
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y; /* Allow vertical scroll, enable horizontal swipe */
}

.chapter-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 3rem 2rem;
    animation: fadeInUp 0.6s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chapter-content h2 {
    font-family: var(--font-reading);
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    line-height: 1.2;
}

.chapter-content p {
    font-family: var(--font-reading);
    font-size: 1.1rem;
    line-height: 1.8;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    text-align: justify;
}

.chapter-image {
    width: 100%;
    height: auto;
    border-radius: 16px;
    margin: 2rem 0;
    box-shadow: var(--shadow-lg);
    transition: transform var(--transition-speed);
}

.chapter-image:hover {
    transform: scale(1.02);
}

/* Media Elements */
.audio-player,
.video-player {
    width: 100%;
    margin: 2rem 0;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.audio-player audio,
.video-player video {
    width: 100%;
    display: block;
}

/* ==========================================
   NAVIGATION CONTROLS
   ========================================== */
.navigation-controls {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    display: flex;
    justify-content: space-between;
    padding: 0 1rem;
    pointer-events: none;
    z-index: 50;
}

.nav-btn {
    width: 50px;
    height: 50px;
    border: none;
    background: var(--surface-elevated);
    color: var(--text-primary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-speed);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    font-size: 1.2rem;
    opacity: 0.7;
}

.nav-btn:hover {
    opacity: 1;
    background: var(--primary-color);
    color: white;
    transform: scale(1.1);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: scale(1);
}

.nav-btn:active:not(:disabled) {
    transform: scale(0.95);
}

/* ==========================================
   CHAPTER INDICATOR
   ========================================== */
.chapter-indicator {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--blur-background);
    backdrop-filter: blur(10px);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
    z-index: 50;
}

/* ==========================================
   FOOTER
   ========================================== */
.flipbook-footer {
    height: var(--footer-height);
    background: var(--surface-elevated);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.05);
    z-index: 100;
}

.footer-content {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 2rem;
}

.footer-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--surface);
    color: var(--text-secondary);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-speed);
    font-size: 1rem;
}

.footer-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
}

.footer-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: translateY(0);
}

/* TTS Button */
.tts-toggle-btn {
    background: var(--primary-color);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    margin-left: 1rem;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
}

.tts-toggle-btn:hover {
    background: var(--primary-dark);
    color: white;
    transform: translateY(-2px);
}

.tts-toggle-btn:active {
    transform: translateY(0);
}

.tts-toggle-btn i {
    font-size: 1rem;
}

.chapter-dots {
    display: flex;
    gap: 0.5rem;
    padding: 0 1rem;
}

.chapter-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border-color);
    cursor: pointer;
    transition: all var(--transition-speed);
}

.chapter-dot:hover {
    background: var(--primary-light);
    transform: scale(1.2);
}

.chapter-dot.active {
    background: var(--primary-color);
    width: 30px;
    border-radius: 5px;
}

/* ==========================================
   MODALS
   ========================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-speed), visibility var(--transition-speed);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--surface-elevated);
    border-radius: 20px;
    box-shadow: var(--shadow-xl);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform var(--transition-speed);
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--surface);
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-speed);
}

.modal-close:hover {
    background: var(--primary-color);
    color: white;
    transform: rotate(90deg);
}

.modal-body {
    padding: 2rem;
    overflow-y: auto;
    max-height: calc(80vh - 80px);
}

/* Table of Contents */
.toc-list {
    list-style: none;
}

.toc-item {
    padding: 1rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.toc-item:hover {
    background: var(--surface);
    transform: translateX(5px);
}

.toc-item.active {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
}

.toc-number {
    width: 36px;
    height: 36px;
    background: var(--surface);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
}

.toc-item.active .toc-number {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.toc-title {
    flex: 1;
    font-weight: 500;
}



input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 0.5rem;
    cursor: pointer;
}

/* ==========================================
   RESPONSIVE DESIGN
   ========================================== */

/* Tablet */
@media (max-width: 1024px) {
    .header-content {
        padding: 0 1.5rem;
    }
    
    .chapter-content {
        padding: 2.5rem 1.5rem;
    }
    
    .chapter-content h2 {
        font-size: 2rem;
    }
}

/* Mobile */
@media (max-width: 768px) {
    :root {
        --header-height: 60px;
        --footer-height: 70px;
        --font-size-base: 15px;
    }
    
    .header-content {
        padding: 0 1rem;
    }
    
    .logo span {
        display: none;
    }
    
    .btn-icon {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }
    
    .chapter-content {
        padding: 2rem 1rem;
    }
    
    .chapter-content h2 {
        font-size: 1.75rem;
    }
    
    .chapter-content p {
        font-size: 1rem;
        text-align: left;
    }
    
    .navigation-controls {
        padding: 0 0.5rem;
    }
    
    .nav-btn {
        width: 44px;
        height: 44px;
        font-size: 1.1rem;
    }
    
    .chapter-indicator {
        top: 0.5rem;
        right: 0.5rem;
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }
    
    .footer-content {
        padding: 0 1rem;
        gap: 0.5rem;
    }
    
    .footer-btn {
        width: 36px;
        height: 36px;
    }
    
    .chapter-dots {
        padding: 0 0.5rem;
        gap: 0.4rem;
    }
    
    .chapter-dot {
        width: 8px;
        height: 8px;
    }
    
    .chapter-dot.active {
        width: 24px;
    }
    
    .modal-content {
        width: 95%;
        max-height: 90vh;
        border-radius: 16px;
    }
    
    .modal-header {
        padding: 1rem 1.5rem;
    }
    
    .modal-header h3 {
        font-size: 1.25rem;
    }
    
    .modal-body {
        padding: 1.5rem;
    }
    
    .theme-switcher {
        flex-direction: column;
    }
    
    .theme-btn {
        min-width: 100%;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .chapter-content h2 {
        font-size: 1.5rem;
    }
    
    .chapter-content p {
        font-size: 0.95rem;
    }
    
    .chapter-image {
        margin: 1.5rem 0;
    }
}

/* Landscape Mobile */
@media (max-width: 900px) and (orientation: landscape) {
    :root {
        --header-height: 50px;
        --footer-height: 60px;
    }
    
    .chapter-content {
        padding: 1.5rem 1rem;
    }
    
    .navigation-controls {
        display: none;
    }
}

/* ==========================================
   SCROLLBAR STYLES
   ========================================== */
.chapter::-webkit-scrollbar {
    width: 8px;
}

.chapter::-webkit-scrollbar-track {
    background: var(--surface);
}

.chapter::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.chapter::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* Firefox */
.chapter {
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) var(--surface);
}

/* ==========================================
   UTILITY CLASSES
   ========================================== */
.hidden {
    display: none !important;
}

.no-scroll {
    overflow: hidden;
}

/* ==========================================
   PRINT STYLES
   ========================================== */
@media print {
    .flipbook-header,
    .flipbook-footer,
    .navigation-controls,
    .chapter-indicator {
        display: none;
    }
    
    .flipbook-main {
        height: auto;
    }
    
    .chapter {
        page-break-after: always;
    }
}

/* ==========================================
   ACCESSIBILITY
   ========================================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
button:focus-visible,
.chapter-dot:focus-visible,
.toc-item:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Model Viewer */
model-viewer {
    width: 100%;
    height: 500px;
    background-color: #18181b;
}