:root {
  --primary-color: #2196f3;
  --danger-color: #f44336;
  --success-color: #4caf50;
  --background-color: #f5f5f5;
  --border-radius: 8px;
  --card-background: #ffffff;
  --text-color: #333333;
  --secondary-text-color: #666666;
  --border-color: #dddddd;
  --hover-color: #1976d2;
  --danger-hover-color: #d32f2f;
  --disabled-color: #cccccc;
  --status-background: #f8f9fa;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* 允许输入框和文本区域选择文本 */
input,
textarea,
select {
  user-select: text !important;
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
}

body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: #000;
  color: var(--text-color);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.app-container {
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

/* Connection overlay (shown when not connected) */
.connection-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #c8c8c8;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  overflow: hidden;
}

/* CrossDesk background text */
.connection-overlay::before {
  content: "CrossDesk";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(30px, 12vw, 320px);
  font-weight: 900;
  color: rgba(0, 0, 0, 1);
  white-space: nowrap;
  letter-spacing: 0.05em;
  z-index: 0;
  pointer-events: none;
  font-family: "Verdana", -apple-system, BlinkMacSystemFont, "Arial Black", "Helvetica Neue", sans-serif;
  font-stretch: condensed;
  max-width: 98%;
  width: fit-content;
  box-sizing: border-box;
  overflow: visible;
}

/* Glassmorphism layer covering CrossDesk text */
.connection-overlay::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 1;
  pointer-events: none;
}

.connection-panel {
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border-radius: 24px; /* Same radius as status bar panel */
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  width: clamp(280px, 85%, 320px);
  position: relative;
  z-index: 2;
  /* Disable text selection and copying */
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  /* Disable double-tap zoom on mobile */
  touch-action: manipulation;
  -ms-touch-action: manipulation;
  /* Add subtle border for better visibility */
  border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Reduce width in portrait orientation */
@media (orientation: portrait) {
  .connection-panel {
    width: clamp(260px, 75%, 280px);
  }
  
  /* Keep label and input on same line in portrait mode if space allows */
  .option {
    flex-wrap: nowrap;
  }
  
  .option label {
    width: auto;
    min-width: 100px;
    margin-bottom: 0;
    flex-shrink: 0;
  }
}

/* Mobile landscape - reduce width for phones in landscape */
@media (max-width: 900px) and (orientation: landscape) {
  .connection-panel {
    width: clamp(280px, 60%, 320px);
  }
}

.connection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  /* Disable text selection and interaction */
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  pointer-events: none;
  /* Disable double-tap zoom */
  touch-action: manipulation;
  -ms-touch-action: manipulation;
}

/* Re-enable pointer events for interactive elements */
.connection-header button,
.connection-header .status-indicator {
  pointer-events: auto;
}

.connection-title-with-icon {
  display: flex;
  align-items: center;
  gap: 12px;
  /* Disable interaction */
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  touch-action: manipulation;
  -ms-touch-action: manipulation;
}

.connection-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
  /* Disable interaction and dragging */
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
  touch-action: manipulation;
  -ms-touch-action: manipulation;
}

.connection-header h2 {
  margin: 0;
  color: #444;
  font-weight: 700;
  font-size: 1.5rem;
  /* Disable interaction */
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  touch-action: manipulation;
  -ms-touch-action: manipulation;
}

/* Status LED indicator */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-led {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: #ccc;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.status-led-off {
  background-color: #f44336;
  box-shadow: 0 0 8px rgba(244, 67, 54, 0.5);
}

.status-led-on {
  background-color: #4caf50;
  box-shadow: 0 0 8px rgba(76, 175, 80, 0.5);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* Option styles */
.option {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  gap: 10px;
}

.option.compact {
  margin-bottom: 8px;
  gap: 8px;
}

.option label {
  width: 120px;
  color: var(--secondary-text-color);
  font-weight: 500;
  font-size: 14px;
  flex-shrink: 0;
  /* Disable interaction on labels */
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  /* Disable double-tap zoom */
  touch-action: manipulation;
  -ms-touch-action: manipulation;
}

.option.compact label {
  width: auto;
  min-width: auto;
  font-size: 13px;
}

.option input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-width: 0;
  max-width: 200px; /* Limit input box width */
  /* Re-enable interaction for input fields */
  pointer-events: auto;
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
}

.option input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.2);
}

