/* Full-screen night drive: canvas underneath, thin HUD at the corners, menu panel on the left.
   Single deliberate dark look, so there is no light variant. */
:root {
  --bg: #05060a;
  --fg: #f2f2ee;
  --dim: rgba(242, 242, 238, 0.58);
  --red: #ff2b2b;
  --gold: #d6ad6a;
  --gold-deep: #9a6a2c;
  --gold-light: #f6d9a0;
  --air: #7fd6ff;
  --ink: #0b0b0d;
  --panel: rgba(8, 9, 14, 0.72);
  --line: rgba(255, 255, 255, 0.14);
  --key: rgba(255, 255, 255, 0.06);
  --shadow: rgba(0, 0, 0, 0.7);
  --veil: rgba(5, 6, 10, 0.75);
  --touch: rgba(242, 242, 238, 0.1);
  --touch-on: rgba(242, 242, 238, 0.32);
  --font: "Chakra Petch", "Segoe UI", system-ui, sans-serif;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --left: env(safe-area-inset-left, 0px);
  --right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
}

body {
  padding-left: max(16px, var(--left));
  padding-right: max(16px, var(--right));
}

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

.hidden { display: none !important; }

kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 0.05em 0.4em;
  margin-right: 0.25em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--key);
  font: 600 0.8em var(--font);
  text-align: center;
  color: var(--fg);
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.label { font-size: 12px; letter-spacing: 0.22em; color: var(--dim); }

