/**
 * Georgiana Timu & Tiberiu Totir - Wedding Invitation
 * Vintage 3D Folding Envelope & Postage Stamp Stylesheet (assets/css/envelope.css)
 */

#envelopeOverlay {
    perspective: 1400px;
    -webkit-perspective: 1400px;
    overflow-x: hidden;
    max-width: 100vw;
    width: 100%;
    -webkit-font-smoothing: antialiased;
    transition: opacity 0.9s cubic-bezier(0.4, 0, 0.2, 1), 
                transform 0.9s cubic-bezier(0.4, 0, 0.2, 1), 
                filter 0.9s ease,
                visibility 0.9s;
    will-change: opacity, transform, filter;
}

#envelopeOverlay.is-dismissing {
    opacity: 0;
    transform: scale(1.04);
    filter: blur(4px);
    pointer-events: none;
}

#envelopeOverlay.opened-done {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    display: none;
}

/* Envelope Container with Entrance & Floating Motion */
@keyframes envelopeEntrance {
    0% {
        opacity: 0;
        transform: translateY(35px) scale(0.92) rotateX(12deg);
    }
    100% {
        opacity: 1;
        transform: translateY(0px) scale(1) rotateX(0deg);
    }
}

@keyframes envelopeIdleFloat {
    0%, 100% {
        transform: translateY(0px) rotate(0deg);
    }
    50% {
        transform: translateY(-8px) rotate(-0.5deg);
    }
}

.envelope-wrapper {
    animation: envelopeEntrance 1.1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    max-width: 100%;
}

