/* ============================================
   THỦ THÀNH ĐẠI CHIẾN - CASTLE DEFENSE GAME
   Tone: Epic + Medieval + Fun
   Colors: Stone Gray, Fire Orange, Royal Blue/Red
   ============================================ */

/* --- CSS Variables --- */
:root {
    --gold: #F5A623;
    --gold-dark: #D4891A;
    --gold-light: #FCEAC5;
    --orange: #FF7A2F;
    --orange-dark: #E06520;
    --brown: #5C3D2E;
    --brown-dark: #3B2518;
    --brown-light: #8B6F5E;
    --cream: #FFF8E7;
    --cream-dark: #F5ECD4;

    --blue: #3B82F6;
    --blue-dark: #1D4ED8;
    --blue-light: #93C5FD;
    --blue-bg: #EFF6FF;
    --blue-glow: rgba(59, 130, 246, 0.4);

    --red: #EF4444;
    --red-dark: #B91C1C;
    --red-light: #FCA5A5;
    --red-bg: #FEF2F2;
    --red-glow: rgba(239, 68, 68, 0.4);

    --green: #22C55E;
    --green-dark: #16A34A;

    --stone: #6B7280;
    --stone-dark: #374151;
    --stone-light: #9CA3AF;

    --shadow-color: rgba(0, 0, 0, 0.25);
    --text-dark: #2D1B0E;
    --text-light: #FFFFFF;
    --border-radius: 16px;
    --border-radius-sm: 10px;
    --border-radius-lg: 24px;

    --font-display: 'Baloo 2', cursive;
    --font-body: 'Nunito', sans-serif;

    --topbar-height: 60px;
}

/* --- Reset --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
    font-family: var(--font-body);
    background: var(--cream);
    color: var(--text-dark);
    -webkit-font-smoothing: antialiased;
}

/* --- Screen System --- */
.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: flex; }

/* ============================================
   SETUP SCREEN
   ============================================ */
#setup-screen {
    background: linear-gradient(145deg, #2D1B0E 0%, #5C3D2E 50%, #8B6F5E 100%);
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
}
#setup-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 5L55 30L30 55L5 30Z' fill='none' stroke='rgba(255,255,255,0.03)' stroke-width='1'/%3E%3C/svg%3E") repeat;
    pointer-events: none;
}

.setup-container {
    max-width: 1320px;
    width: 100%;
    margin: 0 auto;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 2;
    position: relative;
}

.setup-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}
.header-castle {
    font-size: 3.5rem;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
    animation: float 3s ease-in-out infinite;
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}
.setup-header-text { flex: 1; }
.game-title {
    font-family: var(--font-display);
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--gold);
    text-shadow: 2px 2px 0 rgba(0,0,0,0.4), 0 0 20px rgba(245,166,35,0.3);
    letter-spacing: 1px;
    line-height: 1.1;
}
.game-subtitle {
    font-size: 1rem;
    font-weight: 700;
    color: var(--cream-dark);
    margin-top: 3px;
}

/* Zalo CTA */
.zalo-cta {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 18px; border-radius: 50px;
    background: linear-gradient(135deg, #FF6B35 0%, #FF3E6C 50%, #E8175D 100%);
    color: white; text-decoration: none;
    font-family: var(--font-body); font-size: 0.85rem; font-weight: 700;
    box-shadow: 0 4px 0 #c22048, 0 6px 20px rgba(255,62,108,0.35);
    transition: all 0.2s; white-space: nowrap; flex-shrink: 0;
}
.zalo-cta:hover { transform: translateY(-3px) scale(1.04); }
.zalo-cta-icon { font-size: 1.5rem; }
.zalo-cta-text { line-height: 1.2; text-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.zalo-cta-badge {
    background: white; color: #0068FF; font-size: 0.68rem; font-weight: 900;
    padding: 2px 8px; border-radius: 20px; letter-spacing: 0.5px; text-transform: uppercase;
}
@keyframes shake {
    0%,86%{transform:translateX(0)} 88%{transform:translateX(-3px) rotate(-1deg)}
    90%{transform:translateX(3px) rotate(1deg)} 92%{transform:translateX(-3px)}
    94%{transform:translateX(3px)} 96%{transform:translateX(-2px)} 100%{transform:translateX(0)}
}
.shake-animation { animation: shake 3s ease-in-out infinite; }
.shake-animation:hover { animation: none; }

/* Setup Grid */
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; flex: 1; min-height: 0; }
.setup-col-left, .setup-col-right { display: flex; flex-direction: column; gap: 12px; }

.setup-section {
    background: rgba(255,248,231,0.95); border-radius: var(--border-radius);
    padding: 16px 20px;
    box-shadow: 0 3px 0 rgba(0,0,0,0.15), 0 4px 12px rgba(0,0,0,0.1);
    border: 2px solid var(--cream-dark);
}
.setup-section-grow { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.section-title {
    font-family: var(--font-display); font-size: 1.15rem; font-weight: 700;
    color: var(--brown-dark); margin-bottom: 12px;
}
.question-count-badge {
    display: inline-block; background: var(--gold); color: white;
    font-size: 0.72rem; padding: 1px 10px; border-radius: 20px;
    font-family: var(--font-body); font-weight: 800; vertical-align: middle; margin-left: 6px;
}

/* Team Names */
.team-names-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.team-name-input label { display: block; font-weight: 800; margin-bottom: 5px; font-size: 0.95rem; }
.team-name-input input {
    width: 100%; padding: 10px 14px; border-radius: var(--border-radius-sm);
    border: 2px solid var(--cream-dark); font-family: var(--font-body);
    font-size: 0.95rem; font-weight: 700; transition: border-color 0.2s; outline: none;
}
.blue-team-input input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-glow); }
.red-team-input input:focus { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-glow); }

