:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --text: #e6e8ec;
  --muted: #99a0ab;
  --accent: #4f8cff;
  --ok: #35c46a;
  --off: #7b828d;
  --danger: #ff4d4f;
  --border: #2a2f3a;
  --radius: 10px;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

header h1 { font-size: 16px; margin: 0; font-weight: 600; }

main { max-width: 900px; margin: 0 auto; padding: 20px; }

.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }

input {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  width: 100%;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.login {
  max-width: 340px;
  margin: 12vh auto;
  display: grid;
  gap: 12px;
}

.device {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  margin-bottom: 10px;
}
.device .name { font-weight: 600; }
.device .meta { font-size: 12px; }

.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); flex: none; }
.dot.online { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel-2);
}

/* Controller */
.controller-main { max-width: 960px; }

.video-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 19.5;
  max-height: 70vh;
  background: #0b0d11;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 8px;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
}
.video-shell.pointer-ready {
  cursor: none;
}
.video-shell.active { border-color: var(--accent); }
.video-shell video,
.video-shell img#previewJpeg,
.video-shell canvas#previewH264 {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
  pointer-events: none;
}
.video-shell img#previewJpeg,
.video-shell canvas#previewH264 {
  position: absolute;
  inset: 0;
  display: none;
}
.video-hint { font-size: 12px; margin: 0 0 10px; }
.video-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.45);
  pointer-events: none;
}
.cal-banner {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 4;
  pointer-events: none;
  background: rgba(8, 10, 14, 0.82);
  color: #f4f6fb;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
  border: 1px solid rgba(255,255,255,.12);
}
.pointer-dot {
  position: absolute;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid #5eead4;
  border-radius: 50%;
  pointer-events: none;
  z-index: 5;
  display: none;
  box-shadow: 0 0 0 1px #000;
}
/* After READY the OS cursor is hidden, so the marker becomes a crosshair. */
.pointer-dot.ready {
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border: none;
  box-shadow: none;
}
.pointer-dot.ready::before,
.pointer-dot.ready::after {
  content: "";
  position: absolute;
  background: #5eead4;
  filter: drop-shadow(0 0 1px #000);
}
.pointer-dot.ready::before {
  left: 50%;
  top: 0;
  width: 2px;
  height: 100%;
  margin-left: -1px;
}
.pointer-dot.ready::after {
  top: 50%;
  left: 0;
  height: 2px;
  width: 100%;
  margin-top: -1px;
}
.debug-overlay {
  position: absolute; left: 10px; bottom: 10px;
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(0,0,0,.65);
  padding: 4px 8px;
  border-radius: 6px;
  pointer-events: none;
}
.debug-toggle { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.debug-toggle input { width: auto; }

.trackpad {
  height: 280px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: repeating-linear-gradient(45deg, #14171d, #14171d 12px, #161a20 12px, #161a20 24px);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); user-select: none; touch-action: none;
  cursor: crosshair;
}
.trackpad.active { border-color: var(--accent); color: var(--accent); }

.controls { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.err { color: var(--danger); font-size: 13px; min-height: 18px; }
.log {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; color: var(--muted);
  background: #0b0d11; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; height: 120px; overflow: auto; white-space: pre-wrap;
}
a { color: var(--accent); }
