:root {
  --bg: #0b0f1a;
  --card: #141b2e;
  --card-2: #1b2439;
  --text: #e7ecf5;
  --muted: #8b96ad;
  --accent: #00e5ff;
  --accent-2: #6c5ce7;
  --danger: #ff5470;
  --ok: #35d07f;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

body {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 0 12px;
  background: linear-gradient(var(--bg) 75%, transparent);
}

.brand { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.battery {
  font-size: .8rem; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  background: var(--card-2); color: var(--text);
  border: 1px solid rgba(255,255,255,.08);
  white-space: nowrap;
}
.battery.low { background: #3a1520; color: #ff90a4; border-color: #7a2740; }
.brand h1 { font-size: 1.05rem; margin: 0; letter-spacing: .2px; }
.status { margin: 2px 0 0; font-size: .8rem; color: var(--muted); }

.dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 12px var(--danger);
  transition: background .2s, box-shadow .2s;
}
.dot.on { background: var(--ok); box-shadow: 0 0 12px var(--ok); }

.card {
  background: var(--card);
  border: 1px solid rgba(255,255,255,.05);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.warn { background: #2a1e10; border-color: #6b4b12; }
.warn strong { color: #ffcf6b; }
.warn p { margin: 6px 0 0; font-size: .85rem; color: #e6d3a8; }
.hidden { display: none !important; }

/* Joystick */
.joystick-card { display: flex; flex-direction: column; align-items: center; }
.joystick {
  position: relative;
  width: min(72vw, 300px);
  height: min(72vw, 300px);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 45%, var(--card-2), #0e1424 70%);
  border: 1px solid rgba(255,255,255,.06);
  box-shadow: inset 0 8px 30px rgba(0,0,0,.5);
  touch-action: none;
}
.joystick::before {
  content: "";
  position: absolute; inset: 22%;
  border: 1px dashed rgba(255,255,255,.08);
  border-radius: 50%;
}
.stick {
  position: absolute;
  left: 50%; top: 50%;
  width: 34%; height: 34%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #2ff3ff, #0091a8);
  box-shadow: 0 6px 20px rgba(0,229,255,.35);
  transition: transform .08s ease-out;
}
.drive-info {
  display: flex; gap: 24px; margin-top: 14px;
  font-size: .85rem; color: var(--muted);
}
.drive-info b { color: var(--text); }

/* Rows */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0;
}
.row > span:first-child { flex: 1; color: var(--muted); font-size: .9rem; }
.row.toggle { justify-content: space-between; }
input[type="range"] { flex: 2; accent-color: var(--accent); }
input[type="color"] {
  width: 44px; height: 32px; border: none; background: none; border-radius: 8px;
  padding: 0;
}
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }

.swatches { display: flex; gap: 6px; }
.swatches button {
  width: 24px; height: 24px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.15); cursor: pointer;
}

/* Aim mode */
.aim-card { border-color: rgba(0,229,255,.35); }
.aim-head { margin-bottom: 12px; }
.aim-head strong { display: block; margin-bottom: 4px; }
.aim-hint { font-size: .8rem; color: var(--muted); }
.aim-rotate { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.aim-rotate input[type="range"] { flex: 1; accent-color: var(--accent); }
.aim-rotate .btn { font-size: 1.3rem; line-height: 1; padding: 8px 16px; }
.aim-actions { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }

/* Buttons */
.btn {
  appearance: none; border: 1px solid rgba(255,255,255,.1);
  background: var(--card-2); color: var(--text);
  border-radius: 12px; padding: 12px 16px; font-size: .95rem;
  cursor: pointer; transition: transform .05s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #04222a; border-color: transparent; font-weight: 600; }
.btn.tiny { padding: 4px 10px; font-size: .75rem; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions .btn:first-child { grid-column: 1 / -1; }

/* Log */
.log-card { padding-top: 12px; }
.log-head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .8rem; margin-bottom: 8px; }
.log {
  margin: 0; max-height: 160px; overflow: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .72rem; color: var(--muted); white-space: pre-wrap; word-break: break-word;
}
