body {
    background: #b6a1a5;
    color: #40424a;
    font-family: "Playfair Display", serif;
    font-optical-sizing: auto;
    font-weight: 200;
    font-style: normal;

    perspective: 600px;
    position: relative;
    width: 100vw;
    height: 100vh;
}

.letter-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
    align-items: center;
    justify-content: center;

    height: 100%;
    width: 100%;
}

.top-fold__heart {
    position: absolute;
    width: 80px;
    height: 60px;
    top: 50%;
    text-align: center;
    left: 50%;
    filter: drop-shadow(0 10px 3px rgba(0, 0, 0, 0.3));
    transform: translate(-50%, -50%);
    z-index: 5;
}

.top-fold__stamp {
    position: absolute;
    background-color: #970101;
    border: 4px solid;
    border-color: #860000;
    border-radius: 45% 55% 40% 60% / 51% 42% 58% 49%;
    width: 70px;
    height: 70px;
    top: 30%;
    left: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.3));
    transform: translate(-50%, -50%);

    z-index: 5;
}

.top-fold__stamp-image {
    height: 100%;
    filter: contrast(200%) brightness(10%);
    opacity: 0.3;
    z-index: 6;
    transition: opacity 0.4s ease-in-out;
}

.envelope {
    position: relative;
    height: 150px;
    width: 200px;
    border-radius: 2px;
    transition: transform 0.4s;

    .body {
        position: absolute;
        bottom: 0;
        width: 0;
        height: 0;
        border-style: solid;
        border-width: 0 0 100px 200px;
        border-radius: 4px;
        border-color: transparent transparent #e8d5b5 transparent;
        z-index: 2;
    }

    .top-fold {
        position: absolute;
        top: 50px;
        width: 0;
        height: 0;
        border-style: solid;
        border-width: 60px 100px 0 100px;
        transform-origin: 50% 0%;
        filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.2));
        /* border-radius: 4px 4px 0 4px; */
        transition:
            transform 0.4s 0.4s,
            z-index 0.2s 0.4s;
        border-color: #bcac91 transparent transparent transparent;
        z-index: 5;
    }

    .back-fold {
        position: absolute;
        bottom: 10px;
        width: 200px;
        height: 90px;
        background: #3b4522;
        z-index: 0;
    }

    .left-fold {
        position: absolute;
        bottom: 0;
        width: 0;
        height: 0;
        border-style: solid;
        border-width: 51px 0 49px 100px;
        border-radius: 0 0 0 4px;
        border-color: transparent transparent transparent #d0bea0;
        z-index: 2;
    }

    .letter {
        left: 20px;
        bottom: 0px;
        position: absolute;
        border-radius: 2px;
        width: 160px;
        height: 60px;
        background: white;
        z-index: 1;
        overflow: hidden;
        transform-style: preserve-3d;
        transition: 0.4s 0.2s;
        transform: translateX(0px) translateY(0px) translateZ(0px);

        .letter__front {
            position: absolute;
            width: 100%;
            height: 100%;
            backface-visibility: hidden;
        }

        .letter__back {
            position: absolute;
            width: 100%;
            height: 100%;
            opacity: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .letter__back-image {
            width: 200px;
            margin: auto;
            filter: grayscale(100%) contrast(150%) brightness(80%);
            transition: filter 0.4s;
        }

        .letter__back-image:hover {
            filter: grayscale(0%) contrast(100%) brightness(100%);
        }

        .letter__back-text {
            box-sizing: border-box;
            height: 100%;
            font-size: 24px;
            text-align: center;
            word-wrap: normal;
            padding: 12px;
            display: flex;
            flex-direction: column;
            gap: 16px;
        }

        .letter__back-salutation {
            font-size: 14px;
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .letter__back-signature {
            font-family: "Mea Culpa", cursive;
            font-weight: 400;
            font-style: normal;
            font-size: 32px;
        }

        .letter-title {
            padding: 8px;
        }

        .letter-context {
            margin-top: 10px;
            margin-left: 5px;
            height: 10px;
            width: 20%;
            background: #1d2505;
        }

        .letter-stamp {
            margin-top: 30px;
            margin-left: 120px;
            border-radius: 100%;
            height: 30px;
            width: 30px;
            background: #1d2505;
            opacity: 0.3;
        }
    }
}

.envelope:hover:not(.open) {
    transform: translateY(10px) translateX(0px);
}

.envelope.open {
    .top-fold {
        transition:
            border-top-color 0.2s 0.2s,
            transform 0.4s;
        transform: rotateX(180deg);
        z-index: 0;
        border-top-color: #424d26;
    }

    .top-fold__stamp-image {
        opacity: 0;
    }

    .letter {
        height: 180px;
        transition-delay: 0.4s;
        animation: wiggle-letter 5s infinite;
    }

    .shadow {
        width: 250px;
    }

    .letter__large {
        animation: present-letter 0.4s forwards;
        transition-delay: 0s;
        z-index: 10;
        box-shadow: 0 -20px 20px 5px rgba(0, 0, 0, 0.15);
        transform-style: preserve-3d;
    }

    .letter__animated {
        animation: hide-letter 0.4s forwards;
    }
}

.letter.letter__large {
    .letter__front {
        opacity: 0;
    }
    .letter__back {
        opacity: 1;
        transform: rotateX(180deg);
        filter: drop-shadow(-6px 4px 5px 8px rgba(0, 0, 0, 0.2));
    }
}

@keyframes wiggle-letter {
    0% {
        transform: translateY(0px);
    }
    25% {
        transform: translateY(-10px);
    }
    50% {
        transform: translateY(0px);
    }
    75% {
        transform: translateY(-10px);
    }
    100% {
        transform: translateY(0px);
    }
}

@keyframes present-letter {
    0% {
        transform: translateY(0px) rotateX(0deg) translateX(0px);
        height: 180px;
        width: 160px;
        z-index: 1;
    }
    50% {
        transform: translateY(-250px) rotateX(-90deg) translateX(0px);
        z-index: 1;
    }
    100% {
        transform: translateY(250px) rotateX(-180deg) translateX(-100px);
        height: 500px;
        width: 360px;
        z-index: 10;
    }
}

@keyframes hide-letter {
    0% {
        transform: translateY(250px) rotateX(-180deg) translateX(-100px);
        height: 500px;
        width: 360px;
        z-index: 10;
    }

    50% {
        transform: translateY(-250px) rotateX(-90deg) translateX(0px);
        z-index: 10;
    }

    100% {
        transform: translateY(0px) rotateX(0deg) translateX(0px);
        height: 180px;
        width: 160px;
        z-index: 1;
    }
}

.horizontal-shake {
    animation: horizontal-shaking 1s forwards;
}

@keyframes horizontal-shaking {
    0% {
        transform: translateY(10px) translateX(0);
    }
    25% {
        transform: translateX(5px);
    }
    50% {
        transform: translateX(-5px);
    }
    75% {
        transform: translateX(5px);
    }
    100% {
        transform: translateY(20px) translateX(0);
    }
}

.timer {
    font-size: 0.8rem;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
