:root {
  color-scheme: light dark;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --background: #f7f7f5;
  --surface: #ffffff;
  --text: #181817;
  --muted: #74736e;
  --faint: #aaa8a1;
  --line: #deddd8;
  --control: #efefec;
  --control-hover: #e7e7e2;
  --button: #1d1d1b;
  --button-text: #ffffff;
  --focus: #5271ff;
  --live: #2d9661;
  --waiting: #b48535;
  --error: #b13f35;
}

:root[data-theme="light"] { color-scheme: light; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #121211;
  --surface: #1a1a18;
  --text: #efeee9;
  --muted: #99978f;
  --faint: #6c6a64;
  --line: #343431;
  --control: #242421;
  --control-hover: #2d2d29;
  --button: #efeee9;
  --button-text: #171716;
  --focus: #8fa2ff;
  --live: #56bd83;
  --waiting: #d1a250;
  --error: #ef8177;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --background: #121211;
    --surface: #1a1a18;
    --text: #efeee9;
    --muted: #99978f;
    --faint: #6c6a64;
    --line: #343431;
    --control: #242421;
    --control-hover: #2d2d29;
    --button: #efeee9;
    --button-text: #171716;
    --focus: #8fa2ff;
    --live: #56bd83;
    --waiting: #d1a250;
    --error: #ef8177;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
}

button,
input { font: inherit; }

button {
  border: 0;
  border-radius: 999px;
  background: var(--button);
  color: var(--button-text);
  padding: 10px 18px;
  cursor: pointer;
  transition: opacity 120ms ease, background 120ms ease;
}

button:hover { opacity: .82; }
button:disabled { cursor: wait; opacity: .42; }
button:focus-visible,
input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.shell {
  width: min(700px, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 28px 22px 18px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0;
}

.topbar,
.room-heading,
.presence,
.actions,
.composer,
.message header,
.identity {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
  padding: 0 0 18px;
  border-bottom: 1px solid var(--line);
}

.room-heading { gap: 13px; min-width: 0; }

h1 {
  display: flex;
  gap: 2px;
  min-width: 0;
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: -.035em;
}

h1 span:first-child { color: var(--faint); font-weight: 500; }
#room-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.presence {
  flex: 0 0 auto;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

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

.status-dot.live { background: var(--live); }
.actions { gap: 6px; }

.quiet {
  background: transparent;
  color: var(--muted);
  padding: 7px 10px;
  font-size: 12px;
}

.quiet:hover { background: var(--control); color: var(--text); opacity: 1; }

.conversation {
  position: relative;
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.messages {
  min-height: 100%;
  margin: 0;
  padding: 14px 0 24px;
  list-style: none;
  overflow-wrap: anywhere;
}

.message {
  padding: 11px 2px 12px;
  border-bottom: 1px solid var(--line);
}

.message header { justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.message strong { font-size: 13px; font-weight: 650; }
.message time { color: var(--muted); font-size: 11px; }
.message p { margin: 0; line-height: 1.48; white-space: pre-wrap; }

.empty {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.empty[hidden] { display: none; }

.footer {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.identity {
  gap: 4px;
  margin: 0 2px 9px;
  color: var(--muted);
  font-size: 12px;
}

.identity strong { color: var(--text); font-weight: 650; }
.identity span::before { content: "·"; margin-right: 4px; color: var(--faint); }

.composer { gap: 8px; }
.message-input { flex: 1; }

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  padding: 11px 15px;
}

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

.error {
  min-height: 18px;
  margin: 7px 3px 0;
  color: var(--error);
  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;
}

@media (max-width: 560px) {
  .shell { padding: 18px 14px 12px; }
  .topbar { align-items: flex-start; padding-bottom: 14px; }
  .room-heading { display: grid; gap: 4px; }
  .presence { margin-left: 2px; }
  .actions { flex-wrap: wrap; justify-content: flex-end; }
  .quiet { padding: 6px 8px; }
  .identity span { display: none; }
  .composer { gap: 7px; }
  button { padding-inline: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}
