/**
 * DZAM Flipbook - Magazine Style CSS
 * Realistic book/magazine appearance with page turning effect
 */

/* Modal */
.flipbook-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a2e 0%, #0d0d0d 100%);
    z-index: 999999;
}

.flipbook-modal.active {
    display: block;
}

/* Wrapper */
.flipbook-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 100%;
    margin: 0 auto;
}

/* Header */
.flipbook-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    background: rgba(0, 0, 0, 0.5);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.flipbook-title {
    color: #fff;
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: 1px;
}

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

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

.fb-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.fb-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.fb-close:hover {
    background: #ff4444;
    border-color: #ff4444;
}

#flipbook-zoom-level {
    color: #fff;
    font-size: 0.9rem;
    min-width: 50px;
    text-align: center;
}

/* Container */
.flipbook-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 20px;
    overflow: hidden;
    background:
        radial-gradient(ellipse at center, rgba(255,255,255,0.03) 0%, transparent 70%),
        linear-gradient(180deg, #0d0d0d 0%, #1a1a1a 100%);
}

/* Loading */
.flipbook-loading {
    text-align: center;
    color: #fff;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #fff;
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 1s linear infinite;
}

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

.flipbook-loading p {
    margin-bottom: 20px;
    font-size: 1.1rem;
}

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

.loading-bar {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    width: 0%;
    transition: width 0.3s ease;
}

#loading-percent {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
}

/* Flipbook */
#flipbook {
    position: relative;
    perspective: 2000px;
    transform-style: preserve-3d;
    transition: transform 0.3s ease;
    background: linear-gradient(90deg,
        #2a2a2a 0%,
        #1a1a1a 2%,
        #1a1a1a 49%,
        #0a0a0a 50%,
        #1a1a1a 51%,
        #1a1a1a 98%,
        #2a2a2a 100%
    );
    border-radius: 5px;
    box-shadow:
        0 0 50px rgba(0, 0, 0, 0.5),
        0 0 100px rgba(0, 0, 0, 0.3),
        inset 0 0 30px rgba(0, 0, 0, 0.3);
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Pages */
.flipbook-page {
    position: absolute;
    background: #fff;
    box-shadow:
        0 0 20px rgba(0, 0, 0, 0.3),
        inset 0 0 50px rgba(0, 0, 0, 0.05);
    transform-style: preserve-3d;
    transform-origin: left center;
    transition: transform 0.6s ease, opacity 0.3s ease;
    overflow: hidden;
    backface-visibility: hidden;
}

.flipbook-page canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Page positions */
.flipbook-page.left {
    left: 20px;
    transform: rotateY(0deg);
    z-index: 2;
    border-radius: 3px 0 0 3px;
}

.flipbook-page.right {
    left: calc(50% + 20px);
    transform: rotateY(0deg);
    z-index: 2;
    border-radius: 0 3px 3px 0;
}

.flipbook-page.hidden {
    opacity: 0;
    pointer-events: none;
}

.flipbook-page.prev {
    z-index: 1;
}

.flipbook-page.next {
    z-index: 1;
}

/* Page turn animation */
.flipbook-page.turning {
    animation: turnPage 0.6s ease forwards;
    z-index: 10;
}

@keyframes turnPage {
    0% {
        transform: rotateY(0deg);
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    }
    50% {
        transform: rotateY(-90deg);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    }
    100% {
        transform: rotateY(-180deg);
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    }
}

.flipbook-page.turning-back {
    animation: turnPageBack 0.6s ease forwards;
    z-index: 10;
    transform-origin: right center;
}

@keyframes turnPageBack {
    0% {
        transform: rotateY(-180deg);
    }
    50% {
        transform: rotateY(-90deg);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    }
    100% {
        transform: rotateY(0deg);
    }
}

/* Page shadow/gradient overlay */
.flipbook-page::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 50px;
    height: 100%;
    background: linear-gradient(to right,
        transparent,
        rgba(0, 0, 0, 0.1) 80%,
        rgba(0, 0, 0, 0.2)
    );
    pointer-events: none;
}

