:root {
  --orange: #ff7b33;
  --orange2: #ffb457;
  --green: #7ee06a;
  --cream: #f5ead6;
  --red: #ff4545;
  --panel: rgba(16, 9, 30, 0.88);
  --line: rgba(255, 123, 51, 0.45);
  --font-display: 'Impact', 'Trebuchet MS', 'Arial Black', sans-serif;
  --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #0d0718;
  font-family: var(--font-ui);
  color: var(--cream);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

canvas {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 0;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- overlays ---------- */
#scanlines {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0.5;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.09) 0 1px, transparent 1px 3px);
}

#vignette {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(255, 30, 30, 0.6) 100%);
}

#lowhp {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
}

body.lowhp #lowhp {
  opacity: 1;
  animation: lowp 1.1s ease-in-out infinite;
}

@keyframes lowp {
  0%, 100% { box-shadow: inset 0 0 60px rgba(255, 40, 40, 0); }
  50% { box-shadow: inset 0 0 140px rgba(255, 40, 40, 0.6); }
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  display: none;
  padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
}

body[data-state="play"] #hud,
body[data-state="pause"] #hud {
  display: block;
}

#hudTL {
  position: absolute;
  top: 14px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.barwrap {
  width: min(220px, 32vw);
  height: 16px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--line);
  clip-path: polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
}

.barwrap.small {
  width: min(150px, 22vw);
  height: 8px;
}

#hpFill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #4caf50, var(--green));
  transition: width 0.15s;
}

body.lowhp #hpFill {
  background: linear-gradient(90deg, #c0392b, var(--red));
}

#dashFill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #e0a33a, var(--orange2));
}

#kills {
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 13px;
  opacity: 0.85;
  text-shadow: 0 2px 4px #000;
}

#hudTC {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
}

#score {
  font-family: var(--font-display);
  font-size: clamp(26px, 5vw, 42px);
  line-height: 1;
  text-shadow: 0 0 18px rgba(255, 123, 51, 0.6), 0 3px 0 rgba(0, 0, 0, 0.6);
}

#score.pop {
  animation: pop 0.18s ease;
}

@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

#wave {
  letter-spacing: 5px;
  font-weight: 700;
  font-size: clamp(11px, 2vw, 14px);
  color: var(--orange2);
  text-shadow: 0 2px 4px #000;
  margin-top: 2px;
}

#combo {
  margin-top: 5px;
  opacity: 0;
  transition: opacity 0.2s;
}

#combo.on {
  opacity: 1;
}

#comboTxt {
  font-family: var(--font-display);
  font-size: clamp(13px, 2.4vw, 18px);
  color: var(--green);
  text-shadow: 0 0 12px rgba(126, 224, 106, 0.7), 0 2px 0 #000;
}

.combodrain {
  width: 110px;
  height: 5px;
  background: rgba(0, 0, 0, 0.5);
  margin: 3px auto 0;
  border: 1px solid rgba(126, 224, 106, 0.4);
}

#comboBar {
  height: 100%;
  width: 100%;
  background: var(--green);
}

#hudTR {
  position: absolute;
  top: 12px;
  right: 14px;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.iconbtn {
  width: 46px;
  height: 46px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--cream);
  font-size: 19px;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}

.iconbtn:active {
  transform: scale(0.92);
}

#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 30px;
  height: 30px;
}

#crosshair .dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px;
  border-radius: 50%;
  background: var(--cream);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.9);
}

#chRing {
  position: absolute;
  inset: 0;
  border: 2px solid rgba(245, 234, 214, 0.75);
  border-radius: 50%;
}

#chRing.fire {
  animation: chf 0.13s ease;
}

@keyframes chf {
  0% { transform: scale(1.7); border-color: var(--orange2); }
  100% { transform: scale(1); }
}

#lockHint {
  position: absolute;
  left: 50%;
  top: 62%;
  transform: translateX(-50%);
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--orange2);
  text-shadow: 0 2px 6px #000;
  display: none;
  animation: blink 1s infinite;
}

@keyframes blink {
  50% { opacity: 0.35; }
}

/* ---------- banners & popups ---------- */
#banner {
  position: fixed;
  left: 50%;
  top: 26%;
  transform: translateX(-50%);
  z-index: 6;
  pointer-events: none;
  font-family: var(--font-display);
  font-size: clamp(26px, 6vw, 52px);
  color: var(--cream);
  white-space: nowrap;
  text-shadow: 0 0 24px rgba(255, 123, 51, 0.8), 0 4px 0 rgba(0, 0, 0, 0.7);
  opacity: 0;
}

#banner.show {
  animation: bannerIn 2.3s ease forwards;
}

