/* ==========================================================================
   Luna Read Studio - Premium 3D Book Flipbook Styles
   ========================================================================== */

:root {
    --bg-dark: #0b0d14;
    --bg-surface: #141724;
    --bg-surface-elevated: #1e2238;
    --bg-glass: rgba(20, 23, 36, 0.85);
    
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.35);
    --accent: #38bdf8;
    
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: rgba(255, 255, 255, 0.1);
    --border-hover: rgba(255, 255, 255, 0.2);
    
    --header-height: 64px;
    --footer-height: 70px;
    
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.6);
    --shadow-book: 0 15px 35px rgba(0, 0, 0, 0.7), 0 0 20px rgba(0, 0, 0, 0.4);
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

/* App Structure */
.app-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    position: relative;
    background: radial-gradient(circle at 50% 30%, #1e2238 0%, #0b0d14 70%);
}

/* Header */
.app-header {
    height: var(--header-height);
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
}

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

.book-badge {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: #fff;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.title-group {
    display: flex;
    flex-direction: column;
}

.book-title {
    font-family: 'Noto Serif Bengali', serif;
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
}

.book-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.header-center {
    display: flex;
    align-items: center;
}

.page-indicator {
    background: rgba(255, 255, 255, 0.06);
    padding: 6px 18px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    font-size: 0.9rem;
    font-weight: 500;
    color: #e2e8f0;
    letter-spacing: 0.5px;
}

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

.divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 4px;
}

/* Button UI */
.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.icon-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 0 12px var(--primary-glow);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-fast);
    border: none;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--border-hover);
}

/* Workspace Stage */
.workspace-stage {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 20px;
}

/* Navigation Overlay Arrows */
.stage-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(20, 23, 36, 0.7);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 50;
    transition: all var(--transition-fast);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.stage-nav:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 0 20px var(--primary-glow);
}

.nav-prev { left: 30px; }
.nav-next { right: 30px; }

/* Loader */
.loader-container {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: var(--text-muted);
    font-size: 0.95rem;
    z-index: 60;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Header Zoom Toolbar */
.zoom-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.04);
    padding: 3px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.zoom-badge {
    font-size: 0.82rem;
    font-weight: 600;
    color: #e2e8f0;
    min-width: 44px;
    text-align: center;
}

/* Workspace Stage Zoom & Drag Pan States */
.workspace-stage.zoomed-in {
    cursor: grab;
}

.workspace-stage.zoomed-in:active {
    cursor: grabbing;
}

.stage-zoom-hint {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 17, 26, 0.75);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.78rem;
    color: var(--text-muted);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 55;
}

.workspace-stage.zoomed-in .stage-zoom-hint {
    opacity: 1;
}

/* Flipbook Stage & Container */
.flipbook-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease-out;
}

.flipbook-container {
    box-shadow: var(--shadow-book);
    border-radius: 4px;
    transition: transform 0.15s ease-out;
}

/* Individual Page Element Styles */
.page {
    background-color: #ffffff;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;

    /* Lightweight GPU Layer Optimization */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    isolation: isolate;
}

/* Hardcover page effect */
.page.--hard {
    background-color: #1a1d29;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.page-content {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;

    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    isolation: isolate;
}

.page-img {
    width: 100%;
    height: 100%;
    object-fit: contain; /* ALWAYS preserve natural aspect ratio for inner text pages */
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    background: #ffffff;
    opacity: 0; /* Fade in when image finishes loading */
    transition: opacity 0.25s ease-in-out;

    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    pointer-events: none;
}

.page-img.loaded {
    opacity: 1;
}

/* Full Edge-to-Edge Cover Images (Zero White Margins / Borders) */
.page-cover-front, .page-cover-back {
    background-color: #1a1d29 !important;
    border: none !important;
}

.page-content-cover {
    background-color: #1a1d29 !important;
}

.page-img.cover-img {
    object-fit: fill !important; /* Fills 100% of cover page width & height Edge-to-Edge */
    background: transparent !important;
}

/* Per-Page Sleek Loading Spinner */
.page-spinner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    z-index: 10;
    transition: opacity 0.2s ease-out;
}

.mini-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(99, 102, 241, 0.15);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Realistic Spine Crease Shadow */
.page-shadow-left {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 30px;
    background: linear-gradient(to left, rgba(0,0,0,0.22) 0%, rgba(0,0,0,0.06) 50%, rgba(0,0,0,0) 100%);
    pointer-events: none;
}

.page-shadow-right {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 30px;
    background: linear-gradient(to right, rgba(0,0,0,0.22) 0%, rgba(0,0,0,0.06) 50%, rgba(0,0,0,0) 100%);
    pointer-events: none;
}

.page-number-overlay {
    position: absolute;
    bottom: 12px;
    font-size: 0.75rem;
    color: #64748b;
    font-weight: 500;
}

.page-left .page-number-overlay { left: 16px; }
.page-right .page-number-overlay { right: 16px; }

/* Footer Scrubber */
.app-footer {
    height: var(--footer-height);
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 24px;
    z-index: 100;
}

