:root {
  --bg: #0f1218;
  --panel: #171b24;
  --panel-2: #1e2330;
  --border: #2a3142;
  --text: #e6e9f0;
  --muted: #8b94a8;
  --accent: #4a9eff;
  --accent-dim: #2d6bb8;
  --danger: #ff5a5a;
  --ok: #3ddc84;
  --warn: #ffb020;
  --radius: 8px;
}

* { box-sizing: border-box; }

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

button, input, select {
  font: inherit;
  color: inherit;
}

/* ── 登录页 ─────────────────────────────────────── */

.login-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 20px;
}

.login-card .sub {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 13px;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}

.field input {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}

.field input:focus { border-color: var(--accent-dim); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}

.btn:hover:not(:disabled) { background: #252c3c; border-color: #3a4459; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent); }

.btn-danger { border-color: #5a2a2a; color: #ff9a9a; }
.btn-danger:hover:not(:disabled) { background: #3a1f1f; }

.btn-block { width: 100%; }

.msg {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  display: none;
}
.msg.show { display: block; }
.msg.error { background: #3a1f1f; border: 1px solid #5a2a2a; color: #ff9a9a; }
.msg.ok { background: #16301f; border: 1px solid #24503a; color: #8fe0b0; }

.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tabs button {
  flex: 1;
  padding: 8px;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

/* ── 控制台布局 ─────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  grid-template-rows: 48px 1fr;
  height: 100vh;
  gap: 1px;
  background: var(--border);
}

.topbar {
  grid-column: 1 / -1;
  background: var(--panel);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.topbar .brand { font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; }

.side {
  background: var(--panel);
  overflow-y: auto;
  padding: 16px;
}

.main {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
}

.side h2 {
  margin: 0 0 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.side + .side h2:not(:first-child) { margin-top: 24px; }

/* ── 设备列表 ───────────────────────────────────── */

.device {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--panel-2);
}
.device:hover { border-color: var(--accent-dim); }
.device.active { border-color: var(--accent); background: #1b2838; }
.device .info { flex: 1; min-width: 0; }
.device .name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}
.device .meta { font-size: 11px; color: var(--muted); }

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #4a5464;
  flex-shrink: 0;
}
.dot.online { background: var(--ok); box-shadow: 0 0 6px rgba(61,220,132,.6); }
.dot.busy { background: var(--warn); }

/* ── 画面 ───────────────────────────────────────── */

.stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  /* 必须是确定尺寸，不能靠内容撑开。
     否则 .stage 的高度 = canvas 的高度，而 canvas 的高度又要根据
     .stage 的高度算出来 —— 循环依赖会让画面每重算一次就缩小一圈。
     画面尺寸统一以父容器 .main 为基准计算（见 console.js 的 layoutCanvas）。 */
  width: 100%;
  height: 100%;
}

#screen {
  display: block;
  background: #000;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
  cursor: crosshair;
  touch-action: none;   /* 阻止浏览器把触摸解释成滚动/缩放 */
  max-width: 100%;
  max-height: 100%;
}

.stage .overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
  pointer-events: none;
}

.stage .overlay.hidden { display: none; }

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 控制面板 ───────────────────────────────────── */

.keypad {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.keypad .btn { padding: 8px; font-size: 12px; }

.quality label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0 4px;
}
.quality input[type=range] { width: 100%; }

.stats {
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, Consolas, monospace;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-all;
}

.pair-code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 30px;
  letter-spacing: .18em;
  text-align: center;
  padding: 18px;
  background: var(--panel-2);
  border: 1px dashed var(--accent-dim);
  border-radius: var(--radius);
  margin: 10px 0;
}

.hint { font-size: 12px; color: var(--muted); line-height: 1.7; }

.audit-entry {
  font-size: 11px;
  font-family: ui-monospace, Consolas, monospace;
  padding: 6px 8px;
  border-left: 2px solid var(--border);
  margin-bottom: 4px;
  color: var(--muted);
  word-break: break-all;
}
.audit-entry .act { color: var(--text); }

.chain-ok { color: var(--ok); }
.chain-bad { color: var(--danger); }

@media (max-width: 1100px) {
  .app { grid-template-columns: 220px 1fr 220px; }
}
