@font-face {
  font-family: Bungee;
  src: url(fonts/bungee-latin-400-normal.woff2) format('woff2');
  font-display: swap;
}
@font-face {
  font-family: Rubik;
  src: url(fonts/rubik-latin-700-normal.woff2) format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --ink: #000;
  --paper: #fff;
  --volt: #ffe12e;
  --signal: #ff5a1f;
  --sky: #1fb4ff;
  --low: #ff2e4d;
  --u: min(1vh, 0.5625vw);
  --edge: max(8px, calc(var(--u) * 2.2));
  color-scheme: light;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky);
  font-family: Rubik, system-ui, sans-serif;
  font-weight: 700;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

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

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 4px solid var(--sky); outline-offset: 3px; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0 0 auto 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding: calc(var(--edge) + env(safe-area-inset-top)) calc(var(--edge) + env(safe-area-inset-right)) 0 calc(var(--edge) + env(safe-area-inset-left));
  pointer-events: none;
  font-size: max(13px, calc(var(--u) * 3.2));
}
#hud button { pointer-events: auto; }

.charge { display: flex; align-items: center; gap: 0.3em; }
.charge .bolt {
  width: 2.2em; height: 2.2em;
  fill: var(--volt); stroke: var(--ink); stroke-width: 2; stroke-linejoin: round;
  filter: drop-shadow(2px 2px 0 var(--ink));
}
.charge .bar {
  width: min(26vw, 13em);
  height: 1.3em;
  border: 3px solid var(--ink);
  border-radius: 0.7em;
  background: var(--paper);
  box-shadow: 3px 3px 0 var(--ink);
  overflow: hidden;
}
.charge .bar i {
  display: block;
  height: 100%;
  width: calc(var(--charge, 1) * 100%);
  background: var(--volt);
  border-right: 3px solid var(--ink);
  transition: background-color 0.2s;
}
.charge.low .bar i { background: var(--low); animation: blink 0.5s steps(2) infinite; }
.charge.gain .bolt { animation: zap 0.25s ease-out; }
@keyframes blink { 50% { opacity: 0.45; } }
@keyframes zap { 50% { transform: scale(1.35) rotate(-8deg); } }

.dist {
  font-family: Bungee, sans-serif;
  text-align: center;
  line-height: 1;
  color: var(--paper);
  -webkit-text-stroke: 0.14em var(--ink);
  paint-order: stroke fill;
}
.dist b { font-weight: 400; font-size: 2.1em; }
.dist span { font-size: 1.1em; margin-left: 0.1em; }
.dist small { display: block; font-size: 0.7em; margin-top: 0.3em; color: var(--volt); }

.right { display: flex; justify-content: flex-end; align-items: center; gap: 0.5em; }
.coins { display: flex; align-items: center; gap: 0.25em; font-family: Bungee, sans-serif; font-size: 1.15em; color: var(--paper); -webkit-text-stroke: 0.14em var(--ink); paint-order: stroke fill; }
.coins .spark { width: 1.5em; height: 1.5em; }
.spark circle { fill: var(--volt); stroke: var(--ink); stroke-width: 2; }
.spark path { fill: var(--ink); }

