/**
 * Diary Book CSS
 * 3D floating book styles for the Astronaut Diary
 */

/* ========================================
   BOOK CONTAINER
   ======================================== */

.diary-book-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    perspective: 2000px;
    overflow: hidden;
}

.diary-book-container.hidden {
    display: none !important;
}

/* Space backdrop */
.diary-book-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(ellipse at 20% 30%, rgba(138, 43, 226, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 70%, rgba(65, 105, 225, 0.15) 0%, transparent 50%),
        linear-gradient(135deg, #0a0a1a 0%, #1a1a3e 50%, #0d0d2b 100%);
    z-index: 1;
}

.space-stars {
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(2px 2px at 20px 30px, white, transparent),
        radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 90px 40px, white, transparent),
        radial-gradient(2px 2px at 130px 80px, rgba(255,255,255,0.6), transparent),
        radial-gradient(1px 1px at 160px 120px, white, transparent);
    background-size: 200px 200px;
    animation: twinkle 5s ease-in-out infinite alternate;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

/* ========================================
   BOOK WRAPPER
   ======================================== */

.diary-book-wrapper {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    /* CRITICAL: transform-style: flat prevents children from intersecting in 3D space.
       This ensures the overlay is drawn ON TOP of the tilted book, not cut through it. */
    transform-style: flat;
}

/* Back button - positioned outside the book on the left */
.diary-book-back {
    position: fixed;
    top: 1rem;
    left: 1rem;
    padding: 0.75rem 1.25rem;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 2rem;
    color: white;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 200;
}

.diary-book-back:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateX(-5px);
    border-color: rgba(255, 193, 7, 0.5);
}

/* ========================================
   THE 3D BOOK - TWO PAGE SPREAD
   ======================================== */

.diary-book {
    position: relative;
    display: flex;
    width: min(95vw, 1100px);
    height: min(80vh, 750px);
    transform-style: preserve-3d;
    transform: rotateX(5deg);
    transition: transform 0.5s ease;
    animation: bookFloat 6s ease-in-out infinite;
}

@keyframes bookFloat {
    0%, 100% { transform: rotateX(5deg) translateY(0); }
    50% { transform: rotateX(3deg) translateY(-10px); }
}

.diary-book:hover {
    animation-play-state: paused;
    transform: rotateX(2deg);
}

/* Book spine - center of the open book */
.book-spine {
    position: absolute;
    left: 50%;
    top: 0;
    width: 20px;
    height: 100%;
    transform: translateX(-50%);
    background: linear-gradient(90deg, 
        rgba(0,0,0,0.3) 0%, 
        rgba(0,0,0,0.1) 30%,
        rgba(255,255,255,0.1) 50%,
        rgba(0,0,0,0.1) 70%,
        rgba(0,0,0,0.3) 100%
    );
    z-index: 10;
    pointer-events: none;
}

/* Pages edge - hide for now */
.book-pages-edge {
    display: none;
}

/* ========================================
   BOOK PAGES - TWO PAGE SPREAD
   ======================================== */

.book-page {
    position: relative;
    width: 50%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s ease;
    /* Ensure child elements stack correctly */
    isolation: isolate;
}

.book-page-left {
    border-radius: 10px 0 0 10px;
    box-shadow: 
        -5px 5px 30px rgba(0,0,0,0.4),
        inset -10px 0 30px rgba(0,0,0,0.1);
}

.book-page-left.page-hidden .page-content {
    background: linear-gradient(135deg, #3a2060 0%, #2a1a4a 100%);
}

.book-page-right {
    border-radius: 0 10px 10px 0;
    box-shadow: 
        5px 5px 30px rgba(0,0,0,0.4),
        inset 10px 0 30px rgba(0,0,0,0.1);
}

/* Page content wrapper */
.page-front,
.page-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
}

.page-front {
    transform: rotateY(0deg);
    z-index: 2;
}

.page-back {
    transform: rotateY(180deg);
    background: #f5f5dc;
    z-index: 1;
    pointer-events: none;
}

