:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --text: #1d1d1f;
  --muted: #7a7a7a;
  --line: #e3e1db;
  --mine: #2f6df6;
  --mine-text: #ffffff;
  --theirs: #ecebe7;
  --ok: #2bb24c;
  --warn: #d9822b;
  --fail: #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --panel: #1b1b1b;
    --text: #ececec;
    --muted: #9a9a9a;
    --line: #2e2e2e;
    --mine: #3b74f7;
    --theirs: #2a2a2a;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  justify-content: center;
}

.chat {
  width: 100%;
  max-width: 640px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-inline: 1px solid var(--line);
}

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
h1 { font-size: 18px; margin: 0; }
.status { font-size: 13px; color: var(--muted); }
.status[data-ok="1"]::before { content: "● "; color: var(--ok); }
.status[data-ok="0"]::before { content: "● "; color: var(--warn); }

.messages {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 16px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg p { margin: 0; }
.msg b { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.msg time { display: block; font-size: 11px; opacity: .65; text-align: right; margin-top: 2px; }
.mine { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 4px; }
.theirs { align-self: flex-start; background: var(--theirs); border-bottom-left-radius: 4px; }
.system { align-self: center; color: var(--muted); font-size: 13px; padding: 2px 8px; text-align: center; }
.msg a { color: inherit; }
.msg img, .msg video { display: block; max-width: 100%; max-height: 360px; border-radius: 10px; margin-top: 6px; }
.msg video { background: #000; }
.msg video.circle { width: 220px; height: 220px; max-height: none; border-radius: 50%; object-fit: cover; cursor: pointer; }
.msg audio { display: block; width: 280px; max-width: 100%; margin-top: 6px; }
.msg .file { display: inline-block; margin-top: 6px; text-decoration: underline; }
.bare { background: none; padding: 0; }
.bare time { padding-right: 6px; }
.card { margin-top: 6px; border-radius: 12px; overflow: hidden; background: var(--panel); border: 1px solid var(--line); }
.card img { margin: 0; border-radius: 0; width: 100%; max-height: 220px; object-fit: cover; }
.card .body { padding: 10px 12px; }
.card p { margin: 2px 0 0; color: var(--muted); }
.btn { display: inline-block; margin: 8px 6px 0 0; padding: 6px 12px; border-radius: 10px; border: 0; font: inherit;
       background: var(--mine); color: #fff !important; text-decoration: none; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--mine) !important; border: 1px solid var(--mine); }
.btn.light { background: #fff; color: #3a2357 !important; }
.btn:disabled { opacity: .5; cursor: default; }
.choices { margin-top: 4px; }
.choices span { font-size: 14px; color: var(--muted); }
.announce { padding: 14px; border-radius: 16px; background: linear-gradient(135deg, #2b1d4a, #6b2d5c); color: #fff; max-width: 320px; }
.announce small { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; opacity: .75; }
.announce h3 { margin: 4px 0 2px; font-size: 18px; }
.announce p { opacity: .85; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 2px; }
.chip { padding: 3px 8px; border-radius: 8px; background: rgba(255, 255, 255, .15); font-size: 13px; }
.pending { opacity: .6; }
.failed { background: var(--fail); cursor: pointer; }

.composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}
textarea {
  flex: 1;
  resize: none;
  font: inherit;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  max-height: 160px;
}
button {
  font: inherit;
  border: 0;
  border-radius: 12px;
  padding: 0 16px;
  background: var(--mine);
  color: #fff;
  cursor: pointer;
}
