:root {
  --bg: #0a0b0f;
  --panel: #14161d;
  --panel-2: #1b1e28;
  --border: #262a36;
  --text: #e8eaf0;
  --muted: #8a90a3;
  --accent: #7c6cff;
  --accent-2: #4cc2ff;
  --danger: #ff5c6c;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; }
.row { display: flex; gap: 10px; margin-top: 16px; }
.row .btn { flex: 1; }

.view { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---- 通用组件 ---- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.btn {
  border: none; border-radius: 10px; padding: 12px 18px;
  font-size: 15px; font-weight: 600; color: var(--text);
  background: var(--panel-2); cursor: pointer; transition: filter .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 4px 24px rgba(124, 108, 255, .35);
}
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.sm { padding: 7px 14px; font-size: 13px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 4px; }
input, select, textarea {
  width: 100%; margin-top: 6px; padding: 12px 14px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 15px; outline: none;
}
input:focus { border-color: var(--accent); }

.logo { font-size: 26px; font-weight: 800; letter-spacing: .5px; display: flex; align-items: center; gap: 10px; }
.logo.small { font-size: 17px; }
.logo-glow {
  width: 14px; height: 14px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 16px var(--accent);
}
.logo.small .logo-glow { width: 10px; height: 10px; }

/* ---- 注册页 ---- */
#view-setup { align-items: center; justify-content: center; padding: 20px; }
.setup-card { width: 100%; max-width: 380px; }
.setup-card .logo { margin-bottom: 6px; }
.setup-card .btn { width: 100%; margin-top: 22px; }

/* ---- 设备列表 ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  padding-top: max(14px, env(safe-area-inset-top));
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.online { background: #3ddc84; box-shadow: 0 0 8px #3ddc84; }
.dot.offline { background: var(--muted); }
.device-main { padding: 24px 20px; max-width: 680px; width: 100%; margin: 0 auto; }
.device-main h2 { font-size: 15px; color: var(--muted); font-weight: 600; margin-bottom: 14px; }
.device-list { display: flex; flex-direction: column; gap: 10px; }
.device-item {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; cursor: pointer; transition: border-color .15s, background .15s;
}
.device-item:hover { border-color: var(--accent); background: var(--panel-2); }
.device-icon {
  width: 42px; height: 42px; border-radius: 11px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  background: linear-gradient(135deg, rgba(124,108,255,.2), rgba(76,194,255,.15));
  border: 1px solid rgba(124,108,255,.3);
}
.device-name { font-weight: 600; font-size: 15px; }
.device-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---- 会话 ---- */
.session {
  background: #000;
  /* 锁死为视口高度,防止视频内容(如竖屏显示器)把工具栏顶出可视区 */
  height: 100dvh; min-height: 0; overflow: hidden; position: relative;
}
/* 工具栏改为浮层后,画面占满整屏 —— 手机上这一块面积就是可用性 */
.video-wrap { flex: 1; min-height: 0; position: relative; overflow: hidden; touch-action: none; }
#remote-video {
  width: 100%; height: 100%; object-fit: contain; display: block;
  background: #000; pointer-events: none;
  transform-origin: 0 0; will-change: transform;
}
.session-loading {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; color: var(--muted);
  background: var(--bg); font-size: 14px;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.spinner.small { width: 18px; height: 18px; border-width: 2px; }
.device-loading {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 14px; padding: 18px 2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.switch-loading {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 10px; z-index: 5;
  background: rgba(10, 11, 15, .88); border: 1px solid var(--border);
  border-radius: 12px; padding: 13px 20px; color: var(--muted); font-size: 14px;
}
.stats {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px;
  background: rgba(10, 11, 15, .8); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 11px; font-family: ui-monospace, monospace;
  color: var(--accent-2); pointer-events: none; white-space: pre-line;
}
/* ---- 本地虚拟光标 / 手势提示 ---- */
.cursor {
  position: absolute; top: 0; left: 0; width: 26px; height: 26px;
  margin: -3px 0 0 -3px; pointer-events: none; z-index: 6;
  will-change: transform;
}
.cursor svg { width: 100%; height: 100%; fill: #fff; stroke: rgba(0,0,0,.75); stroke-width: 1.4; }
.cursor.pressed { transform-origin: 4px 4px; }
.cursor.pressed::after {
  content: ''; position: absolute; left: -6px; top: -6px; width: 38px; height: 38px;
  border-radius: 50%; border: 2px solid var(--accent-2); opacity: .9;
}
.gesture-hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(10, 11, 15, .82); border: 1px solid var(--border);
  color: var(--text); font-size: 13px; padding: 8px 16px; border-radius: 999px;
  pointer-events: none; z-index: 8; animation: pop .14s ease-out;
}
@keyframes pop { from { transform: translate(-50%, -50%) scale(.9); opacity: 0; } }
.zoom-badge {
  position: absolute; right: 10px; top: max(8px, env(safe-area-inset-top));
  background: rgba(10, 11, 15, .8); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px; font-size: 12px; color: var(--accent-2);
  z-index: 7; cursor: pointer;
}

/* ---- 底部浮层(按键条 + 工具栏) ---- */
.dock {
  position: absolute; left: 0; right: 0; bottom: var(--kb-inset, 0px);
  z-index: 20; transition: transform .22s ease, opacity .22s ease;
  /* 不用 backdrop-filter:它要对下面每一帧视频做实时模糊,手机 GPU 上直接吃掉帧率 */
  background: rgba(16, 17, 23, .96);
  border-top: 1px solid var(--border);
}
.dock.down { transform: translateY(110%); opacity: 0; pointer-events: none; }
.dock-handle {
  position: absolute; left: 50%; bottom: calc(var(--kb-inset, 0px) + max(6px, env(safe-area-inset-bottom)));
  transform: translateX(-50%); z-index: 21;
  width: 108px; height: 26px; border: none; cursor: pointer;
  background: none; display: flex; align-items: center; justify-content: center;
}
.dock-handle::before {
  content: ''; width: 62px; height: 5px; border-radius: 3px;
  background: rgba(232, 234, 240, .45); box-shadow: 0 0 10px rgba(0,0,0,.6);
}
.toolbar {
  display: flex; gap: 2px; padding: 6px 6px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  justify-content: space-evenly;
}
.dock .keybar + .toolbar { border-top: 1px solid var(--border); }
.tool {
  border: none; background: none; color: var(--muted);
  border-radius: 10px; padding: 8px 4px 6px; cursor: pointer;
  min-width: 44px; font-size: 10.5px;
  display: inline-flex; flex-direction: column; align-items: center; gap: 4px;
}
.tool:active { background: var(--panel-2); }
.tool .ic { width: 20px; height: 20px; }
.tool .tl { line-height: 1; white-space: nowrap; }
.ic {
  flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.device-icon .ic { width: 20px; height: 20px; color: var(--accent-2); }
.ic-fill { fill: currentColor; stroke: none; }
.tool.active { color: var(--accent-2); }
.tool.danger { color: var(--danger); }

/* ---- 按键条:手机软键盘没有的 Ctrl / Alt / 方向键 / 组合键 ---- */
.keybar { padding: 8px 0 2px; }
.keybar-row {
  display: flex; gap: 6px; padding: 0 8px 6px;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.keybar-row::-webkit-scrollbar { display: none; }
.kb {
  flex: none; min-width: 46px; height: 38px; padding: 0 12px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px;
  color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.kb:active { background: var(--accent); border-color: var(--accent); color: #fff; }
.kb.wide { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.kb.mod.on { border-color: var(--accent); color: var(--accent-2); background: rgba(124,108,255,.16); }
.kb.mod.locked { border-color: var(--accent-2); color: #fff; background: rgba(76,194,255,.22); }
.kb.mod.locked::after { content: '·锁'; font-size: 10px; margin-left: 3px; opacity: .8; }

/* ---- 分段选择 / 滑杆 ---- */
.seg { display: flex; gap: 4px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; flex: none; }
.seg-btn {
  border: none; background: none; color: var(--muted); cursor: pointer;
  padding: 7px 12px; border-radius: 7px; font-size: 13px; font-weight: 600;
}
.seg-btn.on { background: var(--accent); color: #fff; }
.sheet-row input[type=range] {
  width: 46%; flex: none; margin: 0; padding: 0; border: none; background: none;
  accent-color: var(--accent);
}
.help-list { list-style: none; margin: 6px 0 2px; }
.help-list li {
  display: flex; gap: 12px; align-items: baseline;
  padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.help-list li:last-child { border-bottom: none; }
.help-list b { flex: none; width: 116px; font-size: 13px; }
.help-list span { color: var(--muted); font-size: 12.5px; line-height: 1.5; }

/* ---- 更多控制面板(底部弹层) ---- */
.sheet { position: fixed; inset: 0; z-index: 45; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--panel); border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: 18px 20px calc(env(safe-area-inset-bottom) + 14px);
  animation: sheet-up .18s ease-out;
}
@keyframes sheet-up { from { transform: translateY(30%); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-title { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.sheet-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 13px 0; border-bottom: 1px solid var(--border);
}
.sheet-row:last-of-type { border-bottom: none; }
.sheet-label { font-size: 14px; display: flex; flex-direction: column; gap: 2px; }
.sheet-label small { color: var(--muted); font-size: 11px; }
.sheet-row select { width: auto; margin: 0; padding: 8px 10px; font-size: 13px; }
.chip {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 8px 16px; font-size: 13px; cursor: pointer; flex: none;
}
.chip.active { border-color: var(--accent); color: var(--accent-2); }
.sheet-close { width: 100%; margin-top: 12px; }
#hidden-input {
  position: fixed; left: -9999px; bottom: 0; width: 10px; height: 10px;
  opacity: 0.01;
}

/* ---- 弹窗 / Toast ---- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card { width: 100%; max-width: 340px; }
.modal-card h3 { font-size: 16px; }
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 10px; font-size: 13px; z-index: 60;
  max-width: 86vw;
}
