:root {
  color-scheme: light;
  font-family: 'Avenir Next', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-synthesis: none;
  color: #242039;
  background: #ece9f5;
  --ink: #242039;
  --muted: #6c657e;
  --line: #ede9f3;
  --accent: #6647d2;
  --accent-hover: #5739bd;
  --sidebar: #27213c;
  --sidebar-text: #c0b7d6;
  --peach: #ffbd9f;
  --green: #238465;
}

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

body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(16px, 3vw, 44px);
  display: grid;
  place-items: center;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, input, textarea { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid #896aea; outline-offset: 3px; }
button { color: inherit; }

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
  vertical-align: middle;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
}

.brand-mark {
  width: 41px;
  height: 41px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--peach);
  color: #332547;
}

.brand-mark svg { width: 27px; height: 27px; }
.brand-mark-detail { fill: var(--peach); }
.brand-name { font-size: 1.38rem; font-weight: 750; letter-spacing: -.055em; }

.auth-screen { width: min(100%, 1000px); }

.auth-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 530px;
  border-radius: 28px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 24px 75px #3e2c641f, 0 3px 12px #3a2e5010;
}

.auth-art {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-rows: auto 1fr;
  align-items: center;
  padding: 34px 38px;
  overflow: hidden;
  background: var(--sidebar);
}

.auth-art::before, .auth-art::after {
  position: absolute;
  z-index: -1;
  inset: 53% auto auto 50%;
  width: 72%;
  aspect-ratio: 1;
  translate: -50% -50%;
  border: 1px solid #9e84ed28;
  border-radius: 50%;
  content: '';
}

