/* ========== FLIPBOOK VIEWER STYLES ========== */
:root {
    --bg-color: #050505;
    --accent: #d4af37;
    --speed: 0.6s;
    --page-bg: #ffffff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    background: var(--bg-color);
    height: 100vh;
    width: 100vw;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-family: system-ui, -apple-system, sans-serif;
}

.book-viewport {
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 3000px;
    padding: 20px;
    box-sizing: border-box;
}

.book {
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.25, 1, 0.5, 1);
    visibility: hidden;
}

.book.page-1-active {
    transform: translateX(-25%);
}

.book.spread-active {
    transform: translateX(0);
}

.book.last-page-active {
    transform: translateX(25%);
}

.leaf {
    position: absolute;
    top: 0;
    left: 50%;
    width: 50%;
    height: 100%;
    transform-style: preserve-3d;
    transform-origin: left center;
    transition: transform var(--speed) cubic-bezier(0.645, 0.045, 0.355, 1);
    z-index: 1;
}

.leaf.flipped {
    transform: rotateY(-180deg);
}

.page-front,
.page-back {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    background: var(--page-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 40px rgba(0,0,0,0.05), 0 0 20px rgba(0,0,0,0.3);
    overflow: hidden;
    cursor: pointer;
}

.page-front {
    border-radius: 0 5px 5px 0;
    border-left: 1px solid rgba(0,0,0,0.1);
}

.page-back {
    transform: rotateY(180deg);
    border-radius: 5px 0 0 5px;
    border-right: 1px solid rgba(0,0,0,0.1);
}

canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
    image-rendering: -webkit-optimize-contrast;
}

/* Navigation Buttons */
.nav-btn {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 60px;
    height: 100px;
    background: rgba(255,255,255,0.08);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 999;
    transition: 0.2s;
    font-size: 40px;
    user-select: none;
    backdrop-filter: blur(10px);
}

.nav-btn:hover {
    background: var(--accent);
    color: #000;
}

.nav-btn.left {
    left: 0;
    border-radius: 0 12px 12px 0;
}

.nav-btn.right {
    right: 0;
    border-radius: 12px 0 0 12px;
}

.nav-btn.disabled {
    opacity: 0;
    pointer-events: none;
}

/* Loader */
.loader {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #333;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s infinite linear;
}

.loading-text {
    color: var(--accent);
    margin-top: 15px;
    font-size: 18px;
    letter-spacing: 1px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

@keyframes spin {
    100% { transform: rotate(360deg); }
}

/* Empty pages styling */
.page-front:empty,
.page-back:empty {
    background: transparent;
    box-shadow: none;
    cursor: default;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .nav-btn {
        width: 40px;
        height: 80px;
        font-size: 30px;
    }
    
    .book-viewport {
        padding: 10px;
    }
    
    .loading-text {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .nav-btn {
        width: 35px;
        height: 70px;
        font-size: 25px;
    }
    
    .nav-btn.left {
        border-radius: 0 8px 8px 0;
    }
    
    .nav-btn.right {
        border-radius: 8px 0 0 8px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .nav-btn {
        background: rgba(0,0,0,0.5);
        backdrop-filter: blur(5px);
    }
    
    .nav-btn:hover {
        background: rgba(255,255,255,0.08);
        color: #fff;
    }
}

/* Print styles */
@media print {
    body, html {
        background: white;
        overflow: visible;
        display: block;
    }
    
    .nav-btn, .loader {
        display: none !important;
    }
    
    .book-viewport {
        padding: 0;
        perspective: none;
    }
    
    .book {
        visibility: visible !important;
        transform: none !important;
        width: 100% !important;
        height: auto !important;
    }
    
    .leaf {
        position: relative;
        left: 0;
        width: 100%;
        transform: none !important;
        page-break-after: always;
    }
    
    .page-front, .page-back {
        position: relative;
        transform: none !important;
        box-shadow: none;
    }
}