/* Moto Rampage */
:root {
  --ink: #f4f7fb;
  --muted: #b9c6d6;
  --panel: rgba(18, 26, 36, 0.82);
  --accent: #ff7a1a;
  --accent-ink: #1b1400;
  --danger: #ff5252;
  --good: #7cff8a;
  --police: #64b5f6;
  --gutter: max(16px, env(safe-area-inset-left));
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #1b2430;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
}

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

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: none;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding: max(12px, env(safe-area-inset-top)) var(--gutter) 0;
  pointer-events: none;
  /* readable on a bright snowy sky as well as at night */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75), 0 2px 8px rgba(0, 0, 0, 0.5);
}
body[data-state="playing"] #hud,
body[data-state="paused"] #hud,
body[data-state="ending"] #hud,
body[data-state="shop"] #hud { display: grid; }

#lives {
  color: var(--danger);
  font-size: clamp(20px, 4.5vw, 28px);
  letter-spacing: 2px;
  line-height: 1;
  word-break: break-all; /* extra armour lives wrap on narrow screens */
}
#env {
  margin-top: 4px;
  font-size: 13px;
  color: var(--ink);
  white-space: nowrap;
}
#biome {
  margin-top: 2px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
#time {
  margin-top: 6px;
  font-size: clamp(15px, 3.5vw, 20px);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
#time.low { color: var(--danger); font-weight: 700; }

.hud-center { text-align: center; }
#score {
  font-size: clamp(30px, 8vw, 48px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
#best { font-size: 13px; color: var(--ink); margin-top: 2px; white-space: nowrap; }

/* Upgrade button under the score */
.hud-btn {
  pointer-events: auto;
  margin-top: 6px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  font-size: 15px;
  font-weight: 700;
  text-shadow: none;
  white-space: nowrap;
}
.hud-btn:hover { background: rgba(0, 0, 0, 0.5); }
.hud-btn .key { font-size: 12px; color: var(--muted); font-weight: 600; }
.hud-btn.can-buy { background: var(--accent); color: var(--accent-ink); animation: pulse 1.6s ease-in-out infinite; }
.hud-btn.can-buy .key { color: rgba(27, 20, 0, 0.65); }
body.touch .hud-btn .key { display: none; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 179, 0, 0.55); }
  50% { box-shadow: 0 0 0 7px rgba(255, 179, 0, 0); }
}

.hud-right {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.icon-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  font-size: 18px;
  line-height: 44px;
  text-align: center;
}
.icon-btn:hover { background: rgba(0, 0, 0, 0.5); }
.icon-btn.off { opacity: 0.45; text-decoration: line-through; }

/* Floating score text */
#popups { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }

/* Name of a newly entered biome, shown for a few seconds */
#biome-banner {
  position: fixed;
  left: 50%;
  top: max(26%, 158px); /* below the score, stage bar and Upgrade button on short screens */
  transform: translateX(-50%);
  max-width: calc(100vw - 2 * var(--gutter));
  text-align: center;
  pointer-events: none;
  opacity: 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7), 0 4px 18px rgba(0, 0, 0, 0.45);
}
.banner-name {
  font-size: clamp(26px, 6.5vw, 44px);
  font-weight: 800;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.banner-tag {
  margin-top: 2px;
  font-size: clamp(13px, 3vw, 17px);
  color: var(--ink);
}
body:not([data-state="playing"]):not([data-state="ending"]) #biome-banner { display: none; }
.popup {
  position: absolute;
  opacity: 0;
  font-size: clamp(20px, 5vw, 30px);
  font-weight: 800;
  white-space: nowrap;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
}
.popup.plus { color: var(--good); }
.popup.police { color: var(--police); font-size: clamp(26px, 6.5vw, 40px); }
.popup.minus { color: var(--danger); }
.popup.heart { color: #ff6b8a; font-size: clamp(24px, 6vw, 36px); }

/* Red flash when the rider is hit */
#damage {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(220, 0, 0, 0.75) 100%);
}

/* ---------------------------------------------------- touch controls ---- */

#touch { display: none; }
body.touch[data-state="playing"] #touch { display: block; }

#stick {
  position: fixed;
  left: var(--gutter);
  bottom: max(20px, env(safe-area-inset-bottom));
  width: clamp(120px, 34vw, 170px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.35);
  touch-action: none;
}
#stick-knob {
  position: absolute;
  left: 30%;
  top: 30%;
  width: 40%;
  height: 40%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  pointer-events: none;
}

