/* ===================================================
   PREMIUM FLIPBOOK READER — 10 THEMES
   =================================================== */

/* ═══ DEFAULT THEME: dark_space ═══ */
:root {
    --reader-bg:      #0d1117;
    --toolbar-bg:     rgba(16, 20, 28, 0.85);
    --toolbar-border: rgba(255,255,255,0.08);
    --accent:         #f39c12;
    --accent-glow:    rgba(243,156,18,0.35);
    --text-main:      #e6edf3;
    --text-muted:     #7d8590;
    --btn-hover:      rgba(255,255,255,0.09);
    --btn-active:     rgba(243,156,18,0.18);
    --side-btn-bg:    rgba(16,20,28,0.7);
    --thumb-bg:       #1c2128;
    --page-bg:        #ffffff;
}

/* ═══ THEME 2: midnight_blue ═══ */
body.reader-theme-midnight_blue {
    --reader-bg:      #060d1a;
    --toolbar-bg:     rgba(8,16,32,0.88);
    --toolbar-border: rgba(56,189,248,0.12);
    --accent:         #38bdf8;
    --accent-glow:    rgba(56,189,248,0.35);
    --text-main:      #dde8f5;
    --text-muted:     #5a80a8;
    --btn-hover:      rgba(56,189,248,0.1);
    --btn-active:     rgba(56,189,248,0.18);
    --side-btn-bg:    rgba(8,16,32,0.75);
    --thumb-bg:       #0f1e30;
}

/* ═══ THEME 3: forest_dark ═══ */
body.reader-theme-forest_dark {
    --reader-bg:      #060e08;
    --toolbar-bg:     rgba(8,18,10,0.88);
    --toolbar-border: rgba(16,185,129,0.12);
    --accent:         #10b981;
    --accent-glow:    rgba(16,185,129,0.35);
    --text-main:      #d8f2e5;
    --text-muted:     #4a7a62;
    --btn-hover:      rgba(16,185,129,0.1);
    --btn-active:     rgba(16,185,129,0.18);
    --side-btn-bg:    rgba(8,18,10,0.75);
    --thumb-bg:       #0c1e10;
}

/* ═══ THEME 4: warm_amber ═══ */
body.reader-theme-warm_amber {
    --reader-bg:      #1a1005;
    --toolbar-bg:     rgba(28,18,6,0.88);
    --toolbar-border: rgba(245,158,11,0.15);
    --accent:         #f59e0b;
    --accent-glow:    rgba(245,158,11,0.38);
    --text-main:      #fef3c7;
    --text-muted:     #92724a;
    --btn-hover:      rgba(245,158,11,0.1);
    --btn-active:     rgba(245,158,11,0.2);
    --side-btn-bg:    rgba(28,18,6,0.75);
    --thumb-bg:       #241805;
}

/* ═══ THEME 5: light_paper ═══ */
body.reader-theme-light_paper {
    --reader-bg:      #f5f5f0;
    --toolbar-bg:     rgba(250,250,248,0.88);
    --toolbar-border: rgba(0,0,0,0.1);
    --accent:         #e67e22;
    --accent-glow:    rgba(230,126,34,0.3);
    --text-main:      #1a1a1a;
    --text-muted:     #888;
    --btn-hover:      rgba(0,0,0,0.07);
    --btn-active:     rgba(230,126,34,0.15);
    --side-btn-bg:    rgba(240,240,235,0.85);
    --thumb-bg:       #e8e8e3;
}

/* ═══ THEME 6: nordic_light ═══ */
body.reader-theme-nordic_light {
    --reader-bg:      #f8f9fc;
    --toolbar-bg:     rgba(255,255,255,0.85);
    --toolbar-border: rgba(0,0,0,0.08);
    --accent:         #4f46e5;
    --accent-glow:    rgba(79,70,229,0.28);
    --text-main:      #111827;
    --text-muted:     #6b7280;
    --btn-hover:      rgba(0,0,0,0.06);
    --btn-active:     rgba(79,70,229,0.12);
    --side-btn-bg:    rgba(245,246,250,0.9);
    --thumb-bg:       #eaecf2;
}

