/* Custom Fonts */
@import url('https://fonts.googleapis.com/css2?family=Zhi+Mang+Xing&family=Noto+Sans+SC:wght@300;400;500;700&display=swap');

/* Import Custom Local Fonts */
/* Removed heavy local TTF fonts to improve loading speed. Using Google Fonts instead. */

/* Base Styles */
html {
    scroll-behavior: smooth;
    overflow-y: hidden;
    height: 100%;
}

body {
    -webkit-tap-highlight-color: transparent; /* Remove mobile tap highlight */
    background-color: #f4e6e6; /* Extremely low saturation warm grey-pink */
    overflow-x: hidden;
    overflow-y: hidden; /* Prevent scrolling initially */
    transition: overflow-y 0.5s ease;
    font-family: 'ZCOOL XiaoWei', 'Noto Serif SC', 'Ma Shan Zheng', 'Courier New', Courier, monospace;
    height: 100%;
}

html.can-scroll, body.can-scroll {
    overflow-y: auto !important;
    height: auto !important;
    overflow-x: hidden;
}

/* Scrollbar Hide for webkit */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: #fdfbfb; 
}
::-webkit-scrollbar-thumb {
    background: #fce7f3; 
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: #f472b6; 
}

/* Animations */
@keyframes spin-slow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.animate-spin-slow {
    animation: spin-slow 4s linear infinite;
    will-change: transform;
}

@keyframes pulse-heart {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
.animate-pulse-heart {
    animation: pulse-heart 2s ease-in-out infinite;
    will-change: transform;
}

/* Typography Enhancements */
.font-handwriting {
    font-family: 'Caveat', 'Long Cang', 'Zhi Mang Xing', cursive;
    letter-spacing: 2px;
    text-shadow: 2px 4px 10px rgba(244, 143, 177, 0.2);
}

.font-sans {
    font-family: 'Noto Sans SC', sans-serif;
}

.font-serif-sc {
    font-family: 'ZCOOL XiaoWei', 'Noto Serif SC', serif;
}

/* =========================================
   Pure CSS Envelope Structure
   ========================================= */

.envelope-section {
    perspective: 1500px;
    min-height: 100vh; /* Ensure the section can scroll if content exceeds screen height */
    height: auto; /* Let it grow naturally */
    /* Add a subtle gradient background to the section to blend with the body */
    background: linear-gradient(to bottom, #f4e6e6 0%, #fdfbfb 40%, #fdfbfb 60%, #f4e6e6 100%);
    padding-bottom: 120px; /* Add extra padding at the bottom so it doesn't feel cramped */
}

.css-envelope {
    position: relative;
    display: block;
    width: 280px; /* Smaller width for standard mobile screens */
    height: 190px; /* Proportionally smaller height */
    background-color: #f4e6e6; /* Extremely low saturation pink/beige */
    background-image: linear-gradient(to bottom right, #faf0f0, #eedbdb);
    border-radius: 6px;
    box-shadow: 0 15px 35px rgba(200, 180, 180, 0.3);
    transition: transform 0.3s ease;
    z-index: 10;
    margin-bottom: 20px; /* Give some space at the bottom */
}

@media (min-width: 375px) {
    .css-envelope {
        width: 320px;
        height: 220px;
    }
}

@media (min-width: 768px) {
    .css-envelope {
        width: 500px;
        height: 320px;
    }
}

.css-envelope:hover {
    transform: translateY(-5px);
}

/* Envelope Front Pocket (Using Borders for Triangles) */
.css-pocket {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 0;
    
    /* Mobile sizes */
    border-left: 140px solid #ecdcdc; /* Very soft dusty pink */
    border-right: 140px solid #ecdcdc;
    border-bottom: 105px solid #e2caca; /* Slightly darker for depth */
    border-top: 85px solid transparent;
    
    border-radius: 0 0 6px 6px;
    z-index: 3; /* Keep in front of letter */
    pointer-events: none;
}

@media (min-width: 375px) {
    .css-pocket {
        border-left: 160px solid #ecdcdc;
        border-right: 160px solid #ecdcdc;
        border-bottom: 120px solid #e2caca;
        border-top: 100px solid transparent;
    }
}

@media (min-width: 768px) {
    .css-pocket {
        border-left: 250px solid #ecdcdc;
        border-right: 250px solid #ecdcdc;
        border-bottom: 180px solid #e2caca;
        border-top: 140px solid transparent;
    }
}

/* Envelope Top Flap */
.css-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    
    /* Mobile sizes */
    border-left: 140px solid transparent;
    border-right: 140px solid transparent;
    border-top: 105px solid #ebdada; /* Matches pocket left/right mostly */
    border-bottom: 0 solid transparent;
    
    transform-origin: top; /* Rotate from the top edge */
    z-index: 4; /* Initially on top of everything */
    pointer-events: none;
}

@media (min-width: 375px) {
    .css-flap {
        border-left: 160px solid transparent;
        border-right: 160px solid transparent;
        border-top: 130px solid #ebdada;
    }
}

@media (min-width: 768px) {
    .css-flap {
        border-left: 250px solid transparent;
        border-right: 250px solid transparent;
        border-top: 190px solid #ebdada;
    }
}

/* Wax Seal Image */
.css-flap::after {
    content: '';
    position: absolute;
    left: -30px; /* Center horizontally */
    top: -45px;  /* Move it slightly higher */
    width: 60px;
    height: 60px;
    background-image: url('https://cdn.pixabay.com/photo/2016/09/24/09/34/wax-seal-1691233_1280.png'); /* A nice real wax seal image */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 50%;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.15));
}

