:root {
  --bg: #0b1220;
  --red: #e83b3b;
  --amber: #ffb020;
  --ice: #e8eef8;
  --muted: #8a9bb8;
  --green: #2ecc71;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ice);
  font-family: "Exo 2", system-ui, sans-serif;
  touch-action: none;
  user-select: none;
}

#app { position: relative; width: 100%; height: 100%; height: 100dvh; }

#c {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  padding: calc(0.6rem + var(--safe-t)) 0.85rem 0;
}

#hud::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 70% at 50% 42%, transparent 55%, rgba(0, 0, 0, 0.35) 100%);
  pointer-events: none;
  z-index: 0;
}

#hud > * { position: relative; z-index: 1; }

#cockpit-frame {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

#cockpit-frame[hidden] { display: none !important; }

#cockpit-frame .pillar {
  position: absolute;
  top: -5%;
  width: 12vw;
  max-width: 5.5rem;
  height: 110%;
  background: linear-gradient(90deg, rgba(8, 10, 14, 0.92), rgba(8, 10, 14, 0.15));
  filter: blur(0.5px);
}

#cockpit-frame .pillar.left {
  left: -2%;
  transform: skewX(-8deg);
}

#cockpit-frame .pillar.right {
  right: -2%;
  transform: skewX(8deg);
  background: linear-gradient(-90deg, rgba(8, 10, 14, 0.92), rgba(8, 10, 14, 0.15));
}

#cockpit-frame .hood-shade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 22%;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.45));
}

#hud[hidden] { display: none !important; }

.hud-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.hud-block {
  min-width: 4.5rem;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  background: rgba(8, 14, 28, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
}

.hud-block .lbl {
  display: block;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 700;
}

.hud-block span:last-child {
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.05rem;
  font-weight: 600;
}

.hud-speed {
  position: absolute;
  right: 0.85rem;
  top: calc(4.2rem + var(--safe-t));
  text-align: right;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55);
}

.hud-speed span {
  font-family: "IBM Plex Mono", monospace;
  font-size: 2.4rem;
  font-weight: 600;
  line-height: 1;
}

.hud-speed small {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}

.boost-wrap {
  position: absolute;
  left: 0.85rem;
  right: 0.85rem;
  bottom: calc(5.8rem + var(--safe-b));
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.boost-wrap > span {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--amber);
}

.boost-bar {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: rgba(8, 14, 28, 0.75);
  border: 1px solid rgba(255, 176, 32, 0.35);
  overflow: hidden;
}

.boost-bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #c45a10, var(--amber), #ffe08a);
  transform-origin: left center;
  transform: scaleX(1);
}

.tree {
  position: absolute;
  left: 50%;
  top: calc(5.5rem + var(--safe-t));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.55rem;
  border-radius: 12px;
  background: rgba(8, 14, 28, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.tree i {
  display: block;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: #2a3140;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35);
}

.tree i.on-red { background: #ff2a2a; box-shadow: 0 0 12px #ff2a2a; }
.tree i.on-amber { background: #ffb020; box-shadow: 0 0 12px #ffb020; }
.tree i.on-green { background: #2ecc71; box-shadow: 0 0 14px #2ecc71; }

.tree-msg {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(12.5rem + var(--safe-t));
  margin: 0;
  text-align: center;
  font-weight: 800;
  letter-spacing: 0.08em;
  font-size: 1.1rem;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}

#controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 0.55rem;
  padding: 0.65rem 0.85rem calc(0.85rem + var(--safe-b));
  background: linear-gradient(transparent, rgba(6, 10, 20, 0.85));
}

#controls[hidden] { display: none !important; }

.pad {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  min-height: 4.4rem;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--ice);
  background: rgba(18, 28, 48, 0.88);
  cursor: pointer;
  touch-action: manipulation;
}

.pad:active, .pad.on {
  background: rgba(40, 70, 130, 0.95);
  border-color: rgba(120, 180, 255, 0.45);
}

.pad.gas {
  background: linear-gradient(180deg, #4ad878, #1e9a48);
  color: #06140a;
  border-color: #6dff9a;
}

.pad.boost {
  color: #1a1208;
  background: linear-gradient(180deg, #ffd060, #e07020);
  border-color: #ffb040;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: end center;
  padding: 1.25rem;
  padding-bottom: calc(1.25rem + var(--safe-b));
  background:
    linear-gradient(180deg, rgba(8, 14, 28, 0.25), rgba(8, 14, 28, 0.92)),
    radial-gradient(ellipse at 50% 0%, rgba(232, 59, 59, 0.28), transparent 55%);
  overflow: auto;
}

.screen[hidden] { display: none !important; }

.screen-inner { width: min(26rem, 100%); }

.garage-inner { padding-top: 1rem; }

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.screen h1 {
  margin: 0.2rem 0 0.45rem;
  font-size: clamp(2.4rem, 11vw, 3.4rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 0.95;
}

.tag {
  margin: 0 0 1rem;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.95rem;
}

.car-list {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.car-card {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  background: rgba(14, 22, 38, 0.9);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.car-card.selected {
  border-color: rgba(232, 59, 59, 0.75);
  box-shadow: 0 0 0 1px rgba(232, 59, 59, 0.35);
  background: rgba(40, 18, 22, 0.95);
}

.car-card strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 800;
  margin-bottom: 0.2rem;
}

.car-card .stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  margin-top: 0.45rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: var(--muted);
}

.car-card .stats b {
  display: block;
  color: var(--ice);
  font-size: 0.88rem;
}

.cta {
  appearance: none;
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 0.95rem 1rem;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #140808;
  background: linear-gradient(180deg, #ff6a5a, var(--red));
  cursor: pointer;
}

.cta:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.back {
  display: inline-block;
  margin-top: 0.85rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}

.credit {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  color: rgba(138, 155, 184, 0.75);
}
