* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Roboto', sans-serif; overflow: hidden; background: #030305; }
.hidden { display: none !important; }

.bg-layer { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -2; }
#circuit-bg { background-color: #f8fafc; }
#fixed-grid { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: linear-gradient(to right, rgba(0, 143, 76, 0.08) 1px, transparent 1px), linear-gradient(to bottom, rgba(0, 143, 76, 0.08) 1px, transparent 1px); background-size: 40px 40px; z-index: -2;}
#circuit-canvas { position: absolute; top: 0; left: 0; z-index: -1; }

.transition-screen { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999; pointer-events: none; opacity: 0; transition: opacity 0.8s ease-in-out; }
.flash-active { opacity: 1 !important; }

.screen { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; }
.flex-center { display: flex; justify-content: center; align-items: center; }
.scrollable { overflow-y: auto; padding: 40px 15px; -webkit-overflow-scrolling: touch; }

.intro-panel { text-align: center; max-width: 700px; padding: 40px; background: rgba(255, 255, 255, 0.95); border-radius: 20px; border: 1px solid rgba(0, 143, 76, 0.2); color: #334155; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); margin: 0 20px; transition: opacity 0.5s ease, transform 0.5s ease; }
.fade-out-quick { opacity: 0 !important; pointer-events: none; transform: translateY(-20px) scale(0.95); }
.fade-in-slow { animation: slowReveal 1.5s ease-out forwards; }

@keyframes slowReveal {
    0% { opacity: 0; transform: translateY(20px); }
    100% { opacity: 1; transform: translateY(0); }
}

.sub-title { color: #008f4c; margin-bottom: 15px; text-transform: uppercase; letter-spacing: 1.5px; font-size: 1.3rem; font-weight: bold;}
.story-box p { color: #475569; margin-bottom: 15px; line-height: 1.6; font-size: 1rem; font-weight: 500;}

.btn.cosmic-btn { padding: 15px 30px; border-radius: 8px; font-weight: bold; font-size: 1.1rem; cursor: pointer; text-transform: uppercase; border: 2px solid #008f4c; transition: 0.3s; width: 100%; max-width: 320px; margin: 25px auto 0; display: block; background: transparent; color: #008f4c; position: relative; overflow: hidden; }
.btn.cosmic-btn span { position: relative; z-index: 2; }
.btn.cosmic-btn::before { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #008f4c; z-index: 1; transform: scaleX(0); transform-origin: right; transition: transform 0.4s; }
.btn.cosmic-btn:hover { color: #fff; box-shadow: 0 0 20px rgba(0, 143, 76, 0.4); }
.btn.cosmic-btn:hover::before { transform: scaleX(1); transform-origin: left; }

.form-card { box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); border-top: 6px solid #008f4c; }
.scale-100-form { transform: scale(1) !important; } 

.form-input { transition: box-shadow 0.5s ease-in-out, border-color 0.5s ease-in-out, background-color 0.3s ease; }
.form-input:focus { outline: none; border-color: #008f4c; box-shadow: 0 0 12px rgba(0, 143, 76, 0.4), inset 0 0 4px rgba(0, 143, 76, 0.1); }


/* ========================================================
   HIỆU ỨNG NÚT BẤM (BÌNH MINH NĂNG LƯỢNG)
======================================================== */
.btn-dawn { 
    position: relative;
    background-color: #008f4c; 
    color: white; 
    border: none;
    cursor: pointer;
    overflow: hidden; /* Quan trọng: Giữ mặt trời bên dưới */
    transition: all 0.3s ease;
}

.btn-text {
    position: relative;
    z-index: 10;
    transition: all 0.3s;
}

/* Đang kết nối: Chuyển màu tối, chữ vàng */
.btn-dawn.is-loading { 
    background-color: #020617 !important; 
    color: #fbbf24 !important; 
    pointer-events: none;
}

/* Mặt trời lặn (Mặc định) */
.btn-dawn::before {
    content: ''; 
    position: absolute;
    bottom: -50px; 
    left: 50%; 
    transform: translateX(-50%);
    width: 40px; 
    height: 40px;
    background: #fbbf24;
    border-radius: 50%;
    box-shadow: 0 0 20px #fbbf24;
    transition: all 1.5s ease-in-out;
    z-index: 1;
}

/* Đang kết nối: Mặt trời nhô lên đỉnh nút */
.btn-dawn.is-loading::before {
    bottom: 10px; 
}

/* Thành công: Mở khóa overflow và phóng to khổng lồ */
.btn-dawn.is-success { 
    overflow: visible !important; 
    background-color: transparent !important;
}

.btn-dawn.is-success .btn-text { 
    opacity: 0; /* Ẩn text đi */
}

/* Khi bùng nổ, mặt trời nhỏ trong nút biến mất ngay; phần mở rộng do #sun-overlay đảm nhận */
.btn-dawn.is-success::before {
    opacity: 0;
    transition: none;
}

/* Lớp phủ mặt trời toàn màn hình (mở rộng bằng clip-path từ vị trí nút, xem launchSun trong script.js) */
#sun-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 9998; pointer-events: none;
    visibility: hidden; opacity: 0;
    background: radial-gradient(circle at 50% 50%, #fff3b0 0%, #fbbf24 45%, #fbbf24 100%);
    -webkit-clip-path: circle(0px at 50% 50%); clip-path: circle(0px at 50% 50%);
}

@media (max-width: 768px) {
    .form-card, #form-box-wrapper { transform: none !important; animation: fadeInMobile 0.8s ease forwards; }
    @keyframes fadeInMobile { from { opacity: 0; } to { opacity: 1; } }
    .form-card { background: rgba(255, 255, 255, 0.9) !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; border: 1px solid rgba(255, 255, 255, 0.7) !important; box-shadow: 0 15px 35px rgba(0, 143, 76, 0.1) !important; border-top: 6px solid #008f4c !important; }
    #form-box-wrapper header, #form-box-wrapper form { background: transparent !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; border-bottom: none !important; }
    .form-input { background: rgba(255, 255, 255, 0.6) !important; border: 1px solid rgba(0, 143, 76, 0.2) !important; color: #1e293b !important; -webkit-appearance: none; }
    .form-input:focus { background: rgba(255, 255, 255, 0.95) !important; border-color: #008f4c !important; }
}

.fade-text {
  display: inline-block;
  transition: opacity 0.3s ease;
  opacity: 1;
}

.fade-text.is-hidden {
  opacity: 0;
}

/* Nút tương tác trên Canvas */
.action-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: all 0.3s ease;
}

.action-btn:hover {
    background: #008f4c;
    border-color: #00e676;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 143, 76, 0.5);
}

/* Đảm bảo khung scroll tốt nếu thẻ canvas quá to trên mobile */
#intro-content-success {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
/* Gợi ý / báo lỗi dưới ô nhập */
.field-hint { font-size: 0.8rem; margin-top: 4px; font-weight: 500; }
.field-hint.ok { color: #15803d; }
.field-hint.err { color: #e3000f; }
.field-hint.info { color: #b45309; }
.field-hint button { text-decoration: underline; font-weight: 700; cursor: pointer; background: none; border: 0; padding: 0; color: inherit; }
.form-input.is-invalid { border-color: #e3000f !important; }
.form-input.is-valid { border-color: #16a34a !important; }

/* ========================================================
   TỐI ƯU ĐIỆN THOẠI
   - bỏ backdrop-filter (làm mờ nền phía sau canvas đang chuyển động => repaint liên tục, giật)
   - thu nhỏ khoảng đệm để thẻ cào đủ rộng trên màn hình hẹp (360px)
======================================================== */
@media (max-width: 768px) {
    .intro-panel { padding: 24px 12px; margin: 0 6px; backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(255, 255, 255, 0.97); }
    .scrollable { padding: 16px 8px; }
    #form-box-wrapper header { padding-top: 20px; padding-bottom: 14px; }
    .action-btn { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(0, 0, 0, 0.8); }
    .btn.cosmic-btn { padding: 13px 20px; }
}

/* ========================================================
   VÒNG QUAY MAY MẮN
======================================================== */
.wheel-wrap { position: relative; width: min(400px, calc(100% - 28px)); aspect-ratio: 1 / 1; margin: 14px auto 0; }
/* Bóng đổ tĩnh (vẽ 1 lần). Trước đây dùng filter: drop-shadow trên canvas nên bị tính lại ở mỗi khung hình quay */
.wheel-wrap::before { content: ''; position: absolute; inset: 0.5%; border-radius: 50%; box-shadow: 0 12px 22px rgba(0, 0, 0, 0.35); pointer-events: none; }
/* Mặt vòng quay (JS chèn): chỉ đổi transform khi quay => chạy trên GPU */
.wheel-face { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; will-change: transform; }
/* Lớp viền + bóng đèn + vòng tâm: nằm trên mặt vòng quay, không xoay */
#wheelCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }

/* Kim chỉ ở vị trí 3 giờ (bên phải), mũi nhọn hướng vào tâm */
.wheel-pointer {
    position: absolute; top: 50%; right: -5%; width: 13%; height: 11%;
    transform: translate(0, -50%); transform-origin: 80% 50%; z-index: 3; pointer-events: none;
    transition: transform 0.06s ease-out;
    filter: drop-shadow(0 4px 5px rgba(0, 0, 0, 0.45));
    background: linear-gradient(270deg, #ff4b5c 0%, #e3000f 55%, #a30009 100%);
    clip-path: polygon(0 50%, 64% 0, 100% 0, 100% 100%, 64% 100%);
}
.wheel-pointer::after { content: ''; position: absolute; right: 14%; top: 50%; height: 30%; aspect-ratio: 1; transform: translateY(-50%); border-radius: 50%; background: #fff3b0; box-shadow: inset 0 -2px 3px rgba(0,0,0,.25); }

/* Nút QUAY ở tâm */
.wheel-hub {
    position: absolute; top: 50%; left: 50%; width: 21%; aspect-ratio: 1; transform: translate(-50%, -50%);
    border-radius: 50%; z-index: 2; cursor: pointer;
    background: radial-gradient(circle at 35% 30%, #fff3b0 0%, #fbbf24 40%, #d97706 100%);
    border: 4px solid #fff; color: #7a1d00; font-weight: 900; font-size: clamp(12px, 3.6vw, 17px); letter-spacing: 0.5px;
    box-shadow: 0 6px 18px rgba(217, 119, 6, 0.6), inset 0 -4px 8px rgba(0, 0, 0, 0.18);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    -webkit-tap-highlight-color: transparent;
}
.wheel-hub::after {
    content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 3px solid rgba(251, 191, 36, .6); pointer-events: none;
    animation: hubRing 1.8s ease-out infinite;
}
.wheel-hub:disabled::after { animation: none; opacity: 0; }
@keyframes hubRing { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(1.38); opacity: 0; } }
.wheel-hub-play { font-size: 0.6em; line-height: 1; }
.wheel-hub:active { transform: translate(-50%, -50%) scale(0.94); }
.wheel-hub:disabled, .spin-main-btn:disabled { animation: none; opacity: 0.55; cursor: not-allowed; }

.spin-main-btn {
    padding: 12px 26px; border-radius: 999px; border: 0; cursor: pointer; font-weight: 800; font-size: 1.02rem; color: #fff; letter-spacing: .5px;
    background: linear-gradient(90deg, #008f4c, #00b862); box-shadow: 0 8px 20px rgba(0, 143, 76, 0.4); transition: transform .15s;
}
.spin-main-btn:active { transform: scale(0.96); }

/* ===== Nhập OTP trước mỗi lượt quay ===== */
.otp-box { margin: 14px auto 0; max-width: 280px; }
.otp-label { display: block; font-weight: 700; font-size: .92rem; color: #334155; margin-bottom: 6px; }
.otp-input {
    width: 100%; text-align: center; font-size: 1.6rem; font-weight: 800; letter-spacing: .5em; padding: 10px 8px 10px 18px;
    border: 2px solid #cbd5e1; border-radius: 12px; background: #fff; color: #0f172a; outline: none;
}
.otp-input:focus { border-color: #008f4c; box-shadow: 0 0 0 3px rgba(0, 143, 76, .18); }
.otp-input:disabled { opacity: .6; }
.finish-link {
    display: block; margin: 14px auto 0; padding: 6px 10px; background: none; border: 0; cursor: pointer;
    font-size: .85rem; font-weight: 600; color: #64748b; text-decoration: underline; text-underline-offset: 3px;
}
.finish-link:disabled { opacity: .45; cursor: not-allowed; }

/* ===== Tổng kết: các giải đã quay được trong khung ===== */
.final-summary { margin-top: 6px; font-size: 1rem; font-weight: 700; color: #334155; }
.final-summary:empty { display: none; }
/* Cột cố định theo --fw (JS đặt theo số giải), tự xuống hàng và căn giữa => luôn hiện đủ cùng lúc.
   min(..., 46%) để điện thoại hẹp vẫn xếp được 2 khung / hàng */
.prize-frames {
    --fw: 160px;
    display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; max-width: 640px; margin: 14px auto 0;
}
.prize-frame {
    flex: 0 0 min(var(--fw), calc(50% - 7px)); box-sizing: border-box; min-width: 0;
    position: relative; padding: 10px 10px 8px; border: 3px solid transparent; border-radius: 16px; text-align: center;
    background: linear-gradient(#fffef8, #f6ecc9) padding-box,
                linear-gradient(135deg, #8a6a12, #f3d36b, #fff3b0, #d9a82e, #8a6a12) border-box;
    box-shadow: 0 8px 22px rgba(0, 0, 0, .28), inset 0 0 0 1px rgba(255, 255, 255, .6);
}
.prize-frame-media {
    aspect-ratio: 1; display: flex; align-items: center; justify-content: center; overflow: hidden;
    border-radius: 10px; background: radial-gradient(circle at 50% 40%, #fffef8, #f3e8c6);
}
.prize-frame-img { width: 100%; height: 100%; object-fit: contain; }
.prize-frame-text {
    padding: 8px; font-family: 'Playfair Display', 'Times New Roman', serif; font-weight: 900; line-height: 1.2;
    font-size: clamp(.95rem, 3.6vw, 1.25rem); color: #006a38; text-transform: uppercase; overflow-wrap: anywhere;
}
.prize-frame-text.md { font-size: clamp(.8rem, 3vw, 1rem); }
.prize-frame-text.sm { font-size: clamp(.66rem, 2.4vw, .8rem); }
.prize-frame-name { margin-top: 6px; font-size: .85rem; font-weight: 800; color: #6b5a2a; line-height: 1.25; }
.prize-frame-count {
    position: absolute; top: -8px; right: -8px; min-width: 28px; padding: 3px 7px; border-radius: 999px;
    background: #e3000f; color: #fff; font-size: .8rem; font-weight: 800; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
}
.prize-frame-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; }
.frame-btn {
    padding: 4px 9px; border-radius: 999px; border: 1px solid #c9a227; background: #fff; cursor: pointer; white-space: nowrap;
    font-size: .72rem; font-weight: 700; color: #6b5a2a;
}
.frame-btn:active { transform: scale(.95); }
.winner-img { display: block; max-width: 60%; max-height: 120px; margin: 0 auto 8px; object-fit: contain; }

/* ===== Thông báo trúng thưởng hoành tráng ===== */
.winner-modal {
    position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center; padding: 16px;
    background: radial-gradient(circle at 50% 40%, rgba(0, 70, 38, 0.92), rgba(2, 8, 5, 0.95));
    opacity: 0; visibility: hidden; transition: opacity .4s ease, visibility .4s;
}
.winner-modal.show { opacity: 1; visibility: visible; }
.winner-rays {
    position: absolute; left: 50%; top: 50%; width: 94vmax; height: 94vmax; margin: -47vmax 0 0 -47vmax; pointer-events: none;
    background: repeating-conic-gradient(from 0deg, rgba(255, 214, 90, 0.20) 0deg 7deg, rgba(255, 214, 90, 0) 7deg 20deg);
    -webkit-mask-image: radial-gradient(circle closest-side, #000 0%, transparent 100%); mask-image: radial-gradient(circle closest-side, #000 0%, transparent 100%); will-change: transform;
    animation: raysSpin 28s linear infinite;
}
@keyframes raysSpin { to { transform: rotate(360deg); } }

.winner-card {
    position: relative; width: min(440px, 100%); padding: 28px 22px 24px; text-align: center; overflow: hidden;
    background: linear-gradient(180deg, #fffdf6 0%, #f6ecce 100%); border-radius: 26px;
    border: 3px solid #d4af37; box-shadow: 0 0 0 6px rgba(0, 106, 56, .9), 0 0 60px rgba(251, 191, 36, .55), 0 30px 60px rgba(0,0,0,.5);
    transform: scale(.6) translateY(30px); opacity: 0;
}
.winner-modal.show .winner-card { animation: cardPop .75s cubic-bezier(.2, 1.4, .4, 1) .1s forwards; }
@keyframes cardPop { to { transform: scale(1) translateY(0); opacity: 1; } }
.winner-glow { position: absolute; top: -90px; left: 50%; width: 260px; height: 260px; margin-left: -130px; border-radius: 50%; background: radial-gradient(circle, rgba(251,191,36,.65), transparent 70%); pointer-events: none; }
.winner-icon { position: relative; font-size: 64px; line-height: 1; animation: iconBounce 1.1s ease-in-out infinite; filter: drop-shadow(0 6px 8px rgba(0,0,0,.25)); }
@keyframes iconBounce { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-10px) scale(1.08); } }
.winner-title { position: relative; margin-top: 8px; font-family: 'Playfair Display', serif; font-weight: 900; font-size: clamp(22px, 6.5vw, 30px); letter-spacing: 4px; color: #006a38; }
.winner-sub { position: relative; margin-top: 4px; font-family: 'Playfair Display', serif; font-style: italic; font-weight: 600; color: #6b5a2a; }
.winner-name-box {
    position: relative; margin: 16px 0 12px; padding: 16px 12px; border-radius: 18px;
    background: linear-gradient(135deg, #004d28, #006a38); border: 2px solid #e9c35a; box-shadow: inset 0 0 18px rgba(0,0,0,.35);
}
.winner-name {
    display: block; font-family: 'Playfair Display', serif; font-weight: 900; font-size: clamp(24px, 8vw, 36px); line-height: 1.2; word-break: break-word; text-transform: uppercase;
    background: linear-gradient(100deg, #b8860b 10%, #fff0b0 35%, #ffd54a 50%, #fff0b0 65%, #b8860b 90%); background-size: 220% 100%;
    -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
    animation: shimmer 2.4s linear infinite; padding: 5px;
}
@keyframes shimmer { from { background-position: 220% 0; } to { background-position: -220% 0; } }
.winner-note { position: relative; font-size: .9rem; color: #6b5a2a; margin-bottom: 16px; }
.winner-btn {
    position: relative; width: 100%; padding: 14px; border: 0; border-radius: 14px; cursor: pointer; font-weight: 800; font-size: 1rem; color: #fff;
    background: linear-gradient(90deg, #008f4c, #00b862); box-shadow: 0 8px 20px rgba(0,143,76,.4);
}
.winner-btn:active { transform: scale(.98); }
/* Kết quả không trúng: tông nhẹ nhàng */
.winner-modal.lose .winner-rays { display: none; }
.winner-modal.lose .winner-glow { background: radial-gradient(circle, rgba(148, 163, 184, .45), transparent 70%); }
.winner-modal.lose .winner-icon { animation: none; }
.winner-modal.lose .winner-name-box { background: linear-gradient(135deg, #1e3a2c, #2f5d44); }
.winner-modal.lose .winner-name { background: none; -webkit-text-fill-color: #fff; color: #fff; animation: none; text-transform: none; font-size: clamp(20px, 6vw, 28px); }
@media (max-width: 768px) { .winner-rays { animation-duration: 40s; } }
