:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2230;
  --muted: #5f6b7d;
  --border: #dde1e8;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #d1343a;
  --ok: #1e9c5a;
  --warn: #c98a08;
  --secondary: var(--bg);
  --secondary-text: var(--text);
  --radius: 12px;
  color-scheme: light;
}

/* Dark mode follows the device unless the page sets data-theme on <html>. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b;
    --surface: #1b2029;
    --text: #e6e9ef;
    --muted: #9aa4b4;
    --border: #2c3340;
    --accent: #5b8ff9;
    --danger: #f06368;
    --ok: #3cc47c;
    --warn: #e8b23a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #12151b;
  --surface: #1b2029;
  --text: #e6e9ef;
  --muted: #9aa4b4;
  --border: #2c3340;
  --accent: #5b8ff9;
  --danger: #f06368;
  --ok: #3cc47c;
  --warn: #e8b23a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  margin-right: auto;
}

.room-tag { color: var(--muted); font-size: 14px; }
.logout { margin: 0; }
.logout .btn { padding: 6px 12px; }
.login { max-width: 420px; margin: 0 auto; }

.notice {
  padding: 10px 12px;
  border-left: 4px solid var(--warn);
  border-radius: 8px;
  background: color-mix(in srgb, var(--warn) 14%, transparent);
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

h1 { font-size: 1.5rem; margin: 0 0 12px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 0.85rem; margin: 0 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.muted { color: var(--muted); }
.small { font-size: 14px; }

label { display: block; font-weight: 600; margin: 12px 0 6px; }

select, input[type="text"], input[type="password"], input:not([type]), input[readonly] {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

input[type="range"] { width: 100%; }
input[type="range"], input[type="checkbox"] { accent-color: var(--accent); }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 0;
  min-width: 0;
}

legend { font-weight: 600; padding: 0 6px; }

.grid.two {
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 720px) {
  .grid.two { grid-template-columns: 1fr; }
}

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--secondary);
  color: var(--secondary-text);
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.big { padding: 14px 24px; font-size: 1.1rem; flex: 1; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  margin: 6px 0;
}
.check input { width: 18px; height: 18px; }

.target-list { columns: 2; column-gap: 16px; }
@media (max-width: 480px) { .target-list { columns: 1; } }
.target-list .check { break-inside: avoid; }

.badge {
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 999px;
  color: var(--muted);
}
.badge:empty { display: none; }
.badge[data-state="connected"] { color: var(--ok); border: 1px solid currentColor; }
.badge[data-state="reconnecting"] { color: var(--warn); border: 1px solid currentColor; }
.badge[data-state="failed"] { color: var(--danger); border: 1px solid currentColor; }

.listener-count {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.listener-count.waiting { color: var(--warn); font-weight: 600; }

.pill {
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.pill[data-state="online"] { color: var(--ok); border-color: currentColor; }
.pill[data-state="live"] { color: #fff; background: var(--danger); border-color: var(--danger); }

.meter {
  height: 8px;
  margin-top: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.meter > div {
  height: 100%;
  width: 0;
  background: var(--ok);
  transition: width 80ms linear;
}

.share { display: flex; gap: 8px; }

.transcripts {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.transcript, .transcript-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.text {
  white-space: pre-wrap;
  max-height: 220px;
  overflow-y: auto;
  min-height: 2.5em;
}
.text.source { color: var(--muted); margin-top: 8px; }

.transcript-box { margin-top: 16px; }
.transcript-box summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }

.errors { color: var(--danger); min-height: 1.5em; }

.listener { max-width: 520px; margin: 0 auto; }
.listener-head { display: flex; gap: 8px; justify-content: flex-end; }
.unavailable { text-align: center; }

a.btn { display: inline-block; text-decoration: none; }

.room-list { list-style: none; margin: 0; padding: 0; }
.room-list li {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.room-list li:first-child { border-top: 0; }
.room-list li span { margin-right: auto; font-weight: 600; }

/* Embedded in a mobile WebView or iframe: no chrome, edge to edge. */
body.embed .container { padding: 12px; }
body.embed .card { border: none; border-radius: 0; margin: 0; padding: 12px 4px; background: transparent; }
body.embed .listener { max-width: none; }
