/* ── Reset & Variables ─────────────────────────────── */
:root {
  --bg: #0d0d14;
  --panel: rgba(15, 15, 25, 0.96);
  --border: rgba(255,255,255,0.08);
  --accent: #00e5ff;
  --accent2: #ff3cac;
  --ok: #00ff88;
  --warn: #ffb700;
  --err: #ff4444;
  --text: #e8e8f0;
  --muted: #6b6b8a;
  --radius: 10px;
  --font-mono: 'Share Tech Mono', monospace;
  --font-ui: 'Exo 2', sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
  user-select: none;
}

/* ── Canvas principal ──────────────────────────────── */
canvas#canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
  cursor: crosshair;
}

/* ── Tooltip survol ────────────────────────────────── */
#tooltip {
  position: fixed;
  pointer-events: none;
  background: rgba(0,0,0,0.85);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  white-space: nowrap;
  display: none;
  z-index: 100;
  backdrop-filter: blur(4px);
  transform: translate(12px, -50%);
}

/* ── Panneau UI ────────────────────────────────────── */
#ui {
  position: fixed;
  top: 16px;
  left: 16px;
  background: var(--panel);
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 8px 40px rgba(0,0,0,0.6), 0 0 0 1px rgba(0,229,255,0.04);
  width: 230px;
  backdrop-filter: blur(12px);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { opacity:0; transform:translateX(-20px); }
  to   { opacity:1; transform:translateX(0); }
}

/* Header */
#ui-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-ui);
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 2px;
  text-transform: uppercase;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#logo-img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  image-rendering: pixelated;
}

#status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.4s;
  box-shadow: 0 0 0 0 transparent;
}
#status-dot.online {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
  animation: pulse 2s infinite;
}
#status-dot.error { background: var(--err); }

@keyframes pulse {
  0%,100% { box-shadow: 0 0 4px var(--ok); }
  50%      { box-shadow: 0 0 12px var(--ok); }
}

/* Coords */
#coords-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0,229,255,0.05);
  border: 1px solid rgba(0,229,255,0.12);
  border-radius: 7px;
  padding: 7px 10px;
  margin-bottom: 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
}

#pixel-color-info {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid var(--border);
  transition: background 0.15s;
}

/* Palette */
#picker {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
  margin-bottom: 10px;
}

#picker button {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
  padding: 0;
  margin: 0;
}

#picker button:hover {
  transform: scale(1.18);
  z-index: 2;
}

#picker button.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,229,255,0.25);
  transform: scale(1.12);
}

/* Couleur perso */
#custom-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

#custom-row label { flex: 0 0 auto; font-size: 11px; }

#customColor {
  width: 30px;
  height: 26px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  padding: 0;
  background: none;
}

#useCustom {
  flex: 1;
  padding: 5px 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 11px;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: background 0.15s;
  width: auto;
  margin: 0;
}
#useCustom:hover { background: rgba(255,255,255,0.12); }

/* Sélection affichée */
#selected-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}

#selected-preview {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid var(--border);
  transition: background 0.2s;
}

#selected-hex {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
}

/* Cooldown */
#cd-wrap { margin-bottom: 12px; }

#cd-bar {
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 6px;
}

#cd-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
  transition: width 1s linear;
}

#cd {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ok);
  padding: 7px;
  background: rgba(0,255,136,0.06);
  border: 1px solid rgba(0,255,136,0.15);
  border-radius: 7px;
  transition: all 0.3s;
}

#cd.waiting {
  color: var(--warn);
  background: rgba(255,183,0,0.07);
  border-color: rgba(255,183,0,0.2);
}

/* Actions */
#actions { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }

button {
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  color: white;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s, box-shadow 0.2s;
  letter-spacing: 0.5px;
}

button:hover:not(:disabled) { opacity: 0.88; transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: 0.35; cursor: not-allowed; }

#place {
  background: linear-gradient(135deg, #0070f3, #00bfff);
  box-shadow: 0 4px 14px rgba(0,112,243,0.35);
}

#save {
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  padding: 8px;
}
#save:hover:not(:disabled) { background: rgba(255,255,255,0.12); color: var(--text); }

