@font-face {
  font-family: "Lilita One";
  src: url("./fonts/LilitaOne-Regular.ttf") format("truetype");
  font-display: swap;
}

/* =====================================================================
   Gran Zoorismo UI — glossy toy style.
   Tokens: --u scales menus, --h scales the race HUD (both 12.8px at
   1280x720 and grow/shrink with the viewport). Display text = ink stroke
   UNDER a gradient fill + a hard drop shadow (.fx-text + data-text).
   ===================================================================== */
:root {
  --ink: #2b2640;
  --ink-soft: #4a4366;
  --ink-mute: #807aa3;
  --white: #ffffff;
  --orange: #ff9a1f;
  --orange-dark: #d86a00;
  --pink: #ff4f9a;
  --pink-dark: #c92d72;
  --purple: #8a56e8;
  --purple-dark: #5e33b5;
  --blue: #2fb4ff;
  --blue-dark: #1a7fc9;
  --green: #4fd85a;
  --yellow: #ffd23f;
  --panel: #ffffff;
  --panel-2: #f4f0ff;
  --focus: #35cfff;
  --font: "Lilita One", "Arial Black", "Segoe UI Black", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --spring-big: cubic-bezier(0.3, 1.9, 0.5, 1);
  --out: cubic-bezier(0.16, 1, 0.3, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --u: clamp(7.5px, min(1vw, 1.78vh), 21px);
  --h: clamp(7px, min(1vw, 1.78vh), 20px);
  --line: max(3px, calc(var(--u) * 0.3));
  --hline: max(2.5px, calc(var(--h) * 0.3));
  --gap: max(12px, calc(var(--u) * 1.25));
  --hgap: max(9px, calc(var(--h) * 1.05));
  --fill-white: linear-gradient(180deg, #ffffff 0%, #ffffff 42%, #e4f2ff 62%, #c3e2ff 100%);
  --fill-gold: linear-gradient(180deg, #fffbe0 0%, #ffe680 34%, #ffc21f 58%, #ff9415 100%);
  --fill-silver: linear-gradient(180deg, #ffffff 0%, #f1f4fb 40%, #c8d2e8 60%, #9babcb 100%);
  --fill-bronze: linear-gradient(180deg, #ffeedd 0%, #ffc490 40%, #ea8d48 60%, #c3622a 100%);
  --fill-sky: linear-gradient(180deg, #ffffff 0%, #ffffff 38%, #bfe8ff 60%, #6cc4ff 100%);
  --fill-coral: linear-gradient(180deg, #fff0f1 0%, #ffc1c8 38%, #ff7a8a 60%, #ff4561 100%);
  --fill-purple: linear-gradient(180deg, #ffffff 0%, #f4eeff 40%, #cfbaff 62%, #a582f7 100%);
  --fill-green: linear-gradient(180deg, #f6ffd0 0%, #c8f86e 40%, #6fdf4a 62%, #2fbf45 100%);
  --fill-pink: linear-gradient(180deg, #fff0f7 0%, #ffb3d6 38%, #ff6fae 60%, #f03c8a 100%);
  --fill-cyan: linear-gradient(180deg, #f2feff 0%, #b5f1ff 38%, #57d2ff 60%, #1f9cf0 100%);
}

@media (orientation: portrait) {
  :root {
    --u: clamp(7.5px, min(2.9vw, 1.45vh), 16px);
    --h: clamp(6.5px, min(2.25vw, 1.15vh), 14px);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #2c8dff;
  color: var(--ink);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  /* embedded in a portal page: a scroll that reaches an edge here never moves the page around the game */
  overscroll-behavior: none;
}

#game-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

button {
  font-family: var(--font);
  cursor: pointer;
  border: 0;
  color: inherit;
  background: none;
  padding: 0;
}

img {
  -webkit-user-drag: none;
}

.ico {
  display: inline-grid;
  place-items: center;
  width: 1.15em;
  height: 1.15em;
  flex: none;
  line-height: 0;
}

.ico svg,
.stat-ico svg,
.thumb-chip svg,
.t-ico svg,
.fact svg,
.lock-ico svg,
.tile-check svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

/* ------------------------------------------------------- display text --- */
.fx-text,
.place-num,
.place-suffix,
.countdown,
.banner {
  color: var(--ink);
  -webkit-text-stroke: var(--fx-stroke, 0.17em) var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 var(--fx-drop, 0.09em) 0 var(--ink);
  white-space: nowrap;
}

.fx-text,
.place-num,
.place-suffix {
  position: relative;
}

.fx-text::after,
.place-num::after,
.place-suffix::after,
.countdown::after,
.banner::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  padding: inherit;
  text-align: inherit;
  color: transparent;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 0;
  text-shadow: none;
  background: var(--fx-fill, var(--fill-white));
  -webkit-background-clip: text;
  background-clip: text;
  pointer-events: none;
}

.tone-gold { --fx-fill: var(--fill-gold); }
.tone-silver { --fx-fill: var(--fill-silver); }
.tone-bronze { --fx-fill: var(--fill-bronze); }
.tone-sky { --fx-fill: var(--fill-sky); }
.tone-coral { --fx-fill: var(--fill-coral); }
.tone-purple { --fx-fill: var(--fill-purple); }
.tone-green { --fx-fill: var(--fill-green); }

/* ------------------------------------------------------------ buttons --- */
.big-btn,
.mid-btn,
.round-btn {
  --c-hi: #ffc75a;
  --c: #ff9d22;
  --c-lo: #ff7f0a;
  --c-dk: #c45a00;
  --lip: max(4px, calc(var(--u) * 0.45));
  --sh: inset 0 calc(var(--lip) * -0.85) 0 rgba(60, 10, 70, 0.16), inset 0 2px 0 rgba(255, 255, 255, 0.55), 0 var(--lip) 0 var(--ink);
  --amb: 0 calc(var(--lip) + 4px) 12px rgba(28, 14, 76, 0.26);
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.32em;
  border: var(--line) solid var(--ink);
  color: #fff;
  line-height: 1;
  letter-spacing: 0.02em;
  background: linear-gradient(180deg, var(--c-hi) 0%, var(--c) 50%, var(--c-lo) 100%);
  box-shadow: var(--sh), var(--amb);
  text-shadow: 0 0.08em 0 var(--c-dk);
  transition: translate 0.12s ease, box-shadow 0.12s ease, filter 0.15s ease, scale 0.3s var(--spring);
}

.big-btn::before,
.mid-btn::before,
.round-btn::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 6%;
  right: 6%;
  top: 7%;
  height: 44%;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.06));
  pointer-events: none;
}

.big-btn {
  font-size: max(18px, calc(var(--u) * 2.3));
  padding: 0.42em 1.05em 0.5em;
  border-radius: calc(var(--u) * 1.55);
}

.mid-btn {
  --lip: max(4px, calc(var(--u) * 0.38));
  font-size: max(14px, calc(var(--u) * 1.55));
  padding: 0.52em 1em 0.6em;
  border-radius: calc(var(--u) * 1.25);
}

.big-btn .ico,
.mid-btn .ico {
  width: 1.12em;
  height: 1.12em;
  margin: -0.1em 0;
}

.round-btn {
  --c-hi: #ffffff;
  --c: #f7f4ff;
  --c-lo: #e1d9ff;
  --c-dk: #b9aee6;
  --lip: max(4px, calc(var(--u) * 0.36));
  width: max(46px, calc(var(--u) * 4.2));
  height: max(46px, calc(var(--u) * 4.2));
  border-radius: 50%;
  color: var(--purple);
  text-shadow: none;
  font-size: max(22px, calc(var(--u) * 2.15));
}

.round-btn::before {
  left: 16%;
  right: 16%;
  top: 8%;
  height: 40%;
}

.round-btn .ico {
  width: 1.02em;
  height: 1.02em;
}

@media (hover: hover) {
  .big-btn:hover:not(:disabled),
  .mid-btn:hover:not(:disabled),
  .round-btn:hover {
    filter: brightness(1.07) saturate(1.05);
    translate: 0 -2px;
  }
}

.big-btn:active:not(:disabled),
.mid-btn:active:not(:disabled),
.round-btn:active {
  translate: 0 calc(var(--lip) * 0.75);
  --sh: inset 0 calc(var(--lip) * -0.5) 0 rgba(60, 10, 70, 0.16), inset 0 2px 0 rgba(255, 255, 255, 0.45), 0 calc(var(--lip) * 0.25) 0 var(--ink);
  --amb: 0 3px 6px rgba(28, 14, 76, 0.2);
  transition-duration: 0.04s;
}

.big-btn:disabled,
.mid-btn:disabled {
  filter: grayscale(0.85) brightness(0.93);
  cursor: default;
}

.btn-orange { --c-hi: #ffc75a; --c: #ff9d22; --c-lo: #ff7f0a; --c-dk: #b85200; }
.btn-pink { --c-hi: #ff8cc2; --c: #ff5aa2; --c-lo: #f23a88; --c-dk: #a81d58; }
.btn-purple { --c-hi: #b593ff; --c: #8f5cf0; --c-lo: #7744dc; --c-dk: #47258f; }
.btn-blue { --c-hi: #8be0ff; --c: #3cbaff; --c-lo: #1c9cf0; --c-dk: #0b5f9f; }
.btn-green { --c-hi: #9ef58f; --c: #55dc5e; --c-lo: #32c246; --c-dk: #177a2c; }

/* -------------------------------------------------------------- chips --- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.38em;
  background: linear-gradient(180deg, #ffffff 55%, #ece6ff);
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  padding: 0.16em 0.8em 0.2em 0.2em;
  font-size: max(16px, calc(var(--u) * 1.75));
  line-height: 1;
  box-shadow: inset 0 -3px 0 rgba(120, 100, 200, 0.16), 0 calc(var(--u) * 0.36) 0 var(--ink);
}

.coin-icon {
  position: relative;
  width: 1.25em;
  height: 1.25em;
  border-radius: 50%;
  display: inline-block;
  flex: none;
  border: max(2px, 0.12em) solid var(--ink);
  background:
    radial-gradient(circle at 33% 28%, #fffbe0 0 14%, rgba(255, 251, 224, 0) 16%),
    radial-gradient(circle, #ffe266 0 44%, #f0a800 46% 56%, #ffd23f 58% 100%);
  box-shadow: inset 0 -0.1em 0 rgba(176, 100, 0, 0.45);
}

.chip.pop,
.hud-chip.pop {
  animation: chip-pop 0.45s var(--spring);
}

.chip.pop .coin-icon,
.hud-chip.pop .coin-icon {
  animation: coin-flip 0.5s ease;
}

.chip.spend,
.hud-chip.spend {
  animation: chip-spend 0.4s ease;
}

/* ------------------------------------------------------------ screens --- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  z-index: 10;
}

.screen.active,
.screen.leaving {
  display: flex;
}

.screen.leaving {
  z-index: 9;
  pointer-events: none;
  animation: screen-out 0.24s ease forwards;
}

/* the loading sky dissolves over the title (keeps its z-index 60) */
#screen-loading.leaving {
  animation: screen-out 0.45s ease forwards;
}

.screen.leaving * {
  pointer-events: none !important;
}

/* swoosh between the menu showcase and a race */
.wipe {
  position: absolute;
  inset: 0;
  z-index: 55;
  pointer-events: none;
  overflow: hidden;
  display: none;
}

.wipe.run,
.wipe.cover {
  display: block;
}

.wipe.cover {
  pointer-events: auto;
}

.wipe > i {
  position: absolute;
  top: -12%;
  bottom: -12%;
  left: -50%;
  width: 200%;
  background:
    linear-gradient(90deg, #ffd23f 0 1.4%, #ffffff 1.4% 2.4%, rgba(255, 255, 255, 0) 2.4%),
    linear-gradient(270deg, #ffd23f 0 1.4%, #ffffff 1.4% 2.4%, rgba(255, 255, 255, 0) 2.4%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.1) 0 1.6%, rgba(255, 255, 255, 0) 1.6% 5%),
    linear-gradient(180deg, #1f78ec 0%, #3d9dff 55%, #7fd0ff 100%);
  transform: translateX(0) skewX(-14deg);
  will-change: transform;
}

.wipe.cover > i {
  animation: wipe-in 0.4s cubic-bezier(0.3, 0, 0.2, 1) both;
}

.wipe.run > i {
  animation: wipe-away 0.62s 0.06s cubic-bezier(0.7, 0, 0.25, 1) forwards;
}

.wipe-label {
  position: absolute;
  left: 50%;
  top: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15em;
  font-weight: 400;
  font-size: max(26px, calc(var(--u) * 3.6));
  transform: translate(-50%, -50%) skewX(14deg);
  opacity: 0;
}

.wipe.cover .wipe-label {
  animation: fade-in 0.25s 0.32s ease both;
}

.wipe.run.held .wipe-label {
  opacity: 1;
}

.wipe-kart {
  width: 2.7em;
  height: 1.8em;
  animation: kart-hop 0.34s ease-in-out infinite alternate;
}

.wipe-kart svg {
  width: 100%;
  height: 100%;
  display: block;
}

.wipe-label .fx-text {
  --fx-stroke: 0.18em;
  --fx-drop: 0.09em;
}

/* ------------------------------------------------------------ loading --- */
#screen-loading {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--u) * 1.7);
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 60%),
    linear-gradient(180deg, #1f78ec 0%, #43a2ff 42%, #92d4ff 74%, #eaf8ff 100%);
  z-index: 60;
}

.sky-clouds {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

#screen-loading > :not(.sky-clouds) {
  z-index: 1;
}

.loading-text {
  position: relative;
}

.sky-clouds i {
  position: absolute;
  left: 0;
  width: calc(var(--u) * 20);
  height: calc(var(--u) * 5);
  border-radius: 999px;
  background: #ffffff;
  opacity: 0.8;
  box-shadow: inset 0 calc(var(--u) * -1) 0 rgba(170, 200, 240, 0.45);
  animation: cloud-drift 46s linear infinite;
}

.sky-clouds i::before,
.sky-clouds i::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: #ffffff;
}

.sky-clouds i::before {
  left: 18%;
  bottom: 40%;
  width: 34%;
  height: 130%;
}

.sky-clouds i::after {
  left: 44%;
  bottom: 30%;
  width: 42%;
  height: 170%;
}

.sky-clouds i:nth-child(1) { top: 12%; animation-delay: -6s; }
.sky-clouds i:nth-child(2) { top: 30%; scale: 0.7; opacity: 0.6; animation-duration: 62s; animation-delay: -38s; }
.sky-clouds i:nth-child(3) { top: 70%; scale: 1.3; animation-duration: 54s; animation-delay: -20s; }
.sky-clouds i:nth-child(4) { top: 84%; scale: 0.9; animation-duration: 40s; animation-delay: -31s; }
.sky-clouds i:nth-child(5) { top: 52%; scale: 0.55; opacity: 0.5; animation-duration: 70s; animation-delay: -52s; }

.logo-wrap {
  position: relative;
  display: block;
  line-height: 0;
}

.logo-wrap img {
  width: 100%;
  display: block;
}

.logo-shine {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  -webkit-mask: url("./logo.png.webp") center / 100% 100% no-repeat;
  mask: url("./logo.png.webp") center / 100% 100% no-repeat;
}

.logo-shine::before {
  content: "";
  position: absolute;
  top: -10%;
  bottom: -10%;
  left: -30%;
  width: 22%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.85) 50%, rgba(255, 255, 255, 0));
  transform: translateX(0) skewX(-20deg);
  animation: shine 4.2s 1.4s ease-in-out infinite;
}

.loading-logo-wrap {
  position: relative;
  width: min(calc(var(--u) * 50), 88vw);
  animation: bob 2.6s ease-in-out infinite;
}

.loading-logo {
  filter: drop-shadow(0 calc(var(--u) * 0.7) 0 rgba(43, 38, 64, 0.25));
}

.loading-bar {
  position: relative;
  width: min(calc(var(--u) * 30), 72vw);
  height: max(22px, calc(var(--u) * 2.3));
  padding: 3px;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  background: linear-gradient(180deg, #d8d0f3, #ffffff 65%);
  box-shadow: inset 0 3px 0 rgba(43, 38, 64, 0.16), 0 calc(var(--u) * 0.42) 0 var(--ink);
}

.loading-bar span {
  position: relative;
  display: block;
  height: 100%;
  width: 0%;
  min-width: 14px;
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 55%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.24) 25%, rgba(255, 255, 255, 0) 25% 50%, rgba(255, 255, 255, 0.24) 50% 75%, rgba(255, 255, 255, 0) 75%),
    linear-gradient(180deg, #ffbe45, #ff9a1f);
  background-size: 100% 100%, 26px 26px, 100% 100%;
  box-shadow: inset 0 -3px 0 rgba(190, 90, 0, 0.35);
  transition: width 0.35s var(--out);
  animation: stripes 0.7s linear infinite;
}

.loading-rider {
  position: absolute;
  right: max(-30px, calc(var(--u) * -2.6));
  top: 50%;
  width: max(46px, calc(var(--u) * 4.6));
  height: max(31px, calc(var(--u) * 3.07));
  transform: translateY(-74%);
  animation: rider 0.32s ease-in-out infinite alternate;
}

.loading-rider svg {
  width: 100%;
  height: 100%;
  display: block;
}

.loading-text {
  margin: 0;
  color: #fff;
  font-size: max(16px, calc(var(--u) * 1.8));
  -webkit-text-stroke: 0.2em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.12em 0 var(--ink);
}

.loading-tip {
  position: absolute;
  left: 50%;
  bottom: calc(var(--gap) * 1.4 + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(92vw, calc(var(--u) * 46));
  margin: 0;
  text-align: center;
  color: var(--ink-soft);
  font-family: var(--body);
  font-weight: 700;
  font-size: max(12px, calc(var(--u) * 1.15));
  background: rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  padding: 0.5em 1.2em;
}

/* -------------------------------------------------------------- title --- */
#screen-title {
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(2px + var(--safe-top)) calc(var(--gap) + var(--safe-right)) calc(var(--gap) * 0.85 + var(--safe-bottom)) calc(var(--gap) + var(--safe-left));
  pointer-events: none;
}

#screen-title > * {
  pointer-events: auto;
}

.top-strip {
  position: absolute;
  top: calc(var(--gap) + var(--safe-top));
  left: calc(var(--gap) + var(--safe-left));
  right: calc(var(--gap) + var(--safe-right));
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none !important;
}

.top-strip > * {
  pointer-events: auto;
}

.title-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* the logo's top lines up with the coin chip and the settings button */
  padding-top: calc(var(--gap) * 0.9);
}

.title-logo-wrap {
  width: min(calc(var(--u) * 46), 88vw);
  animation: bob 3.2s ease-in-out infinite;
}

.title-logo {
  filter: drop-shadow(0 calc(var(--u) * 0.55) 0 rgba(43, 38, 64, 0.3));
}

.title-tagline {
  position: relative;
  margin: calc(var(--u) * 0.55) 0 0;
  z-index: 1;
}

.title-tagline span {
  display: inline-block;
  font-size: max(12px, calc(var(--u) * 1.42));
  color: #fff;
  padding: 0.28em 1.05em 0.34em;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 50%),
    linear-gradient(180deg, #ff7cb6, #ff4f9a 55%, #e63a86);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.4), 0 calc(var(--u) * 0.32) 0 var(--ink);
  text-shadow: 0 0.08em 0 #a8215d;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.title-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--u) * 1);
}

.title-buttons {
  display: flex;
  gap: calc(var(--u) * 1.4);
}

.title-buttons .big-btn {
  min-width: calc(var(--u) * 14.5);
  font-size: max(22px, calc(var(--u) * 2.95));
  padding: 0.34em 0.95em 0.42em;
  border-radius: calc(var(--u) * 1.7);
}

.title-buttons .big-btn .ico {
  width: 1.02em;
  height: 1.02em;
}

.racer-btn {
  gap: 0.55em;
  padding: 0.28em 1.15em 0.34em 0.3em;
  font-size: max(15px, calc(var(--u) * 1.55));
  border-radius: 999px;
}

.racer-face {
  width: 2.25em;
  height: 2.25em;
  border-radius: 50%;
  object-fit: cover;
  border: max(2.5px, 0.12em) solid var(--ink);
  background: var(--rc, #ffffff);
  box-shadow: 0 0.08em 0 var(--c-dk);
}

.racer-face.empty {
  visibility: hidden;
  width: 0.4em;
}

.racer-btn-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.12em;
  line-height: 1;
}

.racer-btn-text small {
  font-size: 0.66em;
  opacity: 0.92;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* The EvilDot studio mark, layered like the studio site does it: the tail is
   its own layer, swaying behind the base (brand/evildot-*.webp, built by
   tools/brand/build.py; the box is the 1192 x 909 export). */
.studio-mark {
  position: relative;
  display: inline-block;
  height: calc(var(--u) * 4);
  aspect-ratio: 1192 / 909;
  filter: drop-shadow(0 2px 0 rgba(43, 38, 64, 0.35));
}

.studio-mark img {
  position: absolute;
  display: block;
  pointer-events: none;
  user-select: none;
}

.studio-base {
  inset: 0;
  width: 100%;
  height: 100%;
}

.studio-tail {
  left: 17.785%;
  top: 32.233%;
  width: 12.416%;
  height: 19.362%;
  transform-origin: 63.004% 89.301%;
  animation: studio-tail 3.8s ease-in-out infinite;
}

@keyframes studio-tail {
  0%, 100% { transform: rotate(-4deg); }
  35% { transform: rotate(9deg); }
  70% { transform: rotate(-9deg); }
}

.title-footer {
  display: flex;
  align-items: center;
  gap: calc(var(--u) * 0.75);
  margin: 0;
}

.title-footer .studio-mark {
  height: max(34px, calc(var(--u) * 3.9));
}

.copyright {
  margin: 0;
  font-family: var(--body);
  font-weight: 700;
  font-size: max(10px, calc(var(--u) * 0.9));
  line-height: 1.3;
  color: #fff;
  text-align: left;
  text-shadow: 0 1px 0 rgba(43, 38, 64, 0.8), 0 0 6px rgba(43, 38, 64, 0.4);
}

.copyright b {
  font-weight: 800;
}

.loading-studio .studio-mark {
  height: max(44px, calc(var(--u) * 5.4));
}

#screen-title.active .top-strip { animation: drop-in 0.5s 0.05s var(--spring) both; }
#screen-title.active .title-logo-wrap { animation: logo-in 0.75s var(--spring) both, bob 3.2s 0.75s ease-in-out infinite; }
#screen-title.active .title-tagline { animation: ribbon-in 0.55s 0.28s var(--spring) both; }
#screen-title.active .title-buttons .big-btn { animation: pop-up 0.5s var(--spring) both; }
#screen-title.active .title-buttons .big-btn:nth-child(1) { animation-delay: 0.3s; }
#screen-title.active .title-buttons .big-btn:nth-child(2) { animation-delay: 0.38s; }
#screen-title.active .racer-btn { animation: pop-up 0.5s 0.46s var(--spring) both; }
#screen-title.active .title-footer { animation: fade-in 0.6s 0.6s ease both; }

/* -------------------------------------------------------- panel pages --- */
#screen-racers,
#screen-courses {
  flex-direction: column;
  padding: calc(var(--gap) * 0.8 + var(--safe-top)) calc(var(--gap) + var(--safe-right)) calc(var(--gap) + var(--safe-bottom)) calc(var(--gap) + var(--safe-left));
  gap: calc(var(--u) * 1);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
}

.panel-header h2 {
  margin: 0;
  flex: 1;
  min-width: 0;
  text-align: center;
  font-weight: 400;
  font-size: max(22px, calc(var(--u) * 3.2));
  line-height: 1.15;
  --fx-fill: var(--fill-purple);
  --fx-stroke: 0.2em;
  --fx-drop: 0.1em;
}

.screen.active .panel-header { animation: drop-in 0.5s var(--spring) both; }

/* ------------------------------------------------------------- racers --- */
.racer-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, calc(var(--u) * 27));
  gap: var(--gap);
  align-items: end;
}

.racer-grid {
  --tile: clamp(64px, calc(var(--u) * 9.4), 156px);
  display: grid;
  grid-template-columns: repeat(4, var(--tile));
  gap: calc(var(--u) * 0.85);
  align-content: end;
  justify-content: start;
  padding: 0 0 calc(var(--u) * 0.45) 2px;
}

.racer-tile {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  border: var(--line) solid var(--ink);
  border-radius: calc(var(--u) * 1.5);
  overflow: hidden;
  background: var(--rc, #ffffff);
  box-shadow: 0 calc(var(--u) * 0.42) 0 var(--ink), 0 calc(var(--u) * 0.42 + 5px) 12px rgba(28, 14, 76, 0.25);
  transition: translate 0.25s var(--spring), scale 0.25s var(--spring), box-shadow 0.2s ease;
  animation: tile-in 0.45s var(--spring) both;
  animation-delay: calc(var(--i, 0) * 40ms + 140ms);
}

.racer-tile::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0) 38%);
  pointer-events: none;
}

.racer-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: scale 0.3s var(--spring);
}

.racer-tile .tile-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  font-size: max(11px, calc(var(--u) * 1.12));
  color: #fff;
  padding: 0.7em 0.3em 0.35em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: linear-gradient(180deg, rgba(43, 38, 64, 0), rgba(43, 38, 64, 0.82) 55%);
  text-shadow: 0 0.08em 0 var(--ink);
}

@media (hover: hover) {
  .racer-tile:hover { translate: 0 -3px; }
  .racer-tile:hover img { scale: 1.06; }
}

.racer-tile:active {
  translate: 0 3px;
}

.racer-tile.selected {
  translate: 0 calc(var(--u) * -0.5);
  border-color: #ffffff;
  box-shadow: 0 0 0 calc(var(--line) * 0.9) #ffb21e, 0 0 0 calc(var(--line) * 0.9 + 3px) var(--ink), 0 calc(var(--u) * 0.42 + 6px) 0 var(--ink), 0 calc(var(--u) * 0.42 + 10px) 16px rgba(28, 14, 76, 0.32);
}

.racer-tile.selected img {
  scale: 1.08;
}

.racer-tile.locked img {
  filter: grayscale(1) brightness(0.6) contrast(0.92);
}

.racer-tile .lock {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2em;
  padding-bottom: 0.9em;
  font-size: max(11px, calc(var(--u) * 1.15));
}

.racer-tile .lock-ico {
  width: 2.3em;
  height: 2.3em;
  display: block;
  filter: drop-shadow(0 2px 0 rgba(43, 38, 64, 0.55));
}

.racer-tile .lock b {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  font-weight: 400;
  color: var(--ink);
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 0.08em 0.55em 0.12em 0.14em;
  box-shadow: 0 2px 0 var(--ink);
}

.racer-tile .lock .coin-icon {
  width: 1.15em;
  height: 1.15em;
  border-width: 2px;
}

.racer-tile .tile-check {
  position: absolute;
  top: 6%;
  right: 6%;
  z-index: 3;
  width: max(20px, calc(var(--u) * 2));
  height: max(20px, calc(var(--u) * 2));
  padding: 0.18em;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(180deg, #8cf07f, #2fbf45);
  border: 2.5px solid var(--ink);
  box-shadow: 0 2px 0 var(--ink);
}

.racer-grid.instant .racer-tile {
  animation: none;
}

.racer-card {
  --rc: #27c46b;
  position: relative;
  align-self: end;
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 0.62);
  background: linear-gradient(180deg, #ffffff 70%, #f5f1ff);
  border: calc(var(--line) * 1.15) solid var(--ink);
  border-radius: calc(var(--u) * 2);
  box-shadow: 0 calc(var(--u) * 0.55) 0 var(--ink), 0 calc(var(--u) * 0.55 + 8px) 24px rgba(28, 14, 76, 0.3);
  padding: 0 calc(var(--u) * 1.25) calc(var(--u) * 1.25);
  overflow: hidden;
}

.screen.active .racer-card { animation: slide-left 0.55s 0.12s var(--spring) both; }
.racer-card.swap .racer-card-head > * { animation: name-swap 0.4s var(--spring) both; }

.racer-card-head {
  position: relative;
  margin: 0 calc(var(--u) * -1.25);
  padding: calc(var(--u) * 0.85) calc(var(--u) * 1.25) calc(var(--u) * 0.75);
  background:
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.12) 0 10px, rgba(255, 255, 255, 0) 10px 20px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0) 60%),
    var(--rc);
  border-bottom: var(--line) solid var(--ink);
  transition: background-color 0.3s ease;
}

.racer-card h3 {
  margin: 0;
  font-weight: 400;
  font-size: max(22px, calc(var(--u) * 2.9));
  line-height: 1.05;
  color: #fff;
  -webkit-text-stroke: 0.18em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.09em 0 var(--ink);
}

.racer-species {
  margin: 0.3em 0 0;
  display: inline-block;
  font-size: max(12px, calc(var(--u) * 1.2));
  color: #fff;
  background: rgba(43, 38, 64, 0.55);
  border-radius: 999px;
  padding: 0.18em 0.75em 0.24em;
}

.racer-tagline {
  margin: 0;
  font-size: max(12px, calc(var(--u) * 1.25));
  color: var(--pink-dark);
  line-height: 1.2;
}

.stat-bars {
  display: grid;
  gap: calc(var(--u) * 0.5);
  margin: calc(var(--u) * 0.1) 0 calc(var(--u) * 0.35);
}

.stat {
  display: grid;
  grid-template-columns: auto calc(var(--u) * 6.2) 1fr;
  align-items: center;
  gap: calc(var(--u) * 0.55);
  font-size: max(12px, calc(var(--u) * 1.2));
  color: var(--ink-soft);
}

.stat-ico {
  width: 1.65em;
  height: 1.65em;
  display: block;
}

.stat .pips {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
}

.stat .pip {
  height: max(9px, calc(var(--u) * 1.05));
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: #ece8fb;
  box-shadow: inset 0 2px 0 rgba(43, 38, 64, 0.12);
}

.stat .pip.on {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 55%), var(--pc, var(--orange));
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.14);
  animation: pip-in 0.36s var(--spring) both;
  animation-delay: calc(var(--p, 1) * 45ms + 60ms);
}

