/* ============================================
   STYLE.CSS — MANDRAGORA "Jugo De Diamantes"
   Feuille de styles principale du site

   Architecture : viewport sticky + scroll-driven animations.
   Tous les éléments sont empilés en position absolute dans le viewport.
   Leur visibilité est contrôlée par JavaScript via opacity/visibility.
   ============================================ */

/* --- RESET MINIMAL --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* --- VARIABLES CSS ---
   Valeurs par défaut — automatiquement écrasées par config.js au chargement.
   ⚠ Modifier les valeurs dans config.js, PAS ici. */
:root {
  --bg: #0A0A0A;
  --text: #E8E4DE;
  --accent: #8B1A1A;
  --letter: #FFFFFF;
  --topo: #373737;
  --topo-light: #4B4B4B;
  --font-display: 'Playfair Display', serif;
  --font-mono: 'Space Mono', monospace;
  --font-hand: 'Caveat', cursive;
  /* Table */
  --table-bg: #111111;
  /* Carte postale */
  --postcard-bg: #f5f0e8;
  --postcard-border: #d4cfc5;
  --postcard-divider: #c0b8a8;
  --postcard-text: #2a2a2a;
  --postcard-label: #888;
  --postcard-input: #1a1a1a;
  /* Scroll */
  --scroll-container-height: 375vh;
}

/* --- BASE ---
   IMPORTANT : pas de overflow-x: hidden sur html/body,
   sinon position: sticky est cassé dans certains navigateurs.
   Le viewport gère son propre overflow: hidden. */
html {
  background-color: var(--bg);
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- SCROLL CONTAINER ---
   Rail de scroll (375vh = -25% vs 500vh) — le scroll pilote les animations via ScrollTrigger */
#scroll-container {
  height: var(--scroll-container-height);
  overflow-x: clip;
}

/* --- VIEWPORT STICKY ---
   Reste collé en haut pendant que le scroll progresse.
   100dvh corrige le bug iOS Safari où 100vh inclut la barre d'adresse. */
#viewport {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  background-color: var(--bg);
}

/* --- GRAIN FILMIQUE ---
   Overlay permanent, animé, subtil — ne bloque pas les interactions */
#viewport::after {
  content: "";
  position: absolute;
  inset: -20%;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-size: 128px 128px;
  animation: grain 0.5s steps(6) infinite;
  will-change: transform;
}

@keyframes grain {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-5%, -10%); }
  20% { transform: translate(-15%, 5%); }
  30% { transform: translate(7%, -15%); }
  40% { transform: translate(-5%, 15%); }
  50% { transform: translate(-15%, 10%); }
  60% { transform: translate(15%, 0%); }
  70% { transform: translate(0%, 10%); }
  80% { transform: translate(3%, -15%); }
  90% { transform: translate(-10%, 5%); }
}

/* --- CURSEUR CUSTOM (desktop uniquement) ---
   Réticule rouge SVG */
@media (hover: hover) {
  body {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cline x1='12' y1='2' x2='12' y2='10' stroke='%238B1A1A' stroke-width='1'/%3E%3Cline x1='12' y1='14' x2='12' y2='22' stroke='%238B1A1A' stroke-width='1'/%3E%3Cline x1='2' y1='12' x2='10' y2='12' stroke='%238B1A1A' stroke-width='1'/%3E%3Cline x1='14' y1='12' x2='22' y2='12' stroke='%238B1A1A' stroke-width='1'/%3E%3Ccircle cx='12' cy='12' r='3' fill='none' stroke='%238B1A1A' stroke-width='0.5'/%3E%3C/svg%3E") 12 12, crosshair;
  }
  button, a, input, textarea, select, label { cursor: pointer; }
  input, textarea { cursor: text; }
}

/* --- TOGGLES (langue et audio) ---
   Fixés au-dessus de tout, style discret */
#lang-toggle,
#audio-toggle {
  position: fixed;
  z-index: 10000;
  top: 20px;
  background: none;
  border: 1px solid var(--text);
  border-radius: 0;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 6px 12px;
  opacity: 0.4;
  transition: opacity 0.3s ease;
  touch-action: manipulation;
}

#lang-toggle:hover,
#audio-toggle:hover {
  opacity: 1;
}

#lang-toggle { left: 20px; }
#audio-toggle { right: 20px; }


/* ============================================
   PHASE 1 — INTRO (typewriter)
   ============================================ */

#phase-intro {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10%;
  z-index: 20;
  background-color: var(--bg);
}

#intro-text {
  font-family: var(--font-mono);
  font-size: clamp(16px, 3vw, 22px);
  letter-spacing: 1px;
  line-height: 1.6;
  position: relative;
  display: inline-block;
}

