/* Flipbook Modal Overlay */
.flipbook-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    display: none;
    /* Hidden by default */
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.flipbook-overlay.active {
    display: flex;
    opacity: 1;
}

/* Header Controls (Download + Close) */
.flipbook-header {
    position: absolute;
    top: 30px;
    right: 40px;
    /* Align to right */
    left: auto;
    /* Unset left */
    width: auto;
    /* Auto width */
    padding: 0;
    display: flex;
    justify-content: flex-end;
    /* Align items to right */
    align-items: center;
    gap: 15px;
    /* Space between buttons */
    pointer-events: none;
    z-index: 1001;
}

.flip-download-btn,
.flipbook-close {
    pointer-events: auto;
    cursor: pointer;
    color: white;
    transition: all 0.3s ease;
}

/* Download Button Style */
.flip-download-btn {
    text-decoration: none;
    font-family: inherit;
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 20px;
    border-radius: 30px;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    gap: 8px;
}

.flip-download-btn:hover {
    background: white;
    color: black;
}

/* Close Button Update */
.flipbook-close {
    position: relative;
    /* Reset absolute since it's in flex header now */
    top: auto;
    right: auto;
    font-size: 2rem;
    background: none;
    border: none;
}

.flipbook-close:hover {
    transform: rotate(90deg);
    color: var(--accent-color);
}

/* 3D Book Container */
.book-stage {
    perspective: 1500px;
    width: 90%;
    max-width: 1000px;
    /* Max spread width */
    height: 80vh;
    /* Responsive height */
    position: relative;
    display: flex;
    justify-content: center;
}

.book-wrapper {
    position: relative;
    width: 400px;
    /* Half width (single page width) */
    height: 100%;
    transform-style: preserve-3d;
}

/* Pages */
.book-page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Maintain PDF aspect ratio via JS ideally, or fit to container */
    background: white;
    transform-origin: left center;
    /* Flip axis */
    transform-style: preserve-3d;
    transition: transform 1s cubic-bezier(0.645, 0.045, 0.355, 1);
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.1), 0 5px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    /* Center content */
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    /* Hide back when flipped */
    border-radius: 4px 0 0 4px;
    /* Left round */
    overflow: hidden;
    cursor: pointer;
}

/* Z-Index Logic for Stacking */
/* Pages stack: 1 on top, 2 under... */
/* When flipped: 1 goes left (-180deg). 2 revealed. */

/* Front vs Back faces logic is tricky without 'backface-visibility: visible' on generic pages.
   Simplified approach: All pages are "Right side" pages initially.
   When flipped, they rotate -180deg to become "Left side".
*/

.book-page.flipped {
    transform: rotateY(-180deg);
}

/* Canvas styling */
.book-page canvas {
    width: 100%;
    height: auto;
    max-height: 100%;
    object-fit: contain;
}

/* Navigation Controls (Floating Arrows) */
.flip-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    z-index: 1002;
}

.flip-btn {
    background: white;
    color: black;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease, background 0.2s;
}

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

.flip-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    background: #ccc;
}

/* Initial "Book Cover" Look */
/* To make it look like a closed book initially:
   All pages stacked.
   Open animation: Page 1 rotates.
*/

/* Mobile Responsive */
@media (max-width: 768px) {
    .book-wrapper {
        width: 90vw;
    }

    .book-page {
        transform-origin: center;
        /* On mobile maybe slide instead of flip? Or allow flip */
    }

    .book-page.flipped {
        /* On mobile, standard flip might go off screen if origin is left. 
           Let's change to a stack swap or ensure width fits.
        */
        transform: rotateY(-180deg);
    }
}