@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=DM+Sans:wght@300;400;500&display=swap');

/* ── Variables globales ── */
:root {
  --bg:        #0d0d0f;
  --sidebar:   #111116;
  --border:    #222228;
  --accent:    #e8ff47;
  --accent2:   #ff4f7b;
  --text:      #e8e8f0;
  --muted:     #685566;
  --pixel-sz:  10px;
  --radius:    6px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  overflow: hidden;
}

/* ── Layout desktop : sidebar gauche + canvas droite ── */
body {
  display: flex;
  flex-direction: row;
}

/* ── Sidebar desktop : scroll global activé ── */
.sidebar {
  width: 240px;
  min-width: 240px;
  height: 100vh;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto; /* ✅ scroll sidebar activé */
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── Header sidebar ── */
.sidebar-header {
  padding: 28px 20px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: linear-gradient(160deg, #16161c 0%, #111116 100%);
}

/* ── Logo pixel 3x3 animé ── */
.logo-pixel {
  display: grid;
  grid-template-columns: repeat(3, var(--pixel-sz));
  grid-template-rows: repeat(3, var(--pixel-sz));
  gap: 2px;
}

.logo-pixel span {
  display: block;
  width: var(--pixel-sz);
  height: var(--pixel-sz);
  border-radius: 1px;
  animation: pixelPop 1.2s ease forwards;
  opacity: 0;
}

/* Chaque carré s'allume avec une couleur et un délai différent */
.logo-pixel span:nth-child(1)  { background: var(--accent);  animation-delay: 0.0s; }
.logo-pixel span:nth-child(2)  { background: var(--accent2); animation-delay: 0.1s; }
.logo-pixel span:nth-child(3)  { background: #47e8ff;        animation-delay: 0.2s; }
.logo-pixel span:nth-child(4)  { background: #ff9f47;        animation-delay: 0.3s; }
.logo-pixel span:nth-child(5)  { background: var(--accent);  animation-delay: 0.4s; }
.logo-pixel span:nth-child(6)  { background: var(--accent2); animation-delay: 0.5s; }
.logo-pixel span:nth-child(7)  { background: #47e8ff;        animation-delay: 0.6s; }
.logo-pixel span:nth-child(8)  { background: #ff9f47;        animation-delay: 0.7s; }
.logo-pixel span:nth-child(9)  { background: var(--accent);  animation-delay: 0.8s; }

/* Animation : part de 0, grossit légèrement puis revient à taille normale */
@keyframes pixelPop {
  0%   { opacity: 0; transform: scale(0); }
  60%  { opacity: 1; transform: scale(1.3); }
  100% { opacity: 1; transform: scale(1); }
}

/* ── Titre principal ── */
h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(232, 255, 71, 0.3);
  letter-spacing: 0.02em;
}

/* ── Badge de statut connexion ── */
.status-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--muted);
  background: rgba(255,255,255,0.04);
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

/* ── Dot de statut : rouge par défaut (déconnecté) ── */
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ff4444;
  box-shadow: 0 0 8px rgba(255, 68, 68, 0.6);
  transition: background 0.4s, box-shadow 0.4s;
  flex-shrink: 0;
}

/* Dot vert animé quand la classe .connected est ajoutée par le JS */
.status-badge.connected .status-dot {
  background: #4cff91;
  box-shadow: 0 0 8px rgba(76, 255, 145, 0.6);
  animation: pulse 2s infinite;
}

/* Dot rouge fixe quand la classe .disconnected est ajoutée par le JS */
.status-badge.disconnected .status-dot {
  background: #ff4c4c;
  box-shadow: 0 0 8px rgba(255, 76, 76, 0.6);
  animation: none;
}

/* Animation de pulsation du dot connecté */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* ── Sections de la sidebar ── */
.sidebar-section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; /* empêche les sections d'être compressées */
}

/* Label de section en pixel font très petit */
.section-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ── Palette de couleurs ── */
#palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Chaque bouton couleur */
.color {
  width: 26px;
  height: 26px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  outline: none;
  position: relative;
}

/* Survol : grossit légèrement */
.color:hover {
  transform: scale(1.2);
  border-color: rgba(255,255,255,0.3);
}

/* Couleur sélectionnée : bordure jaune + halo */
.color.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(232, 255, 71, 0.25), inset 0 0 0 1px rgba(0,0,0,0.3);
  transform: scale(1.15);
}

/* ── Affichage du cooldown ── */
.cooldown-display {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 10px;
}

/* Chiffre du compte à rebours en grand */
#cooldown {
  font-family: 'Press Start 2P', monospace;
  font-size: 32px;
  color: var(--accent);
  line-height: 1;
  text-shadow: 0 0 20px rgba(232, 255, 71, 0.4);
  transition: color 0.3s;
}

/* Chiffre en rose quand le cooldown est actif (data-active="true" mis par le JS) */
#cooldown[data-active="true"] {
  color: var(--accent2);
  text-shadow: 0 0 20px rgba(255, 79, 123, 0.4);
}

