:root {
    --primary: #ff4d6d;
    --primary-dark: #c9184a;
    --secondary: #fff0f3;
    --accent: #ffb3c1;
    --bg-color: #fff5f5;
    --text-color: #590d22;
    --envelope-color: #ff758f;
    --paper-color: #f8edeb;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-color);
    font-family: 'Poppins', sans-serif;
    overflow: hidden;
    background: radial-gradient(circle at center, #fff0f3 0%, #ffccd5 100%);
}

.container {
    position: relative;
    z-index: 10;
}

/* --- Envelope Styles --- */
.envelope-wrapper {
    cursor: pointer;
    perspective: 1000px;
}

.envelope {
    position: relative;
    width: 300px;
    height: 200px;
    background-color: var(--envelope-color);
    box-shadow: 0 10px 30px rgba(89, 13, 34, 0.2);
    transition: transform 0.5s ease;
}

.envelope .front {
    position: absolute;
    width: 0;
    height: 0;
    z-index: 3;
}

.envelope .flap {
    border-left: 150px solid transparent;
    border-right: 150px solid transparent;
    border-top: 110px solid var(--envelope-color);
    transform-origin: top;
    transition: transform 0.4s 0.2s ease;
    z-index: 4;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.1));
}

.envelope .pocket {
    border-left: 150px solid var(--accent);
    border-right: 150px solid var(--accent);
    border-bottom: 180px solid var(--primary);
    bottom: 0;
    z-index: 3;
}

/* --- Letter Styles --- */
.letter {
    position: absolute;
    top: 5px;
    left: 10px;
    width: 280px;
    height: 180px;
    background-color: var(--paper-color);
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 2;
    transition: transform 0.6s ease, top 0.6s ease;
}

.letter-content {
    border: 1px solid rgba(255, 77, 109, 0.2);
    height: 100%;
    padding: 15px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    overflow: hidden;
}

.letter-title {
    font-family: 'Dancing Script', cursive;
    color: var(--primary-dark);
    font-size: 1.5rem;
    margin-bottom: 15px;
}

.letter-text {
    font-family: 'Playfair Display', serif;
    font-size: 0.9rem;
    line-height: 1.4;
    color: var(--text-color);
    margin-bottom: 10px;
}

.letter-signature {
    font-family: 'Dancing Script', cursive;
    font-size: 1.2rem;
    color: var(--primary-dark);
    align-self: flex-end;
}

/* --- Wax Seal --- */
.seal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    background: radial-gradient(circle, #8a0e28 0%, #590d22 100%);
    border-radius: 50%;
    z-index: 5;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3), inset 0 2px 5px rgba(255, 255, 255, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
}

.seal::after {
    content: '❤';
    color: var(--accent);
    font-size: 1.5rem;
}

.envelope.open .seal {
    opacity: 0;
    pointer-events: none;
}

/* --- Open Animation --- */
.envelope.open .flap,
.envelope.open .pocket,
.envelope.open .seal {
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.envelope.open {
    background-color: transparent !important;
    box-shadow: none !important;
}

.envelope.open .letter {
    transform: translate(-50%, -50%) scale(1.1);
    height: 520px;
    width: 350px;
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 100;
    padding: 40px;
    box-shadow: 0 20px 50px rgba(89, 13, 34, 0.2);
    transition: all 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.envelope.open .letter-content {
    justify-content: flex-start;
    padding: 0px;
    height: 100%;
    overflow-y: auto;
}

.envelope.open .letter-text {
    font-size: 1.1rem;
    margin-bottom: 20px;
}

/* Close Button in Letter */
.close-btn {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--primary);
    color: white;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
    z-index: 101;
}

.envelope.open .close-btn {
    display: flex;
}

.close-btn:hover {
    background: var(--primary-dark);
}

/* --- Instruction --- */
.instruction {
    text-align: center;
    margin-top: 40px;
    color: var(--primary-dark);
    font-weight: 600;
    letter-spacing: 1px;
    animation: bounce 2s infinite;
}

@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-10px);
    }

    60% {
        transform: translateY(-5px);
    }
}

/* --- Hearts Animation --- */
.hearts {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 6;
    pointer-events: none;
}

.heart {
    position: absolute;
    width: 20px;
    height: 20px;
    background-color: var(--primary);
    transform: rotate(-45deg);
    opacity: 0;
}

.heart::before,
.heart::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background-color: var(--primary);
    border-radius: 50%;
}

.heart::before {
    top: -10px;
    left: 0;
}

.heart::after {
    top: 0;
    right: -10px;
}

.envelope.open .heart {
    animation: heart-pop 1s forwards;
}

.heart.a1 {
    animation-delay: 0.2s;
    left: -20px;
}

.heart.a2 {
    animation-delay: 0.4s;
    left: 0px;
}

.heart.a3 {
    animation-delay: 0.6s;
    left: 20px;
}

@keyframes heart-pop {
    0% {
        transform: translate(0, 0) rotate(-45deg) scale(0);
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    100% {
        transform: translate(var(--tw-x, 0), -120px) rotate(-45deg) scale(1.5);
        opacity: 0;
    }
}

.heart.a1 {
    --tw-x: -80px;
}

.heart.a2 {
    --tw-x: 0px;
}

.heart.a3 {
    --tw-x: 80px;
}

/* --- Background Hearts --- */
.background-decor {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.floating-heart {
    position: absolute;
    bottom: -50px;
    width: 30px;
    height: 30px;
    background-color: rgba(255, 77, 109, 0.1);
    transform: rotate(-45deg);
    animation: float 10s infinite linear;
}

.floating-heart::before,
.floating-heart::after {
    content: '';
    position: absolute;
    width: 30px;
    height: 30px;
    background-color: inherit;
    border-radius: 50%;
}

.floating-heart::before {
    top: -15px;
    left: 0;
}

.floating-heart::after {
    top: 0;
    right: -15px;
}

@keyframes float {
    0% {
        transform: translateY(0) rotate(-45deg) scale(1);
        opacity: 0;
    }

    10% {
        opacity: 0.5;
    }

    90% {
        opacity: 0.5;
    }

    100% {
        transform: translateY(-120vh) rotate(-45deg) scale(1.2);
        opacity: 0;
    }
}