/* css/style.css */

:root {
    --bg-color: #1c1b1a;
    --text-color: #f0f4f8;
    --glass-bg: rgba(14, 13, 13, 0.75);
    --glass-border: rgba(255, 255, 255, 0.08);
    --primary-color: #4f8ef7;
    --primary-glow: rgba(79, 142, 247, 0.25);
    --hover-color: #74a8ff;
    --transition-speed: 0.28s;
    --shadow-book: 0 30px 80px rgba(0, 0, 0, 0.7), 0 8px 30px rgba(0, 0, 0, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    /* Deep charcoal background with subtle warm radial spotlight — matches premium
       flipbook reader aesthetic (FlipHTML5-style). Not blue-tinted. */
    background-color: var(--bg-color);
    background-image:
        /* Soft warm glow centred behind the book */
        radial-gradient(ellipse 55% 48% at 50% 52%, rgba(78, 68, 56, 0.55) 0%, rgba(48, 42, 35, 0.2) 55%, transparent 75%),
        /* Base charcoal gradient: lighter center, deep vignette at edges */
        radial-gradient(ellipse 110% 100% at 50% 50%, #2c2926 0%, #1c1917 38%, #111010 65%, #090808 100%);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ─── Loading Overlay ──────────────────────────────────────────────────────── */

.loader-overlay {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 55% 48% at 50% 52%, rgba(78, 68, 56, 0.45) 0%, transparent 75%),
        linear-gradient(160deg, #201e1c 0%, #131211 50%, #090808 100%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    /* Fade handled via opacity; display toggled by JS */
    transition: opacity 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Wrapper keeps loader centred and avoids layout shifts */
.loader-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    animation: loader-fade-in 0.5s ease both;
}

@keyframes loader-fade-in {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Animated Book Icon ─────────────────────────────────────────────────── */

.loader-book {
    position: relative;
    width: 64px;
    height: 52px;
    margin-bottom: 28px;
}

.loader-page {
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 30px;
    height: 44px;
    border-radius: 2px 6px 6px 2px;
    transform-origin: left center;
    background: linear-gradient(135deg, #c8d8f8 0%, #e8eeff 60%, #f8faff 100%);
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.4);
}

.loader-page-1 {
    transform: translateX(-100%) rotateY(0deg);
    animation: flip-page1 2.4s ease-in-out infinite;
    z-index: 3;
    border-radius: 6px 2px 2px 6px;
    background: linear-gradient(135deg, #dce8ff 0%, #b8ccf8 100%);
    transform-origin: right center;
}

.loader-page-2 {
    transform: translateX(-50%);
    z-index: 2;
    animation: flip-page2 2.4s ease-in-out infinite;
    background: linear-gradient(135deg, #c0d4f5 0%, #ddeaff 100%);
}

.loader-page-3 {
    transform: translateX(-50%) translateX(2px);
    z-index: 1;
    opacity: 0.55;
    background: linear-gradient(135deg, #a8bfe8 0%, #c8d8f8 100%);
}

@keyframes flip-page1 {
    0% {
        transform: translateX(-100%) rotateY(0deg);
        opacity: 1;
    }

    40% {
        transform: translateX(-100%) rotateY(-60deg);
        opacity: 1;
    }

    55% {
        transform: translateX(-100%) rotateY(-120deg);
        opacity: 0.7;
    }

    70% {
        transform: translateX(-100%) rotateY(-180deg);
        opacity: 0;
    }

    71% {
        transform: translateX(-100%) rotateY(0deg);
        opacity: 0;
    }

    85% {
        opacity: 1;
    }

    100% {
        transform: translateX(-100%) rotateY(0deg);
        opacity: 1;
    }
}

@keyframes flip-page2 {
    0% {
        transform: translateX(-50%) scaleX(1);
    }

    40% {
        transform: translateX(-50%) scaleX(0.92);
    }

    70% {
        transform: translateX(-50%) scaleX(1);
    }

    100% {
        transform: translateX(-50%) scaleX(1);
    }
}

/* ─── Loader Text & Progress ─────────────────────────────────────────────── */

.loader-text {
    font-size: 13px;
    font-weight: 400;
    letter-spacing: 0.06em;
    color: rgba(200, 218, 255, 0.65);
    text-transform: uppercase;
    margin-bottom: 18px;
    min-width: 180px;
    text-align: center;
}

.loader-bar-track {
    width: 180px;
    height: 2px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    overflow: hidden;
}

.loader-bar-fill {
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, transparent 0%, var(--primary-color) 50%, var(--hover-color) 100%);
    border-radius: 2px;
    animation: loader-shimmer 1.8s ease-in-out infinite;
}

@keyframes loader-shimmer {
    0% {
        transform: translateX(-200%);
    }

    60% {
        transform: translateX(250%);
    }

    100% {
        transform: translateX(250%);
    }
}

/* ─── Main Container and Zoom Wrapper ───────────────────────────────────── */

.main-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.zoom-wrapper {
    /* No transition by default — pan must follow pointer 1:1 with zero lag.
       The .zoom-animating class is added only for button/dblclick zooms. */
    transform-origin: center center;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    /* Pre-promote to GPU compositor layer so the first zoom has no pop. */
    will-change: transform;
}

.zoom-wrapper.zoom-animating {
    transition: transform 0.22s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ─── Flipbook ────────────────────────────────────────────────────────────── */

.flipbook {
    /* Layered shadow: deep ambient + close-range definition */
    box-shadow:
        0 40px 100px rgba(0, 0, 0, 0.75),
        0 16px 40px rgba(0, 0, 0, 0.55),
        0 4px 12px rgba(0, 0, 0, 0.4);
    border-radius: 3px;
    /* Keeps the StPageFlip canvas on the GPU during continuous page-turn transforms. */
    will-change: transform;
    /* Short transition so cover-mode add/remove is smooth */
    transition: clip-path 0.15s ease-in-out, transform 0.15s ease-in-out,
                filter 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

/* ─── Cover-only display mode ────────────────────────────────────────────── */
/* StPageFlip (landscape mode, showCover:true) positions the cover page on the
   RIGHT half of a double-wide container, leaving the left half empty/dark.
   This class:
     1. Clips the left (empty) half away with clip-path.
     2. Shifts the container left by 25% (= half a page width) so the cover
        is centred in the viewport instead of sitting to the right of centre.
     3. Replaces box-shadow (which clips with clip-path) with filter:drop-shadow
        which renders AFTER clip-path and follows only the visible content.
   The class is added on init and removed the moment a flip animation begins,
   so the animation always runs on the full unconstrained container. */
.flipbook.cover-mode {
    clip-path: inset(0 0 0 50%);   /* show only right half — the cover page   */
    transform: translateX(-25%);   /* shift left 25% of 2W = W/2, centring it  */
    box-shadow: none;              /* box-shadow would be clipped; use filter  */
    filter: drop-shadow(0 22px 55px rgba(0, 0, 0, 0.75))
            drop-shadow(0 6px 18px rgba(0, 0, 0, 0.55));
}

.page {
    background-color: #fff;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.page canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ─── Glassmorphism Controls ─────────────────────────────────────────────── */

.ui-controls {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--glass-border);
    padding: 9px 18px;
    border-radius: 32px;
    display: flex;
    gap: 4px;
    z-index: 100;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 1px 0 rgba(255, 255, 255, 0.04) inset;
}

.ui-controls button {
    background: transparent;
    border: none;
    color: rgba(220, 232, 255, 0.75);
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background var(--transition-speed), color var(--transition-speed), transform 0.15s ease;
}

.ui-controls button:hover {
    background: rgba(79, 142, 247, 0.14);
    color: var(--hover-color);
    transform: scale(1.08);
}

.ui-controls button:active {
    transform: scale(0.95);
}

.ui-controls button svg {
    width: 19px;
    height: 19px;
}

/* ─── Side Navigation Buttons ────────────────────────────────────────────── */

.nav-btn {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: var(--glass-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--glass-border);
    color: rgba(220, 232, 255, 0.7);
    width: 46px;
    height: 46px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: background var(--transition-speed), color var(--transition-speed),
        transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow var(--transition-speed);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

.nav-btn:hover {
    background: rgba(79, 142, 247, 0.16);
    color: var(--hover-color);
    transform: translateY(-50%) scale(1.12);
    box-shadow: 0 6px 24px rgba(79, 142, 247, 0.2), 0 4px 18px rgba(0, 0, 0, 0.35);
}

.nav-btn:active {
    transform: translateY(-50%) scale(0.96);
}

.left-nav {
    left: 20px;
}

.right-nav {
    right: 20px;
}

.nav-btn svg {
    width: 22px;
    height: 22px;
}

/* ─── Page Counter ─────────────────────────────────────────────────────── */

.page-counter {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--glass-border);
    padding: 7px 15px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.03em;
    color: rgba(200, 218, 255, 0.75);
    z-index: 100;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
}

/* ─── Thumbnail Sidebar ──────────────────────────────────────────────────── */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    height: 100vh;
    background: var(--glass-bg);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-right: 1px solid var(--glass-border);
    z-index: 200;
    /* Use transform instead of left so the slide runs on the compositor thread
       with no layout recalculation on every animation frame. */
    transform: translateX(-100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 32px rgba(0, 0, 0, 0.5);
}

.sidebar.visible {
    transform: translateX(0);
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    font-weight: 500;
    font-size: 14px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(200, 218, 255, 0.65);
}

#btn-close-thumbnails {
    background: transparent;
    border: none;
    color: rgba(200, 218, 255, 0.6);
    font-size: 22px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-speed), color var(--transition-speed);
    line-height: 1;
}

#btn-close-thumbnails:hover {
    background: rgba(79, 142, 247, 0.14);
    color: var(--hover-color);
}

.thumbnails-container {
    padding: 20px;
    overflow-y: auto;
    flex-grow: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.thumbnails-container::-webkit-scrollbar {
    width: 5px;
}

.thumbnails-container::-webkit-scrollbar-track {
    background: transparent;
}

.thumbnails-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
}

.thumbnails-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

.thumbnail-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    /* transition:all forces the browser to check every property on each frame.
       Only transition the properties that actually animate. */
    transition: opacity var(--transition-speed);
}

.thumbnail-preview {
    width: 100%;
    aspect-ratio: 1 / 1.414;
    /* A4 aspect ratio fallback */
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.2);
    overflow: hidden;
    /* Scope to only the properties that visibly animate; avoids layout checks
       on every frame when the sidebar is open and items are scrolling. */
    transition: transform var(--transition-speed) cubic-bezier(0.25, 0.46, 0.45, 0.94),
        box-shadow var(--transition-speed),
        border-color var(--transition-speed);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    /* Keep on GPU so the translateY hover lift is compositor-only. */
    will-change: transform;
}

.thumbnail-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail-label {
    margin-top: 7px;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.04em;
    color: rgba(200, 218, 255, 0.45);
    transition: color var(--transition-speed);
}

.thumbnail-item:hover .thumbnail-preview,
.thumbnail-item.active .thumbnail-preview {
    border-color: var(--primary-color);
    transform: translateY(-3px);
    box-shadow: 0 8px 22px rgba(79, 142, 247, 0.28);
}

.thumbnail-item:hover .thumbnail-label,
.thumbnail-item.active .thumbnail-label {
    color: var(--primary-color);
}

/* ─── Corner Preview Hints ───────────────────────────────────────────────── */

.corner-preview {
    position: absolute;
    width: 38px;
    height: 38px;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.18s ease-in-out, transform 0.18s ease-in-out;
}

.corner-preview.top.left {
    top: 0;
    left: 0;
    border-top: 2.5px solid var(--primary-color);
    border-left: 2.5px solid var(--primary-color);
    border-radius: 4px 0 0 0;
}

.corner-preview.top.right {
    top: 0;
    right: 0;
    border-top: 2.5px solid var(--primary-color);
    border-right: 2.5px solid var(--primary-color);
    border-radius: 0 4px 0 0;
}

.corner-preview.bottom.left {
    bottom: 0;
    left: 0;
    border-bottom: 2.5px solid var(--primary-color);
    border-left: 2.5px solid var(--primary-color);
    border-radius: 0 0 0 4px;
}

.corner-preview.bottom.right {
    bottom: 0;
    right: 0;
    border-bottom: 2.5px solid var(--primary-color);
    border-right: 2.5px solid var(--primary-color);
    border-radius: 0 0 4px 0;
}

.has-corner-preview.hover-top-left .corner-preview.top.left,
.has-corner-preview.hover-top-right .corner-preview.top.right,
.has-corner-preview.hover-bottom-left .corner-preview.bottom.left,
.has-corner-preview.hover-bottom-right .corner-preview.bottom.right {
    opacity: 1;
    transform: scale(1.1);
    box-shadow: 0 0 12px var(--primary-glow);
    background: radial-gradient(circle at center, rgba(79, 142, 247, 0.18) 0%, transparent 70%);
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .nav-btn {
        width: 38px;
        height: 38px;
    }

    .left-nav {
        left: 10px;
    }

    .right-nav {
        right: 10px;
    }
}