/* RACEMAX — thème désert / savane */
:root {
  --sand: #e8c07a;
  --sand-dark: #c89a55;
  --orange: #ff7a1a;
  --orange-deep: #e05e00;
  --night: #221410;
  --night-2: #2e1c14;
  --cream: #fff3e0;
  --green: #7ad36a;
  --yellow: #ffd94a;
  --red: #ff5a4a;
  --blue: #4aa8ff;
  --radius: 14px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  background: #1a0f0a;
  color: var(--cream);
}

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

#ui { position: fixed; inset: 0; pointer-events: none; }
#ui button, #ui input { pointer-events: auto; }

/* ===== écrans ===== */
.screen {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
  background:
    radial-gradient(120% 90% at 50% 110%, rgba(255,150,40,.28), transparent 60%),
    linear-gradient(180deg, rgba(30,15,8,.82), rgba(20,10,6,.9));
  overflow-y: auto;
}
.screen.visible { display: flex; }

.panel {
  background: linear-gradient(180deg, rgba(46,28,20,.96), rgba(30,17,12,.97));
  border: 2px solid rgba(255,150,60,.35);
  border-radius: var(--radius);
  box-shadow: 0 18px 60px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,220,160,.12);
  padding: 28px 32px;
  width: min(660px, 100%);
  max-height: 96vh;
  overflow-y: auto;
}

