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

html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: 'Poppins', sans-serif;
  background: #0b0e1a;
  color: #fff;
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app { position: fixed; inset: 0; }

#game-canvas, #preview-canvas { display: block; width: 100%; height: 100%; }

#game-canvas { position: absolute; inset: 0; }

#vignette {
  position: absolute; inset: 0; pointer-events: none; z-index: 4;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.45) 100%);
}

.hidden { display: none !important; }

.screen {
  position: absolute; inset: 0; z-index: 10;
  display: none;
  align-items: center; justify-content: center;
  flex-direction: column;
}
.screen.active {
  display: flex;
}

.menu-panel {
  background: rgba(12, 16, 34, 0.78);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 22px;
  padding: 38px 46px;
  text-align: center;
  backdrop-filter: blur(10px);
  box-shadow: 0 24px 80px rgba(0,0,0,0.55), 0 0 60px rgba(80,140,255,0.12);
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  animation: panelIn 0.5s cubic-bezier(.2,.9,.3,1.2);
  max-width: 92vw;
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(26px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.title {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900; font-size: clamp(34px, 7vw, 64px);
  letter-spacing: 3px; line-height: 1;
  background: linear-gradient(180deg, #ffffff 0%, #9ecbff 55%, #4f7dff 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 14px rgba(80,140,255,0.45));
}
.title span {
  background: linear-gradient(180deg, #ffd34d, #ff7a2f);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

.subtitle {
  color: #9fb3d8; letter-spacing: 6px; text-transform: uppercase; font-size: 12px;
  font-weight: 600;
}

.btn {
  font-family: 'Orbitron', sans-serif;
  font-weight: 700; font-size: 15px; letter-spacing: 2px;
  color: #dbe6ff; background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 13px 30px; border-radius: 14px; cursor: pointer;
  transition: transform 0.12s, box-shadow 0.2s, background 0.2s;
  min-width: 200px;
}
.btn:hover { background: rgba(255,255,255,0.16); transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, #ffd34d, #ff7a2f);
  color: #2b1600; border: none;
  box-shadow: 0 10px 30px rgba(255,140,40,0.4);
  font-size: 17px;
}
.btn.primary:hover { box-shadow: 0 14px 40px rgba(255,140,40,0.6); }
.btn.small { min-width: 130px; padding: 10px 16px; font-size: 12px; }

.menu-row { display: flex; gap: 10px; }

.name-input {
  width: 240px;
  font-family: 'Orbitron', sans-serif;
  font-size: 14px; letter-spacing: 2px; text-align: center;
  color: #dbe6ff; background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 14px; padding: 12px 16px; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.name-input::placeholder { color: #7f92bd; letter-spacing: 3px; }
.name-input:focus {
  border-color: #ffb454; background: rgba(255,255,255,0.12);
  box-shadow: 0 0 0 3px rgba(255,170,60,0.25);
}

#end-winner {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900; font-size: clamp(20px, 4vw, 30px);
  letter-spacing: 2px;
  background: linear-gradient(180deg, #d4ff7d, #3ad97c);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 14px rgba(60,220,140,0.4));
  margin-bottom: 2px;
}
#end-winner.lose {
  background: linear-gradient(180deg, #ff9a7d, #ff4d5e);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 14px rgba(255,80,100,0.4));
}

#end-pos {
  font-family: 'Orbitron', sans-serif;
  font-weight: 800; font-size: clamp(14px, 2.6vw, 20px);
  letter-spacing: 2px; color: #eaf2ff;
  text-shadow: 0 2px 10px rgba(0,0,0,0.55);
  margin-bottom: 4px;
}

#end-trophy {
  font-size: clamp(48px, 10vw, 72px);
  line-height: 1;
  margin: 6px 0 2px;
  animation: trophy-pop 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) both, trophy-float 1.6s ease-in-out 0.8s infinite;
  filter: drop-shadow(0 6px 18px rgba(255,200,80,0.55));
}
@keyframes trophy-pop {
  0% { transform: scale(0) rotate(-30deg); opacity: 0; }
  70% { transform: scale(1.25) rotate(8deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
@keyframes trophy-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.best-list { display: flex; flex-direction: column; gap: 5px; min-width: 260px; }
.best-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 6px 12px; border-radius: 10px;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
  font-family: 'Orbitron', sans-serif; font-size: 12px; letter-spacing: 1px;
  color: #b9c8ec;
}
.best-row .rank { color: #ffd34d; font-weight: 700; min-width: 20px; text-align: left; }
.best-row .pname { flex: 1; text-align: left; color: #dbe6ff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.best-row .pdist { color: #9ecbff; font-weight: 700; }
.best-row.me { border-color: #ffb454; background: rgba(255,180,84,0.14); box-shadow: 0 0 12px rgba(255,170,60,0.2); }
.best-row.me .pname { color: #ffd34d; }

#podium {
  margin: 8px 0 4px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.podium-row { display: flex; align-items: flex-end; justify-content: center; gap: 10px; }
.podium-place { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 92px; }
.podium-place .podium-medal { font-size: 28px; line-height: 1; }
.podium-place .podium-name {
  font-family: 'Orbitron', sans-serif; font-size: 11px; letter-spacing: 1px;
  color: #dbe6ff; max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.podium-place .podium-dist { font-family: 'Orbitron', sans-serif; font-size: 10px; color: #9ecbff; }
.podium-block { width: 84px; border-radius: 8px 8px 0 0; }
.podium-place.first .podium-block { height: 88px; background: linear-gradient(180deg, #ffd34d, #c9961c); box-shadow: 0 0 18px rgba(255,211,77,0.45); }
.podium-place.second .podium-block { height: 62px; background: linear-gradient(180deg, #cbd4e0, #8f9cb0); }
.podium-place.third .podium-block { height: 44px; background: linear-gradient(180deg, #e0a878, #a86a38); }
.podium-place.me .podium-name { color: #ffb454; }
.podium-place.empty { opacity: 0.45; }
.podium-place.first .podium-name { font-weight: 700; }

.controls-hint {
  color: #7f92bd; font-size: 11px; letter-spacing: 1px; margin-top: 6px;
}

.screen-title {
  font-family: 'Orbitron', sans-serif;
  font-weight: 800; font-size: clamp(26px, 5vw, 44px);
  letter-spacing: 3px; margin-bottom: 4px;
  background: linear-gradient(180deg, #fff, #9ecbff);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

.garage-panel {
  background: rgba(10, 14, 30, 0.85);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 22px;
  padding: 26px 30px;
  backdrop-filter: blur(10px);
  box-shadow: 0 24px 80px rgba(0,0,0,0.55);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  width: min(920px, 94vw);
  max-height: 94vh; overflow-y: auto;
  animation: panelIn 0.5s cubic-bezier(.2,.9,.3,1.2);
}

.garage-body { display: flex; gap: 26px; align-items: stretch; width: 100%; flex-wrap: wrap; justify-content: center; }

.preview-wrap { flex: 0 0 300px; display: flex; flex-direction: column; align-items: center; gap: 8px; }

#preview-canvas-wrap {
  width: 300px; height: 200px; border-radius: 18px;
  background: radial-gradient(circle at 50% 70%, #2a3a6b, #0d1430);
  border: 1px solid rgba(255,255,255,0.12);
  overflow: hidden;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.5);
}

.car-name {
  font-family: 'Orbitron', sans-serif; font-weight: 800; letter-spacing: 4px;
  color: #ffd34d; font-size: 18px;
}
.car-desc { color: #9fb3d8; font-size: 12px; letter-spacing: 2px; text-transform: uppercase; }

.options { flex: 1 1 420px; display: flex; flex-direction: column; gap: 14px; justify-content: center; }

.option-row { display: flex; align-items: center; gap: 14px; }
.opt-label {
  font-family: 'Orbitron', sans-serif; font-size: 11px; font-weight: 700;
  letter-spacing: 2px; color: #9fb3d8; width: 78px; flex: 0 0 78px; text-align: right;
}
.opt-btns { display: flex; gap: 8px; flex-wrap: wrap; }

.opt {
  font-family: 'Orbitron', sans-serif; font-size: 11px; font-weight: 700;
  letter-spacing: 1px; color: #9fb3d8;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 10px; padding: 8px 14px; cursor: pointer;
  transition: all 0.15s;
}
.opt:hover { background: rgba(255,255,255,0.14); }
.opt.active {
  background: linear-gradient(135deg, #ffd34d, #ff7a2f);
  color: #2b1600; border-color: transparent;
  box-shadow: 0 6px 18px rgba(255,140,40,0.4);
}

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  border: 3px solid rgba(255,255,255,0.2);
  transition: transform 0.12s, border-color 0.15s, box-shadow 0.15s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(255,211,77,0.55), 0 0 16px rgba(255,211,77,0.5);
  transform: scale(1.1);
}

.garage-actions { display: flex; gap: 14px; }

#hud {
  position: absolute; inset: 0; z-index: 6; pointer-events: none;
  padding: 18px 22px; display: flex; flex-direction: column; justify-content: space-between;
}

#hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }

.hud-speed {
  font-family: 'Orbitron', sans-serif; font-size: 34px; font-weight: 900;
  color: #fff; text-shadow: 0 2px 12px rgba(0,0,0,0.5); line-height: 1;
}
.hud-speed .hud-unit { font-size: 13px; color: #9fd0ff; margin-left: 4px; }

#lives { display: flex; gap: 8px; padding-top: 6px; }
.life {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, #ff5a4e, #d91e18);
  box-shadow: 0 4px 12px rgba(217,30,24,0.5);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: #fff;
}
.life.lost { background: rgba(255,255,255,0.08); box-shadow: none; color: #5b6478; }

#hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }

#dist-label {
  font-family: 'Orbitron', sans-serif; font-size: 13px; letter-spacing: 1px;
  color: #cfe0ff; text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
#dist-label b { font-size: 17px; }
#finish-dist { color: #7f92bd; }

#pos-label {
  font-family: 'Orbitron', sans-serif; font-size: 13px; letter-spacing: 1px;
  color: #ffd34d; text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
#pos-label b { font-size: 17px; color: #fff; }

.hud-btn {
  pointer-events: auto; cursor: pointer;
  width: 38px; height: 38px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(10,16,36,0.55);
  color: #fff; font-family: 'Orbitron', sans-serif; font-weight: 800; font-size: 14px;
  backdrop-filter: blur(6px);
}
.hud-btn:hover { background: rgba(255,255,255,0.2); }

.bars { display: flex; flex-direction: column; gap: 9px; max-width: 420px; }

.bar-row { display: flex; align-items: center; gap: 10px; }

.bar-label {
  font-family: 'Orbitron', sans-serif; font-size: 10px; font-weight: 700;
  letter-spacing: 2px; color: #9fb3d8; width: 46px;
}
.bar-label.fuel { color: #7dff9b; }
.bar-label.race { color: #ffd34d; }

.bar {
  flex: 1; height: 15px; border-radius: 9px;
  background: rgba(255,255,255,0.09);
  border: 1px solid rgba(255,255,255,0.14);
  overflow: hidden;
}
.bar > div {
  height: 100%; border-radius: 9px; width: 100%;
  transition: width 0.15s linear;
}
#fuel-bar {
  background: linear-gradient(90deg, #ff4d3a, #ffb03a);
  box-shadow: 0 0 14px rgba(255,120,40,0.7);
}
#fuel-bar.low { animation: pulse 0.8s infinite; }
#progress-bar {
  background: linear-gradient(90deg, #37e0ff, #ffd34d);
  box-shadow: 0 0 14px rgba(80,200,255,0.7);
}

@keyframes pulse { 50% { opacity: 0.45; } }

#boost-tag {
  position: absolute; top: 118px; left: 50%; transform: translateX(-50%);
  font-family: 'Orbitron', sans-serif; font-weight: 900; font-size: 22px;
  letter-spacing: 6px; color: #fff;
  background: linear-gradient(90deg, #ff5f6d, #ffc371);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  text-shadow: 0 0 24px rgba(255,120,60,0.8);
  animation: boostPulse 0.4s infinite alternate;
}
@keyframes boostPulse { from { transform: translateX(-50%) scale(1); } to { transform: translateX(-50%) scale(1.12); } }

#offroad-tag {
  position: absolute; top: 150px; left: 50%; transform: translateX(-50%);
  font-family: 'Orbitron', sans-serif; font-weight: 900; font-size: 20px;
  letter-spacing: 6px; color: #ffd34d;
  text-shadow: 0 0 18px rgba(255,150,50,0.9);
  animation: boostPulse 0.35s infinite alternate;
}

#curve-tag {
  position: absolute; top: 182px; left: 50%; transform: translateX(-50%);
  font-family: 'Orbitron', sans-serif; font-weight: 900; font-size: 19px;
  letter-spacing: 5px; color: #7fd8ff;
  text-shadow: 0 0 18px rgba(80,180,255,0.9);
  animation: boostPulse 0.4s infinite alternate;
}

#hint-tags { display: flex; gap: 10px; justify-content: center; }
.hint-tag {
  font-family: 'Orbitron', sans-serif; font-size: 10px; letter-spacing: 2px;
  color: rgba(255,255,255,0.55); background: rgba(10,16,36,0.4);
  padding: 6px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.12);
}

#countdown {
  position: absolute; inset: 0; z-index: 9;
  display: flex; align-items: center; justify-content: center; pointer-events: none;
}
#countdown-num {
  font-family: 'Orbitron', sans-serif; font-weight: 900;
  font-size: 120px; color: #fff;
  text-shadow: 0 0 40px rgba(80,160,255,0.9);
  animation: countPop 1s ease-out;
}
@keyframes countPop {
  from { opacity: 0; transform: scale(2.2); }
  30% { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.8); }
}

.end-result-wrap { display: flex; gap: 26px; flex-wrap: wrap; justify-content: center; margin: 6px 0 10px; }
.end-stat { display: flex; flex-direction: column; gap: 2px; min-width: 120px; }
.end-label {
  font-family: 'Orbitron', sans-serif; font-size: 10px; letter-spacing: 2px; color: #9fb3d8;
}
.end-stat b { font-family: 'Orbitron', sans-serif; font-size: 24px; color: #ffd34d; }

#end-title.win { background: linear-gradient(180deg, #d4ff7d, #3ad97c); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

#touch-zone {
  position: absolute; inset: 0; z-index: 5; display: grid;
  grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
  pointer-events: none;
}
@media (pointer: coarse) { #touch-zone { display: grid; } }
@media (pointer: fine) { #touch-zone { display: none; } }
.tzone { pointer-events: auto; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 8px; }
