:root {
  --ink: #e8f1ff;
  --muted: #8aa0c0;
  --panel: rgba(8, 14, 28, 0.72);
  --accent: #3ec6ff;
  --fly: #ffffff;
}

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

html, body {
  height: 100%;
  background: #05070d;
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", Helvetica, Arial, sans-serif;
}

body {
  display: grid;
  place-items: center;
  min-height: 100%;
}

#wrap {
  position: relative;
  /* Fit the 16:9 stage in both width and height of the viewport. */
  width: min(100vw, 1280px, 177.78vh);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  touch-action: none; /* swipes change lanes instead of scrolling */
  user-select: none;
  -webkit-user-select: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #07101c;
}

#hud {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px 20px 28px;
  pointer-events: none;
  /* Keeps the HUD readable over bright buildings on zoomed cameras. */
  background: linear-gradient(rgba(4, 7, 14, 0.55), rgba(4, 7, 14, 0));
}

.brand {
  letter-spacing: 0.38em;
  font-size: 12px;
  font-weight: 700;
  opacity: 0.9;
}

.scores {
  display: flex;
  gap: 22px;
  margin-left: auto;
}

.stat span {
  display: block;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--muted);
}

.stat b {
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.pill {
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: var(--panel);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 11px;
  letter-spacing: 0.16em;
  cursor: pointer;
}

.pill:hover { border-color: var(--accent); }

#modeTag {
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(62, 198, 255, 0.16);
  color: var(--accent);
  font-size: 9px;
  letter-spacing: 0.2em;
}

#flyBtn {
  position: absolute;
  right: 28px;
  bottom: 28px;
  z-index: 3;
  width: 132px;
  height: 132px;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, #d7ecff 55%, #9fd4ff);
  color: #081018;
  font-weight: 800;
  letter-spacing: 0.18em;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(80, 180, 255, 0.35);
}

#flyBtn:disabled {
  cursor: default;
  filter: saturate(0.55) brightness(0.85);
}

#flyBtn .fly-label {
  position: relative;
  z-index: 1;
  font-size: 28px;
}

#flyBtn .hint {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 2px;
  font-size: 10px;
  letter-spacing: 0.28em;
  opacity: 0.55;
}

#cooldownBar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background: rgba(8, 16, 28, 0.45);
  pointer-events: none;
}

#overlay, #pauseOverlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(3, 6, 12, 0.62);
  backdrop-filter: blur(8px);
}

#overlay.hidden, #pauseOverlay.hidden { display: none; }

.card {
  width: min(92vw, 420px);
  padding: 36px 32px;
  border-radius: 20px;
  background: linear-gradient(180deg, #121a2a, #0a101a);
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
}

.kicker {
  letter-spacing: 0.32em;
  font-size: 11px;
  color: var(--accent);
  margin-bottom: 8px;
}

.card h1 { font-size: 40px; font-weight: 700; }
.result { margin: 12px 0 24px; color: var(--muted); }
.result b { color: var(--ink); }

#restartBtn, #resumeBtn, #pauseRestartBtn {
  border: 0;
  background: #fff;
  color: #081018;
  font-weight: 700;
  letter-spacing: 0.14em;
  padding: 14px 28px;
  border-radius: 999px;
  cursor: pointer;
}

#restartBtn:hover, #resumeBtn:hover { background: #cfeeff; }

@media (max-width: 720px) {
  #flyBtn { width: 104px; height: 104px; right: 16px; bottom: 16px; }
  #flyBtn .fly-label { font-size: 22px; }
}

/* Level-up announcement */
#banner {
  position: absolute;
  left: 50%;
  top: 22%;
  z-index: 2;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-size: clamp(22px, 5vw, 56px);
  font-weight: 800;
  letter-spacing: 0.2em;
  color: #fff;
  text-shadow: 0 0 24px rgba(62, 198, 255, 0.8), 0 4px 20px rgba(0, 0, 0, 0.5);
  opacity: 0;
  white-space: nowrap;
}

#banner small {
  display: block;
  margin-top: 4px;
  font-size: 0.3em;
  letter-spacing: 0.3em;
  color: var(--accent);
  text-align: center;
}

#banner.show { animation: banner 2.2s ease-out; }

@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.9); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%); }
}

/* Touch controls — only on devices without hover (phones, tablets). */
.touch-pad {
  position: absolute;
  bottom: 28px;
  z-index: 3;
  display: none;
  gap: 10px;
}

.touch-pad.left { left: 20px; flex-direction: column; }
.touch-pad.right { right: 172px; align-items: flex-end; }

.touch-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: var(--panel);
  color: var(--ink);
  font-size: 22px;
  cursor: pointer;
  touch-action: none;
}

.touch-btn:active, .touch-btn.held { background: rgba(62, 198, 255, 0.35); }

@media (hover: none) {
  .touch-pad { display: flex; }
}

/* Overlay extras: difficulty picker, controls help */
.card { max-height: 92vh; overflow-y: auto; }

