:root {
  --bg: #ffffff;
  --bg-soft: #f5f6f8;
  --fg: #1f2328;
  --fg-dim: #616a75;
  --line: #e3e6ea;
  --bubble: #f1f3f5;
  --quote-line: #c6cbd2;
  --accent: #1a73e8;
  --chip: #e8f0fe;
  --chip-fg: #1558c0;
  --mention: #e8f0fe;
  --mention-fg: #1558c0;
  --code-bg: #f0f2f4;
  --max: 860px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c;
    --bg-soft: #1f2226;
    --fg: #e6e8ea;
    --fg-dim: #9aa2ac;
    --line: #2c3034;
    --bubble: #24282d;
    --quote-line: #3d444c;
    --accent: #7cadf5;
    --chip: #22334d;
    --chip-fg: #a8c7f7;
    --mention: #22334d;
    --mention-fg: #a8c7f7;
    --code-bg: #22262a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- header ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem max(1rem, calc((100vw - var(--max)) / 2));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.bar-left { display: flex; align-items: center; gap: .7rem; min-width: 0; }

.badge {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border-radius: 7px;
  background: #e8453c;
  color: #fff;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.bar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub { margin: 0; font-size: 12px; color: var(--fg-dim); }

.live { display: inline-flex; align-items: center; gap: .4rem; font-size: 12px; color: var(--fg-dim); }
.live i { width: 7px; height: 7px; border-radius: 50%; background: #1e8e3e; }
.live.stale i { background: #d93025; }
.live.syncing i { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- feed ---------- */

main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

.empty-state { color: var(--fg-dim); text-align: center; padding: 4rem 0; }

.day {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin: 1.6rem 0 .9rem;
  color: var(--fg-dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
}
.day::before, .day::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.thread { margin: 0 0 1.1rem; }

.msg { display: flex; gap: .7rem; padding: .15rem 0; }
.msg.compact { padding-top: 0; }
.msg.reply { margin-left: 1.6rem; border-left: 2px solid var(--line); padding-left: .9rem; }

.avatar {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--fg-dim);
  margin-top: .15rem;
  user-select: none;
}
.avatar.spacer { background: none; }

.body { min-width: 0; flex: 1; }

.meta { display: flex; align-items: baseline; gap: .5rem; margin-bottom: .05rem; }
.who { font-weight: 600; font-size: 14px; }
.meta time { font-size: 11.5px; color: var(--fg-dim); }

.text {
  background: var(--bubble);
  border-radius: 4px 14px 14px 14px;
  padding: .5rem .75rem;
  overflow-wrap: anywhere;
  max-width: 100%;
  width: fit-content;
}
.compact .text { border-radius: 14px; }
.text.muted { color: var(--fg-dim); background: none; padding-left: 0; }

.text a { color: var(--accent); text-decoration: none; }
.text a:hover { text-decoration: underline; }

.text code {
  background: var(--code-bg);
  border-radius: 4px;
  padding: .08em .35em;
  font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.text pre {
  background: var(--code-bg);
  border-radius: 8px;
  padding: .6rem .75rem;
  margin: .4rem 0;
  overflow-x: auto;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre;
}

.mention {
  background: var(--mention);
  color: var(--mention-fg);
  border-radius: 4px;
  padding: 0 .2em;
  font-weight: 500;
}

.quote {
  margin: .25rem 0;
  padding: .25rem 0 .25rem .7rem;
  border-left: 3px solid var(--quote-line);
  font-size: 13px;
  color: var(--fg-dim);
  display: flex;
  flex-direction: column;
  gap: .05rem;
}
.q-who { font-weight: 600; }
.q-text { overflow-wrap: anywhere; }

.reactions { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .3rem; }
.chip {
  background: var(--chip);
  color: var(--chip-fg);
  border-radius: 999px;
  padding: .1rem .5rem;
  font-size: 12px;
  line-height: 1.5;
}

.att-img { display: block; margin-top: .4rem; }
.att-img img {
  max-width: min(100%, 420px);
  border-radius: 10px;
  border: 1px solid var(--line);
  display: block;
}

.att-file {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  margin-top: .4rem;
  padding: .35rem .6rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  color: var(--fg);
  text-decoration: none;
}
.att-file:hover { border-color: var(--accent); }
.att-file.missing { color: var(--fg-dim); }
.clip { filter: grayscale(1); }

.edited { font-size: 11px; color: var(--fg-dim); margin-left: .2rem; }

/* ---------- footer ---------- */

.foot {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--fg-dim);
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  justify-content: space-between;
}
.dim { opacity: .8; }

@media (max-width: 560px) {
  .msg.reply { margin-left: .5rem; padding-left: .6rem; }
  .avatar { width: 28px; height: 28px; font-size: 12px; }
}

/* ---------- own messages sit right, like Chat ---------- */

.msg.mine { flex-direction: row-reverse; }
.msg.mine .body { display: flex; flex-direction: column; align-items: flex-end; }
.msg.mine .meta { flex-direction: row-reverse; }
.msg.mine .text {
  background: var(--chip);
  color: var(--fg);
  border-radius: 14px 4px 14px 14px;
}
.msg.mine.compact .text { border-radius: 14px; }
.msg.mine .quote { border-left: none; border-right: 3px solid var(--quote-line);
                   padding: .25rem .7rem .25rem 0; text-align: right; }
.msg.mine .avatar.spacer { display: none; }
