/* Malkovich Ai Agency, motion de présentation.
   Palette de marque : encre #0A0A0A, ambre #F5A524 (la porte), blanc. */

:root {
  --bg: #0a0a0a;
  --bg-rgb: 10, 10, 10;
  --accent: #f5a524;
  --accent-rgb: 245, 165, 36;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-io: cubic-bezier(0.76, 0, 0.24, 1);
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  --card-w: 260px;
  --card-h: 340px;
  --card-gap: 38px; /* identique à CARD.gap dans engine.js */
  --k: 1; /* échelle de la scène, fixée par engine.js */
  --zoom: 1.1; /* grossissement des tuiles dans le plan */
  --ox: 0px; /* position du plan, fixée par engine.js */
  --oy: 0px;
  --tx: 0; /* inclinaison au pointeur, -1 à 1 */
  --ty: 0;

  --pad: clamp(20px, 5.4vw, 84px);
  --pad-top: clamp(20px, 4.6vh, 56px);
}

* { box-sizing: border-box; margin: 0; }

html { background: var(--bg); scroll-behavior: auto; }

body {
  background: var(--bg);
  color: #fff;
  overflow-x: clip;
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

img { user-select: none; -webkit-user-drag: none; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Le hero : un pavé haut (.pin, hauteur posée par pin.js) dans lequel la scène reste collée à l'écran
   pendant que le défilement change de chapitre. Aucun ancêtre ne doit avoir overflow hidden ou auto. */
.pin { position: relative; }

.stage {
  position: relative;
  height: var(--stage-h, 100svh);
  background: var(--bg);
  overflow: clip; /* clip, pas hidden : la focalisation d'un bouton ne doit pas faire défiler la scène */
  isolation: isolate;
  --dock: 0; /* 0 = le grand logo est au centre, 1 = il a rejoint la barre (posé par pin.js) */
}

/* ---------- Scène 3D ---------- */

.scene {
  position: absolute;
  inset: 0;
  perspective: calc(var(--k) * var(--persp, 1500px));
  perspective-origin: var(--persp-origin, 50% 38%);
}

.plane {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  transform:
    translate3d(var(--ox), var(--oy), 0)
    rotateX(calc(var(--rx, 48deg) + var(--ty) * var(--tilt-y, -4deg)))
    rotateZ(calc(var(--rz, 34deg) + var(--tx) * var(--tilt-x, 5deg)))
    scale(calc(var(--k) * var(--zoom)));
}

.scroller {
  position: absolute;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
  will-change: transform;
}

/* La caméra : elle descend d'un rail à l'autre à chaque chapitre (transform posé par engine.js). */
.camera.is-moving { transition: transform 1.9s cubic-bezier(0.65, 0, 0.35, 1); }

/* Un rail : une bande horizontale qui défile en continu, avec ses tuiles. L'origine est le centre de la bande. */
.rail {
  position: absolute;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
  will-change: transform;
}
.rail__band {
  position: absolute;
  background: rgba(255, 255, 255, 0.022);
  border-radius: 36px;
  pointer-events: none;
  transition: background 0.9s var(--ease-out);
}
.rail.is-active .rail__band { background: rgba(var(--accent-rgb), 0.07); }

/* ---------- Tuiles ---------- */

/* Toutes les tuiles sont dessinées à la taille « sortie du rang » (--tile-w x --tile-h, fixée par engine.js)
   et ramenées à la taille d'une petite tuile par --rest. Position de la case : --x, en pixels de plan.
   Pendant la sortie du rang, engine.js remplace ce transform par le sien (position et échelle). */
.card {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--tile-w, 558px);
  height: var(--tile-h, 718px);
  transform: translate3d(calc(var(--x) - var(--tile-w, 558px) / 2), calc(var(--tile-h, 718px) / -2), 0) scale(var(--rest, 0.466));
  transform-style: preserve-3d;
}

/* Une tuile conçue pour 260 x 340 qu'on affiche en grand : on agrandit tout son contenu d'un bloc. */
.scalebox {
  position: absolute;
  left: 0;
  top: 0;
  width: 260px;
  height: 340px;
  transform-origin: 0 0;
}

/* Tuiles de remplissage : photos du travail de l'agence, sur les rails décor. */
.fill img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.card__lift {
  position: absolute;
  inset: 0;
  transition: transform 0.8s var(--ease-out);
}

/* Rayon et ombre sont pensés pour la taille « sortie du rang » ; au repos, la tuile est réduite de moitié environ. */
.card__body {
  position: absolute;
  inset: 0;
  border-radius: 48px;
  overflow: hidden;
  background: #15181d;
  box-shadow: 0 60px 110px -34px rgba(0, 0, 0, 0.7);
  opacity: 0;
  transition: box-shadow 0.9s var(--ease-out);
}

/* Voile sombre sur les cartes qui ne sont pas au chapitre actif. */
.card__body::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: rgba(var(--bg-rgb), 0.66);
  opacity: 0;
  transition: opacity 0.9s var(--ease-out);
}

