/**
 * Presence - Premium Video Call UI
 * 
 * Features:
 * - Glassmorphism design
 * - Animated gradient backgrounds
 * - Circular avatar with video overlay
 * - Smooth animations throughout
 */

:root {
  /* Colors */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: rgba(20, 20, 30, 0.8);
  --bg-glass: rgba(255, 255, 255, 0.03);
  --bg-glass-hover: rgba(255, 255, 255, 0.06);
  
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --text-muted: rgba(255, 255, 255, 0.4);
  
  --accent-primary: #6366f1;
  --accent-secondary: #8b5cf6;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-blue: #3b82f6;
  --accent-glow: rgba(99, 102, 241, 0.5);
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.12);
  
  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Playfair Display', Georgia, serif;
  
  /* Spacing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-full: 50%;
  
  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

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

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   DISCLAIMER
   ============================================ */

.disclaimer {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.disclaimer-dot {
  width: 6px;
  height: 6px;
  background: var(--accent-primary);
  border-radius: 50%;
  animation: pulse 2s ease infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

/* ============================================
   SCREENS
   ============================================ */

#app { height: 100%; }
.screen { display: none; height: 100%; position: relative; }
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ============================================
   SETUP SCREEN
   ============================================ */

#setup-screen {
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* Animated background orbs */
.setup-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.gradient-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.5;
  animation: float 20s ease-in-out infinite;
}

.orb-1 {
  width: 400px;
  height: 400px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  top: -100px;
  right: -100px;
  animation-delay: 0s;
}

.orb-2 {
  width: 300px;
  height: 300px;
  background: linear-gradient(135deg, #06b6d4, var(--accent-blue));
  bottom: -50px;
  left: -50px;
  animation-delay: -7s;
}

.orb-3 {
  width: 250px;
  height: 250px;
  background: linear-gradient(135deg, var(--accent-secondary), #ec4899);
  top: 50%;
  left: 50%;
  animation-delay: -14s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(30px, -30px) scale(1.1); }
  50% { transform: translate(-20px, 20px) scale(0.9); }
  75% { transform: translate(20px, 30px) scale(1.05); }
}

.setup-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  animation: fadeUp 0.8s var(--ease-out);
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.setup-card {
  background: var(--bg-card);
  backdrop-filter: blur(40px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 40px;
  box-shadow: 
    0 0 0 1px rgba(255,255,255,0.05) inset,
    0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* Brand */
.brand {
  text-align: center;
  margin-bottom: 36px;
}

.brand-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px var(--accent-glow);
}

.brand-icon svg {
  width: 28px;
  height: 28px;
  color: white;
}

.brand h1 {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.brand p {
  font-size: 15px;
  color: var(--text-secondary);
}

/* Photo Upload */
.photo-section {
  margin-bottom: 28px;
}

.photo-upload {
  display: block;
  width: 140px;
  height: 140px;
  margin: 0 auto;
  border-radius: var(--radius-full);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.3s var(--ease-out);
}

.photo-upload:hover {
  transform: scale(1.03);
}

.photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-glass);
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-full);
  transition: all 0.3s ease;
}

.photo-upload:hover .photo-placeholder {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.1);
}

.photo-icon {
  width: 36px;
  height: 36px;
  color: var(--text-muted);
}

.photo-placeholder span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.photo-placeholder small {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding: 0 16px;
}

.photo-preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-full);
}

.photo-upload.has-photo .photo-placeholder {
  display: none;
}

.photo-upload.has-photo {
  border: 3px solid var(--accent-green);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
}

/* Form Fields */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.field {
  margin-bottom: 16px;
}

.form-grid .field {
  margin-bottom: 0;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.field .optional {
  font-weight: 400;
  color: var(--text-muted);
}

.field input,
.field select {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  transition: all 0.2s ease;
}

.field select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 12px;
}

.field input::placeholder {
  color: var(--text-muted);
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.1);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}

