:root {
  --red: #e52521;
  --yellow: #fbd000;
  --blue: #049cd8;
  --green: #43b047;
  --dark: #1b1b2f;
  --white: #fff;
  --shadow: 0 6px 0 rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #6ec6ff; font-family: 'Fredoka', system-ui, sans-serif; color: var(--dark); user-select: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; }
.screen.active { display: flex; }

/* Fond rayé animé */
.bg-stripes {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(-45deg, #ff5a4f 0 60px, var(--red) 60px 120px);
  background-size: 170px 170px;
  animation: stripes 3s linear infinite;
}
@keyframes stripes { to { background-position: 170px 0; } }

.pop { animation: pop .5s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Connexion */
.login-card {
  position: relative; width: min(420px, 92vw); padding: 34px 32px 26px;
  background: var(--white); border-radius: 28px; border: 6px solid var(--dark);
  box-shadow: 0 12px 0 var(--dark); text-align: center;
}
.logo { font-family: 'Luckiest Guy', cursive; font-size: 64px; line-height: 1; letter-spacing: 2px; transform: rotate(-4deg); margin-top: -8px; }
.logo span:first-child { color: var(--red); -webkit-text-stroke: 3px var(--dark); }
.logo span:last-child { color: var(--yellow); -webkit-text-stroke: 3px var(--dark); }
.tagline { font-weight: 600; margin: 10px 0 20px; color: #555; }
form label { display: block; text-align: left; font-weight: 700; margin-bottom: 14px; }
form input {
  width: 100%; margin-top: 6px; padding: 12px 16px; font: inherit; font-size: 18px;
  border: 4px solid var(--dark); border-radius: 16px; outline: none; transition: transform .15s, border-color .15s;
}
form input:focus { border-color: var(--blue); transform: scale(1.02); }
#in-code { text-transform: uppercase; letter-spacing: 6px; text-align: center; }
.colors-label { text-align: left; font-weight: 700; }
.colors { display: flex; gap: 10px; justify-content: center; margin: 8px 0 20px; }
.colors button {
  width: 38px; height: 38px; border-radius: 50%; border: 4px solid var(--dark); cursor: pointer;
  transition: transform .15s;
}
.colors button.sel { transform: scale(1.25); box-shadow: 0 0 0 4px var(--yellow); }

.btn {
  font-family: 'Luckiest Guy', cursive; font-size: 24px; letter-spacing: 1px; cursor: pointer;
  padding: 14px 28px; border: 5px solid var(--dark); border-radius: 20px; color: var(--white);
  -webkit-text-stroke: 1px var(--dark); box-shadow: 0 7px 0 var(--dark); transition: transform .1s, box-shadow .1s;
}
.btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--dark); }
.btn-go { background: linear-gradient(var(--green), #2e8a32); width: 100%; }
.btn-go:hover { filter: brightness(1.1); }
.btn:disabled { filter: grayscale(1); cursor: wait; }
.error { color: var(--red); font-weight: 700; min-height: 24px; margin-top: 12px; }
.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-10px); } 50% { transform: translateX(10px); } 75% { transform: translateX(-6px); } }

/* Chargement */
.loading-box { position: relative; text-align: center; color: var(--white); width: min(520px, 90vw); }
.loading-box h2 { font-family: 'Luckiest Guy', cursive; font-size: 44px; -webkit-text-stroke: 2px var(--dark); text-shadow: var(--shadow); }
.kart-bounce { font-size: 90px; animation: bounce .6s ease-in-out infinite alternate; transform-origin: bottom; }
@keyframes bounce { from { transform: translateY(0) rotate(-3deg); } to { transform: translateY(-18px) rotate(3deg); } }
.bar { height: 30px; margin: 22px 0 12px; background: var(--white); border: 5px solid var(--dark); border-radius: 20px; overflow: hidden; }
#load-fill {
  height: 100%; width: 0; transition: width .2s;
  background: repeating-linear-gradient(-45deg, var(--yellow) 0 16px, #ffb800 16px 32px);
  background-size: 45px 45px; animation: stripes 1s linear infinite;
}
#load-step { font-weight: 700; font-size: 18px; }
.tip { margin-top: 18px; background: rgba(0,0,0,.25); padding: 10px 16px; border-radius: 14px; }

/* HUD */
.hud { pointer-events: none; display: none; }
.hud.active { display: block; }
.hud-top-left { position: absolute; top: 18px; left: 22px; }
.pos {
  font-family: 'Luckiest Guy', cursive; font-size: 96px; line-height: 1; color: var(--yellow);
  -webkit-text-stroke: 4px var(--dark); text-shadow: 0 6px 0 var(--dark); transition: transform .2s;
}
.pos sup { font-size: 40px; }
.pos.bump { transform: scale(1.3); }
.hud-lap, .timer, .best, .speed, .players-list, .help {
  color: var(--white); font-weight: 700; text-shadow: 0 3px 0 var(--dark), 0 0 6px rgba(0,0,0,.6);
}
.hud-lap { font-size: 30px; }
.hud-top-right { position: absolute; top: 20px; right: 24px; text-align: right; }
.timer { font-family: 'Luckiest Guy', cursive; font-size: 44px; letter-spacing: 1px; }
.best { font-size: 16px; line-height: 1.4; }
#minimap {
  position: absolute; left: 20px; bottom: 20px; width: 200px; height: 200px;
  background: rgba(255,255,255,.2); border: 4px solid rgba(27,27,47,.8); border-radius: 50%;
}
.hud-bottom-right { position: absolute; right: 26px; bottom: 20px; width: 220px; text-align: center; }
.speedo { width: 220px; }
.speedo-bg { fill: none; stroke: rgba(0,0,0,.35); stroke-width: 18; stroke-linecap: round; }
.speedo-fg { fill: none; stroke: var(--yellow); stroke-width: 18; stroke-linecap: round; stroke-dasharray: 252; stroke-dashoffset: 252; transition: stroke .2s; }
.speed { margin-top: -62px; font-family: 'Luckiest Guy', cursive; font-size: 50px; }
.speed small { font-size: 18px; margin-left: 4px; }
.drift { height: 26px; font-weight: 700; font-size: 20px; margin-top: 4px; }
.players-list { position: absolute; top: 160px; left: 24px; font-size: 16px; line-height: 1.7; }
.players-list .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--dark); margin-right: 6px; vertical-align: -1px; }
.players-list .me { color: var(--yellow); }
.banner {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%); text-align: center;
  font-family: 'Luckiest Guy', cursive; font-size: 30px; color: var(--white); -webkit-text-stroke: 1.5px var(--dark);
  text-shadow: 0 4px 0 var(--dark); background: rgba(27,27,47,.35); padding: 14px 30px; border-radius: 20px; display: none;
}
.banner small { display: block; font-family: 'Fredoka'; -webkit-text-stroke: 0; font-size: 18px; margin-top: 6px; }
.banner.show { display: block; animation: pop .4s cubic-bezier(.2,1.6,.4,1); }
.countdown {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  font-family: 'Luckiest Guy', cursive; font-size: 200px; color: var(--yellow); -webkit-text-stroke: 6px var(--dark);
  text-shadow: 0 10px 0 var(--dark);
}
.countdown.go { color: var(--green); }
.countdown.tick { animation: tick .9s ease-out both; }
@keyframes tick { from { transform: translate(-50%, -50%) scale(2.2); opacity: 0; } 25% { transform: translate(-50%, -50%) scale(1); opacity: 1; } to { transform: translate(-50%, -50%) scale(.8); opacity: 0; } }
.toast {
  position: absolute; left: 50%; top: 12%; transform: translateX(-50%); opacity: 0; transition: opacity .3s;
  font-family: 'Luckiest Guy', cursive; font-size: 28px; color: var(--white); -webkit-text-stroke: 1.2px var(--dark); text-shadow: 0 4px 0 var(--dark);
}
.toast.show { opacity: 1; }
.help { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); font-size: 14px; opacity: .85; white-space: nowrap; }