/* Timer */
.timer-selector { display: flex; gap: 8px; flex-wrap: wrap; }
.timer-btn {
    padding: 9px 16px; border: 2px solid var(--cream-dark); border-radius: var(--border-radius-sm);
    background: white; font-family: var(--font-body); font-weight: 800; font-size: 0.95rem;
    cursor: pointer; transition: all 0.2s; color: var(--brown-dark);
}
.timer-btn:hover { border-color: var(--gold); transform: translateY(-1px); }
.timer-btn.active {
    border-color: var(--orange); background: var(--orange); color: white;
    box-shadow: 0 3px 0 var(--orange-dark);
}

/* Hotkey Guide */
.hotkey-guide {
    text-align: center; padding: 12px;
    background: rgba(255,248,231,0.95); border-radius: var(--border-radius); border: 2px dashed rgba(255,255,255,0.2);
}
.hotkey-guide h3 { font-family: var(--font-display); color: var(--brown-dark); margin-bottom: 8px; font-size: 0.95rem; }
.hotkey-row { display: flex; justify-content: center; gap: 28px; flex-wrap: wrap; }
.hotkey-team { font-weight: 700; font-size: 0.88rem; }
.blue-text { color: var(--blue); }
.red-text { color: var(--red); }
kbd {
    display: inline-block; padding: 3px 7px; background: var(--cream-dark); border-radius: 5px;
    font-weight: 800; font-family: var(--font-body); font-size: 0.82rem;
    box-shadow: 0 2px 0 #ccc; margin: 0 2px; min-width: 24px; text-align: center;
}

