.envelope-wrapper {
    cursor: pointer;
    perspective: 1200px;
    transition: transform 0.4s ease, opacity 0.4s ease;
}

.envelope-wrapper.hide {
    transform: scale(0.65) translateY(-30px);
    opacity: 0;
    pointer-events: none;
    display: none;
}

.envelope {
    position: relative;
    width: 340px;
    height: 275px;
    background: #020914; /* Đáy trong lòng bao thư */
    border-radius: 12px;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.8), 0 0 35px rgba(0, 210, 255, 0.35);
    border: 1.5px solid rgba(0, 230, 255, 0.5);
    perspective: 1200px;
    overflow: visible !important; /* Cho phép thẻ nhô cao lên khỏi miệng thư */
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: 0;
    transition: all 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.envelope:hover {
    transform: translateY(-8px) scale(1.03);
    box-shadow: 0 25px 55px rgba(0, 0, 0, 0.9), 0 0 45px rgba(0, 230, 255, 0.6);
    border-color: #00f0ff;
}

/* 4 góc điểm ngắm công nghệ */
.tech-corner {
    position: absolute;
    width: 8px;
    height: 8px;
    border-color: #00f0ff;
    z-index: 10;
}
.tech-corner.tl { top: 6px; left: 6px; border-top: 2px solid #00f0ff; border-left: 2px solid #00f0ff; }
.tech-corner.tr { top: 6px; right: 6px; border-top: 2px solid #00f0ff; border-right: 2px solid #00f0ff; }
.tech-corner.bl { bottom: 6px; left: 6px; border-bottom: 2px solid #00f0ff; border-left: 2px solid #00f0ff; }
.tech-corner.br { bottom: 6px; right: 6px; border-bottom: 2px solid #00f0ff; border-right: 2px solid #00f0ff; }

/* Nắp bao thư */
.envelope-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 170px solid transparent;
    border-right: 170px solid transparent;
    border-top: 110px solid #103b6e;
    border-radius: 8px 8px 0 0;
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.6));
    transform-origin: top center;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 5;
}

/* Con dấu Mũ Tốt Nghiệp Radar */
.seal {
    position: absolute;
    top: 75px;
    width: 74px;
    height: 74px;
    background: radial-gradient(circle, #00f0ff, #00509d);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    cursor: pointer;
    z-index: 6;
    border: 2px solid #ffffff;
    box-shadow: 0 0 25px rgba(0, 240, 255, 0.9);
}

.radar-circle {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px dashed rgba(255, 255, 255, 0.7);
    animation: rotateRadar 6s linear infinite;
}

@keyframes rotateRadar {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.seal .grad-cap-icon {
    font-size: 24px;
    color: #ffffff;
    filter: drop-shadow(0 0 6px #00f0ff);
    margin-bottom: 2px;
}

.seal .scan-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 1px;
    color: #fff;
}

/* MẶT TRƯỚC PHONG BÌ (LỚP TRÊN CÙNG: z-index 3): CHE CHÂN THẺ TỰ NHIÊN */
.envelope-front-text {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: 22px;
    background: linear-gradient(180deg, rgba(8, 29, 58, 0.95) 0%, #04142b 100%);
    border-radius: 0 0 11px 11px;
    z-index: 3; /* Che toàn bộ phần chân thẻ, tạo cảm giác thẻ nằm TRONG túi */
    text-align: center;
}

.system-tag {
    font-family: 'JetBrains Mono', monospace;
    font-size: 8.5px;
    color: #00f0ff;
    letter-spacing: 1px;
    margin-bottom: 3px;
    opacity: 0.9;
}

.envelope-front-text .subtitle {
    font-size: 11px;
    letter-spacing: 2.5px;
    color: #92cdff;
    font-weight: 700;
    text-transform: uppercase;
}

.envelope-front-text .guest-name-text {
    font-family: 'Dancing Script', cursive;
    color: #ffffff;
    font-size: 30px;
    text-shadow: 0 0 10px rgba(0, 240, 255, 0.7);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =========================================
   HIỆU ỨNG RÚT THẺ ACCESS_GRANTED TỪ TRONG TÚI RA
   ========================================= */

/* Nắp phong bì mở lật 180 độ ra sau */
.envelope-wrapper.opening .envelope-flap {
    transform: rotateX(180deg);
    z-index: 1; /* Nằm sau cùng làm nền tam giác */
    filter: drop-shadow(0 -4px 10px rgba(0, 240, 255, 0.4));
}

/* THẺ ACCESS_GRANTED NẰM GỌN TRONG LÒNG THƯ (LỚP GIỮA: z-index 2) */
.inner-letter-mock {
    position: absolute;
    top: 25px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    width: 82%;
    height: 140px;
    background: linear-gradient(180deg, #072247, #030d1c);
    border: 1.5px solid #00f0ff;
    border-radius: 8px;
    z-index: 2; /* Nằm giữa nắp thư (1) và mặt trước bao thư (3) */
    opacity: 0;
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #00f0ff;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    transition: transform 0.65s cubic-bezier(0.2, 0.9, 0.3, 1.2), opacity 0.3s;
    pointer-events: none;
}

.inner-letter-mock .sub-status {
    font-size: 8.5px;
    color: #79a6db;
    margin-top: 3px;
    letter-spacing: 1px;
    font-weight: 400;
}

/* KHI BẤM MỞ: RÚT THẺ VÚT LÊN CAO KHỎI MIỆNG PHONG BÌ */
.envelope-wrapper.opening .inner-letter-mock {
    opacity: 1;
    transform: translateX(-50%) translateY(-115px); /* Vút lên cao khỏi miệng thư */
}

/* Con dấu tan biến */
.envelope-wrapper.opening .seal {
    transform: scale(0);
    opacity: 0;
    transition: all 0.3s ease;
}

/* Sau khi mở nắp, bao thư từ từ lùi nhẹ xuống làm nền cho thiệp bay lên */
.envelope-wrapper.opening .envelope {
    transform: translateY(15px) scale(0.96);
    transition: transform 0.6s ease;
}