html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1b1b1b;
  font-family: system-ui, sans-serif;
  color: #fff;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

.hidden {
  display: none !important;
}

/* While the menu is open, hide the race UI. */
body.in-menu #hud,
body.in-menu #touch,
body.in-menu #countdown,
body.in-menu #controls {
  display: none;
}

#hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 8px;
  font-size: 17px;
  line-height: 1.5;
  font-weight: 600;
  text-shadow: 0 1px 2px #000;
}

#countdown {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(80px, 22vmin, 140px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 4px 12px #000;
  pointer-events: none;
}

/* Difficulty menu */
#menu {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
}

#menu .panel,
#results {
  width: min(90vw, 360px);
  padding: 24px 26px;
  background: rgba(0, 0, 0, 0.85);
  border-radius: 14px;
  text-align: center;
  box-sizing: border-box;
}

#menu h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 8vmin, 40px);
  color: #ffd54f;
  text-shadow: 0 3px 8px #000;
}

#menu .label {
  margin: 0;
  font-size: 15px;
  opacity: 0.85;
}

.diffs {
  display: flex;
  gap: 10px;
  margin: 14px 0 8px;
}

.diff {
  flex: 1;
  padding: 12px 0;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.diff.active {
  background: #fdd835;
  border-color: #fdd835;
  color: #222;
}

#diffHelp {
  min-height: 44px;
  margin: 6px 0 16px;
  font-size: 15px;
  opacity: 0.85;
}

.primary,
.secondary {
  font-size: 17px;
  padding: 12px 18px;
  border-radius: 8px;
  border: 0;
  color: #fff;
  cursor: pointer;
}

.primary {
  background: #e53935;
}

.secondary {
  background: rgba(255, 255, 255, 0.15);
}

/* Results */
#results h2 {
  margin: 0 0 12px;
}

#standings {
  text-align: left;
  padding-left: 24px;
  margin: 0 0 18px;
  font-size: 18px;
  line-height: 1.7;
}

#results .row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* On-screen controls for phones and tablets. */
#touch {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  pointer-events: none;
}

#touch .pad {
  display: flex;
  gap: 14px;
}

.btn {
  width: clamp(64px, 20vmin, 96px);
  height: clamp(64px, 20vmin, 96px);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: clamp(16px, 4.5vmin, 22px);
  font-weight: 800;
  pointer-events: auto;
  touch-action: none;
  -webkit-touch-callout: none;
  cursor: pointer;
}

.btn.gas {
  background: rgba(67, 160, 71, 0.6);
}

.btn.brake {
  background: rgba(229, 57, 53, 0.55);
}

.btn.active {
  filter: brightness(1.6);
  transform: scale(0.95);
}

#controls {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 6px;
  font-size: 14px;
  opacity: 0.85;
  white-space: nowrap;
}

/* Touch devices get on-screen buttons, so the keyboard hint is not needed there. */
@media (pointer: coarse) {
  #controls {
    display: none;
  }
}
