:root {
  --bg: #0f1419;
  --panel: #161c23;
  --panel-2: #1c242d;
  --line: #273140;
  --text: #e6edf3;
  --muted: #8b98a8;
  --faint: #5d6a7a;
  --accent: #3ddc97;
  --accent-ink: #062016;
  --accent-soft: rgba(61, 220, 151, 0.12);
  --private: #b39dff;
  --private-soft: rgba(179, 157, 255, 0.12);
  --mention: rgba(255, 196, 87, 0.14);
  --warn: #ffc457;
  --danger: #ff6b6b;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
  --people-w: 240px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.ok .dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.bad .dot { background: var(--danger); }
.wait .dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ------------------------------------------------------------- join -- */
.join {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    linear-gradient(transparent 31px, rgba(255,255,255,.025) 32px) 0 0 / 100% 32px,
    radial-gradient(1200px 500px at 50% -10%, rgba(61,220,151,.10), transparent 60%),
    var(--bg);
}
.join-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 30px 80px rgba(0,0,0,.35);
}
.brand { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 26px; }
.brand-mark {
  flex: none; width: 46px; height: 46px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
}
.brand-mark svg { width: 26px; height: 26px; stroke-width: 3; }
h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.tagline { margin: 2px 0 0; color: var(--muted); }

label { display: block; font-weight: 600; margin-bottom: 8px; }
.join-row { display: flex; gap: 8px; }
input, textarea {
  font: inherit; color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  min-width: 0;
}
input { flex: 1; font-family: var(--mono); }
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
#join-btn {
  border: 0; border-radius: 10px; padding: 0 18px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
#join-btn:disabled { opacity: .6; cursor: progress; }
.hint { margin: 6px 0 0; color: var(--faint); font-size: 13px; }
.error { margin: 10px 0 0; color: var(--danger); font-size: 14px; }

.status-strip {
  display: flex; align-items: center; gap: 8px;
  margin: 22px 0 0; padding: 10px 12px;
  border-radius: 10px; background: var(--panel-2);
  color: var(--muted); font-size: 13px; font-family: var(--mono);
}
.terminal-box { margin-top: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; }
.terminal-box summary { padding: 10px 0; cursor: pointer; color: var(--muted); font-size: 14px; }
.terminal-box p { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.terminal-box pre {
  margin: 0 0 10px; padding: 10px 12px; overflow-x: auto;
  background: var(--bg); border-radius: 8px; font: 13px/1.5 var(--mono); color: var(--accent);
}
.links { display: flex; gap: 8px; flex-wrap: wrap; }
.fine-print { margin: 18px 0 0; color: var(--faint); font-size: 12.5px; }

/* ------------------------------------------------------------- chat -- */
.chat {
  height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--people-w) 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "top top" "people messages" "people composer";
  position: relative;
}
.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.room { flex: 1; min-width: 0; }
.room h2 { margin: 0; font-size: 16px; }
.room-meta { margin: 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-meta .sep { margin: 0 6px; color: var(--faint); }
.conn {
  display: flex; align-items: center; gap: 7px;
  font: 12px var(--mono); color: var(--muted);
  padding: 6px 10px; border-radius: 999px; background: var(--panel-2);
}
.text-btn { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; color: var(--muted); }
.text-btn:hover { color: var(--text); border-color: var(--faint); }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 8px; position: relative; display: none; }
.badge {
  position: absolute; top: -2px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  font: 700 11px/18px var(--sans); text-align: center;
}

