:root {
  --bg: #f5f5f7; --fg: #1d1d1f; --muted: #6e6e73; --card: #fff; --line: #d2d2d7;
  --accent: #4f46e5; --error: #d70015;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1c1c1e; --fg: #f5f5f7; --muted: #98989d; --card: #2c2c2e; --line: #3a3a3c; --accent: #818cf8; --error: #ff453a; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
[hidden] { display: none !important; }

.panel { max-width: 420px; margin: 12vh auto 0; padding: 0 16px; }
.panel h1 { font-size: 28px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.error { color: var(--error); min-height: 1.4em; }
header { display: flex; align-items: baseline; justify-content: space-between; }
form { display: grid; gap: 10px; }
input[type=email], input[type=password] { padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--fg); font: inherit; }
button { padding: 10px 14px; border-radius: 10px; border: 0; background: var(--accent); color: #fff; font: inherit; cursor: pointer; }
button.link { background: none; color: var(--accent); padding: 0; }
button.link.danger { color: var(--error); font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
#account { margin-top: 40px; padding-top: 12px; border-top: 1px solid var(--line); }
#account .error { font-size: 13px; margin: 6px 0 0; }

#device-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
#device-list button { width: 100%; text-align: left; background: var(--card); color: var(--fg);
  border: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
#device-list button:hover { border-color: var(--accent); }
#device-list .platform { color: var(--muted); font-size: 13px; }

#viewer { position: fixed; inset: 0; height: 100dvh; display: flex; flex-direction: column; background: #000; }
/* Nothing on the page scrolls or zooms under a finger while a screen is shown. */
body.viewing { overflow: hidden; overscroll-behavior: none; }
#bar { display: flex; gap: 12px; align-items: center; background: #1c1c1e; color: #f5f5f7; font-size: 13px;
  padding: max(6px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left)); }
#bar #viewer-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#bar #viewer-state { color: #98989d; flex: 1; white-space: nowrap; }
#bar button { padding: 4px 10px; font-size: 13px; }
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#video { width: 100%; height: 100%; object-fit: contain; display: block; cursor: default; transform-origin: 0 0; }
/* Where the host's pointer is, when a finger drives it: red, green while the button is held. */
#cursor { position: absolute; left: -4px; top: -4px; width: 8px; height: 8px; border-radius: 50%;
  background: #ff3b30; border: 1px solid #fff; box-shadow: 0 0 2px rgba(0, 0, 0, .7); pointer-events: none; }
#cursor.pressing { background: #34c759; }
/* Receives keystrokes and IME composition; kept focusable but out of sight. 16px: a smaller font
   makes iOS zoom the page when it is focused. */
#ime { position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0;
  resize: none; font-size: 16px; }
/* Special keys, on top of the soft keyboard (placed by placeKeys). */
#keys { position: fixed; left: 0; right: 0; top: 0; display: flex; gap: 6px; overflow-x: auto;
  padding: 6px max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left));
  background: rgba(28, 28, 30, .96); -webkit-overflow-scrolling: touch; }
#keys button { flex: 0 0 auto; min-width: 44px; padding: 9px 10px; border-radius: 8px; background: #3a3a3c;
  color: #f5f5f7; font-size: 15px; }
#keys button.on { background: var(--accent); }
@media (pointer: coarse) {
  #swap-label { display: none; }   /* a phone has no Ctrl key to swap */
  #bar { gap: 8px; }
  #bar button { padding: 7px 12px; font-size: 14px; }
}