.cooldown-unit {
  font-size: 13px;
  color: var(--accent);
  font-weight: 300;
}

/* Barre de progression du cooldown */
.cooldown-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

/* Remplissage de la barre, animé par le JS via style.width */
.cooldown-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border-radius: 2px;
}

/* ── Boutons d'action ── */
.sidebar-actions {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* Style de base commun à tous les boutons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
  letter-spacing: 0.01em;
}

/* Légère compression au clic */
.btn:active { transform: scale(0.97); }

/* Bouton principal : fond jaune, texte noir */
.btn-primary {
  background: var(--accent);
  color: #0d0d0f;
  box-shadow: 0 2px 12px rgba(232, 255, 71, 0.2);
}

.btn-primary:hover {
  background: #f0ff6a;
  box-shadow: 0 4px 20px rgba(232, 255, 71, 0.35);
}

/* Bouton secondaire : transparent avec bordure */
.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.05);
  border-color: var(--muted);
}

/* ── Hint boxes desktop et mobile ── */
.hint-desktop, .hint-mobile {
  margin: 20px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--accent);
  line-height: 2;
  flex-shrink: 0;
}

.hint-desktop span, .hint-mobile span {
  display: inline-block;
  width: 16px;
}

/* Par défaut les deux sont cachés — les media queries décident lequel afficher */
.hint-desktop { display: none; }
.hint-mobile  { display: none; }

/* Souris/trackpad → affiche desktop uniquement */
@media (any-pointer: fine) {
  .hint-desktop { display: block; }
  .hint-mobile  { display: none; }
}

/* Écran tactile → affiche mobile uniquement */
@media (any-pointer: coarse) and (not (any-pointer: fine)) {
  .hint-desktop { display: none; }
  .hint-mobile  { display: block; }
}

/* ── Bannière flottante au dessus du canvas ── */
.canvas-banner {
  position: absolute;
  text-align: center;
  top: 130px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(13, 13, 15, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 12px 24px;
  font-family: 'DM Sans', sans-serif;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-image: linear-gradient(90deg, var(--accent), var(--accent2));
}

/* ── Zone du canvas ── */
.canvas-wrap {
  flex: 1;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
  position: relative;
}

/* Grille de fond subtile en pseudo-élément */
.canvas-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

#canvas {
  display: block;
  cursor: crosshair;
  image-rendering: pixelated;
  position: relative;
  z-index: 1;
}

#canvas:focus { outline: none; }

/* ── Panneau admin (visible uniquement sur ?admin=1) ── */
.admin-panel {
  border-bottom: 1px solid var(--accent2);
  background: rgba(255, 79, 123, 0.05);
}

.admin-status {
  font-size: 11px;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.5;
}

/* Champ mot de passe admin */
.admin-input {
  width: 100%;
  padding: 8px 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  outline: none;
}

.admin-input:focus {
  border-color: var(--accent2);
}

/* ════════════════════════════════════════════
   RESPONSIVE MOBILE (portrait < 768px)
   Layout vertical : canvas en haut, sidebar en bas
   ════════════════════════════════════════════ */
@media (max-width: 768px) and (orientation: portrait) {

  /* Layout vertical : canvas au dessus, sidebar en dessous */
  body {
    flex-direction: column;
    overflow: hidden;
  }

  /* Sidebar mobile : barre en bas avec scroll interne */
  .sidebar {
    width: 100%;
    min-width: unset;
    height: auto;
    max-height: 45vh;
    border-right: none;
    border-top: 1px solid var(--border);
    overflow-y: auto;
    order: 2;
  }

  /* Header compact sur mobile : logo + titre côte à côte */
  .sidebar-header {
    padding: 12px 16px;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
  }

  /* Logo plus petit sur mobile */
  .logo-pixel { --pixel-sz: 7px; }

  /* Titre plus petit */
  h1 {
    font-size: 9px;
    text-align: left;
  }

  /* Palette : boutons plus grands pour les doigts */
  .color {
    width: 32px;
    height: 32px;
  }

  /* Cooldown plus compact */
  #cooldown { font-size: 22px; }

  /* Sections moins de padding */
  .sidebar-section { padding: 12px 16px; }

  /* Boutons côte à côte sur mobile */
  .sidebar-actions {
    padding: 12px 16px;
    flex-direction: row;
  }

  /* Classement : 3 lignes visibles sur mobile */
  #leaderboard { max-height: 90px; }

  /* Canvas mobile : prend le haut de l'écran */
  .canvas-wrap {
    width: 100%;
    height: 55vh;
    flex: unset;
    order: 1;
  }

  /* Bannière plus petite sur mobile */
  .canvas-banner {
    font-size: 11px;
    white-space: normal;
    text-align: center;
    width: 85%;
    top: 10px;
    padding: 8px 14px;
  }
}

/* ════════════════════════════════════════════
   POPUP PSEUDO
   ════════════════════════════════════════════ */

