/* ===========================================================================
   Wald Maâlam — galerie 3D immersive
   Feuille de base du MOTEUR : reset, variables de palette, écran de chargement,
   ancrages d'interface. L'habillage (hero, filtres, modale, formulaire) sera
   ajouté par-dessus ; rien ici ne doit préempter ces choix.
   Palette : catalog.md §7 — Typographies : catalog.md §8
   ========================================================================= */

/* --- 1. Variables ------------------------------------------------------- */

:root {
  /* Palette officielle (§7) */
  --paper: #e8e1d2;
  --ink: #211f1a;
  --olive: #6b6b45;
  --rust: #9b4030;
  --stone: #a79c8c;
  --walnut: #6b4226;
  --sand: #d8c79a;

  /* Couleurs de statut utilisées en dur sur le site source (§7) */
  --reserved-bg: #e8891c;
  --reserved-fg: #2a1b00;
  --reserved-arrow: #a85f0e;
  --sold-bg: #b3241c;
  --sold-fg: #fbeae8;
  --sold-arrow: #7a160f;
  --whatsapp: #25d366;
  --whatsapp-hover: #1ebe5a;
  --whatsapp-fg: #08380f;

  /* Fond de scène : la même teinte que le brouillard WebGL, pour qu'il n'y
     ait aucune couture entre le canvas et la page. */
  --scene-bg: #241e18;

  /* Typographies (§8) */
  --font-display: 'Fraunces', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial,
    sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);

  color-scheme: dark;
}

/* --- 2. Reset ----------------------------------------------------------- */

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

html,
body {
  margin: 0;
  padding: 0;
}

html {
  /* v3 — la caméra n'est plus pilotée par le défilement. En mode immersif tout
     le contenu est en position fixe : le document n'a donc aucune hauteur à
     défiler, et il n'y a rien à bloquer. On coupe seulement le rebond / le
     « tirer pour rafraîchir » qui, sur mobile, volerait le geste vertical au
     joystick de marche. La vue grille de secours, elle, défile normalement :
     c'est du contenu HTML dans le flux. */
  background: var(--scene-bg);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  background: var(--scene-bg);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 500;
  margin: 0;
}

::selection {
  background: var(--rust);
  color: var(--paper);
}

img {
  max-width: 100%;
  display: block;
}

/* --- 3. Canvas de navigation -------------------------------------------- */

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  /* v3 — le canvas EST la surface de navigation : glisser pour regarder,
     joystick virtuel à gauche pour marcher. Le navigateur ne doit donc
     s'approprier aucun geste (ni défilement, ni pincement, ni pull-to-refresh),
     d'où `none` là où la v2 laissait `pan-y` au document. */
  touch-action: none;
  /* Un glisser-regarder ne doit jamais sélectionner de texte ni faire
     apparaître la loupe de sélection iOS. */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* --- 4. Couches d'interface --------------------------------------------- */

#ui-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

/* Les enfants directs qui doivent être cliquables réactivent les évènements. */
#ui-layer > * {
  pointer-events: auto;
}

/* --- 5. Écran de chargement --------------------------------------------- */

#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.6rem;
  padding: 2rem;
  background: radial-gradient(ellipse at 50% 42%, #2f2820 0%, #191510 72%, #120f0b 100%);
  opacity: 1;
  transition: opacity 0.75s var(--ease-out), visibility 0s linear 0.75s;
}

#loading-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--sand);
  opacity: 0.75;
  margin: 0;
}

.loading-title {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(1.9rem, 6vw, 3.1rem);
  letter-spacing: 0.01em;
  color: var(--paper);
  text-align: center;
}

.loading-subtitle {
  font-family: var(--font-display);
  font-weight: 500;
  font-style: italic;
  font-size: clamp(0.95rem, 2.4vw, 1.15rem);
  color: var(--sand);
  opacity: 0.72;
  margin: -0.9rem 0 0;
  text-align: center;
}

#loading-bar {
  position: relative;
  width: min(340px, 68vw);
  height: 2px;
  background: rgba(232, 225, 210, 0.16);
  overflow: hidden;
}

#loading-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, var(--walnut), var(--sand));
  transition: width 0.28s var(--ease-out);
}

.loading-meta {
  display: flex;
  gap: 1.1rem;
  align-items: baseline;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  color: var(--stone);
}

#loading-percent {
  color: var(--sand);
  font-variant-numeric: tabular-nums;
}