/* Question Actions & List */
.question-actions { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.action-btn {
    padding: 8px 14px; border: none; border-radius: var(--border-radius-sm);
    font-family: var(--font-body); font-weight: 700; font-size: 0.88rem; cursor: pointer; transition: all 0.2s;
}
.add-btn { background: var(--green); color: white; box-shadow: 0 3px 0 var(--green-dark); }
.add-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 0 var(--green-dark); }
.import-btn { background: var(--blue); color: white; box-shadow: 0 3px 0 var(--blue-dark); }
.import-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 0 var(--blue-dark); }
.export-btn { background: var(--gold); color: white; box-shadow: 0 3px 0 var(--gold-dark); }
.export-btn:hover:not(:disabled) { transform: translateY(-2px); }
.export-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.bank-btn {
    background: linear-gradient(135deg, #FF7A2F 0%, #F5A623 100%); color: white;
    box-shadow: 0 3px 0 #D4891A;
}
.bank-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 0 #D4891A; }

.question-list { flex: 1; overflow-y: auto; padding-right: 4px; min-height: 0; }
.question-list::-webkit-scrollbar { width: 6px; }
.question-list::-webkit-scrollbar-thumb { background: var(--gold); border-radius: 3px; }
.empty-state { text-align: center; padding: 20px; color: var(--brown-light); }
.empty-icon { font-size: 2rem; display: block; margin-bottom: 6px; }

.question-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    background: var(--cream); border-radius: var(--border-radius-sm);
    margin-bottom: 6px; border: 1px solid var(--cream-dark); transition: all 0.2s;
}
.question-item:hover { border-color: var(--gold); }
.question-number {
    min-width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
    background: var(--gold); color: white; border-radius: 50%; font-weight: 800; font-size: 0.82rem; flex-shrink: 0;
}
.question-preview { flex: 1; font-weight: 700; font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.question-item-actions { display: flex; gap: 6px; }
.qi-btn {
    width: 32px; height: 32px; border: none; border-radius: 8px; cursor: pointer;
    font-size: 0.85rem; display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.qi-edit { background: var(--blue-light); color: var(--blue-dark); }
.qi-delete { background: var(--red-light); color: var(--red-dark); }
.qi-btn:hover { transform: scale(1.1); }

/* Start Button */
.start-btn {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    width: 100%; padding: 16px; border: none; border-radius: var(--border-radius);
    background: linear-gradient(135deg, #DC2626 0%, #FF7A2F 50%, #F5A623 100%);
    color: white; font-family: var(--font-display); font-size: 1.4rem; font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 0 #991B1B, 0 6px 16px rgba(220,38,38,0.3);
    transition: all 0.2s; text-shadow: 1px 2px 0 rgba(0,0,0,0.3); letter-spacing: 1px; flex-shrink: 0;
}
.start-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 0 #991B1B, 0 8px 24px rgba(220,38,38,0.4); }
.start-btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #991B1B; }
.start-btn.disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(0.4); }
.start-icon { font-size: 1.5rem; }

/* ============================================
   GAME SCREEN
   ============================================ */
#game-screen {
    flex-direction: column;
    background: linear-gradient(180deg, #1a0a00 0%, #2D1B0E 30%, #4a2c1a 100%);
    position: relative; overflow: hidden;
}
#game-screen::before {
    content: ''; position: absolute; inset: 0;
    background: radial-gradient(ellipse at 50% 100%, rgba(255,122,47,0.08) 0%, transparent 60%);
    pointer-events: none;
}

/* Topbar */
.game-topbar {
    height: var(--topbar-height); display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px;
    background: linear-gradient(180deg, rgba(0,0,0,0.5) 0%, rgba(0,0,0,0.2) 100%);
    border-bottom: 2px solid rgba(245,166,35,0.3); z-index: 10;
}
.topbar-team { display: flex; align-items: center; gap: 8px; }
.topbar-team-name { font-family: var(--font-display); font-size: 1.2rem; font-weight: 800; }
.blue-side .topbar-team-name { color: var(--blue-light); text-shadow: 0 0 10px var(--blue-glow); }
.red-side .topbar-team-name { color: var(--red-light); text-shadow: 0 0 10px var(--red-glow); }
.topbar-center { display: flex; flex-direction: column; align-items: center; }
.game-mode-badge {
    background: rgba(245,166,35,0.2); color: var(--gold); padding: 4px 16px; border-radius: 20px;
    font-weight: 800; font-size: 0.85rem; border: 1px solid rgba(245,166,35,0.3);
}
.game-q-counter { color: var(--cream-dark); font-size: 0.8rem; font-weight: 700; margin-top: 2px; }

/* Battle Area */
.battle-area {
    flex: 1; display: flex; align-items: stretch; padding: 10px 20px;
    gap: 16px; min-height: 0; position: relative; z-index: 5;
}

/* Castle Zone */
.castle-zone {
    width: 250px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 8px; position: relative;
}

/* HP Bar */
.castle-hp-bar {
    width: 200px; height: 28px; background: rgba(0,0,0,0.5); border-radius: 14px;
    border: 2px solid rgba(255,255,255,0.15); position: relative; overflow: hidden;
}
.hp-fill {
    height: 100%; border-radius: 12px; transition: width 0.6s ease;
    position: relative;
}
.blue-hp-fill {
    background: linear-gradient(90deg, #1D4ED8 0%, #3B82F6 50%, #60A5FA 100%);
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.3), 0 0 8px var(--blue-glow);
}
.red-hp-fill {
    background: linear-gradient(90deg, #B91C1C 0%, #EF4444 50%, #F87171 100%);
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.3), 0 0 8px var(--red-glow);
}
.hp-text {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    font-weight: 900; font-size: 0.85rem; color: white; text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* Shield */
.shield-indicator {
    display: flex; align-items: center; gap: 4px;
    background: rgba(255,255,255,0.1); padding: 4px 12px; border-radius: 20px;
    font-size: 0.85rem; font-weight: 800; color: var(--gold-light);
    opacity: 0; transition: opacity 0.3s;
}
.shield-indicator.visible { opacity: 1; }
.shield-icon { font-size: 1rem; }

/* Castle CSS Art */
.castle {
    width: 180px; height: 200px; position: relative; transition: all 0.3s;
    filter: drop-shadow(0 8px 20px rgba(0,0,0,0.4));
}
.castle-body {
    position: absolute; bottom: 0; left: 30px; right: 30px; height: 140px;
    background: linear-gradient(180deg, #6B7280 0%, #4B5563 50%, #374151 100%);
    border-radius: 8px 8px 0 0;
    border: 2px solid #9CA3AF;
    display: flex; align-items: center; justify-content: center;
}
.castle-body::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 16px;
    background: repeating-linear-gradient(90deg, #6B7280 0px, #6B7280 14px, transparent 14px, transparent 20px);
    border-radius: 8px 8px 0 0;
}
.castle-gate { font-size: 3.5rem; margin-top: 10px; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3)); }

.castle-tower {
    position: absolute; bottom: 0; width: 40px; height: 170px;
    background: linear-gradient(180deg, #9CA3AF 0%, #6B7280 50%, #4B5563 100%);
    border: 2px solid #D1D5DB; border-radius: 6px 6px 0 0;
}
.castle-tower::before {
    content: ''; position: absolute; top: -20px; left: 50%; transform: translateX(-50%);
    width: 0; height: 0;
    border-left: 24px solid transparent; border-right: 24px solid transparent;
}
.castle-tower::after {
    content: '🪟'; position: absolute; top: 30px; left: 50%; transform: translateX(-50%);
    font-size: 1.2rem;
}
.left-tower { left: -10px; }
.right-tower { right: -10px; }

.blue-castle .castle-tower::before { border-bottom: 24px solid var(--blue); }
.blue-castle .castle-body { border-color: var(--blue-light); }
.red-castle .castle-tower::before { border-bottom: 24px solid var(--red); }
.red-castle .castle-body { border-color: var(--red-light); }

.castle-flag {
    position: absolute; top: -30px; left: 50%; transform: translateX(-50%);
    font-size: 1.8rem; animation: flagWave 2s ease-in-out infinite;
}
@keyframes flagWave {
    0%,100% { transform: translateX(-50%) rotate(-5deg); }
    50% { transform: translateX(-50%) rotate(5deg); }
}

.castle-fire {
    position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
    font-size: 2rem; opacity: 0; transition: opacity 0.5s;
}
.castle-fire.burning { opacity: 1; animation: fireFlicker 0.3s ease-in-out infinite alternate; }
@keyframes fireFlicker {
    0% { transform: translateX(-50%) scale(1) rotate(-2deg); }
    100% { transform: translateX(-50%) scale(1.15) rotate(2deg); }
}

.castle-label {
    font-family: var(--font-display); font-size: 1.1rem; font-weight: 800;
    color: var(--cream); text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* Castle damage states */
.castle.damaged { animation: castleShake 0.4s ease; }
@keyframes castleShake {
    0%,100% { transform: translateX(0); }
    25% { transform: translateX(-8px) rotate(-1deg); }
    50% { transform: translateX(8px) rotate(1deg); }
    75% { transform: translateX(-4px); }
}
.castle.destroyed {
    opacity: 0.4; filter: grayscale(1) drop-shadow(0 8px 20px rgba(0,0,0,0.4));
    transform: scale(0.9);
}

/* Question Zone */
.question-zone {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-width: 0; position: relative;
}

/* Buzz Waiting */
.buzz-waiting { text-align: center; animation: buzzPulse 2s ease-in-out infinite; }
@keyframes buzzPulse {
    0%,100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}
.buzz-icon { font-size: 4rem; margin-bottom: 12px; }
.buzz-text {
    font-family: var(--font-display); font-size: 1.6rem; font-weight: 800;
    color: var(--gold); text-shadow: 0 0 20px rgba(245,166,35,0.4);
}
.buzz-keys {
    display: flex; gap: 30px; margin-top: 12px; justify-content: center;
}
.key-hint { font-weight: 800; font-size: 1rem; }

/* Question Display */
.question-display {
    width: 100%; max-width: 600px;
    background: rgba(255,248,231,0.95); border-radius: var(--border-radius-lg);
    padding: 20px 24px;
    box-shadow: 0 8px 0 rgba(0,0,0,0.15), 0 20px 60px rgba(0,0,0,0.3);
    border: 3px solid var(--gold);
}
.answering-team {
    text-align: center; font-family: var(--font-display); font-size: 1.1rem; font-weight: 800;
    margin-bottom: 10px; padding: 6px 16px; border-radius: 20px;
}
.answering-team.blue-answering { background: var(--blue-bg); color: var(--blue-dark); }
.answering-team.red-answering { background: var(--red-bg); color: var(--red-dark); }

.timer-display {
    width: 100%; height: 8px; background: rgba(0,0,0,0.1); border-radius: 4px;
    margin-bottom: 14px; position: relative; overflow: hidden;
}
.timer-bar {
    height: 100%; background: linear-gradient(90deg, var(--green) 0%, var(--gold) 50%, var(--red) 100%);
    border-radius: 4px; transition: width 0.3s linear; width: 100%;
}
.timer-text {
    position: absolute; right: 8px; top: -22px;
    font-weight: 900; font-size: 0.85rem; color: var(--brown-dark);
}

.q-text {
    font-family: var(--font-display); font-size: 1.3rem; font-weight: 700;
    color: var(--brown-dark); text-align: center; margin-bottom: 16px; line-height: 1.4;
}

.answers-container { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.answer-btn {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px; border: 3px solid var(--cream-dark); border-radius: var(--border-radius-sm);
    background: white; cursor: pointer; transition: all 0.2s;
    font-family: var(--font-body); font-size: 1rem; font-weight: 700; text-align: left;
}
.answer-btn:hover { border-color: var(--gold); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(245,166,35,0.2); }
.answer-btn .ans-label {
    min-width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
    border-radius: 8px; font-weight: 800; font-size: 0.9rem; color: white; flex-shrink: 0;
}
.answer-btn:nth-child(1) .ans-label { background: var(--blue); }
.answer-btn:nth-child(2) .ans-label { background: var(--orange); }
.answer-btn:nth-child(3) .ans-label { background: var(--green); }
.answer-btn:nth-child(4) .ans-label { background: var(--red); }

.answer-btn.correct { border-color: var(--green); background: #F0FDF4; box-shadow: 0 0 12px rgba(34,197,94,0.4); }
.answer-btn.wrong { border-color: var(--red); background: #FEF2F2; opacity: 0.7; }
.answer-btn.disabled { pointer-events: none; }

/* Action Chooser */
.action-chooser {
    text-align: center;
    background: rgba(255,248,231,0.95); border-radius: var(--border-radius-lg);
    padding: 24px 30px;
    box-shadow: 0 8px 0 rgba(0,0,0,0.15), 0 20px 60px rgba(0,0,0,0.3);
    border: 3px solid var(--gold);
    animation: modalSlideIn 0.3s ease;
}
@keyframes modalSlideIn {
    from { transform: translateY(40px) scale(0.95); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}
.action-title {
    font-family: var(--font-display); font-size: 1.4rem; color: var(--brown-dark);
    margin-bottom: 16px;
}
.action-buttons { display: flex; gap: 14px; justify-content: center; }
.action-choice {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 18px 24px; border: 3px solid var(--cream-dark); border-radius: var(--border-radius);
    background: white; cursor: pointer; transition: all 0.25s; min-width: 120px;
    font-family: var(--font-body);
}
.action-choice:hover { transform: translateY(-4px) scale(1.05); }
.action-emoji { font-size: 2.5rem; }
.action-name { font-weight: 800; font-size: 1rem; color: var(--brown-dark); }
.action-desc { font-size: 0.8rem; color: var(--brown-light); font-weight: 700; }

.attack-choice:hover { border-color: var(--red); background: var(--red-bg); box-shadow: 0 6px 20px var(--red-glow); }
.defend-choice:hover { border-color: var(--blue); background: var(--blue-bg); box-shadow: 0 6px 20px var(--blue-glow); }
.heal-choice:hover { border-color: var(--green); background: #F0FDF4; box-shadow: 0 6px 20px rgba(34,197,94,0.3); }

/* Battle Effect */
.battle-effect {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; z-index: 50;
    background: rgba(0,0,0,0.4); backdrop-filter: blur(2px);
    animation: effectFadeIn 0.2s ease;
}
@keyframes effectFadeIn { from { opacity: 0; } to { opacity: 1; } }
.effect-emoji { font-size: 5rem; animation: effectBurst 0.6s ease-out; }
@keyframes effectBurst {
    0% { transform: scale(0.3) rotate(-20deg); opacity: 0; }
    50% { transform: scale(1.3) rotate(10deg); opacity: 1; }
    100% { transform: scale(1) rotate(0deg); }
}
.effect-text {
    font-family: var(--font-display); font-size: 1.8rem; font-weight: 800;
    color: white; text-shadow: 0 3px 6px rgba(0,0,0,0.5); margin-top: 10px;
}

/* ===== PROJECTILE SYSTEM ===== */

/* Flying projectile */
.projectile-flying {
    position: fixed;
    font-size: 2.8rem;
    z-index: 200;
    pointer-events: none;
    filter: drop-shadow(0 0 12px rgba(255, 200, 0, 0.6)) drop-shadow(0 4px 8px rgba(0,0,0,0.4));
    will-change: left, top, transform;
}

/* Trail particles (small emojis left behind) */
.trail-particle {
    position: fixed;
    font-size: 1.2rem;
    z-index: 199;
    pointer-events: none;
    animation: trailFade 0.4s ease-out forwards;
}
@keyframes trailFade {
    0% { opacity: 0.8; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) translateY(10px); }
}

/* Impact flash (big radial glow) */
.impact-flash {
    position: fixed;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    z-index: 201;
    pointer-events: none;
    transform: translate(-50%, -50%);
    animation: impactFlash 0.5s ease-out forwards;
}
@keyframes impactFlash {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.2); }
    30% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.8); }
}

/* Impact particles (scatter emojis) */
.impact-particle {
    position: fixed;
    font-size: 1.6rem;
    z-index: 202;
    pointer-events: none;
    animation: impactScatter 0.8s ease-out forwards;
}
@keyframes impactScatter {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(0.5);
    }
    40% {
        opacity: 1;
        transform: translate(
            calc(-50% + var(--tx)),
            calc(-50% + var(--ty))
        ) scale(1.2);
    }
    100% {
        opacity: 0;
        transform: translate(
            calc(-50% + var(--tx) * 1.3),
            calc(-50% + var(--ty) * 1.3 + 40px)
        ) scale(0.4);
    }
}

/* ============================================
   RESULT SCREEN
   ============================================ */
#result-screen {
    flex-direction: column;
    background: linear-gradient(180deg, #1a0a00 0%, #2D1B0E 50%, #5C3D2E 100%);
    justify-content: center; align-items: center; position: relative;
}
.result-container {
    max-width: 700px; width: 90%; text-align: center; z-index: 10;
}
.result-castles { display: flex; align-items: center; justify-content: center; gap: 20px; margin-bottom: 24px; }
.result-castle-col { text-align: center; }
.result-castle-visual { font-size: 5rem; margin-bottom: 8px; }
.result-castle-visual.winner { animation: winnerGlow 1.5s ease-in-out infinite; }
@keyframes winnerGlow {
    0%,100% { filter: drop-shadow(0 0 10px rgba(255,215,0,0.5)); transform: scale(1); }
    50% { filter: drop-shadow(0 0 30px rgba(255,215,0,0.8)); transform: scale(1.1); }
}
.result-castle-visual.loser { filter: grayscale(1); opacity: 0.5; }
.result-team-name {
    font-family: var(--font-display); font-size: 1.3rem; font-weight: 800; color: var(--cream);
}
.result-hp { font-weight: 800; font-size: 1rem; color: var(--gold); margin-top: 4px; }

.result-vs { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.result-crown { font-size: 3rem; animation: float 2s ease-in-out infinite; }
.result-winner-text {
    font-family: var(--font-display); font-size: 1.6rem; font-weight: 800;
    color: var(--gold); text-shadow: 0 0 20px rgba(255,215,0,0.5);
}

.result-stats {
    background: rgba(255,248,231,0.1); border-radius: var(--border-radius); padding: 16px;
    margin-bottom: 20px; color: var(--cream-dark); font-weight: 700; font-size: 0.95rem;
    border: 1px solid rgba(255,255,255,0.1);
}
.result-actions { display: flex; gap: 12px; justify-content: center; }
.result-btn {
    padding: 14px 28px; border: none; border-radius: var(--border-radius-sm);
    font-family: var(--font-display); font-size: 1.1rem; font-weight: 800;
    cursor: pointer; transition: all 0.2s;
}
.replay-btn {
    background: linear-gradient(135deg, var(--orange) 0%, var(--gold) 100%);
    color: white; box-shadow: 0 4px 0 var(--orange-dark);
}
.replay-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--orange-dark); }
.home-btn {
    background: white; color: var(--brown-dark); border: 2px solid var(--cream-dark);
}
.home-btn:hover { background: var(--cream-dark); }

#confetti-canvas {
    position: fixed; inset: 0; z-index: 5; pointer-events: none;
}

