:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --accent-2: #8a6bff;
  --secondary: #2a2b3d;
  --text: #fff;
  --muted: #aaadbe;
  --sun: #ffcf2e;
  --coral: #ff5a6a;
  --lime: #7be34a;
  --hud-h: 48px;
  --help-h: 22px;
  --controls-h: 0px;
  font-family:
    "Nunito",
    ui-rounded,
    "SF Pro Rounded",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-weight: 800;
}
* {
  box-sizing: border-box;
}
html,
body {
  width: 100%;
  min-width: 0;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
body {
  padding: 8px;
  background:
    radial-gradient(110% 70% at 50% 0%, #2c1d55 0%, rgba(15, 16, 32, 0) 62%),
    var(--bg);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
:focus-visible {
  outline: 3px solid #ffd84a;
  outline-offset: 2px;
}
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 5px;
  border-radius: 6px;
  background: var(--secondary);
  box-shadow: 0 2px 0 #121322;
  color: #fff;
  font: inherit;
  font-size: 0.9em;
  text-align: center;
}

.shell {
  width: min(1100px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

/* HUD */
.hud {
  width: 100%;
  min-height: var(--hud-h);
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 1 auto;
  min-width: 0;
}
.brand-icon {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  filter: drop-shadow(0 3px 6px rgba(255, 90, 106, 0.35));
}
.brand h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.02em;
  white-space: nowrap;
  background: linear-gradient(180deg, #fff3b0, var(--sun) 45%, #ff7a3d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 0 #6b2a3a);
}
.chips {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 8px 13px;
  border-radius: 999px;
  background: linear-gradient(180deg, #2a2b40, var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 #0a0b16;
}
.chip span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.chip strong {
  display: inline-block;
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.chip-time strong {
  min-width: 3.4em;
  color: #fff;
}
.chip-target strong {
  color: var(--sun);
}
.chip-stars {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  fill: url(#star-g);
  stroke: #a55a00;
  stroke-width: 1.4;
}
.chip-target[data-stars="2"] .chip-stars {
  fill: #d8dbe8;
  stroke: #6b6f86;
}
.chip-target[data-stars="1"] .chip-stars {
  fill: #e0915a;
  stroke: #7a3f1a;
}
.chip-target[data-stars="1"] strong {
  color: #ffb27a;
}
.chip-target[data-stars="2"] strong {
  color: #e9ecf5;
}
.chip.pop strong {
  animation: pop 0.35s cubic-bezier(0.3, 1.8, 0.5, 1);
}
.chip-time.bonus {
  animation: chip-flash 0.7s ease;
}
@keyframes pop {
  50% {
    transform: scale(1.35);
  }
}
@keyframes chip-flash {
  0%,
  40% {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.08),
      0 3px 0 #0a0b16,
      0 0 0 3px rgba(123, 227, 74, 0.8),
      0 0 18px rgba(123, 227, 74, 0.6);
  }
}
.hud-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}
.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 #15162a;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    background 0.12s ease;
}
.icon-btn:hover:not(:disabled) {
  background: #36374e;
}
.icon-btn:active:not(:disabled) {
  transform: translateY(2px) scale(0.96);
}
.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
#sound-btn .mute {
  display: none;
}
#sound-btn[aria-pressed="false"] .mute {
  display: inline;
}
#sound-btn[aria-pressed="false"] .wave {
  display: none;
}

/* Stage */
.stage {
  position: relative;
  width: 100%;
  height: clamp(
    250px,
    calc(
      100svh - 16px - var(--hud-h) - var(--help-h) - var(--controls-h) - 26px
    ),
    640px
  );
  max-height: 118vw;
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(180deg, #7fd3ff, #d7f4ff);
  box-shadow:
    0 0 0 3px #2a2b3d,
    0 14px 40px rgba(0, 0, 0, 0.45);
  isolation: isolate;
}
#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}
#canvas:focus-visible {
  box-shadow: inset 0 0 0 3px #ffd84a;
}
.progress {
  position: absolute;
  left: 50%;
  top: 10px;
  width: min(46%, 360px);
  height: 10px;
  transform: translateX(-50%);
  border-radius: 99px;
  background: rgba(15, 16, 32, 0.45);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  z-index: 2;
}
.progress-fill {
  position: absolute;
  inset: 2px auto 2px 2px;
  width: 0;
  max-width: calc(100% - 4px);
  border-radius: 99px;
  background: linear-gradient(90deg, #ffe066, #ff8a3d);
  box-shadow: 0 0 8px rgba(255, 200, 80, 0.7);
}
.progress-marks i {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 16px;
  margin-left: -2px;
  border-radius: 2px;
  background: #fff;
  opacity: 0.55;
}
.progress-marks i.on {
  background: #7be34a;
  opacity: 1;
}
.progress-marks i.goal {
  width: 8px;
  margin-left: -4px;
  background: repeating-linear-gradient(180deg, #fff 0 4px, #1a1b28 4px 8px);
  opacity: 1;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 14px;
  background: radial-gradient(
    90% 90% at 50% 40%,
    rgba(20, 16, 50, 0.45),
    rgba(10, 10, 24, 0.78)
  );
  overflow-y: auto;
  animation: fade-in 0.25s ease;
}
.overlay[hidden] {
  display: none;
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
.card {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 18px;
  border-radius: 26px;
  background: linear-gradient(180deg, #25264a, var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 6px 0 #0b0c18,
    0 20px 50px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: card-in 0.42s cubic-bezier(0.2, 1.5, 0.4, 1);
}
@keyframes card-in {
  from {
    transform: translateY(18px) scale(0.9);
    opacity: 0;
  }
}
.card-title {
  background: linear-gradient(
    180deg,
    rgba(37, 38, 74, 0.86),
    rgba(26, 27, 40, 0.92)
  );
  backdrop-filter: blur(4px);
}
.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.86;
  transform: rotate(-4deg);
  margin: 4px 0 6px;
}
.logo span {
  font-size: clamp(40px, 9vw, 62px);
  font-weight: 900;
  letter-spacing: -0.03em;
  -webkit-text-stroke: 2px #3a0d1c;
  paint-order: stroke fill;
}
.logo-moto {
  background: linear-gradient(180deg, #fff6b8 0%, #ffcf2e 48%, #ff8a1c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 #7a2b00);
}
.logo-stunt {
  margin-left: 0.7em;
  background: linear-gradient(180deg, #ffb3bd 0%, #ff4d5e 50%, #c3123a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 #5a0718);
}
.card-copy {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.35;
  max-width: 30ch;
}
.card-heading {
  margin: 0;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -0.02em;
}
.card-kicker {
  margin: 0;
  color: var(--sun);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.card-stars {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
.row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.pill {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: 0;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    filter 0.12s ease;
}
.pill svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.pill:active {
  transform: translateY(3px) scale(0.97);
}
.pill-primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    0 5px 0 #3a1fa8,
    0 10px 24px rgba(104, 66, 255, 0.45);
}
.pill-primary:hover {
  filter: brightness(1.08);
}
.pill-big {
  min-width: 200px;
  min-height: 56px;
  font-size: 22px;
  padding: 12px 30px;
}
.pill-big svg {
  width: 24px;
  height: 24px;
}
.pill-secondary {
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 4px 0 #15162a;
}
.pill-secondary:hover {
  background: #36374e;
}
.pill-next {
  background: linear-gradient(180deg, #95f05f, #3fb52e);
  color: #0f2a0a;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 4px 0 #1f6b16;
}
.pill-next:hover {
  filter: brightness(1.06);
}
.pill[hidden] {
  display: none;
}

/* Win */
.card-win {
  gap: 8px;
}
.win-stars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin: 2px 0 4px;
}
.big-star {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.big-star:nth-child(2) {
  width: 72px;
  height: 72px;
  transform: translateY(-8px);
}
.big-star svg {
  width: 100%;
  height: 100%;
  fill: #34365a;
  stroke: #23244a;
  stroke-width: 1.2;
}
.big-star.on svg {
  fill: url(#star-g);
  stroke: #a55a00;
  filter: drop-shadow(0 3px 0 #9a4a00)
    drop-shadow(0 0 12px rgba(255, 207, 46, 0.55));
  animation: star-pop 0.55s cubic-bezier(0.2, 1.8, 0.4, 1) both;
}
.big-star img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: grayscale(1) brightness(0.35);
}
.big-star.on img {
  filter: drop-shadow(0 3px 0 #9a4a00);
  animation: star-pop 0.55s cubic-bezier(0.2, 1.8, 0.4, 1) both;
}
@keyframes star-pop {
  0% {
    transform: scale(0) rotate(-60deg);
  }
  100% {
    transform: scale(1) rotate(0);
  }
}
.final {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
}
.final-col {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 6px;
  border-radius: 16px;
  background: var(--panel-2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.final-label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.final-value {
  font-size: 24px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.final-best {
  color: var(--sun);
}
.win-note {
  margin: 0;
  min-height: 1.2em;
  color: var(--muted);
  font-size: 14px;
}
.win-note b {
  color: #9dff6a;
}
.badge {
  margin: 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe066, #ffb02e);
  color: #3a2200;
  font-size: 13px;
  font-weight: 900;
  animation: star-pop 0.5s cubic-bezier(0.2, 1.8, 0.4, 1) both 0.9s;
}
.badge[hidden] {
  display: none;
}

/* Levels */
.card-levels {
  width: min(720px, 100%);
  gap: 10px;
  padding: 16px;
}
.levels-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
}
.levels-head h2 {
  flex: 1 1 auto;
  margin: 0;
  text-align: left;
  font-size: 22px;
  font-weight: 900;
}
.total-stars {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 16px;
}
.total-stars span {
  color: var(--muted);
  font-size: 13px;
}
.star-ico {
  width: 20px;
  height: 20px;
  fill: url(#star-g);
  stroke: #a55a00;
  stroke-width: 1.2;
}
.level-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}
.lvl {
  --c1: #6fdc5a;
  --c2: #2f9b3c;
  --c3: #1c5e25;
  position: relative;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, var(--c1), var(--c2));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 4px 0 var(--c3);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.lvl[data-theme="canyon"] {
  --c1: #ffb35a;
  --c2: #e0662b;
  --c3: #8a3412;
}
.lvl[data-theme="glacier"] {
  --c1: #8fdcff;
  --c2: #3c93e0;
  --c3: #1e4f8a;
}
.lvl[data-theme="volcano"] {
  --c1: #ff7a6a;
  --c2: #c02a4a;
  --c3: #5e0f26;
}
.lvl:hover:not(:disabled) {
  transform: translateY(-2px);
}
.lvl:active:not(:disabled) {
  transform: translateY(2px);
}
.lvl-num {
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}
.lvl-stars {
  display: flex;
  gap: 1px;
}
.lvl-stars svg {
  width: 14px;
  height: 14px;
  fill: rgba(0, 0, 0, 0.28);
}
.lvl-stars svg.on {
  fill: url(#star-g);
  stroke: #8a4a00;
  stroke-width: 1.4;
}
.lvl-best {
  font-size: 10px;
  opacity: 0.9;
  font-variant-numeric: tabular-nums;
}
.lvl:disabled {
  cursor: default;
  filter: grayscale(0.85) brightness(0.55);
}
.lvl .lock {
  width: 20px;
  height: 20px;
  fill: #fff;
  opacity: 0.85;
}
.lvl.current {
  outline: 3px solid #fff;
  outline-offset: 2px;
}
.garage-title {
  width: 100%;
  margin: 4px 0 0;
  text-align: left;
  font-size: 16px;
  font-weight: 900;
}
.garage-title span {
  margin-left: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.garage {
  width: 100%;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 8px;
}
.skin {
  flex: 0 0 auto;
  width: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px 6px;
  border: 0;
  border-radius: 16px;
  background: var(--panel-2);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 #0b0c18;
  cursor: pointer;
  font-size: 11px;
}
.skin canvas {
  width: 72px;
  height: 48px;
}
.skin[aria-checked="true"] {
  box-shadow:
    0 0 0 3px var(--accent-2),
    0 3px 0 #0b0c18;
  background: #2d2a55;
}
.skin:disabled {
  cursor: default;
  opacity: 0.55;
}
.skin-need {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--sun);
}
.skin-need svg {
  width: 11px;
  height: 11px;
  fill: var(--sun);
}

/* Hint */
.hint {
  position: absolute;
  left: 50%;
  bottom: 18%;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transform: translateX(-50%);
  pointer-events: none;
}
.hint[hidden] {
  display: none;
}
.hint-keys {
  display: flex;
  gap: 6px;
}
.key {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(180deg, #fff, #dfe2f0);
  color: #1a1b28;
  font-size: 22px;
  box-shadow:
    0 5px 0 #8b8fa8,
    0 10px 20px rgba(0, 0, 0, 0.35);
  animation: key-press 1.1s ease-in-out infinite;
}
.hint.lean .key {
  animation-duration: 1.4s;
}
.hint.lean .key:nth-child(2) {
  animation-delay: 0.7s;
}
@keyframes key-press {
  0%,
  100% {
    transform: translateY(0);
    box-shadow:
      0 5px 0 #8b8fa8,
      0 10px 20px rgba(0, 0, 0, 0.35);
  }
  45%,
  60% {
    transform: translateY(4px);
    box-shadow:
      0 1px 0 #8b8fa8,
      0 4px 10px rgba(0, 0, 0, 0.35);
  }
}
.hint-hand {
  display: none;
  width: 56px;
  height: 56px;
  animation: hand-tap 1.1s ease-in-out infinite;
}
.hint-text {
  margin: 0;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(15, 16, 32, 0.82);
  font-size: 16px;
  white-space: nowrap;
}
.hint-text b {
  color: var(--sun);
}
@keyframes hand-tap {
  0%,
  100% {
    transform: translate(0, 0) scale(1);
  }
  50% {
    transform: translate(0, 6px) scale(0.92);
  }
}

/* Touch controls */
.controls {
  display: none;
  width: 100%;
  align-items: stretch;
  justify-content: space-between;
  gap: 10px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.ctrl-group {
  display: flex;
  gap: 8px;
}
.ctrl {
  width: 70px;
  height: 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: linear-gradient(180deg, #34355a, #24253d);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.12),
    0 5px 0 #101122;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  touch-action: none;
  cursor: pointer;
  transition:
    transform 0.08s ease,
    box-shadow 0.08s ease;
}
.ctrl svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}
.ctrl-gas {
  width: 104px;
  background: linear-gradient(180deg, #95f05f, #3fb52e);
  color: #0f2a0a;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 5px 0 #1f6b16;
}
.ctrl-brake {
  background: linear-gradient(180deg, #ff7a8a, #d8304a);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.3),
    0 5px 0 #7a1224;
}
.ctrl.held {
  transform: translateY(4px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.12),
    0 1px 0 #101122;
  filter: brightness(1.15);
}
.help {
  margin: 0;
  min-height: var(--help-h);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

@media (hover: none), (pointer: coarse), (max-width: 720px) {
  :root {
    --controls-h: 80px;
  }
  .controls {
    display: flex;
  }
  .help {
    display: none;
  }
  :root {
    --help-h: 0px;
  }
  .hint-keys {
    display: none;
  }
  .hint-hand {
    display: block;
  }
}
@media (max-width: 720px) {
  .brand h1 {
    display: none;
  }
  .chip {
    padding: 7px 10px;
  }
  .chip span {
    display: none;
  }
  .level-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .card-levels {
    padding: 12px;
  }
}
@media (max-width: 380px) {
  body {
    padding: 6px;
  }
  .brand-icon {
    display: none;
  }
  .chip strong {
    font-size: 16px;
  }
  .icon-btn {
    width: 40px;
    height: 40px;
  }
  .ctrl {
    width: 60px;
  }
  .ctrl-gas {
    width: 84px;
  }
  .ctrl-group {
    gap: 6px;
  }
  .pill-big {
    min-width: 170px;
  }
}

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