:root {
  --bg: #0a0c11;
  --panel: #12151d;
  --panel-2: #171b25;
  --border: #232838;
  --text: #e7e9f0;
  --muted: #8890a4;
  --accent: #22d3b0;
  --accent-dim: #17513f;
  --danger: #ff6b6b;
  --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

.hidden { display: none !important; }

.screen { height: 100vh; width: 100vw; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.06em;
  font-size: 14px;
}
.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

/* ===== Gate (nev megadasa) ===== */
#gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(34,211,176,0.08), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(34,211,176,0.05), transparent 40%),
    var(--bg);
}
.gate-card {
  width: 380px;
  max-width: 90vw;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.terms-footer {
  margin-top: 16px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}
.terms-footer a { color: var(--accent); }
.gate-card h1 {
  font-family: var(--font-display);
  font-size: 24px;
  margin: 20px 0 6px;
}
.muted { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 20px; }

#gate-form { display: flex; flex-direction: column; gap: 12px; }
#name-input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
#name-input:focus { border-color: var(--accent); }

.gender-field { display: flex; flex-direction: column; gap: 8px; }
.gender-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.gender-options { display: flex; gap: 8px; }
.gender-opt {
  flex: 1;
  cursor: pointer;
  background: var(--panel-2);
  border: 2px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  padding: 10px 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-body);
  position: relative;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}
.gender-opt:hover { color: var(--text); border-color: #3a4258; }
.gender-opt.selected {
  border-color: var(--accent);
  color: #06120f;
  background: var(--accent);
  font-weight: 700;
  transform: translateY(-1px);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.gender-opt.selected::before {
  content: '✓ ';
}

.age-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  cursor: pointer;
  user-select: none;
}
.age-check input {
  margin-top: 2px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

#gate-form button.join-text-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
#gate-form button.join-text-btn:hover { border-color: var(--accent); color: var(--accent); }

.primary-btn, .accent-btn, .ghost-btn, #gate-form button {
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 600;
  border-radius: 10px;
  border: none;
  padding: 12px 18px;
  font-size: 14px;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.google-signin-btn {
  display: flex;
  justify-content: center;
  margin: 4px 0 12px;
  border-radius: 999px;
  overflow: hidden;
}
.signed-in-as {
  text-align: center;
  font-size: 13px;
  color: var(--accent);
  margin: 0 0 8px;
}

#gate-form button, .primary-btn, .accent-btn {
  background: var(--accent);
  color: #06120f;
}
#gate-form button:hover, .primary-btn:hover, .accent-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}
.ghost-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.ghost-btn:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }

button:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }

/* Text-chat mode: no camera, so hide the video elements and let the
   overlay text/status occupy the (now empty) video frame area. */
body.text-mode .local-video-wrap,
body.text-mode #remote-video {
  display: none;
}

/* ===== App shell ===== */
#app { display: flex; flex-direction: column; }

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}
.topbar .brand { justify-self: start; }
.topbar .me { justify-self: end; }
.me {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 4px 10px 4px 4px;
  cursor: pointer;
  font-family: var(--font-body);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.me:hover { border-color: var(--border); background: var(--panel-2); }
.me #me-name { color: var(--text); font-weight: 600; }

.online-badge {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: online-pulse 2s ease-in-out infinite;
}
#online-count { color: var(--text); font-weight: 700; }
.online-label { text-transform: uppercase; letter-spacing: 0.04em; font-size: 11px; }

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

.stage {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 6px 480px;
  gap: 16px;
  padding: 16px 24px 24px;
  min-height: 0;
}

.video-column { display: flex; flex-direction: column; gap: 12px; min-height: 0; }

.resizer {
  cursor: col-resize;
  position: relative;
  background: transparent;
  touch-action: none;
}
.resizer::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 3px;
  transform: translateX(-50%);
  border-radius: 3px;
  background: var(--border);
  transition: background 0.15s ease;
}
.resizer:hover::after,
.resizer.dragging::after {
  background: var(--accent);
}

.video-frame {
  position: relative;
  flex: 1;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  min-height: 0;
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #05070a;
}

.local-video-wrap {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 160px;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #05070a;
  z-index: 2;
}
#local-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.camera-switch-btn {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(10, 12, 17, 0.75);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 3;
  padding: 0;
}
.camera-switch-btn:hover { border-color: var(--accent); }

