/* envelope.css */
/* ==================================================
   ORIGINAL 3D FROSTED PAPER ENVELOPE
   ================================================== */
.envelope-wrapper { position: absolute; top: 50%; left: 50%; margin-top: 20px; width: var(--env-width); max-width: 90vw; height: var(--env-height); z-index: 25; opacity: 0; transform: translate(-50%, -50%) scale(var(--env-start-scale)); pointer-events: none; perspective: 1500px; }
.scene.envelope-revealing .envelope-wrapper { opacity: 1; transform: translate(-50%, -50%) scale(1); transition: opacity var(--env-duration) ease-out, transform var(--env-duration) cubic-bezier(0.2, 0.8, 0.2, 1); }
.scene.envelope-settled .envelope-wrapper { opacity: 1; transform: translate(-50%, -50%) scale(1); pointer-events: auto; }
.envelope-wrapper.dissolve-envelope { opacity: 0 !important; transform: translate(-50%, -50%) scale(1.3) !important; transition: all 1s ease-in-out !important; pointer-events: none !important; }

.envelope-card { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); will-change: transform; cursor: grab; touch-action: pan-y pinch-zoom; }
.envelope-card:active { cursor: grabbing; }

.env-face { position: absolute; inset: 0; border-radius: 6px; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; background: rgba(240, 245, 255, 0.08); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); border: 1px solid rgba(255, 255, 255, 0.15); box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.05), 0 15px 40px rgba(0, 0, 0, 0.6); }
.envelope-card.opened .env-face { overflow: visible !important; }

.env-front { transform: rotateY(0deg); }
.env-back { transform: rotateY(180deg); flex-direction: column; padding: 24px; justify-content: center; }

.paper-noise { position: absolute; inset: 0; z-index: 0; pointer-events: none; opacity: 0.3; mix-blend-mode: overlay; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); border-radius: inherit; }
.env-flap { 
    position: absolute; top: 0; left: 0; width: 100%; height: 55%; 
    clip-path: polygon(0 0, 100% 0, 50% 100%); 
    z-index: 10; 
    background: linear-gradient(to bottom, rgba(255,255,255,0.08), transparent); 
    border-bottom: 1px solid rgba(255,255,255,0.2); 
    transform-origin: top center; 
}
.envelope-card.opened .env-flap { 
    transform: rotateX(180deg); /* Folds outward towards the user instead of inward */
    transition: transform 0.9s cubic-bezier(0.25, 1, 0.5, 1); 
    z-index: 10; /* Keeps the flap in front of the emerging letter */
    pointer-events: none; 
}
.wax-seal { position: absolute; top: 55%; left: 50%; transform: translate(-50%, -50%); width: 34px; height: 34px; border-radius: 50%; z-index: 11; transition: transform 0.2s ease; background: #fdfbf7; border: 1px solid rgba(255,255,255,0.8); box-shadow: inset 0 -2px 6px rgba(0,0,0,0.2), 0 4px 10px rgba(0,0,0,0.4); cursor: pointer;}
.wax-seal::after { content: ''; position: absolute; top: -7px; left: -7px; right: -7px; bottom: -7px; border-radius: 50%; }
.wax-seal:hover { transform: translate(-50%, -50%) scale(1.15); }
.scene.envelope-settled .wax-seal { animation: wax-pulse var(--env-pulse) infinite ease-in-out; }
.envelope-card.opened .wax-seal { opacity: 0; transform: translate(-50%, -50%) scale(0.6); transition: all 0.5s ease; pointer-events: none; }
@keyframes wax-pulse { 0%, 100% { box-shadow: inset 0 -2px 6px rgba(0,0,0,0.2), 0 0 5px rgba(253, 251, 247, 0.4); filter: brightness(1); } 50% { box-shadow: inset 0 -2px 6px rgba(0,0,0,0.2), 0 0 20px 4px rgba(253, 251, 247, 0.8); filter: brightness(1.2); } }

.env-scribble { position: absolute; top: 45%; left: 15%; font-family: "Comic Sans MS", cursive, sans-serif; font-size: 1.1rem; color: rgba(255,255,255,0.7); transform: rotate(-5deg); z-index: 5; }
.env-stamp { position: absolute; top: 30px; right: 20px; width: 35px; height: 45px; border: 1px solid rgba(200, 160, 255, 0.4); border-radius: 2px; background: rgba(200, 160, 255, 0.1); z-index: 5; transform: rotate(3deg); display: flex; flex-direction: column; align-items: center; padding: 3px; }
.stamp-inner { width: 100%; height: 60%; background: rgba(200, 160, 255, 0.2); margin-top: 2px; position: relative; }
.stamp-inner::after { content: '❁'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: rgba(255,255,255,0.6); font-size: 14px; }
.env-doodles { position: absolute; bottom: 15px; left: 15px; width: 40px; height: 50px; border-left: 1px solid rgba(255,255,255,0.3); border-bottom: 1px solid transparent; border-radius: 0 0 0 15px; z-index: 5; }
.env-doodles::after { content: '♡'; position: absolute; top: -10px; left: -8px; color: rgba(255,255,255,0.5); font-size: 16px; transform: rotate(-15deg); }

.back-content { position: relative; z-index: 5; color: rgba(255,255,255,0.9); font-family: "Brush Script MT", "Lucida Handwriting", cursive; font-size: 1.1rem; width: 100%; height: 100%; display: flex; flex-direction: column; align-items: flex-start; text-align: left; }
.hw-title { margin-bottom: 12px; }
.hw-address-block { margin-bottom: 15px; text-align: left; line-height: 1.4; }
.hw-sender { text-align: right; margin-top: auto; width: 100%; }

/* ==================================================
   MINIMALIST NIGHT SKY LETTER SYSTEM
   ================================================== */
.notes-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 4; clip-path: inset(-500% -20% 45% -20%); pointer-events: none; }

