:root {
  --bg: #1c1c22;
  --panel: rgba(18, 18, 24, 0.85);
  --text: #f4f0ff;
  --muted: #b3a8d6;
  --green: #2ee6a6;
  --red: #ff3b5c;
  --blue: #3ba7ff;
  --gold: #ffd23f;
  --pink: #ff4fd8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

.hidden { display: none !important; }

/* ---------- Écrans ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px 16px;
  text-align: center;
  background: radial-gradient(ellipse at center, rgba(28, 28, 34, 0.55), rgba(8, 8, 10, 0.92));
  z-index: 10;
}
.screen.clear { background: none; pointer-events: none; }
.screen.top { justify-content: flex-start; background: none; pointer-events: none; padding-top: 32px; }

h1 {
  font-family: Bungee, Inter, sans-serif;
  font-size: clamp(48px, 11vw, 120px);
  margin: 0;
  line-height: 1;
  letter-spacing: 2px;
  text-shadow: 0 0 24px rgba(46, 230, 166, 0.6);
}
h1 span { color: var(--green); }

h2 {
  font-family: Bungee, Inter, sans-serif;
  font-size: clamp(32px, 7vw, 64px);
  margin: 0;
}

.tagline { font-size: 20px; color: var(--muted); margin: 0; }
.tagline b { color: var(--text); }

.moves { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.move {
  background: var(--panel);
  border: 2px solid var(--green);
  border-radius: 16px;
  padding: 14px 18px;
  min-width: 150px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.move.low { border-color: var(--red); }
.move.high { border-color: var(--blue); }
.move.tunnel { border-color: var(--gold); }
.move .icon { font-size: 34px; line-height: 1.1; }
/* Cartes-interrupteurs du mode personnalisé : ✓ actif, ✕ désactivé (grisé) */
button.move {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  cursor: pointer;
  position: relative;
  transition: opacity 0.2s, filter 0.2s, transform 0.1s;
}
button.move:hover { background: var(--panel); }
button.move::after {
  content: '✓';
  position: absolute; top: 6px; right: 10px;
  font-size: 15px; font-weight: 800;
  color: var(--green);
}
.move.off { opacity: 0.35; filter: grayscale(1); }
button.move.off::after { content: '✕'; color: var(--muted); }
.key-hint.off { opacity: 0.4; text-decoration: line-through; }
.move span { color: var(--muted); font-size: 14px; }

#mode-desc { margin-top: -6px; }

.buttons { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
button {
  font: 700 18px Inter, sans-serif;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 14px 26px;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}
button:hover { transform: translateY(-2px); background: rgba(255, 255, 255, 0.16); }
button.primary { background: var(--green); color: #0d0820; border-color: var(--green); }
button.primary:hover { background: #5cf0bd; }

.quality-pick { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.quality-pick select {
  font: 600 14px Inter, sans-serif;
  color: var(--text);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}

button.link {
  background: none; border: none; padding: 4px 8px;
  font-size: 14px; font-weight: 600; color: var(--muted);
  text-decoration: underline;
}
button.link:hover { color: var(--text); background: none; transform: none; }

.credits {
  max-width: 640px;
  max-height: 60vh;
  overflow-y: auto;
  text-align: left;
  background: var(--panel);
  border-radius: 16px;
  padding: 8px 22px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}
.credits h3 { color: var(--text); font-size: 16px; margin: 14px 0 6px; }
.credits b { color: var(--text); }
.credits a { color: var(--green); }

.hint { color: var(--muted); font-size: 14px; max-width: 620px; line-height: 1.5; margin: 0; }
.warn { color: var(--gold); max-width: 560px; margin: 0; }

.spinner {
  width: 54px; height: 54px;
  border: 5px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bar { width: min(420px, 80vw); height: 14px; border-radius: 99px; background: rgba(255, 255, 255, 0.15); overflow: hidden; }
#calib-bar { height: 100%; width: 0; background: var(--green); transition: width 0.1s; }
#screen-calib {
  gap: 10px; padding-top: 20px; z-index: 25;
  background: rgba(8, 8, 10, 0.82); /* le décor ne gêne pas la lecture des consignes */
}
button.back {
  position: absolute; top: 16px; left: 16px;
  font-size: 15px; padding: 10px 18px;
}
.calib-instr { font-size: 22px; margin: 0; text-shadow: 0 2px 8px #000; }
.calib-instr b { color: var(--gold); }
.calib-sub { font-size: 15px; color: var(--muted); margin: 0; max-width: 620px; text-shadow: 0 2px 8px #000; }
.calib-status {
  font-size: 18px; font-weight: 800; margin: 4px 0 0;
  padding: 4px 14px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
}
.calib-status.warn { color: var(--gold); }
.calib-status.bad { color: var(--red); }
.calib-status.good { color: var(--green); }

#countdown {
  font-family: Bungee, Inter, sans-serif;
  font-size: clamp(90px, 22vw, 220px);
  color: var(--gold);
  text-shadow: 0 0 40px rgba(255, 210, 63, 0.7), 0 6px 0 #000;
}
#countdown.pop { animation: pop 0.8s ease-out; }
@keyframes pop { from { transform: scale(1.8); opacity: 0; } 30% { opacity: 1; } to { transform: scale(1); } }

/* Dégradé sombre en haut : les consignes restent lisibles sur les néons, le perso reste visible en bas */
#screen-test {
  background: linear-gradient(to bottom, rgba(8, 8, 10, 0.88) 0, rgba(8, 8, 10, 0.7) 300px, rgba(8, 8, 10, 0) 420px);
}
.test-text { font-size: 18px; margin: 0; max-width: 560px; text-shadow: 0 2px 8px #000; }
.test-text.ready {
  font-size: 22px; font-weight: 800;
  max-width: 92vw;
  color: #0d0820;
  background: var(--green);
  padding: 8px 20px;
  border-radius: 999px;
  text-shadow: none;
  box-shadow: 0 0 24px rgba(46, 230, 166, 0.6);
  animation: ready-pulse 1.2s ease-in-out infinite;
}
@keyframes ready-pulse { 50% { transform: scale(1.05); } }
.checklist { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.check {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 800;
  transition: border-color 0.2s, background 0.2s;
}
.check .box { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.4); }
.check.flash { background: rgba(255, 255, 255, 0.18); }
.check.done { border-color: var(--green); }
.check.done .box { background: var(--green); border-color: var(--green); box-shadow: 0 0 10px var(--green); }
.interactive { pointer-events: auto; }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.final { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.final div {
  background: var(--panel);
  border-radius: 16px;
  padding: 14px 22px;
  min-width: 120px;
  display: flex; flex-direction: column;
}
.final span { color: var(--muted); font-size: 14px; }
.final b { font-size: 36px; }
.best { color: var(--gold); font-weight: 700; margin: 0; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.hud-left { position: absolute; top: 16px; left: 16px; }
.score {
  font-family: Bungee, Inter, sans-serif;
  font-size: 44px;
  text-shadow: 0 3px 0 #000, 0 0 16px rgba(46, 230, 166, 0.5);
}
.coins { display: flex; align-items: center; gap: 8px; font-size: 22px; font-weight: 800; color: var(--gold); }
.coin-icon { width: 18px; height: 18px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 10px var(--gold); }
.hud-right { position: absolute; top: 18px; right: 16px; display: flex; align-items: center; gap: 14px; }
#lives { display: flex; gap: 6px; font-size: 32px; }
#btn-pause {
  pointer-events: auto; /* le HUD laisse passer les clics, sauf ce bouton */
  width: 44px; height: 44px; padding: 0;
  border-radius: 12px;
  background: var(--panel);
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
/* Icône pause dessinée en CSS (deux barres) : pas de dépendance à une police */
#btn-pause::before, #btn-pause::after {
  content: '';
  width: 5px; height: 16px;
  border-radius: 2px;
  background: var(--text);
}
.hud-right .heart { color: var(--red); text-shadow: 0 0 10px var(--red); }
.hud-right .heart.lost { color: rgba(255, 255, 255, 0.15); text-shadow: none; }

.hud-bottom {
  position: absolute;
  bottom: 16px; left: 16px;
  display: flex; align-items: center; gap: 14px;
}
.counter {
  background: var(--panel);
  border-radius: 14px;
  padding: 8px 14px;
  font-size: 13px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center;
}
.counter b { font-size: 26px; color: var(--text); }
.gesture {
  background: var(--panel);
  border-radius: 14px;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
}
.lanes { display: flex; gap: 6px; }
.lane-dot { width: 18px; height: 18px; border-radius: 50%; background: rgba(255, 255, 255, 0.15); }
.lane-dot.on { background: var(--green); box-shadow: 0 0 10px var(--green); }
.tag-move {
  font-weight: 800; font-size: 13px;
  padding: 4px 10px; border-radius: 99px;
  background: rgba(255, 255, 255, 0.08); color: rgba(255, 255, 255, 0.35);
}
#g-jump.on { background: var(--red); color: #fff; }
#g-squat.on { background: var(--blue); color: #fff; }

/* Console façon tapis de course */
.console {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  padding: 6px;
  background: #0a0a0c;
  border: 2px solid #3a3a42;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5), inset 0 0 12px rgba(46, 230, 166, 0.08);
}
.console .cell {
  min-width: 92px;
  padding: 4px 10px;
  display: flex; flex-direction: column; align-items: center;
  background: #111114;
  border-radius: 8px;
}
.console span { font: 500 10px Orbitron, monospace; letter-spacing: 1.5px; color: #8a8a96; }
.console b {
  font: 800 26px Orbitron, monospace;
  color: var(--green);
  text-shadow: 0 0 10px rgba(46, 230, 166, 0.7);
  font-variant-numeric: tabular-nums;
}
.console .cell:nth-child(3) b { color: #ffb020; text-shadow: 0 0 10px rgba(255, 176, 32, 0.7); }
.console i { font: 500 10px Orbitron, monospace; color: #8a8a96; font-style: normal; }

/* Messages du coach */
#coach {
  position: absolute;
  top: 30%; left: 50%;
  transform: translate(-50%, -50%);
  font-family: Bungee, Inter, sans-serif;
  font-size: clamp(36px, 7vw, 72px);
  white-space: nowrap;
  color: #fff;
  text-shadow: 0 4px 0 #000, 0 0 30px rgba(255, 210, 63, 0.8);
  opacity: 0;
}
#coach.show { animation: coach 1.3s ease-out forwards; }
#coach.good { color: var(--gold); }
#coach.bad { color: var(--red); text-shadow: 0 4px 0 #000, 0 0 30px rgba(255, 59, 92, 0.8); }
@keyframes coach {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.8); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
}

/* Tutoriel guidé : indice sur la prochaine rangée */
#tuto-hint {
  position: absolute;
  top: 168px; left: 50%;
  transform: translateX(-50%);
  max-width: min(720px, 92vw);
  text-align: center;
  background: rgba(10, 10, 12, 0.85);
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: 8px 18px;
  font-weight: 800;
  font-size: clamp(16px, 2.4vw, 24px);
}
#tuto-hint b { font-family: Bungee, Inter, sans-serif; color: var(--gold); margin-right: 10px; }

/* Jauge de tunnel */
#tunnel-gauge {
  position: absolute;
  top: 40%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 14px;
  background: rgba(10, 10, 12, 0.85);
  border: 2px solid var(--blue);
  border-radius: 16px;
  padding: 10px 18px;
}
#tunnel-label { font-family: Bungee, Inter, sans-serif; font-size: 28px; color: var(--blue); }
#tunnel-gauge.fail { border-color: var(--red); }
#tunnel-gauge.fail #tunnel-label { color: var(--red); }
.gauge { width: min(260px, 40vw); height: 16px; border-radius: 99px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
#tunnel-bar { height: 100%; width: 100%; background: var(--blue); box-shadow: 0 0 12px var(--blue); }
#tunnel-gauge.fail #tunnel-bar { background: var(--red); box-shadow: none; }
#tunnel-time { font: 800 26px Orbitron, monospace; min-width: 64px; text-align: right; }

/* Jauge de porte à reps (même place que celle du tunnel) */
#gate-gauge {
  position: absolute;
  top: 40%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 14px;
  background: rgba(10, 10, 12, 0.85);
  border: 2px solid var(--gold);
  border-radius: 16px;
  padding: 10px 18px;
}
#gate-gauge span { font-family: Bungee, Inter, sans-serif; font-size: 28px; color: var(--gold); }
#gate-bar { height: 100%; width: 0; background: var(--gold); box-shadow: 0 0 12px var(--gold); transition: width 0.2s; }
#gate-count { font: 800 26px Orbitron, monospace; min-width: 80px; text-align: right; }

/* Jauge du bonus protéines */
#boost-gauge {
  position: absolute;
  top: 112px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  background: rgba(10, 10, 12, 0.85);
  border: 2px solid #ffb020;
  border-radius: 14px;
  padding: 6px 14px;
  box-shadow: 0 0 20px rgba(255, 176, 32, 0.5);
}
#boost-gauge span { font-family: Bungee, Inter, sans-serif; font-size: 20px; color: #ffb020; }
#boost-bar { height: 100%; width: 100%; background: #ffb020; box-shadow: 0 0 12px #ffb020; }

/* ---------- Webcam ---------- */
#cam {
  position: fixed;
  right: 16px; bottom: 16px;
  width: min(320px, 40vw);
  aspect-ratio: 16 / 9;
  border-radius: 16px;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.25);
  background: #000;
  z-index: 20;
  transition: width 0.3s, right 0.3s, bottom 0.3s;
}
/* Pendant la calibration : grand aperçu sous les consignes (sans les recouvrir) */
#cam.big {
  width: min(800px, 92vw, calc((100vh - 285px) * 16 / 9));
  top: 270px; bottom: auto;
  z-index: 30; /* au-dessus du fond sombre de l'écran de calibration */
  right: 50%;
  transform: translateX(50%);
}
#cam video, #cam canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* effet miroir */
}
#cam-warn {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(255, 59, 92, 0.85);
  font-weight: 800; font-size: 13px; text-align: center;
  padding: 4px;
}

