:root {
    --bg-color: #dfd7cc;
    --envelope-color: #2b4c3f; /* Elegant Deep Emerald */
    --envelope-flap: #1f372e;
    --stamp-color: #b52b2b; /* Deep Wax Red */
    --card-bg: #fffcf7;
    --text-color: #333;
}

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

body {
    background-color: var(--bg-color);
    font-family: 'Georgia', serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    perspective: 1000px; /* Crucial for 3D flap flip */
}

.container {
    position: relative;
    width: 100%;
    max-width: 420px;
    height: 600px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Envelope Wrapper */
.envelope-wrapper {
    position: relative;
    width: 380px;
    height: 280px;
    transition: transform 0.5s ease;
}

.envelope {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: var(--envelope-color);
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
    z-index: 2;
}

/* 3D Flap */
.flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 190px solid transparent;
    border-right: 190px solid transparent;
    border-top: 140px solid var(--envelope-flap);
    transform-origin: top;
    transition: transform 0.6s ease 0.2s; /* delays flap until stamp animation finishes */
    z-index: 4;
}

/* Bottom Pocket of Envelope */
.pocket {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 190px solid transparent;
    border-right: 190px solid transparent;
    border-bottom: 150px solid var(--envelope-color);
    filter: brightness(0.95);
    z-index: 3;
}

/* Wax Stamp Button */
.stamp {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -30%);
    width: 80px;
    height: 80px;
    background-color: var(--stamp-color);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #e6c687;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3), inset 0 0 8px rgba(0,0,0,0.4);
    cursor: pointer;
    z-index: 5;
    transition: transform 0.3s ease, opacity 0.5s ease;
}

.stamp:active {
    transform: translate(-50%, -30%) scale(0.9);
}

.initials {
    font-weight: bold;
    font-size: 1.1rem;
    letter-spacing: 1px;
}

.click-text {
    font-size: 0.5rem;
    text-transform: uppercase;
    margin-top: 4px;
    opacity: 0.8;
}

/* The Secret Invitation Card */
.invitation-card {
    position: absolute;
    top: 10px;
    left: 15px;
    width: 350px;
    height: 260px;
    background-color: var(--card-bg);
    padding: 30px 20px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    z-index: 1;
    transition: transform 0.8s cubic-bezier(0.19, 1, 0.22, 1) 0.6s, height 0.8s cubic-bezier(0.19, 1, 0.22, 1) 0.6s;
    overflow: hidden;
    border-radius: 4px;
}

.card-content {
    text-align: center;
    color: var(--text-color);
    opacity: 0;
    transition: opacity 0.5s ease 1s;
}

.names {
    font-size: 1.8rem;
    margin: 10px 0;
    color: var(--envelope-color);
}

.divider {
    border: none;
    border-top: 1px solid #d4af37; /* Gold accent */
    width: 60%;
    margin: 15px auto;
}

.btn {
    margin-top: 15px;
    padding: 8px 16px;
    background: var(--envelope-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* --- ANIMATION STATES TRIPPED BY JS --- */

.envelope-wrapper.is-open .stamp {
    transform: translate(-50%, -30%) scale(0);
    opacity: 0;
    pointer-events: none;
}

.envelope-wrapper.is-open .flap {
    transform: rotateX(180deg);
    z-index: 1; /* Drop behind the card once opened */
}

.envelope-wrapper.is-open .invitation-card {
    transform: translateY(-200px); /* Slides up out of the envelope */
    height: 480px; /* Expands visually into a full card/scroll */
    z-index: 4; /* Sits proudly in front of envelope */
}

.envelope-wrapper.is-open .card-content {
    opacity: 1;
}

/* Move the whole unit down a bit when opened to balance screen space */
.envelope-wrapper.is-open {
    transform: translateY(100px);
}