/* Hide old paper stacks */
.note-stack-bg { display: none !important; }

/* Premium Dark Glassmorphic Note */
.love-note { 
    position: absolute; 
    top: 12%; 
    left: 5%; 
    width: 90%; 
    height: 160%; 
    background: rgba(8, 12, 24, 0.65); /* Obsidian transparency */
    backdrop-filter: blur(16px); 
    -webkit-backdrop-filter: blur(16px);
    border-radius: 8px; 
    border: 1px solid rgba(255,255,255,0.15); 
    box-shadow: 0 -15px 40px rgba(0,0,0,0.6), inset 0 0 30px rgba(163, 194, 255, 0.05); 
    transform: translateY(100%) rotate(-3deg); 
    pointer-events: auto; 
    display: flex; 
    flex-direction: column; 
    z-index: 5; 
    overflow: hidden; 
    will-change: transform; 
}

.love-note.revealed { animation: note-emerge 1.8s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
@keyframes note-emerge { 
    0% { transform: translateY(100%) rotate(-3deg); } 
    70% { transform: translateY(-112%) rotate(0.5deg); } 
    100% { transform: translateY(-110%) rotate(0deg); } 
}

.love-note.dismissed { animation: note-drift-away 1.2s cubic-bezier(0.4, 0, 0.2, 1) forwards; pointer-events: none; }
@keyframes note-drift-away { 
    0% { transform: translateY(-110%) rotate(0deg); opacity: 1; filter: blur(0px); } 
    100% { transform: translateY(-135%) rotate(3deg); opacity: 0; filter: blur(8px); } 
}

.scene.envelope-settled .envelope-wrapper.reading-mode { 
    transform: translate(-50%, 22vh) scale(0.95); 
    transition: transform 1.2s cubic-bezier(0.2, 0.8, 0.2, 1); 
}

/* Ethereal Glow overlays instead of paper noise */
.note-moonlight-wash { 
    position: absolute; 
    inset: 0; 
    pointer-events: none; 
    z-index: 1; 
    background: radial-gradient(circle at 50% 0%, rgba(163, 194, 255, 0.15) 0%, transparent 60%); 
}

/* Clean, centered typography layout with unified scrolling */
.night-sky-layout { 
    position: relative; 
    z-index: 3; 
    padding: 40px 30px 80px 30px; /* Generous bottom padding to clear the fade mask */
    display: flex; 
    flex-direction: column; 
    height: 100%; 
    box-sizing: border-box; 
    align-items: center;
    
    /* Global scroll applied here */
    overflow-y: auto;          
    touch-action: pan-y pinch-zoom;
    scrollbar-width: none; 
    -ms-overflow-style: none;
    
    /* Elegant fade-out at the bottom */
    -webkit-mask-image: linear-gradient(to bottom, black 80%, transparent 100%);
    mask-image: linear-gradient(to bottom, black 80%, transparent 100%);
}
.night-sky-layout::-webkit-scrollbar { display: none; }

.note-greeting { 
    font-family: 'Spectral', 'Georgia', serif; 
    font-size: 1.4rem; 
    color: #ffffff; 
    font-style: italic; 
    margin-top: 20px;
    margin-bottom: 30px; 
    letter-spacing: 1px; 
    text-shadow: 0 0 15px rgba(255,255,255,0.4); 
    width: 100%;
    text-align: center;
    flex-shrink: 0; /* Prevents text from squishing */
}

.poetic-body { 
    font-family: 'Spectral', 'Georgia', serif; 
    font-size: 1.15rem; 
    color: rgba(230, 240, 255, 0.85); 
    line-height: 1.9; 
    text-align: center; 
    white-space: pre-line;
    text-shadow: 0 2px 5px rgba(0,0,0,0.5); 
    margin-bottom: 40px;
    flex-shrink: 0; /* Prevents text from squishing */
}

@media (max-height: 520px) {
    .scene.envelope-settled .envelope-wrapper.reading-mode {
        margin-top: 0;
        transform: translate(-50%, 36vh) scale(0.95);
        transform: translate(-50%, 36dvh) scale(0.95);
    }
    .reading-mode .love-note {
        height: min(160%, calc(100vh - 5rem));
        height: min(160%, calc(100dvh - 5rem));
    }
    .reading-mode .night-sky-layout { padding: 1.25rem 1.25rem 3.5rem; }
}

/* Beautiful, cinematic CTA Button */
.night-sky-cta { 
    font-family: 'Spectral', serif; 
    font-style: italic; 
    font-size: 1.05rem; 
    color: #ffffff; 
    letter-spacing: 2px; 
    padding: 14px 35px; 
    background: linear-gradient(135deg, rgba(255,255,255,0.1), rgba(255,255,255,0.02)); 
    border: 1px solid rgba(255,255,255,0.3); 
    border-radius: 40px; 
    cursor: pointer; 
    transition: all 0.4s ease; 
    box-shadow: 0 4px 20px rgba(0,0,0,0.3), inset 0 0 10px rgba(255,255,255,0.1); 
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    flex-shrink: 0; /* Ensures the button maintains its shape */
    margin-bottom: 20px;
}

.night-sky-cta:hover { 
    background: rgba(255,255,255,0.2); 
    border-color: rgba(255,255,255,0.6);
    box-shadow: 0 6px 25px rgba(163, 194, 255, 0.4), inset 0 0 15px rgba(255,255,255,0.3); 
    transform: translateY(-2px); 
}



@media (prefers-reduced-motion: reduce) { 
    .scene.envelope-settled .envelope-wrapper.reading-mode { transition-duration: 0.1s; }
    .love-note.revealed { animation: none; transform: translateY(-110%) rotate(0deg); }
    .love-note.dismissed { animation: none; opacity: 0; }
}
