/**
 * Book Reader - Fullscreen PDF Viewer with Page Flip
 */

/* Click hint on hero book */
#hero-book .book-click-hint {
    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85rem;
    font-weight: 600;
    color: #a855f7 !important;
    background: rgba(0, 0, 0, 0.85) !important;
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid rgba(168, 85, 247, 0.3);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 100;
}

#hero-book {
    cursor: pointer;
    transition: transform 0.3s ease;
}

#hero-book:hover {
    transform: scale(1.02);
}

#hero-book:hover .book-click-hint {
    opacity: 1;
}

/* Reader Overlay */
.book-reader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

.book-reader.active {
    opacity: 1;
    visibility: visible;
}

.book-reader-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 20, 0.98);
    backdrop-filter: blur(20px);
}

/* Container */
.book-reader-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 1400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1;
    transform: scale(0.9);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.book-reader.active .book-reader-container {
    transform: scale(1);
}

/* Close button */
.book-reader-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    font-size: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10;
}

.book-reader-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* Page counter */
.book-reader-counter {
    position: absolute;
    top: 25px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'DM Sans', sans-serif;
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 20px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Book spread */
.book-reader-spread {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: calc(100% - 120px);
    gap: 0;
}

/* Navigation zones */
.book-reader-nav {
    flex: 0 0 60px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

.book-reader-nav:hover {
    opacity: 1;
}

.nav-arrow {
    font-size: 2rem;
    color: white;
    transition: transform 0.3s ease;
}

.nav-prev:hover .nav-arrow {
    transform: translateX(-5px);
}

.nav-next:hover .nav-arrow {
    transform: translateX(5px);
}

/* Pages container */
.book-reader-pages {
    position: relative;
    display: flex;
    height: 100%;
    max-height: 85vh;
    perspective: 2000px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 8px;
    box-shadow:
        0 25px 80px rgba(0, 0, 0, 0.5),
        0 0 100px rgba(138, 43, 226, 0.15);
    overflow: hidden;
}

/* Individual pages */
.book-page {
    width: 400px;
    height: 100%;
    background: #faf8f5;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.book-page canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.page-left {
    border-right: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: inset -10px 0 30px rgba(0, 0, 0, 0.1);
}

.page-right {
    box-shadow: inset 10px 0 30px rgba(0, 0, 0, 0.1);
}

/* Center spine */
.book-spine-center {
    width: 4px;
    height: 100%;
    background: linear-gradient(to right,
        rgba(0, 0, 0, 0.3),
        rgba(0, 0, 0, 0.1),
        rgba(0, 0, 0, 0.3)
    );
}

/* Page flip animation */
.page-flip {
    position: absolute;
    right: 50%;
    top: 0;
    width: 400px;
    height: 100%;
    transform-origin: left center;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.645, 0.045, 0.355, 1);
    pointer-events: none;
    opacity: 0;
    z-index: 10;
}

.page-flip.flipping {
    opacity: 1;
}

.page-flip.flip-forward {
    transform: rotateY(-180deg);
}

.page-flip.flip-backward {
    transform: rotateY(0deg);
}

.page-flip-front,
.page-flip-back {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    background: #faf8f5;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.page-flip-front {
    box-shadow:
        -5px 0 20px rgba(0, 0, 0, 0.2),
        0 0 10px rgba(0, 0, 0, 0.1);
}

.page-flip-back {
    transform: rotateY(180deg);
    box-shadow:
        5px 0 20px rgba(0, 0, 0, 0.2),
        0 0 10px rgba(0, 0, 0, 0.1);
}

.page-flip-front canvas,
.page-flip-back canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Controls */
.book-reader-controls {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.reader-btn {
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.reader-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.reader-btn:active {
    transform: translateY(0);
}

#btn-download {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: transparent;
}

#btn-download:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

/* Loading state */
.book-page.loading::after {
    content: '';
    position: absolute;
    width: 40px;
    height: 40px;
    border: 3px solid rgba(102, 126, 234, 0.2);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Single page mode for first/last */
.book-reader-pages.single-page .page-left {
    display: none;
}

.book-reader-pages.single-page .book-spine-center {
    display: none;
}

.book-reader-pages.single-page .page-right {
    border-radius: 8px;
}

/* Responsive - Tablet */
@media (max-width: 1100px) {
    .book-page {
        width: 320px;
    }

    .page-flip {
        width: 320px;
    }
}

/* Single page mode for tablet and below */
@media (max-width: 900px) {
    .book-reader-container {
        padding: 10px;
        justify-content: flex-start;
        padding-top: 60px;
    }

    .book-reader-spread {
        height: calc(100vh - 140px);
        flex: 1;
    }

    .book-reader-pages {
        background: transparent;
        box-shadow: none;
        height: 100%;
        max-height: none;
    }

    .page-left,
    .book-spine-center {
        display: none !important;
    }

    .book-page {
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 8px;
        box-shadow:
            0 20px 60px rgba(0, 0, 0, 0.4),
            0 0 80px rgba(138, 43, 226, 0.1);
    }

    .book-page canvas {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    .page-right {
        box-shadow:
            0 20px 60px rgba(0, 0, 0, 0.4),
            -5px 0 20px rgba(0, 0, 0, 0.1) inset;
    }

    .page-flip {
        width: 100%;
        max-width: none;
        height: 100%;
        right: 0;
        left: 0;
        transform: none;
        transform-origin: center center;
    }

    .page-flip.flip-forward {
        transform: rotateY(-180deg);
    }

    .page-flip.flip-backward {
        transform: rotateY(0deg);
    }

    .book-reader-nav {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        height: auto;
        padding: 20px;
        z-index: 20;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 50%;
    }

    .nav-prev {
        left: 10px;
    }

    .nav-next {
        right: 10px;
    }

    .nav-arrow {
        font-size: 1.5rem;
    }

    .book-reader-controls {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }

    .reader-btn {
        padding: 10px 16px;
        font-size: 0.85rem;
    }

    .book-reader-counter {
        font-size: 0.9rem;
        padding: 6px 16px;
    }
}

/* Mobile */
@media (max-width: 500px) {
    .book-reader-container {
        padding: 5px;
        padding-top: 50px;
    }

    .book-reader-spread {
        height: calc(100vh - 120px);
    }

    .book-reader-nav {
        padding: 12px;
        background: rgba(0, 0, 0, 0.3);
    }

    .nav-prev {
        left: 5px;
    }

    .nav-next {
        right: 5px;
    }

    .nav-arrow {
        font-size: 1.2rem;
    }

    .reader-btn {
        padding: 8px 12px;
        font-size: 0.75rem;
    }

    #btn-first,
    #btn-last {
        display: none;
    }

    .book-reader-close {
        width: 36px;
        height: 36px;
        font-size: 22px;
        top: 8px;
        right: 8px;
    }

    .book-reader-counter {
        top: 12px;
        font-size: 0.8rem;
        padding: 5px 12px;
    }

    .book-reader-controls {
        margin-top: 10px;
    }
}

/* Touch feedback */
@media (hover: none) {
    .book-reader-nav {
        opacity: 0.5;
    }

    .book-reader-nav:active {
        opacity: 1;
    }
}

/* Keyboard focus styles */
.reader-btn:focus-visible,
.book-reader-close:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* True fullscreen mode - maximize reading area */
.book-reader.is-fullscreen .book-reader-container {
    padding: 5px;
    padding-top: 40px;
}

.book-reader.is-fullscreen .book-reader-spread {
    height: calc(100vh - 90px);
}

.book-reader.is-fullscreen .book-reader-counter {
    top: 8px;
    font-size: 0.75rem;
    padding: 4px 10px;
    opacity: 0.7;
}

.book-reader.is-fullscreen .book-reader-close {
    top: 5px;
    right: 5px;
    width: 32px;
    height: 32px;
    font-size: 18px;
    opacity: 0.7;
}

.book-reader.is-fullscreen .book-reader-close:hover {
    opacity: 1;
}

.book-reader.is-fullscreen .book-reader-controls {
    margin-top: 5px;
    opacity: 0.8;
}

.book-reader.is-fullscreen .reader-btn {
    padding: 6px 10px;
    font-size: 0.7rem;
}

.book-reader.is-fullscreen .book-reader-nav {
    opacity: 0.3;
}

.book-reader.is-fullscreen .book-reader-nav:hover {
    opacity: 0.8;
}

/* Fullscreen button styling */
#btn-fullscreen {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    border-color: transparent;
}

#btn-fullscreen:hover {
    background: linear-gradient(135deg, #38ef7d 0%, #11998e 100%);
}

/* Page number indicator on pages */
.book-page::before {
    content: attr(data-page);
    position: absolute;
    bottom: 15px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.75rem;
    color: rgba(0, 0, 0, 0.3);
}

.page-left::before {
    left: 15px;
}

.page-right::before {
    right: 15px;
}
