:root {
  color-scheme: light dark;
  --bg: #f6f5fb;
  --surface: #ffffff;
  --text: #1b1a26;
  --muted: #6b6980;
  --border: #e2e0ee;
  --accent: #6246ea;
  --accent-text: #ffffff;
  --in: #ebe9f5;
  --ok: #1f9d6b;
  --warn: #c2410c;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12111c;
    --surface: #1c1b2a;
    --text: #eeedf7;
    --muted: #9c99b5;
    --border: #2e2c42;
    --accent: #8b74ff;
    --accent-text: #12111c;
    --in: #27253a;
    --ok: #4ade80;
    --warn: #fb923c;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0 auto;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button, textarea, input { font: inherit; color: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 9px; }
.brand h1 { margin: 0; font-size: 1.15rem; line-height: 1.2; }
.brand p { margin: 0; font-size: 0.8rem; color: var(--muted); }

.toggle, .composer button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  white-space: nowrap;
}

.toggle[aria-pressed="true"] {
  background: transparent;
  color: var(--text);
  box-shadow: inset 0 0 0 1.5px var(--border);
}

button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px 10px;
}

.pill {
  flex: none;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--in);
  color: var(--muted);
}
.pill[data-state="listening"] { color: var(--ok); }
.pill[data-state="receiving"], .pill[data-state="sending"] { color: var(--accent); }

.meter {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--in);
  overflow: hidden;
}
#meter-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--accent);
  transition: width 80ms linear;
}

.roster {
  margin: 0;
  padding: 0 16px 10px;
  font-size: 0.8rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

#log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
}

.empty {
  margin: auto;
  max-width: 420px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}
.empty h2 { color: var(--text); font-size: 1.05rem; margin: 0 0 8px; }
.empty ol { padding-left: 1.2em; margin: 0 0 12px; }
.empty p { margin: 0; }

.msg {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 16px;
  background: var(--in);
  align-self: flex-start;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg b {
  display: block;
  font-size: 0.75rem;
  color: var(--accent);
}
.msg.out {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-text);
}
.msg.bad {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--border);
  color: var(--warn);
  font-size: 0.88rem;
}
.msg small {
  display: block;
  margin-top: 2px;
  font-size: 0.7rem;
  opacity: 0.75;
}
.msg[data-status="sending"], .msg[data-status="waiting"], .msg[data-status="retrying"] { opacity: 0.65; }
.msg[data-status="failed"] {
  background: transparent;
  color: var(--text);
  box-shadow: inset 0 0 0 1.5px var(--warn);
}
.msg[data-status="failed"] small { color: var(--warn); opacity: 1; font-weight: 600; }

.note {
  align-self: center;
  max-width: 90%;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.notice {
  margin: 0 16px 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1.5px var(--warn);
  font-size: 0.88rem;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px 4px;
  border-top: 1px solid var(--border);
}
.composer textarea, .composer input {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 7.5em;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 1rem;
  line-height: 1.35;
}
.count {
  flex: none;
  align-self: center;
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.count.over { color: var(--warn); font-weight: 600; }

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 16px 10px;
}
.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
}
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.link {
  border: 0;
  background: none;
  padding: 4px 8px;
  font-size: 0.78rem;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}
