/* --- ENVELOPE ANIMATION SYSTEM --- */

/* 1. Full Screen Blur Overlay */
.page-blur-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6); /* Dark overlay */
    backdrop-filter: blur(12px);
    z-index: 9990;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

.page-blur-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* 2. The Envelope (Fixed Positioning) */
.envelope-wrapper {
    position: fixed;
    bottom: -200px; /* Start off-screen */
    left: 50%;
    transform: translateX(-50%);
    width: 140px;
    height: 90px;
    z-index: 10000; /* Above blur */
    transition: bottom 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.envelope-wrapper.visible {
    bottom: 20%; /* Move up into view */
}

.envelope-back {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #1e293b;
    border-radius: 6px;
    z-index: 1;
}

.envelope-front {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--primary);
    clip-path: polygon(0 0, 50% 60%, 100% 0, 100% 100%, 0 100%);
    z-index: 20; /* In front of the form */
    border-radius: 6px;
}

.envelope-lid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 50%;
    background: #60a5fa;
    clip-path: polygon(0 0, 50% 100%, 100% 0);
    transform-origin: top;
    transform: rotateX(0deg);
    z-index: 21; /* On top of everything initially */
    transition: transform 0.4s ease;
    backface-visibility: hidden;
}

.envelope-wrapper.lid-open .envelope-lid {
    transform: rotateX(180deg);
    z-index: 1; /* Moves behind when open */
}

.envelope-wrapper.lid-close .envelope-lid {
    transform: rotateX(0deg);
    z-index: 21;
}

/* 3. Form Flying Animation */
.contact-form.flying {
    position: fixed;
    z-index: 9995; /* Above blur, below envelope front/lid */
    transform-origin: center bottom;
    transition: all 1.2s cubic-bezier(0.6, -0.28, 0.735, 0.045);
    pointer-events: none;
    width: 100% !important; /* Maintain width during flight setup */
    max-width: 600px; /* Limit width if needed */
}

.contact-form.flying.minimize {
    top: auto !important;
    bottom: 20% !important; /* Target envelope position */
    left: 50% !important;
    transform: translateX(-50%) scale(0.05) translateY(50px);
    opacity: 0;
}

/* 4. Envelope Exit */
.envelope-wrapper.fly-away {
    bottom: -200px;
    opacity: 0;
    transition: all 0.6s ease-in;
}

/* 5. Success Message */
.form-success {
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.5s ease;
    text-align: center;
    padding: 40px;
}

.form-success.visible {
    opacity: 1;
    transform: translateY(0);
}
