/* ==========================================================================
   VARIABLES & THEME
   ========================================================================== */
:root {
    /* Colors - Soft, dreamy, warm */
    --bg-color: #fcf4f4;
    --bg-gradient: linear-gradient(135deg, #fdf6f5 0%, #f7e6e9 100%);
    --primary-color: #e5989b;
    --secondary-color: #b5838d;
    --accent-color: #ffb4a2;
    --text-color: #6d597a;
    --text-light: #9e8aab;
    --white: #ffffff;
    
    /* Typography */
    --font-heading: 'Playfair Display', serif;
    --font-body: 'Inter', sans-serif;
    --font-script: 'Caveat', cursive;
    
    /* Animation timing */
    --transition-fast: 0.3s ease;
    --transition-normal: 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   RESET & GLOBAL
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 17px; /* Base scale for mobile */
}

@media (min-width: 400px) {
    html {
        font-size: 18.5px; /* Slightly larger on wider phones/desktop */
    }
}

body {
    font-family: var(--font-body);
    background: var(--bg-gradient);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: hidden; /* Prevent scroll on non-scrollable scenes */
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

/* Base App Container */
.app-container {
    position: relative;
    width: 100%;
    max-width: 500px; /* Mobile optimal, centered on desktop */
    margin: 0 auto;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport for mobile Safari/Chrome */
    overflow: hidden;
}

/* Scene Setup */
.scene {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
    z-index: 10;
    padding: 24px;
}

.scene.active {
    opacity: 1;
    visibility: visible;
    z-index: 20;
}

/* Utility Classes */
.flex-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mt-top {
    margin-top: 40px;
}

/* Typography */
h1.main-title, h1.final-title {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    font-weight: 600;
    color: var(--secondary-color);
    line-height: 1.2;
    text-align: center;
    margin-bottom: 20px;
}

.highlight {
    color: var(--primary-color);
    font-style: italic;
}

.scene-subtitle {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--secondary-color);
    margin-bottom: 40px;
    text-align: center;
}

.instruction-text {
    font-size: 0.9rem;
    color: var(--text-light);
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* Buttons */
.primary-btn {
    background: var(--primary-color);
    color: var(--white);
    border: none;
    padding: 14px 32px;
    border-radius: 30px;
    font-size: 1rem;
    font-weight: 500;
    font-family: var(--font-body);
    box-shadow: 0 10px 20px rgba(229, 152, 155, 0.3);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    margin-top: 30px;
}

.primary-btn:active {
    transform: scale(0.95);
}

.outline-btn {
    background: transparent;
    color: var(--secondary-color);
    border: 2px solid var(--secondary-color);
    padding: 12px 28px;
    border-radius: 30px;
    font-size: 1rem;
    font-weight: 500;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-top: 40px;
}

.outline-btn:active {
    transform: scale(0.95);
    background: rgba(181, 131, 141, 0.1);
}

/* ==========================================================================
   SCENE 1: GIFT BOX
   ========================================================================== */
.gift-wrapper {
    margin: 60px 0;
    cursor: pointer;
    perspective: 1000px;
    transform: scale(1.25);
}

.gift-box {
    position: relative;
    width: 140px;
    height: 140px;
    transition: transform 0.3s ease;
}

.gift-wrapper:active .gift-box {
    transform: scale(0.9);
}

/* Shaking animation class added via JS */
.gift-box.shake {
    animation: shake 0.5s ease-in-out infinite;
}

/* Open state added via JS */
.gift-box.open .gift-lid {
    transform: translateY(-80px) rotate(-15deg);
    opacity: 0;
}
.gift-box.open .gift-body {
    transform: scale(0.95);
    opacity: 0.8;
}

.gift-lid {
    position: absolute;
    top: 0;
    left: -10px;
    width: 160px;
    height: 35px;
    background: var(--primary-color);
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    z-index: 2;
    transition: all 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ribbon-bow {
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 30px;
    background: var(--secondary-color);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 70%, 0 100%);
}

.gift-body {
    position: absolute;
    top: 35px;
    left: 0;
    width: 140px;
    height: 105px;
    background: var(--accent-color);
    border-radius: 0 0 8px 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    transition: all 0.5s ease;
}

.ribbon-vertical {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 25px;
    height: 100%;
    background: var(--secondary-color);
}
.gift-lid::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 25px;
    height: 100%;
    background: var(--secondary-color);
}

/* ==========================================================================
   SCENE 3: SURPRISE TEXT
   ========================================================================== */
.typewriter-container {
    min-height: 80px;
    margin: 20px 0;
    text-align: center;
}

#typewriter-text {
    font-family: var(--font-script);
    font-size: 1.8rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-color);
}

