:root {
  --bg: #05070f;
  --fg: #f2f5fb;
  --accent: #4fd1ff;
  --panel-bg: rgba(6, 10, 24, 0.65);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

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

#multivers-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #05070f;
  padding: 0.5rem 1rem;
  z-index: 100;
  border-radius: 0 0 0.4rem 0;
}
.skip-link:focus {
  left: 0;
}

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 1rem 1.25rem;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.5), transparent);
  pointer-events: none;
  z-index: 5;
}
#hud h1 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}
#ambiance-status {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  color: #cfe0ff;
}
#portal-caption {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: #e8f4ff;
  min-height: 1.1em;
  opacity: 0.9;
}

/* Barre du bas — regroupe navigation et contrôles, se fait discrète au repos. */
#bottom-bar {
  position: fixed;
  bottom: 0.85rem;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  transition: opacity 0.6s ease;
}
#bottom-bar.idle {
  opacity: 0.4;
}
#bottom-bar:hover,
#bottom-bar:focus-within {
  opacity: 1;
}

.portal-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-width: min(94vw, 760px);
  justify-content: center;
  padding: 0.4rem;
  background: var(--panel-bg);
  border-radius: 0.9rem;
  backdrop-filter: blur(6px);
}

.portal-btn {
  --portal-color: var(--accent);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.65rem;
  border-radius: 0.65rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: var(--fg);
  font-size: 0.78rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.portal-btn:hover {
  background: rgba(255, 255, 255, 0.13);
  transform: translateY(-2px);
}
.portal-btn:focus-visible {
  outline: 2px solid var(--portal-color);
  outline-offset: 2px;
}
.portal-btn[aria-current="true"] {
  border-color: var(--portal-color);
}
.portal-icon {
  font-size: 0.95rem;
}

#controls {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

#motion-toggle,
#legacy-link {
  padding: 0.35rem 0.7rem;
  border-radius: 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: var(--panel-bg);
  color: var(--fg);
  font-size: 0.72rem;
  text-decoration: none;
  cursor: pointer;
}
#motion-toggle:disabled {
  opacity: 0.5;
  cursor: default;
}
#motion-toggle:focus-visible,
#legacy-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Téléportation vers le Terrain 3D — coin haut-droit, indépendante de #bottom-bar
   (donc jamais affectée par son fondu d'inactivité, .idle). Marge fixe en rem, comme
   #bottom-bar juste au-dessus, plutôt que env(safe-area-inset-*) : cette page n'a pas
   viewport-fit=cover (contrairement à index.html à la racine) et n'en a jamais eu
   besoin sur iPad réel (validations du 2026-08-30/09-17) ; ajouter cover ici changerait
   le comportement d'autres éléments (#hud) sans nécessité pour ce bouton. z-index sous
   #portal-panel (20), au même niveau que #hud/#bottom-bar (5) : se cache derrière le
   panneau ouvert comme le reste de l'interface. */
.teleport-link {
  position: fixed;
  top: 0.85rem;
  right: 0.85rem;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  min-width: 44px;
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: var(--panel-bg);
  color: var(--fg);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  backdrop-filter: blur(6px);
  touch-action: manipulation;
}

.teleport-link:hover {
  background: rgba(255, 255, 255, 0.13);
}

.teleport-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.teleport-icon {
  font-size: 1.05rem;
  line-height: 1;
}

.fallback-sky {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
  transition: background 2s ease;
}
.fallback-core {
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  background: radial-gradient(circle, #eafcff, var(--accent) 60%, transparent 70%);
  box-shadow: 0 0 40px var(--accent);
}
.fallback-note {
  max-width: 26rem;
  text-align: center;
  padding: 0 1rem;
  font-size: 0.9rem;
  color: #dce8ff;
}

.fatal-error {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}
.fatal-error a {
  color: var(--accent);
}

/* Panneau de confirmation de portail (v0.5) — nom, description, entrée dans l'univers. */
.portal-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
/* L'attribut HTML `hidden` n'a que la priorité d'une règle user-agent normale
   ([hidden] { display: none; }) — une règle auteur normale comme .portal-panel
   { display: flex; } ci-dessus la bat toujours dans la cascade CSS, peu importe
   la spécificité du sélecteur. Sans cette règle explicite, le panneau restait
   display:flex en permanence dès le chargement de la page (backdrop + boîte vide
   couvrant tout l'écran, pointer-events actif) : confirmé par un test Chromium/
   Playwright réel sur agentvirtuel.ca/multivers/ le 2026-08-25, y compris
   l'échec de clic Playwright sur .portal-btn (« intercepted by another element »)
   — cause racine du "rien ne se passe au toucher" sur Safari iPad. */
.portal-panel[hidden] {
  display: none;
}
.portal-panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 4, 12, 0.72);
}
.portal-panel-box {
  position: relative;
  max-width: 26rem;
  width: 100%;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #0a0f22;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 1rem;
  padding: 1.5rem 1.5rem 1.25rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.portal-panel-box h2 {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
}
.portal-panel-box p {
  margin: 0 0 1.1rem;
  font-size: 0.9rem;
  color: #cfe0ff;
  line-height: 1.5;
}
.portal-panel-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  /* #portal-panel-content porte un z-index:2 en ligne (index.html, ronde de diagnostic
     du 24-25 août) ; sans z-index explicite ici, ce bouton reste en z-index:auto et le
     titre (large, à droite) passe visuellement par-dessus lui et intercepte le clic —
     confirmé par un test Playwright réel le 2026-08-25 (bouton close inactionnable). */
  z-index: 3;
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.4rem;
}
.portal-panel-close:hover {
  background: rgba(255, 255, 255, 0.1);
}
.portal-panel-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.portal-panel-actions {
  display: flex;
  justify-content: flex-end;
}
.portal-panel-enter {
  padding: 0.6rem 1.1rem;
  border-radius: 0.6rem;
  border: none;
  background: var(--accent);
  color: #05070f;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
.portal-panel-enter:hover {
  filter: brightness(1.1);
}
.portal-panel-enter:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}
.portal-panel-soon {
  margin: 0 !important;
  color: #8fa0d0 !important;
  font-size: 0.85rem !important;
  font-style: italic;
}

/* Transition légère avant de quitter le hub vers un univers construit. */
body.transition-out {
  animation: multivers-fade-out 0.38s ease forwards;
}
@keyframes multivers-fade-out {
  to {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .portal-btn,
  #bottom-bar,
  .fallback-sky {
    transition: none;
  }
  body.transition-out {
    animation: none;
  }
}

/* iPad / tablette en paysage */
@media (min-width: 900px) and (max-width: 1366px) and (orientation: landscape) {
  .portal-nav {
    max-width: min(90vw, 820px);
  }
}

/* Téléphone */
@media (max-width: 640px) {
  #hud {
    padding: 0.75rem 0.9rem;
  }
  #hud h1 {
    font-size: 0.95rem;
  }
  #ambiance-status,
  #portal-caption {
    font-size: 0.72rem;
  }
  .portal-label {
    display: none;
  }
  .portal-btn {
    padding: 0.5rem;
  }
  #bottom-bar {
    bottom: 0.5rem;
  }
}

/* Très petite hauteur (téléphone en paysage) — resserre encore la barre du bas */
@media (max-height: 420px) {
  #bottom-bar {
    bottom: 0.35rem;
    gap: 0.3rem;
  }
  .portal-nav {
    padding: 0.3rem;
  }
  .portal-btn {
    padding: 0.35rem 0.5rem;
  }
}
