@import url('https://fonts.googleapis.com/css2?family=Quicksand:wght@400;500;600;700&display=swap');

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ======================
   PAGE BASE
   ====================== */
body {
    font-family: 'Quicksand', sans-serif;
    min-height: 100vh;
    min-height: 100dvh;
    background: linear-gradient(145deg, #e8608e 0%, #f472a0 35%, #f0879e 65%, #f4a0b5 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

/* ======================
   BACKGROUND EFFECTS
   ====================== */
.bg-effects {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

/* Bokeh */
.bokeh {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
    animation: bokehDrift 10s ease-in-out infinite alternate;
}

@keyframes bokehDrift {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: .25;
    }

    50% {
        transform: translate(20px, -25px) scale(1.15);
        opacity: .45;
    }

    100% {
        transform: translate(-15px, 15px) scale(.9);
        opacity: .2;
    }
}

/* Floating hearts */
.float-heart {
    position: absolute;
    bottom: -30px;
    font-size: 1.1rem;
    opacity: 0;
    animation: heartFloat 8s ease-in-out infinite;
}

@keyframes heartFloat {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 0;
    }

    8% {
        opacity: .35;
    }

    85% {
        opacity: .3;
    }

    100% {
        transform: translateY(-110vh) rotate(25deg);
        opacity: 0;
    }
}

/* Rose petals */
.petal {
    position: absolute;
    top: -20px;
    width: 12px;
    height: 16px;
    background: radial-gradient(ellipse, #f5a0b5 30%, #e8608e);
    border-radius: 50% 50% 50% 0;
    opacity: 0;
    animation: petalDrift 10s ease-in-out infinite;
}

@keyframes petalDrift {
    0% {
        transform: translateY(0) rotate(0) translateX(0);
        opacity: 0;
    }

    8% {
        opacity: .4;
    }

    85% {
        opacity: .3;
    }

    100% {
        transform: translateY(110vh) rotate(400deg) translateX(50px);
        opacity: 0;
    }
}

/* Vignette */
.vignette {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, 0.15) 100%);
}

/* ======================
   ENVELOPE SECTION
   ====================== */
.envelope-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    width: 100%;
    padding-top: 30px;
}

.envelope {
    position: relative;
    width: 380px;
    height: 240px;
    cursor: pointer;
    perspective: 1000px;
    animation: envelopeFloat 4s ease-in-out infinite;
    filter: drop-shadow(0 15px 15px rgba(0, 0, 0, 0.2));
}

@keyframes envelopeFloat {

    0%,
    100% {
        transform: translateY(0);
        filter: drop-shadow(0 15px 15px rgba(0, 0, 0, 0.2));
    }

    50% {
        transform: translateY(-8px);
        filter: drop-shadow(0 25px 30px rgba(0, 0, 0, 0.25));
    }
}

/* Envelope back */
.env-back {
    position: absolute;
    inset: 0;
    background: #d9534f;
    border-radius: 0 0 12px 12px;
    z-index: 1;
}

/* Letter peek inside envelope */
.env-letter-inside {
    position: absolute;
    top: 15px;
    left: 8%;
    width: 84%;
    height: 70%;
    background: #fffaf0;
    border-radius: 6px;
    z-index: 2;
    transition: transform .5s .3s cubic-bezier(.22, 1, .36, 1), opacity .3s .6s ease;
}

.envelope.open .env-letter-inside {
    transform: translateY(-60px) scale(.9);
    opacity: 0;
}

/* Pocket triangles */
.env-front-left {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 190px solid #f5a3a2;
    border-top: 120px solid transparent;
    border-bottom: 120px solid transparent;
    z-index: 3;
}

.env-front-right {
    position: absolute;
    top: 0;
    right: 0;
    width: 0;
    height: 0;
    border-right: 190px solid #f5a3a2;
    border-top: 120px solid transparent;
    border-bottom: 120px solid transparent;
    z-index: 3;
}

.env-front-bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 190px solid transparent;
    border-right: 190px solid transparent;
    border-bottom: 130px solid #ff6f61;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    z-index: 4;
}

/* Flap */
.env-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 190px solid transparent;
    border-right: 190px solid transparent;
    border-top: 140px solid #c0453f;
    z-index: 6;
    transform-origin: top center;
    transition: transform .5s ease-in-out;
}