/* Stats */
#stats-bar {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--font-mono);
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* ── Minimap ───────────────────────────────────────── */
#minimap {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 120px;
  height: 120px;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  image-rendering: pixelated;
  cursor: pointer;
  transition: transform 0.2s;
}
#minimap:hover { transform: scale(1.08); }

/* ── Toast notification ────────────────────────────── */
#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: rgba(15,15,25,0.96);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s;
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  white-space: nowrap;
}

#toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

#toast.ok    { border-color: rgba(0,255,136,0.4); color: var(--ok); }
#toast.error { border-color: rgba(255,68,68,0.4); color: var(--err); }
#toast.warn  { border-color: rgba(255,183,0,0.4); color: var(--warn); }

/* ── Scrollbar cachée ──────────────────────────────── */
::-webkit-scrollbar { display: none; }

/* ── Chat ──────────────────────────────────────────── */
#chat-widget {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 300px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideIn 0.3s ease;
  z-index: 50;
}

#chat-widget.collapsed #chat-messages,
#chat-widget.collapsed #chat-input-row {
  display: none;
}

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
  background: rgba(0,229,255,0.04);
  cursor: pointer;
  user-select: none;
}

#chat-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 22px;
  height: 22px;
  border-radius: 5px;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
#chat-toggle:hover { background: rgba(255,255,255,0.08); color: var(--text); }

#chat-messages {
  height: 200px;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.chat-msg {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  word-break: break-word;
  animation: msgIn 0.2s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-msg .chat-author {
  font-weight: bold;
  margin-right: 5px;
}

.chat-msg.own .chat-author { color: var(--accent); }
.chat-msg.other .chat-author { color: var(--accent2); }
.chat-msg.system { color: var(--muted); font-style: italic; text-align: center; font-size: 11px; }

.chat-msg .chat-text { color: var(--text); }
.chat-msg .chat-time { color: var(--muted); font-size: 10px; margin-left: 4px; }

#chat-input-row {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

#chat-input {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 10px;
  outline: none;
  transition: border-color 0.2s;
}
#chat-input:focus { border-color: rgba(0,229,255,0.4); }
#chat-input::placeholder { color: var(--muted); }

#chat-send {
  width: 34px;
  height: 34px;
  padding: 0;
  background: linear-gradient(135deg, #0070f3, #00bfff);
  border-radius: 8px;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#chat-notif {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--accent2);
  color: white;
  font-size: 10px;
  font-family: var(--font-ui);
  font-weight: bold;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
}

/* ── Pseudo ────────────────────────────────────────── */
#pseudo-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding: 7px 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-family: var(--font-mono);
  font-size: 12px;
}

#pseudo-display {
  flex: 1;
  color: var(--accent);
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#pseudo-input {
  flex: 1;
  display: none;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
}

#pseudo-edit, #pseudo-save {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
#pseudo-edit:hover, #pseudo-save:hover { background: rgba(255,255,255,0.08); color: var(--text); }
#pseudo-save { color: var(--ok); border-color: rgba(0,255,136,0.3); }

/* Badge messages non lus */
#chat-badge {
  background: var(--accent2);
  color: white;
  font-size: 10px;
  font-family: var(--font-ui);
  font-weight: bold;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 4px;
  display: none;
  align-items: center;
  justify-content: center;
  margin-left: auto;
}

/* ── Loupe ─────────────────────────────────────────── */
#lens {
  position: fixed;
  display: none;
  border-radius: 10px;
  border: 2px solid var(--accent);
  box-shadow: 0 6px 30px rgba(0,0,0,0.7), 0 0 0 1px rgba(0,229,255,0.15);
  image-rendering: pixelated;
  z-index: 90;
  pointer-events: none;
}

/* ── Écran pseudo (première visite) ───────────────── */
#pseudo-screen {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(8px);
  animation: fadeIn 0.4s ease;
}

#pseudo-screen.hidden {
  animation: fadeOut 0.35s ease forwards;
  pointer-events: none;
}

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

#pseudo-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 40px 36px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7), 0 0 0 1px rgba(0,229,255,0.06);
  width: 340px;
  animation: slideUp 0.4s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