.stat-speed { --pc: #ffc21f; }
.stat-accel { --pc: #ff8a3d; }
.stat-handling { --pc: #3fc8ff; }
.stat-weight { --pc: #a37cf4; }

#racer-select,
#racer-try {
  width: 100%;
}

#racer-try {
  display: none;
}

#racer-select .price {
  display: inline-flex;
  align-items: center;
  gap: 0.22em;
  margin-left: 0.25em;
  padding: 0.06em 0.5em 0.1em 0.12em;
  border-radius: 999px;
  background: rgba(23, 80, 30, 0.28);
}

#racer-select .price .coin-icon {
  width: 1.05em;
  height: 1.05em;
}

/* ------------------------------------------------------------ courses --- */
.option-row {
  display: flex;
  gap: calc(var(--u) * 1.1);
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.screen.active .option-row { animation: drop-in 0.5s 0.08s var(--spring) both; }

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: linear-gradient(180deg, #ffffff 55%, #ece6ff);
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  box-shadow: inset 0 -3px 0 rgba(120, 100, 200, 0.16), 0 calc(var(--u) * 0.4) 0 var(--ink);
}

.segmented button {
  display: inline-flex;
  align-items: center;
  gap: 0.32em;
  font-size: max(14px, calc(var(--u) * 1.5));
  padding: 0.4em 0.95em 0.46em 0.7em;
  border-radius: 999px;
  color: var(--ink-soft);
  transition: background 0.2s ease, color 0.2s ease, scale 0.25s var(--spring);
}

.segmented button .ico {
  width: 1.15em;
  height: 1.15em;
}

.segmented button.on {
  color: #fff;
  background: linear-gradient(180deg, var(--s-hi, #b593ff), var(--s-lo, #7744dc));
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45), inset 0 -3px 0 rgba(30, 10, 70, 0.22), 0 0 0 2.5px var(--ink);
  text-shadow: 0 0.08em 0 rgba(30, 10, 70, 0.5);
}

.segmented button[data-diff="breezy"] { --s-hi: #8ff07c; --s-lo: #2fb845; }
.segmented button[data-diff="gusty"] { --s-hi: #7fd6ff; --s-lo: #1a8fe3; }
.segmented button[data-diff="stormy"] { --s-hi: #b593ff; --s-lo: #6a37d0; }

.gp-btn small {
  font-size: 0.7em;
  opacity: 0.92;
  margin-left: 0.2em;
}

.difficulty-hint {
  align-self: center;
  margin: calc(var(--u) * -0.1) 0 0;
  padding: 0.22em 1em 0.28em;
  text-align: center;
  color: #fff;
  font-size: max(12px, calc(var(--u) * 1.25));
  border-radius: 999px;
  background: rgba(36, 28, 80, 0.55);
  text-shadow: 0 0.08em 0 var(--ink);
}

.screen.active .difficulty-hint { animation: fade-in 0.4s 0.2s ease both; }

.course-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, calc(var(--u) * 16)), calc(var(--u) * 23)));
  justify-content: center;
  align-content: center;
  gap: calc(var(--u) * 1.3);
  overflow: auto;
  padding: 8px 8px calc(var(--u) * 1.2);
  scrollbar-width: none;
}

.course-grid::-webkit-scrollbar {
  display: none;
}

.course-card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-align: left;
  color: var(--ink);
  background: #ffffff;
  border: calc(var(--line) * 1.1) solid var(--ink);
  border-radius: calc(var(--u) * 1.8);
  overflow: hidden;
  --sh: 0 calc(var(--u) * 0.55) 0 var(--ink);
  --amb: 0 calc(var(--u) * 0.55 + 6px) 20px rgba(28, 14, 76, 0.28);
  box-shadow: var(--sh), var(--amb);
  transition: translate 0.25s var(--spring), scale 0.25s var(--spring), box-shadow 0.2s ease;
  animation: card-rise 0.55s var(--spring) both;
  animation-delay: calc(var(--i, 0) * 60ms + 160ms);
}

