/* ============================================
   Talk — Video Call Interface
   Aesthetic: Deep Space Noir
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300&family=Instrument+Serif:ital@0;1&display=swap');

/* --- Tokens --- */
:root {
  --bg-deep: #0a0a0f;
  --bg-surface: #12121a;
  --bg-elevated: #1a1a26;
  --bg-hover: #222233;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-focus: rgba(255, 255, 255, 0.12);

  --text-primary: #e8e6e3;
  --text-secondary: rgba(232, 230, 227, 0.55);
  --text-muted: rgba(232, 230, 227, 0.3);

  --accent: #c9a87c;
  --accent-glow: rgba(201, 168, 124, 0.15);
  --accent-hover: #ddbf98;

  --danger: #e05555;
  --danger-glow: rgba(224, 85, 85, 0.2);
  --danger-hover: #e87070;

  --success: #5ec269;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html, body {
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-deep);
  color: var(--text-primary);
  overflow: hidden;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }

/* --- Noise texture overlay --- */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

/* ============================================
   LANDING PAGE
   ============================================ */

.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  position: relative;
}

/* Ambient glow behind the card */
.landing::after {
  content: '';
  position: absolute;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: pulse-glow 8s ease-in-out infinite;
}

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

.landing-card {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3rem;
  animation: fade-up 800ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Logo */
.logo {
  text-align: center;
}

.logo-title {
  font-family: var(--font-display);
  font-size: clamp(3.5rem, 8vw, 5.5rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text-primary);
}

.logo-title em {
  font-style: italic;
  color: var(--accent);
}

.logo-sub {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  font-weight: 300;
  color: var(--text-secondary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Actions */
.landing-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  width: 100%;
  max-width: 340px;
}

.btn-create {
  width: 100%;
  padding: 1rem 2rem;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--bg-deep);
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: all var(--transition-smooth);
  position: relative;
  overflow: hidden;
}

.btn-create::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%);
  opacity: 0;
  transition: opacity var(--transition-smooth);
}

.btn-create:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 8px 30px var(--accent-glow);
}

.btn-create:hover::before { opacity: 1; }

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

.divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

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

.join-group {
  display: flex;
  width: 100%;
  gap: 0.5rem;
}

.input-room {
  flex: 1;
  padding: 0.85rem 1.2rem;
  font-size: 0.9rem;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  outline: none;
  transition: all var(--transition-fast);
}

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

.input-room:focus {
  border-color: var(--border-focus);
  background: var(--bg-elevated);
}

.btn-join {
  padding: 0.85rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-join:hover {
  background: var(--bg-hover);
  border-color: var(--border-focus);
}

/* ============================================
   ROOM PAGE
   ============================================ */

.room {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background: #000;
}

/* Remote video — fullscreen */
.video-remote-wrap {
  position: absolute;
  inset: 0;
  z-index: 1;
}

#remoteVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

/* Local video — PiP */
.video-local-wrap {
  position: absolute;
  bottom: 100px;
  right: 20px;
  width: 200px;
  aspect-ratio: 16/9;
  border-radius: var(--radius-md);
  overflow: hidden;
  z-index: 10;
  border: 2px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  transition: all var(--transition-smooth);
  cursor: grab;
}

.video-local-wrap:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

#localVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: var(--bg-surface);
}

/* Overlay states */
.room-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(20px);
  gap: 1.5rem;
  padding: 2rem;
  text-align: center;
  transition: opacity var(--transition-smooth);
}

.room-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.room-overlay h2 {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  font-weight: 400;
  color: var(--text-primary);
}

.room-overlay p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.6;
  max-width: 400px;
}

/* Waiting animation */
.waiting-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.waiting-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot-bounce 1.4s ease-in-out infinite;
}

.waiting-dots span:nth-child(2) { animation-delay: 0.2s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-bounce {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.2); }
}

/* Invite link box */
.invite-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem 0.6rem 1.2rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  max-width: 420px;
  width: 100%;
}

.invite-box input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  outline: none;
  min-width: 0;
}

.invite-box .btn-copy-invite {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-glow);
  border-radius: var(--radius-full);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.invite-box .btn-copy-invite:hover {
  background: rgba(201, 168, 124, 0.25);
}

/* Status toast */
.status-toast {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-60px);
  z-index: 20;
  padding: 0.6rem 1.4rem;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  backdrop-filter: blur(12px);
  opacity: 0;
  transition: all var(--transition-spring);
  pointer-events: none;
  white-space: nowrap;
}

.status-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Peer camera off placeholder */
.peer-avatar {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
}

.peer-avatar.visible {
  display: flex;
}

.peer-avatar-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
}

.peer-avatar-circle svg {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
}

/* Peer mic indicator */
.peer-mic-off {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 15;
  display: none;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  font-size: 0.75rem;
  color: var(--danger);
  background: rgba(224, 85, 85, 0.1);
  border-radius: var(--radius-full);
}

.peer-mic-off.visible {
  display: flex;
}

.peer-mic-off svg {
  width: 14px;
  height: 14px;
}

/* ============================================
   TOOLBAR
   ============================================ */

.toolbar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.25rem 1.5rem;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 100%);
}

.toolbar-btn {
  position: relative;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  transition: all var(--transition-fast);
}

.toolbar-btn svg {
  width: 22px;
  height: 22px;
  color: var(--text-primary);
  transition: color var(--transition-fast);
}

.toolbar-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-focus);
  transform: translateY(-2px);
}

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

/* Muted / off state */
.toolbar-btn.muted {
  background: var(--danger);
  border-color: var(--danger);
}

.toolbar-btn.muted:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.toolbar-btn.muted svg {
  color: #fff;
}

/* Active state (e.g., screen share active) */
.toolbar-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}

.toolbar-btn.active svg {
  color: var(--bg-deep);
}

.toolbar-btn.active:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* End call button */
.toolbar-btn.btn-end {
  background: var(--danger);
  border-color: var(--danger);
  width: 60px;
  height: 52px;
  border-radius: var(--radius-full);
}

.toolbar-btn.btn-end svg {
  color: #fff;
}

.toolbar-btn.btn-end:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  box-shadow: 0 4px 20px var(--danger-glow);
}

/* Tooltips */
.toolbar-btn[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 0.35rem 0.7rem;
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition-fast);
}

.toolbar-btn[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 640px) {
  .video-local-wrap {
    width: 130px;
    bottom: 90px;
    right: 12px;
  }

  .toolbar {
    padding: 1rem;
    gap: 0.4rem;
  }

  .toolbar-btn {
    width: 46px;
    height: 46px;
  }

  .toolbar-btn svg {
    width: 20px;
    height: 20px;
  }

  .toolbar-btn.btn-end {
    width: 54px;
    height: 46px;
  }

  .toolbar-btn[data-tooltip]::after {
    display: none;
  }

  .invite-box {
    flex-direction: column;
    border-radius: var(--radius-md);
    padding: 0.8rem;
  }

  .invite-box input {
    text-align: center;
    font-size: 0.8rem;
  }
}

/* ============================================
   UTILITY
   ============================================ */

.hidden { display: none !important; }

/* Fade-in animation for overlays */
.fade-in {
  animation: fade-in 400ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
