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

:root {
  --ink: #f2f5f7;
  --dim: #8fa3b0;
  --accent: #ffd23f;
  --panel: rgba(12, 18, 26, 0.88);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: #0b1118;
  font-family: var(--font);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
}

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

#hud {
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  gap: 28px;
  padding: 18px 22px;
  pointer-events: none;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}

.stat {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.stat .label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
}

.stat .value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat .value small {
  font-size: 13px;
  font-weight: 500;
  color: var(--dim);
  margin-left: 2px;
}

.stat.over-par .value {
  color: #e0553c;
}

/* ---------- Mute ---------- */

#mute {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(12, 18, 26, 0.5);
  color: var(--ink);
  font-size: 16px;
  cursor: pointer;
  z-index: 3;
}

#mute:hover {
  background: rgba(12, 18, 26, 0.8);
}

/* ---------- Combo panel ---------- */

/* The multiplier, the points riding on it, and the time left to extend it.
   Without a visible timer the chain is invisible and the risk is unreadable. */
#combo {
  position: fixed;
  top: 84px;
  left: 22px;
  width: 132px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 210, 63, 0.35);
  border-radius: 10px;
  background: rgba(12, 18, 26, 0.6);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}

#combo.on {
  opacity: 1;
  transform: none;
}

.combo-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  line-height: 1;
}

#combo-mult {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
}

#combo-pts {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.combo-track {
  margin-top: 7px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}

#combo-bar {
  height: 100%;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(1);
}

/* ---------- Boost meter ---------- */

#boost {
  position: fixed;
  left: 22px;
  bottom: 26px;
  width: 30px;
  height: 128px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(12, 18, 26, 0.55);
  overflow: hidden;
  pointer-events: none;
}

#boost-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #ffd23f, #ff8a3c);
  transform-origin: bottom;
  transform: scaleY(0);
  transition: transform 0.12s linear;
}

#boost .boost-label {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%) rotate(-90deg);
  transform-origin: center;
  font-size: 8px;
  letter-spacing: 0.18em;
  color: rgba(255, 255, 255, 0.5);
}

/* The bottom-left corner belongs to the lean pad on touch, so the meter moves
   up under the mute button rather than sitting beneath a thumb. */
body.touch #boost {
  top: 64px;
  right: 16px;
  bottom: auto;
  left: auto;
  width: 24px;
  height: 96px;
}

#boost.ready {
  border-color: var(--accent);
  animation: boostReady 0.9s ease-in-out infinite;
}

#boost.firing #boost-fill {
  background: #fff;
}

@keyframes boostReady {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 210, 63, 0); }
  50% { box-shadow: 0 0 14px 2px rgba(255, 210, 63, 0.55); }
}

/* ---------- Trick toast ---------- */

#toast {
  --toast-scale: 1;
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translate(-50%, 0) scale(0.9);
  font-size: calc(30px * var(--toast-scale));
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--accent);
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.7);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

#toast.pop {
  animation: pop 1s ease-out forwards;
}

/* Losing a chain reads red, so the one bad event never looks like a reward. */
#toast.bad {
  color: #ff6a4d;
}

@keyframes pop {
  0% {
    opacity: 0;
    transform: translate(-50%, 10px) scale(0.8);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1.06);
  }
  70% {
    opacity: 1;
    transform: translate(-50%, -6px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -26px) scale(0.98);
  }
}

/* ---------- Coins ---------- */

.coin-val {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.coin-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: linear-gradient(150deg, #ffe98a, #e0a01e);
  border: 1px solid rgba(120, 80, 10, 0.55);
  flex: none;
}

/* ---------- Ghost gap ---------- */

/* Metres ahead or behind, live. A racer wants "am I winning" now, not a time
   that only resolves at the finish. */
#ghost-gap {
  position: fixed;
  top: 84px;
  right: 16px;
  display: none;
  flex-direction: column;
  align-items: flex-end;
  padding: 6px 10px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(12, 18, 26, 0.6);
  pointer-events: none;
}

#ghost-gap.on {
  display: flex;
}

#ghost-gap-v {
  font-size: 19px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

#ghost-gap small {
  font-size: 8px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
}

#ghost-gap.ahead #ghost-gap-v {
  color: #8fc45a;
}

#ghost-gap.behind #ghost-gap-v {
  color: #ff8a6a;
}

body.touch #ghost-gap {
  top: 170px;
}

/* ---------- Unlock / achievement banner ---------- */

#unlock {
  position: fixed;
  top: 12%;
  left: 50%;
  transform: translate(-50%, -8px);
  padding: 11px 22px;
  border-radius: 999px;
  border: 1px solid rgba(255, 210, 63, 0.5);
  background: rgba(12, 18, 26, 0.92);
  font-size: 16px;
  font-weight: 800;
  color: var(--accent);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
}

#unlock.show {
  animation: unlockPop 2.4s ease-out forwards;
}

@keyframes unlockPop {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(0.9); }
  10% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  85% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -10px) scale(0.98); }
}

/* ---------- Tutorial hint ---------- */

#hint {
  position: fixed;
  bottom: 16%;
  left: 50%;
  transform: translate(-50%, 8px);
  padding: 10px 18px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(12, 18, 26, 0.82);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
}

#hint.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Overlay ---------- */

#overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, rgba(10, 16, 24, 0.72), rgba(6, 10, 15, 0.94));
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

#overlay.show {
  opacity: 1;
  pointer-events: auto;
}

/* Title screen: lighten the scrim so the attract-mode ride shows through,
   dark enough at the foot that the centred panel stays readable. */
#overlay.demo {
  background: linear-gradient(180deg, rgba(8, 12, 18, 0.26), rgba(6, 10, 15, 0.66));
  backdrop-filter: blur(1.5px);
}

.panel {
  width: min(420px, 88vw);
  padding: 34px 30px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.panel.wide {
  width: min(760px, 94vw);
  padding: 24px 22px;
}

/* Only one screen is ever mounted at a time. */
.screen {
  display: none;
}

.screen.on {
  display: block;
}

/* An inactive screen must never take space. Some panels set their own display
   (e.g. .title-wide { display:flex } in the HOME FIT PASS, which lands later in
   the file at equal specificity), which would otherwise keep the title visible
   behind every other screen. Force the hidden state to win. */
.screen:not(.on) {
  display: none !important;
}

.panel h1 {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.panel h2 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.panel .tag {
  margin-top: 6px;
  color: var(--dim);
  font-size: 14px;
}

#result-body,
#over-body {
  margin-top: 16px;
  font-size: 15px;
  color: var(--ink);
  line-height: 1.7;
}

#result-body b,
#over-body b {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

#result-body small,
#over-body small {
  color: var(--dim);
  font-size: 12px;
}