#fire {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 8px));
  width: clamp(96px, 26vw, 130px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 112, 67, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.5);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 1px;
  touch-action: none;
}
#fire.active { background: rgba(255, 112, 67, 0.85); transform: scale(0.95); }

/* ------------------------------------------------------------ menus ---- */

#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 16, 24, 0.35);
}
#overlay[hidden] { display: none; }

.panel {
  width: min(460px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 28px 24px;
  border-radius: 20px;
  background: var(--panel);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  text-align: center;
  touch-action: pan-y; /* allow scrolling a tall panel on small screens */
}
.panel[hidden] { display: none; }

h1 {
  font-size: clamp(40px, 12vw, 64px);
  font-weight: 900;
  letter-spacing: -1px;
  line-height: 1;
}
h1 span { color: var(--accent); }
h2 { font-size: 34px; font-weight: 800; margin-bottom: 16px; }

.tagline { color: var(--muted); margin: 10px 0 18px; }

.rules {
  list-style: none;
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
  text-align: left;
  font-size: 15px;
}
.rules li { padding: 8px 12px; border-radius: 10px; background: rgba(255, 255, 255, 0.06); }
.rules b { display: inline-block; min-width: 3.4em; color: var(--accent); }

.controls { font-size: 13px; color: var(--muted); margin-bottom: 18px; line-height: 1.5; }
.touch-only { display: none; }
body.touch .touch-only { display: block; }
body.touch .kbd-only { display: none; }

.panel button {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 14px;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.1);
}
.panel button:hover { background: rgba(255, 255, 255, 0.18); }
.panel button.primary { background: var(--accent); color: var(--accent-ink); }
.panel button.primary:hover { filter: brightness(1.08); }

.best-line { margin-top: 14px; font-size: 14px; color: var(--muted); }

.result {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin: 8px 0 12px;
}
.result > div { display: flex; flex-direction: column; }
.result .label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.result span:last-child { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; }
.new-best { color: var(--accent); font-weight: 800; font-size: 18px; margin-bottom: 4px; }
.stats { color: var(--muted); font-size: 14px; margin-bottom: 8px; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; }

/* ----------------------------------------------------- upgrade menu ---- */

.panel-wide { width: min(860px, 100%); padding: 22px 20px; overflow-x: hidden; }
.panel-wide h2 { margin-bottom: 6px; }
body.touch .kbd-only-inline { display: none; }

