:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --mine: #d7f2ee;
  --theirs: #ffffff;
  --border: #e3e5e9;
  --error: #b42318;
  --radius: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --text: #eceef2;
    --muted: #9aa1ad;
    --accent: #2dd4bf;
    --accent-text: #062b27;
    --mine: #134e48;
    --theirs: #1f232b;
    --border: #2a2f38;
    --error: #f97066;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

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

a { color: var(--accent); overflow-wrap: anywhere; }

.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--error); margin: 0; }

/* ---- join ---- */

.join {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.join-card {
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.join-card h1 { margin: 0; font-size: 1.5rem; }
.join-card p { margin: 0; }
.join-card label { display: grid; gap: 6px; font-weight: 600; font-size: 0.9rem; }

.join-card input, .join-card select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-weight: 400;
  font-size: 1rem;
}

.join-card button {
  padding: 13px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
}

/* ---- chat ---- */

.chat {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.me { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.me strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.link {
  border: 0;
  background: none;
  color: var(--accent);
  padding: 6px 0;
  cursor: pointer;
}

.messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 16px;
}

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.older {
  display: block;
  margin: 0 auto 12px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.msg {
  max-width: 85%;
  align-self: flex-start;
  background: var(--theirs);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  padding: 8px 12px;
}

.msg.mine {
  align-self: flex-end;
  background: var(--mine);
  border-color: transparent;
  border-radius: var(--radius);
  border-bottom-right-radius: 4px;
}

.author { font-size: 0.8rem; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg time { display: block; text-align: right; font-size: 0.7rem; color: var(--muted); margin-top: 2px; }

.status {
  margin: 0;
  padding: 6px 16px;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 160px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  /* 16px keeps iOS from zooming into the field */
  font-size: 16px;
}

.composer button {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.1rem;
  cursor: pointer;
}

.composer button:disabled { opacity: 0.5; }

/* ---- rooms ---- */

.code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.join-card button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.join-card button:disabled { opacity: 0.6; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--border);
}

.room { display: flex; align-items: center; gap: 12px; flex: none; }

.pill {
  padding: 6px 12px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}

/* ---- participant colors: each message carries its author's --hue ---- */

:root {
  --bubble-s: 75%;
  --bubble-l: 93%;
  --bubble-border-l: 82%;
  --name-s: 65%;
  --name-l: 32%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bubble-s: 32%;
    --bubble-l: 20%;
    --bubble-border-l: 30%;
    --name-s: 80%;
    --name-l: 72%;
  }
}

.msg, .msg.mine {
  background: hsl(var(--hue, 200) var(--bubble-s) var(--bubble-l));
  border-color: hsl(var(--hue, 200) var(--bubble-s) var(--bubble-border-l));
}

.author { color: hsl(var(--hue, 200) var(--name-s) var(--name-l)); }

/* ---- who is here, join notices ---- */

.online {
  margin: 0;
  padding: 6px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.person {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  color: hsl(var(--hue, 200) var(--name-s) var(--name-l));
}

.person::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: hsl(var(--hue, 200) 70% 50%);
}

.notice {
  align-self: center;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 2px 10px;
}

.notice strong { color: hsl(var(--hue, 200) var(--name-s) var(--name-l)); }

.ai-notice {
  margin: 0;
  padding: 6px 16px;
  font-size: 0.8rem;
  color: var(--text);
  background: hsl(45 95% 88%);
  border-bottom: 1px solid hsl(45 70% 75%);
}

@media (prefers-color-scheme: dark) {
  .ai-notice { background: hsl(45 40% 18%); border-color: hsl(45 35% 28%); }
}

.join-card .ai-notice { border: 0; border-radius: 10px; padding: 8px 12px; }
