* { margin: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #101116;
  overflow: hidden;
}

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

/* ---- chrome flottant (verre sombre) ---- */
.brand,
.hud {
  background: rgba(16, 17, 22, 0.78);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  color: #fff;
  z-index: 10;
}

.brand {
  position: fixed; top: 16px; left: 16px;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.hud {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  width: min(720px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 999px;
}

.play {
  flex: none;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.play:hover { background: rgba(255, 255, 255, 0.22); }
.play:active { transform: scale(0.93); }

.trails-btn {
  flex: none;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.trails-btn:hover { background: rgba(255, 255, 255, 0.22); }
.trails-btn.on { background: #fff; color: #101116; }

#minimap {
  position: fixed; left: 16px; bottom: 24px;
  width: 270px; height: 260px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  z-index: 9;
  cursor: pointer;
}
/* écrans étroits : la timeline centrée arrive au-dessus, on remonte la minimap */
@media (max-width: 1320px) { #minimap { bottom: 104px; } }
@media (max-width: 620px) { #minimap { display: none; } }

.track {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

#ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* un déplacement d'une personne : pastille à sa couleur, sur sa voie */
.tick {
  position: absolute;
  top: 50%;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--c);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.85);
  pointer-events: auto;
  cursor: pointer;
}
.tick:hover { transform: translate(-50%, -50%) scale(1.35); }
.tick:hover, .tick.pinned { z-index: 5; }

.tick-label {
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  background: rgba(16, 17, 22, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 11px; font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
}
.tick:hover .tick-label,
.tick.pinned .tick-label { display: block; text-align: center; }

/* ligne « départ → arrivée » sous le nom, pastilles de timeline uniquement */
.tick-move {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.75);
}

#slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(to right,
    #fff var(--p, 100%),
    rgba(255, 255, 255, 0.22) var(--p, 100%));
  outline: none;
  cursor: pointer;
}
#slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}
#slider::-moz-range-thumb {
  width: 17px; height: 17px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

.date {
  flex: none;
  min-width: 8em;
  text-align: right;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.92);
}

/* bouton « Aujourd'hui », à droite du bloc timeline ; centré verticalement
   sur lui : centre du hud (bordures comprises) = bottom 24 + 64/2 = 56 */
.today-btn {
  position: fixed;
  left: calc(50% + min(720px, 100vw - 32px) / 2 + 12px);
  bottom: 34px;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 50%;
  background: rgba(16, 17, 22, 0.78);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  color: #fff;
  cursor: pointer;
  z-index: 10;
  transition: background 0.2s, transform 0.1s;
}
.today-btn:hover { background: rgba(44, 47, 58, 0.9); }
.today-btn:active { transform: scale(0.96); }
@media (max-width: 900px) {
  .today-btn { left: auto; right: 16px; bottom: 104px; }
}

/* ---- markers ---- */
/* pas de `position` ici : MapLibre pose son .maplibregl-marker en absolute,
   et notre feuille chargée après ne doit pas l'écraser.
   Le pin est un point 0×0 ancré sur les coordonnées exactes ; la sphère
   (.bubble) s'en écarte librement et la pointe SVG les relie en continu. */
.pin {
  width: 0; height: 0;
  cursor: default;
  transition: opacity 0.45s;
}
.pin.hidden { pointer-events: none; }

.pin .tail {
  position: absolute; left: 0; top: 0;
  overflow: visible;
  pointer-events: none;
}
.pin .tail path {
  fill: var(--ring);
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 2.5;
  paint-order: stroke;
  stroke-linejoin: round;
}

.bubble {
  position: absolute; left: 0; top: 0;
  width: 54px; height: 54px;
  will-change: transform;
  cursor: pointer;
}

.pin.selected .avatar {
  box-shadow: 0 0 0 3px #fff, 0 6px 18px rgba(0, 0, 0, 0.45);
}

.avatar {
  position: relative;
  z-index: 1;
  width: 100%; height: 100%;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--ring);
  background: var(--ring);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.92), 0 6px 14px rgba(0, 0, 0, 0.3);
}
.avatar img {
  position: relative; z-index: 1;
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.initials {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 18px; font-weight: 600;
  background: var(--ring);
}

.badge {
  position: absolute; top: -7px; right: -7px; z-index: 2;
  font-size: 15px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.3s, transform 0.3s;
}
.pin.traveling .badge { opacity: 1; transform: scale(1); }

.pin.mini .bubble { width: 36px; height: 36px; }
.pin.mini .avatar { border-width: 2px; }
.pin.mini .tail path { stroke-width: 2; }
.pin.mini .initials { font-size: 12px; }
.pin.mini .badge { display: none; }

.cluster-badge {
  z-index: 5; /* devant les épingles et leurs chips */
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(16, 17, 22, 0.78);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #fff;
  font-family: inherit;
  font-size: 11px; font-weight: 600;
  padding: 4px 11px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  /* jamais de transition sur transform : MapLibre positionne le marker par
     transform inline, l'animer ferait traîner le badge derrière la carte */
  transition: background 0.2s;
}
.cluster-badge:hover { background: rgba(44, 47, 58, 0.9); }

.chip-time {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.75);
  font-variant-numeric: tabular-nums;
}
.chip-time .clock-ic { width: 9px; height: 9px; }
/* l'heure mutualisée s'affiche SOUS « N villes » */
.cluster-badge { display: inline-flex; flex-direction: column; align-items: center; gap: 1px; }
.cluster-badge .clock-ic { width: 10px; height: 10px; opacity: 0.8; }

