:root {
  --ink: #17231c;
  --panel: #1d3b2a;
  --yellow: #ffc928;
  --paper: #fff8e1;
  /* Button size: four buttons (Gas counts 1.25x) plus gaps and edge padding must fit the width. */
  --b: min(calc((100vw - 56px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) / 4.25), 26vh, 96px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--panel);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--paper); touch-action: none; user-select: none; -webkit-user-select: none;
}
canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
[hidden] { display: none !important; }

#hud {
  position: fixed; top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left));
  display: flex; flex-wrap: wrap; gap: 6px; max-width: calc(100% - 150px);
}
#hud div, #mute, #warn {
  background: var(--panel); border: 2px solid var(--ink); border-radius: 10px;
  padding: 5px 10px; font-size: clamp(13px, 3.4vw, 18px);
}
#hud b { color: var(--yellow); font-variant-numeric: tabular-nums; }
#mute {
  position: fixed; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right));
  z-index: 20; color: var(--paper); font-family: inherit; cursor: pointer;
}

#msg {
  position: fixed; left: 0; right: 0; top: 30%; text-align: center; pointer-events: none;
  font-size: clamp(36px, 12vmin, 96px); font-weight: 800; color: var(--yellow);
  text-shadow: 0 3px 0 var(--ink), 0 -3px 0 var(--ink), 3px 0 0 var(--ink), -3px 0 0 var(--ink);
}
#msg.small { font-size: clamp(20px, 6vmin, 40px); }
#warn {
  position: fixed; left: 50%; top: 58%; transform: translateX(-50%);
  background: #c0392b; border-color: var(--paper); font-weight: 700; white-space: nowrap;
}

#pad {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between;
  gap: 8px;
  padding: 0 max(12px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  pointer-events: none;
}
.grp { display: flex; gap: 8px; align-items: flex-end; }
#pad button {
  pointer-events: auto; touch-action: none; width: var(--b); height: var(--b);
  border-radius: 18px; border: 3px solid var(--ink); background: var(--paper); color: var(--ink);
  font: 800 clamp(15px, 4vmin, 22px) system-ui, sans-serif; opacity: .88;
}
#pad button.gas { background: var(--yellow); width: calc(var(--b) * 1.25); height: calc(var(--b) * 1.25); }
#pad button.on { transform: scale(.94); background: #9bd8a8; }
#pad button.gas.on { background: #ffe58a; }
body:not([data-s=race]):not([data-s=count]) #pad,
body:not([data-s=race]):not([data-s=count]) #hud { display: none; }
@media (hover: hover) and (pointer: fine) { #pad { display: none; } }

.screen {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  background: rgba(23, 35, 28, .82); padding: 16px; overflow: auto;
}
.card {
  background: var(--panel); border: 3px solid var(--yellow); border-radius: 18px;
  padding: 22px; max-width: 460px; width: 100%; text-align: center;
}
h1 { margin: 0 0 10px; font-size: clamp(30px, 8vmin, 48px); color: var(--yellow); }
.card p { margin: 8px 0; font-size: clamp(16px, 3.6vmin, 20px); line-height: 1.4; }
.card .small { font-size: 14px; opacity: .85; }
.card b { color: var(--yellow); font-variant-numeric: tabular-nums; }
#newbest { color: #9bd8a8; font-weight: 800; }
.primary {
  margin-top: 12px; width: 100%; padding: 16px; font: 800 22px system-ui, sans-serif;
  background: var(--yellow); color: var(--ink); border: 3px solid var(--ink); border-radius: 14px; cursor: pointer;
}
.primary:focus-visible, #mute:focus-visible { outline: 3px solid var(--paper); outline-offset: 2px; }
@media (max-height: 420px) {
  .card { padding: 12px; } h1 { margin-bottom: 4px; } .card p { margin: 4px 0; } .primary { padding: 10px; margin-top: 6px; }
}
