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

:root {
  --bg: #0f172a;
  --card: #1e293b;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --text: #e2e8f0;
  --muted: #94a3b8;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.hidden { display: none !important; }

/* ---------- Lobby ---------- */
.lobby {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
  background: radial-gradient(ellipse at top, #1e293b, #0f172a 70%);
}

.lobby-card {
  width: 100%;
  max-width: 520px;
  background: var(--card);
  border: 1px solid #334155;
  border-radius: 16px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  margin: auto;
}

.lobby-card h1 { font-size: 26px; margin-bottom: 10px; }
.lobby-card .lore {
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.55;
  margin-bottom: 18px;
  font-style: italic;
}
.lobby-card .hint { font-size: 12px; color: var(--muted); margin-top: 14px; }
.lobby-card .version-tag { font-size: 11px; color: var(--muted); opacity: 0.6; margin-top: 8px; text-align: center; }


.lobby-card input {
  width: 100%;
  padding: 13px 16px;
  font-size: 16px;
  border-radius: 10px;
  border: 1px solid #475569;
  background: #0f172a;
  color: var(--text);
  outline: none;
  margin-bottom: 14px;
}
.lobby-card input:focus { border-color: var(--accent); }

/* Grille des métiers */
.job-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.job-card {
  background: #0f172a;
  border: 2px solid #334155;
  border-radius: 10px;
  padding: 10px 8px;
  cursor: pointer;
  text-align: left;
  transition: border-color .12s, transform .12s;
}
.job-card:hover { transform: translateY(-1px); }
.job-card.selected { border-color: var(--accent); background: rgba(99,102,241,.1); }
.job-card .job-head { font-size: 14px; font-weight: 700; margin-bottom: 3px; }
.job-card .job-salary { font-size: 11px; color: #4ade80; margin-bottom: 3px; }
.job-card .job-desc { font-size: 10.5px; color: var(--muted); line-height: 1.35; }

#join-btn {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: background .15s;
}
#join-btn:hover { background: var(--accent-hover); }
#join-btn:disabled { opacity: .6; cursor: wait; }

/* ---------- Jeu ---------- */
.game { position: fixed; inset: 0; }
#canvas { display: block; width: 100%; height: 100%; }

/* HUD */
.hud-top {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  z-index: 10;
}

.hud-pill {
  background: rgba(15, 23, 42, .8);
  backdrop-filter: blur(8px);
  border: 1px solid #334155;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.hud-money { color: #4ade80; }

.hud-btn { pointer-events: auto; cursor: pointer; font-size: 16px; }
#mute-btn { margin-left: auto; }
.hud-btn.muted { background: rgba(239, 68, 68, .85); border-color: #ef4444; }

/* Boutons taxi */
.taxi-action {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(100px + env(safe-area-inset-top));
  z-index: 15;
  pointer-events: auto;
  background: rgba(234, 179, 8, .9);
  border-color: #eab308;
  color: #111827;
}
#taxi-exit-btn { top: calc(145px + env(safe-area-inset-top)); }

.vehicle-action {
  position: fixed;
  top: calc(190px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  background: rgba(59, 130, 246, 0.9);
  border-color: #60a5fa;
  font-weight: 700;
}

/* Boutons crime (braquage / incarcérer) */
.crime-action {
  position: fixed;
  top: calc(235px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  background: rgba(220, 38, 38, 0.9);
  border-color: #f87171;
  font-weight: 700;
}
#jail-btn { top: calc(280px + env(safe-area-inset-top)); background: rgba(168, 85, 247, 0.9); border-color: #c084fc; }

/* Étoiles wanted dans le HUD */
.hud-wanted {
  background: rgba(220, 38, 38, .85);
  border-color: #f87171;
  animation: wantedPulse 1s infinite alternate;
}
@keyframes wantedPulse { from { box-shadow: 0 0 0 rgba(239,68,68,.6); } to { box-shadow: 0 0 14px rgba(239,68,68,.8); } }

/* Écran prison */
.jail-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: repeating-linear-gradient(
    90deg,
    rgba(0,0,0,.75) 0 40px,
    rgba(15,23,42,.35) 40px 90px
  );
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.jail-box {
  background: rgba(15,23,42,.92);
  border: 2px solid #64748b;
  border-radius: 16px;
  padding: 24px 40px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.7);
}
.jail-icon { font-size: 42px; }
.jail-title { font-size: 22px; font-weight: 800; letter-spacing: 3px; color: #f8fafc; margin: 6px 0; }
.jail-timer { font-size: 34px; font-weight: 800; color: #fbbf24; font-variant-numeric: tabular-nums; }
.jail-hint { font-size: 12px; color: var(--muted); margin-top: 8px; }



/* Annonces */
.announce {
  position: fixed;
  top: calc(56px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(600px, calc(100% - 30px));
  background: rgba(99,102,241,.92);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  z-index: 20;
  animation: slideDown .25s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
@keyframes slideDown { from { opacity: 0; transform: translate(-50%, -12px); } }

/* Panneau mission */
.mission-panel {
  position: fixed;
  top: calc(56px + env(safe-area-inset-top));
  right: 10px;
  width: 250px;
  z-index: 9;
}

.mission-request {
  width: 100%;
  padding: 10px;
  border: 1px solid #334155;
  border-radius: 10px;
  background: rgba(15,23,42,.85);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.mission-request:hover { border-color: var(--accent); }

.mission-card {
  margin-top: 6px;
  background: rgba(15,23,42,.9);
  backdrop-filter: blur(8px);
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px;
}
.mission-title { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.mission-desc { font-size: 12px; color: var(--muted); line-height: 1.4; margin-bottom: 8px; }
.mission-status { font-size: 12px; font-weight: 600; color: #fbbf24; margin-bottom: 6px; }
.mission-bar {
  height: 8px;
  background: #1e293b;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}
.mission-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6366f1, #4ade80);
  border-radius: 999px;
  transition: width .4s;
}
.mission-abandon {
  width: 100%;
  padding: 6px;
  border: none;
  border-radius: 8px;
  background: rgba(239,68,68,.2);
  color: #fca5a5;
  font-size: 12px;
  cursor: pointer;
}

/* Toasts */
.toasts {
  position: fixed;
  bottom: calc(190px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  z-index: 30;
  pointer-events: none;
  width: min(420px, calc(100% - 30px));
}
.toast {
  background: rgba(15,23,42,.92);
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  animation: slideDown .2s ease;
  text-align: center;
}

/* Menu joueur */
.player-menu {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--card);
  border: 1px solid #475569;
  border-radius: 14px;
  padding: 16px;
  z-index: 40;
  width: 240px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.player-menu-name { font-size: 15px; font-weight: 700; text-align: center; margin-bottom: 4px; }
#player-menu-btns { display: flex; flex-direction: column; gap: 8px; }
.player-menu button {

  padding: 10px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: #0f172a;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.player-menu button:hover { border-color: var(--accent); }

/* Inventaire */
.inv-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--card);
  border: 1px solid #475569;
  border-radius: 14px;
  padding: 18px;
  z-index: 40;
  width: min(400px, calc(100% - 30px));
  max-height: 75vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.inv-panel h3 { margin-bottom: 12px; text-align: center; }
.inv-empty { font-size: 12.5px; color: var(--muted); text-align: center; padding: 8px 0; }
.inv-subtitle { font-size: 13px; font-weight: 700; margin: 12px 0 6px; color: var(--muted); }
.inv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #0f172a;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  margin-bottom: 6px;
}
.inv-row .inv-name { flex: 1; }
.inv-row .inv-name small { color: var(--muted); }
.inv-row button {
  padding: 6px 12px;
  border: 1px solid #334155;
  border-radius: 7px;
  background: #1e293b;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.inv-row button:hover { border-color: var(--accent); }
#inv-close {
  width: 100%;
  padding: 9px;
  margin-top: 8px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

/* Modale offre */
.offer-modal {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  background: var(--card);
  border: 2px solid var(--accent);
  border-radius: 14px;
  padding: 20px;
  z-index: 50;
  width: min(340px, calc(100% - 30px));
  box-shadow: 0 20px 60px rgba(0,0,0,.7);
  text-align: center;
}
.offer-modal p { font-size: 14px; line-height: 1.5; margin-bottom: 14px; }
.offer-btns { display: flex; gap: 10px; }
.offer-btns button {
  flex: 1;
  padding: 11px;
  border: none;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
#offer-accept { background: #16a34a; color: white; }
#offer-decline { background: #334155; color: var(--text); }

/* Panneau admin */

.admin-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--card);
  border: 1px solid #475569;
  border-radius: 14px;
  padding: 18px;
  z-index: 40;
  width: min(420px, calc(100% - 30px));
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.admin-panel h3 { margin-bottom: 12px; text-align: center; }
.admin-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.admin-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #0f172a;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}
.admin-row .ar-name { font-weight: 700; flex: 1; }
.admin-row select {
  background: #1e293b;
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
}
.admin-hint { font-size: 11px; color: var(--muted); margin-bottom: 10px; line-height: 1.5; }
#admin-close {
  width: 100%;
  padding: 9px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

/* Chat */
.chat {
  position: fixed;
  left: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: min(360px, calc(100% - 20px));
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}

.chat-log {
  max-height: 140px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  mask-image: linear-gradient(to bottom, transparent, black 20%);
}

.chat-line {
  background: rgba(15, 23, 42, .75);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  line-height: 1.35;
  word-wrap: break-word;
  animation: fadeIn .2s ease;
}
.chat-line .who { font-weight: 700; }
.chat-line.me-action { font-style: italic; color: #c4b5fd; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } }

.chat-form { display: flex; gap: 6px; }

.chat-form input {
  flex: 1;
  padding: 10px 14px;
  font-size: 14px;
  border-radius: 999px;
  border: 1px solid #334155;
  background: rgba(15, 23, 42, .85);
  color: var(--text);
  outline: none;
}
.chat-form input:focus { border-color: var(--accent); }

.chat-form button {
  width: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 15px;
  cursor: pointer;
}

/* Joystick mobile */
.joystick {
  position: fixed;
  right: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(148, 163, 184, .12);
  border: 2px solid rgba(148, 163, 184, .3);
  display: none;
  z-index: 6;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(99, 102, 241, .85);
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
}

/* ---------- Boutons contextuels (entrer / boutique / planter / tirer) ---------- */
.ctx-btns {
  position: fixed;
  right: 12px;
  top: 110px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 7;
  align-items: flex-end;
}

.ctx-btn {
  border: 1px solid #475569;
  background: rgba(15, 23, 42, .88);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
.ctx-btn:active { transform: scale(.96); }

.ctx-btn.danger {
  background: rgba(153, 27, 27, .92);
  border-color: #ef4444;
  animation: pulse-danger 1.4s infinite;
}

@keyframes pulse-danger {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .5); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* ---------- HUD combat (PV / arme) ---------- */
.combat-hud {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(58px + env(safe-area-inset-top));
  background: rgba(15, 23, 42, .85);
  border: 1px solid #334155;
  border-radius: 14px;
  padding: 8px 14px;
  font-size: 14px;
  z-index: 6;
  pointer-events: none;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 200px;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
.ch-row { display: flex; align-items: center; gap: 8px; }
.ch-row.ch-sub { justify-content: center; gap: 10px; }
.ch-hp-ico { font-size: 15px; }
.ch-bar {
  flex: 1;
  height: 10px;
  background: rgba(255,255,255,.12);
  border-radius: 999px;
  overflow: hidden;
}
.ch-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .3s ease, background .3s ease;
}
.ch-hp-txt { font-size: 12px; color: #cbd5e1; font-weight: 600; }
.ch-weapon { font-size: 12.5px; font-weight: 600; }
.ch-weapon.ch-none { color: #94a3b8; }
.ch-weapon.ch-armed { color: #fbbf24; }
.ch-armor { font-size: 12.5px; color: #7dd3fc; font-weight: 600; }

.ctx-btn.info { pointer-events: none; opacity: .95; }


/* Sur écran tactile : montrer le joystick, adapter le chat + missions */
@media (pointer: coarse) {
  .joystick { display: block; }
  .chat { width: min(300px, calc(100% - 170px)); }
  .chat-log { max-height: 100px; }
  .mission-panel { width: 210px; }
  .ctx-btns { top: auto; bottom: calc(170px + env(safe-area-inset-bottom)); }
  .combat-hud { font-size: 12.5px; }
}