/* --- 6. Indicateur de progression (habillage à venir) ------------------- */

/* Emplacement réservé : structure minimale et lisible, volontairement sobre.
   Un agent d'interface peut remplacer entièrement le contenu de
   #progress-indicator — seuls ses `data-*` font contrat. */
#progress-indicator {
  position: fixed;
  right: clamp(0.85rem, 2.4vw, 1.9rem);
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  opacity: 0;
  transition: opacity 0.8s var(--ease-out) 0.25s;
  pointer-events: none;
  user-select: none;
}

#app-root.is-ready #progress-indicator {
  opacity: 1;
}

#progress-indicator .pi-track {
  position: relative;
  width: 2px;
  height: clamp(120px, 26vh, 220px);
  background: rgba(232, 225, 210, 0.18);
}

#progress-indicator .pi-fill {
  position: absolute;
  inset: 0 0 auto 0;
  height: 0%;
  background: var(--sand);
}

#progress-indicator .pi-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--sand);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
}

#progress-indicator .pi-count {
  color: var(--stone);
  opacity: 0.7;
}

@media (max-width: 640px) {
  #progress-indicator .pi-track {
    height: 90px;
  }
}

/* --- 6 bis. Indice de navigation et joystick tactile --------------------
   Deux éléments créés PAR LE MOTEUR dans #ui-layer (cf. contrat en tête de
   assets/js/main.js). L'indice est une légende, pas un dialogue : il ne prend
   jamais le focus, n'intercepte jamais le pointeur, et s'efface au premier
   geste ou après quelques secondes. */

#nav-hint {
  position: fixed;
  left: 50%;
  /* Décollé du bas de l'écran, et z-index au-dessus de la couche d'interface :
     tant que l'ancien `#scroll-hint` de ui.js (« faites défiler pour avancer »,
     devenu faux avec la v3 et à retirer par l'agent UI) occupe le tout-bas de
     l'écran avec un z-index de 35, les deux légendes ne doivent ni se
     superposer ni se masquer. */
  bottom: clamp(2.8rem, 9vh, 4.6rem);
  transform: translate(-50%, 0.6rem);
  z-index: 40;
  margin: 0;
  max-width: min(90vw, 34rem);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background: rgba(20, 17, 13, 0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(216, 199, 154, 0.16);
  font-family: var(--font-mono);
  font-size: clamp(0.6rem, 1.9vw, 0.7rem);
  letter-spacing: 0.06em;
  line-height: 1.5;
  text-align: center;
  color: var(--sand);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  user-select: none;
  transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out),
    visibility 0s linear 0.6s;
}

#nav-hint.is-visible {
  opacity: 0.92;
  visibility: visible;
  transform: translate(-50%, 0);
  transition-delay: 0s;
}

/* Joystick virtuel : son centre est posé là où le doigt s'est posé, dans la
   moitié gauche de l'écran. Il n'existe visuellement que pendant l'appui. */
#nav-stick {
  position: fixed;
  z-index: 20;
  width: 116px;
  height: 116px;
  margin: -58px 0 0 -58px;
  border-radius: 50%;
  border: 1px solid rgba(216, 199, 154, 0.34);
  background: rgba(20, 17, 13, 0.28);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s var(--ease-out), visibility 0s linear 0.18s;
}

#nav-stick.is-active {
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}

#nav-stick .nav-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(216, 199, 154, 0.62);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

/* Pas de requête média pour masquer le joystick sur poste à souris : il n'est
   rendu visible (`.is-active`) que pendant un appui de pointeur TACTILE dans
   la moitié gauche de l'écran. Les machines hybrides (portable à écran
   tactile) sont ainsi servies correctement, ce qu'une règle
   `(pointer: fine) { display: none }` aurait cassé. */

/* --- 7. Vue de secours (2D) — conteneur vide, à peupler ----------------- */

#fallback-grid {
  position: relative;
  z-index: 30;
  min-height: 100vh;
  padding: clamp(1rem, 4vw, 3rem);
  background: var(--paper);
  color: var(--ink);
}

#fallback-grid[hidden] {
  display: none;
}

#app-root.is-fallback #progress-indicator,
#app-root.is-fallback #nav-hint,
#app-root.is-fallback #nav-stick {
  display: none;
}

/* --- 8. Accessibilité --------------------------------------------------- */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  #loading-screen,
  #loading-bar-fill,
  #progress-indicator {
    transition-duration: 0.01ms;
  }
}