/* ===== accueil ===== */
.home-panel { text-align: center; }
.logo {
  font-size: clamp(44px, 8vw, 74px);
  font-style: italic; font-weight: 900;
  letter-spacing: 2px;
  color: var(--cream);
  text-shadow: 0 4px 0 var(--orange-deep), 0 10px 28px rgba(255,120,20,.45);
}
.logo span { color: var(--orange); }
.tagline { color: #d9b98c; margin: 6px 0 26px; font-size: 15px; }

.field { display: block; text-align: left; margin-bottom: 18px; }
.field span { display: block; font-size: 13px; color: #d9b98c; margin-bottom: 6px; font-weight: bold; }
.field input {
  width: 100%; padding: 12px 14px; font-size: 18px;
  background: rgba(0,0,0,.35); color: var(--cream);
  border: 2px solid rgba(255,170,80,.3); border-radius: 10px; outline: none;
}
.field input:focus { border-color: var(--orange); }

.btn {
  font-family: inherit; font-weight: 800; font-style: italic;
  background: linear-gradient(180deg, #4a3123, #382317);
  color: var(--cream);
  border: 2px solid rgba(255,170,80,.4);
  border-radius: 10px; padding: 10px 20px; font-size: 15px;
  cursor: pointer; transition: transform .08s, filter .12s;
}
.btn:hover:not(:disabled) { filter: brightness(1.15); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, var(--orange), var(--orange-deep));
  border-color: rgba(255,220,150,.5);
  color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.3);
}
.btn.big { font-size: 20px; padding: 14px 30px; width: 100%; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.ghost { background: rgba(0,0,0,.25); border-color: rgba(255,170,80,.25); }

.or { display: flex; align-items: center; gap: 12px; margin: 16px 0; color: #b9976a; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: rgba(255,170,80,.25); }

.join-row { display: flex; gap: 10px; }
.join-row input {
  flex: 1; padding: 12px 14px; font-size: 22px; letter-spacing: 6px;
  text-align: center; text-transform: uppercase;
  background: rgba(0,0,0,.35); color: var(--cream);
  border: 2px solid rgba(255,170,80,.3); border-radius: 10px; outline: none;
}
.join-row input:focus { border-color: var(--orange); }

.hint { margin-top: 16px; font-size: 13px; color: #b9976a; }

/* ===== salon ===== */
.room-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.room-label { font-size: 12px; color: #d9b98c; font-weight: bold; }
.room-code-row { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.room-code {
  font-size: 42px; font-weight: 900; letter-spacing: 10px;
  color: var(--yellow); text-shadow: 0 3px 0 rgba(0,0,0,.4);
  background: rgba(0,0,0,.3); padding: 4px 8px 4px 18px; border-radius: 10px;
  border: 2px dashed rgba(255,217,74,.4);
}

.section-title { margin: 20px 0 10px; font-size: 16px; color: var(--cream); font-style: italic; }
.section-title small { color: #b9976a; font-size: 12px; font-style: normal; }

#lobby-players { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#lobby-players li {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,.25); border-radius: 10px; padding: 8px 12px;
  border: 1px solid rgba(255,170,80,.18);
}
.player-dot { width: 16px; height: 16px; border-radius: 50%; flex: none; box-shadow: 0 0 10px currentColor; }
.player-name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-vehicle { margin-left: auto; font-size: 12px; color: #b9976a; white-space: nowrap; }
.host-badge {
  font-size: 10px; font-weight: 900; letter-spacing: 1px;
  background: var(--orange); color: #fff; border-radius: 6px; padding: 2px 6px; flex: none;
}

#vehicle-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.vehicle-card {
  font-family: inherit; cursor: pointer;
  background: rgba(0,0,0,.3); color: var(--cream);
  border: 2px solid rgba(255,170,80,.22); border-radius: 12px;
  padding: 10px; display: flex; flex-direction: column; gap: 8px; align-items: center;
  transition: transform .1s, border-color .15s, background .15s;
}
.vehicle-card svg { width: 100%; height: 52px; fill: #e8d5b5; stroke: #e8d5b5; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; fill-opacity: .15; }
.vehicle-card:hover:not(:disabled) { transform: translateY(-3px); border-color: var(--orange); }
.vehicle-card.selected { border-color: var(--yellow); background: rgba(255,180,40,.12); box-shadow: 0 0 18px rgba(255,180,40,.2); }
.vehicle-card:disabled { opacity: .38; cursor: not-allowed; filter: grayscale(.8); }
.vehicle-card .taken-by { font-size: 11px; color: var(--yellow); font-weight: 700; display: none; }
.vehicle-card:disabled .taken-by { display: block; }
.v-name { font-weight: 800; font-size: 13px; text-align: center; }
.v-stats { width: 100%; display: grid; grid-template-columns: auto 1fr; gap: 2px 6px; font-size: 10px; align-items: center; }
.v-stats em { color: #b9976a; font-style: normal; }
.v-stats i { height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--orange), var(--yellow)); display: block; }

.lobby-actions { margin-top: 22px; }
.wait-msg { text-align: center; margin-top: 10px; color: #d9b98c; font-size: 14px; min-height: 20px; }
.controls-hint { margin-top: 14px; text-align: center; font-size: 12px; color: #b9976a; }
.controls-hint b { color: var(--cream); background: rgba(0,0,0,.35); padding: 1px 6px; border-radius: 5px; }

/* ===== HUD ===== */
#hud { position: absolute; inset: 0; }
#hud.hidden { display: none; }

#hud-top-left { position: absolute; top: 18px; left: 20px; }
#hud-position {
  font-size: 44px; font-weight: 900; font-style: italic;
  color: var(--yellow); text-shadow: 0 3px 0 rgba(0,0,0,.5), 0 6px 20px rgba(0,0,0,.5);
}
#hud-lap {
  font-size: 20px; font-weight: 800;
  color: var(--cream); text-shadow: 0 2px 0 rgba(0,0,0,.5);
}

#hud-top-center { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); text-align: center; }
#hud-time {
  font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums;
  background: rgba(0,0,0,.4); padding: 4px 18px; border-radius: 10px;
  border: 1px solid rgba(255,200,100,.3);
}
#hud-room-tag { margin-top: 6px; font-size: 12px; color: #d9b98c; letter-spacing: 2px; }

#hud-bottom-right { position: absolute; bottom: 20px; right: 24px; text-align: right; }
#hud-speed {
  font-size: 46px; font-weight: 900; font-style: italic;
  color: var(--cream); text-shadow: 0 3px 0 rgba(0,0,0,.5), 0 6px 20px rgba(0,0,0,.5);
}
#hud-speed small { font-size: 16px; color: #d9b98c; }

#countdown {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%);
  font-size: 150px; font-weight: 900; font-style: italic;
  color: var(--orange);
  text-shadow: 0 6px 0 rgba(0,0,0,.4), 0 0 60px rgba(255,140,20,.8);
  animation: pop .9s ease-out;
}
#countdown.hidden { display: none; }
#countdown.go { color: var(--green); }
@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(2.2); opacity: 0; }
  18% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  85% { opacity: 1; }
  100% { opacity: 0; }
}

#wrong-way {
  position: absolute; top: 22%; left: 50%; transform: translateX(-50%);
  font-size: 26px; font-weight: 900; font-style: italic; color: var(--red);
  background: rgba(0,0,0,.55); padding: 8px 20px; border-radius: 10px;
  border: 2px solid var(--red); animation: blink 0.6s infinite alternate;
}
#wrong-way.hidden { display: none; }
@keyframes blink { from { opacity: .55; } to { opacity: 1; } }

