:root {
  --bg: #000;
  --panel: rgba(28, 30, 36, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f2f3f5;
  --dim: #9aa0ad;
  --accent: #4c8dff;
  --bad: #ff6b6b;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, "PingFang SC", system-ui, sans-serif;
  overflow: hidden; overscroll-behavior: none; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
.hidden { display: none !important; }

/* 连接页 */
#login { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: #0b0c10; }
.login-box { width: 100%; max-width: 340px; text-align: center; }
.logo { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 16px;
  background: radial-gradient(circle at 30% 30%, #7fb0ff, #2a5fd6 70%); box-shadow: 0 8px 30px rgba(76,141,255,.35); }
h1 { font-size: 24px; margin: 0 0 6px; }
.msg { color: var(--dim); min-height: 1.4em; margin: 0 0 18px; }
.msg.err { color: var(--bad); }
#pin-form, #code-form { display: flex; gap: 8px; }
#code { flex: 1; min-width: 0; font: 600 22px/1 ui-monospace, Menlo, monospace; letter-spacing: .08em; text-align: center;
  padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: #15171c; color: var(--text); -webkit-user-select: text; user-select: text; }
#code-form button { padding: 0 18px; border-radius: 12px; border: 0; background: var(--accent); color: #fff; font: 600 16px/1 inherit; }
.list-title { margin: 22px 0 8px; text-align: left; color: var(--dim); font-size: 13px; }
.device { display: flex; gap: 8px; margin-bottom: 8px; }
.device-go { flex: 1; display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: #15171c; color: var(--text); font: 15px/1.2 inherit; text-align: left; }
.device-go span { color: var(--dim); font: 13px ui-monospace, Menlo, monospace; }
.device-del { flex: none; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: transparent; color: var(--dim); font: 13px inherit; }
.link { margin-top: 16px; background: none; border: 0; color: var(--accent); font: 14px inherit; }
#login { overflow-y: auto; }
.acct-bar { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin: -6px 0 10px; }
.acct-bar .link { margin: 0; }
#acct-login { display: flex; flex-direction: column; gap: 8px; text-align: left; }
#acct-login input { width: 100%; min-width: 0; font: 600 18px/1 ui-monospace, Menlo, monospace; padding: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: #15171c; color: var(--text); -webkit-user-select: text; user-select: text; }
.acct-row { display: flex; gap: 8px; }
.acct-row input { flex: 1; }
.acct-row button { flex: none; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: #15171c; color: var(--text); font: 15px inherit; }
.acct-row .acct-primary { flex: 1; height: 44px; background: var(--accent); border: 0; color: #fff; font-weight: 600; }
.device-go .online { color: #34c77b; }
.device-go .offline { color: var(--dim); }
#pin { flex: 1; min-width: 0; font: 600 22px/1 ui-monospace, Menlo, monospace; letter-spacing: .2em; text-align: center;
  padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: #15171c; color: var(--text); -webkit-user-select: text; user-select: text; }
#pin-form button { padding: 0 18px; border-radius: 12px; border: 0; background: var(--accent); color: #fff; font: 600 16px/1 inherit; }
.tip { color: var(--dim); font-size: 13px; margin-top: 20px; }

/* 画面 */
#stage { position: fixed; inset: 0; background: #000; touch-action: none; }
#view { position: absolute; inset: 0; transform-origin: 0 0; will-change: transform; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; pointer-events: none; }
#cursor {
  position: absolute; left: 0; top: 0; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(76, 141, 255, .35); box-shadow: 0 0 0 1px rgba(0,0,0,.6), 0 1px 4px rgba(0,0,0,.5);
  pointer-events: none; will-change: transform;
}
#cursor.drag { background: rgba(255, 170, 60, .7); }
#cursor.off { display: none; }

#hud { position: absolute; top: calc(6px + var(--safe-t)); left: calc(8px + var(--safe-l)); padding: 4px 8px; border-radius: 8px;
  background: rgba(0,0,0,.6); font: 11px/1.4 ui-monospace, Menlo, monospace; color: #b8f5c8; pointer-events: none; white-space: pre; }
#toast { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); padding: 10px 16px; border-radius: 12px;
  background: var(--panel); pointer-events: none; text-align: center; max-width: 80%; }

#clip-bar { position: absolute; top: calc(48px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 4;
  display: flex; align-items: center; gap: 8px; max-width: calc(100% - 32px); padding: 6px 6px 6px 12px;
  border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
#clip-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dim); font-size: 13px; min-width: 0; }
#clip-bar button { flex: none; height: 32px; padding: 0 12px; border-radius: 8px; border: 0; background: var(--accent); color: #fff; font: 14px/1 inherit; }
#clip-bar #clip-close { background: transparent; color: var(--dim); padding: 0 6px; }

#xfer { position: absolute; top: calc(96px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 4;
  display: flex; align-items: center; gap: 8px; width: min(560px, calc(100% - 32px)); padding: 6px 6px 6px 12px;
  border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
#xfer-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
#xfer-bar { flex: none; width: 80px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
#xfer-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
#xfer button { flex: none; height: 32px; padding: 0 12px; border-radius: 8px; border: 0; background: var(--accent); color: #fff; font: 14px/1 inherit; }
#xfer #xfer-close { background: transparent; color: var(--dim); padding: 0 6px; }

/* 虚拟手柄 */
#gamepad { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
#gamepad > * { pointer-events: auto; touch-action: none; }
#gp-look { position: absolute; top: 0; right: 0; bottom: 0; width: 50%; display: flex; align-items: flex-start; justify-content: center; }
#gp-look span { margin-top: calc(56px + var(--safe-t)); font-size: 12px; color: rgba(255,255,255,.35); pointer-events: none; }
#gp-stick { position: absolute; left: calc(28px + var(--safe-l)); bottom: calc(28px + var(--safe-b)); width: 150px; height: 150px;
  border-radius: 50%; background: rgba(255,255,255,.08); border: 2px solid rgba(255,255,255,.25); }
#gp-knob { position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%;
  background: rgba(255,255,255,.35); will-change: transform; pointer-events: none; }
#gp-top { position: absolute; top: calc(8px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; gap: 6px; }
#gp-buttons { position: absolute; right: calc(70px + var(--safe-r)); bottom: calc(16px + var(--safe-b));
  display: grid; grid-template-columns: repeat(3, 58px); gap: 8px; }
#gamepad button { height: 44px; border-radius: 12px; border: 1px solid rgba(255,255,255,.25); background: rgba(28,30,36,.45);
  color: #fff; font: 600 14px/1 inherit; -webkit-user-select: none; user-select: none; }
#gp-top button { height: 34px; padding: 0 10px; font-weight: 500; white-space: nowrap; }
#gamepad button.big { height: 58px; }
#gamepad button.fire { background: rgba(255, 90, 90, .45); }
#gamepad button.down { background: rgba(76, 141, 255, .8); border-color: var(--accent); }

/* 画质设置 */
#settings { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; background: rgba(0,0,0,.45); }
#settings .sheet { width: min(460px, calc(100% - 32px)); max-height: calc(100% - 24px); overflow: auto; padding: 14px 16px;
  border-radius: 16px; background: var(--panel); border: 1px solid var(--line); }
.sheet-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; }
.sheet-row > span { color: var(--dim); font-size: 14px; flex: none; }
.sheet-row select { min-width: 0; max-width: 70%; background: #2a2d35; color: var(--text); border: 0; border-radius: 8px; padding: 7px 10px; font: 14px inherit; }
.seg { display: flex; background: #2a2d35; border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: transparent; color: var(--text); font: 14px/1 inherit; padding: 7px 11px; border-radius: 7px; white-space: nowrap; }
.seg button.on { background: var(--accent); color: #fff; }
.sheet-note { color: var(--dim); font-size: 12px; margin: 6px 0 10px; }
.sheet-row .ghost { flex: none; height: 34px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line); background: #2a2d35; color: var(--text); font: 14px/1 inherit; }
.lat-result { flex: 1; text-align: right; font-size: 12px; color: var(--dim); }
#settings-close { width: 100%; height: 40px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font: 600 15px/1 inherit; }

#menu-btn { position: absolute; right: calc(10px + var(--safe-r)); bottom: calc(10px + var(--safe-b)); width: 40px; height: 40px;
  border-radius: 50%; border: 1px solid var(--line); background: rgba(28,30,36,.55); color: var(--text); font-size: 18px; z-index: 3; }
#toolbar { position: absolute; left: var(--safe-l); right: calc(58px + var(--safe-r)); bottom: calc(6px + var(--safe-b)); z-index: 3;
  display: flex; flex-direction: column; gap: 6px; padding: 0 8px; }
.bar { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; touch-action: pan-x; padding: 2px; }
.bar::-webkit-scrollbar { display: none; }
.bar button { flex: none; height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: 14px/1 inherit; white-space: nowrap; }
.bar button:active { background: #3a3f4b; }
.bar button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.bar button.danger { color: var(--bad); }

/* 电脑浏览器：显示全屏按钮；手机：显示键盘按钮 */
.desktop-only { display: none; }
@media (hover: hover) and (pointer: fine) {
  .touch-only { display: none !important; }
  .desktop-only { display: inline-block; }
  #stage { cursor: default; }
}

/* 隐藏的输入框：用来唤起 iPhone 键盘 */
#kbd { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0;
  font-size: 16px; /* 小于 16px 时 iOS 会自动放大页面 */ -webkit-user-select: text; user-select: text; }