#pseudo-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  image-rendering: pixelated;
  margin-bottom: 12px;
}

#pseudo-card h1 {
  font-family: var(--font-ui);
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

#pseudo-card p {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 24px;
  font-family: var(--font-mono);
}

#pseudo-first-input {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 16px;
  padding: 12px 16px;
  text-align: center;
  outline: none;
  margin-bottom: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  letter-spacing: 1px;
}

#pseudo-first-input:focus {
  border-color: rgba(0,229,255,0.5);
  box-shadow: 0 0 0 3px rgba(0,229,255,0.1);
}

#pseudo-confirm {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #0070f3, #00bfff);
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  box-shadow: 0 4px 20px rgba(0,112,243,0.4);
  transition: transform 0.15s, opacity 0.15s;
}
#pseudo-confirm:hover { opacity: 0.88; transform: translateY(-1px); }

#pseudo-error {
  display: block;
  margin-top: 10px;
  color: var(--err);
  font-family: var(--font-mono);
  font-size: 12px;
  min-height: 16px;
}

/* ── Pseudo affiché dans l'UI ─────────────────────── */
#pseudo-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 10px;
  padding: 7px 10px;
  background: rgba(0,229,255,0.04);
  border: 1px solid rgba(0,229,255,0.1);
  border-radius: 7px;
  font-family: var(--font-mono);
  font-size: 13px;
}

#pseudo-display {
  color: var(--accent);
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Panneau Admin ─────────────────────────────────── */
#admin-open {
  position: fixed;
  bottom: 16px;
  left: 16px;
  width: 36px;
  height: 36px;
  background: rgba(20,20,30,0.8);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.2s;
  z-index: 50;
  padding: 0;
}
#admin-open:hover { opacity: 1; }

#admin-panel {
  position: fixed;
  bottom: 60px;
  left: 16px;
  width: 260px;
  background: var(--panel);
  border: 1px solid rgba(255,60,60,0.3);
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.7);
  backdrop-filter: blur(12px);
  z-index: 200;
  display: none;
  animation: slideIn 0.2s ease;
}

#admin-panel.visible { display: block; }

#admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,60,60,0.2);
  font-family: var(--font-ui);
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 2px;
  color: #ff4444;
}

#admin-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  width: auto;
  padding: 0 4px;
}

#admin-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#admin-status {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 8px;
  background: rgba(255,255,255,0.04);
  border-radius: 6px;
  color: var(--muted);
  text-align: center;
}

.admin-btn {
  width: 100%;
  padding: 9px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  color: white;
  transition: opacity 0.2s;
}
.admin-btn.danger { background: rgba(255,60,60,0.8); }
.admin-btn.ok     { background: rgba(0,200,100,0.8); }
.admin-btn:hover  { opacity: 0.85; }

#admin-body hr { border: none; border-top: 1px solid var(--border); margin: 2px 0; }

#ban-row {
  display: flex;
  gap: 6px;
}

#ban-ip-input {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 6px 8px;
  outline: none;
}

#ban-row .admin-btn { width: auto; padding: 6px 12px; flex-shrink: 0; }

#clear-region-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

#clear-region-row input {
  width: 45px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 6px;
  text-align: center;
  outline: none;
}

#clear-region-row input:focus {
  border-color: rgba(255,60,60,0.4);
}

#btn-clear-region {
  flex: 1;
  padding: 6px 8px;
  font-size: 11px;
}

#banned-list {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  max-height: 80px;
  overflow-y: auto;
}
/* ═══════════════════════════════════════════════════════
   NOUVELLES FONCTIONNALITÉS
   ═══════════════════════════════════════════════════════ */

/* ── Goto coordonnées ──────────────────────────────── */
#goto-row {
  display: flex;
  gap: 5px;
  margin-bottom: 10px;
  align-items: center;
}

#goto-x, #goto-y {
  width: 52px;
  flex-shrink: 0;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 8px;
  outline: none;
  text-align: center;
  -moz-appearance: textfield;
  transition: border-color 0.2s;
}
#goto-x::-webkit-inner-spin-button,
#goto-y::-webkit-inner-spin-button { -webkit-appearance: none; }
#goto-x:focus, #goto-y:focus { border-color: rgba(0,229,255,0.4); }

