*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --royal-blue: #2563eb;
  --royal-blue-dark: #1d4ed8;
  --logo-glow: rgba(59, 130, 246, 0.5);
  --glass-bg: rgba(15, 23, 42, 0.8);
  --dark-grey: #1e293b;
  --dark-grey-bg: #020617;
  --charcoal: #111;
  --charcoal-light: #222;
  --text-primary: #e5e7eb;
  --text-muted: #9ca3af;
  --border-subtle: rgba(148, 163, 184, 0.3);
  --green-pulse: #22c55e;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  background: #000;
  color: var(--text-primary);
  overflow: hidden;
}

.app {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #000;
}

/* --- 50/50 split: exact viewport halves --- */
.video-grid {
  position: relative;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

#stranger-container,
.stranger-half {
  height: 100vh;
  width: 100vw;
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
  z-index: 1;
}

/* Movable PIP: user self-view — draggable, stays within viewport */
#local-container,
.local-half {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 110px;
  aspect-ratio: 3 / 4;
  background: #000;
  overflow: hidden;
  z-index: 1000;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(148, 163, 184, 0.45);
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  transition: left 0.16s ease, top 0.16s ease, right 0.16s ease, bottom 0.16s ease;
}

#local-container.pip-dragging,
.local-half.pip-dragging {
  cursor: grabbing;
  transition: none;
}

/* When PIP is positioned by drag/snap we use left/top instead of bottom/right */
#local-container.pip-positioned,
.local-half.pip-positioned {
  right: auto;
  bottom: auto;
}

/* Blurred placeholder in bottom half while camera is initializing */
.local-placeholder {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.app.camera-initializing .local-placeholder {
  opacity: 1;
}

/* --- Video scaling --- */
#remoteVideo,
#localVideo,
video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

#remoteVideo {
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease-in;
}

.app.has-remote #remoteVideo {
  opacity: 1;
}

#localVideo {
  transform: scaleX(-1);
  border-radius: 12px;
  z-index: 120;
  touch-action: none; /* prevent page scroll while dragging PIP */
}

/* --- No Signal overlay (stranger half when no peer) --- */
.no-signal-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.no-signal-overlay > * {
  pointer-events: none;
}

/* Classic TV static: noise overlay */
.tv-static {
  position: absolute;
  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='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  opacity: 0.15;
  mix-blend-mode: overlay;
  animation: staticFlicker 0.15s steps(3) infinite;
}

@keyframes staticFlicker {
  0% { opacity: 0.12; transform: translate(0, 0); }
  33% { opacity: 0.18; transform: translate(-2px, 1px); }
  66% { opacity: 0.14; transform: translate(1px, -2px); }
  100% { opacity: 0.16; transform: translate(-1px, -1px); }
}

/* Hide static when we have remote video */
.app.has-remote .no-signal-overlay .tv-static {
  opacity: 0;
  animation: none;
}

/* No static on landing — only show when searching (searching-overlay handles that) */
body:not(.is-searching):not(.is-connected) .no-signal-overlay .tv-static {
  opacity: 0;
  pointer-events: none;
}

/* --- Global "Searching" static overlay: hidden on landing, only when swiping to match --- */
.searching-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background-color: #000;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='5' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-size: 220px 220px;
  mix-blend-mode: normal;
  animation: searchingStaticShift 0.18s steps(4) infinite;
  z-index: 8;
  pointer-events: none;
  transition: opacity 0.15s ease-out;
}

.searching-overlay-text {
  position: relative;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #ffffff;
  text-shadow:
    0 0 8px rgba(255, 255, 255, 0.7),
    0 0 18px rgba(59, 130, 246, 0.45),
    0 0 30px rgba(59, 130, 246, 0.4);
  padding: 10px 22px;
  border-radius: 999px;
  background: radial-gradient(circle at 20% 0%, rgba(255, 255, 255, 0.08), transparent 55%),
              radial-gradient(circle at 80% 100%, rgba(59, 130, 246, 0.18), transparent 60%);
  box-shadow: 0 0 26px rgba(15, 23, 42, 0.9);
  animation: searchingTextFlicker 0.12s steps(2) infinite;
}

@keyframes searchingTextFlicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

@keyframes searchingStaticShift {
  0% {
    transform: translate(0, 0);
    opacity: 0.7;
  }
  33% {
    transform: translate(-3px, 2px);
    opacity: 0.85;
  }
  66% {
    transform: translate(2px, -3px);
    opacity: 0.75;
  }
  100% {
    transform: translate(-1px, -1px);
    opacity: 0.8;
  }
}

