* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #87ceeb;
  font-family: "Segoe UI", Arial, sans-serif;
}

canvas {
  display: block;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  z-index: 10;
}

#dash {
  position: absolute;
  bottom: 28px;
  right: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#signal-indicators {
  display: flex;
  gap: 60px;
}

.signal-arrow {
  font-size: 22px;
  color: #2a2e33;
  opacity: 0.3;
  transition: opacity 0.05s linear, color 0.05s linear;
}

.signal-arrow.on {
  color: #3ee06a;
  opacity: 1;
  filter: drop-shadow(0 0 4px #3ee06a);
}

#shift-lights {
  display: flex;
  gap: 4px;
  padding: 5px 8px;
  background: rgba(10, 12, 15, 0.55);
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

#shift-lights .lamp {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: #23262b;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  transition: background 0.05s linear, box-shadow 0.05s linear;
}

#shift-lights .lamp.lit-green {
  background: #3ee06a;
  box-shadow: 0 0 7px 1px #3ee06a;
}

#shift-lights .lamp.lit-amber {
  background: #f2b705;
  box-shadow: 0 0 7px 1px #f2b705;
}

#shift-lights .lamp.lit-red {
  background: #ff3b30;
  box-shadow: 0 0 9px 2px #ff3b30;
}

#shift-lights.flash .lamp.lit-red {
  animation: shift-flash 0.12s steps(1) infinite;
}

@keyframes shift-flash {
  50% { background: #fff; box-shadow: 0 0 14px 4px #fff; }
}

#tach-gauge {
  position: relative;
  width: 208px;
  height: 208px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, #2c2f34, #111316 72%),
    conic-gradient(
      from -130deg,
      #4b4f56 0deg 195deg,
      #f2b705 195deg 227.5deg,
      #ff3b30 227.5deg 260deg,
      transparent 260deg 360deg
    );
  box-shadow:
    0 4px 18px rgba(0, 0, 0, 0.5),
    inset 0 0 0 5px #1a1c1f,
    inset 0 0 0 7px rgba(255, 255, 255, 0.06);
}

#tach-gauge::before {
  content: "";
  position: absolute;
  inset: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #23262b, #15171a 75%);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6);
}

.tach-tick {
  position: absolute;
  background: #cfd3d8;
  border-radius: 1px;
}

.tach-tick.major {
  width: 3px;
  height: 12px;
  background: #f2f4f6;
}

.tach-tick.minor {
  width: 2px;
  height: 6px;
  background: #7c8189;
}

.tach-label {
  position: absolute;
  font-size: 15px;
  font-weight: 700;
  color: #f2f4f6;
  transform: translate(-50%, -50%);
}

.tach-label.redline {
  color: #ff6a52;
}

#tach-needle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 78px;
  background: linear-gradient(#ff6a4a, #ff3b30);
  border-radius: 2px 2px 1px 1px;
  transform-origin: 50% 88%;
  transform: translate(-50%, -88%) rotate(-130deg);
  transition: transform 0.06s linear;
  z-index: 2;
  box-shadow: 0 0 4px rgba(255, 59, 48, 0.6);
}

#tach-hub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  background: radial-gradient(circle at 40% 35%, #e8e8e8, #8a8d92 70%);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

#gauge-glass {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0) 32%);
  pointer-events: none;
  z-index: 4;
}

#gauge-center {
  position: absolute;
  left: 50%;
  top: 58%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 1;
}

#speed-value {
  font-size: 46px;
  font-weight: 800;
  line-height: 1;
  color: #fff;
}

#speed-unit {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.7;
  margin-top: 1px;
}

#drift-badge {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #ff5a3c;
  background: rgba(15, 20, 25, 0.45);
  border: 2px solid #ff5a3c;
  border-radius: 10px;
  padding: 6px 16px;
  animation: drift-pulse 0.5s ease-in-out infinite alternate;
}

@keyframes drift-pulse {
  from { opacity: 0.7; transform: translateX(-50%) scale(1); }
  to { opacity: 1; transform: translateX(-50%) scale(1.06); }
}

#gear-value {
  font-size: 17px;
  font-weight: 700;
  margin-top: 6px;
  padding: 2px 11px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.15);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}

#tach-rpm {
  font-size: 10px;
  font-weight: 600;
  color: #9aa0a6;
  margin-top: 3px;
  letter-spacing: 0.5px;
}

#hint-panel {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  background: rgba(15, 20, 25, 0.4);
  padding: 6px 14px;
  border-radius: 8px;
  white-space: nowrap;
}

#car-select-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: rgba(15, 20, 25, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}

