/* =============================================================
   map.css — Carte interactive JeuxRSE
   Taille fixe : MAP_W × MAP_H (définie dans map.js)
   ============================================================= */

/* ── Variables CSS — ombres des tokens joueurs ───────────────── */
:root {
  /* Ellipse d'ombre au sol */
  --token-shadow-size: 0.85;                    /* fraction de la demi-largeur de l'avatar (1.0 = même largeur que l'avatar) */
  --token-shadow-aspect: 0.30;                  /* rapport ry/rx de l'ellipse (0 = trait, 1 = cercle) */
  --token-shadow-color: rgba(0, 0, 0, 0.35);    /* couleur + opacité          */
  --token-shadow-offset-y: 0.9;                   /* décalage vertical (px, lu en JS) */

  /* Contour (ring) de l'avatar */
  --token-ring-gap: 15;                          /* débordement du contour au-delà de l'avatar (px) */
  --token-ring-radius: 30;                      /* arrondi des coins du rectangle de contour (px) */
  --token-ring-width: 0.5;                      /* épaisseur du trait (px) */
  --token-ring-color-online:  rgba(0, 230, 118, 1);   /* couleur joueur en ligne  */
  --token-ring-color-offline: rgba(97, 97, 97, 0.6);  /* couleur joueur hors-ligne */
  --token-ring-color-self:    rgb(171, 211, 221);  /* couleur joueur courant   */
  --token-ring-pulse-width: 2;                  /* épaisseur max pendant la pulsation */
  --token-ring-pulse-opacity: 0.5;              /* opacité min pendant la pulsation  */

  /* Halo au survol */
  --token-glow-radius: 6px;                     /* rayon du halo              */
  --token-glow-color: rgba(255, 255, 255, 0.9); /* couleur du halo            */
}

/* ── Conteneur principal de la carte ──────────────────────────── */
#map-container {
  position: relative;       /* ancrage pour canvas Rive et popups absolus */
  display: block;
  width: 100%;
  height: 100%;
  line-height: 0;           /* supprime l'espace inline sous le SVG */
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  background: #111;         /* couleur de sécurité avant chargement du fond */
}

/* Curseur pendant le pan (bouton milieu maintenu) */
#map-container.is-panning,
#map-container.is-panning * {
  cursor: grabbing !important;
}

/* ── SVG racine (100% du conteneur, viewBox géré par JS) ────── */
#game-map {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
  user-select: none;
}

/* ── Calque 0 : fond de carte ────────────────────────────────── */
#layer-bg image {
  display: block;
}

/* ── Calque 1 : grille de tuiles (layer-grid) ───────────────── */
/* Toggle : touche G  |  JS : GameMap.toggleGrid()               */
.tile-grid-line {
  stroke: rgba(255, 255, 255, 0.18);
  stroke-width: 0.75;
  stroke-dasharray: 2 4;            /* tirets fins pour ne pas écraser le fond */
  pointer-events: none;
}
/* Lignes de rang (tous les 5 rangées) : un peu plus marquées    */
.tile-grid-line.major {
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 1;
  stroke-dasharray: none;
}
.tile-cell-label {
  font-size: 9px;
  font-family: monospace;
  fill: rgba(255, 255, 255, 0.45);
  pointer-events: none;
  user-select: none;
}

/* ── Calque 1 : bâtiments ────────────────────────────────────── */
.map-building {
  cursor: pointer;
  transition: filter 0.2s ease, opacity 0.3s ease;
}
.map-building:hover {
  filter: brightness(1.25) drop-shadow(0 0 8px rgba(255, 220, 80, 0.8));
}
.map-building.locked {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(0.8);
}
.map-building.hidden-element {
  display: none;
}

/* ── Calque 2 : zones / events ───────────────────────────────── */
.map-zone {
  cursor: pointer;
  transition: opacity 0.3s ease;
}
.map-zone.hidden-element {
  display: none;
}
.map-zone-fill {
  fill: rgba(56, 189, 248, 0.15);
  stroke: rgba(56, 189, 248, 0.6);
  stroke-width: 2;
  stroke-dasharray: 6 4;
  transition: fill 0.25s;
}
.map-zone:hover .map-zone-fill {
  fill: rgba(56, 189, 248, 0.28);
}
.map-marker {
  cursor: pointer;
  transition: transform 0.2s ease;
  transform-origin: center;
}
.map-marker:hover {
  transform: scale(1.15);
}
.map-marker.hidden-element {
  display: none;
}