.envelope.open .env-flap {
    transform: rotateX(180deg);
    z-index: 2;
    transition: transform .5s ease-in-out;
}

/* ======================
   BUTTONS
   ====================== */
.btn-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 14px;
    padding: 24px 16px 36px;
    z-index: 2;
    width: 100%;
    max-width: 600px;
}

.letter-btn {
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    padding: 18px 36px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all .25s ease;
    min-width: 200px;
    text-align: center;
    line-height: 1.3;
}

.open-btn {
    background: linear-gradient(135deg, #f47a8f, #ee5a6f);
    color: #fff;
    box-shadow: 0 4px 22px rgba(238, 90, 111, .35);
}

.open-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 32px rgba(238, 90, 111, .55), 0 0 20px rgba(244, 114, 160, .25);
}

.open-btn:active {
    transform: scale(.97);
}

.open-btn.pulse {
    animation: btnPulse .6s ease;
}

.close-btn {
    background: rgba(255, 255, 255, .18);
    color: #fff;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, .25);
}

.close-btn:hover {
    background: rgba(255, 255, 255, .32);
    transform: scale(1.05);
}

@keyframes btnPulse {
    0% {
        box-shadow: 0 4px 22px rgba(238, 90, 111, .35);
    }

    50% {
        box-shadow: 0 4px 44px rgba(238, 90, 111, .7), 0 0 40px rgba(244, 114, 160, .4);
    }

    100% {
        box-shadow: 0 4px 22px rgba(238, 90, 111, .35);
    }
}

/* ======================
   LETTER OVERLAY
   ====================== */
.letter-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .35);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .4s ease;
    padding: 20px;
    gap: 24px;
}

.letter-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Heart glow behind card */
.letter-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 500px;
    height: 500px;
    transform: translate(-50%, -55%);
    background: radial-gradient(circle, rgba(244, 114, 160, .35) 0%, transparent 60%);
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
    transition: opacity .6s .3s ease;
}

.letter-overlay.visible .letter-glow {
    opacity: 1;
}

/* ======================
   LETTER CARD
   ====================== */
.letter-card {
    position: relative;
    width: min(600px, 92vw);
    max-height: 65vh;
    /* Ensure it leaves room for buttons */
    overflow-y: auto;
    /* Scroll if content is too long */
    overflow-x: hidden;
    /* No horizontal scrollbar */
    background: #fffaf0;
    border-radius: 16px;
    box-shadow:
        0 16px 60px rgba(0, 0, 0, .2),
        0 0 100px rgba(244, 114, 160, .1);
    transform: scale(.3) rotateX(60deg);
    transform-origin: bottom center;
    opacity: 0;
    transition: transform .7s .2s cubic-bezier(.22, 1, .36, 1),
        opacity .4s .2s ease;

    /* Paper texture */
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 30px,
            rgba(200, 180, 160, 0.06) 30px,
            rgba(200, 180, 160, 0.06) 31px);

    /* Scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: #f47a8f transparent;
}

/* Webkit scrollbar */
.letter-card::-webkit-scrollbar {
    width: 6px;
}

.letter-card::-webkit-scrollbar-track {
    background: transparent;
}

.letter-card::-webkit-scrollbar-thumb {
    background-color: #f47a8f;
    border-radius: 10px;
}

.letter-overlay.visible .letter-card {
    transform: scale(1) rotateX(0deg);
    opacity: 1;
    animation: letterHover 5s ease-in-out 1s infinite;
}

@keyframes letterHover {

    0%,
    100% {
        transform: scale(1) translateY(0);
    }

    50% {
        transform: scale(1) translateY(-4px);
    }
}

.letter-content {
    padding: 30px 35px;
    /* Reduced padding */
}

.letter-to {
    font-family: 'Dancing Script', cursive;
    font-size: 1.1rem;
    font-weight: 700;
    color: #c45c78;
    margin-bottom: 8px;
}

