:root {
  --bg: #111318;
  --panel: #1c1f27;
  --panel-2: #262a35;
  --line: #353a47;
  --text: #eef1f6;
  --muted: #a5adbd;
  --accent: #ff5a3c;
  --accent-2: #ffc83d;
  --good: #7ddc4a;
  --bad: #ff4a4a;
  --cyan: #6fe3ff;
  --radius: 10px;
  --hud-h: 44px;
  --header-h: 48px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent-2);
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.site-logo {
  font-weight: 800;
  font-size: 20px;
  text-decoration: none;
  color: var(--text);
  letter-spacing: 0.5px;
}

.site-logo span {
  color: var(--accent-2);
  font-weight: 600;
  font-size: 13px;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.site-header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.page {
  padding: 8px 8px 40px;
}

/* ---------- Game layout ---------- */

.game-root {
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: min(1280px, calc((100vh - var(--header-h) - var(--hud-h) - 24px) * 1.7778));
  max-width: min(1280px, calc((100dvh - var(--header-h) - var(--hud-h) - 24px) * 1.7778));
  min-width: min(100%, 320px);
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 300px;
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hud {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px;
  min-height: var(--hud-h);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.hud-item {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-weight: 800;
  font-size: 18px;
  white-space: nowrap;
}

.hud-item small {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.hud-level {
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
  max-width: 28%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-time small.over {
  color: var(--bad);
}

.hud-time small.under {
  color: var(--good);
}

.nut {
  width: 14px;
  height: 14px;
  align-self: center;
  background: var(--accent-2);
  clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0 50%);
  position: relative;
}

.hud-stunts span {
  color: var(--cyan);
}

.hud-fuel .bar {
  width: 80px;
}

.hud-spacer {
  flex: 1;
}

.bar {
  height: 10px;
  background: #0b0c10;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #ff8a1f, #ffd166);
  transition: width 0.1s linear;
}

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  transition:
    background 0.12s,
    transform 0.06s;
}

.btn:hover:not(:disabled) {
  background: #313645;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn:focus-visible,
.tbtn:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(180deg, #ff6a45, #e0402a);
  border-color: #ff8a6a;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #ff7d5c, #e84a33);
}

.btn-icon {
  min-width: 36px;
  padding: 5px 8px;
}

.toast {
  position: absolute;
  left: 50%;
  top: 8%;
  transform: translateX(-50%);
  background: rgba(10, 12, 16, 0.85);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 16px;
  font-weight: 700;
  font-size: 15px;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  z-index: 4;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
}

/* ---------- Touch controls ---------- */

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

.touch > div {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.tbtn {
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(20, 22, 30, 0.45);
  color: #fff;
  font-size: 26px;
  font-weight: 800;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.tbtn.gas {
  width: 78px;
  height: 78px;
  background: rgba(90, 200, 90, 0.45);
}

.tbtn.action {
  width: 52px;
  height: 52px;
  font-size: 20px;
  background: rgba(255, 200, 61, 0.4);
}

.tbtn.small {
  width: 56px;
  height: 36px;
  border-radius: 18px;
  font-size: 13px;
}

.tbtn.down {
  background: rgba(255, 255, 255, 0.35);
}

/* ---------- Overlay / menus ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 16, 0.55);
  z-index: 5;
  overflow: auto;
  padding: 14px;
}

.overlay.show {
  display: flex;
}

.overlay.dim {
  background: rgba(10, 12, 16, 0.86);
}

.menu {
  width: min(780px, 100%);
  max-height: 100%;
  margin: auto;
}

.panel-box {
  background: rgba(22, 25, 33, 0.92);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
}

.menu h2 {
  margin: 0 0 10px;
  font-size: 24px;
}

.title {
  text-align: center;
}

.logo {
  font-size: clamp(38px, 8vw, 76px);
  font-weight: 900;
  letter-spacing: 3px;
  margin: 0;
  color: #fff;
  -webkit-text-stroke: 2px #1a0c08;
  text-shadow:
    0 4px 0 #b52a16,
    0 8px 24px rgba(0, 0, 0, 0.5);
  transform: rotate(-2deg);
}

.tagline {
  color: #e9edf5;
  margin: 8px 0 16px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

.menu-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.menu-buttons .btn {
  padding: 12px 14px;
  font-size: 16px;
}

.menu-buttons .btn small {
  display: block;
  font-weight: 500;
  font-size: 12px;
  opacity: 0.85;
  margin-top: 3px;
}

.stat-row {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 14px;
}

.stat-row b {
  color: var(--text);
}

.goal {
  margin: 12px auto 0;
  max-width: 440px;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
}

.goal .bar {
  height: 12px;
  margin-top: 4px;
}

.goal .bar-fill {
  background: linear-gradient(90deg, #ffc83d, #fff0b0);
}

.menu-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.menu-top h2 {
  margin: 0;
}

.bolts {
  font-weight: 800;
  color: var(--accent-2);
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.vehicle-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.vtab {
  padding: 6px 12px;
  border-radius: 999px;
}

.vtab.active {
  background: var(--accent);
  border-color: #ff8a6a;
  color: #fff;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.lcard {
  text-align: left;
  padding: 10px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 78px;
}

.lcard .num {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.lcard .nm {
  font-size: 15px;
}

.lcard .st {
  color: #555b69;
  letter-spacing: 2px;
  font-size: 15px;
}

.lcard .st .on {
  color: var(--accent-2);
}

.lcard .bt {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.lcard.locked {
  opacity: 0.5;
}

.results {
  text-align: center;
}

.results .big {
  font-size: clamp(30px, 6vw, 50px);
  font-weight: 900;
  margin: 0;
  letter-spacing: 2px;
}

.results .big.win {
  color: var(--good);
}

.results .big.lose {
  color: var(--bad);
}

.results .cause {
  color: var(--muted);
  margin: 2px 0 8px;
}

.stars {
  font-size: 40px;
  letter-spacing: 6px;
  color: #3b404d;
  margin: 4px 0;
}

.stars span.on {
  color: var(--accent-2);
  display: inline-block;
  animation: pop 0.35s ease-out both;
}

@keyframes pop {
  0% {
    transform: scale(0.2);
  }
  70% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
  }
}

.star-reqs {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.star-reqs .ok {
  color: var(--good);
}

.report {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  text-align: left;
  font-size: 14px;
  margin: 10px auto;
  max-width: 560px;
}

.report h4 {
  margin: 0 0 4px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.report ul {
  margin: 0;
  padding-left: 18px;
}

.near {
  color: var(--accent-2);
  font-weight: 700;
  margin: 6px 0;
}

.ach-toast {
  color: var(--accent-2);
  font-weight: 700;
  margin: 4px 0;
}

.shop {
  display: grid;
  gap: 14px;
}

.shop h3 {
  margin: 0 0 6px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 8px;
  min-width: 78px;
  font-size: 12px;
}

.swatch .chip {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.swatch.selected {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 1px var(--accent-2) inset;
}

.vehicle-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.vcard {
  text-align: left;
  padding: 10px;
  font-weight: 500;
  font-size: 13px;
}

.vcard b {
  font-size: 15px;
  display: block;
}

.vcard.selected {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 1px var(--accent-2) inset;
}

.ach-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.ach {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 13px;
  opacity: 0.55;
}

.ach.done {
  opacity: 1;
  border-color: var(--accent-2);
}

.ach b {
  display: block;
}

.toggle-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
  flex-wrap: wrap;
}

.keys {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
}

kbd {
  background: #2a2e3a;
  border: 1px solid #454b5a;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  font-size: 0.9em;
  font-family: inherit;
}

.rotate-hint {
  display: none;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 6px;
}

.ad-slot {
  max-width: 970px;
  margin: 14px auto 0;
  min-height: 0;
}

.ad-slot:empty {
  display: none;
}

.about {
  max-width: 820px;
  margin: 24px auto 0;
  color: #d5dae4;
  line-height: 1.55;
}

.about h1 {
  font-size: 26px;
}

.about h2 {
  font-size: 19px;
}

@media (max-width: 720px) {
  .hud {
    gap: 6px;
    padding: 3px 6px;
    min-height: 36px;
  }
  .hud-item {
    font-size: 14px;
  }
  .hud-level {
    display: none;
  }
  .hud-fuel .bar {
    width: 44px;
  }
  .btn-icon {
    min-width: 30px;
    padding: 3px 6px;
  }
  .tbtn {
    width: 54px;
    height: 54px;
    font-size: 22px;
  }
  .tbtn.gas {
    width: 64px;
    height: 64px;
  }
  .report {
    grid-template-columns: 1fr;
  }
  .stars {
    font-size: 30px;
  }
}

@media (orientation: portrait) and (max-width: 720px) {
  .game-root:not(.menu-mode) + .rotate-hint,
  .game-root:not(.menu-mode) .rotate-hint {
    display: block;
  }
  .stage {
    aspect-ratio: 4 / 3;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stars span.on {
    animation: none;
  }
}