/* ═══ THEME 7: rose_dark ═══ */
body.reader-theme-rose_dark {
    --reader-bg:      #0f0407;
    --toolbar-bg:     rgba(18,5,10,0.88);
    --toolbar-border: rgba(244,63,94,0.15);
    --accent:         #f43f5e;
    --accent-glow:    rgba(244,63,94,0.38);
    --text-main:      #ffe4ec;
    --text-muted:     #8a4a58;
    --btn-hover:      rgba(244,63,94,0.1);
    --btn-active:     rgba(244,63,94,0.18);
    --side-btn-bg:    rgba(18,5,10,0.75);
    --thumb-bg:       #1e0810;
}

/* ═══ THEME 8: royal_purple ═══ */
body.reader-theme-royal_purple {
    --reader-bg:      #080012;
    --toolbar-bg:     rgba(12,2,20,0.9);
    --toolbar-border: rgba(168,85,247,0.18);
    --accent:         #a855f7;
    --accent-glow:    rgba(168,85,247,0.4);
    --text-main:      #f0e8ff;
    --text-muted:     #7055a0;
    --btn-hover:      rgba(168,85,247,0.1);
    --btn-active:     rgba(168,85,247,0.2);
    --side-btn-bg:    rgba(12,2,20,0.78);
    --thumb-bg:       #140820;
}

/* ═══ THEME 9: ocean_deep ═══ */
body.reader-theme-ocean_deep {
    --reader-bg:      #020c14;
    --toolbar-bg:     rgba(3,14,24,0.9);
    --toolbar-border: rgba(6,182,212,0.15);
    --accent:         #06b6d4;
    --accent-glow:    rgba(6,182,212,0.38);
    --text-main:      #d0f4ff;
    --text-muted:     #3a7a90;
    --btn-hover:      rgba(6,182,212,0.1);
    --btn-active:     rgba(6,182,212,0.2);
    --side-btn-bg:    rgba(3,14,24,0.78);
    --thumb-bg:       #071520;
}

/* ═══ THEME 10: sepia_classic ═══ */
body.reader-theme-sepia_classic {
    --reader-bg:      #f4ede4;
    --toolbar-bg:     rgba(244,237,228,0.9);
    --toolbar-border: rgba(120,80,40,0.15);
    --accent:         #8b5e3c;
    --accent-glow:    rgba(139,94,60,0.3);
    --text-main:      #3d2b1f;
    --text-muted:     #8a6a50;
    --btn-hover:      rgba(120,80,40,0.08);
    --btn-active:     rgba(139,94,60,0.15);
    --side-btn-bg:    rgba(234,224,210,0.9);
    --thumb-bg:       #e8dccf;
    --page-bg:        #fdf6ec;
}

/* ═══════════════════════════════════════════════
   BASE STYLES
═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body, html {
    width: 100%; height: 100%;
    overflow: hidden;
    background: var(--reader-bg);
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    color: var(--text-main);
    user-select: none;
    -webkit-user-select: none;
    transition: background 0.4s ease, color 0.4s ease;
}

#reader-wrapper {
    position: relative;
    width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
}

/* ═══════════════ TOP BAR ═══════════════ */
.reader-topbar {
    height: 54px;
    background: var(--toolbar-bg);
    backdrop-filter: blur(16px) saturate(160%);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    border-bottom: 1px solid var(--toolbar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    z-index: 50;
    flex-shrink: 0;
    transition: background 0.4s ease, border-color 0.4s ease;
}

.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 100px;
    background: var(--btn-hover);
    border: 1px solid var(--toolbar-border);
    white-space: nowrap;
    transition: all 0.25s ease;
}

.back-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 4px 14px var(--accent-glow);
}

.book-title-display {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 380px;
}

/* ═══════════════ BOOK STAGE ═══════════════ */
.book-stage {
    flex: 1;
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 20px;
    min-height: 0;
}

/* ═══ Zoom & Pan Container ═══ */
#zoom-pan-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
}

/* Grab cursor when zoomed in */
#zoom-pan-container.is-zoomed {
    cursor: grab;
}
#zoom-pan-container.is-panning {
    cursor: grabbing;
}

