:root {
  --bg: #12151a;
  --bg-2: #1a1f27;
  --card: #20262f;
  --text: #f3eee6;
  --muted: #9a9286;
  --accent: #f0a03a;
  --accent-2: #e86a2a;
  --danger: #e85d4c;
  --ok: #3dbe7a;
  --glass: rgba(14, 16, 20, 0.58);
  --stroke: rgba(255, 255, 255, 0.08);
  --radius: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --pop: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #12151a;
  color: #f3eee6;
  font-family: "Cairo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  touch-action: none;
}

body {
  user-select: none;
  -webkit-user-select: none;
}

img, svg, canvas { display: block; }

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  touch-action: none;
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.screen-fill {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#screen-loading { z-index: 40; background: #12151a; color: #f3eee6; }
#screen-error { z-index: 45; background: rgba(12, 14, 18, 0.92); color: #f3eee6; }
#screen-menu { z-index: 20; }
#screen-help { z-index: 30; background: rgba(10, 12, 16, 0.55); color: #f3eee6; backdrop-filter: blur(16px); }
#screen-over { z-index: 30; background: rgba(10, 12, 16, 0.62); color: #f3eee6; backdrop-filter: blur(16px); }

.load-card {
  width: min(360px, 100%);
  text-align: center;
}

.load-mark {
  position: relative;
  width: 120px;
  height: 48px;
  margin: 0 auto 24px;
}

.load-road {
  position: absolute;
  inset: auto 0 10px;
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(90deg, #2a2e36, #3a404a 40%, #2a2e36);
  overflow: hidden;
}

.load-road::after {
  content: "";
  position: absolute;
  inset: 2px auto 2px 0;
  width: 28%;
  background: repeating-linear-gradient(90deg, #f0a03a 0 8px, transparent 8px 16px);
  animation: road-run 0.9s linear infinite;
}

.load-car {
  position: absolute;
  left: 0;
  bottom: 16px;
  width: 36px;
  height: 16px;
  border-radius: 5px 8px 3px 3px;
  background: linear-gradient(90deg, #e86a2a, #f0a03a);
  animation: car-run 1.4s var(--ease) infinite;
  box-shadow: 0 6px 12px rgba(232, 106, 42, 0.35);
}

.load-title {
  margin: 0 0 8px;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #f3eee6;
}

.load-caption {
  margin: 0 0 20px;
  color: #9a9286;
  font-size: 15px;
}

.load-track {
  height: 8px;
  border-radius: 99px;
  background: #1c2128;
  overflow: hidden;
}

.load-bar {
  height: 100%;
  width: 8%;
  border-radius: 99px;
  background: linear-gradient(90deg, #e86a2a, #f0a03a);
  transition: width 0.35s var(--ease);
}

@keyframes road-run {
  from { transform: translateX(-40%); }
  to { transform: translateX(220%); }
}
@keyframes car-run {
  0%, 100% { transform: translateX(8px); }
  50% { transform: translateX(76px); }
}

.menu-veil {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(12, 14, 18, 0.28) 0%, rgba(12, 14, 18, 0.18) 40%, rgba(12, 14, 18, 0.72) 100%);
  pointer-events: none;
}

.menu-inner {
  position: relative;
  width: min(440px, 100%);
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #f0a03a;
}

.hero-title {
  margin: 0 0 12px;
  font-size: 48px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: #f3eee6;
  text-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

.hero-sub {
  margin: 0 auto 24px;
  max-width: 34ch;
  color: #c8c0b4;
  font-size: 15px;
  line-height: 1.65;
}

.hiscore-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 16px;
  margin-bottom: 24px;
  border-radius: 999px;
  background: rgba(14, 16, 20, 0.58);
  color: #f3eee6;
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
}

.chip-label {
  font-size: 13px;
  color: #9a9286;
}

.hiscore-chip strong {
  font-size: 24px;
  font-weight: 800;
  color: #f0a03a;
}

.menu-actions { display: flex; flex-direction: column; gap: 12px; }
.menu-row { display: flex; gap: 10px; }
.menu-row .btn { flex: 1; }

.menu-hint {
  margin: 20px 0 0;
  font-size: 13px;
  color: #9a9286;
}

.panel {
  width: min(400px, 100%);
  padding: 28px 24px;
  border-radius: 16px;
  background: rgba(20, 24, 30, 0.78);
  color: #f3eee6;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(16px);
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

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

.panel h2 {
  margin: 0 0 12px;
  font-size: 28px;
  letter-spacing: -0.02em;
  color: #f3eee6;
}

.panel p {
  margin: 0 0 20px;
  color: #c8c0b4;
  font-size: 15px;
}

.panel-icon { font-size: 36px; margin-bottom: 12px; }

.help-list {
  margin: 0 0 24px;
  padding: 0 8px 0 0;
  text-align: right;
  color: #e6dfd4;
  font-size: 15px;
  line-height: 1.7;
}

.help-list li { margin-bottom: 10px; }

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 16px;
  border-radius: 14px;
  min-height: 48px;
  padding: 12px 20px;
  transition: transform 0.12s ease-out, filter 0.2s var(--ease), background 0.2s;
  color: #f3eee6;
  background: #2a313c;
}

.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid #f0a03a; outline-offset: 3px; }
.btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
  color: #9a9286;
}

.btn-primary {
  background: linear-gradient(180deg, #f6b24e 0%, #e86a2a 78%, #d85c20 100%);
  color: #1a120c;
  border-radius: 999px;
  border: 1px solid rgba(255, 224, 176, 0.38);
  box-shadow:
    0 12px 28px rgba(180, 70, 16, 0.4),
    0 4px 10px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.52),
    inset 0 -1px 0 rgba(90, 30, 6, 0.28);
}

.btn-primary:hover { filter: brightness(1.05); }

.btn-primary:active {
  filter: brightness(0.94);
  box-shadow:
    0 4px 12px rgba(180, 70, 16, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    inset 0 -1px 0 rgba(90, 30, 6, 0.2);
}

.btn-ghost {
  background: rgba(16, 14, 12, 0.58);
  color: #f3eee6;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 16px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-ghost:active {
  background: rgba(10, 8, 7, 0.74);
  border-color: rgba(255, 255, 255, 0.12);
  filter: brightness(0.82);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.btn-ghost:disabled {
  background: rgba(16, 14, 12, 0.38);
  color: #9a9286;
  filter: none;
}

.btn-xl { min-height: 56px; font-size: 18px; width: 100%; }

#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

#minimap-wrap {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 88px;
  pointer-events: none;
}

#minimap {
  width: 88px;
  height: 88px;
  border-radius: 14px;
  background: rgba(14, 16, 20, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.mmap-label {
  display: block;
  margin-top: 4px;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: #9a9286;
}

#hud-stats {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: min(148px, 38vw);
}

.stat-pill {
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  border-radius: 14px;
  background: rgba(14, 16, 20, 0.58);
  color: #f3eee6;
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
}

.stat-k {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: #9a9286;
  font-weight: 700;
}

.stat-v {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: #f3eee6;
  font-variant-numeric: tabular-nums;
}

.stat-time .stat-v { color: #f0a03a; }
.stat-time.is-low {
  background: rgba(80, 22, 20, 0.72);
  color: #f3eee6;
  border-color: rgba(232, 93, 76, 0.4);
}
.stat-time.is-low .stat-v { color: #ff8a7a; }

.stat-slim .stat-v { font-size: 18px; }

#mission-banner,
#toast {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
  max-width: 80vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

#mission-banner {
  top: 112px;
  background: rgba(14, 16, 20, 0.62);
  color: #f3eee6;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#toast {
  top: 152px;
  background: linear-gradient(115deg, #e86a2a, #f0a03a);
  color: #1a120c;
}

#speedo {
  position: absolute;
  left: 50%;
  bottom: 118px;
  transform: translateX(-50%);
  width: 88px;
  height: 88px;
  pointer-events: none;
}

.speedo-svg { width: 88px; height: 88px; }
.speedo-ring {
  fill: rgba(14, 16, 20, 0.55);
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 6;
}
.speedo-arc {
  fill: none;
  stroke: url(#none);
  stroke: #f0a03a;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 250;
  stroke-dashoffset: 250;
  transform: rotate(-210deg);
  transform-origin: 60px 60px;
}

#speedo-needle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 28px;
  margin: -26px 0 0 -1.5px;
  border-radius: 3px;
  background: #f3eee6;
  transform-origin: 50% 26px;
  transform: rotate(-120deg);
}

.speedo-read {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 10px;
  color: #f3eee6;
}

.speedo-read strong {
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
}

.speedo-read span {
  font-size: 10px;
  color: #9a9286;
  letter-spacing: 0.08em;
  font-weight: 700;
}

#controls {
  position: absolute;
  inset: auto 0 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 12px;
  pointer-events: none;
}

.cluster {
  display: flex;
  gap: 8px;
  pointer-events: auto;
  align-items: flex-end;
}

.cluster-right {
  display: grid;
  grid-template-columns: 56px 72px;
  grid-template-rows: 52px 72px 56px;
  gap: 8px;
}

#btn-hand { grid-column: 1; grid-row: 2; }
#btn-gas { grid-column: 2; grid-row: 1 / span 2; }
#btn-brake { grid-column: 1 / span 2; grid-row: 3; }

.pad {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(14, 16, 20, 0.58);
  color: #f3eee6;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s ease-out, background 0.15s, border-color 0.15s;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.pad span { color: #c8c0b4; }
.pad:focus-visible { outline: 2px solid #f0a03a; outline-offset: 2px; }
.pad.is-pressed {
  transform: scale(0.96);
  background: rgba(240, 160, 58, 0.28);
  color: #f3eee6;
  border-color: rgba(240, 160, 58, 0.55);
}

.pad-steer {
  width: 68px;
  height: 68px;
  border-radius: 50%;
}

.pad-gas {
  width: 72px;
  height: 100%;
  border-radius: 22px;
  background: rgba(61, 190, 122, 0.18);
  color: #d8ffe8;
  border-color: rgba(61, 190, 122, 0.35);
}
.pad-gas span { color: #b7f0cf; }
.pad-gas.is-pressed { background: rgba(61, 190, 122, 0.42); }

.pad-brake {
  height: 56px;
  border-radius: 16px;
  background: rgba(232, 93, 76, 0.16);
  color: #ffd4ce;
  border-color: rgba(232, 93, 76, 0.32);
}
.pad-brake span { color: #f3b2aa; }
.pad-brake.is-pressed { background: rgba(232, 93, 76, 0.4); }

.pad-hand {
  width: 56px;
  height: 56px;
  border-radius: 16px;
}

.over-kicker { color: #e85d4c; }
.record-badge {
  display: inline-block;
  margin: -8px 0 16px;
  padding: 6px 12px;
  border-radius: 999px;
  background: linear-gradient(115deg, #e86a2a, #f0a03a);
  color: #1a120c;
  font-size: 13px;
  font-weight: 800;
}

.over-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 24px;
}

.over-grid div {
  padding: 12px 6px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: #f3eee6;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.over-grid span {
  display: block;
  font-size: 11px;
  color: #9a9286;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.over-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
  font-weight: 800;
  color: #f3eee6;
}

#screen-over .btn-ghost { width: 100%; margin-top: 8px; }

@media (min-width: 900px) {
  .hero-title { font-size: 56px; }
  #minimap-wrap { width: 112px; }
  #minimap { width: 112px; height: 112px; }
  #hud-stats { width: 168px; }
  #speedo { bottom: 132px; width: 100px; height: 100px; }
  .speedo-svg { width: 100px; height: 100px; }
  .pad-steer { width: 76px; height: 76px; }
  #controls { padding: 0 28px 20px; }
}

@media (max-height: 700px) {
  .hero-title { font-size: 36px; }
  #speedo { bottom: 108px; }
  #mission-banner { top: 100px; }
}

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