:root {
  color-scheme: dark;
  --bg: #090909;
  --bg-soft: #101010;
  --panel: #141414;
  --panel-light: #1a1a1a;
  --line: #2a2a2a;
  --line-strong: #3a3a3a;
  --text: #f2f2f2;
  --muted: #969696;
  --faint: #686868;
  --accent: #e9e2d0;
  --accent-ink: #101010;
  --ok: #75d18a;
  --warn: #e4bc63;
  --bad: #e36d6d;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.42);
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(120deg, rgba(42, 51, 58, 0.72), rgba(13, 13, 13, 0.96) 36%, rgba(9, 9, 9, 1)),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  display: grid;
  grid-template-rows: auto auto 1fr;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(13, 13, 13, 0.94);
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
}

.brand,
.topbar-actions,
.row-head,
.chat-head,
.tabs {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  color: var(--text);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 15px;
  text-transform: lowercase;
}

.brand-mark {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border: 2px solid var(--text);
  font-family: var(--mono);
  font-weight: 800;
  font-size: 12px;
}

.topbar-actions {
  gap: 10px;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.status-dot::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
}

.status-dot[data-state="online"]::before {
  background: var(--ok);
}

.status-dot[data-state="wait"]::before {
  background: var(--warn);
}

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

.notice {
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 13px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
}

.sidebar,
.chat {
  grid-column: 1;
  grid-row: 1;
}

body.view-rooms .chat {
  display: none;
}

body.view-chat .sidebar {
  display: none;
}

.auth-gate {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 34px;
}

.landing {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 34px;
}

.landing-inner {
  width: min(720px, 100%);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 18px;
}

.landing-inner h1 {
  margin: 0;
  font-size: clamp(40px, 7vw, 84px);
  letter-spacing: -0.04em;
  line-height: 1;
}

.landing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.auth-card {
  width: min(940px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) 360px;
  border: 1px solid var(--line);
  background: #0d0d0d;
}

.auth-copy {
  min-height: 560px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 44px;
  border-right: 1px solid var(--line);
}

.lead,
.hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.lead {
  max-width: 560px;
  margin-top: 22px;
  font-size: 17px;
}

.hint {
  margin-top: 10px;
  font-size: 13px;
}

.sidebar {
  min-height: 0;
  display: grid;
  background: rgba(8, 8, 8, 0.64);
}

.panel {
  padding: 24px;
}

.auth-panel {
  border-bottom: 0;
}

.room-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.trace {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #0d0d0d;
}

.trace strong {
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
}

.trace span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.trace[data-state="ok"] {
  border-color: rgba(117, 209, 138, 0.42);
}

.trace[data-state="warn"] {
  border-color: rgba(228, 188, 99, 0.58);
}

.trace[data-state="error"] {
  border-color: rgba(227, 109, 109, 0.68);
}

.section-head {
  margin-bottom: 20px;
}

.row-head {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(34px, 5vw, 58px);
  font-weight: 800;
}

h2 {
  font-size: 22px;
  font-weight: 800;
}

.tabs {
  width: 100%;
  padding: 3px;
  gap: 3px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  margin-bottom: 18px;
}

.tab {
  flex: 1;
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.tab.is-active {
  background: var(--text);
  color: var(--bg);
}

.stack {
  display: grid;
  gap: 12px;
}

.stack.compact {
  gap: 10px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
}

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

input {
  height: 43px;
  padding: 0 12px;
}

textarea {
  min-height: 48px;
  max-height: 160px;
  resize: none;
  padding: 13px 14px;
  line-height: 1.4;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

.primary-btn,
.secondary-btn,
.icon-btn,
.send-btn {
  border: 1px solid var(--line-strong);
  border-radius: 0;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.primary-btn,
.secondary-btn {
  min-height: 42px;
  padding: 0 14px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.primary-btn {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.secondary-btn {
  background: var(--panel-light);
  color: var(--text);
}

.secondary-btn.slim {
  min-height: 36px;
}

.icon-btn,
.send-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  background: var(--panel-light);
  color: var(--text);
  font-family: var(--mono);
  font-weight: 800;
}

.send-btn {
  width: 48px;
  height: 48px;
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--accent);
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.code-form {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--line-strong);
}

.rooms-list {
  min-height: 120px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 4px;
}

.room-item {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "name copy"
    "id copy";
  align-items: center;
  gap: 5px;
  width: 100%;
  padding: 13px 12px;
  border: 1px solid var(--line);
  background: #0d0d0d;
  color: var(--text);
  text-align: left;
}

.room-item.is-active {
  border-color: var(--accent);
  background: #181611;
}

.room-name {
  grid-area: name;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.room-id {
  grid-area: id;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.room-copy {
  grid-area: copy;
  align-self: center;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.room-copy:hover {
  color: var(--text);
  border-color: var(--accent);
  background: #181611;
}

.chat {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.chat-head {
  min-height: 88px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

.chat-back {
  display: inline-grid;
}

.chat-head-title {
  flex: 1;
  min-width: 0;
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.empty-state {
  margin: auto;
  max-width: 560px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

.empty-state .prompt {
  margin: 0 0 10px;
  color: var(--text);
  font-family: var(--mono);
  font-size: clamp(34px, 7vw, 72px);
  font-weight: 800;
  line-height: 1;
}

.message {
  width: min(72%, 620px);
  display: grid;
  gap: 6px;
}

.message.is-mine {
  align-self: flex-end;
}

.message-body {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 12px 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.is-mine .message-body {
  border-color: #5a5140;
  background: #191713;
}

.message-meta {
  display: flex;
  gap: 10px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
}

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

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 16px 24px 22px;
  border-top: 1px solid var(--line);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 13px 15px;
  border: 1px solid var(--line-strong);
  background: #101010;
  color: var(--text);
  box-shadow: var(--shadow);
  font-family: var(--mono);
  font-size: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  .shell {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    border-left: 0;
    border-right: 0;
  }

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

  .auth-gate {
    padding: 20px;
  }

  .auth-card {
    grid-template-columns: 1fr;
  }

  .auth-copy {
    min-height: auto;
    padding: 28px 24px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .panel {
    padding: 20px;
  }

  .message {
    width: min(88%, 620px);
  }
}

@media (max-width: 520px) {
  .topbar,
  .chat-head,
  .composer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .brand span:last-child {
    display: none;
  }

  .status-dot {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  h1 {
    font-size: 38px;
  }

  .message {
    width: 100%;
  }
}