.cursor {
    display: inline-block;
    width: 2px;
    height: 1.1rem;
    background-color: var(--primary-color);
    animation: blink 1s step-end infinite;
    vertical-align: middle;
    margin-left: 2px;
}

/* ==========================================================================
   SCENE 4: PHOTO GALLERY
   ========================================================================== */
#scene-4 {
    overflow-y: auto; /* Allow scrolling for photos */
    padding-bottom: 100px;
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

/* Hide scrollbar for Chrome, Safari and Opera */
#scene-4::-webkit-scrollbar {
    display: none;
}

.photo-gallery {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    margin-top: 30px;
    width: 100%;
}

.polaroid {
    background: var(--white);
    padding: 12px 12px 24px 12px;
    border-radius: 4px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.08);
    width: 80%;
    max-width: 280px;
    transform: rotate(var(--rot)) translateY(50px);
    opacity: 0;
    transition: all 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.polaroid.show {
    transform: rotate(var(--rot)) translateY(0);
    opacity: 1;
}

.img-wrapper {
    width: 100%;
    aspect-ratio: 1/1; /* Square photos */
    overflow: hidden;
    background: #eee;
}

.img-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.caption {
    font-family: var(--font-script);
    text-align: center;
    margin-top: 15px;
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--text-color);
}

.bottom-action {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20px;
    background: linear-gradient(to top, var(--bg-color) 60%, transparent);
    display: flex;
    justify-content: center;
    z-index: 100;
}

/* ==========================================================================
   SCENE 5: LETTER
   ========================================================================== */
.envelope-wrapper {
    position: relative;
    cursor: pointer;
    width: 340px;
    height: 210px;
    margin: 20px 0;
    transition: transform 0.3s ease;
}

.envelope-wrapper:active {
    transform: scale(0.95);
}

.envelope {
    position: absolute;
    width: 100%;
    height: 100%;
    background: #ffd6db;
    border-radius: 8px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.1);
}

.envelope-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 110px 170px 0 170px;
    border-color: var(--primary-color) transparent transparent transparent;
    transform-origin: top;
    transition: transform 0.6s 0.2s, z-index 0s 0.6s;
    z-index: 3;
}

.envelope-body {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 8px;
    border-style: solid;
    border-width: 0 170px 100px 170px;
    border-color: transparent #ffccd2 #ffc2c9 #ffccd2;
    z-index: 2;
}

.heart-sticker {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    z-index: 4;
    transition: opacity 0.3s;
}

.letter {
    position: absolute;
    bottom: 0;
    left: 5%;
    width: 90%;
    height: 90%;
    background: var(--white);
    border-radius: 4px;
    padding: 20px 20px 20px 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    z-index: 1;
    transition: transform 0.8s 0.5s;
    overflow-y: auto;
}

/* Custom scrollbar for letter */
.letter::-webkit-scrollbar {
    width: 4px;
}
.letter::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
}

.letter p {
    font-size: 1.05rem; /* Increased font size */
    line-height: 1.5;
    margin-bottom: 12px;
    opacity: 0;
    transition: opacity 0.5s 1.2s;
}

.letter .signature {
    margin-top: 15px;
    font-family: var(--font-heading);
    font-style: italic;
    color: var(--primary-color);
}

/* Open State */
.envelope-wrapper.open .envelope-flap {
    transform: rotateX(180deg);
    z-index: 0;
}

.envelope-wrapper.open .heart-sticker {
    opacity: 0;
}

.envelope-wrapper.open .letter {
    transform: translateY(-60px);
    z-index: 3;
    height: 350px; /* Safe height for all mobile screens */
    padding-bottom: 20px; /* Reset padding since we use overflow-y: auto */
    box-shadow: 0 15px 30px rgba(0,0,0,0.15);
}

.envelope-wrapper.open .letter p {
    opacity: 1;
}
.envelope-wrapper.open {
    cursor: default;
}
.envelope-wrapper.open:active {
    transform: none;
}

/* ==========================================================================
   SCENE 6: CAKE
   ========================================================================== */