#goto-btn {
  flex: 1;
  padding: 6px 8px;
  background: rgba(0,229,255,0.1);
  border: 1px solid rgba(0,229,255,0.25);
  border-radius: 7px;
  color: var(--accent);
  font-size: 11px;
  font-family: var(--font-ui);
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  width: auto;
}
#goto-btn:hover { background: rgba(0,229,255,0.2); }

/* ── Toggle buttons row ─────────────────────────────── */
#toggles-row {
  display: flex;
  gap: 5px;
  margin-bottom: 10px;
}

.toggle-btn {
  flex: 1;
  padding: 6px 4px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  font-size: 11px;
  font-family: var(--font-ui);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: auto;
  white-space: nowrap;
}
.toggle-btn:hover { background: rgba(255,255,255,0.1); color: var(--text); }
.toggle-btn.active {
  background: rgba(0,229,255,0.1);
  border-color: rgba(0,229,255,0.35);
  color: var(--accent);
}

/* ── Historique pixels ──────────────────────────────── */
#pixel-history {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: 320px;
  max-width: calc(100vw - 32px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  z-index: 40;
  overflow: hidden;
}

#history-header {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.5px;
}

#history-list {
  max-height: 90px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.history-entry {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.history-entry:hover { background: rgba(0,229,255,0.05); }

.h-color {
  width: 12px; height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
}
.h-pseudo { color: var(--accent2); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-coords { color: var(--accent); font-size: 10px; flex-shrink: 0; }
.h-time   { color: var(--muted); font-size: 10px; flex-shrink: 0; }

/* ── Leaderboard ────────────────────────────────────── */
#leaderboard-panel {
  position: fixed;
  top: 16px;
  right: 152px;
  width: 220px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  z-index: 60;
  display: none;
  animation: slideIn 0.2s ease;
  overflow: hidden;
}
#leaderboard-panel.visible { display: block; }

#leaderboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 13px;
  color: var(--warn);
}

#leaderboard-close {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 14px; width: auto; padding: 0 4px;
}

#leaderboard-list {
  padding: 8px 0;
  max-height: 280px;
  overflow-y: auto;
}

.lb-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  transition: background 0.15s;
}
.lb-entry:hover { background: rgba(255,255,255,0.04); }
.lb-entry.lb-me { background: rgba(0,229,255,0.06); }
.lb-rank  { font-size: 14px; width: 20px; text-align: center; flex-shrink: 0; }
.lb-name  { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-count { color: var(--warn); font-size: 11px; flex-shrink: 0; }
.lb-empty { padding: 14px; text-align: center; color: var(--muted); font-size: 12px; font-family: var(--font-mono); }

/* ── Mode jour (light mode) ─────────────────────────── */
body.light-mode {
  --bg: #d8d8e8;
  --panel: rgba(240, 240, 252, 0.97);
  --border: rgba(0,0,0,0.1);
  --text: #1a1a2e;
  --muted: #6b6b8a;
}
body.light-mode #ui,
body.light-mode #chat-widget,
body.light-mode #leaderboard-panel,
body.light-mode #pixel-history,
body.light-mode #admin-panel {
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}
body.light-mode #coords-bar { background: rgba(0,112,243,0.07); border-color: rgba(0,112,243,0.15); }
body.light-mode #cd { background: rgba(0,180,80,0.08); border-color: rgba(0,180,80,0.2); }
body.light-mode #cd.waiting { background: rgba(255,150,0,0.08); }

/* ═══════════════════════════════════════════════════════
   MOBILE — redesign complet
   ═══════════════════════════════════════════════════════ */

/* Cacher les pads sur desktop */
#mobile-controls,
#mobile-zoom { display: none; }