/* Show overlay only when body has .is-searching (swipe-to-match / re-queue); hide when connected */
body.is-searching .searching-overlay {
  display: flex;
  opacity: 1;
}

body.is-connected .searching-overlay {
  display: none !important;
}

/* --- Landing hero: centered vertical stack (logo, I AM, COUNTRY, swipe hint) --- */
.landing-stack {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 70;
  pointer-events: auto;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.landing-stack > * {
  margin-bottom: 20px;
}

.landing-stack > *:last-child {
  margin-bottom: 0;
}

/* Static "Swipe left to start" text — no animation */
.swipe-hint {
  margin: 0;
  text-align: center;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 600;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
}

#main-logo {
  display: block;
  width: 100%;
  max-width: 180px;
  height: auto;
}

.logo-block {
  padding: 14px 32px 12px;
  border-radius: 20px;
  background: var(--glass-bg);
  border: 1px solid rgba(59, 130, 246, 0.4);
  box-shadow: 0 0 16px var(--logo-glow), 0 0 32px rgba(59, 130, 246, 0.2);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* .logo-main removed (replaced by #main-logo image) */

.users-online-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px 10px;
  border-radius: 999px;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green-pulse);
  box-shadow: 0 0 10px var(--green-pulse), 0 0 16px rgba(34, 197, 94, 0.5);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.85; transform: scale(1.15); }
}

.online-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.online-count {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
}