.people {
  grid-area: people;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 16px 10px;
  overflow-y: auto;
}
.people h3 { margin: 0 8px 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.people h3 span { color: var(--faint); }
.people ul { list-style: none; margin: 0; padding: 0; }
.people li button {
  width: 100%; text-align: left; background: none; border: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 8px;
}
.people li button:hover { background: var(--panel-2); }
.people li button[disabled] { cursor: default; }
.people li button[disabled]:hover { background: none; }
.avatar {
  flex: none; width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center;
  font: 700 12px var(--sans); color: #0b0f14;
}
.people .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.people .you { color: var(--faint); font-size: 12px; margin-left: auto; }
.people-hint { margin: 14px 8px 0; font-size: 12px; color: var(--faint); }
.scrim { display: none; }

.messages {
  grid-area: messages;
  overflow-y: auto;
  padding: 18px 20px 8px;
  display: flex; flex-direction: column;
  overscroll-behavior: contain;
}
.empty { margin: auto; color: var(--faint); }
.day { align-self: center; margin: 10px 0; font: 11.5px var(--mono); color: var(--faint); }

.msg { display: flex; gap: 10px; margin-top: 14px; max-width: 760px; }
.msg.cont { margin-top: 3px; }
.msg.cont .avatar { visibility: hidden; height: 0; }
.msg .body { min-width: 0; }
.msg .head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 2px; }
.msg.cont .head { display: none; }
.msg .who { font-weight: 650; font-size: 14px; }
.msg .time { font: 11px var(--mono); color: var(--faint); }
.msg .text {
  white-space: pre-wrap; overflow-wrap: anywhere;
  padding: 7px 12px; border-radius: 4px var(--radius) var(--radius) var(--radius);
  background: var(--panel-2); display: inline-block; max-width: 100%;
}
.msg.cont .text { border-radius: 4px var(--radius) var(--radius) 4px; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg.mine .head { justify-content: flex-end; }
.msg.mine .body { display: flex; flex-direction: column; align-items: flex-end; }
.msg.mine .text { background: var(--accent); color: var(--accent-ink); border-radius: var(--radius) 4px var(--radius) var(--radius); }
.msg.mine.cont .text { border-radius: var(--radius) 4px 4px var(--radius); }
.msg.private .text { background: var(--private-soft); color: var(--text); border: 1px dashed rgba(179,157,255,.45); }
.msg.private .who::after { content: " 🔒"; font-size: 11px; }
.msg .dm-label { font: 11px var(--mono); color: var(--private); }
.msg.mention .text { background: var(--mention); box-shadow: inset 3px 0 0 var(--warn); }
.msg.history { opacity: .72; }
.history-rule {
  align-self: stretch; display: flex; align-items: center; gap: 10px;
  margin: 16px 0 4px; color: var(--faint); font: 11px var(--mono);
}
.history-rule::before, .history-rule::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.sys {
  align-self: center; margin: 10px 0 2px; padding: 3px 10px;
  font: 12px var(--mono); color: var(--muted);
  border-radius: 999px; background: rgba(255,255,255,.03);
}
.sys.err { color: var(--danger); }
.sys.help { align-self: stretch; white-space: pre-wrap; border-radius: 10px; text-align: left; padding: 10px 14px; }

.jump {
  position: absolute; right: 24px; bottom: 96px;
  border: 0; border-radius: 999px; padding: 7px 14px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

.composer {
  grid-area: composer;
  padding: 8px 20px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.dm-chip {
  display: inline-flex; align-items: center; gap: 8px;
  margin-bottom: 8px; padding: 4px 6px 4px 12px;
  border-radius: 999px; background: var(--private-soft); color: var(--private); font-size: 13px;
}
.dm-chip button { background: none; border: 0; color: inherit; font-size: 18px; line-height: 1; padding: 0 6px; }
#send-form { display: flex; gap: 8px; align-items: flex-end; }
textarea { flex: 1; resize: none; max-height: 160px; line-height: 1.45; }
#send-btn {
  flex: none; width: 44px; height: 44px; border: 0; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
}
#send-btn svg { fill: currentColor; stroke-width: 1.2; }
#send-btn:disabled { opacity: .4; cursor: not-allowed; }
.composer-hint { display: flex; justify-content: space-between; gap: 12px; margin: 6px 2px 0; font-size: 11.5px; color: var(--faint); }
#counter.near { color: var(--warn); }

.toast {
  position: fixed; left: 50%; top: 70px; transform: translateX(-50%);
  padding: 9px 16px; border-radius: 10px; z-index: 30;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.4);
  max-width: calc(100% - 32px);
}

/* ------------------------------------------------------------- mobile -- */
@media (max-width: 760px) {
  .chat { grid-template-columns: 1fr; grid-template-areas: "top" "messages" "composer"; }
  .icon-btn { display: block; }
  .people {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 20;
    width: min(280px, 82vw);
    transform: translateX(-100%); transition: transform .2s ease;
    border-right: 1px solid var(--line);
  }
  .chat.people-open .people { transform: none; }
  .chat.people-open .scrim { display: block; position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.5); }
  .messages { padding: 12px 12px 6px; }
  .composer { padding-left: 12px; padding-right: 12px; }
  .composer-hint span:first-child { display: none; }
  .conn #conn-text { display: none; }
  .conn { padding: 8px; }
  .msg { max-width: 92%; }
  .jump { right: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
