:root {
  --bg: #04101e;
  --fg: #cfeaff;
  --accent: #ff9a3c;
  --panel: rgba(4, 16, 30, 0.62);
  --line: rgba(120, 200, 255, 0.35);
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 12px/1.3 ui-monospace, Menlo, Consolas, monospace;
  position: fixed;
  inset: 0;
  width: 100%;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#hud {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  pointer-events: none;
}

.panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 8px;
  white-space: pre;
}

#race {
  white-space: normal;
  top: calc(env(safe-area-inset-top) + 6px);
  left: calc(env(safe-area-inset-left) + 6px);
  min-width: 96px;
}
#timer { font-size: 20px; font-weight: bold; letter-spacing: 1px; }
#gateinfo, #speed { opacity: 0.85; }

#stats {
  top: calc(env(safe-area-inset-top) + 76px);
  left: calc(env(safe-area-inset-left) + 6px);
  font-size: 11px;
}
#stats[hidden] { display: none; }

#toolbar {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 6px);
  right: calc(env(safe-area-inset-right) + 6px);
  display: flex;
  gap: 4px;
  pointer-events: auto;
}

button {
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  touch-action: manipulation;
}
button:active { background: rgba(60, 120, 180, 0.6); }

#arrow {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 40px);
  left: 50%;
  margin-left: -14px;
  width: 28px;
  text-align: center;
  font-size: 24px;
  color: var(--accent);
}
#arrow[hidden] { display: none; }

#banner {
  position: absolute;
  top: 38%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 1px;
  text-shadow: 0 0 6px #000;
}
#banner.warn { color: #ff6b5a; }

#steer-hint {
  position: absolute;
  left: calc(env(safe-area-inset-left) + 5vmin);
  bottom: calc(env(safe-area-inset-bottom) + 6vmin);
  opacity: 0.45;
  text-align: center;
  font-size: 14px;
}
#steer-hint small { font-size: 10px; }
#steer-hint.gone { opacity: 0; }

#steer-ring {
  position: absolute;
  width: 18vmin;
  height: 18vmin;
  margin: -9vmin 0 0 -9vmin;
  border: 2px solid var(--line);
  border-radius: 50%;
  display: none;
}
#steer-knob {
  position: absolute;
  width: 7vmin;
  height: 7vmin;
  left: 50%;
  top: 50%;
  margin: -3.5vmin 0 0 -3.5vmin;
  border-radius: 50%;
  background: rgba(120, 200, 255, 0.65);
}

#pads {
  position: absolute;
  right: calc(env(safe-area-inset-right) + 3vmin);
  bottom: calc(env(safe-area-inset-bottom) + 3vmin);
  display: flex;
  align-items: flex-end;
  gap: 2vmin;
}
.pad {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: rgba(20, 60, 100, 0.28);
  font-size: 11px;
  letter-spacing: 0;
}
#pad-throttle { width: 26vmin; height: 36vmin; border-color: var(--accent); }
#pad-brake { width: 22vmin; height: 22vmin; }
.pad.on { background: rgba(255, 154, 60, 0.45); }
#pad-brake.on { background: rgba(255, 80, 80, 0.45); }

#status {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 4px);
  transform: translateX(-50%);
  opacity: 0.85;
  text-align: center;
}

#results {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#results[hidden] { display: none; }
#results .card {
  pointer-events: auto;
  background: rgba(4, 16, 30, 0.88);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 18px;
  text-align: center;
  max-height: 78%;
  overflow: hidden;
  margin-top: 30px;
}
#res-title { font-size: 14px; letter-spacing: 2px; opacity: 0.8; }
#res-time { font-size: 28px; font-weight: bold; }
#res-best { opacity: 0.85; margin-bottom: 4px; }
#res-splits { margin: 4px 0; text-align: left; font-size: 11px; white-space: pre; }
#b-retry { font-size: 15px; padding: 8px 22px; border-color: var(--accent); }

#info {
  position: absolute;
  inset: 8px;
  box-sizing: border-box;
  padding: 8px;
  overflow: auto;
  touch-action: pan-y;
  background: rgba(4, 16, 30, 0.95);
  border: 1px solid var(--line);
  border-radius: 8px;
  -webkit-user-select: text;
  user-select: text;
}
#info[hidden] { display: none; }
.info-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
label { display: block; margin: 4px 0; }
select, input[type=text] {
  font: inherit;
  color: var(--fg);
  background: #0a2236;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px;
}
input[type=text] { width: 60%; }
pre { white-space: pre-wrap; word-break: break-word; margin: 6px 0; }
textarea {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  color: var(--fg);
  background: #0a2236;
  border: 1px solid var(--line);
  -webkit-user-select: text;
  user-select: text;
}

#rotate {
  display: none;
  position: absolute;
  inset: 0;
  background: var(--bg);
  align-items: center;
  justify-content: center;
  font-size: 20px;
  z-index: 10;
}
@media (orientation: portrait) { #rotate { display: flex; } }
