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

:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface-2: #24243a;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --danger: #e74c3c;
  --success: #2ecc71;
  --text: #f0f0f5;
  --text-muted: #8888a0;
  --radius: 16px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
}

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

.screen {
  display: none;
  width: 100vw;
  height: 100vh;
}
.screen.active { display: flex; }

/* ── Upload Screen ── */
#upload-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, #1a1040 0%, var(--bg) 70%);
}

.upload-container {
  width: 90%;
  max-width: 520px;
  text-align: center;
}

.logo-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.logo h1 {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.subtitle { color: var(--text-muted); margin: 0.5rem 0 2rem; font-size: 0.95rem; }

.upload-zone {
  border: 2px dashed var(--surface-2);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  cursor: pointer;
  transition: all 0.3s;
  background: var(--surface);
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(108,92,231,0.08);
  transform: translateY(-2px);
}
.upload-icon { font-size: 2.5rem; margin-bottom: 1rem; }
.upload-text { font-weight: 600; font-size: 1.1rem; }
.upload-hint { color: var(--text-muted); margin-top: 0.3rem; font-size: 0.85rem; }
.upload-formats { color: var(--text-muted); margin-top: 1rem; font-size: 0.75rem; }

.preview-section { margin-top: 2rem; }
.preview-section.hidden { display: none; }

.preview-card {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--accent);
  box-shadow: 0 0 30px rgba(108,92,231,0.3);
}
.preview-card img { width: 100%; height: 100%; object-fit: cover; }

.preview-overlay {
  position: absolute; inset: 0;
  background: rgba(108,92,231,0.15);
  display: none;
}
.preview-overlay.active { display: block; }

.scan-line {
  position: absolute;
  width: 100%; height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent-light), transparent);
  animation: scan 1.5s ease-in-out infinite;
}
@keyframes scan {
  0% { top: 0; }
  100% { top: 100%; }
}

.preview-status { color: var(--text-muted); margin-bottom: 1rem; font-size: 0.9rem; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 2rem;
  background: linear-gradient(135deg, var(--accent), #5a4bd1);
  color: white;
  border: none;
  border-radius: 50px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 20px rgba(108,92,231,0.4);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 28px rgba(108,92,231,0.5); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-arrow { font-size: 1.2rem; }

/* ── Visio Screen ── */
#visio-screen {
  flex-direction: column;
  background: var(--bg);
}

.visio-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.call-info { display: flex; align-items: center; gap: 0.6rem; }
.call-status-dot {
  width: 8px; height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.call-status-text { font-size: 0.85rem; color: var(--success); font-weight: 500; }
.call-timer { font-size: 0.85rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.call-title { font-size: 1rem; font-weight: 600; }

.visio-main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.video-panel {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f0f13;
  overflow: hidden;
}

.avatar-frame {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
}

.avatar-frame.hidden {
  display: none;
}

#avatar-image {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 200px);
  width: auto;
  height: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  object-fit: contain;
  transition: transform 0.08s ease-out, filter 0.08s ease-out;
}

.video-loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: #0f0f13;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.video-loading.hidden {
  display: none;
}

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.video-overlay {
  position: absolute;
  bottom: 1.5rem;
  left: 1.5rem;
}

.speaking-indicator { display: flex; align-items: center; gap: 0.5rem; }
.speaking-indicator.hidden { display: none; }

.sound-waves {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 24px;
}
.sound-waves span {
  display: block;
  width: 3px;
  background: var(--accent-light);
  border-radius: 2px;
  animation: wave 0.8s ease-in-out infinite;
}
.sound-waves span:nth-child(1) { animation-delay: 0s; height: 8px; }
.sound-waves span:nth-child(2) { animation-delay: 0.15s; height: 16px; }
.sound-waves span:nth-child(3) { animation-delay: 0.3s; height: 12px; }
.sound-waves span:nth-child(4) { animation-delay: 0.45s; height: 20px; }

@keyframes wave {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1.5); }
}

/* Chat Panel */
.chat-panel {
  width: 360px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid rgba(255,255,255,0.05);
  transition: width 0.3s, opacity 0.3s;
}
.chat-panel.collapsed {
  width: 0;
  opacity: 0;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.message {
  max-width: 85%;
  padding: 0.7rem 1rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.4;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}
.message.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border-bottom-left-radius: 4px;
}
.message.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
}

.chat-input-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.05);
}

.chat-input-area input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 24px;
  padding: 0.7rem 1rem;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}
.chat-input-area input:focus { border-color: var(--accent); }

.mic-btn, .send-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}
.mic-btn {
  background: var(--surface-2);
  color: var(--text-muted);
}
.mic-btn:hover { background: var(--accent); color: white; }
.mic-btn.listening {
  background: var(--danger);
  color: white;
  animation: pulse 1s infinite;
}

.send-btn {
  background: var(--accent);
  color: white;
}
.send-btn:hover { background: var(--accent-light); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.mic-hint {
  padding: 0 1rem 0.6rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

.mic-hint.hidden { display: none; }

/* Controls Bar */
.visio-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 1rem;
  background: var(--surface);
  border-top: 1px solid rgba(255,255,255,0.05);
}

.control-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}
.control-btn:hover { background: #333350; transform: scale(1.05); }
.control-btn.danger { background: var(--danger); }
.control-btn.danger:hover { background: #c0392b; }

/* Responsive */
@media (max-width: 768px) {
  .chat-panel { width: 100%; position: absolute; right: 0; top: 0; bottom: 80px; z-index: 10; }
  .chat-panel.collapsed { width: 0; }
}