/* ===== FONTS ===== */
@import url('https://fonts.googleapis.com/css?family=Poiret+One');
@import url('https://fonts.googleapis.com/css?family=Dosis:800|Lobster|Pacifico|Brush+Script+MT');
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap');

/* ===== VARIABLES ===== */
:root {
    --primary-pink: #FFB6C1;
    --secondary-pink: #FFC0CB;
    --accent-red: #FF6B9D;
    --cream: #FFF5EE;
    --text-dark: #4A4A4A;
    --white: #FFFFFF;
    --card-red: #D32F2F;   
    --heart-pink: #FFB3C3; 
    --heart-bg: #FCE3E9;  
    
    /* Screen 5 Vars */
    --celeb-env-bg: #f08080;
    --celeb-card-bg: #eae2b7;
    --celeb-text: #003049;
    --celeb-heart: #d62828;
}

/* ===== BASE STYLES ===== */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

body {
    font-family: 'Montserrat', sans-serif;
    /* Use Screen 3/4 background color as base or cream */
    background: #fae1dd; 
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    /* Custom cursor */
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="%23FF6B9D"><path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/></svg>'), auto;
}

/* ===== SHARED SCREEN STYLES ===== */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    transition: opacity 0.5s ease;
    z-index: 10;
}

.screen.active {
    display: flex;
    opacity: 1;
    z-index: 20;
}

/* =========================================
   ANIMATIONS
   ========================================= */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes heartbeat {
    0% { transform: scale(1); }
    14% { transform: scale(1.1); }
    28% { transform: scale(1); }
    42% { transform: scale(1.1); }
    70% { transform: scale(1); }
}

/* =========================================
   SCREEN 1: ENVELOPE DESIGN
   ========================================= */
#screen1 { 
    background: #fff; 
    flex-direction: column; 
    perspective: 1300px; /* Essential for 3D rain */
    overflow: hidden;
}

/* --- Fallin Hearts Background (Chocolate Rains) --- */
#chocolate_rains {
    position: absolute;
    top: 50%; left: 50%;
    width: 0; height: 0; /* Centered origin */
    transform: rotateX(-15deg);
    transform-style: preserve-3d;
    z-index: 0; /* Behind envelope */
}

.heart {
    position: absolute;
    top: 50%; left: 50%;
    transform-style: preserve-3d;
    /* CSS Vars set by JS: --tx, --tz, --delay, --rot-dur */
    transform: translateX(var(--tx)) translateZ(var(--tz)) scale3d(0.5, 0.5, 0.5);
}

.movable {
    animation: drop 5000ms var(--delay) linear infinite;
    opacity: 0; /* Start hidden */
}

.ring {
    width: 300px; height: 300px;
    border-radius: 100%;
    opacity: 0;
    border: 1px solid rgba(255, 0, 0, 1);
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    animation: wave 5000ms calc(var(--delay) + 3900ms) ease-out infinite;
}

.inner {
    animation: rotation var(--rot-dur) linear infinite;
    position: absolute;
    width: 40px; height: 40px; /* Approx container size */
    top: -20px; left: -20px;
}

/* Heart Geometry */
.left {
    position: absolute;
    left: -20px;
    width: 20px; height: 20px;
    background: rgba(200, 0, 0, 1);
    border-radius: 100%;
    transform-origin: 100% 0;
}
.left::before {
    content: ''; position: absolute;
    top: 10px;
    width: 20px; height: 25px;
    background: rgba(200, 0, 0, 1);
    border-radius: 0 0 0 100%;
}

.right {
    position: absolute;
    left: 0;
    width: 20px; height: 20px;
    background: rgba(200, 0, 0, 1);
    border-radius: 100%;
    transform-origin: 0 0;
}
.right::before {
    content: ''; position: absolute;
    top: 10px;
    width: 20px; height: 25px;
    background: rgba(200, 0, 0, 1);
    border-radius: 0 0 100% 0;
}

.reverse {
    transform: translateY(70px) rotateZ(180deg);
    opacity: 0.1;
}
.reverse .left, .reverse .right {
    opacity: 0.5; 
}

/* Keyframes */
@keyframes rotation {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(360deg); }
}

@keyframes drop {
    0% { transform: translateY(-1000px); opacity: 0; }
    80% { transform: translateY(0); opacity: 3; } /* opacity > 1 acts as 1 */
    100% { transform: translateY(-40px); opacity: 0; }
}

