:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --text: #e8eaf0;
  --muted: #9aa1ae;
  --accent: #5b8cff;
  --danger: #ff5b6e;
  --border: #2a2f3a;
  --green: #22c08a;
  --green-dark: #189068;
  --light-bg: #ffffff;
  --light-surface: #eef0f3;
  --light-text: #1a1c22;
  --light-muted: #6b7280;
  --blue: #3b6fd6;
  --blue-dark: #2f59ad;
  --pink: #f3a6ac;
  --pink-dark: #ea7883;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  /* 100% first as a fallback for browsers without dvh; 100dvh (where
     supported) tracks the *actual* visible viewport on mobile, which
     100%/100vh don't — those are based on the layout viewport assuming the
     browser's address bar is hidden, so the real page ends up taller than
     what's visible and the whole app becomes scrollable ("sliding") as the
     address bar shows/hides. overflow: hidden below is the other half of
     the fix: this is a fixed, app-like screen, not a scrolling page. */
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }

/* ---------- Gate ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  padding: 16px;
  z-index: 50;
}

.gate-card {
  display: flex;
  width: 100%;
  max-width: 920px;
  height: 560px;
  max-height: 90vh;
  background: var(--panel);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
}

.gate-video-pane {
  position: relative;
  flex: 1 1 45%;
  background: #000;
  min-height: 320px;
}
.gate-video-pane .bg-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gate-logo {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 90px;
  width: auto;
  filter: drop-shadow(0 4px 16px rgba(0,0,0,.5));
}

.gate-form-pane {
  flex: 1 1 55%;
  background: #fff;
  color: #1a1c22;
  padding: 36px 34px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.gate-form-pane h1 { margin: 0 0 6px; font-size: 26px; }
.gate-form-pane .tagline { margin: 0 0 22px; color: #6b7280; font-size: 14px; }

.social-buttons { display: flex; flex-direction: column; gap: 10px; }
.social-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid #e3e5ea;
  background: #fff;
  color: #1a1c22;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.social-btn.fb { background: #1877f2; border-color: #1877f2; color: #fff; }
.social-btn:disabled { cursor: not-allowed; }

.social-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 800;
  background: rgba(255,255,255,.25);
}
.social-icon.google {
  background: #fff;
  color: #4285F4;
  border: 1px solid #e3e5ea;
}

.social-note {
  margin: 10px 0 0;
  font-size: 12px;
  color: #9aa0ab;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0;
  color: #b7bcc5;
  font-size: 12px;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e3e5ea;
}

.age-statement {
  font-size: 13px;
  color: #6b7280;
  margin: 0 0 14px;
  line-height: 1.5;
}
.age-statement a { color: var(--accent); }

#gate-enter, .primary {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: #e0253d;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
#gate-enter:disabled { opacity: .4; cursor: not-allowed; }
#gate-enter:hover:not(:disabled) { background: #c01f33; }

@media (max-width: 700px) {
  .gate-card { flex-direction: column; height: auto; max-height: 95vh; overflow-y: auto; }
  .gate-video-pane { height: 180px; flex: none; }
}

/* ---------- Main app ---------- */
#app { display: flex; flex-direction: column; height: 100%; height: 100dvh; }

/* Two independent columns: each is its own video pane stacked on top of its
   own footer (controls on the left, chat on the right) — not two full-width
   rows. */
main.columns {
  flex: 1;
  display: flex;
  gap: 2px;
  background: var(--border);
  min-height: 0;
}

.col {
  flex: 1 1 50%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.pane {
  position: relative;
  flex: 1;
  background: #000;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.pane video {
  /* Absolutely positioned (not just width/height: 100%) so the video's own
     intrinsic aspect ratio can never feed into the flex height calculation
     for .col/.pane above — that's what was making the two panes unequal
     once a real camera stream (with real intrinsic dimensions) was
     playing, a case this project's own testing can't reach since this
     environment's browser blocks real camera access. */
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
}

/* Animated TV-static placeholder shown before the camera stream starts —
   same asset used on the stranger pane, so both idle screens genuinely
   look like static instead of a barely-visible CSS gradient. */
.noise-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: .5;
}

/* Animated 8-dot "loading" spinner — used as the stranger pane's idle
   background on phones and as the "Accessing camera…" indicator. Built in
   CSS (not a gif) so it's crisp, lightweight and genuinely animates. */