.scrubber-container {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    max-width: 800px;
}

.scrubber-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.scrubber-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--border-hover);
}

.slider-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid #fff;
    box-shadow: 0 0 10px var(--primary-glow);
    cursor: pointer;
    transition: transform var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.25);
}

.page-jump {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.page-jump input {
    width: 54px;
    height: 34px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: #fff;
    text-align: center;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
}

.page-jump input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 8px var(--primary-glow);
}

/* Thumbnail Drawer */
.thumbnail-drawer {
    position: fixed;
    top: 0;
    right: -380px;
    width: 360px;
    height: 100%;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    z-index: 200;
    transition: right var(--transition-smooth);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.thumbnail-drawer.open {
    right: 0;
}

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

.drawer-header h3 {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 6px;
}

.close-btn:hover { color: #fff; }

.thumbnail-grid {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.thumb-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    border-radius: 8px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.03);
    border: 2px solid transparent;
    transition: all var(--transition-fast);
}

.thumb-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.thumb-item.active {
    border-color: var(--primary);
    box-shadow: 0 0 12px var(--primary-glow);
    background: rgba(99, 102, 241, 0.15);
}

.thumb-img {
    width: 100%;
    aspect-ratio: 1 / 1.4;
    object-fit: cover;
    border-radius: 4px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.thumb-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
}

.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 190;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-smooth);
}

.drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

/* High-Res Reader Zoom Modal */
.zoom-modal {
    position: fixed;
    inset: 0;
    background: rgba(11, 13, 20, 0.95);
    backdrop-filter: blur(16px);
    z-index: 300;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-smooth);
}

.zoom-modal.open {
    opacity: 1;
    pointer-events: auto;
}

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

.zoom-title {
    font-size: 1.1rem;
    font-weight: 600;
}

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

.zoom-viewport {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    position: relative;
    padding: 40px;
}

.zoom-viewport:active {
    cursor: grabbing;
}

.zoom-content {
    display: flex;
    gap: 10px;
    transition: transform 0.1s ease-out;
    transform-origin: center center;
    box-shadow: var(--shadow-lg);
}

.zoom-page-img {
    height: 85vh;
    width: auto;
    border-radius: 4px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    background: #fff;
}

.zoom-hint {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20, 23, 36, 0.85);
    padding: 8px 18px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    font-size: 0.82rem;
    color: var(--text-muted);
    pointer-events: none;
}

/* Mobile Responsiveness & Touch Optimization */
@media (max-width: 768px) {
    :root {
        --header-height: 56px;
        --footer-height: 62px;
    }

    .app-header {
        padding: 0 10px;
        gap: 6px;
    }

    .header-left {
        gap: 8px;
    }

    .book-badge {
        width: 32px;
        height: 32px;
        font-size: 0.95rem;
        border-radius: 8px;
    }

    .book-title {
        font-size: 1rem;
    }

    .book-subtitle {
        display: none;
    }

    .header-center {
        display: none;
    }

    .header-right {
        gap: 6px;
    }

    .icon-btn {
        width: 34px;
        height: 34px;
        font-size: 0.9rem;
        border-radius: 8px;
    }

    .btn {
        padding: 6px 10px;
        font-size: 0.8rem;
        gap: 4px;
    }

    .divider {
        display: none;
    }

    .workspace-stage {
        padding: 8px 4px;
    }

    /* Floating semi-transparent navigation arrows on mobile */
    .stage-nav {
        width: 38px;
        height: 38px;
        font-size: 0.95rem;
        background: rgba(15, 17, 26, 0.6);
        backdrop-filter: blur(6px);
        border: 1px solid rgba(255, 255, 255, 0.15);
    }

    .nav-prev { left: 6px; }
    .nav-next { right: 6px; }

    /* Footer Scrubber on Mobile */
    .app-footer {
        padding: 0 10px;
    }

    .scrubber-container {
        gap: 8px;
    }

    .scrubber-btn {
        width: 32px;
        height: 32px;
        font-size: 0.85rem;
    }

    .page-jump span:first-child {
        display: none;
    }

    .page-jump input {
        width: 44px;
        height: 30px;
        font-size: 0.85rem;
    }

    /* Thumbnail Drawer on Mobile */
    .thumbnail-drawer {
        width: 100vw;
        right: -100vw;
    }

    .thumbnail-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 14px;
    }

    /* High-Res Zoom Modal on Mobile */
    .zoom-header {
        padding: 0 12px;
        height: 52px;
    }

    .zoom-title {
        font-size: 0.9rem;
    }

    .zoom-viewport {
        padding: 10px;
    }

    .zoom-content {
        flex-direction: column;
        gap: 12px;
        align-items: center;
    }

    .zoom-page-img {
        width: 96vw;
        height: auto;
        max-height: 80vh;
        object-fit: contain;
    }

    .zoom-hint {
        font-size: 0.75rem;
        padding: 6px 14px;
        bottom: 10px;
        width: 90%;
        text-align: center;
    }
}

