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

html,
body {
    width: 100%;
    height: 100%;
    touch-action: pan-x pan-y;
}

body {
    background: linear-gradient(135deg, #f9a8c4, #f472b6, #c084fc, #e879f9);
    background-size: 400% 400%;
    animation: gradientShift 10s ease infinite;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-family: 'Lato', sans-serif;
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

/* ── Vignette overlay ── */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 60%, rgba(0, 0, 0, 0.45) 100%);
    pointer-events: none;
    z-index: 0;
}

/* ── Background particle canvas ── */
#bg-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    contain: strict;
}

/* ── Scene container ── */
#scene {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(16px, 3vw, 28px);
}

/* ── "Click to open" message ── */
#open-msg {
    font-family: 'Chewy', cursive;
    font-weight: 400;
    font-size: clamp(16px, 3.8vw, 48px);
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 1px 10px rgba(160, 60, 90, 0.5);
    letter-spacing: 0.06em;
    opacity: 0;
    transition: opacity 0.8s ease;
    user-select: none;
    pointer-events: none;
    margin-bottom: 44px;
}

#open-msg.visible {
    opacity: 1;
    pointer-events: auto;
}

#open-msg .letter {
    display: inline-block;
}

/* ── Flip prompt ── */
#flip-msg {
    position: fixed;
    bottom: 14vh;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Chewy', cursive;
    font-weight: 400;
    font-size: clamp(16px, 3.8vw, 34px);
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 1px 10px rgba(160, 60, 90, 0.5);
    letter-spacing: 0.06em;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    z-index: 20;
    transition: opacity 0.6s ease;
    animation: none;
}

#flip-msg.visible {
    opacity: 1;
    pointer-events: auto;
    animation: flipMsgPulse 1.8s ease-in-out infinite;
    cursor: pointer;
}

@keyframes flipMsgPulse {

    0%,
    100% {
        transform: translateX(-50%) scale(1);
    }

    50% {
        transform: translateX(-50%) scale(1.08);
    }
}


/* ── Envelope wrapper ── */
#envelope-wrapper {
    position: relative;
    /* Fill the screen on small displays; cap at 1280 px on large ones;
       also prevent overflow if the viewport is short */
    width: min(1280px, 95vw, calc(60dvh * 420 / 264));
    /* Aspect ratio 420:264 = ~1.591 */
    aspect-ratio: 420 / 264;
    transform: translateY(calc(100dvh + 300px));
    transition: transform 1s cubic-bezier(0.16, 1, 0.3, 1);
    filter: drop-shadow(0 16px 40px rgba(160, 60, 90, 0.3));
    cursor: pointer;
    will-change: transform;
}

#envelope-wrapper.arrived {
    transform: translateY(0);
}

/* ── SVG envelope layers (back + front) fill the wrapper ── */
#svg-back {
    overflow: visible;
    /* open flap extends above the viewBox */
}

#svg-back,
#svg-front {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ── Name-writing canvas, overlaid on the envelope ── */
#name-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    contain: strict;
}

/* ── Card inside the envelope ── */
#card-container {
    cursor: pointer;
    position: absolute;
    left: 50%;
    top: 50%;
    width: 55%;
    aspect-ratio: 1074 / 1586;
    transform: translate(-50%, -50%);
    perspective: 800px;
    opacity: 1;
    transition: opacity 0.4s ease;
    will-change: transform;
}

#card {
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transform: rotate(-90deg);
    will-change: transform;
}

.card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    overflow: hidden;
    box-shadow: 0 6px 24px rgba(120, 40, 70, 0.25);
}

.card-front img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    user-select: none;
    pointer-events: none;
    z-index: 1;
    transition: opacity 1s ease-in-out;
}

.card-front img.fade-out {
    opacity: 0;
}

#card-img-2 {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    z-index: 0;
}

.card-back {
    background: #fff8fa;
    transform: rotateY(180deg);
}

/* ── Card back message ── */
.card-message-shell {
    position: absolute;
    top: 4%;
    left: 7%;
    right: 7%;
    bottom: 10%;
    overflow: hidden;
    font-family: 'Lato', sans-serif;
    font-size: clamp(7px, 1.95vh, 24px);
    font-weight: 300;
    color: #4a2030;
    line-height: 1.65;
    pointer-events: none;
}

