* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--ground);
  color: var(--text);
}

body {
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--signature);
  color: var(--on-signature);
}

a { color: var(--signature-text); }

button, a, input, textarea, select {
  -webkit-tap-highlight-color: transparent;
}

button, .secondary-button, input, textarea, select {
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

button:not(:disabled):active { transform: translateY(1px); }

input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 1; }

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.hidden {
  display: none !important;
}

.app-loading {
  display: grid;
  min-height: 100vh;
  place-items: center;
  color: var(--text-muted);
}

/* A decoy field that people never see or reach; only form-filling bots fill it. */
/* "Continue with Google/Twitch" under the sign-in form. */
.sign-in-providers { display: grid; gap: 0.6rem; }
.sign-in-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.25rem 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.sign-in-divider::before,
.sign-in-divider::after { flex: 1; height: 1px; background: var(--line); content: ""; }

.provider-sign-up-note {
  display: grid;
  gap: 0.35rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: var(--raised);
}
.provider-sign-up-note p { margin: 0; }
.provider-sign-up-note .link-button {
  justify-self: start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--signature-text);
  font: inherit;
  font-size: 0.9rem;
  text-decoration: underline;
  cursor: pointer;
}

.registration-trap {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Attribution line at the end of each page. */
.powered-by {
  margin: 1.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: center;
}

.powered-by a {
  color: inherit;
}

/* The installation's documents (#160), when configured: 44px tall targets. */
.powered-by .footer-documents a { display: inline-block; padding-block: 0.75rem; font-weight: 600; }

/* A labelled theme selector, compact enough for the sidebar footer. */
.theme-select {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.theme-select select {
  width: auto;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  grid-template-rows: 1fr auto;
  gap: 2rem;
  padding: clamp(1.25rem, 5vw, 4rem);
  place-items: center;
  background: radial-gradient(ellipse at 10% 30%, color-mix(in srgb, var(--signature) 8%, transparent), transparent 65%);
}

.auth-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 27rem);
  align-items: center;
  gap: clamp(2rem, 7vw, 7rem);
  width: min(100%, 72rem);
}

.welcome-eyebrow {
  margin: 0 0 1.5rem;
  color: var(--signature-text);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.welcome-title {
  margin: 0;
  font-family: var(--display-font);
  font-size: clamp(2.7rem, 5vw, 4.5rem);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: var(--display-tracking);
}

.welcome-copy {
  max-width: 31rem;
  margin: 1.5rem 0 0;
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1.8;
}

.welcome-art { display: block; width: min(100%, 24rem); margin-top: 2rem; }
.art-orbit { stroke: var(--line); stroke-dasharray: 3 8; }
.art-bubble-back { fill: var(--raised); stroke: var(--line); }
.art-bubble-front { fill: var(--signature); }
.art-lines { stroke: var(--text-muted); stroke-width: 5; stroke-linecap: round; }
.art-dots { fill: var(--on-signature); }
.art-spark { stroke: var(--presence-text); stroke-width: 2; stroke-linecap: round; }

.auth-card {
  width: min(100%, 30rem);
  padding: clamp(1.5rem, 3vw, 2.5rem);
  border: 1px solid var(--line);
  border-radius: 1.75rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand {
  margin: 0;
  font-size: clamp(1.65rem, 4vw, 2.4rem);
  letter-spacing: -0.045em;
  overflow-wrap: anywhere;
}

.tagline {
  margin: 0.4rem 0 1.75rem;
  color: var(--text-muted);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
  padding: 0.3rem;
  border-radius: 0.9rem;
  background: var(--ground);
  margin-bottom: 1.5rem;
}

.auth-tabs button,
.secondary-button,
.room-button,
.join-button {
  border: 1px solid var(--field-line);
  border-radius: 0.75rem;
  background: var(--raised);
  color: var(--text);
}

.auth-tabs button {
  padding: 0.7rem;
  border-color: transparent;
  background: transparent;
}

.auth-tabs button[aria-selected="true"] {
  border-color: var(--field-line);
  background: var(--surface);
  box-shadow: 0 2px 5px var(--shadow-soft);
  color: var(--signature-text);
}

.form-stack {
  display: grid;
  gap: 1rem;
}

label {
  display: grid;
  gap: 0.4rem;
  color: var(--text-muted);
  font-size: 0.92rem;
}

/* A checkbox sits on the first line of its text; the label grid above would
   stack it on a line of its own. */
label:has(> input[type="checkbox"]) {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
}

input[type="checkbox"] {
  width: auto;
  flex: none;
  padding: 0;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--field-line);
  border-radius: 0.75rem;
  background: var(--ground);
  color: var(--text);
  padding: 0.8rem 0.9rem;
}

input:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid var(--signature-text);
  outline-offset: 2px;
}

