:root {
    --bg-color: #fdfbf7;
    /* Warm off-white background */
    --envelope-color: #e8f3e8;
    /* Soft Mint/Sage */
    --envelope-shadow: rgba(0, 0, 0, 0.1);
    --card-bg: #fffcf5;
    /* Creamy card background */
    --text-primary: #4a5d4a;
    /* Dark green/grey for text */
    --text-accent: #d4af37;
    /* Gold accent */
    --seal-color: #f3e5ab;
    /* Pale Gold/Cream wax */
    --font-script: 'Dancing Script', cursive;
    --font-serif: 'Playfair Display', serif;
    --font-sans: 'Montserrat', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-color);
    background-image: url('background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    font-family: var(--font-sans);
}

.container {
    perspective: 1000px;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.envelope-wrapper {
    position: relative;
    width: 320px;
    height: 220px;
    cursor: pointer;
}

.envelope {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: var(--envelope-color);
    box-shadow: 0 10px 30px var(--envelope-shadow);
    transform-style: preserve-3d;
    transition: transform 0.8s ease;
}

/* Flaps */
.flap {
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
    z-index: 2;
}

.top-flap {
    top: 0;
    left: 0;
    border-width: 110px 160px 0 160px;
    border-color: #dbe9db transparent transparent transparent;
    /* Slightly darker mint */
    transform-origin: top;
    transition: transform 0.6s ease 0.2s, z-index 0.2s;
    z-index: 5;
}

.right-flap {
    top: 0;
    right: 0;
    border-width: 110px 160px 110px 0;
    border-color: transparent #e1efe1 transparent transparent;
    z-index: 3;
}

.bottom-flap {
    bottom: 0;
    left: 0;
    border-width: 0 160px 110px 160px;
    border-color: transparent transparent #e8f3e8 transparent;
    z-index: 4;
}

.left-flap {
    top: 0;
    left: 0;
    border-width: 110px 0 110px 160px;
    border-color: transparent transparent transparent #e1efe1;
    z-index: 3;
}

/* Wax Seal - LARGE AND CENTERED */
.wax-seal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100px;
    /* Huge size as requested */
    height: 100px;
    background: var(--seal-color);
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2), inset 0 2px 5px rgba(255, 255, 255, 0.5);
    z-index: 6;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-serif);
    font-weight: bold;
    color: #c5a028;
    font-size: 2.5rem;
    /* Large font */
    border: 2px solid rgba(255, 255, 255, 0.3);
    transition: opacity 0.4s ease;
    white-space: nowrap;
    /* Force single line */
}

/* Card - FIXED POSITION POP-UP */
.card {
    position: fixed;
    /* Fix to viewport */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    /* Start smaller */
    opacity: 0;
    z-index: 9999;
    /* Max z-index */
    height: 85vh;
    /* Increased from 80vh */
    max-height: 650px;
    /* Increased from 600px */
    width: 90vw;
    max-width: 400px;
    background: var(--card-bg);
    border-radius: 10px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    text-align: center;
    pointer-events: none;
    /* Click through when hidden */
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* Bouncy pop */
}

/* Open State for Card */
.envelope-wrapper.open .card {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    /* Pop to full size */
    pointer-events: all;
}

.envelope-wrapper.open .top-flap {
    transform: rotateX(180deg);
    z-index: 1;
}

.envelope-wrapper.open .wax-seal {
    opacity: 0;
    pointer-events: none;
}

/* Card Content & Phases */
.card-content {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.phase-section {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
    position: absolute;
    font-size: 2.5rem;
    color: var(--text-primary);
    margin-bottom: 15px;
    text-align: center;
}

.sub-question {
    font-family: var(--font-sans);
    color: #888;
    font-size: 1.2rem;
}

/* Phase 2: Game */
.game-header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 220px;
    margin-bottom: 20px;
    font-family: var(--font-sans);
    font-size: 1rem;
    color: #666;
}

.player-x {
    color: #e08e79;
    font-weight: bold;
}

