:root {
  --accent: #ff5a1f;
  --accent2: #ffc93c;
  --panel: rgba(12, 16, 26, 0.72);
  --text: #eef3ff;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b1020;
  font-family: 'Rajdhani', 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game { position: relative; width: 100vw; height: 100vh; }

#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.hud-top {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
}

.hud-box {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 8px 16px;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

.hud-label {
  display: block;
  font-size: 10px;
  letter-spacing: 3px;
  color: rgba(238, 243, 255, 0.55);
  font-weight: 600;
}

.hud-value {
  font-family: 'Orbitron', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

#timeVal { font-variant-numeric: tabular-nums; }

.minimap-box { text-align: center; }
.minimap-box canvas {
  display: block;
  margin-top: 4px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.35);
}

.hud-bottom {
  position: absolute;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
}

#speedo {
  font-family: 'Orbitron', sans-serif;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 10px 34px;
  backdrop-filter: blur(6px);
  display: inline-block;
}

#speedVal {
  font-size: 46px;
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(180deg, #fff 20%, #9fb2e0);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

#speedUnit {
  font-size: 14px;
  letter-spacing: 2px;
  color: rgba(238, 243, 255, 0.6);
  margin-left: 8px;
}

#statusMsg {
  margin-top: 8px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--accent2);
  min-height: 20px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

#nitroBox {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 6px 14px;
  backdrop-filter: blur(6px);
}

#nitroLabel {
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #57c7ff;
}

#nitroBar {
  width: 160px;
  height: 10px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

#nitroFill {
  height: 100%;
  width: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, #39a0ff, #6fe3ff);
  transition: width 0.08s linear;
  box-shadow: 0 0 10px rgba(87, 199, 255, 0.8);
}

#nitroFill.empty { background: linear-gradient(90deg, #2a3140, #3a4354); box-shadow: none; }

.hud-actions {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  justify-content: center;
  pointer-events: none;
}

.hud-actions button {
  pointer-events: auto;
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: rgba(238, 243, 255, 0.9);
  background: rgba(10, 14, 26, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 20px;
  padding: 8px 16px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.hud-actions button:hover {
  background: rgba(255, 90, 31, 0.35);
  border-color: var(--accent);
  color: #ffffff;
}

.hud-actions button:active { transform: translateY(1px); }

#hud.paused { opacity: 0.35; transition: opacity 0.15s ease; }

.hud-actions.top-hud {
  position: absolute;
  top: 300px;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 0;
}

@media (pointer: coarse) {
  .hud-actions.top-hud { top: 292px; }
}

/* ---------- Touch controls ---------- */
#touchControls {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.tc-btn {
  position: absolute;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: rgba(255, 255, 255, 0.9);
  pointer-events: auto;
  touch-action: none;
}

.tc-btn.pressed { background: rgba(255, 90, 31, 0.55); border-color: var(--accent); }

#tc-left  { left: 18px;  bottom: 40px; }
#tc-right { left: 104px; bottom: 40px; }
#tc-up    { right: 18px; bottom: 100px; }
#tc-down  { right: 104px; bottom: 40px; }
#tc-nitro { right: 18px; bottom: 178px; font-size: 15px; font-family: 'Orbitron', sans-serif; }

/* ---------- Flash (crash) ---------- */
#flash {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: radial-gradient(circle at center, rgba(255, 60, 20, 0.0), rgba(255, 40, 10, 0.75));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease-out;
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10, 14, 28, 0.55), rgba(6, 9, 18, 0.88));
  backdrop-filter: blur(3px);
}

.overlay-card {
  text-align: center;
  max-width: 620px;
  padding: 36px 48px;
  background: rgba(10, 14, 26, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 22px;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.6);
}