@keyframes wave {
    0% {
        transform: translate(-50%, -50%) rotateX(90deg) scale(0) translateZ(-37px);
        opacity: 2;
    }
    100% {
        transform: translate(-50%, -50%) rotateX(90deg) scale(2) translateZ(-37px);
        opacity: 0;
    }
}

.s1-envelope-wrapper {
    position: relative;
    /* Auto-scale on mobile */
    transform: scale(min(1, 0.8)); 
    transition: transform 0.3s ease;
}

@media (min-width: 400px) {
    .s1-envelope-wrapper { transform: scale(0.9); }
}
@media (min-width: 768px) {
    .s1-envelope-wrapper { transform: scale(1); }
}

.s1-envelope-card {
    background: #fff;
    box-shadow: -1px 8px 3px 0 rgba(0, 0, 0, 0.6);
    height: 21em;
    padding: 2em;
    position: relative;
    width: 15em;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.s1-envelope-card h1 {
    font-size: 1.8em;
    font-weight: 700;
    margin: 0;
    text-transform: uppercase;
    text-align: center;
    line-height: 1.2;
    color: #333;
}

.s1-envelope-card em { color: #cc2119; font-style: normal; }

.s1-envelope {
    background: #cb231c;
    box-shadow: 0 3px 2px rgba(0, 0, 0, 0.8);
    height: 21em;
    width: 15em;
    margin: -2em -2em;
    position: absolute;
    top: 0;
    left: 0;
    transform: rotate(-8deg);
    z-index: 1;
}

.s1-envelope-heart {
    bottom: 4em;
    position: absolute;
    right: 4em;
}

.s1-envelope-heart::before,
.s1-envelope-heart::after {
    background-color: #cd231b;
    border-radius: 50px 50px 0 0;
    content: "";
    height: 25px;
    left: 15px;
    position: absolute;
    transform: rotate(-45deg);
    transform-origin: 0 100%;
    width: 15px;
}

.s1-envelope-heart::after {
    left: 0;
    transform: rotate(45deg);
    transform-origin: 100% 100%;
}

.continue-btn-container { margin-top: 3rem; z-index: 30; position: absolute; bottom: 10%; }

/* =========================================
   SCREEN 2: VALENTINE CARD DESIGN (Split Heart)
   ========================================= */
/* =========================================
   SCREEN 2: VALENTINE CARD DESIGN (Split Heart)
   ========================================= */
#screen2 {
    background-color: #ddd;
    font-family: 'Poiret One', Segoe UI Light, cursive;
    /* Flex column to stack card and button */
    display: flex;
    flex-direction: column; 
    justify-content: center;
    align-items: center;
    overflow: hidden; 
    position: relative;
}

#card {
    position: relative;
    width: 460px;
    height: 260px;
    /* Scale origin center so it shrinks in place */
    transform-origin: center center;
    cursor: pointer;
    z-index: 10;
    margin-bottom: 50px; 
}

#card .heart {
    width: 260px;
    height: 260px;
    position: absolute; /* Replaces float: left */
    top: 0;
}

#card #heart1 {
    left: 0;
    z-index: 3; /* Top layer for closed state */
}

#card #message {
    width: 200px;
    height: 200px;
    position: absolute;
    top: 0;
    left: 130px; /* Calculated from 260 (width) - 130 (margin) */
    background-color: #333;
    border-radius: 35% 0 35% 0;
    text-align: center;
    z-index: 1; /* Behind hearts */
    overflow: hidden; /* Ensure text doesn't spill if it gets weird */
}

#card #heart2 {
    left: 200px; /* Calculated from previous elements */
    top: -60px; /* Matching the negative margin */
    z-index: 3;
}

/* Ensure inner heart elements inherit positioning context if needed */
#card .heart #circle {
    height: 130px;
    width: 130px;
    border-radius: 50%;
    background-color: #D32F2F;
}

#card .heart #rec {
    margin-top: -60px;
    width: 130px;
    height: 130px;
    background-color: #D32F2F;
    border-radius: 35% 0 0 0;
}

#card .heart #half2 {
    transform: rotate(-90deg);
    margin-top: -330px;
    margin-left: -200px;
}

#card #heart2 #circle, 
#card #heart2 #rec {
    background-color: #fff;
}

#card #heart2 #half2 #rec {
    border-bottom: 1px solid #eee;
    margin-top: -61px;
}

#card #message h2 {
    font-size: 20px;
    color: #fff;
    width: 160px;
    margin-top: 60px;
    margin-left: 16px;
}