.card__body::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 38%, rgba(0, 0, 0, 0.2));
}

.card.is-cold .card__body::before { opacity: 1; }

/* Le rail actif se soulève un peu ; la tuile sortie du rang vient bien au-dessus, cerclée d'ambre. */
.card.is-hot .card__lift { transform: translate3d(0, 0, 40px); }
.card.is-pop .card__lift { transform: translate3d(0, 0, 150px); transition-duration: 0.65s; }

.card.is-pop .card__body {
  box-shadow:
    0 0 0 3px var(--accent),
    0 0 110px -10px rgba(var(--accent-rgb), 0.6),
    0 90px 130px -40px rgba(0, 0, 0, 0.9);
}

/* L'étiquette du service n'apparaît que sur la tuile sortie du rang. */
.card__tag {
  position: absolute;
  left: 22px;
  top: 22px;
  z-index: 5;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #111;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.4s;
}

.card.is-pop .card__tag { opacity: 1; transition-delay: 0.3s; }

.art { position: absolute; inset: 0; }

/* Les cartes hors écran ne consomment pas d'animation ; celles des rails éteints restent figées. */
.card:not(.is-live) * { animation-play-state: paused !important; }
.card.is-cold .art,
.card.is-cold .art * { animation-play-state: paused !important; }

/* ---------- Fondu sous le texte, grain ---------- */

.fade {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: var(--dock);
  background:
    radial-gradient(120% 95% at 0% 0%, var(--bg) 28%, rgba(var(--bg-rgb), 0.86) 44%, rgba(var(--bg-rgb), 0.35) 60%, rgba(var(--bg-rgb), 0) 80%),
    linear-gradient(0deg, rgba(var(--bg-rgb), 0.72), rgba(var(--bg-rgb), 0) 26%),
    linear-gradient(270deg, rgba(var(--bg-rgb), 0.5), rgba(var(--bg-rgb), 0) 12%);
}

.fade::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.08;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Marque, texte, chapitres ---------- */

.copy {
  position: absolute;
  z-index: 4;
  left: var(--pad);
  top: calc(var(--pad-top) + clamp(72px, 16vh, 150px));
  max-width: min(66vw, 980px);
}

.copy__eyebrow {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: clamp(11px, 1.15vw, 15px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent);
}

.copy__eyebrow::before { content: ""; width: 34px; height: 2px; background: var(--accent); }

.copy__title {
  margin-top: clamp(14px, 2.6vh, 28px);
  font-family: var(--serif);
  font-size: clamp(2.2rem, min(6.4vw, 11.5vh), 6.6rem);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.025em;
  font-variation-settings: "opsz" 144;
}

.ln {
  display: block;
  overflow: hidden;
  padding: 0.06em 0 0.16em;
  margin: -0.06em 0 -0.16em;
}

.w { display: inline-block; transform: translate3d(0, 115%, 0); }
.w--accent { color: var(--accent); font-style: italic; }

.copy__sub {
  margin-top: clamp(16px, 3vh, 30px);
  max-width: 30em;
  font-size: clamp(14px, 1.5vw, 20px);
  font-weight: 500;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.74);
}

.copy__eyebrow, .copy__sub { opacity: 0; transform: translate3d(0, 14px, 0); }