.card-message-page {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    padding-bottom: 0.7em;
}

.card-back.is-typing {
    cursor: pointer;
}

.card-message-shell p {
    margin: 0;
    min-height: 1em;
}

.card-message-shell .msg-greeting {
    font-family: 'Dancing Script', cursive;
    font-size: clamp(9px, 4.85vh, 54px);
    font-weight: 500;
    color: #b5325a;
    margin-bottom: 0.3em;
    line-height: 1.2;
}

.card-message-shell .msg-signature {
    font-weight: 700;
    color: #b5325a;
    margin-top: 0.15em;
}

.card-message-nav {
    position: absolute;
    right: 4.6%;
    bottom: 3.2%;
    display: flex;
    align-items: center;
    gap: 0.5em;
    z-index: 2;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.card-message-nav.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.card-message-page-indicator {
    display: inline-flex;
    align-items: center;
    min-height: 2.4em;
    padding: 0.3em 0.8em;
    border-radius: 999px;
    background: rgba(255, 248, 250, 0.92);
    border: 1px solid rgba(181, 50, 90, 0.18);
    box-shadow: 0 6px 18px rgba(181, 50, 90, 0.12);
    font-size: clamp(6px, 1.5vh, 15px);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #8e2347;
    white-space: nowrap;
}

.card-message-button {
    border: 0;
    border-radius: 999px;
    padding: 0.42em 0.95em;
    background: linear-gradient(135deg, #b5325a, #d94d7f);
    color: #fff;
    font: inherit;
    font-size: clamp(7px, 1.8vh, 17px);
    font-weight: 700;
    letter-spacing: 0.04em;
    box-shadow: 0 8px 20px rgba(181, 50, 90, 0.24);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.card-message-button:hover,
.card-message-button:focus-visible {
    transform: translateY(-1px) scale(1.03);
    box-shadow: 0 10px 24px rgba(181, 50, 90, 0.3);
    outline: none;
}

.card-message-button:active {
    transform: scale(0.97);
}

.card-message-button-next {
    animation: cardMessageButtonPulse 1.8s ease-in-out infinite;
}

.card-message-button-prev {
    background: rgba(255, 248, 250, 0.96);
    color: #8e2347;
    border: 1px solid rgba(181, 50, 90, 0.18);
    box-shadow: 0 6px 18px rgba(181, 50, 90, 0.12);
}

@keyframes cardMessageButtonPulse {

    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 8px 20px rgba(181, 50, 90, 0.24);
    }

    50% {
        transform: scale(1.06);
        box-shadow: 0 12px 28px rgba(181, 50, 90, 0.32);
    }
}

.card-message-measure {
    visibility: hidden;
    opacity: 0;
}

.card-skip-hint {
    position: absolute;
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    bottom: 5%;
    padding: 0.3em 0.9em;
    border-radius: 999px;
    background: rgba(255, 248, 250, 0.92);
    border: 1px solid rgba(181, 50, 90, 0.2);
    box-shadow: 0 4px 14px rgba(181, 50, 90, 0.14);
    font-family: 'Lato', sans-serif;
    font-size: clamp(6px, 1.35vh, 13px);
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #8e2347;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.4s ease, transform 0.4s ease;
    pointer-events: none;
    z-index: 3;
}

.card-skip-hint.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Confetti cannon canvas (full-screen, on top) ── */
#confetti-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
    contain: strict;
}

/* ── Effect canvas: wax dissolve + fold animation ──
   Extends 50% above the envelope so the opened flap
   can appear sticking up above the top edge.          */
#effect-canvas {
    position: absolute;
    top: -50%;
    left: 0;
    width: 100%;
    height: 150%;
    pointer-events: none;
    contain: strict;
}

/* ── Card flip animation ── */
@keyframes cardFlipBounce {
    0% {
        transform: rotateY(0deg);
    }

    50% {
        transform: rotateY(210deg);
    }

    68% {
        transform: rotateY(162deg);
    }

    82% {
        transform: rotateY(193deg);
    }

    91% {
        transform: rotateY(174deg);
    }

    97% {
        transform: rotateY(182deg);
    }

    100% {
        transform: rotateY(180deg);
    }
}