/* Vintage Handmade Parchment Envelope Body */
.envelope-box {
    position: relative;
    width: min(92vw, 540px);
    height: min(65vw, 360px);
    min-height: 270px;
    background: #E8DCC4;
    background-image: 
        radial-gradient(ellipse at 50% 50%, rgba(255, 252, 245, 0.45) 0%, transparent 70%),
        radial-gradient(#6E5638 0.7px, transparent 0.7px);
    background-size: 100% 100%, 14px 14px;
    border-radius: 12px;
    border: 1px solid rgba(135, 105, 65, 0.4);
    box-shadow: 
        0 35px 85px -15px rgba(50, 35, 18, 0.42), 
        0 0 0 1px rgba(110, 85, 50, 0.22), 
        inset 0 0 70px rgba(130, 95, 50, 0.22),
        inset 0 0 20px rgba(90, 65, 30, 0.16);
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    transition: transform 1.2s cubic-bezier(0.2, 0.8, 0.25, 1) 0.35s, 
                -webkit-transform 1.2s cubic-bezier(0.2, 0.8, 0.25, 1) 0.35s,
                box-shadow 1.2s ease 0.35s;
    animation: envelopeIdleFloat 7s ease-in-out infinite 1.1s;
}

.envelope-box:hover {
    box-shadow: 
        0 42px 95px -15px rgba(50, 35, 18, 0.5), 
        0 0 0 1px rgba(110, 85, 50, 0.3), 
        inset 0 0 70px rgba(130, 95, 50, 0.26);
}

/* Inner Luxury Invitation Card */
.envelope-letter {
    position: absolute;
    inset: 16px 28px;
    background: #FFFEFB;
    border-radius: 8px;
    border: 1px solid rgba(197, 160, 89, 0.45);
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1.5rem;
    box-shadow: 0 4px 20px rgba(45, 35, 20, 0.08);
    background-image: radial-gradient(rgba(140, 115, 75, 0.04) 1px, transparent 0);
    background-size: 16px 16px;
    transform: translate3d(0, 0, 1px);
    -webkit-transform: translate3d(0, 0, 1px);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transition: transform 1.2s cubic-bezier(0.2, 0.8, 0.25, 1) 0.35s,
                -webkit-transform 1.2s cubic-bezier(0.2, 0.8, 0.25, 1) 0.35s,
                box-shadow 1.2s ease 0.35s;
    will-change: transform, box-shadow;
}

/* Left pocket fold */
.envelope-pocket-left {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #DFD1B0 0%, #D4C39D 60%, #C4B188 100%);
    -webkit-clip-path: polygon(0 0, 52% 52%, 0 100%);
    clip-path: polygon(0 0, 52% 52%, 0 100%);
    z-index: 3;
    border-radius: 12px;
    box-shadow: inset 3px 3px 12px rgba(80, 55, 30, 0.18);
    border-left: 1px solid rgba(130, 100, 60, 0.25);
    transform: translate3d(0, 0, 2px);
    -webkit-transform: translate3d(0, 0, 2px);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Right pocket fold */
.envelope-pocket-right {
    position: absolute;
    inset: 0;
    background: linear-gradient(225deg, #DFD1B0 0%, #D4C39D 60%, #C4B188 100%);
    -webkit-clip-path: polygon(100% 0, 48% 52%, 100% 100%);
    clip-path: polygon(100% 0, 48% 52%, 100% 100%);
    z-index: 3;
    border-radius: 12px;
    box-shadow: inset -3px 3px 12px rgba(80, 55, 30, 0.18);
    border-right: 1px solid rgba(130, 100, 60, 0.25);
    transform: translate3d(0, 0, 2px);
    -webkit-transform: translate3d(0, 0, 2px);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Bottom pocket fold */
.envelope-pocket-bottom {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, #C2AE82 0%, #D6C49E 55%, #E5D7B9 100%);
    -webkit-clip-path: polygon(0 100%, 50% 48%, 100% 100%);
    clip-path: polygon(0 100%, 50% 48%, 100% 100%);
    z-index: 4;
    border-radius: 12px;
    filter: drop-shadow(0 -5px 14px rgba(45, 30, 12, 0.25));
    transform: translate3d(0, 0, 3px);
    -webkit-transform: translate3d(0, 0, 3px);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Top flap fold */
.envelope-flap {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, #ECE1C8 0%, #DFD1B0 55%, #D0BF98 100%);
    -webkit-clip-path: polygon(0 0, 50% 55%, 100% 0);
    clip-path: polygon(0 0, 50% 55%, 100% 0);
    transform-origin: top center;
    -webkit-transform-origin: top center;
    transform: translate3d(0, 0, 4px) rotateX(0deg);
    -webkit-transform: translate3d(0, 0, 4px) rotateX(0deg);
    transition: transform 0.85s cubic-bezier(0.35, 0, 0.25, 1),
                -webkit-transform 0.85s cubic-bezier(0.35, 0, 0.25, 1);
    z-index: 5;
    border-radius: 12px;
    filter: drop-shadow(0 8px 20px rgba(45, 30, 12, 0.28));
    will-change: transform;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Vintage Postage Stamp: Dog Otto */
.envelope-stamp {
    position: absolute;
    top: 16px;
    right: 22px;
    width: min(22vw, 92px);
    aspect-ratio: 382 / 512;
    z-index: 20; /* Placed firmly on top of the closed envelope */
    transform: rotate(3deg);
    filter: drop-shadow(0 4px 12px rgba(30, 20, 10, 0.35)) drop-shadow(0 1px 3px rgba(0, 0, 0, 0.2));
    transition: opacity 0.4s ease, transform 0.4s ease;
    cursor: pointer;
    pointer-events: auto;
    background: #FFFFFF;
    padding: 2px;
    border-radius: 2px;
}

.envelope-stamp:hover {
    transform: rotate(0deg) scale(1.08);
    filter: drop-shadow(0 10px 22px rgba(30, 20, 10, 0.45));
}

.stamp-img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

/* Vintage Crimson Red Wax Seal */
@keyframes sealGleam {
    0%, 100% {
        box-shadow:
            0 12px 28px rgba(45, 10, 10, 0.52),
            inset 0 3px 7px rgba(255, 180, 180, 0.38),
            inset 0 -5px 10px rgba(25, 0, 0, 0.75);
    }
    50% {
        box-shadow:
            0 16px 36px rgba(168, 46, 46, 0.65),
            inset 0 3px 9px rgba(255, 210, 210, 0.55),
            inset 0 -5px 12px rgba(25, 0, 0, 0.85);
    }
}

.wax-seal-btn {
    position: absolute;
    top: 52%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 25;
    width: 90px;
    height: 90px;
    border-radius: 53% 47% 52% 48% / 49% 52% 48% 51%;
    background: radial-gradient(circle at 32% 28%, #B83434 0%, #7E1212 55%, #460404 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), 
                opacity 0.4s ease, 
                filter 0.4s ease;
    border: none;
    outline: none;
    animation: sealGleam 3.5s ease-in-out infinite;
}

.wax-seal-btn:hover {
    transform: translate(-50%, -50%) scale(1.08);
}

.wax-seal-btn:focus-visible {
    outline: 3px solid #E8EDE3;
    outline-offset: 4px;
}

.wax-seal-inner {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    border: 1.5px dashed rgba(245, 210, 175, 0.55);
    box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.55), 0 1px 2px rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #F8E5CC;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

/* ========================================================
   Active Opening Animation: Pure Fluid Emerge & Zero Clipping
   ======================================================== */
.envelope-box.is-opening {
    animation-play-state: paused;
    transform: translate3d(0, 60px, 0) scale(0.92);
    -webkit-transform: translate3d(0, 60px, 0) scale(0.92);
    box-shadow: 0 25px 60px -15px rgba(45, 32, 18, 0.3);
}

.envelope-box.is-opening .envelope-flap {
    transform: rotateX(180deg) translate3d(0, 0, -1px);
    -webkit-transform: rotateX(180deg) translate3d(0, 0, -1px);
    z-index: 1;
    filter: drop-shadow(0 -4px 10px rgba(50, 35, 15, 0.12));
}

.envelope-box.is-opening .wax-seal-btn {
    transform: translate(-50%, -50%) scale(1.15) rotate(4deg);
    -webkit-transform: translate(-50%, -50%) scale(1.15) rotate(4deg);
    opacity: 0;
    filter: blur(2px);
    pointer-events: none;
}

.envelope-box.is-opening .envelope-stamp {
    opacity: 0;
    pointer-events: none;
    transform: rotate(4deg) scale(0.9);
    -webkit-transform: rotate(4deg) scale(0.9);
}

.envelope-box.is-opening .envelope-letter {
    transform: translate3d(0, -165px, 25px) scale(1.1);
    -webkit-transform: translate3d(0, -165px, 25px) scale(1.1);
    z-index: 30;
    box-shadow: 
        0 35px 80px -15px rgba(35, 22, 10, 0.4),
        0 0 0 1px rgba(197, 160, 89, 0.5);
}

@media (max-width: 640px) {
    .envelope-box.is-opening {
        transform: translate3d(0, 45px, 0) scale(0.92);
        -webkit-transform: translate3d(0, 45px, 0) scale(0.92);
    }

    .envelope-box.is-opening .envelope-letter {
        transform: translate3d(0, -130px, 25px) scale(1.06);
        -webkit-transform: translate3d(0, -130px, 25px) scale(1.06);
    }
}

/* Subtle Countdown Progress Bar */
.envelope-progress-track {
    width: min(80vw, 320px);
    height: 3px;
    background: rgba(30, 30, 28, 0.08);
    border-radius: 9999px;
    overflow: hidden;
    position: relative;
}

.envelope-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #B56E4B, #C5A059, #4E5744);
    border-radius: 9999px;
    transition: width 0.05s linear;
}
