:root {
  --bg: #0e1116;
  --panel: #171b22;
  --panel-2: #1f2530;
  --text: #e8ecf2;
  --muted: #8b95a5;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-bottom: 1px solid #222935;
}
.brand { font-size: 19px; display: flex; align-items: center; gap: 8px; }
.brand b { color: var(--accent); }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.online { color: var(--muted); display: flex; align-items: center; gap: 6px; font-size: 14px; }
.online #onlineCount { color: var(--text); font-weight: 600; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

/* Left: stranger's square webcam, Next/Stop, chat. Right: my smaller webcam and tools. */
.layout {
  --side: 280px;
  --sq: clamp(300px, min(calc(100vw - var(--side) - 56px), calc(100vh - 340px)), 760px);
  flex: 1;
  display: flex; justify-content: center; align-items: flex-start;
  gap: 16px; padding: 12px;
}
.col-main { width: var(--sq); display: flex; flex-direction: column; gap: 10px; }
.col-side { width: var(--side); flex: none; display: flex; flex-direction: column; gap: 12px; }
.video-box {
  position: relative; background: #000; border-radius: var(--radius); overflow: hidden;
  width: 100%; aspect-ratio: 1 / 1;
}
.video-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-box.local.mirror video { transform: scaleX(-1); }
.video-box:fullscreen { border-radius: 0; aspect-ratio: auto; }
.video-box:fullscreen video { object-fit: contain; }
.tag {
  position: absolute; left: 10px; top: 10px; font-size: 12px; padding: 3px 9px;
  background: rgba(0,0,0,.55); border-radius: 999px; color: #cfd6e2;
}
.status {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center; padding: 20px; background: var(--panel); color: var(--muted);
}
.status[hidden] { display: none; }
.status p { margin: 0; font-size: 16px; }
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid #2a3240; border-top-color: var(--accent); animation: spin 0.9s linear infinite;
}
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg) } }

