/* Apprends-moi à conduire — interface FR. Menus translucides posés sur le décor
   3D animé, HUD épuré façon tableau de bord moderne. */
:root {
  --bg: #07090e;
  --glass: rgba(14, 17, 24, 0.55);
  --glass-strong: rgba(12, 15, 22, 0.78);
  --line: rgba(255, 255, 255, 0.10);
  --accent: #ffb547;
  --accent-2: #ff7a3d;
  --ok: #4fd18b;
  --warn: #f2b632;
  --danger: #f05252;
  --text: #f4f1ea;
  --muted: rgba(244, 241, 234, 0.62);
  --font: "Inter", "SF Pro Display", -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  --display: "Avenir Next", "Futura", "Century Gothic", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
/* L'étalonnage est fait dans le rendu (post-traitement) : calque neutre. */
#grade { display: none; }
#overlay { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
#overlay > * { pointer-events: auto; }

/* ---------- écrans (par-dessus la scène animée) ---------- */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 26px; padding: 40px 24px;
  background:
    linear-gradient(90deg, rgba(5, 7, 12, 0.72) 0%, rgba(5, 7, 12, 0.35) 45%, rgba(5, 7, 12, 0.15) 100%),
    linear-gradient(0deg, rgba(5, 7, 12, 0.6) 0%, rgba(5, 7, 12, 0) 40%);
  text-align: center;
  animation: fadeIn .5s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.screen-title {
  font-family: var(--display);
  font-size: clamp(24px, 3.6vw, 42px);
  font-weight: 700;
  letter-spacing: -0.01em;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
}
.card {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 36px 42px;
  max-width: 560px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}
h1 { font-family: var(--display); font-size: 28px; font-weight: 700; letter-spacing: -0.01em; }

/* écran titre : grand titre en bas à gauche, façon affiche de film */
#screen-title { align-items: flex-start; justify-content: flex-end; padding: 0 0 9vh 7vw; text-align: left; }
.title-card {
  background: none; border: none; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none;
  align-items: flex-start; padding: 0; max-width: 760px; gap: 22px;
}
.title-card .game-title {
  font-family: var(--display);
  font-size: clamp(42px, 7.2vw, 96px);
  line-height: 0.95;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: #fff;
  text-shadow: 0 6px 40px rgba(0, 0, 0, 0.55);
}
.title-card .game-title::after {
  content: ''; display: block; width: 72px; height: 4px; margin-top: 22px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 2px;
}
.subtitle { color: var(--muted); font-size: 18px; line-height: 1.5; max-width: 520px; }

/* ---------- boutons ---------- */
.btn {
  font: inherit; font-weight: 650; font-size: 15px; letter-spacing: 0.01em;
  border: 1px solid transparent; border-radius: 999px;
  padding: 13px 26px; cursor: pointer;
  transition: transform .12s ease, background .2s ease, box-shadow .2s ease, border-color .2s ease;
  color: #1a1206;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 30px rgba(255, 140, 50, 0.35);
}
.btn.primary:hover { box-shadow: 0 14px 40px rgba(255, 140, 50, 0.5); }
.btn.secondary { background: rgba(255, 255, 255, 0.92); color: #12151c; }
.btn.ghost { background: rgba(255, 255, 255, 0.06); color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.12); }
.btn.small { padding: 8px 16px; font-size: 13px; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.btn-row.wrap { max-width: 480px; }
.title-card .btn.primary { padding: 16px 38px; font-size: 17px; }

/* ---------- choix personnage ---------- */
.char-row { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.char-card {
  width: 240px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 26px 22px 24px;
  cursor: pointer;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  transition: transform .18s ease, border-color .2s ease, background .2s ease;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.char-card:hover { transform: translateY(-6px); border-color: rgba(255, 181, 71, 0.7); background: var(--glass-strong); }
.char-card h2 { font-family: var(--display); font-size: 26px; font-weight: 700; }
.char-portrait {
  width: 112px; height: 112px; border-radius: 50%;
  margin-bottom: 8px; position: relative; overflow: hidden;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15), 0 10px 30px rgba(0, 0, 0, 0.35);
}
.char-portrait::after {
  content: ''; position: absolute; left: 50%; top: 58%; transform: translate(-50%, 0);
  width: 52%; height: 70%; border-radius: 50% 50% 40% 40%;
  background: rgba(255, 255, 255, 0.16);
}
.char-lily { background: linear-gradient(160deg, #e6b98a, #9a6a3e); }
.char-alix { background: linear-gradient(160deg, #6d4a32, #1b1210); }
.char-marlon { background: linear-gradient(160deg, #e0a06a, #7b8e9a); }
.char-age { color: var(--accent); font-weight: 700; font-size: 14px; }
.char-tag { font-weight: 650; }
.char-trait { color: var(--muted); font-size: 14px; line-height: 1.45; }

/* ---------- micro ---------- */
.mic-card { gap: 20px; }
.mic-info { color: var(--muted); min-height: 24px; }
.meter {
  position: relative; width: 340px; max-width: 70vw; height: 14px;
  background: rgba(0, 0, 0, 0.4); border-radius: 7px; overflow: hidden;
  border: 1px solid var(--line);
}
.meter-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--ok), var(--warn), var(--danger)); transition: width .05s linear; }
.meter-thr { position: absolute; top: -3px; width: 2px; height: 20px; background: #fff; box-shadow: 0 0 8px #fff; }
.sens { display: flex; flex-direction: column; gap: 8px; width: 340px; max-width: 70vw; color: var(--muted); font-size: 14px; }
.sens input { width: 100%; accent-color: var(--accent); }

/* ---------- grille de niveaux ---------- */
.levels-head { display: flex; align-items: center; gap: 18px; width: 100%; max-width: 780px; justify-content: center; position: relative; }
.levels-head .btn { position: absolute; left: 0; }
.level-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 10px; max-width: 780px; width: 100%;
  background: var(--glass); border: 1px solid var(--line); border-radius: 22px; padding: 18px 20px 22px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.zone-label {
  grid-column: 1 / -1; text-align: left;
  color: var(--accent); font-weight: 700; letter-spacing: 0.14em;
  margin-top: 8px; text-transform: uppercase; font-size: 12px;
}
.level-cell {
  aspect-ratio: 1; border: 1px solid var(--line); border-radius: 14px;
  background: rgba(255, 255, 255, 0.05); color: var(--text);
  cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  font: inherit; transition: transform .12s ease, background .2s ease, border-color .2s ease;
}
.level-cell:hover:not(.locked) { transform: translateY(-2px); background: rgba(255, 181, 71, 0.16); border-color: rgba(255, 181, 71, 0.6); }
.level-cell.locked { opacity: 0.35; cursor: not-allowed; }
.level-num { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; }
.stars { display: flex; gap: 2px; }
.stars .star { color: rgba(255, 255, 255, 0.18); font-size: 12px; }
.stars .star.on { color: var(--accent); text-shadow: 0 0 10px rgba(255, 181, 71, 0.6); }
.stars.big .star { font-size: 44px; }

/* ---------- HUD ---------- */
.hud { position: absolute; inset: 0; pointer-events: none; font-weight: 600; }
.hud-top {
  position: absolute; top: max(16px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  background: var(--glass); border: 1px solid var(--line);
  padding: 9px 18px; border-radius: 999px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.hud-level { font-size: 15px; font-variant-numeric: tabular-nums; }
.hud-zone { color: var(--accent); text-transform: uppercase; font-size: 11px; letter-spacing: 0.16em; }
.progress { width: 200px; height: 4px; background: rgba(255, 255, 255, 0.14); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .2s ease; }

.hud-right { position: absolute; top: max(16px, env(safe-area-inset-top)); right: 18px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.gauge {
  background: var(--glass); border: 1px solid var(--line);
  padding: 9px 14px 10px; border-radius: 14px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.gauge-label { font-size: 10px; color: var(--muted); display: block; margin-bottom: 6px; letter-spacing: 0.14em; text-transform: uppercase; }
.gauge-bar { width: 160px; height: 6px; background: rgba(255, 255, 255, 0.12); border-radius: 3px; overflow: hidden; }
.gauge-fill { height: 100%; transition: width .15s ease, background .3s ease; border-radius: 3px; }
.dmg-fill { background: var(--ok); width: 100%; }
.speed {
  font-family: var(--display); font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums;
  line-height: 1; letter-spacing: -0.02em;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.6);
}

/* conducteur : nom + jauge de stress (le portrait 3D a été retiré) */
.portrait-wrap {
  position: absolute; bottom: max(22px, env(safe-area-inset-bottom)); left: 22px;
  display: flex; flex-direction: column; gap: 7px;
  background: var(--glass); border: 1px solid var(--line);
  padding: 10px 14px 12px; border-radius: 14px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.portrait-name { font-size: 14px; font-weight: 700; }
.portrait-name::after { content: ' · stress'; color: var(--muted); font-weight: 500; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; }
.portrait-wrap .stress { width: 170px; }
.stress-fill { background: linear-gradient(90deg, #ffb547, #f05252); width: 0%; }

.subtitle-line {
  position: absolute; bottom: 92px; left: 50%; transform: translateX(-50%);
  max-width: min(72%, 760px); text-align: center;
  background: rgba(8, 10, 16, 0.62); color: #fff;
  padding: 11px 22px; border-radius: 14px; font-size: 19px; font-weight: 550; line-height: 1.4;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  opacity: 0; transition: opacity .25s ease;
}

.mic-indicator {
  position: absolute; bottom: max(22px, env(safe-area-inset-bottom)); right: 22px;
  display: flex; align-items: center; gap: 10px;
  background: var(--glass); border: 1px solid var(--line);
  padding: 9px 15px; border-radius: 999px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.mic-dot { width: 10px; height: 10px; border-radius: 50%; background: #555; transition: background .2s; }
.mic-dot.on { background: var(--ok); box-shadow: 0 0 12px var(--ok); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 2px var(--ok); } }
.heard { color: var(--accent); font-size: 15px; min-width: 60px; }
.heard.flash { animation: flash .5s ease; }
@keyframes flash { 0% { transform: scale(1.25); color: #fff; } 100% { transform: scale(1); } }

.countdown {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-weight: 800; letter-spacing: -0.03em;
  font-size: clamp(70px, 15vw, 170px); color: #fff;
  text-shadow: 0 8px 50px rgba(0, 0, 0, 0.6);
}
.countdown.pop { animation: pop .55s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes pop { 0% { transform: scale(0.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.fps { position: absolute; top: 70px; left: 14px; font-size: 12px; color: #8f8; background: rgba(0,0,0,.4); padding: 2px 7px; border-radius: 6px; }
.debug-box { position: absolute; bottom: 74px; right: 22px; }
.debug-box input { font: inherit; padding: 9px 13px; border-radius: 10px; border: 1px solid var(--line); background: rgba(10, 12, 18, 0.8); color: #fff; width: 220px; }

.end-card { min-width: min(480px, 90vw); }
.end-card .seed { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.pause-screen { background: rgba(5, 7, 12, 0.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
#screen-levelend, #screen-gameover { background: rgba(5, 7, 12, 0.35); }

@media (max-width: 680px) {
  .level-grid { grid-template-columns: repeat(5, 1fr); padding: 14px; }
  .char-row { flex-direction: column; align-items: center; }
  .progress { width: 110px; }
  .speed { font-size: 30px; }
  #screen-title { padding: 0 6vw 8vh; }
}

/* choix de l'accompagnateur sur l'écran titre */
.parent-q { font-size: 13px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); margin-top: 6px; }
.parent-row { justify-content: flex-start; }
.title-card .parent-row .btn { padding: 15px 30px; font-size: 16px; }

/* ---------- mobile : paysage obligatoire ---------- */
#rotate {
  position: fixed; inset: 0; z-index: 10; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: radial-gradient(ellipse at center, #141a26 0%, #05070b 75%);
  color: var(--text); text-align: center; padding: 30px;
}
#rotate p { font-family: var(--display); font-size: 26px; font-weight: 700; }
#rotate span { color: var(--muted); font-size: 15px; }
.rotate-phone {
  width: 54px; height: 92px; border: 3px solid var(--text); border-radius: 12px; position: relative;
  animation: turn 2.2s ease-in-out infinite;
}
.rotate-phone::after { content: ''; position: absolute; left: 50%; bottom: 6px; width: 14px; height: 3px; margin-left: -7px; border-radius: 2px; background: var(--text); }
@keyframes turn { 0%, 20% { transform: rotate(0); } 55%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
@media (orientation: portrait) and (pointer: coarse) {
  #rotate { display: flex; }
}

/* ---------- petits écrans en paysage (téléphones) ---------- */
@media (max-height: 500px) {
  .screen { gap: 12px; padding: 14px 18px; justify-content: center; }
  .screen-title { font-size: 22px; margin-bottom: 0; }
  #screen-title { padding: 0 0 5vh 6vw; }
  .title-card { gap: 10px; }
  .title-card .game-title { font-size: clamp(30px, 9vh, 52px); }
  .title-card .game-title::after { margin-top: 10px; }
  .subtitle { font-size: 14px; }
  .title-card .parent-row .btn { padding: 11px 22px; font-size: 14px; }
  .card { padding: 18px 22px; gap: 10px; }
  .char-row { flex-direction: row; flex-wrap: nowrap; gap: 10px; }
  .char-card { width: 30vw; max-width: 210px; padding: 12px 10px; gap: 4px; }
  .char-portrait { width: 56px; height: 56px; margin-bottom: 2px; }
  .char-card h2 { font-size: 18px; }
  .char-trait { font-size: 12px; }
  .level-grid { grid-template-columns: repeat(10, 1fr); gap: 6px; padding: 10px 12px; max-width: 94vw; }
  .zone-label { margin-top: 2px; font-size: 10px; }
  .level-num { font-size: 15px; }
  .stars .star { font-size: 9px; }
  .levels-head .btn { position: static; }
  .hud-top { top: 8px; padding: 5px 12px; gap: 8px; }
  .hud-level { font-size: 12px; }
  .progress { width: 90px; }
  .hud-right { top: 8px; right: 10px; gap: 4px; }
  .gauge { padding: 5px 9px 6px; }
  .gauge-bar { width: 110px; }
  .speed { font-size: 26px; }
  .portrait-wrap { bottom: 8px; left: 10px; padding: 6px 10px 8px; }
  .portrait-wrap .stress { width: 120px; }
  .mic-indicator { bottom: 8px; right: 10px; padding: 6px 11px; }
  .subtitle-line { bottom: 52px; font-size: 15px; padding: 7px 14px; }
  .countdown { font-size: 22vh; }
  .stars.big .star { font-size: 30px; }
  .btn { padding: 10px 18px; font-size: 14px; }
}
