:root {
  --ink: #f8fbff;
  --muted: rgba(248, 251, 255, 0.66);
  --line: rgba(248, 251, 255, 0.18);
  --panel: rgba(6, 12, 18, 0.62);
  --panel-strong: rgba(7, 14, 20, 0.86);
  --accent: #ffdf5d;
  --danger: #ff5a45;
  --ok: #52f2b8;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #071018;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

input {
  font: inherit;
}

.shell {
  position: relative;
  width: 100vw;
  height: 100svh;
  min-height: 480px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgba(55, 111, 124, 0.28), transparent 34%),
    linear-gradient(180deg, #0d2026 0%, #071018 100%);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.garage,
.result {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 5;
  width: min(560px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(7, 14, 20, 0.88), rgba(7, 14, 20, 0.7));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(18px);
  transition:
    opacity 220ms ease,
    transform 220ms ease,
    visibility 220ms ease;
}

.garage.is-hidden,
.result {
  visibility: hidden;
  opacity: 0;
  transform: translate(-50%, -46%);
  pointer-events: none;
}

.result.is-visible {
  visibility: visible;
  opacity: 1;
  transform: translate(-50%, -50%);
  pointer-events: auto;
}

.garage__header {
  display: grid;
  gap: 6px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 0.95;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(48px, 9vw, 92px);
}

h2 {
  margin-top: 8px;
  font-size: clamp(36px, 7vw, 68px);
}

.car-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.car-option {
  min-width: 0;
  padding: 14px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  text-align: left;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.car-option:hover,
.car-option.is-selected {
  border-color: rgba(255, 223, 93, 0.9);
  background: rgba(255, 223, 93, 0.12);
  transform: translateY(-2px);
}

.car-option strong {
  display: block;
  margin-bottom: 10px;
  font-size: 16px;
  white-space: nowrap;
}

.car-option dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 8px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.car-option dt,
.car-option dd {
  margin: 0;
}

.car-option dd {
  color: var(--ink);
  font-weight: 800;
}

.primary-action {
  width: 100%;
  min-height: 50px;
  border-radius: 8px;
  background: var(--accent);
  color: #161303;
  font-size: 16px;
  font-weight: 900;
  transition:
    transform 160ms ease,
    filter 160ms ease;
}

.primary-action:disabled {
  cursor: not-allowed;
  filter: grayscale(0.4);
  opacity: 0.48;
}

.primary-action:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.primary-action:disabled:hover {
  transform: none;
  filter: grayscale(0.4);
}

.name-entry {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.name-entry span,
.leaderboard h3 {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.name-entry input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  padding: 0 14px;
  touch-action: manipulation;
  user-select: text;
}

.name-entry input:focus {
  border-color: rgba(255, 223, 93, 0.9);
  background: rgba(255, 255, 255, 0.12);
}

.name-entry.is-invalid input {
  border-color: rgba(255, 90, 69, 0.9);
}

.hud {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  right: max(18px, env(safe-area-inset-right));
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  pointer-events: none;
}

.hud > div {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(12px);
}

.hud__label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.hud strong {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  font-size: clamp(18px, 5vw, 30px);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cooldown {
  position: absolute;
  top: calc(max(18px, env(safe-area-inset-top)) + 74px);
  left: 50%;
  z-index: 3;
  width: min(220px, 42vw);
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  transform: translateX(-50%);
}

.cooldown span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--ok);
  transform-origin: left center;
}

.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 4;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 0 max(20px, env(safe-area-inset-left)) 0 max(20px, env(safe-area-inset-right));
  pointer-events: none;
}

.shell:not(.is-racing) .hud,
.shell:not(.is-racing) .cooldown,
.shell:not(.is-racing) .controls {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.steer {
  display: grid;
  width: min(34vw, 156px);
  aspect-ratio: 1.45;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.28);
  pointer-events: auto;
  transition:
    transform 120ms ease,
    background 120ms ease,
    opacity 120ms ease;
}

.steer:active {
  transform: translateY(2px) scale(0.98);
  background: rgba(255, 223, 93, 0.22);
}

.steer[disabled] {
  opacity: 0.42;
}

.steer span {
  font-size: clamp(56px, 18vw, 94px);
  line-height: 0.65;
}

.result p:last-of-type {
  margin: 16px 0 22px;
  color: var(--muted);
  font-size: 16px;
}

.leaderboard {
  margin: 0 0 18px;
}

.leaderboard h3 {
  margin: 0 0 10px;
}

.leaderboard ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 13px;
}

.leaderboard li:last-child {
  border-bottom: 0;
}

.leaderboard b {
  color: var(--ink);
}

.leaderboard strong {
  color: var(--accent);
  font-size: 14px;
}

@media (max-width: 680px) {
  .shell {
    min-height: 100svh;
  }

  .garage,
  .result {
    top: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: calc(100vw - 24px);
    max-height: calc(100svh - 24px);
    padding: 18px;
    overflow: auto;
    transform: translate(-50%, 0);
  }

  .garage.is-hidden,
  .result {
    transform: translate(-50%, 20px);
  }

  .result.is-visible {
    transform: translate(-50%, 0);
  }

  .garage__header {
    gap: 4px;
    margin-bottom: 14px;
  }

  .eyebrow {
    font-size: 11px;
  }

  h1 {
    font-size: clamp(42px, 15vw, 62px);
  }

  h2 {
    font-size: clamp(36px, 13vw, 54px);
  }

  .car-list {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 12px;
  }

  .car-option {
    display: grid;
    grid-template-columns: 0.62fr 1fr;
    gap: 8px;
    align-items: center;
    min-height: 74px;
    padding: 10px 12px;
  }

  .car-option strong {
    margin: 0;
    font-size: 15px;
  }

  .car-option dl {
    gap: 3px 8px;
    font-size: 11px;
  }

  .primary-action {
    min-height: 52px;
  }

  .name-entry {
    margin-bottom: 12px;
  }

  .name-entry input {
    min-height: 46px;
  }

  .leaderboard {
    margin-bottom: 14px;
  }

  .leaderboard li {
    min-height: 31px;
  }

  .hud {
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    gap: 6px;
  }

  .hud > div {
    padding: 8px 9px;
  }

  .hud strong {
    font-size: clamp(25px, 9vw, 38px);
  }

  .cooldown {
    top: calc(max(10px, env(safe-area-inset-top)) + 86px);
    width: min(328px, 84vw);
    height: 6px;
  }

  .controls {
    bottom: max(14px, env(safe-area-inset-bottom));
    gap: 0;
    padding: 0 max(14px, env(safe-area-inset-left)) 0 max(14px, env(safe-area-inset-right));
  }

  .steer {
    width: min(35vw, 136px);
    min-width: 118px;
    height: clamp(86px, 14svh, 118px);
    aspect-ratio: auto;
  }
}

@media (orientation: portrait) and (max-width: 680px) {
  .shell {
    background:
      radial-gradient(circle at 50% 10%, rgba(68, 132, 139, 0.24), transparent 30%),
      linear-gradient(180deg, #0e2a30 0%, #071018 100%);
  }
}

@media (max-width: 380px) {
  .garage,
  .result {
    padding: 14px;
  }

  .car-option {
    min-height: 68px;
  }

  .hud > div {
    padding: 7px;
  }

  .hud__label {
    font-size: 10px;
  }

  .steer {
    min-width: 104px;
  }
}
