:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --text: #1f1d1a;
  --muted: #6b665d;
  --line: #ddd8cc;
  --accent: #7a3e2b;
  --mine: #f3e9e1;
  --mine-tint: #fbf6f2;
  --control: #8f877a;
  --on-accent: #ffffff;
  --warn: #a33a1f;
}
/* Dark tokens: from the OS unless the user picked Light, or when the user
   picked Dark. theme.js sets data-theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1816;
    --panel: #24211e;
    --text: #ece7de;
    --muted: #a39d92;
    --line: #3a3530;
    --accent: #d99a7c;
    --mine: #33281f;
    --mine-tint: #29231e;
    --control: #766e63;
    --on-accent: #1a1816;
    --warn: #f08a6a;
  }
}
:root[data-theme="dark"] {
  --bg: #1a1816;
  --panel: #24211e;
  --text: #ece7de;
  --muted: #a39d92;
  --line: #3a3530;
  --accent: #d99a7c;
  --mine: #33281f;
  --mine-tint: #29231e;
  --control: #766e63;
  --on-accent: #1a1816;
  --warn: #f08a6a;
}
:root { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark; } }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
input[type=checkbox] { width: auto; margin-top: 3px; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
h1 { font-size: 20px; margin: 0; color: var(--accent); letter-spacing: 0.02em; }
h2 { font-size: 15px; margin: 0 0 8px; }
#chat-name { font-size: 20px; }
h1 a { color: inherit; text-decoration: none; }
.head-right { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
#who { display: flex; gap: 12px; align-items: center; color: var(--muted); }
nav.pages { display: flex; gap: 12px; font-size: 14px; }
a { color: var(--accent); }
.theme-pick { display: flex; gap: 6px; align-items: center; margin: 0; font-size: 14px; color: var(--muted); }
select {
  font: inherit; font-size: 14px; color: var(--text); background: var(--bg);
  border: 1px solid var(--control); border-radius: 6px; padding: 3px 6px;
}
#flash { margin: 8px 16px 0; padding: 8px 12px; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; }
main { flex: 1; display: flex; gap: 16px; padding: 16px; min-height: 0; }
#signed-out { justify-content: center; align-items: flex-start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.narrow { max-width: 460px; width: 100%; }
.notice { background: var(--mine); border-radius: 6px; padding: 10px; font-size: 14px; }
.small { font-size: 13px; color: var(--muted); }
.warn { color: var(--warn); }
label { display: block; margin: 10px 0 4px; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
input, textarea {
  font: inherit; font-size: max(16px, 1em); color: var(--text); background: var(--bg);
  border: 1px solid var(--control); border-radius: 6px; padding: 7px 9px; width: 100%;
}
button {
  font: inherit; cursor: pointer; border: 1px solid var(--accent); background: var(--accent);
  color: var(--on-accent); border-radius: 6px; padding: 6px 12px;
}
button:disabled { opacity: 0.6; cursor: default; }
button.link { background: none; border: none; color: var(--accent); padding: 0; text-decoration: underline; }
#login-form button { margin-top: 12px; }
#sidebar { width: 280px; flex-shrink: 0; display: flex; flex-direction: column; gap: 18px; }
#sidebar form { display: flex; gap: 6px; margin-top: 6px; }
ul.spaces { list-style: none; margin: 0; padding: 0; }
ul.spaces li { margin: 2px 0; display: flex; flex-direction: column; }
button.space {
  background: none; border: 1px solid transparent; color: var(--text); text-align: left;
  padding: 5px 8px; width: 100%;
}
button.space:hover { border-color: var(--line); }
button.space.active { background: var(--mine); border-color: var(--line); }
#chat, #empty { flex: 1; min-width: 0; }
#chat { display: flex; flex-direction: column; min-height: 0; max-height: calc(100vh - 90px); }
.chat-head { display: flex; justify-content: space-between; align-items: baseline; }
#members { margin-bottom: 10px; }
#members ul { margin: 0 0 8px; padding-left: 18px; }
#add-form, .invite { display: flex; gap: 6px; }
#active { width: 200px; flex-shrink: 0; align-self: flex-start; }
#active h2 { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }
#active-list { list-style: none; margin: 0; padding: 0; }
#active-list li { padding: 7px 0; border-top: 1px solid var(--line); line-height: 1.3; }
#active-list li:first-child { border-top: none; padding-top: 0; }
#active-list .name { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
#active-list .name.did { font-size: 12px; font-weight: normal; color: var(--muted); }
#active-list .you { font-size: 13px; color: var(--muted); }
#active-list .rest { display: block; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.page { max-width: 680px; width: 100%; margin: 0 auto; line-height: 1.6; align-self: flex-start; }
.page h2 { font-size: 17px; margin: 20px 0 6px; }
.page h2:first-child { margin-top: 0; }
.page ul, .page ol { padding-left: 22px; }
.page li + li { margin-top: 4px; }
#messages {
  list-style: none; margin: 0; padding: 8px; flex: 1; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; min-height: 200px;
}
.msg {
  position: relative; padding: 6px 10px; margin-top: 10px; border-radius: 6px;
  border-left: 3px solid transparent;
}
.msg:first-child { margin-top: 0; }
.msg.cont { margin-top: 0; padding-top: 2px; }
.msg.mine { background: var(--mine-tint); border-left-color: var(--accent); }
.msg.mine.cont { border-top-left-radius: 0; border-top-right-radius: 0; }
.msg.mine:has(+ .msg.mine.cont) { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.msg-head { display: flex; gap: 10px; align-items: baseline; }
.author { font-weight: 600; font-size: 14px; }
.cont-time { position: absolute; top: 3px; right: 8px; opacity: 0; }
.msg.cont:hover .cont-time, .msg.cont:focus-within .cont-time { opacity: 1; }
.text {
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; line-height: 1.6; max-width: 72ch;
}
#messages li.empty-state {
  height: 100%; min-height: 180px; display: flex; align-items: center; justify-content: center;
}
#post-form { margin-top: 10px; }
.attach-row { display: flex; gap: 10px; align-items: center; min-width: 0; flex-wrap: wrap; }
label.attach {
  display: inline-block; margin: 0; cursor: pointer; color: var(--accent);
  border: 1px solid var(--accent); border-radius: 6px; padding: 4px 10px; font-size: 14px;
}
label.attach input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
label.attach:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.msg-file { margin-top: 4px; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reactions button {
  font-size: 14px; line-height: 1.2; padding: 2px 8px; border-radius: 12px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
}
.reactions button.mine { border-color: var(--accent); background: var(--mine); }
.reactions .react-add { color: var(--muted); padding: 1px 7px; display: inline-flex; align-items: center; }
.reactions .react-add:hover, .reactions .react-add:focus-visible { color: var(--accent); }
.reactions .react-add svg { display: block; }
.palette {
  position: absolute; z-index: 10; display: grid; grid-template-columns: repeat(8, 34px); gap: 2px;
  padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
.palette button {
  font-size: 20px; line-height: 1; padding: 6px 0; background: transparent; color: var(--text);
  border: 1px solid transparent; border-radius: 6px;
}
.palette button:hover, .palette button:focus { background: var(--mine); }
.palette button.mine { border-color: var(--accent); }
.msg-file img {
  display: block; max-width: min(100%, 360px); max-height: 280px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--bg);
}
.msg-file img[style*="aspect-ratio"] { height: auto; max-height: none; }
.file-caption { margin-top: 2px; overflow-wrap: anywhere; }
.msg-file a.pdf {
  display: inline-block; padding: 10px 14px; border: 1px solid var(--line); border-radius: 6px;
  color: var(--accent); background: var(--bg); overflow-wrap: anywhere; max-width: min(100%, 360px);
}
.file-preview { margin-top: 6px; }
#chat.dropping { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 6px; }
.file-preview img {
  display: block; max-width: min(100%, 240px); max-height: 160px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--bg);
}
#post-text { resize: none; overflow-y: auto; max-height: calc(8 * 1.45em + 16px); }
.post-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px 10px; margin-top: 6px; }
.post-actions { margin-left: auto; }
.post-actions { display: flex; align-items: center; gap: 10px; }
#post-note { margin: 6px 0 0; }
#post-note:empty { display: none; }
@media (max-width: 720px) {
  main { flex-direction: column; padding: 12px 16px; }
  #sidebar, #active { width: 100%; }
  header { flex-wrap: wrap; gap: 8px; }
  #chat { max-height: none; }
  #messages { max-height: 60vh; }
}
