:root {
  --bg: #f8fafc;
  --fg: #0f172a;
  --muted: #64748b;
  --panel: rgba(255, 255, 255, 0.92);
  --border: #e2e8f0;
  --accent: #2563eb;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

[hidden] { display: none !important; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  border-radius: 8px;
  padding: 6px 12px;
}

/* ---------- Accueil ---------- */

#join-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#join-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#join-form h1 { margin: 0 0 8px; text-align: center; }
.version { margin: 0; text-align: center; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

#join-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  color: var(--muted);
}

#join-form label.color-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

#join-form input:not([type="color"]) {
  font-size: 16px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
}

#join-form button[type="submit"] {
  font-size: 16px;
  padding: 12px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.error { color: var(--err); font-size: 14px; margin: 0; }

/* ---------- Jeu ---------- */

#game-screen { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; }

#top {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
#top > * { pointer-events: auto; }

#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 14px;
  background: var(--panel);
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  font-size: 14px;
  max-width: 100%;
  white-space: nowrap;
}

#room-label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }

.status::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  background: currentColor;
}
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.err { color: var(--err); }

#topbar button { border-radius: 999px; padding: 4px 12px; }

#controls {
  position: absolute;
  right: 12px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#controls button {
  width: 44px;
  height: 44px;
  font-size: 20px;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

#player-list {
  position: absolute;
  left: 12px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 1000;
  margin: 0;
  padding: 8px 10px;
  list-style: none;
  background: var(--panel);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  font-size: 13px;
  max-height: 40vh;
  max-width: calc(100% - 92px);
  overflow-y: auto;
}

#player-list:empty { display: none; }

#player-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  cursor: pointer;
}

#player-list li.offline { opacity: 0.5; }
#player-list .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
#player-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#player-list .dist { color: var(--muted); margin-left: auto; padding-left: 8px; }

/* ---------- Marqueurs ---------- */

.player-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 4px rgba(0, 0, 0, 0.4);
}
.player-marker.me { width: 22px; height: 22px; }
.player-marker.stale { opacity: 0.45; }

.leaflet-tooltip.player-label {
  font-weight: 600;
  padding: 2px 6px;
}

/* ---------- Règles (accueil) ---------- */

.rules { font-size: 14px; color: var(--muted); }
.rules summary { cursor: pointer; }
.rules ul { padding-left: 18px; margin: 8px 0 0; line-height: 1.5; }

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

#hud {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 5px 14px;
  background: var(--panel);
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  max-width: 100%;
}
#score { font-weight: 700; }
.gps.good { color: var(--ok); }
.gps.meh { color: var(--warn); }
.gps.bad { color: var(--err); font-weight: 600; }
#bomb-state.ready { color: var(--ok); font-weight: 600; }
#bomb-state.wait { color: var(--muted); }
#bomb-state.ghost { color: #7c3aed; font-weight: 600; }

#alert {
  width: 100%;
  max-width: 420px;
  padding: 10px 14px;
  border-radius: 12px;
  color: #fff;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  font-variant-numeric: tabular-nums;
}
#alert.danger { background: var(--err); animation: pulse 0.5s ease-in-out infinite alternate; }
#alert.near { background: var(--warn); }
#alert.safe { background: var(--ok); }
#alert.ghost { background: #7c3aed; }
#alert small { display: block; font-weight: 500; opacity: 0.9; }

@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.04); } }

/* ---------- Notifications ---------- */

#toasts {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  pointer-events: none !important;
}
.toast {
  max-width: 100%;
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.88);
  color: #fff;
  font-size: 14px;
  text-align: center;
  animation: toast-in 0.2s ease-out;
  transition: opacity 0.4s;
}
.toast.good { background: rgba(22, 163, 74, 0.92); }
.toast.bad { background: rgba(220, 38, 38, 0.92); }
@keyframes toast-in { from { transform: translateY(-10px); opacity: 0; } }

/* ---------- Écran de mort ---------- */

#death {
  position: absolute;
  inset: 0;
  z-index: 1002;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(220, 38, 38, 0.45);
  animation: death-flash 0.6s ease-out;
  pointer-events: none;
}
.death-box {
  background: rgba(15, 23, 42, 0.9);
  color: #fff;
  border-radius: 16px;
  padding: 20px 28px;
  text-align: center;
}
.death-title { font-size: 28px; font-weight: 800; margin-bottom: 6px; }
@keyframes death-flash { from { background: rgba(255, 255, 255, 0.95); } }

/* ---------- Bombes ---------- */

.bomb-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  font-size: 22px;
  position: relative;
}
.bomb-icon b {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--err);
  color: #fff;
  font-size: 15px;
  border-radius: 999px;
  padding: 1px 8px;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.bomb-icon span { display: inline-block; animation: shake 0.15s linear infinite alternate; }
@keyframes shake { from { transform: rotate(-8deg); } to { transform: rotate(8deg); } }

.boom-icon {
  width: 80px;
  height: 80px;
  font-size: 56px;
  line-height: 80px;
  text-align: center;
  animation: boom 1.2s ease-out forwards;
}
@keyframes boom {
  0% { transform: scale(0.3); opacity: 1; }
  60% { transform: scale(1.4); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}

.blast-flash { animation: blast 1.2s ease-out forwards; }
@keyframes blast {
  from { fill-opacity: 0.8; stroke-opacity: 1; }
  to { fill-opacity: 0; stroke-opacity: 0; }
}

.player-marker.ghost { opacity: 0.4; outline: 2px dashed #7c3aed; outline-offset: 2px; }

#player-list .score { font-weight: 700; font-variant-numeric: tabular-nums; margin-left: 4px; }
#player-list li.me .name { font-weight: 700; }