.course-grid.instant .course-card {
  animation: fade-in 0.25s ease both;
}

/* races grouped by cup: three cards per row under a cup header with its own
   Grand Prix button */
.course-grid.cups {
  grid-template-columns: repeat(3, minmax(0, calc(var(--u) * 23)));
  /* rows keep their content height and the grid scrolls (cards clip their
     overflow, so auto rows would squeeze them to fit) */
  grid-auto-rows: max-content;
  align-content: start;
}

/* the obby ladder: eight cards, four to a row on landscape screens; rows keep
   their content height like the cups (the stars or the lock line stays in
   view) and the list scrolls when they do not fit */
.course-grid.obby {
  grid-auto-rows: max-content;
  align-content: start;
  align-content: safe center;
}

@media (orientation: landscape) {
  .course-grid.obby { grid-template-columns: repeat(4, minmax(0, calc(var(--u) * 21))); }
}

.cup-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(var(--u) * 1);
  margin-top: calc(var(--u) * 0.6);
  padding: calc(var(--u) * 0.35) calc(var(--u) * 0.4) calc(var(--u) * 0.35) calc(var(--u) * 0.9);
  color: #fff;
  border: calc(var(--line) * 1.1) solid var(--ink);
  border-radius: calc(var(--u) * 1.4);
  background: linear-gradient(180deg, var(--cup-hi), var(--cup-lo));
  box-shadow: 0 calc(var(--u) * 0.4) 0 var(--ink);
  animation: card-rise 0.55s var(--spring) both;
  animation-delay: calc(var(--i, 0) * 60ms + 120ms);
}

