: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: 10px; justify-content: center; max-width: 980px; margin: 0 auto; }
.mode {
  flex: 1 1 140px; max-width: 200px; text-align: left; padding: 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.mode .num { color: var(--accent); font-weight: 700; font-size: 13px; letter-spacing: 0.08em; }
.mode .title { font-size: 17px; font-weight: 700; }
.mode .blurb { color: var(--muted); font-size: 13px; }
.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); }
.version { margin-top: 18px; color: var(--muted); font-size: 12px; opacity: 0.7; }
#account { display: flex; justify-content: flex-end; align-items: center; gap: 10px; min-height: 40px; margin-bottom: 6px; font-size: 14px; color: var(--muted); }
#account button { padding: 8px 14px; min-height: 40px; font-size: 14px; }
button.link { background: none; border: 0; padding: 4px; min-height: 0; color: var(--accent); text-decoration: underline; }

/* ---------- 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)); }
#btnSound { right: calc(86px + var(--safe-r)); }
#ask.nudge { animation: nudge 0.9s ease-in-out 2; }
@keyframes nudge { 50% { transform: translateX(-50%) scale(1.08); border-color: var(--good); } }
#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;
  pointer-events: none;
  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; } }
#praise.warn { color: #ffb24d; }
@media (prefers-reduced-motion: reduce) { #praise, #ask.nudge, .ghost { animation: none !important; } }

/* ---------- starting the drone ----------
   Off to the right so the controls never hide the drone they start. */
#startPanel {
  position: fixed; left: 74%; top: 56%; transform: translate(-50%, -50%);
  display: flex; gap: 18px; align-items: center;
}
#startPanel button { background: none; border: 0; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
#startPanel .cap { font-size: 14px; color: var(--text); text-shadow: 0 1px 6px #000; white-space: nowrap; }
#startPanel .cap b { color: #ff7b7b; }
#startPanel .is-on .cap b { color: var(--good); }
.switch .track {
  width: 96px; height: 48px; border-radius: 24px; position: relative;
  background: #3a4560; border: 2px solid var(--line); transition: background 0.2s;
}
.switch .knob {
  position: absolute; top: 4px; left: 4px; width: 36px; height: 36px; border-radius: 50%;
  background: #eaf0ff; transition: left 0.2s;
}
.switch.is-on .track { background: var(--good); }
.switch.is-on .knob { left: 52px; }
.power { position: relative; }
.power .ring {
  width: 104px; height: 104px; border-radius: 50%; display: block;
  background: conic-gradient(var(--good) calc(var(--p, 0) * 360deg), rgba(255,255,255,0.15) 0);
}
.power .sym {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center;
  background: #e9edf6; color: #1b2438; font-size: 40px; line-height: 1;
}
.power:disabled { opacity: 0.35; }
.attention { animation: attention 1.2s ease-in-out infinite; }
@keyframes attention { 50% { filter: drop-shadow(0 0 14px var(--good)) brightness(1.15); } }
#holdRing {
  position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%);
  width: 92px; height: 92px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(var(--good) calc(var(--p, 0) * 360deg), rgba(255,255,255,0.15) 0);
}
#holdRing span { position: absolute; inset: 10px; border-radius: 50%; background: rgba(11, 18, 32, 0.85); }

/* ---------- the coach: a ghost thumb shows which way to push ---------- */
.ghost {
  position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border-radius: 50%; border: 2px dashed rgba(255, 255, 255, 0.85); background: rgba(255,255,255,0.18);
  pointer-events: none; animation: ghost 1.3s ease-in-out infinite;
}
@keyframes ghost {
  0%, 15% { transform: translate(0, 0); opacity: 0; }
  30% { opacity: 1; }
  70%, 100% { transform: translate(calc(var(--gx) * 38px), calc(var(--gy) * 38px)); opacity: 0.9; }
}
.stick-label {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; font-size: 13px; font-weight: 700; color: #fff; text-shadow: 0 1px 6px #000;
  pointer-events: none;
}
body.no-sticks #touchSticks { display: none; }
#keys {
  position: fixed; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%);
  padding: 6px 12px; border-radius: 10px; background: var(--panel);
  color: var(--muted); font-size: 13px; white-space: nowrap; display: flex; gap: 10px; align-items: center;
}
#keys kbd {
  display: inline-block; min-width: 26px; padding: 3px 6px; border-radius: 6px; text-align: center;
  border: 1px solid var(--line); background: #1a2440; color: var(--text); font: 600 13px/1.2 system-ui, sans-serif;
}
#keys kbd.on { background: var(--good); color: #06101f; border-color: var(--good); }
.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; }
#savePrompt { margin: 4px 0 0; font-size: 14px; color: var(--muted); }

/* ---------- register / log in ---------- */
#authCard {
  z-index: 60; width: min(92vw, 380px); max-height: 94vh; overflow-y: auto; text-align: left;
  background: #101a30; gap: 8px; padding: 18px 20px;
  box-shadow: 0 0 0 100vmax rgba(3, 6, 14, 0.72);   /* dims everything behind */
}
#authCard .close { position: absolute; top: 8px; right: 8px; padding: 6px 12px; min-height: 36px; }
#authCard h2 { text-align: center; }
.tabs { display: flex; gap: 6px; }
.tab { flex: 1; padding: 8px; min-height: 40px; }
.tab.on { background: var(--accent); border-color: var(--accent); color: #06101f; font-weight: 700; }
#authForm { display: flex; flex-direction: column; gap: 6px; }
#authForm label { font-size: 14px; color: var(--muted); margin-top: 4px; }
#authForm input {
  font: inherit; color: var(--text); background: #0f1830; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
}
#pwRule { font-size: 12px; }
.error { color: #ff8f8f; min-height: 18px; margin: 4px 0; font-size: 14px; }
.note { font-size: 12px; color: var(--muted); margin: 0; }

/* ---------- 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; }

/* ---------- the test site says so ---------- */
#testBadge {
  position: fixed; z-index: 70; left: calc(12px + var(--safe-l)); top: calc(58px + var(--safe-t));
  padding: 3px 12px; border-radius: 8px; background: #ff8a1f; color: #1b0f00;
  font: 800 12px/1.4 system-ui, sans-serif; letter-spacing: 0.1em; pointer-events: 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; } }
