:root {
  --bg: #061018;
  --panel: rgba(8, 24, 40, 0.88);
  --text: #e8f4ff;
  --muted: #8fb3c9;
  --accent: #3ec7ff;
  --ok: #3dd68c;
  --warn: #f5c542;
  --bad: #ff6b6b;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

#canvas-wrap, #c {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: fixed;
  z-index: 10;
  pointer-events: none;
}

.hud * { pointer-events: auto; }

.title {
  top: 16px;
  left: 16px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid rgba(62, 199, 255, 0.25);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  max-width: min(420px, calc(100vw - 200px));
}

.title h1 {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.title p {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

.qr-panel {
  top: 16px;
  right: 16px;
  width: 168px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid rgba(62, 199, 255, 0.25);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  text-align: center;
}

.qr-panel .label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

#qrcode {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  border-radius: 8px;
  padding: 8px;
  min-height: 144px;
}

#qrcode img, #qrcode canvas {
  display: block;
  width: 128px !important;
  height: 128px !important;
}

.status {
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.4;
}

.status .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  background: var(--warn);
}

.status.waiting .dot { background: var(--warn); }
.status.connected .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status.error .dot { background: var(--bad); }

.legend {
  bottom: 16px;
  left: 16px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid rgba(62, 199, 255, 0.2);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.legend span { color: var(--text); font-weight: 600; }
.legend .jib { color: #7ec8ff; }
.legend .main { color: #ffffff; }
.legend .spin { color: #ff7a59; }

/* Controller page */
body.controller {
  overflow: auto;
  background: linear-gradient(160deg, #07131d 0%, #0b2a3d 50%, #12304a 100%);
}

.controller-wrap {
  min-height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 28px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.controller-wrap h1 {
  font-size: 24px;
  font-weight: 700;
}

.card {
  background: var(--panel);
  border: 1px solid rgba(62, 199, 255, 0.22);
  border-radius: 18px;
  padding: 18px;
  backdrop-filter: blur(12px);
}

.card p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  margin-top: 8px;
}

.big-btn {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 18px 20px;
  font-size: 18px;
  font-weight: 700;
  color: #041018;
  background: linear-gradient(135deg, #5ce1ff, #3ec7ff 40%, #2aa8ff);
  box-shadow: 0 10px 30px rgba(62, 199, 255, 0.35);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.big-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.big-btn.secondary {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.15);
  box-shadow: none;
}

.meter {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 8px 10px;
  font-size: 13px;
  align-items: center;
}

.meter .bar {
  height: 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  overflow: hidden;
}

.meter .fill {
  height: 100%;
  width: 50%;
  background: var(--accent);
  border-radius: 999px;
  transform-origin: left center;
}

.hint {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.hint strong { color: var(--text); }

.error-box {
  color: #ffd0d0;
  background: rgba(255, 80, 80, 0.12);
  border: 1px solid rgba(255, 100, 100, 0.35);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
  display: none;
}

.error-box.show { display: block; }

@media (max-width: 640px) {
  .title { max-width: calc(100vw - 32px); }
  .qr-panel { width: 140px; padding: 10px; }
  #qrcode { min-height: 116px; padding: 6px; }
  #qrcode img, #qrcode canvas { width: 104px !important; height: 104px !important; }
}

.touch-pad {
  margin-top: 12px;
  height: 140px;
  border-radius: 16px;
  border: 1px dashed rgba(62, 199, 255, 0.35);
  background: rgba(62, 199, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  touch-action: none;
  user-select: none;
}

.bottom-stack {
  left: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  max-width: min(340px, calc(100vw - 32px));
}

.bottom-stack .legend {
  position: relative;
  left: auto;
  bottom: auto;
  width: 100%;
}

.imu-panel {
  width: 100%;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid rgba(62, 199, 255, 0.28);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  font-variant-numeric: tabular-nums;
}

.imu-panel.live {
  border-color: rgba(61, 214, 140, 0.45);
}

.imu-title {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.04em;
  color: var(--text);
  margin-bottom: 10px;
}

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

.imu-grid-sub {
  margin-top: 8px;
  opacity: 0.92;
}

.imu-item span {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 2px;
}

.imu-item strong {
  display: block;
  font-size: 18px;
  font-weight: 700;
  color: #7ee0ff;
  line-height: 1.2;
}

.imu-grid-sub .imu-item strong {
  font-size: 15px;
  color: var(--text);
}

.imu-meta {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

@media (max-width: 640px) {
  .imu-item strong { font-size: 15px; }
  .imu-grid-sub .imu-item strong { font-size: 13px; }
}
