:root {
    --linen: #f8f3ec;
    --shadow: rgba(57, 35, 24, 0.15);
    --envelope-height: min(90vh, 640px);
    --envelope-slide: calc(1.8 * min(88vw, 520px));
    --card-offset: 19%;
    --card-width: 64%;
    --card-center-shift: 0px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Playfair Display", "Times New Roman", serif;
    color: #40332a;
    background: radial-gradient(circle at top, rgba(255, 255, 255, 0.8), transparent 60%),
        radial-gradient(circle at 20% 80%, rgba(247, 235, 223, 0.7), transparent 65%),
        var(--linen);
    overflow-x: hidden;
}

.page {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: clamp(16px, 4vw, 32px);
    position: relative;
}

.page::after {
    content: "";
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0.65) 35%, rgba(255, 255, 255, 0) 70%),
        rgba(255, 255, 255, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-out;
}

.restart {
    position: fixed;
    right: clamp(16px, 4vw, 32px);
    bottom: clamp(16px, 4vw, 32px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: clamp(36px, 9vw, 48px);
    height: clamp(36px, 9vw, 48px);
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 14px 35px rgba(24, 17, 12, 0.26);
    color: #40332a;
    font-family: inherit;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
    transform: translateY(12px);
    z-index: 80;
    visibility: hidden;
}

.restart__icon {
    font-size: clamp(16px, 4vw, 20px);
    line-height: 1;
}

.restart.is-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    visibility: visible;
}

.page--flash::after {
    animation: page-flash 1.4s ease-out forwards;
}

.envelope {
    position: relative;
    height: var(--envelope-height);
    width: min(88vw, 520px);
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding: 0;
    overflow: visible;
    cursor: pointer;
}

.envelope:focus-visible {
    outline: 3px solid rgba(57, 35, 24, 0.4);
    outline-offset: 12px;
}

.envelope[data-state="open"] {
    cursor: default;
}

.envelope__image {
    height: 100%;
    width: auto;
    max-width: 100%;
    display: block;
    object-fit: contain;
}

.envelope__image--closed {
    z-index: 2;
    transform-origin: center bottom;
    opacity: 1;
}

.envelope[data-state="open"] .envelope__image--closed {
    animation: envelope-fade 1.1s ease-in forwards;
}

.envelope__open-group {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    pointer-events: none;
    opacity: 0;
}

.envelope__image--body {
    height: min(102%, calc(100% + 24px));
    width: auto;
    max-width: none;
    z-index: 1;
}


.envelope__card-container {
    position: absolute;
    bottom: var(--card-offset);
    left: 50%;
    width: var(--card-width);
    max-width: 280px;
    aspect-ratio: 297 / 419;
    transform: translate(calc(-50% + var(--card-center-shift)), 0);
    transform-origin: center bottom;
    filter: drop-shadow(0 12px 30px rgba(40, 29, 20, 0.18));
    pointer-events: none;
    z-index: 2;
    overflow: visible;
}

.card {
    position: relative;
    width: 100%;
    height: 100%;
    perspective: 1200px;
    pointer-events: none;
}

.card--interactive {
    pointer-events: auto;
}

.card-container--interactive {
    pointer-events: auto;
}

.card__inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transform: rotateY(0deg) scale(0.92);
    transform-origin: center bottom;
    transition: transform 0.8s ease;
    opacity: 1;
}

.card--interactive .card__inner {
    cursor: pointer;
}

.card--flipped .card__inner {
    transform: rotateY(180deg) scale(1);
}

.card__face {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 0;
    overflow: hidden;
    background: transparent;
}

.envelope__card {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    opacity: 1;
}

.card__face-media {
    width: 100%;
    height: 100%;
    display: block;
    border: none;
    background: transparent;
}

.card__face--back {
    transform: rotateY(180deg);
}

.card__cta {
    position: absolute;
    left: 50%;
    bottom: calc(-1 * clamp(52px, 12vw, 76px));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transform: translate(-50%, 12px);
    padding: 8px 18px;
    background: rgba(255, 255, 255, 0.28);
    backdrop-filter: blur(10px) saturate(1.35);
    -webkit-backdrop-filter: blur(10px) saturate(1.35);
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: #40332a;
    font-size: clamp(12px, 3vw, 16px);
    letter-spacing: 0.08em;
    text-transform: none;
    text-align: center;
    font-family: "Snell Roundhand", "Segoe Script", "Apple Chancery", "URW Chancery L", cursive;
    line-height: 1.3;
    box-shadow: 0 16px 35px rgba(24, 17, 12, 0.18);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 5;
}

.card__cta:focus-visible {
    outline: 2px solid rgba(64, 51, 42, 0.45);
    outline-offset: 3px;
}

