:root {
  color-scheme: dark;
  --ink: #070908;
  --panel: #111512;
  --panel-2: #171c18;
  --panel-3: #202620;
  --line: rgba(239, 244, 232, 0.12);
  --line-strong: rgba(239, 244, 232, 0.24);
  --text: #f4f6ee;
  --muted: #929b91;
  --lime: #c7ff38;
  --mint: #75f5a2;
  --warm: #ffae42;
  --red: #ff5d4d;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.58);
  --radius: 8px;
  --ease: cubic-bezier(0.2, 0.78, 0.2, 1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: #050706;
  color: var(--text);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.026) 1px, transparent 1px);
  background-size: 30px 30px;
  opacity: 0.8;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 2px solid var(--lime);
  outline-offset: 2px;
}

p,
h1,
h2 {
  margin: 0;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.game-shell {
  position: relative;
  display: grid;
  min-height: 100svh;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  place-items: center;
}

.game-card {
  position: relative;
  display: grid;
  width: min(100%, 440px);
  height: min(880px, calc(100svh - 20px));
  min-height: 710px;
  padding: 14px;
  overflow: hidden;
  background: rgba(13, 16, 14, 0.96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  grid-template-rows: auto auto auto auto minmax(210px, 1fr) auto;
  gap: 10px;
}

.game-card::before {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  background: linear-gradient(122deg, rgba(255, 255, 255, 0.055), transparent 24%, transparent 72%, rgba(199, 255, 56, 0.035));
}

.topbar,
.mode-switch,
.run-meta,
.score-grid,
.track-panel,
.control-zone {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  min-height: 50px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand-lockup,
.top-actions,
.run-meta,
.car-label,
.result-topline,
.progress-copy,
.section-title {
  display: flex;
  align-items: center;
}

.brand-lockup {
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  width: 5px;
  height: 38px;
  flex: 0 0 auto;
  background: var(--lime);
  box-shadow: 0 0 20px rgba(199, 255, 56, 0.45);
}

.brand-lockup p,
.garage-header p {
  color: var(--lime);
  font-size: 9px;
  font-weight: 850;
  line-height: 1;
}

h1 {
  margin-top: 5px;
  overflow: hidden;
  color: #fbfcf7;
  font-size: 25px;
  font-weight: 840;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  flex: 0 0 auto;
  gap: 6px;
}

.credit-chip {
  display: flex;
  height: 38px;
  padding: 0 9px;
  align-items: center;
  gap: 6px;
  color: #f5f8ed;
  font-size: 12px;
  background: #1a201a;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.credit-chip i {
  width: 8px;
  height: 8px;
  background: var(--warm);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(255, 174, 66, 0.5);
}

.icon-button,
.close-button {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  color: var(--muted);
  background: #181d19;
  border: 1px solid var(--line);
  border-radius: 6px;
  place-items: center;
  transition: color 160ms var(--ease), background 160ms var(--ease), transform 160ms var(--ease);
}

.icon-button:hover,
.close-button:hover {
  color: var(--lime);
  background: #222920;
}

.icon-button:active,
.close-button:active {
  transform: scale(0.95);
}

.icon-button svg {
  width: 19px;
  height: 19px;
}

.mode-switch {
  display: grid;
  padding: 4px;
  background: #080a09;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}

.mode-button {
  display: flex;
  min-width: 0;
  height: 42px;
  padding: 0 8px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  background: transparent;
  border-radius: 5px;
  transition: color 160ms var(--ease), background 160ms var(--ease);
}

.mode-button small {
  padding: 2px 4px;
  color: #6f776e;
  font-size: 8px;
  background: #171a18;
  border-radius: 3px;
}

.mode-button.is-active {
  color: #10150c;
  background: var(--lime);
}

.mode-button.is-active small {
  color: #d9ffc0;
  background: #28321d;
}

.run-meta {
  min-width: 0;
  justify-content: space-between;
  gap: 12px;
}

.run-meta > div {
  min-width: 0;
}

.run-meta span,
.run-meta strong {
  display: block;
}

#roundLabel {
  color: var(--lime);
  font-size: 9px;
  font-weight: 850;
}

#modeBrief {
  margin-top: 3px;
  overflow: hidden;
  color: #d5ddd2;
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.car-label {
  min-width: 0;
  flex: 0 1 auto;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
}

.car-label i {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  background: #e9ece5;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
}

.car-label b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.score-tile {
  min-width: 0;
  padding: 9px 8px;
  background: #151916;
  border-top: 1px solid var(--line);
}

.score-tile span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-tile strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: #f5f7f1;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-tile-accent {
  border-top-color: rgba(199, 255, 56, 0.62);
}

.score-tile-accent strong {
  color: var(--lime);
}

.track-panel {
  display: grid;
  min-height: 0;
  overflow: hidden;
  background: #090b0a;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  grid-template-rows: auto 1fr auto;
}

.track-panel.is-blind {
  border-color: rgba(255, 93, 77, 0.3);
}

.track-head,
.track-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 9px;
  font-weight: 780;
}

.track-head {
  padding: 10px 11px 0;
}

.track-head span:first-child {
  color: var(--lime);
}

.track-footer {
  padding: 0 11px 9px;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 200px;
}

.rush-feedback {
  position: absolute;
  top: 47%;
  left: 50%;
  z-index: 2;
  color: var(--lime);
  font-size: 34px;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 6px 22px rgba(0, 0, 0, 0.8);
  transform: translate(-50%, -35%) scale(0.8);
}

.rush-feedback.is-visible {
  animation: feedback-pop 620ms var(--ease);
}

.control-zone {
  display: grid;
  gap: 7px;
}

.press-pad {
  position: relative;
  display: grid;
  width: 100%;
  height: 104px;
  overflow: hidden;
  color: #10150c;
  background: var(--lime);
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: var(--radius);
  box-shadow: inset 0 -12px 0 rgba(39, 52, 20, 0.12), 0 10px 24px rgba(0, 0, 0, 0.32);
  place-content: center;
  touch-action: none;
  transition: transform 120ms var(--ease), background 160ms var(--ease);
}

.press-pad::before {
  position: absolute;
  inset: 8px;
  content: "";
  border: 1px solid rgba(18, 25, 9, 0.18);
  border-radius: 5px;
}

.press-pad.is-pressed {
  background: var(--warm);
  transform: translateY(3px);
}

.press-pad.is-braking {
  background: var(--red);
}

.press-gauge {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 5px;
  background: rgba(6, 9, 4, 0.7);
  transition: width 80ms linear;
}

.press-copy,
.press-subcopy {
  position: relative;
  z-index: 1;
  text-align: center;
}

.press-copy {
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.press-subcopy {
  margin-top: 7px;
  font-size: 10px;
  font-weight: 760;
  opacity: 0.66;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.quick-actions button {
  display: flex;
  height: 38px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #c8d0c5;
  font-size: 11px;
  font-weight: 720;
  background: #171b18;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.quick-actions svg {
  width: 15px;
  height: 15px;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  opacity: 0;
  pointer-events: none;
  place-items: center;
  transition: opacity 200ms var(--ease);
}

.sheet.is-open {
  opacity: 1;
  pointer-events: auto;
}

.sheet-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.76);
  backdrop-filter: blur(12px);
}

.result-card,
.garage-card {
  position: relative;
  width: min(100%, 420px);
  max-height: calc(100svh - 24px);
  overflow: auto;
  background: #121612;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  scrollbar-width: none;
  transform: translateY(22px) scale(0.985);
  transition: transform 240ms var(--ease);
}

.result-card::-webkit-scrollbar,
.garage-card::-webkit-scrollbar {
  display: none;
}

.sheet.is-open .result-card,
.sheet.is-open .garage-card {
  transform: translateY(0) scale(1);
}

.result-card {
  padding: 18px;
}

.result-topline {
  justify-content: space-between;
}

#resultKicker {
  color: var(--lime);
  font-size: 10px;
  font-weight: 850;
}