/* ============================================
   MODALS
   ============================================ */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); z-index: 1000;
    justify-content: center; align-items: center; padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal-content {
    background: white; border-radius: var(--border-radius-lg); width: 100%; max-width: 650px;
    box-shadow: 0 8px 0 var(--cream-dark), 0 20px 60px rgba(0,0,0,0.2);
    overflow: hidden; animation: modalSlideIn 0.3s ease;
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center; padding: 20px 24px;
    background: linear-gradient(135deg, var(--gold-light) 0%, var(--cream) 100%);
    border-bottom: 2px solid var(--cream-dark);
}
.modal-header h2 { font-family: var(--font-display); font-size: 1.3rem; color: var(--brown-dark); }
.modal-close {
    width: 36px; height: 36px; border: none; background: var(--red-light); color: var(--red-dark);
    border-radius: 10px; cursor: pointer; font-size: 1.1rem; font-weight: 800; transition: all 0.15s;
}
.modal-close:hover { background: var(--red); color: white; transform: scale(1.1); }
.modal-body { padding: 24px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 0.95rem; color: var(--brown-dark); }
.form-group textarea, .form-group input[type="text"] {
    width: 100%; padding: 12px 14px; border: 2px solid var(--cream-dark); border-radius: var(--border-radius-sm);
    font-family: var(--font-body); font-size: 1rem; font-weight: 600; outline: none;
    transition: border-color 0.2s; resize: vertical;
}
.form-group textarea:focus, .form-group input[type="text"]:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(245,166,35,0.2); }
.answers-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.answer-group { background: var(--cream); padding: 12px; border-radius: var(--border-radius-sm); border: 1px solid var(--cream-dark); }
.answer-label {
    display: inline-block; width: 26px; height: 26px; line-height: 26px; text-align: center;
    border-radius: 6px; font-weight: 800; font-size: 0.8rem; color: white; margin-right: 6px; vertical-align: middle;
}
.a-label { background: var(--blue); }
.b-label { background: var(--orange); }
.c-label { background: var(--green); }
.d-label { background: var(--red); }
.correct-radio {
    display: flex; align-items: center; gap: 4px; margin-top: 8px;
    font-size: 0.85rem; font-weight: 700; cursor: pointer; color: var(--green-dark);
}
.correct-radio input { accent-color: var(--green); }
.modal-footer {
    display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px;
    background: var(--cream); border-top: 2px solid var(--cream-dark);
}
.modal-btn {
    padding: 12px 24px; border: none; border-radius: var(--border-radius-sm);
    font-family: var(--font-body); font-weight: 700; font-size: 1rem; cursor: pointer; transition: all 0.2s;
}
.cancel-btn { background: white; color: var(--brown-dark); border: 2px solid var(--cream-dark); }
.cancel-btn:hover { background: var(--cream-dark); }
.save-btn { background: var(--green); color: white; box-shadow: 0 3px 0 var(--green-dark); }
.save-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 0 var(--green-dark); }

