@import url("https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;700;800&family=Space+Grotesk:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap");

:root {
  --ink-900: #0d1b2a;
  --ink-800: #142838;
  --panel: #16324a;
  --panel-line: #24455f;
  --brick: #ff5a36;
  --brick-dim: #c94427;
  --volt: #3ddad7;
  --yolk: #ffd23f;
  --ok: #6cd97e;
  --text-hi: #f4f1e8;
  --text-lo: #9fb3c4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink-900);
  color: var(--text-hi);
  font-family: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#game-root { position: relative; width: 100%; height: 100vh; height: 100dvh; }
canvas#scene { display: block; width: 100%; height: 100%; touch-action: none; }

.display { font-family: "Baloo 2", "Space Grotesk", sans-serif; font-weight: 700; }
.mono { font-family: "JetBrains Mono", ui-monospace, "SF Mono", monospace; }

/* ---------- Start overlay ---------- */

#start-screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px;
  background: radial-gradient(ellipse at 50% 20%, rgba(255,90,54,0.18), transparent 55%),
              linear-gradient(180deg, var(--ink-900) 0%, #0a1520 100%);
  text-align: center; padding: 32px; z-index: 20;
}

.blockrow { display: flex; gap: 10px; }
.blockrow i { width: 22px; height: 22px; border-radius: 5px; display: inline-block; }

.brand { display: flex; flex-direction: column; gap: 6px; }
.brand .eyebrow { text-transform: uppercase; letter-spacing: 0.32em; font-size: 12px; color: var(--volt); font-weight: 600; }
.brand h1 {
  margin: 0; font-size: clamp(44px, 9vw, 96px); line-height: 0.92; letter-spacing: -0.01em;
  color: var(--text-hi); text-shadow: 6px 6px 0 var(--brick-dim); text-wrap: balance;
}
.brand h1 span { color: var(--yolk); text-shadow: 6px 6px 0 var(--brick-dim); }

.tagline { max-width: 46ch; color: var(--text-lo); font-size: 15px; line-height: 1.55; }

#name-field { display: flex; flex-direction: column; gap: 6px; align-items: center; }
#name-input {
  font-family: "JetBrains Mono", monospace; font-size: 15px; text-align: center;
  background: var(--ink-800); border: 1px solid var(--panel-line); border-radius: 8px;
  color: var(--text-hi); padding: 9px 14px; width: 220px;
}
#name-input:focus-visible { outline: 2px solid var(--volt); outline-offset: 2px; }

.rules { display: grid; grid-template-columns: repeat(3, minmax(120px, 1fr)); gap: 14px; width: min(520px, 100%); }
.rule-card { background: var(--panel); border: 1px solid var(--panel-line); border-radius: 10px; padding: 12px 10px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.rule-card .key { font-family: "JetBrains Mono", monospace; font-size: 12px; background: var(--ink-800); border: 1px solid var(--panel-line); border-radius: 6px; padding: 3px 8px; color: var(--yolk); }
.rule-card .label { font-size: 12px; color: var(--text-lo); letter-spacing: 0.02em; }

#play-btn {
  appearance: none; border: none; cursor: pointer; background: var(--brick); color: #1a0a05;
  font-family: "Baloo 2", sans-serif; font-weight: 700; font-size: 20px; padding: 14px 40px;
  border-radius: 12px; box-shadow: 0 6px 0 var(--brick-dim); transition: transform 0.08s ease;
}
#play-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#play-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 var(--brick-dim); }
#play-btn:focus-visible { outline: 3px solid var(--volt); outline-offset: 3px; }

.fine-print { color: var(--text-lo); font-size: 12px; max-width: 40ch; }

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

#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; display: none; }

#crosshair { position: absolute; top: 50%; left: 50%; width: 22px; height: 22px; transform: translate(-50%, -50%); }
#crosshair::before, #crosshair::after { content: ""; position: absolute; background: var(--text-hi); box-shadow: 0 0 0 1px rgba(0,0,0,0.4); }
#crosshair::before { left: 50%; top: 0; bottom: 0; width: 2px; transform: translateX(-50%); }
#crosshair::after { top: 50%; left: 0; right: 0; height: 2px; transform: translateY(-50%); }
#crosshair.hit::before, #crosshair.hit::after { background: var(--brick); }

.hud-panel {
  position: absolute; display: flex; align-items: center; gap: 10px;
  background: rgba(20,40,56,0.82); border: 1px solid var(--panel-line); border-radius: 10px;
  padding: 10px 16px; backdrop-filter: blur(3px);
}

#hud-health { left: max(20px, env(safe-area-inset-left)); bottom: max(20px, env(safe-area-inset-bottom)); }
#hud-ammo { right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); }
#hud-players { right: max(20px, env(safe-area-inset-right)); top: max(20px, env(safe-area-inset-top)); }
#hud-score { left: 50%; top: max(20px, env(safe-area-inset-top)); transform: translateX(-50%); flex-direction: column; gap: 2px; align-items: center; }

