:root {
  --bg-primary: #090d16;
  --bg-glass: rgba(15, 23, 42, 0.84);
  --bg-surface: #1e293b;
  --border-glass: rgba(148, 163, 184, 0.18);
  --accent: #38bdf8;
  --accent-active: #0284c7;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", sans-serif;
  touch-action: none;
}

/* Login Overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: radial-gradient(circle at 50% 20%, #1e293b 0%, #090d16 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-overlay.hidden {
  display: none;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: 24px;
  padding: 28px 24px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.login-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 18px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}

.login-card h1 {
  font-size: 21px;
  font-weight: 700;
  margin-bottom: 6px;
}

.login-card p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.4;
}

.login-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border-glass);
  background: rgba(9, 13, 22, 0.75);
  color: var(--text-main);
  font-size: 16px;
  margin-bottom: 14px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

.login-input:focus {
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, #38bdf8, #0284c7);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:active {
  transform: scale(0.98);
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}

/* Main Workspace Layout */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* IMMERSIVE FULLSCREEN MODE */
.app-container.is-fullscreen {
  padding: 0;
}

.app-container.is-fullscreen .top-bar,
.app-container.is-fullscreen .mouse-strip,
.app-container.is-fullscreen .bottom-dock {
  display: none !important;
}

.app-container.is-fullscreen .key-bar {
  display: none;
}

.app-container.is-fullscreen.show-fs-keys .key-bar {
  display: flex;
  position: fixed;
  left: max(8px, var(--safe-left));
  right: max(8px, var(--safe-right));
  bottom: max(8px, var(--safe-bottom));
  z-index: 35;
  border-radius: 14px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  background: rgba(9, 13, 22, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.65);
}

/* Top Status Bar */
.top-bar {
  height: 44px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-glass);
  z-index: 20;
  flex-shrink: 0;
}

.status-group {
  display: flex;
  align-items: center;
  gap: 7px;
  overflow: hidden;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
}

.status-dot.online {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-dot.waiting {
  background: var(--warning);
}

.host-label {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 125px;
}

.metrics-badge {
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  padding: 3px 7px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  padding: 6px 9px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  white-space: nowrap;
}

.icon-btn.active {
  background: rgba(56, 189, 248, 0.22);
  border-color: var(--accent);
  color: var(--accent);
}

.icon-btn.accent-btn {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.45);
  color: #e0f2fe;
}

@media (max-width: 440px) {
  .top-bar {
    padding: 0 8px;
  }
  .status-group {
    gap: 5px;
  }
  .host-label {
    font-size: 12px;
    max-width: 72px;
  }
  .metrics-badge {
    font-size: 10px;
    padding: 2px 5px;
  }
  .top-actions {
    gap: 4px;
  }
  .icon-btn {
    padding: 5px 7px;
    font-size: 11px;
    border-radius: 8px;
  }
}

/* Viewport & Screen Canvas */
.viewport {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #03060c;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.canvas-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  will-change: transform;
}

.screen-surface {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  background: #0b1120;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.65);
}

.screen-surface.hidden {
  display: none;
}

/* Stretch / Fill Viewport option in Fullscreen */
.app-container.is-fullscreen.fill-screen .canvas-wrapper {
  width: 100%;
  height: 100%;
}

.app-container.is-fullscreen.fill-screen .screen-surface {
  width: 100% !important;
  height: 100% !important;
  max-width: none;
  max-height: none;
  object-fit: fill;
}

/* Floating Mini HUD in Fullscreen Mode */
.floating-hud {
  position: absolute;
  top: max(10px, var(--safe-top));
  right: max(12px, var(--safe-right));
  z-index: 40;
  display: flex;
  align-items: center;
  flex-direction: row-reverse;
  gap: 6px;
}

.floating-hud.hidden {
  display: none;
}

.hud-fab {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: rgba(9, 13, 22, 0.68);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text-main);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
  opacity: 0.72;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.floating-hud.expanded .hud-fab {
  opacity: 1;
  background: rgba(56, 189, 248, 0.28);
}

.hud-menu {
  display: none;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
  background: rgba(9, 13, 22, 0.86);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  padding: 5px 7px;
  border-radius: 14px;
  max-width: calc(100vw - 75px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.65);
}

.floating-hud.expanded .hud-menu {
  display: flex;
}

.hud-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  padding: 6px 9px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.hud-btn:active, .hud-btn.active {
  background: var(--accent);
  color: #090d16;
  border-color: var(--accent);
}

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

