
/* Full Page Flipbook */
.flipbook-fullpage * {
    box-sizing: border-box;
}

.flipbook-fullpage {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Top Bar */
.flipbook-topbar {
    height: 60px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.flipbook-topbar-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.flipbook-back-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.flipbook-back-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.flipbook-catalog-title {
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.flipbook-topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.topbar-btn:hover {
    background: #415EA8;
    transform: scale(1.05);
}

.topbar-btn.download-btn {
    background: #415EA8;
    padding: 0 15px;
    width: auto;
    gap: 8px;
}

.topbar-btn.download-btn:hover {
    background: #5a7bc4;
}

/* Main Flipbook Area */
.flipbook-main-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 20px;
    overflow: hidden;
}

/* Flipbook Container */
.flipbook-container {
    position: relative;
    width: 100%;
    max-width: 1400px;
    height: calc(100vh - 160px);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* The Book */
#flipbook {
    width: 100%;
    height: 100%;
}

/* Navigation Arrows */
.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 60px;
    height: 120px;
    background: rgba(0, 0, 0, 0.4);
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    transition: all 0.3s;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-arrow:hover:not(:disabled) {
    background: rgba(65, 94, 168, 0.8);
}

.nav-arrow:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-arrow.prev {
    left: 0;
    border-radius: 0 12px 12px 0;
}

.nav-arrow.next {
    right: 0;
    border-radius: 12px 0 0 12px;
}

/* Bottom Bar */
.flipbook-bottombar {
    height: 80px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 0 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

/* Page Slider */
.page-slider-container {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
    max-width: 600px;
}

.page-slider {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.page-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #415EA8;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

.page-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.page-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #415EA8;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.page-info {
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    min-width: 100px;
    text-align: center;
}

/* Bottom Controls */
.bottom-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bottom-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bottom-btn:hover:not(:disabled) {
    background: #415EA8;
    transform: scale(1.1);
}

.bottom-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Loading Screen */
.flipbook-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(26, 26, 46, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: #415EA8;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    color: #fff;
    margin-top: 20px;
    font-size: 18px;
}

.loading-progress {
    width: 200px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin-top: 15px;
    overflow: hidden;
}

.loading-progress-bar {
    height: 100%;
    background: #415EA8;
    border-radius: 2px;
    transition: width 0.3s;
    width: 0%;
}

/* Error State */
.flipbook-error {
    text-align: center;
    color: #fff;
}

.flipbook-error i {
    font-size: 64px;
    color: #e74c3c;
    margin-bottom: 20px;
}

.flipbook-error h3 {
    font-size: 24px;
    margin-bottom: 15px;
}

/* StPageFlip Styles */
.stf__parent {
    width: 100% !important;
    height: 100% !important;
}

.stf__wrapper {
    display: flex;
    justify-content: center;
}

.page {
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

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

.page-cover {
    background: linear-gradient(135deg, #415EA8, #2a3f7a);
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
}

.page-cover h2 {
    font-size: 28px;
    margin-bottom: 10px;
}

.page-cover p {
    opacity: 0.8;
}

/* Responsive */
@media (max-width: 1024px) {
    .flipbook-catalog-title {
        display: none;
    }
    
    .nav-arrow {
        width: 50px;
        height: 100px;
        font-size: 24px;
    }
}

@media (max-width: 768px) {
    .flipbook-topbar {
        height: 50px;
        padding: 0 10px;
    }
    
    .flipbook-back-btn,
    .topbar-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    .topbar-btn.download-btn span {
        display: none;
    }
    
    .topbar-btn.download-btn {
        width: 36px;
        padding: 0;
    }
    
    .flipbook-main-area {
        padding: 10px;
    }
    
    .flipbook-container {
        height: calc(100vh - 140px);
    }
    
    .nav-arrow {
        width: 40px;
        height: 80px;
        font-size: 20px;
    }
    
    .flipbook-bottombar {
        height: 70px;
        gap: 10px;
        flex-wrap: wrap;
    }
    
    .page-slider-container {
        order: 2;
        width: 100%;
        max-width: none;
    }
    
    .bottom-controls {
        order: 1;
    }
    
    .bottom-btn {
        width: 38px;
        height: 38px;
        font-size: 14px;
    }
    
    .page-info {
        font-size: 14px;
        min-width: 80px;
    }
}

/* Touch hint */
.touch-hint {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 15px 25px;
    border-radius: 30px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    animation: fadeInOut 4s ease-in-out forwards;
    z-index: 200;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; transform: translateX(-50%) translateY(20px); }
    15%, 85% { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.touch-hint i {
    font-size: 20px;
}

/* Fit the real PDF spread; only actual pages have a paper surface. */
.flipbook-fullpage { height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.flipbook-main-area { min-height: 0; padding: 12px; overflow: hidden; overscroll-behavior: contain; }
.flipbook-container { flex: 0 0 auto; max-width: none; margin: auto; touch-action: none; }
.flipbook-main-area.is-zoomed { display: block; overflow: auto; scrollbar-gutter: stable both-edges; }
.flipbook-main-area.is-zoomed .flipbook-container { touch-action: auto; }
.flipbook-fullpage #flipbook { flex: none; transition: none; }
.flipbook-fullpage .stf__parent { flex-shrink: 0; }
.flipbook-fullpage .page { overflow: hidden; backface-visibility: hidden; }
.flipbook-fullpage .page img { display: block; width: 100%; height: 100%; object-fit: contain; }
.flipbook-fullpage .nav-arrow { display: none; }
.flipbook-topbar { min-height: 52px; height: auto; padding: 8px 12px; gap: 8px; }
.flipbook-topbar-left { min-width: 0; }
.flipbook-catalog-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flipbook-topbar-right { flex-shrink: 0; gap: 8px; }
.flipbook-bottombar { height: auto; min-height: 68px; flex-wrap: nowrap; padding: 10px 12px; gap: 10px; }
.page-slider-container { min-width: 0; gap: 8px; }
.page-slider { min-width: 0; }
.page-info { min-width: 90px; white-space: nowrap; }
.flipbook-fullpage button:disabled { opacity: .35; cursor: default; }
.touch-hint { pointer-events: none; bottom: 84px; font-size: 12px; padding: 8px 12px; white-space: nowrap; }
.touch-hint[hidden] { display: none; }
@media (max-width: 768px) {
    .page-slider-container, .bottom-controls { order: initial; }
    .page-slider-container { width: auto; }
    .bottom-controls { gap: 4px; }
    .bottom-btn { width: 34px; height: 40px; border-radius: 8px; }
    .flipbook-bottombar { min-height: 60px; gap: 6px; padding: 6px; }
    .page-info { min-width: 56px; font-size: 12px; }
    .page-slider-container { gap: 5px; }
}
@media (max-height: 500px) {
    .flipbook-topbar { min-height: 44px; padding-top: 4px; padding-bottom: 4px; }
    .flipbook-bottombar { min-height: 48px; padding-top: 4px; padding-bottom: 4px; }
    .touch-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .flipbook-fullpage *, .flipbook-fullpage *::before, .flipbook-fullpage *::after { animation: none !important; transition: none !important; }
}

.flipbook-fullpage .page img { user-select: none; -webkit-user-drag: none; }

html.catalog-reading, .catalog-reading body { overflow: hidden; }