.crash-line {
  color: #e0553c;
  font-weight: 600;
}

/* ---------- Result stars ---------- */

#result-stars {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 20px;
}

#result-stars:empty {
  display: none;
}

.rstar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 84px;
}

.rstar i {
  font-size: 34px;
  font-style: normal;
  color: rgba(255, 255, 255, 0.14);
  line-height: 1;
}

.rstar span {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
}

.rstar.on i {
  color: var(--accent);
  text-shadow: 0 0 18px rgba(255, 210, 63, 0.6);
  animation: starPop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) backwards;
  animation-delay: var(--d);
}

.rstar.on span {
  color: var(--ink);
}

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

/* ---------- Level select ---------- */

.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 {
  flex: 1;
  text-align: left;
}

.back {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font-size: 16px;
  cursor: pointer;
}

.back:hover {
  background: rgba(255, 255, 255, 0.12);
}

.stars-total {
  font-size: 13px;
  color: var(--dim);
}

.stars-total b {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

#level-grid {
  max-height: min(58vh, 460px);
  overflow-y: auto;
  text-align: left;
  padding-right: 6px;
}

.pack {
  margin: 14px 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
}

.pack:first-child {
  margin-top: 0;
}

.pack-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 8px;
}

.lvl {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.1s ease, border-color 0.1s ease;
}

.lvl:hover {
  background: rgba(255, 210, 63, 0.12);
  border-color: rgba(255, 210, 63, 0.4);
  transform: translateY(-2px);
}

.lvl-id {
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--dim);
}

.lvl-name {
  font-size: 13px;
  font-weight: 700;
}

.lvl-stars i {
  font-size: 11px;
  font-style: normal;
  color: rgba(255, 255, 255, 0.16);
}

.lvl-stars i.on {
  color: var(--accent);
}

.lvl-id em {
  font-style: normal;
  margin-left: 3px;
  font-size: 8px;
}

/* ---------- Garage ---------- */

#bike-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 9px;
}

.bike {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 11px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease, background 0.1s ease;
}

.bike:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 210, 63, 0.4);
}

.bike.active {
  border-color: var(--accent);
  background: rgba(255, 210, 63, 0.1);
}

.bike.locked {
  opacity: 0.55;
}

.bike.afford .bike-foot {
  color: var(--accent);
}

.bike-name {
  font-size: 14px;
  font-weight: 800;
}

.bike-name em {
  font-style: normal;
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
}

.bike-blurb {
  font-size: 11px;
  line-height: 1.4;
  color: var(--dim);
  min-height: 31px;
}

.bike-bars {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

.bar {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  background: var(--accent);
}

.bike-foot {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  color: var(--dim);
}

/* ---------- Stunt tracks ---------- */

#track-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.track-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease, background 0.1s ease;
}

.track-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 210, 63, 0.5);
  background: rgba(255, 210, 63, 0.06);
}

.track-name {
  font-size: 16px;
  font-weight: 800;
}

.track-blurb {
  font-size: 12px;
  line-height: 1.45;
  color: var(--dim);
  min-height: 34px;
}

.track-foot {
  font-size: 11px;
  font-weight: 700;
  color: var(--dim);
}

.track-foot b {
  color: var(--accent);
}

.track-stars {
  color: var(--accent);
  letter-spacing: 1px;
  font-size: 15px;
}

/* Big star row on the track-complete screen */
#over-body .track-stars {
  display: block;
  font-size: 30px;
  letter-spacing: 4px;
  margin-bottom: 8px;
}

/* ---------- Rider colours ---------- */

.swatches {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.swatch-label {
  width: 52px;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}

.swatch-row {
  display: flex;
  gap: 7px;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.16);
  cursor: pointer;
  padding: 0;
}

.swatch.on {
  border-color: #fff;
  transform: scale(1.15);
}

/* ---------- Achievements & trick book ---------- */

#ach-grid,
#book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 7px;
  max-height: 30vh;
  overflow-y: auto;
}

#book-grid {
  max-height: 56vh;
}

.ach,
.trick {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.03);
  opacity: 0.45;
}

.ach.on,
.trick.on {
  opacity: 1;
  border-color: rgba(255, 210, 63, 0.35);
  background: rgba(255, 210, 63, 0.07);
}

.ach b,
.trick b {
  font-size: 12px;
}

.ach span,
.trick-how {
  font-size: 10px;
  line-height: 1.4;
  color: var(--dim);
}

.trick-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.trick-head i {
  font-style: normal;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.panel .tag.left {
  text-align: left;
  margin-bottom: 10px;
}

.good {
  color: #8fc45a;
  font-weight: 600;
}

/* ---------- Share row ---------- */

.link {
  border: 0;
  background: none;
  color: var(--dim);
  font-family: var(--font);
  font-size: 11.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 0;
}

.link:hover {
  color: var(--accent);
}

.keys {
  margin: 22px auto 4px;
  display: grid;
  gap: 8px;
  width: fit-content;
}

.key-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--dim);
}

.key-row span {
  margin-left: 8px;
}

kbd {
  min-width: 30px;
  padding: 4px 7px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-bottom-width: 3px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}

.modes {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.modes button {
  flex: 1;
  padding: 14px;
  border: 0;
  border-radius: 10px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.modes button.primary {
  background: var(--accent);
  color: #10161d;
}

.modes button.ghost {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--ink);
}

.modes button:hover {
  filter: brightness(1.12);
  transform: translateY(-1px);
}

.modes button:active {
  transform: translateY(1px);
}

.fine {
  margin-top: 14px;
  font-size: 11.5px;
  color: #5f7280;
}

/* Hero PLAY button + stat strip on the title screen */
.hero-play {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #10161d;
  font-family: var(--font);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s ease, filter 0.12s ease;
}

.hero-play:hover {
  filter: brightness(1.12);
  transform: translateY(-1px);
}

.hero-play:active {
  transform: translateY(1px);
}

.title-stats {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--dim);
}

.title-stats b {
  color: var(--ink);
  font-weight: 700;
}

.title-stats .coin-dot {
  vertical-align: middle;
}

