:root {
  --bg: #050507;
  --lav: #C4BBE0;
  --blue: #2B2BFF;
  --amber: #FFA500;
  --ink: rgba(255, 255, 255, 0.94);
  --mute: rgba(196, 187, 224, 0.6);
}

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

html, body {
  height: 100%;
  background: #000;
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  cursor: default;
}

#stage { position: fixed; inset: 0; z-index: 0; }
#stage canvas { display: block; }

/* HUD canvas overlay — drawn each frame in JS.
   Explicit width/height lock the element's layout size so the (large) bitmap
   backing store can't drive layout — otherwise clientWidth feeds back and grows. */
#hud { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; }

/* Launch / start screen */
.launch {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10,10,18,0.86), rgba(0,0,0,0.96));
  text-align: center; transition: opacity 0.6s ease, visibility 0.6s ease;
}
.launch.hidden { opacity: 0; visibility: hidden; }
.launch-inner { padding: 30px; max-width: 560px; }
.brand { font-size: 16px; font-weight: 500; letter-spacing: 0.06em; color: var(--lav); margin-bottom: 0.6em; }
.launch h1 {
  font-size: clamp(40px, 8vw, 88px); font-weight: 700; letter-spacing: 0.06em; line-height: 1;
  margin-bottom: 0.35em;
}
.sub { font-size: clamp(13px, 1.6vw, 16px); color: var(--mute); margin-bottom: 2em; letter-spacing: 0.02em; }
.controls {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 18px;
  font-family: "JetBrains Mono", monospace; font-size: 12px; color: var(--mute);
  margin-bottom: 2.4em;
}
.controls div { display: flex; flex-direction: column; gap: 4px; }
.controls span { color: var(--amber); font-weight: 700; letter-spacing: 0.12em; }
/* Show the control legend that matches the input. JS adds body.touch. */
.controls-touch { display: none; }
body.touch .controls-mouse { display: none; }
body.touch .controls-touch { display: grid; }
#launchBtn {
  font-family: "JetBrains Mono", monospace; font-size: 13px; font-weight: 700; letter-spacing: 0.28em;
  color: #050507; background: var(--lav); border: 0; padding: 16px 34px; cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}
#launchBtn:hover { background: #fff; transform: translateY(-2px); }

.paused {
  position: fixed; inset: 0; z-index: 9;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.55); pointer-events: none;
  font-family: "JetBrains Mono", monospace; font-size: 13px; letter-spacing: 0.22em; color: var(--mute);
}
.paused[hidden] { display: none; }

.fallback {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 40px; text-align: center;
  background: var(--bg); color: var(--mute);
  font-family: "JetBrains Mono", monospace; font-size: 13px; letter-spacing: 0.04em;
}
.fallback[hidden] { display: none; }

/* ── Touch controls (mobile) ─────────────────────────────────── */
#touch { position: fixed; inset: 0; z-index: 5; display: none; touch-action: none; }
#touch.show { display: block; }
body:not(.touch) #touch { display: none; }
#touch > * { pointer-events: auto; }

/* Whole-screen drag-to-steer zone; the controls below sit on top of it. */
.t-steer { position: absolute; inset: 0; touch-action: none; }

/* Floating joystick that appears where the steer touch begins. */
.t-stick {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px;
  border: 1.5px solid rgba(196, 187, 224, 0.45); border-radius: 50%;
  display: none; pointer-events: none;
}
.t-stick.on { display: block; }
.t-stick-knob {
  position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border-radius: 50%; background: rgba(196, 187, 224, 0.22); border: 1.5px solid var(--lav);
}

/* Throttle slider, left edge. */
.t-throttle {
  position: absolute; left: 16px; top: 26%; width: 58px; height: 46%;
  border: 1.5px solid rgba(196, 187, 224, 0.4); border-radius: 30px; overflow: hidden;
  display: flex; align-items: flex-start; justify-content: center; touch-action: none;
  background: rgba(8, 8, 14, 0.4);
}
.t-fill { position: absolute; left: 0; bottom: 0; width: 100%; height: 0%; background: rgba(196, 187, 224, 0.4); }
.t-throttle span {
  position: relative; margin-top: 10px; font-family: "JetBrains Mono", monospace;
  font-size: 10px; font-weight: 700; letter-spacing: 0.14em; color: var(--lav);
}

.t-rolls { position: absolute; left: 16px; bottom: 26px; display: flex; gap: 12px; }
.t-actions { position: absolute; right: 16px; bottom: 26px; display: flex; flex-direction: column; gap: 12px; align-items: flex-end; }

.t-btn {
  font-family: "JetBrains Mono", monospace; font-weight: 700; font-size: 13px; letter-spacing: 0.14em;
  color: var(--lav); background: rgba(8, 8, 14, 0.5); border: 1.5px solid rgba(196, 187, 224, 0.4);
  border-radius: 12px; min-width: 66px; min-height: 58px; padding: 0 14px; touch-action: none;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.t-btn:active, .t-btn.on { background: rgba(196, 187, 224, 0.9); color: #050507; }
.t-boost { min-width: 92px; }
.t-boost:active, .t-boost.on { background: var(--amber); border-color: var(--amber); color: #050507; }
