:root {
    --bg-color: #fdf0f2;
    --primary-red: #800020;
    --envelope-color: #f3e5ab; 
    --envelope-flap-dark: #e6d28a;
    --paper-color: #fff;
    --wax-red: #b91e1e;
    --text-color: #2c0b0e;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background-color: var(--bg-color);
    font-family: 'Playfair Display', serif;
    color: var(--text-color);
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Screens */
.screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    transition: opacity 1s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}
.hidden { opacity: 0; pointer-events: none; z-index: -10; display: none; }
.active { opacity: 1; z-index: 10; display: flex; }

/* Close Overlay */
#close-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 9; /* Below envelope logic (z-index 10) but above everything else? 
                   Actually envelope-container is 10. Letter becomes 100.
                   Overlay needs to be below Letter (100) but above PhotoWall (0).
                   Let's make Overlay 90. */
    z-index: 90;
    cursor: pointer;
    background: transparent; /* No dark overlay */
}

/* Timer Screen */
.timer-container {
    padding: 3rem;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(128, 0, 32, 0.1);
}

#countdown {
    display: flex;
    gap: 20px;
    margin-top: 2rem;
    justify-content: center;
}

.time-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 80px;
}

.time-box span:first-child {
    font-family: 'Cinzel', serif;
    font-size: 3rem;
    color: var(--primary-red);
    font-weight: bold;
    line-height: 1;
}

.time-box .label {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 5px;
    color: #888;
}

.admin-lock {
    margin-top: 3rem;
    font-size: 1.2rem;
    opacity: 0.1;
    cursor: pointer;
    transition: opacity 0.3s;
}
.admin-lock:hover { opacity: 0.8; }

#admin-panel { margin-top: 10px; }
#admin-pin {
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
    text-align: center;
    font-size: 1rem;
    width: 150px;
}

/* Login Screen Styles */
.login-container {
    padding: 3rem;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(128, 0, 32, 0.1);
    z-index: 20;
}
h1 { font-family: 'Great Vibes', cursive; font-size: 5rem; color: var(--primary-red); line-height: 1; text-shadow: 2px 2px 0px rgba(0,0,0,0.05);}
p { font-size: 1.2rem; margin-bottom: 2rem; color: #8a3a4b; }
.pin-wrapper { position: relative; display: inline-block; }
#pin-input { position: absolute; top:0; left:0; width:100%; height:100%; opacity:0; cursor:pointer; font-size:3rem; }
.hearts-display { display: flex; gap: 20px; justify-content: center; }
.heart-slot { font-size: 3.5rem; width: 60px; height: 70px; display: flex; justify-content: center; align-items: center; color: var(--primary-red); transition: transform 0.2s; }
.heart-slot.empty .outline { color: #dcb3b9; }
.heart-slot.active-cursor .outline { color: var(--primary-red); animation: pulse 1s infinite; }
.heart-slot.filled { animation: pop 0.4s ease; filter: drop-shadow(0 4px 6px rgba(128,0,32,0.2)); }
@keyframes pulse { 50% { transform: scale(1.1); } }
@keyframes pop { 50% { transform: scale(1.2); } }
.shake { animation: shake 0.5s; }
@keyframes shake { 0%, 100% {transform: translateX(0);} 25% {transform: translateX(-5px);} 75% {transform: translateX(5px);} }

/* Modern Infinite Photo Wall */
.photo-wall-container {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    z-index: 0;
    overflow: hidden;
    background: #000;
}

.photo-marquee {
    display: flex;
    width: max-content; 
    overflow: hidden;
    margin-bottom: 0px; 
}

.marquee-content {
    display: flex;
    gap: 0;
}

.photo-item {
    padding: 4px; 
    line-height: 0; 
}

.photo-item img {
    height: 32vh; 
    width: auto;
    border-radius: 2px;
    box-shadow: none;
    transition: transform 0.3s;
    display: block; 
    object-fit: cover;
}

.photo-item img:hover {
    transform: scale(1.05);
    z-index: 5;
    box-shadow: 0 0 20px rgba(0,0,0,0.8);
    position: relative;
    border-radius: 2px;
}

/* Animations */
.marquee-left {
    animation: scrollLinear 60s linear infinite;
}
.marquee-right {
    animation: scrollLinear 65s linear infinite reverse; 
}

@keyframes scrollLinear {
    0% { transform: translate3d(0, 0, 0); }
    100% { transform: translate3d(-25%, 0, 0); } 
}

/* Premium Envelope - Bigger */
.envelope-container {
    position: absolute;
    z-index: 10;
    perspective: 1500px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.envelope-container.active-z { z-index: 100; }

.envelope-wrapper {
    position: relative;
    cursor: pointer;
    transition: transform 0.5s ease;
}
.envelope-wrapper:hover { transform: translateY(-10px); }

.envelope {
    width: 600px; /* Increased from 450px */
    height: 400px; /* Increased from 300px */
    background: var(--envelope-color);
    position: relative;
    box-shadow: 0 15px 35px rgba(0,0,0,0.4), inset 0 0 20px rgba(0,0,0,0.1);
    border-radius: 5px;
}

/* Flaps - Recalculated for 600x400 */
.envelope::after { 
    content: ''; position: absolute; top:0; left:0;
    border-style: solid;
    border-width: 200px 300px 200px 300px; /* H/2 and W/2 */
    border-color: transparent #e8dcb5 transparent #e8dcb5; 
    z-index: 2;
    border-radius: 5px;
    pointer-events: none;
}

.envelope::before { 
    content: ''; position: absolute; bottom:0; left:0;
    border-style: solid;
    border-width: 0 300px 240px 300px; /* W/2 is 300. 240 is proportional depth */
    border-color: transparent transparent #ede2bc transparent;
    z-index: 3;
    border-radius: 5px;
    pointer-events: none;
    filter: drop-shadow(0 -2px 5px rgba(0,0,0,0.05));
}

.flap {
    position: absolute; top:0; left:0;
    width: 0; height: 0;
    border-style: solid;
    border-width: 210px 300px 0 300px; /* Slightly more than H/2 (200) */
    border-color: var(--envelope-flap-dark) transparent transparent transparent;
    z-index: 4;
    transform-origin: top;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1) 0.1s, z-index 0.2s;
    filter: drop-shadow(0 2px 5px rgba(0,0,0,0.1));
}

/* Wax Seal */
.wax-seal {
    position: absolute;
    top: 140px; /* Adjusted for larger flap */
    left: 50%;
    transform: translateX(-50%);
    width: 80px; height: 80px; /* Bigger seal */
    background: radial-gradient(circle at 30% 30%, #ff4d4d, #b91e1e);
    border-radius: 50%;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3), inset 0 0 10px rgba(0,0,0,0.5);
    z-index: 5;
    display: flex; justify-content: center; align-items: center;
    color: rgba(0,0,0,0.3);
    font-family: 'Cinzel', serif;
    font-size: 2.5rem;
    font-weight: bold;
    border: 2px dashed rgba(0,0,0,0.1);
    transition: transform 0.6s ease 0.1s, opacity 0.4s ease 0.1s;
}

/* Letter */
.letter {
    position: absolute;
    width: 550px; height: 350px; /* Fits inside 600x400 */
    background: #fff;
    top: 25px; left: 25px;
    padding: 0;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 1;
    transition: transform 0.8s cubic-bezier(0.68, -0.55, 0.27, 1.55) 0.6s, z-index 0.1s, height 0.8s ease, width 0.8s ease, left 0.8s ease;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    text-align: center;
    border-radius: 3px;
    background-image: none;
    overflow: hidden;
}

.letter canvas {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Ensure the whole page is visible */
    display: block;
}

/* Sound Hint */
.sound-hint {
    margin-top: 30px;
    padding: 0;
    background: transparent;
    border-radius: 0;
    color: #8a3a4b; 
    font-size: 0.85rem;
    font-weight: normal;
    font-family: 'Playfair Display', serif;
    letter-spacing: 1px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    opacity: 0.7;
    animation: fadeIn 2s ease-in-out;
}

@keyframes fadeIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 0.7; transform: translateY(0); }
}