/* On narrow/touch screens the health, ammo, and joystick would otherwise
   stack on top of each other in the bottom corners — lift the panels clear
   of the on-screen controls. */
.is-touch #hud-health { bottom: max(150px, calc(env(safe-area-inset-bottom) + 150px)); }
.is-touch #hud-ammo { bottom: max(150px, calc(env(safe-area-inset-bottom) + 150px)); }
.is-touch #scoreboard { display: none; } /* reclaim screen space; score is still in the top pill */

.hud-label { text-transform: uppercase; font-size: 10px; letter-spacing: 0.18em; color: var(--text-lo); }
.hud-value { font-family: "JetBrains Mono", monospace; font-size: 22px; font-variant-numeric: tabular-nums; color: var(--text-hi); }

#health-bar-track { width: 110px; height: 10px; background: var(--ink-800); border-radius: 5px; overflow: hidden; border: 1px solid var(--panel-line); }
#health-bar-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--ok), #9be79f); transition: width 0.15s ease; }

#scoreboard {
  position: absolute; left: 20px; top: 20px; width: 200px;
  background: rgba(20,40,56,0.82); border: 1px solid var(--panel-line); border-radius: 10px; padding: 10px 12px;
}
.sb-title { text-transform: uppercase; font-size: 10px; letter-spacing: 0.18em; color: var(--text-lo); margin-bottom: 6px; }
.sb-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 3px 0; font-family: "JetBrains Mono", monospace; }
.sb-row .sb-name { color: var(--text-hi); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.sb-row .sb-name.me { color: var(--yolk); }
.sb-row .sb-kd { color: var(--text-lo); }

#killfeed {
  position: absolute; top: 70px; right: 20px; display: flex; flex-direction: column; gap: 4px;
  align-items: flex-end; z-index: 12;
}
.kill-line {
  background: rgba(20,40,56,0.82); border: 1px solid var(--panel-line); border-radius: 6px;
  padding: 5px 10px; font-size: 12px; font-family: "JetBrains Mono", monospace; opacity: 0;
  transform: translateX(8px); transition: opacity 0.25s ease, transform 0.25s ease;
}
.kill-line.show { opacity: 1; transform: translateX(0); }

/* ---------- End overlay ---------- */

#end-screen {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(10,18,26,0.92); z-index: 30; text-align: center;
}
#end-screen .panel { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 40px 48px; background: var(--panel); border: 1px solid var(--panel-line); border-radius: 16px; }
#end-screen h2 { margin: 0; font-family: "Baloo 2", sans-serif; font-size: 36px; color: var(--brick); }
#end-killer { margin: 0; }
#respawn-count { font-size: 34px; color: var(--yolk); }

#retry-btn {
  appearance: none; border: none; cursor: pointer; background: var(--volt); color: #062a29;
  font-family: "Baloo 2", sans-serif; font-weight: 700; font-size: 18px; padding: 12px 30px;
  border-radius: 10px; box-shadow: 0 5px 0 #1f8f8c;
}
#retry-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#retry-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #1f8f8c; }

#pointer-hint {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(20,40,56,0.82); border: 1px solid var(--panel-line); border-radius: 8px;
  padding: 8px 14px; font-size: 12px; color: var(--text-lo); z-index: 15; display: none;
}

/* Pointer lock is a desktop-mouse concept — never show the relock hint on touch. */
.is-touch #pointer-hint { display: none !important; }

/* ---------- Touch controls (phone / tablet) ---------- */

#touch-controls { position: absolute; inset: 0; z-index: 13; }

#touch-joystick {
  position: absolute;
  left: max(24px, env(safe-area-inset-left));
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 28px));
  width: 132px; height: 132px;
  border-radius: 50%;
  background: rgba(20, 40, 56, 0.55);
  border: 2px solid var(--panel-line);
  pointer-events: auto;
  touch-action: none;
}

#touch-joystick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 56px; height: 56px;
  margin-left: -28px; margin-top: -28px;
  border-radius: 50%;
  background: rgba(244, 241, 232, 0.85);
  border: 2px solid var(--brick);
  transition: transform 0.05s linear;
}

#touch-fire {
  position: absolute;
  right: max(28px, env(safe-area-inset-right));
  bottom: max(38px, calc(env(safe-area-inset-bottom) + 38px));
  width: 84px; height: 84px;
  border-radius: 50%;
  background: rgba(255, 90, 54, 0.28);
  border: 2px solid var(--brick);
  appearance: none;
  pointer-events: auto;
  touch-action: none;
}
#touch-fire::after {
  content: "";
  position: absolute; inset: 22px;
  border-radius: 50%;
  background: var(--brick);
  opacity: 0.9;
}
#touch-fire:active::after { opacity: 1; transform: scale(0.9); }

@media (prefers-reduced-motion: reduce) {
  #play-btn, #retry-btn, .kill-line, #touch-joystick-knob { transition: none; }
}
