:root { 
    --primary: #d90429; 
    --gold: #ffd700; 
    --bg-dark: #2b0505; 
    --bg-light: #8d0801; 
    --error: #ff4d4f; 
}

body { 
    font-family: 'Montserrat', sans-serif; 
    background: radial-gradient(circle, var(--bg-light) 0%, var(--bg-dark) 100%); 
    color: #fff; 
    margin: 0; 
    min-height: 100vh; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    overflow-x: hidden; 
    -webkit-tap-highlight-color: transparent; 
}

/* --- TITLE --- */
.header-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 20px 0 8px 0;
}
.title-logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
    filter: drop-shadow(0 2px 6px rgba(255,215,0,0.4));
}
h1 { 
    font-family: 'Dancing Script', cursive; 
    color: var(--gold); 
    text-shadow: 0 0 10px rgba(255, 0, 0, 0.8); 
    margin: 0; 
    font-size: 3rem; 
    text-align: center;
}
.subtitle {
    color: rgba(255,255,255,0.85);
    font-size: 0.95rem;
    margin: 0 0 15px 0;
    text-align: center;
}

/* --- GRID LAYOUT (CĂN GIỮA) --- */
.grid-container { 
    display: grid; 
    /* PC: 6 cột, căn giữa bằng margin auto */
    grid-template-columns: repeat(6, 1fr); 
    gap: 20px; 
    max-width: 1000px; 
    padding: 20px; 
    width: 100%;
    box-sizing: border-box; /* Quan trọng để không bị tràn lề */
}

/* --- ENVELOPE CARD (BAO LÌ XÌ) --- */
.envelope-card { 
    background: var(--primary); 
    border: 2px solid var(--gold); 
    border-radius: 15px; 
    aspect-ratio: 3/4; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: flex-start;
    padding: 6px;
    cursor: pointer; 
    transition: 0.3s; 
    position: relative; 
    box-shadow: 0 8px 20px rgba(0,0,0,0.4);
    user-select: none;
    overflow: hidden;
}

/* Số thứ tự: nhỏ gọn góc trên-trái */
.envelope-num {
    position: absolute;
    top: 4px;
    left: 4px;
    z-index: 5;
    background: rgba(255,215,0,0.9);
    color: var(--primary);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    font-size: 0.7rem;
    line-height: 1;
}

.envelope-img { 
    width: 95%; 
    flex: 1;
    min-height: 0;
    object-fit: contain;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.35)); 
    pointer-events: none; 
    transition: transform 0.3s;
}

/* Hiệu ứng khi mở */
.envelope-card.opened { 
    filter: grayscale(1); 
    opacity: 0.6; 
    pointer-events: none; 
    background: #444; 
    border-color: #888;
}

/* --- HIỆU ỨNG RUNG LẮC (SHAKE) --- */
/* PC: Di chuột vào -> Bao rung lắc */
@media (hover: hover) {
    .envelope-card:hover:not(.opened) {
        animation: shake 0.4s ease-in-out infinite;
        box-shadow: 0 0 25px var(--gold);
        border-color: #fff;
        z-index: 10;
    }
}
/* Mobile: Chạm 1 lần -> Bao rung lắc */
.envelope-card.active-touch {
    animation: shake 0.4s ease-in-out infinite;
    box-shadow: 0 0 25px var(--gold);
    border-color: #fff;
    z-index: 10;
}

@keyframes shake {
    0%, 100% { transform: rotate(0deg) translateY(0); }
    15% { transform: rotate(-5deg) translateY(-2px); }
    30% { transform: rotate(5deg) translateY(0); }
    45% { transform: rotate(-4deg) translateY(-2px); }
    60% { transform: rotate(4deg) translateY(0); }
    75% { transform: rotate(-3deg) translateY(-1px); }
}

