/* Base design system & styling tokens */
:root {
  --bg-gradient: linear-gradient(135deg, #090a1a 0%, #1a080d 50%, #06050b 100%);
  --accent-color: #007fff; /* Zoom Blue */
  --accent-glow: rgba(0, 127, 255, 0.35);
  --glass-bg: rgba(25, 18, 46, 0.4);
  --glass-border: rgba(255, 255, 255, 0.06);
  --text-primary: #f5f3ff;
  --text-secondary: #8ba2ff; /* Soft blue-gray text */
  --success-color: #00f2fe;
  --danger-color: #ef3038; /* AnyDesk Red */
  --panel-width: 380px;
}

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

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

button, input, select, textarea {
  touch-action: manipulation;
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-gradient);
  color: var(--text-primary);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Ambient glow graphics */
.ambient-glow {
  position: absolute;
  top: 15%;
  left: 25%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(0, 127, 255, 0.35) 0%, rgba(239, 48, 56, 0.15) 50%, rgba(0,0,0,0) 70%);
  filter: blur(40px);
  z-index: 0;
  pointer-events: none;
}

/* Glassmorphism utility card */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease, background 0.3s ease, border-color 0.3s ease;
  transform: translateZ(0);
  will-change: transform;
}

/* Config & Login Overlay */
.panel-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(8, 6, 16, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px));
  z-index: 1000;
  transition: opacity 0.5s ease;
  transform: translateZ(0);
  will-change: opacity;
}

.panel-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.config-card {
  width: var(--panel-width);
  max-width: 100%;
  flex: 0 0 auto;
  padding: 40px 30px;
  text-align: center;
  z-index: 1001;
}

.auth-lockout-notice {
  margin: 0 0 18px;
  padding: 13px 14px;
  border: 1px solid rgba(255, 83, 83, 0.72);
  border-radius: 10px;
  background: rgba(126, 18, 24, 0.42);
  color: #ffd9dc;
  font-size: 0.86rem;
  line-height: 1.45;
  text-align: left;
}

.auth-lockout-notice.hidden {
  display: none;
}

@media (max-height: 650px) {
  .panel-overlay {
    align-items: flex-start;
  }

  .config-card {
    padding-top: 20px;
    padding-bottom: 20px;
  }
}

.logo {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(90deg, #ef3038, #ff5e62, #00c6ff, #007fff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 5px;
  letter-spacing: -0.5px;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 30px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.input-group {
  margin-bottom: 20px;
  text-align: left;
}

.input-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.input-group input:focus {
  outline: none;
  border-color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 10px rgba(121, 40, 202, 0.2);
}

.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.btn-primary {
  width: 100%;
  padding: 14px 20px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-color) 0%, #4facfe 100%);
  color: #fff;
  border: none;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(121, 40, 202, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn-primary:active {
  transform: scale(0.98);
  box-shadow: 0 2px 8px rgba(121, 40, 202, 0.3);
}

/* Viewport and HTML5 Video Element */
.viewport {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  background: #000;
  /* Crucial touch action override to allow full touch custom gesture handling */
  touch-action: none;
}

#remoteVideo {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
  transform-origin: center center;
  will-change: transform;
}

/* Invisible input for soft-keyboard trigger */
#kbdHelper {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  font-size: 16px; /* Prevents iOS auto-zoom on focus */
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
}

/* HUD Overlay status bar */
.hud-bar {
  position: absolute;
  top: calc(15px + env(safe-area-inset-top, 0px));
  left: calc(15px + env(safe-area-inset-left, 0px));
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  z-index: 20;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
}

.status-dot.disconnected {
  background: var(--danger-color);
  box-shadow: 0 0 8px var(--danger-color);
  animation: pulse-red 2s infinite;
}

.status-dot.connecting {
  background: #f1c40f;
  box-shadow: 0 0 8px #f1c40f;
  animation: pulse-yellow 1s infinite alternate;
}

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

@keyframes pulse-red {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}
@keyframes pulse-yellow {
  0% { transform: scale(0.9); opacity: 0.6; }
  100% { transform: scale(1.1); opacity: 1; }
}

/* Floating Dock Controller */
.controller-dock {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateZ(0);
  width: min(92vw, 560px);
  max-width: 560px;
  padding: 8px 12px 12px;
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(145deg, rgba(28, 38, 68, 0.72), rgba(10, 12, 28, 0.56)),
    rgba(12, 14, 30, 0.48);
  border: 1px solid rgba(188, 218, 255, 0.24);
  border-radius: 22px;
  box-shadow:
    0 22px 70px rgba(0, 0, 0, 0.46),
    0 8px 24px rgba(0, 80, 180, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(28px) saturate(190%);
  -webkit-backdrop-filter: blur(28px) saturate(190%);
  z-index: 100;
  transition:
    width 0.24s ease,
    max-width 0.24s ease,
    padding 0.24s ease,
    border-radius 0.24s ease,
    transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1),
    opacity 0.24s ease,
    background-color 0.24s ease;
  will-change: left, top, transform, opacity;
}

.controller-dock::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% -10%, rgba(117, 193, 255, 0.32), transparent 42%),
    linear-gradient(115deg, rgba(255, 255, 255, 0.08), transparent 34%);
}

