: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 page */
.connection-overlay {
  --ink: #19365b;
  --muted: #526a87;
  --primary-color: #255397;
  --hover-color: #1e4279;
  --line: #d6e3f2;
  --disabled-color: #d6e3f2;
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  overflow: auto;
  padding: clamp(24px, 6vw, 80px) 6%;
  border-top: 1px solid var(--line);
  background:
    linear-gradient(0deg, #f5f8fc, transparent 38%),
    linear-gradient(115deg, #f5f9fe, #edf4fc 52%, #e0ebf8);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.connection-layout {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(310px, 1fr);
  grid-template-areas: "intro panel" "resources panel";
  align-items: center;
  gap: 30px clamp(32px, 7vw, 120px);
  width: 100%;
  max-width: 1180px;
  margin: auto;
  padding-block: 42px;
}

.connection-layout::before {
  content: "CrossDesk" / "";
  position: absolute;
  bottom: 0;
  left: 50%;
  z-index: -1;
  transform: translateX(-50%);
  font: 600 min(19vw, 300px)/1.1 -apple-system, BlinkMacSystemFont, sans-serif;
  letter-spacing: -0.065em;
  color: rgb(69 135 219 / 13%);
  text-shadow: 0 5px 22px #25539719;
  filter: blur(3px);
  pointer-events: none;
}

.connection-intro {
  grid-area: intro;
  align-self: end;
}

.connection-intro h1 {
  margin: 0 0 26px;
  font-size: clamp(32px, 4vw, 56px);
  font-weight: 650;
  line-height: 1.4;
  letter-spacing: -0.05em;
}

.connection-intro h1 span {
  display: block;
  color: #4587db;
}

.connection-intro p {
  max-width: 480px;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.95;
}

.connection-resources {
  grid-area: resources;
  align-self: start;
}

.resource-actions,
.resource-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.resource-actions a {
  display: inline-grid;
  place-items: center;
  min-height: 48px;
  padding: 0 24px;
  border: 1px solid #b9cfe9;
  border-radius: 2px;
  background: #ffffffc9;
  color: var(--primary-color);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

.resource-actions a:first-child {
  border-color: var(--primary-color);
  background: var(--primary-color);
  color: #fff;
}

.resource-actions a:hover {
  border-color: var(--primary-color);
  background: #fff;
}

.resource-actions a:first-child:hover {
  background: var(--hover-color);
}

.resource-links {
  gap: 8px 26px;
  margin-top: 20px;
}

.resource-links a {
  color: var(--muted);
  font-size: 13px;
  text-decoration-color: #b9cfe9;
  text-underline-offset: 5px;
}

.resource-links a:hover {
  color: var(--primary-color);
  text-decoration-color: currentColor;
}

.connection-overlay a:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 4px;
}

.connection-panel {
  position: relative;
  grid-area: panel;
  padding: clamp(24px, 3.5vw, 48px);
  background: #fff;
  box-shadow: 0 24px 50px #25539719;
}

.client-version {
  margin: 16px 0 0;
  color: var(--muted, #666);
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

/* Status LED indicator */
.status-indicator {
  position: absolute;
  top: 16px;
  right: 16px;
}

.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;
  }
}

.connection-panel .option {
  display: grid;
  gap: 6px;
}

.connection-panel .option + .option {
  margin-top: 18px;
}

.connection-panel label {
  font-size: 14px;
  font-weight: 600;
}

.connection-panel input {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 8px 12px;
  border: 1px solid #b9cfe9;
  border-radius: 2px;
  background: #fbfdff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}

.connection-panel input::placeholder {
  color: #637993;
}

.connection-panel input:focus {
  border-color: var(--primary-color);
  outline: 2px solid #4587db55;
  outline-offset: 0;
}

.connection-panel input[aria-invalid="true"] {
  border-color: #b33737;
}

.connection-feedback {
  /* Reserve two lines so even a wrapped warning keeps the form in place. */
  display: grid;
  align-content: center;
  min-height: 3em;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.connection-feedback[data-tone="error"] {
  color: #b33737;
}

.connection-panel .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.connection-panel button {
  flex: 1 1 auto;
  min-height: 46px;
  border-radius: 2px;
  font: inherit;
  font-weight: 600;
}

.connection-panel button:disabled {
  color: #526a87;
}


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),
button.pointer-lock-hover:not(:disabled) {
  background-color: var(--hover-color);
  transform: translateY(-1px);
}

button:active:not(:disabled),
button.pointer-lock-active:not(:disabled) {
  transform: translateY(0);
}

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

.connection-panel .secondary-btn {
  border: 1px solid #b9cfe9;
  background: #fff;
  color: var(--primary-color);
}

.connection-panel .secondary-btn:hover:not(:disabled) {
  background: #edf4fc;
}

#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;
}

/* Pointer Lock hides the system cursor; show a page cursor outside the video. */
.locked-pointer-cursor {
  position: fixed;
  top: 0;
  left: 0;
  width: 18px;
  height: 24px;
  z-index: 2147483647;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='24' viewBox='0 0 18 24'%3E%3Cpath d='M1 1v18l4.5-4 3.5 8 3-1.5-3.5-7.5H16Z' fill='%23000' stroke='%23fff' stroke-width='1.5' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat;
}

/* In-page select options stay usable while the system cursor is locked. */
.locked-select-menu {
  position: fixed;
  z-index: 2147483646;
  max-width: calc(100vw - 16px);
  max-height: min(240px, calc(100vh - 16px));
  overflow-y: auto;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: #111827;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.locked-select-option {
  display: block;
  width: 100%;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #fff;
  text-align: left;
  white-space: nowrap;
}

.locked-select-option[aria-selected="true"],
.locked-select-option:focus-visible {
  background: #374151;
}

/* 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);
  }
}

/* Shared mobile floating controls. Only menu content scrolls on short screens. */
.connected-overlay {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}
.connected-overlay [hidden] { display: none !important; }
#session-menu-shield {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  pointer-events: auto;
  touch-action: none;
  transform: none;
  cursor: default;
}
.panel-collapsed-bar {
  position: fixed;
  width: 54px;
  height: 54px;
  min-width: 54px;
  padding: 4px;
  border: 0;
  border-radius: 50%;
  background: #f5f5f7;
  box-shadow: 0 3px 12px #0003;
  pointer-events: auto;
  touch-action: none;
  cursor: grab;
  z-index: 2;
}
.panel-collapsed-bar:hover:not(:disabled), .panel-collapsed-bar.pointer-lock-hover {
  background: #fff;
  transform: none;
}
.panel-collapsed-bar:active { cursor: grabbing; }
.collapsed-bar-icon { width: 46px; height: 46px; pointer-events: none; -webkit-user-drag: none; }
.connected-panel {
  position: fixed;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-sizing: border-box;
  padding: 12px;
  border-radius: 18px;
  color: #202124;
  background: #fafafc;
  box-shadow: 0 8px 30px #0004;
  pointer-events: auto;
  overflow: hidden;
  z-index: 1;
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
}
.connected-panel button { min-width: 0; color: #24262b; background: #eeeef2; border-radius: 9px; padding: 8px; font-size: 12px; }
.connected-panel button:hover:not(:disabled), .connected-panel button.pointer-lock-hover { background: #e0e6ee; transform: none; }
.connected-panel button:disabled { opacity: .45; cursor: not-allowed; }
.session-menu-header { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.session-menu-heading { flex: 1; min-width: 0; }
.session-menu-heading strong { font-size: 14px; }
.connected-panel .session-icon-button { width: 30px; height: 30px; padding: 0; font-size: 24px; background: transparent; flex-shrink: 0; }
.connected-panel .status-led { width: 8px; height: 8px; flex-shrink: 0; margin: 0 3px; }
#connection-quality { margin: 3px 0 0; font-size: 10px; line-height: 1.4; color: #737780; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.session-menu-body { overflow-y: auto; min-height: 0; overscroll-behavior: contain; touch-action: pan-y; }
.session-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.session-landscape .session-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.connected-panel .session-tile { min-height: 64px; display: flex; flex-direction: column; gap: 6px; font-size: 11px; padding: 8px 2px; }
.session-tile svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.audio-icon-volume { display: none; }
.audio-is-playing .audio-icon-volume { display: block; }
.audio-is-playing .audio-icon-mute { display: none; }
.connected-panel .session-disconnect { width: 100%; min-height: 34px; flex: 0 0 auto; }
.connected-panel .session-danger { color: #fff; background: #e64e4e; }
.connected-panel .session-danger:hover:not(:disabled), .connected-panel .session-danger.pointer-lock-hover:not(:disabled) { background: #ce3d3d; }
.connected-panel fieldset { border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
.connected-panel legend, .session-field-label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 600; }
.session-segments { display: flex; gap: 4px; }
.session-segments button { flex: 1; }
.session-segments button[aria-pressed="true"] { color: #1262b3; background: #e0edfc; }
.session-detail { color: #737780; font-size: 11px; margin: 8px 0; }
.session-feedback { margin: 8px 0 0; color: #8b5959; font-size: 12px; }
.session-feedback:empty { display: none; }
#video-settings-retry { margin-top: 8px; }
#display-id, #display-resolution { width: 100%; box-sizing: border-box; background: #eeeef2; color: #24262b; border: 0; padding: 10px; border-radius: 8px; }
#display-resolution:disabled { opacity: .55; cursor: not-allowed; }
.resolution-setting { margin-bottom: 12px; }
.session-network { margin: 0; font-size: 12px; }
.session-network > div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid #ececf0; }
.session-network dt { color: #737780; }
.session-network dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.connected-panel .client-version { color: #91949c; font-size: 10px; margin: 10px 0 0; text-align: center; }
.connected-panel[data-page="disconnect"] { padding: 16px; gap: 16px; }
.connected-panel[data-page="disconnect"] .session-menu-heading strong { font-size: 15px; }
.connected-panel[data-page="disconnect"] #connection-quality,
.connected-panel[data-page="disconnect"] .status-led { display: none; }
.session-confirm-title { margin: 0; font-size: 14px; font-weight: 600; line-height: 1.5; }
.session-confirm-detail { margin: 8px 0 0; color: #737780; font-size: 12px; line-height: 1.7; }
.session-confirm-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 18px; padding-top: 14px; border-top: 1px solid #e6e8ee; }
.session-confirm-actions button { min-height: 44px; font-size: 13px; }

#file-transfer-select { width: 100%; }
.clipboard-sync { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.clipboard-sync-label { font-size: 13px; font-weight: 600; }
.clipboard-sync .session-detail { margin: 4px 0 0; }
.connected-panel .clipboard-switch { flex: 0 0 40px; justify-content: flex-start; width: 40px; height: 24px; padding: 3px; border-radius: 999px; background: #c5c9d0; }
.connected-panel .clipboard-switch:hover:not(:disabled) { background: #b4bbc5; }
.clipboard-switch span { display: block; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px #0002; }
.connected-panel .clipboard-switch[aria-checked="true"] { background: #2175d5; }
.connected-panel .clipboard-switch[aria-checked="true"]:hover:not(:disabled) { background: #1964b9; }
.clipboard-switch[aria-checked="true"] span { transform: translateX(16px); }
.clipboard-actions { display: flex; gap: 8px; margin-bottom: 12px; }
.clipboard-actions button { flex: 1; }
.clipboard-feedback { color: #626772; font-size: 11px; }
.clipboard-manual { margin-top: 14px; border-top: 1px solid #e8e9ed; }
.clipboard-manual summary { cursor: pointer; padding: 10px 0 2px; color: #626772; font-size: 12px; }
.clipboard-manual summary:focus-visible { outline: 2px solid #2175d5; outline-offset: -2px; border-radius: 4px; }
.clipboard-manual-fields { padding-top: 12px; }
.clipboard-text { box-sizing: border-box; width: 100%; resize: vertical; min-height: 64px; max-height: 200px; padding: 8px; border: 1px solid #d8dce4; border-radius: 8px; background: #fff; color: #24262b; font: inherit; user-select: text; -webkit-user-select: text; touch-action: auto; }
#clipboard-send-text { width: 100%; margin: 6px 0 12px; }
#file-transfer-list { list-style: none; margin: 0; padding: 0; }
.file-transfer-item { border-top: 1px solid #e0e2e8; padding: 12px 0; }
.file-transfer-header { display: flex; align-items: center; gap: 8px; }
.file-transfer-header strong { flex: 1; min-width: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.connected-panel .file-transfer-remove { flex: 0 0 24px; width: 24px; height: 24px; padding: 0; font-size: 16px; line-height: 1; }
.file-transfer-item p { margin: 5px 0; font-size: 11px; color: #626772; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.file-transfer-item progress { display: block; width: 100%; height: 6px; margin: 8px 0; accent-color: #1262b3; }
.file-transfer-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.file-transfer-item [hidden] { display: none; }

/* The mouse bar follows the orb and yields its space while the menu is open. */
#virtual-mouse {
  position: fixed;
  z-index: 90;
  width: 140px;
  height: 48px;
  box-sizing: border-box;
  padding: 4px;
  border-radius: 12px;
  background: #f5f5f7;
  box-shadow: 0 3px 12px #0003;
  touch-action: none;
}
.virtual-mouse-row { display: flex; align-items: stretch; gap: 4px; width: 100%; }
.virtual-mouse-btn, .virtual-scroll-btn { min-width: 0; padding: 0; color: #333; background: #e8e8ee; border-radius: 8px; font-size: 11px; }
.virtual-mouse-btn { flex: 1; }
.virtual-scroll-buttons { width: 28px; display: flex; flex-direction: column; gap: 2px; }
.virtual-scroll-btn { width: 28px; flex: 1; font-size: 13px; line-height: 1; }
.virtual-mouse-btn:hover:not(:disabled), .virtual-scroll-btn:hover:not(:disabled) { background: #d8dfeb; transform: none; }

/* 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;
}

.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;
  }
}


/* Focus styles for accessibility */
button:focus-visible,
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;
}

@media (max-width: 760px) {
  .connection-overlay {
    padding: 24px max(16px, 5vw);
  }

  .connection-layout {
    max-width: 480px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "intro" "panel" "resources";
    gap: 24px;
    padding-block: 8px 24px;
  }

  .connection-intro h1 {
    font-size: clamp(27px, 6.5vw, 36px);
    margin-bottom: 12px;
  }

  .connection-intro p {
    font-size: 14px;
    line-height: 1.7;
  }
}

@media (max-width: 768px) {
  .control-buttons {
    width: 100%;
}

  .control-btn {
    flex: 1;
}
}

/* Keep the keyboard header reachable, including in landscape and after rotation. */
.virtual-keyboard {
  position: fixed;
  z-index: 95;
  min-width: 0;
  max-width: none;
  overflow: hidden;
  padding: 8px;
  border-radius: 14px;
  background: #f5f5f7;
  box-shadow: 0 4px 20px #0003;
  transition: none;
}
.keyboard-header { height: 28px; margin-bottom: 8px; color: #555; font-size: 12px; touch-action: none; }
.keyboard-grip { flex: 1; text-align: center; font-size: 20px; color: #999; }
.keyboard-close-btn { min-width: 28px; width: 28px; height: 28px; padding: 0; font-size: 20px; }
.keyboard-layout { max-height: calc(var(--keyboard-height, 100dvh) - 60px); overflow: auto; overscroll-behavior: contain; touch-action: pan-y; }
.keyboard-row { flex-shrink: 0; }