.cup-row:first-child { margin-top: 0; }
.cup-breeze { --cup-hi: #8ff07c; --cup-lo: #2fb845; }
.cup-sun { --cup-hi: #ffc75a; --cup-lo: #ff7f0a; }
.cup-storm { --cup-hi: #b593ff; --cup-lo: #6a37d0; }
.course-grid.instant .cup-row { animation: fade-in 0.25s ease both; }

.cup-name {
  display: flex;
  align-items: center;
  gap: 0.45em;
  font-family: var(--font);
  font-size: max(16px, calc(var(--u) * 1.7));
  text-shadow: 0 0.08em 0 rgba(30, 10, 70, 0.55);
  white-space: nowrap;
}

.cup-name svg { width: 1.25em; height: 1.25em; flex: none; }

.cup-medal {
  font-size: 0.62em;
  padding: 0.15em 0.6em 0.2em;
  border-radius: 999px;
  border: 2px solid var(--ink);
  color: var(--ink);
  background: #fff;
  text-shadow: none;
}

.cup-medal.m1 { background: #ffd84d; }
.cup-medal.m2 { background: #dfe6ef; }
.cup-medal.m3 { background: #f2b27a; }

.cup-btn {
  font-size: max(13px, calc(var(--u) * 1.25));
  white-space: nowrap;
}

.cup-btn small { font-size: 0.7em; opacity: 0.92; margin-left: 0.2em; }
.cup-btn .ico { width: 1em; height: 1em; margin-left: 0.35em; }

@media (hover: hover) {
  .course-card:hover { translate: 0 -5px; }
  .course-card:hover .thumb > svg { scale: 1.06; }
}

.course-card:active {
  translate: 0 3px;
}

.course-card .thumb {
  position: relative;
  height: calc(var(--u) * 8.8);
  min-height: 70px;
  overflow: hidden;
  border-bottom: var(--line) solid var(--ink);
  background: var(--tc, #4aa8ff);
}

.course-card .thumb > svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transition: scale 0.4s var(--out);
}

.course-card .thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 40%);
  pointer-events: none;
}

.thumb-chip {
  position: absolute;
  left: 0.55em;
  top: 0.55em;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  font-size: max(11px, calc(var(--u) * 1.05));
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 0.1em 0.6em 0.14em 0.18em;
  box-shadow: 0 2px 0 var(--ink);
}

.thumb-chip svg {
  width: 1.35em;
  height: 1.35em;
}

.course-card .info {
  padding: calc(var(--u) * 0.7) calc(var(--u) * 1) calc(var(--u) * 0.9);
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 0.35);
  flex: 1;
}

.course-card .name {
  font-size: max(16px, calc(var(--u) * 1.85));
  line-height: 1.05;
}

.course-card .blurb {
  flex: 1;
  font-size: max(11.5px, calc(var(--u) * 1.04));
  line-height: 1.3;
  color: var(--ink-soft);
  font-family: var(--body);
  font-weight: 600;
}

.course-card .best {
  display: flex;
  align-items: center;
  gap: 0.45em;
  font-size: max(12px, calc(var(--u) * 1.15));
  color: var(--purple);
}

.course-card .best.none {
  color: var(--ink-mute);
}

.course-card.locked {
  cursor: not-allowed;
  filter: saturate(0.35) brightness(0.92);
}

.course-card.locked .lock-ico {
  display: inline-grid;
  width: 1.2em;
  height: 1.2em;
}

.course-card.locked .lock-ico svg {
  width: 100%;
  height: 100%;
}

.medal {
  display: inline-grid;
  place-items: center;
  min-width: 2.4em;
  padding: 0.08em 0.45em 0.12em;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: linear-gradient(180deg, #ece6ff, #cfc3f7);
  color: var(--ink);
  font-size: 0.9em;
}

.medal.m1 { background: linear-gradient(180deg, #fff3a6, #ffc21f); }
.medal.m2 { background: linear-gradient(180deg, #ffffff, #c8d2e8); }
.medal.m3 { background: linear-gradient(180deg, #ffd9b5, #e88a45); }

.best-time {
  color: var(--ink-soft);
}

.stars {
  display: inline-flex;
  gap: 1px;
}

.stars span {
  width: 1.2em;
  height: 1.2em;
  display: inline-block;
}

.stars span svg {
  width: 100%;
  height: 100%;
  display: block;
}

.stars span:not(.on) svg {
  filter: grayscale(1);
  opacity: 0.35;
}

/* ---------------------------------------------------------------- HUD --- */
.hud {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  pointer-events: none;
}

.hud.active {
  display: block;
}

.hud-left {
  position: absolute;
  top: calc(var(--hgap) * 0.8 + var(--safe-top));
  left: calc(var(--hgap) + var(--safe-left));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: calc(var(--h) * 0.62);
}

.hud-place {
  position: relative;
  display: flex;
  align-items: baseline;
  font-size: calc(var(--h) * 6.8);
  line-height: 0.86;
  transform-origin: 30% 80%;
  --fx-fill: var(--fill-sky);
}

.place-num {
  font-size: 1em;
  --fx-stroke: 0.15em;
  --fx-drop: 0.075em;
}

.place-suffix {
  font-size: 0.44em;
  margin-left: 0.04em;
  --fx-stroke: 0.22em;
  --fx-drop: 0.13em;
}

.hud-place::before {
  content: "";
  position: absolute;
  left: 100%;
  top: -0.02em;
  width: 0.34em;
  height: 0.3em;
  margin-left: 0.04em;
  opacity: 0;
  background: center / contain no-repeat;
  pointer-events: none;
}

.hud-place.bump.up::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 21'%3E%3Cpath d='M12 2 22 19H2z' fill='%234fd85a' stroke='%232b2640' stroke-width='2.6' stroke-linejoin='round'/%3E%3C/svg%3E");
  animation: arrow-up 1.1s ease forwards;
}

.hud-place.bump.down::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 21'%3E%3Cpath d='M12 19 22 2H2z' fill='%23ff4f6a' stroke='%232b2640' stroke-width='2.6' stroke-linejoin='round'/%3E%3C/svg%3E");
  animation: arrow-down 1.1s ease forwards;
}

.hud-place.bump.up { animation: place-up 0.6s var(--spring); }
.hud-place.bump.down { animation: place-down 0.5s ease; }

.hud-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.34em;
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff 52%, #ece6ff);
  border: var(--hline) solid var(--ink);
  border-radius: 999px;
  padding: 0.14em 0.75em 0.18em 0.24em;
  font-size: max(13px, calc(var(--h) * 1.75));
  line-height: 1;
  box-shadow: inset 0 -3px 0 rgba(120, 100, 200, 0.16), 0 calc(var(--h) * 0.32) 0 var(--ink);
}

.hud-chip .ico {
  width: 1.32em;
  height: 1.32em;
}

.hud-lap .lap-label {
  font-size: 0.7em;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: -0.1em;
}

.hud-lap b {
  font-weight: 400;
  font-size: 1.12em;
}

.hud-lap.final b {
  color: #f0347a;
}

.hud-lap.pulse {
  animation: chip-pop 0.55s var(--spring);
}

#hud-time {
  display: inline-block;
  min-width: 4.35em;
  font-variant-numeric: tabular-nums;
}

.hud-right {
  position: absolute;
  top: calc(var(--hgap) * 0.8 + var(--safe-top));
  right: calc(var(--hgap) * 2 + max(44px, calc(var(--h) * 4.1)) + var(--safe-right));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--h) * 0.75);
}

.hud .coin-chip {
  font-size: max(14px, calc(var(--h) * 1.85));
  padding: 0.12em 0.8em 0.16em 0.16em;
}

.hud .coin-chip b {
  font-weight: 400;
  min-width: 1.1em;
  text-align: center;
}

/* item slot */
.item-slot {
  --s: calc(var(--h) * 7.2);
  position: relative;
  width: var(--s);
  height: var(--s);
  min-width: 56px;
  min-height: 56px;
}

.item-ring {
  position: absolute;
  inset: calc(var(--h) * -0.8);
  border-radius: 36%;
  overflow: hidden;
  opacity: 0;
  box-shadow: 0 0 0 2px var(--ink);
  transition: opacity 0.18s ease;
}

.item-ring::before {
  content: "";
  position: absolute;
  left: -30%;
  top: -30%;
  width: 160%;
  height: 160%;
  background: conic-gradient(#ff5f7a, #ffd23f, #4fd85a, #2fb4ff, #8a56e8, #ff5f7a);
  animation: spin 0.8s linear infinite paused;
}

.item-slot.rolling .item-ring {
  opacity: 1;
}

.item-slot.rolling .item-ring::before {
  animation-play-state: running;
}

.item-glow {
  position: absolute;
  inset: -34%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 232, 110, 0.9) 0%, rgba(255, 205, 50, 0.5) 34%, rgba(255, 190, 30, 0) 68%);
  opacity: 0;
  pointer-events: none;
}

.item-slot.has-item .item-glow {
  animation: glow 1.3s ease-in-out infinite;
}

.item-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: calc(var(--hline) * 1.12) solid var(--ink);
  border-radius: 30%;
  background: radial-gradient(circle at 50% 36%, #ffffff 0 34%, #f1ecff 62%, #d7cdfa 100%);
  box-shadow: inset 0 calc(var(--h) * -0.45) 0 rgba(110, 90, 190, 0.2), 0 calc(var(--h) * 0.45) 0 var(--ink);
}

.item-face::before {
  content: "";
  position: absolute;
  z-index: 0;
  left: 10%;
  right: 10%;
  top: 6%;
  height: 34%;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0));
}

.item-face::after {
  content: "";
  position: absolute;
  z-index: 2;
  top: -20%;
  bottom: -20%;
  left: -60%;
  width: 45%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.85) 50%, rgba(255, 255, 255, 0));
  transform: translateX(0) skewX(-18deg);
  opacity: 0;
}

.item-slot.rolling .item-face::after {
  opacity: 1;
  animation: sweep 0.55s linear infinite;
}

.item-slot.empty .item-face {
  background: radial-gradient(circle at 50% 36%, rgba(255, 255, 255, 0.82) 0 30%, rgba(236, 230, 255, 0.72) 62%, rgba(206, 194, 245, 0.7) 100%);
}

.item-slot.empty .item-inner::before {
  content: "?";
  font-size: calc(var(--s) * 0.5);
  line-height: 1;
  color: rgba(110, 90, 190, 0.32);
}

.item-inner {
  position: relative;
  z-index: 1;
  width: 82%;
  height: 82%;
  display: grid;
  place-items: center;
}

.item-inner > svg,
.item-inner > img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.item-icon-3d {
  filter: drop-shadow(0 0 1px rgba(43, 38, 64, 0.9)) drop-shadow(0 3px 0 rgba(43, 38, 64, 0.5));
}

.item-slot.rolling .item-inner {
  animation: roll 0.12s linear infinite alternate;
}

.item-slot.got .item-face { animation: slot-got 0.55s var(--spring-big); }
.item-slot.got .item-inner { animation: icon-in 0.5s var(--spring-big); }
.item-slot.used .item-face { animation: slot-used 0.35s ease; }
.item-slot.shake { animation: shake 0.4s ease; }

.item-count {
  position: absolute;
  right: -16%;
  bottom: -16%;
  z-index: 3;
  display: none;
  color: #fff;
  background: linear-gradient(180deg, #ff8cc2, #ff4f9a 60%, #e93a86);
  border: var(--hline) solid var(--ink);
  border-radius: 999px;
  font-size: max(12px, calc(var(--h) * 1.45));
  padding: 0.02em 0.45em 0.1em;
  text-shadow: 0 0.08em 0 #a81d58;
  box-shadow: 0 2px 0 var(--ink);
}

.item-count.on {
  display: block;
}

.item-count.tick {
  animation: chip-pop 0.4s var(--spring);
}

.item-name {
  position: absolute;
  right: calc(100% + var(--h) * 1.1);
  top: 50%;
  margin-top: -0.6em;
  font-size: max(13px, calc(var(--h) * 1.55));
  line-height: 1.2;
  white-space: nowrap;
  color: #fff;
  -webkit-text-stroke: 0.22em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.12em 0 var(--ink);
  opacity: 0;
  pointer-events: none;
}

.item-name.on {
  animation: item-name 1.7s var(--out) forwards;
}

.hud .pause-btn {
  position: absolute;
  top: calc(var(--hgap) * 0.8 + var(--safe-top));
  right: calc(var(--hgap) + var(--safe-right));
  width: max(44px, calc(var(--h) * 4.1));
  height: max(44px, calc(var(--h) * 4.1));
  border-width: var(--hline);
  --lip: max(3px, calc(var(--h) * 0.34));
  --amb: 0 0 0 transparent;
  font-size: max(20px, calc(var(--h) * 2.1));
  pointer-events: auto;
}

/* minimap: frosted plate (no backdrop-filter: cheap on phones) */
.minimap {
  position: absolute;
  left: calc(var(--hgap) + var(--safe-left));
  bottom: calc(var(--hgap) + var(--safe-bottom));
  width: calc(var(--h) * 13.6);
  height: calc(var(--h) * 13.6);
  min-width: 92px;
  min-height: 92px;
  border-radius: calc(var(--h) * 2.4);
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.32), rgba(255, 255, 255, 0.08) 72%),
    rgba(36, 30, 70, 0.32);
  border: max(2.5px, calc(var(--hline) * 0.85)) solid rgba(255, 255, 255, 0.82);
  box-shadow: 0 0 0 2px rgba(43, 38, 64, 0.6), 0 calc(var(--h) * 0.35) 0 rgba(43, 38, 64, 0.45);
}

/* standings: chips slide between fixed number slots */
.hud-standings {
  --row: calc(var(--h) * 3.05);
  --face: calc(var(--h) * 2.5);
  position: absolute;
  right: calc(var(--hgap) + var(--safe-right));
  top: 50%;
  width: calc(var(--h) * 5.6);
  height: calc(var(--row) * var(--n, 8));
  transform: translateY(-44%);
}