/* Wide title panel so all five stunt-track cards sit on one row and the whole
   menu fits without a scrollbar. Kept trim vertically by the compact rules below. */
.title-wide {
  width: min(860px, 94vw);
  max-height: 94vh;
  overflow-y: auto;
  padding: 20px 30px;
}

/* Smaller, tighter type on the busy home screen. */
.title-wide h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
}

/* Game name — the star of the title screen, sits under the studio name. */
.game-name {
  margin-top: 2px;
  font-size: 46px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--accent);
}

.title-wide .tag {
  font-size: 13px;
}

.title-wide .modes {
  margin-top: 12px;
}

.title-wide .modes button {
  padding: 11px;
  font-size: 13px;
}

.title-wide .hero-play {
  margin-top: 14px;
  padding: 13px;
  font-size: 17px;
}

.title-wide .title-stats {
  margin-top: 10px;
}

.home-section {
  margin: 12px 0 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
  text-align: left;
}

.home-section small {
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: #5f7280;
}

.home-track-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 8px;
}

/* Compact card variant for the home grid: name + best/stars only, no blurb. */
.track-card.compact {
  gap: 4px;
  padding: 10px 11px;
}

.track-card.compact .track-name {
  font-size: 13px;
}

.track-card.compact .track-foot {
  font-size: 10px;
}

/* Compact controls: three columns, small type, so it stops eating vertical space. */
.keys.compact {
  grid-template-columns: repeat(3, auto);
  justify-content: center;
  gap: 6px 20px;
  margin: 16px auto 2px;
}

.keys.compact .key-row {
  font-size: 12px;
}

.keys.compact kbd {
  min-width: 22px;
  padding: 2px 5px;
  border-bottom-width: 2px;
  font-size: 11px;
}

.title-wide .fine {
  margin-top: 10px;
}

/* ---------- Menu vs playing ---------- */

#hud,
#boost,
#combo {
  transition: opacity 0.2s ease;
}

body:not(.playing) #hud,
body:not(.playing) #boost,
body:not(.playing) #combo,
body:not(.playing) #hint {
  opacity: 0;
}

body:not(.playing) #touch {
  display: none;
}

/* ---------- Touch controls ---------- */

#touch {
  position: fixed;
  inset: auto 0 0 0;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 18px 26px;
  pointer-events: none;
}

.pad {
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

/* The left-thumb D-pad: jump (hop) on top, duck (brake) below, flip/lean on
   the sides. Grid areas mean HTML order never matters, and the empty centre
   cell keeps opposite actions a full button apart — you can roll the thumb
   between them but never hit two at once. */
.pad.dpad {
  display: grid;
  grid-template-areas:
    ".    up   ."
    "left .    right"
    ".    down .";
  gap: 8px;
  justify-items: center;
  align-items: center;
}

.dpad .tbtn {
  align-self: auto;
}

.dpad .tbtn[data-key="hop"] { grid-area: up; }
.dpad .tbtn[data-key="leanBack"] { grid-area: left; }
.dpad .tbtn[data-key="leanFwd"] { grid-area: right; }
.dpad .tbtn[data-key="brake"] { grid-area: down; }

/* Buttons size against the viewport (clamped to sane touch targets), so no
   cluster can ever outgrow a narrow phone and clip off-screen. */
.tbtn {
  width: clamp(50px, 15vw, 68px);
  height: clamp(50px, 15vw, 68px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: rgba(16, 24, 33, 0.55);
  color: var(--ink);
  font-size: 24px;
  backdrop-filter: blur(6px);
}

.tbtn.wide {
  width: clamp(62px, 19vw, 88px);
  background: rgba(255, 210, 63, 0.22);
  border-color: rgba(255, 210, 63, 0.45);
}

.tbtn.small {
  width: clamp(44px, 12vw, 52px);
  height: clamp(44px, 12vw, 52px);
  font-size: 18px;
  align-self: flex-end;
}

.pad {
  align-items: center;
}

.tbtn:active {
  background: rgba(255, 255, 255, 0.28);
}

body.touch #touch {
  display: flex;
}

@media (max-width: 520px) {
  .stat .value {
    font-size: 20px;
  }
  #toast {
    font-size: 26px;
  }
}

/* ==========================================================================
   HOME REDESIGN — kid-modern. Overrides the older homepage rules above:
   a glassy panel over the live My School demo ride, a gradient hero button,
   emoji-badged adventure cards and colourful mode cards. Everything below
   also carries the mobile pass (safe areas, dvh, tap targets).
   ========================================================================== */

:root {
  --accent2: #ff8a3c;
  --pop-pink: #ff7ab8;
  --pop-blue: #4fc3f7;
}

/* The title scrim: much lighter and warmer, so the sunny school ride behind
   it IS the background — alive beats any static image. */
#overlay.demo {
  background: linear-gradient(180deg, rgba(20, 40, 70, 0.10) 0%, rgba(10, 16, 26, 0.45) 60%, rgba(8, 12, 19, 0.72) 100%);
  backdrop-filter: blur(1px);
}

.title-wide {
  width: min(920px, 96vw);
  padding: 22px 24px 18px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(165deg, rgba(16, 24, 38, 0.82), rgba(10, 15, 24, 0.86));
  backdrop-filter: blur(14px);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.brand {
  line-height: 1.05;
}

.studio {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--dim);
}

/* The game name is the hero: a warm gradient with a slow shimmer sweep. */
.title-wide .game-name {
  margin-top: 2px;
  font-size: clamp(38px, 7vw, 52px);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(100deg, #ffd23f 20%, #ff8a3c 45%, #ff7ab8 62%, #ffd23f 85%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 6s linear infinite;
  filter: drop-shadow(0 4px 22px rgba(255, 178, 60, 0.28));
}

@keyframes shimmer {
  0% { background-position: 0% 0; }
  100% { background-position: 220% 0; }
}

/* "BMX Bike Game" descriptor inside the H1 — reads as a quiet subtitle under
   the Ridgeline wordmark, keeps the keyword visible without stealing the hero. */
.game-kind {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  -webkit-text-fill-color: var(--dim); /* opt out of the wordmark's gradient clip */
  filter: none;
  animation: none;
}

/* On-page description for crawlers & new players — visible but understated,
   tucked at the foot of the title screen. Spans the full panel width so it
   stays a few short lines and never forces the panel to scroll. */
.seo-about {
  margin-top: 10px;
  width: 100%;
  color: var(--dim);
  font-size: 10.5px;
  line-height: 1.4;
  text-align: left;
  opacity: 0.72;
}
.seo-about p { margin: 0; }
.seo-about b { color: var(--muted, var(--dim)); font-weight: 700; }

.title-wide .tag {
  margin-top: 4px;
  font-size: 13px;
}

/* Stat chips: little pills that read at a glance. */
.title-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.ts-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  font-size: 12.5px;
  color: var(--dim);
}

