/* Flipbook Gallery Styles - Sequential Page Flipping */
.flipbook-gallery {
    /* Works with Bootstrap grid system */
    margin: 0;
}

.layout-flipbook_gallery_section {
    /* Container styles for flipbook gallery sections */
    position: relative;
}

.flipbook-item {
    position: relative;
    width: 100%;
    height: 400px;
    perspective: 1000px;
    margin-bottom: 1rem;
    overflow: visible;
}

.flipbook-container {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.flipbook-page {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    backface-visibility: hidden;
    transform-origin: left center;
    transition: transform 0.8s cubic-bezier(0.645, 0.045, 0.355, 1);
    z-index: 1;
}

/* Active page (currently visible) */
.flipbook-page.active {
    z-index: 3;
}

/* Page being flipped */
.flipbook-page.flipping {
    z-index: 4;
    transform: rotateY(-180deg);
}

/* Pages that have been flipped (behind) */
.flipbook-page.flipped {
    z-index: 2;
    transform: rotateY(-180deg);
}

/* Book page flip animation - from right to left */
.flipbook-page.page-turn-start {
    animation: pageTurnStart 0.8s cubic-bezier(0.645, 0.045, 0.355, 1) forwards;
}

@keyframes pageTurnStart {
    0% {
        transform: rotateY(0deg);
        transform-origin: right center;
    }
    50% {
        transform: rotateY(-90deg);
        transform-origin: right center;
        box-shadow: -5px 5px 20px rgba(0, 0, 0, 0.3);
    }
    100% {
        transform: rotateY(-180deg);
        transform-origin: right center;
    }
}

/* Integration with existing theme classes */
.flipbook-item.radius .flipbook-page {
    /* Inherit radius from existing theme */
    border-radius: inherit;
}

.flipbook-item.a-block .flipbook-page {
    /* Match existing theme block styles */
    display: block;
}

.flipbook-page.front {
    z-index: 2;
}

.flipbook-page.back {
    transform: rotateY(180deg);
}

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

.flip-button {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #333;
    transition: all 0.3s ease;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.flip-button:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.1);
}

.flip-button::before {
    content: "→";
    font-weight: bold;
}

/* Hide button when on last page */
.flipbook-item[data-current-page="last"] .flip-button {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Reset/previous button when on last page */
.flipbook-item[data-current-page="last"] .flip-button::before {
    content: "↻";
}

.flipbook-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    color: white;
    padding: 20px 15px 15px;
    font-size: 14px;
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.flipbook-item:hover .flipbook-caption {
    opacity: 1;
}

/* Responsive Design - Match existing theme breakpoints */
@media (max-width: 768px) {
    .flipbook-item {
        height: 320px;
    }
    
    .flip-button {
        width: 35px;
        height: 35px;
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .flipbook-item {
        height: 280px;
    }
}

/* Integration with existing spacing classes */
.flipbook-item.mb-1 {
    margin-bottom: 0.25rem !important;
}

.flipbook-item.mb-xl-4 {
    margin-bottom: 1.5rem !important;
}

@media (min-width: 1200px) {
    .flipbook-item.mb-xl-4 {
        margin-bottom: 1.5rem !important;
    }
}

/* Animation variants */
.flipbook-item.flip-horizontal .flipbook-container {
    transition: transform 0.6s ease-in-out;
}

.flipbook-item.flip-vertical .flipbook-container {
    transition: transform 0.6s ease-in-out;
}

.flipbook-item.flip-vertical.flipped .flipbook-container {
    transform: rotateX(180deg);
}

/* Loading state */
.flipbook-page.loading {
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flipbook-page.loading::before {
    content: "Loading...";
    color: #666;
    font-size: 14px;
}