.auth-art::after { width: 89%; border-color: #9e84ed17; }
.auth-image { width: min(115%, 450px); height: auto; justify-self: center; margin-block: 0 10px; }
.auth-panel { align-self: center; padding: 54px clamp(34px, 5vw, 76px); }
.auth-panel h1 { margin: 0 0 32px; font-size: clamp(1.85rem, 3.4vw, 2.5rem); letter-spacing: -.075em; line-height: 1.18; }
.auth-form { display: grid; gap: 19px; }
.auth-field { display: grid; gap: 8px; }
.auth-field label { font-size: .9rem; font-weight: 650; }
.auth-field input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #e4deed;
  color: var(--ink);
  background: #fbfafe;
}
.auth-field input::placeholder { color: #817891; }
.auth-field input:focus { border-color: #9279e4; outline: 0; box-shadow: 0 0 0 3px #9479e32b; }
.auth-error, .compose-status { margin: 0; color: #a32948; font-size: .86rem; line-height: 1.5; }
.auth-notice { margin: 0; color: #1e7055; font-size: .88rem; line-height: 1.5; }
.auth-submit, .send-button {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: .94rem;
  font-weight: 650;
}
.auth-submit { min-height: 48px; margin-top: 6px; }
.auth-submit:hover:not(:disabled), .send-button:hover:not(:disabled) { background: var(--accent-hover); }
.auth-submit:disabled { opacity: .65; }

.workspace {
  position: relative;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) 231px;
  width: min(100%, 1450px);
  height: calc(100vh - 2 * clamp(16px, 3vw, 44px));
  height: calc(100dvh - 2 * clamp(16px, 3vw, 44px));
  max-height: 1060px;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid #e1dbed;
  border-radius: 23px;
  background: #fff;
  box-shadow: 0 24px 66px #35275518, 0 2px 8px #3527550a;
}

.rooms-sidebar, .members-sidebar, .chat { min-height: 0; min-width: 0; }
.rooms-sidebar { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: var(--sidebar); color: var(--sidebar-text); }
.rooms-sidebar .brand { min-height: 84px; padding: 15px 22px; }
.room-nav { min-height: 0; overflow: auto; padding: 15px 12px 22px; scrollbar-width: thin; }
.sidebar-label { margin: 0 10px 11px; color: #beb3d7; font-size: .82rem; font-weight: 650; }
.room-list, .message-list { list-style: none; margin: 0; padding: 0; }
.room-list { display: grid; gap: 5px; }
.room-button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 7px 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: #ede8f8;
  text-align: start;
}
.room-button:hover { background: #ffffff0a; }
.room-button[aria-current]:not([aria-current='false']) {
  border-color: #a895f23b;
  background: #403457;
  color: #fff;
}
.room-button[aria-current]:not([aria-current='false'])::before {
  position: absolute;
  inset: 14px auto 14px -1px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--peach);
  content: '';
}
.room-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .93rem; font-weight: 650; }
.room-unread { display: inline-grid; place-items: center; min-width: 22px; min-height: 22px; padding-inline: 5px; border-radius: 999px; color: #302144; background: var(--peach); font-size: .75rem; font-weight: 750; }
.room-online { width: 7px; height: 7px; flex: none; border-radius: 50%; background: #7ae0ba; }
.room-nav p { margin: 10px; font-size: .86rem; line-height: 1.55; }

.own-profile { min-height: 76px; display: flex; align-items: center; gap: 10px; padding: 13px 14px 13px 19px; border-top: 1px solid #ffffff17; }
.own-profile-info { min-width: 0; flex: 1; display: grid; gap: 2px; }
.own-name, .own-username { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.own-name { color: #fff; font-size: .91rem; font-weight: 650; }
.own-username { font-size: .75rem; }
.own-profile .profile-edit { width: 34px; }
.own-profile .profile-edit + .profile-edit { margin-inline-start: -6px; }

.avatar {
  --avatar-fill: #e9e1ff;
  --avatar-ink: #56359b;
  width: 39px;
  height: 39px;
  flex: none;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  background: var(--avatar-fill);
  color: var(--avatar-ink);
  font-size: .96rem;
  font-weight: 750;
  line-height: 1;
  user-select: none;
}
.avatar[data-tone='1'] { --avatar-fill: #ffded1; --avatar-ink: #875042; }
.avatar[data-tone='2'] { --avatar-fill: #d5eee7; --avatar-ink: #2f6b5b; }
.avatar[data-tone='3'] { --avatar-fill: #e0e9ff; --avatar-ink: #3a558d; }
.avatar[data-tone='4'] { --avatar-fill: #f4dff1; --avatar-ink: #793c70; }
.avatar[data-tone='5'] { --avatar-fill: #ffeabf; --avatar-ink: #76571f; }
.room-button .avatar { width: 34px; height: 34px; border-radius: 10px; font-size: .86rem; }
.own-avatar { width: 36px; height: 36px; }

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  flex: none;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
}
.icon-button:hover { color: var(--accent); background: #f1ebfc; }
.rooms-sidebar .icon-button { color: #d1c7e7; }
.rooms-sidebar .icon-button:hover { color: #fff; background: #ffffff15; }
.drawer-close { margin-inline-start: auto; }
.drawer-close, .rooms-toggle, .members-toggle, .drawer-overlay { display: none; }

.chat { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.chat-header { display: flex; align-items: center; justify-content: space-between; min-height: 84px; gap: 12px; padding: 14px 25px; border-bottom: 1px solid var(--line); }
.chat-heading, .chat-actions { display: flex; min-width: 0; align-items: center; gap: 12px; }
.chat-heading-text { min-width: 0; }
.chat-heading .room-avatar { width: 43px; height: 43px; border-radius: 13px; font-size: 1.1rem; }
.chat-heading h1 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.18rem; font-weight: 750; letter-spacing: -.025em; line-height: 1.35; }
.room-status { display: block; margin-top: 3px; color: var(--muted); font-size: .78rem; }
.room-status[data-state='online'], .peer-status[data-state='online'] { color: var(--green); }
.connection-status { display: flex; flex: none; align-items: center; gap: 7px; color: var(--muted); font-size: .78rem; }
.status-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: #a87e3a; }
.connection-status[data-state='online'] .status-dot, .connection-status[data-state='connected'] .status-dot { background: #3a9d7a; }
.connection-status[data-state='offline'] .status-dot { background: #bd596f; }

.message-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #dad2ea transparent; background: #fbfaff; }
.message-scroll:focus-visible { outline-offset: -3px; }
.timeline { display: flex; flex-direction: column; min-height: 100%; width: min(100%, 900px); margin-inline: auto; padding: 24px clamp(18px, 3.1vw, 41px); }
.empty-state { flex: 1; align-self: center; display: grid; justify-items: center; align-content: center; width: 100%; margin-block: 4px 21px; text-align: center; }
.empty-image { width: min(100%, 248px); height: auto; margin-bottom: 3px; }
.empty-state h2 { margin: 0; font-size: clamp(1.25rem, 2.3vw, 1.7rem); font-weight: 750; letter-spacing: -.045em; line-height: 1.4; overflow-wrap: anywhere; }
.empty-state p { margin: 8px 0 0; font-size: .94rem; color: var(--muted); line-height: 1.55; }
.message-list { margin-top: auto; width: 100%; }
.message-day { display: flex; align-items: center; gap: 13px; margin: 14px 0 23px; color: var(--muted); font-size: .76rem; }
.message-day::before, .message-day::after { flex: 1; border-top: 1px solid #eae5f1; content: ''; }
.message { display: flex; align-items: flex-start; gap: 10px; margin-top: 18px; }
.message--grouped { margin-top: 5px; }
.message--own { flex-direction: row-reverse; }
.message-avatar { width: 34px; height: 34px; border-radius: 11px; font-size: .85rem; }
.message--grouped .message-avatar { visibility: hidden; }
.message-content { display: grid; justify-items: start; max-width: min(82%, 570px); min-width: 0; }
.message--own .message-content { justify-items: end; }
.message-meta { display: flex; align-items: baseline; gap: 8px; max-width: 100%; margin-bottom: 4px; color: var(--muted); }
.message--own .message-meta { flex-direction: row-reverse; }
.message-author { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); font-size: .82rem; font-weight: 700; }
.message-time { flex: none; font-size: .72rem; }
.message-bubble { max-width: 100%; margin: 0; padding: 9px 13px; border: 1px solid #eee8f7; border-radius: 4px 14px 14px 14px; background: #f0ebf8; font-size: .96rem; line-height: 1.52; overflow-wrap: anywhere; white-space: pre-wrap; }
.message--own .message-bubble { border-color: #ddd1fc; border-radius: 14px 4px 14px 14px; background: #e8deff; }
.message--grouped .message-bubble { border-radius: 14px; }
.message-image-button {
  display: grid;
  place-items: center;
  width: min(276px, 55vw);
  max-width: 100%;
  aspect-ratio: 4 / 3;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid #e8e0f2;
  border-radius: 13px;
  background: #f1edf8;
  color: var(--muted);
  font-size: .88rem;
  cursor: zoom-in;
}
.message-image-button:hover:not(:disabled) { border-color: #ab95e6; }
.message-image { display: block; width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.message-image-button + .message-bubble { margin-top: 5px; }

.composer { border-top: 1px solid var(--line); padding: 15px clamp(14px, 2.6vw, 28px) max(15px, env(safe-area-inset-bottom)); }
.composer-inner { width: min(100%, 900px); margin-inline: auto; }
.compose-status { padding: 0 5px 7px; }
.image-draft {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  max-width: 100%;
  margin: 0 0 9px;
  padding: 6px 6px 6px 7px;
  border: 1px solid #e8e0f2;
  border-radius: 12px;
  background: #faf7ff;
}
.image-draft-preview { display: block; flex: none; border-radius: 7px; object-fit: cover; background: #eee7f8; }
.image-draft-name { min-width: 0; max-width: min(270px, 42vw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .87rem; }
.image-draft .icon-button .icon { width: 16px; height: 16px; }
.message-form { display: flex; align-items: end; gap: 9px; padding: 6px; border: 1px solid #e6dfef; border-radius: 15px; background: #fbfafe; }
.message-form:focus-within { border-color: #a38cea; box-shadow: 0 0 0 3px #9479e31c; }
.choose-image { color: var(--accent); }
.choose-image:disabled { opacity: .47; color: var(--muted); background: transparent; }
.message-input { display: block; flex: 1; min-width: 0; min-height: 40px; max-height: 130px; width: 100%; padding: 9px 9px 7px; border: 0; outline: 0; resize: none; background: transparent; color: var(--ink); line-height: 1.45; }
.message-input::placeholder { color: #81778e; }
.message-input:disabled { opacity: .78; }
.send-button { display: flex; flex: none; align-items: center; justify-content: center; gap: 7px; min-height: 40px; min-width: 86px; padding: 7px 12px; }
.send-button .icon { width: 1.06rem; height: 1.06rem; }
.send-button:disabled { background: #ebe5f5; color: #6d617f; }

.members-sidebar { background: #fff; border-left: 1px solid var(--line); overflow: auto; }
.members-header { display: flex; align-items: center; gap: 8px; min-height: 84px; padding: 14px 21px; border-bottom: 1px solid var(--line); }
.members-header h2 { margin: 0; font-size: .94rem; font-weight: 750; }
.peer-profile { display: grid; justify-items: center; gap: 5px; padding: 26px 14px 24px; text-align: center; }
.peer-avatar { width: 65px; height: 65px; border-radius: 21px; margin-bottom: 7px; font-size: 1.56rem; }
.peer-name, .peer-username { max-width: 100%; overflow-wrap: anywhere; }
.peer-name { margin: 0; font-size: 1rem; font-weight: 750; }
.peer-username, .peer-status { margin: 0; color: var(--muted); font-size: .78rem; }
.peer-status { margin-top: 7px; padding: 4px 9px; border-radius: 999px; background: #f4f0f9; font-weight: 600; }
.peer-status[data-state='online'] { background: #e6f4ef; }
.edit-alias {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 15px;
  padding: 8px 12px;
  border: 1px solid #ebe2f6;
  border-radius: 9px;
  background: #faf7fe;
  color: #6046a6;
  font-size: .86rem;
  font-weight: 650;
}
.edit-alias:hover { background: #f0e8fa; }
.edit-alias .icon { width: 15px; height: 15px; }

.alias-dialog, .password-dialog, .image-dialog {
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 18px 70px #21183153;
}
.alias-dialog::backdrop, .password-dialog::backdrop, .image-dialog::backdrop { background: #231b3a83; }
.alias-dialog { width: 370px; }
.password-dialog { width: 400px; }
.alias-form, .password-form { display: grid; gap: 11px; padding: 17px 20px 19px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-heading h2 { margin: 0; font-size: 1.14rem; }
.alias-input { width: 100%; min-height: 45px; padding: 9px 12px; border: 1px solid #e4deed; border-radius: 9px; color: var(--ink); background: #fbfafe; }
.alias-input:focus { border-color: #9279e4; outline: 0; box-shadow: 0 0 0 3px #9479e32b; }
.alias-hint, .password-hint { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.45; }
.dialog-actions { display: flex; justify-content: end; }
.dialog-actions .auth-submit { min-height: 39px; min-width: 76px; padding-inline: 14px; }
.image-dialog { isolation: isolate; background: #29213d; }
.image-dialog::backdrop { background: #1a142bd9; }
.image-dialog img { display: block; max-width: 100%; max-height: calc(100dvh - 32px); width: auto; height: auto; object-fit: contain; }
.image-dialog .icon-button { position: absolute; z-index: 1; inset: 7px 7px auto auto; color: #fff; background: #29213dd9; }
.image-dialog .icon-button:hover { background: #47336c; }

.toast {
  position: fixed;
  z-index: 5;
  right: 22px;
  bottom: 22px;
  max-width: min(340px, calc(100vw - 44px));
  padding: 11px 15px;
  border-radius: 10px;
  background: var(--sidebar);
  color: #fff;
  box-shadow: 0 8px 22px #35275530;
  font-size: .88rem;
}

@media (max-width: 1060px) {
  .workspace { grid-template-columns: 224px minmax(0, 1fr); }
  .members-toggle, .members-sidebar .drawer-close { display: inline-grid; }
  .members-sidebar { position: absolute; z-index: 3; inset: 0 0 0 auto; width: min(82%, 270px); visibility: hidden; transform: translateX(100%); }
  .workspace[data-drawer='members'] .members-sidebar { visibility: visible; transform: none; }
  .drawer-overlay { position: absolute; inset: 0; z-index: 2; display: block; padding: 0; border: 0; background: #251c4466; }
}

@media (max-width: 700px) {
  body { display: block; padding: 0; }
  .workspace { grid-template-columns: minmax(0, 1fr); width: 100%; height: 100vh; height: 100dvh; max-height: none; border: 0; border-radius: 0; }
  .rooms-toggle, .rooms-sidebar .drawer-close { display: inline-grid; }
  .rooms-sidebar { position: absolute; z-index: 3; inset: 0 auto 0 0; width: min(82%, 290px); visibility: hidden; transform: translateX(-100%); }
  .workspace[data-drawer='rooms'] .rooms-sidebar { visibility: visible; transform: none; }
  .auth-screen { width: 100%; min-height: 100vh; min-height: 100dvh; display: grid; align-items: center; padding: 20px 16px; }
  .auth-card { grid-template-columns: minmax(0, 1fr); min-height: 0; width: min(100%, 420px); justify-self: center; border-radius: 22px; }
  .auth-art { min-height: 154px; grid-template-rows: auto; padding: 21px 23px; align-items: start; }
  .auth-art .brand { z-index: 1; }
  .auth-image { position: absolute; inset: auto -10px -10px auto; width: 172px; margin: 0; }
  .auth-art::before, .auth-art::after { inset: 65% auto auto 80%; width: 176px; }
  .auth-art::after { width: 228px; }
  .auth-panel { padding: 28px 24px 34px; }
  .auth-panel h1 { margin-bottom: 23px; }
  .chat-header, .members-header, .rooms-sidebar .brand { min-height: 69px; padding: 10px 12px; }
  .chat-heading, .chat-actions { gap: 6px; }
  .chat-heading .room-avatar { width: 37px; height: 37px; border-radius: 11px; }
  .chat-heading h1 { font-size: 1.05rem; }
  .chat-actions .connection-label { display: none; }
  .chat-actions .connection-status:not([data-state='online']):not([data-state='connected']) .connection-label { display: inline; }
  .composer { padding-top: 10px; }
  .message-form { gap: 4px; }
  .message-input { padding-inline: 5px; }
  .timeline { padding: 15px; }
  .message-content { max-width: 80%; }
  .send-button { min-width: 65px; gap: 4px; padding-inline: 8px; }
}

@media (max-height: 470px) {
  .empty-image { width: min(100%, 142px); }
  .empty-state { margin-block: 0; }
  .auth-screen { min-height: auto; }
}