.modes {
  display: inline-flex;
  margin: 4px 0 18px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.mode-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.mode-btn[aria-checked="true"] { background: var(--accent); color: #04121c; }

.controls {
  list-style: none;
  margin: 0 0 10px;
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.controls kbd {
  display: inline-block;
  min-width: 22px;
  margin-right: 3px;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
}

.controls b { color: var(--ink); }
.controls.touch { display: none; }

@media (hover: none) {
  .controls.keys { display: none; }
  .controls.touch { display: grid; }
}

.tip { font-size: 12px; color: var(--accent); margin-bottom: 18px; }

@media (max-width: 720px) {
  #hud { gap: 10px; padding: 10px 12px; }
  .brand { display: none; }
  .scores { gap: 12px; }
  .stat b { font-size: 18px; }
  .pill { padding: 6px 10px; font-size: 9px; }
  .touch-pad { bottom: 16px; }
  .touch-pad.right { right: 132px; }
  .touch-btn { width: 46px; height: 46px; font-size: 18px; }
}

/* Tesla colour picker */
.colors {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: -6px 0 16px;
  font-size: 12px;
  color: var(--muted);
}

.color-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
}

.color-btn i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.color-btn[aria-checked="true"] { border-color: var(--accent); background: rgba(62, 198, 255, 0.15); }

.fine { margin-top: 14px; font-size: 10px; color: var(--muted); opacity: 0.7; }

/* Pause screen */
.pause-actions { display: flex; gap: 10px; justify-content: center; }
#pauseRestartBtn.secondary { background: transparent; color: var(--ink); border: 1px solid rgba(255, 255, 255, 0.25); }
#pauseRestartBtn.secondary:hover { border-color: var(--accent); }
#pauseOverlay kbd {
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
}
.pill:disabled { opacity: 0.4; cursor: default; }

/* Token counters (top-left, under the title) */
#tokens {
  position: absolute;
  top: 54px;
  left: 20px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.tok {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: max-content;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.tok i {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-style: normal;
  font-weight: 800;
  font-size: 11px;
}

.tok.grok i { background: #0e1116; color: #fff; border: 1px solid #fff; }
.tok.cursor i { background: #fff; color: #14181f; }
.tok b { color: var(--ink); font-size: 14px; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }
.tok.bump { animation: bump 0.45s ease-out; }

@keyframes bump {
  0% { transform: scale(1); border-color: var(--accent); }
  35% { transform: scale(1.18); box-shadow: 0 0 18px rgba(62, 198, 255, 0.6); }
  100% { transform: scale(1); }
}

.wallet { margin: -8px 0 16px; font-size: 12px; color: var(--muted); }
.wallet b { color: var(--ink); }
.wallet small { display: block; font-size: 10px; opacity: 0.7; }

@media (max-width: 720px) {
  #tokens { top: 44px; left: 12px; }
  .tok { font-size: 8px; }
}

/* Driver picker */
.drivers { margin: -6px 0 16px; font-size: 12px; color: var(--muted); }
.drivers > span { display: block; margin-bottom: 6px; }
#driverPicker { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }

.driver-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 64px;
  padding: 6px 2px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: transparent;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.driver-btn canvas { width: 44px; height: 44px; }
.driver-btn[aria-checked="true"] { border-color: var(--accent); background: rgba(62, 198, 255, 0.15); }
#driverPerk { margin-top: 8px; color: var(--accent); }

.tok.driver { padding-left: 3px; }
.tok.driver canvas { width: 22px; height: 22px; }
.tok.driver b { font-size: 12px; letter-spacing: 0.08em; }

/* Splash screen */
#splash {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: #03060d;
  transition: opacity 0.6s ease, transform 0.6s ease;
}

#splash.leaving { opacity: 0; transform: scale(1.04); pointer-events: none; }

#splashCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }

.splash-content {
  position: relative;
  text-align: center;
  padding: 0 16px;
  transform: translateY(-14vh);
}

.splash-kicker {
  font-size: 12px;
  letter-spacing: 0.5em;
  color: var(--accent);
  opacity: 0;
  animation: rise 0.8s 0.2s ease-out forwards;
}

.splash-title {
  margin: 10px 0 26px;
  font-size: clamp(38px, 9vw, 104px);
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1;
  white-space: nowrap;
}

.splash-title span {
  display: inline-block;
  opacity: 0;
  background: linear-gradient(180deg, #ffffff 30%, #9fd8ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 30px rgba(62, 198, 255, 0.35);
  animation: letter 0.6s ease-out forwards;
}

.splash-title .gap { width: 0.05em; }

/* Stagger the letters. */
.splash-title span:nth-child(1) { animation-delay: 0.30s; }
.splash-title span:nth-child(2) { animation-delay: 0.36s; }
.splash-title span:nth-child(3) { animation-delay: 0.42s; }
.splash-title span:nth-child(4) { animation-delay: 0.48s; }
.splash-title span:nth-child(5) { animation-delay: 0.54s; }
.splash-title span:nth-child(6) { animation-delay: 0.60s; }
.splash-title span:nth-child(8) { animation-delay: 0.72s; }
.splash-title span:nth-child(9) { animation-delay: 0.78s; }
.splash-title span:nth-child(10) { animation-delay: 0.84s; }
.splash-title span:nth-child(11) { animation-delay: 0.90s; }
.splash-title span:nth-child(12) { animation-delay: 0.96s; }

.splash-track {
  width: min(320px, 70vw);
  height: 3px;
  margin: 0 auto 18px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.splash-track i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #ffffff);
  transform: scaleX(0);
  transform-origin: left;
}

.splash-prompt {
  font-size: 12px;
  letter-spacing: 0.32em;
  color: var(--ink);
  opacity: 0;
}

.splash-prompt.show { animation: blink 1.4s ease-in-out infinite; }

.splash-fine {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  color: var(--muted);
}

@keyframes letter {
  from { opacity: 0; transform: translateY(30px) scale(0.8); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: none; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes blink {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}
#driverCredit { margin-top: 2px; font-size: 10px; color: var(--muted); opacity: 0.8; }