/* ── Calque 3 : tokens joueurs ───────────────────────────────── */
.player-token {
  cursor: pointer;
  transition: filter 0.2s ease;
}
.player-token:hover {
  filter: drop-shadow(0 0 var(--token-glow-radius) var(--token-glow-color));
}
.player-token .token-shadow {
  fill: var(--token-shadow-color);
  /* rx et ry sont appliqués comme attributs SVG dans app.js (lus depuis --token-shadow-rx/ry) */
}
.player-token .token-avatar {
  clip-path: circle(50%);
}
.player-token .token-ring {
  fill: none;
  stroke-width: var(--token-ring-width);
}
.player-token .token-ring.online  { stroke: var(--token-ring-color-online); }
.player-token .token-ring.offline { stroke: var(--token-ring-color-offline); }
.player-token .token-nametag {
  font-size: 11px;
  font-weight: 700;
  fill: #fff;
  text-anchor: middle;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  pointer-events: none;
}
/* Animation de pulsation pour le joueur courant */
.player-token.is-self .token-ring {
  stroke: var(--token-ring-color-self);
  animation: ring-pulse 1.8s ease-in-out infinite;
}
@keyframes ring-pulse {
  0%, 100% { stroke-opacity: 1;                          stroke-width: var(--token-ring-width); }
  50%       { stroke-opacity: var(--token-ring-pulse-opacity); stroke-width: var(--token-ring-pulse-width); }
}

/* Joueur hors-ligne : token atténué */
.player-token.offline {
  opacity: 0.5;
}

/* ── Calque 4 : popups SVG ───────────────────────────────────── */
#layer-popups {
  pointer-events: none;
}
.map-popup {
  pointer-events: auto;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.7));
  cursor: default;
}
.map-popup .popup-bg {
  fill: #1e293b;
  stroke: #334155;
  stroke-width: 1.5;
  rx: 10px;
}
.map-popup .popup-title {
  font-weight: 700;
  font-size: 13px;
  fill: #38bdf8;
}
.map-popup .popup-body {
  font-size: 11px;
  fill: #cbd5e1;
}
.map-popup .popup-close {
  fill: #64748b;
  cursor: pointer;
  transition: fill 0.15s;
}
.map-popup .popup-close:hover { fill: #f87171; }
/* Animation d'entrée des popups */
.map-popup {
  animation: popup-in 0.18s ease;
}
@keyframes popup-in {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── Overlay HUD de la carte (zoom / clumbs / joueurs + boutons) ── */
/* ── Barre d'outils carte (au-dessus du container SVG, pleine largeur) ── */
#map-toolbar {
  flex-shrink: 0;
  width: 100%;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  box-sizing: border-box;
  background: rgba(8, 16, 32, 0.65);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(56, 189, 248, 0.15);
  gap: 12px;
  /* Aucun pointer-events trick nécessaire : pas dans #map-container */
}

#map-toolbar-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
  white-space: nowrap;
}
#map-stat-zoom {
  color: #38bdf8;
  min-width: 44px;
}
.map-stat-icon {
  font-size: 11px;
  opacity: 0.75;
}
.map-stat-sep {
  color: rgba(148, 163, 184, 0.3);
  font-weight: 400;
}

#map-toolbar-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}
#map-toolbar-actions button {
  background: rgba(30, 41, 59, 0.80);
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 6px;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 600;
  height: 26px;
  padding: 0 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
#map-toolbar-actions button:hover {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.65);
  color: #e2e8f0;
}
#map-toolbar-actions button:active {
  background: rgba(56, 189, 248, 0.32);
}

/* ── HUD de debug (position souris + stats carte) — bas gauche ── */
#map-debug-hud {
  position: absolute;
  bottom: 10px;
  left: 10px;
  z-index: 20;
  pointer-events: none;
  font-family: monospace;
  font-size: 11px;
  line-height: 1.6;
  color: rgba(148, 163, 184, 0.90);
  background: rgba(0, 0, 0, 0.50);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(56, 189, 248, 0.15);
  border-radius: 6px;
  padding: 6px 10px;
  white-space: nowrap;
  display: none; /* masqué par défaut, activé avec la grille */
}
#map-debug-hud .dbg-sep {
  display: block;
  border-top: 1px solid rgba(56, 189, 248, 0.12);
  margin: 3px 0;
}

/* ── Canvas Rive (superposé, transparent) ────────────────────── */
#rive-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;   /* les clics passent au SVG en dessous */
  display: block;
}

/* ── Zone de jeu : colonne (toolbar + carte) ────────────────── */
#game-area {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
  padding: 0;
  box-sizing: border-box;
}/* Neutralise le padding:8px de style.css (même spécificité, map.css chargé après) */
#game-screen #game-area {
  flex-direction: column;
  padding: 0;
  align-items: stretch;
}
#map-container {
  flex: 1;
  min-height: 0; /* important pour que flex ne dépasse pas */
}