/* Open State */
.envelope.open .flap { transform: rotateX(180deg); z-index: 1; }
.envelope.open .wax-seal { transform: translateX(-50%) translateY(-50px) scale(0.5); opacity: 0; }
.envelope.open .letter { 
    /* Center on screen */
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    
    /* Fit to PDF Content (Portrait Aspect Ratio) */
    height: 90vh;
    aspect-ratio: 1 / 1.4; /* Approx A4/Letter ratio */
    width: auto;
    max-width: 95vw; /* Ensure it fits on mobile */
    
    z-index: 100;
    border-radius: 2px;
    box-shadow: none; /* Removed backdrop dimming */
    background: transparent; /* Let the PDF bg show */
}

/* On mobile, maybe width is the constraint? */
@media (max-width: 600px) {
    .envelope.open .letter {
        width: 95vw;
        height: auto;
        aspect-ratio: 1 / 1.4;
    }
}

/* Click Hint */
.click-hint {
    margin-top: 3rem;
    color: #fff;
    font-size: 1.4rem;
    font-family: 'Cinzel', serif;
    letter-spacing: 2px;
    opacity: 0.8;
    text-shadow: 0 2px 10px rgba(0,0,0,0.8);
    animation: shine 3s infinite;
}

@keyframes shine {
    0%, 100% { opacity: 0.5; text-shadow: 0 0 5px rgba(255,255,255,0.2); }
    50% { opacity: 1; text-shadow: 0 0 20px rgba(255,255,255,0.8); }
}

.petal {
    position: fixed; top: -50px; font-size: 2rem; z-index: 100;
    pointer-events: none; animation: fall linear forwards;
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.1));
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 600px) {
    .photo-item img { height: 18vh; }
    .envelope { width: 300px; height: 200px; }
    .envelope::after { border-width: 100px 150px 100px 150px; }
    .envelope::before { border-width: 0 150px 110px 150px; }
    .flap { border-width: 110px 150px 0 150px; }
    .letter { width: 260px; left: 20px; }
    .wax-seal { top: 70px; }
    h1 { font-size: 3.5rem; }
    .letter-image { width: 80px; height: 70px; }
    .envelope.open .letter { height: 350px; transform: translateY(-160px); }
    .time-box span:first-child { font-size: 2rem; }
}
