:root {
  --bg: #14161a;
  --panel: #1c1f26;
  --panel-2: #23272f;
  --line: #2e333c;
  --fg: #e6e9ee;
  --muted: #8b93a1;
  --accent: #46a3ff;
  --ok: #37c26e;
  --warn: #f0a63a;
  --err: #f05a5a;
}

* { box-sizing: border-box; }

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

#app {
  display: grid;
  grid-template-columns: 272px 1fr;
  height: 100vh;
}

/* ---------- sidebar ---------- */
#sidebar {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-height: 0;
}

.side-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.side-head h1 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .3px;
}
.conn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.dot.ok { background: var(--ok); }
.dot.err { background: var(--err); }
.dot.warn { background: var(--warn); }

.auth-row {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.auth-row input { flex: 1; }

.side-tools {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.side-tools input { flex: 1; }

input[type="search"], input[type="password"] {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--fg);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}
input[type="search"]:focus, input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
}

.device-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.device-list .empty {
  color: var(--muted);
  padding: 18px 12px;
  text-align: center;
  font-size: 13px;
}
.device {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  align-items: center;
}
.device:hover { background: var(--panel-2); }
.device.active { background: #263040; box-shadow: inset 0 0 0 1px var(--accent); }
.device.offline { opacity: .5; cursor: default; }

.thumb {
  width: 54px;
  height: 96px;
  border-radius: 5px;
  background: #0e1013 center/contain no-repeat;
  border: 1px solid var(--line);
  flex: none;
}
.thumb.placeholder { display: grid; place-items: center; color: var(--muted); font-size: 11px; }

.device .meta { min-width: 0; }
.device .name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.device .sub {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.device .row2 {
  display: flex;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
}
/* State the operator has to know before opening a device: no injection without the
   accessibility service, and no system cast indicator on the screenshot route. */
.device .row2 .flag.warn { color: var(--warn); }
.device .row2 .flag.accent { color: var(--accent); }

.side-foot {
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
}

/* ---------- stage ---------- */
#stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.title-block { display: flex; flex-direction: column; min-width: 150px; }
.title-block strong { font-size: 14px; }
.muted { color: var(--muted); font-size: 12px; }

.metrics {
  display: flex;
  gap: 14px;
  margin-left: auto;
}
.metrics div {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 52px;
}
.metrics b { font-size: 15px; font-variant-numeric: tabular-nums; }
.metrics span { font-size: 10px; color: var(--muted); }

.tool-buttons { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.toggle {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.toggle input { accent-color: var(--accent); }

.btn {
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }

.controls {
  display: flex;
  gap: 22px;
  align-items: flex-end;
  padding: 10px 16px;
  background: #181b21;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.ctl { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.ctl label {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}
.ctl output { color: var(--fg); font-variant-numeric: tabular-nums; }
.ctl input[type="range"] { accent-color: var(--accent); width: 100%; }
.keys { flex-direction: row; gap: 6px; min-width: 0; align-items: center; }
.keys .btn { padding: 6px 10px; white-space: nowrap; }
.text-row {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  min-width: 240px;
  flex: 1 1 240px;
}
.text-row input {
  flex: 1;
  min-width: 0;
  background: #101318;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--fg);
  padding: 6px 10px;
  font-size: 13px;
}
.text-row input:focus { outline: none; border-color: var(--accent); }
.text-row input:disabled { opacity: .45; }
.control-notice {
  /* Takes the whole row of the wrapping flex container so the guidance reads as a
     line of prose instead of a narrow column squeezed next to the buttons. */
  flex: 1 0 100%;
  margin: 0;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--warn);
  background: rgba(240, 166, 58, .1);
  border-left: 3px solid var(--warn);
  border-radius: 0 6px 6px 0;
}

.screen-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  /* Flex rather than grid: in a grid with an implicit auto row, the row is sized by the
     image itself, so the image's `max-height: 100%` has no definite height to resolve
     against and is dropped — a 756x1680 frame rendered full size in a 640px box and the
     viewer only saw the top third. A flex container with a definite height resolves it. */
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-conic-gradient(#101216 0 25%, #14171c 0 50%) 50% / 28px 28px;
  overflow: hidden;
}

#screen {
  max-width: 100%;
  max-height: 100%;
  display: none;
  object-fit: contain;
  background: #000;
  box-shadow: 0 10px 40px rgba(0,0,0,.55);
  touch-action: none;
}
#screen.live { display: block; cursor: crosshair; }
#screen.live:not(.interactive) { cursor: default; }

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 6px;
  color: var(--muted);
  pointer-events: none;
}
.placeholder p { margin: 0; }
.placeholder p:first-child { font-size: 16px; color: var(--fg); }
.placeholder.hidden { display: none; }

/* Notices belong in the status row, never on top of the picture: an overlay over the
   phone hides exactly what the operator is looking at, and one that never fades reads
   as scenery. */
.banner {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  max-width: 46%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(240, 90, 90, .14);
  color: #ff9d9d;
  border: 1px solid rgba(240, 90, 90, .45);
}
.banner.warn { color: var(--warn); border-color: rgba(240, 166, 58, .5); background: rgba(240, 166, 58, .12); }
.banner.info { color: var(--accent); border-color: rgba(70, 163, 255, .45); background: rgba(70, 163, 255, .12); }

/* Shown while the relay has nothing new to send: the frame is frozen, the link is fine.
   The two chips share one row so neither of them ever sits on top of the phone. */
.flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-self: flex-start;
  margin-top: 4px;
}
.still-flag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--warn);
  background: rgba(240, 166, 58, .12);
  border: 1px solid rgba(240, 166, 58, .4);
}

/* Which path is feeding frames. Deliberately calm: on the accessibility route a slow
   picture is the platform's own limit, so this states the mode rather than a fault. */
.source-flag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--accent);
  background: rgba(70, 163, 255, .12);
  border: 1px solid rgba(70, 163, 255, .4);
}

.ripple-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.ripple {
  position: absolute;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border-radius: 50%;
  border: 2px solid rgba(70, 163, 255, .95);
  background: rgba(70, 163, 255, .22);
  animation: ripple .55s ease-out forwards;
}
@keyframes ripple {
  from { transform: scale(.35); opacity: 1; }
  to { transform: scale(2.1); opacity: 0; }
}

.watermark {
  position: absolute;
  right: 10px;
  bottom: 8px;
  font-size: 11px;
  color: rgba(230, 233, 238, .5);
  background: rgba(0,0,0,.35);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}

.statusbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 12px;
}

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #sidebar { max-height: 34vh; }
  .metrics { order: 3; width: 100%; margin-left: 0; justify-content: space-between; }
}
