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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  /* Safe area for notched iPads */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ─── Status Overlay ─── */
#status-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

#status-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.status-content {
  text-align: center;
}

.portal-logo svg {
  animation: spin 8s linear infinite;
  margin-bottom: 24px;
}

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

#status-text {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.02em;
  margin-bottom: 8px;
}

#status-sub {
  font-size: 14px;
  opacity: 0.5;
}

/* ─── PIN Entry Screen ─── */
.pin-screen {
  width: 100%;
  max-width: 320px;
  padding: 0 24px;
}

.pin-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
}

.pin-sub {
  font-size: 14px;
  opacity: 0.5;
  margin-bottom: 24px;
}

.pin-display {
  font-size: 32px;
  letter-spacing: 8px;
  min-height: 44px;
  margin-bottom: 20px;
  text-align: center;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.pin-key {
  width: 100%;
  aspect-ratio: 1.4;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 24px;
  font-weight: 500;
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
}

.pin-key:active {
  background: rgba(255, 255, 255, 0.2);
}

.pin-connect {
  width: 100%;
  padding: 16px;
  border: none;
  background: #2563eb;
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s ease;
}

.pin-connect:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.pin-error {
  margin-top: 12px;
  font-size: 14px;
  color: #ef4444;
  min-height: 20px;
}

.room-link {
  display: block;
  margin-top: 20px;
  font-size: 14px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.65);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s ease;
}

.room-link:hover {
  color: #fff;
}

/* ─── Remote Video (Fullscreen) ─── */
#remote-video {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  background: #000;
}

/* ─── Local Video (PiP) ─── */
#local-video {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 120px;
  height: 160px;
  object-fit: cover;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  z-index: 20;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  /* Draggable hint */
  touch-action: none;
}

/* Hide local video until stream is active */
#local-video:not([srcObject]),
#local-video.hidden {
  display: none;
}

/* ─── Tap Zone & Reaction Bar ─── */
#tap-zone {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 25;
  display: flex;
  justify-content: center;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

#reaction-bar {
  display: flex;
  gap: 12px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 28px;
  padding: 8px 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.reaction-btn {
  width: 52px;
  height: 52px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.reaction-btn:active {
  transform: scale(0.85);
  background: rgba(255, 255, 255, 0.2);
}

/* ─── Connection Indicator ─── */
#connection-indicator {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: opacity 0.4s ease;
}

#connection-indicator.connected {
  opacity: 0;
  transition-delay: 3s;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
  transition: background 0.3s ease;
}

#connection-indicator.connected .dot {
  background: #22c55e;
}

#connection-indicator.error .dot {
  background: #ef4444;
}

/* ─── Audio Controls ─── */
#audio-controls {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  z-index: 40;
  display: flex;
  gap: 8px;
}

#audio-controls button {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 50%;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#mute-btn.muted,
#speaker-btn.muted {
  background: rgba(239, 68, 68, 0.6);
}

/* ─── Floating Reaction Animation ─── */
.floating-reaction {
  position: fixed;
  z-index: 35;
  font-size: 96px;
  pointer-events: none;
  animation: float-up 2.2s ease-out forwards;
}

@keyframes float-up {
  0% {
    opacity: 1;
    transform: translateY(0) scale(0.6);
  }
  15% {
    transform: translateY(-60px) scale(1.4);
  }
  100% {
    opacity: 0;
    transform: translateY(-400px) scale(1) rotate(15deg);
  }
}

/* ─── Pulse animation for incoming reactions ─── */
@keyframes pulse-border {
  0%, 100% { border-color: rgba(255, 255, 255, 0.2); }
  50% { border-color: rgba(239, 68, 100, 0.8); }
}

#remote-video.pulse {
  animation: pulse-border 0.5s ease;
}
