:root {
  color-scheme: dark;
  --bg: #0b0c10;
  --surface: #13151b;
  --surface-2: #1a1d25;
  --border: #252934;
  --border-strong: #323746;
  --text: #e9ebf1;
  --muted: #8a90a2;
  --accent: #6c7bff;
  --accent-hover: #7f8cff;
  --danger: #e5484d;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: 1120px; margin: 0 auto; padding: 20px 24px 8px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  flex: none; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #6c7bff, #b36cff);
}
.brand-name { font-size: 16px; font-weight: 650; letter-spacing: .1px; }
.brand-sub { font-size: 12.5px; color: var(--muted); }
/* Text colour is set by setConnState(); the dot follows it via currentColor. */
.pill {
  flex: none; display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
}
.pill::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor;
}

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px;
  max-width: 1120px; margin: 0 auto; padding: 12px 24px 32px; align-items: start;
}
.stage-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* ---------- stage ---------- */
.stage {
  position: relative; width: 100%; max-width: 680px; margin: 0 auto;
  aspect-ratio: 1 / 1; border-radius: var(--radius); overflow: hidden;
  background: #000; border: 1px solid var(--border);
}
.stage img, .stage video, .stage canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
/* The still preview stays painted UNDERNEATH both players for the whole
   session. A player with no src renders transparent, so any stall, swap or
   buffer underrun falls back to the avatar's own face instead of the black
   stage — the old code toggled `hidden` and flashed black at every seam. */
#avatarPreview { z-index: 0; }
#playerA, #playerB { z-index: 1; }   /* the players swap 1/2 between themselves */
#stageCanvas { z-index: 2; }          /* frames transport: drawn over the preview */
#stageCanvas[hidden] { display: none; }
.stage-status {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  padding: 36px 18px 14px; font-size: 13.5px; font-weight: 500;
  background: linear-gradient(to top, rgba(0,0,0,.72), rgba(0,0,0,0));
  pointer-events: none;
}

/* ---------- buttons ---------- */
.controls {
  display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px; width: 100%; max-width: 680px; margin: 0 auto;
}
.btn {
  font: inherit; font-weight: 600; padding: 12px 14px; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer; color: var(--text);
  transition: background-color .15s, border-color .15s, opacity .15s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary.stop { background: var(--danger); }
.btn-secondary { background: var(--surface-2); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { border-color: #4a5063; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); }

/* ---------- panels ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.panel-title {
  margin: 0 0 12px; font-size: 11.5px; font-weight: 650; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted);
}
.field { display: block; margin-bottom: 12px; }
.field-label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border-strong); border-radius: 10px; padding: 9px 12px;
}
select[hidden], .field:has(select[hidden]) { display: none; }
.field-hint { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); }
.field-hint:empty { display: none; }
.field-hint.error { color: var(--danger); }

/* avatar photo upload: consent first, then the button unlocks */
.upload-consent { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; cursor: pointer; }
.upload-consent input { margin-top: 2px; accent-color: var(--accent); }
.upload-btn { width: 100%; padding: 9px 12px; }

/* mic level: the bar's width and colour are driven by the barge gate script */
.meter { display: flex; align-items: center; gap: 10px; margin: -4px 0 14px; }
.meter-track {
  flex: 1; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden;
}
.meter-bar { height: 100%; width: 0%; background: #3fb950; transition: width .06s ease; }
.meter-status { flex: none; font-size: 11.5px; color: var(--muted); }

/* ---------- transcript ---------- */
.log {
  min-height: 160px; max-height: 300px; overflow-y: auto;
  font-size: 13.5px; line-height: 1.55; color: #c9ccd6;
}
.log:empty::before { content: "Your conversation will appear here."; color: var(--muted); }
.log > div { padding: 6px 0; border-bottom: 1px solid var(--border); }
.log > div:last-child { border-bottom: 0; }
.log b { color: #9fb0ff; font-weight: 600; margin-right: 4px; }
.log i { color: #d8a657; font-style: normal; }

/* ---------- pipeline status ---------- */
.proc { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0; }
.proc dt { font-size: 11.5px; color: var(--muted); }
.proc dd { margin: 0; font-size: 13px; font-weight: 500; color: var(--muted); }

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 8px 16px 24px; }
  .topbar { padding: 16px 16px 4px; }
}
@media (max-width: 480px) {
  .brand-sub { display: none; }
  .controls { grid-template-columns: 1fr 1fr; }
  .controls #startBtn { grid-column: 1 / -1; }
}