.network-quality-indicator {
  position: relative;
  width: 16px;
  height: 16px;
  margin-left: 6px;
  border-radius: 999px;
  border: 2px solid rgba(148, 163, 184, 0.6);
  box-shadow: 0 0 0 0 rgba(148, 163, 184, 0.4);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.network-quality-indicator::after {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: inherit;
  background: radial-gradient(circle at 30% 30%, #e5e7eb, transparent 60%);
  opacity: 0.9;
}

.network-quality-indicator.quality-good {
  border-color: #22c55e;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  animation: qualityPulseGood 1.8s ease-out infinite;
}

.network-quality-indicator.quality-ok {
  border-color: #eab308;
  box-shadow: 0 0 0 0 rgba(234, 179, 8, 0.6);
  animation: qualityPulseOk 2s ease-out infinite;
}

.network-quality-indicator.quality-poor {
  border-color: #f97316;
  box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.7);
  animation: qualityPulsePoor 1.5s ease-out infinite;
}

@keyframes qualityPulseGood {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

@keyframes qualityPulseOk {
  0% {
    box-shadow: 0 0 0 0 rgba(234, 179, 8, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(234, 179, 8, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(234, 179, 8, 0);
  }
}

@keyframes qualityPulsePoor {
  0% {
    box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.8);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(249, 115, 22, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(249, 115, 22, 0);
  }
}

/* (Marquee/swipe CTA removed — static .swipe-hint inside .landing-stack) */

/* --- Status banner (over static) — shown when JS sets a message --- */
.status-banner {
  position: absolute;
  bottom: 20%;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 24px;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  white-space: nowrap;
  z-index: 10;
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.status-banner.is-visible {
  opacity: 1;
  visibility: visible;
}

.status-banner.status-success {
  color: #22c55e;
}

.status-banner.status-denied {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(30, 27, 27, 0.9);
}

/* --- Report button (visible when connected) --- */
.stranger-corner-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 100;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: none;
  background: rgba(15, 23, 42, 0.85);
  color: #e5e7eb;
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease, transform 0.1s ease, background 0.15s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.icon-btn:hover {
  transform: translateY(-1px) scale(1.02);
  background: rgba(30, 64, 175, 0.9);
}

.icon-btn-danger {
  background: rgba(239, 68, 68, 0.9);
}

.icon-btn-danger:hover {
  background: rgba(220, 38, 38, 0.95);
}

.app.has-remote .icon-btn {
  opacity: 1;
  visibility: visible;
}

/* --- Local overlay: country panel + reaction row --- */
.local-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.local-overlay > * {
  pointer-events: none;
}

/* --- Top overlay: Users Online (fixed top-left), Data Saver (fixed top-right) --- */
.top-controls {
  position: relative;
  width: 0;
  height: 0;
  z-index: 110;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.top-controls-left {
  position: fixed;
  top: 20px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
}

.top-controls-right {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
}

/* When match is found (body.is-chatting): corner indicators stay visible at 0.5 opacity */
body.is-chatting .top-controls,
body.is-chatting .top-controls-left,
body.is-chatting .top-controls-right {
  opacity: 0.5;
}

/* Vanish: hide logo, buttons, and swipe hint when match is found or searching */
body.is-chatting .landing-stack,
body.is-searching .landing-stack {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* Fallback when .app gets chat-mode-active (no body class) */
.app.chat-mode-active .top-controls,
.app.chat-mode-active .top-controls-left,
.app.chat-mode-active .top-controls-right {
  opacity: 0.5;
}

.app.chat-mode-active .landing-stack {
  opacity: 0;
  pointer-events: none;
}

/* --- Zero-UI / Total immersion (Ghost UI): hide all chrome when connected --- */
body.is-connected #main-logo,
body.is-connected #users-online-container,
body.is-connected #data-saver-container,
body.is-connected #iamBtn,
body.is-connected #countryBtn,
body.is-connected .swipe-cta,
body.is-connected .swipe-hint,
body.is-connected #landing-hero,
body.is-connected .landing-stack {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.4s ease-in-out;
}

.choice-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 28px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: white;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.choice-btn-glass {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.choice-btn:hover {
  transform: scale(1.02);
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.4);
}

.choice-label {
  letter-spacing: 0.06em;
}

.choice-emoji {
  font-size: 1.25rem;
}

.choice-country-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Toggle: Data Saver --- */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 0.8rem;
  color: var(--text-primary);
}

.toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-track {
  position: relative;
  width: 42px;
  height: 22px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.7);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.9);
  transition: background 0.18s ease, border-color 0.18s ease;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #e5e7eb;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  transition: transform 0.18s ease;
}

.toggle input:checked + .toggle-track {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  border-color: rgba(34, 197, 94, 0.9);
}

.toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(18px);
}

.toggle-label {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* --- Country overlay (refined) --- */
.country-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  pointer-events: none;
}

.country-overlay.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.country-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.country-overlay-panel {
  position: relative;
  width: 90%;
  max-width: 340px;
  padding: 24px;
  border-radius: 20px;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}

.country-overlay-title {
  margin: 0 0 16px;
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-primary);
}

.country-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.country-item {
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s ease;
}

.country-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* --- Reaction row: bottom, visible during chat --- */
.reaction-row {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 20;
  pointer-events: auto;
}

.reaction-emoji {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-bg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform 0.15s ease, background 0.15s ease;
}

.reaction-emoji:hover {
  transform: scale(1.1);
  background: rgba(255, 255, 255, 0.15);
}

/* --- Swipe feedback --- */
.swipe-feedback {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 16px 28px;
  border-radius: 24px;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  font-size: 0.9rem;
  font-weight: 600;
  color: #fff;
  z-index: 150;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.swipe-feedback.is-visible {
  opacity: 1;
  visibility: visible;
}

/* (Legacy .swipe-cta-track removed — swipe hint is inside .landing-stack) */

.app.chat-active .no-signal-overlay .status-banner {
  display: none;
}

/* --- Swipe target: ensure #stranger-container receives touch --- */
#stranger-container {
  touch-action: pan-y;
}

/* Transition state: solid black so user never sees frozen frame of previous stranger */
#stranger-container.is-transitioning {
  background-color: #000;
}
#stranger-container.is-transitioning #remoteVideo {
  opacity: 0;
}

/* --- Swipe transition for remote panel --- */
.app.swipe-next #stranger-container {
  animation: swipeOutIn 260ms ease-in-out;
}

@keyframes swipeOutIn {
  0% {
    transform: translateX(0);
    opacity: 1;
  }
  40% {
    transform: translateX(-60px);
    opacity: 0;
  }
  60% {
    transform: translateX(40px);
    opacity: 0;
  }
  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

/* --- Mobile --- */
@media (max-width: 900px) {
  .status-banner {
    white-space: normal;
    max-width: 85%;
  }
  #local-container,
  .local-half {
    width: 110px;
  }
  .top-controls-left {
    top: 20px;
    left: 20px;
  }
  .top-controls-right {
    top: 20px;
    right: 20px;
  }
}

/* --- Desktop wide: slightly larger PiP --- */
@media (min-width: 1200px) {
  #local-container,
  .local-half {
    width: 140px;
  }
}