.primary-button {
  border: 0;
  border-radius: 0.75rem;
  background: var(--signature);
  color: var(--on-signature);
  font-weight: 700;
  padding: 0.85rem 1rem;
  box-shadow: 0 3px 0 color-mix(in srgb, var(--signature-text) 60%, var(--ground));
}

.primary-button:hover:not(:disabled) { background: var(--signature-text); }

.secondary-button:hover:not(:disabled), .join-button:hover:not(:disabled) {
  border-color: var(--signature-text);
  background: color-mix(in srgb, var(--signature) 9%, var(--surface));
}

a.secondary-button { display: inline-block; text-decoration: none; text-align: center; }

.secondary-button,
.join-button {
  padding: 0.7rem 0.9rem;
}

.error-text {
  min-height: 1.4rem;
  margin: 0;
  color: var(--error);
}

/* The shell is exactly one viewport tall, so the message list scrolls inside
   it and the composer stays in view however long the conversation grows. */
.chat-shell {
  position: relative;
  --sidebar-width: 15.5rem;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  padding: 1rem;
  gap: 1rem;
}

.chat-shell.members-open { grid-template-columns: var(--sidebar-width) minmax(0, 1fr) 15rem; }

/* Maintenance lockdown: a notice on the sign-in card and a strip above the chat. */
.lockdown-notice {
  margin: 0 0 1rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid color-mix(in srgb, var(--unsure-line) 55%, var(--line));
  border-radius: 0.8rem;
  background: color-mix(in srgb, var(--unsure-line) 12%, var(--surface));
  color: var(--text);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.chat-shell > .lockdown-banner { grid-column: 1 / -1; margin: 0; }
.chat-shell:has(> .lockdown-banner:not(.hidden)) { grid-template-rows: auto minmax(0, 1fr); }

/* Sidebar: rooms and direct messages; on phones it becomes a drawer. */
.sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 0.25rem;
  padding-bottom: 0.5rem;
  overflow-y: auto;
  background: transparent;
}

/* Keep each section at its natural size; the sidebar scrolls as a whole instead. */
.sidebar > * {
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.65rem 1rem 1rem;
}

.brand-row { display: grid; gap: 0.1rem; min-width: 0; }

.sidebar-header h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.045em;
  overflow-wrap: anywhere;
}

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.15rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.connection-status::before {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--text-muted);
  content: "";
}

.connection-status[data-state="connected"]::before {
  background: var(--text-muted);
}

.connection-status[data-state="error"]::before {
  background: var(--error);
}

.nav-section { display: grid; gap: 0.15rem; }

.rooms-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0.75rem 0.65rem 0.25rem 1rem;
}

.rooms-heading {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rooms-heading-row .section-add {
  width: 1.75rem;
  height: 1.75rem;
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.15rem;
  text-decoration: none;
}

.rooms-heading-row .section-add:hover { background: var(--surface); color: var(--text); }

.room-list {
  display: grid;
  gap: 0.1rem;
  padding: 0 0.5rem;
}

.room-list > .room-meta { padding: 0.35rem 0.65rem; }

.room-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  border-color: transparent;
  border-radius: 0.65rem;
  background: transparent;
  color: var(--text-muted);
  text-align: left;
}

.room-button:hover { background: var(--surface); color: var(--text); }

.room-button.active {
  border-color: color-mix(in srgb, var(--signature-text) 30%, var(--field-line));
  background: color-mix(in srgb, var(--signature) 13%, var(--ground));
  color: var(--text);
  box-shadow: inset 3px 0 var(--signature-text);
}

.room-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-hash { color: var(--text-muted); font-weight: 500; }
.room-button.active .room-hash { color: var(--signature-text); }

.room-flag {
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 650;
  white-space: nowrap;
}

.room-flag.invited { border-color: var(--presence-text); color: var(--presence-text); }
.room-lock { flex: none; width: 0.85rem; height: 0.85rem; color: var(--text-muted); }

.room-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.dm-list { display: grid; gap: 0.1rem; margin: 0; padding: 0 0.5rem; list-style: none; }
.dm-list > .room-meta { padding: 0.35rem 0.65rem; }

.dm-button {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.65rem;
  border-radius: 0.65rem;
  color: var(--text-muted);
  text-decoration: none;
}

