:root {
  --bg-main: #090d16;
  --bg-surface: #111827;
  --bg-card: #1f2937;
  --border-color: #374151;
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #06b6d4;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --warning: #f59e0b;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-sans);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* Header */
.app-header {
  height: 54px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 10;
}

.header-left, .header-center, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 1px;
}

.brand-radar {
  width: 12px;
  height: 12px;
  background-color: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--accent);
  animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

.brand-title .highlight {
  color: var(--primary);
}

.session-badge {
  background-color: var(--bg-card);
  padding: 4px 10px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  border: 1px solid var(--border-color);
  display: flex;
  gap: 6px;
}

.badge-label {
  color: var(--text-muted);
}

.badge-value {
  color: var(--accent);
  font-weight: 600;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 10px;
  border-radius: 20px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--danger);
  transition: background-color 0.3s;
}

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

.connection-status.waiting .status-dot {
  background-color: var(--warning);
  box-shadow: 0 0 8px var(--warning);
}

.latency-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.mode-badge {
  background-color: rgba(59, 130, 246, 0.15);
  color: var(--primary);
  border: 1px solid rgba(59, 130, 246, 0.4);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.5px;
}

.mode-badge.control {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.4);
}

/* Viewport Area */
.viewport-area {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #030712;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

.stream-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  user-select: none;
  overflow: hidden;
  border-radius: 0;
}

#remoteVideo {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  user-select: none;
  touch-action: none;
  -webkit-user-drag: none;
}

.touch-ripple {
  position: absolute;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: rgba(56, 189, 248, 0.35);
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.4);
  animation: ripple 0.35s ease-out forwards;
  z-index: 25;
}

@keyframes ripple {
  to {
    transform: translate(-50%, -50%) scale(1.6);
    opacity: 0;
  }
}

/* Modals */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(3, 7, 18, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  width: 100%;
  max-width: 420px;
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8);
}

.modal-header {
  text-align: center;
  margin-bottom: 24px;
}

.modal-icon {
  font-size: 36px;
  margin-bottom: 12px;
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}

.modal-header p {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.4;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-card);
  color: var(--text-main);
  font-size: 14px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-block {
  width: 100%;
  padding: 12px;
}

.btn-primary {
  background-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-danger {
  background-color: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background-color: var(--danger-hover);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background: var(--bg-card);
}

.btn-icon {
  background: transparent;
  color: var(--text-muted);
  padding: 8px;
}

.btn-icon:hover {
  color: var(--text-main);
}

.error-msg {
  color: var(--danger);
  font-size: 12px;
  font-family: var(--font-mono);
  margin-top: 10px;
  text-align: center;
  min-height: 18px;
}

.modal-footer {
  margin-top: 20px;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
}

/* Modal Waiting */
.modal-waiting {
  text-align: center;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(59, 130, 246, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s infinite linear;
  margin: 0 auto 16px;
}

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

.overlay-notice {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(3, 7, 18, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

.notice-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 24px 32px;
  border-radius: 12px;
  text-align: center;
  max-width: 360px;
}

.notice-card h3 {
  margin-bottom: 8px;
}

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

/* Footer */
.app-footer {
  height: 32px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.info-tag {
  letter-spacing: 0.5px;
}

/* Audio Autoplay Notification */
.audio-notice {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.95);
  border: 1px solid var(--warning);
  padding: 8px 16px;
  border-radius: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 35;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  font-size: 13px;
  white-space: nowrap;
}

/* Mobile Quick Action Dock */
.mobile-dock {
  position: absolute;
  bottom: 44px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 30px;
  padding: 6px 10px;
  display: flex;
  gap: 8px;
  z-index: 30;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
}

.dock-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.dock-btn.active, .dock-btn:hover {
  background: var(--primary);
  color: #fff;
}

/* Mobile Input Sheet */
.mobile-input-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding: 12px 16px 20px;
  z-index: 60;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.sheet-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
}

.sheet-row {
  display: flex;
  gap: 8px;
}

.sheet-row input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: #fff;
  font-size: 14px;
  outline: none;
}

.sheet-keys {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.key-chip {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.key-chip:active {
  background: var(--primary);
  color: #fff;
}

/* Remote Browser Navigation Toolbar */
.nav-toolbar {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.94);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 30px;
  padding: 4px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 45;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
  max-width: 94%;
  width: 580px;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.nav-toolbar.collapsed {
  transform: translate(-50%, -120%);
  opacity: 0;
  pointer-events: none;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 13px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.nav-btn:active {
  background: var(--primary);
  color: #fff;
}

.nav-url-form {
  display: flex;
  align-items: center;
  flex: 1;
  background: #090d16;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  padding: 2px 4px 2px 12px;
}

.nav-url-form input {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
  min-width: 0;
}

.nav-go-btn {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  width: auto;
  padding: 3px 10px;
  border-radius: 12px;
}

/* Zoom & Pan Reset Floating Pill */
.zoom-pill {
  position: absolute;
  top: 60px;
  right: 16px;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--accent);
  border-radius: 20px;
  padding: 4px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 40;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
}

.btn-zoom-reset {
  background: var(--accent);
  color: #030712;
  border: none;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-zoom-reset:hover {
  opacity: 0.85;
}

/* Screen Mode & Fit Controls */
.btn-screen-fit {
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #38bdf8;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-family: var(--font-mono);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-screen-fit:hover {
  background: rgba(56, 189, 248, 0.28);
  border-color: #38bdf8;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.35);
}

.btn-screen-fit.is-fit {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.45);
  color: #fbbf24;
}

.btn-screen-fit.is-fit:hover {
  background: rgba(245, 158, 11, 0.25);
  border-color: #fbbf24;
}

/* Responsive Media Queries */
@media (max-width: 768px) {
  .app-header {
    height: 48px;
    padding: 0 10px;
  }

  .session-badge {
    display: none !important;
  }

  .latency-badge {
    display: none !important;
  }

  .brand-title {
    font-size: 14px;
  }

  .btn {
    padding: 6px 10px;
  }

  .app-footer {
    display: none;
  }

  .mobile-dock {
    display: flex !important;
  }

  #mobileKeyboardBtn {
    display: inline-flex !important;
  }
}

@media (max-width: 480px) {
  .modal-card {
    padding: 20px;
    margin: 12px;
  }

  .mode-badge {
    display: none !important;
  }
}