.copy.is-in .w { animation: word-in 1.05s var(--ease-out) calc(var(--n) * 80ms) forwards; }
.copy.is-in .copy__eyebrow { animation: fade-up 0.8s var(--ease-out) 0.05s forwards; }
.copy.is-in .copy__sub { animation: fade-up 0.9s var(--ease-out) 0.4s forwards; }

.copy.is-out .w { animation: word-out 0.5s var(--ease-io) calc(var(--n) * 30ms) forwards; }
.copy.is-out .copy__eyebrow, .copy.is-out .copy__sub { opacity: 1; transform: none; animation: fade-out 0.35s ease forwards; }

@keyframes word-in { from { transform: translate3d(0, 115%, 0); } to { transform: none; } }
@keyframes word-out { from { transform: none; } to { transform: translate3d(0, -115%, 0); } }
@keyframes fade-up { to { opacity: 1; transform: none; } }
@keyframes fade-out { to { opacity: 0; } }

.chapters {
  position: absolute;
  z-index: 4;
  left: var(--pad);
  bottom: var(--pad-top);
  display: flex;
  gap: clamp(10px, 1.6vw, 22px);
  width: min(900px, calc(100vw - 2 * var(--pad)));
  opacity: var(--dock);
}

.chapter {
  all: unset;
  box-sizing: border-box;
  flex: 1;
  display: grid;
  gap: 10px;
  min-width: 0;
  cursor: pointer;
  font-size: clamp(10px, 0.9vw, 12px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.46);
  transition: color 0.4s;
}

.chapter__short { display: none; }

.chapter__bar { position: relative; height: 2px; overflow: hidden; border-radius: 2px; background: rgba(255, 255, 255, 0.2); }
.chapter__fill { position: absolute; inset: 0; background: var(--accent); transform: scaleX(0); transform-origin: left; }
.chapter.is-active { color: #fff; }
.chapter.is-done .chapter__fill { transform: scaleX(1); }
.chapter:hover { color: #fff; }
.chapter:focus-visible { outline: 2px solid var(--accent); outline-offset: 8px; }

/* ---------- Ouverture : la scène apparaît, puis les tuiles une à une ---------- */

.stage.is-playing .scene { animation: scene-in 1.2s var(--ease-out) both; }
.stage.is-playing .card__body { animation: card-in 1.1s var(--ease-out) calc(0.25s + var(--d) * 45ms) both; }

@keyframes scene-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes card-in { from { opacity: 0; transform: translate3d(0, 40px, 0) scale(0.88); } to { opacity: 1; transform: none; } }

/* Six chapitres : sous 1100 px, le nom court remplace le numéro et le nom complet. */
@media (max-width: 1100px) {
  .chapter__n, .chapter__full { display: none; }
  .chapter__short { display: inline; }
}

/* ---------- Portrait (téléphone) ---------- */

@media (max-aspect-ratio: 1/1) {
  .copy { max-width: calc(100vw - 2 * var(--pad)); top: calc(var(--pad-top) + clamp(56px, 10vh, 90px)); }
  .copy__title { font-size: clamp(2rem, 10.6vw, 4.2rem); }
  .copy__sub { font-size: clamp(14px, 3.8vw, 18px); max-width: 24em; }
  .copy__eyebrow { font-size: clamp(10px, 2.8vw, 13px); }
  .fade {
    background:
      linear-gradient(180deg, var(--bg) 28%, rgba(var(--bg-rgb), 0.82) 42%, rgba(var(--bg-rgb), 0) 60%),
      linear-gradient(0deg, rgba(var(--bg-rgb), 0.85), rgba(var(--bg-rgb), 0) 20%);
  }
  .chapter { font-size: clamp(9px, 2.5vw, 12px); letter-spacing: 0.1em; }
  .chapter__n, .chapter__full { display: none; }
  .chapter__short { display: inline; }
}

/* ---------- Mouvement réduit : image fixe, texte visible ---------- */

.stage.is-static .card__body { opacity: 1; }
.stage.is-static .copy__eyebrow, .stage.is-static .copy__sub { opacity: 1; transform: none; }
.stage.is-static .w { transform: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: 0.001ms !important;
  }
}
