:root {
  --bg: #070b14;
  --ink: #e8f0ff;
  --dim: #8b98b3;
  --accent: #38e8c6;
  --hot: #ff5a6a;
  --panel: rgba(12, 18, 32, 0.82);
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 600 14px/1.3 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  overflow: hidden; overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
body { position: fixed; inset: 0; }
#app { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#stage { position: relative; flex: 0 0 auto; line-height: 0; }
canvas#game { display: block; background: #05080f; image-rendering: auto; touch-action: none; }

#topbar { position: absolute; top: calc(4px + var(--sat)); right: calc(6px + var(--sar)); display: flex; gap: 6px; line-height: 1; }
#topbar button {
  font: 700 10px/1 inherit; letter-spacing: 0.08em; color: var(--ink); background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 6px; padding: 8px 9px; min-height: 30px; cursor: pointer;
}
#topbar button[aria-pressed="true"] { color: var(--hot); border-color: var(--hot); }
#toast {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); line-height: 1.3;
  background: var(--panel); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 8px; padding: 6px 12px;
  font-size: 12px; opacity: 0; transition: opacity 0.25s; pointer-events: none; white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ---- controls: hidden until a touch is seen (body.touch), START is always available to pointers ---- */
#controls { position: absolute; inset: 0; pointer-events: none; display: flex; align-items: flex-end; justify-content: space-between;
  padding: 0 calc(10px + var(--sar)) calc(10px + var(--sab)) calc(10px + var(--sal)); gap: 8px; }
.pad { display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.pad .row { display: flex; gap: 10px; }
#pad-mid { align-items: center; flex: 1 1 auto; }
#spec-row { display: none; gap: 8px; }
body.touch.spectating #spec-row { display: flex; }
button.ctl, button.act {
  pointer-events: auto; touch-action: none; font: 800 15px/1 inherit; letter-spacing: 0.06em; color: var(--ink);
  background: rgba(20, 30, 52, 0.55); border: 2px solid rgba(255, 255, 255, 0.35); border-radius: 16px; cursor: pointer;
}
/* while racing the pads sit over the track: keep them see-through so obstacles stay readable */
body.racing button.ctl { background: rgba(20, 30, 52, 0.16); border-color: rgba(255, 255, 255, 0.3); color: rgba(232, 240, 255, 0.75); }
body.racing #btn-name, body.racing #btn-full { display: none; }
button.ctl { display: none; }
body.touch button.ctl { display: block; }
button.ctl.big { width: 92px; height: 78px; font-size: 26px; }
button.ctl.jump { width: 194px; height: 84px; font-size: 22px; border-color: var(--accent); }
button.ctl.small { width: 92px; height: 52px; font-size: 13px; }
button.ctl.down, button.act:active { background: rgba(56, 232, 198, 0.35); border-color: var(--accent); }
button.act { padding: 10px 16px; min-height: 44px; font-size: 13px; }
button.act.start {
  display: none; min-width: 200px; min-height: 64px; font-size: 24px; color: #04110e; background: var(--accent); border-color: #b9fff0;
  box-shadow: 0 0 22px rgba(56, 232, 198, 0.45);
}
body.can-start button.act.start { display: block; }
body:not(.touch) button.act.start { min-width: 150px; min-height: 44px; font-size: 16px; }
body:not(.touch) #controls { padding-bottom: calc(14px + var(--sab)); }

/* portrait: game band on top, controls fill the space below it */
@media (orientation: portrait) {
  #app { justify-content: flex-start; }
  #stage { margin-top: var(--sat); }
  body.touch #controls { top: auto; height: auto; }
  button.ctl.big { width: 84px; height: 84px; }
  button.ctl.jump { width: 150px; height: 96px; }
  button.ctl.small { width: 70px; height: 54px; font-size: 12px; }
  body.touch #pad-mid { position: absolute; left: 0; right: 0; bottom: calc(230px + var(--sab)); }
}
@media (orientation: landscape) and (max-height: 430px) {
  button.ctl.big { width: 84px; height: 62px; }
  button.ctl.jump { width: 178px; height: 68px; }
  button.ctl.small { width: 84px; height: 44px; }
  button.act.start { min-height: 54px; font-size: 20px; }
}

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(3, 6, 12, 0.86);
  padding: calc(12px + var(--sat)) calc(12px + var(--sar)) calc(12px + var(--sab)) calc(12px + var(--sal)); z-index: 10; overflow: auto; touch-action: auto; }
.overlay[hidden] { display: none; }
#name-form { width: min(420px, 100%); background: #0c1220; border: 1px solid rgba(56, 232, 198, 0.45); border-radius: 14px; padding: 20px; -webkit-user-select: text; user-select: text; }
#name-form h1 { margin: 0 0 2px; font-size: 24px; letter-spacing: 0.06em; color: var(--accent); font-style: italic; }
#name-form .sub { margin: 0 0 14px; color: var(--dim); font-weight: 500; }
#name-form label { display: block; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); margin-bottom: 4px; }
#name-input { width: 100%; font: 700 20px/1.2 inherit; color: var(--ink); background: #060a12; border: 2px solid rgba(255, 255, 255, 0.25); border-radius: 10px; padding: 10px 12px; }
#name-input:focus { outline: none; border-color: var(--accent); }
#name-go { width: 100%; margin-top: 12px; font: 800 18px/1 inherit; letter-spacing: 0.06em; color: #04110e; background: var(--accent); border: 0; border-radius: 10px; padding: 14px; cursor: pointer; }
.fine { margin: 12px 0 0; font-size: 11px; font-weight: 500; color: var(--dim); line-height: 1.45; }
.fine b { color: var(--ink); }
@media (max-height: 420px) { .fine.keys { display: none; } #name-form { padding: 12px 16px; } }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