/* Overlay sombre par dessus tout le site */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

/* Carte centrale */
.popup {
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

/* Logo pixel miniature dans la popup */
.logo-pixel-sm {
  display: grid;
  grid-template-columns: repeat(3, 8px);
  grid-template-rows: repeat(3, 8px);
  gap: 2px;
  margin-bottom: 4px;
}

.logo-pixel-sm span {
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 1px;
  animation: pixelPop 1.2s ease forwards;
  opacity: 0;
}

.logo-pixel-sm span:nth-child(1) { background: var(--accent);  animation-delay: 0.0s; }
.logo-pixel-sm span:nth-child(2) { background: var(--accent2); animation-delay: 0.1s; }
.logo-pixel-sm span:nth-child(3) { background: #47e8ff;        animation-delay: 0.2s; }
.logo-pixel-sm span:nth-child(4) { background: #ff9f47;        animation-delay: 0.3s; }
.logo-pixel-sm span:nth-child(5) { background: var(--accent);  animation-delay: 0.4s; }
.logo-pixel-sm span:nth-child(6) { background: var(--accent2); animation-delay: 0.5s; }
.logo-pixel-sm span:nth-child(7) { background: #47e8ff;        animation-delay: 0.6s; }
.logo-pixel-sm span:nth-child(8) { background: #ff9f47;        animation-delay: 0.7s; }
.logo-pixel-sm span:nth-child(9) { background: var(--accent);  animation-delay: 0.8s; }

.popup-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(232, 255, 71, 0.3);
  text-align: center;
}

.popup-subtitle {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

/* Champ texte pseudo */
.popup-input {
  width: 100%;
  padding: 12px 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  outline: none;
  text-align: center;
  transition: border-color 0.2s;
}

.popup-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(232, 255, 71, 0.15);
}

/* Message d'erreur */
.popup-error {
  font-size: 12px;
  color: var(--accent2);
  min-height: 16px;
  text-align: center;
}

/* Bouton pleine largeur */
.popup-btn {
  width: 100%;
  padding: 12px;
  font-size: 14px;
}

.popup-hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

/* ════════════════════════════════════════════
   LEADERBOARD DANS LA SIDEBAR
   ════════════════════════════════════════════ */

/* Affichage du pseudo courant */
#playerInfo {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 10px;
}

/* Liste du classement : 5 lignes visibles puis scroll interne indépendant */
#leaderboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 170px; /* 5 lignes × ~28px + gaps */
  overflow-y: scroll;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) var(--border);
  padding-right: 4px;
  overscroll-behavior: contain; /* scroll indépendant de la sidebar */
}

/* Ligne du classement */
.lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.03);
  font-size: 12px;
  flex-shrink: 0;
}

/* Ligne surlignée pour le joueur courant */
.lb-me {
  background: rgba(232, 255, 71, 0.08);
  border: 1px solid rgba(232, 255, 71, 0.2);
}

.lb-rank {
  width: 24px;
  font-size: 13px;
  flex-shrink: 0;
}

/* Pseudo tronqué si trop long */
.lb-pseudo {
  flex: 1;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Score en muted à droite */
.lb-count {
  color: var(--muted);
  font-size: 11px;
  flex-shrink: 0;
}

/* ── Pixel Battle ── */
.battle-teams {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin: 8px 0;
}

.battle-team-btn {
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.battle-team-btn:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.battle-score-row {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.battle-team-label {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}

/* ════════════════════════════════════════════
   /* ── Outils admin ── */
   ════════════════════════════════════════════ */

.admin-tools {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.admin-tool-btn {
  font-size: 12px;
  padding: 8px 12px;
}

.admin-tool-hint {
  font-size: 10px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.5;
}
/* ── Notification flottante ── */
.notif {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(13, 13, 15, 0.95);
  border: 1px solid var(--accent);
  border-radius: 20px;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  z-index: 500;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 0 20px rgba(232, 255, 71, 0.3);
}

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

/* ── Texte sous le canvas ── */
.canvas-sub-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
  text-align: center;
}

/* ── Compte à rebours battle ── */
.battle-countdown-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  pointer-events: none;
}

.battle-countdown-box {
  background: rgba(13, 13, 15, 0.92);
  border: 2px solid var(--accent2);
  border-radius: 20px;
  padding: 32px 48px;
  text-align: center;
  box-shadow: 0 0 40px rgba(255, 79, 123, 0.4);
}

.battle-countdown-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  color: var(--accent2);
  margin-bottom: 16px;
}

.battle-countdown-number {
  font-family: 'Press Start 2P', monospace;
  font-size: 72px;
  color: var(--accent);
  line-height: 1;
  text-shadow: 0 0 30px rgba(232, 255, 71, 0.6);
  animation: countPulse 1s ease-out;
}

.battle-countdown-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 16px;
}

@keyframes countPulse {
  0%   { transform: scale(1.4); opacity: 0.5; }
  100% { transform: scale(1);   opacity: 1; }
}