/* Page content */
.page-content {
    width: 100%;
    height: 100%;
    background: #fafafa;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.book-page-left .page-content {
    border-radius: 10px 0 0 10px;
}

.book-page-right .page-content {
    border-radius: 0 10px 10px 0;
}

.page-inner {
    position: relative;
    width: 100%;
    height: 100%;
}

.page-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: white;
}

.page-number {
    position: absolute;
    bottom: 0.5rem;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.85rem;
    color: rgba(0,0,0,0.4);
    background: rgba(255,255,255,0.8);
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
}

.book-page-left .page-number {
    left: 1rem;
}

.book-page-right .page-number {
    right: 1rem;
}

.activity-indicator {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    font-size: 1.5rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.page-blank {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #3a2060 0%, #2a1a4a 100%);
    color: rgba(255,255,255,0.3);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.2rem;
}

/* ========================================
   PAGE FLIP ANIMATIONS - Enhanced 3D Effect
   ======================================== */

/* Right page flip (going forward) */
.book-page-right.flipping {
    transform-origin: left center;
    animation: pageFlipForward 0.7s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
    z-index: 100;
}

@keyframes pageFlipForward {
    0% {
        transform: perspective(2000px) rotateY(0deg);
        box-shadow: 5px 5px 30px rgba(0,0,0,0.4);
    }
    25% {
        transform: perspective(2000px) rotateY(-45deg) scale(1.02);
        box-shadow: -15px 10px 40px rgba(0,0,0,0.5);
    }
    50% {
        transform: perspective(2000px) rotateY(-90deg) scale(1.04);
        box-shadow: -25px 15px 50px rgba(0,0,0,0.6);
    }
    75% {
        transform: perspective(2000px) rotateY(-135deg) scale(1.02);
        box-shadow: -15px 10px 40px rgba(0,0,0,0.5);
    }
    100% {
        transform: perspective(2000px) rotateY(-180deg);
        box-shadow: 5px 5px 30px rgba(0,0,0,0.4);
    }
}

/* Left page flip (going back) */
.book-page-left.flipping-back {
    transform-origin: right center;
    animation: pageFlipBack 0.7s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
    z-index: 100;
}

@keyframes pageFlipBack {
    0% {
        transform: perspective(2000px) rotateY(0deg);
        box-shadow: -5px 5px 30px rgba(0,0,0,0.4);
    }
    25% {
        transform: perspective(2000px) rotateY(45deg) scale(1.02);
        box-shadow: 15px 10px 40px rgba(0,0,0,0.5);
    }
    50% {
        transform: perspective(2000px) rotateY(90deg) scale(1.04);
        box-shadow: 25px 15px 50px rgba(0,0,0,0.6);
    }
    75% {
        transform: perspective(2000px) rotateY(135deg) scale(1.02);
        box-shadow: 15px 10px 40px rgba(0,0,0,0.5);
    }
    100% {
        transform: perspective(2000px) rotateY(180deg);
        box-shadow: -5px 5px 30px rgba(0,0,0,0.4);
    }
}

/* Page curl effect during flip */
.book-page-right.flipping .page-content,
.book-page-left.flipping-back .page-content {
    transform-style: preserve-3d;
}

.book-page-right.flipping::after,
.book-page-left.flipping-back::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(0,0,0,0.1) 30%,
        rgba(255,255,255,0.15) 50%,
        rgba(0,0,0,0.1) 70%,
        transparent 100%
    );
    pointer-events: none;
    animation: pageShadow 0.7s ease-in-out;
}

@keyframes pageShadow {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

/* ========================================
   PAGE TURN AREAS
   ======================================== */

.page-turn-area {
    position: absolute;
    top: 0;
    width: 12%;
    height: 100%;
    cursor: pointer;
    z-index: 15;
    transition: background 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: rgba(255,255,255,0);
}

.page-turn-left {
    left: 0;
    border-radius: 10px 0 0 10px;
}

.page-turn-right {
    right: 0;
    border-radius: 0 10px 10px 0;
}

.page-turn-area:hover {
    color: rgba(255,255,255,0.5);
}

.page-turn-left:hover {
    background: linear-gradient(90deg, rgba(255,255,255,0.15), transparent);
}

.page-turn-right:hover {
    background: linear-gradient(-90deg, rgba(255,255,255,0.15), transparent);
}

/* ========================================
   PENCIL OVERLAY (Filled Answers)
   ======================================== */

.pencil-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 5;
}