.option select {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 13px;
  background-color: var(--card-background);
  height: 36px;
  box-sizing: border-box;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.option select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.2);
}

.option select:disabled {
  background-color: #f3f3f3;
  color: #999;
  cursor: not-allowed;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
  /* Re-enable interaction for buttons */
  pointer-events: auto;
}

button {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  color: white;
  background-color: var(--primary-color);
  transition: background-color 0.2s, transform 0.1s;
  font-size: 14px;
  min-width: 80px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover:not(:disabled) {
  background-color: var(--hover-color);
  transform: translateY(-1px);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  background-color: var(--disabled-color);
  cursor: not-allowed;
  transform: none;
}

#disconnect {
  background-color: var(--danger-color);
}

#disconnect:hover:not(:disabled) {
  background-color: var(--danger-hover-color);
}

/* Video display */
#media {
  width: 100%;
  height: 100%;
  position: relative;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: transform 0.1s ease-out;
  transform-origin: center center;
}

/* Connecting overlay */
.connecting-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  pointer-events: none;
}

.connecting-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: white;
  font-size: 18px;
  font-weight: 500;
}

.connecting-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Connected overlay (shown when connected) */
.connected-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  pointer-events: none;
}

.connected-panel {
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(10px);
  border: none;
  padding: 12px 16px;
  pointer-events: auto;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  transform: translateY(0);
  opacity: 1;
  cursor: default;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border-radius: 24px; /* Same radius as minimized button (48px / 2 = 24px) */
  /* Note: position: fixed is needed for panel positioning, icon uses absolute positioning relative to this */
}

.connected-panel.minimized {
  transform: translateY(0);
  opacity: 1;
  padding: 0;
  background: transparent;
  backdrop-filter: none;
  border: none;
  width: auto;
  min-width: 48px;
  max-width: 48px;
  height: 48px;
  min-height: 48px;
  max-height: 48px;
  right: auto;
  bottom: auto;
}

.connected-panel.minimized .panel-content {
  display: none;
}

.panel-content {
  display: block;
  padding-left: 72px; /* Make room for the icon on the left */
  padding-right: 16px; /* Match panel's right padding */
}

.panel-collapsed-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  backdrop-filter: blur(10px);
  padding: 10px;
  border-radius: 50%;
  border: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  width: 56px;
  height: 56px;
  min-width: 56px;
  max-width: 56px;
  min-height: 56px;
  max-height: 56px;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 300;
  pointer-events: auto;
}

.panel-collapsed-bar:hover {
  background: #ffffff;
}

.collapsed-bar-text {
  color: #000;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.collapsed-bar-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
  pointer-events: none;
}
  
.connected-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.connected-controls-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex: 1;
  width: 100%;
  justify-content: flex-end;
  box-sizing: border-box;
}

/* Ensure all controls have consistent height and alignment */
.connected-controls-row > * {
  height: 36px;
  display: flex;
  align-items: center;
}

/* When space is limited or in landscape orientation, switch to vertical layout */
@media (max-width: 900px), (orientation: landscape) {
  .connected-controls-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  
  .connected-controls-row .option.compact {
    width: 100%;
  }
  
  .controls-right-group {
    width: 100%;
    margin-left: 0;
    justify-content: center;
  }
  
  .connected-controls-row .connection-status-group {
    width: auto;
    justify-content: center;
  }
  
  .connected-controls-row .disconnect-btn {
    width: auto;
    min-width: auto;
  }
  
  .connected-controls-row .minimize-btn {
    width: 28px;
    min-width: 28px;
  }
}

.connected-header .option.compact {
  margin-bottom: 0;
  flex-shrink: 0;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 8px; /* Ensure consistent gap between label and select */
}

.connected-header .option.compact label {
  margin-bottom: 0;
  height: auto;
  line-height: 36px;
  min-width: 60px;
  text-align: right;
}

.connected-header .option.compact select {
  height: 36px;
  box-sizing: border-box;
  width: 110px;
  min-width: 110px;
  max-width: 110px; /* Ensure fixed width */
  border: 1px solid rgba(0, 0, 0, 0.2);
  padding: 0 8px;
  margin: 0;
  margin-right: 0; /* Ensure no right margin */
  flex-shrink: 0; /* Prevent shrinking */
}

/* Left side: options (画面 and 鼠标模式) */
.connected-controls-row .option.compact {
  flex-shrink: 0;
  /* Ensure select box right edge aligns with disconnect button */
  display: flex;
  align-items: center;
}

