:root {
  --ink: #12203c;
  --gold: #ffcf4b;
  --panel: rgba(18, 32, 60, 0.82);
  --line: rgba(255, 255, 255, 0.22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a1730;
  color: #fff;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, Arial, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

/* ---------- HUD ---------- */

#hud {
  position: fixed;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: linear-gradient(rgba(8, 16, 34, 0.72), rgba(8, 16, 34, 0));
  pointer-events: none;
}

.brand {
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 2px 0 #7a4a00, 0 0 14px rgba(255, 207, 75, 0.5);
  white-space: nowrap;
}

.stats {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
  align-items: center;
  min-width: 0;
  font-size: 14px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 6px 10px;
  min-height: 36px;
  backdrop-filter: blur(3px);
}

.stat .label {
  font-size: 12px;
  opacity: 0.8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat b { font-size: 15px; }

.stat-hp .bar {
  display: block;
  width: 74px;
  height: 8px;
  border-radius: 6px;
  background: #0a1225;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.stat-hp .bar em {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #6ef58a, #37d766);
  transition: width 0.15s linear, background 0.2s linear;
}

.stat-weapon { min-width: 132px; }
#ammo { color: var(--gold); }

button {
  font-family: inherit;
  font-weight: 900;
  color: #17213a;
  background: var(--gold);
  border: 3px solid #fff7;
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
  box-shadow: 0 4px 0 #a97700;
  pointer-events: auto;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #a97700;
}

#scoreBtn { margin-left: auto; font-size: 13px; white-space: nowrap; }

#conn {
  position: fixed;
  z-index: 4;
  left: 50%;
  top: 64px;
  transform: translateX(-50%);
  background: rgba(180, 40, 40, 0.9);
  border: 2px solid #ff9a9a;
  border-radius: 10px;
  padding: 6px 14px;
  font-size: 13px;
}

/* ---------- death overlay ---------- */

#respawn {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: radial-gradient(circle at 50% 55%, rgba(120, 10, 10, 0.18), rgba(5, 8, 18, 0.55));
}

#respawn[hidden] { display: none !important; }
#conn[hidden] { display: none !important; }

.respawn-box {
  text-align: center;
  background: var(--panel);
  border: 3px solid #ff6b5e;
  border-radius: 18px;
  padding: 18px 34px 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.respawn-box .boom { font-size: 40px; }
.respawn-box h2 {
  margin: 4px 0 6px;
  letter-spacing: 4px;
  color: #ff8b7f;
  font-size: 26px;
}
.respawn-box p { margin: 4px 0; font-size: 15px; }
.respawn-box b { color: var(--gold); font-size: 18px; }
.respawn-box .hint { font-size: 12px; opacity: 0.65; }

/* ---------- scoreboard ---------- */

#scoreboard {
  position: fixed;
  inset: 0;
  z-index: 6;
  background: rgba(4, 9, 22, 0.72);
  display: grid;
  place-items: center;
  padding: 16px;
}

#scoreboard[hidden] { display: none !important; }

.board {
  position: relative;
  width: min(480px, 94vw);
  max-height: 84vh;
  overflow: auto;
  background: linear-gradient(180deg, #1d2f55, #121f3c);
  border: 3px solid var(--gold);
  border-radius: 18px;
  padding: 18px 18px 22px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
}

.board h2 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: 2px;
  color: var(--gold);
  text-align: center;
}

.board #closeBoard {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  background: #2a3f6b;
  color: #fff;
  border-color: #ffffff40;
  box-shadow: 0 3px 0 #101a30;
}

#leaders {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 14px;
}

#leaders li {
  display: grid;
  grid-template-columns: 26px 1fr auto 52px;
  align-items: center;
  gap: 8px;
  padding: 7px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

#leaders li.self {
  background: rgba(255, 207, 75, 0.16);
  border-radius: 8px;
}

#leaders .rank { opacity: 0.55; font-weight: 900; text-align: center; }
#leaders .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#leaders .kd { opacity: 0.6; font-size: 12px; }
#leaders b { color: var(--gold); text-align: right; }
#leaders .empty { display: block; opacity: 0.6; text-align: center; padding: 16px 0; }

/* ---------- mobile controls ---------- */

#mobile { display: none; }

body.touch #mobile {
  display: flex;
  position: fixed;
  z-index: 3;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 22px;
  pointer-events: none;
}

body.touch #help { display: none; }

#stickArea {
  position: relative;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.45);
  background: radial-gradient(circle at 50% 50%, rgba(120, 180, 255, 0.16), rgba(10, 24, 48, 0.5));
  pointer-events: auto;
  touch-action: none;
}

#stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  border: 3px solid #fff;
  display: grid;
  place-items: center;
  will-change: transform;
}

#stick .knob {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: inset 0 -3px 0 #b27d00;
}

.mobileButtons {
  display: flex;
  gap: 14px;
  pointer-events: auto;
}

.mobileButtons button {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  font-size: 11px;
  letter-spacing: 0.5px;
  box-shadow: 0 5px 0 #a97700;
}

#specialBtn { background: #ff9de2; box-shadow: 0 5px 0 #a5448b; }

#help {
  position: fixed;
  z-index: 2;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.78);
  text-shadow: 0 2px 3px #000;
  white-space: nowrap;
  pointer-events: none;
}

@media (max-width: 900px) {
  .brand { display: none; }
}

@media (max-width: 720px) {
  #hud { padding: 8px; gap: 8px; }
  .stats { gap: 6px; }
  .stat { padding: 4px 7px; min-height: 30px; gap: 5px; border-radius: 9px; font-size: 12px; }
  .stat .label { font-size: 10px; }
  .stat b { font-size: 13px; }
  .stat-hp .bar { width: 46px; height: 6px; }
  .stat-weapon { min-width: 0; }
  #scoreBtn { font-size: 11px; padding: 6px 8px; }
  #help { display: none; }
}

@media (max-height: 520px) {
  #stickArea { width: 110px; height: 110px; }
  .mobileButtons button { width: 66px; height: 66px; }
}

/* 16-bit arcade polish */
:root { --gold: #ffe06a; }
.brand { text-shadow: 2px 2px 0 #693d14, 0 0 18px #ffcf4b99; }
.stat, .board, .respawn-box {
  box-shadow: 0 4px 0 rgba(0,0,0,.25), 0 0 0 1px rgba(255,255,255,.08) inset, 0 10px 30px rgba(0,0,0,.22);
}
button { image-rendering: pixelated; text-shadow: 0 1px 0 #fff8; }
#help { padding: 7px 14px; border: 1px solid #ffffff30; border-radius: 8px; background: #08152acc; }