/* Virtual cursor overlay for Trackpad Mode */
.virtual-cursor {
  position: absolute;
  width: 18px;
  height: 18px;
  pointer-events: none;
  z-index: 15;
  transform: translate(-2px, -2px);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.85));
  transition: transform 0.04s linear;
}

.virtual-cursor.clicking {
  transform: translate(-2px, -2px) scale(0.82);
}

body.desktop-mouse .virtual-cursor {
  display: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  pointer-events: none;
}

.empty-state.hidden {
  display: none;
}

.perm-banner {
  position: absolute;
  top: 8px;
  left: 12px;
  right: 12px;
  background: rgba(245, 158, 11, 0.92);
  color: #090d16;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  z-index: 18;
  text-align: center;
}

.perm-banner.hidden {
  display: none;
}

/* Trackpad Mouse Buttons Strip */
.mouse-strip {
  display: flex;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(15, 23, 42, 0.92);
  border-top: 1px solid var(--border-glass);
  flex-shrink: 0;
}

.mouse-btn {
  flex: 1;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid var(--border-glass);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.mouse-btn:active, .mouse-btn.active {
  background: rgba(56, 189, 248, 0.25);
  border-color: var(--accent);
  color: var(--accent);
}

/* Mac Keyboard & Modifier Bar */
.key-bar {
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  overflow-x: auto;
  background: var(--bg-glass);
  border-top: 1px solid var(--border-glass);
  flex-shrink: 0;
  scrollbar-width: none;
}

.key-bar::-webkit-scrollbar {
  display: none;
}

.key-pill {
  flex-shrink: 0;
  padding: 8px 11px;
  border-radius: 9px;
  border: 1px solid var(--border-glass);
  background: rgba(30, 41, 59, 0.85);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 600;
}

.key-pill:active, .key-pill.active {
  background: var(--accent);
  color: #090d16;
  border-color: var(--accent);
}

/* Bottom Dock */
.bottom-dock {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 8px 10px;
  background: var(--bg-glass);
  border-top: 1px solid var(--border-glass);
  flex-shrink: 0;
}

.dock-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 10px;
}

.dock-btn span.icon {
  font-size: 17px;
}

.dock-btn.active, .dock-btn:active {
  color: var(--accent);
}

/* Compact adjustments when in Landscape even outside Fullscreen */
@media (orientation: landscape) {
  .top-bar {
    height: 36px;
    padding: 0 8px;
  }
  .mouse-strip {
    padding: 4px 8px;
  }
  .mouse-btn {
    padding: 6px;
    font-size: 11px;
  }
  .key-bar {
    padding: 4px 8px;
  }
  .key-pill {
    padding: 5px 9px;
    font-size: 11px;
  }
  .bottom-dock {
    padding: 4px 8px;
  }
  .dock-btn {
    flex-direction: row;
    gap: 5px;
    font-size: 11px;
    padding: 3px 8px;
  }
  .dock-btn span.icon {
    font-size: 14px;
  }
}

/* Hidden iPhone native keyboard input */
#hiddenKeyboardInput {
  position: fixed;
  top: -100px;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  font-size: 16px;
}

/* Slide-up Drawers / Modals (Quick Mac Actions, Stream Settings, Clipboard) */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.drawer-backdrop.hidden {
  display: none;
}

.drawer-sheet {
  width: 100%;
  max-width: 480px;
  background: #0f172a;
  border-top: 1px solid var(--border-glass);
  border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  max-height: 80vh;
  overflow-y: auto;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.drawer-header h2 {
  font-size: 16px;
  font-weight: 700;
}

.close-btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.action-tile {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 12px 8px;
  color: var(--text-main);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.action-tile:active {
  background: rgba(56, 189, 248, 0.2);
  border-color: var(--accent);
}

.setting-row {
  margin-bottom: 16px;
}

.setting-row label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-muted);
}

.segment-group {
  display: flex;
  gap: 8px;
}

.segment-btn {
  flex: 1;
  padding: 9px 6px;
  border-radius: 10px;
  border: 1px solid var(--border-glass);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 600;
}

.segment-btn.active {
  background: var(--accent);
  color: #090d16;
  border-color: var(--accent);
}

.clipboard-area {
  width: 100%;
  min-height: 90px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border-glass);
  background: #090d16;
  color: var(--text-main);
  font-size: 15px;
  margin-bottom: 12px;
  user-select: text;
  -webkit-user-select: text;
}