/* --- RESPONSIVE MOBILE --- */
@media (max-width: 768px) { 
    .grid-container { 
        grid-template-columns: repeat(2, 1fr); 
        gap: 15px; 
        max-width: 400px;
    } 
    .header-title { margin: 15px 0 6px 0; gap: 10px; }
    .title-logo { width: 40px; height: 40px; }
    h1 { font-size: 2.2rem; }
    .subtitle { font-size: 0.85rem; margin-bottom: 12px; }
    .envelope-card { border-radius: 12px; padding: 5px; }
    .envelope-img { width: 92%; }
    .envelope-num { width: 16px; height: 16px; font-size: 0.65rem; top: 3px; left: 3px; }
    .prize-money-img { max-width: 150px; max-height: 75px; }
    .duplicate-modal-content { padding: 22px 20px; }
}

/* --- MODAL (POPUP) --- */
.modal { 
    display: none; 
    position: fixed; 
    z-index: 2000; 
    left: 0; top: 0; 
    width: 100%; height: 100%; 
    background: rgba(0,0,0,0.7); 
    justify-content: center; 
    align-items: center; 
    backdrop-filter: blur(5px); 
}

.modal-content { 
    background: #fff; 
    color: #333; 
    padding: 30px; 
    border-radius: 20px; 
    width: 90%; 
    max-width: 400px; 
    text-align: center; 
    border: 4px solid var(--gold); 
    box-shadow: 0 0 40px rgba(255, 215, 0, 0.3); 
    animation: popIn 0.3s ease-out; 
    position: relative;
}

.modal-title { color: var(--primary); margin-top: 0; text-transform: uppercase; }
.modal-desc { font-size: 0.9rem; color: #666; margin-bottom: 20px; }

/* Form Elements */
.form-group { text-align: left; margin-bottom: 15px; position: relative; }
label { display: block; font-weight: bold; font-size: 0.9rem; color: var(--primary); margin-bottom: 6px; }
input { 
    width: 100%; padding: 12px 15px; 
    border: 2px solid #ddd; border-radius: 10px; 
    box-sizing: border-box; font-size: 16px; 
    transition: 0.3s; font-family: 'Montserrat', sans-serif;
}
input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 8px rgba(217, 4, 41, 0.15); }

/* Dropdown Ngân Hàng */
.bank-list {
    position: absolute; top: 100%; left: 0; right: 0;
    background: white; border: 2px solid var(--primary); border-top: none;
    border-radius: 0 0 10px 10px; max-height: 200px; overflow-y: auto;
    z-index: 100; display: none; box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}