.ts-chip b {
  color: var(--ink);
}

/* The hero: one big friendly pill that resumes your adventure. */
.title-wide .hero-play {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(460px, 100%);
  margin: 12px auto 4px;
  padding: 13px 22px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  color: #241a05;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: none;
  box-shadow: 0 10px 28px rgba(255, 165, 50, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s cubic-bezier(0.2, 1.6, 0.4, 1), box-shadow 0.15s ease;
}

/* A shine that sweeps the button every few seconds — "press me". */
.title-wide .hero-play::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 46px;
  left: -70px;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.65), transparent);
  transform: skewX(-20deg);
  animation: shine 3.4s ease-in-out infinite;
}

@keyframes shine {
  0%, 55% { left: -70px; }
  85%, 100% { left: 120%; }
}

.title-wide .hero-play:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 14px 34px rgba(255, 165, 50, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  filter: none;
}

.title-wide .hero-play:active {
  transform: scale(0.97);
}

.hp-ic {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.16);
  font-size: 13px;
  flex: none;
}

/* Section headings with an emoji lead. */
.home-section {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 10px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ink);
}

.hs-emoji {
  font-size: 17px;
}

.home-section small {
  font-size: 11px;
  font-weight: 600;
  color: var(--dim);
}

/* ---------- Adventure cards ---------- */

.home-track-grid {
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  gap: 7px;
}

.track-card {
  position: relative;
  flex-direction: row;
  align-items: center;
  gap: 11px;
  padding: 9px 12px 9px 11px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  overflow: hidden;
  transition: transform 0.15s cubic-bezier(0.2, 1.6, 0.4, 1), border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Each world's colour washes in from the corner behind its emoji. */
.track-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(130% 110% at 0% 0%, var(--card-accent, var(--accent)) 0%, transparent 52%);
  opacity: 0.16;
  pointer-events: none;
}

.track-card:hover {
  transform: translateY(-3px) scale(1.015);
  border-color: var(--card-accent, var(--accent));
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.04));
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
}

.track-card:active {
  transform: scale(0.97);
}

.track-emoji {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 25px;
  position: relative;
}

@supports (background: color-mix(in srgb, red 50%, blue)) {
  .track-emoji {
    background: color-mix(in srgb, var(--card-accent, #ffd23f) 26%, transparent);
  }
}

.track-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  position: relative;
}

.track-name {
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  padding-right: 36px; /* clear of the absolutely-placed star row */
}

.track-blurb {
  min-height: 0;
  font-size: 11px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.track-foot {
  font-size: 10.5px;
}

.track-stars {
  position: absolute;
  top: 8px;
  right: 11px;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--accent);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}

.track-stars.free {
  color: var(--dim);
  font-size: 13px;
}

/* The big star row on the track-complete screen must stay put (it reuses the
   class) — undo the card positioning there. */
#over-body .track-stars {
  position: static;
  font-size: 30px;
  letter-spacing: 4px;
}

.track-card.compact {
  padding: 10px 11px 10px 10px;
  gap: 10px;
}

.track-card.compact .track-emoji {
  width: 40px;
  height: 40px;
  font-size: 22px;
  border-radius: 12px;
}

.track-card.compact .track-name {
  font-size: 12.5px;
}

.track-card.compact .track-foot {
  font-size: 10px;
}

/* ---------- Challenge mode cards ---------- */

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 9px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 13px 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-family: var(--font);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.2, 1.6, 0.4, 1), filter 0.15s ease, box-shadow 0.15s ease;
}

.mode-card b {
  font-size: 14px;
  font-weight: 800;
}

.mode-card small {
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.75);
}

.mc-emoji {
  font-size: 24px;
  line-height: 1.1;
}

.mc-levels {
  background: linear-gradient(150deg, rgba(102, 187, 106, 0.32), rgba(27, 94, 63, 0.4));
  border-color: rgba(102, 187, 106, 0.45);
}

.mc-endless {
  background: linear-gradient(150deg, rgba(79, 195, 247, 0.3), rgba(21, 71, 110, 0.42));
  border-color: rgba(79, 195, 247, 0.45);
}

.mc-daily {
  background: linear-gradient(150deg, rgba(149, 117, 205, 0.32), rgba(69, 39, 120, 0.42));
  border-color: rgba(149, 117, 205, 0.5);
}

.mode-card:hover {
  transform: translateY(-3px) scale(1.02);
  filter: brightness(1.15);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.3);
}

.mode-card:active {
  transform: scale(0.97);
}

/* ---------- Small stuff row ---------- */

.home-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.chip-btn {
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.chip-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 210, 63, 0.5);
  transform: translateY(-1px);
}

.chip-btn:active {
  transform: scale(0.96);
}

.title-wide .keys.compact {
  margin: 10px auto 0;
  opacity: 0.85;
}

/* Keyboard help is noise on a touchscreen. */
body.touch .keys {
  display: none;
}

/* The touch pads must never sit over a menu. The old `body:not(.playing)`
   hide rule ties on specificity with `body.touch #touch { display: flex }`
   and loses to source order — this later, more specific rule settles it. */
body.touch:not(.playing) #touch {
  display: none;
}

/* Visible focus for keyboard kids. */
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ==========================================================================
   MOBILE PASS — safe areas, dynamic viewport, tap targets, momentum scroll.
   ========================================================================== */

/* Dynamic viewport height: keeps panels clear of mobile browser chrome. */
@supports (height: 1dvh) {
  .title-wide { max-height: 94dvh; }
  .panel { max-height: 96dvh; overflow-y: auto; }
}

.title-wide,
.panel,
#level-grid,
#book-grid,
#ach-grid {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Notch / home-bar safe areas. */
#hud {
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  padding-left: calc(18px + env(safe-area-inset-left, 0px));
}

#mute {
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
}

#touch {
  padding: 0
    calc(14px + env(safe-area-inset-right, 0px))
    calc(18px + env(safe-area-inset-bottom, 0px))
    calc(14px + env(safe-area-inset-left, 0px));
}

