:root {
  --bg: #0b0d10; --fg: #e9edf2; --dim: #9aa4b1; --panel: rgba(16, 19, 24, .86);
  --line: rgba(255, 255, 255, .12); --acc: #3d8bfd; --ok: #2ecc71; --warn: #f1c40f; --bad: #ff4d4f;
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; overscroll-behavior: none; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: var(--fg); background: rgba(255,255,255,.08); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 14px; cursor: pointer; }
button:hover { background: rgba(255,255,255,.14); }
button:active { transform: scale(.97); }
.hidden { display: none !important; }

#stage { position: fixed; inset: 0; }
#vcanvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }

.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 14px; color: var(--dim); pointer-events: none; text-align: center; padding: 20px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--acc);
  border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between;
  align-items: flex-start; gap: 8px; padding: 10px calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l));
  pointer-events: none; }
#top > div { display: flex; gap: 6px; flex-wrap: wrap; pointer-events: auto; }
.pill { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px;
  white-space: nowrap; font-variant-numeric: tabular-nums; }
.pill.dim { color: var(--dim); }
.pill.ok { color: var(--ok); } .pill.warnc { color: var(--warn); } .pill.bad { color: #fff; background: var(--bad); }
.icon { width: 40px; height: 40px; padding: 0; border-radius: 50%; background: var(--panel); font-weight: 700; }
.icon.on { background: var(--acc); border-color: var(--acc); }

#bottom { position: absolute; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(560px, 60vw); }
.main { background: var(--acc); border-color: var(--acc); font-weight: 600; padding: 11px 22px; border-radius: 12px; }
.main.secondary { background: var(--panel); border-color: var(--line); }
.hint { color: var(--dim); font-size: 12px; text-align: center; background: var(--panel);
  padding: 4px 10px; border-radius: 8px; }
#power { display: flex; align-items: center; gap: 10px; background: var(--panel); padding: 6px 12px;
  border-radius: 10px; border: 1px solid var(--line); }
#power input { width: 160px; }

.stop { position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(16px + var(--safe-b));
  width: 86px; height: 86px; border-radius: 50%; background: var(--bad); border: 3px solid rgba(255,255,255,.7);
  font-weight: 800; font-size: 17px; letter-spacing: .5px; box-shadow: 0 4px 18px rgba(0,0,0,.5); z-index: 5; }
.stop:hover { background: #ff2a2d; }

#estop { position: absolute; top: 64px; left: 50%; transform: translateX(-50%); background: var(--bad);
  color: #fff; padding: 10px 16px; border-radius: 12px; display: flex; gap: 14px; align-items: center;
  font-size: 16px; box-shadow: 0 4px 20px rgba(0,0,0,.4); }
#estop button { background: #fff; color: #000; border: 0; font-weight: 700; }

/* --- сенсорные стики --- */
#sticks { position: absolute; inset: 0; pointer-events: none; }
.stick { position: absolute; bottom: calc(24px + var(--safe-b)); width: 150px; height: 150px;
  pointer-events: auto; touch-action: none; }
.stick span { position: absolute; left: 0; right: 0; bottom: -18px; text-align: center; color: var(--dim);
  font-size: 11px; text-shadow: 0 1px 2px #000; }
#stickL { left: calc(22px + var(--safe-l)); }
#stickR { right: calc(122px + var(--safe-r)); }
.stick .track { position: absolute; background: rgba(255,255,255,.10); border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px; }
.stick.v .track { left: 50%; top: 0; bottom: 0; width: 56px; transform: translateX(-50%); }
.stick.h .track { top: 50%; left: 0; right: 0; height: 56px; transform: translateY(-50%); }
.stick .knob { position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px;
  border-radius: 50%; background: rgba(255,255,255,.35); border: 2px solid rgba(255,255,255,.75);
  box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.stick.active .knob { background: rgba(61,139,253,.6); }

body.touch #bottom { bottom: calc(10px + var(--safe-b)); width: min(360px, 44vw); }
body.touch #btnStop { width: 70px; height: 70px; font-size: 14px; right: calc(22px + var(--safe-r));
  bottom: auto; top: 60px; }
body.touch #power input { width: 100px; }

/* --- панели --- */
.panel { position: absolute; top: 58px; right: calc(10px + var(--safe-r)); width: min(380px, calc(100vw - 20px));
  max-height: calc(100% - 70px); overflow: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; backdrop-filter: blur(6px); user-select: text; }
.panel h3 { margin: 0 0 8px; font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
.close { padding: 2px 8px; border-radius: 8px; }
.small { color: var(--dim); font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.nm input { width: 120px; background: rgba(0,0,0,.3); color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; font: inherit; }
#stats { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
#stats td { padding: 3px 0; border-bottom: 1px solid var(--line); }
#stats td:last-child { text-align: right; }

.set { border-bottom: 1px solid var(--line); padding: 8px 0; }
.set .lbl { display: flex; justify-content: space-between; gap: 10px; }
.set input[type=checkbox] { width: 22px; height: 22px; flex: none; }
.set .lbl b { font-variant-numeric: tabular-nums; }
.set .ctl { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.set input[type=range] { flex: 1; }
.set button { padding: 3px 9px; }
.set select { background: #1a1e24; color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 5px; }

#clock { position: absolute; left: calc(12px + var(--safe-l)); top: 58px; background: #fff; color: #000;
  padding: 8px 14px; border-radius: 10px; max-width: 260px; }
#clockVal { font: 700 54px/1 ui-monospace, Menlo, Consolas, monospace; }
#clock small { display: block; font-size: 11px; margin-top: 4px; color: #333; }

@media (max-width: 700px), (max-height: 480px) {
  .hint { display: none; }
  .icon { width: 36px; height: 36px; }
  .pill { padding: 4px 9px; font-size: 12px; }
}
