:root {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #141a22;
  --surface-raised: #1a222d;
  --surface-soft: #10151c;
  --border: #29323e;
  --border-strong: #3a4655;
  --text: #f5f7fa;
  --muted: #98a2b3;
  --subtle: #687386;
  --accent: #e50914;
  --accent-hover: #ff2731;
  --accent-soft: rgba(229, 9, 20, 0.14);
  --green: #2ed573;
  --warning: #f7b731;
  --danger: #ff4757;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.34);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

button {
  color: inherit;
}

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

[hidden] {
  display: none !important;
}

.chat-shell {
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.chat-view {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.join-view {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 28px;
  background: var(--bg);
}

.join-brand {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border: 1px solid rgba(229, 9, 20, 0.7);
  border-radius: 8px;
  background: var(--accent);
  box-shadow: 0 10px 28px rgba(229, 9, 20, 0.2);
  font-size: 24px;
  font-weight: 900;
}

.join-heading {
  margin-bottom: 24px;
}

.eyebrow,
.chat-title p {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
}

.join-heading h1,
.dialog-header h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
}

.entry-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 20px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-soft);
}

.entry-tab {
  min-height: 38px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.entry-tab.is-active {
  background: var(--surface-raised);
  color: var(--text);
}

.entry-form,
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.entry-form label,
.settings-form label {
  color: #c7ced8;
  font-size: 12px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0b0f14;
  color: var(--text);
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  padding: 10px 12px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #5f6b7a;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 42px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  margin-top: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary-button:hover,
.send-button:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.secondary-button {
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
}

.danger-button {
  width: 100%;
  margin-top: 12px;
  border: 1px solid rgba(255, 71, 87, 0.5);
  background: rgba(255, 71, 87, 0.09);
  color: #ff8c96;
}

.form-error {
  margin: 14px 0 0;
  color: #ff9aa3;
  font-size: 13px;
  line-height: 1.45;
}

.chat-view {
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

.chat-header {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.96);
  flex: 0 0 auto;
  z-index: 5;
}

.chat-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(229, 9, 20, 0.12);
}

.chat-title p {
  margin-bottom: 1px;
  font-size: 9px;
}

.chat-title h1 {
  overflow: hidden;
  margin: 0;
  font-size: 14px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.presence {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 6px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #cbd3dd;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.presence:hover {
  background: var(--surface-raised);
}

.presence-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
}

.icon-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 17px;
}

.icon-button:hover {
  border-color: var(--border);
  background: var(--surface-raised);
  color: var(--text);
}

.connection-state {
  flex: 0 0 auto;
  min-height: 24px;
  padding: 5px 12px;
  border-bottom: 1px solid var(--border);
  background: #111720;
  color: var(--warning);
  font-size: 11px;
  text-align: center;
}

.connection-state.is-connected {
  display: none;
}

.notice {
  flex: 0 0 auto;
  padding: 9px 12px 10px;
  border-bottom: 1px solid rgba(229, 9, 20, 0.24);
  background: var(--accent-soft);
}

.notice-label,
.section-label {
  display: block;
  margin-bottom: 3px;
  color: #ff747b;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.notice p {
  margin: 0;
  color: #f2d8da;
  font-size: 12px;
  line-height: 1.4;
}

.pinned-section {
  flex: 0 0 auto;
  max-height: 66px;
  overflow: hidden;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}