#notification {
  position: absolute; top: 30%; left: 50%; transform: translateX(-50%);
  font-size: 30px; font-weight: 900; font-style: italic; color: var(--yellow);
  text-shadow: 0 3px 0 rgba(0,0,0,.5), 0 0 40px rgba(255,200,60,.7);
  white-space: nowrap;
}
#notification.hidden { display: none; }
#notification.show { animation: notif 2.2s ease-out forwards; }
@keyframes notif {
  0% { opacity: 0; transform: translateX(-50%) scale(1.6); }
  12% { opacity: 1; transform: translateX(-50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

#btn-mute { position: absolute; top: 18px; right: 20px; }

#mini-results {
  position: absolute; top: 70px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.55); border: 1px solid rgba(255,200,100,.35);
  border-radius: 12px; padding: 10px 18px; min-width: 260px;
}
#mini-results.hidden { display: none; }
#mini-results h3 { font-size: 13px; color: #d9b98c; margin-bottom: 6px; text-align: center; }
#mini-results ol { list-style: none; }
#mini-results li { display: flex; gap: 8px; font-size: 14px; padding: 2px 0; align-items: center; }
#mini-results .mr-rank { width: 20px; font-weight: 900; color: var(--yellow); }
#mini-results .mr-time { margin-left: auto; font-variant-numeric: tabular-nums; color: #d9b98c; }
#mini-results .mr-dots { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }

/* ===== résultats ===== */
.results-panel { text-align: center; }
.results-title { font-size: 34px; font-style: italic; font-weight: 900; color: var(--yellow); text-shadow: 0 3px 0 rgba(0,0,0,.4); margin-bottom: 18px; }
#results-list { list-style: none; margin: 0 auto 22px; max-width: 420px; }
#results-list li {
  display: flex; align-items: center; gap: 12px;
  background: rgba(0,0,0,.3); border: 1px solid rgba(255,170,80,.25);
  border-radius: 10px; padding: 10px 16px; margin-bottom: 8px;
  animation: slidein .5s ease-out;
}
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
#results-list .rank { font-size: 22px; font-weight: 900; font-style: italic; width: 34px; color: var(--orange); }
#results-list li:first-child .rank { color: var(--yellow); }
#results-list .pname { font-weight: 800; font-size: 17px; }
#results-list .pvehicle { font-size: 12px; color: #b9976a; }
#results-list .ptime { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 800; font-size: 16px; }
#results-list .ptime.dnf { color: var(--red); font-size: 13px; }
.results-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.results-actions .btn { width: auto; }

/* ===== overlays ===== */
.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: rgba(15,8,5,.8); font-size: 18px; color: var(--cream); z-index: 10;
}
.overlay.hidden { display: none; }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 5px solid rgba(255,170,80,.2); border-top-color: var(--orange);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: rgba(120,30,20,.95); border: 2px solid var(--red);
  color: #fff; font-weight: 700; padding: 10px 22px; border-radius: 10px; z-index: 20;
}
#toast.info { background: rgba(40,30,15,.95); border-color: var(--orange); }
#toast.hidden { display: none; }

@media (max-width: 640px) {
  #lobby-players { grid-template-columns: 1fr; }
  #countdown { font-size: 90px; }
  #hud-speed { font-size: 32px; }
  #hud-position { font-size: 30px; }
  .room-code { font-size: 30px; letter-spacing: 6px; }
}
