:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #10131a;
  --surface: #181d27;
  --surface-2: #222938;
  --border: #30394b;
  --text: #f3f5f8;
  --muted: #aeb7c7;
  --accent: #7da7ff;
  --accent-strong: #a8c3ff;
  --danger: #ff8f8f;
  --success: #8fe0ae;
  --warning: #f2c14e;
  --shadow: 0 18px 50px rgb(0 0 0 / 0.25);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
}

button,
input,
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(--muted);
}

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

.auth-card {
  width: min(100%, 30rem);
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3.25rem);
  letter-spacing: -0.05em;
}

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

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

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

.auth-tabs button {
  padding: 0.7rem;
}

.auth-tabs button[aria-selected="true"] {
  border-color: var(--accent);
  color: var(--accent-strong);
}

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

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

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

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

.primary-button {
  border: 0;
  border-radius: 0.75rem;
  background: var(--accent);
  color: #0b1323;
  font-weight: 700;
  padding: 0.85rem 1rem;
}

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

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

/* 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 {
  display: grid;
  grid-template-columns: 18rem minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

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

.sidebar-header,
.sidebar-footer {
  padding: 1rem;
}

.sidebar-header {
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  margin: 0;
  font-size: 1.35rem;
}

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

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

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

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

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

.room-list {
  display: grid;
  gap: 0.35rem;
  padding: 0 0.65rem 1rem;
  overflow-y: auto;
}

.room-button {
  display: grid;
  gap: 0.15rem;
  padding: 0.75rem;
  text-align: left;
}

.room-button.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2));
}

.room-name {
  font-weight: 650;
}

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

.sidebar-footer {
  display: grid;
  gap: 0.75rem;
  margin-top: auto;
  border-top: 1px solid var(--border);
}

.current-user {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

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

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

.empty-state {
  display: grid;
  padding: 2rem;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.message-list {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 0.8rem;
  padding: 1.25rem;
  overflow-y: auto;
}

.message {
  display: grid;
  gap: 0.2rem;
  max-width: 52rem;
}

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

.message-author {
  font-weight: 700;
}

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

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

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

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

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

.message-reply-button:hover,
.message-reply-button:focus-visible {
  color: inherit;
}

.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(--border);
  border-radius: 0.3rem;
  background: var(--surface-2);
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

.reply-preview:hover {
  border-left-color: var(--accent-strong);
}

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

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

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

.mention {
  border-radius: 0.25rem;
  padding: 0 0.2rem;
  background: #364056;
  color: #dbe6ff;
  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(--border);
  border-radius: 1rem;
  padding: 0.1rem 0.5rem;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

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

.reaction-button-active {
  border-color: var(--accent);
  background: #2a3550;
  color: #dbe6ff;
}

.reaction-button-count {
  font-variant-numeric: tabular-nums;
  color: var(--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(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  line-height: 1;
}

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

.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(--border);
  border-radius: 0.3rem;
  padding: 0.1rem 0.4rem;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 0.95rem;
}

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

.mention-broadcast {
  background: #433e3b;
  color: #ffe0b2;
}

.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(--accent-strong) 12%, var(--surface));
  font-size: 0.85rem;
}

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

.reply-banner-cancel {
  flex-shrink: 0;
  border: 0;
  background: transparent;
  color: var(--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;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: var(--surface-2);
  box-shadow: var(--shadow);
}

.mention-autocomplete-option {
  padding: 0.4rem 0.6rem;
  border-radius: 0.4rem;
  cursor: pointer;
}

.mention-autocomplete-option.active {
  background: #3f4b64;
}

.composer-wrap {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
}

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

.composer-help {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.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(--border);
  border-radius: 0.8rem;
  background: var(--surface-2);
  box-shadow: var(--shadow);
}

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

@media (max-width: 48rem) {
  .chat-shell {
    grid-template-columns: 8.5rem minmax(0, 1fr);
  }

  .room-meta,
  .current-user-label {
    display: none;
  }

  .sidebar-header h1 {
    font-size: 1.05rem;
  }
}

@media (max-width: 34rem) {
  .chat-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    max-height: 45dvh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .room-list {
    display: flex;
    overflow-x: auto;
  }

  .room-button {
    min-width: 8rem;
  }

  .sidebar-footer {
    display: none;
  }

  .chat-main {
    min-height: 0;
  }
}