/* Bigger tap targets on touch devices. */
body.touch .lvl {
  padding: 13px 12px;
}

body.touch .back {
  width: 42px;
  height: 42px;
}

body.touch .mode-card {
  padding: 15px 10px 14px;
}

/* Phones (portrait-ish): tighter panel, two-up adventure cards, snug hero. */
@media (max-width: 680px) {
  .title-wide {
    width: 96vw;
    padding: 16px 12px 14px;
    border-radius: 20px;
  }
  .home-track-grid {
    grid-template-columns: 1fr 1fr;
    gap: 7px;
  }
  .track-card.compact {
    padding: 9px 9px 9px 8px;
    gap: 8px;
  }
  .track-card.compact .track-emoji {
    width: 36px;
    height: 36px;
    font-size: 19px;
  }
  #track-grid {
    grid-template-columns: 1fr;
  }
  .track-card .track-blurb {
    display: none;
  }
  .mode-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .mode-card small {
    display: none;
  }
  .title-wide .hero-play {
    padding: 13px 16px;
    font-size: 15.5px;
  }
  .panel.wide {
    padding: 18px 12px;
  }
  .home-section small {
    display: none;
  }
}

/* Short landscape phones: keep the menu usable without burying the ride. */
@media (max-height: 520px) {
  .title-wide {
    padding: 12px 16px 10px;
  }
  .title-wide .game-name {
    font-size: 30px;
  }
  .title-wide .tag {
    display: none;
  }
  .title-wide .hero-play {
    margin-top: 8px;
    padding: 10px 16px;
  }
  .home-section {
    margin: 12px 0 7px;
  }
  #hint {
    bottom: 8%;
  }
}

/* Small phones in-game: tighter HUD (button sizing is handled by the clamps
   above and the orientation layouts below). */
@media (max-width: 420px) {
  #hud {
    gap: 16px;
    padding-right: 10px;
  }
}

/* ---------- Touch layout per orientation ----------
   Landscape keeps the classic single row: leans bottom-left, actions bottom-
   right — it fits with room to spare. Portrait is too narrow for six buttons
   in a row (the old layout pushed the throttle off the right edge), so the
   right hand gets a 2×2 corner cluster instead: the throttle — the button a
   thumb rests on — biggest and innermost-bottom, brake beside it, hop and
   boost on the row above. Both clusters hug the bottom corners, inside
   natural thumb arcs, and never cover the bike (it rides centre-screen). */

@media (orientation: portrait) {
  /* Right hand: boost stacked above the throttle in the corner. The throttle
     keeps its position and size — it's the button that already works. */
  .pad.right {
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
  }
  .tbtn[data-key="throttle"] {
    /* The primary button: big, round, right under the resting thumb. */
    width: clamp(64px, 19vw, 80px);
    height: clamp(64px, 19vw, 80px);
    font-size: 26px;
  }
  /* D-pad buttons: uniform, sized so the 3-wide cluster stays inside the
     bottom-left thumb arc even on 320px phones (3 × ~52px + gaps ≈ 172px). */
  .dpad .tbtn {
    width: clamp(48px, 14vw, 60px);
    height: clamp(48px, 14vw, 60px);
    font-size: 21px;
  }
}

/* ==========================================================================
   HOME FIT PASS — the whole title screen fits ONE viewport, no scrollbar.
   Every vertical size on the home panel is a clamp() against vh, so the page
   compresses smoothly on short viewports (125–150% scaled laptops, small
   windows) instead of overflowing into the panel's scroll. The Adventures
   grid is the tall item: densified to ~6-up on desktop (2 rows for 11
   worlds), and on narrow screens it becomes a 2-row sideways swipe strip
   rather than a 6-row tower. The panel keeps overflow-y:auto purely as an
   emergency valve for absurdly tiny windows — by design it never engages.
   ========================================================================== */

.title-wide {
  display: flex;
  flex-direction: column;
  width: min(1500px, 80vw);
  padding: clamp(10px, 2vh, 20px) clamp(16px, 2vw, 32px) clamp(8px, 1.6vh, 16px);
  overflow-x: hidden;
  touch-action: pan-y;
}

.studio {
  font-size: clamp(9px, 1.4vh, 11px);
}

.title-wide .game-name {
  font-size: clamp(26px, 5.6vh, 46px);
}

.title-wide .tag {
  margin-top: 2px;
  font-size: clamp(11px, 1.7vh, 13px);
}

.title-stats {
  margin-top: clamp(6px, 1.2vh, 10px);
}

.ts-chip {
  padding: clamp(3px, 0.7vh, 6px) 12px;
  font-size: clamp(11px, 1.6vh, 12.5px);
}

.title-wide .hero-play {
  margin: clamp(8px, 1.4vh, 12px) auto 2px;
  padding: clamp(9px, 1.7vh, 13px) 22px;
  font-size: clamp(14px, 2.2vh, 17px);
}

.hp-ic {
  width: clamp(22px, 3.6vh, 28px);
  height: clamp(22px, 3.6vh, 28px);
  font-size: 12px;
}

.home-section {
  margin: clamp(8px, 1.6vh, 14px) 0 clamp(5px, 1vh, 8px);
  font-size: clamp(12px, 1.8vh, 14px);
}

/* Six across the wide panel, always two rows for 11 worlds. Fixed columns
   (not auto-fill) so a wider box makes the cards wider, never adds a 7th. */
.home-track-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: clamp(5px, 1vh, 8px) 10px;
}

.track-card.compact {
  padding: clamp(6px, 1.2vh, 9px) 10px clamp(6px, 1.2vh, 9px) 9px;
  gap: 9px;
}

.track-card.compact .track-emoji {
  width: clamp(28px, 4.6vh, 38px);
  height: clamp(28px, 4.6vh, 38px);
  font-size: clamp(16px, 2.6vh, 21px);
  border-radius: 11px;
}

.track-card.compact .track-name {
  padding-right: 30px; /* the compact star row is smaller — reclaim a line */
}

.track-card.compact .track-stars {
  top: 7px;
  right: 9px;
  font-size: 11px;
}

.mode-card {
  padding: clamp(7px, 1.4vh, 12px) 10px clamp(6px, 1.2vh, 11px);
}

body.touch .mode-card {
  padding: clamp(9px, 1.8vh, 15px) 10px clamp(8px, 1.6vh, 14px);
}