@media (max-width: 700px) {

  /* ── Canvas plein écran ──────────────────────────── */
  canvas#canvas { cursor: default; }

  /* ── Tooltip désactivé sur mobile ───────────────── */
  #tooltip { display: none !important; }

  /* ── Loupe désactivée sur mobile ────────────────── */
  #lens { display: none !important; }

  /* ── Minimap : coin haut droit, plus petite ──────── */
  #minimap {
    width: 72px;
    height: 72px;
    top: 12px;
    right: 12px;
    border-radius: 6px;
  }

  /* ── Pseudo screen ───────────────────────────────── */
  #pseudo-card {
    width: calc(100vw - 32px);
    padding: 32px 24px;
  }

  /* ══════════════════════════════════════════════════
     BARRE DU BAS — panneau principal repensé
     ══════════════════════════════════════════════════ */
  #ui {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    border-radius: 20px 20px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding: 0;
    max-height: 52vh;
    overflow-y: auto;
    overflow-x: hidden;
    animation: slideUpMobile 0.3s ease;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.6), 0 -1px 0 rgba(0,229,255,0.08);
    z-index: 50;
    /* Scrollbar invisible */
    scrollbar-width: none;
  }
  #ui::-webkit-scrollbar { display: none; }

  @keyframes slideUpMobile {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }

  /* Handle visuel pour drag */
  #ui::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    margin: 10px auto 0;
  }

  /* Header compact */
  #ui-header {
    padding: 8px 16px 0;
    margin-bottom: 8px;
  }

  /* Pseudo row */
  #pseudo-row {
    padding: 6px 16px;
    margin-bottom: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  /* Coords bar */
  #coords-bar {
    margin: 6px 16px;
    padding: 6px 10px;
    font-size: 12px;
  }

  /* ── Palette : ligne unique scrollable ───────────── */
  #picker {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    padding: 4px 16px 6px;
    margin-bottom: 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  #picker::-webkit-scrollbar { display: none; }

  #picker button {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 8px;
    flex-shrink: 0;
  }

  /* Couleur perso */
  #custom-row {
    padding: 0 16px;
    margin-bottom: 6px;
  }

  /* Couleur sélectionnée */
  #selected-row {
    padding: 0 16px;
    margin-bottom: 8px;
  }

  /* Cooldown */
  #cd-wrap { padding: 0 16px; margin-bottom: 8px; }

  /* Bouton place : grand et tactile */
  #actions { padding: 0 16px; gap: 8px; margin-bottom: 8px; }

  #place {
    padding: 14px;
    font-size: 15px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,112,243,0.4);
  }

  #save { padding: 10px; font-size: 12px; }

  /* Stats */
  #stats-bar { padding: 8px 16px 14px; }

  /* ══════════════════════════════════════════════════
     CHAT — au-dessus du panel UI
     ══════════════════════════════════════════════════ */
  #chat-widget {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 52vh;
    width: 100%;
    border-radius: 0;
    border-left: none;
    border-right: none;
    z-index: 45;
    max-height: 180px;
  }

  #chat-widget.collapsed {
    max-height: 38px;
    bottom: 52vh;
  }

  #chat-messages { height: 100px; }

  /* ══════════════════════════════════════════════════
     CONTRÔLES DE NAVIGATION — joystick virtuel
     ══════════════════════════════════════════════════ */
  #mobile-controls {
    display: block;
    position: fixed;
    left: 16px;
    bottom: calc(52vh + 8px);
    z-index: 40;
    width: 136px;
    height: 136px;
    /* Grille 3x3 pour les 4 directions */
  }

  .mobile-pad {
    position: absolute;
    width: 44px;
    height: 44px;
    background: rgba(0,0,0,0.55);
    border: 1.5px solid rgba(255,255,255,0.15);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: rgba(255,255,255,0.8);
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: background 0.1s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  .mobile-pad:active {
    background: rgba(0,229,255,0.3);
    border-color: rgba(0,229,255,0.5);
    transform: scale(0.92);
  }

  /* Croix directionnelle */
  #mobile-pad-up    { top: 0;   left: 46px; }
  #mobile-pad-down  { bottom: 0; left: 46px; }
  #mobile-pad-left  { top: 46px; left: 0; }
  #mobile-pad-right { top: 46px; right: 0; }

  /* ── Zoom + place pixel — colonne droite ─────────── */
  #mobile-zoom {
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: fixed;
    right: 16px;
    bottom: calc(52vh + 8px);
    z-index: 40;
  }

  .mobile-zoom-btn {
    width: 48px;
    height: 48px;
    background: rgba(0,0,0,0.55);
    border: 1.5px solid rgba(255,255,255,0.15);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: background 0.1s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  .mobile-zoom-btn:active {
    background: rgba(0,229,255,0.3);
    border-color: rgba(0,229,255,0.5);
    transform: scale(0.92);
  }

  /* ── Bouton place pixel flottant ─────────────────── */
  #mobile-place-btn {
    display: flex;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #0070f3, #00bfff);
    border-radius: 16px;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 4px 20px rgba(0,112,243,0.5);
    border: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.1s, box-shadow 0.1s;
  }
  #mobile-place-btn:active {
    transform: scale(0.9);
    box-shadow: 0 2px 10px rgba(0,112,243,0.3);
  }

  /* ── Admin panel ─────────────────────────────────── */
  #admin-panel {
    left: 0; right: 0;
    bottom: calc(52vh);
    width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 60vh;
    overflow-y: auto;
  }

  #admin-open {
    bottom: calc(52vh + 8px);
    left: auto;
    right: 72px;
  }

  /* ── Toast ───────────────────────────────────────── */
  #toast {
    bottom: calc(52vh + 8px);
    font-size: 12px;
    padding: 8px 14px;
    max-width: calc(100vw - 32px);
  }

  /* ── Historique ──────────────────────────────────── */
  #pixel-history {
    bottom: auto;
    top: 12px;
    left: 12px;
    right: 92px;
    width: auto;
    transform: none;
    max-height: 72px;
  }
  #history-list { max-height: 50px; }

  /* ── Leaderboard ─────────────────────────────────── */
  #leaderboard-panel {
    right: auto;
    left: 12px;
    top: 90px;
    width: calc(100vw - 24px);
    max-width: 320px;
  }

  /* ── Toggles row ─────────────────────────────────── */
  #toggles-row {
    padding: 0 16px 6px;
    flex-wrap: wrap;
  }
}