#car-select-btn:hover {
  background: rgba(30, 36, 42, 0.75);
}

#money-display {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 16px;
  font-weight: 700;
  background: rgba(15, 20, 25, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding: 8px 14px;
}

#shop-btn {
  position: absolute;
  top: 60px;
  right: 16px;
  pointer-events: auto;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: rgba(15, 20, 25, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}

#shop-btn:hover {
  background: rgba(30, 36, 42, 0.75);
}

#settings-btn {
  position: absolute;
  top: 104px;
  right: 16px;
  pointer-events: auto;
  font-size: 16px;
  background: rgba(15, 20, 25, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

#settings-btn:hover {
  background: rgba(30, 36, 42, 0.75);
}

#shop-panel {
  position: absolute;
  top: 104px;
  right: 16px;
  pointer-events: auto;
  background: rgba(15, 20, 25, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 14px;
  width: 260px;
  backdrop-filter: blur(4px);
}

#shop-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
}

.shop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.shop-row:first-child {
  border-top: none;
}

.shop-row-label {
  font-size: 13px;
  flex: 1;
}

.shop-row-tiers {
  display: flex;
  gap: 3px;
  margin-right: 8px;
}

.shop-tier-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
}

.shop-tier-dot.filled {
  background: #3ee06a;
}

.shop-buy-btn {
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: rgba(62, 224, 106, 0.2);
  border: 1px solid #3ee06a;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}

.shop-buy-btn:disabled {
  color: #888;
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.15);
  cursor: default;
}

.shop-buy-btn.maxed {
  color: #3ee06a;
  background: transparent;
  border-color: transparent;
}

#shop-close-btn {
  margin-top: 10px;
  width: 100%;
  font: inherit;
  font-size: 12px;
  color: #ccc;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
}

#car-select-panel {
  position: absolute;
  top: 62px;
  left: 16px;
  pointer-events: auto;
  background: rgba(15, 20, 25, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 8px;
  max-height: 70vh;
  overflow-y: auto;
  backdrop-filter: blur(4px);
}

#car-select-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 190px;
}

.car-select-item {
  font: inherit;
  font-size: 14px;
  color: #eee;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

.car-select-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.car-select-item.active {
  background: rgba(255, 90, 60, 0.25);
  border-color: #ff5a3c;
  font-weight: 700;
}

#loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 20px;
  background: #87ceeb;
  z-index: 20;
}

#loading.hidden {
  display: none;
}

#loading.error {
  background: #2a1414;
  color: #ff8a75;
  font-size: 16px;
  text-align: center;
  padding: 32px;
  line-height: 1.5;
}

#main-menu {
  position: fixed;
  inset: 0;
  z-index: 30;
}

#main-menu:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(rgba(8, 10, 14, 0.45), rgba(8, 10, 14, 0.82) 75%),
    url("../menu-hero.png") center 40% / cover no-repeat,
    radial-gradient(circle at 50% 30%, #2a3542, #0d1014 75%);
}

#menu-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 24px;
}

#menu-title {
  font-size: clamp(38px, 12vw, 72px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 2px;
  color: #ff3b30;
  text-shadow:
    0 0 24px rgba(255, 59, 48, 0.6),
    3px 3px 0 #0d1014,
    -1px -1px 0 #fff2;
  -webkit-text-stroke: 1.5px #1a1c1f;
}

#menu-subtitle {
  margin-top: -14px;
  font-size: 14px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #b9c0c8;
}

#menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 220px;
}

#menu-buttons button {
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

#menu-play-btn {
  background: linear-gradient(#ff5a3c, #d8321f);
  border-color: #ff5a3c;
  box-shadow: 0 4px 16px rgba(255, 59, 48, 0.4);
}

#menu-buttons button:hover {
  filter: brightness(1.12);
}

#settings-panel {
  position: fixed;
  inset: 0;
  z-index: 31;
  background: rgba(8, 10, 13, 0.72);
  backdrop-filter: blur(3px);
}

#settings-panel:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
}

#settings-card {
  width: 320px;
  max-width: 88vw;
  background: rgba(20, 23, 28, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 22px;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-title {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 4px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.settings-row input[type="range"] {
  width: 140px;
  accent-color: #ff5a3c;
}

.settings-toggle {
  width: 20px;
  height: 20px;
  accent-color: #ff5a3c;
  cursor: pointer;
}

.settings-btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  padding: 11px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.settings-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.settings-btn-danger {
  color: #ff8a75;
  border-color: rgba(255, 90, 60, 0.4);
  background: rgba(255, 59, 48, 0.1);
}

.settings-btn-danger:hover {
  background: rgba(255, 59, 48, 0.22);
}