.mc-emoji {
  font-size: clamp(17px, 2.8vh, 22px);
}

.mode-card b {
  font-size: clamp(12px, 1.9vh, 14px);
}

.mode-card small {
  font-size: clamp(9.5px, 1.5vh, 10.5px);
}

.home-foot {
  margin-top: clamp(7px, 1.4vh, 12px);
}

.chip-btn {
  padding: clamp(6px, 1.2vh, 9px) 15px;
  font-size: clamp(11px, 1.7vh, 12.5px);
}

.title-wide .keys.compact {
  margin: clamp(7px, 1.4vh, 14px) auto 0;
  gap: clamp(3px, 0.8vh, 6px) 18px;
}

.keys.compact .key-row {
  font-size: clamp(10px, 1.6vh, 12px);
}

.keys.compact kbd {
  min-width: 20px;
  padding: 1px 4px;
  font-size: 10.5px;
}

/* Menus that DO scroll internally (levels, garage) still pan on touch. */
.panel {
  touch-action: pan-y;
}

/* Narrow screens: the adventure grid becomes a 2-row sideways swipe strip —
   the panel keeps a fixed, short height instead of stacking 6 rows of cards.
   Overrides the earlier phone `1fr 1fr` rule by source order. */
@media (max-width: 680px) {
  .home-track-grid {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-template-rows: repeat(2, auto);
    grid-auto-columns: minmax(146px, 44vw);
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 4px;
  }
  .home-track-grid .track-card {
    scroll-snap-align: start;
  }
  /* Narrow swipe cards wrap their names anyway — give the star row room. */
  .track-card.compact .track-name {
    padding-right: 36px;
  }
}

/* Short viewports (scaled-up laptops, small windows): drop the decorative
   tagline and the last few px of breathing room — everything else stays. */
@media (max-height: 680px) {
  .title-wide .tag {
    display: none;
  }
  .title-stats {
    margin-top: 5px;
  }
  .home-section {
    margin: 6px 0 4px;
  }
  .title-wide .keys.compact {
    margin-top: 5px;
  }
}

/* VERY short (landscape phones, tiny windows): the adventures become a
   single-row swipe strip and the keyboard legend goes — touch devices hide
   it anyway, and a window this short needs the buttons, not the manual. */
@media (max-height: 520px) {
  .home-track-grid {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-template-rows: auto;
    grid-auto-columns: minmax(146px, 190px);
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 4px;
  }
  .home-track-grid .track-card {
    scroll-snap-align: start;
  }
  .title-wide .keys {
    display: none;
  }
  .ts-chip {
    padding: 2px 10px;
  }
  .mode-card small {
    display: none;
  }
  .home-foot {
    margin-top: 5px;
  }
}

/* Short landscape (phones held sideways): size off the height so the D-pad's
   three rows stay inside the bottom-left quadrant and the track ahead stays
   visible. The throttle keeps its landscape size. */
@media (orientation: landscape) and (max-height: 460px) {
  .tbtn {
    width: clamp(48px, 16vh, 62px);
    height: clamp(48px, 16vh, 62px);
    font-size: 21px;
  }
  .tbtn.wide {
    width: clamp(60px, 20vh, 80px);
  }
  .tbtn.small {
    width: clamp(44px, 13vh, 50px);
    height: clamp(44px, 13vh, 50px);
  }
  .dpad .tbtn {
    width: clamp(42px, 13vh, 52px);
    height: clamp(42px, 13vh, 52px);
    font-size: 18px;
  }
  .pad.dpad {
    gap: 6px;
  }
  #touch {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
}

/* ==========================================================================
   MY FRIENDS — join screen + in-room roster & chat
   ========================================================================== */

/* Join screen fields */
.friends-join { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.friends-join .fld { display: flex; flex-direction: column; gap: 5px; text-align: left; }
.friends-join .fld span {
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--dim);
}
.friends-join input {
  width: 100%; padding: 11px 13px; border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14); background: rgba(255, 255, 255, 0.06);
  color: var(--ink); font-family: var(--font); font-size: 15px;
}
.friends-join input:focus {
  outline: none; border-color: var(--accent); background: rgba(255, 255, 255, 0.1);
}
.friends-join .primary { margin-top: 2px; }
.fine.bad { color: #ff8a8a; }
.fine.good { color: #86e29a; }

/* In-room HUD is inert until you've actually joined a room. */
#friends-hud { display: none; }
body.friends #friends-hud { display: block; }

/* Once you're in a room the top-right entry button is replaced by this
   "Online Now" box, and the personal ghost gap steps aside for it. */
body.friends #friends-btn { display: none !important; }
body.friends #ghost-gap { display: none !important; }

#friends-roster {
  position: fixed;
  top: 58px;
  right: 12px;
  left: auto;
  z-index: 40;
  width: min(56vw, 208px);
  max-height: 42vh;
  overflow-y: auto;
  padding: 9px 11px 10px;
  border-radius: 14px;
  background: rgba(9, 15, 24, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  pointer-events: none;
}
.fonline-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}
.fonline-head b { color: #fff; font-weight: 800; }
.fonline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #86e29a;
  box-shadow: 0 0 6px #86e29a;
}
.fonline-dot.off { background: #ff8a8a; box-shadow: none; }
.fonline-list { display: flex; flex-direction: column; gap: 6px; }
.frow {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
}
.frow .fdot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.frow em {
  margin-left: auto;
  padding-left: 6px;
  font-style: normal;
  font-weight: 600;
  font-size: 10.5px;
  color: var(--dim);
  white-space: nowrap;
}
.frow.you { color: var(--accent); }

#friends-chat {
  position: fixed; left: 12px; bottom: 12px; z-index: 40;
  width: min(78vw, 320px);
  display: flex; flex-direction: column; gap: 6px;
}
#friends-msgs {
  max-height: 30vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px; padding-right: 2px;
}
.fmsg {
  align-self: flex-start; max-width: 100%;
  padding: 6px 10px; border-radius: 12px;
  background: rgba(10, 14, 20, 0.66); border: 1px solid rgba(255, 255, 255, 0.08);
  color: #fff; font-size: 12.5px; line-height: 1.3; backdrop-filter: blur(4px);
  word-break: break-word;
}
.fmsg b { color: var(--accent); margin-right: 5px; font-weight: 800; }
.fmsg.mine {
  align-self: flex-end;
  background: rgba(255, 150, 40, 0.22); border-color: rgba(255, 180, 80, 0.4);
}
#friends-chat-form { display: flex; gap: 6px; }
#friends-chat-input {
  flex: 1; min-width: 0; padding: 9px 12px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16); background: rgba(10, 14, 20, 0.7);
  color: #fff; font-family: var(--font); font-size: 13px; backdrop-filter: blur(4px);
}
#friends-chat-input:focus { outline: none; border-color: var(--accent); }
#friends-chat-form button {
  flex: none; width: 40px; border-radius: 999px; border: 0; cursor: pointer;
  background: linear-gradient(120deg, var(--accent), var(--accent2, #ff8a3c));
  color: #241a05; font-size: 14px; font-weight: 800;
}
.friends-hud-btns { display: flex; gap: 6px; }
#friends-home,
#friends-leave {
  padding: 5px 11px; border-radius: 999px; cursor: pointer;
  background: rgba(10, 14, 20, 0.6); border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--dim); font-family: var(--font); font-size: 11px; font-weight: 700;
  backdrop-filter: blur(4px);
}
#friends-home:hover { color: #fff; border-color: rgba(255, 210, 63, 0.5); }
#friends-leave:hover { color: #fff; border-color: rgba(255, 120, 120, 0.5); }