.select-wrapper {
  position: relative;
}

.select-wrapper select {
  appearance: none;
  cursor: pointer;
  padding-right: 40px;
}

.select-arrow {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

/* Advanced Section */
.advanced-section {
  margin: 24px 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.advanced-section summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
  font-size: 14px;
  color: var(--text-secondary);
  transition: background 0.2s;
}

.advanced-section summary::-webkit-details-marker {
  display: none;
}

.advanced-section summary:hover {
  background: var(--bg-glass);
}

.advanced-section summary svg {
  width: 18px;
  height: 18px;
}

.advanced-section summary .chevron {
  margin-left: auto;
  transition: transform 0.3s var(--ease-out);
}

.advanced-section[open] summary .chevron {
  transform: rotate(180deg);
}

.advanced-content {
  padding: 16px;
  border-top: 1px solid var(--border-subtle);
}

.advanced-content p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

.advanced-content input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: monospace;
  font-size: 13px;
}

/* Start Button */
.start-btn {
  width: 100%;
  position: relative;
  padding: 18px 24px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  overflow: hidden;
  transition: all 0.3s var(--ease-out);
}

.start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px var(--accent-glow);
}

.start-btn:active {
  transform: translateY(0);
}

.btn-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: relative;
  z-index: 1;
}

.btn-content svg {
  width: 22px;
  height: 22px;
}

.btn-content span {
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 600;
  color: white;
}

.btn-shine {
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  animation: shine 3s ease infinite;
}

@keyframes shine {
  0%, 100% { left: -100%; }
  50% { left: 100%; }
}

/* Privacy Note */
.privacy-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-muted);
}

.privacy-note svg {
  width: 14px;
  height: 14px;
}

/* ============================================
   CALL SCREEN
   ============================================ */

#call-screen {
  flex-direction: column;
  background: var(--bg-primary);
}

.call-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ambient-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  opacity: 0.3;
  animation: ambientPulse 8s ease-in-out infinite;
}

@keyframes ambientPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.3; }
  50% { transform: translate(-50%, -50%) scale(1.2); opacity: 0.2; }
}

.call-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

/* Call Header */
.call-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  padding-top: 60px;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 100px;
}

.header-right {
  justify-content: flex-end;
}

.signal-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

.signal-bars span {
  width: 3px;
  background: var(--accent-green);
  border-radius: 1px;
}

.signal-bars span:nth-child(1) { height: 4px; }
.signal-bars span:nth-child(2) { height: 7px; }
.signal-bars span:nth-child(3) { height: 10px; }
.signal-bars span:nth-child(4) { height: 14px; }

.connection-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent-green);
}

.header-center {
  text-align: center;
}

.caller-name {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 500;
}

.call-timer {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* Avatar Section */
.avatar-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.avatar-container {
  position: relative;
  width: 220px;
  height: 220px;
}

@media (min-height: 750px) {
  .avatar-container {
    width: 280px;
    height: 280px;
  }
}

.avatar-img,
.avatar-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-full);
  object-fit: cover;
}

.avatar-img {
  z-index: 1;
}

.avatar-video {
  z-index: 2;
  background: var(--bg-secondary);
}

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

.avatar-glow {
  position: absolute;
  inset: -20px;
  border-radius: var(--radius-full);
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  opacity: 0.5;
  z-index: 0;
  animation: glowPulse 4s ease-in-out infinite;
}

@keyframes glowPulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 0.3; transform: scale(1.1); }
}

.speaking-ring {
  position: absolute;
  inset: -8px;
  border-radius: var(--radius-full);
  border: 3px solid var(--accent-green);
  opacity: 0;
  z-index: 3;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.speaking-ring.active {
  opacity: 1;
  animation: speakRing 1.5s ease-out infinite;
}

@keyframes speakRing {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}

.avatar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding: 8px 16px;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: 100px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--accent-green);
  border-radius: 50%;
  animation: pulse 2s ease infinite;
}