.controller-dock > * {
  position: relative;
  z-index: 1;
}

.controller-dock.is-positioned {
  right: auto;
  bottom: auto;
  transform: translateZ(0);
}

.controller-dock.is-dragging {
  transition: none;
  box-shadow:
    0 28px 82px rgba(0, 0, 0, 0.52),
    0 0 34px rgba(0, 127, 255, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.controller-dock.hidden {
  transform: translate(-50%, calc(150% + env(safe-area-inset-bottom, 0px))) translateZ(0);
  opacity: 0;
  pointer-events: none;
}

.controller-dock.is-positioned.hidden {
  transform: translateY(36px) scale(0.94) translateZ(0);
}

.dock-topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  margin-bottom: 7px;
}

.dock-drag-handle {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: grab;
  touch-action: none;
}

.dock-drag-handle:active,
.dock-compact-drag:active {
  cursor: grabbing;
}

.dock-grip {
  color: rgba(190, 219, 255, 0.62);
  font-size: 1rem;
  line-height: 1;
  letter-spacing: -2px;
}

.dock-title {
  font-size: 0.71rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dock-drag-hint {
  overflow: hidden;
  color: rgba(206, 220, 255, 0.56);
  font-size: 0.64rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dock-window-button {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.07);
  color: rgba(238, 245, 255, 0.88);
  font: 700 1.1rem/1 system-ui, sans-serif;
  cursor: pointer;
  transition: background-color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.dock-window-button:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(170, 216, 255, 0.34);
}

.dock-compact-bar {
  display: none;
  align-items: center;
  gap: 4px;
}

.dock-compact-drag {
  flex: 0 0 30px;
  width: 30px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: rgba(190, 219, 255, 0.66);
  font-size: 1rem;
  cursor: grab;
  touch-action: none;
}

.dock-restore-button {
  height: 34px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid rgba(168, 215, 255, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  font: 700 0.72rem/1 'Outfit', sans-serif;
  letter-spacing: 0.03em;
  cursor: pointer;
}

.dock-restore-button:active {
  background: rgba(0, 127, 255, 0.24);
}

.dock-restore-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success-color);
  box-shadow: 0 0 9px rgba(0, 242, 254, 0.75);
}

.dock-restore-chevron {
  color: rgba(201, 225, 255, 0.72);
  font-size: 0.8rem;
}

.controller-dock.is-collapsed {
  width: auto;
  max-width: none;
  padding: 6px;
  border-radius: 17px;
}

.controller-dock.is-collapsed .dock-topbar,
.controller-dock.is-collapsed .dock-row {
  display: none;
}

.controller-dock.is-collapsed .dock-compact-bar {
  display: flex;
}

.dock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dock-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dock-section.flex-row {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.dock-label {
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Toggleable button groups */
.btn-toggle-group {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 2px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-toggle {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  padding: 6px 12px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.btn-toggle.active {
  background: var(--accent-color);
  color: #fff;
  box-shadow: 0 2px 8px rgba(121, 40, 202, 0.3);
}

.dock-divider {
  width: 1px;
  height: 30px;
  background: rgba(255, 255, 255, 0.1);
  margin: 0 8px;
}

/* Action buttons */
.btn-action {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.btn-action:active, .btn-action.active {
  background: var(--accent-color);
  border-color: var(--accent-color);
  box-shadow: 0 0 10px rgba(121, 40, 202, 0.3);
}

.btn-action:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-action.remote-mic {
  position: relative;
}

.btn-action.remote-mic.requesting {
  border-color: #f59e0b;
  animation: mic-request-pulse 1s ease-in-out infinite alternate;
}

.btn-action.remote-mic.active {
  background: #dc2626;
  border-color: #ef4444;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.55);
}

.btn-action.remote-mic.error {
  border-color: #ef4444;
  color: #fca5a5;
}

.mic-live-dot {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
}

.remote-mic.active .mic-live-dot {
  display: block;
}

.remote-mic-notice {
  position: fixed;
  left: 50%;
  bottom: 92px;
  z-index: 1200;
  max-width: min(88vw, 520px);
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid rgba(248, 113, 113, 0.7);
  border-radius: 10px;
  background: rgba(69, 10, 10, 0.94);
  color: #fee2e2;
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.38);
}

.remote-mic-notice.hidden {
  display: none;
}

@keyframes mic-request-pulse {
  from { opacity: 0.55; }
  to { opacity: 1; }
}

/* Dropdown */
.select-quality {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  padding: 8px 10px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

/* Make dropdown option text highly legible by forcing a solid dark font color on mobile and desktop OS renderers */
.select-quality option {
  color: #11111b !important;
  background-color: #ffffff !important;
}

/* Danger Circle disconnect button */
.btn-danger-circle {
  background: rgba(255, 0, 127, 0.15);
  border: 1px solid rgba(255, 0, 127, 0.3);
  color: var(--danger-color);
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  flex: 0 0 36px;
  padding: 0;
  border-radius: 999px;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  line-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-danger-circle:active {
  background: var(--danger-color);
  color: #fff;
  transform: scale(0.95);
  box-shadow: 0 0 10px rgba(255, 0, 127, 0.4);
}

/* Responsive adjustments */
@media (max-width: 480px) {
  .config-card {
    width: 92%;
    padding: 25px 20px;
  }
  .controller-dock {
    width: 96%;
    padding: 7px 10px 10px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }
  .controller-dock.is-collapsed {
    width: auto;
    padding: 6px;
  }
  .dock-topbar {
    margin-bottom: 5px;
  }
  .dock-drag-hint {
    display: none;
  }
  .dock-row {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }
  .dock-divider {
    display: none; /* Hide vertical line in stacked layout */
  }
  .dock-section {
    align-items: center;
  }
  .dock-section .dock-label {
    display: none; /* Hide label to save vertical space on mobile */
  }
  .btn-toggle-group {
    padding: 1px;
  }
  .btn-toggle {
    padding: 4px 8px;
    font-size: 0.7rem;
  }
  .btn-action {
    width: 32px;
    height: 32px;
  }
  .btn-action svg {
    width: 16px;
    height: 16px;
  }
  .select-quality {
    padding: 6px 8px;
    font-size: 0.7rem;
  }
  .btn-danger-circle {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    flex-basis: 32px;
  }
  .btn-danger-circle svg {
    width: 16px;
    height: 16px;
  }
}