.chat {
  background: var(--panel); border-radius: var(--radius);
  display: flex; flex-direction: column;
  height: max(170px, calc(100vh - var(--sq) - 170px));
}
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; padding: 7px 11px; border-radius: 12px; word-wrap: break-word; white-space: pre-wrap; }
.msg.me { align-self: flex-end; background: var(--accent-2); color: #fff; border-bottom-right-radius: 4px; }
.msg.them { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.msg.sys { align-self: center; background: none; color: var(--muted); font-size: 13px; padding: 2px; text-align: center; }
.typing { padding: 0 14px 6px; font-size: 12px; color: var(--muted); }
.typing[hidden] { display: none; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #252c38; }
.chat-form input {
  flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid #2c3442; color: var(--text);
  border-radius: 10px; padding: 10px 12px; font: inherit; outline: none;
}
.chat-form input:focus { border-color: var(--accent); }

.controls { display: flex; align-items: center; gap: 10px; }
.controls .btn { flex: 1; }
.controls .hint { flex: none; }

.tools { background: var(--panel); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.tool-row { display: flex; justify-content: space-between; gap: 6px; }
.tools .btn.country, .tools .btn.report { max-width: none; width: 100%; justify-content: center; padding: 10px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field > span { display: flex; justify-content: space-between; }
.field b { color: var(--text); font-weight: 600; }
.field select {
  width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid #2c3442;
  border-radius: 8px; padding: 7px 8px; font: inherit; font-size: 13px;
}
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.check.small { font-size: 13px; color: var(--muted); align-items: flex-start; }
.check.small input { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.btn.icon[aria-pressed="true"]#mirrorBtn { background: #16263f; color: #93c5fd; }
.btn {
  border: 0; border-radius: 10px; padding: 11px 22px; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--panel-2); color: var(--text); transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; min-width: 130px; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn.danger { background: #2a1d22; color: #fca5a5; }
.btn.danger:hover:not(:disabled) { background: #3b2128; }
.btn.icon { padding: 10px; width: 44px; height: 44px; display: grid; place-items: center; }
.btn.icon svg { width: 22px; height: 22px; fill: currentColor; }
.btn.icon[aria-pressed="false"] { background: var(--danger); color: #fff; }
.btn.big { width: 100%; padding: 14px; font-size: 16px; margin-top: 8px; }
.chat-form .btn, .chat-form button {
  border: 0; border-radius: 10px; padding: 0 16px; background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.chat-form button:disabled { opacity: .4; cursor: not-allowed; }
.hint { color: var(--muted); font-size: 12px; margin-left: auto; }

.modal {
  position: fixed; inset: 0; background: rgba(5,8,12,.85); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10;
}
.modal[hidden] { display: none; }
.card { background: var(--panel); border-radius: 18px; padding: 28px; max-width: 460px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.card h1 { margin: 0 0 8px; font-size: 24px; }
.card p { color: var(--muted); margin: 0 0 14px; }
.rules { margin: 0 0 16px; padding-left: 20px; color: #c4ccd8; font-size: 14px; }
.rules li { margin-bottom: 6px; }
.check { display: flex; gap: 10px; align-items: center; cursor: pointer; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.error { color: #fca5a5 !important; margin-top: 12px !important; font-size: 14px; }

.btn.report { display: flex; align-items: center; gap: 6px; background: #2b2615; color: #fcd34d; }
.btn.report:hover:not(:disabled) { background: #3a3218; }
.btn.report svg { width: 18px; height: 18px; fill: currentColor; }
.btn.ghost { background: transparent; color: var(--muted); }
.card h2 { margin: 0 0 8px; font-size: 21px; }
.reasons { display: grid; gap: 8px; }
.reasons .btn { text-align: left; }
.reasons .btn:hover { background: #2a3240; }
.legal { margin: 14px 0 0 !important; font-size: 13px; text-align: center; }
.legal a, .footer a { color: var(--muted); }
.footer { text-align: center; font-size: 12px; color: var(--muted); padding: 0 0 10px; }

.btn.country { display: flex; align-items: center; gap: 6px; max-width: 260px; }
.btn.country span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.country svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.btn.country.on { background: #16263f; color: #93c5fd; }
.card.wide { max-width: 520px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modes { display: grid; gap: 6px; margin: 10px 0 12px; }
.modes label { display: flex; gap: 10px; align-items: center; cursor: pointer; padding: 8px 10px; border-radius: 10px; background: var(--panel-2); }
.modes input { accent-color: var(--accent); width: 16px; height: 16px; }
.cpick { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.cpick[hidden] { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { background: #16263f; color: #bfdbfe; border: 0; border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 13px; cursor: pointer; }
.chip::after { content: " ×"; opacity: .7; }
#cSearch {
  background: var(--panel-2); border: 1px solid #2c3442; color: var(--text); border-radius: 10px;
  padding: 9px 12px; font: inherit; outline: none; margin-bottom: 8px;
}
#cSearch:focus { border-color: var(--accent); }
.clist { overflow-y: auto; min-height: 120px; max-height: 38vh; border: 1px solid #252c38; border-radius: 10px; }
.clist label { display: flex; align-items: center; gap: 10px; padding: 7px 10px; cursor: pointer; }
.clist label:hover { background: var(--panel-2); }
.clist input { accent-color: var(--accent); }
.clist .flag { font-size: 18px; width: 24px; text-align: center; }
.clist .cnt { margin-left: auto; font-size: 12px; color: var(--ok); }
.cnote { font-size: 12px !important; margin: 10px 0 0 !important; }
.cactions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.top-right { display: flex; align-items: center; gap: 16px; }
.userbox { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.userbox[hidden] { display: none; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }
.auth { background: var(--panel-2); border-radius: 12px; padding: 14px; margin-bottom: 14px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.auth p { margin: 0 !important; font-size: 14px; text-align: center; }
.auth-msg { color: #c4ccd8 !important; }
.auth-msg.err { color: #fca5a5 !important; }
.auth-msg[hidden], .auth-user[hidden], #gsiBtn[hidden] { display: none; }
.auth-user { color: var(--text) !important; word-break: break-all; }

@media (max-width: 820px) {
  .layout {
    display: grid; gap: 10px; padding: 10px;
    grid-template-columns: 38% minmax(0, 1fr);
    grid-template-areas: "remote remote" "ctrl ctrl" "local tools" "chat chat";
    align-items: start;
  }
  .col-main, .col-side { display: contents; }
  .video-box.remote { grid-area: remote; }
  .controls { grid-area: ctrl; }
  .video-box.local { grid-area: local; border-radius: 10px; }
  .tools { grid-area: tools; padding: 8px; gap: 8px; }
  .chat { grid-area: chat; height: 300px; }
  .tool-row .btn.icon { width: 38px; height: 38px; padding: 8px; }
  .tools .btn.country, .tools .btn.report { padding: 8px 10px; font-size: 13px; }
  .field, .check.small { font-size: 12px; }
  .video-box.local .status p { font-size: 12px; }
  .tag { left: 6px; top: 6px; font-size: 11px; max-width: calc(100% - 12px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .hint { display: none; }
  .userbox #userEmail { display: none; }
  .online span[data-i18n] { display: none; }
}
.auth[hidden] { display: none; }
.flangs { margin: 4px 0 6px; line-height: 1.9; }