/* Initial State: Closed */
#card #heart1 {
    transform: rotate(180deg);
    animation: closeLeft 2s ease-in-out forwards;
}

#card #heart2 {
    animation: closeRight 2s ease-in-out forwards;
}

/* Hover / Click Interaction */
#card:hover #heart1,
#card.open #heart1 {
    animation: openLeft 2s ease-in-out forwards;
}

#card:hover #heart2,
#card.open #heart2 {
    animation: openRight 2s ease-in-out forwards;
}

/* Keyframes */
@keyframes closeLeft {
    from { transform: rotateY(0deg); }
    to { transform: rotateY(180deg); }
}

@keyframes openLeft {
    from { transform: rotateY(180deg); }
    to { transform: rotateY(0deg); }
}

@keyframes closeRight {
    from { transform: rotateX(0deg) rotate(180deg); }
    to { transform: rotateX(180deg); }
}

@keyframes openRight {
    0% { transform: rotateX(180deg); }
    100% { transform: rotateX(0deg) rotateZ(180deg); }
}

.hint-text {
   display: none; /* remove old hint text style */
}

/* =========================================
   SCREENS 3 & 4: HEART ANIMATION
   ========================================= */
#screen3, #screen4 { background: #ff93a6; }

#canvas-container {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0; pointer-events: none;
    opacity: 0; transition: opacity 0.5s;
}

#canvas { width: 100%; height: 100%; }
.o_heart { fill: var(--heart-pink); }
.i_heart { fill: var(--heart-bg); }

.s34-center-text {
    z-index: 100;
    position: relative;
    font-size: clamp(2rem, 5vw, 3.5rem);
    letter-spacing: 3px;
    font-family: 'Dosis', sans-serif;
    font-weight: bold;
    color: var(--heart-pink);
    background: white;
    padding: 15px 30px;
    border-radius: 5px;
    border: 3px solid var(--heart-bg);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    white-space: normal; /* Allow wrapping */
    max-width: 90%;      /* Ensure it fits on screen */
    text-align: center;
    /* Soft entrance */
    animation: fadeIn 1s ease-out;
}

/* Screen 4 Buttons */
.action-buttons {
    position: absolute; bottom: 20%;
    display: flex; gap: 20px;
    z-index: 200;
    flex-wrap: wrap;
    justify-content: center;
}

/* Button sizing for mobile */
.action-btn {
    padding: 15px 40px;
    font-size: 1.5rem;
    font-family: 'Dosis', sans-serif;
    font-weight: bold;
    border: none; border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    transition: transform 0.2s, box-shadow 0.2s;
    min-width: 120px; /* Touch target */
    min-height: 60px; /* Touch target */
}

.action-btn:active { transform: scale(0.95); }

#yesBtn { 
    background: #fff; 
    color: var(--heart-pink); 
    border: 4px solid var(--heart-bg);
    z-index: 1000; /* CRITICAL FIX for clickability */
    animation: pulse 2s infinite ease-in-out; /* Attention grabber */
}

#noBtn { 
    background: #FF6B6B; 
    color: white; 
    border: 4px solid #FF5252; 
    position: relative; 
    transition: all 0.2s ease-out; /* Smooth dodge */
    /* z-index: 999; - below Yes button */
}

/* =========================================
   SCREEN 5: CELEBRATION ENVELOPE
   ========================================= */
#screen5 { 
    background-color: #fae1dd; 
    overflow: hidden; /* Ensure particles don't scroll page */
}

#screen2 .continue-btn-container {
    position: absolute;
    bottom: 5%;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
    z-index: 20;
}

.tap-instruction {
    font-family: 'Montserrat', sans-serif;
    color: #333;
    font-size: 1.1em;
    font-weight: bold;
    animation: pulse 1.5s infinite;
    background: rgba(255,255,255,0.9);
    padding: 8px 16px;
    border-radius: 20px;
    margin-bottom: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

#celebrationCanvas {
    position: fixed; /* Fixed to viewport */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1; /* Behind envelope/card but visible */
    pointer-events: none; /* Let clicks pass through */
}

/* Renamed container to avoid conflict */
.s5-env-container {
    position: relative;
    transform: translateY(50px) scale(0.8); /* Scale down default for mobile safety */
    z-index: 10; /* Above canvas */
}
@media (min-width: 768px) {
    .s5-env-container { transform: translateY(50px) scale(1); }
}