/* Right side: status and buttons */
.controls-right-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  margin-left: 0;
  height: 36px;
  /* Ensure disconnect button right edge aligns with select box */
  position: relative;
}

.connected-controls-row .connection-status-group {
  flex-shrink: 0;
  margin: 0;
  position: relative;
}

.connected-controls-row .disconnect-btn {
  flex-shrink: 0;
  margin: 0;
}

.connected-controls-row .minimize-btn {
  flex-shrink: 0;
  margin: 0;
}

.control-buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.control-btn {
  padding: 6px 12px;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  height: 36px;
  transition: background-color 0.2s;
  }
  
.control-btn:hover {
  background-color: var(--hover-color);
}

/* Connection status group (now inside panel) */
.connection-status-group {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.05);
  backdrop-filter: blur(10px);
  padding: 0 8px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  height: 36px;
  box-sizing: border-box;
  min-width: auto;
  justify-content: center;
  position: relative;
}

.connection-status-label {
  color: #333;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.connection-status-group .status-indicator {
  flex-shrink: 0;
}

/* Disconnect button (now inside panel) */
.disconnect-btn {
  padding: 0 12px;
  background-color: var(--danger-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  height: 36px;
  min-width: auto;
  transition: background-color 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  margin-right: 0; /* Ensure no right margin for alignment */
  position: relative; /* Ensure box-shadow doesn't affect alignment */
  }
  
.disconnect-btn:hover {
  background-color: var(--danger-hover-color);
}

.disconnect-btn:active {
  transform: translateY(0);
}

/* Minimize button */
.minimize-btn {
  padding: 0;
  background-color: rgba(0, 0, 0, 0.1);
  color: #333;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  height: 36px;
  width: 28px;
  min-width: 28px;
  line-height: 1;
  transition: background-color 0.2s;
  flex-shrink: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  }

.minimize-btn:hover {
  background-color: rgba(0, 0, 0, 0.15);
  border-color: rgba(0, 0, 0, 0.3);
}

.minimize-btn:active {
  transform: translateY(0);
}

/* Virtual mouse related styles */
#virtual-mouse {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background-color: rgba(255, 255, 255, 0.18);
  border-radius: max(8px, 1vw);
  padding: max(6px, 0.8vh) max(6px, 0.8vw);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  width: auto;
  min-width: min(320px, 90vw);
  max-width: min(400px, 90vw);
  touch-action: none;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
  backdrop-filter: blur(3px);
  transition: background-color 0.2s, padding 0.3s ease;
  display: flex;
  flex-direction: column;
}

#virtual-mouse.dragging {
  transition: none;
}

#virtual-mouse.minimized {
  background-color: rgba(255, 255, 255, 0.18);
  padding: max(6px, 0.8vh) max(4px, 0.6vw);
}

.virtual-mouse-header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: max(4px, 0.6vh);
  padding-left: 0;
  padding-right: 0;
  cursor: move;
  user-select: none;
  touch-action: none;
  gap: max(4px, 0.6vw);
}

.virtual-mouse-minimize-btn {
  padding: 0;
  background-color: rgba(255, 255, 255, 0.48);
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: max(4px, 0.6vw);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  user-select: none;
  touch-action: manipulation;
  transition: all 0.1s;
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  box-sizing: border-box;
  outline: none !important;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  margin-left: auto;
}

.virtual-mouse-minimize-btn:active {
  background-color: rgba(200, 200, 200, 0.65) !important;
  transform: scale(0.92);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.virtual-mouse-minimize-btn:focus {
  outline: none !important;
  background-color: rgba(255, 255, 255, 0.48) !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08) !important;
}

.virtual-mouse-restore-btn {
  padding: 0;
  background-color: rgba(255, 255, 255, 0.6);
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  cursor: pointer;
  font-size: 18px;
  font-weight: 500;
  height: 36px;
  width: 36px;
  min-width: 36px;
  transition: background-color 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  white-space: nowrap;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  position: absolute;
  top: 0;
  flex-shrink: 0;
  z-index: 1;
}

.virtual-mouse-restore-btn:hover {
  background-color: rgba(255, 255, 255, 0.8);
}

.virtual-mouse-restore-btn:active {
  background-color: rgba(200, 200, 200, 0.8);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

#virtual-mouse.minimized-to-statusbar {
  display: none !important;
}