.icon {
  width: 2.6em; height: 2.6em;
  display: grid; place-items: center;
  padding: 0;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: 3px 3px 0 var(--ink);
}
.icon svg { width: 60%; height: 60%; fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.icon:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
#muteBtn[aria-pressed="true"] .waves { display: none; }

/* ---------- touch pedals ---------- */
#touch {
  position: fixed;
  inset: 0;
  display: none;
  touch-action: none;
}
.touch #touch { display: block; }
.pedal {
  position: absolute;
  bottom: calc(var(--edge) * 1.4 + env(safe-area-inset-bottom));
  width: max(84px, calc(var(--u) * 21));
  aspect-ratio: 1;
  border: 4px solid var(--ink);
  border-radius: 28%;
  background: var(--paper);
  box-shadow: 5px 5px 0 var(--ink);
  display: grid;
  place-items: center;
}
.pedal.brake { left: calc(var(--edge) * 1.6 + env(safe-area-inset-left)); }
.pedal.gas { right: calc(var(--edge) * 1.6 + env(safe-area-inset-right)); background: var(--volt); }
.pedal svg { width: 55%; fill: none; stroke: var(--ink); stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; }
.pedal span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); bottom: 0; font-size: max(12px, calc(var(--u) * 2.6)); color: var(--paper); -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; }
.pedal.on { transform: translate(4px, 4px); box-shadow: 1px 1px 0 var(--ink); opacity: 1; }
.pulse .pedal.gas { animation: nudge 0.9s ease-in-out infinite; }
@keyframes nudge { 50% { transform: scale(1.08); } }

/* ---------- ready overlay ---------- */
#ready {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: none;
}
.state-ready #ready { display: block; }
#garageBtn {
  pointer-events: auto;
  position: absolute;
  left: calc(var(--edge) + env(safe-area-inset-left));
  top: calc(var(--edge) * 1.3 + max(13px, calc(var(--u) * 3.2)) * 3.4 + env(safe-area-inset-top));
}
.chip {
  font-family: Bungee, sans-serif;
  font-size: max(13px, calc(var(--u) * 3));
  padding: 0.45em 0.9em;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 0.6em;
  box-shadow: 3px 3px 0 var(--ink);
}
.hint {
  position: absolute;
  left: 50%;
  top: 60%;
  translate: -50% 0;
  margin: 0;
  font-family: Bungee, sans-serif;
  font-size: max(16px, calc(var(--u) * 4.2));
  color: var(--paper);
  -webkit-text-stroke: 0.16em var(--ink);
  paint-order: stroke fill;
  white-space: nowrap;
  animation: nudge 1.2s ease-in-out infinite;
}
.hint kbd {
  display: inline-block;
  font-family: Rubik, sans-serif;
  color: var(--ink);
  -webkit-text-stroke: 0;
  background: var(--volt);
  border: 3px solid var(--ink);
  border-radius: 0.3em;
  padding: 0 0.35em;
  box-shadow: 2px 2px 0 var(--ink);
}
.touch .hint { top: auto; bottom: calc(var(--edge) * 2 + max(84px, calc(var(--u) * 21)) + 1.5em); }

/* ---------- dialogs ---------- */
dialog {
  border: 4px solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 8px 8px 0 var(--ink);
  padding: clamp(12px, calc(var(--u) * 3.5), 28px);
  width: min(560px, 92vw);
  max-height: 92vh;
  overflow: auto;
  font-size: max(14px, calc(var(--u) * 3));
}
dialog::backdrop { background: rgb(0 40 80 / 0.45); }
dialog h2 {
  font-family: Bungee, sans-serif;
  font-weight: 400;
  font-size: 2em;
  margin: 0 0 0.2em;
  line-height: 1.05;
  transform: rotate(-2deg);
  color: var(--signal);
  -webkit-text-stroke: 0.06em var(--ink);
  paint-order: stroke fill;
}
.row { display: flex; gap: 0.6em; justify-content: flex-end; margin-top: 0.8em; flex-wrap: wrap; }
.btn {
  font-family: Bungee, sans-serif;
  font-size: 1em;
  padding: 0.55em 1.1em;
  min-height: 48px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 4px 4px 0 var(--ink);
}
.btn.primary { background: var(--volt); font-size: 1.15em; }