.dm-button:hover { background: var(--surface); color: var(--text); }
.dm-button.unread { color: var(--text); font-weight: 700; }
.dm-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.unread-count {
  min-width: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--signature);
  color: var(--on-signature);
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1.35rem;
  text-align: center;
}

.all-conversations {
  margin: 0.2rem 0.5rem 0;
  padding: 0.35rem 0.65rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  text-decoration: none;
}

.all-conversations:hover { color: var(--text); }

/* Small round initials, shared by direct messages, members, and the account menu. */
.mini-avatar {
  position: relative;
  display: inline-grid;
  flex: none;
  width: 1.75rem;
  height: 1.75rem;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--raised);
  color: var(--signature-text);
  font-size: 0.62rem;
  font-weight: 750;
  letter-spacing: 0.03em;
}

.mini-avatar[data-tone="1"] { color: var(--presence-text); background: color-mix(in srgb, var(--presence) 10%, var(--surface)); }
.mini-avatar[data-tone="2"] { color: var(--text); background: color-mix(in srgb, var(--signature) 15%, var(--surface)); }
.mini-avatar[data-tone="3"] { color: var(--text-muted); }

.mini-avatar.online::after {
  position: absolute;
  right: -0.3rem;
  bottom: -0.2rem;
  width: 0.55rem;
  height: 0.55rem;
  border: 2px solid var(--ground);
  border-radius: 50%;
  background: var(--text-muted);
  content: "";
}

.mini-avatar.idle::after { background: var(--unsure-line); }

/* A profile picture covers the initials once it has loaded; the online dot stays on top. */
.avatar-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
  opacity: 0;
}

.has-photo > .avatar-photo { opacity: 1; }
.mini-avatar.online::after { z-index: 1; }
.user-button { position: relative; }

/* Search sits in the top bar on wide screens and in the drawer on phones. */
.chat-shell .drawer-search,
.chat-shell .drawer-close,
.chat-shell .drawer-toggle,
.chat-shell .drawer-backdrop { display: none; }

/* ---- Members panel ---- */
.members-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow-y: auto;
}

.members-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0.75rem 0.75rem 1.1rem;
  border-bottom: 1px solid var(--line);
}

.members-panel h2 { margin: 0; font-size: 0.95rem; }

.members-panel h3 {
  margin: 1rem 1.1rem 0.4rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.member-list { display: grid; gap: 0.1rem; margin: 0; padding: 0 0.5rem 1rem; list-style: none; }
.member-list > .room-meta { padding: 0.35rem 0.6rem; }

.member-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  border-radius: 0.65rem;
}

.member-name { flex: 1; min-width: 0; overflow: hidden; font-size: 0.9rem; text-overflow: ellipsis; white-space: nowrap; }
.member-note { color: var(--text-muted); font-size: 0.72rem; white-space: nowrap; }

.chat-shell .close-button {
  width: 2rem;
  height: 2rem;
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
}

.chat-shell .close-button:hover { background: var(--raised); color: var(--text); }

/* ---- Top bar actions and popovers ---- */
.header-actions { display: flex; flex: none; align-items: center; gap: 0.3rem; }

.header-button {
  position: relative;
  display: inline-flex;
  min-width: 2.5rem;
  height: 2.5rem;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0 0.6rem;
  border: 1px solid transparent;
  border-radius: 0.8rem;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 650;
  text-decoration: none;
}

.header-button:hover,
.header-button[aria-expanded="true"],
.header-button[aria-pressed="true"] {
  border-color: var(--field-line);
  background: var(--raised);
  color: var(--text);
}

.header-badge {
  position: absolute;
  top: 0.2rem;
  right: 0.15rem;
  min-width: 1.05rem;
  height: 1.05rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: var(--signature);
  color: var(--on-signature);
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1.05rem;
  text-align: center;
}

.header-divider { width: 1px; height: 1.5rem; margin: 0 0.35rem; background: var(--line); }

.user-button {
  width: 2.5rem;
  height: 2.5rem;
  margin-left: 0.25rem;
  padding: 0;
  border: 2px solid var(--signature-text);
  border-radius: 50%;
  background: color-mix(in srgb, var(--signature) 18%, var(--surface));
  /* Persimmon text on its own tint is under 4.5:1 in dark; the ring carries the colour. */
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.popover-anchor { position: relative; }

.popover {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.5rem);
  right: 0;
  display: grid;
  width: 19rem;
  max-height: calc(100dvh - 6rem);
  padding: 0.4rem;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: 0 18px 48px var(--shadow-strong);
}

#notifications-popover { width: 22rem; }

