/* =========================================================================
           1. RESET & KHUNG MOBILE MÀN HÌNH DỌC
           ========================================================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    /* Ngăn chặn double-tap zoom trên mobile */
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #03060f;
    font-family: 'Chakra Petch', sans-serif;
    color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Khung thiết bị di động màn hình dọc */
#app-container {
    position: relative;
    width: 100%;
    max-width: 480px;
    height: 100dvh;
    max-height: 920px;
    background: radial-gradient(circle at 50% 48%, #0e1e47 0%, #060c1f 62%, #02040b 100%);
    overflow: hidden;
  
    transition: box-shadow 0.35s ease, border-color 0.35s ease;
}

/* Cảnh báo viền khung máy theo cấp độ nguy hiểm */
#app-container.danger-tier-mid {
    box-shadow: 0 0 45px rgba(255, 145, 0, 0.3);
    border-color: rgba(255, 145, 0, 0.4);
}

#app-container.danger-tier-high {
    box-shadow: 0 0 50px rgba(255, 23, 68, 0.42);
    border-color: rgba(255, 23, 68, 0.55);
}

/* Lưới công nghệ nền mờ */
.cyber-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(0, 240, 255, 0.045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 240, 255, 0.045) 1px, transparent 1px);
    background-size: 30px 30px;
    pointer-events: none;
    z-index: 0;
}

/* Vòng tròn năng lượng trang trí trung tâm lấy cảm hứng từ đề xuất POWER UP */
.energy-ring-bg {
    position: absolute;
    top: 53%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    height: 300px;
    border-radius: 50%;
    border: 2px solid rgba(0, 240, 255, 0.15);
    box-shadow:
        0 0 38px rgba(0, 240, 255, 0.08),
        inset 0 0 38px rgba(157, 0, 255, 0.12);
    pointer-events: none;
    z-index: 0;
}

.energy-ring-bg::before {
    content: '';
    position: absolute;
    inset: 14px;
    border-radius: 50%;
    border: 1px dashed rgba(0, 240, 255, 0.24);
    animation: spinSlow 26s linear infinite;
}

.energy-ring-bg::after {
    content: '';
    position: absolute;
    inset: -12px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: rgba(0, 240, 255, 0.35);
    border-bottom-color: rgba(188, 19, 254, 0.35);
    animation: spinReverse 16s linear infinite;
}

@keyframes spinSlow {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

@keyframes spinReverse {
    from {
        transform: rotate(360deg);
    }

    to {
        transform: rotate(0deg);
    }
}

/* Hiệu ứng rung màn hình */
.shake-screen {
    animation: screenShake 0.38s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes screenShake {

    10%,
    90% {
        transform: translate3d(-4px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(6px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-7px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(7px, 0, 0);
    }
}

/* Lớp phủ nháy đỏ khi chạm Bom */
.bomb-flash-overlay {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle, transparent 35%, rgba(255, 23, 68, 0.5) 100%);
    pointer-events: none;
    opacity: 0;
    z-index: 50;
    transition: opacity 0.14s ease-out;
}

/* =========================================================================
           2. QUẢN LÝ 3 MÀN HÌNH (SCREENS)
           ========================================================================= */
.screen {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    z-index: 10;
}

.screen.active {
    display: flex;
}

/* =========================================================================
           SCREEN 1: MÀN HÌNH CHỜ GAME
           ========================================================================= */
#screen-start {
    justify-content: space-between;
    align-items: center;
    padding: 28px 20px 26px;
    text-align: center;
    overflow-y: auto;
}

.brand-badge {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 999px;
    background: rgba(0, 240, 255, 0.12);
    border: 1px solid rgba(0, 240, 255, 0.45);
    color: #00f0ff;
    font-size: 0.74rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.game-title {
    font-family: 'UTM Nokia';
    font-size: 2.9rem;
    font-weight: 900;
    line-height: 1.05;
    letter-spacing: 2px;
    background: linear-gradient(180deg, #ffffff 15%, #00f0ff 55%, #0077ff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 18px rgba(0, 240, 255, 0.55));
}

.game-subtitle {
    margin-top: 6px;
    font-size: 0.92rem;
    color: #a5b8d9;
}

/* Bảng hướng dẫn luật chơi trực quan */
.rules-card {
    width: 100%;
    background: rgba(11, 20, 46, 0.85);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 240, 255, 0.28);
    border-radius: 20px;
    padding: 15px 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    text-align: left;
    margin: 12px 0;
}

.rules-card h3 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #00f0ff;
    margin-bottom: 10px;
    text-align: center;
}

.rule-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.035);
    margin-bottom: 8px;
}

