:root {
  color-scheme: dark;
  --ink: #ecf0e9;
  --muted: #98a59d;
  --paper: #090e0c;
  --panel: #111815;
  --line: #29332e;
  --forest: #245c49;
  --acid: #d8f24b;
  --rust: #ff8c70;
  --body-glow: rgb(216 242 75 / 9%);
  --body-start: #070b09;
  --body-end: #101813;
  --glass: rgb(17 24 21 / 92%);
  --input: #0b110e;
  --sidebar: #070c0a;
  --sidebar-text: #d4ddd7;
  --sidebar-muted: #8fa097;
  --sidebar-hover: rgb(255 255 255 / 7%);
  --focused-ink: #193f32;
  --message-hover: #151e1a;
  --message-text: #dce3de;
  --timestamp: #849188;
  --link: #8fd8bd;
  --media: #0b110e;
  --embed: #18211d;
  --shadow: 0 18px 50px rgb(0 0 0 / 35%);
}

:root[data-theme="light"] {
  color-scheme: light;
  --ink: #18201c;
  --muted: #66716a;
  --paper: #f4f1e8;
  --panel: #fffdf7;
  --line: #d9d4c6;
  --forest: #193f32;
  --rust: #b84b2f;
  --body-glow: rgb(216 242 75 / 24%);
  --body-start: #eee9dc;
  --body-end: #e8e3d5;
  --glass: rgb(255 253 247 / 88%);
  --input: #ffffff;
  --sidebar: #193f32;
  --sidebar-text: #ced8d2;
  --sidebar-muted: #9eb1a7;
  --sidebar-hover: rgb(255 255 255 / 8%);
  --focused-ink: #193f32;
  --message-hover: #f7f3e9;
  --message-text: #29312d;
  --timestamp: #879089;
  --link: #236854;
  --media: #ebe8de;
  --embed: #eeece3;
  --shadow: 0 18px 50px rgb(30 39 34 / 12%);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 15%, var(--body-glow), transparent 27rem),
    linear-gradient(135deg, var(--body-start) 0%, var(--paper) 58%, var(--body-end) 100%);
  font-family: "Trebuchet MS", "Gill Sans", sans-serif;
  transition: color .2s ease, background-color .2s ease;
}

button, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.eyebrow, .nav-label, .panel-kicker {
  margin: 0;
  color: var(--muted);
  font-size: .69rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.login-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.login-card {
  position: relative;
  width: min(100%, 28rem);
  padding: clamp(2rem, 7vw, 4rem);
  border: 1px solid var(--line);
  border-radius: 2px 2px 38px 2px;
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  animation: arrive .45s ease-out both;
}

.login-card h1, .brand-block h1 {
  margin: .3rem 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.7rem, 9vw, 4.6rem);
  font-weight: 400;
  letter-spacing: -.07em;
  line-height: .95;
}

.login-intro { color: var(--muted); line-height: 1.55; margin: 1.3rem 0 2rem; }
.login-card form { display: grid; gap: 1rem; }
.login-card label { display: grid; gap: .45rem; font-size: .78rem; font-weight: 800; }
.login-card input {
  width: 100%;
  padding: .9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--input);
  outline: none;
}
.login-card input:focus { border-color: var(--forest); box-shadow: 0 0 0 3px rgb(25 63 50 / 12%); }
.login-card button {
  margin-top: .35rem;
  padding: .95rem 1.1rem;
  border: 0;
  border-radius: 7px;
  color: white;
  background: var(--forest);
  font-weight: 800;
}
.form-error { min-height: 1.1rem; margin: 0; color: var(--rust); font-size: .8rem; }
.theme-toggle { white-space: nowrap; }
.login-theme-toggle {
  position: absolute;
  top: 1rem;
  right: 1rem;
  margin: 0 !important;
  padding: .45rem .65rem !important;
  border: 1px solid var(--line) !important;
  color: var(--muted) !important;
  background: transparent !important;
  font-size: .7rem;
}

.app-shell { height: 100%; display: grid; grid-template-columns: 17rem minmax(0, 1fr); }
.sidebar {
  z-index: 5;
  min-height: 0;
  display: flex;
  flex-direction: column;
  color: #f7f4e9;
  background: var(--sidebar);
  box-shadow: 8px 0 30px rgb(17 36 29 / 12%);
}
.brand-block { padding: 1.5rem 1.4rem 1.25rem; display: flex; align-items: start; justify-content: space-between; }
.brand-block .eyebrow { color: var(--sidebar-muted); }
.brand-block h1 { font-size: 2.25rem; letter-spacing: -.05em; }
.connection-state { margin-top: .15rem; color: var(--acid); font-size: .65rem; font-weight: 800; text-transform: uppercase; }
.sidebar nav { min-height: 0; flex: 1; overflow-y: auto; padding: .8rem; }
.nav-label { padding: 0 .6rem .7rem; color: var(--sidebar-muted); }
.channel-list { display: grid; gap: .25rem; }
.channel-button {
  width: 100%;
  display: grid;
  grid-template-columns: 1rem minmax(0, 1fr) auto;
  gap: .55rem;
  align-items: center;
  padding: .72rem .65rem;
  border: 0;
  border-radius: 8px;
  color: var(--sidebar-text);
  background: transparent;
  text-align: left;
}
.channel-button:hover, .channel-button.is-open { color: white; background: var(--sidebar-hover); }
.channel-button.is-focused { color: var(--focused-ink); background: var(--acid); }
.channel-hash { opacity: .6; font-weight: 800; }
.channel-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.channel-count {
  min-width: 1.35rem;
  padding: .14rem .36rem;
  border-radius: 999px;
  color: var(--focused-ink);
  background: var(--acid);
  font-size: .65rem;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
}
.channel-button.is-focused .channel-count { background: var(--focused-ink); color: var(--acid); }
.sidebar-footer { padding: 1rem 1.35rem; display: flex; gap: .75rem; align-items: center; justify-content: space-between; border-top: 1px solid rgb(255 255 255 / 10%); font-size: .75rem; }
.text-button { padding: 0; border: 0; color: var(--acid); background: none; }