.virtual-mouse-row {
  display: flex;
  gap: max(4px, 0.6vw);
  justify-content: center;
  align-items: stretch;
  flex-wrap: nowrap;
  width: 100%;
}

.virtual-mouse-btn {
  flex: 1 1 0;
  min-width: 54px;
  max-width: none;
  height: 54px;
  background-color: rgba(255, 255, 255, 0.48) !important;
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: max(4px, 0.6vw);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  user-select: none;
  touch-action: manipulation;
  transition: all 0.1s;
  padding: 0 8px;
  box-sizing: border-box;
  outline: none !important;
  -webkit-tap-highlight-color: transparent;
}

.virtual-mouse-btn:active {
  background-color: rgba(200, 200, 200, 0.65) !important;
  transform: scale(0.92);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.virtual-mouse-btn:focus {
  outline: none !important;
  background-color: rgba(255, 255, 255, 0.48) !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08) !important;
}

.virtual-scroll-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 30px;
  height: 54px;
  flex-shrink: 0;
  flex-grow: 0;
}

.virtual-scroll-btn {
  flex: 1;
  width: 30px;
  min-width: 30px;
  max-width: 30px;
  height: 25px;
  background-color: rgba(255, 255, 255, 0.48) !important;
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: max(4px, 0.6vw);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  user-select: none;
  touch-action: manipulation;
  transition: all 0.1s;
  padding: 0;
  box-sizing: border-box;
  outline: none !important;
  -webkit-tap-highlight-color: transparent;
}

.virtual-scroll-btn:active {
  background-color: rgba(200, 200, 200, 0.65) !important;
  transform: scale(0.92);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.virtual-scroll-btn:focus {
  outline: none !important;
  background-color: rgba(255, 255, 255, 0.48) !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08) !important;
}

/* Virtual keyboard styles */
.virtual-keyboard {
  position: absolute;
  bottom: max(80px, 8vh);
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  background-color: rgba(255, 255, 255, 0.18);
  border-radius: max(8px, 1vw);
  padding: max(8px, 1vh) max(6px, 0.8vw);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  width: min(98%, calc(100vw - 20px));
  max-width: 98%;
  min-width: min(300px, 90vw);
  touch-action: none;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
  backdrop-filter: blur(3px);
  transition: background-color 0.2s, padding 0.3s ease;
}

.virtual-keyboard.dragging {
  transition: none;
}

.keyboard-header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: max(6px, 0.8vh);
  padding-left: 0;
  padding-right: 0;
  cursor: move;
  user-select: none;
  touch-action: none;
}

.keyboard-toggle-btn {
  background-color: rgba(0, 0, 0, 0.2);
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.3);
  border-radius: max(4px, 0.6vw);
  padding: max(4px, 0.6vh) max(10px, 1.2vw);
  font-size: max(12px, 1.2vw);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: all 0.2s;
  font-weight: 500;
  position: relative;
  z-index: 1;
}

.keyboard-close-btn {
  background-color: rgba(255, 255, 255, 0.6);
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: max(4px, 0.6vw);
  padding: max(4px, 0.6vh) max(10px, 1.2vw);
  font-size: max(12px, 1.2vw);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: all 0.2s;
  font-weight: 500;
  position: relative;
  z-index: 1;
}

.keyboard-toggle-btn:hover {
  background-color: rgba(0, 0, 0, 0.25);
}

.keyboard-close-btn:hover {
  background-color: rgba(255, 255, 255, 0.7);
}

.keyboard-toggle-btn:active {
  background-color: rgba(0, 0, 0, 0.3);
  transform: scale(0.95);
}

.keyboard-close-btn:active {
  background-color: rgba(255, 255, 255, 0.8);
  transform: scale(0.95);
}

.keyboard-layout {
  display: flex;
  flex-direction: column;
  gap: max(4px, 0.6vh);
}

.keyboard-row {
  display: flex;
  gap: max(2px, 0.4vw);
  justify-content: center;
  align-items: stretch;
  flex-wrap: nowrap;
  width: 100%;
}

.keyboard-key {
  flex: 1 1 0;
  min-width: max(22px, 2.8vw);
  max-width: none;
  height: max(32px, 4.5vh);
  background-color: rgba(255, 255, 255, 0.48) !important;
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: max(4px, 0.6vw);
  font-size: max(10px, 1.1vw);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: all 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 max(4px, 0.6vw);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  box-sizing: border-box;
  outline: none !important;
  -webkit-tap-highlight-color: transparent;
}