.flipbook-page.left::after {
    right: auto;
    left: 0;
    background: linear-gradient(to left,
        transparent,
        rgba(0, 0, 0, 0.1) 80%,
        rgba(0, 0, 0, 0.15)
    );
}

/* Book spine effect */
#flipbook::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 100%;
    background: linear-gradient(90deg,
        rgba(0, 0, 0, 0.4) 0%,
        rgba(0, 0, 0, 0.2) 30%,
        rgba(255, 255, 255, 0.05) 50%,
        rgba(0, 0, 0, 0.2) 70%,
        rgba(0, 0, 0, 0.4) 100%
    );
    z-index: 100;
    pointer-events: none;
}

/* Navigation arrows */
.flipbook-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 60px;
    height: 100px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 100;
}

.flipbook-nav svg {
    width: 30px;
    height: 30px;
    fill: currentColor;
}

.flipbook-nav.prev {
    left: 20px;
    border-radius: 0 10px 10px 0;
}

.flipbook-nav.next {
    right: 20px;
    border-radius: 10px 0 0 10px;
}

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

/* Footer */
.flipbook-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    padding: 15px 30px;
    background: rgba(0, 0, 0, 0.5);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-wrap: wrap;
}

.fb-btn-sm {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.fb-btn-sm svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.fb-btn-sm:hover {
    background: rgba(255, 255, 255, 0.2);
}

.page-info {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-size: 0.95rem;
}

.page-info input {
    width: 60px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    text-align: center;
    font-size: 0.95rem;
}

.page-info input:focus {
    outline: none;
    border-color: #fff;
}

/* Thumbnails */
.page-thumbnails {
    display: flex;
    gap: 8px;
    margin-left: 20px;
    padding-left: 20px;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
    max-width: 400px;
    overflow-x: auto;
    padding: 5px 0;
}

.page-thumb {
    flex-shrink: 0;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    opacity: 0.6;
}

.page-thumb:hover {
    opacity: 1;
    border-color: rgba(255, 255, 255, 0.5);
}

.page-thumb.active {
    opacity: 1;
    border-color: #4CAF50;
}

/* Responsive */
@media (max-width: 1200px) {
    #flipbook {
        transform: scale(0.9);
    }
}

@media (max-width: 992px) {
    #flipbook {
        transform: scale(0.7);
    }

    .flipbook-nav {
        width: 50px;
        height: 80px;
    }

    .page-thumbnails {
        display: none;
    }
}

@media (max-width: 768px) {
    .flipbook-header {
        padding: 10px 15px;
        flex-wrap: wrap;
        gap: 10px;
    }

    .flipbook-title {
        width: 100%;
        text-align: center;
        font-size: 1rem;
    }

    .flipbook-controls {
        width: 100%;
        justify-content: center;
    }

    #flipbook {
        transform: scale(0.5);
    }

    .flipbook-nav {
        width: 40px;
        height: 60px;
    }

    .flipbook-nav.prev {
        left: 5px;
    }

    .flipbook-nav.next {
        right: 5px;
    }

    .flipbook-footer {
        padding: 10px 15px;
        gap: 10px;
    }

    .page-info span:first-child {
        display: none;
    }
}

@media (max-width: 480px) {
    #flipbook {
        transform: scale(0.4);
    }

    .fb-btn {
        width: 35px;
        height: 35px;
    }

    #flipbook-zoom-level {
        display: none;
    }
}

/* Fullscreen mode */
.flipbook-wrapper:fullscreen {
    background: #0d0d0d;
}

.flipbook-wrapper:fullscreen #flipbook {
    transform: scale(1.1);
}

/* Print styles */
@media print {
    .flipbook-modal {
        display: none !important;
    }
}

/* Smooth scrollbar for thumbnails */
.page-thumbnails::-webkit-scrollbar {
    height: 6px;
}

.page-thumbnails::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.page-thumbnails::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.page-thumbnails::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}
