/* EVOLVE DRIVE - friendly arcade look: cream cards, soft 3D pill buttons, rounded type,
   short springy motion that gives feedback (press, pop, settle) rather than decoration. */
:root {
  --ink: #1f2344;
  --ink-soft: #5a5f86;
  --cream: #fffaf0;
  --cream-2: #f3ecdf;
  --line: #e4dccb;
  --green: #45d46d;
  --green-2: #27b152;
  --green-edge: #17823a;
  --yellow: #ffd23f;
  --yellow-2: #f7a928;
  --yellow-edge: #b36f07;
  --blue: #52b4ff;
  --blue-2: #2d86ea;
  --blue-edge: #1b5bb0;
  --red: #ff6464;
  --red-2: #e84646;
  --red-edge: #a8262a;
  --glass: rgba(255, 255, 255, 0.92);
  --radius: 22px;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font: ui-rounded, 'SF Pro Rounded', 'Nunito', 'Varela Round', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #52b9f5;
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-touch-callout: none;
}

button { font: inherit; color: inherit; }
kbd {
  font-family: var(--font);
  font-size: 0.8em;
  font-weight: 900;
  padding: 0 6px;
  border-radius: 6px;
  background: rgba(31, 35, 68, 0.1);
  box-shadow: inset 0 -2px 0 rgba(31, 35, 68, 0.18);
}
[hidden] { display: none !important; }

#app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
}
#app > * { min-width: 0; }

.stage {
  position: relative;
  overflow: hidden;
  min-height: 0;
  background: #52b9f5;
}
#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
}

