:root {
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --bg: #0b1220;
  --panel: rgba(16, 24, 40, 0.88);
  --line: rgba(120, 160, 255, 0.35);
  --text: #eaf0ff;
  --muted: #9fb0d0;
  --accent: #4da3ff;
  --good: #6fe3c4;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
#app3d { position: fixed; inset: 0; }
#app3d canvas { display: block; }

button {
  font: inherit; color: var(--text); cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 18px; min-height: 44px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #06101f; font-weight: 700; }

/* ---------- mode picker ---------- */
.view {
  position: fixed; inset: 0; z-index: 40; overflow-y: auto;
  background: rgba(11, 18, 32, 0.92);
  padding: calc(24px + var(--safe-t)) calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
  text-align: center;
}
.view h1 { margin: 0 0 4px; font-size: 28px; }
.view .sub { margin: 0 0 20px; color: var(--muted); }
#modes { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; }
.mode {
  flex: 1 1 200px; max-width: 280px; text-align: left; padding: 18px;
  display: flex; flex-direction: column; gap: 6px;
}
.mode .num { color: var(--accent); font-weight: 700; font-size: 13px; letter-spacing: 0.08em; }
.mode .title { font-size: 20px; font-weight: 700; }
.mode .blurb { color: var(--muted); font-size: 14px; }
.mode .state { margin-top: 6px; font-size: 13px; color: var(--good); min-height: 18px; }
.mode:disabled { opacity: 0.45; cursor: default; }
.mode:disabled .state { color: var(--muted); }

/* ---------- flight ---------- */
/* The overlay itself never takes a touch, so nothing can swallow a
   thumbstick drag; each control opts back in. */
#view-flight { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#view-flight button { pointer-events: auto; }
.chip { position: fixed; top: calc(10px + var(--safe-t)); padding: 8px 14px; min-height: 40px; font-size: 14px; }
#btnBack { left: calc(10px + var(--safe-l)); }
#btnCam { right: calc(10px + var(--safe-r)); }
#ask {
  position: fixed; left: 50%; top: calc(12px + var(--safe-t)); transform: translateX(-50%);
  max-width: 60vw; padding: 8px 18px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 20px; font-weight: 700; text-align: center;
}
#dots { position: fixed; left: 50%; top: calc(64px + var(--safe-t)); transform: translateX(-50%); display: flex; gap: 8px; }
#dots i { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, 0.2); }
#dots i.on { background: var(--good); }
#praise {
  position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%);
  font-size: 40px; font-weight: 800; color: var(--good); white-space: nowrap;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.8);
  animation: pop 0.25s ease-out;
}
@keyframes pop { from { transform: translate(-50%, -50%) scale(0.6); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #praise { animation: none; } }
#btnStart {
  /* Off to the side so it never hides the drone it starts. */
  position: fixed; left: 76%; top: 56%; transform: translate(-50%, -50%);
  width: 150px; height: 150px; border-radius: 50%;
  background: var(--good); border: 0; color: #06101f; font-size: 28px; font-weight: 800;
  box-shadow: 0 0 0 10px rgba(111, 227, 196, 0.2);
}
#keys {
  position: fixed; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%);
  padding: 6px 14px; border-radius: 10px; background: var(--panel);
  color: var(--muted); font-size: 14px; white-space: nowrap;
}
.card {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 50;
  min-width: 260px; padding: 22px; border-radius: 16px; text-align: center;
  background: var(--panel); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px; pointer-events: auto;
}
.card h2 { margin: 0 0 6px; font-size: 24px; }

/* ---------- touch sticks (from the drone-competition app) ----------
   Nothing else may occupy these two bottom corners. */
#touchSticks .stick {
  position: fixed; z-index: 30;
  bottom: calc(24px + var(--safe-b));
  width: 128px; height: 128px;
  border: 1px solid rgba(120, 160, 255, 0.35);
  border-radius: 50%;
  background: rgba(16, 24, 40, 0.45);
  touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#touchSticks .stick[data-stick="left"] { left: calc(20px + var(--safe-l)); }
#touchSticks .stick[data-stick="right"] { right: calc(20px + var(--safe-r)); }
#touchSticks .nub {
  position: absolute; left: 50%; top: 50%;
  width: 50px; height: 50px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(77, 163, 255, 0.55);
  touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
/* Mode 1 has one control: up and down. */
body.one-stick #touchSticks .stick[data-stick="right"] { display: none; }

/* ---------- QR page ---------- */
.qr-page { overflow: auto; height: auto; min-height: 100%; background: #fff; color: #111; text-align: center; padding: 24px; }
.qr-page #code svg { width: min(70vw, 420px); height: auto; }
.qr-page input { font: inherit; padding: 8px 10px; width: min(90vw, 420px); border: 1px solid #999; border-radius: 8px; }
.qr-page label { display: block; margin: 14px 0 4px; color: #444; font-size: 14px; }
.qr-page #link { word-break: break-all; font-family: ui-monospace, monospace; }
@media print { .qr-page .no-print { display: none; } }
