:root {
  --bg: #f4f5f7;
  --panel: rgba(255, 255, 255, 0.86);
  --text: #1c2024;
  --muted: #5d6670;
  --border: #d4d8dd;
  --accent: #1f6fd1;
  --ok: #1e8a4c;
  --warn: #b7791f;
  --bad: #c0392b;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c;
    --panel: rgba(28, 32, 37, 0.88);
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --border: #353b42;
    --accent: #5b9cf0;
  }
}
:root[data-theme="dark"] {
  --bg: #15181c;
  --panel: rgba(28, 32, 37, 0.88);
  --text: #e6e8eb;
  --muted: #9aa3ad;
  --border: #353b42;
  --accent: #5b9cf0;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, sans-serif;
  display: flex;
  flex-direction: column;
}
header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
h1 { font-size: 16px; margin: 0; }
.links { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; }
.links a { color: var(--accent); text-decoration: none; }
.links a:hover { text-decoration: underline; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; align-items: center; }
button, select {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
label { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.pill {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.pill.running { color: var(--ok); border-color: var(--ok); }
.pill.error { color: var(--bad); border-color: var(--bad); }
main { position: relative; flex: 1; min-height: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#hud {
  position: absolute;
  top: 12px;
  left: 12px;
  margin: 0;
  padding: 8px 12px;
  display: grid;
  grid-template-columns: auto auto;
  gap: 2px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  pointer-events: none;
}
#hud dt { color: var(--muted); }
#hud dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; }
#hud .armed { color: var(--bad); font-weight: 600; }
#hud .warn { color: var(--warn); font-weight: 600; }
#console {
  position: absolute;
  right: 12px;
  top: 12px;
  width: min(560px, calc(100% - 24px));
  max-height: 45%;
  display: flex;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
#console[hidden] { display: none; }
#console pre {
  margin: 0;
  padding: 8px 12px;
  overflow: auto;
  font: 11px/1.4 var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
  flex: 1;
}
#controller {
  position: absolute;
  right: 12px;
  top: 12px;
  width: min(340px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  z-index: 1;
}
#controller[hidden] { display: none; }
#controller p { margin: 0 0 8px; }
#controller .device { font-family: var(--mono); font-size: 11px; color: var(--muted); word-break: break-all; }
#controller .axes, #controller .map { display: grid; gap: 4px 8px; align-items: center; margin-bottom: 8px; }
#controller .axes { grid-template-columns: auto 1fr; font: 11px var(--mono); color: var(--muted); }
#controller .map { grid-template-columns: auto auto auto; }
#controller .bar { position: relative; height: 8px; border-radius: 4px; background: var(--border); }
#controller .bar > div { position: absolute; top: 0; bottom: 0; left: 50%; border-radius: 4px; background: var(--accent); }
#controller button.learning { border-color: var(--accent); color: var(--accent); }
@media (max-width: 700px) {
  #console { top: auto; bottom: 200px; max-height: 30%; }
  #hud { font-size: 12px; }
}
#joystick {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(440px, calc(100% - 24px));
  user-select: none;
  -webkit-user-select: none;
}
.atom {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
  background: linear-gradient(#f2f2ef, #d9d9d4);
  border: 1px solid #b9b9b3;
  border-radius: 28px 28px 40px 40px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  color: #222;
}
.stick {
  justify-self: center;
  width: min(110px, 26vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(#3b3d40 55%, #2a2c2e 70%, #1b1c1d);
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: grab;
}
.knob {
  width: 46%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #5d6064, #2b2d30 70%);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.6), inset 0 0 0 3px #45484c;
  pointer-events: none;
}
.middle { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.buttons { display: flex; align-items: center; gap: 8px; }
.side {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  background: linear-gradient(#fafafa, #cfcfca);
  border: 1px solid #a9a9a3;
  color: #555;
  font-size: 11px;
  font-weight: 600;
  touch-action: none;
}
.side:active { background: #c4c4bf; }
.screen {
  width: min(112px, 25vw);
  aspect-ratio: 1;
  border-radius: 10px;
  border: 6px solid #f7f7f5;
  outline: 1px solid #a9a9a3;
  background: #0b0b0c;
  color: #f2f2f2;
  font: 11px/1.2 var(--mono);
  padding: 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  touch-action: none;
  overflow: hidden;
}
.screen:active { filter: brightness(1.3); }
.screen .title { color: #9aa3ad; text-align: center; letter-spacing: 1px; }
.screen .hint { color: #9aa3ad; font-size: 9px; text-align: center; }
.screen .tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
.screen .tile {
  display: grid;
  place-items: center;
  height: 34px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  color: #111;
}
.screen .tiles.small .tile { height: 15px; font-size: 8px; }
.tile.stable { background: #4d8df7; }
.tile.sport { background: #f2c94c; }
.tile.manual { background: #f28cc4; }
.tile.auto { background: #5fd38a; }
.screen .state { text-align: center; font-weight: 700; }
.screen .armed { color: #ff5a4f; }
.screen .safe { color: #5fd38a; }
.screen .landing { color: #f2c94c; }
.screen .lost { color: #9aa3ad; }
.screen .alt { text-align: center; font-size: 20px; font-weight: 700; }
.screen .alt small { font-size: 10px; color: #9aa3ad; }
.screen .row { display: flex; justify-content: space-between; font-size: 10px; color: #c9cdd2; }
.keys { margin: 0; font-size: 10px; color: #6a6a66; text-align: center; max-width: 150px; }
@media (max-width: 420px) {
  .atom { padding: 10px; gap: 4px; }
  .keys { display: none; }
  .stick { width: 22vw; }
  .screen { width: 22vw; border-width: 4px; padding: 4px; }
  .buttons { gap: 4px; }
  .side { width: 26px; height: 26px; }
  .screen .alt { font-size: 15px; }
  .screen .tiles.small { display: none; }
}
