:root {
  color-scheme: dark;
  --bg: #0b1420;
  --panel: rgba(8, 20, 33, 0.82);
  --panel-2: rgba(22, 54, 77, 0.92);
  --line: rgba(130, 215, 255, 0.34);
  --text: #f4f8ff;
  --muted: #bcd0dc;
  --accent: #ffd76a;
  --danger: #ff746f;
  --good: #73ef9c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  background:
    linear-gradient(rgba(7, 16, 26, 0.8), rgba(7, 16, 26, 0.88)),
    url("./assets/classic-wallpaper.png") center / min(100vw, 720px) auto,
    radial-gradient(circle at 20% 12%, rgba(255, 216, 106, 0.18), transparent 24%),
    radial-gradient(circle at 86% 26%, rgba(91, 203, 255, 0.16), transparent 24%),
    linear-gradient(180deg, #152a38, #07101a 72%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  display: grid;
  place-items: center;
  padding: 12px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 6px;
  width: min(100%, 430px);
  height: min(100svh, 920px);
  padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
  border: 1px solid rgba(130, 215, 255, 0.22);
  border-radius: 10px;
  background: rgba(3, 12, 21, 0.62);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(10px);
}

.top-bar,
.stats,
.controls {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.top-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
}

.brand {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.brand p {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  overflow: hidden;
  font-size: clamp(22px, 6.4vw, 34px);
  font-weight: 950;
  line-height: 0.95;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}

.car-picker {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
}

.car-picker select {
  min-width: 0;
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(22, 54, 77, 0.92);
  color: var(--text);
  font: inherit;
  padding: 0 8px;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 5px;
}

button,
.garage-link {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.garage-link {
  display: grid;
  place-items: center;
  min-width: 40px;
  color: var(--accent);
  text-decoration: none;
}

button:active {
  transform: translateY(1px);
}

.actions button,
.actions .garage-link {
  min-height: 32px;
  padding: 0 8px;
  font-size: 12px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 7px;
}

.stats div {
  display: grid;
  gap: 1px;
  padding: 7px 9px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.stats span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.stats strong {
  font-size: 24px;
  line-height: 1;
}

.road-wrap {
  position: relative;
  justify-self: center;
  width: min(100%, 360px);
  height: 100%;
  max-height: 100%;
  min-height: 0;
  aspect-ratio: 9 / 16;
  border: 2px solid rgba(130, 215, 255, 0.28);
  border-radius: 12px;
  overflow: hidden;
  background: #1d2630;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 20px;
  background: rgba(2, 8, 15, 0.72);
  text-align: center;
}

.overlay > * {
  position: relative;
  z-index: 1;
}

.party-image {
  width: min(100%, 228px);
  height: 172px;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.32);
}

.goal-video {
  display: none;
  width: min(100%, 244px);
  height: 192px;
  object-fit: cover;
  border: 2px solid rgba(255, 215, 106, 0.48);
  border-radius: 10px;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.42);
}

.overlay.goal .party-image {
  display: none;
}

.overlay.goal .goal-video {
  display: block;
}

.overlay.hidden {
  display: none;
}

.overlay strong {
  max-width: 9ch;
  font-size: clamp(30px, 10vw, 46px);
  line-height: 1.02;
  text-shadow: 0 3px 18px rgba(0, 0, 0, 0.65);
}

.overlay span {
  color: #e9f5ff;
  font-size: 16px;
  font-weight: 850;
}

#startBtn {
  min-width: 130px;
  background: linear-gradient(180deg, #ffcf5b, #d98322);
  color: #201207;
}

.goal-art {
  position: relative;
  display: none;
  width: 210px;
  height: 116px;
  overflow: hidden;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 12%, rgba(255, 215, 106, 0.44), transparent 70px);
}

.overlay.goal .goal-art {
  display: block;
  height: 80px;
}

.goal-art span {
  position: absolute;
  left: 65px;
  bottom: 14px;
  width: 82px;
  height: 45px;
  border-radius: 20px 20px 6px 6px;
  background: #ff8ab0;
  box-shadow: inset 0 11px 0 #fff0ba, 0 7px 0 #d8597f;
}

.goal-art span::before {
  position: absolute;
  left: 36px;
  top: -42px;
  width: 10px;
  height: 45px;
  border-radius: 6px;
  background: repeating-linear-gradient(135deg, #75e3ff 0 6px, #fff6cc 6px 12px);
  content: "";
}

.goal-art span::after {
  position: absolute;
  left: 36px;
  top: -58px;
  width: 10px;
  height: 19px;
  border-radius: 100% 0;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  content: "";
  transform: rotate(36deg);
}

.goal-art i {
  position: absolute;
  top: -20px;
  left: 10%;
  width: 10px;
  height: 18px;
  border-radius: 3px;
  background: var(--accent);
  animation: confetti 1.3s linear infinite;
}

.goal-art i:nth-child(2) {
  left: 31%;
  background: #73ef9c;
  animation-delay: -0.32s;
}

.goal-art i:nth-child(3) {
  left: 63%;
  background: #75e3ff;
  animation-delay: -0.8s;
}

.goal-art i:nth-child(4) {
  left: 84%;
  background: #ff746f;
  animation-delay: -1.08s;
}

@keyframes confetti {
  to {
    transform: translateY(145px) rotate(320deg);
  }
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1.25fr 1fr;
  gap: 7px;
  padding: 7px;
}

.controls button {
  min-height: 54px;
  font-size: 34px;
}

#boostBtn {
  background: linear-gradient(180deg, #ffcf5b, #c66f22);
  color: #251306;
  font-size: 24px;
}

@media (max-width: 430px) {
  body {
    padding: 0;
  }

  .app {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    gap: 5px;
    padding: max(5px, env(safe-area-inset-top)) 7px max(5px, env(safe-area-inset-bottom));
    border: 0;
    border-radius: 0;
  }

  .top-bar {
    grid-template-columns: minmax(86px, 1fr) auto;
    padding: 5px;
  }

  h1 {
    font-size: clamp(20px, 6.4vw, 26px);
  }

  .car-picker {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
    font-size: 10px;
  }

  .car-picker span {
    display: none;
  }

  .car-picker select {
    min-height: 27px;
    padding: 0 6px;
  }

  .actions button,
  .actions .garage-link {
    min-height: 27px;
    padding: 0 5px;
    font-size: 10px;
  }

  .stats {
    gap: 5px;
    padding: 5px;
  }

  .stats div {
    min-height: 34px;
    padding: 5px 7px;
  }

  .stats span {
    font-size: 10px;
  }

  .stats strong {
    font-size: 20px;
  }

  .controls {
    gap: 6px;
    padding: 6px;
  }

  .controls button {
    min-height: 48px;
    font-size: 28px;
  }

  #boostBtn {
    font-size: 21px;
  }
}