.rule-item:last-child {
    margin-bottom: 0;
}

.orb-preview-group {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 64px;
    justify-content: center;
    flex-shrink: 0;
}

.mini-orb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-block;
}

.mini-blue {
    background: radial-gradient(circle at 30% 30%, #a8f9ff, #0088ff);
    box-shadow: 0 0 8px #00bfff;
}

.mini-purple {
    background: radial-gradient(circle at 30% 30%, #f3b8ff, #9d00ff);
    box-shadow: 0 0 8px #c44dff;
}

.mini-green {
    background: radial-gradient(circle at 30% 30%, #b8ffcf, #00c853);
    box-shadow: 0 0 8px #00e676;
}

.mini-super {
    width: 30px;
    height: 30px;
    background: radial-gradient(circle at 30% 30%, #fff7b2, #ffab00);
    box-shadow: 0 0 12px #ffd600;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'UTM Nokia';
    font-size: 0.72rem;
    font-weight: 900;
    color: #3d2200;
}

.mini-bomb {
    width: 30px;
    height: 30px;
    background: radial-gradient(circle at 30% 30%, #ff8a80, #d50000);
    box-shadow: 0 0 12px #ff1744;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.88rem;
}

.mini-escalate {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: rgba(255, 171, 0, 0.16);
    border: 1px solid rgba(255, 171, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

.rule-text {
    font-size: 0.84rem;
    line-height: 1.32;
    color: #e2ecff;
}

.rule-text strong {
    color: #ffffff;
}

/* Nút bấm Neon chủ đạo */
.btn-neon {
    width: 100%;
    padding: 15px 24px;
    border: none;
    border-radius: 16px;
    font-family: 'Chakra Petch', sans-serif;
    font-size: 1.22rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #030914;
    background: linear-gradient(135deg, #00f0ff 0%, #00a2ff 100%);
    box-shadow:
        0 6px 22px rgba(0, 240, 255, 0.45),
        inset 0 2px 2px rgba(255, 255, 255, 0.65);
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn-neon:active {
    transform: scale(0.96);
    box-shadow: 0 2px 12px rgba(0, 240, 255, 0.35);
}

.btn-secondary {
    width: 100%;
    padding: 13px 20px;
    border-radius: 16px;
    font-family: 'Chakra Petch', sans-serif;
    font-size: 1.02rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #00f0ff;
    background: rgba(0, 240, 255, 0.08);
    border: 1px solid rgba(0, 240, 255, 0.4);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-secondary:active {
    transform: scale(0.97);
    background: rgba(0, 240, 255, 0.18);
}

/* =========================================================================
           SCREEN 2: MÀN HÌNH CHƠI GAME
           ========================================================================= */
#screen-game {
    justify-content: flex-start;
}

/* Header cố định phía trên: Trái = Điểm số, Giữa = Cấp độ/Tỉ lệ Bom, Phải = Thời gian 60s */


/* Chỉ báo cấp độ nguy hiểm ở giữa Header */
.hud-danger {
    flex-direction: column;
    gap: 1px;
    padding: 4px 10px;
    border-color: rgba(255, 171, 0, 0.45);
    background: rgba(28, 18, 38, 0.88);
    transition: all 0.3s ease;
}

.hud-danger-level {
    font-family: 'UTM Nokia';
    font-size: 0.72rem;
    font-weight: 900;
    color: #ffd600;
    letter-spacing: 0.5px;
}

.hud-danger-rate {
    font-size: 0.68rem;
    font-weight: 700;
    color: #ff8a80;
}

.hud-danger.high-alert {
    border-color: #ff1744;
    box-shadow: 0 0 14px rgba(255, 23, 68, 0.5), inset 0 0 8px rgba(255, 23, 68, 0.25);
}

.hud-timer .hud-value {
    color: #ffffff;
}

.hud-timer.warning {
    border-color: #ff1744;
    animation: pulseWarning 0.55s infinite alternate;
}

.hud-timer.warning .hud-value {
    color: #ff5252;
    text-shadow: 0 0 12px rgba(255, 23, 68, 0.85);
}

@keyframes pulseWarning {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.06);
    }
}

/* Thanh trạng thái SUPER POWER x2 */
#super-power-banner {
    position: absolute;
    top: 74px;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    z-index: 23;
    background: linear-gradient(90deg, #ff8f00, #ffd600, #ff8f00);
    color: #261400;
    font-weight: 900;
    font-size: 0.82rem;
    padding: 5px 16px;
    border-radius: 999px;
    box-shadow: 0 0 20px rgba(255, 214, 0, 0.85);
    letter-spacing: 0.8px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease;
    white-space: nowrap;
}

#super-power-banner.active {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Banner cảnh báo tăng độ khó mỗi mốc 10s */
#difficulty-toast {
    position: absolute;
    top: 110px;
    left: 50%;
    transform: translateX(-50%) scale(0.85);
    z-index: 24;
    background: linear-gradient(90deg, rgba(183, 28, 28, 0.95), rgba(255, 23, 68, 0.96), rgba(183, 28, 28, 0.95));
    border: 1px solid #ff8a80;
    color: #ffffff;
    font-weight: 700;
    font-size: 0.78rem;
    padding: 6px 15px;
    border-radius: 999px;
    box-shadow: 0 0 22px rgba(255, 23, 68, 0.85);
    letter-spacing: 0.5px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    white-space: nowrap;
}

#difficulty-toast.show {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

/* Nút âm thanh nhỏ nổi ở góc dưới cùng bên phải */
#btn-sound-toggle {
    position: absolute;
    bottom: 14px;
    right: 14px;
    z-index: 30;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(11, 22, 48, 0.78);
    border: 1px solid rgba(0, 240, 255, 0.32);
    color: #00f0ff;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Khu vực chơi chính */
#game-arena {
    position: relative;
    flex: 1;
    width: 100%;
    overflow: hidden;
    z-index: 15;
    max-height: 65vh;
}

/* =========================================================================
           QUẢ CẦU NĂNG LƯỢNG (BUBBLE ORBS)
           ========================================================================= */
.energy-orb {
    position: absolute;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scale(0);
    transition: transform 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.2s ease;
    will-change: transform, opacity;
}

.energy-orb.spawned {
    transform: scale(1);
}

.energy-orb.fading {
    transform: scale(0.2);
    opacity: 0;
}

/* Lớp bọt khí nổi bên trong tạo chiều sâu */
.orb-inner {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    animation: bubbleFloat 2.3s ease-in-out infinite alternate;
}

/* Ánh phản chiếu bọt khí */
.orb-inner::before {
    content: '';
    position: absolute;
    top: 14%;
    left: 18%;
    width: 28%;
    height: 18%;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.68);
    transform: rotate(-30deg);
    pointer-events: none;
}

@keyframes bubbleFloat {
    0% {
        transform: translateY(-4px) scale(0.98);
    }

    100% {
        transform: translateY(4px) scale(1.03);
    }
}

/* Màu sắc các loại cầu */
.orb-blue .orb-inner {
    
    box-shadow: 0 0 18px rgba(0, 195, 255, 0.75), inset 0 0 10px rgba(255, 255, 255, 0.5);
    border: 1.5px solid rgba(150, 240, 255, 0.8);
}

.orb-purple .orb-inner {
    
    box-shadow: 0 0 18px rgba(196, 77, 255, 0.75), inset 0 0 10px rgba(255, 255, 255, 0.5);
    border: 1.5px solid rgba(235, 175, 255, 0.8);
}

.orb-green .orb-inner {
    
    box-shadow: 0 0 18px rgba(0, 230, 118, 0.75), inset 0 0 10px rgba(255, 255, 255, 0.5);
    border: 1.5px solid rgba(175, 255, 200, 0.8);
}

/* Cầu SUPER POWER */
.orb-super .orb-inner {
    box-shadow: 0 0 26px rgba(255, 214, 0, 0.95), 0 0 40px rgba(255, 145, 0, 0.6);
    border: 2px solid #ffffff;
    animation: superPulse 0.65s ease-in-out infinite alternate;
}

.orb-super .orb-tag {
    font-family: 'UTM Nokia';
    font-weight: 900;
    font-size: 0.95rem;
    color: #2b1400;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

@keyframes superPulse {
    from {
        transform: scale(0.95) rotate(-4deg);
    }

    to {
        transform: scale(1.07) rotate(4deg);
    }
}

/* Cầu Đỏ - Bom Năng Lượng */
.orb-bomb .orb-inner {
    /* background: radial-gradient(circle at 35% 35%, #ff8a80 0%, #e50000 55%, #6e0000 100%); */
    box-shadow: 0 0 22px rgba(255, 23, 68, 0.85), inset 0 0 12px rgba(255, 180, 180, 0.5);
    border: 2px solid #ff5252;
    animation: bombPulse 0.52s ease-in-out infinite alternate;
}

.orb-bomb .orb-tag {
    font-size: 1.25rem;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
}

@keyframes bombPulse {
    from {
        transform: scale(0.96);
    }

    to {
        transform: scale(1.05);
    }
}

/* Hiệu ứng chữ điểm bay lên khi chạm */
.floating-score {
    position: absolute;
    font-family: 'UTM Nokia';
    font-weight: 900;
    font-size: 1.15rem;
    pointer-events: none;
    z-index: 40;
    transform: translate(-50%, -50%);
    animation: floatUpScore 0.75s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    white-space: nowrap;
}

@keyframes floatUpScore {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(0.7);
    }

    40% {
        opacity: 1;
        transform: translate(-50%, -110%) scale(1.15);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -180%) scale(0.95);
    }
}

/* Sóng xung kích vỡ bọt */
.pop-ripple {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.4);
    border: 3px solid #00f0ff;
    z-index: 35;
    animation: rippleExpand 0.42s ease-out forwards;
}

@keyframes rippleExpand {
    to {
        transform: translate(-50%, -50%) scale(1.9);
        opacity: 0;
    }
}

/* =========================================================================
           SCREEN 3: MÀN HÌNH THÔNG BÁO KẾT QUẢ
           ========================================================================= */
#screen-result {
    justify-content: center;
    align-items: center;
    padding: 24px 20px;
    text-align: center;
    background: rgba(4, 8, 20, 0.88);
    backdrop-filter: blur(12px);
}

.result-card {
    width: 100%;
    background: linear-gradient(180deg, rgba(16, 30, 66, 0.94) 0%, rgba(9, 17, 40, 0.97) 100%);
    border: 1px solid rgba(0, 240, 255, 0.35);
    border-radius: 24px;
    padding: 24px 18px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.65), 0 0 25px rgba(0, 240, 255, 0.15);
}

