/* Vellum — clean-modern theme. Light by default, dark via prefers-color-scheme
   or an explicit [data-theme] set by the header toggle. */

:root {
  --bg: #f7f7f9;
  --surface: #ffffff;
  --surface-2: #f1f2f6;
  --border: #e4e4ea;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-weak: #eef2ff;
  --accent-text: #4338ca;
  --code-bg: #f1f2f6;
  --mark-bg: #fde68a;
  --shadow: 0 1px 2px rgba(17, 24, 39, .06), 0 4px 12px rgba(17, 24, 39, .05);
  --radius: 12px;
  --radius-sm: 8px;
  /* Status colors (theme-aware) — used by admin badges/notices. */
  --ok: #15803d;
  --ok-weak: #dcfce7;
  --warn: #b45309;
  --warn-weak: #fef3c7;
  --danger: #b91c1c;
  --danger-weak: #fee2e2;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16171c;
    --surface: #1e2027;
    --surface-2: #262932;
    --border: #2e313b;
    --text: #e7e8ec;
    --muted: #9aa0ad;
    --accent: #8b87ff;
    --accent-weak: #262444;
    --accent-text: #c4c1ff;
    --code-bg: #14151a;
    --mark-bg: #7c6f2e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 18px rgba(0, 0, 0, .3);
    --ok: #4ade80;
    --ok-weak: #14352098;
    --warn: #fbbf24;
    --warn-weak: #3a2e0f98;
    --danger: #f87171;
    --danger-weak: #3a181898;
  }
}

[data-theme="dark"] {
  --bg: #16171c;
  --surface: #1e2027;
  --surface-2: #262932;
  --border: #2e313b;
  --text: #e7e8ec;
  --muted: #9aa0ad;
  --accent: #8b87ff;
  --accent-weak: #262444;
  --accent-text: #c4c1ff;
  --code-bg: #14151a;
  --mark-bg: #7c6f2e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 18px rgba(0, 0, 0, .3);
  --ok: #4ade80;
  --ok-weak: #14352098;
  --warn: #fbbf24;
  --warn-weak: #3a2e0f98;
  --danger: #f87171;
  --danger-weak: #3a181898;
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  line-height: 1.55;
}

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

/* ---- Header ----------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-header__inner {
  max-width: 880px;
  margin: 0 auto;
  padding: .7rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; color: var(--accent); }
.header-search { flex: 1; display: flex; min-width: 0; }
.header-search input {
  width: 100%;
  font: inherit;
  padding: .4rem .7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
}
.header-search input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.theme-toggle {
  flex: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.theme-toggle:hover { border-color: var(--accent); }

main { max-width: 880px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }

h1 { font-size: 1.5rem; letter-spacing: -0.02em; margin: .2rem 0 1rem; }

.muted { color: var(--muted); font-size: .85rem; }
.backlink { display: inline-block; margin-bottom: .5rem; }

/* ---- Channel list ----------------------------------------------------- */
.channel-group {
  font-size: .72rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: .08em; margin: 1.5rem 0 .4rem; font-weight: 600;
}
.channel-list { list-style: none; padding: 0; margin: 0; }
.channel-list li { margin: .15rem 0; }
.channel-list a {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .35rem .6rem; border-radius: var(--radius-sm);
  color: var(--text);
}
.channel-list a:hover { background: var(--surface-2); text-decoration: none; }
.channel-list .hash { color: var(--muted); }
.vc-icon { color: var(--muted); }
.badge {
  font-size: .65rem; background: var(--accent-weak); color: var(--accent-text);
  border-radius: 999px; padding: .1rem .45rem; margin-left: .35rem;
  vertical-align: middle; font-weight: 600;
}

/* ---- Messages --------------------------------------------------------- */
.messages { display: flex; flex-direction: column; gap: .2rem; }
.msg {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: .7rem;
  padding: .45rem .5rem;
  border-radius: var(--radius-sm);
}
.msg:hover { background: var(--surface-2); }
/* The message linked from a search hit (#m<id>): a left accent bar plus a brief
   flash so the eye lands on it. */
