/* Overlay - Flexbox Centering */
#apv-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #515558;
    /* Fullscreen Grey */
    z-index: 100000;
    display: none;
    /* Hidden by default */
    /* Flexbox centering */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    /* Prevent scrollbars */
    perspective: 2500px;
    /* Enable 3D space */
}

#apv-overlay.apv-active {
    display: flex;
    /* Show only when active */
}

/* Dark Mode */
#apv-overlay.apv-dark-mode {
    background: #2b2e31;
    /* Even darker for dark mode if needed, or keep same */
}

/* Close Button */
#apv-close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 30px;
    cursor: pointer;
    z-index: 200000;
}

/* Loader */
/* Loader */
#apv-loader {
    color: #fff;
    font-size: 20px;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

#apv-loader::before {
    content: "";
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #fff;
    border-radius: 50%;
    animation: apv-spin 1s linear infinite;
}

@keyframes apv-spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Flipbook Container */
/* Flipbook Container */
#apv-flipbook {
    /* Shadow moved to ::before for dynamic sizing */
    background: transparent;
    /* Transparent so pages float */
    /* Fallback */
    /* Dimensions are set via JS, but max-width/height ensure containment */
    max-width: 98vw;
    max-height: 95vh;
    overflow: visible;
    /* Visible for 3D effect */
    transform: rotateX(15deg) translateY(-20px);
    /* Slight backward tilt */
    transform-style: preserve-3d;
    position: relative;
    /* Identify context for pseudo-el */
}

/* Dynamic Shadow via Pseudo-element */
#apv-flipbook::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    box-shadow: 0 30px 40px -20px rgba(0, 0, 0, 0.7);
    transition: all 0.3s ease;
    /* Smooth transition for size changes */
}

/* Shadow States */
/* Cover (First Page) - Assuming Right aligned in LTR or Centered? 
   Ref: stpageflip usually centers single pages in 'stretch' or 'user' mode unless specifically 'dble' 
   But typically for a book:
   - Cover is single page on right (if startPage=0) or centered?
   - The user screenshot showed it centered in 2-page space, but shadow was wide.
   
   If the container is fixed width (spread width), and cover is single page:
   Cover is usually half-width of container.
*/

/* 
   Logic: 
   If Cover (Page 0): content is usually on the Right side of the spread in 2-page view.
   However, if showCover:true is set in stpageflip, it treats cover specially.
   
   Common StPageFlip behavior with showCover: true:
   - Landscape: Container is full width.
     - Cover: Rendered on right half? Or centered?
     - Typically: It occupies the right half of the container area if we want realistic book.
   - BUT the user screenshot looks like the page is in the middle of a wide gray area.
   
   Let's assume standard behavior:
   - Container = Spread Width.
   - Cover = Single Page Width (Half of Container).
   - Position: Usually Right-Aligned for LTR books.
*/

/* Class: .apv-view-cover (First page) */
#apv-flipbook.apv-view-cover::before {
    width: 50%;
    left: 25%;
    /* Centered in container (25% gap | 50% page | 25% gap) */
}

/* Mobile / Portrait Mode */
#apv-flipbook.apv-view-portrait::before {
    width: 100%;
    left: 0;
}

/* End Page (if single on left) */
#apv-flipbook.apv-view-end::before {
    width: 50%;
    left: 0;
}

/* Page - Canvas Containment */
.apv-page {
    background-color: white;
    overflow: hidden;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.apv-page canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    /* Ensure canvas doesn't overflow page div */
    display: block;
}

/* Toolbar */
#apv-toolbar {
    position: absolute;
    /* Pinned to bottom, or relative if we want flow */
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(51, 51, 51, 0.9);
    padding: 10px 20px;
    border-radius: 0;
    /* No rounded corners */
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 200000;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

#apv-toolbar button {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

#apv-toolbar button:hover {
    background: rgba(255, 255, 255, 0.2);
}

#apv-toolbar span {
    color: #fff;
    font-weight: bold;
    min-width: 60px;
    text-align: center;
}

/* Side Navigation Arrows */
.apv-arrow-nav {
    position: fixed;
    /* Fixed relative to viewport to ensure clickable */
    top: 50%;
    transform: translateY(-50%);
    background: transparent !important;
    /* Force no background */
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 80px;
    cursor: pointer;
    z-index: 2147483647 !important;
    /* Above everything (Max Int) */
    padding: 20px;
    border-radius: 0 !important;
    /* No circle */
    width: auto;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    user-select: none;
    outline: none;
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    /* Ensure clickable */
}

.apv-arrow-nav:hover {
    color: #fff;
    background: transparent !important;
    transform: translateY(-50%) scale(1.1);
}

#apv-arrow-prev {
    left: 20px;
}

#apv-arrow-next {
    right: 20px;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .apv-arrow-nav {
        display: none;
        /* Hide large arrows on mobile, use toolbar */
    }

    #apv-toolbar {
        width: 90%;
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Hide Fullscreen on Mobile */
    #apv-fullscreen {
        display: none;
    }
}