*,
*::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;
}

.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;
}

.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 ---------- */

.share-row {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 14px;
}

.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;
}

/* ---------- 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;
  padding: 0 18px 26px;
  pointer-events: none;
}

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

.tbtn {
  width: 68px;
  height: 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: 88px;
  background: rgba(255, 210, 63, 0.22);
  border-color: rgba(255, 210, 63, 0.45);
}

.tbtn.small {
  width: 52px;
  height: 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;
  }
}