/* Inner wrapper */
#zoom-pan-inner {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#flipbook-viewport {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: center center;
    will-change: transform;
    flex-shrink: 0;
}

/* Zoom blocker overlay — sits above the flipbook and prevents
   StPageFlip from intercepting clicks/drag while panning */
#zoom-block-overlay {
    display: none;
    position: absolute;
    inset: -30px;
    z-index: 50;
    cursor: inherit;
}
#zoom-pan-container.is-zoomed #zoom-block-overlay {
    display: block;
}

.flipbook-container { display: block; }

/* Page */
.page { background-color: var(--page-bg, #fff); overflow: hidden; position: relative; }
.page .page-canvas { width: 100%; height: 100%; display: block; }
.page .page-webp-img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}
.page .page-loading {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: #f8f8f8;
    color: #999; font-size: 13px;
}

/* ═══ Book Cover Styling ═══ */
.page.page-cover {
    background: #151921;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 0 25px rgba(0,0,0,0.3);
}

.page-cover .cover-inner {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #11141a;
}

.page-cover .cover-img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}

/* Spine shadow on left edge of front cover */
.page-cover-front .cover-spine-effect {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 26px;
    background: linear-gradient(to right, 
        rgba(0,0,0,0.55) 0%, 
        rgba(0,0,0,0.22) 35%, 
        rgba(255,255,255,0.06) 70%, 
        rgba(0,0,0,0) 100%);
    pointer-events: none;
    z-index: 2;
}

/* Realistic Gloss & Lighting on Cover */
.page-cover .cover-gloss-effect {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, 
        rgba(255,255,255,0.14) 0%, 
        rgba(255,255,255,0.03) 40%, 
        rgba(0,0,0,0) 60%, 
        rgba(0,0,0,0.18) 100%);
    pointer-events: none;
    z-index: 3;
}

/* ═══ Inside Blank Page (Kapak Arkası Boş Sayfa) ═══ */
.page.page-inside-cover {
    background-color: var(--page-bg, #fcfcfb);
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.04);
}

.page-inside-cover .blank-page-inner {
    width: 100%;
    height: 100%;
    position: relative;
    background: radial-gradient(circle at 60% 50%, rgba(255,255,255,0.95), rgba(247,246,242,0.9));
}

/* Cilt katlanma gölgesi (Sağ kenar - omurgaya bakan taraf) */
.page-inside-cover .inside-spine-shadow {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 32px;
    background: linear-gradient(to left, 
        rgba(0,0,0,0.2) 0%, 
        rgba(0,0,0,0.06) 40%, 
        rgba(0,0,0,0) 100%);
    pointer-events: none;
}

/* Side nav buttons */
.side-nav-btn {
    position: absolute;
    top: 50%; transform: translateY(-50%);
    width: 48px; height: 68px;
    background: var(--side-btn-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--toolbar-border);
    color: var(--text-main);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    border-radius: 12px;
    z-index: 40;
    font-size: 18px;
    transition: all 0.22s ease;
}

.side-nav-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 6px 20px var(--accent-glow);
    width: 54px;
}

.side-nav-btn.prev { left: 14px; }
.side-nav-btn.next { right: 14px; }

/* ═══════════════ WATERMARK OVERLAY ═══════════════ */
.watermark-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
}

.watermark-overlay.pos-top-left    { align-items: flex-start;  justify-content: flex-start;  padding: 20px; }
.watermark-overlay.pos-top-right   { align-items: flex-start;  justify-content: flex-end;    padding: 20px; }
.watermark-overlay.pos-bottom-left { align-items: flex-end;    justify-content: flex-start;  padding: 20px; }
.watermark-overlay.pos-bottom-right{ align-items: flex-end;    justify-content: flex-end;    padding: 20px; }
.watermark-overlay.pos-center      { align-items: center;      justify-content: center; }

.watermark-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    pointer-events: none;
    user-select: none;
    transform-origin: center center;
    transition: transform 0.2s ease;
}

.watermark-inner img {
    max-width: 220px;
    max-height: 120px;
    object-fit: contain;
    display: block;
}

.watermark-text-el {
    font-family: 'Outfit', sans-serif, -apple-system;
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
    letter-spacing: 1px;
}