.popover hr { width: 100%; margin: 0.3rem 0; border: 0; border-top: 1px solid var(--line); }

.popover-identity { display: flex; align-items: center; gap: 0.7rem; padding: 0.7rem 0.7rem 0.8rem; }
.popover-identity .mini-avatar { width: 2.4rem; height: 2.4rem; font-size: 0.75rem; }
.popover-identity > div { min-width: 0; }
.popover-identity strong { display: block; overflow: hidden; text-overflow: ellipsis; }
.popover-identity span[aria-hidden] { color: var(--text-muted); font-size: 0.8rem; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.7rem;
  border: 0;
  border-radius: 0.6rem;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  text-align: left;
  text-decoration: none;
}

.menu-item:hover { background: var(--raised); }
.menu-item svg { flex: none; width: 1.05rem; height: 1.05rem; color: var(--text-muted); }
.danger-item, .danger-item svg { color: var(--error); }

.menu-group { display: grid; gap: 0.45rem; margin: 0; padding: 0.55rem 0.7rem 0.7rem; border: 0; }

.menu-group-label {
  padding: 0;
  margin-bottom: 0.45rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 0.2rem;
  border: 1px solid var(--field-line);
  border-radius: 0.7rem;
  background: var(--ground);
}

.segmented label {
  display: block;
  position: relative;
  padding: 0.35rem 0;
  border-radius: 0.5rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented label:has(input:checked) {
  background: var(--raised);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 1px 0 var(--field-line);
}

.segmented label:has(input:focus-visible) { outline: 2px solid var(--signature-text); outline-offset: 1px; }

.menu-group .menu-switch {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  cursor: pointer;
}

/* Colour-scheme picker: a swatch per scheme, each a radio button. */
.scheme-picker { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.scheme-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.scheme-option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.scheme-swatch {
  display: inline-block;
  flex: none;
  width: 1.6rem;
  height: 1.6rem;
  border: 2px solid var(--field-line);
  border-radius: 50%;
}

.scheme-option:has(input:checked) .scheme-swatch { outline: 2px solid var(--signature-text); outline-offset: 2px; }
.scheme-option:has(input:focus-visible) .scheme-swatch { outline: 3px solid var(--text); outline-offset: 2px; }
.scheme-option:has(input:checked) .scheme-name { font-weight: 700; }


.popover .powered-by { margin: 0.3rem 0 0.2rem; padding: 0 0.7rem; text-align: left; }

.popover-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0.7rem 0.4rem;
}

.popover-title h2 { margin: 0; font-size: 0.95rem; }

.text-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--signature-text);
  font-size: 0.8rem;
}

.text-button:hover { text-decoration: underline; }

.notification-preview { display: grid; gap: 0.1rem; margin: 0; padding: 0; list-style: none; }
.notification-preview > .room-meta { padding: 0.6rem 0.7rem; }

.notification-item {
  display: grid;
  gap: 0.15rem;
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 0;
  border-radius: 0.6rem;
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  text-align: left;
  text-decoration: none;
}

a.notification-item:hover { background: var(--raised); }
.notification-item.unread { background: color-mix(in srgb, var(--signature) 9%, var(--surface)); }
.notification-item strong { font-weight: 700; }
.notification-item span { color: var(--text-muted); }
.notification-item time { color: var(--text-muted); font-size: 0.75rem; }

/* A username that opens the name menu; it reads as text until hovered. */
.user-name {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-weight: inherit;
  text-align: inherit;
}

.user-name:hover { text-decoration: underline; text-underline-offset: 0.15em; }
button.user-name.mention { padding: 0 0.2rem; border-radius: 0.25rem; background: var(--presence-wash); color: var(--text); font-weight: 600; }

