:root {
    --bg-gradient: linear-gradient(135deg, #f5eae6 0%, #e8cbc0 100%);
    --envelope-bg: #dcae96;
    --envelope-inner: #cba089;
    --envelope-flap: #e6beaa;
    --paper-bg: #faf8f5;
    --text-primary: #3d2f2b;
    --text-secondary: #705b56;
    --accent: #c94b4b;
    --accent-glow: rgba(201, 75, 75, 0.3);
    --shadow-main: rgba(61, 47, 43, 0.12);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Poppins', sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1000px;
}

/* Particles Canvas */
#particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.container {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
}

/* Envelope Wrapper */
.envelope-wrapper {
    position: relative;
    width: 480px;
    height: 350px;
    background: transparent;
    cursor: pointer;
    transition: transform 0.5s ease, opacity 0.5s ease;
}

.envelope {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: var(--envelope-bg);
    border-radius: 0 0 10px 10px;
    box-shadow: 0 15px 35px var(--shadow-main);
    transform-style: preserve-3d;
}

/* Envelope Flaps */
.flap {
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
}

/* The top triangular flap */
.top-flap {
    top: 0;
    left: 0;
    border-width: 180px 240px 0 240px;
    border-color: var(--envelope-flap) transparent transparent transparent;
    transform-origin: top;
    z-index: 4;
    transition: transform 0.4s ease-in-out, z-index 0.2s ease-in-out;
}

/* The pocket of the envelope */
.pocket {
    bottom: 0;
    left: 0;
    border-width: 180px 240px 170px 240px;
    border-color: transparent var(--envelope-bg) var(--envelope-bg) var(--envelope-bg);
    z-index: 3;
    border-radius: 0 0 10px 10px;
}

/* The dummy letter inside the envelope */
.letter {
    position: absolute;
    bottom: 10px;
    left: 24px;
    width: 432px;
    height: 310px;
    background: var(--paper-bg);
    border-radius: 8px;
    padding: 30px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.05);
    z-index: 2;
    transition: transform 0.6s cubic-bezier(0.25, 1, 0.5, 1), z-index 0.3s;
    overflow: hidden;
}

.letter-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    color: var(--text-primary);
}

.letter-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 15px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.letter-body {
    font-family: 'Dancing Script', cursive;
    font-size: 1.45rem;
    line-height: 1.8;
    overflow-y: auto;
    padding-right: 5px;
}

/* Custom scrollbar for letter */
.letter-body::-webkit-scrollbar {
    width: 6px;
}
.letter-body::-webkit-scrollbar-track {
    background: transparent;
}
.letter-body::-webkit-scrollbar-thumb {
    background-color: var(--text-secondary);
    border-radius: 10px;
}

.greeting {
    margin-bottom: 15px;
    font-weight: 700;
}

.letter-body p {
    margin-bottom: 20px;
}

.signature {
    margin-top: 30px;
    font-size: 1.3rem;
}

.signature-name {
    font-weight: 700;
    margin-top: 5px;
}

/* Heart Seal Button */
.heart {
    position: absolute;
    top: 155px;
    left: 215px;
    width: 50px;
    height: 50px;
    background-color: var(--accent);
    transform: rotate(-45deg);
    z-index: 5;
    cursor: pointer;
    box-shadow: 0 4px 10px var(--accent-glow);
    transition: transform 0.4s ease, opacity 0.4s ease, background-color 0.3s ease;
}

.heart:before, .heart:after {
    content: "";
    position: absolute;
    width: 50px;
    height: 50px;
    background-color: var(--accent);
    border-radius: 50%;
}

.heart:before {
    top: -25px;
    left: 0;
}

.heart:after {
    left: 25px;
    top: 0;
}

/* Seal Pulsing Animation */
@keyframes pulse {
    0% {
        transform: rotate(-45deg) scale(1);
        box-shadow: 0 4px 10px var(--accent-glow);
    }
    50% {
        transform: rotate(-45deg) scale(1.1);
        box-shadow: 0 6px 20px rgba(201, 75, 75, 0.5);
    }
    100% {
        transform: rotate(-45deg) scale(1);
        box-shadow: 0 4px 10px var(--accent-glow);
    }
}

.envelope-wrapper:not(.open) .heart {
    animation: pulse 1.5s infinite;
}

.envelope-hint {
    position: absolute;
    bottom: -60px;
    width: 100%;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
    letter-spacing: 1px;
    animation: bounce 2s infinite;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

/* --- ANIMATION ACTIONS --- */

/* 1. Open the Flap */
.envelope-wrapper.open .top-flap {
    transform: rotateX(180deg);
    z-index: 1; /* Slide behind letter once flipped */
}

/* Hide seal (heart) when open */
.envelope-wrapper.open .heart {
    transform: rotate(-45deg) scale(0);
    opacity: 0;
    pointer-events: none;
}

/* 2. Slide the Letter Out slightly */
.envelope-wrapper.open .letter {
    transform: translateY(-160px);
    z-index: 2;
}

/* Shrink envelope slightly when letter is maximized in modal */
.envelope-wrapper.expanded {
    transform: scale(0.85);
    opacity: 0.5;
}

/* --- MODAL LETTER SYSTEM --- */
.letter-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(61, 47, 43, 0.35);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.letter-modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.letter-modal-card {
    background: var(--paper-bg);
    width: 90%;
    max-width: 600px;
    height: 80vh;
    max-height: 700px;
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 25px 55px rgba(61, 47, 43, 0.25);
    position: relative;
    transform: scale(0.85) translateY(30px);
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    flex-direction: column;
}

.letter-modal-overlay.active .letter-modal-card {
    transform: scale(1) translateY(0);
}

.letter-modal-card .letter-body {
    font-size: 1.55rem;
    flex: 1;
}

/* Close/Fold Button on Modal */
.close-btn {
    position: absolute;
    bottom: -70px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--text-primary);
    color: var(--paper-bg);
    border: none;
    padding: 12px 30px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
    letter-spacing: 1px;
    text-transform: uppercase;
    transition: background-color 0.3s, transform 0.3s;
}

.close-btn:hover {
    background-color: var(--accent);
    transform: translateX(-50%) translateY(-2px);
}

/* Responsive adjustments */
@media (max-width: 520px) {
    .envelope-wrapper {
        width: 320px;
        height: 233px;
    }
    .top-flap {
        border-width: 120px 160px 0 160px;
    }
    .pocket {
        border-width: 120px 160px 113px 160px;
    }
    .letter {
        width: 288px;
        height: 200px;
        left: 16px;
        padding: 15px;
    }
    .letter-body {
        font-size: 1.1rem;
        line-height: 1.5;
    }
    .heart {
        top: 96px;
        left: 135px;
        width: 35px;
        height: 35px;
    }
    .heart:before, .heart:after {
        width: 35px;
        height: 35px;
    }
    .heart:before {
        top: -18px;
    }
    .heart:after {
        left: 18px;
    }
    .envelope-wrapper.open .letter {
        transform: translateY(-110px);
    }
    .letter-modal-card {
        padding: 24px;
        height: 75vh;
    }
    .letter-modal-card .letter-body {
        font-size: 1.25rem;
    }
    .close-btn {
        bottom: -60px;
        padding: 10px 24px;
        font-size: 0.8rem;
    }
}