/* ═══════════════ BOTTOM TOOLBAR ═══════════════ */
.reader-bottombar {
    height: 58px;
    background: var(--toolbar-bg);
    backdrop-filter: blur(16px) saturate(160%);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    border-top: 1px solid var(--toolbar-border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 16px;
    z-index: 50;
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: none;
    transition: background 0.4s ease, border-color 0.4s ease;
}
.reader-bottombar::-webkit-scrollbar { display: none; }

.tool-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 40px; height: 40px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.tool-btn:hover {
    background: var(--btn-hover);
    color: var(--text-main);
}

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

.tool-separator {
    width: 1px; height: 22px;
    background: var(--toolbar-border);
    margin: 0 4px;
    flex-shrink: 0;
}

.page-counter {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0 6px;
    flex-shrink: 0;
}

.page-input {
    width: 48px; height: 32px;
    background: var(--btn-hover);
    border: 1px solid var(--toolbar-border);
    border-radius: 8px;
    color: var(--text-main);
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
}
.page-input:focus { outline: none; border-color: var(--accent); }

/* ═══════════════ THEME PICKER PANEL ═══════════════ */
.theme-picker-panel {
    position: absolute;
    bottom: 66px;
    right: 14px;
    background: var(--toolbar-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--toolbar-border);
    border-radius: 18px;
    padding: 16px;
    z-index: 100;
    display: none;
    min-width: 280px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    animation: slideUp 0.25s ease;
}

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

.theme-picker-panel.open { display: block; }

.theme-picker-panel h4 {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid var(--toolbar-border);
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--btn-hover);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    color: var(--text-main);
    text-align: left;
}

.theme-option:hover { border-color: var(--accent); background: var(--btn-active); }
.theme-option.active { border-color: var(--accent); background: var(--btn-active); }

.theme-dot {
    width: 14px; height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,0.15);
}

/* ═══════════════ THUMBNAILS DRAWER ═══════════════ */
.thumb-drawer {
    position: absolute;
    bottom: 58px; left: 0;
    width: 100%; height: 148px;
    background: rgba(10,12,18,0.95);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--toolbar-border);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 22px;
    overflow-x: auto;
    overflow-y: hidden;
    z-index: 60;
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
}

.thumb-drawer.open { transform: translateY(0); opacity: 1; pointer-events: auto; }

.thumb-item {
    flex: 0 0 auto;
    height: 118px; width: 84px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: all 0.2s ease;
    background: var(--thumb-bg);
}

.thumb-item:hover { transform: translateY(-4px); border-color: var(--accent); }
.thumb-item.active { border-color: var(--accent); box-shadow: 0 0 12px var(--accent-glow); }

.thumb-item canvas,
.thumb-item img { width: 100%; height: 100px; object-fit: cover; display: block; }

.thumb-item .thumb-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 2px 0;
}

/* ═══════════════ LOADING OVERLAY ═══════════════ */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: var(--reader-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    z-index: 100;
    transition: opacity 0.5s ease;
}

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

.loading-text { font-size: 14px; color: var(--text-muted); }

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

/* ═══════════════ RESPONSIVE ═══════════════ */
@media (max-width: 768px) {
    .reader-topbar { height: 48px; padding: 0 12px; }
    .back-btn { padding: 6px 10px; font-size: 12px; }
    .book-title-display { max-width: 160px; font-size: 12px; }
    .book-stage { padding: 6px 4px; }
    .side-nav-btn { width: 30px; height: 50px; font-size: 14px; opacity: 0.8; }
    .side-nav-btn.prev { left: 4px; }
    .side-nav-btn.next { right: 4px; }
    .reader-bottombar { height: 52px; padding: 0 6px; gap: 2px; }
    .tool-btn { width: 36px; height: 36px; font-size: 14px; }
    #btn-zoom-reset, #btn-autoplay { display: none; }
    .theme-picker-panel { right: 6px; min-width: 240px; }
    .theme-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .book-title-display { max-width: 110px; font-size: 11px; }
    .tool-btn { width: 32px; height: 32px; font-size: 13px; }
    #btn-mute { display: none; }
    .tool-separator { margin: 0 2px; }
}