.popover.name-menu {
  position: fixed;
  z-index: 50;
  right: auto;
  width: 17rem;
  max-height: calc(100dvh - 1rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.name-menu-actions { display: grid; }

/* The profile card behind every name. */
.profile-head { align-items: center; padding: 0.8rem 0.7rem; }
.profile-head > div { display: grid; gap: 0.2rem; justify-items: start; }
.profile-head strong { font-size: 1.05rem; overflow-wrap: anywhere; }
.popover-identity .mini-avatar.profile-avatar { width: 3.5rem; height: 3.5rem; font-size: 0.95rem; }
.profile-badge {
  padding: 0.05rem 0.5rem;
  border: 1px solid color-mix(in srgb, var(--signature-text) 45%, var(--line));
  border-radius: 999px;
  color: var(--signature-text);
  font-size: 0.72rem;
  font-weight: 700;
}
.name-menu .profile-meta { color: var(--text-muted); font-size: 0.8rem; }
.name-menu-status { margin: 0.2rem 0.7rem 0.5rem; color: var(--text-muted); font-size: 0.82rem; }
/* The card's Moderation part: a labelled group per scope. */
.name-menu-moderation, .name-menu-group { display: grid; }
.name-menu-moderation hr { width: 100%; margin: 0.35rem 0; border: 0; border-top: 1px solid var(--line); }
.name-menu-group-label {
  margin: 0.3rem 0.7rem 0.15rem;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.name-menu .popover-identity span { color: var(--text-muted); font-size: 0.8rem; }

.name-menu-backdrop {
  position: fixed;
  z-index: 45;
  inset: 0;
  background: var(--scrim);
}

.popover-footer {
  padding: 0.55rem 0.7rem;
  color: var(--signature-text);
  font-size: 0.85rem;
  text-decoration: none;
}

.chat-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: var(--ground);
  box-shadow: var(--shadow);
}

.room-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1rem 0.9rem 2rem;
  border-bottom: 1px solid var(--line);
  border-radius: 1.5rem 1.5rem 0 0;
  background: var(--surface);
}

.room-heading { flex: 1; }

.room-heading h2,
.room-heading p {
  margin: 0;
}

.room-heading h2 {
  font-family: var(--display-font);
  font-size: 1.65rem;
  font-weight: 400;
  letter-spacing: var(--display-tracking);
}
.room-header > .room-heading { min-width: 0; overflow-wrap: anywhere; }

.room-heading p {
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.empty-state {
  display: grid;
  padding: 2rem;
  place-items: center;
  color: var(--text-muted);
  text-align: center;
  align-content: center;
  gap: 1.5rem;
  font-family: var(--display-font);
  font-size: 1.65rem;
}

.empty-state::before {
  content: "";
  width: 4rem;
  height: 3rem;
  margin: auto;
  border: 2px solid var(--signature-text);
  border-radius: 1.25rem 1.25rem 1.25rem 0.25rem;
  background: color-mix(in srgb, var(--signature) 8%, transparent);
  box-shadow: 0.75rem -0.75rem 0 var(--raised);
}

.message-list {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 1.5rem;
  padding: 2rem clamp(1rem, 3vw, 3rem);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.message {
  position: relative;
  display: grid;
  gap: 0.35rem;
  width: 100%;
  max-width: 56rem;
  padding-left: 3.25rem;
  margin-inline: auto;
  min-height: 2.5rem;
  flex-shrink: 0;
}

.message-avatar {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  width: 2.4rem;
  height: 2.4rem;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 0.9rem 0.9rem 0.35rem 0.9rem;
  background: var(--raised);
  color: var(--signature-text);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.04em;
}
.message-avatar[data-tone="1"] { color: var(--presence-text); background: color-mix(in srgb, var(--presence) 10%, var(--surface)); }
.message-avatar[data-tone="2"] { color: var(--text); background: color-mix(in srgb, var(--signature) 15%, var(--surface)); }
.message-avatar[data-tone="3"] { color: var(--text-muted); border-radius: 50%; }

.message-header {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.message-author {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.message-time {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.message-body {
  margin: 0;
  line-height: 1.7;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

/* Message formatting: links, `code`, code blocks and > quotes. */
.message-link { overflow-wrap: anywhere; }
.message-code,
.message-codeblock {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.9em;
  border: 1px solid var(--line);
  background: var(--raised);
}
.message-code { padding: 0.05rem 0.35rem; border-radius: 0.35rem; }
.message-codeblock {
  margin: 0.35rem 0;
  padding: 0.6rem 0.8rem;
  border-radius: 0.6rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
/* The general code pill style must not apply inside a block. */
.message-codeblock code {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  font: inherit;
}
.message-quote {
  margin: 0.35rem 0;
  padding: 0.1rem 0 0.1rem 0.8rem;
  border-left: 3px solid var(--signature-text);
  color: var(--text-muted);
}

/* Unread rooms in the sidebar, the divider above the first unread message,
   and the way back down after scrolling up. */
.room-button.unread { color: var(--text); font-weight: 700; }
.new-messages-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--signature-text);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.new-messages-divider::before,
.new-messages-divider::after { flex: 1; height: 1px; background: var(--signature); content: ""; }
.jump-latest {
  position: absolute;
  top: -3.25rem;
  left: 50%;
  z-index: 2;
  padding: 0.5rem 1rem;
  border: 1px solid var(--field-line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transform: translateX(-50%);
  white-space: nowrap;
}
.jump-latest:hover { border-color: var(--signature-text); }

/* "Alex is typing…": one quiet line above the composer, its space always kept. */
.typing-indicator {
  min-height: 1.3rem;
  margin: 0 0 0.35rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

/* A message from someone this account ignores, collapsed to one line. */
.message.ignored-message {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-style: italic;
}
.ignored-message .link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--signature-text);
  font: inherit;
  font-style: normal;
  text-decoration: underline;
  cursor: pointer;
}

/* A neutral room notice ("Alex was muted in this room for 1 hour.") and the
   message box of someone who is muted. */
.message.room-notice { display: block; text-align: center; }
.room-notice p {
  display: inline-block;
  margin: 0;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  background: var(--raised);
  color: var(--text-muted);
  font-size: 0.88rem;
}
.muted-notice {
  display: grid;
  gap: 0.25rem;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--raised);
}
.muted-notice span { color: var(--text-muted); font-size: 0.9rem; }

/* A ping: a private notice between its sender and target. */
.message.ping-notice {
  padding-top: 0.55rem;
  padding-bottom: 0.65rem;
  padding-right: 0.9rem;
  border: 1px solid color-mix(in srgb, var(--presence-text) 45%, var(--line));
  border-radius: 1rem;
  background: color-mix(in srgb, var(--presence) 9%, var(--ground));
}

.message.ping-notice .ping-icon {
  top: 0.45rem;
  left: 0.45rem;
  width: 2rem;
  height: 2rem;
  border-color: color-mix(in srgb, var(--presence-text) 45%, var(--line));
  border-radius: 50%;
  background: color-mix(in srgb, var(--presence) 16%, var(--surface));
  font-size: 0.95rem;
}

.ping-label { color: var(--presence-text); font-size: 0.75rem; font-weight: 700; }
.ping-text { font-style: italic; }

.message.emote .message-body {
  color: var(--signature-text);
  font-style: italic;
}

.message.deleted .message-body {
  color: var(--text-muted);
  font-style: italic;
}

.message-reply-button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  padding: 0.25rem 0.4rem;
  border-radius: 0.4rem;
  text-decoration: none;
  text-underline-offset: 0.15rem;
}

.message-reply-button:hover,
.message-reply-button:focus-visible {
  color: inherit;
  background: var(--raised);
}

.reply-preview {
  display: flex;
  width: 100%;
  gap: 0.4rem;
  align-items: baseline;
  max-width: 52rem;
  margin: 0 0 0.15rem;
  padding: 0.3rem 0.6rem;
  border: 0;
  border-left: 3px solid var(--line);
  border-radius: 0.3rem;
  background: var(--raised);
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

.reply-preview:hover {
  border-left-color: var(--signature-text);
}

.reply-preview-author {
  font-weight: 700;
  flex-shrink: 0;
}

.reply-preview-excerpt {
  min-width: 0;
  overflow: hidden;
  color: var(--text-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-preview-unavailable {
  color: var(--text-muted);
  font-style: italic;
  cursor: default;
}

.mention {
  border-radius: 0.25rem;
  padding: 0 0.2rem;
  background: var(--presence-wash);
  color: var(--text);
  font-weight: 600;
}

.reaction-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.3rem;
}

.reaction-button {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border: 1px solid var(--field-line);
  border-radius: 1rem;
  min-height: 1.8rem;
  padding: 0.15rem 0.6rem;
  background: var(--raised);
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.reaction-button:hover,
.reaction-button:focus-visible {
  border-color: var(--signature-text);
}

.reaction-button-active {
  border-color: var(--signature-text);
  background: var(--presence-wash);
  color: var(--text);
}

.reaction-button-count {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.reaction-button-active .reaction-button-count {
  color: inherit;
}

.reaction-add-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border: 1px solid var(--field-line);
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  line-height: 1;
}

.reaction-add-button:hover,
.reaction-add-button:focus-visible {
  color: var(--text);
  border-color: var(--signature-text);
}

.reaction-picker {
  display: flex;
  flex-basis: 100%;
  gap: 0.25rem;
  margin-top: 0.2rem;
}

.reaction-picker[hidden] {
  display: none;
}

.reaction-picker-option {
  border: 1px solid var(--field-line);
  border-radius: 0.3rem;
  padding: 0.1rem 0.4rem;
  background: var(--raised);
  cursor: pointer;
  font-size: 0.95rem;
}

.reaction-picker-option:hover,
.reaction-picker-option:focus-visible {
  border-color: var(--signature-text);
}

.mention-broadcast {
  background: var(--presence-wash);
  color: var(--text);
}

.reply-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
  padding: 0.4rem 0.7rem;
  border-radius: 0.4rem;
  background: color-mix(in srgb, var(--signature-text) 12%, var(--surface));
  font-size: 0.85rem;
  min-width: 0;
}

.reply-banner span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-banner-cancel {
  flex-shrink: 0;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  text-decoration: underline;
  text-underline-offset: 0.15rem;
}

.reply-banner-cancel:hover,
.reply-banner-cancel:focus-visible {
  color: inherit;
}

.mention-autocomplete {
  position: fixed;
  z-index: 20;
  max-height: 14rem;
  margin: 0 0 0.3rem;
  padding: 0.3rem;
  overflow-y: auto;
  scroll-padding-block: 0.3rem; /* the active option scrolls into view clear of the edge */
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: var(--raised);
  box-shadow: var(--shadow);
}

.mention-autocomplete-option {
  padding: 0.4rem 0.6rem;
  border-inline-start: 3px solid transparent;
  border-radius: 0.4rem;
  cursor: pointer;
}

/* The option Enter or Tab would pick (keyboard, or the pointer hovering it).
   It gets an accent wash and, so it never depends on colour alone, an accent
   bar at the start edge (--signature-text, at least 3:1 against the list). */
.mention-autocomplete-option.active {
  border-inline-start-color: var(--signature-text);
  background: color-mix(in srgb, var(--signature) 16%, var(--raised));
  color: var(--text);
}
:root[data-scheme="contrast"] .mention-autocomplete-option.active {
  outline: 2px solid var(--text);
  outline-offset: -2px;
}

/* The "/" command list and the /help dialog. */
.command-option {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.75rem;
}
.command-option span { color: var(--text-muted); font-size: 0.85rem; }
.command-option.active span { color: inherit; }
/* Six commands at most, so the list grows to fit instead of scrolling. */
.command-suggestions { max-height: none; overflow-y: visible; }
.command-help {
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 1.25rem;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: var(--surface);
  color: inherit;
  box-shadow: var(--shadow);
}
.command-help::backdrop { background: var(--scrim); }
.command-help h2,
.command-help h3 { margin: 0 0 0.75rem; }
.command-help h3 { margin-top: 1.25rem; font-size: 1rem; }
.command-help-list {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.5rem 1rem;
  margin: 0;
}
.command-help-list dd { margin: 0; color: var(--text-muted); }
.command-help-note { margin: 1.25rem 0; color: var(--text-muted); font-size: 0.9rem; }
@media (max-width: 30rem) {
  .command-help-list { grid-template-columns: minmax(0, 1fr); gap: 0.2rem; }
  .command-help-list dd { margin-bottom: 0.5rem; }
}

.composer-wrap {
  position: relative;
  min-width: 0;
  padding: 0.75rem clamp(1rem, 3vw, 3rem) 1.25rem;
  border-radius: 0 0 1.5rem 1.5rem;
  background: var(--ground);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
  max-width: 56rem;
  margin-inline: auto;
  padding: 0.65rem;
  border: 1px solid var(--field-line);
  border-radius: 1.25rem;
  background: var(--surface);
  box-shadow: 0 5px 20px var(--shadow-soft);
}

.composer:focus-within { border-color: var(--signature-text); }
.composer .primary-button { min-height: 3rem; margin-right: 0.2rem; }

.composer textarea {
  min-height: 3rem;
  max-height: 10rem;
  resize: vertical;
  border-color: transparent;
  background: transparent;
}

.composer-help {
  max-width: 56rem;
  margin: 0.65rem auto 0;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.composer-wrap > .reply-banner { max-width: 56rem; margin-inline: auto; }

.toast-region {
  position: fixed;
  z-index: 10;
  top: 1rem;
  right: 1rem;
  display: grid;
  width: min(24rem, calc(100vw - 2rem));
  gap: 0.6rem;
}

.toast {
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: var(--raised);
  box-shadow: var(--shadow);
}

.toast code {
  white-space: nowrap;
}

.toast.error {
  border-color: var(--error);
}

/* Too narrow for a third column: the members panel overlays the chat. */
@media (max-width: 64rem) {
  .chat-shell.members-open { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }

  .chat-shell.members-open .members-panel {
    position: absolute;
    z-index: 15;
    top: 1rem;
    right: 1rem;
    bottom: 1rem;
    width: 16rem;
  }
}

@media (max-width: 48rem) {
  .auth-layout { grid-template-columns: minmax(0, 28rem); justify-content: center; gap: 2rem; }
  .auth-intro { text-align: center; }
  .welcome-eyebrow { margin-bottom: 0.75rem; }
  .welcome-title { font-size: 2.7rem; }
  .welcome-copy, .welcome-art { display: none; }

  .chat-shell {
    --sidebar-width: 13rem;
    padding: 0.5rem;
    gap: 0.5rem;
  }

  .room-header { padding: 0.75rem 0.75rem 0.75rem 1rem; }
  .room-heading p { display: none; }
}


@media (max-width: 34rem) {
  .auth-shell { padding: 1.25rem; gap: 1rem; }
  .welcome-title { font-size: 2.2rem; }
  .auth-card { padding: 1.35rem; border-radius: 1.25rem; }
  .chat-shell,
  .chat-shell.members-open {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
    gap: 0;
    padding: 0;
  }

  .chat-shell:has(> .lockdown-banner:not(.hidden)) { grid-template-rows: auto minmax(0, 1fr); }
  .chat-shell > .lockdown-banner { border-radius: 0; border-width: 0 0 1px; font-size: 0.8rem; }

  /* The sidebar is a drawer behind the menu button. */
  .sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    width: min(20rem, 86vw);
    padding-bottom: 1rem;
    border-right: 1px solid var(--line);
    background: var(--ground);
    box-shadow: 0 0 60px var(--shadow-strong);
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }

  .chat-shell.drawer-open .sidebar {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease;
  }

  .chat-shell.drawer-open .drawer-backdrop,
  .chat-shell.members-open .drawer-backdrop,
  .chat-shell.sheet-open .drawer-backdrop {
    position: fixed;
    z-index: 25;
    inset: 0;
    display: block;
    background: var(--scrim);
  }

  .chat-shell.sheet-open .drawer-backdrop { z-index: 35; }

  .chat-shell .drawer-close, .chat-shell .drawer-toggle { display: inline-flex; }
  .sidebar-header { padding: 0.9rem 0.75rem 0.5rem 1.1rem; }
  .room-button { padding: 0.65rem 0.75rem; font-size: 0.95rem; }
  .dm-button { padding: 0.55rem 0.75rem; }

  .chat-shell .drawer-search {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0.25rem 0.75rem;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--field-line);
    border-radius: 0.8rem;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.9rem;
    text-decoration: none;
  }

  .room-header { gap: 0.35rem; padding: 0.5rem 0.5rem 0.5rem 0.4rem; border-radius: 0; }
  .room-heading h2 { overflow: hidden; font-size: 1.25rem; text-overflow: ellipsis; white-space: nowrap; }
  .header-actions { gap: 0.1rem; }
  .header-button { min-width: 2.75rem; height: 2.75rem; padding: 0 0.45rem; }
  .header-divider, .header-search { display: none; }
  .user-button { width: 2.4rem; height: 2.4rem; }
  .join-button { padding: 0.45rem 0.7rem; font-size: 0.85rem; }

  /* Members and the menus open as sheets from the bottom. */
  .chat-shell.members-open .members-panel {
    position: fixed;
    z-index: 30;
    inset: auto 0 0 0;
    top: auto;
    width: auto;
    max-height: 70dvh;
    border-radius: 1.25rem 1.25rem 0 0;
    box-shadow: 0 -12px 48px var(--shadow-strong);
  }

  .popover,
  #notifications-popover {
    position: fixed;
    z-index: 40;
    inset: auto 0 0 0;
    width: auto;
    max-height: 80dvh;
    padding: 0.5rem 0.5rem max(0.75rem, env(safe-area-inset-bottom));
    border-radius: 1.25rem 1.25rem 0 0;
  }

  .menu-item { padding: 0.75rem 0.8rem; }
  .popover.name-menu { inset: auto 0 0 0; width: auto; }

  .message-list { padding: 1.25rem 0.85rem; }
  .message { padding-left: 2.65rem; }
  .message-avatar { width: 2rem; height: 2rem; border-radius: 0.7rem; font-size: 0.65rem; }
  .message-header { gap: 0.3rem 0.5rem; }
  .message-time { font-size: 0.68rem; }
  .composer-wrap { padding: 0.5rem 0.65rem max(0.75rem, env(safe-area-inset-bottom)); }
  .composer { padding: 0.4rem; gap: 0.35rem; }
  .composer .primary-button { padding-inline: 0.8rem; }
  .composer-help { font-size: 0.65rem; }

  .chat-main {
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .composer-wrap { border-radius: 0; }
}

