:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dbe1e8;
  --text: #17202c;
  --muted: #5d6877;
  --accent: #2f7d96;
  --accent-text: #ffffff;
  --danger: #a32d2d;
  --danger-text: #ffffff;
  --ok: #2b7a12;
  --warn: #9a5a08;
  --scope-bg: #eef2f6;
  --scope-line: #2f7d96;
  --scope-grid: #c9d2dc;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d131c;
    --surface: #162030;
    --border: #2a3a52;
    --text: #e4eaf2;
    --muted: #93a1b5;
    --accent: #5cb8d6;
    --accent-text: #0d131c;
    --danger: #f07a7a;
    --danger-text: #0d131c;
    --ok: #7bd36a;
    --warn: #f0b45a;
    --scope-bg: #0f1826;
    --scope-line: #5cb8d6;
    --scope-grid: #2a3a52;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d131c;
  --surface: #162030;
  --border: #2a3a52;
  --text: #e4eaf2;
  --muted: #93a1b5;
  --accent: #5cb8d6;
  --accent-text: #0d131c;
  --danger: #f07a7a;
  --danger-text: #0d131c;
  --ok: #7bd36a;
  --warn: #f0b45a;
  --scope-bg: #0f1826;
  --scope-line: #5cb8d6;
  --scope-grid: #2a3a52;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.top {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; }
.tag { font-weight: 500; font-size: 12px; color: var(--muted); margin-left: 4px; }
.who { color: var(--muted); font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .chip { margin-left: auto; }

main { max-width: 720px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 16px;
}
h1 { font-size: 20px; margin: 0 0 6px; }
h2 { font-size: 15px; margin: 0 0 10px; }
h2 small { font-weight: 400; color: var(--muted); margin-left: 6px; }

.actions { display: flex; gap: 10px; }
button {
  font: inherit;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: default; }
button.primary { flex: 1; background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.primary.danger { background: var(--danger); border-color: var(--danger); color: var(--danger-text); }
button[aria-pressed="true"] { background: var(--warn); border-color: var(--warn); color: #fff; }
button.quiet { min-height: 36px; margin-top: 12px; font-size: 14px; color: var(--muted); background: transparent; }

.peers { display: grid; gap: 12px; margin-top: 16px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .peers { grid-template-columns: 1fr 1fr; } }
.peer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 0;
}
.peer header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.peer header strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.level { height: 8px; border-radius: 4px; background: var(--scope-bg); overflow: hidden; }
.level .bar { height: 100%; width: 0; background: var(--ok); transition: width 60ms linear; }
.spectrum { display: block; width: 100%; height: 96px; margin-top: 8px; border-radius: 8px; background: var(--scope-bg); }

.chip {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.chip[data-state="connected"], .chip[data-state="in room"] { color: var(--ok); border-color: currentColor; }
.chip[data-state="failed"], .chip[data-state="denied"], .chip[data-state="error"] { color: var(--danger); border-color: currentColor; }

.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented button { flex: 1 1 auto; min-height: 44px; padding: 0 12px; }
.segmented button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.segmented button small { display: block; font-size: 11px; font-weight: 400; opacity: 0.85; }

.flags { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 12px; }
.flags label, label.test { display: flex; align-items: center; gap: 8px; min-height: 36px; }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }

.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.hint .off { color: var(--warn); font-weight: 600; }

.diag h3 { font-size: 14px; margin: 12px 0 4px; }
.diag h3:first-child { margin-top: 0; }
.diag dl { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 2px 12px; margin: 0; font-size: 13px; }
.diag dt { color: var(--muted); }
.diag dd { margin: 0; font: 12px/1.5 ui-monospace, monospace; overflow-wrap: anywhere; }

details { margin-top: 12px; }
summary { cursor: pointer; min-height: 32px; }
.log { margin: 6px 0 0; padding-left: 0; list-style: none; font: 12px/1.5 ui-monospace, monospace; max-height: 240px; overflow: auto; color: var(--muted); }