/* Résultats */
#screen-results { background: rgba(27, 27, 47, .55); backdrop-filter: blur(3px); }
.results-card {
  width: min(560px, 94vw); background: var(--white); border: 6px solid var(--dark); border-radius: 28px;
  box-shadow: 0 12px 0 var(--dark); padding: 26px 30px; text-align: center;
}
.results-title { font-family: 'Luckiest Guy', cursive; font-size: 54px; color: var(--yellow); -webkit-text-stroke: 3px var(--dark); }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; height: 190px; margin: 14px 0 18px; }
.podium .step { width: 120px; display: flex; flex-direction: column; align-items: center; animation: rise .7s cubic-bezier(.2,1.4,.4,1) both; }
.podium .step .name { font-weight: 700; margin-bottom: 4px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium .step .block {
  width: 100%; border: 4px solid var(--dark); border-radius: 12px 12px 0 0; display: flex; align-items: flex-start; justify-content: center;
  font-family: 'Luckiest Guy', cursive; font-size: 40px; color: var(--white); -webkit-text-stroke: 2px var(--dark); padding-top: 6px;
}
.podium .p1 .block { height: 130px; background: var(--yellow); }
.podium .p2 .block { height: 95px; background: #c0c8d0; }
.podium .p3 .block { height: 70px; background: #d9914a; }
.podium .p1 { animation-delay: .3s; } .podium .p2 { animation-delay: .1s; } .podium .p3 { animation-delay: .5s; }
@keyframes rise { from { transform: translateY(80px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.results-list { list-style: none; text-align: left; margin-bottom: 20px; max-height: 200px; overflow: auto; }
.results-list li { display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-radius: 12px; font-weight: 600; font-size: 18px; }
.results-list li:nth-child(odd) { background: #f1f3f8; }
.results-list li.me { background: #fff4bf; }
.results-list .rk { font-family: 'Luckiest Guy', cursive; width: 40px; font-size: 22px; }
.results-list .nm { flex: 1; }
.results-list .dot { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--dark); }

/* Tir */
.btn-fire {
  position: absolute; left: 50%; bottom: 44px; transform: translateX(-50%); pointer-events: auto;
  width: 84px; height: 84px; border-radius: 50%; border: 5px solid var(--dark); cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #ffe27a, #ff8c00 55%, #e52521); box-shadow: 0 6px 0 var(--dark);
  font-size: 36px; line-height: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  opacity: .55; filter: grayscale(.6); transition: opacity .15s, filter .15s, transform .1s;
}
.btn-fire small { font-family: 'Luckiest Guy', cursive; font-size: 14px; color: var(--white); -webkit-text-stroke: 1px var(--dark); }
.btn-fire.ready { opacity: 1; filter: none; }
.btn-fire:active { transform: translateX(-50%) scale(.92); }
.btn-fire.cd { animation: firecd .2s linear; }
@keyframes firecd { from { transform: translateX(-50%) scale(.85); } to { transform: translateX(-50%) scale(1); } }
.hud.hit::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255,120,0,0) 40%, rgba(255,60,0,.55)); animation: hitflash .7s ease-out both;
}
@keyframes hitflash { from { opacity: 1; } to { opacity: 0; } }
