:root {
  color-scheme: dark;
  --ink: #f5f3e8;
  --muted: #a9b0aa;
  --panel: rgba(11, 13, 12, 0.72);
  --panel-strong: rgba(11, 13, 12, 0.9);
  --line: rgba(245, 243, 232, 0.18);
  --orange: #ff8a2a;
  --cyan: #50d6ff;
  --green: #79f26d;
  --red: #ff4f5e;
  --road: #181b19;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--road);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
a {
  font: inherit;
}

#game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #121512;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #161916;
  cursor: crosshair;
}

.cursor-locked #game-canvas {
  cursor: none;
}

.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 16;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.55));
}

.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  border-radius: 999px;
  background: rgba(245, 243, 232, 0.92);
}

.crosshair::before {
  width: 2px;
  height: 28px;
  transform: translate(-50%, -50%);
}

.crosshair::after {
  width: 28px;
  height: 2px;
  transform: translate(-50%, -50%);
}

.storm-tint {
  position: absolute;
  inset: 0;
  z-index: 8;
  background:
    radial-gradient(circle at center, rgba(59, 167, 255, 0.05), rgba(59, 167, 255, 0.2)),
    linear-gradient(rgba(59, 167, 255, 0.16), rgba(25, 74, 190, 0.2));
  mix-blend-mode: screen;
  pointer-events: none;
}

.hud {
  position: absolute;
  inset: 14px 16px auto;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(220px, 1fr);
  align-items: start;
  gap: 14px;
  pointer-events: none;
}

.hud-left,
.hud-right {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.hud-left {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.hud-right {
  justify-content: flex-end;
  flex-direction: column;
  justify-self: end;
  width: min(280px, 34vw);
}

.home-link,
.stat,
.meter,
.status-pill,
.title-mark,
.speed-readout {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(10px);
}

.home-link {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  pointer-events: auto;
}

.home-link:hover {
  border-color: rgba(80, 214, 255, 0.55);
}

.stat {
  min-width: 86px;
  min-height: 40px;
  padding: 7px 10px 8px;
  border-radius: 8px;
}

.money-stat {
  display: flex;
  align-items: center;
  gap: 8px;
}

.money-icon {
  font-size: 20px;
  line-height: 1;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
}

.stat strong {
  display: block;
  color: var(--ink);
  font-size: 19px;
  line-height: 1.1;
  margin-top: 3px;
}

.hud-center {
  justify-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

.title-mark {
  border-radius: 8px;
  padding: 9px 16px;
  color: var(--orange);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 16px;
}

.speed-readout {
  min-width: 96px;
  border-radius: 8px;
  padding: 6px 12px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.speed-readout span {
  color: var(--ink);
  font-weight: 800;
}

.meter {
  width: 100%;
  border-radius: 8px;
  padding: 9px;
}

.meter-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.meter-track {
  position: relative;
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(245, 243, 232, 0.12);
}

.meter-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  border-radius: inherit;
  transform-origin: left center;
  transition: width 0.12s linear, background 0.12s linear;
}

.nitro-fill {
  background: linear-gradient(90deg, var(--cyan), #f7f871);
}

.heat-fill {
  width: 0%;
  background: linear-gradient(90deg, var(--orange), var(--red));
}

.health-hud {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 12;
  width: min(420px, calc(100vw - 36px));
  padding: 11px 12px 12px;
  border: 1px solid rgba(121, 242, 109, 0.4);
  border-radius: 8px;
  background: rgba(8, 12, 9, 0.78);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.health-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
}

.health-track {
  position: relative;
  height: 22px;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(245, 243, 232, 0.12);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.health-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4fd86b, var(--green));
  box-shadow: 0 0 18px rgba(121, 242, 109, 0.3);
  transition: width 0.16s ease, background 0.16s ease;
}

.health-fill.low {
  background: linear-gradient(90deg, var(--red), var(--orange));
}

.health-fill.damage-flash,
.health-fill.storm-damage {
  background: linear-gradient(90deg, #ff1f36, #ff6a7a);
  box-shadow: 0 0 24px rgba(255, 31, 54, 0.58);
}

.health-fill.damage-flash {
  animation: healthFlash 0.28s ease;
}

@keyframes healthFlash {
  0% {
    filter: brightness(2.1);
  }
  100% {
    filter: brightness(1);
  }
}

.status-pill {
  align-self: flex-end;
  min-width: 92px;
  border-radius: 999px;
  padding: 6px 11px;
  color: var(--green);
  text-align: center;
  font-size: 12px;
}

.status-pill.hot {
  color: var(--red);
  border-color: rgba(255, 79, 94, 0.46);
}

.start-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background:
    linear-gradient(rgba(13, 15, 13, 0.5), rgba(13, 15, 13, 0.78)),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.035) 0 2px, transparent 2px 18px);
  overflow-y: auto;
  padding: 28px 16px;
}

.start-panel {
  width: min(980px, calc(100vw - 32px));
  padding: 30px;
  border: 1px solid rgba(245, 243, 232, 0.24);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  text-align: center;
}

.lobby-panel {
  display: grid;
  gap: 18px;
}

.lobby-header {
  position: relative;
}

.lobby-money {
  position: absolute;
  top: 0;
  right: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  font-size: 20px;
}

.match-result {
  min-height: 22px;
  margin: 8px 0 0;
  color: var(--green);
  font-weight: 700;
}

.lobby-section {
  text-align: left;
}

.lobby-section h2 {
  margin: 0 0 10px;
  color: var(--cyan);
  font-size: 14px;
  text-transform: uppercase;
}

.car-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(124px, 1fr));
  gap: 10px;
}