@keyframes bannerIn {
  0% { opacity: 0; transform: translateX(-50%) scale(0.5); }
  12% { opacity: 1; transform: translateX(-50%) scale(1.1); }
  20% { transform: translateX(-50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

#streak {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translateX(-50%);
  z-index: 6;
  pointer-events: none;
  font-family: var(--font-display);
  font-size: clamp(18px, 4vw, 30px);
  color: var(--green);
  white-space: nowrap;
  text-shadow: 0 0 18px rgba(126, 224, 106, 0.9), 0 3px 0 rgba(0, 0, 0, 0.7);
  opacity: 0;
}

#streak.show {
  animation: streakIn 1.3s ease forwards;
}

@keyframes streakIn {
  0% { opacity: 0; transform: translateX(-50%) scale(0.4); }
  18% { opacity: 1; transform: translateX(-50%) scale(1.15); }
  30% { transform: translateX(-50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

#popups {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  overflow: hidden;
}

.pop {
  position: absolute;
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--cream);
  text-shadow: 0 0 8px rgba(255, 180, 87, 0.8), 0 2px 0 #000;
  transform: translate(-50%, -50%);
  will-change: transform, opacity;
  opacity: 0;
}

.pop.big {
  font-size: 24px;
  color: var(--orange2);
}

.pop.heal {
  color: var(--green);
}

/* ---------- touch controls ---------- */
#touchUI {
  display: none;
}

body.touch[data-state="play"] #touchUI {
  display: block;
}

#zoneL {
  position: fixed;
  left: 0;
  top: 0;
  width: 46%;
  height: 100%;
  z-index: 7;
}

#zoneR {
  position: fixed;
  right: 0;
  top: 0;
  width: 54%;
  height: 100%;
  z-index: 7;
}

.stick {
  position: fixed;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  z-index: 8;
  pointer-events: none;
  border: 2px solid rgba(245, 234, 214, 0.3);
  background: rgba(255, 255, 255, 0.05);
  display: none;
}

.stick .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(255, 123, 51, 0.4);
  border: 2px solid rgba(255, 180, 87, 0.7);
}

#btnDash {
  position: fixed;
  right: calc(20px + env(safe-area-inset-right));
  bottom: calc(190px + env(safe-area-inset-bottom));
  z-index: 9;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: rgba(255, 123, 51, 0.22);
  border: 2px solid var(--line);
  color: var(--cream);
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 1px;
}

#btnDash:active {
  background: rgba(255, 123, 51, 0.5);
  transform: scale(0.93);
}

body:not(.touch) #btnDash {
  display: none;
}

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  padding: 20px;
  background: radial-gradient(ellipse at 50% 30%, rgba(60, 25, 80, 0.55), rgba(8, 4, 18, 0.92) 75%);
}

body[data-state="menu"] #startScreen { display: flex; }
body[data-state="pause"] #pauseScreen { display: flex; }
body[data-state="over"] #overScreen { display: flex; }

.title {
  font-family: var(--font-display);
  font-size: clamp(42px, 10vw, 96px);
  line-height: 0.95;
  background: linear-gradient(180deg, var(--orange2), var(--orange) 55%, #c22f2f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 26px rgba(255, 90, 30, 0.45)) drop-shadow(0 5px 0 rgba(0, 0, 0, 0.6));
  animation: flick 4s infinite;
}

@keyframes flick {
  0%, 100% { opacity: 1; }
  92% { opacity: 1; }
  93% { opacity: 0.5; }
  94% { opacity: 1; }
  97% { opacity: 0.65; }
  98% { opacity: 1; }
}

.subtitle {
  letter-spacing: 6px;
  font-weight: 700;
  color: var(--green);
  font-size: clamp(11px, 2.4vw, 15px);
  text-shadow: 0 0 12px rgba(126, 224, 106, 0.6);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px 22px;
  max-width: min(480px, 92vw);
  clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
}

.panel h3 {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--orange2);
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.ctrls {
  display: grid;
  grid-template-columns: auto auto;
  gap: 4px 16px;
  font-size: 13px;
  text-align: left;
}

.ctrls b {
  color: var(--orange2);
  font-weight: 700;
  text-align: right;
}

body.touch .ctrl-desktop { display: none; }
body:not(.touch) .ctrl-touch { display: none; }

.btn {
  font-family: var(--font-display);
  font-size: clamp(16px, 3vw, 21px);
  letter-spacing: 2px;
  color: #1a0e08;
  background: linear-gradient(180deg, var(--orange2), var(--orange));
  border: none;
  padding: 15px 44px;
  clip-path: polygon(12px 0, 100% 0, calc(100% - 12px) 100%, 0 100%);
  box-shadow: 0 0 30px rgba(255, 123, 51, 0.35);
  transition: transform 0.1s;
}

.btn:hover { transform: scale(1.05); }
.btn:active { transform: scale(0.95); }

.btn.ghost {
  background: transparent;
  color: var(--cream);
  border: 1px solid var(--line);
  box-shadow: none;
  font-size: 14px;
  padding: 11px 30px;
}

.hslist {
  list-style: none;
  min-width: min(300px, 74vw);
  font-size: 14px;
}

.hslist li {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 4px 8px;
  letter-spacing: 1px;
}

.hslist li:nth-child(odd) { background: rgba(255, 255, 255, 0.04); }
.hslist li.you { color: var(--green); text-shadow: 0 0 8px rgba(126, 224, 106, 0.6); }
.hslist .rank { color: var(--orange2); font-weight: 700; margin-right: 10px; }
.hsempty { opacity: 0.5; letter-spacing: 2px; font-size: 13px; padding: 6px; }

.bigscore {
  font-family: var(--font-display);
  font-size: clamp(38px, 9vw, 64px);
  color: var(--cream);
  text-shadow: 0 0 22px rgba(255, 123, 51, 0.7), 0 4px 0 rgba(0, 0, 0, 0.6);
}

.statrow {
  display: flex;
  gap: 26px;
  justify-content: center;
  font-size: 13px;
  letter-spacing: 2px;
}

.statrow b {
  display: block;
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--orange2);
}