.stand-num {
  position: absolute;
  left: 0;
  top: 0;
  height: var(--row);
  display: flex;
  align-items: center;
  transform: translateY(calc(var(--row) * var(--slot, 0)));
  font-size: max(11px, calc(var(--h) * 1.45));
  color: #fff;
  -webkit-text-stroke: 0.24em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.1em 0 var(--ink);
}

.stand-row {
  position: absolute;
  right: 0;
  top: 0;
  height: var(--row);
  display: flex;
  align-items: center;
  transform: translateY(calc(var(--row) * var(--slot, 0)));
  transition: transform 0.45s var(--spring);
}

.stand-row img {
  width: var(--face);
  height: var(--face);
  display: block;
  border-radius: 50%;
  border: max(2px, calc(var(--hline) * 0.8)) solid var(--ink);
  background: var(--rc, #ffffff);
  box-shadow: 0 2px 0 var(--ink);
}

.stand-row.me {
  z-index: 2;
}

.stand-row.me img {
  width: calc(var(--face) * 1.3);
  height: calc(var(--face) * 1.3);
  border-color: #ffffff;
  box-shadow: 0 0 0 max(2px, calc(var(--hline) * 0.8)) var(--ink), 0 0 0 calc(max(2px, calc(var(--hline) * 0.8)) + 3px) #ffbe1f, 0 3px 0 calc(max(2px, calc(var(--hline) * 0.8)) + 3px) var(--ink);
}

/* intro title */
.course-title {
  position: absolute;
  left: 50%;
  top: 21%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--h) * 0.75);
  transform: translateX(-50%);
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.course-title::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 50%;
  top: 50%;
  width: 150vw;
  height: 150%;
  transform: translate(-50%, -50%) skewY(-3deg) scaleX(0);
  background: linear-gradient(90deg, rgba(36, 28, 80, 0), rgba(36, 28, 80, 0.5) 26%, rgba(36, 28, 80, 0.5) 74%, rgba(36, 28, 80, 0));
}

.course-title.on {
  opacity: 1;
}

.course-title.on::before {
  animation: band-in 0.6s var(--out) both;
}

.ct-name {
  font-size: max(30px, calc(var(--h) * 6));
  line-height: 1.05;
  --fx-fill: var(--fill-sky);
  --fx-stroke: 0.15em;
  --fx-drop: 0.08em;
}

.course-title.on .ct-name {
  animation: title-in 0.7s var(--spring) both;
}

.ct-sub {
  display: flex;
  gap: 0.5em;
}

.ct-chip {
  font-size: max(13px, calc(var(--h) * 1.6));
  color: var(--ink);
  background: linear-gradient(180deg, #ffe680, #ffc21f);
  border: var(--hline) solid var(--ink);
  border-radius: 999px;
  padding: 0.12em 0.85em 0.18em;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.55), 0 calc(var(--h) * 0.3) 0 var(--ink);
}

.course-title.on .ct-chip {
  animation: pop-up 0.5s 0.25s var(--spring) both;
}

.course-title.on .ct-chip + .ct-chip {
  animation-delay: 0.34s;
}

/* skip the course flyover (bottom right, above the touch controls) */
.intro-skip {
  position: absolute;
  right: calc(var(--h) * 3 + var(--safe-right, 0px));
  bottom: calc(var(--h) * 4 + var(--safe-bottom, 0px));
  display: none;
  align-items: center;
  gap: 0.3em;
  font-family: var(--font);
  font-size: max(15px, calc(var(--h) * 2.2));
  color: #fff;
  padding: 0.3em 0.7em 0.36em 1em;
  border: var(--hline) solid var(--ink);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(60, 44, 130, 0.82), rgba(36, 28, 80, 0.82));
  box-shadow: 0 calc(var(--h) * 0.35) 0 var(--ink);
  text-shadow: 0 0.08em 0 rgba(20, 10, 50, 0.6);
  pointer-events: auto;
  cursor: pointer;
  animation: pop-up 0.45s 0.6s var(--spring) both;
}

.intro-skip.on { display: inline-flex; }
/* touch screens: the controls own the bottom corners, so under the title */
.touch .intro-skip { right: 50%; bottom: auto; top: calc(21% + var(--h) * 19.5); translate: 50% 0; }
.touch .intro-skip:active { translate: 50% 2px; }
.intro-skip .ico { width: 1em; height: 1em; }
.intro-skip:active { translate: 0 2px; }

.ct-best { display: inline-flex; align-items: center; gap: 0.3em; }
.ct-best svg { width: 1.1em; height: 1.1em; }

/* countdown */
.countdown {
  position: absolute;
  left: 50%;
  top: 33%;
  transform: translate(-50%, -50%);
  font-size: calc(var(--h) * 15);
  line-height: 1;
  opacity: 0;
  --fx-stroke: 0.12em;
  --fx-drop: 0.06em;
}

.countdown::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 50%;
  top: 50%;
  width: 1.15em;
  height: 1.15em;
  margin: -0.575em 0 0 -0.575em;
  border-radius: 50%;
  border: 0.045em solid rgba(255, 255, 255, 0.95);
  opacity: 0;
}