.shop-wallet {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  gap: 4px 16px;
  margin-bottom: 14px;
  font-size: 15px;
}
.shop-wallet b { font-size: 24px; color: var(--accent); font-variant-numeric: tabular-nums; }
.shop-wallet .muted { color: var(--muted); font-size: 13px; }

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
  text-align: left;
}
.shop-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
}
.shop-card.equipped { border-color: var(--accent); background: rgba(255, 122, 26, 0.12); }
.shop-card.locked { opacity: 0.6; }
.shop-head { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.shop-key {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 12px;
  font-weight: 700;
}
body.touch .shop-key { display: none; }
.shop-tag { margin-left: auto; font-size: 12px; color: var(--accent); font-weight: 700; }
.shop-desc { font-size: 13px; color: var(--muted); }
.stat {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 6px;
  font-size: 12px;
}
.stat-label { color: var(--muted); }
.stat-bar {
  grid-column: 1 / -1;
  grid-row: 2;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.stat-fill { display: block; height: 100%; border-radius: 3px; background: var(--good); }
.stat-value { text-align: right; font-variant-numeric: tabular-nums; }
.shop-extra { justify-content: space-between; }
.panel .shop-buy { margin-top: auto; padding: 10px; font-size: 15px; }
.panel button:disabled { cursor: default; opacity: 0.55; }
.panel button:disabled:hover { background: rgba(255, 255, 255, 0.1); }

/* Landscape phones: tighter menu so more fits without scrolling */
@media (max-height: 500px) {
  .panel-wide { padding: 14px 14px; }
  .panel-wide h2 { font-size: 24px; margin-bottom: 2px; }
  .shop-wallet { margin-bottom: 8px; }
  .shop-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  #shop-extras { grid-template-columns: repeat(2, 1fr); }
  .shop-card { padding: 8px 10px; gap: 4px; }
  .shop-desc { display: none; }
  .stat-bar { display: none; }
  .shop-extra { flex-direction: row; align-items: center; }
  .shop-extra .shop-head { flex: 1; }
  .panel .shop-extra .shop-buy { width: auto; margin-top: 0; padding: 8px 14px; }
  .panel-wide > button { margin-top: 4px; padding: 10px; }

  /* title, pause and game-over panels */
  .panel { padding: 16px 20px; }
  h1 { font-size: 40px; }
  h2 { font-size: 26px; margin-bottom: 8px; }
  .tagline { margin: 4px 0 8px; }
  .rules { gap: 4px; margin-bottom: 8px; font-size: 13px; }
  .rules li { padding: 4px 10px; }
  .controls { margin-bottom: 8px; }
  .panel button { padding: 10px; margin-top: 6px; }
  .best-line { margin-top: 6px; }
}

/* ----------------------------------------------------------- stages ---- */

/* Stage progress under the credits: "Stage 1 · 1840 / 2500" and a bar */
#stage { margin: 3px auto 0; width: clamp(150px, 30vw, 220px); }
#stage-label {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.stage-bar {
  height: 6px;
  margin-top: 2px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.4);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
  overflow: hidden;
}
#stage-fill {
  width: 0;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), #ffe082);
  transition: width 0.25s ease-out;
}
#stage.endless #stage-fill { background: linear-gradient(90deg, #7c4dff, #64b5f6); }

/* Short notices (e.g. "Don't hit ambulances!") */
#toast {
  position: fixed;
  left: 50%;
  top: max(42%, 190px);
  transform: translateX(-50%);
  max-width: calc(100vw - 2 * var(--gutter));
  padding: 8px 16px;
  border-radius: 12px;
  background: rgba(10, 16, 24, 0.75);
  font-size: clamp(16px, 4vw, 22px);
  font-weight: 800;
  text-align: center;
  pointer-events: none;
  opacity: 0;
}
#toast.warn { color: #ff8a80; box-shadow: 0 0 0 2px rgba(255, 82, 82, 0.6); }
#toast.info { color: var(--ink); box-shadow: 0 0 0 2px rgba(100, 181, 246, 0.6); }
body:not([data-state="playing"]) #toast { display: none; }