/* Captions */
.captions-wrapper {
  padding: 0 24px;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.captions {
  max-width: 500px;
  padding: 16px 24px;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  font-size: 15px;
  line-height: 1.6;
  text-align: center;
  color: var(--text-primary);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s var(--ease-out);
}

.captions.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Self View */
.self-view {
  position: absolute;
  top: 100px;
  right: 20px;
  width: 100px;
  height: 140px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-secondary);
  border: 2px solid var(--border-subtle);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.self-view video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.self-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  color: var(--text-muted);
}

.self-placeholder svg {
  width: 32px;
  height: 32px;
}

.self-view.has-video .self-placeholder {
  display: none;
}

/* Controls */
.controls-section {
  padding: 24px;
  padding-bottom: 40px;
}

.controls-bar {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 12px;
}

.ctrl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  transition: transform 0.2s var(--ease-out);
}

.ctrl-btn:hover {
  transform: scale(1.05);
}

.ctrl-btn:active {
  transform: scale(0.95);
}

.ctrl-icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  transition: all 0.2s ease;
}

.ctrl-icon svg {
  width: 24px;
  height: 24px;
  color: var(--text-primary);
}

.ctrl-icon .icon-off {
  display: none;
}

.ctrl-btn.muted .icon-on,
.ctrl-btn.off .icon-on {
  display: none;
}

.ctrl-btn.muted .icon-off,
.ctrl-btn.off .icon-off {
  display: block;
}

.ctrl-btn.muted .ctrl-icon,
.ctrl-btn.off .ctrl-icon {
  background: var(--accent-red);
  border-color: var(--accent-red);
}

.ctrl-btn span {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Speak button */
.speak-btn .ctrl-icon {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none;
}

.speak-btn .ctrl-icon svg {
  width: 28px;
  height: 28px;
  color: white;
}

.speak-btn.listening .ctrl-icon {
  background: linear-gradient(135deg, var(--accent-green), #059669);
  animation: listenPulse 1s ease infinite;
}

@keyframes listenPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  50% { box-shadow: 0 0 0 16px rgba(16, 185, 129, 0); }
}

/* End button */
.end-btn .ctrl-icon {
  background: var(--accent-red);
  border-color: var(--accent-red);
}

.end-btn .ctrl-icon svg {
  color: white;
}

/* Chat Panel */
.chat-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 55%;
  background: var(--bg-card);
  backdrop-filter: blur(40px);
  border-top: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  animation: slideUp 0.3s var(--ease-out);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
}

.chat-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.chat-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-glass);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.chat-close:hover {
  background: var(--bg-glass-hover);
  color: var(--text-primary);
}

.chat-close svg {
  width: 18px;
  height: 18px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.5;
  animation: msgIn 0.2s var(--ease-out);
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
}

.chat-message.ai {
  align-self: flex-start;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
}

.chat-form {
  display: flex;
  gap: 12px;
  padding: 16px 24px 32px;
  border-top: 1px solid var(--border-subtle);
}

.chat-form input {
  flex: 1;
  padding: 14px 18px;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: 100px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
}

.chat-form input::placeholder {
  color: var(--text-muted);
}

.chat-form input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.chat-form button {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: transform 0.2s;
}

.chat-form button:hover {
  transform: scale(1.05);
}

.chat-form button svg {
  width: 20px;
  height: 20px;
  color: white;
}

/* Responsive */
@media (max-width: 480px) {
  .setup-card {
    padding: 28px 24px;
  }
  
  .avatar-container {
    width: 180px;
    height: 180px;
  }
  
  .controls-bar {
    gap: 8px;
  }
  
  .ctrl-icon {
    width: 50px;
    height: 50px;
  }
  
  .speak-btn .ctrl-icon {
    width: 64px;
    height: 64px;
  }
  
  .self-view {
    width: 80px;
    height: 110px;
    top: 80px;
    right: 12px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
