:root {
  --bg: #0b0e14;
  --panel: #151a24;
  --line: #2a3344;
  --text: #e6ebf5;
  --muted: #8d9bb5;
  --accent: #35c4f0;
  --ok: #3ddc97;
  --warn: #ffb020;
  --danger: #ff4d5e;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.3 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- Status bar ---------- */

.status {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.chip {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

body.connected .chip {
  color: var(--text);
  border-color: var(--accent);
}

/* Below 10%, the warning must be impossible to miss. */
body.low-battery #battery {
  color: #1b1200;
  background: var(--warn);
  border-color: var(--warn);
  font-weight: 700;
}

.connect {
  margin-right: auto;
  padding: 9px 16px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
}

body.connected .connect {
  border-color: var(--ok);
  color: var(--ok);
}

.icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 17px;
  line-height: 1;
}

.icon-btn:disabled {
  opacity: 0.35;
}

/* ---------- Settings panel ---------- */

.panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 5, 9, 0.72);
}

.panel[hidden] {
  display: none;
}

.panel-card {
  width: min(420px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 14px 16px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin: 0;
  font-size: 17px;
}

.panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.panel-label {
  color: var(--muted);
}

.panel-value {
  color: var(--muted);
  font-family: ui-monospace, monospace;
  font-size: 12px;
}

#update-row:not([hidden]) .panel-label {
  color: var(--ok);
}

.choices {
  display: flex;
  gap: 6px;
}

.choice {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
}

.choice[aria-pressed='true'] {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Flight area ---------- */

.pad {
  flex: 1 1 auto;
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 10px;
  min-height: 0;
}

.stick {
  position: relative;
  flex: 1 1 0;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 20px;
  background: radial-gradient(circle at center, #1b2230 0%, #111621 70%);
  touch-action: none;
}

.stick-hint {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  pointer-events: none;
}

/* Position indicator: without it you fly without knowing where the stick is. */
.knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 74px;
  height: 74px;
  margin: -37px 0 0 -37px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: rgba(53, 196, 240, 0.18);
  pointer-events: none;
  will-change: transform;
}

.center {
  flex: 0 0 clamp(170px, 26vw, 260px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action {
  padding: 14px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
}

.action:disabled {
  opacity: 0.4;
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.action.compact {
  padding: 10px 2px;
  font-size: 12px;
  font-weight: 500;
}

.notice {
  color: var(--accent);
  border-color: var(--accent);
}

.panel-row-stack {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.slider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.slider input[type='range'] {
  flex: 1 1 auto;
  min-width: 0;
}

/* The generated limit slider needs the same treatment as the light one, or the
   longest label plus the readout squeezes it off a phone screen. */
#limit-rows input[type='range'] {
  flex: 1 1 auto;
  min-width: 0;
}

.limit-value {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  min-width: 68px;
  text-align: right;
}

/* "Land" is the reflex control: one tap, always visible. */
.action.land {
  border-color: var(--ok);
  color: var(--ok);
}

/* ---------- Motor cut-off ---------- */

.cutoff {
  position: relative;
  height: 54px;
  border: 1px solid var(--danger);
  border-radius: 12px;
  background: #241115;
  overflow: hidden;
  touch-action: none;
}

.cutoff-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-left: 46px;
  color: var(--danger);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: center;
  pointer-events: none;
}

.cutoff-handle {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 44px;
  height: 44px;
  border-radius: 9px;
  background: var(--danger);
  touch-action: none;
}

.cutoff-handle::after {
  content: "⟩⟩";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #2a0007;
  font-size: 15px;
  font-weight: 700;
}

/* In portrait the layout stays usable but invites turning the phone. */
@media (orientation: portrait) {
  .pad {
    flex-direction: column;
  }
  .center {
    flex: 0 0 auto;
  }
}
