.chat-launcher { position: fixed; right: max(24px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom)); z-index: 20; display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 50px; padding: 13px 20px; border: 1px solid #c5d6f4; border-radius: 999px; background: linear-gradient(135deg, #f5f9ff, #eae5fc); color: #4569a4; box-shadow: 0 6px 24px #354f7d30, inset 0 1px 0 #fff; font-size: 14px; font-weight: 600; }
.chat-launcher:hover { background: #e4eafb; box-shadow: 0 8px 28px #354f7d40; }
.chat-launcher:focus-visible { outline: 3px solid #8a73be; outline-offset: 4px; }
.chat-launcher .icon { width: 21px; height: 21px; }
#chat-dialog {
  --chat-bg: #0c141e;
  --chat-panel: #131c27;
  --chat-card: #18202b;
  --chat-raised: #1c2738;
  --chat-line: #ffffff1a;
  --chat-ink: #e2e8f0;
  --chat-muted: #a8b6c8;
  --chat-gold: #fcd34d;
  width: min(1400px, calc(100vw - 48px));
  max-width: none;
  height: min(850px, calc(100dvh - 48px));
  max-height: none;
  padding: 0;
  overflow: hidden;
  border: 1px solid #ffffff26;
  border-radius: 20px;
  color: var(--chat-ink);
  background: var(--chat-bg);
  box-shadow: 0 24px 80px #000a;
  color-scheme: dark;
}
#chat-dialog::backdrop { background: #030810c9; backdrop-filter: blur(5px); }
#chat-dialog [hidden] { display: none !important; }
#chat-dialog :focus-visible { outline: 2px solid var(--chat-gold); outline-offset: 2px; }
#chat-root { height: 100%; display: flex; flex-direction: column; }
.chat-heading, .chat-peer { display: flex; align-items: center; gap: 10px; background: var(--chat-panel); border-bottom: 1px solid var(--chat-line); }
.chat-heading { justify-content: space-between; padding: 12px 20px; }
.chat-heading h2 { margin: 0; font-size: clamp(.9rem, 2vw, 1.2rem); color: #f1f5f9; }
#chat-dialog .icon-button { background: var(--chat-raised); color: var(--chat-ink); border: 1px solid var(--chat-line); }
.chat-layout { display: grid; grid-template-columns: clamp(300px, 27vw, 352px) minmax(0,1fr); flex: 1; min-height: 0; }
.chat-inbox { display: flex; flex-direction: column; gap: 12px; min-height: 0; padding: 16px 12px 0; background: var(--chat-panel); border-right: 1px solid var(--chat-line); }
.chat-inbox-scroll { overflow: auto; min-height: 0; padding: 2px 4px 12px; }
.chat-filters { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 2px; padding: 4px; background: #0f1722; border: 1px solid var(--chat-line); border-radius: 12px; }
.chat-filters button { min-height: 36px; padding: 2px; border: 0; border-radius: 8px; color: var(--chat-muted); background: transparent; font-size: .72rem; }
.chat-filters button:hover, .chat-filters [aria-pressed=true] { color: var(--chat-gold); background: #f59e0b1a; }
#chat-message::placeholder { color: var(--chat-muted); }
.chat-list-item { position: relative; display: flex; align-items: start; gap: 10px; width: 100%; min-height: 86px; margin-bottom: 4px; padding: 10px; border: 1px solid transparent; border-radius: 14px; background: transparent; color: var(--chat-ink); text-align: left; }
.chat-list-item:hover { background: #162130; }
.chat-list-item.selected { background: #1a2536; border-color: #f59e0b66; }
.chat-list-item.unread:not(.selected) { background: #1c2738; }
.chat-list-item + .chat-list-item { margin-top: 4px; }
.chat-list-item + .chat-list-item::before { content: ""; position: absolute; top: -5px; inset-inline: 10px; border-top: 1px solid var(--chat-line); pointer-events: none; }
.chat-list-copy { min-width: 0; flex: 1; }
.chat-list-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.chat-list-item strong, .chat-list-title, .chat-list-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list-item strong { min-width: 0; font-size: .87rem; }
.chat-list-title { margin: 3px 0; color: var(--chat-gold); font-size: .79rem; }
.chat-list-item small, .chat-list-item time { color: var(--chat-muted); font-size: .73rem; }
.chat-list-item time { flex-shrink: 0; white-space: nowrap; }
.chat-list-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 6px; font-size: .68rem; color: var(--chat-muted); }
.chat-list-tags > span { padding: 2px 5px; border-radius: 5px; background: #ffffff0d; }
.chat-list-tags .chat-state-tag { color: #bae6fd; }
.chat-list-tags .chat-count, #chat-unread { background: #fbbf24; color: #111827; border-radius: 999px; padding: 2px 6px; font-size: .68rem; font-weight: 800; }
#chat-unread[hidden] { display: none; }
.chat-art { display: grid; place-items: center; flex: 0 0 44px; width: 44px; height: 44px; background: #0c141e; border: 1px solid #38bdf840; border-radius: 11px; color: #bae6fd; overflow: hidden; }
.chat-art.mvp .game-card { width: 100%; height: 100%; }
.chat-list-art { position: relative; }
.chat-online { position: absolute; right: -2px; bottom: -2px; width: 11px; height: 11px; border: 2px solid var(--chat-panel); border-radius: 50%; background: #34d399; }
.chat-art img { width: 100%; height: 100%; padding: 3px; object-fit: contain; }
.chat-thread { position: relative; display: grid; grid-template-columns: minmax(0,1fr); min-height: 0; min-width: 0; }
.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-placeholder { margin: auto; padding: 20px; text-align: center; color: var(--chat-muted); }
.chat-peer { padding: 10px 16px; flex-wrap: wrap; row-gap: 6px; }
.chat-peer-name { min-width: 0; flex: 1; }
.chat-peer h3 { margin: 0 0 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #f1f5f9; font-size: .94rem; }
.chat-peer p { margin: 0; color: var(--chat-muted); font-size: .75rem; }
#chat-back { display: none; }
.chat-menu { position: relative; z-index: 2; }
.chat-menu summary { display: grid; place-items: center; min-width: 38px; min-height: 36px; color: var(--chat-ink); background: var(--chat-raised); border: 1px solid var(--chat-line); border-radius: 9px; cursor: pointer; list-style: none; }
.chat-menu summary::-webkit-details-marker { display: none; }
.chat-toolbar { position: absolute; right: 0; width: max-content; padding: 7px; margin-top: 6px; background: var(--chat-panel); border: 1px solid #ffffff30; border-radius: 12px; box-shadow: 0 12px 32px #0008; }
.chat-toolbar button { display: block; width: 100%; text-align: left; }
.chat-summary { display: flex; gap: 12px; align-items: center; padding: 10px 16px; background: var(--chat-card); border-bottom: 1px solid var(--chat-line); overflow-wrap: anywhere; }
.chat-summary > div { min-width: 0; flex: 1; }
.chat-summary strong { display: block; color: #f1f5f9; font-size: .9rem; }
.chat-summary p { margin: 2px 0 0; color: var(--chat-gold); font-size: .78rem; }
.chat-summary small { color: var(--chat-muted); font-size: .72rem; }
.chat-messages { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 14px 18px; }
.chat-safety { margin-bottom: 14px; padding: 10px 12px; border: 1px solid #f59e0b55; border-radius: 11px; background: #241e16; color: #fde68a; font-size: .79rem; line-height: 1.5; }
.chat-safety-guide { border-color: #38bdf855; background: #142536; color: #bae6fd; }
.chat-safety-guide ul { margin: 4px 0 0; padding-inline-start: 18px; }
.chat-beginning { text-align: center; color: var(--chat-muted); font-size: .72rem; }
.chat-message { width: fit-content; max-width: min(88%, 510px); margin: 12px 0; padding: 10px 13px; border: 1px solid var(--chat-line); border-radius: 4px 15px 15px; background: #162232; overflow-wrap: anywhere; }
.chat-message.mine { margin-left: auto; border-color: #f59e0b66; border-radius: 15px 4px 15px 15px; background: linear-gradient(110deg,#362a1a,#38291b); color: #fef3c7; }
.chat-message.system { margin-inline: auto; border-radius: 14px; background: var(--chat-card); color: var(--chat-ink); }
.chat-message p { margin: 0; white-space: pre-wrap; font-size: .89rem; line-height: 1.55; }
.chat-message small { display: block; margin-top: 6px; font-size: .7rem; color: var(--chat-muted); }
.chat-message.mine:not(.system) small { color: #e6cca2; }
.chat-read { margin-left: 6px; color: #7dd3fc; }
.chat-attachment { display: block; width: min(240px, 100%); height: auto; aspect-ratio: 8 / 5; object-fit: contain; background: var(--chat-bg); border-radius: 8px; }
.chat-compose-area { background: var(--chat-panel); border-top: 1px solid var(--chat-line); padding: 8px 14px 12px; }
#chat-composer { display: flex; gap: 8px; }
.chat-compose-actions { display: grid; gap: 5px; flex: 0 0 clamp(108px, 32%, 155px); }
.chat-input { display: flex; flex: 1; flex-direction: column; justify-content: end; min-width: 0; }
#chat-message { display: block; flex: 1; width: 100%; resize: none; color: var(--chat-ink); background: #0f1722; border: 1px solid #ffffff30; border-radius: 10px; padding: 9px 10px; font: inherit; font-size: .88rem; }
#chat-dialog .text-button, #chat-dialog .primary { min-height: 36px; padding: 6px 9px; border: 1px solid var(--chat-line); border-radius: 9px; background: #ffffff0a; color: var(--chat-ink); font-size: .75rem; line-height: 1.2; text-decoration: none; box-shadow: none; transform: none; }
#chat-dialog .text-button:hover { background: #ffffff14; color: var(--chat-gold); }
#chat-dialog .primary { background: linear-gradient(110deg,#fbbf24,#f59e0b); color: #111827; font-weight: 800; }
#chat-dialog .primary:hover { background: #fcd34d; }
#chat-dialog button:disabled { opacity: .55; cursor: not-allowed; }
#chat-clear-draft-mode { overflow-wrap: anywhere; max-width: 100%; margin-top: 4px; }
#chat-dialog .form-note { color: var(--chat-muted); background: var(--chat-raised); }
#chat-error { margin: 0; padding: 8px 16px; color: #fecaca; background: #381e25; }
#chat-error:empty { display: none; }
#chat-more { width: 100%; margin-top: 8px; }
@media (max-width: 360px) {
  #chat-back span { display: none; }
}
@media (max-width: 767px) {
  #chat-dialog { width: 100%; height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .chat-layout { display: flex; }
  .chat-inbox { width: 100%; border: 0; }
  .chat-layout:has(.has-conversation) .chat-inbox, .chat-thread:not(.has-conversation) { display: none; }
  .chat-thread.has-conversation { width: 100%; }
  #chat-back { display: block; white-space: nowrap; }
  .chat-heading { padding: 8px 12px; }
  .chat-peer { padding: 8px; gap: 5px; }
  .chat-summary, .chat-messages { padding-inline: 10px; }
  .chat-compose-area { padding: 6px 8px max(8px, env(safe-area-inset-bottom)); }
  .chat-launcher { right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

.chat-loading { display: grid; align-content: start; gap: 12px; padding: 14px; width: 100%; }
.chat-loading .skeleton { min-height: 56px; height: 56px; border-radius: 12px; background: var(--chat-card); }
.chat-thread .chat-loading { padding-block: 24px; }
.chat-thread .chat-loading .skeleton:nth-child(2) { width: 70%; justify-self: end; }