.letter-line {
    width: 60px;
    height: 2px;
    background: linear-gradient(90deg, #f472a0, #f5a3a2);
    border-radius: 2px;
    margin-bottom: 16px;
}

.letter-greeting {
    font-family: 'Dancing Script', cursive;
    font-size: 1.5rem;
    /* Reduced */
    font-weight: 700;
    color: #c45c78;
    margin-bottom: 15px;
}

.letter-text {
    font-family: 'Playfair Display', serif;
    font-size: 1.05rem;
    /* Reduced */
    color: #555;
    line-height: 1.6;
    margin-bottom: 12px;
}

.letter-text:last-child {
    margin-bottom: 0;
}

/* Overlay buttons row */
.overlay-btns {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    flex-shrink: 0;
    z-index: 101;
}

.next-link {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ======================
   SPARKLES
   ====================== */
.sparkle {
    position: absolute;
    font-size: 1.1rem;
    color: rgba(244, 169, 191, .65);
    opacity: 0;
    pointer-events: none;
    z-index: 5;
}

.letter-overlay.visible .sparkle {
    animation: sparkle 2.5s ease-in-out infinite alternate;
}

.s1 {
    top: -10px;
    left: -10px;
    animation-delay: 0s;
}

.s2 {
    top: -10px;
    right: -10px;
    animation-delay: .7s;
}

.s3 {
    bottom: -10px;
    left: -10px;
    animation-delay: 1.4s;
}

.s4 {
    bottom: -10px;
    right: -10px;
    animation-delay: 2.1s;
}

@keyframes sparkle {
    0% {
        opacity: 0;
        transform: scale(.5) rotate(0deg);
    }

    50% {
        opacity: 1;
        transform: scale(1.3) rotate(180deg);
    }

    100% {
        opacity: .2;
        transform: scale(.7) rotate(360deg);
    }
}

/* ======================
   HEART BURST
   ====================== */
.heart-burst {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

.burst-heart {
    position: absolute;
    top: 50%;
    left: 50%;
    opacity: 0;
    animation: burstFly 1.2s cubic-bezier(.1, .8, .2, 1) forwards;
}

@keyframes burstFly {
    0% {
        transform: translate(-50%, -50%) scale(0) rotate(0deg);
        opacity: 1;
    }

    15% {
        transform: translate(-50%, -50%) scale(1.2) rotate(var(--r));
        opacity: 1;
    }

    100% {
        transform: translate(var(--tx), var(--ty)) scale(1) rotate(var(--r));
        opacity: 0;
    }
}

/* ======================
   MOBILE: 520px
   ====================== */
@media (max-width: 520px) {
    .envelope {
        width: 300px;
        height: 190px;
    }

    .env-front-left {
        border-left-width: 150px;
    }

    .env-front-right {
        border-right-width: 150px;
    }

    .env-front-left,
    .env-front-right {
        border-top-width: 95px;
        border-bottom-width: 95px;
    }

    .env-front-bottom {
        border-left-width: 150px;
        border-right-width: 150px;
        border-bottom-width: 100px;
    }

    .env-flap {
        border-left-width: 150px;
        border-right-width: 150px;
        border-top-width: 110px;
    }

    .letter-content {
        padding: 32px 28px;
    }

    .letter-greeting {
        font-size: 1.4rem;
    }

    .letter-text {
        font-size: 1.05rem;
    }

    .letter-btn {
        min-width: 170px;
        padding: 15px 28px;
        font-size: .92rem;
    }

    .letter-glow {
        width: 320px;
        height: 320px;
    }
}

/* ======================
   MOBILE: 380px
   ====================== */
@media (max-width: 380px) {
    .envelope {
        width: 260px;
        height: 165px;
    }

    .env-front-left {
        border-left-width: 130px;
    }

    .env-front-right {
        border-right-width: 130px;
    }

    .env-front-left,
    .env-front-right {
        border-top-width: 82px;
        border-bottom-width: 83px;
    }

    .env-front-bottom {
        border-left-width: 130px;
        border-right-width: 130px;
        border-bottom-width: 88px;
    }

    .env-flap {
        border-left-width: 130px;
        border-right-width: 130px;
        border-top-width: 95px;
    }

    .letter-content {
        padding: 24px 20px;
    }

    .letter-to {
        font-size: 1rem;
    }

    .letter-greeting {
        font-size: 1.2rem;
    }

    .letter-text {
        font-size: .95rem;
        line-height: 1.6;
    }

    .letter-btn {
        min-width: 150px;
        padding: 13px 22px;
        font-size: .85rem;
    }
}