@keyframes cardFlipBounceReverse {
    0% {
        transform: rotateY(180deg);
    }

    50% {
        transform: rotateY(-30deg);
    }

    68% {
        transform: rotateY(18deg);
    }

    82% {
        transform: rotateY(-13deg);
    }

    91% {
        transform: rotateY(6deg);
    }

    97% {
        transform: rotateY(-2deg);
    }

    100% {
        transform: rotateY(0deg);
    }
}

/* ══════════════════════════════════════════════
   LOADER OVERLAY
   ══════════════════════════════════════════════ */

#loader {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #000;
    overflow: hidden;
    opacity: 1;
    transition: opacity 0.85s ease;
}

/* ── Gradient background layer (fades in when spotlight turns on) ── */
#loader::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(135deg, #831843, #9d174d, #6b21a8, #7e22ce);
    background-size: 400% 400%;
    animation: gradientShift 10s ease infinite;
    opacity: 0;
    transition: opacity 1.2s ease;
    pointer-events: none;
}

#loader.spotlight-on::after {
    opacity: 0.22;
}

/* ── Loader content wrapper ── */
#loader-content {
    position: relative;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(20px, 4vw, 36px);
    opacity: 0;
    transition: opacity 0.8s ease;
}

#loader-content.visible {
    opacity: 1;
}

/* ── Spotlight canvas (JS-controlled) ── */
#spotlight-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 3;
    opacity: 1;
    transition: opacity 1.4s ease;
}

#loader.spotlight-off #spotlight-canvas {
    opacity: 0;
}

#loader.fade-out {
    opacity: 0;
    pointer-events: none;
}

#loader-icon {
    font-size: clamp(52px, 14vw, 96px);
    line-height: 1;
    user-select: none;
    animation: loaderIn 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both,
        loaderIconBounce 2.4s ease-in-out 0.7s infinite;
    filter: drop-shadow(0 6px 18px rgba(180, 60, 100, 0.30));
}

@keyframes loaderIn {
    from {
        opacity: 0;
        transform: translateY(-24px) scale(0.7);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes loaderIconBounce {

    0%,
    100% {
        transform: rotate(-6deg);
    }

    50% {
        transform: rotate(6deg);
    }
}

/* Bar track — tall pill, text lives inside */
#loader-bar-track {
    position: relative;
    width: min(520px, 82vw);
    height: clamp(56px, 11vw, 76px);
    border-radius: 99px;
    /* Outer glass shell */
    background: rgba(255, 255, 255, 0.22);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow:
        /* depth shadow */
        0 8px 32px rgba(170, 50, 100, 0.28),
        0 2px 8px rgba(170, 50, 100, 0.14),
        /* inner dark bevel at bottom — gives the concave bowl feel */
        inset 0 -3px 8px rgba(140, 30, 80, 0.20),
        /* bright highlight rim at top */
        inset 0 2px 1px rgba(255, 255, 255, 0.80),
        /* glassy border ring */
        inset 0 0 0 1.5px rgba(255, 255, 255, 0.50);
    animation: loaderBarIn 0.7s 0.15s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    overflow: hidden;
}

/* Top-edge specular highlight strip — the "glass ridge" */
#loader-bar-track::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 8%;
    right: 8%;
    height: 35%;
    border-radius: 99px;
    background: linear-gradient(180deg,
            rgba(255, 255, 255, 0.70) 0%,
            rgba(255, 255, 255, 0.08) 100%);
    pointer-events: none;
    z-index: 3;
}

@keyframes loaderBarIn {
    from {
        opacity: 0;
        transform: scaleX(0.6);
    }

    to {
        opacity: 1;
        transform: scaleX(1);
    }
}

