:root {
  --ink: #0a1016;
  --paper: #eaf2fa;
  --moss: #5ec4a8;
  --clay: #e0894a;
  --cash: #c4f09a;
  --sky: #7eb6d4;
  --glass: rgba(12, 18, 26, 0.55);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #060a10;
  color: var(--paper);
  font-family: "DM Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#view {
  position: absolute;
  inset: 0;
}

#view canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1.2rem;
  pointer-events: none;
  z-index: 2;
  background: linear-gradient(180deg, rgba(6, 10, 16, 0.82) 0%, rgba(6, 10, 16, 0.35) 55%, transparent 100%);
}

.hud-left,
.hud-right,
.hud-center {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.hud-center {
  flex-direction: column;
  min-width: 160px;
}

.meter {
  display: flex;
  flex-direction: column;
  min-width: 4.5rem;
}

.meter .label,
.car-name {
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.7;
}

.meter .value {
  font-family: "Bebas Neue", sans-serif;
  font-size: 1.85rem;
  letter-spacing: 0.04em;
  line-height: 1;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.45);
}

.meter .value small {
  font-size: 0.7rem;
  margin-left: 0.2rem;
  opacity: 0.65;
}

.cash {
  color: var(--cash);
}

.car-name {
  margin-bottom: 0.25rem;
}

.damage-bar {
  width: 168px;
  height: 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.damage-fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--clay), #e8c46a, var(--moss));
  transition: width 0.15s ease;
}

.ghost,
.cta {
  pointer-events: auto;
  appearance: none;
  border: none;
  cursor: pointer;
  font-weight: 700;
  border-radius: 999px;
  transition: transform 0.15s ease, background 0.15s ease;
}

.ghost {
  font-family: "DM Sans", sans-serif;
  background: var(--glass);
  color: var(--paper);
  border: 1px solid rgba(230, 238, 248, 0.22);
  padding: 0.48rem 0.9rem;
  font-size: 0.8rem;
  backdrop-filter: blur(8px);
}

.ghost:hover {
  background: rgba(230, 238, 248, 0.16);
  transform: translateY(-1px);
}

.cta {
  font-family: "Bebas Neue", sans-serif;
  font-size: 1.4rem;
  letter-spacing: 0.08em;
  padding: 0.75rem 1.65rem;
  color: #0d1814;
  background: linear-gradient(135deg, #c8f09a, #5ec4a8 55%, #3db89e);
  box-shadow: 0 12px 32px rgba(94, 196, 168, 0.32);
}

.cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 36px rgba(94, 196, 168, 0.4);
}

.hint {
  position: absolute;
  top: 5.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background: rgba(8, 14, 22, 0.78);
  border: 1px solid rgba(184, 233, 134, 0.4);
  color: var(--cash);
  font-weight: 700;
  font-size: 0.9rem;
  pointer-events: none;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.hint[hidden] {
  display: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 30% 10%, rgba(126, 182, 217, 0.22), transparent 45%),
    radial-gradient(ellipse at 70% 80%, rgba(94, 196, 168, 0.12), transparent 40%),
    linear-gradient(165deg, rgba(8, 14, 22, 0.78), rgba(5, 8, 12, 0.88));
  backdrop-filter: blur(6px);
}

/* Respawn / wrecked: keep the world sharp behind the card */
.overlay:has(#panel-wrecked:not([hidden])) {
  background: rgba(6, 10, 16, 0.28);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.overlay[hidden] {
  display: none;
}

.panel {
  width: min(92%, 440px);
  text-align: center;
  padding: 1.65rem 1.4rem;
  animation: rise 0.4s ease;
  background: linear-gradient(165deg, rgba(18, 26, 36, 0.72), rgba(10, 14, 20, 0.55));
  border: 1px solid rgba(230, 238, 248, 0.1);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(12px);
}

.overlay:has(#panel-wrecked:not([hidden])) #panel-wrecked {
  background: linear-gradient(165deg, rgba(18, 26, 36, 0.92), rgba(10, 14, 20, 0.88));
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.55);
}

.panel[hidden] {
  display: none;
}

.panel.garage {
  width: min(94%, 640px);
  text-align: left;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--moss);
  opacity: 0.95;
}

.boot-error {
  color: #ff8f7a;
  background: rgba(196, 69, 54, 0.2);
  border: 1px solid rgba(255, 143, 122, 0.35);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  margin: 0 0 1rem;
  font-size: 0.85rem;
  line-height: 1.4;
}

.panel h1,
.panel h2 {
  margin: 0;
  font-family: "Bebas Neue", sans-serif;
  letter-spacing: 0.06em;
  line-height: 0.95;
  color: #f2f7ff;
}

.panel h1 {
  font-size: clamp(3.1rem, 10vw, 4.6rem);
  text-shadow: 0 2px 28px rgba(94, 196, 168, 0.28);
}