.pinned-messages {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.pinned-messages::-webkit-scrollbar {
  display: none;
}

.pinned-item {
  max-width: 230px;
  flex: 0 0 auto;
  overflow: hidden;
  padding: 6px 8px;
  border: 1px solid rgba(229, 9, 20, 0.36);
  border-radius: 5px;
  background: rgba(229, 9, 20, 0.08);
  color: #f3c8cb;
  cursor: pointer;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 10px 20px;
  overscroll-behavior: contain;
  scrollbar-color: #343f4d transparent;
  scrollbar-width: thin;
}

.empty-state {
  height: 100%;
  min-height: 140px;
  display: grid;
  place-items: center;
  padding: 30px;
  color: var(--subtle);
  font-size: 13px;
  text-align: center;
}

.message {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  margin-bottom: 10px;
}

.message.is-own {
  flex-direction: row-reverse;
}

.avatar {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 50%;
  background: var(--avatar-color, #455a64);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.avatar.is-admin {
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 2px rgba(229, 9, 20, 0.18);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-content {
  min-width: 0;
  max-width: calc(86% - 37px);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 0 4px 3px;
  color: var(--muted);
  font-size: 10px;
}

.message.is-own .message-meta {
  justify-content: flex-end;
}

.author-name {
  overflow: hidden;
  color: #d8dee7;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role-badge {
  padding: 1px 4px;
  border: 1px solid rgba(229, 9, 20, 0.42);
  border-radius: 3px;
  background: var(--accent-soft);
  color: #ff8188;
  font-size: 8px;
  font-weight: 900;
  text-transform: uppercase;
}

.role-badge.is-moderator {
  border-color: rgba(46, 213, 115, 0.42);
  background: rgba(46, 213, 115, 0.1);
  color: #75e6a5;
}

.message-time {
  color: var(--subtle);
  white-space: nowrap;
}

.message-ip {
  color: #ff9aa1;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 9px;
  white-space: nowrap;
}

.bubble {
  position: relative;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px 7px 7px 2px;
  background: var(--surface-raised);
  color: #edf1f6;
  font-size: 13px;
  line-height: 1.42;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.is-own .bubble {
  border-color: rgba(229, 9, 20, 0.48);
  border-radius: 7px 7px 2px 7px;
  background: #311418;
}

.message.is-admin .bubble {
  border-color: rgba(229, 9, 20, 0.58);
  background: #2b1519;
}

.message.is-pinned .bubble {
  box-shadow: inset 3px 0 0 var(--accent);
}

.message-actions {
  display: flex;
  gap: 3px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity 120ms ease;
}

.message:hover .message-actions,
.message:focus-within .message-actions {
  opacity: 1;
}

.message.is-own .message-actions {
  justify-content: flex-end;
}

.message-action {
  min-height: 25px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-soft);
  color: var(--muted);
  cursor: pointer;
  font-size: 9px;
  font-weight: 700;
}

.message-action:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.jump-button {
  position: absolute;
  right: 12px;
  bottom: 72px;
  z-index: 4;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: #202a36;
  box-shadow: var(--shadow);
  color: #fff;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}

.composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: #0b0f14;
  z-index: 5;
}

.composer textarea {
  max-height: 110px;
  min-height: 42px;
  resize: none;
  border-color: rgba(229, 9, 20, 0.44);
  line-height: 1.35;
}

.send-button {
  height: 42px;
  padding: 0 15px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
}

.settings-dialog {
  width: min(94vw, 560px);
  max-height: 92vh;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
}

.settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
  font-size: 20px;
}

.settings-scroll {
  max-height: calc(92vh - 70px);
  overflow-y: auto;
  padding: 0 16px 18px;
}

.settings-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}

.settings-section:last-child {
  border-bottom: 0;
}

.settings-section h3 {
  margin: 0 0 14px;
  font-size: 14px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.settings-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  cursor: pointer;
}

.toggle-row input {
  width: 34px;
  min-height: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.profile-editor {
  display: flex;
  align-items: center;
  gap: 14px;
}

.profile-preview {
  width: 52px;
  height: 52px;
  font-size: 18px;
}

.profile-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.file-button,
.text-button {
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.file-button {
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface-raised);
}

.text-button {
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: #ff7f89;
}

.field-hint {
  margin: 10px 0 0;
  color: var(--subtle);
  font-size: 11px;
  line-height: 1.45;
}

.compact-form {
  padding-bottom: 16px;
}

.staff-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.online-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.online-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-soft);
}

.online-ip {
  color: #ff8b92;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 10px;
}

.staff-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-soft);
}

.staff-name {
  overflow: hidden;
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.staff-detail {
  margin-top: 2px;
  color: var(--subtle);
  font-size: 10px;
}

.staff-remove {
  padding: 5px 7px;
  border: 1px solid rgba(255, 71, 87, 0.35);
  border-radius: 4px;
  background: transparent;
  color: #ff8993;
  cursor: pointer;
  font-size: 10px;
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 76px;
  z-index: 20;
  max-width: calc(100vw - 30px);
  transform: translateX(-50%);
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #202a36;
  box-shadow: var(--shadow);
  color: #fff;
  font-size: 12px;
  text-align: center;
}

.toast.is-error {
  border-color: rgba(255, 71, 87, 0.55);
  background: #35171b;
}

@media (max-width: 420px) {
  .join-view {
    padding: 22px 18px;
  }

  .presence {
    font-size: 10px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .message-content {
    max-width: calc(90% - 37px);
  }
}

@media (hover: none) {
  .message-actions {
    opacity: 1;
  }
}