.btn.ad { background: #b8f0ff; display: flex; align-items: center; gap: 0.45em; font-size: 0.8em; min-height: 44px; padding: 0.4em 0.8em; text-align: left; }
.btn.ad span { display: grid; }
.btn.ad small { font-family: Rubik, sans-serif; font-size: 0.75em; }
.btn.ad .clap { width: 1.7em; height: 1.7em; flex: none; fill: var(--paper); stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled { opacity: 0.45; cursor: default; }
.ads { justify-content: flex-start; }
.ads:empty { display: none; }
.adnote { margin: 0; align-self: center; font-size: 0.8em; }

.big { font-family: Bungee, sans-serif; font-size: 1.5em; margin: 0.1em 0 0.3em; }
.big b { font-weight: 400; font-size: 1.9em; }
.big span { font-size: 0.55em; color: #555; }
.big span.new { color: var(--signal); }
.unlock { background: var(--volt); border: 3px solid var(--ink); border-radius: 10px; padding: 0.35em 0.6em; margin: 0.3em 0; }
.lines { list-style: none; padding: 0; margin: 0.3em 0; display: grid; gap: 0.15em; }
.lines li { display: flex; justify-content: space-between; border-bottom: 2px dashed #bbb; padding: 0.1em 0; }
.lines li.total { border: 0; font-family: Bungee, sans-serif; font-size: 1.2em; }
.missions { list-style: none; padding: 0; margin: 0.5em 0 0; display: grid; gap: 0.35em; }
.missions li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.1em 0.6em;
  align-items: center;
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 0.3em 0.5em;
  font-size: 0.9em;
}
.missions li.done { background: #c8ffb0; }
.missions .meter { grid-column: 1 / -1; height: 0.45em; border: 2px solid var(--ink); border-radius: 1em; overflow: hidden; }
.missions .meter i { display: block; height: 100%; width: calc(var(--p) * 100%); background: var(--signal); }

.gar-head { display: flex; justify-content: space-between; align-items: center; }
.gar-head .coins { font-size: 1.2em; }
section { margin-top: 0.6em; }
.cards { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4em; }
.cards li { display: contents; }
.cards button {
  display: grid;
  justify-items: center;
  gap: 0.1em;
  padding: 0.3em 0.2em;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #f1f1f1;
  font-size: 0.85em;
  min-height: 48px;
}
.cards button[aria-pressed="true"] { background: var(--volt); box-shadow: 3px 3px 0 var(--ink); }
.cards canvas { width: 100%; aspect-ratio: 2; }
.cards .name { font-family: Bungee, sans-serif; }
.cards .price { font-size: 0.85em; }
.upgrades { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.35em; }
.upgrades li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.5em; }
.upgrades .pips { display: flex; gap: 3px; margin-top: 0.15em; }
.upgrades .pips i { width: 1.4em; height: 0.55em; border: 2px solid var(--ink); border-radius: 3px; }
.upgrades .pips i.on { background: var(--signal); }
.upgrades small { display: block; color: #555; font-size: 0.8em; }
.upgrades .btn { font-size: 0.85em; min-width: 7.5em; padding: 0.4em 0.6em; }
.biomes { list-style: none; padding: 0; margin: 0; display: flex; gap: 0.35em; flex-wrap: wrap; }
.biomes button {
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--paper);
  padding: 0.3em 0.6em;
  min-height: 44px;
  text-align: left;
  font-size: 0.85em;
}
.biomes button[aria-pressed="true"] { background: var(--volt); box-shadow: 3px 3px 0 var(--ink); }
.biomes button:disabled { background: #e6e6e6; color: #666; cursor: default; }
.biomes small { display: block; font-size: 0.8em; }

@media (prefers-reduced-motion: reduce) {
  .hint, .pulse .pedal.gas, .charge.low .bar i { animation: none; }
}

#garage { width: min(940px, 95vw); font-size: max(13px, calc(var(--u) * 2.6)); }
#garage h2 { font-size: 1.6em; margin: 0; }
.gar-body { display: grid; gap: 0.6em 1.4em; }
@media (min-aspect-ratio: 4/3) {
  .gar-body { grid-template-columns: 1.15fr 1fr; align-items: start; }
  .gar-right section { margin-top: 0; }
}
