:root {
  --bg: #0b0b0d;
  --panel: #151517;
  --panel-2: #1d1d20;
  --border: #2a2a2e;
  --text: #f5f5f6;
  --muted: #8b8b93;
  --ring: rgba(255, 255, 255, 0.14);
  --danger: #ff6b6b;
  --r: 16px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

/* Themed scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  background-clip: padding-box;
  border: 2px solid transparent;
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }

/* Motion — restrained entrances + smooth hovers.
   List entrances are gated behind .intro (set only on real changes, never on
   the background polls) so nothing flickers on refresh. */
@keyframes cardIn { from { opacity: 0; transform: translateY(10px) scale(0.99); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes riseIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes toastPop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.brand { animation: fadeIn 0.6s ease both; }
.card { animation: cardIn 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both; }

/* Revealed on select (their display toggles from none) */
.selected, .threadbar { animation: riseIn 0.26s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.compose { animation: riseIn 0.3s cubic-bezier(0.2, 0.7, 0.2, 1) both; }

/* Picker results animate on every keystroke — that's user-driven, so fine */
.results li { animation: riseIn 0.2s ease both; }
.results li:nth-child(2) { animation-delay: 26ms; }
.results li:nth-child(3) { animation-delay: 52ms; }
.results li:nth-child(4) { animation-delay: 78ms; }
.results li:nth-child(5) { animation-delay: 104ms; }
.results li:nth-child(6) { animation-delay: 130ms; }
.results li:nth-child(7) { animation-delay: 156ms; }
.results li:nth-child(8) { animation-delay: 182ms; }

/* Thread + notifications: only when the container is flagged .intro */
.thread.intro li { animation: riseIn 0.3s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.notifs.intro .notifs-head { animation: fadeIn 0.3s ease both; }
.notifs.intro .notif { animation: riseIn 0.24s ease both; }
.notifs.intro .notif:nth-of-type(2) { animation-delay: 34ms; }
.notifs.intro .notif:nth-of-type(3) { animation-delay: 68ms; }
.notifs.intro .notif:nth-of-type(4) { animation-delay: 102ms; }
.notifs.intro .notif:nth-of-type(5) { animation-delay: 136ms; }
.notifs.intro .notif:nth-of-type(6) { animation-delay: 170ms; }

.toast.pop { animation: toastPop 0.28s ease both; }

/* Smooth hovers in one place */
.results li, .notif, .chip button, .replies, .threadbar button {
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.wrap {
  width: 100%;
  max-width: 560px;
}

.brand {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 18px;
}
.brand b { color: var(--text); font-weight: 600; letter-spacing: 0.02em; }

/* Card */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

/* Inputs */
input[type="text"], textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font: inherit;
  padding: 14px 16px;
  resize: none;
}
input::placeholder, textarea::placeholder { color: var(--muted); }

.field {
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid transparent;
  transition: border-color 0.15s ease;
}
.field:focus-within { border-color: var(--ring); }

/* Notifications (unread summary) */
.notifs { padding: 4px; }
.notifs:empty { display: none; }
.notifs-head {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 6px 12px 8px;
}
.notif {
  all: unset;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--muted);
}
.notif:hover { background: var(--panel-2); color: var(--text); }
.notif-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--muted);
  flex: none;
}
.badge.mention {
  width: auto;
  height: auto;
  min-width: 18px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--text);
  color: #0b0b0d;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  line-height: 16px;
}

/* Recipient picker */
.picker { position: relative; }
.selected {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 14px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  font-weight: 500;
}
.chip button {
  all: unset;
  cursor: pointer;
  color: var(--muted);
  width: 20px;
  height: 20px;
  border-radius: 999px;
  text-align: center;
  line-height: 20px;
}
.chip button:hover { color: var(--text); background: var(--border); }

.results {
  list-style: none;
  margin: 6px 0 0;
  padding: 4px;
  max-height: 46vh;
  overflow-y: auto;
}
.results:empty { display: none; }
.results li {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
.results li .kind {
  color: var(--muted);
  font-size: 12px;
  margin-left: auto;
  text-transform: lowercase;
}
.results li[aria-selected="true"] { background: var(--panel-2); }

/* Message search results (full-text hits, below the name matches) */
.msg-results { padding: 4px; max-height: 46vh; overflow-y: auto; }
.msg-results:empty { display: none; }
.msg-results-head {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 8px 12px 6px;
}
.msg-result {
  all: unset;
  cursor: pointer;
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  border-radius: 10px;
}
.msg-result:hover { background: var(--panel-2); }
.msg-meta {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
  margin-bottom: 2px;
}
.msg-ch { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-who { color: var(--muted); }
.msg-at { color: var(--muted); margin-left: auto; flex: none; }
.msg-snippet {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  max-height: 2.9em;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-result:hover .msg-snippet { color: var(--text); }

/* Thread (recent history) */
.thread {
  display: none;
  list-style: none;
  margin: 8px 0 0;
  padding: 6px 6px 2px;
  max-height: 42vh;
  overflow-y: auto;
}
.thread.show { display: block; }
.thread li { padding: 7px 8px; border-radius: 10px; }
.thread .who {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 1px;
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.thread .who .at { color: var(--muted); font-weight: 400; font-size: 11px; }
.thread .body { white-space: pre-wrap; word-break: break-word; }
.thread .body a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--muted);
  text-underline-offset: 2px;
}
.thread .body a:hover { text-decoration-color: var(--text); }
/* Mentions & channel refs render as subtle tags; a mention of you stands out. */
.thread .body .mention {
  color: var(--text);
  background: var(--panel-2);
  border-radius: 5px;
  padding: 0 4px;
  font-weight: 500;
}
.thread .body .mention.me {
  color: #0b0b0d;
  background: var(--text);
}
/* Emphasis */
.thread .body strong { font-weight: 700; }
.thread .body em { font-style: italic; }
.thread .body s { color: var(--muted); }
.thread .body code.code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 5px;
}
.thread .body pre.codeblock {
  white-space: pre;
  overflow-x: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 6px 0;
}
.thread .body pre.codeblock code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: var(--text);
}
.thread li.mine .who { color: var(--text); }
/* The message you jumped to from search: a lingering marker plus a brief flash. */
@keyframes hitFlash { 0%, 12% { background: var(--ring); } 100% { background: transparent; } }
.thread li.hit {
  box-shadow: inset 2px 0 0 var(--text);
  animation: hitFlash 1.5s ease-out both;
}
.thread .empty { color: var(--muted); text-align: center; padding: 18px; font-size: 13px; }

/* Images — always on their own line, even without a preceding newline */
.thread .body a.img { display: block; width: fit-content; margin-top: 4px; }
.thread .body img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 10px;
  border: 1px solid var(--border);
  opacity: 0;
  transition: opacity 0.35s ease;
}
.thread .body img.loaded { opacity: 1; }