.countdown.c3 { --fx-fill: linear-gradient(180deg, #ffeef0 0%, #ffa0ad 38%, #ff526c 60%, #e4294f 100%); }
.countdown.c2 { --fx-fill: linear-gradient(180deg, #fff4dc 0%, #ffcf72 38%, #ff9d22 60%, #f07400 100%); }
.countdown.c1 { --fx-fill: var(--fill-gold); }
.countdown.go { --fx-fill: var(--fill-green); font-size: calc(var(--h) * 13.5); }

.countdown.show {
  animation: count-pop 0.9s var(--out) forwards;
}

.countdown.show::before {
  animation: burst 0.65s 0.06s ease-out both;
}

/* banners: LAP 2/3, FINAL LAP!, FINISH! */
.banner {
  position: absolute;
  left: 50%;
  top: 25%;
  padding: 0.04em 0.3em;
  transform: translate(-50%, -50%);
  font-size: calc(var(--h) * 6.4);
  line-height: 1.1;
  opacity: 0;
  --fx-stroke: 0.15em;
  --fx-drop: 0.08em;
}

.banner::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: -1.4em;
  right: -1.4em;
  top: 16%;
  bottom: 4%;
  background: linear-gradient(90deg, rgba(36, 28, 80, 0), var(--band, rgba(36, 28, 80, 0.5)) 20%, var(--band, rgba(36, 28, 80, 0.5)) 80%, rgba(36, 28, 80, 0));
  transform: skewX(-14deg) scaleX(0);
}

.banner.final { --fx-fill: var(--fill-pink); --band: rgba(150, 20, 80, 0.5); }
.banner.finish { --fx-fill: var(--fill-gold); --band: rgba(110, 60, 0, 0.5); }
.banner.lap { --fx-fill: var(--fill-cyan); --band: rgba(10, 60, 130, 0.5); }

.banner.show {
  animation: banner-pop 1.8s ease forwards;
}

.banner.show::before {
  animation: band 1.8s var(--out) forwards;
}

/* toasts */
.toasts {
  position: absolute;
  left: 50%;
  top: calc(var(--hgap) * 0.8 + var(--safe-top));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--h) * 0.5);
  max-width: min(48vw, 600px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.45em;
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff 50%, #efeaff);
  border: var(--hline) solid var(--ink);
  border-radius: 999px;
  padding: 0.18em 0.95em 0.22em 0.2em;
  font-size: max(13px, calc(var(--h) * 1.55));
  line-height: 1.12;
  white-space: nowrap;
  box-shadow: inset 0 -3px 0 rgba(120, 100, 200, 0.14), 0 calc(var(--h) * 0.3) 0 var(--ink);
  animation: toast-in 2.4s var(--out) forwards;
}

.toast .t-ico {
  width: 1.65em;
  height: 1.65em;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0.2em;
  color: #fff;
  border-radius: 50%;
  border: max(2px, 0.12em) solid var(--ink);
  background: linear-gradient(180deg, #c7b6ff, #8f5cf0);
}

.toast.good { background: linear-gradient(180deg, #ffffff 45%, #e3ffe0); }
.toast.bad { background: linear-gradient(180deg, #ffffff 45%, #ffe3ea); }
.toast.good .t-ico { background: linear-gradient(180deg, #8cf07f, #2fbf45); }
.toast.bad .t-ico { background: linear-gradient(180deg, #ff9aa8, #ff4f6a); }

/* wrong way */
.wrong-way {
  position: absolute;
  left: 50%;
  top: 41%;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.12em;
  transform: translate(-50%, -50%);
  font-size: max(26px, calc(var(--h) * 4));
}

.wrong-way .ico {
  width: 1.75em;
  height: 1.75em;
  padding: 0.28em;
  color: #fff;
  border-radius: 50%;
  border: var(--hline) solid var(--ink);
  background: radial-gradient(circle at 40% 32%, #ff95a0, #ff3d55 60%, #d61f3d);
  box-shadow: 0 0.08em 0 var(--ink);
}

.wrong-way .fx-text {
  --fx-fill: var(--fill-coral);
  --fx-stroke: 0.17em;
}

.wrong-way.on {
  display: flex;
  animation: ww 0.8s ease-in-out infinite;
}

.speedlines {
  position: absolute;
  inset: -10%;
  opacity: 0;
  background: repeating-conic-gradient(from 0deg at 50% 50%, rgba(255, 255, 255, 0.55) 0deg 1.2deg, transparent 1.2deg 9deg);
  -webkit-mask-image: radial-gradient(circle at 50% 50%, transparent 34%, #000 70%);
  mask-image: radial-gradient(circle at 50% 50%, transparent 34%, #000 70%);
  transition: opacity 0.25s ease;
  animation: spin-lines 0.35s linear infinite;
  will-change: transform, opacity;
}

.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
}

/* ------------------------------------------------------ touch controls --- */
.touch-controls {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 48%;
  pointer-events: none;
}

.touch .touch-controls {
  display: block;
}

.touch .minimap {
  bottom: auto;
  top: calc(var(--h) * 15.6 + var(--safe-top));
  width: calc(var(--h) * 9.6);
  height: calc(var(--h) * 9.6);
}

/* keep the standings clear of the Item / Drift buttons */
.touch .hud-standings {
  --row: calc(var(--h) * 2.75);
  --face: calc(var(--h) * 2.3);
  top: calc(var(--h) * 13.8 + var(--safe-top));
  transform: none;
}

.touch-stick {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 52%;
  height: 100%;
  pointer-events: auto;
  touch-action: none;
}

.stick-base {
  position: absolute;
  left: calc(26px + var(--safe-left));
  bottom: calc(26px + var(--safe-bottom));
  width: 136px;
  height: 136px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.1) 0 36%, rgba(255, 255, 255, 0.3) 37% 100%);
  border: 4px solid rgba(43, 38, 64, 0.5);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.35), 0 4px 0 rgba(43, 38, 64, 0.35);
  transition: opacity 0.15s ease, scale 0.2s var(--spring);
}

.touch-stick.active .stick-base {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.18) 0 36%, rgba(255, 255, 255, 0.42) 37% 100%);
  scale: 1.04;
}

.stick-arrow {
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  margin-top: -9px;
  border-style: solid;
}

.stick-arrow.left {
  left: 10px;
  border-width: 9px 13px 9px 0;
  border-color: transparent rgba(43, 38, 64, 0.55) transparent transparent;
}

.stick-arrow.right {
  right: 10px;
  border-width: 9px 0 9px 13px;
  border-color: transparent transparent transparent rgba(43, 38, 64, 0.55);
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 30%, #ffffff 0 30%, #ece6ff 62%, #cdc1f6 100%);
  border: 4px solid var(--ink);
  box-shadow: inset 0 -5px 0 rgba(110, 90, 190, 0.25), 0 5px 0 var(--ink);
}

.touch-right {
  position: absolute;
  right: calc(14px + var(--safe-right));
  bottom: calc(16px + var(--safe-bottom));
  width: 214px;
  height: 204px;
  pointer-events: none;
}

.touch-right button {
  --c-hi: #ffc75a;
  --c: #ff9d22;
  --c-lo: #ff7f0a;
  --c-dk: #b85200;
  position: absolute;
  isolation: isolate;
  pointer-events: auto;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 50%;
  border: 4px solid var(--ink);
  color: #fff;
  line-height: 1;
  text-shadow: 0 2px 0 var(--c-dk);
  background: linear-gradient(180deg, var(--c-hi), var(--c) 52%, var(--c-lo));
  box-shadow: inset 0 -6px 0 rgba(60, 10, 70, 0.18), inset 0 3px 0 rgba(255, 255, 255, 0.5), 0 6px 0 var(--ink);
  transition: translate 0.06s ease, box-shadow 0.06s ease;
}

.touch-right button::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 18%;
  right: 18%;
  top: 7%;
  height: 38%;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.04));
}

/* generous invisible hit area */
.touch-right button::after {
  content: "";
  position: absolute;
  inset: -12px;
  border-radius: 50%;
}

.touch-right button .ico {
  width: 40%;
  height: 40%;
}

.touch-right button span {
  font-size: 0.74em;
}

.touch-right button[data-touch="drift"] {
  right: 0;
  bottom: 0;
  width: 104px;
  height: 104px;
  font-size: 22px;
}

.touch-right button[data-touch="item"] {
  --c-hi: #b593ff;
  --c: #8f5cf0;
  --c-lo: #7744dc;
  --c-dk: #47258f;
  right: 22px;
  bottom: 118px;
  width: 80px;
  height: 80px;
  font-size: 19px;
}

.touch-right button[data-touch="brake"] {
  --c-hi: #ff8cc2;
  --c: #ff5aa2;
  --c-lo: #f23a88;
  --c-dk: #a81d58;
  right: 116px;
  bottom: 6px;
  width: 66px;
  height: 66px;
  font-size: 16px;
}

/* with auto-accelerate off (Settings) a gas pedal joins the cluster */
.touch-right button[data-touch="gas"] {
  --c-hi: #9ef58f;
  --c: #55dc5e;
  --c-lo: #32c246;
  --c-dk: #177a2c;
  display: none;
  right: 112px;
  bottom: 86px;
  width: 74px;
  height: 74px;
  font-size: 17px;
}

.touch-controls.manual-gas .touch-right button[data-touch="gas"] {
  display: flex;
}

.touch-right button[data-touch="item"].has-item {
  box-shadow: inset 0 -6px 0 rgba(60, 10, 70, 0.18), inset 0 3px 0 rgba(255, 255, 255, 0.5), 0 0 0 4px #ffd23f, 0 6px 0 4px var(--ink);
  animation: ready 1s ease-in-out infinite;
}

.touch-right button.active {
  translate: 0 5px;
  box-shadow: inset 0 -3px 0 rgba(60, 10, 70, 0.18), inset 0 3px 0 rgba(255, 255, 255, 0.4), 0 1px 0 var(--ink);
}

/* ------------------------------------------------------------- modals --- */
.modal {
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: calc(var(--gap) + var(--safe-top)) calc(var(--gap) + var(--safe-right)) calc(var(--gap) + var(--safe-bottom)) calc(var(--gap) + var(--safe-left));
  background: radial-gradient(ellipse at 50% 45%, rgba(40, 26, 92, 0.34), rgba(20, 12, 52, 0.74));
}

.modal.active {
  animation: fade-in 0.22s ease both;
}

.modal.leaving {
  z-index: 39;
  animation: fade-out 0.22s ease forwards;
}

.modal-card {
  position: relative;
  width: min(calc(var(--u) * 32), 100%);
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: calc(var(--u) * 0.8);
  padding: 0 calc(var(--u) * 1.7) calc(var(--u) * 1.8);
  text-align: center;
  background: linear-gradient(180deg, #ffffff 0%, #ffffff 62%, #f3efff 100%);
  border: calc(var(--line) * 1.25) solid var(--ink);
  border-radius: calc(var(--u) * 2.3);
  box-shadow: 0 calc(var(--u) * 0.65) 0 var(--ink), 0 20px 50px rgba(20, 10, 60, 0.4);
}

.modal-card::-webkit-scrollbar {
  display: none;
}

.modal.active .modal-card {
  animation: card-in 0.5s var(--spring) both;
}

.modal.leaving .modal-card {
  animation: card-out 0.22s ease forwards;
}

.modal.active .modal-card > * {
  animation: rise-in 0.42s var(--spring) both;
}

.modal.active .modal-card > :nth-child(2) { animation-delay: 0.08s; }
.modal.active .modal-card > :nth-child(3) { animation-delay: 0.12s; }
.modal.active .modal-card > :nth-child(4) { animation-delay: 0.16s; }
.modal.active .modal-card > :nth-child(5) { animation-delay: 0.2s; }
.modal.active .modal-card > :nth-child(6) { animation-delay: 0.24s; }
.modal.active .modal-card > :nth-child(7) { animation-delay: 0.28s; }
.modal.active .modal-card > :nth-child(8) { animation-delay: 0.32s; }

.card-title {
  margin: 0 calc(var(--u) * -1.7) calc(var(--u) * 0.5);
  padding: calc(var(--u) * 1.05) calc(var(--u) * 1) calc(var(--u) * 0.95);
  font-weight: 400;
  font-size: max(24px, calc(var(--u) * 3));
  line-height: 1;
  background:
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.1) 0 12px, rgba(255, 255, 255, 0) 12px 24px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 55%),
    linear-gradient(180deg, #a77ff9, #7d47e6);
  border-bottom: var(--line) solid var(--ink);
}

.card-title .fx-text {
  --fx-fill: var(--fill-white);
  --fx-stroke: 0.2em;
  --fx-drop: 0.1em;
}

.pause-card .big-btn {
  margin-bottom: calc(var(--u) * 0.2);
}

/* ------------------------------------------------------------ results --- */
.confetti {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.confetti i {
  position: absolute;
  top: -4%;
  width: var(--w, 9px);
  height: calc(var(--w, 9px) * 0.45);
  border-radius: 2px;
  animation: confetti var(--t, 3s) var(--d, 0s) linear both;
}

.results-card {
  width: min(calc(var(--u) * 64), 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.12fr);
  grid-template-areas:
    "head table"
    "podium table"
    "reward table"
    "buttons table";
  grid-template-rows: auto 1fr auto auto;
  column-gap: calc(var(--u) * 1.7);
  row-gap: calc(var(--u) * 0.9);
  align-items: center;
  padding: calc(var(--u) * 1.5) calc(var(--u) * 1.7) calc(var(--u) * 1.7);
}

.results-card.obby {
  width: min(calc(var(--u) * 34), 100%);
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "head" "podium" "reward" "buttons";
  grid-template-rows: auto auto auto auto;
}

/* the obby card has no standings table: left in the grid with an area the
   template does not name, it opened an empty implicit column on the right
   and pushed everything left */
.results-card.obby .results-table {
  display: none;
}

.results-head {
  grid-area: head;
}

#results-title {
  margin: 0;
  display: inline-block;
  font-weight: 400;
  font-size: max(26px, calc(var(--u) * 3.7));
  line-height: 1.08;
  --fx-stroke: 0.18em;
  --fx-drop: 0.09em;
}

.results-sub {
  margin: calc(var(--u) * 0.35) 0 0;
  color: var(--ink-soft);
  font-size: max(13px, calc(var(--u) * 1.35));
}

.podium {
  grid-area: podium;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: calc(var(--u) * 0.5);
  align-self: end;
  min-height: calc(var(--u) * 13.5);
  padding-top: calc(var(--u) * 0.6);
}

.podium::after {
  content: "";
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 0;
  height: var(--line);
  border-radius: 99px;
  background: var(--ink);
}

.results-card.obby .podium {
  flex-direction: column;
  align-items: center;
  min-height: 0;
}

.results-card.obby .podium::after {
  display: none;
}

.pod {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: calc(var(--u) * 7.8);
}

.pod-face {
  position: relative;
  z-index: 1;
  width: calc(var(--u) * 5.2);
  height: calc(var(--u) * 5.2);
  border-radius: 50%;
  border: var(--line) solid var(--ink);
  background: var(--rc, #ffffff);
  box-shadow: 0 calc(var(--u) * 0.3) 0 var(--ink);
  animation: face-drop 0.6s var(--spring-big) both;
}

.pod.p1 .pod-face {
  width: calc(var(--u) * 6.4);
  height: calc(var(--u) * 6.4);
}

.pod-face img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.pod.me .pod-face {
  border-color: #ffffff;
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 7px #ffbe1f, 0 calc(var(--u) * 0.3) 0 7px var(--ink);
}

.pod-face em,
.res-row .nm em {
  font-style: normal;
  color: #fff;
  background: linear-gradient(180deg, #ffbe45, #ff8a00);
  border: 2px solid var(--ink);
  border-radius: 999px;
  text-shadow: 0 1px 0 #a24a00;
  line-height: 1.1;
}

.pod-face em {
  position: absolute;
  left: 50%;
  bottom: -0.55em;
  translate: -50% 0;
  font-size: max(10px, calc(var(--u) * 1));
  padding: 0.04em 0.5em 0.1em;
}

.pod-name {
  margin: 0.5em 0 0.3em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: max(11px, calc(var(--u) * 1.15));
  color: var(--ink);
}

.pod-block {
  width: 100%;
  display: grid;
  place-items: center;
  border: var(--line) solid var(--ink);
  border-bottom: 0;
  border-radius: calc(var(--u) * 0.9) calc(var(--u) * 0.9) 0 0;
  transform-origin: 50% 100%;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.55), inset calc(var(--u) * -0.5) 0 0 rgba(0, 0, 0, 0.08);
  animation: block-rise 0.55s var(--out) both;
}

.pod.p1 .pod-block { height: calc(var(--u) * 6.2); background: linear-gradient(180deg, #fff3a6, #ffd23f 40%, #f5a300); }
.pod.p2 .pod-block { height: calc(var(--u) * 4.4); background: linear-gradient(180deg, #ffffff, #dfe6f4 40%, #a9b7d6); }
.pod.p3 .pod-block { height: calc(var(--u) * 3.2); background: linear-gradient(180deg, #ffe3c6, #f2a66a 45%, #c9692f); }

.pod.p3 .pod-block { animation-delay: 0.2s; }
.pod.p2 .pod-block { animation-delay: 0.3s; }
.pod.p1 .pod-block { animation-delay: 0.42s; }
.pod.p3 .pod-face { animation-delay: 0.45s; }
.pod.p2 .pod-face { animation-delay: 0.55s; }
.pod.p1 .pod-face { animation-delay: 0.68s; }

.pod-block b {
  font-weight: 400;
  font-size: max(20px, calc(var(--u) * 2.9));
  line-height: 1;
  --fx-stroke: 0.2em;
  --fx-drop: 0.1em;
}

.obby-stars {
  display: flex;
  gap: calc(var(--u) * 0.4);
  justify-content: center;
}

.big-star {
  width: calc(var(--u) * 6);
  height: calc(var(--u) * 6);
  min-width: 52px;
  min-height: 52px;
  animation: star-pop 0.55s var(--spring-big) both;
  animation-delay: calc(var(--i, 1) * 150ms + 250ms);
}

.big-star:nth-child(2) {
  translate: 0 -14%;
}

.big-star svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 3px 0 rgba(43, 38, 64, 0.35));
}

.big-star:not(.on) svg {
  filter: grayscale(1) brightness(1.35);
  opacity: 0.45;
}

.obby-facts {
  display: flex;
  gap: calc(var(--u) * 0.6);
  justify-content: center;
  flex-wrap: wrap;
  margin-top: calc(var(--u) * 0.8);
}

.fact {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  color: var(--ink);
  background: #f2eeff;
  border: 2px solid #e2dbff;
  border-radius: 999px;
  padding: 0.2em 0.85em 0.24em 0.28em;
  font-size: max(14px, calc(var(--u) * 1.5));
}

.fact svg {
  width: 1.45em;
  height: 1.45em;
  color: #ffffff;
}

.fact b {
  font-weight: 400;
}

.results-table {
  grid-area: table;
  align-self: center;
  display: flex;
  flex-direction: column;
  gap: calc(var(--u) * 0.32);
  text-align: left;
}

.res-row {
  display: grid;
  grid-template-columns: calc(var(--u) * 2.2) calc(var(--u) * 2.6) minmax(0, 1fr) auto;
  gap: calc(var(--u) * 0.6);
  align-items: center;
  min-height: calc(var(--u) * 3.1);
  padding: calc(var(--u) * 0.2) calc(var(--u) * 0.9) calc(var(--u) * 0.2) calc(var(--u) * 0.3);
  border-radius: 999px;
  background: #f4f1ff;
  border: 2px solid transparent;
  font-size: max(13px, calc(var(--u) * 1.35));
  animation: row-in 0.45s var(--spring) both;
  animation-delay: calc(var(--i, 0) * 50ms + 220ms);
}

.res-row.gp {
  grid-template-columns: calc(var(--u) * 2.2) calc(var(--u) * 2.6) minmax(0, 1fr) auto auto;
}

.res-row .pos {
  display: grid;
  place-items: center;
  width: calc(var(--u) * 2.2);
  height: calc(var(--u) * 2.2);
  min-width: 20px;
  min-height: 20px;
  border-radius: 50%;
  color: var(--ink-soft);
  background: #e4ddff;
  font-size: 0.92em;
}

.res-row.m1 .pos { background: linear-gradient(180deg, #fff3a6, #ffc21f); color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.res-row.m2 .pos { background: linear-gradient(180deg, #ffffff, #c8d2e8); color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.res-row.m3 .pos { background: linear-gradient(180deg, #ffe3c6, #e88a45); color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }

.res-row img {
  width: calc(var(--u) * 2.6);
  height: calc(var(--u) * 2.6);
  min-width: 22px;
  min-height: 22px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: var(--rc, #ffffff);
}

.res-row .nm {
  display: flex;
  align-items: center;
  gap: 0.4em;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}

.res-row .nm em {
  font-size: 0.7em;
  padding: 0.02em 0.45em 0.08em;
}

.res-row.me {
  background: linear-gradient(90deg, #fff4d6, #ffe2a4);
  border-color: #ff9a1f;
  box-shadow: 0 2px 0 #d97a00;
}

.res-row .t {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  font-size: 0.92em;
}

.res-row .pts {
  color: var(--purple);
  min-width: 3.3em;
  text-align: right;
}

.res-row .pts small {
  font-size: 0.66em;
  margin-left: 0.15em;
}

.reward-row {
  grid-area: reward;
  display: flex;
  gap: calc(var(--u) * 0.9);
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.reward-chip {
  font-size: max(17px, calc(var(--u) * 2));
}

.reward-chip strong {
  font-weight: 400;
  min-width: 2.2em;
}

.results-buttons {
  grid-area: buttons;
  display: flex;
  gap: calc(var(--u) * 0.75);
  justify-content: center;
  flex-wrap: wrap;
}

.results-buttons .big-btn {
  flex: 1 1 100%;
  font-size: max(17px, calc(var(--u) * 2.05));
}

.results-buttons .mid-btn {
  flex: 1 1 0;
  max-width: calc(var(--u) * 13);
}

/* ----------------------------------------------------------- settings --- */
.settings-card {
  width: min(calc(var(--u) * 36), 100%);
}

.setting-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: calc(var(--u) * 0.9);
  font-size: max(15px, calc(var(--u) * 1.65));
  padding: calc(var(--u) * 0.42) calc(var(--u) * 0.2);
  text-align: left;
  border-bottom: 2px dashed #e4ddff;
}

.set-ico {
  --c-hi: #b593ff;
  --c-lo: #7744dc;
  width: 2.05em;
  height: 2.05em;
  padding: 0.36em;
  color: #fff;
  border-radius: 0.6em;
  border: max(2.5px, 0.12em) solid var(--ink);
  background: linear-gradient(180deg, var(--c-hi), var(--c-lo));
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45), 0 3px 0 var(--ink);
}

.set-ico[data-ico="music"] { --c-hi: #ff8cc2; --c-lo: #f23a88; }
.set-ico[data-ico="sound"] { --c-hi: #8be0ff; --c-lo: #1c9cf0; }
.set-ico[data-ico="sparkle"] { --c-hi: #b593ff; --c-lo: #7744dc; }
.set-ico[data-ico="gauge"] { --c-hi: #ffc75a; --c-lo: #ff7f0a; }

.toggle {
  --sh: inset 0 3px 0 rgba(43, 38, 64, 0.18);
  position: relative;
  width: 3.5em;
  height: 1.9em;
  font-size: inherit;
  border-radius: 999px;
  border: max(3px, 0.14em) solid var(--ink);
  background: linear-gradient(180deg, #d6d0ec, #ebe7fa);
  box-shadow: var(--sh);
  transition: background 0.2s ease, scale 0.25s var(--spring);
}

.toggle::before {
  content: "OFF";
  position: absolute;
  right: 0.5em;
  top: 50%;
  margin-top: -0.55em;
  font-size: 0.5em;
  line-height: 1.1;
  color: var(--ink-mute);
}

.toggle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0.1em;
  width: 1.42em;
  height: 1.42em;
  margin-top: -0.71em;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 30%, #ffffff 0 34%, #f1edff 70%, #d7cff6);
  border: max(2.5px, 0.12em) solid var(--ink);
  box-shadow: 0 2px 0 rgba(43, 38, 64, 0.45);
  transition: left 0.32s var(--spring);
}

.toggle.on {
  --sh: inset 0 3px 0 rgba(20, 90, 30, 0.25);
  background: linear-gradient(180deg, #7fe872, #3fcf4f 60%, #2fb845);
}

.toggle.on::before {
  content: "ON";
  right: auto;
  left: 0.6em;
  color: #fff;
  text-shadow: 0 1px 0 #1b8431;
}

.toggle.on::after {
  left: calc(100% - 1.52em);
}

.controls-help {
  display: grid;
  gap: 0.5em;
  text-align: left;
  font-size: max(12px, calc(var(--u) * 1.2));
  color: var(--ink-soft);
  background: #f6f3ff;
  border: 2px solid #e6e0ff;
  border-radius: calc(var(--u) * 1.1);
  padding: 0.7em 0.85em;
}

.controls-help p {
  margin: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3em 0.45em;
}

.controls-help b {
  min-width: 6.4em;
  color: var(--purple);
  font-weight: 400;
}

.controls-help span + b {
  min-width: 0;
  margin-left: 0.8em;
}

.controls-help span {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.28em;
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.8em;
  height: 1.8em;
  padding: 0 0.35em;
  font-family: var(--font);
  font-size: 0.88em;
  line-height: 1;
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff, #ebe6fb);
  border: 2px solid var(--ink);
  border-radius: 0.45em;
  box-shadow: 0 2px 0 var(--ink);
}

kbd.wide {
  padding: 0 0.55em;
}

.credits {
  margin: 0;
  font-size: max(10.5px, calc(var(--u) * 0.95));
  line-height: 1.35;
  color: #8a83a8;
  font-family: var(--body);
}

.ui-toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--gap) * 1.5 + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 70;
  display: none;
  max-width: calc(100vw - 32px);
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff 50%, #efeaff);
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  padding: 0.35em 1.1em 0.45em;
  font-size: max(15px, calc(var(--u) * 1.55));
  text-align: center;
  box-shadow: inset 0 -3px 0 rgba(120, 100, 200, 0.14), 0 calc(var(--u) * 0.36) 0 var(--ink);
}

.ui-toast.on {
  display: block;
  animation: toast-in 2.4s var(--out) forwards;
}

/* ----------------------------------------------- focus (pad / keyboard) --- */
button:focus {
  outline: none;
}

.big-btn:focus-visible,
.mid-btn:focus-visible,
.round-btn:focus-visible,
.big-btn.nav-focus,
.mid-btn.nav-focus,
.round-btn.nav-focus,
.course-card:focus-visible,
.course-card.nav-focus {
  box-shadow: var(--sh), 0 calc(var(--lip, 6px) * 0.5) 0 calc(var(--lip, 6px) * 0.5 + 4px) #ffffff, 0 calc(var(--lip, 6px) * 0.5) 0 calc(var(--lip, 6px) * 0.5 + 8px) var(--focus), var(--amb);
  scale: 1.045;
  z-index: 2;
}

.course-card:focus-visible,
.course-card.nav-focus {
  --lip: calc(var(--u) * 0.55);
  scale: 1.03;
}

.racer-tile:focus-visible,
.racer-tile.nav-focus {
  box-shadow: 0 0 0 4px #ffffff, 0 0 0 8px var(--focus), 0 calc(var(--u) * 0.42 + 6px) 0 2px var(--ink);
  scale: 1.06;
  z-index: 2;
}

.segmented button:focus-visible,
.segmented button.nav-focus,
.toggle:focus-visible,
.toggle.nav-focus {
  box-shadow: var(--sh, 0 0 0 transparent), 0 0 0 3px #ffffff, 0 0 0 7px var(--focus);
  scale: 1.06;
}

/* --------------------------------------------------------- keyframes --- */
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-0.8deg); }
  50% { transform: translateY(-6px) rotate(0.8deg); }
}

@keyframes shine {
  0% { transform: translateX(0) skewX(-20deg); }
  30%, 100% { transform: translateX(720%) skewX(-20deg); }
}

@keyframes cloud-drift {
  from { transform: translateX(-30vw); }
  to { transform: translateX(130vw); }
}

@keyframes stripes {
  to { background-position: 0 0, 26px 0, 0 0; }
}

@keyframes rider {
  from { transform: translateY(-74%) rotate(-2deg); }
  to { transform: translateY(-82%) rotate(2deg); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes screen-out {
  to { opacity: 0; transform: scale(1.03); }
}

@keyframes wipe-away {
  from { transform: translateX(0) skewX(-14deg); }
  to { transform: translateX(112%) skewX(-14deg); }
}

@keyframes wipe-in {
  from { transform: translateX(-112%) skewX(-14deg); }
  to { transform: translateX(0) skewX(-14deg); }
}

@keyframes kart-hop {
  from { transform: translateY(0) rotate(-3deg); }
  to { transform: translateY(-12%) rotate(3deg); }
}

@keyframes drop-in {
  from { opacity: 0; transform: translateY(-60%); }
  to { opacity: 1; transform: none; }
}

@keyframes logo-in {
  0% { opacity: 0; transform: translateY(-30%) scale(0.6); }
  60% { opacity: 1; }
  100% { opacity: 1; transform: none; }
}

@keyframes ribbon-in {
  from { opacity: 0; transform: scaleX(0.2); }
  to { opacity: 1; transform: none; }
}

@keyframes pop-up {
  from { opacity: 0; transform: translateY(40%) scale(0.7); }
  to { opacity: 1; transform: none; }
}

@keyframes tile-in {
  from { opacity: 0; transform: translateY(30%) scale(0.75); }
  to { opacity: 1; transform: none; }
}

@keyframes card-rise {
  from { opacity: 0; transform: translateY(18%) scale(0.9); }
  to { opacity: 1; transform: none; }
}

@keyframes slide-left {
  from { opacity: 0; transform: translateX(30%); }
  to { opacity: 1; transform: none; }
}

@keyframes name-swap {
  from { opacity: 0; transform: translateX(-12%); }
  to { opacity: 1; transform: none; }
}

@keyframes pip-in {
  from { transform: scaleX(0.2); opacity: 0.2; }
  to { transform: none; opacity: 1; }
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(8%) scale(0.82); }
  to { opacity: 1; transform: none; }
}

@keyframes card-out {
  to { opacity: 0; transform: scale(0.92); }
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

@keyframes row-in {
  from { opacity: 0; transform: translateX(14%); }
  to { opacity: 1; transform: none; }
}

@keyframes block-rise {
  from { transform: scaleY(0); }
  to { transform: none; }
}

@keyframes face-drop {
  0% { opacity: 0; transform: translateY(-80%) scale(0.6); }
  100% { opacity: 1; transform: none; }
}

@keyframes star-pop {
  0% { opacity: 0; transform: scale(0.2) rotate(-40deg); }
  100% { opacity: 1; transform: none; }
}

@keyframes confetti {
  0% { transform: translate3d(0, -6vh, 0) rotate(var(--r, 0deg)); }
  100% { transform: translate3d(var(--x, 0), 108vh, 0) rotate(calc(var(--r, 0deg) + 720deg)); }
}

@keyframes chip-pop {
  0% { scale: 1; }
  35% { scale: 1.2; }
  100% { scale: 1; }
}

@keyframes chip-spend {
  0%, 100% { translate: 0 0; }
  25% { translate: -5px 0; }
  75% { translate: 5px 0; }
}

@keyframes coin-flip {
  0% { transform: scaleX(1); }
  50% { transform: scaleX(-1); }
  100% { transform: scaleX(1); }
}

@keyframes place-up {
  0% { transform: scale(1); }
  30% { transform: scale(1.34) rotate(-6deg); }
  60% { transform: scale(0.95) rotate(2deg); }
  100% { transform: none; }
}

@keyframes place-down {
  0% { transform: none; }
  25% { transform: translateY(8%) scale(1.12, 0.84); }
  55% { transform: translateY(-4%) scale(0.95, 1.06); }
  100% { transform: none; }
}

@keyframes arrow-up {
  0% { opacity: 0; transform: translateY(40%) scale(0.4); }
  18% { opacity: 1; transform: translateY(-10%) scale(1.15); }
  70% { opacity: 1; transform: translateY(-25%); }
  100% { opacity: 0; transform: translateY(-60%); }
}

@keyframes arrow-down {
  0% { opacity: 0; transform: translateY(-40%) scale(0.4); }
  18% { opacity: 1; transform: translateY(10%) scale(1.15); }
  70% { opacity: 1; transform: translateY(25%); }
  100% { opacity: 0; transform: translateY(60%); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes glow {
  0%, 100% { opacity: 0.5; transform: scale(0.88); }
  50% { opacity: 1; transform: scale(1.05); }
}

@keyframes sweep {
  from { transform: translateX(0) skewX(-18deg); }
  to { transform: translateX(380%) skewX(-18deg); }
}

@keyframes roll {
  from { transform: translateY(-7%) scale(0.92); }
  to { transform: translateY(7%) scale(0.92); }
}

@keyframes slot-got {
  0% { transform: scale(1); }
  30% { transform: scale(1.2) rotate(-4deg); }
  60% { transform: scale(0.95) rotate(2deg); }
  100% { transform: none; }
}

@keyframes icon-in {
  0% { transform: scale(0.2) rotate(-30deg); }
  100% { transform: none; }
}

@keyframes slot-used {
  0% { transform: scale(0.86); }
  100% { transform: none; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px) rotate(-6deg); }
  75% { transform: translateX(6px) rotate(6deg); }
}

@keyframes item-name {
  0% { opacity: 0; transform: translateX(14px) scale(0.8); }
  12% { opacity: 1; transform: none; }
  78% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateX(-8px); }
}

@keyframes band-in {
  from { transform: translate(-50%, -50%) skewY(-3deg) scaleX(0); }
  to { transform: translate(-50%, -50%) skewY(-3deg) scaleX(1); }
}

@keyframes title-in {
  0% { opacity: 0; transform: translateX(-30%) scale(0.7); }
  100% { opacity: 1; transform: none; }
}

@keyframes count-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(2.4); }
  16% { opacity: 1; transform: translate(-50%, -50%) scale(0.9); }
  28% { transform: translate(-50%, -50%) scale(1.06); }
  40% { transform: translate(-50%, -50%) scale(1); }
  74% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.82); }
}

@keyframes burst {
  0% { opacity: 0.95; transform: scale(0.3); }
  100% { opacity: 0; transform: scale(1.6); }
}

@keyframes banner-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(-6deg); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(2deg); }
  22% { transform: translate(-50%, -50%) scale(1) rotate(0); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(1); }
}

@keyframes band {
  0% { transform: skewX(-14deg) scaleX(0); }
  16% { transform: skewX(-14deg) scaleX(1); }
  100% { transform: skewX(-14deg) scaleX(1); }
}

@keyframes toast-in {
  0% { opacity: 0; transform: translateY(-14px) scale(0.7); }
  9% { opacity: 1; transform: translateY(0) scale(1.06); }
  15% { transform: scale(1); }
  84% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-8px) scale(0.96); }
}

@keyframes ww {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.08); }
}

@keyframes spin-lines {
  from { transform: rotate(0deg); }
  to { transform: rotate(6deg); }
}

@keyframes ready {
  0%, 100% { scale: 1; }
  50% { scale: 1.07; }
}

@keyframes fade-hold {
  0% { opacity: 0; }
  10% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------------------------------------------------- short landscape --- */
@media (max-height: 520px) and (orientation: landscape) {
  .title-buttons .big-btn { min-width: calc(var(--u) * 13); }
  .racer-grid { --tile: clamp(52px, calc(var(--u) * 8.6), 120px); }
  .racer-tile .tile-name { display: none; }
  .racer-card { gap: calc(var(--u) * 0.45); }
  .racer-tagline { display: none; }
  .course-card .blurb { display: none; }
  .course-card .thumb { min-height: 56px; height: calc(var(--u) * 7.4); }
  .modal-card { gap: calc(var(--u) * 0.6); }
  .podium { min-height: calc(var(--u) * 11); }
  .touch .hud-standings { display: none; }
  .loading-tip { display: none; }
  .touch .controls-help { display: none; }
  .setting-row { padding: calc(var(--u) * 0.25) calc(var(--u) * 0.2); }
  .card-title { padding: calc(var(--u) * 0.7) calc(var(--u) * 1) calc(var(--u) * 0.6); }
}

@media (max-height: 420px) and (orientation: landscape) {
  .touch-controls { height: 62%; }
  .stick-base { width: 116px; height: 116px; bottom: calc(14px + var(--safe-bottom)); }
  .touch-right { transform: scale(0.82); transform-origin: bottom right; }
  .touch .minimap { display: none; }
  .hud-standings { display: none; }
}

/* ------------------------------------------------------------ portrait --- */
@media (orientation: portrait) {
  .title-top { padding-top: calc(var(--gap) + max(46px, calc(var(--u) * 4.2)) + 4px); }
  .title-logo-wrap { width: min(calc(var(--u) * 46), 90vw); }
  .title-tagline { margin-top: calc(var(--u) * 0.5); }
  .title-tagline span { font-size: max(12px, min(calc(var(--u) * 1.3), 3.65vw)); padding: 0.3em 0.9em 0.36em; }
  .title-buttons { gap: calc(var(--u) * 1); }
  .title-buttons .big-btn { min-width: 0; width: min(42vw, 210px); font-size: max(22px, min(calc(var(--u) * 2.7), 8vw)); }

  .racer-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto auto; gap: calc(var(--u) * 0.9); }
  .racer-grid { grid-row: 2; --tile: auto; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: calc(var(--u) * 0.7); justify-content: stretch; }
  .racer-card { grid-row: 3; padding: 0 calc(var(--u) * 1.1) calc(var(--u) * 1.1); gap: calc(var(--u) * 0.5); }
  .racer-card-head { margin: 0 calc(var(--u) * -1.1); padding: calc(var(--u) * 0.7) calc(var(--u) * 1.1) calc(var(--u) * 0.6); display: flex; align-items: center; justify-content: space-between; gap: 0.6em; }
  .racer-species { margin: 0; }
  .racer-tile .tile-name { font-size: max(10px, calc(var(--u) * 1)); }
  .stat { grid-template-columns: auto calc(var(--u) * 6) 1fr; }
  .screen.active .racer-card { animation-name: rise-in; }

  .panel-header h2 { font-size: max(20px, min(calc(var(--u) * 2.5), 6.4vw)); }
  .option-row { gap: calc(var(--u) * 0.7); }
  .segmented button { font-size: max(13px, min(calc(var(--u) * 1.35), 3.8vw)); padding: 0.42em 0.75em 0.48em 0.55em; }
  .course-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; gap: calc(var(--u) * 0.9); }
  .course-card .thumb { height: calc(var(--u) * 7.6); }
  .course-card .name { font-size: max(15px, calc(var(--u) * 1.55)); }
  .course-card .blurb { font-size: max(11px, calc(var(--u) * 0.98)); }
  .course-grid.cups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cup-btn small { display: none; }
  .course-grid.obby { grid-template-columns: minmax(0, 1fr); }
  .course-grid.obby .course-card { flex-direction: row; }
  .course-grid.obby .course-card .thumb { width: 40%; height: auto; min-height: 96px; border-bottom: 0; border-right: var(--line) solid var(--ink); flex: none; }

  .hud-standings { --row: calc(var(--h) * 3.3); --face: calc(var(--h) * 2.8); top: calc(var(--h) * 31 + var(--safe-top)); transform: none; width: calc(var(--h) * 6); }
  .toasts { top: calc(var(--h) * 15.8 + var(--safe-top)); max-width: 50vw; }
  .toast { white-space: normal; text-align: left; }
  .touch .toasts { max-width: 48vw; }
  .touch .hud-standings { --row: calc(var(--h) * 3.1); --face: calc(var(--h) * 2.6); top: calc(var(--h) * 31 + var(--safe-top)); }
  .touch .minimap { top: calc(var(--h) * 15.6 + var(--safe-top)); }
  .touch-controls { height: 40%; }
  .course-title { top: 31%; }
  .ct-name { font-size: max(26px, min(calc(var(--h) * 6), 9.4vw)); }
  .banner { top: 37%; font-size: max(30px, min(calc(var(--h) * 6.4), 10.5vw)); }
  .countdown { top: 36%; }
  .wrong-way { top: 47%; }
  .controls-help b { min-width: 5.3em; }

  /* single column: compact podium + rows so the card fits without scrolling */
  .results-card { grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "podium" "table" "reward" "buttons"; grid-template-rows: auto auto auto auto auto; row-gap: calc(var(--u) * 0.6); padding: calc(var(--u) * 1.2) calc(var(--u) * 1.3) calc(var(--u) * 1.4); }
  .podium { min-height: 0; padding-top: 0; }
  .pod-face { width: calc(var(--u) * 4.6); height: calc(var(--u) * 4.6); }
  .pod.p1 .pod-face { width: calc(var(--u) * 5.4); height: calc(var(--u) * 5.4); }
  .pod.p1 .pod-block { height: calc(var(--u) * 5.2); }
  .pod.p2 .pod-block { height: calc(var(--u) * 3.8); }
  .pod.p3 .pod-block { height: calc(var(--u) * 2.8); }
  .pod-name { margin: 0.35em 0 0.2em; }
  .results-table { gap: calc(var(--u) * 0.25); }
  .res-row { min-height: 0; padding-top: 2px; padding-bottom: 2px; font-size: max(13px, calc(var(--u) * 1.25)); }
  .res-row img { width: calc(var(--u) * 2.3); height: calc(var(--u) * 2.3); min-width: 20px; min-height: 20px; }
  .res-row .pos { width: calc(var(--u) * 2); height: calc(var(--u) * 2); min-width: 18px; min-height: 18px; }
}

@media (orientation: portrait) and (max-height: 700px) {
  .racer-tile .tile-name { display: none; }
  .racer-card .racer-tagline { display: none; }
  .pod-face { width: calc(var(--u) * 3.9); height: calc(var(--u) * 3.9); }
  .pod.p1 .pod-face { width: calc(var(--u) * 4.6); height: calc(var(--u) * 4.6); }
  .pod.p1 .pod-block { height: calc(var(--u) * 4.4); }
  .pod.p2 .pod-block { height: calc(var(--u) * 3.3); }
  .pod.p3 .pod-block { height: calc(var(--u) * 2.5); }
  .pod-block b { font-size: max(18px, calc(var(--u) * 2.5)); }
}

/* ------------------------------------------------------ reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  .screen *,
  .screen,
  .modal-card,
  .loading-bar span,
  .loading-rider,
  .sky-clouds i,
  .logo-shine::before,
  .item-ring::before,
  .item-glow,
  .item-face::after,
  .item-slot,
  .item-slot *,
  .hud-place,
  .hud-place::before,
  .hud-chip,
  .chip,
  .coin-icon,
  .course-title *,
  .course-title::before,
  .wrong-way,
  .touch-right button,
  .confetti i {
    animation: none !important;
  }

  .speedlines,
  .wipe,
  .confetti {
    display: none !important;
  }

  .stand-row,
  .big-btn,
  .mid-btn,
  .round-btn,
  .racer-tile,
  .course-card,
  .toggle::after {
    transition: none !important;
  }

  .course-title::before {
    transform: translate(-50%, -50%) skewY(-3deg) scaleX(1);
  }

  .item-slot.has-item .item-glow {
    opacity: 0.75;
  }

  .countdown.show { animation: fade-hold 0.9s linear forwards; }
  .countdown.show::before { animation: none; }
  .banner.show { animation: fade-hold 1.8s linear forwards; }
  .banner.show::before { animation: none; transform: skewX(-14deg) scaleX(1); }
  .toast,
  .ui-toast.on { animation: fade-hold 2.4s linear forwards; }
  .item-name.on { animation: fade-hold 1.7s linear forwards; }
}

/* ---------------------------------------------------------- sun flare --- */
.sun-flare {
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: 0;
  z-index: 1;
}

.sun-flare i {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  will-change: transform;
}