.car-card,
.challenge-card,
.shop-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.car-card {
  position: relative;
  min-height: 92px;
  padding: 0;
  color: var(--ink);
  overflow: hidden;
  cursor: pointer;
}

.car-card:hover,
.car-card.selected {
  border-color: rgba(80, 214, 255, 0.72);
  background: rgba(80, 214, 255, 0.12);
}

.car-card.selected::after {
  content: '';
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(121, 242, 109, 0.18);
}

.car-preview {
  width: 100%;
  height: 92px;
  display: block;
  background:
    linear-gradient(135deg, rgba(80, 214, 255, 0.08), transparent),
    rgba(0, 0, 0, 0.24);
}

.challenge-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.challenge-card {
  min-height: 104px;
  padding: 12px;
}

.challenge-card.done {
  border-color: rgba(121, 242, 109, 0.54);
  background: rgba(121, 242, 109, 0.1);
}

.challenge-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
  font-size: 14px;
  font-weight: 800;
}

.challenge-reward {
  color: var(--green);
  white-space: nowrap;
}

.challenge-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(245, 243, 232, 0.13);
}

.challenge-progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--cyan));
}

.challenge-meta {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.shop-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.shop-card {
  min-height: 124px;
  padding: 12px;
  color: var(--ink);
  text-align: left;
}

.shop-card h3 {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 15px;
}

.shop-card p {
  min-height: 34px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.shop-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.shop-level {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
}

.shop-buy {
  width: auto;
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #10140f;
  font-weight: 900;
  cursor: pointer;
}

.shop-buy:disabled {
  opacity: 0.45;
  cursor: default;
  background: rgba(245, 243, 232, 0.22);
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 13px;
  text-transform: uppercase;
}

.start-panel h1 {
  margin: 0 0 22px;
  color: var(--ink);
  font-size: clamp(42px, 8vw, 78px);
  line-height: 0.95;
}

.start-panel button {
  justify-self: center;
  width: min(240px, 100%);
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  background: var(--orange);
  color: #11110f;
  font-weight: 900;
  font-size: 27px;
  cursor: pointer;
  box-shadow: 0 14px 0 #8f3e13, 0 22px 42px rgba(255, 138, 42, 0.2);
}

.start-panel button:active {
  transform: translateY(6px);
  box-shadow: 0 8px 0 #8f3e13, 0 16px 28px rgba(255, 138, 42, 0.2);
}

.go-flash {
  position: absolute;
  inset: 0;
  z-index: 18;
  display: grid;
  place-items: center;
  color: var(--green);
  font-size: clamp(80px, 18vw, 190px);
  font-weight: 900;
  text-shadow: 0 12px 0 rgba(0, 0, 0, 0.3);
  pointer-events: none;
  animation: goPop 0.9s ease forwards;
}

@keyframes goPop {
  0% {
    opacity: 0;
    transform: scale(0.72);
  }
  18% {
    opacity: 1;
    transform: scale(1.04);
  }
  100% {
    opacity: 0;
    transform: scale(1.26);
  }
}

.loading-error {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 50;
  width: min(520px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255, 79, 94, 0.6);
  border-radius: 8px;
  background: rgba(18, 10, 12, 0.94);
  color: var(--ink);
  padding: 20px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

@media (max-width: 760px) {
  .hud {
    inset: 10px 10px auto;
    grid-template-columns: 1fr auto;
  }

  .hud-center {
    grid-column: 1 / -1;
    grid-row: 2;
    flex-direction: row;
  }

  .title-mark {
    font-size: 12px;
    padding: 7px 10px;
  }

  .hud-right {
    width: min(210px, 48vw);
  }

  .health-hud {
    left: 10px;
    bottom: 10px;
    width: min(330px, calc(100vw - 20px));
  }

  .stat {
    min-width: 68px;
  }

  .home-link {
    min-height: 36px;
    padding: 0 11px;
  }

  .start-screen {
    padding: 12px 10px;
  }

  .start-panel {
    padding: 18px;
  }

  .lobby-money {
    position: static;
    justify-content: center;
    margin: 0 auto 8px;
    width: fit-content;
  }
}
