@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a26;
  --bg-card-hover: #22222f;
  --bg-glass: rgba(26, 26, 38, 0.7);
  --bg-input: #15151f;

  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #555570;

  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --accent-glow: rgba(108, 92, 231, 0.3);
  --accent-gradient: linear-gradient(135deg, #6c5ce7, #a29bfe);

  --success: #00d2a0;
  --success-glow: rgba(0, 210, 160, 0.3);
  --danger: #ff6b6b;
  --danger-glow: rgba(255, 107, 107, 0.3);
  --warning: #ffd93d;

  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px var(--accent-glow);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Background Animation ───────────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(108, 92, 231, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(162, 155, 254, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(0, 210, 160, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ─────────────────────────────────────────────────── */
.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────── */
.header {
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
  background: rgba(10, 10, 15, 0.8);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: var(--shadow-glow);
}

.logo-text {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent-light);
  background: rgba(108, 92, 231, 0.15);
  padding: 3px 8px;
  border-radius: 20px;
  border: 1px solid rgba(108, 92, 231, 0.25);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all 0.3s ease;
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 8px var(--success-glow);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-dot.connecting {
  background: var(--warning);
  animation: pulse-dot 1s ease-in-out infinite;
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger-glow);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.3); }
}

/* ── Connect Screen ─────────────────────────────────────────── */
.connect-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.connect-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 48px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.connect-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-light), transparent);
}

.connect-title {
  font-size: 1.75rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.connect-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 36px;
  line-height: 1.5;
}

.code-input-group {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-bottom: 28px;
}

.code-separator {
  width: 6px;
}

.code-digit {
  width: 46px;
  height: 56px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.2rem;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: all 0.2s ease;
  caret-color: var(--accent);
}

.code-digit:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: rgba(108, 92, 231, 0.05);
}

.code-digit.filled {
  border-color: var(--accent-light);
  background: rgba(108, 92, 231, 0.08);
}

.connect-btn {
  width: 100%;
  padding: 16px 24px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  color: white;
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.connect-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.connect-btn:active:not(:disabled) {
  transform: translateY(0);
}

.connect-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.connect-btn .spinner {
  display: none;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

.connect-btn.loading .btn-text { display: none; }
.connect-btn.loading .spinner { display: inline-block; }

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

.connect-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 28px 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.connect-divider::before,
.connect-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.connect-info {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  background: rgba(108, 92, 231, 0.06);
  border: 1px solid rgba(108, 92, 231, 0.12);
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.connect-info-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ── Viewer Screen ──────────────────────────────────────────── */
.viewer-screen {
  flex: 1;
  display: none;
  flex-direction: column;
  background: #000;
}

.viewer-screen.active {
  display: flex;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}

.viewer-toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.viewer-room-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-light);
  background: rgba(108, 92, 231, 0.12);
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid rgba(108, 92, 231, 0.2);
}

.viewer-permission-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}

.viewer-permission-badge.viewer {
  color: #ffd93d;
  background: rgba(255, 217, 61, 0.12);
  border: 1px solid rgba(255, 217, 61, 0.3);
}

.viewer-permission-badge.controller {
  color: var(--success);
  background: rgba(0, 210, 160, 0.12);
  border: 1px solid rgba(0, 210, 160, 0.3);
}

.viewer-stats {
  display: flex;
  gap: 16px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

.viewer-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.toolbar-btn.danger:hover {
  background: rgba(255, 107, 107, 0.1);
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.3);
}

.quality-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: 8px;
  padding-right: 12px;
  border-right: 1px solid var(--border);
}

.quality-selector label {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.quality-select {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.78rem;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238888a0' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
}

.quality-select:hover {
  border-color: var(--border-hover);
}

.quality-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.quality-select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

.viewer-canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  background: #0a0a0a;
}

#remote-screen {
  max-width: 100%;
  max-height: 100%;
  cursor: default;
  image-rendering: auto;
}

.viewer-canvas-container.fit-screen #remote-screen {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ── Local Lock Tooltip ─────────────────────────────────────── */
.local-lock-tooltip {
  position: absolute;
  display: none;
  padding: 8px 16px;
  background: rgba(20, 20, 30, 0.92);
  border: 1px solid rgba(255, 217, 61, 0.4);
  border-radius: 8px;
  color: #ffd93d;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  transform: translate(16px, 16px);
}

.local-lock-tooltip.active {
  display: block;
}

/* ── Connection Status Overlay ──────────────────────────────── */
.connection-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 10, 15, 0.9);
  backdrop-filter: blur(12px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.connection-overlay.active {
  display: flex;
}

.connection-overlay-content {
  text-align: center;
}

.connection-overlay-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.connection-overlay-text {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.connection-overlay-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ══════════════════════════════════════════════
   SECURITY KEY / AUTH DIALOG
   ══════════════════════════════════════════════ */
.auth-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 15, 0.92);
  backdrop-filter: blur(16px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 600;
}

.auth-dialog-overlay.active {
  display: flex;
}

.auth-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 36px 36px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
  animation: authDialogIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes authDialogIn {
  from { opacity: 0; transform: scale(0.92) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.auth-dialog::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 50%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #ffd93d, transparent);
}

.auth-dialog-icon {
  font-size: 2.8rem;
  margin-bottom: 12px;
}

.auth-dialog-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.3px;
}

.auth-dialog-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 28px;
}

.auth-pin-inputs {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
}

.auth-pin-digit {
  width: 48px;
  height: 60px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  outline: none;
  transition: all 0.2s ease;
  caret-color: var(--warning);
}

.auth-pin-digit:focus {
  border-color: var(--warning);
  box-shadow: 0 0 0 3px rgba(255, 217, 61, 0.2);
  background: rgba(255, 217, 61, 0.04);
}

.auth-pin-digit.filled {
  border-color: rgba(255, 217, 61, 0.5);
  background: rgba(255, 217, 61, 0.06);
}

.auth-pin-digit.error {
  border-color: var(--danger);
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.auth-error {
  padding: 8px 16px;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.2);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 500;
  margin-bottom: 16px;
}

.auth-submit-btn {
  width: 100%;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #ffd93d, #f59e0b);
  color: #1a1a2e;
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.auth-submit-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 0 30px rgba(255, 217, 61, 0.3);
}

.auth-submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-submit-btn .spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(26, 26, 46, 0.3);
  border-top-color: #1a1a2e;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

.auth-submit-btn.loading .btn-text { display: none; }
.auth-submit-btn.loading .spinner { display: inline-block; }

/* ── Toast Notifications ────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  font-size: 0.85rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  animation: toast-in 0.3s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  backdrop-filter: blur(12px);
  max-width: 360px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 560px) {
  .connect-card {
    padding: 32px 24px;
  }
  .code-digit {
    width: 44px;
    height: 56px;
    font-size: 1.25rem;
  }
  .header {
    padding: 16px 20px;
  }
  .logo-text {
    font-size: 1.25rem;
  }
  .auth-dialog {
    margin: 0 16px;
    padding: 32px 24px 28px;
  }
  .auth-pin-digit {
    width: 42px;
    height: 52px;
    font-size: 1.2rem;
  }
}
