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

:root {
  --cyan: #46e6ff;
  --pink: #ff5fa2;
  --red: #ff2d55;
  --ink: #eef0f5;
  --dim: #8a8aa0;
  --bg: #04050a;
  --pad: max(14px, env(safe-area-inset-left));
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; }

/* ── Flash rouge à l'impact ──────────────────────────────────────────── */
#flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 85%, rgba(255, 45, 85, 0.55), rgba(255, 45, 85, 0.12) 60%, transparent);
  opacity: 0;
}
#flash.on { animation: flash 0.9s ease-out; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

/* ── HUD ─────────────────────────────────────────────────────────────── */
#hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: var(--pad);
  right: calc(var(--pad) + 140px);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}
#score {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  text-shadow: 0 0 18px rgba(70, 230, 255, 0.55);
  line-height: 1;
}
#hud-record { font-size: 0.8rem; color: var(--dim); margin-top: 4px; letter-spacing: 0.05em; }
#hud-center { text-align: center; flex: 1; max-width: 340px; }
#phase { font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink); opacity: 0.85; }
#phase-bar { height: 2px; margin-top: 6px; background: rgba(255, 255, 255, 0.12); border-radius: 2px; overflow: hidden; }
#phase-bar i { display: block; height: 100%; width: 0; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
#lives { display: flex; gap: 6px; padding-top: 6px; }
#lives i {
  width: 14px; height: 14px;
  border: 2px solid var(--cyan);
  background: rgba(70, 230, 255, 0.25);
  box-shadow: 0 0 8px rgba(70, 230, 255, 0.6);
  transition: opacity 0.3s, transform 0.3s;
}
#lives i.lost { opacity: 0.15; transform: scale(0.7); box-shadow: none; }

@media (max-width: 600px) {
  #hud { right: calc(var(--pad) + 120px); }
  #hud-center { display: none; }
}

/* ── Boutons outils (pause, son, plein écran) ────────────────────────── */
#tools {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  z-index: 20;
}
.tool {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(8, 10, 20, 0.55);
  backdrop-filter: blur(6px);
  transition: border-color 0.2s, background 0.2s;
}
.tool:hover { border-color: var(--cyan); background: rgba(70, 230, 255, 0.12); }
.tool svg { width: 18px; height: 18px; fill: currentColor; }
#btn-mute .off, #btn-mute.muted .on { display: none; }
#btn-mute.muted .off { display: block; }
#btn-fs .exit, #btn-fs.active .enter { display: none; }
#btn-fs.active .exit { display: block; }

/* ── Médaillon webcam ────────────────────────────────────────────────── */
#cam {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: clamp(120px, 18vw, 200px);
  z-index: 5;
}
#cam video, #cam canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  transform: scaleX(-1);
  border-radius: 12px;
}
#cam video { border: 1px solid rgba(70, 230, 255, 0.45); box-shadow: 0 0 18px rgba(70, 230, 255, 0.25); background: #000; opacity: 0.85; }
#cam canvas { position: absolute; top: 0; left: 0; pointer-events: none; }
#cam.lost video { border-color: var(--red); box-shadow: 0 0 18px rgba(255, 45, 85, 0.45); }
#steer-gauge {
  position: relative;
  height: 6px;
  margin-top: 8px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
}
#steer-gauge::after {
  content: '';
  position: absolute;
  left: 50%; top: -3px; bottom: -3px;
  width: 1px;
  background: rgba(255, 255, 255, 0.35);
}
#steer-knob {
  position: absolute;
  top: -3px;
  left: 50%;
  width: 12px; height: 12px;
  margin-left: -6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
}

/* ── Messages centraux (décompte, phase) ─────────────────────────────── */
#center-msg {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
  padding: 0 24px;
}
#center-big {
  font-size: clamp(3rem, 14vw, 6rem);
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 0 40px rgba(70, 230, 255, 0.6);
}
#center-sub { margin-top: 14px; font-size: 1rem; color: var(--ink); opacity: 0.85; max-width: 420px; }

#toast {
  position: fixed;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  font-size: clamp(1.1rem, 3.4vw, 1.6rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 0 24px rgba(70, 230, 255, 0.8);
  pointer-events: none;
  opacity: 0;
}
#toast small { display: block; font-size: 0.6em; letter-spacing: 0.2em; color: var(--dim); margin-bottom: 6px; }
#toast.show { animation: toast 2.4s ease-out; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -40%); }
  15% { opacity: 1; transform: translate(-50%, -50%); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -55%); }
}

/* ── Menus ───────────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  background: radial-gradient(ellipse at center, rgba(4, 5, 10, 0.35), rgba(4, 5, 10, 0.8));
  z-index: 10;
  overflow-y: auto;
}
.panel {
  width: min(520px, 100%);
  text-align: center;
  padding: 28px 26px 22px;
  border-radius: 18px;
  background: rgba(8, 10, 20, 0.72);
  border: 1px solid rgba(70, 230, 255, 0.22);
  box-shadow: 0 0 60px rgba(70, 230, 255, 0.08);
  backdrop-filter: blur(10px);
  margin: auto;
}
.panel.small { width: min(380px, 100%); }
.logo {
  font-size: clamp(2.4rem, 9vw, 3.6rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1;
  text-shadow: 0 0 30px rgba(70, 230, 255, 0.55);
}
.logo span { color: var(--cyan); margin-left: 0.18em; }
h2 { font-size: 1.8rem; letter-spacing: 0.06em; }
.tagline { margin-top: 10px; color: var(--dim); }
#pause-sub { margin-top: 8px; color: var(--dim); }

#result { margin-top: 20px; }
.res-label { font-size: 0.8rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--dim); }
#res-score {
  font-size: clamp(2.6rem, 10vw, 3.8rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 30px rgba(70, 230, 255, 0.6);
  line-height: 1.1;
}
#res-record { color: var(--dim); font-size: 0.95rem; }
#res-record.best { color: var(--pink); text-shadow: 0 0 14px rgba(255, 95, 162, 0.6); }

.buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.btn {
  padding: 13px 18px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.04);
  font-weight: 500;
  font-size: 1rem;
  letter-spacing: 0.03em;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.btn:hover { border-color: var(--cyan); background: rgba(70, 230, 255, 0.08); }
.btn.primary {
  border-color: var(--cyan);
  background: rgba(70, 230, 255, 0.16);
  box-shadow: 0 0 20px rgba(70, 230, 255, 0.25);
}
.btn.primary:hover { background: rgba(70, 230, 255, 0.26); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.error { margin-top: 12px; color: var(--pink); font-size: 0.9rem; }

.howto {
  list-style: none;
  margin-top: 20px;
  text-align: left;
  font-size: 0.86rem;
  color: var(--dim);
  display: grid;
  gap: 6px;
}
.howto b { color: var(--ink); font-weight: 500; }
#menu-record { margin-top: 14px; font-size: 0.9rem; color: var(--ink); opacity: 0.8; }
.credit { margin-top: 14px; font-size: 0.75rem; color: var(--dim); }
.credit a { color: var(--cyan); text-decoration: none; }
.credit a:hover { text-decoration: underline; }

@media (max-height: 560px) {
  .panel { padding: 18px 20px 14px; }
  .howto { display: none; }
  .buttons { margin-top: 14px; }
}