.camera-modal-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 50vh;
  overflow-y: auto;
}
.camera-modal-item {
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  border: 1px solid transparent;
}
.camera-modal-item:hover { background: var(--panel-2); }
.camera-modal-item.active {
  color: var(--accent);
  font-weight: 700;
  border-color: var(--accent);
  background: var(--accent-dim);
}

.partner-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.partner-flag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  line-height: 1;
}
.partner-flag img {
  display: block;
  border-radius: 2px;
  box-shadow: 0 0 0 1px var(--border);
}
.partner-flag-code {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.partner-gender {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
}
.partner-gender.male { background: rgba(79, 124, 255, 0.15); color: #6f92ff; }
.partner-gender.female { background: rgba(255, 107, 158, 0.15); color: #ff8fb8; }
.partner-gender.unspecified { display: none; }

.me-avatar,
.partner-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: #06120f;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--border);
}
.me-avatar:empty,
.partner-avatar:empty { display: none; }
.me-avatar img,
.partner-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.partner-name {
  font-size: 14px;
  font-weight: 600;
}

/* ===== Stage overlay (idle / searching states) ===== */
.stage-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: radial-gradient(circle at 50% 45%, rgba(34,211,176,0.06), transparent 60%), #05070a;
  z-index: 3;
  transition: opacity 0.25s ease;
}
.stage-overlay.connected { opacity: 0; pointer-events: none; }

#overlay-text { color: var(--muted); font-size: 14px; margin: 0; }

.radar {
  position: relative;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.radar span {
  position: absolute;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  width: 64px;
  height: 64px;
  opacity: 0;
  animation: radar-ping 2.4s ease-out infinite;
}
.radar span:nth-child(2) { animation-delay: 0.8s; }
.radar span:nth-child(3) { animation-delay: 1.6s; }
.radar::after {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 16px var(--accent);
}
.stage-overlay:not(.searching) .radar span { animation-play-state: paused; opacity: 0; }

@keyframes radar-ping {
  0% { transform: scale(0.3); opacity: 0.9; }
  100% { transform: scale(1.6); opacity: 0; }
}

.controls {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===== Chat ===== */
.chat-column {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  min-height: 0;
  overflow: hidden;
}
.chat-header {
  padding: 14px 16px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  text-transform: uppercase;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-hint { color: var(--muted); font-size: 13px; }

.msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}
.msg.me { align-self: flex-end; background: var(--accent-dim); border: 1px solid var(--accent); }
.msg.them { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--border); }
.msg.system { align-self: center; color: var(--muted); font-size: 12px; background: none; }
.msg-original {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  opacity: 0.65;
  font-style: italic;
}

/* Floating chat bubbles over the video — only shown on mobile (see
   the mobile media query), where the persistent message list is hidden. */
.video-message-overlay {
  display: none;
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 84px;
  z-index: 3;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
.video-message-bubble {
  align-self: flex-start;
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.35;
  background: rgba(23, 27, 37, 0.88);
  backdrop-filter: blur(6px);
  color: var(--text);
  border: 1px solid var(--border);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  word-wrap: break-word;
}
.video-message-bubble.me {
  align-self: flex-end;
  background: rgba(34, 211, 176, 0.22);
  border-color: var(--accent);
}
.video-message-bubble.visible { opacity: 1; transform: translateY(0); }

.chat-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}
#chat-input {
  flex: 1;
  min-width: 120px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  outline: none;
  font-size: 14px;
}
#chat-input:focus { border-color: var(--accent); }
.chat-form button {
  background: var(--accent);
  color: #06120f;
  border: none;
  border-radius: 10px;
  padding: 0 16px;
  font-weight: 600;
  cursor: pointer;
}
.switch-video-below-btn {
  width: calc(100% - 24px);
  margin: 0 12px 12px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 9px 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.switch-video-below-btn:hover:not(:disabled) { background: var(--accent-dim); }
.switch-video-below-btn:disabled { border-color: var(--border); color: var(--muted); cursor: not-allowed; }

/* ===== Modals (Friends / Sign-in required) ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 10, 0.72);
  backdrop-filter: blur(3px);
}
.modal-card {
  width: 380px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 14px;
}
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}
.modal-close:hover { color: var(--text); }

.friends-list { display: flex; flex-direction: column; gap: 4px; }
.friend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
}
.friend-row:hover { background: var(--panel-2); }
.friend-row .avatar-circle { width: 32px; height: 32px; font-size: 13px; }
.friend-row-name { flex: 1; font-size: 14px; font-weight: 600; }
.friend-call-btn {
  background: var(--accent);
  color: #06120f;
  border: none;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}
.friend-call-btn:hover { opacity: 0.85; }
.friend-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #555d70;
  flex-shrink: 0;
}
.friend-status-dot.online { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

.friend-remove-btn {
  position: relative;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #555d70;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s ease, background 0.15s ease;
}
.friend-remove-btn:hover { color: #ff6b6b; background: rgba(255, 107, 107, 0.12); }
.friend-remove-btn::after {
  content: 'Remove friend';
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-right: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 5;
}
.friend-remove-btn:hover::after { opacity: 1; }

.logout-btn {
  width: 100%;
  margin-bottom: 14px;
  font-size: 12px;
  padding: 8px 0;
}
.friends-heading {
  font-family: var(--font-display);
  font-size: 14px;
  margin: 4px 0 12px;
  color: var(--text);
}

.nickname-field { margin-bottom: 16px; }
.nickname-row { display: flex; gap: 8px; margin-top: 6px; }
#nickname-input {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
#nickname-input:focus { border-color: var(--accent); }
#nickname-save-btn { padding: 0 14px; }

/* Shared circular avatar look, reused for friends-list rows */
.avatar-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  font-weight: 700;
  color: #06120f;
  background: var(--accent);
}
.avatar-circle img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ===== Friend-request bubble inside chat ===== */
.friend-request-card {
  align-self: center;
  width: 100%;
  max-width: 90%;
  background: var(--panel-2);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.friend-request-card .frc-top { display: flex; align-items: center; gap: 8px; }
.friend-request-card .avatar-circle { width: 26px; height: 26px; font-size: 12px; }
.friend-request-actions { display: flex; gap: 8px; }
.friend-request-actions button {
  flex: 1;
  border: none;
  border-radius: 8px;
  padding: 6px 0;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
}
.fr-accept { background: var(--accent); color: #06120f; }
.fr-decline { background: var(--panel); border: 1px solid var(--border) !important; color: var(--text); }
.friend-request-card.resolved { opacity: 0.6; }
.friend-request-card.resolved .friend-request-actions { display: none; }

@media (max-width: 860px) {
  html, body { color-scheme: dark; }

  .stage {
    display: block;
    position: relative;
    grid-template-columns: none;
    padding: 0;
    gap: 0;
    height: calc(100dvh - 53px); /* dvh accounts for mobile browser toolbars better than vh */
    overflow: hidden;
  }
  .video-column {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
  }
  .video-frame {
    flex: 1;
    min-height: 0;
    border-radius: 0;
    border: none;
  }
  .controls {
    padding: 10px 12px;
    background: var(--bg);
  }
  .local-video-wrap { width: 96px; top: 10px; right: 10px; }
  .resizer { display: none; }

  /* Chat panel is pinned to the bottom of .stage and floats ON TOP of the
     video column (which fills the whole stage) — this guarantees a real
     visual overlap regardless of how tall the video/controls end up being. */
  /* Chat panel is pinned to the bottom of .stage, but on mobile it's
     shrunk to just the input bar — the message list, header, and
     partner-info live in the desktop sidebar only. Actual chat messages
     instead float over the video as fading bubbles (see
     .video-message-overlay above). */
  .chat-column {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    border-radius: 0;
    border: none;
    background: rgba(10, 12, 17, 0.94);
    backdrop-filter: blur(10px);
    z-index: 5;
    box-shadow: none;
    padding-top: 4px;
  }
  .chat-header,
  #partner-info,
  #chat-log,
  #switch-video-btn {
    display: none !important;
  }
  .chat-form { border-top: none; }

  .video-message-overlay { display: flex; }

  /* iOS Safari auto-zooms the whole page on focus if an input's font-size
     is under 16px — bump it up here to prevent that. */
  #chat-input { font-size: 16px; }
}