@media (max-width: 380px) {
  #picker button { width: 32px; height: 32px; min-width: 32px; }
  .mobile-pad { width: 40px; height: 40px; font-size: 16px; }
  .mobile-zoom-btn { width: 44px; height: 44px; }
  #mobile-controls { width: 128px; height: 128px; }
  #mobile-pad-up    { left: 42px; }
  #mobile-pad-down  { left: 42px; }
  #mobile-pad-left  { top: 42px; }
  #mobile-pad-right { top: 42px; right: 0; }
}

/* ── Login Admin overlay ───────────────────────────── */
#admin-login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 15, 0.85);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
#admin-login-overlay.visible { display: flex; }

#admin-login-card {
  background: var(--panel);
  border: 1px solid rgba(255,60,60,0.25);
  border-radius: 16px;
  padding: 28px 24px;
  width: 300px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7);
  animation: slideUp 0.25s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#admin-login-title {
  font-family: var(--font-ui);
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 2px;
  color: #ff4444;
  text-align: center;
}

#admin-key-input {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 15px;
  padding: 12px 14px;
  text-align: center;
  outline: none;
  letter-spacing: 2px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#admin-key-input:focus {
  border-color: rgba(255,60,60,0.5);
  box-shadow: 0 0 0 3px rgba(255,60,60,0.1);
}

#admin-login-error {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--err);
  text-align: center;
  min-height: 16px;
}

#admin-login-btns {
  display: flex;
  gap: 8px;
}

#admin-login-cancel {
  flex: 1;
  padding: 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  width: auto;
}

#admin-login-confirm {
  flex: 1;
  padding: 10px;
  background: rgba(255,60,60,0.8);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  width: auto;
}
#admin-login-confirm:hover { opacity: 0.85; }

/* ── hCaptcha ──────────────────────────────────────── */
#hcaptcha-widget {
  display: flex;
  justify-content: center;
  margin: 4px 0 2px;
}

/* ── Bouton langue ─────────────────────────────────── */
#lang-toggle {
  width: auto;
  padding: 3px 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px;
  font-family: var(--font-ui);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.5px;
}
#lang-toggle:hover {
  background: rgba(255,255,255,0.12);
  color: var(--text);
}