:root {
  --bg: #0d1117;
  --panel: #161b22;
  --line: #262d38;
  --fg: #e6edf3;
  --dim: #8b949e;
  --accent: #58a6ff;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.view { display: none; min-height: 100%; }
.view.active { display: flex; flex-direction: column; }

#view-login, #view-devices {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.panel {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
}
.panel.wide { max-width: 560px; }

h1 { margin: 0 0 4px; font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 17px; font-weight: 600; }
.dim { color: var(--dim); }
.sub { margin: 0 0 22px; color: var(--dim); }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}

label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--dim); }
label.row { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; color: var(--fg); }
label.row input { margin: 0; }

input[type=password], input[type=text], select {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 13px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  padding: 9px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #06121f;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
#login-btn { width: 100%; margin-top: 20px; }

button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--fg);
  font-weight: 500;
}
button.ghost:hover { background: #1f2630; }
button.ghost.danger { color: var(--bad); border-color: #40232a; }

.error {
  margin: 14px 0 0; padding: 9px 11px;
  background: #2d1418; border: 1px solid #5c2b31; border-radius: 6px;
  color: #ffa198; font-size: 13px;
}

/* Device list */
.devices { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.devices li {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 15px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.devices .meta { flex: 1; min-width: 0; }
.devices .name { font-weight: 600; }
.devices .id { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.busy { background: var(--warn); }

.settings { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 14px; }
.settings summary { cursor: pointer; color: var(--dim); font-size: 13px; }

/* Session */
#view-session { background: #000; }

/* Pin the session to the viewport so the HUD cannot be pushed off the bottom
   edge. dvh tracks mobile browser chrome as it hides and shows, which vh does
   not — on a phone, vh is the *largest* possible viewport and clips content. */
#view-session.active {
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0; /* let the flex child actually shrink instead of overflowing */
  overflow: hidden;
  background: #000;
  /* Stop the browser panning, zooming or firing synthetic mouse events; every
     touch here is ours to interpret. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#video {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
  /* Nearest-neighbour keeps remote text crisp instead of smeared when the
     stream is not at an exact 1:1 scale. */
  image-rendering: -webkit-optimize-contrast;
}

.local-cursor {
  position: absolute;
  width: 20px; height: 29px;
  pointer-events: none;
  z-index: 6;
  /* The path's tip sits at (2, 1.5), so shift the element to put that tip
     exactly on the reported cursor coordinate rather than the box corner. */
  transform: translate(-2px, -1.5px);
  /* A soft shadow on top of the stroke keeps it readable over busy content
     such as a photo or a syntax-highlighted editor. */
  filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.55));
}
.local-cursor svg { display: block; }

.overlay-click {
  position: absolute; inset: 0; z-index: 8;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 10, 16, 0.72);
  backdrop-filter: blur(2px);
  cursor: pointer;
}
.overlay-click[hidden] { display: none; }
.click-inner { text-align: center; display: grid; gap: 8px; }
.click-inner strong { font-size: 19px; }
.click-inner span { color: var(--dim); font-size: 13px; }

.stats {
  position: absolute; top: 12px; left: 12px; z-index: 7;
  padding: 11px 13px;
  background: rgba(6, 10, 16, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.65;
  white-space: pre;
  pointer-events: none;
  color: var(--fg);
}

.drop-hint {
  position: absolute; inset: 0; z-index: 9;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 10, 16, 0.7);
  border: 3px dashed var(--accent);
  pointer-events: none;
}
.drop-hint[hidden] { display: none; }
.drop-inner { font-size: 17px; font-weight: 600; color: var(--fg); }

.transfers {
  position: absolute; right: 12px; bottom: 12px; z-index: 7;
  display: grid; gap: 6px;
  max-width: 380px;
  pointer-events: none;
}
.transfers[hidden] { display: none; }
.transfer {
  padding: 7px 11px;
  background: rgba(6, 10, 16, 0.88);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono); font-size: 11.5px;
  color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.transfer.ok { border-color: #2b5f38; color: var(--ok); }
.transfer.bad { border-color: #5c2b31; color: #ffa198; }

.hud-select {
  width: auto;
  padding: 4px 8px;
  font-size: 11.5px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--fg);
  font-family: var(--mono);
}
.hud-select[hidden] { display: none; }

.session-error {
  position: absolute; left: 50%; top: 24px; transform: translateX(-50%);
  z-index: 10;
  max-width: min(560px, 90vw);
  padding: 12px 16px;
  background: #2d1418;
  border: 1px solid #5c2b31;
  border-radius: 8px;
  color: #ffa198;
  font-size: 13px; line-height: 1.5;
}
.session-error[hidden] { display: none; }

/* Touch layout: the HUD needs finger-sized targets and room to wrap. */
body.touch .hud { gap: 10px; flex-wrap: wrap; padding: 8px 10px; }
body.touch .hud button { padding: 9px 13px; font-size: 13px; }
body.touch .hud .dim { font-size: 11px; }

.hud {
  display: flex; align-items: center; gap: 16px;
  padding: 7px 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 12px;
}
.hud .spacer { flex: 1; }
.hud button { padding: 5px 10px; font-size: 11.5px; }

.toast {
  position: fixed; bottom: 58px; left: 50%; transform: translateX(-50%);
  z-index: 20;
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  max-width: 80vw;
}
.toast[hidden] { display: none; }

code {
  font-family: var(--mono); font-size: 12px;
  background: var(--bg); padding: 1px 5px; border-radius: 4px;
  border: 1px solid var(--line);
}

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise 0.18s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translate(-50%, 6px); } }
}