.workspace-shell { min-width: 0; min-height: 0; position: relative; display: flex; flex-direction: column; }
.workspace {
  min-width: 0;
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--panel-count, 1), minmax(20rem, 1fr));
  gap: 1px;
  overflow-x: auto;
  background: var(--line);
}
.chat-panel { min-width: 20rem; min-height: 0; position: relative; display: flex; flex-direction: column; background: var(--panel); }
.chat-panel.is-focused { box-shadow: inset 0 3px var(--acid); }
.panel-header { min-height: 5.25rem; padding: 1.15rem 1.4rem; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.panel-title { margin: .2rem 0 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.55rem; font-weight: 400; }
.icon-button { width: 2rem; height: 2rem; border: 1px solid var(--line); border-radius: 50%; color: inherit; background: transparent; }
.panel-close { display: none; }
.message-scroller { min-height: 0; flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 1rem 0 2rem; }
.history-state { padding: 1rem 1.4rem; color: var(--muted); font-size: .8rem; text-align: center; }
.message-list { margin: 0; padding: 0; list-style: none; }
.message { display: grid; grid-template-columns: 2.55rem minmax(0, 1fr); gap: .8rem; padding: .78rem 1.4rem; animation: reveal .24s ease-out both; }
.message:hover { background: var(--message-hover); }
.avatar { width: 2.55rem; height: 2.55rem; border-radius: 12px 12px 12px 3px; object-fit: cover; background: var(--media); }
.avatar-fallback { display: grid; place-items: center; color: white; background: var(--forest); font-family: Georgia, serif; font-size: 1.1rem; }
.message-meta { display: flex; gap: .55rem; align-items: baseline; min-width: 0; }
.author { font-size: .9rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timestamp { color: var(--timestamp); font-size: .68rem; white-space: nowrap; }
.message-content { margin-top: .18rem; color: var(--message-text); font-size: .9rem; line-height: 1.48; overflow-wrap: anywhere; white-space: pre-wrap; }
.message-content a, .embed a, .attachment-link { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.attachment-image, .embed-image { display: block; max-width: min(100%, 34rem); max-height: 28rem; margin-top: .65rem; border-radius: 8px; object-fit: contain; background: var(--media); }
.attachment-image.is-expandable, .embed-image.is-expandable { cursor: zoom-in; }
.attachment-image.is-expandable:focus-visible, .embed-image.is-expandable:focus-visible { outline: 3px solid var(--acid); outline-offset: 3px; }
.attachment-link { display: inline-block; margin-top: .45rem; font-size: .78rem; }
.embed { max-width: 34rem; margin-top: .6rem; padding: .75rem .9rem; border-left: 3px solid var(--forest); border-radius: 0 7px 7px 0; background: var(--embed); font-size: .82rem; line-height: 1.45; }
.embed-title { margin: 0 0 .3rem; font-weight: 800; }
.embed-description { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.new-message-pill { position: absolute; right: 1.2rem; bottom: 1.2rem; padding: .55rem .85rem; border: 0; border-radius: 999px; color: white; background: var(--forest); box-shadow: var(--shadow); font-size: .76rem; font-weight: 800; }
.add-panel { position: absolute; right: 1.2rem; top: 1.25rem; z-index: 3; padding: .55rem .8rem; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); font-size: .75rem; font-weight: 800; }
.mobile-bar { display: none; }

.image-lightbox {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 1rem;
  background: rgb(3 7 5 / 92%);
  backdrop-filter: blur(12px);
  animation: lightbox-in .18s ease-out both;
  cursor: zoom-out;
  contain: strict;
}
.lightbox-image {
  display: block;
  width: auto;
  height: auto;
  max-width: calc(100vw - 2rem);
  max-height: calc(100dvh - 2rem);
  flex: 0 1 auto;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 24px 80px rgb(0 0 0 / 55%);
  cursor: default;
}
body.lightbox-open { overflow: hidden; }
.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 1;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid rgb(255 255 255 / 30%);
  border-radius: 50%;
  color: white;
  background: rgb(0 0 0 / 45%);
  font-size: 1.5rem;
  line-height: 1;
}

@keyframes arrive { from { opacity: 0; transform: translateY(14px); } }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } }
@keyframes lightbox-in { from { opacity: 0; } }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(85vw, 20rem); transform: translateX(-105%); transition: transform .22s ease; }
  .sidebar.is-open { transform: translateX(0); }
  .mobile-bar { min-height: 3.5rem; padding: .65rem 1rem; display: flex; align-items: center; justify-content: space-between; background: var(--panel); border-bottom: 1px solid var(--line); }
  .workspace { grid-template-columns: repeat(var(--panel-count, 1), minmax(100vw, 1fr)); scroll-snap-type: x mandatory; }
  .chat-panel { min-width: 100vw; scroll-snap-align: start; }
  .message { padding-inline: 1rem; }
  .panel-header { padding-inline: 1rem; }
  .add-panel { display: none; }
  .image-lightbox { padding: .5rem; }
  .lightbox-image { max-width: calc(100vw - 1rem); max-height: calc(100dvh - 1rem); }
}

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