* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1f2120;
  color: #fbf3e4;
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* ---------- HUD ---------- */

.hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 68px;
  display: flex;
  gap: 8px;
  pointer-events: none;
}

.chip {
  min-width: 92px;
  padding: 6px 12px 7px;
  border-radius: 16px;
  background: rgb(31 33 32 / 0.78);
  border: 2px solid rgb(255 255 255 / 0.1);
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.chip .label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #d9cfbd;
}

.chip .value {
  display: flex;
  align-items: baseline;
  gap: 3px;
  white-space: nowrap;
}

.chip strong {
  font-size: clamp(18px, 3.6vmin, 26px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.chip small {
  font-size: 12px;
  font-weight: 700;
  color: #d9cfbd;
}

.chip-coin strong {
  color: #facc15;
}

.chip.nitro {
  border-color: #27d6c1;
  box-shadow: 0 0 16px rgb(34 211 238 / 0.55);
}

.chip.nitro strong {
  color: #27d6c1;
}

@media (max-width: 480px) {
  .chip {
    flex: 1 1 0;
    min-width: 0;
    padding: 5px 9px 6px;
  }
}

.icon-btn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: 10px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 0.14);
  background: rgb(31 33 32 / 0.78);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.pause-icon {
  width: 16px;
  height: 18px;
  border-left: 5px solid currentColor;
  border-right: 5px solid currentColor;
}

.icon-btn:focus-visible,
.btn:focus-visible {
  outline: 3px solid #c6f432;
  outline-offset: 3px;
}

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  background: rgb(31 33 32 / 0.55);
}

.card {
  width: 100%;
  max-width: 440px;
  margin: auto;
  padding: clamp(18px, 4.5vmin, 34px) clamp(18px, 4vmin, 30px);
  border-radius: 28px;
  background: rgb(42 44 42 / 0.94);
  border: 2px solid rgb(255 255 255 / 0.08);
  box-shadow: 0 24px 60px rgb(0 0 0 / 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 2vmin, 14px);
  text-align: center;
}

.title {
  margin: 0;
  font-size: clamp(36px, 10vmin, 64px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #facc15, #fb923c 45%, #fb7185);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title.small {
  font-size: clamp(30px, 8vmin, 50px);
}

.card p {
  margin: 0;
}

.goal {
  font-size: clamp(15px, 3.4vmin, 18px);
  color: #f1e8d6;
  max-width: 34ch;
}

.hint {
  font-size: 14px;
  color: #d9cfbd;
}

.hint kbd {
  display: inline-block;
  min-width: 24px;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid rgb(255 255 255 / 0.25);
  border-bottom-width: 3px;
  background: rgb(255 255 255 / 0.06);
  color: #fbf3e4;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}

.sub {
  font-size: 13px;
  color: #d9cfbd;
  min-height: 1em;
}

.score-big {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.score-big > span {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #d9cfbd;
}

.score-big strong {
  font-size: clamp(40px, 11vmin, 64px);
  font-weight: 900;
  color: #facc15;
  font-variant-numeric: tabular-nums;
}

.breakdown {
  font-size: 15px;
  color: #e0d6c3;
}

.best {
  font-size: 16px;
  color: #f1e8d6;
}

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: #a3e635;
  color: #1a2e05;
  font-size: 13px;
  font-weight: 900;
}

.near-miss {
  margin: 4px 0 0;
  font-size: 14px;
  font-weight: 800;
  color: #ff6b4a;
  letter-spacing: 0.02em;
  animation: pulse-near 1.5s ease-in-out infinite;
}

@keyframes pulse-near {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.85; transform: scale(1.02); }
}

.btn {
  min-width: 170px;
  min-height: 54px;
  padding: 12px 30px;
  border: 0;
  border-radius: 999px;
  background: #ee5e24;
  color: #15130f;
  font: inherit;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 0 #b8400f;
  transition: transform 0.08s ease;
}

.btn:hover {
  background: #d93d12;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #b8400f;
}

.mode-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  width: 100%;
}