.card-container--interactive {
    pointer-events: auto;
}

.card-container--interactive .card__cta {
    pointer-events: auto;
    opacity: 0.95;
    transform: translate(-50%, 0);
}

.envelope__card-container--expanded.card-container--interactive {
    padding-bottom: 0;
}

.envelope__image--top {
    position: absolute;
    bottom: 0;
    z-index: 3;
    height: min(102%, calc(100% + 24px));
    width: auto;
    max-width: none;
}

.envelope[data-state="open"] .envelope__open-group {
    animation:
        envelope-open 0.9s ease-out 0.05s forwards,
        envelope-slide-right 1s ease-in-out 0.7s forwards;
}

.envelope[data-state="open"] .envelope__card-container {
    animation: card-counter-slide 1s ease-in-out 0.7s forwards;
    animation-fill-mode: forwards;
}

.envelope[data-state="open"] .card__inner {
    animation: card-rise 1.1s ease-out 0.15s forwards;
    animation-fill-mode: forwards;
}

html.card-expanded,
body.card-expanded {
    overflow: hidden;
    height: 100%;
}

.envelope__card-container--expanded {
    animation: none !important;
    position: fixed;
    top: 0;
    left: 0;
    bottom: auto;
    transform: none;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    pointer-events: auto;
    z-index: 40;
    filter: drop-shadow(0 24px 70px rgba(24, 17, 12, 0.28));
}

.envelope__card-container--expanded .envelope__card {
    width: 100%;
    height: 100%;
    opacity: 1;
}


@keyframes envelope-fade {
    0% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

@keyframes envelope-open {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

@keyframes card-rise {
    0% {
        transform: scale(0.92);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes page-flash {
    0% {
        opacity: 0;
    }

    25% {
        opacity: 1;
    }

    60% {
        opacity: 0.55;
    }

    100% {
        opacity: 0;
    }
}

@keyframes envelope-slide-right {
    0% {
        transform: translateX(0);
    }

    100% {
        transform: translateX(var(--envelope-slide));
    }
}

@keyframes card-counter-slide {
    0% {
        transform: translate(-50%, 0);
    }

    100% {
        transform: translate(calc(-50% - var(--envelope-slide)), 0);
    }
}

@media (max-width: 900px) {
    :root {
        --card-offset: 21%;
        --card-center-shift: -8px;
    }
}

@media (max-width: 720px) {
    :root {
        --card-offset: 24%;
        --card-center-shift: -14px;
    }
}

@media (max-width: 640px) {
    :root {
        --card-offset: clamp(112px, 24vh, 204px);
        --card-width: 60%;
        --card-center-shift: -22px;
    }
}

@media (max-width: 520px) {
    :root {
        --card-width: 56%;
        --card-center-shift: -30px;
    }
}

@media (max-width: 480px) {
    :root {
        --card-offset: clamp(124px, 27vh, 214px);
        --card-width: 52%;
        --card-center-shift: -36px;
    }
}

@media (max-width: 480px) and (min-height: 880px) {
    :root {
        --card-offset: clamp(136px, 29vh, 226px);
    }
}

@media (max-width: 420px) and (max-height: 780px) {
    :root {
        --card-offset: clamp(104px, 24vh, 164px);
        --card-width: 50%;
        --card-center-shift: -40px;
    }
}

@media (max-width: 380px) and (max-height: 700px) {
    :root {
        --card-offset: clamp(94px, 22vh, 148px);
        --card-width: 48%;
        --card-center-shift: -44px;
    }
}

@media (max-height: 720px) {
    :root {
        --envelope-height: min(92vh, 560px);
    }
}
.envelope__cta {
    position: absolute;
    top: max(8%, 36px);
    left: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    transform: translate(-50%, -10px);
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.28);
    backdrop-filter: blur(8px) saturate(1.4);
    -webkit-backdrop-filter: blur(8px) saturate(1.4);
    border-radius: 999px;
    font-size: clamp(13px, 3.2vw, 18px);
    letter-spacing: 0.04em;
    text-transform: none;
    font-family: "Snell Roundhand", "Segoe Script", "Apple Chancery", "URW Chancery L", cursive;
    color: #40332a;
    box-shadow: 0 18px 40px rgba(24, 17, 12, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.45);
    transition: opacity 0.4s ease, transform 0.4s ease;
    pointer-events: none;
    opacity: 0.98;
    z-index: 5;
    min-width: clamp(160px, 54vw, 220px);
    justify-content: center;
}

.envelope:focus-visible .envelope__cta,
.envelope:hover .envelope__cta {
    transform: translate(-50%, -16px);
}

.envelope[data-state="open"] .envelope__cta {
    opacity: 0;
    transform: translate(-50%, -22px);
    transition-delay: 0.1s;
}
