/* DuoMeet Friend Page -- Mobile-first, dark theme */

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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-surface: #0f3460;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0b8;
  --accent: #4a9eff;
  --accent-dim: rgba(74, 158, 255, 0.3);
  --error-red: #e74c3c;
  --success-green: #2ecc71;
  --status-bar-bg: rgba(26, 26, 46, 0.85);
  --pip-border: rgba(255, 255, 255, 0.15);
  --transition-speed: 0.3s;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* -- Screen containers -- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-speed) ease, visibility var(--transition-speed) ease;
  /* Safe area insets for notched phones */
  padding:
    env(safe-area-inset-top, 0)
    env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0)
    env(safe-area-inset-left, 0);
}

.screen.active {
  opacity: 1;
  visibility: visible;
}

/* -- Connection / Waiting screens -- */

.connecting-content,
.error-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px;
  max-width: 400px;
  width: 100%;
}

.logo {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.status-text {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}

/* Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--accent-dim);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 32px;
}

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

/* Pulse ring for waiting state */
.pulse-ring {
  width: 48px;
  height: 48px;
  border: 3px solid var(--accent);
  border-radius: 50%;
  animation: pulse 1.8s ease-in-out infinite;
  margin-bottom: 32px;
}

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

/* Camera preview on connection/waiting screens */
#preview-video,
#waiting-preview {
  width: 200px;
  height: 150px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--bg-secondary);
  border: 1px solid var(--pip-border);
  transform: scaleX(-1); /* Mirror self-view */
}

/* -- Active screen -- */

#screen-active {
  background: #000;
  padding: 0;
}

/* Status bar */
.status-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top, 0));
  background: var(--status-bar-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 13px;
  color: var(--text-secondary);
  transition: opacity var(--transition-speed) ease;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.connected {
  background: var(--success-green);
  box-shadow: 0 0 6px var(--success-green);
}

.status-dot.reconnecting {
  background: #f39c12;
  animation: blink 1s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Stranger video - fills the screen */
#stranger-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

/* PIP containers -- shared base */
.pip-container {
  position: absolute;
  bottom: calc(24px + env(safe-area-inset-bottom, 0));
  z-index: 20;
  /* Match the split-screen slot aspect ratio (roughly 9:16 portrait) */
  width: 90px;
  height: 160px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--pip-border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  background: var(--bg-secondary);
}

/* Host camera PIP -- bottom-left */
.pip-left {
  left: calc(16px + env(safe-area-inset-left, 0));
  display: none; /* Hidden by default; shown when stranger is active */
}

/* Self camera PIP -- bottom-right */
.pip-right {
  right: calc(16px + env(safe-area-inset-right, 0));
}

#host-video,
#self-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#self-video {
  transform: scaleX(-1); /* Mirror self-view */
}

/* -- Error screen -- */

.error-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid var(--error-red);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  color: var(--error-red);
  margin-bottom: 20px;
}

.error-text {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  line-height: 1.4;
}

.error-detail {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}

.btn-retry {
  appearance: none;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  padding: 14px 32px;
  border-radius: 10px;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  transition: background 0.2s ease, transform 0.1s ease;
  font-family: inherit;
}

.btn-retry:hover {
  background: #3b8bef;
}

.btn-retry:active {
  transform: scale(0.97);
}

/* -- Desktop breakpoint -- */

@media (min-width: 768px) {
  .logo {
    font-size: 40px;
  }

  #preview-video,
  #waiting-preview {
    width: 280px;
    height: 210px;
  }

  #screen-active {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #stranger-video {
    position: relative;
    inset: auto;
    max-width: 960px;
    max-height: 720px;
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    border-radius: 12px;
    object-fit: cover;
  }

  .pip-container {
    width: 120px;
    height: 214px;
    bottom: 32px;
    border-radius: 16px;
  }

  .pip-left {
    left: 32px;
  }

  .pip-right {
    right: 32px;
  }

  .status-bar {
    border-radius: 0 0 8px 8px;
    max-width: 960px;
    margin: 0 auto;
    left: 50%;
    transform: translateX(-50%);
    right: auto;
    padding: 10px 20px;
  }
}

/* -- Landscape on mobile -- */

@media (max-width: 767px) and (orientation: landscape) {
  .pip-container {
    width: 50px;
    height: 90px;
    bottom: 12px;
    border-radius: 8px;
  }

  .pip-left {
    left: 12px;
  }

  .pip-right {
    right: 12px;
  }

  .connecting-content,
  .error-content {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
  }

  .logo {
    width: 100%;
    margin-bottom: 8px;
    font-size: 24px;
  }

  #preview-video,
  #waiting-preview {
    width: 160px;
    height: 120px;
  }
}
