:root {
  --bg: #1b1530;
  --panel: rgba(22, 18, 40, 0.88);
  --accent: #8e44ff;
  --accent-2: #ffb347;
  --text: #f4f1ff;
  --muted: #a9a2c4;
  --health: #4cd964;
  --armor: #3fa9ff;
  --danger: #ff4d4f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

button {
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
}
button:hover { background: rgba(255, 255, 255, 0.16); }
button.primary {
  background: linear-gradient(135deg, var(--accent), #c06cff);
  border: none;
  font-weight: 700;
}
button.primary:hover { filter: brightness(1.1); }

input {
  font: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding: 10px 14px;
  min-width: 0;
  user-select: text;
  -webkit-user-select: text;
}

.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; font-size: 14px; }
.hidden { display: none !important; }

/* ---------- Écrans ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(27, 21, 48, 0.35), rgba(27, 21, 48, 0.85));
  overflow-y: auto;
  z-index: 20;
  touch-action: pan-y;
}
.screen.visible { display: flex; }

.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 28px;
  width: min(920px, 100%);
  max-height: 100%;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
}
.panel.small {
  width: min(440px, 100%);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel h2 { margin: 0 0 8px; }

h1 {
  margin: 0;
  font-size: clamp(40px, 9vw, 72px);
  letter-spacing: 4px;
  font-weight: 900;
  line-height: 1;
}
h1 span { color: var(--accent-2); }
.tagline { margin: 6px 0 20px; color: var(--muted); }

label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row input { flex: 1; }

.columns {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 28px;
  margin-top: 18px;
}
@media (max-width: 720px) {
  .columns { grid-template-columns: 1fr; }
  .panel { padding: 20px; }
}

.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tabs button { padding: 4px 12px; font-size: 13px; }
.tabs button.active { background: var(--accent); border-color: var(--accent); }

.leaderboard { width: 100%; border-collapse: collapse; font-size: 14px; }
.leaderboard th, .leaderboard td { padding: 6px 4px; text-align: left; }
.leaderboard th { color: var(--muted); font-weight: 600; border-bottom: 1px solid rgba(255, 255, 255, 0.12); }
.leaderboard td:nth-child(n + 3), .leaderboard th:nth-child(n + 3) { text-align: right; }
.leaderboard tbody tr:nth-child(1) td:nth-child(2) { color: #ffd700; font-weight: 700; }
.leaderboard tbody tr:nth-child(2) td:nth-child(2) { color: #d7d7d7; font-weight: 700; }
.leaderboard tbody tr:nth-child(3) td:nth-child(2) { color: #e0a060; font-weight: 700; }
.leaderboard td:nth-child(2) { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.keys { list-style: none; padding: 0; margin: 0 0 12px; line-height: 2; font-size: 14px; }
kbd {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 12px;
  font-family: inherit;
}
.touch-only { display: none; }
body.touch .touch-only { display: block; }
body.touch .desktop-only { display: none; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0; }
.stats div { background: rgba(255, 255, 255, 0.06); border-radius: 10px; padding: 10px 4px; }
.stats strong { display: block; font-size: 22px; }
.stats span { font-size: 12px; color: var(--muted); }

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

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7); }

.hud-top-left {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  display: flex;
  gap: 8px;
}
.pill {
  background: rgba(0, 0, 0, 0.45);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 700;
  font-size: 18px;
  display: flex;
  gap: 6px;
  align-items: center;
}
.pill-icon { font-size: 15px; }

.hud-zone {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.45);
  border-radius: 999px;
  padding: 6px 16px;
  font-weight: 600;
  white-space: nowrap;
}

.hud-top-right {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
#hud-minimap {
  width: 180px;
  height: 180px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: #000;
}
#hud-feed { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; font-size: 13px; }
.feed-row { background: rgba(0, 0, 0, 0.45); padding: 3px 10px; border-radius: 6px; }
.feed-row.mine { background: rgba(142, 68, 255, 0.7); }

#hud-crosshair {
  --gap: 6px;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
}
#hud-crosshair i {
  position: absolute;
  background: #fff;
  box-shadow: 0 0 2px #000;
}
#hud-crosshair i:nth-child(1) { width: 2px; height: 8px; left: -1px; bottom: var(--gap); }
#hud-crosshair i:nth-child(2) { width: 2px; height: 8px; left: -1px; top: var(--gap); }
#hud-crosshair i:nth-child(3) { width: 8px; height: 2px; top: -1px; right: var(--gap); }
#hud-crosshair i:nth-child(4) { width: 8px; height: 2px; top: -1px; left: var(--gap); }

#hud-hitmarker {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  opacity: 0;
  background:
    linear-gradient(45deg, transparent 45%, #fff 45%, #fff 55%, transparent 55%),
    linear-gradient(-45deg, transparent 45%, #fff 45%, #fff 55%, transparent 55%);
  -webkit-mask: radial-gradient(circle, transparent 5px, #000 6px);
  mask: radial-gradient(circle, transparent 5px, #000 6px);
}
#hud-hitmarker.head {
  background:
    linear-gradient(45deg, transparent 45%, var(--accent-2) 45%, var(--accent-2) 55%, transparent 55%),
    linear-gradient(-45deg, transparent 45%, var(--accent-2) 45%, var(--accent-2) 55%, transparent 55%);
}
#hud-hitmarker.kill {
  background:
    linear-gradient(45deg, transparent 42%, var(--danger) 42%, var(--danger) 58%, transparent 58%),
    linear-gradient(-45deg, transparent 42%, var(--danger) 42%, var(--danger) 58%, transparent 58%);
}
#hud-hitmarker.show { animation: hit 0.25s ease-out; }
@keyframes hit { from { opacity: 1; transform: scale(1.3); } to { opacity: 0; transform: scale(1); } }

#hud-prompt {
  position: absolute;
  left: 50%;
  top: 62%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 14px;
  border-radius: 8px;
  display: none;
  white-space: nowrap;
}
#hud-prompt.visible { display: block; }

#hud-announce {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  font-size: clamp(18px, 3vw, 28px);
  font-weight: 800;
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s;
  width: 90%;
}
#hud-announce.visible { opacity: 1; }

#hud-action {
  position: absolute;
  left: 50%;
  top: 56%;
  transform: translateX(-50%);
  text-align: center;
  font-size: 13px;
  display: none;
}
#hud-action.visible { display: block; }
#hud-action .bar { width: 140px; height: 5px; background: rgba(0, 0, 0, 0.5); border-radius: 3px; margin-top: 4px; overflow: hidden; }
#hud-action-bar { height: 100%; background: #fff; width: 0; }

.hud-bottom {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  gap: 14px;
}
.bars { display: flex; flex-direction: column; gap: 4px; width: 240px; }
.bars .bar {
  position: relative;
  height: 18px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 5px;
  overflow: hidden;
}
.bars .bar.armor { height: 12px; }
.bars .bar div { height: 100%; transition: width 0.15s; }
.bars .health div { background: var(--health); }
.bars .armor div { background: var(--armor); }
.bars .bar span { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); font-size: 12px; font-weight: 700; }
.medkits { background: rgba(0, 0, 0, 0.45); border-radius: 8px; padding: 6px 10px; font-weight: 700; color: #ff8a80; }
.slots { display: flex; gap: 6px; }
.slot {
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 4px 10px;
  min-width: 120px;
  display: flex;
  flex-direction: column;
}
.slot.active { border-color: var(--accent-2); background: rgba(0, 0, 0, 0.6); }
.slot.empty { opacity: 0.55; }
.slot-name { font-size: 12px; color: var(--muted); }
.slot-ammo { font-size: 18px; font-weight: 800; }

#hud-damage {
  position: absolute;
  inset: 0;
  opacity: 0;
  box-shadow: inset 0 0 120px rgba(255, 0, 0, 0.8);
}
#hud-damage.show { animation: dmg 0.45s ease-out; }
@keyframes dmg { from { opacity: 1; } to { opacity: 0; } }

#hud-storm {
  position: absolute;
  inset: 0;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  font-weight: 800;
  font-size: 20px;
  color: #e6d4ff;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(110, 40, 200, 0.45));
}
#hud-storm.visible { display: flex; }

#hud-scope {
  position: absolute;
  inset: 0;
  display: none;
  background:
    linear-gradient(#000, #000) center / 2px 100% no-repeat,
    linear-gradient(#000, #000) center / 100% 2px no-repeat,
    radial-gradient(circle at center, transparent 0, transparent 34vmin, #000 34.3vmin);
}
#hud-scope.visible { display: block; }

/* ---------- Contrôles tactiles ---------- */

#touch { display: none; }
#hud:not(.hidden) ~ #touch.active { display: block; }
.touch-zone { position: fixed; inset: 0; z-index: 11; }
.joy-base {
  position: fixed;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.35);
  display: none;
  z-index: 12;
  pointer-events: none;
}
.joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  transform: translate(-50%, -50%);
}
.tbtn {
  position: fixed;
  z-index: 13;
  width: 56px;
  height: 56px;
  padding: 0;
  border-radius: 50%;
  font-size: 22px;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.4);
  touch-action: none;
}
.tbtn.pressed { background: rgba(142, 68, 255, 0.7); }
.tbtn.fire { width: 84px; height: 84px; right: 24px; bottom: 96px; font-size: 32px; }
.tbtn.jump { right: 120px; bottom: 20px; }
.tbtn.reload { right: 186px; bottom: 66px; }
.tbtn.aim { right: 120px; bottom: 150px; }
.tbtn.swap { right: 196px; bottom: 140px; }
.tbtn.heal { right: 30px; bottom: 20px; }
.tbtn.interact { right: 50%; bottom: 34%; transform: translateX(50%); display: none; }
.tbtn.interact.available { display: block; }
.tbtn.pause { left: 50%; top: 52px; transform: translateX(-50%); width: 40px; height: 40px; font-size: 14px; }

body.touch #hud-minimap { width: 120px; height: 120px; }
body.touch .hud-bottom { left: 16px; transform: none; flex-wrap: wrap; max-width: 55vw; }
body.touch .bars { width: 180px; }
body.touch .slot { min-width: 90px; }
body.touch #hud-crosshair, body.touch #hud-hitmarker { pointer-events: none; }

@media (max-width: 720px) {
  .hud-zone { top: 60px; font-size: 13px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Salon et spectateur ---------- */

.lobby-players {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.lobby-players li {
  background: rgba(142, 68, 255, 0.35);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 14px;
}

#spectate {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 15;
  display: none;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border-radius: 12px;
  padding: 8px 12px;
  white-space: nowrap;
}
#spectate.visible { display: flex; }
#spectate button { padding: 6px 12px; }