/* ---------------------------------------------------------------- Buttons: soft 3D pills */
.btn {
  --face: #ffffff;
  --face-2: #f1ece2;
  --edge: #cfc5b3;
  --text: var(--ink);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--face), var(--face-2));
  box-shadow: 0 5px 0 var(--edge), 0 9px 18px rgba(20, 24, 50, 0.18), inset 0 2px 0 rgba(255, 255, 255, 0.55);
  color: var(--text);
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 140ms var(--spring), box-shadow 120ms ease, filter 150ms ease;
}
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.btn:active:not(:disabled) {
  transform: translateY(4px) scale(0.97);
  box-shadow: 0 1px 0 var(--edge), 0 3px 8px rgba(20, 24, 50, 0.16), inset 0 2px 0 rgba(255, 255, 255, 0.4);
  transition-duration: 70ms;
}
.btn:focus-visible, .icon-btn:focus-visible, .round-btn:focus-visible, .part-card:focus-visible, .tab:focus-visible { outline: 3px solid var(--blue-2); outline-offset: 3px; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { transform: translateY(-2px) scale(1.03); filter: brightness(1.05); }
  .btn:active:not(:disabled) { transform: translateY(4px) scale(0.97); }
}
.btn-play { --face: #178040; --face-2: #126b35; --edge: var(--green-edge); --text: #ffffff; text-shadow: 0 2px 0 rgba(0, 80, 30, 0.35); }
.btn-garage { --face: #1f6fd0; --face-2: #1b5bb0; --edge: #14428a; --text: #ffffff; text-shadow: 0 2px 0 rgba(10, 40, 90, 0.35); }
.btn-evolve { --face: #ffe27a; --face-2: var(--yellow-2); --edge: var(--yellow-edge); --text: #3a2600; }
.btn-test { --face: #c75c10; --face-2: #a84c08; --edge: #7a3605; --text: #ffffff; text-shadow: 0 2px 0 rgba(110, 40, 0, 0.35); }
.btn-quiet { --face: #ffffff; --face-2: #f4efe6; --edge: #d8cfbe; --text: var(--ink-soft); font-size: 14px; }
.btn-danger { --face: #b82c2c; --face-2: #a8262a; --edge: var(--red-edge); --text: #ffffff; }
.btn-danger:disabled { filter: grayscale(0.7) opacity(0.6); cursor: not-allowed; }
.btn-danger-ghost { background: transparent; box-shadow: none; color: #a8262a; border: 2px dashed rgba(168, 38, 42, 0.5); font-size: 13px; min-height: 44px; } /* 5.2:1 on the cream card */
.btn.is-locked { filter: saturate(0.35) brightness(0.96); }
.btn.bought { animation: bought 0.42s var(--spring); }
.btn.denied { animation: shake 0.3s linear; }

.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 16px;
  background: var(--glass);
  box-shadow: 0 4px 0 rgba(31, 35, 68, 0.18), 0 6px 14px rgba(20, 24, 50, 0.14);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: transform 140ms var(--spring), box-shadow 100ms ease;
}
.icon-btn:active { transform: translateY(3px) scale(0.92); box-shadow: 0 1px 0 rgba(31, 35, 68, 0.18); transition-duration: 70ms; }
@media (hover: hover) and (pointer: fine) { .icon-btn:hover { transform: scale(1.06); } }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .ico-speaker { fill: var(--ink); }
.icon-btn .ico-mute { display: none; stroke: var(--red-2); }
.icon-btn.is-muted .ico-waves { display: none; }
.icon-btn.is-muted .ico-mute { display: inline; }

.round-btn {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffffff, #efe8dc);
  box-shadow: 0 4px 0 #cfc5b3, 0 6px 12px rgba(20, 24, 50, 0.16);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 140ms var(--spring), box-shadow 100ms ease, opacity 150ms;
}
.round-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.round-btn:active:not(:disabled) { transform: translateY(3px) scale(0.92); box-shadow: 0 1px 0 #cfc5b3; }
.round-btn:disabled { opacity: 0.35; cursor: default; }

/* ---------------------------------------------------------------- HUD */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  padding: max(8px, var(--safe-top)) 10px 0;
  pointer-events: none;
}
.hud-left { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; }
.hud-actions { display: flex; gap: 6px; pointer-events: auto; }
.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 4px 14px 4px 8px;
  border-radius: 999px;
  background: var(--glass);
  box-shadow: 0 4px 0 rgba(31, 35, 68, 0.16), 0 6px 14px rgba(20, 24, 50, 0.12);
}
.stat-value { font-size: 19px; font-weight: 900; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.1; color: var(--ink); }
.coin-ico {
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #fff4b0 0 18%, #ffd43b 19% 58%, #e39a00 60%);
  box-shadow: inset 0 -2px 0 rgba(150, 90, 0, 0.35);
}
.stat-money .stat-value { color: #a35f00; font-size: 20px; } /* 4.9:1 on the white pill */
.stat-money.bump .coin-ico, .stat-value.bump { animation: bump 0.16s ease-out; }
.fuel { min-height: 32px; padding: 4px 10px 4px 8px; width: min(190px, 44vw); }
.fuel svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--green-2); stroke-width: 2.4; stroke-linejoin: round; }
.fuel-track { flex: 1; height: 12px; border-radius: 999px; background: #e7e1d4; overflow: hidden; box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.1); }
.fuel-fill { height: 100%; width: 100%; background: linear-gradient(#7cf29d, #2fbf5a); transform-origin: left center; border-radius: 999px; }
.fuel.is-mid .fuel-fill { background: linear-gradient(#ffe27a, #f7a928); }
.fuel.is-mid svg { stroke: var(--yellow-2); }
.fuel.is-low .fuel-fill { background: linear-gradient(#ff9d9d, #f04b4b); }
/* Pulsing animations only change transform or opacity, so they never repaint the HUD every frame. */
.fuel.is-low { animation: pulse-soft 0.9s ease-in-out infinite; box-shadow: 0 4px 0 rgba(232, 70, 70, 0.4), 0 0 0 4px rgba(255, 100, 100, 0.3); }
.fuel.is-low svg { stroke: var(--red-2); }

.stat-progress {
  justify-self: center;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  width: min(360px, 100%);
  padding: 5px 14px 7px;
  border-radius: 20px;
  min-width: 0;
}
.progress-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.stage-chip { padding: 1px 8px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 12px; font-weight: 900; letter-spacing: 0.04em; white-space: nowrap; }
.stat-progress .stat-value { font-size: 17px; }
.stat-speed { margin-left: auto; font-size: 13px; font-weight: 800; color: var(--ink-soft); white-space: nowrap; font-variant-numeric: tabular-nums; }
.progress-track { position: relative; height: 10px; border-radius: 999px; background: #e7e1d4; box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.1); }
.progress-fill { height: 100%; width: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--blue), var(--green)); transform-origin: left center; transform: scaleX(0); }
.flag-ico {
  position: absolute;
  right: -4px;
  top: -8px;
  width: 16px;
  height: 22px;
  background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 22'%3E%3Cpath d='M3 1v20' stroke='%231f2344' stroke-width='2.4' stroke-linecap='round'/%3E%3Cpath d='M4 2h10v8H4z' fill='%23fff'/%3E%3Cpath d='M4 2h3.3v2.7H4zM10.6 2H14v2.7h-3.4zM7.3 4.7h3.3v2.6H7.3zM4 7.3h3.3V10H4zM10.6 7.3H14V10h-3.4z' fill='%231f2344'/%3E%3C/svg%3E");
}

/* The start screen shows only money and buttons: run progress and fuel appear once driving. */
#app[data-phase='ready'] .stat-progress,
#app[data-phase='ready'] .fuel,
#app[data-phase='ready'] .boost,
#app[data-phase='ready'] .speedo,
#app[data-phase='ready'] .combo,
#app[data-phase='evolving'] .stat-progress,
#app[data-phase='evolving'] .speedo,
#app[data-phase='evolving'] .boost { visibility: hidden; }

/* Test drive tag + back button */
.btn-back {
  position: absolute;
  z-index: 9;
  left: 50%;
  top: calc(var(--hud-h, 60px) + 8px);
  transform: translateX(-50%);
  --face: #c75c10; --face-2: #a84c08; --edge: #7a3605; --text: #fff;
  min-height: 44px;
  font-size: 14px;
}
.btn-back:active { transform: translateX(-50%) translateY(4px) scale(0.97); }
@media (hover: hover) and (pointer: fine) { .btn-back:hover { transform: translateX(-50%) translateY(-2px) scale(1.03); } }
.test-tag {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 132, 64, 0.9);
  color: #fff;
  font-weight: 900;
  font-size: 12px;
  letter-spacing: 0.1em;
  pointer-events: none;
}

/* ---------------------------------------------------------------- Touch pads */
.pad {
  --size: clamp(76px, 21vmin, 116px);
  position: absolute;
  z-index: 4;
  bottom: calc(18px + var(--safe-bottom));
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0;
  background: rgba(255, 255, 255, 0.26);
  border: 3px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.12), inset 0 -4px 0 rgba(0, 0, 0, 0.08);
  color: #ffffff;
  pointer-events: none;
  transition: transform 90ms var(--spring), background 90ms ease, box-shadow 90ms ease;
}
.pad svg { width: 44%; height: 44%; fill: none; stroke: #ffffff; stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.25)); }
.pad span { font-size: 11px; font-weight: 900; letter-spacing: 0.1em; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45); margin-top: -2px; }
.pad-brake { left: calc(16px + env(safe-area-inset-left, 0px)); }
.pad-gas { right: calc(16px + env(safe-area-inset-right, 0px)); }
.pad.is-down { transform: scale(0.9); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12); }
.pad-gas.is-down { background: rgba(69, 212, 109, 0.62); border-color: #d6ffe0; }
.pad-brake.is-down { background: rgba(255, 100, 100, 0.62); border-color: #ffe0e0; }
@media (hover: hover) and (pointer: fine) {
  .pad { --size: 72px; opacity: 0.85; }
}

/* ---------------------------------------------------------------- Start screen */
.start {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: calc(var(--hud-h, 60px) + 4px) 14px calc(16px + var(--safe-bottom));
  pointer-events: none;
  text-align: center;
}
.start > * { pointer-events: none; }
.start button { pointer-events: auto; }
.start-top, .start-bottom { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.logo {
  margin: 0;
  font-size: clamp(34px, 11vw, 64px);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 0.02em;
  color: #ffffff;
  text-shadow: 0 4px 0 #1f2344, 0 8px 18px rgba(20, 24, 50, 0.3);
  -webkit-text-stroke: 2px #1f2344;
  animation: logo-in 0.5s var(--spring) both;
}
.logo span { display: block; color: var(--yellow); font-size: 0.72em; letter-spacing: 0.18em; }
.stage-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 4px 0 rgba(31, 35, 68, 0.12);
  animation: rise 0.4s var(--spring) 0.08s both;
}
.stage-info { display: flex; flex-direction: column; min-width: 128px; line-height: 1.15; }
.stage-world { font-size: 12px; font-weight: 900; letter-spacing: 0.14em; color: var(--ink-soft); }
.stage-name { font-size: 20px; font-weight: 900; color: var(--ink); }
.stage-theme { font-size: 11px; font-weight: 900; letter-spacing: 0.1em; color: #8a5100; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.start-vehicle { font-size: 14px; font-weight: 800; color: #fff; text-shadow: 0 2px 0 rgba(20, 24, 50, 0.45); }
.start-vehicle b { font-size: 18px; }
.btn-play#btn-start { min-width: min(280px, 80vw); min-height: 64px; font-size: 26px; animation: breathe 1.6s ease-in-out infinite; }
.start-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.start-actions .btn { min-height: 52px; font-size: 15px; white-space: nowrap; }
.btn-evolve .shop-cost { padding: 2px 9px; border-radius: 999px; background: rgba(255, 255, 255, 0.55); font-size: 14px; font-variant-numeric: tabular-nums; }
/* The glow ring fades in and out (opacity only, so the start screen does not repaint every frame). */
.btn-evolve.is-affordable::after { content: ''; position: absolute; inset: -5px; border-radius: inherit; box-shadow: 0 0 0 5px rgba(255, 210, 63, 0.45), 0 0 22px rgba(255, 210, 63, 0.7); opacity: 0; animation: glow 1.2s ease-in-out infinite; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .btn-evolve.is-affordable::after { animation: none; opacity: 0.7; } }
.btn-evolve.is-maxed { filter: saturate(0.3); }
.dot {
  position: absolute;
  top: 5px;
  right: 7px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--red-2);
  border: 3px solid #fff;
  animation: pop 0.35s var(--spring) both;
}
.start-hint { margin: 0; font-size: 13px; font-weight: 800; color: #ffffff; text-shadow: 0 2px 0 rgba(20, 24, 50, 0.45); }
.start-hint kbd { color: var(--ink); background: rgba(255, 255, 255, 0.85); }

.hint-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .hint-keys { display: none; }
  .hint-touch { display: inline; }
}

/* ---------------------------------------------------------------- Coaching */
.coach {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: calc(var(--hud-h, 60px) + 14px);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 9px 18px;
  border-radius: 999px;
  background: linear-gradient(#fff3a8, var(--yellow));
  color: #3a2800;
  font-size: 16px;
  font-weight: 900;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 5px 0 var(--yellow-edge), 0 8px 18px rgba(0, 0, 0, 0.2);
  animation: pop 0.3s var(--spring);
}
.coach kbd { background: rgba(255, 255, 255, 0.6); }
.coach-fuel { background: linear-gradient(#b5530e, #9a4407); box-shadow: 0 5px 0 #7a3605; color: #fff; }

/* ---------------------------------------------------------------- World banner */
.world-banner {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 34px 14px;
  border-radius: 28px;
  background: var(--cream);
  box-shadow: 0 7px 0 rgba(31, 35, 68, 0.2), 0 16px 40px rgba(20, 24, 50, 0.3);
  pointer-events: none;
  animation: banner 1.25s ease-in-out both;
}
.world-banner.is-final { animation-duration: 3.4s; max-width: calc(100% - 32px); }
.world-banner.is-final .world-name { font-size: clamp(26px, 7vw, 44px); text-align: center; white-space: nowrap; }
.world-kicker { font-size: 12px; font-weight: 900; letter-spacing: 0.24em; color: var(--blue-2); }
.world-name { font-size: clamp(30px, 8vw, 52px); font-weight: 900; line-height: 1; color: var(--ink); }
.world-stage { font-size: 13px; font-weight: 900; color: var(--ink-soft); letter-spacing: 0.1em; text-align: center; }

/* ---------------------------------------------------------------- Cards */
.stage.has-dialog::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(20, 24, 50, 0.5);
  z-index: 10;
}
.card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100% - 24px));
  max-height: calc(100% - 20px);
  overflow-y: auto;
  padding: 18px 18px 16px;
  border-radius: 28px;
  background: var(--cream);
  box-shadow: 0 8px 0 rgba(31, 35, 68, 0.22), 0 18px 44px rgba(20, 24, 50, 0.35);
  text-align: center;
  animation: card-in 0.3s var(--spring);
  z-index: 9;
}
.card.menu, .card.confirm { z-index: 11; }
.card-title { margin: 0 0 8px; font-size: 26px; font-weight: 900; letter-spacing: 0.04em; color: var(--ink); }
.card-title.danger { color: var(--red-2); font-size: 22px; }
.gameover.is-crash .card-title { color: var(--red-2); }

.go-distance { position: relative; display: flex; flex-direction: column; align-items: center; margin-bottom: 8px; }
.go-label { font-size: 12px; font-weight: 900; letter-spacing: 0.18em; color: var(--ink-soft); }
.go-distance b { font-size: 50px; line-height: 1; font-weight: 900; color: var(--ink); font-variant-numeric: tabular-nums; animation: settle 0.45s var(--spring) 0.1s both; }
.new-best {
  margin-top: 6px;
  padding: 3px 12px;
  border-radius: 999px;
  background: linear-gradient(#fff3a8, var(--yellow));
  box-shadow: 0 3px 0 var(--yellow-edge);
  color: #3a2800;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.1em;
  animation: pop 0.45s var(--spring) 0.25s both;
}
.go-chips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
.go-chip { display: flex; flex-direction: column; align-items: center; padding: 6px 4px; border-radius: 16px; background: var(--cream-2); min-width: 0; }
.go-chip span { font-size: 10px; font-weight: 900; letter-spacing: 0.12em; color: var(--ink-soft); }
.go-chip b { font-size: 17px; font-weight: 900; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.go-progress { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 12px; font-weight: 900; color: var(--ink-soft); }
.go-progress .progress-fill { transition: transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1); }
.gameover .btn-play { width: 100%; min-height: 60px; font-size: 24px; }
.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.card-actions.stacked { grid-template-columns: 1fr; }
.card-hint { margin: 10px 0 0; font-size: 13px; color: #9a5b00; font-weight: 900; min-height: 1em; } /* 5.2:1 on cream */
.goal-meter { height: 8px; max-width: 220px; margin: 6px auto 0; border-radius: 999px; background: #e7e1d4; overflow: hidden; }
.goal-meter i { display: block; height: 100%; background: linear-gradient(90deg, #ffe27a, var(--yellow-2)); transform-origin: left center; transform: scaleX(0); transition: transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1); }
.results { margin: 0 0 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.results div { display: flex; flex-direction: column; align-items: center; padding: 8px 6px; border-radius: 16px; background: var(--cream-2); }
.results dt { color: var(--ink-soft); font-size: 11px; font-weight: 900; letter-spacing: 0.08em; text-transform: uppercase; }
.results dd { margin: 0; font-weight: 900; font-size: 18px; font-variant-numeric: tabular-nums; }
.confirm-text { color: var(--ink-soft); font-size: 14px; line-height: 1.45; margin: 6px 0 14px; font-weight: 700; }

/* ---------------------------------------------------------------- Evolution banner */
.evolve-banner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: calc(var(--hud-h, 0px) + 3%) 12px 4%;
  pointer-events: none;
  text-align: center;
  z-index: 7;
}
.evolve-title {
  font-size: clamp(36px, 10vw, 66px);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--yellow);
  -webkit-text-stroke: 2px #6b3b00;
  text-shadow: 0 5px 0 #6b3b00, 0 10px 26px rgba(0, 0, 0, 0.4);
}
.evolve-name { font-size: clamp(22px, 5.5vw, 32px); font-weight: 900; margin-top: 2px; color: #fff; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.4); }
.evolve-kind { font-size: 13px; color: #e8ecff; font-weight: 900; text-transform: uppercase; letter-spacing: 0.1em; }
.evolve-banner > .evolve-stats { margin-top: auto; }
.evolve-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 520px; }
.evolve-stats span { padding: 6px 13px; border-radius: 999px; background: linear-gradient(#8cf0a8, var(--green-2)); box-shadow: 0 3px 0 var(--green-edge); color: #fff; font-size: 13px; font-weight: 900; text-shadow: 0 1px 0 rgba(0, 60, 20, 0.35); }
.evolve-banner.show .evolve-title { animation: slam 0.45s var(--spring); }
.evolve-banner.show .evolve-name, .evolve-banner.show .evolve-kind { animation: rise 0.35s var(--spring) 0.1s both; }
.evolve-banner.show .evolve-stats span { animation: rise 0.35s var(--spring) both; }
.evolve-banner.show .evolve-stats span:nth-child(2) { animation-delay: 0.08s; }
.evolve-banner.show .evolve-stats span:nth-child(3) { animation-delay: 0.16s; }

/* ---------------------------------------------------------------- Garage */
.garage {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: var(--cream);
  animation: garage-in 0.28s var(--spring);
}
.garage-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(10px, var(--safe-top)) 12px 8px;
}
.garage-head h2 { margin: 0; font-size: 24px; font-weight: 900; letter-spacing: 0.06em; }
.garage-money { margin-left: auto; box-shadow: none; background: var(--cream-2); min-height: 40px; }
.garage-money b { font-size: 18px; color: #c77800; font-variant-numeric: tabular-nums; }
.garage-close { background: var(--cream-2); box-shadow: 0 3px 0 var(--line); }
.garage-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(120px, 1fr) auto auto auto auto auto;
  gap: 10px;
  padding: 0 12px 10px;
  overflow-y: auto;
}
.garage-preview {
  position: relative;
  min-height: 120px;
  border-radius: 24px;
  background: radial-gradient(ellipse at 50% 85%, #d7f0ff 0 30%, #9fd6fb 70%);
  overflow: hidden;
}
#garage-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.garage-vehicle { position: absolute; left: 12px; top: 8px; display: flex; flex-direction: column; line-height: 1.1; text-align: left; }
.garage-vehicle span { font-size: 11px; font-weight: 900; letter-spacing: 0.12em; color: var(--blue-edge); }
.garage-vehicle b { font-size: 18px; font-weight: 900; }
.garage-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; }
.gstat { display: grid; grid-template-columns: 76px minmax(0, 1fr); align-items: center; gap: 8px; font-size: 11px; font-weight: 900; letter-spacing: 0.06em; color: var(--ink-soft); }
.gbar { position: relative; height: 12px; border-radius: 999px; background: #e7e1d4; overflow: hidden; }
.gbar i { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 999px; transition: width 220ms var(--spring), left 220ms var(--spring); }
.gbar .fill { background: linear-gradient(90deg, var(--blue), var(--blue-2)); }
.gbar .up { background: repeating-linear-gradient(45deg, #45d46d 0 5px, #7ae497 5px 10px); }
.gbar .down { background: repeating-linear-gradient(45deg, #ff6464 0 5px, #ff9a9a 5px 10px); }
.garage-tabs { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  padding: 4px 2px;
  border: 0;
  border-radius: 18px;
  background: var(--cream-2);
  box-shadow: 0 3px 0 var(--line);
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 140ms var(--spring), background 120ms;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.tab:active { transform: scale(0.93); }
.tab.is-active { background: var(--ink); color: #ffffff; box-shadow: 0 3px 0 #0e1130; }
.tab .tab-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green-2); }
.garage-parts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.part-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  min-height: 96px;
  padding: 8px 8px 8px;
  border: 3px solid transparent;
  border-radius: 20px;
  background: #ffffff;
  box-shadow: 0 4px 0 var(--line);
  text-align: left;
  cursor: pointer;
  transition: transform 140ms var(--spring), border-color 120ms;
}
.part-card:active { transform: scale(0.96); }
.part-card.is-selected { border-color: var(--blue-2); }
.part-card.is-equipped { background: #eafbef; box-shadow: 0 4px 0 #bfe8cb; }
.part-name { font-size: 13px; font-weight: 900; line-height: 1.15; color: var(--ink); overflow-wrap: anywhere; }
.part-tags { display: flex; flex-wrap: wrap; gap: 3px; }
.part-tags span { font-size: 10px; font-weight: 900; padding: 0 5px; border-radius: 6px; line-height: 16px; white-space: nowrap; }
.part-tags .plus { background: #dcf7e3; color: #17823a; }
.part-tags .minus { background: #ffe3e3; color: #b3262a; }
.part-state { margin-top: auto; align-self: flex-start; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 900; background: var(--cream-2); color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.part-card.is-equipped .part-state { background: var(--green-2); color: #fff; }
.part-card.is-locked .part-state { color: #b3262a; }
.part-card.is-affordable:not(.is-equipped) .part-state { background: var(--yellow); color: #3a2600; }
.btn-level { width: 100%; justify-content: space-between; min-height: 52px; font-size: 14px; --face: #ffe27a; --face-2: var(--yellow-2); --edge: var(--yellow-edge); --text: #3a2600; }
.btn-level .shop-level { font-size: 12px; opacity: 0.8; }
.btn-level .shop-cost { padding: 2px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.6); font-variant-numeric: tabular-nums; }
.btn-level.is-maxed { filter: saturate(0.2); }
.garage-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 8px 12px calc(12px + var(--safe-bottom)); background: var(--cream); box-shadow: 0 -6px 16px rgba(20, 24, 50, 0.06); }
.garage-foot .btn { min-height: 56px; font-size: 18px; }

/* ---------------------------------------------------------------- Toasts */
.toast-layer {
  position: absolute;
  left: 50%;
  top: calc(var(--hud-h, 60px) + 50px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: calc(100% - 24px);
  pointer-events: none;
  z-index: 12;
}
.toast {
  max-width: 100%;
  padding: 8px 16px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 4px 0 rgba(31, 35, 68, 0.16), 0 8px 18px rgba(20, 24, 50, 0.18);
  font-size: 14px;
  font-weight: 900;
  text-align: center;
  animation: toast 2.2s var(--spring) forwards;
}
/* A coaching tip sits where toasts start: stack the toasts below it instead of on top of it. */
.coach:not([hidden]) ~ .toast-layer { top: calc(var(--hud-h, 60px) + 84px); }
/* In the garage, notices appear above the footer instead of over the car and parts. */
.garage:not([hidden]) ~ .toast-layer { top: auto; bottom: calc(96px + var(--safe-bottom)); }
.toast-good { color: var(--green-edge); }
.toast-bad { color: var(--red-2); }
.toast-info { color: #b36f07; }
.toast-big { font-size: 18px; padding: 10px 20px; background: linear-gradient(#fff3a8, var(--yellow)); color: #3a2600; box-shadow: 0 5px 0 var(--yellow-edge); }

/* ---------------------------------------------------------------- Narrow phones */
@media (max-width: 560px) {
  .hud { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .pill { min-height: 36px; padding: 3px 11px 3px 6px; }
  .stat-money .stat-value { font-size: 17px; }
  .coin-ico { width: 20px; height: 20px; }
  .stat-progress { padding: 4px 10px 6px; }
  .stat-progress .stat-value { font-size: 15px; }
  .stat-speed { display: none; }
  .fuel { width: min(150px, 38vw); min-height: 28px; }
  .icon-btn { width: 44px; height: 44px; border-radius: 14px; }
  .gstat { grid-template-columns: 62px minmax(0, 1fr); font-size: 10px; }
  .garage-stats { gap: 5px 10px; }
  .part-name { font-size: 12px; }
}
@media (max-width: 360px) {
  .hud { grid-template-columns: auto minmax(0, 1fr) auto; }
  .hud-actions { gap: 4px; }
  .stage-chip { font-size: 11px; padding: 1px 6px; }
  .go-distance b { font-size: 42px; }
  .garage-tabs { gap: 4px; }
  .tab { font-size: 10px; }
  .tab svg { width: 20px; height: 20px; }
  .garage-parts { gap: 5px; }
  .part-card { padding: 6px 5px; }
  .part-tags span { font-size: 10px; padding: 0 3px; }
  .stage-info { min-width: 110px; }
}

/* ---------------------------------------------------------------- Short portrait phones */
@media (max-height: 640px) and (orientation: portrait) {
  .logo { font-size: clamp(30px, 10vw, 44px); }
  .start-top, .start-bottom { gap: 7px; }
  .btn-play#btn-start { min-height: 56px; font-size: 22px; }
  .card { padding: 14px 14px 12px; }
  .card-title { font-size: 22px; margin-bottom: 4px; }
  .go-distance b { font-size: 40px; }
  .go-chips { margin-bottom: 8px; }
  .go-progress { margin-bottom: 8px; }
  .gameover .btn-play { min-height: 52px; font-size: 20px; }
  .card-actions { margin-top: 8px; }
  .garage-body { gap: 6px; grid-template-rows: minmax(84px, 1fr) auto auto auto auto auto; }
  .garage-preview { min-height: 90px; }
  .tab { min-height: 50px; }
  .part-card { min-height: 84px; }
}

/* ---------------------------------------------------------------- Short landscape phones */
@media (max-height: 480px) and (orientation: landscape) {
  .hud { padding-top: max(6px, var(--safe-top)); }
  .pill { min-height: 34px; }
  .fuel { min-height: 26px; }
  .stat-progress { width: min(300px, 100%); }
  .logo { font-size: 34px; }
  .logo span { display: inline; font-size: 0.72em; margin-left: 6px; }
  .start { flex-direction: row; align-items: flex-end; justify-content: space-between; padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px)); }
  .start-top { align-items: flex-start; width: auto; align-self: stretch; justify-content: flex-start; }
  .start-bottom { width: auto; align-items: flex-end; gap: 8px; }
  .start-hint { display: none; }
  .btn-play#btn-start { min-width: 220px; min-height: 54px; font-size: 22px; }
  .start-actions .btn { min-height: 46px; font-size: 13px; }
  .stage-name { font-size: 17px; }
  .round-btn { width: 44px; height: 44px; }
  .coach { top: auto; bottom: 14px; font-size: 14px; padding: 7px 14px; }
  .coach:not([hidden]) ~ .toast-layer { top: calc(var(--hud-h, 60px) + 50px); }
  .card { padding: 10px 14px; width: min(520px, calc(100% - 24px)); }
  .card-title { font-size: 20px; margin-bottom: 2px; }
  .gameover { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 14px; align-items: center; }
  .gameover .card-title, .gameover .card-hint, .gameover .goal-meter { grid-column: 1 / -1; }
  .go-distance { margin-bottom: 4px; }
  .go-distance b { font-size: 36px; }
  .go-chips { grid-column: 2; grid-row: 2; margin-bottom: 0; }
  .go-progress { grid-column: 1 / -1; margin: 6px 0; }
  .gameover .btn-play { min-height: 48px; font-size: 20px; }
  .gameover .card-actions { margin-top: 0; }
  .card-hint { margin-top: 4px; font-size: 12px; }
  .results { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 8px; }
  .card-actions.stacked { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .btn { min-height: 44px; font-size: 13px; padding: 6px 12px; }
  .world-banner { top: 36%; padding: 8px 26px 10px; }
  .evolve-banner { padding-top: calc(var(--hud-h, 0px) + 1%); padding-bottom: 2%; }
  .evolve-title { font-size: 34px; }
  .evolve-name { font-size: 20px; }
  .evolve-stats span { font-size: 12px; padding: 3px 9px; }
  .garage-head { padding-top: max(6px, var(--safe-top)); padding-bottom: 4px; }
  .garage-head h2 { font-size: 20px; }
  .garage-body {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    grid-template-rows: minmax(0, 1fr) auto auto auto;
    grid-template-areas: 'preview parts' 'preview presets' 'stats tabs' 'stats level';
    gap: 6px 12px;
    padding-bottom: 6px;
  }
  .garage-preview { grid-area: preview; min-height: 80px; }
  .garage-stats { grid-area: stats; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 10px; align-content: start; }
  .garage-tabs { grid-area: tabs; }
  .garage-parts { grid-area: parts; align-self: start; }
  .garage-presets { grid-area: presets; }
  .btn-level { grid-area: level; min-height: 44px; }
  .tab { min-height: 46px; font-size: 10px; }
  .tab svg { width: 18px; height: 18px; }
  .part-card { min-height: 0; padding: 6px; }
  .part-tags span { font-size: 10px; }
  .garage-foot { padding-top: 4px; padding-bottom: calc(6px + var(--safe-bottom)); }
  .garage-foot .btn { min-height: 44px; font-size: 15px; }
  /* No room above the footer here: notices sit over the garage title row instead of the upgrade button. */
  .garage:not([hidden]) ~ .toast-layer { top: max(6px, var(--safe-top)); bottom: auto; }
  .pad { --size: clamp(64px, 20vmin, 86px); bottom: calc(12px + var(--safe-bottom)); }
}
@media (max-height: 340px) and (orientation: landscape) {
  .logo { font-size: 28px; }
  .stage-picker { padding: 4px; gap: 6px; }
  .stage-info { min-width: 100px; }
  .btn-play#btn-start { min-width: 180px; min-height: 48px; font-size: 20px; }
  .start-vehicle { display: none; }
  .go-distance b { font-size: 30px; }
  .go-chip b { font-size: 14px; }
  .gameover .card-hint { display: none; }
  .go-cause { margin: -6px 0 0; font-size: 11px; }
  .go-tip { margin: 0; font-size: 11px; }
  .garage-stats .gstat { grid-template-columns: 58px minmax(0, 1fr); }
  .garage-tabs { gap: 3px; }
  .garage-parts .part-tags { display: none; }
  .part-card { min-height: 44px; }
}

/* ---------------------------------------------------------------- Desktop */
@media (min-width: 900px) {
  .hud { padding-left: 16px; padding-right: 16px; }
  .pill { min-height: 44px; }
  .stat-value { font-size: 20px; }
  .stat-money .stat-value { font-size: 22px; }
}
/* Wide and tall enough for the big side-by-side garage; short landscape phones keep their own grid. */
@media (min-width: 900px) and (min-height: 481px) {
  .garage-body {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    grid-template-rows: auto auto auto auto auto;
    grid-template-areas: 'preview tabs' 'preview parts' 'preview level' 'presets presets' 'stats stats';
    align-content: start;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    gap: 12px 20px;
  }
  .garage-preview { grid-area: preview; min-height: 320px; }
  .garage-stats { grid-area: stats; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .garage-tabs { grid-area: tabs; }
  .garage-parts { grid-area: parts; }
  .garage-presets { grid-area: presets; }
  .btn-level { grid-area: level; }
  .garage-foot { max-width: 1100px; width: 100%; margin: 0 auto; }
  .part-card { min-height: 120px; }
}

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

/* ---------------------------------------------------------------- Keyframes */
@keyframes bump { 50% { transform: scale(1.25); } }
@keyframes pop { 0% { transform: scale(0.4); opacity: 0; } 70% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1); } }
@keyframes breathe { 50% { transform: scale(1.04); } }
@keyframes card-in { from { opacity: 0; transform: translate(-50%, -42%) scale(0.92); } to { opacity: 1; transform: translate(-50%, -50%); } }
@keyframes garage-in { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@keyframes settle { 0% { transform: scale(1.35); opacity: 0; } 60% { transform: scale(0.95); opacity: 1; } 100% { transform: scale(1); } }
@keyframes slam { 0% { transform: scale(2.4); opacity: 0; } 60% { transform: scale(0.92); opacity: 1; } 100% { transform: scale(1); } }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes logo-in { from { transform: translateY(-18px) scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.8); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  28% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.96); }
}
@keyframes toast { 0% { opacity: 0; transform: translateY(-10px) scale(0.9); } 10% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-6px); } }
@keyframes bought { 0% { transform: none; } 35% { transform: translateY(-4px) scale(1.08); filter: brightness(1.2); } 100% { transform: none; filter: none; } }
@keyframes shake { 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }
@keyframes glow { 50% { opacity: 1; } }


/* ================================================================ Gameplay redesign */
#stage { --pad-main: clamp(76px, 21vmin, 116px); --pad-small: clamp(58px, 15vmin, 84px); }

/* HUD columns */
.hud-center { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.meter { min-height: 30px; padding: 3px 10px 3px 8px; width: min(190px, 44vw); gap: 6px; }
.meter svg { width: 18px; height: 18px; flex: none; fill: none; stroke-width: 2.4; stroke-linejoin: round; }
.meter-track { position: relative; flex: 1; height: 12px; border-radius: 999px; background: #e7e1d4; overflow: hidden; box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.1); }
.meter-fill { height: 100%; width: 100%; transform-origin: left center; border-radius: 999px; }
.meter-note { font-size: 11px; font-weight: 900; color: #b3262a; white-space: nowrap; }
.boost svg { stroke: #e0701a; fill: #ffd23f; }
.boost-fill { background: linear-gradient(#ffd98a, #ff8a2e); }
.boost-fill { position: relative; overflow: hidden; }
.boost.is-full .boost-fill { background: linear-gradient(90deg, #ffb020, #ff4d6d); }
.boost.is-full .boost-fill::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent); animation: sweep 0.8s linear infinite; }
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.boost.is-active { box-shadow: 0 4px 0 rgba(31, 35, 68, 0.16), 0 0 0 3px rgba(255, 138, 46, 0.55); }
.powerups { display: flex; flex-wrap: wrap; gap: 4px; max-width: min(190px, 44vw); }
.powerup-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: var(--glass); font-size: 11px; font-weight: 900; color: var(--ink); box-shadow: 0 3px 0 rgba(31, 35, 68, 0.14); border-left: 5px solid var(--chip, #ffd23f); animation: pop 0.3s var(--spring); }
.powerup-chip i { font-style: normal; font-variant-numeric: tabular-nums; color: var(--ink-soft); }

/* The speedo and combo sit over the sky, so their backing has to stay dark enough for white text. */
.speedo { display: flex; align-items: baseline; gap: 4px; padding: 0 10px; border-radius: 999px; background: rgba(20, 24, 50, 0.82); color: #fff; line-height: 1.25; }
.speedo b { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; min-width: 2.2em; text-align: right; }
.speedo span { font-size: 11px; font-weight: 900; letter-spacing: 0.08em; }
.speedo.is-hot { background: linear-gradient(90deg, rgba(178, 46, 8, 0.92), rgba(168, 90, 8, 0.92)); animation: pulse-soft 0.5s ease-in-out infinite; }
.speedo.is-boost b { color: #fff4c2; }

.combo { display: grid; justify-items: end; padding: 4px 10px 6px; border-radius: 16px; background: rgba(20, 24, 50, 0.78); color: #fff; min-width: 86px; pointer-events: none; }
.combo b { font-size: 30px; line-height: 1; font-weight: 900; color: #ffd23f; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); font-variant-numeric: tabular-nums; }
.combo span { font-size: 10px; font-weight: 900; letter-spacing: 0.14em; }
.combo-bar { width: 100%; height: 5px; border-radius: 999px; background: rgba(255, 255, 255, 0.25); overflow: hidden; margin-top: 3px; }
.combo-bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ffd23f, #ff4d6d); transform-origin: left center; }
.combo.bump b { animation: combo-pop 0.35s var(--spring); }
.combo.tier-5 b, .combo.tier-6 b, .combo.tier-7 b { color: #ff8a2e; text-shadow: 0 0 12px rgba(255, 120, 40, 0.9), 0 3px 0 rgba(0, 0, 0, 0.35); }
.combo.is-lost { animation: shake 0.3s linear; }

.zone-banner { position: absolute; z-index: 6; left: 50%; top: calc(var(--hud-h, 60px) + 40px); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; padding: 6px 18px 8px; border-radius: 18px; background: rgba(20, 24, 50, 0.72); color: #fff; pointer-events: none; text-align: center; max-width: calc(100% - 24px); animation: pop 0.3s var(--spring); }
.zone-kicker { font-size: 10px; font-weight: 900; letter-spacing: 0.2em; color: #7fc8ff; }
.zone-name { font-size: 20px; font-weight: 900; letter-spacing: 0.04em; line-height: 1.1; }
.zone-goal { font-size: 12px; font-weight: 800; color: #ffe27a; }
.zone-banner.is-boss { background: linear-gradient(180deg, rgba(120, 20, 40, 0.9), rgba(40, 10, 20, 0.9)); }
.zone-banner.is-boss .zone-kicker { color: #ffd23f; }
.zone-banner.is-clear { background: rgba(23, 130, 58, 0.9); }
.zone-banner.is-fail { background: rgba(120, 120, 130, 0.8); }

.mode-tag { position: absolute; z-index: 3; right: calc(12px + env(safe-area-inset-right, 0px)); top: calc(var(--hud-h, 60px) + 6px); padding: 2px 10px; border-radius: 999px; background: #e84646; color: #fff; font-size: 11px; font-weight: 900; letter-spacing: 0.1em; pointer-events: none; }

/* Touch pads: BRAKE left, JUMP lower centre, GAS right, BOOST above GAS */
.pad-brake, .pad-gas { --size: var(--pad-main); }
.pad-jump { --size: calc(var(--pad-main) * 0.9); left: 50%; margin-left: calc(var(--size) / -2); }
.pad-boost { --size: var(--pad-small); right: calc(16px + env(safe-area-inset-right, 0px) + (var(--pad-main) - var(--pad-small)) / 2); bottom: calc(18px + var(--safe-bottom) + var(--pad-main) + 16px); }
.pad-ring { position: absolute; inset: -6px; border-radius: 50%; background: conic-gradient(var(--ring, #ffffff) calc(var(--fill, 1) * 360deg), rgba(255, 255, 255, 0.12) 0); -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px)); mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px)); }
.pad-jump { --ring: #7dffb0; }
.pad-boost { --ring: #ffb020; }
.pad-jump.is-down { background: rgba(69, 212, 180, 0.62); border-color: #d6fff4; }
/* The BOOST pad is the smallest one: pressing it only dips it slightly so it never shrinks under 56px. */
.pad-boost.is-down { background: rgba(255, 138, 46, 0.7); border-color: #fff0d6; transform: scale(0.97); }
.pad-boost.is-active { background: rgba(255, 138, 46, 0.5); border-color: #ffd9ae; }
.pad.is-empty { opacity: 0.5; }
.pad.is-ready { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.12), 0 0 0 4px rgba(255, 255, 255, 0.35); }
.pad-boost.is-ready { animation: pulse-soft 0.9s ease-in-out infinite; }
@media (hover: hover) and (pointer: fine) {
  #stage { --pad-main: 72px; --pad-small: 60px; }
}

/* Start screen modes */
.start-modes { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.btn-chip { min-height: 44px; padding: 6px 14px; font-size: 13px; }
.btn-chip[aria-pressed='true'] { --face: #d13636; --face-2: #b82c2c; --edge: var(--red-edge); --text: #fff; }
.btn-daily { --face: #7a4be0; --face-2: #5f34bd; --edge: #40208a; --text: #fff; text-shadow: 0 2px 0 rgba(40, 10, 90, 0.35); }
.btn-daily small { font-size: 10px; opacity: 0.9; }
.start-best { font-size: 12px; opacity: 0.9; }

.coach-jump { background: linear-gradient(#b8ffe0, #45d4b4); box-shadow: 0 5px 0 #17826a; }
.coach-boost { background: linear-gradient(#b5530e, #9a4407); box-shadow: 0 5px 0 #7a3605; color: #fff; }
.world-teaches { margin-top: 4px; font-size: 12px; font-weight: 900; color: #e0701a; letter-spacing: 0.06em; text-align: center; }
.evolve-trait { margin-top: 4px; padding: 3px 12px; border-radius: 999px; background: rgba(255, 210, 63, 0.9); color: #3a2600; font-size: 13px; font-weight: 900; text-transform: uppercase; }

/* Game over */
.go-best { margin-top: 2px; font-size: 12px; font-weight: 900; letter-spacing: 0.08em; color: var(--ink-soft); }
.go-score { position: relative; display: flex; flex-direction: column; align-items: center; margin-bottom: 8px; }
.go-score b { font-size: 46px; line-height: 1; font-weight: 900; color: var(--ink); font-variant-numeric: tabular-nums; animation: settle 0.45s var(--spring) 0.1s both; }
.gameover .go-chips { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.go-records { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin: -2px 0 8px; }
.go-records span { padding: 2px 8px; border-radius: 999px; background: linear-gradient(#fff3a8, var(--yellow)); color: #3a2800; font-size: 11px; font-weight: 900; box-shadow: 0 2px 0 var(--yellow-edge); animation: pop 0.4s var(--spring) both; }

/* Garage presets, stats, parts */
.garage-presets { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.garage-presets::-webkit-scrollbar { display: none; }
.preset { flex: 1 0 auto; min-height: 44px; min-width: 72px; padding: 4px 10px; border: 2px solid transparent; border-radius: 14px; background: var(--cream-2); box-shadow: 0 3px 0 var(--line); color: var(--ink); font: inherit; font-size: 12px; font-weight: 900; letter-spacing: 0.04em; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; transition: transform 140ms var(--spring); }
.preset small { font-size: 10px; color: var(--ink-soft); font-weight: 900; }
.preset:active { transform: scale(0.95); }
.preset.is-active { background: var(--ink); color: #fff; box-shadow: 0 3px 0 #0e1130; }
.preset.is-active small { color: #bfe6ff; }
.preset.is-selected { border-color: var(--blue-2); }
.preset.is-locked small { color: #b3262a; }
.garage-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 12px; }
.garage-parts { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.part-card { min-height: 86px; padding: 6px; }
.part-card.is-locked-world { background: #eceae4; }
.part-card.is-locked-world .part-name { color: var(--ink-soft); }
.part-card.is-locked-world .part-state { background: #d8d4ca; color: var(--ink-soft); }

/* Pause menu settings */
.results.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.results.compact div { padding: 5px 4px; }
.results.compact dt { font-size: 9px; }
.results.compact dd { font-size: 14px; }
.settings { display: grid; gap: 8px; margin-bottom: 10px; }
.setting { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 900; color: var(--ink-soft); }
.setting input { flex: 1; accent-color: var(--blue-2); min-height: 44px; }
.setting-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

@media (max-width: 560px) {
  .meter { width: min(150px, 38vw); min-height: 26px; }
  .speedo b { font-size: 17px; }
  .combo b { font-size: 24px; }
  .combo { min-width: 70px; }
  .go-score b { font-size: 38px; }
  .gameover .go-chips { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .garage-parts .part-tags { display: none; }
  .part-card { min-height: 62px; }
  .part-name { font-size: 11px; }
  .part-state { font-size: 10px; padding: 1px 6px; }
  .results.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-height: 640px) and (orientation: portrait) {
  .go-score b { font-size: 34px; }
  .start-modes .btn { min-height: 44px; }
  .garage-presets .preset { min-height: 44px; padding: 2px 8px; }
}
@media (max-height: 480px) and (orientation: landscape) {
  #stage { --pad-main: clamp(64px, 19vmin, 86px); --pad-small: clamp(58px, 15vmin, 70px); }
  .pad-jump { left: calc(16px + env(safe-area-inset-left, 0px) + var(--pad-main) + 18px); margin-left: 0; bottom: calc(12px + var(--safe-bottom)); }
  .pad-boost { bottom: calc(12px + var(--safe-bottom) + var(--pad-main) + 12px); }
  .meter { min-height: 24px; }
  .zone-banner { top: calc(var(--hud-h, 60px) + 4px); padding: 3px 14px 5px; }
  .zone-name { font-size: 16px; }
  .gameover .go-chips { grid-column: 2; grid-row: 2; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .go-score b { font-size: 32px; }
  .results.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .settings { grid-template-columns: 1fr 1fr; align-items: center; }
  .start-modes { justify-content: flex-start; }
  .garage-parts .part-tags { display: none; }
  .part-card { min-height: 0; }
}
@media (max-height: 340px) and (orientation: landscape) {
  .start-modes .btn { min-height: 44px; font-size: 11px; padding: 4px 10px; }
  .stage-theme { display: none; }
  .speedo { padding: 0 6px; }
  .speedo b { font-size: 15px; min-width: 2em; }
  .speedo span { display: none; }
}

@keyframes pulse-soft { 50% { transform: scale(1.05); } }
@keyframes combo-pop { 0% { transform: scale(1.6); } 100% { transform: scale(1); } }

/* Zone banners sit below the coaching hints so the two never overlap. */
.zone-banner { top: calc(var(--hud-h, 60px) + 92px); }
@media (max-height: 480px) and (orientation: landscape) {
  .zone-banner { top: auto; bottom: calc(24px + var(--safe-bottom) + var(--pad-main)); }
}

/* Shown only if the game never starts (a file failed to load, or the browser cannot run it). */
.boot-error {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font);
}
.boot-error h2 { margin: 0; font-size: 22px; font-weight: 900; }
.boot-error p { margin: 0; max-width: 32ch; font-size: 15px; color: var(--ink-soft); }

/* Why the run ended, under the game over title (P11: "I can fix that next run"). */
.go-cause {
  margin: -4px 0 2px;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #b3262a;
  text-transform: uppercase;
}
.gameover:not(.is-crash) .go-cause { color: var(--ink-soft); }
/* Inside YouTube Playables the YouTube mute is the only overall mute. */
.is-playables #btn-mute, .is-playables #btn-sound { display: none; }
.go-tip { margin: 0 0 4px; font-size: 13px; font-weight: 800; color: #17826a; }
/* Two-column result card on short landscape screens: cause and tip read across the top, score sits beside the chips. */
@media (max-height: 480px) and (orientation: landscape) {
  .gameover .go-cause, .gameover .go-tip, .gameover .go-records { grid-column: 1 / -1; }
  .gameover .go-chips { grid-row: auto; }
  .gameover .go-cause { margin: -2px 0 0; }
}
.pad-jump.is-cue::after { content: ''; position: absolute; inset: -6px; border-radius: 50%; border: 6px solid rgba(125, 255, 176, 0.9); animation: pad-cue 0.55s ease-in-out infinite; pointer-events: none; }
@keyframes pad-cue {
  0%, 100% { transform: scale(0.96); opacity: 0.55; }
  50% { transform: scale(1.14); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .pad-jump.is-cue::after { animation: none; opacity: 1; transform: none; }
}
