:root {
  --bg: rgba(14, 18, 26, 0.76);
  --fg: #e8edf5;
  --dim: #8d99ab;
  --acc: #ffb43a;
  --line: rgba(255, 255, 255, 0.12);
  font-family: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0d1118; color: var(--fg);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }

.panel {
  position: fixed; background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); padding: 10px 14px;
  user-select: none; z-index: 10;
}
.hidden { display: none !important; }

#hud-top { top: 12px; left: 12px; }
.title { font-weight: 800; letter-spacing: 0.16em; font-size: 14px; }
.title span { color: var(--acc); }
.sub { color: var(--dim); font-size: 11px; margin-top: 3px; max-width: 280px; line-height: 1.35; }

#hud-stats { top: 12px; right: 12px; width: 190px; display: grid; gap: 6px; }
.stat { display: grid; grid-template-columns: 1fr auto auto; align-items: baseline; gap: 4px; }
.stat label, .brakes label { color: var(--dim); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; }
.stat b { font-variant-numeric: tabular-nums; font-size: 16px; }
.stat i { color: var(--dim); font-style: normal; font-size: 10.5px; min-width: 24px; }
#s-mode { font-size: 12px; color: var(--acc); text-transform: uppercase; letter-spacing: 0.06em; }
#brakes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 4px; }
#brakes div { height: 5px; border-radius: 3px; background: rgba(255,255,255,0.1); overflow: hidden; }
#brakes div span { display: block; height: 100%; width: 0%; transition: width 0.1s linear; }

#hud-controls {
  bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; align-items: center; max-width: 96vw; overflow-x: auto;
}
button {
  background: rgba(255,255,255,0.08); color: var(--fg); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; font: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
button:hover, button:active { background: rgba(255,255,255,0.18); }
button.on { background: var(--acc); color: #1a1205; border-color: var(--acc); }
.temp { display: grid; gap: 2px; margin-left: 4px; }
.temp label { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; }
.temp input { width: 90px; accent-color: var(--acc); }

/* Virtual Joystick for mobile touch */
#joystick-zone {
  position: fixed; bottom: 24px; left: 24px; width: 130px; height: 130px;
  z-index: 20; touch-action: none; display: flex; align-items: center; justify-content: center;
}
#joystick-base {
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  position: relative; display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
#joystick-knob {
  width: 52px; height: 52px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffd475, var(--acc));
  border: 2px solid rgba(255,255,255,0.4);
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
  position: absolute; pointer-events: none;
  transform: translate(0px, 0px);
  transition: transform 0.08s ease-out;
}
#joystick-knob.active { transition: none; }

#help { top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(520px, 92vw); padding: 18px 22px; z-index: 30; }
#help h3, #offline h3 { margin: 0 0 10px; }
#help table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
#help td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
#help td:first-child { white-space: nowrap; color: var(--dim); }
#help p { color: var(--dim); font-size: 12px; line-height: 1.45; }
kbd {
  display: inline-block; min-width: 18px; padding: 1px 4px; margin-right: 2px; border-radius: 4px;
  background: rgba(255,255,255,0.12); border-bottom: 2px solid rgba(255,255,255,0.2);
  font: 600 10.5px ui-monospace, monospace; text-align: center; color: var(--fg);
}

#toast {
  position: fixed; top: 20%; left: 50%; transform: translateX(-50%); font-weight: 800; font-size: 24px;
  letter-spacing: 0.06em; text-shadow: 0 2px 18px rgba(0,0,0,0.7); pointer-events: none; opacity: 0;
  transition: opacity 0.25s; z-index: 40; text-align: center; width: 90%;
}
#toast.show { opacity: 1; }

#offline { top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; z-index: 30; }
#offline code { background: rgba(0,0,0,0.4); padding: 6px 10px; border-radius: 6px; display: inline-block; }

/* Responsive adjustments for phones in portrait & landscape */
@media (max-width: 768px) {
  #hud-top { top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); max-width: 170px; padding: 6px 10px; }
  .title { font-size: 12px; }
  .sub { display: none; }
  #hud-stats { top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); width: 140px; padding: 6px 8px; gap: 3px; font-size: 11px; }
  .stat b { font-size: 13px; }
  #hud-controls {
    bottom: max(14px, env(safe-area-inset-bottom)); right: max(12px, env(safe-area-inset-right));
    left: auto; transform: none; display: flex; flex-direction: column; gap: 6px;
    width: auto; max-width: none; padding: 6px 8px;
  }
  #hud-controls button { padding: 8px 10px; font-size: 12px; width: 100%; min-width: 70px; }
  .temp { display: none; }
  #joystick-zone { bottom: max(16px, env(safe-area-inset-bottom)); left: max(16px, env(safe-area-inset-left)); }
}
