@import url('https://fonts.googleapis.com/css2?family=Pinyon+Script&family=Playfair+Display:ital,wght@0,400;1,400&display=swap');

:root {
    --env-color: #000000;
    --env-flap: #121d4a;
    --env-pocket: #23395d;
    --letter-bg: #fdf5e6;
    
    /* Sizing Controls */
    --letter-w: 400px;
    --letter-h: 550px;
    --photo-w: 200px; /* Large, clear photos */
}

@media (max-width: 650px) {
    :root {
        --letter-w: 85vw;
        --letter-h: 60vh;
        --photo-w: 35vw;
    }
}

body {
    background: radial-gradient(circle, #e5d3b3 0%, #b5a48b 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    overflow: hidden; 
    font-family: 'Playfair Display', serif;
}

/* --- ENVELOPE (CLOSED) --- */
.envelope-wrapper {
    position: relative;
    cursor: pointer;
    width: 420px;
    height: 280px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.envelope {
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: var(--env-color);
    z-index: 3;
    transition: opacity 0.5s ease;
}

.envelope::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    border-top: 150px solid var(--env-flap);
    border-left: 210px solid transparent;
    border-right: 210px solid transparent;
    z-index: 5;
}

.pocket {
    position: absolute;
    bottom: 0;
    width: 0;
    height: 0;
    border-left: 210px solid var(--env-pocket);
    border-right: 210px solid var(--env-pocket);
    border-bottom: 140px solid var(--env-pocket);
    border-top: 140px solid transparent;
    z-index: 4;
}

/* --- THE LETTER (Optimized for Long Content) --- */
.letter {
    position: absolute;
    width: var(--letter-w);
    height: 180px; /* Initial height before opening */
    background: var(--letter-bg);
    padding: 30px 40px; /* Balanced padding */
    box-sizing: border-box;
    z-index: 2;
    transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    
    /* Elegant Scrolling for long poems */
    overflow-y: auto; 
    scrollbar-width: thin;
    scrollbar-color: #b5a48b transparent;
}

/* Custom Scrollbar for Chrome/Safari */
.letter::-webkit-scrollbar {
    width: 5px;
}
.letter::-webkit-scrollbar-track {
    background: transparent;
}
.letter::-webkit-scrollbar-thumb {
    background-color: #b5a48b;
    border-radius: 10px;
}

.envelope-wrapper.open .letter {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: var(--letter-w);
    height: var(--letter-h);
    z-index: 10;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    padding: 50px; /* More space when open */
}

/* --- TEXT STYLING --- */
.text {
    font-family: 'Playfair Display', serif;
    color: #3e2723;
}
.text h2 { 
    font-family: 'Pinyon Script', cursive; 
    font-size: 38px; 
    margin-bottom: 25px;
    border-bottom: 1px solid rgba(62, 39, 35, 0.1);
    display: inline-block;
}
.text p { 
    font-size: 15px; /* Slightly smaller to fit more text */
    line-height: 1.8; /* Breathable line spacing */
    margin-bottom: 12px;
    text-align: justify; /* Makes the poem look like a formal block */
}
.signature { 
    font-family: 'Pinyon Script', cursive; 
    font-size: 26px; 
    text-align: right; 
    margin-top: 40px; 
    padding-bottom: 20px;
}

.envelope-wrapper.open .envelope,
.envelope-wrapper.open .pocket {
    opacity: 0;
    pointer-events: none;
}

/* --- PHOTO BLAST (STRAIGHT & CLOSE) --- */
.out-photo {
    position: absolute;
    /* 1. Center the origin point of the photos */
    top: 50%;
    left: 50%;
    width: var(--photo-w);
    height: auto;
    border: 6px solid white;
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
    
    /* 2. Use a "bouncy" transition curve for a pop effect */
    /* Added a 0.2s delay so the letter starts opening first */
    transition: all 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s;
    
    /* 3. Initial State: Centered precisely and scaled to 0 */
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
    z-index: 10; /* Behind the open letter (z-index 15) */
}

.envelope-wrapper.open .out-photo { 
    opacity: 1; 
}

/* POSITIONING LOGIC: 
   Using vw/vh ensures photos stay inside the browser window 
   while framing the letter nicely.
*/

/* Top Left - Moved further left and higher */
.envelope-wrapper.open .p1 { transform: translate(-35vw, -35vh) scale(1); }
/* Top Right - Moved left and higher */
.envelope-wrapper.open .p2 { transform: translate(20vw, -35vh) scale(1); }

/* Middle Left - Moved further left and slightly up */
.envelope-wrapper.open .p3 { transform: translate(-35vw, 5vh) scale(1); }
/* Middle Right - Moved left and slightly up */
.envelope-wrapper.open .p4 { transform: translate(20vw, -10vh) scale(1); }

/* Bottom Left - Moved further left and tucked higher */
.envelope-wrapper.open .p5 { transform: translate(-35vw, 25vh) scale(1); }
/* Bottom Right - Moved left and tucked higher */
.envelope-wrapper.open .p6 { transform: translate(20vw, 10vh) scale(1); }

/* On very small screens, keep them even closer so they don't touch the edge */
@media (max-width: 650px) {
    :root {
        --letter-w: 85vw;
        --letter-h: 60vh;
        --photo-w: 35vw;
    }

    /* Maintain the "Higher & Left" shift on mobile devices */
    .envelope-wrapper.open .p1 { transform: translate(-35vw, -35vh) scale(1); }
    .envelope-wrapper.open .p2 { transform: translate(20vw, -35vh) scale(1); }
    .envelope-wrapper.open .p3 { transform: translate(-35vw, 5vh) scale(1); }
    .envelope-wrapper.open .p4 { transform: translate(20vw, -10vh) scale(1); }
    .envelope-wrapper.open .p5 { transform: translate(-35vw, 25vh) scale(1); }
    .envelope-wrapper.open .p6 { transform: translate(20vw, 10vh) scale(1); }
}

.out-photo:hover { transform: scale(1.4) !important; z-index: 100; cursor: zoom-in; }

.instruction {
    margin-top: 30px;
    color: #4e342e;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 11px;
    text-align: center;    /* Centers the text */
    width: 100%;           /* Ensures it uses the full width available */
}