.close-button {
  color: #a6aea4;
  font-size: 22px;
  line-height: 1;
}

.result-hero {
  display: grid;
  margin-top: 17px;
  align-items: center;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 15px;
}

.grade-badge {
  display: grid;
  width: 76px;
  height: 76px;
  color: #0b1007;
  font-size: 48px;
  font-weight: 950;
  background: var(--lime);
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 6px;
  box-shadow: 0 0 30px rgba(199, 255, 56, 0.22);
  place-items: center;
}

#resultTitle {
  overflow-wrap: anywhere;
  color: #f7f8f2;
  font-size: 34px;
  font-weight: 900;
  line-height: 1.02;
}

#resultMessage {
  margin-top: 7px;
  color: #adb6aa;
  font-size: 12px;
  font-weight: 620;
  line-height: 1.45;
}

.result-meter {
  position: relative;
  height: 7px;
  margin: 18px 0;
  background: linear-gradient(90deg, var(--red), var(--warm), var(--lime), var(--warm), var(--red));
}

#meterDot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 15px;
  height: 15px;
  background: #fff;
  border: 3px solid #101510;
  border-radius: 50%;
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.58);
  transform: translate(-50%, -50%);
}

.result-stats {
  display: grid;
  padding: 13px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.result-stats div {
  min-width: 0;
  padding: 0 10px;
  border-right: 1px solid var(--line);
}

.result-stats div:first-child {
  padding-left: 0;
}

.result-stats div:last-child {
  padding-right: 0;
  border-right: 0;
}

.result-stats span,
.result-stats b {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-stats span {
  color: var(--muted);
  font-size: 9px;
}

.result-stats b {
  margin-top: 4px;
  color: #eef2ea;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.unlock-reveal {
  display: none;
  margin: 15px 0 0;
  padding: 14px 0;
  border-top: 1px solid rgba(199, 255, 56, 0.36);
  border-bottom: 1px solid rgba(199, 255, 56, 0.36);
  text-align: center;
}

.unlock-reveal.is-visible {
  display: block;
  animation: unlock-in 420ms var(--ease);
}

.unlock-reveal span {
  color: var(--lime);
  font-size: 9px;
  font-weight: 900;
}

.unlock-reveal strong {
  display: block;
  margin-top: 4px;
  color: #f5f7f1;
  font-size: 24px;
}

.unlock-reveal p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.garage-progress {
  padding: 15px 0 2px;
}

.progress-copy {
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
}

.progress-copy b {
  color: #e9eee5;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 6px;
  margin-top: 8px;
  overflow: hidden;
  background: #282e28;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--lime);
  transition: width 500ms var(--ease);
}

.result-actions {
  display: grid;
  margin-top: 16px;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.result-actions button {
  min-width: 0;
  min-height: 44px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
}

.primary-action {
  color: #10150c;
  background: var(--lime);
}

.secondary-action {
  color: #f0f3ed;
  background: #222822;
  border: 1px solid var(--line-strong);
}

.secondary-action:disabled {
  color: #666e66;
  background: #171a17;
}

.text-action {
  color: #b7c0b4;
  background: transparent;
  border: 1px solid var(--line);
}

.garage-card {
  padding: 16px;
}

.garage-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.garage-header h2 {
  margin-top: 6px;
  color: #f6f7f3;
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
}

.garage-header span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 10px;
}

.garage-grid {
  display: grid;
  margin-top: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.vehicle-card {
  position: relative;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  background: #090b0a;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: left;
}

.vehicle-card.is-selected {
  border-color: var(--lime);
  box-shadow: inset 0 0 0 1px var(--lime);
}

.vehicle-card.is-locked .vehicle-art {
  filter: grayscale(1) brightness(0.3);
}

.vehicle-art {
  display: block;
  width: 100%;
  aspect-ratio: 1.18;
  background-image: url("./assets/garage-collection-v1.jpg");
  background-repeat: no-repeat;
  background-size: 200% 300%;
}

.vehicle-meta {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  min-height: 42px;
  padding: 7px 8px;
  align-items: flex-end;
  justify-content: space-between;
  gap: 6px;
  background: linear-gradient(180deg, transparent, rgba(4, 6, 5, 0.95));
}

.vehicle-meta span,
.vehicle-meta b {
  display: block;
}

.vehicle-meta b {
  overflow: hidden;
  color: #f1f3ee;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vehicle-meta span {
  margin-top: 2px;
  color: #a0a99e;
  font-size: 8px;
}

.vehicle-status {
  flex: 0 0 auto;
  color: var(--lime);
  font-size: 9px;
  font-weight: 850;
}

.vehicle-card.is-locked .vehicle-status {
  color: #a7afa4;
}

.badge-wall {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.section-title {
  justify-content: space-between;
  color: #e6ebe3;
  font-size: 11px;
  font-weight: 800;
}

.section-title b {
  color: var(--muted);
  font-size: 9px;
}

.badge-grid {
  display: grid;
  margin-top: 9px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.badge-item {
  min-width: 0;
  padding: 9px 4px;
  color: #596059;
  background: #0c0e0c;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: center;
}

.badge-item.is-earned {
  color: var(--lime);
  border-color: rgba(199, 255, 56, 0.38);
}

.badge-symbol {
  display: grid;
  width: 28px;
  height: 28px;
  margin: 0 auto;
  font-size: 13px;
  font-weight: 950;
  border: 1px solid currentColor;
  border-radius: 50%;
  place-items: center;
}

.badge-item b {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: currentColor;
  font-size: 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 40;
  max-width: min(88vw, 360px);
  padding: 11px 14px;
  color: #10150c;
  font-size: 11px;
  font-weight: 820;
  background: var(--lime);
  border-radius: 6px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.48);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}

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

@keyframes feedback-pop {
  0% { opacity: 0; transform: translate(-50%, -10%) scale(0.75); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  72% { opacity: 1; transform: translate(-50%, -58%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -78%) scale(0.94); }
}

@keyframes unlock-in {
  0% { opacity: 0; transform: scale(0.94); }
  100% { opacity: 1; transform: scale(1); }
}

@media (max-height: 760px) {
  .game-card {
    height: calc(100svh - 20px);
    min-height: 620px;
    gap: 7px;
    padding: 10px;
    grid-template-rows: auto auto auto auto minmax(150px, 1fr) auto;
  }

  .topbar {
    min-height: 44px;
  }

  .brand-mark {
    height: 32px;
  }

  h1 {
    font-size: 21px;
  }

  .mode-button {
    height: 36px;
  }

  .score-tile {
    padding: 7px;
  }

  .score-tile strong {
    font-size: 15px;
  }

  #gameCanvas {
    min-height: 150px;
  }

  .press-pad {
    height: 78px;
  }

  .press-copy {
    font-size: 21px;
  }

  .press-subcopy {
    margin-top: 4px;
  }

  .quick-actions button {
    height: 34px;
  }
}

@media (min-width: 720px) {
  .game-shell {
    padding: 22px;
  }

  .game-card {
    height: min(880px, calc(100svh - 44px));
    min-height: 740px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