.popup.ambulance { color: #ff8a80; font-size: clamp(22px, 5.5vw, 34px); }
.popup.shield { color: #7fe3ff; }
.rules b.inline { min-width: 0; }
.rules b.ambu { color: #ff5252; }

/* Title: Start (a new game) and buttons for the unlocked stages */
.start-row { display: flex; gap: 8px; align-items: stretch; }
.start-row > button { flex: 1.4; }
#title-stages { display: flex; flex: 2; gap: 8px; }
#title-stages:empty { display: none; }
.panel #title-stages button { margin-top: 10px; font-size: 15px; padding: 6px 8px; line-height: 1.2; }
#title-stages small { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }

.kicker {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 2px;
}
.next-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 4px 0 6px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  font-size: 15px;
}
.next-card .muted { color: var(--muted); font-size: 13px; }
.shop-stage {
  font-size: 14px;
  font-weight: 700;
  vertical-align: middle;
  padding: 3px 9px;
  border-radius: 8px;
  background: rgba(255, 122, 26, 0.2);
  color: var(--accent);
}
.shop-card.stage-locked { opacity: 0.5; border-style: dashed; border-color: rgba(255, 255, 255, 0.2); }
.shop-card.stage-locked .shop-tag { color: var(--muted); }

/* garage: 4 bikes in a row, 6 guns in two rows of three, 5 extras */
#shop-bikes { grid-template-columns: repeat(4, minmax(0, 1fr)); }
#shop-guns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#shop-extras { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.shop-track {
  margin: 2px 0 6px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
  text-align: left;
}
@media (max-width: 700px) {
  #shop-bikes, #shop-extras { grid-template-columns: repeat(2, 1fr); }
  #shop-guns { grid-template-columns: repeat(2, 1fr); }
}

/* Blood setting: a small toggle on the title, a full button in the pause menu */
.panel .setting {
  display: inline-block;
  width: auto;
  margin: 0 0 0 10px;
  padding: 4px 10px;
  font-size: 13px;
  border-radius: 8px;
  background: rgba(200, 30, 30, 0.35);
}
.panel .setting.off, .panel .setting-wide.off { background: rgba(255, 255, 255, 0.1); }
.panel .setting-wide { background: rgba(200, 30, 30, 0.35); }

/* Nitro button above FIRE, only once nitro is bought */
#nitro {
  display: none;
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(max(28px, calc(env(safe-area-inset-bottom) + 8px)) + clamp(96px, 26vw, 130px) + 12px);
  width: clamp(64px, 17vw, 84px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(64, 140, 255, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.4);
  font-weight: 800;
  font-size: 15px;
  touch-action: none;
  opacity: 0.55;
}
body.has-nitro #nitro { display: block; }
#nitro.ready { opacity: 1; background: rgba(64, 140, 255, 0.7); }
#nitro.active { transform: scale(0.95); }

/* Victory confetti (DOM, only while the victory panel shows) */
#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }
#confetti i {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  opacity: 0.95;
}

@media (max-height: 500px) {
  #stage { margin-top: 1px; }
  #stage-label { font-size: 12px; }
  .stage-bar { height: 5px; margin-top: 1px; }
  #toast { top: max(40%, 150px); }
  #shop-bikes { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  #shop-guns { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
  #shop-extras { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .shop-track { margin: 0 0 3px; font-size: 11px; }
  #nitro { bottom: calc(max(28px, calc(env(safe-area-inset-bottom) + 8px)) + 90px); right: calc(max(16px, env(safe-area-inset-right)) + 146px); width: 64px; }
  .shop-extra { flex-direction: column; align-items: stretch; }
  .panel .shop-extra .shop-buy { width: 100%; }
  .shop-card { padding: 6px 8px; }
  .shop-head { font-size: 13px; }
  .panel .shop-buy { font-size: 13px; padding: 7px 4px; }
  .stat { font-size: 11px; }
  .shop-stage { font-size: 12px; }
  #shop-bikes .shop-tag, #shop-guns .shop-tag { display: none; }   /* the border / button say it */
  .shop-wallet .muted { display: none; }
  .panel .shop-buy { white-space: nowrap; font-size: 12px; }
  .panel #title-stages button { margin-top: 6px; padding: 4px 6px; }
  /* title: wider panel, rules in two columns, so Start stays on screen */
  #panel-title, #panel-stage, #panel-victory { width: min(700px, 100%); }
  #panel-title .rules { grid-template-columns: 1fr 1fr; }
  #panel-title .rules li:first-child { grid-column: 1 / -1; }
  #panel-title .controls.touch-only { display: none; }
  .panel-wide h2 { font-size: 20px; }
  .next-card { padding: 6px 10px; font-size: 14px; }
  .result span:last-child { font-size: 30px; }
}
@media (max-height: 500px) and (max-width: 640px) {
  #shop-guns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