#paused {
  position: fixed; top: 40%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: 16px;
  padding: 18px 26px;
  font-size: 22px; font-weight: 800;
  z-index: 15;
}

#toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 8px 18px;
  font-weight: 700;
  z-index: 40;
}

#perf {
  position: fixed; top: 90px; right: 16px;
  margin: 0;
  background: rgba(0, 0, 0, 0.75);
  border-radius: 10px;
  padding: 10px 12px;
  font: 12px/1.5 ui-monospace, Consolas, monospace;
  z-index: 30;
  pointer-events: none;
}
#perf .bad { color: var(--red); }
#perf .ok { color: var(--gold); }
#perf .good { color: var(--green); }

#debug {
  position: fixed; top: 90px; left: 16px;
  margin: 0;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 10px;
  padding: 10px 12px;
  font: 12px/1.5 ui-monospace, Consolas, monospace;
  z-index: 30;
  pointer-events: none;
}

@media (max-width: 760px) {
  .console { top: auto; bottom: 16px; left: auto; right: 16px; transform: none; flex-wrap: wrap; width: 210px; }
  .console .cell { min-width: 0; flex: 1 1 45%; }
  .console b { font-size: 18px; }
}

@media (max-width: 640px) {
  .score { font-size: 32px; }
  .hud-bottom { bottom: auto; top: 110px; flex-direction: column; align-items: flex-start; }
}
