/* ============================================================================
 * style.css — Intro interactive : taquin du logo → explosion de fumée numérique
 * ============================================================================
 * Sommaire
 *   1. Variables à personnaliser (logo, point d'ancrage, vitesses…)
 *   2. Base
 *   3. Écran du taquin (barre, plateau, cases)
 *   4. Point d'ancrage (« emitter »)
 *   5. Canvas des particules
 *   6. Site visibility
 *   7. Accessibilité / mouvement réduit
 * ========================================================================== */


/* ----------------------------------------------------------------------------
 * 1. VARIABLES À PERSONNALISER
 * -------------------------------------------------------------------------- */
.intro {
  /* --- LOGO ---------------------------------------------------------------
   * Chemin de l'image du taquin. Remplace par ton propre fichier.
   * Pour tester avec une image quelconque (placeholder), décommente :
   *   --logo-url: url("https://picsum.photos/900");
   */
  --logo-url: url("../assets/logo-lamp-network-android-chrome-512x512.png");

  /* Rapport largeur / hauteur de l'image (1 = carrée). Ex. 16 / 9 pour un
   * logo panoramique. Le plateau et les cases s'adaptent automatiquement. */
  --board-ratio: 1;

  /* --- POINT D'ANCRAGE DE L'EXPLOSION -------------------------------------
   * Coordonnées en % DANS le logo (0% 0% = coin haut-gauche de l'image).
   * Valeurs actuelles = centre du circuit imprimé du logo 1T1IS.
   *
   * Autre préréglage possible : le bec de la lampe, d'où « sort » le circuit
   *   --emitter-x: 74.2%;   --emitter-y: 43.2%;
   *
   * Astuce : ouvre index.html?debug pour voir le point et le déplacer
   * à l'œil en modifiant ces deux valeurs.
   */
  --emitter-x: 63.5%;
  --emitter-y: 31.6%;

  /* --- ANIMATIONS --------------------------------------------------------- */
  --slide-ms: 170ms;         /* durée du glissement d'une case */
  --site-fade-ms: 1000ms;    /* durée du fondu d'apparition du site */
  /* NB : la durée de l'explosion se règle dans app.js (CONFIG.fx). */

  /* --- TAILLE DU PLATEAU ---------------------------------------------------
   * Le plus petit de : 92 % de la largeur, la hauteur restante, 680 px. */
  --board-size: min(92vw, calc((100vh - 210px) * var(--board-ratio)), 680px);

  /* --- COULEURS (issues du logo) ------------------------------------------ */
  --bg: #000;
  --ink: #e9fffb;
  --muted: #7ea6a0;
  --teal: #12d1b0;
  --teal-bright: #7ff8e8;
  --gold: #c9a54d;

  /* --- POLICES (système uniquement : aucune dépendance, chargement instantané) */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* dvh = hauteur réellement visible sur mobile (barre d'adresse comprise) */
@supports (height: 100dvh) {
  .intro { --board-size: min(92vw, calc((100dvh - 210px) * var(--board-ratio)), 680px); }
}


/* ----------------------------------------------------------------------------
 * 2. BASE
 * -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

.intro {
  font-family: var(--font-ui);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Pendant l'intro : pas de scroll (retiré par app.js à la fin de la transition) */
html.is-intro, html.is-intro body { overflow: hidden; height: 100%; }


/* ----------------------------------------------------------------------------
 * 3. ÉCRAN DU TAQUIN
 * -------------------------------------------------------------------------- */
.intro {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  color: var(--ink);
  background:
    radial-gradient(60% 45% at 50% 42%, rgba(18, 209, 176, .07), transparent 70%),
    var(--bg);
}
.intro.is-hidden { display: none; }       /* masqué par app.js quand l'écran est saturé */

/* --- Barre du haut ------------------------------------------------------- */
.intro__bar {
  width: var(--board-size);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
}
.intro__title {
  margin: 0;
  font-family: var(--font-mono);
  font-size: .95rem;
  letter-spacing: .02em;
  color: var(--teal-bright);
}
.intro__tools { display: flex; flex-wrap: wrap; gap: 6px; }

/* Petits boutons « pastille » */
.chip {
  appearance: none;
  font: inherit;
  font-family: var(--font-mono);
  font-size: .78rem;
  line-height: 1;
  padding: 8px 11px;
  color: var(--teal-bright);
  background: transparent;
  border: 1px solid rgba(18, 209, 176, .38);
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .15s, color .15s, border-color .15s;
}
.chip:hover { border-color: var(--teal); background: rgba(18, 209, 176, .1); }
.chip:focus-visible { outline: 2px solid var(--teal-bright); outline-offset: 2px; }
.chip[aria-pressed="true"] { background: var(--teal); border-color: var(--teal); color: #031210; }
.game-language { width: auto; padding-right: 24px; }
.chip--debug { display: none; border-style: dashed; color: var(--gold); border-color: var(--gold); }
html.debug .chip--debug { display: inline-block; }

/* --- Plateau ------------------------------------------------------------- */
.board-wrap { flex: 1 1 auto; display: grid; place-items: center; min-height: 0; }

.board {
  --n: 6;                                  /* nombre de cases par côté (écrit par app.js) */
  position: relative;
  width: var(--board-size);
  aspect-ratio: var(--board-ratio);
  background: #030606;
  border-radius: 6px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(18, 209, 176, .35),
    0 0 70px rgba(18, 209, 176, .12);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/*
 * UNE CASE
 * - Taille = 1/n du plateau.
 * - Position = transform: translate3d(...) calculé depuis --col / --row.
 *   (transform = animation GPU, fluide même sur mobile ; les % d'un translate
 *   se rapportent à la taille de la case elle-même.)
 * - Image = le logo, agrandi n fois, décalé avec background-position pour
 *   n'en montrer que la bonne portion (--cx / --cy = case d'origine).
 */
.tile {
  --col: 0; --row: 0;                      /* position actuelle (écrite par app.js) */
  --cx: 0;  --cy: 0;                       /* position d'origine dans l'image       */
  position: absolute;
  left: 0; top: 0;
  width: calc(100% / var(--n));
  height: calc(100% / var(--n));
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  will-change: transform;
  transform: translate3d(calc(var(--col) * 100%), calc(var(--row) * 100%), 0);
  transition: transform var(--slide-ms) cubic-bezier(.25, .8, .25, 1);

  background-color: #040808;
  background-image: var(--logo-url);
  background-repeat: no-repeat;
  background-size: calc(var(--n) * 100%) calc(var(--n) * 100%);
  background-position:
    calc(var(--cx) / (var(--n) - 1) * 100%)
    calc(var(--cy) / (var(--n) - 1) * 100%);

  /* fin liseré qui dessine la grille tant que le jeu n'est pas fini */
  box-shadow: inset 0 0 0 1px rgba(18, 209, 176, .16);
  color: var(--teal);
}
@media (hover: hover) {
  .tile:hover { filter: brightness(1.25); }
}
.tile:focus-visible { outline: 2px solid var(--teal-bright); outline-offset: -2px; z-index: 2; }

/* Numéro de la case : indispensable car le logo contient de grandes zones
 * noires (cases identiques). Désactivable avec le bouton « n° ». */
.tile__num {
  position: absolute;
  left: 4px; top: 3px;
  font-family: var(--font-mono);
  font-size: max(8px, calc(var(--board-size) / var(--n) * .2));
  line-height: 1;
  color: var(--teal-bright);
  opacity: .5;
  text-shadow: 0 0 4px #000, 0 0 2px #000;
  pointer-events: none;
  transition: opacity .3s;
}
.board.hide-numbers .tile__num { opacity: 0; }

/* La dernière case (celle qui manque) : invisible jusqu'à la victoire */
.tile--last { opacity: 0; visibility: hidden; pointer-events: none; transition: transform var(--slide-ms), opacity .3s ease .05s, visibility 0s; }

/* Désactive les transitions (mélange instantané) */
.board.no-anim .tile { transition: none; }

/* Logo complet superposé : aperçu (maintenir « aperçu ») et victoire.
 * Il masque aussi les micro-jointures entre cases une fois le puzzle fini. */
.board__full {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--logo-url) center / 100% 100% no-repeat;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s ease;
}
.board.show-preview .board__full { opacity: .96; }

/* État « résolu » : le jeu est bloqué, le logo se complète */
.board.is-solved { pointer-events: none; }
.board.is-solved .tile { box-shadow: none; filter: none; }
.board.is-solved .tile__num { opacity: 0; }
.board.is-solved .tile--last { opacity: 1; visibility: visible; }
.board.is-solved .board__full { opacity: 1; transition-duration: .5s; }

/* --- Pied de l'écran ----------------------------------------------------- */
.intro__foot {
  width: var(--board-size);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.intro__status { margin: 0; font-size: .82rem; color: var(--muted); font-family: var(--font-mono); }
.intro__status output { color: var(--teal-bright); }
.link {
  appearance: none; background: none; border: 0; padding: 4px 0;
  font: inherit; font-size: .82rem; color: var(--muted);
  text-decoration: underline; text-underline-offset: 3px;
  cursor: pointer;
}
.link:hover, .link:focus-visible { color: var(--ink); }

@media (max-width: 600px) {
  .intro {
    --board-size: min(92vw, calc((100vh - 300px) * var(--board-ratio)), 680px);
  }
  .intro__bar, .intro__foot {
    width: 100%;
    max-width: 680px;
  }
  @supports (height: 100dvh) {
    .intro {
      --board-size: min(92vw, calc((100dvh - 300px) * var(--board-ratio)), 680px);
    }
  }
  .intro__foot {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }
  .intro__status { text-align: center; }
  #btn-skip {
    align-self: flex-start;
    min-height: 44px;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid rgba(18, 209, 176, .38);
    border-radius: 6px;
  }
}


/* ----------------------------------------------------------------------------
 * 4. POINT D'ANCRAGE (« EMITTER »)
 * -------------------------------------------------------------------------- */
/* Sous-div absolue, placée en % dans le plateau (donc dans le logo).
 * app.js lit sa position à l'écran pour lancer les particules. */
.emitter {
  position: absolute;
  z-index: 3;
  left: var(--emitter-x);
  top: var(--emitter-y);
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
}
/* Mode ?debug : repère visible (croix + cercle) pour régler les coordonnées */
html.debug .emitter {
  opacity: 1;
  background: radial-gradient(circle, #fff 0 2px, rgba(255, 60, 120, .9) 3px, transparent 7px);
  outline: 1px dashed rgba(255, 255, 255, .8);
}
html.debug .emitter::before,
html.debug .emitter::after {
  content: ""; position: absolute; background: rgba(255, 255, 255, .55);
}
html.debug .emitter::before { left: 50%; top: -400px; width: 1px; height: 800px; }
html.debug .emitter::after  { top: 50%; left: -400px; height: 1px; width: 800px; }

/* Petite impulsion lumineuse au moment de la victoire */
.emitter.is-firing { opacity: 1; background: radial-gradient(circle, #fff 0 25%, var(--teal-bright) 45%, transparent 70%); animation: pulse .5s ease-out forwards; }
@keyframes pulse { from { transform: scale(.6); opacity: 1; } to { transform: scale(9); opacity: 0; } }


/* ----------------------------------------------------------------------------
 * 5. CANVAS DES PARTICULES
 * -------------------------------------------------------------------------- */
/* Plein écran, au-dessus de tout. Affiché seulement pendant la transition. */
.fx {
  display: none;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 100;
  pointer-events: none;
}
@supports (height: 100dvh) { .fx { height: 100dvh; } }


/* ----------------------------------------------------------------------------
 * 6. EXISTING SITE VISIBILITY
 * -------------------------------------------------------------------------- */
#site {
  --site-fade-ms: 1000ms;
  visibility: hidden;
  opacity: 0;
  transition: opacity var(--site-fade-ms) ease;
}
#site.is-visible {
  visibility: visible;
  opacity: 1;
}


/* ----------------------------------------------------------------------------
 * 7. ACCESSIBILITÉ / MOUVEMENT RÉDUIT
 * -------------------------------------------------------------------------- */
/* Pour les personnes qui demandent moins d'animations : app.js remplace
 * l'explosion par un simple fondu ; on raccourcit aussi les glissements. */
@media (prefers-reduced-motion: reduce) {
  .intro { --slide-ms: 1ms; --site-fade-ms: 400ms; }
  #site { --site-fade-ms: 400ms; }
  .emitter.is-firing { animation: none; }
}
