:root {
  --bg: #101418; --panel: #182028; --panel2: #1f2933; --line: #2c3a46; --text: #e6edf3; --muted: #8b9bab;
  --ok: #3fb950; --warn: #d29922; --bad: #f85149; --accent: #58a6ff; --arm: #2ea043; --sit: #1f6feb;
  --c1: #58a6ff; --c2: #f0883e; --c3: #a371f7; --c4: #3fb950;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: env(safe-area-inset-bottom); overscroll-behavior: none; }
h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; align-items: center; gap: 8px; }

.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line); }
.conn { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); flex: none; }
.conn.ok .dot { background: var(--ok); } .conn.sim .dot { background: var(--warn); }
.mode { font-weight: 700; font-size: 13px; padding: 3px 9px; border-radius: 99px; background: var(--panel2); letter-spacing: .04em; }
.mode.balancing { background: var(--arm); } .mode.sitdown { background: var(--sit); } .mode.disarmed { background: #444c56; }
.batt { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; font-size: 13px; }
.battIcon { width: 26px; height: 13px; border: 2px solid var(--muted); border-radius: 3px; position: relative; padding: 1px; }
.battIcon::after { content: ""; position: absolute; right: -5px; top: 3px; width: 3px; height: 5px; background: var(--muted); border-radius: 1px; }
.battFill { height: 100%; width: 0; background: var(--ok); border-radius: 1px; transition: width .5s; }

.tabs { display: flex; background: var(--panel); border-bottom: 1px solid var(--line); }
.tab { flex: 1; padding: 10px; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-color: var(--accent); }
main { padding: 12px; max-width: 980px; margin: 0 auto; }
.page { display: none; } .page.active { display: block; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.btn:disabled { opacity: .4; }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn.hold { position: relative; overflow: hidden; }
.btn.hold .fill { position: absolute; inset: 0; width: 0; background: rgba(255,255,255,.22); }
.btn.hold .lbl { position: relative; }
.btn.arm { background: var(--arm); border-color: var(--arm); }
.btn.stop { background: #d29922; border-color: #d29922; color: #111; }
.btn.sit { background: var(--sit); border-color: var(--sit); }
.btn.kill { background: #5c1a1a; border-color: var(--bad); color: #ffb3ad; }

.video { position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 46vh; background: #000; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.video img { width: 100%; height: 100%; object-fit: contain; display: block; }
.videoOff { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; text-align: center; padding: 12px; }
.hud { position: absolute; left: 8px; bottom: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.hud span { background: rgba(0,0,0,.55); padding: 2px 7px; border-radius: 6px; font-size: 12px; font-variant-numeric: tabular-nums; }
.banner { position: absolute; top: 8px; left: 8px; right: 8px; padding: 6px 10px; border-radius: 8px; background: rgba(248,81,73,.9); font-weight: 600; font-size: 13px; display: none; }
.banner.show { display: block; } .banner.warn { background: rgba(210,153,34,.95); color: #111; }

.driverRow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; font-size: 14px; color: var(--muted); }
.driveArea { display: flex; gap: 14px; align-items: center; justify-content: center; flex-wrap: wrap; }
.joy { position: relative; width: min(62vw, 240px); aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, var(--panel2) 0 60%, var(--panel) 61%);
  border: 2px solid var(--line); touch-action: none; flex: none; }
.joy.disabled { opacity: .35; }
.joy::before, .joy::after { content: ""; position: absolute; background: var(--line); }
.joy::before { left: 50%; top: 10%; bottom: 10%; width: 1px; } .joy::after { top: 50%; left: 10%; right: 10%; height: 1px; }
.joyKnob { position: absolute; width: 34%; aspect-ratio: 1; left: 33%; top: 33%; border-radius: 50%; background: var(--accent); box-shadow: 0 4px 14px rgba(0,0,0,.5); z-index: 2; }
.joyLabel { position: absolute; bottom: 6%; width: 100%; text-align: center; font-size: 11px; color: var(--muted); z-index: 1; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; flex: 1; min-width: 220px; max-width: 360px; }
.actions .btn { padding: 16px 10px; font-size: 15px; }
.hint { color: var(--muted); font-size: 12px; text-align: center; margin: 14px 0 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.card .k { font-size: 12px; color: var(--muted); } .card .v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.card .u { font-size: 12px; color: var(--muted); margin-left: 3px; }
.flags { display: flex; flex-wrap: wrap; gap: 6px; }
.flag { padding: 3px 9px; border-radius: 99px; font-size: 12px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.flag.on { background: var(--warn); color: #111; border-color: var(--warn); font-weight: 600; }
.flag.on.bad { background: var(--bad); color: #fff; border-color: var(--bad); }
.charts { display: grid; gap: 10px; }
figure { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
figcaption { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
canvas { width: 100%; height: 130px; display: block; }
.logCharts { display: grid; gap: 8px; }
.logCharts canvas { height: 120px; }
.events { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow: auto; font-size: 13px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.events li { padding: 5px 10px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; }
.events li:last-child { border: 0; }
.events .ts { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.events .warn { color: var(--warn); } .events .error { color: var(--bad); } .events .note { color: var(--accent); }
.logsTop { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.logsTop select { flex: 1; min-width: 180px; padding: 8px; border-radius: 8px; background: var(--panel2); color: var(--text); border: 1px solid var(--line); font: inherit; }
.fieldPick { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.fieldPick label { font-size: 12px; background: var(--panel); border: 1px solid var(--line); padding: 4px 8px; border-radius: 8px; display: flex; gap: 5px; align-items: center; }
.foot { color: var(--muted); font-size: 11px; text-align: center; padding: 10px; }
.login { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 16px; }
.login[hidden] { display: none; }
.loginBox { width: 100%; max-width: 340px; display: grid; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.loginBox h2 { margin: 0 0 4px; font-size: 18px; }
.loginBox label { font-size: 13px; color: var(--muted); }
.loginBox input { padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: inherit; }
.loginErr { margin: 0; min-height: 1.2em; color: var(--bad); font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; font-size: 14px; z-index: 10; }
@media (min-width: 820px) { .charts { grid-template-columns: 1fr 1fr 1fr; } }
