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

:root {
  --bg: #faf5ff;
  --bg-surface: #f3e8ff;
  --bg-elevated: #e9d5ff;
  --text: #1e1b4b;
  --text-muted: #6b7280;
  --primary: #a78bfa;
  --primary-hover: #8b5cf6;
  --primary-light: #c4b5fd;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Screens ─────────────────────────────────────────── */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.screen.active {
  display: flex;
}

/* ── Home Screen ─────────────────────────────────────── */
.home-content {
  text-align: center;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}

.logo {
  margin-bottom: 1.25rem;
}

.logo img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--primary-light);
  box-shadow: 0 4px 20px rgba(167, 139, 250, 0.25);
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
  color: var(--text);
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 2rem;
}

/* ── Password + Action ───────────────────────────────── */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.input-group {
  position: relative;
}

.input-group input {
  width: 100%;
  background: white;
  border: 1.5px solid var(--bg-elevated);
  color: var(--text);
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.15);
}

.input-group input::placeholder {
  color: #b0b0c0;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.25rem;
}

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  padding: 0.85rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--bg-elevated);
}

.btn-ghost:hover {
  background: var(--bg-surface);
  color: var(--text);
}

/* ── Connecting Screen ───────────────────────────────── */
.connecting-content {
  text-align: center;
  padding: 2rem;
}

.loader {
  width: 44px;
  height: 44px;
  border: 3px solid var(--bg-elevated);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1.5rem;
}

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

.status-text {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

/* ── Call Screen ─────────────────────────────────────── */
.video-container {
  position: fixed;
  inset: 0;
  background: #000;
}

#video-remote {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#video-local {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 1rem);
  right: 1rem;
  width: 120px;
  height: 160px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 2px solid rgba(255, 255, 255, 0.2);
  z-index: 10;
  transform: scaleX(-1);
}

@media (min-width: 768px) {
  #video-local {
    width: 200px;
    height: 150px;
  }
}

.connection-badge {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 1rem);
  left: 1rem;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  color: white;
  z-index: 10;
  transition: opacity 0.3s;
}

.connection-badge.connected { color: var(--success); }
.connection-badge.connecting { color: var(--warning); }
.connection-badge.failed { color: var(--danger); }
.connection-badge.hide { opacity: 0; pointer-events: none; }

/* ── Call Controls ────────────────────────────────────── */
.call-controls {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 2rem);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1.25rem;
  z-index: 20;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
}

.btn-control {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-control:hover {
  background: rgba(255, 255, 255, 0.25);
}

.btn-control.muted {
  background: var(--danger);
}

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

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

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

/* ── Toast ────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 7rem);
  left: 50%;
  transform: translateX(-50%);
  background: white;
  color: var(--text);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 100;
  transition: opacity 0.3s, transform 0.3s;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(1rem);
}

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

/* ── Utilities ────────────────────────────────────────── */
.hidden { display: none !important; }

.screen { animation: fadeIn 0.25s ease-out; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
