:root {
  --bg: #070a0f;
  --surface: #111824;
  --surface-2: #1c2636;
  --border: rgba(255, 255, 255, 0.12);
  --text: #eef3fa;
  --muted: #93a3b8;
  --accent: #3b82f6;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --rail-w: 76px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  user-select: none;
  touch-action: none;
}

/* Connect screen */
.connect-view {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 30% 20%, #17253d 0%, #070a0f 65%);
  overflow-y: auto;
}

.connect-card {
  width: 100%;
  max-width: 420px;
  background: rgba(17, 24, 36, 0.92);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.brand-icon {
  width: 48px;
  height: 48px;
}

.brand-row h1 {
  margin: 0;
  font-size: 21px;
}

.subtitle {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.host-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 16px;
  background: rgba(255, 255, 255, 0.05);
}

.host-badge .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #64748b;
}

.host-badge.online .dot {
  background: var(--accent-2);
  box-shadow: 0 0 8px var(--accent-2);
}

.host-badge.offline .dot {
  background: #f59e0b;
}

.connect-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0c121b;
  color: var(--text);
  font-size: 14px;
  outline: none;
  user-select: text;
}

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

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.primary-btn {
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.connect-error {
  margin: 12px 0 0;
  color: #fca5a5;
  font-size: 13px;
}

/* Stage */
.stage-view {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  background: #000;
}

.stage-view[hidden],
.connect-view[hidden],
[hidden] {
  display: none !important;
}

.video-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

/* Right permanent dark rail */
.side-rail {
  width: var(--rail-w);
  height: 100%;
  padding: 10px 6px calc(10px + env(safe-area-inset-bottom, 0px));
  padding-right: calc(6px + env(safe-area-inset-right, 0px));
  background: #06080c;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  z-index: 30;
}

.stage-view.rail-collapsed .side-rail {
  display: none;
}

.rail-btn {
  width: 64px;
  padding: 10px 4px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: #dbe3ee;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  cursor: pointer;
}

.rail-btn:active,
.rail-btn.active {
  background: rgba(59, 130, 246, 0.22);
  color: #fff;
}

.rail-toggle-handle {
  position: fixed;
  right: var(--rail-w);
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-right: none;
  border-radius: 8px 0 0 8px;
  background: rgba(10, 14, 22, 0.72);
  color: #cbd5e1;
  cursor: pointer;
  z-index: 31;
  padding: 0;
  font-size: 14px;
}

.stage-view.rail-collapsed .rail-toggle-handle {
  right: 0;
}

/* HUD */
.hud-stats {
  position: absolute;
  top: 10px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(12, 18, 28, 0.65);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 11px;
  color: #cbd5e1;
  pointer-events: none;
  z-index: 15;
}

.hud-stats .sep {
  opacity: 0.4;
}

.unmute-pill {
  position: absolute;
  top: 44px;
  right: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(96, 165, 250, 0.5);
  background: rgba(37, 99, 235, 0.85);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  z-index: 20;
}

/* Floating Virtual Mouse */
.vmouse-root {
  position: absolute;
  left: 60%;
  top: 45%;
  z-index: 25;
  touch-action: none;
}

.vmouse-collapsed {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  cursor: grab;
}

.vmouse-expanded {
  position: relative;
  width: 146px;
  padding: 8px;
  border-radius: 18px;
  background: rgba(214, 224, 240, 0.78);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.48);
  color: #1e293b;
}

.vmouse-pointer-tip {
  position: absolute;
  left: -4px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #3b82f6;
  border: 2px solid #fff;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.9);
}

.vmouse-close {
  position: absolute;
  right: -10px;
  top: -10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.7);
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.vmouse-grid {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 68px 46px;
  gap: 5px;
}

.vmouse-btn {
  border: 1px solid rgba(30, 41, 59, 0.25);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.65);
  color: #0f172a;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.vmouse-btn:active {
  background: rgba(59, 130, 246, 0.45);
}

.vmouse-wheel-box {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  width: 30px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 2;
}

.vmouse-mini-btn {
  height: 25px;
  border-radius: 8px;
  border: 1px solid rgba(30, 41, 59, 0.35);
  background: rgba(241, 245, 249, 0.95);
  color: #0f172a;
  font-size: 10px;
  cursor: pointer;
}

.vmouse-drag-btn {
  grid-column: 1 / span 2;
  border: 1px solid rgba(30, 41, 59, 0.25);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.62);
  color: #0f172a;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.vmouse-drag-btn.locked {
  background: #3b82f6;
  color: #fff;
}

.vmouse-drag-handle {
  margin-top: 5px;
  text-align: center;
  font-size: 10px;
  color: #334155;
  padding: 3px 0;
  cursor: grab;
}

/* Bottom 3-tab Keyboard Dock */
.keyboard-dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(14, 19, 28, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  z-index: 40;
}

.kbd-panel {
  padding: 10px 12px 6px;
}

.ime-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ime-input {
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: #0a0f17;
  color: var(--text);
  font-size: 14px;
  user-select: text;
}

.ime-send-btn,
.ime-aux-btn {
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

.ime-aux-btn {
  background: var(--surface-2);
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-btn {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.chip-btn:active {
  background: var(--accent);
}

.pc-keyboard-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 185px;
  overflow-y: auto;
}

.pc-kbd-row {
  display: flex;
  gap: 4px;
}

.pc-key {
  flex: 1;
  min-width: 26px;
  padding: 7px 3px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 11px;
  text-align: center;
  cursor: pointer;
}

.pc-key.wide {
  flex: 1.7;
}

.pc-key.space {
  flex: 4;
}

.pc-key.active {
  background: var(--accent);
  border-color: #93c5fd;
}

.kbd-tabs {
  display: flex;
  align-items: center;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 4px 10px;
  gap: 6px;
}

.kbd-tab {
  flex: 1;
  padding: 7px 6px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.kbd-tab.active {
  color: #60a5fa;
  border-bottom-color: #60a5fa;
  font-weight: 600;
}

.kbd-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

/* Right Ops Drawer */
.ops-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(320px, 82vw);
  background: rgba(18, 24, 34, 0.94);
  backdrop-filter: blur(12px);
  border-left: 1px solid var(--border);
  padding: 14px;
  overflow-y: auto;
  z-index: 35;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  font-weight: 600;
}

.icon-close-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

.drawer-actions-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.tile-btn {
  padding: 10px 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
}

.tile-btn.active {
  background: var(--accent);
}

.tile-btn.danger {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

.drawer-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drawer-label {
  font-size: 12px;
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.segmented.three {
  grid-template-columns: repeat(3, 1fr);
}

.seg-btn {
  padding: 8px 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c121b;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.clip-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.clip-btn {
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.clip-box {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0a0f17;
  color: var(--text);
  padding: 7px;
  font-size: 12px;
  resize: none;
  user-select: text;
}

.toast {
  position: fixed;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #f8fafc;
  font-size: 13px;
  z-index: 100;
}