.mode-row .btn {
  flex: 1 1 150px;
  min-width: 0;
  padding-left: 18px;
  padding-right: 18px;
}

.btn.btn-alt {
  background: #363836;
  border: 1px solid #3a4250;
  box-shadow: 0 6px 0 #46443e;
}

.btn.btn-alt:hover {
  background: #2a3140;
}

.btn.btn-alt:active {
  box-shadow: 0 3px 0 #46443e;
}

.mode-tag {
  padding: 2px 12px;
  border-radius: 999px;
  background: #27d6c1;
  color: #1f2120;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.unlock {
  padding: 6px 14px;
  border-radius: 14px;
  background: #363836;
  border: 1px solid #3a4250;
  color: #fbf3e4;
  font-size: 15px;
  font-weight: 800;
}

.paints {
  display: flex;
  align-items: center;
  gap: 10px;
}

.paint-label {
  font-size: 13px;
  font-weight: 800;
  color: #d9cfbd;
}

.paint-row {
  display: flex;
  gap: 8px;
}

.paint {
  position: relative;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid #3a4250;
  border-radius: 14px;
  background: #363836;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.paint .car-chip {
  width: 16px;
  height: 26px;
  border-radius: 6px 6px 5px 5px;
  box-shadow: inset 0 -5px 0 var(--spoiler);
  background: linear-gradient(90deg, var(--body) 0 30%, var(--stripe) 30% 42%, var(--body) 42% 58%, var(--stripe) 58% 70%, var(--body) 70%);
}

.paint[aria-pressed="true"] {
  border-color: #fbf3e4;
  background: #2a3140;
}

.paint:disabled {
  cursor: not-allowed;
}

.paint:disabled .car-chip {
  opacity: 0.25;
}

.paint .lock {
  position: absolute;
  inset: auto 0 2px 0;
  font-size: 10px;
  font-weight: 900;
  color: #d9cfbd;
}

.paint:focus-visible {
  outline: 3px solid #c6f432;
  outline-offset: 3px;
}

@media (max-height: 430px) {
  .paints {
    display: none;
  }
  .card {
    gap: 6px;
    padding: 14px 22px;
  }
  .title {
    font-size: 36px;
  }
  .title.small {
    font-size: 30px;
  }
  .score-big strong {
    font-size: 38px;
  }
  .btn {
    min-height: 48px;
  }
}

/* ---------- Turbo Twist HUD layout ---------- */

.hud {
  right: 10px;
  justify-content: space-between;
  align-items: flex-start;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stack .chip {
  flex: 0 0 auto;
  min-width: 96px;
  padding: 5px 11px 6px;
}

.time-chip {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  min-width: 118px;
  align-items: center;
  padding: 6px 16px 8px;
  border-color: rgb(250 204 21 / 0.55);
}

.time-chip strong {
  font-size: clamp(30px, 7vmin, 46px);
  color: #facc15;
}

.time-chip.low {
  border-color: #fb7185;
  background: rgb(76 5 25 / 0.82);
  animation: pulse 0.5s ease-in-out infinite alternate;
}

.time-chip.low strong {
  color: #fb7185;
}

@keyframes pulse {
  from {
    transform: translateX(-50%) scale(1);
  }
  to {
    transform: translateX(-50%) scale(1.07);
  }
}

@media (prefers-reduced-motion: reduce) {
  .time-chip.low {
    animation: none;
  }
}

@media (max-width: 480px) {
  .stack .chip {
    flex: 0 0 auto;
    min-width: 84px;
  }
}

.score-big strong small {
  font-size: 0.45em;
  color: #e0d6c3;
}

.title {
  background: linear-gradient(90deg, #27d6c1, #a3e635 50%, #facc15);
  -webkit-background-clip: text;
  background-clip: text;
}