.dot-spinner {
  position: relative;
  width: 48px;
  height: 48px;
}
.dot-spinner .dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: #fff;
  animation: dot-spin-fade 1s linear infinite;
}
.dot-spinner .dot:nth-child(1) { transform: rotate(0deg) translateY(-18px); animation-delay: -1s; }
.dot-spinner .dot:nth-child(2) { transform: rotate(45deg) translateY(-18px); animation-delay: -0.875s; }
.dot-spinner .dot:nth-child(3) { transform: rotate(90deg) translateY(-18px); animation-delay: -0.75s; }
.dot-spinner .dot:nth-child(4) { transform: rotate(135deg) translateY(-18px); animation-delay: -0.625s; }
.dot-spinner .dot:nth-child(5) { transform: rotate(180deg) translateY(-18px); animation-delay: -0.5s; }
.dot-spinner .dot:nth-child(6) { transform: rotate(225deg) translateY(-18px); animation-delay: -0.375s; }
.dot-spinner .dot:nth-child(7) { transform: rotate(270deg) translateY(-18px); animation-delay: -0.25s; }
.dot-spinner .dot:nth-child(8) { transform: rotate(315deg) translateY(-18px); animation-delay: -0.125s; }
@keyframes dot-spin-fade {
  0%, 100% { opacity: 1; }
  50% { opacity: .15; }
}

/* Stranger pane's idle background on every screen size. Scaled up from the
   base 48px spinner. */
.remote-loading-bg {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1.9);
  z-index: 0;
}
.pane.has-stream .remote-loading-bg { display: none !important; }

