* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #111;
  cursor: url('tete-mini.png') 24 24, crosshair;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#monde { position: fixed; inset: 0; }
#monde > div { position: absolute; inset: 0; contain: strict; }

#bg { z-index: 0; }

/* ---------- Têtes ---------- */
#stage {
  z-index: 3;
  transition: transform 1.2s cubic-bezier(.68,-0.55,.27,1.55);
}
.tete {
  position: absolute; top: 0; left: 0;
  will-change: transform;
}
.face {
  position: relative;
  width: 100%; height: 100%;
}
.haut, .bas {
  position: absolute; inset: 0;
  background-image: url('tete.png');
  background-size: cover;
}
/* le visage est coupé au niveau de la bouche */
.haut { clip-path: inset(0 0 36% 0); }
.bas  { clip-path: inset(64% 0 0 0); }

/* la tête parle */
.bavard .bas { will-change: transform; animation: machoire .16s ease-in-out infinite alternate; }
@keyframes machoire { to { transform: translateY(16%); } }

/* menton sur le front */
.swap .haut { transform: translateY(36%); }
.swap .bas  { transform: translateY(-64%); animation: none; }

/* ---------- Traînées & arc-en-ciel ---------- */
.fantome, .arc {
  position: absolute; top: 0; left: 0;
  pointer-events: none;
  will-change: transform, opacity;
  opacity: 0;
}
.fantome { transition: opacity 1s ease-out; }
.fantome .face { width: 100%; height: 100%; }

.arc {
  width: 34px;
  background: linear-gradient(
    #ff1a1a 0 16.66%, #ff9a00 16.66% 33.33%, #ffee00 33.33% 50%,
    #33ee00 50% 66.66%, #0099ff 66.66% 83.33%, #7a33ff 83.33% 100%);
  transition: opacity .9s linear;
  image-rendering: pixelated;
}

/* ---------- Espace 8-bit ---------- */
#espace {
  z-index: 1;
  background: #0d1a4a;
  opacity: 0;
  transition: opacity .5s;
}
#espace.actif { opacity: 1; }
.etoile {
  position: absolute;
  width: 6px; height: 6px;
  background: #fff;
  box-shadow: 6px 0 #fff, -6px 0 #fff, 0 6px #fff, 0 -6px #fff;
  animation: defile-etoile linear infinite, scintille .5s steps(2) infinite;
}
@keyframes defile-etoile {
  from { transform: translateX(110vw); }
  to   { transform: translateX(-10vw); }
}
@keyframes scintille { 50% { box-shadow: 12px 0 #fff, -12px 0 #fff, 0 12px #fff, 0 -12px #fff; } }
#espace:not(.actif) .etoile { animation-play-state: paused; }

/* ---------- Papier peint de têtes ---------- */
#papier {
  z-index: 2;
  inset: -120px !important;
  background: url('tete.png') 0 0 / 120px 120px repeat;
  opacity: 0;
  transition: opacity .6s;
}
#papier.actif {
  opacity: 1;
  animation: defile-papier 1.2s linear infinite;
}
@keyframes defile-papier { to { transform: translate(120px, 120px); } }

/* ---------- Tunnel infini ---------- */
#tunnel {
  z-index: 2;
  display: grid; place-items: center;
  opacity: 0;
  transition: opacity .5s;
  pointer-events: none;
}
#tunnel.actif { opacity: 1; }
#tunnel:not(.actif) { visibility: hidden; transition: opacity .5s, visibility 0s .5s; }
.couche {
  grid-area: 1 / 1;
  border-radius: 50%;
  overflow: hidden;
  will-change: transform;
  animation: tourne 3s linear infinite;
}
.couche:nth-child(even) { animation-direction: reverse; }
@keyframes tourne { to { transform: rotate(360deg); } }
#tunnel:not(.actif) .couche { animation-play-state: paused; }

/* ---------- Boss ---------- */
#boss {
  z-index: 4;
  display: grid; place-items: center;
  pointer-events: none;
}
#boss .tete-boss {
  width: 80vmin; height: 80vmin;
  transform: scale(0) rotate(-720deg);
  transition: transform 1s cubic-bezier(.68,-0.55,.27,1.55);
}
#boss.actif .tete-boss { transform: scale(1) rotate(0); }
#boss .tete-boss .face { will-change: transform; }
#boss.actif .tete-boss .face { animation: hoche .6s ease-in-out infinite alternate; }
@keyframes hoche { from { transform: rotate(-12deg); } to { transform: rotate(12deg) scale(1.05); } }

/* ---------- Zoom sur le front ---------- */
#front {
  z-index: 6;
  background: #000;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
}
#front.actif { visibility: visible; }
#front img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: 37.5% 24%;
  transform-origin: 37.5% 24%;
  will-change: transform;
}
#front .rayons {
  position: absolute; inset: 0;
  background: repeating-conic-gradient(from 0deg at 37.5% 24%,
    transparent 0 5deg, rgba(255,255,255,.7) 5deg 6.5deg, transparent 6.5deg 11deg);
  -webkit-mask: radial-gradient(circle at 37.5% 24%, transparent 22%, #000 65%);
          mask: radial-gradient(circle at 37.5% 24%, transparent 22%, #000 65%);
  opacity: 0;
  will-change: opacity, transform;
}
#front.drame .rayons { animation: rayons .12s steps(2) infinite; }
@keyframes rayons { 0% { opacity: .9; } 100% { opacity: .35; } }

/* ---------- Flash & secousse ---------- */
#flash {
  z-index: 5;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s;
}
#monde.secousse { animation: secousse .45s; }
@keyframes secousse {
  0%, 100% { transform: none; }
  20% { transform: translate(-18px, 10px) rotate(-1deg); }
  40% { transform: translate(16px, -12px) rotate(1deg); }
  60% { transform: translate(-10px, -8px); }
  80% { transform: translate(8px, 10px); }
}

body.pause *, body.pause *::before { animation-play-state: paused !important; }