.pencil-overlay.hidden {
    opacity: 0;
    display: none;
}

/* ========================================
   INFO BUBBLES
   ======================================== */

/* ========================================
   INFO BUBBLES OVERLAY
   Positioned via JavaScript to match book exactly
   ======================================== */

.info-bubbles-overlay {
    /* Position set by JS */
    position: absolute;
    display: flex;
    pointer-events: none;
    z-index: 2000; /* Very high z-index */
}

.bubbles-left,
.bubbles-right {
    position: relative;
    width: 50%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
}

/* Ensure bubbles themselves are clickable */
.info-bubbles-overlay .info-bubble {
    pointer-events: auto !important;
    position: absolute;
}

/* DEBUG MODE: Add ?debug to URL to see bubble container bounds */
.diary-book-container.debug-mode .bubbles-left,
.diary-book-container.debug-mode .bubbles-right {
    background: rgba(255, 0, 0, 0.15);
    border: 2px dashed red;
}

.diary-book-container.debug-mode .info-bubble {
    box-shadow: 0 0 0 3px lime !important;
}

/* Mobile: hide left bubbles since left page is hidden */
@media (max-width: 900px) {
    .bubbles-left {
        display: none;
    }
    
    .bubbles-right {
        width: 100%;
    }
}

.info-bubble {
    position: absolute;
    width: 32px;
    height: 32px;
    background: rgba(255, 193, 7, 0.9);
    border: 2px solid white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: auto !important;
    transition: all 0.3s ease;
    animation: bubblePulse 2s ease-in-out infinite;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    z-index: 100;
}

.info-bubble:hover {
    transform: scale(1.2);
    animation: none;
    background: rgba(255, 193, 7, 1);
}

@keyframes bubblePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.bubble-icon {
    font-size: 1rem;
}

/* ========================================
   CONTROLS
   ======================================== */

.diary-book-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(95vw, 1100px);
    padding: 0.75rem 1.5rem;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    border-radius: 2rem;
    gap: 1rem;
    position: relative;
    z-index: 1000;
}

.controls-left,
.controls-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.page-nav-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-nav-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.page-nav-btn:active {
    transform: scale(0.95);
}

.page-counter {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1rem;
    color: white;
    min-width: 60px;
    text-align: center;
}

.diary-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 1.5rem;
    color: white;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.diary-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.diary-btn.active {
    background: rgba(255, 193, 7, 0.3);
    border-color: rgba(255, 193, 7, 0.5);
}

.btn-icon {
    font-size: 1.1rem;
}

.btn-icon-img {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.nav-icon-img {
    width: 16px;
    height: 16px;
    object-fit: contain;
    filter: brightness(0) invert(1);
}

.turn-arrow {
    width: 32px;
    height: 32px;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.3s ease;
    filter: brightness(0) invert(1);
}

.page-turn-area:hover .turn-arrow {
    opacity: 0.7;
}

.bubble-icon-img {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

/* ========================================
   HINT POPUP
   ======================================== */

.diary-book-hint {
    position: absolute;
    bottom: 8rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: rgba(74, 42, 122, 0.95);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 193, 7, 0.5);
    border-radius: 1rem;
    color: white;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.95rem;
    animation: hintBounce 2s ease-in-out infinite;
    z-index: 1000; /* Increased z-index */
}

.diary-book-hint.hidden {
    display: none;
}

@keyframes hintBounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-5px); }
}

.hint-icon {
    font-size: 1.5rem;
}

.hint-text {
    font-size: 0.95rem;
}

.hint-dismiss {
    padding: 0.4rem 1rem;
    background: rgba(255, 193, 7, 0.8);
    border: none;
    border-radius: 1rem;
    color: #1a1a2e;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.hint-dismiss:hover {
    background: rgba(255, 193, 7, 1);
    transform: scale(1.05);
}