.cake-wrapper {
    position: relative;
    width: 160px;
    height: 160px;
    margin: 50px 0;
    transform: scale(1.25);
}

.cake {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

.cake-base {
    width: 140px;
    height: 60px;
    background: var(--accent-color);
    border-radius: 8px;
    position: relative;
}

.cake-icing {
    width: 150px;
    height: 25px;
    background: var(--white);
    border-radius: 12px;
    position: absolute;
    top: -15px;
    left: -5px;
}

.drip {
    width: 15px;
    height: 30px;
    background: var(--white);
    border-radius: 10px;
    position: absolute;
    top: 10px;
}
.drip:nth-child(1) { left: 10px; height: 25px; }
.drip:nth-child(2) { left: 40px; height: 35px; }
.drip:nth-child(3) { left: 70px; height: 20px; }
.drip:nth-child(4) { left: 100px; height: 30px; }
.drip:nth-child(5) { left: 125px; height: 15px; }

.candle {
    position: absolute;
    top: -55px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 40px;
    background: repeating-linear-gradient(
        -45deg,
        #fff,
        #fff 5px,
        var(--primary-color) 5px,
        var(--primary-color) 10px
    );
    border-radius: 4px;
    cursor: pointer;
}

.flame {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 14px;
    height: 20px;
    background: #ffcf00;
    border-radius: 50% 50% 20% 20%;
    box-shadow: 0 0 15px #ffcf00;
    animation: flicker 0.5s infinite alternate;
    transition: opacity 0.3s;
}

.smoke {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 10px;
    background: rgba(150, 150, 150, 0.5);
    border-radius: 50%;
    filter: blur(2px);
    animation: rise 1.5s ease-out forwards;
}

.wish-made-text {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--primary-color);
    margin-top: 10px;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* ==========================================================================
   SCENE 7: FINAL
   ========================================================================== */
.final-text {
    font-family: var(--font-script);
    font-size: 1.8rem;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 40px;
    color: var(--text-color);
}

.final-signature {
    font-family: var(--font-script);
    font-size: 1.5rem;
    color: var(--primary-color);
    margin-top: 5px;
    font-weight: 600;
}

/* ==========================================================================
   MUSIC CONTROL
   ========================================================================== */
#music-control {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    transition: transform 0.3s;
}
#music-control:active {
    transform: scale(0.9);
}
#music-control.paused {
    opacity: 0.6;
}

/* ==========================================================================
   ANIMATIONS & EFFECTS
   ========================================================================== */
.fade-in {
    opacity: 0;
    transform: translateY(20px);
    animation: fadeIn 0.8s ease forwards;
}

.delay-1 { animation-delay: 0.5s; }
.delay-2 { animation-delay: 1.2s; }
.delay-3 { animation-delay: 2.0s; }
.delay-4 { animation-delay: 2.8s; }

.pulse {
    animation: pulse 2s infinite;
}

@keyframes fadeIn {
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

@keyframes shake {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(3deg); }
    50% { transform: rotate(-3deg); }
    75% { transform: rotate(3deg); }
}

@keyframes blink {
    50% { opacity: 0; }
}

@keyframes flicker {
    0% { transform: translateX(-50%) scale(1); opacity: 0.9; }
    100% { transform: translateX(-50%) scale(1.1); opacity: 1; box-shadow: 0 0 20px #ffcf00; }
}

@keyframes rise {
    0% { transform: translate(-50%, 0) scale(1); opacity: 0.8; }
    100% { transform: translate(-50%, -50px) scale(3); opacity: 0; }
}

@keyframes popIn {
    0% { opacity: 0; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1); }
}

/* Background Particles (Sparkles/Hearts) */
#particles-container, #confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.particle {
    position: absolute;
    background: var(--primary-color);
    border-radius: 50%;
    opacity: 0;
    animation: floatParticle linear forwards;
}

@keyframes floatParticle {
    0% { transform: translateY(0) scale(0); opacity: 0; }
    20% { opacity: 0.6; }
    80% { opacity: 0.6; }
    100% { transform: translateY(-100px) scale(1); opacity: 0; }
}

.confetti {
    position: absolute;
    width: 8px;
    height: 8px;
    animation: fallConfetti ease-in forwards;
}

@keyframes fallConfetti {
    0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(300px) rotate(360deg); opacity: 0; }
}
