* { margin: 0; padding: 0; box-sizing: border-box; }
body { overflow: hidden; background: #000; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; color: #fff; touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

#game-container { position: relative; width: 100vw; height: 100vh; overflow: hidden; }
#game-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---- Overlays ---- */
.overlay {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.82); z-index: 100;
    transition: opacity 0.3s;
}
.overlay.hidden { display: none; }
.overlay h1 { font-size: 4rem; margin-bottom: 0.3em; color: #ff6b35; text-shadow: 0 0 30px #ff6b35; letter-spacing: 0.1em; }
.overlay h2 { font-size: 2.4rem; margin-bottom: 0.8em; color: #ffd166; text-shadow: 0 0 20px #ffd166; }
.overlay p { font-size: 1.1rem; margin: 0.3em 0; color: #ccc; }
.overlay .tagline { font-size: 1.3rem; color: #aaa; margin-bottom: 1.2em; }
.overlay .controls-info { margin: 1em 0; text-align: left; }
.overlay .controls-info p { margin: 0.35em 0; }
.overlay .controls-info b { color: #ffd166; }
.overlay .tip { color: #ff6b35; font-weight: bold; margin-top: 1em; font-size: 1.15rem; }
.overlay button {
    margin-top: 1.5em; padding: 0.8em 2.5em;
    font-size: 1.3rem; font-weight: bold;
    border: 2px solid #ffd166; background: transparent; color: #ffd166;
    cursor: pointer; border-radius: 6px;
    transition: all 0.2s;
}
.overlay button:hover { background: #ffd166; color: #000; }

/* ---- HUD ---- */
#hud { position: absolute; top: 0; left: 0; right: 0; bottom: 0; pointer-events: none; z-index: 10; }
#hud.hidden { display: none; }

#hud-top {
    position: absolute; top: 12px; left: 12px; right: 12px;
    display: flex; align-items: center; gap: 18px;
}

#hp-bar {
    position: relative; width: 220px; height: 22px;
    background: #333; border-radius: 11px; overflow: hidden;
    border: 1px solid #555;
}
#hp-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #e63946, #ff6b6b); transition: width 0.2s; border-radius: 11px; }
#hp-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: bold; text-shadow: 0 1px 2px #000; }

#score-display, #kill-display { font-size: 1.1rem; font-weight: bold; text-shadow: 0 0 8px rgba(255,209,102,0.5); }

/* ---- Level Bar ---- */
#level-bar-wrap { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 180px; }
#level-name { font-size: 0.8rem; font-weight: bold; color: #a78bfa; text-shadow: 0 0 8px rgba(167,139,250,0.4); letter-spacing: 0.05em; }
#level-bar { position: relative; width: 100%; height: 8px; background: #222; border-radius: 4px; overflow: hidden; }
#level-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #a78bfa, #c4b5fd); transition: width 0.3s; border-radius: 4px; }

/* ---- Combo / Momentum / Apex ---- */
#hud-mid {
    position: absolute; top: 50px; left: 50%; transform: translateX(-50%);
    display: flex; flex-direction: column; align-items: center; gap: 4px;
}
#combo-display { font-size: 1.6rem; font-weight: bold; color: #ffd166; text-shadow: 0 0 15px #ffd166; }
#momentum-display { font-size: 1rem; color: #a78bfa; text-shadow: 0 0 12px #a78bfa; }
#apex-indicator {
    font-size: 2.6rem; font-weight: 900; color: #ff6b35;
    text-shadow: 0 0 30px #ff6b35, 0 0 60px #ff6b35;
    animation: apexPulse 0.5s ease-out forwards;
}
@keyframes apexPulse {
    0% { transform: scale(1.8); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}

/* ---- Spell Bar ---- */
#spell-bar {
    position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 6px;
}
.spell-slot {
    width: 72px; padding: 6px 4px;
    background: rgba(255,255,255,0.08); border: 2px solid rgba(255,255,255,0.15);
    border-radius: 8px; text-align: center; transition: all 0.15s;
    pointer-events: auto; cursor: pointer;
}
.spell-slot.active { border-color: #ffd166; background: rgba(255,209,102,0.15); box-shadow: 0 0 12px rgba(255,209,102,0.3); }
.spell-key { display: block; font-size: 0.7rem; color: #888; margin-bottom: 2px; }
.spell-name { display: block; font-size: 0.8rem; font-weight: bold; }

/* Spell-specific colors */
.spell-slot[data-spell="0"] .spell-name { color: #ff6b35; }
.spell-slot[data-spell="1"] .spell-name { color: #73d2de; }
.spell-slot[data-spell="2"] .spell-name { color: #ffd166; }
.spell-slot[data-spell="3"] .spell-name { color: #a78bfa; }
.spell-slot[data-spell="4"] .spell-name { color: #ef476f; }
.spell-slot[data-spell="5"] .spell-name { color: #06d6a0; }

/* ---- Floating Damage Numbers ---- */
#damage-numbers { position: absolute; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.dmg-num {
    position: absolute; font-weight: 900; font-size: 2rem;
    text-shadow: 0 0 8px currentColor, 0 2px 6px rgba(0,0,0,0.8);
    pointer-events: none; white-space: nowrap;
    animation: dmgFloat 1.2s ease-out forwards;
}
.dmg-num.crit {
    font-size: 3.2rem;
    animation: dmgFloatCrit 1.4s ease-out forwards;
}
@keyframes dmgFloat {
    0% { transform: translateY(0) scale(1); opacity: 1; }
    100% { transform: translateY(-60px) scale(0.6); opacity: 0; }
}
@keyframes dmgFloatCrit {
    0% { transform: translateY(0) scale(1.5); opacity: 1; }
    20% { transform: translateY(-15px) scale(1.8); }
    100% { transform: translateY(-90px) scale(0.7); opacity: 0; }
}

/* ---- Upgrade Screen ---- */
#upgrade-screen { pointer-events: auto; }
#upgrade-choices { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.upgrade-card {
    width: 200px; padding: 20px 16px;
    background: rgba(255,255,255,0.06); border: 2px solid rgba(255,255,255,0.12);
    border-radius: 12px; text-align: center; cursor: pointer;
    transition: all 0.2s;
}
.upgrade-card:hover { border-color: #ffd166; background: rgba(255,209,102,0.1); transform: translateY(-4px); }
.upgrade-card .upgrade-icon { font-size: 2.2rem; margin-bottom: 8px; }
.upgrade-card .upgrade-title { font-size: 1rem; font-weight: bold; color: #ffd166; margin-bottom: 6px; }
.upgrade-card .upgrade-desc { font-size: 0.85rem; color: #aaa; line-height: 1.4; }
.upgrade-card .upgrade-cat { font-size: 0.7rem; color: #666; margin-top: 8px; text-transform: uppercase; letter-spacing: 0.1em; }

/* ---- Level Complete Banner (inside upgrade screen) ---- */
#upgrade-header { text-align: center; margin-bottom: 0.5em; }
.lc-banner { font-size: 2rem; font-weight: 900; color: #a78bfa; text-shadow: 0 0 25px #a78bfa; margin-bottom: 0.2em; }
.lc-sub { font-size: 1rem; color: #ccc; margin-bottom: 0.2em; }
.lc-next-text { font-size: 0.9rem; color: #888; font-style: italic; }
.lc-heal { font-size: 0.9rem; color: #06d6a0; margin-top: 0.3em; }

/* ---- Game Over ---- */
#game-over button { pointer-events: auto; }
#final-score { font-size: 1.6rem; color: #ffd166; margin: 0.4em 0; }
#high-score { font-size: 1.1rem; color: #888; }

/* ---- Leaderboard ---- */
.leaderboard { width: 340px; max-height: 260px; overflow-y: auto; margin: 0.8em auto; text-align: left; }
.leaderboard table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.leaderboard th { color: #ffd166; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; padding: 4px 6px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.leaderboard td { padding: 3px 6px; color: #bbb; }
.leaderboard tr:nth-child(even) td { background: rgba(255,255,255,0.03); }
.leaderboard tr:first-child td { color: #ffd166; font-weight: bold; }
.leaderboard .lb-rank { width: 28px; text-align: center; color: #666; }
.leaderboard .lb-title { font-size: 0.75rem; color: #666; text-align: center; margin-bottom: 6px; }

/* ---- Multi-kill Callout ---- */
.multi-kill {
    position: fixed; top: 25%; left: 50%; transform: translateX(-50%);
    font-size: 3rem; font-weight: 900; color: #ffd166;
    text-shadow: 0 0 20px #ffd166, 0 0 40px #ff6b35, 0 4px 8px rgba(0,0,0,0.8);
    pointer-events: none; white-space: nowrap; z-index: 25;
    animation: multiKillPop 1.1s ease-out forwards;
    letter-spacing: 0.1em;
}
@keyframes multiKillPop {
    0% { transform: translateX(-50%) scale(0.3); opacity: 0; }
    15% { transform: translateX(-50%) scale(1.3); opacity: 1; }
    30% { transform: translateX(-50%) scale(1); }
    80% { opacity: 1; }
    100% { transform: translateX(-50%) translateY(-30px) scale(0.8); opacity: 0; }
}

/* ---- Combo Screen Glow ---- */
#combo-glow {
    position: absolute; inset: 0; pointer-events: none; z-index: 14;
    opacity: 0; transition: opacity 0.3s;
}

/* ---- Screen Flash ---- */
#screen-flash {
    position: absolute; inset: 0; pointer-events: none; z-index: 15;
    background: white; opacity: 0; transition: opacity 0.05s;
}

/* ---- Mobile Controls Visibility ---- */
.controls-mobile { display: none; }
@media (hover: none) and (pointer: coarse) {
    .controls-desktop { display: none; }
    .controls-mobile { display: block; }
}

/* ---- Mobile Responsive ---- */
@media (max-width: 768px) {
    .overlay h1 { font-size: 2.4rem; }
    .overlay h2 { font-size: 1.6rem; }
    .overlay p { font-size: 0.95rem; }
    .overlay .tagline { font-size: 1.05rem; }
    .overlay .tip { font-size: 1rem; }
    .overlay button { font-size: 1.1rem; padding: 0.7em 2em; }

    #hud-top { flex-wrap: wrap; gap: 8px; }
    #hp-bar { width: 140px; height: 18px; }
    #hp-text { font-size: 0.65rem; }
    #level-bar-wrap { min-width: 120px; }
    #level-name { font-size: 0.7rem; }
    #score-display, #kill-display { font-size: 0.85rem; }

    #hud-mid { top: 42px; }
    #combo-display { font-size: 1.2rem; }
    #momentum-display { font-size: 0.85rem; }
    #apex-indicator { font-size: 2rem; }

    #spell-bar { gap: 4px; bottom: 10px; }
    .spell-slot { width: 52px; padding: 5px 3px; pointer-events: auto; }
    .spell-key { font-size: 0.6rem; }
    .spell-name { font-size: 0.65rem; }

    .dmg-num { font-size: 1.4rem; }
    .dmg-num.crit { font-size: 2.2rem; }
    .multi-kill { font-size: 2rem; }

    .upgrade-card { width: 150px; padding: 14px 10px; }
    .upgrade-card .upgrade-icon { font-size: 1.6rem; }
    .upgrade-card .upgrade-title { font-size: 0.85rem; }
    .upgrade-card .upgrade-desc { font-size: 0.75rem; }

    #final-score { font-size: 1.2rem; }
    #high-score { font-size: 0.95rem; }
}

@media (max-width: 480px) {
    .overlay h1 { font-size: 1.8rem; }
    .overlay h2 { font-size: 1.3rem; }

    #hud-top { gap: 5px; }
    #hp-bar { width: 100px; height: 16px; }
    #level-bar-wrap { min-width: 90px; }
    #score-display, #kill-display { font-size: 0.75rem; }

    #spell-bar { gap: 3px; }
    .spell-slot { width: 44px; padding: 4px 2px; }
    .spell-name { font-size: 0.55rem; }

    .upgrade-card { width: 120px; padding: 10px 8px; }
    #upgrade-choices { gap: 8px; }
}