#intro-text .char {
  opacity: 0;
  display: inline-block;
}

#intro-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background-color: var(--text);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursorBlink 1s steps(1) infinite;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}


/* ============================================
   PHASE 2 — CARTE TOPOGRAPHIQUE + LETTRE + TEXTES NARRATIFS
   ============================================ */

/* Canvas topographique — couvre tout le viewport */
#topo-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  opacity: 0;
  visibility: hidden;
}

/* Fond table (phase 3-4) — apparaît progressivement */
#table-bg {
  position: absolute;
  inset: 0;
  z-index: 2;
  background-color: var(--table-bg);
  /* Grain de texture subtil sur la table */
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 64 64' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.5' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  background-size: 64px 64px;
  opacity: 0;
  visibility: hidden;
}

/* La lettre — UN SEUL élément qui traverse toutes les phases.
   Conteneur 3D : perspective ici, flip via #postcard-inner.
   Pendant les phases 2-3, carte.jpeg est visible (face avant).
   En phase 4, le flip révèle le formulaire (face arrière). */
#letter {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 50px;
  background: transparent;
  border: none;
  border-radius: 4px;
  z-index: 18;
  opacity: 0;
  visibility: hidden;
  will-change: transform, width, height, opacity;
  perspective: 1200px;
}

/* Textes narratifs du voyage — z-index supérieur à la lettre (18) */
#journey-texts {
  position: absolute;
  inset: 0;
  z-index: 19;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}

#journey-texts .journey-text {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text);
  opacity: 0;
  max-width: 340px;
  line-height: 1.7;
  clip-path: inset(0 100% 0 0);
  white-space: pre-line;
}

/* Positionnement varié des 4 blocs de paroles */
#journey-texts .journey-text:nth-child(1) {
  left: 8%;
  top: 25%;
}

#journey-texts .journey-text:nth-child(2) {
  right: 8%;
  top: 35%;
  text-align: right;
}

#journey-texts .journey-text:nth-child(3) {
  left: 8%;
  top: 55%;
}

#journey-texts .journey-text:nth-child(4) {
  right: 8%;
  top: 30%;
  text-align: right;
}

/* Diamants lumineux (étoiles filantes) */
#light-points-container {
  position: absolute;
  inset: 0;
  z-index: 11;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}

/* Diamant étoile filante — image diamant.png rendue blanche via filter */
.light-point {
  position: absolute;
  width: 18px;
  height: 18px;
  background-image: url('../assets/images/diamant.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  /* PNG noir → rendu blanc/gris clair */
  filter: brightness(0) invert(1);
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
  transform: translate(-50%, -50%);
}

/* Traînée du diamant — direction fixe via --trail-angle, définie au spawn */
.light-point::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 1px;
  background: linear-gradient(to left, rgba(255,255,255,0.8), transparent);
  transform-origin: 0% 50%;
  transform: translate(0, -50%) rotate(var(--trail-angle, 180deg));
  opacity: 0.5;
}


/* ============================================
   PHASE 3 — ARRIVÉE (texte d'arrivée)
   ============================================ */

#arrival-text {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: clamp(14px, 2.5vw, 20px);
  letter-spacing: 1px;
  color: var(--text);
  opacity: 0;
  text-align: center;
  max-width: 80%;
  z-index: 16;
  pointer-events: none;
  white-space: pre-line;
}


/* ============================================
   PHASE 4 — FORMULAIRE CARTE POSTALE
   Le flip 3D se fait directement dans #letter via #postcard-inner.
   Plus besoin d'un élément #postcard séparé.
   ============================================ */

/* Conteneur interne — flip 3D (enfant de #letter) */
#postcard-inner {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 1.2s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 4px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

/* Quand la carte est retournée — classe sur #letter */
#letter.flipped #postcard-inner {
  transform: rotateY(180deg);
}

/* Faces avant et arrière — backface caché */
#postcard-front,
#postcard-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 4px;
  overflow: hidden;
}

/* --- FACE AVANT (carte.jpeg) --- */
#postcard-front {
  background-image: url('../assets/images/carte.jpeg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border: none;
}

/* --- FACE ARRIÈRE (formulaire carte postale) --- */
#postcard-back {
  background: var(--postcard-bg);
  border: 1px solid var(--postcard-border);
  transform: rotateY(180deg);
  display: flex;
  flex-direction: row;
}

/* Ligne verticale séparatrice */
#postcard-line-divider {
  position: absolute;
  top: 8%;
  bottom: 8%;
  left: 50%;
  width: 1px;
  background-color: var(--postcard-divider);
}

