:root {
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #17212b;
  background: #f3f6f8;
  font-synthesis: none;
  --ink: #17212b;
  --muted: #667085;
  --line: #dce3e8;
  --surface: #ffffff;
  --surface-soft: #edf2f5;
  --navy: #17324d;
  --navy-deep: #10273c;
  --coral: #d44d35;
  --coral-soft: #fff0ec;
  --green: #17865b;
  --green-soft: #e7f6ef;
  --shadow: 0 16px 40px rgba(23, 50, 77, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--page, #f3f6f8);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

[hidden] {
  display: none !important;
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.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;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 74px;
  padding: 12px max(24px, calc((100vw - 1180px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--navy);
  color: #fff;
}

.brand-mark svg {
  width: 21px;
  height: 21px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
  line-height: 1.25;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.topbar-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
}

.account-chip {
  display: inline-flex;
  min-width: 0;
  max-width: 230px;
  align-items: center;
  gap: 9px;
  padding: 5px 10px 5px 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  text-decoration: none;
}

.account-chip:hover {
  border-color: #b8c5cf;
  background: var(--surface-soft);
}

.account-avatar {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.account-avatar img,
.message-avatar img,
.member-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.account-username {
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-button {
  border-color: var(--line);
  background: var(--surface);
}

main {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: 42px 0 54px;
}

.auth-view {
  display: grid;
  min-height: calc(100dvh - 238px);
  place-items: center;
}

.auth-panel {
  width: min(440px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel h1 {
  margin: 0;
  color: var(--navy-deep);
  font-size: 32px;
  line-height: 1.2;
}

.auth-copy {
  margin: 12px 0 25px;
  color: var(--muted);
  line-height: 1.7;
}

.auth-register {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.auth-register a {
  margin-left: 5px;
  color: var(--navy);
  font-weight: 700;
  text-decoration: none;
}

.auth-register a:hover {
  text-decoration: underline;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--navy);
  font-weight: 650;
  line-height: 1.2;
  transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:focus-visible,
.icon-button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(23, 50, 77, 0.22);
  outline-offset: 2px;
}

.button.primary {
  background: var(--navy);
  color: #fff;
}

.button.primary:hover {
  background: var(--navy-deep);
}

.button.quiet {
  border-color: var(--line);
  background: var(--surface);
}

.button.quiet:hover {
  border-color: #b8c5cf;
  background: var(--surface-soft);
}

.button.danger {
  border-color: #efc4ba;
  background: var(--coral-soft);
  color: #a83220;
}

.button.danger:hover {
  border-color: var(--coral);
  background: #ffe4dd;
}

.button.wide {
  width: 100%;
  min-height: 48px;
  margin-top: 6px;
}

.lobby-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding: 4px 0 34px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--coral);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.lobby-heading h1,
.room-header h1 {
  margin: 0;
  color: var(--navy-deep);
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1.12;
  letter-spacing: 0;
}

.lede {
  max-width: 680px;
  margin: 15px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.75;
}

.lobby-stat {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 9px;
  margin-bottom: 5px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px var(--green-soft);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 0 18px;
  border-top: 1px solid var(--line);
}

.section-heading h2,
.member-panel h2 {
  margin: 0;
  color: var(--navy-deep);
  font-size: 18px;
  letter-spacing: 0;
}

.section-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.room-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.room-card {
  display: flex;
  min-height: 210px;
  flex-direction: column;
  justify-content: space-between;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(23, 50, 77, 0.03);
  transition: transform 170ms ease, box-shadow 170ms ease, border-color 170ms ease;
}

.room-card:hover {
  transform: translateY(-3px);
  border-color: #bac8d2;
  box-shadow: var(--shadow);
}

.room-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.room-lock {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.room-lock i {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--navy);
}

.room-lock i svg {
  width: 15px;
  height: 15px;
}

.room-count {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.room-card-copy {
  margin: 18px 0;
}

.room-card h2 {
  overflow-wrap: anywhere;
  margin: 0;
  color: var(--navy-deep);
  font-size: 22px;
  line-height: 1.3;
  letter-spacing: 0;
}

.room-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.room-enter {
  justify-content: space-between;
  padding: 9px 11px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
}

.room-enter:hover {
  border-color: var(--navy);
  background: var(--navy);
  color: #fff;
}

.empty-state {
  display: grid;
  min-height: 320px;
  place-items: center;
  align-content: center;
  padding: 48px 20px;
  border: 1px dashed #bcc9d2;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
  text-align: center;
}

.empty-icon {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 8px;
  background: var(--surface);
  color: var(--navy);
  box-shadow: var(--shadow);
}

.empty-icon svg {
  width: 26px;
  height: 26px;
}

.empty-state h2 {
  margin: 20px 0 7px;
  color: var(--navy-deep);
  font-size: 22px;
}

.empty-state p {
  margin: 0 0 20px;
  color: var(--muted);
}

.room-view {
  padding-top: 0;
}

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 8px 0 24px;
}

.room-title-row {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 13px;
}

.room-header h1 {
  overflow-wrap: anywhere;
  font-size: clamp(26px, 3vw, 38px);
}

.room-badge {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 5px;
  padding: 6px 9px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 12px;
  font-weight: 750;
}

.room-badge.protected {
  background: #eef1fb;
  color: #435999;
}

.room-badge svg {
  width: 14px;
  height: 14px;
}

.room-header p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.connection-notice {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 14px;
  padding: 10px 13px;
  border: 1px solid #efd6a7;
  border-radius: 7px;
  background: #fff8e9;
  color: #885d16;
  font-size: 13px;
}

.connection-notice svg {
  flex: 0 0 auto;
}

.chat-layout {
  display: grid;
  height: min(690px, calc(100vh - 205px));
  min-height: 470px;
  grid-template-columns: minmax(0, 1fr) 244px;
  gap: 14px;
}

.conversation-panel,
.member-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.conversation-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.message-scroll {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 17px;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

.message-scroll-empty {
  display: grid;
  min-height: 100%;
  place-items: center;
  align-content: center;
  color: var(--muted);
  text-align: center;
}

.message-scroll-empty span {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  margin-bottom: 13px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--navy);
}

.message-scroll-empty span svg {
  width: 22px;
  height: 22px;
}

.message-scroll-empty p {
  margin: 0;
  font-size: 14px;
}

.message {
  display: flex;
  max-width: min(76%, 680px);
  align-items: flex-start;
  gap: 10px;
  animation: message-in 180ms ease-out both;
}

.message.own {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar,
.member-avatar {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border-radius: 50%;
  background: #e5edf3;
  color: var(--navy);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.message.own .message-avatar {
  background: var(--navy);
  color: #fff;
}

.message-body {
  min-width: 0;
}

.message-body header {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin: 0 2px 5px;
}

.message.own .message-body header {
  justify-content: flex-end;
}

.message-author {
  overflow-wrap: anywhere;
  color: var(--navy-deep);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.message-author:hover {
  text-decoration: underline;
}

.message-time {
  color: #8a96a1;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.message-text {
  overflow-wrap: anywhere;
  margin: 0;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 3px 10px 10px 10px;
  background: #f7f9fa;
  color: #25313c;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.message.own .message-text {
  border-color: var(--navy);
  border-radius: 10px 3px 10px 10px;
  background: var(--navy);
  color: #fff;
}

.composer {
  padding: 13px 15px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 42px;
  max-height: 128px;
  resize: none;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: #f3f6f8;
  color: var(--ink);
  line-height: 1.5;
}

.composer textarea::placeholder {
  color: #8b97a2;
}

.composer textarea:focus {
  border-color: #9bb0bf;
  background: #fff;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 9px;
}

.character-count {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.send-button {
  min-width: 96px;
}

.member-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 17px 15px;
}

.member-panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px 14px;
  border-bottom: 1px solid var(--line);
}

.member-panel-heading h2 {
  font-size: 15px;
}

.member-panel-heading span {
  display: grid;
  min-width: 26px;
  height: 24px;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  margin: 0;
  padding: 12px 0;
  list-style: none;
}

.member {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
  padding: 7px 6px;
  border-radius: 6px;
}

.member.you {
  background: #f2f6f8;
}

.member-profile {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: center;
  gap: 9px;
  color: inherit;
  text-decoration: none;
}

.member-profile:hover .member-name {
  color: var(--navy);
  text-decoration: underline;
}

.member-avatar {
  width: 30px;
  height: 30px;
  flex-basis: 30px;
  font-size: 11px;
}

.member-name {
  overflow: hidden;
  flex: 1;
  color: #34414d;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-owner {
  display: none;
  padding: 3px 5px;
  border-radius: 4px;
  background: #eef1fb;
  color: #435999;
  font-size: 9px;
  font-weight: 800;
}

.member.is-owner .member-owner {
  display: inline-block;
}

.member-note {
  margin: auto 0 0;
  padding: 12px 2px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.modal {
  width: min(480px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: visible;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
}

.modal::backdrop {
  background: rgba(9, 24, 37, 0.54);
  backdrop-filter: blur(4px);
}

.modal[open] {
  animation: modal-in 160ms ease-out both;
}

.modal-card {
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 24px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(9, 24, 37, 0.25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 23px;
}

.modal-header > div {
  display: flex;
  align-items: center;
  gap: 11px;
}

.modal-header h2 {
  margin: 0;
  color: var(--navy-deep);
  font-size: 21px;
  letter-spacing: 0;
}

.modal-icon {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--navy);
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
}

.icon-button:hover {
  border-color: var(--line);
  background: var(--surface-soft);
  color: var(--ink);
}

.field {
  margin: 0 0 17px;
  padding: 0;
  border: 0;
}

.field > label,
.field > legend {
  display: block;
  margin: 0 0 7px;
  color: #34414d;
  font-size: 13px;
  font-weight: 700;
}

.field input:not([type="radio"]) {
  width: 100%;
  height: 44px;
  padding: 10px 12px;
  border: 1px solid #cbd5dc;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.field input:not([type="radio"])::placeholder {
  color: #96a1aa;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 7px;
  background: var(--surface-soft);
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control label {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.segmented-control label svg {
  width: 15px;
  height: 15px;
}

.segmented-control input:checked + label {
  background: var(--surface);
  color: var(--navy);
  box-shadow: 0 2px 8px rgba(23, 50, 77, 0.11);
}

.segmented-control input:focus-visible + label {
  outline: 3px solid rgba(23, 50, 77, 0.22);
  outline-offset: 2px;
}

.form-error {
  min-height: 19px;
  margin: 0 0 9px;
  color: #b13925;
  font-size: 12px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 24px;
  bottom: 24px;
  max-width: min(400px, calc(100vw - 32px));
  padding: 12px 15px;
  border: 1px solid #314d66;
  border-radius: 7px;
  background: var(--navy-deep);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.5;
  animation: toast-in 180ms ease-out both;
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
  .room-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chat-layout {
    grid-template-columns: minmax(0, 1fr) 210px;
  }
}

@media (max-width: 720px) {
  .topbar {
    min-height: 66px;
    padding: 10px 16px;
  }

  .brand small {
    display: none;
  }

  .account-chip {
    max-width: 150px;
  }

  main {
    width: calc(100% - 28px);
    padding: 28px 0 34px;
  }

  .lobby-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 18px;
    padding-bottom: 26px;
  }

  .lobby-heading h1 {
    font-size: 32px;
  }

  .lobby-stat {
    margin: 0;
  }

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

  .room-card {
    min-height: 188px;
  }

  .room-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 18px;
  }

  .room-title-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .room-header .danger {
    width: 100%;
  }

  .chat-layout {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .member-panel {
    order: -1;
    padding: 12px;
  }

  .member-panel-heading {
    padding-bottom: 9px;
  }

  .member-list {
    flex-direction: row;
    gap: 5px;
    padding: 9px 0 0;
    overflow-x: auto;
  }

  .member {
    flex: 0 0 auto;
    padding: 5px 8px 5px 5px;
    background: #f5f8f9;
  }

  .member-name {
    max-width: 100px;
  }

  .member-note {
    display: none;
  }

  .conversation-panel {
    height: max(360px, calc(100dvh - 390px));
    min-height: 0;
  }

  .message-scroll {
    min-height: 0;
    padding: 18px 14px;
  }

  .message {
    max-width: 90%;
  }

  .composer {
    padding: 11px;
  }

  .send-button {
    min-width: 88px;
  }

  .toast {
    right: 16px;
    bottom: 16px;
  }
}

@media (max-width: 420px) {
  .brand-mark {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }

  .topbar > .button {
    min-height: 40px;
    padding: 8px 10px;
  }

  .topbar-actions > .button {
    min-height: 40px;
    padding: 8px 10px;
  }

  .account-chip {
    max-width: 130px;
    padding-right: 6px;
  }

  .section-heading {
    align-items: flex-start;
  }

  .section-heading .button span {
    display: none;
  }

  .modal-card {
    padding: 20px 17px;
  }
}

@media (max-width: 560px) {
  .account-username,
  .topbar-actions > .button span {
    display: none;
  }

  .account-chip {
    max-width: none;
    padding: 4px;
    border-color: transparent;
  }

  .topbar-actions > .button {
    width: 42px;
    min-height: 42px;
    padding: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}