/* Bank Modal */
.bank-modal-content { max-width: 750px; }
.bank-modal-header { background: linear-gradient(135deg, #FF7A2F 0%, #F5A623 100%) !important; }
.bank-modal-header h2 { color: white !important; text-shadow: 1px 2px 0 rgba(0,0,0,0.15); }
.bank-filters { display: flex; gap: 16px; margin-bottom: 16px; }
.bank-filter-group { flex: 1; }
.bank-filter-group label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 0.95rem; color: var(--brown-dark); }
.bank-filter-group select {
    width: 100%; padding: 10px 14px; border: 2px solid var(--cream-dark); border-radius: var(--border-radius-sm);
    font-family: var(--font-body); font-size: 1rem; font-weight: 700; outline: none;
    cursor: pointer; background: white; color: var(--brown-dark); transition: border-color 0.2s;
}
.bank-filter-group select:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255,122,47,0.2); }
.bank-select-all {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 12px; background: var(--cream); border-radius: 8px; margin-bottom: 10px; border: 1px solid var(--cream-dark);
}
.bank-checkbox-label {
    display: flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 700; font-size: 0.9rem; color: var(--brown-dark);
}
.bank-checkbox-label input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--orange); cursor: pointer; }
.bank-selected-count { font-size: 0.82rem; font-weight: 700; color: var(--orange); }
.bank-question-list { max-height: 320px; overflow-y: auto; padding-right: 4px; }
.bank-question-list::-webkit-scrollbar { width: 6px; }
.bank-question-list::-webkit-scrollbar-thumb { background: var(--orange); border-radius: 3px; }
.bank-q-item {
    display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px;
    background: white; border-radius: 8px; margin-bottom: 6px;
    border: 2px solid var(--cream-dark); cursor: pointer; transition: all 0.15s;
}
.bank-q-item:hover { border-color: var(--orange); background: #FFF9F0; }
.bank-q-item.selected { border-color: var(--orange); background: linear-gradient(135deg, #FFF5E6 0%, #FFECD2 100%); }
.bank-q-item input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--orange); cursor: pointer; flex-shrink: 0; margin-top: 2px; }
.bank-q-details { flex: 1; min-width: 0; }
.bank-q-text { font-weight: 700; font-size: 0.92rem; color: var(--brown-dark); margin-bottom: 4px; line-height: 1.4; }
.bank-q-answers { display: flex; flex-wrap: wrap; gap: 6px; }
.bank-q-answer-tag {
    display: inline-block; padding: 2px 8px; border-radius: 6px;
    font-size: 0.72rem; font-weight: 700; background: var(--cream-dark); color: var(--brown-dark);
}
.bank-q-answer-tag.correct-tag { background: var(--green); color: white; }

/* Floating Buttons */
.sound-toggle {
    position: fixed; bottom: 20px; right: 20px; width: 50px; height: 50px; border-radius: 50%;
    background: var(--gold); color: white; border: 3px solid var(--gold-dark);
    font-size: 1.4rem; cursor: pointer; z-index: 999;
    box-shadow: 0 4px 0 var(--gold-dark), 0 6px 16px rgba(0,0,0,0.2);
    transition: all 0.2s; display: flex; align-items: center; justify-content: center;
}
.sound-toggle:hover { transform: translateY(-2px); }
.sound-toggle.muted { background: var(--brown-light); border-color: var(--brown-dark); box-shadow: 0 4px 0 var(--brown-dark); }

.fullscreen-toggle {
    position: fixed; bottom: 20px; right: 80px; width: 50px; height: 50px; border-radius: 50%;
    background: var(--blue); color: white; border: 3px solid var(--blue-dark);
    font-size: 1.4rem; cursor: pointer; z-index: 999;
    box-shadow: 0 4px 0 var(--blue-dark), 0 6px 16px rgba(0,0,0,0.2);
    transition: all 0.2s; display: flex; align-items: center; justify-content: center;
}
.fullscreen-toggle:hover { transform: translateY(-2px); }
.fullscreen-toggle.active { background: var(--green); border-color: var(--green-dark); box-shadow: 0 4px 0 var(--green-dark); }

/* Hidden helper */
.hidden { display: none !important; }

/* ============================================
   AMMO CHOOSER
   ============================================ */
.ammo-chooser {
    text-align: center;
    background: rgba(255,248,231,0.95); border-radius: var(--border-radius-lg);
    padding: 24px 30px;
    box-shadow: 0 8px 0 rgba(0,0,0,0.15), 0 20px 60px rgba(0,0,0,0.3);
    border: 3px solid var(--gold);
    animation: modalSlideIn 0.3s ease;
}
.ammo-title {
    font-family: var(--font-display); font-size: 1.3rem; color: var(--brown-dark);
    margin-bottom: 16px;
}
.ammo-buttons {
    display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
}
.ammo-choice {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 14px 16px; border: 3px solid var(--cream-dark); border-radius: var(--border-radius);
    background: white; cursor: pointer; transition: all 0.25s; min-width: 90px;
    font-family: var(--font-body);
}
.ammo-choice:hover {
    border-color: var(--ammo-color, var(--gold));
    transform: translateY(-4px) scale(1.08);
    box-shadow: 0 6px 20px color-mix(in srgb, var(--ammo-color, var(--gold)) 30%, transparent);
    background: color-mix(in srgb, var(--ammo-color, var(--gold)) 8%, white);
}
.ammo-emoji { font-size: 2.2rem; }
.ammo-name { font-weight: 800; font-size: 0.88rem; color: var(--brown-dark); }
.ammo-dmg {
    font-weight: 800; font-size: 0.78rem; color: var(--red-dark);
    background: var(--red-bg); padding: 1px 10px; border-radius: 10px;
}

/* ============================================
   SUPER ATTACK
   ============================================ */
.super-badge {
    display: inline-block; background: linear-gradient(135deg, #FFD700, #FF7A2F);
    padding: 2px 10px; border-radius: 12px; font-size: 0.8rem; font-weight: 900;
    color: white; text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    animation: superPulse 0.6s ease-in-out infinite alternate;
    margin-left: 6px;
}
@keyframes superPulse {
    0% { transform: scale(1); box-shadow: 0 0 8px rgba(255,215,0,0.4); }
    100% { transform: scale(1.1); box-shadow: 0 0 20px rgba(255,215,0,0.8); }
}

.attack-choice.super-active {
    border-color: var(--gold) !important;
    background: linear-gradient(135deg, #FFF8E7 0%, #FFECD2 100%) !important;
    animation: superGlow 1s ease-in-out infinite alternate;
}
@keyframes superGlow {
    0% { box-shadow: 0 0 8px rgba(255,215,0,0.3); }
    100% { box-shadow: 0 0 24px rgba(255,215,0,0.6), 0 0 48px rgba(255,122,47,0.2); }
}

/* ============================================
   CASTLE CRACK EFFECTS
   ============================================ */
/* HP <= 75%: Light cracks */
.castle.crack-1 .castle-body::after {
    content: '';
    position: absolute; top: 30px; left: 10px;
    width: 40px; height: 2px;
    background: rgba(0,0,0,0.3);
    transform: rotate(-15deg);
    box-shadow: 30px 20px 0 rgba(0,0,0,0.2);
}

/* HP <= 50%: Medium cracks */
.castle.crack-2 .castle-body::after {
    content: '';
    position: absolute; top: 20px; left: 8px;
    width: 50px; height: 2px;
    background: rgba(0,0,0,0.4);
    transform: rotate(-20deg);
    box-shadow:
        25px 25px 0 rgba(0,0,0,0.35),
        -5px 50px 0 1px rgba(0,0,0,0.3),
        35px 60px 0 rgba(0,0,0,0.3);
}
.castle.crack-2 .castle-body {
    background: linear-gradient(180deg, #5C6370 0%, #444B56 50%, #333940 100%) !important;
}

/* HP <= 25%: Heavy cracks + darkened */
.castle.crack-3 .castle-body::after {
    content: '';
    position: absolute; top: 15px; left: 5px;
    width: 60px; height: 3px;
    background: rgba(0,0,0,0.5);
    transform: rotate(-25deg);
    box-shadow:
        20px 20px 0 1px rgba(0,0,0,0.45),
        -8px 40px 0 1px rgba(0,0,0,0.4),
        30px 55px 0 2px rgba(0,0,0,0.4),
        -5px 70px 0 1px rgba(0,0,0,0.35),
        40px 35px 0 1px rgba(0,0,0,0.3);
}
.castle.crack-3 .castle-body {
    background: linear-gradient(180deg, #4A4F57 0%, #3A3E45 50%, #2A2D33 100%) !important;
}
.castle.crack-3 .castle-tower {
    background: linear-gradient(180deg, #6B7078 0%, #555A61 50%, #404448 100%) !important;
}
.castle.crack-3 {
    filter: drop-shadow(0 8px 20px rgba(0,0,0,0.4)) brightness(0.8);
}

/* ============================================
   RESPONSIVE - MOBILE
   ============================================ */
@media (max-width: 768px) {
    /* Setup */
    .setup-grid { grid-template-columns: 1fr; }
    .setup-header { flex-wrap: wrap; }
    .game-title { font-size: 1.7rem; }
    .zalo-cta { order: -1; width: 100%; justify-content: center; }
    .team-names-row { grid-template-columns: 1fr; }

    /* Game screen - vertical layout */
    .battle-area {
        flex-direction: column; padding: 8px 12px; gap: 8px;
    }
    .castle-zone {
        width: 100%; flex-direction: row; gap: 12px;
        justify-content: center; align-items: center;
    }
    .castle { width: 100px; height: 120px; }
    .castle-body { left: 16px; right: 16px; height: 80px; }
    .castle-gate { font-size: 2rem; }
    .castle-tower { width: 24px; height: 100px; }
    .castle-tower::before {
        border-left-width: 14px !important;
        border-right-width: 14px !important;
    }
    .blue-castle .castle-tower::before { border-bottom-width: 14px !important; }
    .red-castle .castle-tower::before { border-bottom-width: 14px !important; }
    .castle-tower::after { font-size: 0.8rem; top: 20px; }
    .castle-flag { font-size: 1.2rem; top: -20px; }
    .castle-hp-bar { width: 120px; height: 22px; }
    .hp-text { font-size: 0.75rem; }
    .castle-label { font-size: 0.9rem; }

    .question-zone { padding: 4px; }
    .question-display { padding: 14px 16px; }
    .q-text { font-size: 1.1rem; }
    .answers-container { grid-template-columns: 1fr; gap: 6px; }
    .answer-btn { padding: 10px 12px; font-size: 0.9rem; }

    .action-buttons { flex-wrap: wrap; gap: 8px; }
    .action-choice { min-width: 90px; padding: 12px 14px; }
    .action-emoji { font-size: 2rem; }

    .ammo-buttons { gap: 8px; }
    .ammo-choice { min-width: 60px; padding: 10px 12px; }
    .ammo-emoji { font-size: 1.6rem; }

    .buzz-icon { font-size: 2.5rem; }
    .buzz-text { font-size: 1.2rem; }
    .buzz-keys { gap: 14px; }

    .topbar-team-name { font-size: 0.9rem; }
    .game-mode-badge { font-size: 0.75rem; padding: 3px 10px; }

    /* Result */
    .result-castle-visual { font-size: 3.5rem; }
    .result-team-name { font-size: 1rem; }
    .result-winner-text { font-size: 1.2rem; }
    .result-btn { padding: 10px 20px; font-size: 0.95rem; }
}

@media (max-width: 480px) {
    .game-topbar { padding: 0 8px; height: 48px; }
    .castle { width: 80px; height: 100px; }
    .castle-body { left: 12px; right: 12px; height: 65px; }
    .castle-gate { font-size: 1.5rem; }
    .castle-tower { width: 20px; height: 80px; }
    .castle-hp-bar { width: 90px; height: 18px; }
    .hp-text { font-size: 0.65rem; }
    .question-display { padding: 10px 12px; }
    .q-text { font-size: 0.95rem; margin-bottom: 10px; }
    .action-choice { min-width: 80px; padding: 10px; }
    .action-emoji { font-size: 1.6rem; }
    .action-name { font-size: 0.85rem; }
    .ammo-choice { min-width: 55px; padding: 8px 10px; }
    .ammo-emoji { font-size: 1.4rem; }
    .ammo-name { font-size: 0.75rem; }
}