.chip {
  position: absolute; bottom: calc(100% + 4px); left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: rgba(16, 17, 22, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 11px; font-weight: 500;
  padding: 3px 9px;
  border-radius: 999px;
  pointer-events: none;
}

/* cercles des lieux visités par la personne sélectionnée */
.visit {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.92), 0 2px 6px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
.visit:hover, .visit.pinned { z-index: 6; }

.visit-label {
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  background: rgba(16, 17, 22, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 12px; font-weight: 600;
  padding: 5px 11px;
  border-radius: 12px;
  text-align: center;
  width: max-content;
  max-width: 220px;
  white-space: normal;
  pointer-events: none;
}
.visit:hover .visit-label,
.visit.pinned .visit-label { display: block; }

.visit-time,
.visit-motif {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.75);
}

/* ---- statistiques ---- */
.stats-btn {
  position: fixed; top: 16px; right: 16px; z-index: 10;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 50%;
  background: rgba(16, 17, 22, 0.78);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
}
.stats-btn:hover { background: rgba(44, 47, 58, 0.9); }

/* panneau flottant en haut à droite — la carte reste interactive derrière */
.stats-panel {
  position: fixed; top: 16px; right: 16px; z-index: 30;
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: rgba(16, 17, 22, 0.88);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  color: #fff;
  padding: 14px 18px 16px;
}
.stats-panel[hidden] { display: none; }

.stats-head {
  font-size: 15px; font-weight: 700;
  margin-bottom: 10px;
  padding-right: 36px; /* place pour la croix */
}

/* croix posée exactement sur l'axe du bouton d'ouverture (centre à 38px des
   bords du viewport, comme le bouton 44px à top/right 16) */
.stats-close {
  position: absolute; top: 8px; right: 8px;
  width: 28px; height: 28px;
  border: none; border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: #fff; font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}
.stats-close:hover { background: rgba(255, 255, 255, 0.22); }

.stat-row {
  display: flex; align-items: baseline; gap: 10px;
  padding: 7px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 13px;
}
.stat-row:first-child { border-top: none; }
.stat-label { color: rgba(255, 255, 255, 0.75); flex: 1; }
.stat-value { font-weight: 650; text-align: right; }
.stat-sub {
  display: block;
  font-size: 11px; font-weight: 400;
  color: rgba(255, 255, 255, 0.55);
}

/* ---- écran de chargement ---- */
#loading {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px;
  background: #101116;
  color: #fff;
  transition: opacity 0.6s;
}
#loading.done { opacity: 0; pointer-events: none; }
.wordmark { font-size: 30px; font-weight: 700; letter-spacing: 0.02em; }
.spinner {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* IMPORTANT : ne jamais redimensionner .pin — c'est un point 0×0 ancré sur
   les coordonnées, tout le repère des pointes en dépend (cf. .bubble) */
@media (max-width: 520px) {
  .hud { gap: 10px; padding: 10px 14px; bottom: 16px; }
  .date { min-width: 6.5em; font-size: 12px; }
}
