:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1f262f;
  --border: #2b323c;
  --text: #e6edf3;
  --muted: #8d99a6;
  --accent: #3b82f6;
  --accent-hover: #2f6fd8;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* An author `display` declaration outranks the UA stylesheet's rule for
   [hidden], so any element that sets its own display — the lobby and the call
   screen both do — would never actually hide. This one rule governs every
   hidden element in the page. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
button { font: inherit; cursor: pointer; }

/* ---- Lobby --------------------------------------------------------------- */

.lobby {
  display: grid;
  place-items: center;
  height: 100vh;
  padding: 24px;
  overflow-y: auto;
}

.lobby-card {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
}

.lobby-card h1 { margin: 0 0 8px; font-size: 22px; }
.tagline { margin: 0 0 24px; color: var(--muted); font-size: 13.5px; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }

input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
}
input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.advanced { margin: 20px 0; border-top: 1px solid var(--border); padding-top: 14px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; font-size: 13.5px; }
.check small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.turn-status { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

/* ---- Buttons ------------------------------------------------------------- */

.primary {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  border: 0;
  border-radius: var(--radius);
  color: #fff;
  font-weight: 600;
}
.primary:hover { background: var(--accent-hover); }
.primary.small { width: auto; padding: 9px 16px; }

.ghost {
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.ghost:hover { border-color: var(--muted); }

.error {
  margin: 14px 0 0;
  padding: 10px 12px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: var(--radius);
  color: #fca5a5;
  font-size: 13px;
}

/* ---- Call layout --------------------------------------------------------- */

.call { display: flex; flex-direction: column; height: 100vh; }

.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.bar-left, .bar-right { display: flex; align-items: center; gap: 10px; }
.brand { font-weight: 600; font-size: 14px; }
#copy-link { padding: 5px 10px; font-size: 12.5px; }

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.subtle { color: var(--muted); }
.badge[data-state="connected"] { color: var(--good); border-color: rgba(34, 197, 94, 0.4); }
.badge[data-state="connecting"], .badge[data-state="reconnecting"] { color: var(--warn); border-color: rgba(245, 158, 11, 0.4); }
.badge[data-state="failed"], .badge[data-state="disconnected"] { color: var(--bad); border-color: rgba(239, 68, 68, 0.4); }

.stage { display: flex; flex: 1; min-height: 0; }

/* ---- Video tiles --------------------------------------------------------- */

.tiles-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
}

.waiting {
  flex: none;
  margin: 12px 12px 0;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: center;
}
.waiting h2 { margin: 0 0 6px; font-size: 17px; }
.waiting .note { margin-bottom: 14px; }
.waiting-link { display: flex; gap: 8px; max-width: 460px; margin: 0 auto; }
.waiting-link input { flex: 1; font-size: 13px; }
.waiting-code { margin: 12px 0 0; font-size: 12.5px; color: var(--muted); }
.waiting-code code { color: var(--text); font-size: 14px; letter-spacing: 0.5px; }

.tiles {
  flex: 1;
  display: grid;
  gap: 12px;
  padding: 12px;
  min-width: 0;
  align-content: center;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.tile {
  position: relative;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}
.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}
.tile.local video { transform: scaleX(-1); }
/* A shared screen must never be mirrored, even in the local preview. */
.tile.local.sharing video { transform: none; }
.tile.no-video video { visibility: hidden; }

.tile .placeholder {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: var(--surface-2);
}
.tile.no-video .placeholder { display: grid; }

.avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  font-weight: 600;
}

.tile .label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
  font-size: 12.5px;
}
.tile .muted-icon { color: var(--bad); }

/* ---- Side panel ---------------------------------------------------------- */

.panel {
  width: 340px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  min-height: 0;
}

.panel-tabs { display: flex; border-bottom: 1px solid var(--border); flex: none; }
.tab {
  flex: 1;
  padding: 12px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.tab-body { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 12px; gap: 10px; }

.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; padding: 7px 11px; border-radius: 10px; background: var(--surface-2); font-size: 13.5px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg .who { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg.mine { align-self: flex-end; background: var(--accent); }
.msg.mine .who { color: rgba(255, 255, 255, 0.75); }
.msg.system { align-self: center; max-width: 100%; background: none; color: var(--muted); font-size: 12px; font-style: italic; }

.chat-form { display: flex; gap: 8px; flex: none; }
.chat-form input { flex: 1; }
.note { margin: 0; font-size: 11.5px; color: var(--muted); flex: none; }

/* ---- File transfer ------------------------------------------------------- */

.dropzone {
  flex: none;
  padding: 22px 14px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone p { margin: 0 0 8px; }
.dropzone.over { border-color: var(--accent); background: rgba(59, 130, 246, 0.08); }

.transfers { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.transfer { padding: 9px 11px; background: var(--surface-2); border-radius: 10px; font-size: 12.5px; }
.transfer .name { display: block; font-weight: 600; word-break: break-all; }
.transfer .meta { color: var(--muted); font-size: 11.5px; }
.transfer progress { width: 100%; height: 5px; margin-top: 6px; }
.transfer.done .meta { color: var(--good); }
.transfer.failed .meta { color: var(--bad); }

/* ---- Controls ------------------------------------------------------------ */

.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex: none;
  flex-wrap: wrap;
}
.control {
  padding: 10px 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
}
.control:hover { border-color: var(--muted); }
.control[data-on="false"] { background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.control.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.control.danger { background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }

/* ---- Toasts -------------------------------------------------------------- */

.toasts { position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; z-index: 10; }
.toast { padding: 9px 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; font-size: 13px; }
.toast.error { border-color: rgba(239, 68, 68, 0.5); color: #fca5a5; }

/* ---- Narrow screens ------------------------------------------------------ */

@media (max-width: 820px) {
  .stage { flex-direction: column; }
  .panel { width: auto; border-left: 0; border-top: 1px solid var(--border); height: 45%; }
  .tiles { grid-template-columns: 1fr; padding: 8px; gap: 8px; }
  .waiting { margin: 8px 8px 0; padding: 14px; }
  .waiting-link { flex-direction: column; }
  .controls { gap: 6px; padding: 8px; }
  .control { padding: 9px 13px; font-size: 13px; }
}