.result-header-tag {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #00f0ff;
    margin-bottom: 4px;
}

.result-title {
    font-family: 'UTM Nokia';
    font-size: 2rem;
    font-weight: 900;
    color: #ffffff;
    margin-bottom: 16px;
}

.final-score-box {
    background: rgba(0, 240, 255, 0.08);
    border: 1px solid rgba(0, 240, 255, 0.32);
    border-radius: 18px;
    padding: 16px 12px;
    margin-bottom: 16px;
}

.final-score-label {
    font-size: 0.82rem;
    color: #9ab3db;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.final-score-number {
    font-family: 'UTM Nokia';
    font-size: 3rem;
    font-weight: 900;
    color: #00f0ff;
    text-shadow: 0 0 20px rgba(0, 240, 255, 0.6);
    line-height: 1.15;
    margin: 4px 0;
}

.rank-badge {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 999px;
    font-size: 0.84rem;
    font-weight: 700;
    background: linear-gradient(90deg, rgba(255, 214, 0, 0.2), rgba(255, 145, 0, 0.25));
    border: 1px solid rgba(255, 214, 0, 0.6);
    color: #ffd600;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.stat-box {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 10px 6px;
}

.stat-val {
    font-family: 'UTM Nokia';
    font-size: 1.25rem;
    font-weight: 900;
    margin-bottom: 3px;
}

.stat-name {
    font-size: 0.72rem;
    color: #9fb4d6;
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}