/* Reply / thread affordance */
.thread .replies {
  all: unset;
  cursor: pointer;
  display: inline-block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.thread .replies:hover { color: var(--text); border-color: var(--ring); }

.threadbar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 2px;
}
.threadbar-label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.threadbar button {
  all: unset;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.threadbar button:hover { color: var(--text); border-color: var(--ring); }

/* Message box */
.compose { margin-top: 10px; display: none; }
.compose textarea { min-height: 120px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 6px 4px;
}
.hint { color: var(--muted); font-size: 12.5px; }
kbd {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 6px;
  font: inherit;
  font-size: 12px;
  color: var(--text);
}

button.send {
  all: unset;
  cursor: pointer;
  background: var(--text);
  color: #0b0b0d;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 999px;
  transition: opacity 0.15s ease, transform 0.05s ease;
}
button.send:hover { opacity: 0.9; }
button.send:active { transform: translateY(1px); }
button.send:disabled { opacity: 0.4; cursor: default; }

.toast {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  min-height: 20px;
  margin-top: 14px;
}
.toast.err { color: var(--danger); }

/* Image lightbox — a fading, scaling overlay instead of navigating away */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: rgba(6, 6, 8, 0);
  cursor: zoom-out;
  transition: background-color 0.24s ease;
}
.lightbox.show { display: flex; }
.lightbox.open { background: rgba(6, 6, 8, 0.82); }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: scale(0.94);
  transition: opacity 0.24s ease, transform 0.26s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.lightbox.open img { opacity: 1; transform: none; }
.thread .body a.img { cursor: zoom-in; }

/* Setup page */
.setup label { display: block; color: var(--muted); font-size: 13px; margin: 14px 6px 6px; }
.setup .field { margin: 0; }
.setup textarea { min-height: 64px; word-break: break-all; }
.setup .actions { display: flex; justify-content: flex-end; padding: 14px 6px 6px; }
.setup .help {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
}
.setup .help code {
  color: var(--text);
  background: var(--bg);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 12px;
}
.setup .help ol { margin: 8px 0 0; padding-left: 18px; }
.setup .help li { margin: 6px 0; }
.setup .err { color: var(--danger); font-size: 13px; padding: 10px 6px 0; }
