/* =========================================
   1. GLOBAL & MOBILE BASE STYLES
   ========================================= */
:root {
    --card-width: 450px; /* INCREASED width for more content space */
    --card-height: 650px; /* INCREASED height for more content space */
    --red-primary: #ff4d4d;
    --pink-secondary: #ff9ff3;
    --blue-accent: #1e90ff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: #f7d794; 
    font-family: 'Arial', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    perspective: 1000px;
}

@media (max-width: 600px) {
    body {
        min-height: -webkit-fill-available;
    }
}

/* =========================================
   2. SPLASH SCREEN STYLING
   ========================================= */
#splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--red-primary) 0%, var(--pink-secondary) 100%);
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.5s ease-out;
    cursor: pointer;
}

#splash-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.splash-text {
    font-size: 2.5em;
    margin-bottom: 20px;
    animation: pulse 1.5s infinite;
}

.tap-prompt {
    position: absolute;
    bottom: 50px;
    font-size: 0.9em;
    opacity: 0.8;
}

.decoration {
    width: 100px;
    height: 100px;
    margin: 10px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
}

.cake-decoration { background: url('assets/cake-icon.svg') center/80% no-repeat; }
.lights-decoration { background: url('assets/lights-icon.svg') center/80% no-repeat; }


/* =========================================
   3. CARD STRUCTURE & 3D FLIPPING
   ========================================= */
.card-wrapper {
    width: var(--card-width);
    height: var(--card-height);
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s; 
}

.card-wrapper.hidden {
    display: none;
}

.card-spine {
    position: absolute;
    top: 0;
    left: 0;
    width: 5px;
    height: 100%;
    background-color: #a04444;
    transform: translateZ(-2px);
}

/* Base style for every page */
.page {
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: white;
    border: 1px solid #ddd;
    border-left: none;
    transform-origin: left center;
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    backface-visibility: hidden;
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
    cursor: pointer;

    /* CRITICAL FIX FOR BLEEDING CONTENT */
    transform: translateZ(0); 
    will-change: transform;
}

/* Z-index for stacking order (Page 1 is on top) */
#page-1 { z-index: 5; }
#page-2 { z-index: 4; }
#page-3 { z-index: 3; }
#page-4 { z-index: 2; }
#page-5 { z-index: 1; }

/* Class added by JavaScript to flip a page */
.page.is-flipped {
    transform: rotateY(-180deg) translateZ(0); 
}

/* =========================================
   4. PAGE CONTENT STYLING
   ========================================= */
.page-content {
    padding: 30px;
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    
    /* Align content to the top for poem/message pages */
    justify-content: flex-start;
    
    align-items: center;
    text-align: center;
}

/* New rule for the pink background on Page 2 (main poem) */
.new-background {
    background-color: #ffe6f2; /* Soft Pink Background */
}

/* Page 1 (Cover) */
.cover-page {
    background: linear-gradient(to top right, #ffe6e6, #ffcccc);
    /* Re-center content on the cover page */
    justify-content: center;
}

.cake-illustration {
    width: 150px;
    height: 150px;
    margin-bottom: 20px;
    background: url('assets/cake.png') center/contain no-repeat; 
}

.cover-text {
    color: var(--red-primary);
}

/* Message Pages (Page 2, 3) */
.main-message p {
    margin-bottom: 15px;
    line-height: 1.6;
    color: #333;
    font-size: 1em;
}

.main-message h2 {
    color: var(--blue-accent);
    margin-top: 20px;
    font-size: 1.8em;
}

/* Photo Page (Page 4) */
.card-photo {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    margin-bottom: 15px;
}

/* Back Cover (Page 5) */
.back-cover {
    background-color: #eee;
    justify-content: space-around;
}

.action-btn {
    padding: 10px 20px;
    background-color: var(--red-primary);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 1.1em;
    cursor: pointer;
    box-shadow: 0 4px #c23939;
    transition: background-color 0.3s, transform 0.1s;
}

.action-btn:active {
    background-color: #c23939;
    box-shadow: 0 2px #962c2c;
    transform: translateY(2px);
}

/* =========================================
   5. FINAL CELEBRATION (Balloons & Confetti)
   ========================================= */
.final-celebration {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 500; 
}

/* Score Counter */
#score-counter {
    position: fixed;
    top: 10px;
    right: 10px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 15px;
    border-radius: 5px;
    font-size: 1.1em;
    font-weight: bold;
    z-index: 600; 
    pointer-events: none;
}