.title {
  font-family: 'Orbitron', sans-serif;
  font-size: 52px;
  font-weight: 900;
  letter-spacing: 4px;
  line-height: 1.05;
  background: linear-gradient(120deg, #fff 10%, #9fd8ff 45%, var(--accent) 95%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.title span {
  background: linear-gradient(120deg, var(--accent2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tagline {
  margin-top: 14px;
  font-size: 19px;
  font-weight: 500;
  color: rgba(238, 243, 255, 0.85);
}

.pause-title { font-size: 40px; }

.feature-row {
  margin-top: 18px;
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.feature-row span {
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 7px 14px;
  border-radius: 30px;
  border: 1px solid var(--accent);
  color: var(--accent2);
  background: rgba(255, 90, 31, 0.1);
}

.controls {
  margin: 22px auto 0;
  list-style: none;
  display: inline-grid;
  grid-template-columns: auto auto;
  gap: 8px 26px;
  text-align: left;
  font-size: 16px;
  color: rgba(238, 243, 255, 0.9);
}

.controls b {
  display: inline-block;
  min-width: 84px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 2px 10px;
  margin-right: 8px;
  text-align: center;
  font-family: 'Orbitron', sans-serif;
  font-size: 12px;
  letter-spacing: 1px;
}

.controls .mob {
  display: none;
  grid-column: 1 / -1;
  text-align: center;
  font-size: 14px;
  color: rgba(238, 243, 255, 0.6);
}

.big-btn {
  margin-top: 26px;
  font-family: 'Orbitron', sans-serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #10131c;
  background: linear-gradient(120deg, var(--accent2), var(--accent));
  border: none;
  border-radius: 14px;
  padding: 16px 46px;
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(255, 90, 31, 0.4);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.big-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 40px rgba(255, 90, 31, 0.55); }
.big-btn:active { transform: translateY(0); }

.over-btns {
  display: flex;
  gap: 14px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.ghost-btn {
  margin-top: 26px;
  font-family: 'Orbitron', sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 2px;
  color: rgba(238, 243, 255, 0.85);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 14px;
  padding: 16px 28px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.4);
}
.ghost-btn:active { transform: translateY(0); }

.portal-link {
  margin-top: 16px;
  display: inline-block;
  font-family: 'Orbitron', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  text-decoration: none;
  color: rgba(238, 243, 255, 0.6);
  padding: 8px 12px;
  border-radius: 10px;
  transition: color 0.12s ease, background 0.12s ease;
}
.portal-link:hover { color: #ffffff; background: rgba(255, 255, 255, 0.08); }

/* ---------- Menu options (car / color / difficulty) ---------- */
.options {
  margin: 20px auto 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 480px;
}

.opt-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: rgba(238, 243, 255, 0.55);
  min-width: 84px;
  text-align: right;
}

.opt-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}

.opt-btn {
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: rgba(238, 243, 255, 0.8);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.opt-btn:hover { background: rgba(255, 255, 255, 0.14); }

.opt-btn.active {
  color: #10131c;
  background: linear-gradient(120deg, var(--accent2), var(--accent));
  border-color: transparent;
}

.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  cursor: pointer;
  transition: all 0.12s ease;
}

.swatch:hover { transform: scale(1.12); }

.swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 3px var(--accent), 0 0 14px rgba(255, 90, 31, 0.6);
}

/* ---------- Winners board ---------- */
.winners-wrap {
  margin: 22px auto 0;
  max-width: 420px;
}

.winners-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--accent2);
}

.winners {
  margin-top: 10px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.winners li {
  font-family: 'Orbitron', sans-serif;
  font-size: 13px;
  letter-spacing: 1px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 7px 14px;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.winners li.current {
  border-color: var(--accent2);
  background: rgba(255, 201, 60, 0.12);
  color: var(--accent2);
}

/* ---------- Driver name input ---------- */
.name-input {
  flex: 1;
  min-width: 0;
  font-family: 'Orbitron', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #eef3ff;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 8px 14px;
  outline: none;
  text-transform: uppercase;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.name-input::placeholder { color: rgba(238, 243, 255, 0.35); }

.name-input:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px rgba(255, 201, 60, 0.2);
}

/* ---------- Victory greeting ---------- */
.greeting {
  margin-top: 6px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--accent2);
}

/* ---------- Loading overlay ---------- */
#loading {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 12, 22, 0.82);
  backdrop-filter: blur(4px);
}

.loading-card {
  font-family: 'Orbitron', sans-serif;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 4px;
  color: #eef3ff;
  padding: 22px 34px;
  border: 1px solid rgba(255, 201, 60, 0.4);
  border-radius: 14px;
  background: rgba(16, 19, 28, 0.9);
  box-shadow: 0 0 30px rgba(255, 90, 31, 0.25);
  animation: loadpulse 1.1s ease-in-out infinite;
}

@keyframes loadpulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.hint {
  margin-top: 16px;
  font-size: 13px;
  letter-spacing: 1px;
  color: rgba(238, 243, 255, 0.45);
}

@media (pointer: coarse) {
  .controls .mob { display: block; }
}

@media (max-width: 620px) {
  .title { font-size: 36px; }
  .overlay-card { padding: 26px 22px; }
  #speedVal { font-size: 36px; }
  .opt-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .opt-label { text-align: left; }
  .opt-group { justify-content: center; }
}

/* Fit on shorter laptop viewports: compact menu/pause/victory cards */
@media (max-height: 960px) {
  .overlay-card { padding: 30px 44px; }
  .title { font-size: 46px; letter-spacing: 3px; }
  .pause-title { font-size: 36px; }
  .tagline { margin-top: 10px; font-size: 17px; }
  .feature-row { margin-top: 16px; gap: 9px; }
  .controls { margin-top: 18px; gap: 7px 24px; }
  .options { margin-top: 16px; gap: 10px; }
  .winners-wrap { margin-top: 18px; }
  .big-btn { margin-top: 20px; font-size: 19px; padding: 15px 42px; }
  .ghost-btn { margin-top: 22px; padding: 14px 26px; }
  .greeting { margin-top: 4px; }
  .hint { margin-top: 14px; }
}

@media (max-height: 860px) {
  .overlay-card { padding: 22px 38px; }
  .title { font-size: 40px; letter-spacing: 3px; }
  .pause-title { font-size: 34px; }
  .tagline { margin-top: 8px; font-size: 16px; }
  .feature-row { margin-top: 12px; gap: 8px; }
  .controls { margin-top: 14px; gap: 6px 22px; font-size: 15px; }
  .options { margin-top: 12px; gap: 8px; }
  .winners-wrap { margin-top: 12px; }
  .big-btn { margin-top: 16px; padding: 13px 40px; }
  .ghost-btn { margin-top: 18px; padding: 13px 24px; }
  .greeting { margin-top: 4px; }
  .hint { margin-top: 12px; }
}

@media (max-height: 730px) {
  .overlay-card { padding: 16px 32px; }
  .title { font-size: 32px; letter-spacing: 2px; }
  .pause-title { font-size: 28px; }
  .tagline { margin-top: 6px; font-size: 14px; }
  .feature-row { margin-top: 10px; gap: 6px; }
  .feature-row span { padding: 5px 11px; font-size: 10px; letter-spacing: 1px; }
  .controls { margin-top: 10px; gap: 4px 18px; font-size: 14px; }
  .controls b { min-width: 70px; padding: 1px 8px; margin-right: 6px; }
  .options { margin-top: 10px; gap: 6px; }
  .opt-btn { padding: 6px 12px; }
  .swatch { width: 26px; height: 26px; }
  .name-input { padding: 6px 12px; }
  .big-btn { margin-top: 12px; font-size: 18px; padding: 11px 34px; }
  .ghost-btn { margin-top: 14px; padding: 11px 20px; }
  .winners { margin-top: 6px; gap: 4px; }
  .winners li { padding: 5px 12px; }
  .hint { margin-top: 10px; }
}

@media (max-height: 620px) {
  .feature-row { display: none; }
  .overlay-card { padding: 12px 26px; }
  .title { font-size: 27px; }
  .controls { margin-top: 8px; }
  .options { margin-top: 8px; }
}