#hsEntry {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

#hsName {
  width: 92px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--green);
  color: var(--green);
  font-family: var(--font-display);
  font-size: 20px;
  text-align: center;
  padding: 8px;
  letter-spacing: 4px;
  text-transform: uppercase;
  outline: none;
}

.newbest {
  color: var(--green);
  font-family: var(--font-display);
  letter-spacing: 2px;
  font-size: clamp(14px, 3vw, 19px);
  text-shadow: 0 0 14px rgba(126, 224, 106, 0.8);
  animation: blink 1s infinite;
}

.hint {
  font-size: 11px;
  letter-spacing: 2px;
  opacity: 0.55;
}

#loadErr {
  position: fixed;
  inset: 0;
  z-index: 99;
  display: none;
  align-items: center;
  justify-content: center;
  background: #0d0718;
  color: var(--cream);
  font-size: 15px;
  padding: 30px;
  text-align: center;
}

/* ================= WEAPON BAR & SCOPE OVERLAY ================= */
#weaponBar {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  background: rgba(10, 6, 20, 0.88);
  border: 1px solid var(--line);
  padding: 4px 6px;
  border-radius: 4px;
  backdrop-filter: blur(8px);
  pointer-events: auto;
  z-index: 12;
}

.wslot {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  height: 26px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  transition: all 0.12s ease;
  user-select: none;
  border-radius: 3px;
}

.wslot:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.wslot.active {
  background: rgba(255, 180, 87, 0.22);
  border-color: var(--amber);
  color: var(--amber);
  box-shadow: 0 0 10px rgba(255, 180, 87, 0.4);
}

.wslot.locked {
  opacity: 0.45;
  background: rgba(0, 0, 0, 0.35);
  border-color: rgba(255, 255, 255, 0.05);
  cursor: not-allowed;
}

.wslot.locked:hover {
  background: rgba(0, 0, 0, 0.35);
  color: rgba(255, 255, 255, 0.55);
}

.wslot.locked .num {
  color: #888;
}

.wslot.locked .name {
  color: #aaa;
  font-size: 8px;
}

.wslot .num {
  font-size: 10px;
  font-family: var(--font-ui);
  font-weight: 700;
  color: var(--amber);
  opacity: 0.9;
}

.wslot .name {
  font-size: 9px;
  font-family: var(--font-display);
  letter-spacing: 0.5px;
  white-space: nowrap;
}

#scopeOverlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  display: none;
  background: radial-gradient(circle at center, transparent 30%, rgba(0,0,0,0.85) 60%, rgba(0,0,0,0.98) 100%);
  box-shadow: inset 0 0 120px #000;
}

#scopeOverlay::before, #scopeOverlay::after {
  content: '';
  position: absolute;
  background: rgba(255, 50, 50, 0.7);
}

#scopeOverlay::before {
  top: 0; bottom: 0; left: 50%; width: 1px; transform: translateX(-50%);
}

#scopeOverlay::after {
  left: 0; right: 0; top: 50%; height: 1px; transform: translateY(-50%);
}

@media (max-width: 768px) {
  #weaponBar {
    bottom: 74px;
    gap: 3px;
    padding: 3px 4px;
    max-width: 96vw;
    overflow-x: auto;
  }
  .wslot {
    padding: 2px 5px;
    height: 24px;
  }
  .wslot .num { font-size: 9px; }
  .wslot .name { font-size: 8px; }
}
