:root {
  --bg: #0d1020;
  --panel: rgba(12, 14, 30, 0.86);
  --text: #f2f4ff;
  --muted: #a3a9d6;
  --accent: #ffd54a;
  --danger: #ff5a6e;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: relative; height: 100%; }

canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: space-around;
  padding: 12px 16px 28px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.45), transparent);
  pointer-events: none;
  z-index: 2;
}
.stat { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.label { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(255,255,255,0.75); }
.stat span:last-child {
  font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
#lives { color: var(--danger); }

#hud { align-items: center; }
.hud-btn {
  pointer-events: auto;
  width: 42px; height: 42px; border-radius: 50%;
  font-size: 22px; font-weight: 800; line-height: 1;
  color: var(--text); background: rgba(12, 14, 30, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.2);
  visibility: hidden;
}
.hud-btn:hover { background: rgba(12, 14, 30, 0.8); }
body.playing .hud-btn { visibility: visible; }
.hud-btns { display: flex; gap: 8px; }
#pause-btn { font-size: 13px; letter-spacing: -2px; }

/* desktop controls card */
.help {
  position: absolute; left: 16px; bottom: 16px; z-index: 2;
  padding: 12px 14px; border-radius: 14px;
  background: rgba(12, 14, 30, 0.6); border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 12.5px; color: rgba(255, 255, 255, 0.85); display: none; gap: 5px;
  pointer-events: none;
}
.help-title { font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; font-size: 11px; color: var(--accent); }
.help-title span { color: var(--muted); font-weight: 600; letter-spacing: 0; text-transform: none; margin-left: 6px; }
body.playing:not(.touch):not(.hide-help) .help { display: grid; }

/* menu: show the matching control list */
.controls .mob { display: none; }
body.touch .controls .mob { display: block; }
body.touch .controls .desk { display: none; }

/* mobile controls */
#touch-ui { display: none; }
body.touch.playing #touch-ui { display: block; }
.stick {
  position: absolute; z-index: 2;
  left: max(20px, env(safe-area-inset-left)); bottom: max(26px, env(safe-area-inset-bottom));
  width: 140px; height: 140px; border-radius: 50%;
  background: rgba(12, 14, 30, 0.35); border: 2px solid rgba(255, 255, 255, 0.25);
  touch-action: none;
}
.knob {
  position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px;
  border-radius: 50%; background: rgba(255, 255, 255, 0.85); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.stick-hint {
  position: absolute; left: 0; right: 0; text-align: center; font-size: 10px; font-weight: 800;
  letter-spacing: 0.12em; color: rgba(255, 255, 255, 0.7); pointer-events: none;
}
.stick-hint.up { top: 6px; }
.stick-hint.down { bottom: 6px; }
.tbtn {
  position: absolute; z-index: 2; border-radius: 50%; touch-action: none;
  color: #fff; font-weight: 900; border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(12, 14, 30, 0.45);
}
.tbtn.jump {
  right: max(22px, env(safe-area-inset-right)); bottom: max(34px, env(safe-area-inset-bottom));
  width: 104px; height: 104px; font-size: 20px; letter-spacing: 0.06em;
  background: rgba(255, 213, 74, 0.88); color: #1a1400; border-color: rgba(255, 255, 255, 0.6);
}
.tbtn.cam { right: 136px; bottom: 42px; width: 56px; height: 56px; font-size: 24px; }
.tbtn:active { transform: scale(0.94); }

button.secondary {
  display: block; margin: 12px auto 0;
  font-size: 15px; font-weight: 700; padding: 9px 30px; border-radius: 999px;
  color: var(--text); background: transparent; border: 1px solid rgba(255, 255, 255, 0.25);
}
button.secondary.hidden { display: none; }

#popup {
  position: absolute;
  top: 26%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--accent);
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  opacity: 0;
  white-space: nowrap;
  z-index: 2;
}
#popup.show { animation: pop 1.1s ease-out forwards; }
@keyframes pop {
  0%   { opacity: 0; transform: translate(-50%, 10px) scale(0.6); }
  15%  { opacity: 1; transform: translate(-50%, 0) scale(1.12); }
  30%  { transform: translate(-50%, 0) scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -24px) scale(1); }
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 8, 20, 0.45);
  backdrop-filter: blur(4px);
  z-index: 3;
  padding: 16px;
}
.overlay.hidden { display: none; }

.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 22px;
  padding: 32px 34px;
  text-align: center;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}
.panel h1 {
  font-size: 42px;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-shadow: 0 0 26px rgba(255, 213, 74, 0.4);
  margin-bottom: 10px;
}
.panel p { color: var(--muted); margin-bottom: 22px; line-height: 1.5; }

@media (min-width: 820px) {
  .overlay { justify-items: start; padding-left: 7vw; }
}
.panel { max-height: calc(100vh - 32px); overflow-y: auto; }

.setup { display: grid; gap: 12px; margin: 0 0 24px; text-align: left; }
.setup.hidden { display: none; }
.field { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 12px; }
.field-label { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
#name-input {
  font: inherit; font-size: 16px; font-weight: 700;
  padding: 9px 12px; border-radius: 10px; width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06); color: var(--text); outline: none;
}
#name-input:focus { border-color: var(--accent); }
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1; padding: 8px 0; font-size: 15px; font-weight: 700; border-radius: 10px;
  background: rgba(255, 255, 255, 0.06); color: var(--text); box-shadow: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.seg button.on { background: var(--accent); color: #1a1400; border-color: var(--accent); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 30px; height: 30px; padding: 0; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15); box-shadow: none;
}
.swatch.on { border-color: #fff; outline: 2px solid var(--accent); outline-offset: 2px; }
#rider-name { color: var(--accent); max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button.primary {
  font: inherit;
  font-size: 19px;
  font-weight: 800;
  padding: 13px 48px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #1a1400;
  cursor: pointer;
  transition: transform 0.1s ease;
  box-shadow: 0 6px 24px rgba(255, 213, 74, 0.35);
}
button { font: inherit; cursor: pointer; border: none; transition: transform 0.1s ease; }
button:hover { transform: translateY(-2px); }
button:active { transform: translateY(1px); }

.controls { margin-top: 22px; font-size: 13px; color: var(--muted); display: grid; gap: 6px; }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  margin: 0 1px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}
.touch { opacity: 0.8; }

/* phones: compact top bar */
@media (max-width: 560px) {
  #hud { padding: 8px 8px 22px; gap: 4px; justify-content: space-between; }
  .stat { min-width: 0; }
  .label { font-size: 9px; letter-spacing: 0.08em; }
  .stat span:last-child { font-size: 16px; white-space: nowrap; }
  #rider-name { max-width: 22vw; }
  .hud-btn { width: 36px; height: 36px; font-size: 18px; }
  .hud-btns { gap: 6px; }
}

.desc { font-size: 12.5px; color: var(--muted); }
.tbtn.zoom { width: 46px; height: 46px; font-size: 24px; right: 30px; }
.tbtn.zin { bottom: 210px; }
.tbtn.zout { bottom: 152px; }
