:root {
  --bg: #0f1020;
  --panel: #1a1c33;
  --panel-2: #23264a;
  --accent: #ff5d8f;
  --accent-2: #5dd2ff;
  --text: #e8e9f3;
  --muted: #9aa0c0;
  --ok: #57e08a;
  --warn: #ffcc4d;
  --danger: #ff5b5b;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh; /* tient compte de la barre d'URL dynamique mobile */
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app { position: fixed; inset: 0; }

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hud-top, .hud-bottom {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.hud-bottom { justify-content: flex-end; }

.hud-pill {
  pointer-events: auto;
  background: rgba(26, 28, 51, 0.78);
  border: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(6px);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
#online-pill { color: var(--ok); }
a.hud-pill { text-decoration: none; color: var(--accent-2); }
a.hud-pill:hover { background: var(--panel-2); }

.hud-btn {
  pointer-events: auto;
  background: rgba(26, 28, 51, 0.82);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.hud-btn:hover { background: var(--panel-2); }
.hud-btn:active { transform: scale(0.95); }

/* ---------- Touch ---------- */
.touch {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-between;
  padding: 18px;
  padding-bottom: max(18px, env(safe-area-inset-bottom));
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
  pointer-events: none;
}
.touch-dpad, .touch-actions { display: flex; gap: 10px; pointer-events: auto; }
/* Bloc d'actions à droite : 5 boutons sur 2-3 colonnes propres. */
.touch-actions { flex-wrap: wrap; justify-content: flex-end; max-width: 222px; }
/* Sur écran tactile, on remonte le HUD bas pour qu'il ne soit jamais SOUS les contrôles. */
@media (pointer: coarse) {
  .hud { padding-bottom: calc(168px + env(safe-area-inset-bottom)); }
}
@media (orientation: landscape) and (pointer: coarse) {
  .hud { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
  .touch-actions { max-width: 222px; }
}
.t-btn {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(35, 38, 74, 0.85);
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  user-select: none;
}
.t-grab    { background: rgba(255, 93, 143, 0.3); }
.t-lasso   { background: rgba(232, 200, 115, 0.32); }   /* corde dorée */
.t-special { background: rgba(93, 210, 255, 0.30); }    /* éclair cyan */
.t-punch   { background: rgba(255, 138, 93, 0.30); }    /* coup orange */
.t-btn:active { background: var(--accent); transform: scale(0.92); }
@media (max-width: 480px) {
  .t-btn { width: 56px; height: 56px; font-size: 19px; }
  .touch-actions { max-width: 200px; }
}

/* ---------- Modales ---------- */
.modal-root {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 6, 16, 0.72);
  backdrop-filter: blur(3px);
}
.modal {
  position: relative;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 22px;
  width: min(560px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.modal h2 { margin: 0 0 4px; font-size: 22px; }
.modal h3 { margin: 18px 0 8px; font-size: 15px; color: var(--accent-2); }
.modal p.sub { margin: 0 0 16px; color: var(--muted); font-size: 14px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input[type=text], .field textarea, .field input[type=file] {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}
.field textarea { resize: vertical; min-height: 70px; }

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn.secondary { background: var(--panel-2); color: var(--text); }
.btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,0.15); }
.btn:active { transform: scale(0.97); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.badge.quarantine { background: rgba(255,204,77,0.18); color: var(--warn); }
.badge.ok { background: rgba(87,224,138,0.18); color: var(--ok); }
.badge.ruin { background: rgba(255,91,91,0.18); color: var(--danger); }

.note {
  font-size: 12px;
  color: var(--muted);
  background: rgba(93,210,255,0.07);
  border-left: 3px solid var(--accent-2);
  padding: 8px 10px;
  border-radius: 6px;
  margin-top: 12px;
}

/* Musée */
.museum-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.monster-card {
  background: var(--panel-2);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}
.monster-card .emoji { font-size: 40px; }
.monster-card .sprite {
  width: 64px; height: 64px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
}
.monster-card .name { font-weight: 700; margin-top: 6px; }
.monster-card .quote { font-size: 12px; color: var(--muted); font-style: italic; margin: 6px 0; }
.monster-card .stats { font-size: 12px; color: var(--accent-2); }
.monster-card .vote { margin-top: 8px; font-size: 13px; cursor: pointer; }

.ugc-preview {
  margin-top: 10px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
}
.ugc-preview img { width: 100%; display: block; max-height: 240px; object-fit: contain; background: #000; }

.hidden { display: none !important; }

.toast-wrap {
  position: fixed;
  bottom: 18px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
  pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.12);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toast-in .25s ease;
}
.toast.ok { border-color: var(--ok); }
.toast.warn { border-color: var(--warn); }
.toast.danger { border-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; } }

kbd {
  background: var(--panel-2);
  border: 1px solid rgba(255,255,255,0.15);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 7px;
  font-size: 12px;
  font-family: ui-monospace, monospace;
}
