:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-card-hover: rgba(31, 41, 55, 0.85);
  --border-color: rgba(255, 255, 255, 0.1);
  --border-color-glow: rgba(59, 130, 246, 0.5);
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  --accent-primary: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.35);
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.35);
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-glow: rgba(239, 68, 68, 0.35);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, Monaco, monospace;
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.5), 0 0 1px 1px var(--border-color);
  --shadow-glow: 0 0 25px var(--accent-glow);
  --transition-fast: 0.18s ease;
  --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(59, 130, 246, 0.12) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(139, 92, 246, 0.10) 0%, transparent 40%);
  background-attachment: fixed;
  overflow-x: hidden;
}

/* Header */
.header {
  border-bottom: 1px solid var(--border-color);
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow);
}

.brand-icon svg {
  width: 22px;
  height: 22px;
  fill: white;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(to right, #ffffff, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-text p {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Container */
.app-container {
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  flex: 1;
  width: 100%;
}

/* Navigation Tabs */
.view-tabs {
  display: flex;
  background: rgba(17, 24, 39, 0.6);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  padding: 0.35rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.75rem;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.65rem 1rem;
  border-radius: calc(var(--radius-md) - 4px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
}

.tab-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.tab-btn:hover:not(.active) {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

/* Card Styles */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-card);
  transition: border-color var(--transition-smooth);
}

.card-header {
  margin-bottom: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.card-title-group h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.3rem;
}

.card-title-group p {
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.82rem;
  font-weight: 600;
  background: rgba(107, 114, 128, 0.2);
  color: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.status-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}

.status-badge.live {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.3);
  box-shadow: 0 0 15px var(--success-glow);
}

.status-badge.live .dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse-dot 1.8s infinite;
}

.status-badge.connecting {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
  border-color: rgba(245, 158, 11, 0.3);
}

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

.status-badge.error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}

.status-badge.error .dot {
  background: var(--danger);
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.75rem 1.4rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  user-select: none;
}

.btn-primary {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.45);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
  box-shadow: 0 4px 15px var(--danger-glow);
}

.btn-danger:hover {
  background: var(--danger-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

.btn-icon-only {
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-icon-only:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.12);
}

.btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none !important;
}

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

.spin {
  animation: spin 1s linear infinite;
}

/* Host Initial State Hero */
.host-hero {
  text-align: center;
  padding: 3rem 1.5rem;
  border: 2px dashed rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-lg);
  background: rgba(0, 0, 0, 0.2);
  margin-bottom: 1.5rem;
}

.hero-icon-wrap {
  width: 76px;
  height: 76px;
  margin: 0 auto 1.5rem auto;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
}

.hero-icon-wrap svg {
  width: 40px;
  height: 40px;
}

.host-hero h3 {
  font-size: 1.35rem;
  margin-bottom: 0.5rem;
  font-weight: 700;
}

.host-hero p {
  color: var(--text-muted);
  max-width: 520px;
  margin: 0 auto 1.75rem auto;
  font-size: 0.95rem;
  line-height: 1.5;
}

.host-options {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--accent-primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Host Active Dashboard */
.host-active-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.stream-stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.stat-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
}

.stat-icon svg {
  width: 20px;
  height: 20px;
}

.stat-info .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-info .stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  font-family: var(--font-mono);
}

/* Sharing Box */
.share-section {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.share-section-title {
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.share-input-group {
  display: flex;
  gap: 0.5rem;
}

.share-input {
  flex: 1;
  background: rgba(11, 15, 25, 0.9);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  color: #93c5fd;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

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

.share-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.code-display {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.code-badge {
  font-family: var(--font-mono);
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #bfdbfe;
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
  font-weight: 700;
  letter-spacing: 0.05em;
  font-size: 0.95rem;
}

/* Video Containers */
.video-viewport {
  position: relative;
  background: #090d16;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6);
  min-height: 220px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-element {
  width: 100%;
  height: auto;
  max-height: 78vh;
  object-fit: contain;
  display: block;
}

.video-overlay-badge {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 10;
  pointer-events: none;
}

.video-controls-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent);
  padding: 1.25rem 1rem 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: 10;
}

.video-viewport:hover .video-controls-bar {
  opacity: 1;
}

.video-controls-left, .video-controls-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Audio prompt on viewer */
.unmute-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid var(--border-color);
  padding: 1.2rem 1.8rem;
  border-radius: var(--radius-md);
  text-align: center;
  z-index: 20;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.8);
  display: none;
}

.unmute-banner.visible {
  display: block;
}

/* QR Code Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  padding: 2rem;
  position: relative;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.75);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.2rem;
  border-radius: 4px;
}

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

.qr-code-wrapper {
  background: white;
  padding: 1.25rem;
  border-radius: var(--radius-md);
  width: fit-content;
  margin: 0 auto 1.5rem auto;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.qr-code-wrapper canvas {
  display: block;
}

/* Viewer Join Form */
.join-form-wrapper {
  max-width: 480px;
  margin: 2rem auto;
  text-align: center;
}

.join-input-group {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.join-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1.15rem;
  color: var(--text-main);
  font-size: 1rem;
  font-family: var(--font-mono);
  outline: none;
}

.join-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Settings Form */
.settings-group {
  margin-bottom: 1.25rem;
}

.settings-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  font-weight: 600;
}

.settings-input, .settings-textarea {
  width: 100%;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  outline: none;
}

.settings-textarea {
  min-height: 80px;
  resize: vertical;
}

/* Collapsible Manual Signaling Section */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
  border-top: 1px solid var(--border-color);
  margin-top: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  user-select: none;
}

.collapsible-header:hover {
  color: var(--text-main);
}

.collapsible-content {
  display: none;
  padding-bottom: 1.5rem;
}

.collapsible-content.open {
  display: block;
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  animation: slide-toast 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  pointer-events: auto;
}

.toast.success {
  border-color: rgba(16, 185, 129, 0.4);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.4);
}

@keyframes slide-toast {
  from {
    opacity: 0;
    transform: translateY(15px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Footer */
.footer {
  margin-top: auto;
  border-top: 1px solid var(--border-color);
  padding: 1.5rem 0;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-dim);
  background: rgba(11, 15, 25, 0.6);
}

.footer a {
  color: var(--text-muted);
  text-decoration: underline;
}

.footer a:hover {
  color: var(--accent-primary);
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .app-container {
    padding: 0 1rem;
    margin: 1rem auto;
  }
  .card {
    padding: 1.25rem;
  }
  .share-input-group {
    flex-direction: column;
  }
  .toast-container {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
  }
}