.s5-valentines {
    position: relative;
    cursor: pointer;
    animation: s5-up 3s linear infinite;
}

@keyframes s5-up {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-30px); }
}

.s5-envelope {
    position: relative;
    width: 300px; height: 200px;
    background-color: var(--celeb-env-bg); 
}

.s5-envelope:before {
    background-color: var(--celeb-env-bg); 
    content:"";
    position: absolute;
    width: 212px; height: 212px;
    transform: rotate(45deg);
    top: -105px; left: 44px;
    border-radius: 30px 0 0 0;
}

.s5-card {
    position: absolute;
    background-color: var(--celeb-card-bg);
    width: 270px; height: 170px;
    top: 5px; left: 15px;
    box-shadow: -5px -5px 100px rgba(0,0,0,0.4); 
    z-index: 5; 
    transition: top 0.5s ease; 
}

.s5-card:before {
    content:"";
    position: absolute;
    border: 3px solid var(--celeb-text);
    border-style: dotted;
    width: 240px; height: 140px;
    left: 12px; top: 12px;
}

.s5-text {
    position: absolute;
    font-family: 'Brush Script MT', cursive;
    font-size: 26px;
    text-align: center;
    line-height: px;
    top: 19px; left: 15px; width: 240px;
    color: var(--celeb-text);
}

.s5-inner-heart {
    background-color: var(--celeb-heart);
    display: inline-block;
    height: 30px; width: 30px;
    margin: 0 10px;
    position: relative;
    top: 110px; left: 105px;
    transform: rotate(-45deg);
}
.s5-inner-heart:before, .s5-inner-heart:after {
    content: "";
    background-color: var(--celeb-heart);
    border-radius: 50%;
    height: 30px; width: 30px;
    position: absolute;
}
.s5-inner-heart:before { top: -15px; left: 0; }
.s5-inner-heart:after { left: 15px; top: 0; }

.s5-front {
    position: absolute;
    border-right: 180px solid #f4978e;
    border-top: 95px solid transparent;
    border-bottom: 100px solid transparent;
    left: 120px; top: 5px;
    width: 0; height: 0;
    z-index: 10;
}
.s5-front:before {
    position: absolute; content:"";
    border-left: 300px solid #f8ad9d;
    border-top: 195px solid transparent;
    left: -120px; top: -95px;
    width: 0; height: 0;
}

.s5-shadow {
    position: absolute;
    width: 330px; height: 25px;
    border-radius: 50%;
    background-color: rgba(0,0,0,0.3);
    top: 265px; left: -15px;
    animation: s5-scale 3s linear infinite;
    z-index: -1;
}
@keyframes s5-scale {
    0%, 100% { transform: scaleX(1); }
    50% { transform: scaleX(0.85); }
}

/* Floating Hearts for S5 */
.s5-hearts { position: absolute; top: 0; }
.one, .two, .three, .four, .five {
    background-color: red;
    display: inline-block;
    height: 10px; width: 10px;
    margin: 0 10px;
    position: relative;
    transform: rotate(-45deg);
    top: 50px;
}
.one:before, .one:after, .two:before, .two:after, 
.three:before, .three:after, .four:before, .four:after, 
.five:before, .five:after {
    content: ""; background-color: red;
    border-radius: 50%; height: 10px; width: 10px;
    position: absolute;
}
.one:before { top: -5px; left: 0; } .one:after { left: 5px; top: 0; }

.one { left: 10px; animation: s5-heart 1s ease-out infinite; }
.two { left: 30px; animation: s5-heart 2s ease-out infinite; }
.three { left: 50px; animation: s5-heart 1.5s ease-out infinite; }
.four { left: 70px; animation: s5-heart 2.3s ease-out infinite; }
.five { left: 90px; animation: s5-heart 1.7s ease-out infinite; }

@keyframes s5-heart {
    0% { transform: translateY(0) rotate(-45deg) scale(0.3); opacity: 1; }
    100% { transform: translateY(-150px) rotate(-45deg) scale(1.3); opacity: 0.5; }
}

/* Common Components */
.next-btn {
    margin-top: 2rem;
    padding: 10px 30px;
    border-radius: 30px;
    background: var(--accent-red);
    color: white;
    border: none;
    cursor: pointer;
    font-family: 'Montserrat', sans-serif;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    z-index: 50;
    font-size: 1.1rem;
    animation: pulse 3s infinite ease-in-out;
}