/* Moitié gauche — message décoratif */
#postcard-left {
  width: 50%;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#postcard-message {
  font-family: var(--font-hand);
  font-size: clamp(16px, 2.5vw, 22px);
  color: var(--postcard-text);
  text-align: center;
  line-height: 1.6;
}

/* Moitié droite — formulaire */
#postcard-right {
  width: 50%;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  position: relative;
}

/* Timbre face arrière */
#postcard-stamp-back {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 42px;
  border: 1.5px dashed var(--postcard-divider);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--postcard-divider);
}

/* Champs du formulaire */
#postcard-form .form-field {
  position: relative;
  margin-bottom: 2px;
}

#postcard-form .form-field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--postcard-label);
  margin-bottom: 1px;
}

#postcard-form .form-field input {
  width: 100%;
  border: none;
  border-bottom: 1px dashed var(--postcard-divider);
  background: transparent;
  font-family: var(--font-hand);
  font-size: clamp(14px, 2vw, 18px);
  color: var(--postcard-input);
  padding: 4px 0;
  outline: none;
  transition: border-color 0.3s ease;
  border-radius: 0;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

#postcard-form .form-field input:focus {
  border-bottom-style: solid;
  border-bottom-color: var(--postcard-input);
}

#postcard-form .form-field input::placeholder {
  color: var(--postcard-divider);
  font-family: var(--font-hand);
}

/* Champ en erreur */
#postcard-form .form-field.field-error input {
  border-bottom-color: var(--accent);
  border-bottom-style: solid;
}

/* Bouton envoi */
#submit-btn {
  margin-top: 8px;
  padding: 8px 24px;
  background: none;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
  cursor: pointer;
  align-self: flex-end;
  transition: background-color 0.3s ease, color 0.3s ease, transform 0.15s ease;
  position: relative;
  overflow: hidden;
}

#submit-btn:hover {
  background-color: var(--accent);
  color: var(--letter);
  transform: scale(1.02);
}

#submit-btn:active {
  transform: scale(0.98);
}

#submit-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* État loading du bouton */
#submit-btn.loading {
  pointer-events: none;
  color: transparent;
}

#submit-btn.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}


/* ============================================
   PHASE 5 — CONFIRMATION
   ============================================ */

#phase-confirmation {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 0 10%;
  z-index: 20;
  opacity: 0;
  visibility: hidden;
}

#confirmation-text {
  font-family: var(--font-mono);
  font-size: clamp(18px, 3.5vw, 28px);
  color: var(--text);
  letter-spacing: 2px;
  text-align: center;
  opacity: 0;
}

#tracking-number {
  font-family: var(--font-mono);
  font-size: clamp(11px, 1.5vw, 14px);
  color: var(--text);
  opacity: 0;
  letter-spacing: 3px;
}

#confirmation-buttons {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  opacity: 0;
}

#presave-btn,
#share-btn {
  display: inline-block;
  padding: 10px 28px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
  text-decoration: none;
  border: 1px solid var(--text);
  color: var(--text);
  background: none;
  transition: background-color 0.3s ease, color 0.3s ease;
  cursor: pointer;
}

#presave-btn:hover,
#share-btn:hover {
  background-color: var(--text);
  color: var(--bg);
}


/* ============================================
   MESSAGE D'ERREUR FORMULAIRE
   ============================================ */

.form-error-msg {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--accent);
  text-align: right;
  margin-top: 4px;
  letter-spacing: 1px;
  animation: fadeInError 0.3s ease;
}

@keyframes fadeInError {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Feedback copie */
#share-btn.copy-success {
  border-color: var(--text);
  opacity: 0.7;
}


/* ============================================
   ACCESSIBILITÉ
   ============================================ */

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

*:focus {
  outline: none;
}


/* ============================================
   RESPONSIVE
   ============================================ */

/* ============================================
   TABLETTE (768px — 1024px)
   ============================================ */

@media (max-width: 1024px) and (min-width: 768px) {
  /* #letter dimensions gérées par JS (responsive breakpoints) */

  #journey-texts .journey-text {
    font-size: 13px;
    max-width: 260px;
  }

  #postcard-form .form-field label {
    font-size: 8px;
  }

  #postcard-form .form-field input {
    font-size: 15px;
    padding: 3px 0;
  }

  #submit-btn {
    padding: 7px 20px;
    font-size: 10px;
  }
}

/* ============================================
   MOBILE (< 768px)
   ============================================ */