.player-o {
    color: #77a8a8;
    font-weight: bold;
}

.tic-tac-toe {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 220px;
    height: 220px;
    margin-bottom: 15px;
}

.cell {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-sans);
    font-size: 2rem;
    font-weight: bold;
    cursor: default;
}

.cell.x {
    color: #e08e79;
}

.cell.o {
    color: #77a8a8;
}

.game-status {
    font-size: 1rem;
    color: #999;
    margin-top: 15px;
    font-style: italic;
}

/* Phase 3: Invitation */
#invitationSection {
    justify-content: space-between;
    padding: 10px 0;
}

.title {
    font-family: var(--font-script);
    font-size: 2.5rem;
    color: var(--text-primary);
    margin-bottom: 10px;
    text-align: center;
    line-height: 1.2;
}

.names {
    font-family: var(--font-serif);
    color: var(--text-primary);
    margin-bottom: 20px;
    text-align: center;
}

.names p {
    margin: 5px 0;
    font-size: 1.1rem;
}

.details {
    font-size: 1rem;
    color: #666;
    line-height: 1.8;
    text-align: center;
    width: 100%;
}

.details p {
    margin: 5px 0;
}

.address {
    font-size: 0.9rem;
    margin-top: 10px;
    padding: 0 10px;
}

.footer-msg {
    font-family: var(--font-script);
    font-size: 1.1rem;
    /* Reduced from 1.3rem */
    color: #b8860b;
    /* Darker Gold as requested */
    margin-top: 15px;
    text-align: center;
    line-height: 1.4;
}

/* Google Maps Button */
.maps-btn {
    display: inline-block;
    margin-top: 10px;
    padding: 8px 15px;
    background-color: var(--text-accent);
    color: #fff;
    text-decoration: none;
    border-radius: 20px;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    transition: background-color 0.3s ease, transform 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.maps-btn:hover {
    background-color: #b89628;
    /* Darker gold */
    transform: translateY(-2px);
}

.maps-btn:active {
    transform: translateY(0);
}

/* Instruction Text */
.instruction-text {
    position: absolute;
    bottom: -50px;
    left: 50%;
    transform: translateX(-50%);
    color: #888;
    font-size: 1rem;
    animation: pulse 2s infinite;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* Hide instruction text when envelope is open */
.envelope-wrapper.open .instruction-text,
.envelope-wrapper.open~.instruction-text,
.envelope-wrapper.open>.instruction-text {
    display: none !important;
    opacity: 0 !important;
}

@keyframes pulse {
    0% {
        opacity: 0.6;
        transform: translateX(-50%) scale(1);
    }

    50% {
        opacity: 1;
        transform: translateX(-50%) scale(1.05);
    }

    100% {
        opacity: 0.6;
        transform: translateX(-50%) scale(1);
    }
}

/* Mobile Optimization */
@media (max-width: 480px) {
    .envelope-wrapper {
        width: 340px;
        height: 230px;
    }

    .top-flap {
        border-width: 115px 170px 0 170px;
    }

    .right-flap {
        border-width: 115px 170px 115px 0;
    }

    .bottom-flap {
        border-width: 0 170px 115px 170px;
    }

    .left-flap {
        border-width: 115px 0 115px 170px;
    }

    .wax-seal {
        width: 90px;
        height: 90px;
        font-size: 2.2rem;
    }

    .title {
        font-size: 2rem;
    }

    .details {
        font-size: 0.9rem;
    }
}

@media (max-width: 360px) {
    .envelope-wrapper {
        width: 300px;
        height: 200px;
    }

    .top-flap {
        border-width: 100px 150px 0 150px;
    }

    .right-flap {
        border-width: 100px 150px 100px 0;
    }

    .bottom-flap {
        border-width: 0 150px 100px 150px;
    }

    .left-flap {
        border-width: 100px 0 100px 150px;
    }

    .wax-seal {
        width: 80px;
        height: 80px;
        font-size: 2rem;
    }
}

/* Utility Class for Hiding Phases */
.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}