/* ========================================
   MASTER CHARACTER
   ======================================== */

.diary-master-container {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    z-index: 100;
    pointer-events: none;
}

.diary-master {
    position: relative;
    width: 120px;
    height: 160px;
    pointer-events: auto;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.diary-master.floating {
    animation: masterFloat 4s ease-in-out infinite;
}

@keyframes masterFloat {
    0%, 100% { transform: translateY(0) rotate(-2deg); }
    50% { transform: translateY(-15px) rotate(2deg); }
}

.master-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 5px 15px rgba(0,0,0,0.4));
}

.diary-master:hover {
    transform: scale(1.1);
}

/* Master Speech Bubble */
.master-speech-bubble {
    position: absolute;
    left: 130px;
    bottom: 50px;
    min-width: 280px;
    max-width: 350px;
    padding: 1rem 1.25rem;
    background: white;
    border-radius: 1rem;
    box-shadow: 0 5px 25px rgba(0,0,0,0.3);
    opacity: 0;
    transform: translateX(-20px) scale(0.9);
    transition: all 0.3s ease;
    pointer-events: none;
}

.master-speech-bubble.show {
    opacity: 1;
    transform: translateX(0) scale(1);
    pointer-events: auto;
}

.master-speech-bubble.hidden {
    display: none;
}

/* Speech bubble tail */
.master-speech-bubble::before {
    content: '';
    position: absolute;
    left: -15px;
    bottom: 30px;
    width: 0;
    height: 0;
    border: 10px solid transparent;
    border-right-color: white;
    border-left: 0;
}

.speech-content {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #1a1a2e;
}

.speech-dismiss {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 24px;
    height: 24px;
    background: rgba(0,0,0,0.1);
    border: none;
    border-radius: 50%;
    color: #666;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.speech-dismiss:hover {
    background: rgba(0,0,0,0.2);
    color: #333;
}

/* ========================================
   TOAST NOTIFICATION
   ======================================== */

.diary-toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    background: rgba(74, 42, 122, 0.95);
    border: 1px solid rgba(255, 193, 7, 0.5);
    border-radius: 1rem;
    color: white;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.95rem;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    z-index: 9999;
}

.diary-toast.show {
    opacity: 1;
    transform: translateY(0);
}

.diary-toast.hidden {
    display: none;
}

/* ========================================
   STAR PARTICLE EFFECT
   ======================================== */

.star-particle {
    position: absolute;
    font-size: 1rem;
    pointer-events: none;
    animation: starBurst 1s ease-out forwards;
}

@keyframes starBurst {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx, 50px), var(--ty, -50px)) scale(0);
    }
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

/* Tablet - show single page */
@media (max-width: 900px) {
    .diary-book {
        width: 95vw;
        max-width: 550px;
        height: 70vh;
        flex-direction: column;
        transform: rotateX(2deg);
        animation: none;
    }
    
    .book-page {
        width: 100%;
        height: 100%;
    }
    
    /* Hide left page on mobile - show only current page */
    .book-page-left {
        display: none;
    }
    
    .book-page-right {
        border-radius: 10px;
    }
    
    .book-page-right .page-content {
        border-radius: 10px;
    }
    
    .book-spine {
        display: none;
    }
    
    .diary-book-controls {
        flex-direction: column;
        gap: 0.5rem;
        width: 95vw;
        max-width: 550px;
        padding: 0.5rem;
    }
    
    .controls-left,
    .controls-right {
        width: 100%;
        justify-content: center;
    }
    
    .btn-label {
        display: none;
    }
    
    .diary-btn {
        padding: 0.5rem 0.75rem;
    }
    
    .diary-master-container {
        bottom: 10rem;
        left: 0.5rem;
    }
    
    .diary-master {
        width: 80px;
        height: 100px;
    }
    
    .master-speech-bubble {
        left: 90px;
        min-width: 200px;
        max-width: 250px;
        font-size: 0.85rem;
        bottom: 20px;
    }
    
    .diary-book-hint {
        bottom: 8rem;
        flex-direction: column;
        text-align: center;
        padding: 0.75rem 1rem;
    }
    
    .diary-book-back {
        position: fixed;
        top: 0.5rem;
        left: 0.5rem;
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
    
    .page-turn-area {
        width: 25%;
    }
}

@media (max-width: 480px) {
    .diary-book {
        height: 60vh;
    }
    
    .diary-master-container {
        bottom: 11rem;
    }
    
    .diary-master {
        width: 60px;
        height: 80px;
    }
    
    .master-speech-bubble {
        left: 70px;
        min-width: 180px;
        max-width: 200px;
        font-size: 0.8rem;
        padding: 0.75rem 1rem;
    }
    
    .info-bubble {
        width: 28px;
        height: 28px;
    }
    
    .bubble-icon {
        font-size: 0.85rem;
    }
}

/* ========================================
   BOOK CLOSED STATE
   ======================================== */

.diary-book.book-closed {
    /* When closed, show as a single book (cover facing right) */
}

.diary-book.book-closed .book-page-left .page-content {
    border-radius: 0 10px 10px 0;
}

.diary-book.book-closed .book-spine {
    opacity: 0;
}

/* Click hint on closed book */
.diary-book.book-closed::after {
    content: '👆 Clique para abrir';
    position: absolute;
    bottom: -3rem;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.7);
    white-space: nowrap;
    animation: pulseHint 2s ease-in-out infinite;
}