@media (min-width: 375px) {
    .css-flap::after {
        left: -35px;
        top: -55px;
        width: 70px;
        height: 70px;
    }
}

@media (min-width: 768px) {
    .css-flap::after {
        left: -45px; 
        top: -65px;  
        width: 90px;
        height: 90px;
    }
}

/* Letter Content */
.css-letter {
    position: absolute;
    /* Change from bottom alignment to top alignment to grow downwards */
    top: 10px;
    left: 10px;
    width: 260px; /* Reduced to fit the smaller 280px envelope */
    height: 180px; /* Force a fixed height initially so it stays hidden behind the flap */
    background-color: #ffffff;
    border-radius: 4px;
    z-index: 2; /* Behind pocket(3) and flap(4) initially */
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    will-change: transform, z-index, height;
    overflow: hidden; /* Hide content overflowing initially */
    transform-origin: top center; /* Ensure transformations and height changes grow downwards */
    /* Remove padding bottom here so button isn't cut off */
}

@media (min-width: 375px) {
    .css-letter {
        width: 300px;
        height: 200px;
    }
}

@media (min-width: 768px) {
    .css-letter {
        left: 20px;
        width: 460px;
        height: 300px;
    }
}

/* ==============================================
   CSS Cake Animation 
   ============================================== */

.cake-area {
    position: relative;
    width: 100%;
    height: 500px; /* Match SVG height */
}

#cake {
    display: block;
    position: absolute;
    bottom: 100px; 
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 500px;
    z-index: 10;
}

/* Hide SVG paths initially to prevent them from showing before animation starts */
#cake path {
    opacity: 0;
}

.cake-area.start-animation #cake path {
    animation: fade-in-svg 0.1s forwards;
}

/* Precise timing based on SVG <animate> begin attributes */
.cake-area.start-animation #cake path:nth-of-type(4) { /* Cream */
    animation: fade-in-svg 0.1s 1.6s forwards; 
}
.cake-area.start-animation #cake path:nth-of-type(3) { /* Top layer */
    animation: fade-in-svg 0.1s 0s forwards; 
}
.cake-area.start-animation #cake path:nth-of-type(2) { /* Middle layer */
    animation: fade-in-svg 0.1s 0.8s forwards; 
}
.cake-area.start-animation #cake path:nth-of-type(1) { /* Bottom layer */
    animation: fade-in-svg 0.1s 1.3s forwards; 
}

@keyframes fade-in-svg {
    0% { opacity: 0; }
    1% { opacity: 1; }
    100% { opacity: 1; }
}

/* Candle Wrapper */
.velas {
    background: #ffffff;
    border-radius: 10px;
    position: absolute;
    bottom: 185px;
    left: 50%;
    margin-left: -2.5px;
    width: 5px;
    height: 35px;
    transform: translateY(-300px);
    backface-visibility: hidden;
    z-index: 20;
    opacity: 0;
}

.cake-area.start-animation .velas {
    animation: drop-in 500ms 4s ease-out forwards;
}

@keyframes drop-in {
    0% { transform: translateY(-300px); opacity: 0; }
    1% { transform: translateY(-300px); opacity: 1; }
    100% { transform: translateY(0); opacity: 1; }
}

.velas:after,
.velas:before {
    background: rgba(255, 0, 0, 0.4);
    content: "";
    position: absolute;
    width: 100%;
    height: 2.22222222px;
}

.velas:after { top: 25%; left: 0; }
.velas:before { top: 45%; left: 0; }

/* Fire */
.fuego {
    border-radius: 100%;
    position: absolute;
    top: -20px;
    left: 70%;
    margin-left: -2.2px;
    width: 6.66666667px;
    height: 18px;
    opacity: 0; /* Hide initially */
}

.cake-area.start-animation .fuego {
    animation-delay: 4.5s;
    animation-fill-mode: forwards;
}

.cake-area.start-animation .fuego:nth-child(1) { animation: fuego 2s 4.5s infinite forwards; }
.cake-area.start-animation .fuego:nth-child(2) { animation: fuego 1.5s 4.5s infinite forwards; }
.cake-area.start-animation .fuego:nth-child(3) { animation: fuego 1s 4.5s infinite forwards; }
.cake-area.start-animation .fuego:nth-child(4) { animation: fuego 0.5s 4.5s infinite forwards; }
.cake-area.start-animation .fuego:nth-child(5) { animation: fuego 0.2s 4.5s infinite forwards; }

/* Animation Fire */
@keyframes fuego {
    0% {
        opacity: 1;
        background: rgba(254, 248, 97, 0.5);
        box-shadow: 0 0 40px 10px rgba(248, 233, 209, 0.2);
        transform: translateY(0) scale(1);
    }
    50% {
        opacity: 1;
        background: rgba(255, 50, 0, 0.1);
        box-shadow: 0 0 40px 20px rgba(248, 233, 209, 0.2);
        transform: translateY(-20px) scale(0);
    }
    100% {
        opacity: 1;
        background: rgba(254, 248, 97, 0.5);
        box-shadow: 0 0 40px 10px rgba(248, 233, 209, 0.2);
        transform: translateY(0) scale(1);
    }
}

.come {
    opacity: 0;
}

.cake-area.start-animation .come {
    animation: coming 2s 0.4s forwards;
}

@keyframes coming {
    from { opacity: 0; }
    to { opacity: 1; }
}

.happy {
    opacity: 0;
    transform: translateY(20px);
}

.happy.animate-in {
    animation: happybirthdays 2s 4.5s forwards;
}

@keyframes happybirthdays {
    0% { opacity: 0; transform: translateY(20px); }
    100% { opacity: 1; transform: translateY(0); }
}