/* Balloon base style (for JS injection) */
.balloon {
    position: absolute;
    /* *** INCREASED SIZE *** */
    width: 140px; 
    height: 180px; 
    /* ********************* */
    background-color: var(--red-primary);
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    bottom: -100px;
    animation: rise 10s linear forwards; /* Slower rise */
    opacity: 0.8;
    pointer-events: auto;
    cursor: pointer;
    transition: transform 0.2s ease-out, opacity 0.5s linear; 
}

.balloon:hover, .balloon:active {
    transform: scale(1.1); 
}

.balloon::after {
    /* String */
    content: '';
    position: absolute;
    width: 2px;
    height: 80px; 
    background-color: rgba(0, 0, 0, 0.5); 
    
    top: 98%; 
    left: calc(50% - 1px);
    
    transform: translateZ(-5px); 
}

/* Style for scattered pictures */
.scatter-pic {
    position: absolute;
    width: 80px;  
    height: 80px; 
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
    opacity: 1;
    z-index: 300; 
}

/* Heart Message Wrapper */
#blast-message-wrapper {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 550;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#blast-message {
    background: yellow;
    color: black;
    padding: 10px 20px;
    border-radius: 5px;
    font-size: 1.2em;
    font-weight: bold;
    margin-top: 10px;
}

/* CSS for the animated heart */
.heart-icon {
    position: relative;
    width: 50px;
    height: 45px;
    background-color: var(--red-primary);
    transform: rotate(-45deg);
    animation: pulse 1s infinite;
}
.heart-icon::before,
.heart-icon::after {
    content: "";
    position: absolute;
    width: 50px;
    height: 45px;
    background-color: var(--red-primary);
    border-radius: 50%;
}
.heart-icon::before {
    top: -25px;
    left: 0;
}
.heart-icon::after {
    left: 25px;
    top: 0;
}


/* Keyframe for Balloon Rising */
@keyframes rise {
    from {
        transform: translateY(0) rotate(0deg);
    }
    to {
        transform: translateY(-100vh) rotate(5deg);
        opacity: 0.1;
    }
}

/* Keyframe for splash screen pulse */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* =========================================
   6. BIRTHDAY TEXT ANIMATION
   ========================================= */
.birthday-text-group {
    position: absolute;
    bottom: 0; 
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 250; 
    pointer-events: none; 
}

.birthday-text {
    font-family: 'Comic Sans MS', cursive, sans-serif;
    font-weight: bold;
    text-shadow: 2px 2px 5px rgba(0,0,0,0.3);
    margin-bottom: 15px; 
    opacity: 0;
    transform: translateY(100px); 
    animation: textRiseAndFade 5s ease-out forwards;
}

.birthday-text:nth-child(1) {
    font-size: 3em;
    color: var(--red-primary);
}
.birthday-text:nth-child(2) {
    font-size: 2.5em;
    color: var(--blue-accent);
}
.birthday-text:nth-child(3) {
    font-size: 3.5em;
    color: var(--pink-secondary);
}
.birthday-text:nth-child(4) {
    font-size: 2em;
    color: #ffe66d; 
}

@keyframes textRiseAndFade {
    0% {
        opacity: 0;
        /* Start position adjusted to push animation higher */
        transform: translateY(400px) scale(0.8); 
    }
    10% {
        opacity: 1;
        /* Final position (center point) */
        transform: translateY(0px) scale(1); 
    }
    90% {
        opacity: 1;
        transform: translateY(0px) scale(1);
    }
    100% {
        opacity: 0;
        /* End position adjusted */
        transform: translateY(-400px) scale(0.8); 
    }
}