/* On touch the D-pad owns the bottom corners — tuck chat up under the roster. */
body.touch #friends-chat { bottom: auto; top: 46px; width: min(64vw, 260px); }
/* Boost sits top-right on touch — drop the Online Now box below it. */
body.touch #friends-roster { top: 168px; right: 10px; width: min(52vw, 180px); }
body.touch #friends-msgs { max-height: 22vh; }

/* ==========================================================================
   MY FRIENDS — top-right entry button + join modal
   ========================================================================== */

/* Prominent entry, top-right on the menu, tucked left of the mute button.
   Hidden during a ride and on non-title screens. */
#friends-btn { display: none; }
body.at-title:not(.playing) #friends-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  position: fixed;
  top: 15px;
  right: 62px;
  z-index: 6;
  padding: 9px 16px 9px 13px;
  border-radius: 999px;
  cursor: pointer;
  border: 0;
  /* A deep dark-blue social gradient, distinct from the gold "Ride" button. */
  background: linear-gradient(120deg, #16337a 0%, #1e40af 50%, #2563c9 100%);
  color: #fff;
  font-family: var(--font);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.01em;
  box-shadow: 0 6px 18px rgba(20, 40, 100, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
/* The 👥 emoji renders in its own dark colour — force it to a clean white
   silhouette so it reads on the dark-blue button. */
#friends-btn .fb-ic {
  font-size: 15px;
  line-height: 1;
  filter: brightness(0) invert(1) drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}
#friends-btn:hover {
  filter: brightness(1.12);
  transform: translateY(-1px);
  box-shadow: 0 9px 24px rgba(37, 99, 201, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
#friends-btn:active { transform: scale(0.96); }
/* On phones, drop the label to a round icon so it never crowds the mute button. */
@media (max-width: 520px) {
  body.at-title:not(.playing) #friends-btn { padding: 9px 11px; right: 60px; }
  #friends-btn .fb-txt { display: none; }
}

/* Join modal — floats above everything, independent of the screen stack. */
#friends-modal { display: none; }
#friends-modal.open {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 38%, rgba(6, 12, 20, 0.62), rgba(4, 8, 14, 0.84));
  backdrop-filter: blur(5px);
  animation: fmodalIn 0.18s ease-out;
}
@keyframes fmodalIn { from { opacity: 0; } to { opacity: 1; } }

.fmodal-card {
  position: relative;
  width: min(400px, 94vw);
  padding: 28px 26px 22px;
  border-radius: 22px;
  text-align: center;
  background: linear-gradient(165deg, rgba(20, 28, 42, 0.98), rgba(11, 17, 27, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
  animation: fcardIn 0.22s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes fcardIn {
  from { transform: translateY(14px) scale(0.96); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.fmodal-x {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--dim);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}
.fmodal-x:hover { color: #fff; background: rgba(255, 255, 255, 0.12); }
.fmodal-emoji { font-size: 40px; line-height: 1; }
.fmodal-card h2 { margin-top: 8px; font-size: 22px; font-weight: 800; }
.fmodal-sub {
  margin: 6px auto 18px;
  max-width: 30ch;
  color: var(--dim);
  font-size: 13px;
  line-height: 1.45;
}
.fmodal-card .fld {
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
  margin-bottom: 12px;
}
.fmodal-card .fld span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
}
.fmodal-card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
}
.fmodal-card input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.1);
}
.fmodal-card .primary {
  width: 100%;
  margin-top: 4px;
  padding: 12px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  background: linear-gradient(120deg, var(--accent), var(--accent2, #ff8a3c));
  color: #241a05;
  font-family: var(--font);
  font-weight: 800;
  font-size: 15px;
  transition: filter 0.12s ease, transform 0.12s ease;
}
.fmodal-card .primary:hover { filter: brightness(1.06); }
.fmodal-card .primary:active { transform: scale(0.98); }
.fmodal-card .fine { margin-top: 10px; font-size: 12px; }
.fmodal-card .fine.dim { margin-top: 14px; color: #6f8494; line-height: 1.4; }

/* ---------- Ibrahim Games portal links ---------- */

a.studio { text-decoration: none; transition: color 0.15s; }
a.studio:hover { color: var(--accent); }

/* "All games" — back to the portal, top-left on the menu (mirrors Friends). */
#home-btn { display: none; }
body.at-title:not(.playing) #home-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  position: fixed;
  top: 15px;
  left: 16px;
  z-index: 6;
  padding: 9px 16px 9px 13px;
  border-radius: 999px;
  background: rgba(12, 18, 26, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #fff;
  font: 700 14px var(--font);
  text-decoration: none;
  backdrop-filter: blur(6px);
  transition: transform 0.15s, background 0.15s;
}
body.at-title:not(.playing) #home-btn:hover { background: rgba(12, 18, 26, 0.92); transform: translateY(-1px); }
#home-btn .hb-ic { font-size: 15px; line-height: 1; }
@media (max-width: 520px) {
  body.at-title:not(.playing) #home-btn { padding: 9px 11px; }
  #home-btn .hb-txt { display: none; }
}

/* Deep-link start card: one big tap target over the attract ride. */
#start-card { display: none; }
#start-card.open {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
  background: radial-gradient(circle at 50% 40%, rgba(6, 12, 20, 0.5), rgba(4, 8, 14, 0.86));
  backdrop-filter: blur(3px);
}
.sc-card {
  width: min(460px, 92vw);
  border: 0;
  border-radius: 22px;
  overflow: hidden;
  background: #121a26;
  color: var(--ink);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--accent), 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: sc-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  transition: transform 0.15s;
}
.sc-card:hover { transform: translateY(-3px) scale(1.02); }
.sc-card:active { transform: scale(0.98); }
.sc-img { display: block; aspect-ratio: 16 / 9; background: #223; }
.sc-img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.sc-body { display: flex; flex-direction: column; gap: 4px; padding: 16px 20px 20px; }
.sc-kicker { font-size: 12px; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--dim); }
.sc-title { font-size: 30px; font-weight: 800; letter-spacing: -0.01em; }
.sc-play {
  align-self: flex-start;
  margin-top: 10px;
  padding: 12px 26px;
  border-radius: 14px;
  background: var(--accent);
  color: #1b1400;
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 5px 0 #c99a00;
  animation: sc-pulse 2.2s ease-in-out infinite;
}
.sc-skip { color: var(--dim); font-size: 14px; text-decoration: underline; }
.sc-skip:hover { color: var(--ink); }
@keyframes sc-in { from { opacity: 0; transform: translateY(20px) scale(0.94); } }
@keyframes sc-pulse { 50% { transform: scale(1.06); } }
@media (prefers-reduced-motion: reduce) { .sc-card, .sc-play { animation: none; } }
.seo-about a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.seo-about a:hover { color: var(--ink); }

/* ---------- Online rooms: code + countdown, and the room notice ---------- */

.froom {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 7px;
  padding-bottom: 7px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  color: var(--dim);
}
.froom b { color: var(--accent); font-size: 12px; letter-spacing: 0.02em; }
.froom-copy {
  padding: 1px 7px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: none;
  color: var(--ink);
  font: 700 10px var(--font);
  cursor: pointer;
}
.froom-copy:hover { background: rgba(255, 255, 255, 0.1); }
.froom-time { margin-left: auto; font-weight: 700; color: var(--ink); }
.froom-time.low { color: #ff8a5c; }
a.primary { display: block; text-decoration: none; text-align: center; }
.fnote-solo {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 10px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  font: 700 14px var(--font);
  cursor: pointer;
}
.fnote-solo:hover { background: rgba(255, 255, 255, 0.13); }

/* ---------- Party (local, turn-based) ---------- */

#screen-party { width: min(460px, 92vw); }
.party-lead { margin: 6px 0 14px; color: var(--dim); font-size: 15px; line-height: 1.45; }
.party-lead b { color: var(--ink); }
.party-names { display: flex; flex-direction: column; gap: 8px; }
.party-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
}
.party-row:focus-within { border-color: var(--pc); }
.party-row i, .party-res i { width: 14px; height: 14px; flex: none; border-radius: 50%; background: var(--pc); box-shadow: 0 0 10px var(--pc); }
.party-row input {
  flex: 1;
  min-width: 0;
  padding: 9px 4px;
  border: 0;
  background: none;
  color: var(--ink);
  font: 700 17px var(--font);
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.party-x { width: 34px; height: 34px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, 0.08); color: var(--dim); font-size: 20px; cursor: pointer; }
.party-add {
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  border: 2px dashed rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  background: none;
  color: var(--dim);
  font: 700 15px var(--font);
  cursor: pointer;
}
.party-add:hover { color: var(--ink); border-color: rgba(255, 255, 255, 0.35); }
.party-go { width: 100%; margin-top: 14px; padding: 14px; font-size: 18px; }
.party-turn { padding: 12px 4px 4px; text-align: center; }
.party-count { font-size: 12px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--dim); }
.party-name {
  margin: 6px 0 4px;
  font-size: clamp(30px, 7vw, 42px);
  font-weight: 800;
  color: var(--pc);
  text-shadow: 0 0 24px color-mix(in srgb, var(--pc) 45%, transparent);
  animation: partyPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.party-pass { color: var(--dim); font-size: 16px; }
.party-pass b { color: var(--ink); }
.party-table, .party-podium { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; }
.party-res {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 15px;
  font-weight: 700;
  text-align: left;
}
.party-res span { flex: 1; }
.party-res b { color: var(--pc); }
.party-res.big { padding: 12px 14px; font-size: 18px; border-left: 4px solid var(--pc); }
.party-res.big:first-child { background: rgba(255, 210, 63, 0.12); transform: scale(1.03); }
.party-res small { color: var(--dim); font-size: 12px; min-width: 56px; text-align: right; }
.party-res .medal { flex: none; font-size: 24px; }
.party-winner {
  margin-top: 4px;
  font-size: clamp(26px, 6vw, 34px);
  font-weight: 800;
  text-align: center;
  animation: partyPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.party-winner b { color: var(--pc); }
.party-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.party-actions .ghost { width: 100%; }
.party-confetti { position: relative; height: 0; }
.party-confetti span {
  position: absolute;
  top: 0;
  left: calc(4% + var(--k) * 4.8%);
  font-size: 22px;
  animation: partyFall 1.6s ease-out calc(var(--k) * 0.05s) both;
  pointer-events: none;
}
@keyframes partyPop { from { transform: scale(0.5); opacity: 0; } }
@keyframes partyFall {
  from { transform: translateY(-30px) rotate(0); opacity: 1; }
  to { transform: translateY(260px) rotate(320deg); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .party-name, .party-winner, .party-confetti span { animation: none; }
  .party-confetti { display: none; }
}

/* Party buttons: the chunky gold "go" button and quiet secondary ones. */
#screen-party button.primary, #screen-party button.ghost {
  display: block;
  border: 0;
  border-radius: 14px;
  font-family: var(--font);
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, background 0.12s ease;
}
#screen-party button.primary {
  background: linear-gradient(120deg, #ffd23f, #ff9a3c);
  color: #241a05;
  box-shadow: 0 5px 0 #c9780f, 0 12px 28px rgba(255, 170, 60, 0.3);
}
#screen-party button.primary:hover { filter: brightness(1.06); transform: translateY(-2px); }
#screen-party button.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #c9780f; }
#screen-party button.ghost {
  padding: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-size: 15px;
}
#screen-party button.ghost:hover { background: rgba(255, 255, 255, 0.14); }