.bank-item { padding: 10px 15px; cursor: pointer; border-bottom: 1px solid #eee; display: flex; align-items: center; }
.bank-item:hover { background-color: #fff0f3; color: var(--primary); font-weight: bold; }

/* Nút Bấm */
.confirm-btn { 
    background: linear-gradient(45deg, #d90429, #ff4d4d); 
    color: white; border: none; 
    padding: 14px; width: 100%; 
    border-radius: 30px; 
    cursor: pointer; font-weight: bold; 
    margin-top: 15px; font-size: 1.1rem; 
    box-shadow: 0 5px 15px rgba(217, 4, 41, 0.4); 
    transition: transform 0.2s; 
}
.confirm-btn:active { transform: scale(0.95); }
#formError { color: var(--error); font-size: 13px; margin-top: 10px; font-weight: bold; }

/* --- Kết Quả (Hiển thị tiền) --- */
.result-content { max-width: 360px; }
.result-title { color: var(--primary); margin: 0 0 5px 0; font-size: 1.6rem; }
.wish-text { color: #666; font-size: 0.95rem; margin: 0 0 15px 0; }
.prize-box { 
    background: linear-gradient(135deg, #fff8f0 0%, #fff0f3 100%);
    padding: 20px; border-radius: 16px; margin: 15px 0; 
    border: 2px solid var(--gold);
    box-shadow: inset 0 2px 10px rgba(255,215,0,0.2);
    display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.prize-money-img {
    max-width: 180px; max-height: 90px; object-fit: contain;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15));
    display: none; /* Hiển thị khi có src hợp lệ */
}
.prize-amount-text { 
    color: var(--primary); font-size: 1.1rem; font-weight: 700;
    letter-spacing: 0.5px;
}

/* --- Modal thông báo SĐT/STK trùng --- */
.duplicate-modal-content {
    background: linear-gradient(180deg, #fff 0%, #fdf8f8 100%);
    padding: 28px 24px; border-radius: 20px; width: 90%; max-width: 340px;
    text-align: center; box-shadow: 0 15px 50px rgba(0,0,0,0.25);
    border: 1px solid rgba(217,4,41,0.15);
    animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.duplicate-icon-wrap {
    width: 56px; height: 56px; margin: 0 auto 16px;
    background: linear-gradient(135deg, #ff6b6b 0%, var(--error) 100%);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 20px rgba(255,77,79,0.4);
}
.duplicate-icon { color: white; font-size: 1.5rem; }
.duplicate-title {
    color: #333; font-size: 1.15rem; font-weight: 700; margin: 0 0 8px 0;
}
.duplicate-desc {
    color: #666; font-size: 0.9rem; line-height: 1.5; margin: 0 0 16px 0;
}
.duplicate-detail {
    background: #f8f8f8; border-radius: 12px; padding: 12px 16px;
    margin-bottom: 20px; text-align: left;
}
.duplicate-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 0; font-size: 0.9rem;
}
.duplicate-row:not(:last-child) { border-bottom: 1px solid #eee; }
.dup-label { color: #888; font-weight: 500; }
.dup-value { color: var(--primary); font-weight: 700; word-break: break-all; }
.btn-close-duplicate {
    background: linear-gradient(135deg, var(--primary) 0%, #ff4d4d 100%);
    color: white; border: none; padding: 12px 24px; border-radius: 30px;
    font-weight: bold; cursor: pointer; font-size: 0.95rem;
    display: inline-flex; align-items: center; gap: 8px;
    box-shadow: 0 4px 15px rgba(217,4,41,0.35);
    transition: transform 0.2s, box-shadow 0.2s;
}
.btn-close-duplicate:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 20px rgba(217,4,41,0.45);
}

/* --- Modal hết lộc --- */
.outofluck-modal-content {
    background: linear-gradient(180deg, #fff 0%, #fff8f0 100%);
    padding: 28px 24px; border-radius: 20px; width: 90%; max-width: 320px;
    text-align: center; box-shadow: 0 15px 50px rgba(0,0,0,0.25);
    border: 2px solid var(--gold);
    animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.outofluck-icon-wrap {
    width: 56px; height: 56px; margin: 0 auto 16px;
    background: linear-gradient(135deg, var(--gold) 0%, #ffec8b 100%);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 20px rgba(255,215,0,0.4);
}
.outofluck-icon { color: #8b6914; font-size: 1.5rem; }
.outofluck-title { color: var(--primary); font-size: 1.2rem; font-weight: 700; margin: 0 0 8px 0; }
.outofluck-desc { color: #666; font-size: 0.95rem; line-height: 1.5; margin: 0 0 20px 0; }
.btn-close-outofluck {
    background: linear-gradient(135deg, var(--primary) 0%, #ff4d4d 100%);
    color: white; border: none; padding: 12px 28px; border-radius: 30px;
    font-weight: bold; cursor: pointer; font-size: 0.95rem;
    display: inline-flex; align-items: center; gap: 8px;
    box-shadow: 0 4px 15px rgba(217,4,41,0.35);
    transition: transform 0.2s, box-shadow 0.2s;
}
.btn-close-outofluck:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 20px rgba(217,4,41,0.45);
}

/* Loading */
#loadingOverlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85); z-index: 3000; 
    display: none; justify-content: center; align-items: center; flex-direction: column;
}
.spinner { 
    border: 5px solid #f3f3f3; border-top: 5px solid var(--gold); 
    border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite; 
}
#loadingOverlay p { color: white; margin-top: 15px; font-weight: bold; }

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes popIn { from {transform: scale(0.8); opacity: 0;} to {transform: scale(1); opacity: 1;} }