@keyframes pulseHint {
    0%, 100% { opacity: 0.7; transform: translateX(-50%) scale(1); }
    50% { opacity: 1; transform: translateX(-50%) scale(1.05); }
}

/* ========================================
   BOOK OPENING/CLOSING ANIMATIONS
   ======================================== */

/* Opening animation - cover rotates 180° */
.diary-book.book-opening-animation {
    animation: bookOpenCover 0.8s ease-in-out forwards;
}

.diary-book.book-opening-animation .book-page-left,
.diary-book.book-opening-animation .book-page-right {
    animation: coverFlipOpen 0.8s ease-in-out forwards;
}

@keyframes bookOpenCover {
    0% {
        transform: rotateX(5deg) translateY(0);
    }
    50% {
        transform: rotateX(0deg) translateY(-20px);
    }
    100% {
        transform: rotateX(5deg) translateY(0);
    }
}

@keyframes coverFlipOpen {
    0% {
        transform: rotateY(0deg);
    }
    100% {
        transform: rotateY(-180deg);
    }
}

/* Closing animation */
.diary-book.book-closing-animation {
    animation: bookCloseCover 0.8s ease-in-out forwards;
}

.diary-book.book-closing-animation .book-page-left,
.diary-book.book-closing-animation .book-page-right {
    animation: coverFlipClose 0.8s ease-in-out forwards;
}

@keyframes bookCloseCover {
    0% {
        transform: rotateX(5deg) translateY(0);
    }
    50% {
        transform: rotateX(0deg) translateY(-20px);
    }
    100% {
        transform: rotateX(5deg) translateY(0);
    }
}

@keyframes coverFlipClose {
    0% {
        transform: rotateY(-180deg);
    }
    100% {
        transform: rotateY(0deg);
    }
}

/* Legacy animations (for initial entrance) */
.diary-book.book-opening {
    animation: bookEntrance 0.8s ease forwards;
}

.diary-book.book-closing {
    animation: bookExit 0.8s ease forwards;
}

@keyframes bookEntrance {
    0% {
        transform: rotateY(-90deg) scale(0.5);
        opacity: 0;
    }
    100% {
        transform: rotateX(5deg) scale(1);
        opacity: 1;
    }
}

@keyframes bookExit {
    0% {
        transform: rotateX(5deg) scale(1);
        opacity: 1;
    }
    100% {
        transform: rotateY(-90deg) scale(0.5);
        opacity: 0;
    }
}

/* ========================================
   DARK MODE COMPATIBILITY
   ======================================== */

@media (prefers-color-scheme: dark) {
    .page-content {
        background: #f0f0e8;
    }
    
    .master-speech-bubble {
        background: #f8f8f0;
    }
}

