:root {
  --bg: #08100f;
  --panel: rgba(9, 13, 22, 0.94);
  --panel-soft: rgba(13, 20, 32, 0.82);
  --line: rgba(255, 255, 255, 0.15);
  --text: #f8fafc;
  --muted: #a8b4c4;
  --accent: #ffd24a;
  --cyan: #34d6c7;
  --red: #ff4f66;
}

* {
  box-sizing: border-box;
}

html,
body {
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  overflow-x: hidden;
  background:
    linear-gradient(145deg, rgba(6, 11, 14, 0.94), rgba(22, 28, 41, 0.98)),
    repeating-linear-gradient(90deg, transparent 0 45px, rgba(255, 255, 255, 0.025) 45px 46px);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  width: min(100vw, 650px);
  padding: 14px;
}

.top-bar {
  display: grid;
  grid-template-columns: 96px 1fr 96px;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

h1 {
  margin: 0;
  color: var(--accent);
  font-size: clamp(2rem, 8vw, 3.15rem);
  line-height: 0.95;
  letter-spacing: 0;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45), 0 0 24px rgba(255, 210, 74, 0.22);
}

.hud-card,
.hud-strip,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 18px 46px rgba(0, 0, 0, 0.34);
}

.hud-card {
  min-height: 58px;
  padding: 8px 10px;
  overflow: hidden;
}

.top-bar .hud-card:last-child {
  text-align: right;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

strong {
  display: block;
  font-size: clamp(1.25rem, 4.5vw, 1.9rem);
  line-height: 1.08;
}

.game-wrap {
  position: relative;
  width: min(100%, 480px, calc((100dvh - 232px) * 0.6667));
  min-width: min(100%, 292px);
  aspect-ratio: 2 / 3;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: #171c22;
  isolation: isolate;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.05), 0 28px 88px rgba(0, 0, 0, 0.58);
}

canvas {
  position: relative;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #151a20;
}

.hud-strip {
  position: absolute;
  z-index: 2;
  top: 10px;
  left: 10px;
  right: 58px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding: 8px;
  pointer-events: none;
}

.hud-strip strong {
  font-size: clamp(0.78rem, 2.8vw, 1rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.powerup-slot {
  min-width: 0;
}

.pause-btn {
  position: absolute;
  z-index: 6;
  top: 10px;
  right: 10px;
  width: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(9, 13, 22, 0.8);
  color: var(--text);
}

.overlay {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  opacity: 1;
  transform: scale(1);
  transition: opacity 180ms ease, transform 180ms ease;
  background:
    linear-gradient(rgba(5, 8, 14, 0.28), rgba(5, 8, 14, 0.78)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 5px);
  pointer-events: auto;
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(100%, 345px);
  padding: 22px;
  background: var(--panel);
  text-align: center;
}

.wide-panel {
  width: min(100%, 415px);
}

.compact {
  width: min(100%, 300px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.panel h2 {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: clamp(2rem, 9vw, 3rem);
  line-height: 0.96;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.45;
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--cyan);
  color: #041715;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 900;
  text-transform: uppercase;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

button:hover,
button:focus-visible {
  background: #74f7e7;
}

.info-list {
  display: grid;
  gap: 10px;
}

.menu-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.menu-panel p {
  margin-bottom: 14px;
}

.secondary-btn,
.menuBackBtn,
.setting-toggle {
  width: 100%;
  margin-top: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.secondary-btn:hover,
.menuBackBtn:hover,
.setting-toggle:hover,
.secondary-btn:focus-visible,
.menuBackBtn:focus-visible,
.setting-toggle:focus-visible {
  background: rgba(52, 214, 199, 0.72);
  color: #041715;
}

.setting-note {
  margin: 12px 0 2px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 0 0 16px;
}

.result-grid > div {
  min-width: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.result-grid strong {
  font-size: clamp(1rem, 5vw, 1.48rem);
}

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

.car-card {
  min-height: 96px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  text-align: left;
}

.car-card.is-selected {
  border-color: rgba(52, 214, 199, 0.9);
  box-shadow: inset 0 0 0 1px rgba(52, 214, 199, 0.42), 0 0 22px rgba(52, 214, 199, 0.16);
}

.car-swatch {
  width: 42px;
  height: 26px;
  margin-bottom: 8px;
  border-radius: 7px;
  box-shadow: inset 8px 0 rgba(255, 255, 255, 0.22), inset -8px 0 rgba(0, 0, 0, 0.18);
}

.car-card strong {
  font-size: 0.98rem;
}

.car-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: none;
}

.touch-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  width: min(100%, 390px);
  margin: 12px auto 0;
  touch-action: none;
}

.touch-stack {
  display: grid;
  grid-template-columns: repeat(3, 58px);
  gap: 8px;
}

.touch-stack .touch-btn:first-child,
.touch-stack .touch-btn:last-child {
  grid-column: 2;
}

.touch-btn {
  width: 72px;
  height: 50px;
  min-height: 50px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.13);
  background: rgba(255, 255, 255, 0.11);
  color: var(--text);
  font-size: 1.32rem;
  line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 22px rgba(0, 0, 0, 0.25);
}

.pause-touch {
  grid-column: 2;
  color: var(--accent);
  font-size: 0.95rem;
}

.touch-btn:hover,
.touch-btn:focus-visible,
.touch-btn.is-pressed {
  transform: translateY(1px);
  background: rgba(52, 214, 199, 0.78);
  color: #051815;
}

@media (max-width: 520px) {
  .game-shell {
    padding: 9px;
  }

  .top-bar {
    grid-template-columns: 74px 1fr 74px;
    gap: 8px;
  }

  .hud-card {
    min-height: 50px;
    padding: 7px;
  }

  .label {
    font-size: 0.55rem;
  }

  h1 {
    font-size: clamp(1.75rem, 8.2vw, 2.35rem);
  }

  .hud-strip {
    top: 8px;
    left: 8px;
    right: 54px;
    gap: 4px;
    padding: 6px;
  }

  .panel {
    padding: 18px;
  }

  .panel h2 {
    font-size: clamp(1.85rem, 10vw, 2.55rem);
  }

  .garage-list {
    gap: 8px;
  }

  .touch-btn {
    width: 62px;
    height: 46px;
    min-height: 46px;
  }

  .touch-stack {
    grid-template-columns: repeat(3, 52px);
  }
}

@media (max-height: 760px) and (min-width: 620px) {
  .game-shell {
    padding: 8px;
  }

  .top-bar {
    margin-bottom: 8px;
  }

  h1 {
    font-size: clamp(2rem, 6.8vw, 2.65rem);
  }

  .game-wrap {
    width: min(100%, 480px, calc((100dvh - 278px) * 0.6667));
  }

  .touch-controls {
    margin-top: 8px;
  }

  .touch-btn {
    height: 42px;
    min-height: 42px;
  }
}
