

.flipbook-viewport {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin: 0;
    background: #525659;
    overflow: hidden;
}

/* --- Scene & Book Layout --- */
.scene-container {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 20px;
    position: relative;
}

.scene {
    width: 100%;
    max-width: 900px;
    aspect-ratio: 3 / 2;
    perspective: 2500px;
    transition: transform 0.3s ease;
}

.book {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.645, 0.045, 0.355, 1);
}

/* 🟢 When Closed: Shift Left to center the cover */
.book.closed {
    transform: translateX(-25%);
}

/* --- Page Styling --- */
.page {
    position: absolute;
    width: 50%;
    height: 100%;
    left: 50%;
    background: #fff;
    transform-origin: left center;
    transform-style: preserve-3d;
    transition: transform 0.9s cubic-bezier(0.645, 0.045, 0.355, 1);
    border-left: 1px solid rgba(0,0,0,0.1); /* Spine line */
}

.front, .back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    background-color: #fff;
    overflow: hidden;
}

.front {
    z-index: 2;
    transform: rotateY(0deg);
}

/* Realistic Page Shadow */
.front::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to right, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 15%);
    pointer-events: none;
}

.back {
    transform: rotateY(180deg);
    z-index: 1;
    background-color: #fdfdfd;
}

.back::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to left, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 15%);
    pointer-events: none;
}

/* Page Flip Action */
.page.flipped {
    transform: rotateY(-180deg);
}

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

/* --- Navigation Buttons --- */
.flip-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    z-index: 2000;
    border: 1px solid rgba(255,255,255,0.2);
    transition: all 0.3s;
}

.flip-nav:hover {
    background: white;
    color: #333;
    box-shadow: 0 0 15px rgba(255,255,255,0.3);
}

#prev { left: 20px; }
#next { right: 20px; }

/* --- Toolbar --- */
.toolbar {
    margin-bottom: 20px;
    height: 50px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 0 25px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    z-index: 5000;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.page-count { font-size: 14px; font-weight: 500; color: #ddd; }
.divider { width: 1px; height: 20px; background: rgba(255,255,255,0.2); }

.tool-btn {
    background: none; border: none; color: #ccc;
    font-size: 18px; cursor: pointer; padding: 8px;
    transition: 0.2s;
}
.tool-btn:hover { color: white; transform: scale(1.1); }

/* --- Responsive --- */
@media (max-width: 768px) {
    .scene { width: 95%; }
    .flip-nav { width: 40px; height: 40px; font-size: 16px; }
    #prev { left: 10px; } 
    #next { right: 10px; }
    .book.closed { transform: translateX(-25%); } /* Keep centering on mobile */
}