.hud-tl { position: absolute; top: calc(18px + var(--top)); left: calc(22px + var(--left)); }
.hud-tr { position: absolute; top: calc(18px + var(--top)); right: calc(22px + var(--right)); text-align: right; }
.score { font-size: 44px; font-weight: 700; line-height: 1; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; text-shadow: 0 2px 18px var(--shadow); }
.sub { margin-top: 6px; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.combo { margin-top: 10px; font-size: 22px; font-weight: 700; color: var(--gold); text-shadow: 0 0 14px rgba(214, 173, 106, 0.6); }
.combo .bar { display: block; width: 120px; height: 3px; margin-top: 4px; background: var(--gold); transform-origin: left; }

.lives { display: flex; gap: 6px; justify-content: flex-end; }
.life {
  width: 34px; height: 12px;
  background: linear-gradient(180deg, var(--fg), #c9c8c2);
  clip-path: polygon(0 100%, 6% 45%, 40% 0, 70% 8%, 100% 55%, 100% 100%);
  border-bottom: 2px solid var(--red);
}
.life.lost { opacity: 0.18; }

.air {
  position: absolute; top: 22%; left: 50%; transform: translateX(-50%);
  font-size: 18px; font-weight: 600; letter-spacing: 0.18em; color: var(--air);
  font-variant-numeric: tabular-nums; white-space: nowrap;
  text-shadow: 0 0 12px rgba(127, 214, 255, 0.5);
}

.hud-bottom {
  position: absolute; bottom: calc(22px + var(--bottom)); right: calc(26px + var(--right));
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
.mode { height: 16px; font-size: 13px; letter-spacing: 0.3em; color: var(--red); text-shadow: 0 0 10px rgba(255, 43, 43, 0.7); }
.speedo { display: flex; align-items: baseline; gap: 8px; text-shadow: 0 2px 20px var(--shadow); }
.speedo #speed { font-size: 64px; font-weight: 700; line-height: 0.9; min-width: 3ch; text-align: right; font-variant-numeric: tabular-nums; }
.speedo .unit { font-size: 13px; letter-spacing: 0.2em; color: var(--dim); }
.gas { width: 260px; max-width: 40vw; }
.gas-label { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; letter-spacing: 0.22em; color: var(--dim); margin-bottom: 4px; }
.gas-bar { height: 6px; background: var(--touch); border-radius: 3px; overflow: hidden; }
#gasFill { height: 100%; width: 100%; background: var(--air); box-shadow: 0 0 10px var(--air); transition: background 0.2s; }
#gasFill.low { background: var(--red); box-shadow: 0 0 10px var(--red); }

.popups {
  position: absolute; top: 30%; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.popup {
  font-size: 26px; font-weight: 700; letter-spacing: 0.06em; white-space: nowrap;
  text-shadow: 0 0 16px var(--shadow), 0 0 2px var(--bg);
  animation: pop 1.9s ease-out forwards;
}
.popup.big { font-size: 38px; color: var(--fg); }
.popup.gold { color: var(--gold); }
.popup.air { color: var(--air); font-size: 20px; }
.popup.red { color: var(--red); font-size: 40px; }
.popup.small { font-size: 18px; color: var(--dim); }
@keyframes pop {
  0% { opacity: 0; transform: translateY(14px) scale(0.85); }
  10% { opacity: 1; transform: translateY(0) scale(1.06); }
  20% { transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-26px); }
}
@keyframes fade { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }

.hint {
  position: absolute; bottom: calc(24px + var(--bottom)); left: calc(22px + var(--left));
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; color: var(--dim);
  transition: opacity 1s;
}

/* ---------- touch controls (phones and tablets only) ----------
   Left thumb: floating joystick. Right thumb: a big JUMP and a BOOST, the way Rocket League Sideswipe does it. */
.touch { display: none; --gas: 100; }
.stick-zone { position: fixed; left: 0; bottom: 0; width: 50%; height: 72%; touch-action: none; }
.stick {
  position: absolute; left: calc(92px + var(--left)); top: calc(100% - 92px - var(--bottom));
  width: 124px; height: 124px; margin: -62px 0 0 -62px;
  border: 2px solid var(--line); border-radius: 50%; background: var(--touch);
  opacity: 0.5; transition: opacity 0.15s; pointer-events: none;
}
.stick.on { opacity: 1; }
.stick-label {
  position: absolute; left: 50%; transform: translateX(-50%);
  font: 600 10px var(--font); letter-spacing: 0.16em; color: var(--dim);
}
.stick-label.up { top: -18px; }
.stick-label.down { bottom: -18px; }
.stick-knob {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px;
  border-radius: 50%; background: var(--fg); opacity: 0.85; box-shadow: 0 2px 12px var(--shadow);
}
.tbtn {
  position: fixed; display: grid; place-items: center; align-content: center; gap: 1px;
  border: 2px solid var(--line); border-radius: 50%;
  background: var(--touch); color: var(--fg);
  font: 700 11px var(--font); letter-spacing: 0.14em;
  touch-action: none; -webkit-touch-callout: none; backdrop-filter: blur(4px);
  transition: transform 0.08s, background 0.08s, opacity 0.2s;
}
.tbtn svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.tbtn small { font-size: 8px; letter-spacing: 0.1em; opacity: 0.75; }
.tboost svg { width: 26px; height: 26px; }
.tbtn.on { transform: scale(0.93); }
.tjump { width: 96px; height: 96px; right: calc(24px + var(--right)); bottom: calc(24px + var(--bottom)); color: var(--air); border-color: transparent; }
.tjump.on { background: rgba(127, 214, 255, 0.28); }
/* compressed-air gauge wrapped around JUMP */
.tjump::before {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  background: conic-gradient(var(--air) calc(var(--gas) * 1%), var(--line) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
}
.tboost { width: 70px; height: 70px; right: calc(132px + var(--right)); bottom: calc(62px + var(--bottom)); color: var(--red); }
@media (max-width: 480px) {
  .tboost { right: calc(40px + var(--right)); bottom: calc(136px + var(--bottom)); }
}
.tboost.on { background: rgba(255, 43, 43, 0.26); }
.touch.empty .tbtn { opacity: 0.45; }
.touch .tpause {
  position: fixed; top: calc(14px + var(--top)); left: 50%; transform: translateX(-50%); z-index: 5;
  width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%;
  background: var(--touch); color: var(--fg); font: 700 13px var(--font); touch-action: none;
}
.touch .tpause.on { background: var(--touch-on); }
.touch-note { display: none; font-size: 14px; color: var(--dim); line-height: 1.6; }
.touch-note b { color: var(--fg); }


/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto;
  padding-block: var(--top) var(--bottom);
  padding-left: max(16px, var(--left));
  padding-right: max(16px, var(--right));
  background: radial-gradient(ellipse at center, rgba(5,6,10,0.15), rgba(5,6,10,0.7));
}
#menu { background: linear-gradient(90deg, rgba(5,6,10,0.85) 0%, rgba(5,6,10,0.45) 45%, rgba(5,6,10,0) 70%); justify-content: flex-start; overflow-y: auto; }
#menu .panel { margin: auto 0 auto 6vw; background: none; border: none; backdrop-filter: none; padding: 0; }
.panel {
  max-width: 560px; width: 100%;
  padding: 28px 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  backdrop-filter: blur(6px);
}
.panel.small { max-width: 420px; text-align: center; margin-block: auto; }
.overlay > .loader { margin-block: auto; }
.kicker { font-size: 12px; letter-spacing: 0.32em; color: var(--gold); }
h1 {
  margin: 6px 0 4px; font-size: clamp(48px, 8vw, 96px); font-weight: 700; line-height: 0.92; letter-spacing: 0.04em;
  text-wrap: balance;
}
h1 span {
  display: block; font-size: 0.42em; letter-spacing: 0.62em;
  background: linear-gradient(90deg, var(--gold-light), var(--gold-deep));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
h2 { margin: 6px 0; font-size: 52px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tag { margin: 10px 0 18px; font-size: 17px; color: var(--dim); }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 26px; margin-bottom: 14px; font-size: 14px; }
.controls h3 { margin: 0 0 4px; font-size: 11px; letter-spacing: 0.28em; color: var(--red); font-weight: 600; }
.controls .group div { margin: 3px 0; }
.rules { font-size: 13px; color: var(--dim); line-height: 1.5; margin: 6px 0 20px; max-width: 65ch; }
.cta {
  pointer-events: auto; cursor: pointer;
  padding: 12px 34px;
  font: 700 18px var(--font); letter-spacing: 0.3em;
  color: var(--ink); background: var(--fg);
  border: none; border-radius: 6px;
  box-shadow: 0 0 0 1px var(--line), 0 8px 30px rgba(255, 43, 43, 0.25);
}
.cta small { font-size: 10px; letter-spacing: 0.2em; opacity: 0.55; margin-left: 8px; }
.cta:hover { box-shadow: 0 0 0 1px var(--fg), 0 8px 34px rgba(255, 43, 43, 0.45); }
.cta:focus-visible, .tbtn:focus-visible, .tpause:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.menu-best { margin-top: 14px; font-size: 13px; letter-spacing: 0.25em; color: var(--dim); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; margin: 16px 0 20px; font-size: 14px; text-align: left; }
.stats div { color: var(--dim); }
.stats div span { float: right; font-weight: 700; color: var(--fg); font-variant-numeric: tabular-nums; }
.credit {
  position: absolute; bottom: calc(14px + var(--bottom)); left: max(16px, 6vw, var(--left));
  right: max(16px, var(--right));
  font-size: 11px; letter-spacing: 0.12em; color: var(--dim); opacity: 0.6;
}

#loading { background: var(--bg); z-index: 10; }
.loader { font-size: 14px; letter-spacing: 0.5em; color: var(--dim); text-align: center; }

/* ---------- challenge and sharing ---------- */
.target { color: var(--gold); }
.challenge {
  margin: 0 0 16px; padding: 10px 14px; max-width: 420px;
  border: 1px solid var(--gold); border-radius: 6px;
  font-size: 15px; color: var(--fg); background: rgba(214, 173, 106, 0.08);
}
.challenge b { color: var(--gold); font-variant-numeric: tabular-nums; }
.over-challenge { margin-top: 8px; font-size: 15px; color: var(--dim); }
.over-challenge.won { color: var(--gold); }
.share { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 16px; margin: 0 0 18px; }
.share-btn {
  cursor: pointer; padding: 10px 20px;
  font: 700 14px var(--font); letter-spacing: 0.2em;
  color: var(--fg); background: transparent;
  border: 1px solid var(--gold); border-radius: 6px;
}
.share-btn:hover { background: rgba(214, 173, 106, 0.12); }
.share-link { font-size: 14px; color: var(--gold); text-underline-offset: 3px; }
.share-text {
  display: block; width: 100%; margin: 0 0 18px; padding: 8px 10px;
  font: 13px var(--font); color: var(--fg); background: var(--key);
  border: 1px solid var(--line); border-radius: 4px;
}
.share-btn:focus-visible, .share-link:focus-visible, .share-text:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.rotate-note { display: none; font-size: 14px; color: var(--air); }

/* no double-tap zoom or pull-to-refresh while playing */
html, body { touch-action: manipulation; overscroll-behavior: none; }
canvas#game, #hud { touch-action: none; }

@media (max-width: 720px) {
  #menu { display: block; background: var(--veil); }
  #menu .panel { margin: 24px auto 16px; }
  .controls { grid-template-columns: 1fr; }
  .score { font-size: 32px; }
  .speedo #speed { font-size: 46px; }
  .gas { width: 200px; }
  .hint { display: none; }
  .stats { grid-template-columns: 1fr; }
  .credit { position: static; max-width: 560px; margin: 0 auto 24px; }
}

/* landscape phones: keep the game-over card on one screen */
@media (max-height: 480px) {
  .panel { padding: 14px 20px; }
  h2 { font-size: 38px; margin: 2px 0; }
  .stats { margin: 8px 0 10px; gap: 2px 18px; font-size: 13px; }
  .share { margin-bottom: 10px; }
  .share-btn { padding: 8px 16px; }
  .cta { padding: 9px 28px; }
}

@media (prefers-reduced-motion: reduce) {
  .popup { animation: fade 1.9s linear forwards; }
}

@media (pointer: coarse) {
  .touch.on { display: block; }
  .touch-note { display: block; }
  .controls, .hint, .cta small { display: none; }
  .hud-bottom { top: calc(66px + var(--top)); bottom: auto; right: calc(22px + var(--right)); gap: 4px; }
  .speedo #speed { font-size: 36px; }
  .gas { width: 130px; }
  .hud-tl .score { font-size: 28px; }
}

@media (pointer: coarse) and (orientation: portrait) {
  .rotate-note { display: block; }
}