.panel h2 {
  font-size: 2.4rem;
  margin-bottom: 0.35rem;
}

.lede {
  margin: 0.65rem 0 1.1rem;
  opacity: 0.82;
  line-height: 1.45;
}

.controls {
  list-style: none;
  margin: 0 0 1.35rem;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.88rem;
  opacity: 0.95;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 12px;
  border: 1px solid rgba(230, 238, 248, 0.08);
}

kbd {
  display: inline-block;
  min-width: 1.4rem;
  padding: 0.12rem 0.4rem;
  margin: 0 0.12rem;
  border-radius: 6px;
  border: 1px solid rgba(230, 238, 248, 0.28);
  background: rgba(255, 255, 255, 0.1);
  font-family: inherit;
  font-size: 0.75rem;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}

.car-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.7rem;
  margin-bottom: 1.1rem;
  max-height: min(48vh, 320px);
  overflow: auto;
}

.map-label {
  margin: 0.35rem 0 0.5rem;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--moss);
  opacity: 0.95;
}

.map-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
  margin: 0 0 1rem;
  text-align: left;
}

.map-card {
  appearance: none;
  border: 1px solid rgba(230, 238, 248, 0.14);
  background: linear-gradient(165deg, rgba(24, 34, 44, 0.95), rgba(12, 18, 24, 0.9));
  color: inherit;
  border-radius: 12px;
  padding: 0.65rem 0.7rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.map-card:hover {
  transform: translateY(-1px);
  border-color: rgba(184, 233, 134, 0.45);
}

.map-card.selected {
  border-color: var(--cash);
  box-shadow: 0 0 0 1px rgba(184, 233, 134, 0.35);
}

.map-card strong {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 0.2rem;
}

.map-card span {
  display: block;
  font-size: 0.72rem;
  line-height: 1.3;
  opacity: 0.72;
}

.panel#panel-title {
  width: min(94%, 560px);
  max-height: min(92vh, 900px);
  overflow-y: auto;
}

.panel#panel-title .map-picker {
  margin: 0 0 1.1rem;
}

.panel#panel-title .controls {
  margin: 1rem 0 0;
  opacity: 0.85;
}

.panel.garage {
  max-height: min(92vh, 900px);
  overflow-y: auto;
}

#map-picker-garage {
  margin-bottom: 1.1rem;
}

.car-card {
  appearance: none;
  border: 1px solid rgba(230, 238, 248, 0.14);
  background: linear-gradient(160deg, rgba(22, 32, 42, 0.95), rgba(12, 18, 26, 0.92));
  color: inherit;
  border-radius: 14px;
  padding: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.car-card:hover {
  transform: translateY(-2px);
  border-color: rgba(184, 233, 134, 0.5);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

.car-card.selected {
  border-color: var(--cash);
  box-shadow: 0 0 0 1px rgba(184, 233, 134, 0.4), 0 8px 22px rgba(94, 196, 168, 0.15);
}

.car-card .swatch {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  margin-bottom: 0.55rem;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.08);
}

.car-card .name {
  font-family: "Bebas Neue", sans-serif;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
}

.car-card .meta {
  margin-top: 0.25rem;
  font-size: 0.78rem;
  opacity: 0.75;
  line-height: 1.35;
}

.garage-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
}

.touch {
  position: absolute;
  inset: auto 0 0 0;
  z-index: 3;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 1rem;
  pointer-events: none;
}

.touch:not([hidden]) {
  display: flex;
}

.stick-zone,
.pedals {
  pointer-events: auto;
}

.stick-base {
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: rgba(12, 18, 26, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.18);
  position: relative;
  backdrop-filter: blur(8px);
  box-shadow: inset 0 0 24px rgba(255, 255, 255, 0.04);
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d8f5b0, #5ec4a8 70%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.pedals {
  display: flex;
  gap: 0.55rem;
  align-items: flex-end;
}

.pedals button {
  appearance: none;
  border: none;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  font-family: "Bebas Neue", sans-serif;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  color: #0d1814;
  background: rgba(230, 238, 248, 0.88);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
}

#btn-gas {
  background: linear-gradient(135deg, #b8e986, #5ec4a8);
}

#btn-brake {
  background: linear-gradient(135deg, #e8a070, #e0894a);
}

@media (max-width: 720px) {
  .hud {
    flex-wrap: wrap;
  }

  .hud-right {
    width: 100%;
    justify-content: flex-end;
  }

  .touch:not([hidden]) {
    display: flex;
  }
}

@media (min-width: 721px) {
  .touch {
    display: none !important;
  }
}


#impact-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  background: radial-gradient(circle at center, rgba(255, 230, 180, 0.55), rgba(255, 80, 40, 0.2) 45%, transparent 70%);
  opacity: 0;
  transition: opacity 0.05s linear;
}
#impact-flash.on {
  opacity: 1;
  transition: none;
}