#loader-bar-fill {
    position: absolute;
    top: 4px;
    bottom: 4px;
    left: 4px;
    width: 0%;
    max-width: calc(100% - 8px);
    /* prevent overflow past the right rim */
    border-radius: 99px;
    /* Vivid hot-pink gradient that shimmers */
    background: linear-gradient(90deg, #f472b6, #ec4899, #db2777, #f472b6);
    background-size: 300% 100%;
    animation: loaderBarShimmer 1.8s linear infinite;
    transition: width 0.12s linear;
    will-change: width;
    /* top highlight on fill for the 3-D "bubble" look */
    box-shadow:
        inset 0 3px 5px rgba(255, 255, 255, 0.45),
        inset 0 -2px 4px rgba(140, 20, 70, 0.30),
        0 2px 10px rgba(220, 50, 120, 0.40);
}

@keyframes loaderBarShimmer {
    0% {
        background-position: 100% 0;
    }

    100% {
        background-position: -100% 0;
    }
}

#loader-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Chewy', cursive;
    font-size: clamp(13px, 3.2vw, 22px);
    color: #fff;
    text-shadow:
        0 1px 0 rgba(255, 255, 255, 0.35),
        0 1px 6px rgba(130, 20, 70, 0.70),
        0 0 14px rgba(200, 50, 110, 0.40);
    letter-spacing: 0.04em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 clamp(16px, 3vw, 28px);
    user-select: none;
    z-index: 2;
}

/* ══════════════════════════════════════════════
   ROTATE OVERLAY (landscape on mobile)
   ══════════════════════════════════════════════ */

#rotate-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 20000;
    background: #1a0010;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

#rotate-icon {
    font-size: clamp(3rem, 14vw, 6rem);
    animation: rotatePhone 2.4s ease-in-out infinite;
}

@keyframes rotatePhone {

    0%,
    30% {
        transform: rotate(0deg);
    }

    55%,
    75% {
        transform: rotate(90deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

#rotate-content p {
    font-family: 'Chewy', cursive;
    font-size: clamp(1.2rem, 5vw, 2rem);
    color: #fff;
    text-align: center;
    max-width: 24ch;
    line-height: 1.4;
    text-shadow: 0 2px 12px rgba(200, 60, 100, 0.5);
    letter-spacing: 0.04em;
}

/* ══════════════════════════════════════════════
   MOBILE PORTRAIT OVERRIDES
   ══════════════════════════════════════════════ */

/* Show rotate overlay when landscape on a mobile-sized screen */
@media (max-width: 900px) and (orientation: landscape) {
    #rotate-overlay {
        display: flex;
    }
}

/* Portrait mobile tweaks */
@media (max-width: 768px) and (orientation: portrait) {

    /* Bigger prompt text */
    #open-msg {
        font-size: clamp(18px, 5.5vw, 48px);
    }

    #flip-msg {
        font-size: clamp(18px, 5.5vw, 34px);
    }

    /* Card message text */
    .card-message-shell {
        font-size: clamp(7px, 3.10vw, 24px);
    }

    .card-message-shell .msg-greeting {
        font-size: clamp(9px, 6.8vw, 54px);
    }

    .card-message-nav {
        right: 4.2%;
        bottom: 2.8%;
        gap: 0.35em;
    }

    .card-message-page-indicator {
        font-size: clamp(7px, 2.6vw, 15px);
        padding: 0.32em 0.72em;
    }

    .card-message-button {
        font-size: clamp(8px, 3vw, 17px);
        padding: 0.45em 0.9em;
    }

    .card-skip-hint {
        font-size: clamp(7px, 2.4vw, 13px);
    }
}

/* ── Bouquet decoration ── */
#bouquet {
    position: fixed;
    bottom: 5vh;
    left: -200vw;
    height: clamp(360px, 70vh, 820px);
    width: auto;
    z-index: 15;
    pointer-events: none;
    user-select: none;
    transform-origin: bottom center;
    filter: drop-shadow(0 10px 28px rgba(80, 30, 60, 0.32));
    will-change: transform;
}

@keyframes bouquetSway {
    0% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-3.5deg);
    }

    75% {
        transform: rotate(3.5deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

@media (max-width: 900px) {
    #bouquet {
        display: none;
    }
}

@keyframes bouquetSwayMobile {
    0% {
        transform: translateX(-18%) rotate(0deg);
    }

    25% {
        transform: translateX(-18%) rotate(-3.5deg);
    }

    75% {
        transform: translateX(-18%) rotate(3.5deg);
    }

    100% {
        transform: translateX(-18%) rotate(0deg);
    }
}