/* Vue 3D (/3d.html) — page autonome : ne charge pas main.css, consomme tokens.css. */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: var(--fz-base);
  color: var(--n-800);
  background: #cfe4f5;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
body.night { background: #0b1220; color: #eef2f7; }
[hidden] { display: none !important; }

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

/* ---------- Surfaces flottantes ---------- */
.v3d-hud, .v3d-panel, .v3d-tool, .v3d-hint, .v3d-error {
  background: rgba(255, 255, 255, .92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: var(--e2);
}
body.night .v3d-hud, body.night .v3d-panel, body.night .v3d-tool, body.night .v3d-hint {
  background: rgba(20, 28, 40, .9);
  color: #eef2f7;
}

/* ---------- Bandeau d'état ---------- */
.v3d-hud {
  position: fixed; z-index: 5;
  top: calc(var(--s-3) + env(safe-area-inset-top, 0px)); left: var(--s-3);
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-2) var(--s-4) var(--s-2) var(--s-2);
  border-radius: var(--r-card);
  max-width: calc(100vw - 2 * var(--s-3));
}
.v3d-back {
  display: inline-flex; align-items: center; gap: var(--s-1);
  padding: var(--s-2) var(--s-3) var(--s-2) var(--s-2);
  border-radius: var(--r-ctl);
  background: var(--brand); color: #fff;
  font-weight: 700; font-size: var(--fz-sm); text-decoration: none;
}
.v3d-back:active { transform: scale(.96); }
.v3d-clock { display: flex; flex-direction: column; line-height: var(--lh-tight); }
.v3d-time { font-size: var(--fz-lg); font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.v3d-date { font-size: var(--fz-xs); color: var(--n-500); text-transform: capitalize; }
body.night .v3d-date { color: #9fb0c3; }
.v3d-state {
  display: grid; grid-template-columns: auto 1fr; column-gap: var(--s-2); align-items: center;
  font-size: var(--fz-sm); font-weight: 600; min-width: 0;
}
.v3d-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--n-300); }
.v3d-dot.live { background: #2ecc71; animation: v3d-pulse 2s var(--ease-in-out) infinite; }
.v3d-dot.down { background: var(--late); }
.v3d-sun { grid-column: 2; font-size: var(--fz-xs); font-weight: 500; color: var(--n-500); white-space: nowrap; }
body.night .v3d-sun { color: #9fb0c3; }
@keyframes v3d-pulse { 50% { box-shadow: 0 0 0 6px rgba(46, 204, 113, 0); } 0%, 100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, .55); } }

/* ---------- Fiche du bus sélectionné ---------- */
.v3d-panel {
  position: fixed; z-index: 6;
  left: var(--s-3); bottom: calc(44px + env(safe-area-inset-bottom, 0px));   /* au-dessus des crédits */
  width: min(360px, calc(100vw - 2 * var(--s-3)));
  padding: var(--s-3);
  border-radius: var(--r-card);
  box-shadow: var(--e3);
  animation: v3d-in var(--dur-3) var(--ease-out);
}
@keyframes v3d-in { from { opacity: 0; transform: translateY(12px); } }
.v3d-panel-head { display: flex; align-items: center; gap: var(--s-2); }
.v3d-badge {
  flex: none; min-width: 40px; padding: 4px 10px; text-align: center;
  border-radius: var(--r-ctl); font-weight: 800; font-size: var(--fz-md);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}
.v3d-headsign { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.v3d-x {
  flex: none; width: 34px; height: 34px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: rgba(16, 21, 27, .08); color: inherit; cursor: pointer;
}
body.night .v3d-x { background: rgba(255, 255, 255, .12); }
.v3d-info { margin: var(--s-3) 0; display: grid; gap: var(--s-1); font-size: var(--fz-sm); }
.v3d-info b { font-variant-numeric: tabular-nums; }
.v3d-info .muted { color: var(--n-500); }
body.night .v3d-info .muted { color: #9fb0c3; }
.v3d-panel-actions { display: flex; gap: var(--s-2); }
.v3d-act {
  flex: 1; padding: var(--s-2) var(--s-3); text-align: center;
  border: 0; border-radius: var(--r-ctl); cursor: pointer;
  background: rgba(16, 21, 27, .08); color: inherit;
  font: inherit; font-size: var(--fz-sm); font-weight: 700; text-decoration: none;
}
body.night .v3d-act { background: rgba(255, 255, 255, .12); }
.v3d-act.on, body.night .v3d-act.on { background: var(--sel); color: #fff; }
.v3d-act:active { transform: scale(.97); }

/* ---------- Commandes ---------- */
.v3d-tools {
  position: fixed; z-index: 5;
  right: var(--s-3); bottom: calc(var(--s-5) + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: var(--s-2);
}
.v3d-tool {
  width: 62px; padding: var(--s-2) 0 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; border-radius: var(--r-card); cursor: pointer;
  color: var(--brand-600); font: inherit; font-size: 11px; font-weight: 700;
  transition: transform var(--dur-1) var(--ease-out);
}
.v3d-tool:active { transform: scale(.94); }
.v3d-tool[aria-pressed="true"] { background: var(--brand); color: #fff; }
body.night .v3d-tool { color: #cfe0f1; }
body.night .v3d-tool[aria-pressed="true"] { background: var(--brand); color: #fff; }
.v3d-tool:focus-visible, .v3d-act:focus-visible, .v3d-x:focus-visible, .v3d-back:focus-visible {
  outline: none; box-shadow: var(--ring);
}

/* ---------- Indication de départ + erreur ---------- */
.v3d-hint {
  position: fixed; z-index: 4; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--s-5) + env(safe-area-inset-bottom, 0px));
  margin: 0; padding: var(--s-2) var(--s-4);
  border-radius: var(--r-pill); font-size: var(--fz-sm); font-weight: 600;
  white-space: nowrap; pointer-events: none;
  transition: opacity var(--dur-3) var(--ease-out);
}
.v3d-hint.gone { opacity: 0; }
.v3d-error {
  position: fixed; z-index: 9; inset: 0; margin: auto;
  width: min(420px, calc(100vw - 2 * var(--s-4))); height: fit-content;
  padding: var(--s-5); border-radius: var(--r-card);
  text-align: center; line-height: var(--lh-base); color: var(--n-800);
}
.v3d-error a { color: var(--brand); font-weight: 700; }

/* Contrôles MapLibre : remontés sous le bandeau, à droite */
.maplibregl-ctrl-top-right { top: calc(var(--s-3) + env(safe-area-inset-top, 0px)); right: var(--s-1); }
.maplibregl-ctrl-group { border-radius: var(--r-ctl) !important; box-shadow: var(--e2) !important; }
.maplibregl-canvas { outline: none; }
.maplibregl-canvas-container.v3d-pointer .maplibregl-canvas { cursor: pointer; }

/* ---------- Téléphone (portrait) ----------
   Écran étroit : bandeau réduit à l'essentiel (retour, heure, nombre de bus), commandes
   en barre horizontale en bas, fiche du bus compacte posée juste au-dessus. La carte
   garde ainsi plus de la moitié de l'écran, et le bus suivi reste visible (view3d.js
   décale le centre de la caméra de la hauteur de la fiche). */
@media (max-width: 600px) {
  .v3d-hud { right: 60px; gap: var(--s-2); padding: 6px var(--s-3) 6px 6px; }
  .v3d-back span, .v3d-date, .v3d-sun { display: none; }
  .v3d-back { padding: var(--s-2); }
  .v3d-time { font-size: var(--fz-md); }
  .v3d-state { font-size: var(--fz-xs); min-width: 0; }
  #v3d-count { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .v3d-tools {
    left: var(--s-3); right: var(--s-3);
    bottom: calc(var(--s-3) + env(safe-area-inset-bottom, 0px));
    flex-direction: row;
  }
  .v3d-tool {
    flex: 1; width: auto; height: 44px; padding: 0;
    flex-direction: row; justify-content: center; gap: 6px; font-size: 12px;
  }
  .v3d-tool svg { width: 18px; height: 18px; flex: none; }

  .v3d-panel {
    left: var(--s-3); right: var(--s-3); width: auto;
    bottom: calc(var(--s-3) + 44px + var(--s-2) + env(safe-area-inset-bottom, 0px));
    padding: var(--s-2) var(--s-3) var(--s-3);
  }
  .v3d-info { margin: 6px 0 var(--s-2); display: flex; flex-wrap: wrap; gap: 2px var(--s-3); }
  .v3d-info .muted { display: none; }
  .v3d-act { padding: var(--s-2); }
  .v3d-x { width: 30px; height: 30px; }

  .v3d-hint {
    left: var(--s-3); right: var(--s-3); transform: none; text-align: center; white-space: normal;
    bottom: calc(var(--s-3) + 44px + var(--s-3) + env(safe-area-inset-bottom, 0px));
  }
  /* Crédits (bouton « i ») : sous le bandeau, pour ne pas passer sous les commandes. */
  .maplibregl-ctrl-bottom-left { bottom: auto; top: calc(62px + env(safe-area-inset-top, 0px)); }
}

/* ---------- Téléphone couché (peu de hauteur) ---------- */
@media (max-height: 480px) and (min-width: 601px) {
  .v3d-date, .v3d-sun, .v3d-hint { display: none; }
  .v3d-hud { padding: 6px var(--s-3) 6px 6px; }
  .v3d-time { font-size: var(--fz-md); }
  .v3d-tools { flex-direction: row; bottom: calc(var(--s-2) + env(safe-area-inset-bottom, 0px)); }
  .v3d-tool { width: 56px; padding: 6px 0 4px; }
  .v3d-panel {
    width: min(300px, 42vw); padding: var(--s-2) var(--s-3) var(--s-3);
    bottom: calc(var(--s-2) + env(safe-area-inset-bottom, 0px));
  }
  .v3d-info { margin: 6px 0 var(--s-2); }
  .v3d-info .muted { display: none; }
  .v3d-act { padding: var(--s-2); font-size: var(--fz-xs); }
  .maplibregl-ctrl-bottom-left { bottom: auto; top: calc(56px + env(safe-area-inset-top, 0px)); }
}
@media (prefers-reduced-motion: reduce) {
  .v3d-dot.live, .v3d-panel { animation: none; }
}
