:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, sans-serif;
  color: #242036;
  background: #f5f3fa;
  --accent: #6243aa;
  --muted: #625c72;
  --line: #e6e1ef;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
main { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
h1, p { margin: 0; }
button, input, textarea, select { font: inherit; }
button {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: .75rem;
  padding: .8rem 1rem;
  font-weight: 650;
  cursor: pointer;
}
button:hover { background: #52358f; }
button:disabled { opacity: .6; cursor: wait; }
:focus-visible { outline: 3px solid #9876dc; outline-offset: 3px; }
input, textarea, select {
  min-width: 0;
  color: inherit;
  background: white;
  border: 1px solid #c8bfd7;
  border-radius: .75rem;
  padding: .8rem 1rem;
}
.login, .chat { background: white; border: 1px solid var(--line); box-shadow: 0 16px 55px #31234414; border-radius: 1.35rem; }
.login { width: min(100%, 27rem); padding: clamp(1.5rem, 5vw, 2.5rem); }
.brand-mark, .avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 3rem;
  height: 3rem;
  border-radius: 1rem;
  color: #513580;
  background: #eae0ff;
  font-size: 1.25rem;
  font-weight: 750;
}
.brand-mark { margin-bottom: 1.25rem; }
.login h1 { font-size: 1.85rem; letter-spacing: -.035em; }
.intro { color: var(--muted); margin: .4rem 0 1.65rem; }
.login form { display: grid; gap: .55rem; }
.login form button { margin-top: .65rem; }
.login label { font-size: .9rem; font-weight: 650; }
.login input + label { margin-top: .5rem; }
.error { color: #9f2347; font-size: .9rem; }
.error:empty { display: none; }
.chat {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  width: min(100%, 53rem);
  height: min(48rem, calc(100dvh - 3rem));
}
.chat-header { display: flex; align-items: center; gap: .85rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.chat-heading { flex: 1; }
.chat-heading h1 { font-size: 1.1rem; }
.chat-heading p, .account { font-size: .9rem; color: var(--muted); }
.chat-heading p { margin-top: .2rem; }
.chat-tools { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; padding: .65rem 1.25rem; border-bottom: 1px solid var(--line); }
.chat-tools select { width: min(100%, 15rem); padding: .5rem .65rem; }
.chat-tools label, .chat-tools button { font-size: .9rem; }
.chat-tools button { margin-left: auto; }
.chat-tools p { width: 100%; color: var(--muted); font-size: .9rem; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
dialog { color: inherit; width: min(calc(100% - 1.5rem), 32rem); max-height: 90dvh; overflow-y: auto; border: 1px solid var(--line); border-radius: 1.25rem; padding: 1.25rem; }
dialog::backdrop { background: #23163980; }
.dialog-header h2 { font-size: 1.2rem; margin: 0; }
.invite-form, #invite-result { display: grid; gap: .55rem; margin: 1rem 0; }
.invite-copy { display: flex; gap: .5rem; }
.invite-copy input { flex: 1; }
#invite-status { min-height: 1.25rem; color: var(--muted); font-size: .9rem; }
.account-list { list-style: none; padding: 0; }
.account-list li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; border-top: 1px solid var(--line); padding: .65rem 0; overflow-wrap: anywhere; }
.account-list button { flex: none; font-size: .85rem; }
.secondary { background: #f1ebfa; color: #503583; }
.secondary:hover { background: #e8def6; }
.thread { overflow-y: auto; padding: 1.25rem; background: #faf8fd; }
.empty { text-align: center; color: var(--muted); margin-top: 2rem; }
.messages { display: grid; gap: .7rem; list-style: none; margin: 0; padding: 0; }
.bubble {
  justify-self: start;
  min-width: 0;
  max-width: min(82%, 34rem);
  border: 1px solid var(--line);
  border-radius: 1rem 1rem 1rem .25rem;
  background: white;
  padding: .65rem .85rem;
}
.bubble.mine { justify-self: end; border-radius: 1rem 1rem .25rem 1rem; background: #ebe2fb; border-color: #e5daf9; }
.bubble p { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble time { display: block; color: var(--muted); text-align: right; font-size: .8rem; margin-top: .3rem; }
.composer { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: .55rem; padding: 1rem 1.25rem; }
.composer textarea { resize: vertical; max-height: 8rem; }
.composer .error { grid-column: 1 / -1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 36rem) {
  main:has(.chat:not([hidden])) { padding: 0; }
  .chat { height: 100dvh; border: 0; border-radius: 0; }
  .chat-header, .chat-tools, .thread, .composer { padding-inline: .8rem; }
  .chat-header { gap: .4rem; }
  .chat-header button { padding-inline: .6rem; }
  .account { display: none; }
}
