.envelope-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    transition: opacity 0.8s ease, visibility 0.8s ease;
}

.envelope-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.envelope-scene {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* --- Обёртка конверта --- */
.envelope {
    position: relative;
    width: 280px;
    height: 180px;
    perspective: 800px;
}

/* --- Тело конверта --- */
.env-body {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 140px;
    background: #e8dfd3;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    z-index: 3;
    overflow: hidden;
    transition: overflow 0s linear 0.3s;
}

/* Внутренний нижний клапан */
.env-body::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 0; height: 0;
    border-left: 140px solid transparent;
    border-right: 140px solid transparent;
    border-bottom: 70px solid #ddd4c6;
    z-index: 3;
}

/* --- Письмо (внутри env-body) --- */
.env-letter {
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 240px;
    background: #fffef8;
    border-radius: 4px;
    padding: 14px 12px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    z-index: 2;
    transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.25s;
}

.env-letter-title {
    font-family: var(--body);
    font-size: 10px;
    color: var(--gray);
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 8px;
    font-weight: 600;
}

.env-letter-names {
    font-family: var(--body);
    font-size: 11px;
    color: var(--ink);
    letter-spacing: 4px;
    text-transform: uppercase;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 8px;
}

.env-letter-heart {
    display: inline-block;
    vertical-align: middle;
}

.env-letter-date {
    font-family: var(--body);
    font-size: 13px;
    color: var(--gray);
    font-style: italic;
}

/* --- Верхний клапан --- */
.env-flap {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 0;
    z-index: 4;
    transform-origin: top center;
    transition: transform 0.6s ease;
}

.env-flap::after {
    content: '';
    display: block;
    width: 0; height: 0;
    border-left: 140px solid transparent;
    border-right: 140px solid transparent;
    border-top: 95px solid #d4c9b8;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.08));
}

/* --- Печать --- */
.env-seal {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    width: 48px;
    height: 48px;
    z-index: 5;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

/* --- Подсказка --- */
.envelope-hint {
    font-family: var(--hand);
    font-size: 20px;
    color: var(--ink);
    margin-top: 30px;
    opacity: 0.6;
    animation: hint-pulse 2s ease-in-out infinite;
    transition: opacity 0.3s ease;
}

@keyframes hint-pulse {
    0%, 100% { opacity: 0.6; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-3px); }
}

/* ================================
   ОТКРЫТОЕ СОСТОЯНИЕ
================================ */
.envelope-scene.opened .env-flap {
    transform: rotateX(180deg);
    z-index: 1;
}

.envelope-scene.opened .env-body {
    overflow: visible;
}

.envelope-scene.opened .env-letter {
    transform: translateX(-50%) translateY(-195px);
}

.envelope-scene.opened .env-seal {
    opacity: 0;
    transform: translateX(-50%) scale(0) rotate(30deg);
    pointer-events: none;
}

.envelope-scene.opened .envelope-hint {
    opacity: 0;
    animation: none;
}




@media (max-width: 360px) {
    .envelope { width: 250px; height: 160px; }
    .env-body { height: 125px; }
    .env-body::before {
        border-left: 125px solid transparent;
        border-right: 125px solid transparent;
        border-bottom: 62px solid #ddd4c6;
    }
    .env-flap::after {
        border-left: 125px solid transparent;
        border-right: 125px solid transparent;
        border-top: 85px solid #d4c9b8;
    }
    .env-letter { width: 215px; padding: 12px 10px; }
    .env-letter-names { font-size: 18px; }
    .env-letter-title { font-size: 10px; }
    .env-letter-date { font-size: 12px; }
    .env-seal { width: 40px; height: 40px; top: 42px; }
    .envelope-hint { font-size: 17px; margin-top: 24px; }
    .envelope-scene.opened .env-letter {
        transform: translateX(-50%) translateY(-170px);
    }
}

@media (min-width: 768px) {
    .envelope { width: 360px; height: 230px; }
    .env-body { height: 180px; }
    .env-body::before {
        border-left: 180px solid transparent;
        border-right: 180px solid transparent;
        border-bottom: 90px solid #ddd4c6;
    }
    .env-flap::after {
        border-left: 180px solid transparent;
        border-right: 180px solid transparent;
        border-top: 120px solid #d4c9b8;
    }
    .env-letter { width: 310px; padding: 22px 20px; }
    .env-letter-names { font-size: 30px; margin-bottom: 8px; }
    .env-letter-title { font-size: 13px; margin-bottom: 6px; }
    .env-letter-date { font-size: 16px; }
    .env-seal { width: 56px; height: 56px; top: 65px; }
    .envelope-hint { font-size: 22px; margin-top: 36px; }
    .envelope-scene.opened .env-letter {
        transform: translateX(-50%) translateY(-245px);
    }
}

@media (min-width: 1024px) {
    .envelope { width: 420px; height: 270px; }
    .env-body { height: 210px; }
    .env-body::before {
        border-left: 210px solid transparent;
        border-right: 210px solid transparent;
        border-bottom: 105px solid #ddd4c6;
    }
    .env-flap::after {
        border-left: 210px solid transparent;
        border-right: 210px solid transparent;
        border-top: 140px solid #d4c9b8;
    }
    .env-letter { width: 360px; padding: 28px 24px; }
    .env-letter-names { font-size: 36px; margin-bottom: 10px; }
    .env-letter-title { font-size: 15px; margin-bottom: 8px; }
    .env-letter-date { font-size: 18px; }
    .env-seal { width: 62px; height: 62px; top: 78px; }
    .envelope-hint { font-size: 24px; margin-top: 44px; }
    .envelope-scene.opened .env-letter {
        transform: translateX(-50%) translateY(-290px);
    }
}

/* Блокировка скролла пока конверт открыт */
html.envelope-lock {
    overflow: hidden !important;
    height: 100% !important;
}

html.envelope-lock body {
    overflow: hidden !important;
    height: 100% !important;
    /* НЕ position:fixed — это ломает всё */
}