.msg:target {
  scroll-margin-top: 1rem;
  box-shadow: inset 3px 0 0 0 var(--accent);
  animation: msg-flash 1.6s ease-out 1;
}
@keyframes msg-flash {
  0% { background: var(--accent-weak); }
  100% { background: transparent; }
}
.msg__avatar {
  width: 40px; height: 40px; border-radius: 50%;
  object-fit: cover; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: var(--muted); font-size: .9rem; overflow: hidden;
}
.msg__body { min-width: 0; }
.msg__head { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.msg__author { font-weight: 600; color: var(--text); }
.msg__time { color: var(--muted); font-size: .78rem; }
.msg__content { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg__content p { margin: .25rem 0; }

.reply-quote {
  display: flex; align-items: center; gap: .4rem;
  font-size: .8rem; color: var(--muted); margin-bottom: .15rem;
}
.reply-quote::before {
  content: ""; width: 14px; height: 8px;
  border-left: 2px solid var(--border); border-top: 2px solid var(--border);
  border-top-left-radius: 6px; display: inline-block;
}
.reply-quote .reply-author { font-weight: 600; color: var(--muted); }

/* inline markdown bits */
.code-inline {
  background: var(--code-bg); padding: .08rem .35rem; border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em;
}
.code-block {
  background: var(--code-bg); padding: .7rem .9rem; border-radius: var(--radius-sm);
  overflow-x: auto; margin: .35rem 0;
}
.code-block code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }
.msg__content blockquote {
  margin: .2rem 0; padding: .1rem 0 .1rem .7rem;
  border-left: 3px solid var(--border); color: var(--muted);
}
.mention {
  background: var(--accent-weak); color: var(--accent-text);
  border-radius: 4px; padding: 0 .2rem; font-weight: 500;
}
.emoji { width: 1.35em; height: 1.35em; vertical-align: -0.25em; }
mark { background: var(--mark-bg); color: inherit; border-radius: 3px; padding: 0 .15rem; }

/* attachments */
.attachment-img {
  max-width: min(420px, 100%); max-height: 360px; height: auto;
  border-radius: var(--radius-sm); margin-top: .35rem; display: block;
  border: 1px solid var(--border);
}
.attachment-file {
  display: inline-flex; align-items: center; gap: .35rem;
  margin-top: .3rem; font-size: .85rem;
}

/* ---- Embeds ----------------------------------------------------------- */
.embed {
  margin-top: .4rem; max-width: 520px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm); padding: .6rem .8rem;
  box-shadow: var(--shadow);
}
.embed__author { display: flex; align-items: center; gap: .4rem; font-size: .82rem; font-weight: 600; }
.embed__author img { width: 20px; height: 20px; border-radius: 50%; }
.embed__title { font-weight: 700; margin: .2rem 0; }
.embed__desc { font-size: .9rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.embed__fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .4rem .8rem; margin: .45rem 0; }
.embed__field-name { font-weight: 600; font-size: .82rem; }
.embed__field-val { font-size: .85rem; color: var(--text); white-space: pre-wrap; }
.embed__img { max-width: 100%; border-radius: var(--radius-sm); margin-top: .45rem; }
.embed__thumb { float: right; max-width: 80px; max-height: 80px; border-radius: var(--radius-sm); margin: 0 0 .4rem .6rem; }
.embed__footer { display: flex; align-items: center; gap: .4rem; font-size: .75rem; color: var(--muted); margin-top: .45rem; }
.embed__footer img { width: 16px; height: 16px; border-radius: 50%; }

/* ---- Reactions -------------------------------------------------------- */
.reactions { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.reaction {
  display: inline-flex; align-items: center; gap: .25rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: .1rem .5rem; font-size: .8rem;
}
.reaction img { width: 1.1em; height: 1.1em; }

/* ---- Search ----------------------------------------------------------- */
.search-form { display: flex; gap: .5rem; margin: 0 0 1.25rem; }
.search-form input {
  flex: 1; font: inherit; padding: .55rem .8rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
}
.search-form input:focus { outline: none; border-color: var(--accent); }
.search-form button {
  font: inherit; font-weight: 600; padding: .55rem 1.1rem; cursor: pointer;
  border: none; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff;
}
.search-sort {
  display: flex; gap: 1rem; align-items: center;
  font-size: .85rem; color: var(--muted);
}
.search-sort input { width: auto; flex: none; }
.result {
  display: block; padding: .7rem .85rem; margin-bottom: .6rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
}
.result:hover { text-decoration: none; border-color: var(--accent); }
.search-count { font-size: .8rem; margin: 0 0 .6rem; }
.load-more {
  display: block; text-align: center; padding: .55rem; cursor: pointer;
  border: 1px dashed var(--border); border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 600;
}
.load-more:hover { text-decoration: none; border-color: var(--accent); color: var(--accent-text); }
.result__meta { font-size: .78rem; color: var(--muted); margin-top: .35rem; }
.result__channel { color: var(--accent-text); font-weight: 600; }

/* ---- Cards / empty / errors ------------------------------------------ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow);
}
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty__icon { font-size: 2rem; opacity: .7; }
.error-page { text-align: center; padding: 4rem 1rem; }
.error-page .code { font-size: 3.5rem; font-weight: 800; color: var(--accent); letter-spacing: -.03em; }

@media (max-width: 560px) {
  .msg { grid-template-columns: 32px 1fr; gap: .5rem; }
  .msg__avatar { width: 32px; height: 32px; }
}
