/* ---------- Tokens ---------- */
:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1f242c;
  --surface-3: #262d36;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4f8cff;
  --accent-hover: #6a9eff;
  --danger: #ef4444;
  --danger-hover: #f06262;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.45);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

video::-webkit-media-controls { display: none !important; }

/* ---------- Buttons ---------- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  transition: background 0.15s ease, transform 0.05s ease;
  box-shadow: 0 1px 3px rgba(79, 140, 255, 0.4);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn-secondary:hover { background: var(--surface-3); border-color: #424a55; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ---------- Landing ---------- */
.landing-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 20%, rgba(79, 140, 255, 0.08), transparent 60%),
    radial-gradient(circle at 80% 80%, rgba(79, 140, 255, 0.05), transparent 50%),
    var(--bg);
}

.landing {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 18px;
  width: 380px;
  max-width: calc(100vw - 32px);
  padding: 40px 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.brand {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
  background: linear-gradient(135deg, #fff 0%, #b3c7ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  margin: -8px 0 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

.divider {
  position: relative;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin: 6px 0;
}
.divider::before,
.divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: calc(50% - 24px);
  height: 1px;
  background: var(--border);
}
.divider::before { left: 0; }
.divider::after { right: 0; }
.divider span { background: var(--surface); padding: 0 8px; }

.text-input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.2);
}
.name-input { text-align: center; }

.join-form {
  display: flex;
  gap: 8px;
}
.join-form input {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: var(--mono);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.join-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.2);
}

/* ---------- Room layout ---------- */
.room-body {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 52px;
}

.room-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.room-label {
  color: var(--muted);
  font-size: 0.85rem;
}
.room-meta code {
  font-family: var(--mono);
  font-size: 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
  margin-left: 4px;
}
.conn-dot.warn { background: #eab308; box-shadow: 0 0 8px rgba(234, 179, 8, 0.5); }
.conn-dot.bad { background: var(--danger); box-shadow: 0 0 8px rgba(239, 68, 68, 0.5); }

.participants {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.participants svg { color: var(--muted); }

/* ---------- Stage ---------- */
.stage {
  display: grid;
  grid-template-columns: 1fr 360px;
  min-height: 0;
  overflow: hidden;
}

.video-area {
  position: relative;
  background: #000;
  overflow: hidden;
}

.remote-slot {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}
.remote-slot video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  display: block;
}
.remote-slot.empty video { display: none; }

/* Empty state card */
.empty-card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 40%, rgba(79, 140, 255, 0.06), transparent 60%),
    #0d1117;
}
.remote-slot:not(.empty) .empty-card { display: none; }

.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
  margin-bottom: 8px;
}
.empty-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}
.empty-sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 8px;
}
.share-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 8px 8px 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.share-link code {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Local PIP ---------- */
.local-slot {
  position: absolute;
  bottom: 100px;
  right: 24px;
  width: 220px;
  height: 140px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow-md);
  z-index: 5;
  transition: transform 0.2s ease;
}
.local-slot:hover { transform: translateY(-2px); }
.local-slot video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  display: block;
}
.local-slot.alone {
  position: static;
  width: min(72vw, 1100px);
  height: min(70vh, 620px);
  margin: 24px auto;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.local-slot.alone .local-label { font-size: 0.85rem; }

.local-label {
  position: absolute;
  bottom: 6px;
  left: 8px;
  padding: 2px 8px;
  font-size: 0.72rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.55);
  border-radius: 4px;
  pointer-events: none;
}

.local-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
}
.local-slot.ready .local-spinner { display: none; }
.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Control bar ---------- */
.control-bar {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(22, 27, 34, 0.8);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  z-index: 10;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text);
  transition: background 0.15s, color 0.15s, transform 0.05s;
}
.ctrl-btn:hover { background: #323a45; }
.ctrl-btn:active { transform: scale(0.96); }

.ctrl-btn .icon-off { display: none; }
.ctrl-btn.off { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
.ctrl-btn.off .icon-on { display: none; }
.ctrl-btn.off .icon-off { display: block; }

.ctrl-btn.danger {
  background: var(--danger);
  color: #fff;
}
.ctrl-btn.danger:hover { background: var(--danger-hover); }

/* ---------- Popover ---------- */
.popover {
  position: absolute;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  width: 320px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.popover.hidden { display: none; }
.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.popover h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}
.select-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}
.select-field select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.select-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.2);
}

/* ---------- Transcript ---------- */
.transcript {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  min-height: 0;
}
.transcript header {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.transcript h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  flex: 1;
}
#transcript-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  scroll-behavior: smooth;
}
#transcript-list::-webkit-scrollbar { width: 8px; }
#transcript-list::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 4px;
}
#transcript-list::-webkit-scrollbar-thumb:hover { background: #3a424d; }

.transcript-block {
  padding: 10px 12px 12px;
  margin-bottom: 12px;
  background: var(--surface-2);
  border-left: 3px solid var(--border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.transcript-block.speaker-A { border-left-color: var(--accent); }
.transcript-block.speaker-B { border-left-color: #f59e0b; }

.block-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 0.72rem;
  color: var(--muted);
}
.block-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--surface-3);
  color: var(--text);
}
.transcript-block.speaker-A .block-label { background: var(--accent); color: white; }
.transcript-block.speaker-B .block-label { background: #f59e0b; color: white; }
.block-name {
  flex: 1;
  font-weight: 600;
  color: var(--text);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.block-time { letter-spacing: 0.02em; }

/* ---------- Name modal (first-time entry) ---------- */
.name-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 11, 16, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
}
.name-modal.hidden { display: none; }
.name-modal .modal-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 360px;
  max-width: calc(100vw - 32px);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.name-modal h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}
.name-modal p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  padding: 4px 0;
}
.toggle-field input { accent-color: var(--accent); width: 16px; height: 16px; }

.block-text {
  line-height: 1.5;
  font-size: 0.92rem;
  color: var(--text);
  word-wrap: break-word;
}

/* ---------- Live caption overlay ---------- */
.caption-overlay {
  position: absolute;
  bottom: 96px;            /* sit above the floating control bar */
  left: 50%;
  transform: translateX(-50%);
  max-width: min(860px, 80%);
  padding: 12px 18px;
  background: rgba(13, 17, 23, 0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: var(--radius-md);
  color: white;
  font-size: 1.05rem;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  box-shadow: var(--shadow-md);
  z-index: 5;
}
.caption-overlay.visible { opacity: 1; }
.caption-label {
  font-weight: 700;
  margin-right: 8px;
  letter-spacing: 0.04em;
}
.caption-label.speaker-A { color: #93b8ff; }
.caption-label.speaker-B { color: #fcd34d; }
.caption-text { white-space: normal; }

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  .stage { grid-template-columns: 1fr; grid-template-rows: 1fr 280px; }
  .transcript { border-left: none; border-top: 1px solid var(--border); }
  .local-slot { width: 140px; height: 100px; bottom: 90px; right: 16px; }
}