.keyboard-key:active {
  background-color: rgba(200, 200, 200, 0.65);
  transform: scale(0.92);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.keyboard-key:focus {
  outline: none !important;
  background-color: rgba(255, 255, 255, 0.48) !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08) !important;
}

.keyboard-key:focus:not(:active) {
  outline: none !important;
  background-color: rgba(255, 255, 255, 0.48) !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08) !important;
}

.keyboard-key:focus-visible {
  outline: none !important;
  background-color: rgba(255, 255, 255, 0.48) !important;
}

/* Wide keys (Backspace, Enter, Caps, Shift) - 1.5x width */
.keyboard-key-wide {
  flex: 1.5 1 0;
  min-width: max(35px, 4.5vw);
}

/* Space key - 4x width */
.keyboard-key-space {
  flex: 4 1 0;
  min-width: max(90px, 12vw);
}

/* Responsive adjustments for very small screens */
@media (max-width: 480px) {
  .virtual-keyboard {
    padding: max(6px, 0.8vh) max(4px, 0.6vw);
    border-radius: max(6px, 0.8vw);
  }
  
  .keyboard-key {
    min-width: max(18px, 2.2vw);
    height: max(28px, 4vh);
    font-size: max(9px, 1vw);
    padding: 0 max(3px, 0.5vw);
  }
  
  .keyboard-key-wide {
    min-width: max(28px, 3.5vw);
  }
  
  .keyboard-key-space {
    min-width: max(70px, 10vw);
  }
  
  .keyboard-row {
    gap: max(1.5px, 0.3vw);
  }
  
  .keyboard-layout {
    gap: max(3px, 0.5vh);
  }
}

/* Responsive adjustments for large screens */
@media (min-width: 1024px) {
  .virtual-keyboard {
    max-width: 800px;
  }
  
  .keyboard-key {
    min-width: 28px;
    height: 42px;
    font-size: 13px;
    padding: 0 8px;
  }
  
  .keyboard-key-wide {
    min-width: 42px;
  }
  
  .keyboard-key-space {
    min-width: 112px;
  }
  
  .keyboard-row {
    gap: 4px;
  }
}


.drag-handle {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: #4CAF50;
  cursor: move;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  font-size: 18px;
  transition: background-color 0.2s;
}

.drag-handle:hover {
  background-color: #45a049;
}

.drag-handle::after {
  content: "≡";
}

#virtual-mouse.minimized .drag-handle {
  position: static;
  width: 40px;
  height: 40px;
}

/* Hide virtual mouse on desktop */
@media (hover: hover) and (pointer: fine) {
  #virtual-mouse {
    display: none;
  }
}


/* Focus styles for accessibility */
button:focus,
input:focus,
select:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* Override global button styles for keyboard keys */
.keyboard-key,
.keyboard-key:focus,
.keyboard-key:focus-visible,
.keyboard-key:focus:not(:active) {
  background-color: rgba(255, 255, 255, 0.48) !important;
  outline: none !important;
  outline-offset: 0 !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08) !important;
  color: #222 !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
}

/* Mobile responsive - small screens */
@media (max-width: 768px) {
  .connection-panel {
    padding: 20px;
  }
}

/* Further reduce width in portrait on small screens */
@media (max-width: 768px) and (orientation: portrait) {
  .connection-panel {
    width: clamp(240px, 70%, 280px);
  }
}

@media (max-width: 768px) {
  .option {
    flex-wrap: nowrap; /* Keep label and input on same line if space allows */
  }

  .option label {
    width: auto;
    min-width: 100px; /* Minimum width for label */
    margin-bottom: 0; /* Remove bottom margin to keep on same line */
    flex-shrink: 0; /* Prevent label from shrinking */
  }
  
  /* Only wrap if screen is very narrow */
  @media (max-width: 400px) {
    .option {
      flex-wrap: wrap;
    }
    
    .option label {
      width: 100%;
      margin-bottom: 5px;
    }
  }

  .connected-header {
    flex-direction: column;
    align-items: stretch;
}

  .connected-header .option.compact {
    min-width: 100%;
  }

  .control-buttons {
    width: 100%;
}

  .control-btn {
    flex: 1;
}
}