@media (max-width: 767px) {
  /* Lettre plus petite sur mobile */
  #letter {
    width: 60px;
    height: 40px;
  }

  /* Textes narratifs plus petits et mieux positionnés pour ne pas chevaucher la carte */
  #journey-texts .journey-text {
    font-size: 11px;
    max-width: 170px;
    line-height: 1.5;
  }

  /* Repositionner les textes pour dégager le centre (carte qui grossit) */
  #journey-texts .journey-text:nth-child(1) {
    left: 5%;
    top: 10%;
  }

  #journey-texts .journey-text:nth-child(2) {
    right: 5%;
    top: 12%;
    left: auto;
  }

  #journey-texts .journey-text:nth-child(3) {
    left: 5%;
    top: 78%;
  }

  #journey-texts .journey-text:nth-child(4) {
    right: 5%;
    top: 10%;
    left: auto;
  }

  /* Texte d'arrivée — au-dessus de la carte, pas dessous */
  #arrival-text {
    top: 5%;
    font-size: clamp(12px, 3vw, 16px);
  }

  /* #letter dimensions gérées par JS (responsive breakpoints) */

  /* Face arrière en colonne */
  #postcard-back {
    flex-direction: column;
  }

  /* Séparateur horizontal au lieu de vertical */
  #postcard-line-divider {
    top: auto;
    bottom: auto;
    left: 8%;
    right: 8%;
    width: auto;
    height: 1px;
    position: relative;
    margin: 4px 0;
  }

  #postcard-left,
  #postcard-right {
    width: 100%;
    padding: 10px 14px;
  }

  #postcard-left {
    min-height: 60px;
    padding: 8px 14px;
  }

  #postcard-message {
    font-size: clamp(14px, 3.5vw, 18px);
    line-height: 1.4;
  }

  /* Formulaire compact */
  #postcard-right {
    gap: 3px;
    justify-content: flex-start;
    padding-top: 8px;
  }

  #postcard-form .form-field {
    margin-bottom: 1px;
  }

  #postcard-form .form-field label {
    font-size: 8px;
    letter-spacing: 1px;
    margin-bottom: 0;
  }

  #postcard-form .form-field input {
    font-size: clamp(13px, 3.5vw, 16px);
    padding: 3px 0;
  }

  /* Timbre plus petit */
  #postcard-stamp-back {
    width: 24px;
    height: 30px;
    font-size: 11px;
    top: 6px;
    right: 6px;
  }

  /* Bouton envoi compact */
  #submit-btn {
    margin-top: 6px;
    padding: 7px 18px;
    font-size: 10px;
    letter-spacing: 2px;
  }

  /* Phase 5 — boutons en colonne */
  #confirmation-buttons {
    flex-direction: column;
    align-items: center;
  }

  #presave-btn,
  #share-btn {
    padding: 8px 24px;
    font-size: 10px;
  }

  /* Toggles plus petits */
  #lang-toggle,
  #audio-toggle {
    font-size: 9px;
    padding: 4px 8px;
    top: 12px;
  }
  #lang-toggle { left: 12px; }
  #audio-toggle { right: 12px; }
}

/* ============================================
   TRÈS PETITS ÉCRANS (< 375px — iPhone SE, etc.)
   ============================================ */

@media (max-width: 374px) {
  /* #letter dimensions gérées par JS (responsive breakpoints) */

  #postcard-left {
    min-height: 50px;
    padding: 6px 10px;
  }

  #postcard-message {
    font-size: 13px;
  }

  #postcard-right {
    padding: 6px 10px;
    gap: 2px;
  }

  #postcard-form .form-field input {
    font-size: 13px;
    padding: 2px 0;
  }

  #submit-btn {
    padding: 5px 14px;
    font-size: 9px;
    margin-top: 4px;
  }

  #journey-texts .journey-text {
    font-size: 11px;
    max-width: 150px;
  }

  #intro-text {
    font-size: 14px;
  }

  #confirmation-text {
    font-size: 16px;
  }
}

/* ============================================
   PAYSAGE MOBILE (court en hauteur)
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
  /* #letter dimensions gérées par JS (responsive breakpoints) */

  #postcard-back {
    flex-direction: row;
  }

  #postcard-line-divider {
    position: absolute;
    top: 8%;
    bottom: 8%;
    left: 50%;
    width: 1px;
    height: auto;
    margin: 0;
  }

  #postcard-left,
  #postcard-right {
    width: 50%;
    padding: 8px 12px;
  }

  #postcard-left {
    min-height: auto;
  }

  #postcard-form .form-field input {
    font-size: 13px;
    padding: 2px 0;
  }

  #submit-btn {
    padding: 4px 14px;
    font-size: 9px;
    margin-top: 4px;
  }

  /* Texte d'arrivée en haut */
  #arrival-text {
    top: 4%;
    font-size: 13px;
  }

  #journey-texts .journey-text {
    font-size: 11px;
    max-width: 160px;
  }
}
