* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #0a0e27; touch-action: none; user-select: none; -webkit-user-select: none; }
canvas { display: block; width: 100%; height: 100%; }

/* ===== UI OVERLAY ===== */
#ui { position: fixed; top: 0; left: 0; width: 100%; pointer-events: none; z-index: 10; padding: 12px; }
.ui-bar { background: rgba(0,0,0,0.6); border-radius: 8px; overflow: hidden; height: 18px; position: relative; margin-bottom: 6px; border: 1px solid rgba(255,255,255,0.15); }
.ui-bar-fill { height: 100%; transition: width 0.2s; border-radius: 7px; }
.ui-bar-label { position: absolute; top: 0; left: 8px; right: 8px; height: 100%; display: flex; align-items: center; justify-content: space-between; font-family: 'Segoe UI', sans-serif; font-size: 11px; color: #fff; text-shadow: 0 1px 2px #000; font-weight: 600; }
#hp-fill { background: linear-gradient(90deg, #e74c3c, #ff6b6b); }
#xp-fill { background: linear-gradient(90deg, #f39c12, #f1c40f); }
#hp-bar { max-width: 240px; }
#xp-bar { max-width: 400px; margin: 0 auto; }
#stats { display: flex; gap: 16px; justify-content: center; font-family: 'Segoe UI', sans-serif; font-size: 13px; color: #ccc; margin-top: 4px; }
#stats span { background: rgba(0,0,0,0.5); padding: 2px 10px; border-radius: 6px; }
#weapons-display { position: fixed; bottom: 12px; left: 12px; pointer-events: none; z-index: 10; display: flex; gap: 6px; flex-wrap: wrap; max-width: 300px; }
.weapon-badge { background: rgba(0,0,0,0.7); border: 1px solid rgba(255,255,255,0.2); border-radius: 6px; padding: 3px 8px; font-family: 'Segoe UI', sans-serif; font-size: 11px; color: #aef; display: flex; align-items: center; gap: 4px; }
.weapon-badge .wlv { color: #ffd700; font-weight: 700; }

/* ===== SCREENS ===== */
.screen-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 100; }
#title-screen { background: radial-gradient(ellipse at 50% 40%, #1a1040 0%, #0a0e27 70%); }
#title-screen h1 { font-family: 'Segoe UI', sans-serif; font-size: clamp(32px, 8vw, 72px); font-weight: 900; color: #fff; text-transform: uppercase; letter-spacing: 4px; text-shadow: 0 0 30px rgba(100,200,255,0.5), 0 0 60px rgba(100,200,255,0.2); margin-bottom: 8px; text-align: center; }
#title-screen .subtitle { font-family: 'Segoe UI', sans-serif; font-size: clamp(14px, 3vw, 22px); color: #8be; letter-spacing: 6px; text-transform: uppercase; margin-bottom: 40px; }
#title-screen .lore { font-family: 'Segoe UI', sans-serif; font-size: clamp(12px, 2.5vw, 16px); color: #7a8baa; max-width: 500px; text-align: center; line-height: 1.6; margin-bottom: 30px; padding: 0 20px; }
.btn { pointer-events: auto; font-family: 'Segoe UI', sans-serif; font-size: 20px; font-weight: 700; padding: 14px 48px; border: none; border-radius: 12px; cursor: pointer; text-transform: uppercase; letter-spacing: 2px; transition: transform 0.15s, box-shadow 0.15s; }
.btn:hover { transform: scale(1.05); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: linear-gradient(135deg, #4ecdc4, #44a08d); color: #fff; box-shadow: 0 4px 20px rgba(78,205,196,0.4); }
.btn-danger { background: linear-gradient(135deg, #e74c3c, #c0392b); color: #fff; box-shadow: 0 4px 20px rgba(231,76,60,0.4); }
#title-screen .controls-hint { font-family: 'Segoe UI', sans-serif; font-size: 13px; color: #556; margin-top: 24px; }
#title-screen .version-tag { position: absolute; bottom: 10px; right: 14px; font-family: 'Segoe UI', monospace; font-size: 10px; color: rgba(255,255,255,0.08); letter-spacing: 0.5px; pointer-events: none; user-select: none; }

/* ===== UPGRADE SCREEN ===== */
#upgrade-screen { background: rgba(0,0,0,0.85); backdrop-filter: blur(8px); }
#upgrade-screen h2 { font-family: 'Segoe UI', sans-serif; font-size: clamp(20px, 5vw, 36px); color: #ffd700; text-transform: uppercase; letter-spacing: 3px; margin-bottom: 8px; text-shadow: 0 0 20px rgba(255,215,0,0.5); }
#upgrade-screen .level-label { font-family: 'Segoe UI', sans-serif; font-size: 14px; color: #aaa; margin-bottom: 24px; }
#upgrade-cards { display: flex; gap: 16px; padding: 0 16px; flex-wrap: wrap; justify-content: center; pointer-events: auto; }
.upgrade-card { background: linear-gradient(180deg, #1a2040 0%, #0f1528 100%); border: 2px solid rgba(255,255,255,0.1); border-radius: 16px; padding: 20px 16px; width: 180px; cursor: pointer; transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s; text-align: center; }
.upgrade-card:hover { transform: translateY(-6px); border-color: #4ecdc4; box-shadow: 0 8px 30px rgba(78,205,196,0.3); }
.upgrade-card .card-icon { font-size: 40px; margin-bottom: 10px; display: block; }
.upgrade-card .card-name { font-family: 'Segoe UI', sans-serif; font-size: 15px; font-weight: 700; color: #fff; margin-bottom: 6px; }
.upgrade-card .card-level { font-family: 'Segoe UI', sans-serif; font-size: 11px; color: #ffd700; margin-bottom: 8px; }
.upgrade-card .card-desc { font-family: 'Segoe UI', sans-serif; font-size: 12px; color: #8899aa; line-height: 1.4; }
.upgrade-card.new-weapon { border-color: rgba(78,205,196,0.4); }
.upgrade-card.prestige-weapon { border-color: rgba(255,215,0,0.6); background: linear-gradient(180deg, #2a1f00 0%, #1a1200 100%); box-shadow: 0 0 20px rgba(255,215,0,0.2); }
.upgrade-card.prestige-weapon:hover { border-color: #ffd700; box-shadow: 0 8px 30px rgba(255,215,0,0.4); }
.upgrade-card.prestige-weapon .card-level { color: #ffd700; font-weight: bold; }
.wlv.prestige { color: #ffd700 !important; }

/* ===== GAME OVER ===== */
#gameover-screen { background: rgba(0,0,0,0.9); }
#gameover-screen h2 { font-family: 'Segoe UI', sans-serif; font-size: clamp(28px, 7vw, 56px); font-weight: 900; color: #e74c3c; text-transform: uppercase; letter-spacing: 3px; margin-bottom: 24px; }
#gameover-stats { font-family: 'Segoe UI', sans-serif; color: #aaa; font-size: 16px; line-height: 2; margin-bottom: 30px; text-align: center; }
#gameover-stats .stat-val { color: #fff; font-weight: 700; font-size: 18px; }
#gameover-screen .btn { margin-top: 10px; }

/* ===== PAUSE ===== */
#pause-hint { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); font-family: 'Segoe UI', sans-serif; color: rgba(255,255,255,0.9); text-transform: uppercase; z-index: 50; display: none; text-shadow: 0 2px 10px rgba(0,0,0,0.8); text-align: center; }
#pause-hint h1 { font-size: 36px; font-weight: 900; letter-spacing: 6px; margin: 0 0 16px 0; }
#pause-hint .weapon-stats { background: rgba(0,0,0,0.6); border-radius: 10px; padding: 12px 20px; font-size: 14px; text-transform: none; letter-spacing: 0; text-align: left; min-width: 260px; }
#pause-hint .weapon-stats table { width: 100%; border-collapse: collapse; }
#pause-hint .weapon-stats th { font-size: 11px; color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: 1px; padding: 2px 8px 6px; border-bottom: 1px solid rgba(255,255,255,0.15); text-align: right; }
#pause-hint .weapon-stats th:first-child { text-align: left; }
#pause-hint .weapon-stats td { padding: 4px 8px; font-variant-numeric: tabular-nums; text-align: right; }
#pause-hint .weapon-stats td:first-child { text-align: left; font-weight: 600; }
#pause-hint .weapon-stats .no-stats { color: rgba(255,255,255,0.4); font-style: italic; text-align: center; padding: 8px; }

/* ===== AUTO-UPGRADE TOGGLE ===== */
.auto-upgrade-toggle { font-family: 'Segoe UI', sans-serif; font-size: 13px; color: #556; margin-top: 20px; cursor: pointer; padding: 6px 16px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.1); background: rgba(255,255,255,0.05); transition: all 0.2s; pointer-events: auto; user-select: none; -webkit-user-select: none; position: relative; z-index: 10; }
.auto-upgrade-toggle:hover { border-color: rgba(78,205,196,0.4); color: #8be; }
.auto-upgrade-toggle.active { border-color: #4ecdc4; color: #4ecdc4; background: rgba(78,205,196,0.1); }
.auto-upgrade-toggle .toggle-icon { font-size: 14px; }

/* ===== AUTO-UPGRADE COUNTDOWN ===== */
.upgrade-card.auto-selected { border-color: #4ecdc4; box-shadow: 0 0 20px rgba(78,205,196,0.4); animation: auto-pulse 1s infinite; }
.auto-countdown { position: absolute; top: -10px; right: -10px; width: 28px; height: 28px; background: #4ecdc4; color: #0a0e27; border-radius: 50%; font-family: 'Segoe UI', sans-serif; font-size: 14px; font-weight: 900; display: flex; align-items: center; justify-content: center; }
.upgrade-card { position: relative; }
@keyframes auto-pulse { 0%, 100% { box-shadow: 0 0 20px rgba(78,205,196,0.4); } 50% { box-shadow: 0 0 30px rgba(78,205,196,0.6); } }

/* ===== SOUND TOGGLE ===== */
#sound-toggle { position: fixed; top: 12px; right: 12px; z-index: 110; background: rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.15); border-radius: 8px; width: 36px; height: 36px; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: border-color 0.2s; padding: 0; color: #fff; }
#sound-toggle:hover { border-color: rgba(78,205,196,0.5); }

.hidden { display: none !important; }

/* ===== MOBILE JOYSTICK ===== */
#joystick-zone { position: fixed; bottom: 0; left: 0; width: 50%; height: 50%; z-index: 20; pointer-events: auto; }
@media (min-width: 769px) { #joystick-zone { display: none; } }
