:root {
  --background: hsl(0 0% 98%);
  --foreground: hsl(0 0% 0%);
  --accent-1: hsl(0 0% 100%);
  --accent-2: hsl(0 0% 96%);
  --border: hsl(0 0% 0% / 0.1);
  --drift: hsl(35 100% 50%);
}

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

html,
body {
  width: 100%;
  height: 100%;
}

body {
  color: var(--foreground);
  background-color: var(--background);
  /* Subtle asphalt dot grid so the world reads less empty */
  background-image: radial-gradient(hsl(0 0% 0% / 0.045) 1px, transparent 1.4px);
  background-size: 26px 26px;
  font-family: "Google Sans", "Google Sans Text", system-ui, -apple-system,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
  overflow: hidden;
}

/* Viewport holds the stacked canvases and is what we shake */
.viewport {
  position: absolute;
  inset: 0;
  will-change: transform;
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.overlay button {
  pointer-events: auto;
}

header {
  position: absolute;
  top: 2rem;
  left: 0;
  right: 0;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: center;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

header.hidden {
  opacity: 0;
  transform: translateY(-12px);
  pointer-events: none;
}

h1 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.instructions {
  opacity: 0.6;
  font-size: 0.95rem;
}

.hud {
  position: absolute;
  top: 1rem;
  left: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.hud-speed {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.speed-value {
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.speed-unit {
  font-size: 0.85rem;
  opacity: 0.5;
  font-weight: 500;
}

.hud-score {
  display: flex;
  flex-direction: column;
}

.score-label {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  opacity: 0.45;
  font-weight: 500;
}

.score-value {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.hud-best {
  display: flex;
  flex-direction: column;
}

.best-value {
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  opacity: 0.6;
}

.boost {
  position: relative;
  width: 130px;
  height: 1.05rem;
  margin-top: 0.35rem;
  background: var(--border);
  border-radius: 1rem;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: box-shadow 0.2s ease;
}

.boost-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, hsl(45 100% 55%), hsl(14 100% 52%));
  border-radius: 1rem;
  transition: width 0.08s linear;
}

.boost-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: hsl(0 0% 0% / 0.5);
}

.boost.ready {
  box-shadow: 0 0 10px hsl(35 100% 50% / 0.7);
}

.boost.ready .boost-label {
  color: hsl(0 0% 100% / 0.9);
}

.boost.active .boost-fill {
  animation: boost-flicker 0.12s steps(2) infinite;
}

@keyframes boost-flicker {
  0% {
    filter: brightness(1);
  }
  100% {
    filter: brightness(1.4);
  }
}

/* Live drift meter — fades in only while drifting */
.drift-meter {
  position: absolute;
  top: 30%;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.drift-meter.active {
  opacity: 1;
  transform: scale(1);
}

.drift-meter.bump .drift-multiplier {
  animation: mult-bump 0.35s ease-out;
}

@keyframes mult-bump {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.5);
    color: var(--drift);
  }
  100% {
    transform: scale(1);
  }
}

.drift-points {
  font-size: 2rem;
  font-weight: 700;
  color: var(--drift);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 0 hsl(0 0% 100% / 0.6);
}

.drift-multiplier {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--foreground);
  opacity: 0.7;
}

.top-buttons {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.icon-button {
  cursor: pointer;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border);
  background: var(--accent-1);
  border-radius: 2.25rem;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--foreground);
}

.github-link {
  text-decoration: none;
  opacity: 0.7;
  transition: opacity 200ms ease;
}

.github-link:hover {
  opacity: 1;
}

.mute-toggle .mute-off {
  display: none;
}
.mute-toggle.muted .mute-on {
  display: none;
}
.mute-toggle.muted .mute-off {
  display: inline;
}

.clear-tire-marks {
  cursor: pointer;
  font-family: inherit;
  height: 2.25rem;
  border: 1px solid var(--border);
  background: var(--accent-1);
  border-radius: 2.25rem;
  font-size: 0.95rem;
  padding: 0 1rem;
  color: var(--foreground);
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.clear-tire-marks.visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.mobile-controls {
  padding: 0 clamp(0.4rem, 2vw, 0.75rem);
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  position: absolute;
  width: 100%;
  bottom: 0.75rem;
  gap: clamp(0.3rem, 1.8vw, 0.5rem);
}

.controls-right,
.controls-left {
  display: flex;
  gap: clamp(0.3rem, 1.8vw, 0.5rem);
}

.controls-mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: clamp(0.3rem, 1.5vw, 0.5rem);
}

/* Buttons scale with viewport width so 5 columns never get chopped off */
.control-button {
  border: 1px solid var(--border);
  background: var(--accent-1);
  width: clamp(3.1rem, 15vw, 5rem);
  height: clamp(3.1rem, 15vw, 5rem);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
}

.control-button:active {
  background: var(--accent-2);
}

.control-button img {
  opacity: 0.5;
  width: clamp(1.9rem, 9vw, 3rem);
}

.boost-btn {
  width: clamp(2.9rem, 13.5vw, 4.5rem);
  height: clamp(2.9rem, 13.5vw, 4.5rem);
  font-weight: 700;
  font-size: clamp(0.62rem, 2.6vw, 0.8rem);
  letter-spacing: 0.04em;
  color: hsl(210 100% 50%);
}

.boost-btn:active {
  background: hsl(210 100% 50%);
  color: var(--accent-1);
}
