:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev2: #1c232d;
  --border: #2a323d;
  --text: #e6edf3;
  --text-dim: #9aa7b4;
  --accent: #2f9bff;
  --accent-2: #1f6feb;
  --green: #2ea043;
  --gray: #6e7681;
  --amber: #d29922;
  --danger: #f85149;
  --shadow: 0 6px 24px rgba(0,0,0,.4);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--bg-elev);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 26px; color: var(--accent); }
.title { font-size: 16px; font-weight: 700; letter-spacing: .3px; }
.subtitle { font-size: 12px; color: var(--text-dim); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.selected-chip {
  padding: 6px 12px; border-radius: 999px; background: var(--bg-elev2);
  border: 1px solid var(--border); font-size: 13px; max-width: 340px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.selected-chip[data-empty="true"] { color: var(--text-dim); }
.selected-chip[data-empty="false"] { color: var(--text); border-color: var(--accent-2); }

.btn {
  cursor: pointer; border: 1px solid var(--border); background: var(--bg-elev2);
  color: var(--text); padding: 7px 14px; border-radius: 8px; font-size: 13px;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: #232b36; }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.user-chip {
  display: flex; align-items: baseline; gap: 6px; padding: 6px 12px;
  border-radius: 999px; background: var(--bg-elev2); border: 1px solid var(--border);
  font-size: 13px; max-width: 220px; overflow: hidden;
}
.user-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-login { color: var(--text-dim); font-size: 11.5px; white-space: nowrap; }

/* ---------- login gate ---------- */
.login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 340px; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 26px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-brand { display: flex; align-items: center; gap: 10px; }
.login-brand .logo { font-size: 24px; color: var(--accent); }
.login-brand .title { font-size: 16px; font-weight: 700; }
.login-note { margin: -6px 0 4px; font-size: 12.5px; color: var(--text-dim); }
.login-field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--text-dim); }
.login-field input {
  background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 9px 11px; font-size: 14px;
}
.login-field input:focus { outline: none; border-color: var(--accent-2); }
.login-error { font-size: 12.5px; color: var(--danger); background: rgba(248,81,73,.1); border: 1px solid rgba(248,81,73,.35); border-radius: 8px; padding: 8px 10px; }
.login-submit { width: 100%; padding: 9px 14px; font-size: 14px; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 320px minmax(360px, 1fr) 380px;
  gap: 18px; padding: 18px; align-items: start;
  max-width: 1400px; margin: 0 auto;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- device pool ---------- */
.pool {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.pool-head { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.pool-head h2 { margin: 0 0 8px; font-size: 14px; }
.pool-counts { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-dim); background: var(--bg-elev2);
}
.pill.active { color: #7ee2a8; border-color: #245c37; }
.pill.offline { color: #c0c9d2; }
.pill.total { color: #9db8e6; }

.device-list { list-style: none; margin: 0; padding: 8px; max-height: 72vh; overflow: auto; }
.device-list .empty { padding: 16px; color: var(--text-dim); text-align: center; }
.device {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 10px; cursor: pointer; border: 1px solid transparent;
  transition: background .12s, border-color .12s;
}
.device:hover { background: var(--bg-elev2); }
.device.selected { background: #12233b; border-color: var(--accent-2); }
.device[data-online="false"] { opacity: .72; }
.device[data-online="false"]:not(.selected) { cursor: pointer; }
.device.unavailable { cursor: not-allowed; }
.device.mine { border-color: #245c37; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; background: var(--gray); }
.device[data-online="true"] .dot { background: var(--green); box-shadow: 0 0 8px #2ea04388; }
.device-main { min-width: 0; flex: 1; }
.device-label { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-id { display: block; font-size: 11.5px; color: var(--text-dim); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-badges { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.pool-foot { padding: 8px 16px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-dim); }

/* tri-state occupancy badge */
.status-badge {
  font-size: 10px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--text-dim); white-space: nowrap; letter-spacing: .2px; font-weight: 600;
}
.status-badge.idle { color: #7ee2a8; border-color: #245c37; background: rgba(46,160,67,.08); }
.status-badge.used { color: var(--amber); border-color: #6b5115; background: rgba(210,153,34,.1); }
.status-badge.used.mine { color: #7cc4ff; border-color: #1f4c78; background: rgba(47,155,255,.12); }
.status-badge.unavailable { color: var(--text-dim); border-color: var(--border); background: rgba(110,118,129,.08); }
.release-btn { font-size: 10.5px; padding: 3px 9px; border-radius: 999px; }

/* ---------- stage / screen ---------- */
.stage { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.screen-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.screen-toolbar .btn:disabled { opacity: .5; cursor: not-allowed; }
.fps-label { font-size: 12.5px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.fps-label select { background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; }
.live-status { font-size: 12px; color: var(--text-dim); margin-left: auto; }
.live-status.live { color: #7ee2a8; }
.live-status.err { color: #ff8078; }
.live-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.screen-panel {
  background: #05070a; border: 1px solid var(--border); border-radius: var(--radius);
  aspect-ratio: 16 / 9; display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden; box-shadow: var(--shadow);
}
.screen-placeholder { text-align: center; color: var(--text-dim); padding: 24px; max-width: 460px; }
.screen-icon { font-size: 40px; opacity: .5; margin-bottom: 8px; }
.screen-title { font-size: 15px; color: var(--text); margin-bottom: 6px; }
.screen-note { font-size: 12.5px; line-height: 1.6; }
.screen-note code { background: var(--bg-elev2); padding: 1px 5px; border-radius: 5px; }

.device-info { position: absolute; inset: 0; padding: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; align-content: start; background: linear-gradient(180deg,#0a0f16,#05070a); }
.device-info .kv { display: flex; flex-direction: column; gap: 2px; }
.device-info .k { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; }
.device-info .v { font-size: 14px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.device-info .info-head { grid-column: 1 / -1; font-size: 13px; color: var(--accent); font-weight: 700; }

.activity {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; height: 150px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; color: var(--text-dim);
}
.activity .line { padding: 2px 0; border-bottom: 1px dashed #1e2530; }
.activity .ok { color: #7ee2a8; }
.activity .err { color: #ff8078; }
.activity .t { color: #5e6875; margin-right: 8px; }

/* ---------- remote ---------- */
.remote-panel {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 12px;
  box-shadow: var(--shadow);
}
.remote-wrap { position: relative; width: 300px; max-width: 100%; user-select: none; }
.remote-img { width: 100%; display: block; border-radius: 10px; -webkit-user-drag: none; }
.remote-overlay { position: absolute; inset: 0; }

.hotspot {
  position: absolute; transform: translate(-50%, -50%);
  border: 0; padding: 0; margin: 0; cursor: pointer; background: transparent;
  border-radius: 50%; transition: background .08s, box-shadow .08s, transform .05s;
}
.hotspot:hover { background: rgba(47,155,255,.20); box-shadow: 0 0 0 2px rgba(47,155,255,.55) inset; }
.hotspot:active { transform: translate(-50%, -50%) scale(.94); }
.hotspot.flash { background: rgba(47,155,255,.5); box-shadow: 0 0 14px rgba(47,155,255,.8); }
.hotspot.rect { border-radius: 10px; }
.hotspot.disabled { cursor: not-allowed; }
.hotspot.disabled:hover { background: rgba(248,81,73,.12); box-shadow: 0 0 0 2px rgba(248,81,73,.4) inset; }
.remote-panel.no-target .hotspot:not(.disabled):hover { background: rgba(210,153,34,.16); box-shadow: 0 0 0 2px rgba(210,153,34,.4) inset; }

.remote-hint { font-size: 12px; color: var(--text-dim); text-align: center; }

/* ---------- toasts ---------- */
.toast-stack { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 70; }
.toast {
  background: var(--bg-elev2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; max-width: 340px;
  animation: slidein .16s ease; }
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--danger); }
.toast .toast-key { font-family: ui-monospace, monospace; color: var(--accent); }
@keyframes slidein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- "how to connect" modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5,7,10,.62); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px;
}
.modal {
  width: 100%; max-width: 420px; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-close {
  cursor: pointer; border: 0; background: transparent; color: var(--text-dim);
  font-size: 15px; line-height: 1; padding: 4px 6px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg-elev2); color: var(--text); }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.connect-device-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--text-dim);
}
.claim-btn { width: 100%; padding: 10px 14px; font-size: 14px; }
.connect-divider {
  font-size: 11.5px; color: var(--text-dim); text-align: center; position: relative;
  margin: 2px 0;
}
.connect-row {
  display: flex; align-items: center; gap: 8px; background: var(--bg-elev2);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.connect-label { font-size: 11px; color: var(--text-dim); flex: 0 0 auto; width: 52px; }
.connect-value {
  flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; overflow: auto; white-space: nowrap; background: transparent;
}
.copy-btn { flex: 0 0 auto; padding: 4px 10px; font-size: 11.5px; }
