:root {
  color-scheme: light dark;
  --bg: #f6f6f8;
  --panel: #ffffff;
  --text: #17171c;
  --muted: #6b6b76;
  --line: #e3e3ea;
  --accent: #3f5bd8;
  --accent-text: #ffffff;
  --mine: #3f5bd8;
  --theirs: #ffffff;
  --danger: #c4321c;
  --ok: #1f8a4c;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111116;
    --panel: #1b1b22;
    --text: #ececf1;
    --muted: #9a9aa6;
    --line: #2c2c36;
    --accent: #6d84ff;
    --mine: #3f55c9;
    --theirs: #22222b;
    --danger: #ff6b55;
    --ok: #46c27a;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
}

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

button {
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  padding: 0.55rem 1.1rem;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
button:disabled { opacity: 0.6; cursor: default; }
button.ghost { background: transparent; color: var(--muted); padding-inline: 0.6rem; }
button.danger { background: transparent; color: var(--danger); border: 1px solid currentColor; padding: 0.35rem 0.8rem; }

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

/* Login */

.login-page { display: grid; place-items: center; padding: 1rem; }

.login {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 2rem 1.5rem;
}
.login h1 { margin: 0; font-size: 1.75rem; }
.login .hint { margin: 0.25rem 0 1.5rem; color: var(--muted); }
.login form { display: flex; flex-direction: column; gap: 1rem; }
.login label { display: flex; flex-direction: column; gap: 0.35rem; font-weight: 600; font-size: 0.9rem; }
.login input {
  font-weight: 400;
  font-size: 1rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.login input:focus, .composer textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login button { margin-top: 0.5rem; padding-block: 0.7rem; }
.error { margin: 0; padding: 0.6rem 0.8rem; border-radius: 10px; background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

/* Chat */

.chat-page { display: flex; flex-direction: column; height: 100dvh; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.bar .title { display: flex; align-items: baseline; gap: 0.6rem; min-width: 0; }
.bar h1 { margin: 0; font-size: 1.15rem; }
.status { font-size: 0.8rem; color: var(--muted); }
.status.live { color: var(--ok); }
.actions { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.actions form { margin: 0; }
.me { font-size: 0.85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 12rem; }

.log { flex: 1; overflow-y: auto; padding: 1rem; }
.log ol { list-style: none; margin: 0 auto; padding: 0; max-width: 760px; display: flex; flex-direction: column; gap: 0.6rem; }
.older { display: block; margin: 0 auto 1rem; background: transparent; color: var(--accent); border: 1px solid var(--line); font-size: 0.85rem; }
.empty { text-align: center; color: var(--muted); margin-top: 3rem; }

.msg { max-width: min(80%, 560px); align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.meta { display: flex; gap: 0.5rem; font-size: 0.75rem; color: var(--muted); margin: 0 0.4rem 0.15rem; }
.msg.mine .meta { justify-content: flex-end; }
.who { font-weight: 600; }
.text {
  margin: 0;
  padding: 0.55rem 0.85rem;
  border-radius: 16px 16px 16px 4px;
  background: var(--theirs);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.mine .text { background: var(--mine); color: #fff; border-color: transparent; border-radius: 16px 16px 4px 16px; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 160px;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
}

@media (max-width: 480px) {
  .me { display: none; }
  .msg { max-width: 88%; }
}