.connecting-indicator {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.connecting-indicator span { color: rgba(255,255,255,.7); font-size: 13px; }
#pane-local.connecting .pane-logo { display: none; }
#pane-local.connecting .connecting-indicator { display: flex; }

.pane-logo {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  text-align: center;
  pointer-events: none;
}
.pane-logo-img {
  width: clamp(140px, 30vw, 220px);
  height: auto;
  opacity: .92;
  filter: drop-shadow(0 4px 14px rgba(0,0,0,.4));
}
.pane-logo-tag {
  margin-top: 6px;
  font-size: 13px;
  color: rgba(255,255,255,.4);
}
.online-pill {
  margin-top: 18px;
  font-size: 13px;
  color: rgba(255,255,255,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

#pane-local.has-stream .noise-bg,
#pane-local.has-stream .pane-logo {
  display: none;
}

.pane-mini-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: flex;
  gap: 8px;
}
.mini-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(23,26,33,.7);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mini-btn svg { width: 16px; height: 16px; }
.mini-btn.danger { border-color: #4a2630; }
.mini-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---- Phone-only elements: all hidden here, switched on in the mobile
   media query at the bottom of this file. ---- */
.mobile-pane-label {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  background: rgba(20,22,27,.7);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.mobile-icon-stack {
  display: none;
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  flex-direction: column;
  gap: 12px;
}
.stack-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: rgba(20,22,27,.75);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stack-btn svg { width: 19px; height: 19px; }
.stack-btn:disabled { opacity: .35; cursor: not-allowed; }
.stack-btn.is-open { background: var(--accent); }

.mobile-call-row {
  display: none;
  gap: 10px;
}
/* Bordered, semi-transparent pills — same visual language as the
   Country/"I am" tiles they replace on phones. */
.mobile-pill {
  flex: 1;
  border-radius: 10px;
  padding: 12px 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1.5px solid rgba(255,255,255,.55);
  background: rgba(20,22,27,.55);
  color: #fff;
}
.mobile-pill-stop { color: #ff8a93; border-color: rgba(255,138,147,.7); display: none; }
.mobile-pill-next { display: none; }
.mobile-call-row.is-active .mobile-pill-start { display: none; }
.mobile-call-row.is-active .mobile-pill-stop,
.mobile-call-row.is-active .mobile-pill-next { display: flex; }

.mobile-top-bar {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 2;
  align-items: center;
  justify-content: space-between;
}
.country-pill {
  background: rgba(20,22,27,.7);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.country-pill .pill-sep { opacity: .5; }
.mobile-top-icons { display: flex; gap: 8px; }
.top-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  background: rgba(20,22,27,.7);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.top-icon-btn svg { width: 17px; height: 17px; }
.top-icon-btn.danger { color: var(--danger); }
.top-icon-btn:disabled { opacity: .45; cursor: not-allowed; }

.mobile-tabbar {
  display: none;
  flex: 0 0 auto;
  background: #000;
  border-top: 1px solid #1c1e24;
  padding: 10px 0 max(10px, env(safe-area-inset-bottom));
  align-items: center;
  justify-content: space-around;
}
.tab-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,.55);
  cursor: not-allowed;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tab-btn svg { width: 21px; height: 21px; }
.tab-btn.active { background: var(--green); color: #0d1f17; cursor: default; }

.remote-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, 40px);
  z-index: 1;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  width: 80%;
}

.spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
}
.spinner .ring {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,.15);
  border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Bottom control bar: four equal tiles (light theme, matches reference) */
.control-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: #e3e5ea;
  flex: 0 0 auto; /* never let flexbox shrink this below its content's height */
  /* Matches .chat-area's height so the two video panes above them end up
     the same height on desktop/tablet — see the mobile breakpoint, which
     resets this back to auto for the compact phone layout. */
  height: 160px;
}

.tile {
  border: none;
  background: var(--light-surface);
  color: var(--light-text);
  font-size: 20px;
  font-weight: 700;
  padding: 18px 10px;
  cursor: pointer;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tile:disabled { opacity: .5; cursor: not-allowed; }

.tile-start { background: var(--green); color: #0d1f17; }
.tile-start:hover:not(:disabled) { background: var(--green-dark); color: #fff; }
.tile-stop { background: var(--pink); color: #fff; }
.tile-stop:hover:not(:disabled) { background: var(--pink-dark); }

/* Start tile's label: "Start" when idle, "Next" once connected. On phones
   this whole tile is hidden — see .mobile-call-row in the breakpoint below. */
.tile-start .label-active-desktop { display: none; }
.tile-start.is-active .label-idle { display: none; }
.tile-start.is-active .label-active-desktop { display: inline; }

.tile-select { position: relative; padding: 0; background: var(--light-surface); }
.tile-select-btn {
  width: 100%;
  height: 100%;
  min-height: 72px;
  border: none;
  background: transparent;
  color: var(--light-text);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.tile-select-value { font-size: 22px; }

.tile-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e3e5ea;
  border-radius: 10px 10px 0 0;
  max-height: 260px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: 0 -8px 24px rgba(0,0,0,.08);
}
.tile-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: transparent;
  border: none;
  color: var(--light-text);
  font-size: 14px;
  cursor: pointer;
}
.tile-menu button:hover { background: var(--light-surface); }

/* Chat (light theme, matches reference) */
.chat-area {
  height: 160px;
  flex: 0 0 auto;
  background: var(--light-bg);
  display: flex;
  flex-direction: column;
  border-top: 1px solid #e3e5ea;
}

.chat-notice {
  flex: 0 0 auto;
  background: var(--light-surface);
  color: var(--light-muted);
  font-size: 13.5px;
  line-height: 1.5;
  padding: 14px 18px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.chat-notice a { color: var(--accent); }
.chat-notice-icon {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-notice-text { flex: 1; }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-log .msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; line-height: 1.4; }
.chat-log .me { align-self: flex-end; background: var(--accent); color: #fff; }
.chat-log .them { align-self: flex-start; background: var(--light-surface); color: var(--light-text); }
.chat-log .sys {
  align-self: center;
  color: var(--light-muted);
  font-size: 13px;
  text-align: center;
}
.chat-log .sys a { color: var(--accent); }

.chat-form {
  display: flex;
  align-items: center;
  border-top: 1px solid #e3e5ea;
  padding: 6px 10px;
  gap: 6px;
}
.chat-form input {
  flex: 1;
  padding: 12px 4px;
  background: transparent;
  border: none;
  color: var(--light-text);
  outline: none;
  /* iOS/Android auto-zoom focused inputs under 16px regardless of the
     viewport's user-scalable setting — keep this at 16px to avoid it. */
  font-size: 16px;
}
.chat-form input::placeholder { color: #a9adb6; }
.send-btn {
  padding: 0 14px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}
.emoji-btn {
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  padding: 0 6px;
  color: var(--light-muted);
}

@media (max-width: 760px) {
  main.columns { flex-direction: column; }
  /* Without this, .col can collapse shorter than its own children's
     combined height (control-bar + mobile-call-row refuse to shrink, but
     the column around them still could), and the overflow spills out to
     visually overlap the next column instead of the page just scrolling. */
  .col { min-height: auto; }
  .pane { min-height: 160px; }

  /* Phone-only chrome on each pane. Idle backgrounds (noise / spinner) are
     now the same on every screen size, so nothing to toggle here for them. */
  .mobile-pane-label { display: block; }
  .mobile-icon-stack { display: flex; }
  #pane-local .pane-mini-controls { display: none; }
  .mobile-top-bar { display: flex; }
  #pane-remote .pane-mini-controls { display: none; }
  /* Bottom tab bar removed for now (most of its 5 icons were non-functional
     placeholders) — markup/CSS left in place to bring back easily. */

  /* Country/"I am" preference tiles are desktop-only on phones — Start/Stop
     move into an overlay on your own video instead (below). */
  .control-bar { display: none; }

  /* Start/Stop/Next: an overlay near the bottom of your own video, styled
     as bordered pills (not full tiles) so it doesn't compete visually with
     the mini icon stack. */
  .mobile-call-row {
    display: flex;
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 14px;
    z-index: 2;
    padding: 0;
    background: transparent;
  }

  #pane-remote { touch-action: pan-y; } /* leaves vertical scroll alone, frees horizontal for swipe-to-skip */

  /* Chat is reached via the 💬 icon in the local pane's icon stack; its own
     notice line only matters there once opened, so hide the duplicate. */
  .chat-area { display: none; height: auto; max-height: 50%; }
  .chat-area.mobile-chat-open { display: flex; }
  .chat-area .chat-notice { display: none; }
}
