.chat-toggle {
  cursor: pointer;
}
.chat-launcher {
  position: fixed;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 11px 19px;
  border: 1px solid #d3ff84;
  border-radius: 999px;
  color: #0d1623;
  background: #c5ff52;
  font: inherit;
  font-weight: 750;
  box-shadow: 0 8px 30px #0007;
}
.chat-launcher:hover { background: #d6ff88; }
.chat-open .chat-launcher { visibility: hidden; }
#chat-panel {
  display: flex;
  flex-direction: column;
  color: #eff4fc;
  background: #131e2e;
  border: 1px solid #324259;
  border-radius: 18px;
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.45;
  text-align: left;
  box-shadow: 0 18px 70px #0008;
}
#chat-panel[hidden], #chat-panel [hidden], #player-chat-slot[hidden] { display: none !important; }
#chat-home > #chat-panel {
  position: fixed;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 40;
  width: 340px;
  max-width: calc(100vw - 28px);
  height: min(560px, 75vh);
  height: min(560px, 75svh);
}
#player-chat-slot {
  display: flex;
  flex: 0 0 300px;
  width: 300px;
  min-width: 0;
  min-height: 0;
}
#player-chat-slot > #chat-panel {
  position: static;
  width: 100%;
  min-height: 0;
  height: 100%;
  max-height: none;
  border-radius: 12px;
  box-shadow: none;
}
#chat-panel .chat-header {
  display: flex;
  flex-shrink: 0;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid #2c394d;
}
#chat-panel h2 {
  margin: 0 0 3px;
  color: #f3f7fe;
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -.02em;
}
#chat-status {
  margin: 0;
  color: #a9b9cc;
  font-size: 11px;
}
#chat-status::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: #8da0bb;
  vertical-align: 1px;
}
#chat-status[data-state='connected']::before { background: #c5ff52; }
#chat-status[data-state='error']::before { background: #ffb59e; }
#chat-close {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid #3b4a60;
  border-radius: 9px;
  color: #d9e5f5;
  background: #1c2a3d;
  font-size: 25px;
  cursor: pointer;
}
#chat-close:hover { background: #2a3b52; }
#chat-panel .chat-note {
  flex-shrink: 0;
  margin: 0;
  padding: 10px 16px;
  color: #acbbcd;
  background: #101a29;
  font-size: 11px;
  line-height: 1.55;
}
#chat-messages {
  flex: 1 1 auto;
  min-height: 90px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 14px 12px;
  scrollbar-width: thin;
  scrollbar-color: #4b5e76 transparent;
}
.chat-empty {
  margin: 30px 4px;
  text-align: center;
  color: #aebed1;
  font-size: 13px;
}
.chat-message {
  margin: 7px 0 0;
  padding: 10px 11px 6px;
  background: #1a293d;
  border: 1px solid #293a50;
  border-radius: 10px;
  overflow-wrap: anywhere;
}
.chat-message-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.chat-message-name {
  min-width: 0;
  color: #d1f899;
  font-size: 12px;
  font-weight: 700;
}
.chat-message-time {
  flex-shrink: 0;
  color: #9badc4;
  font-size: 10px;
}
#chat-panel .chat-message-text {
  margin: 5px 0 4px;
  color: #eff4fc;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
}
.chat-report {
  display: block;
  margin: 0 0 0 auto;
  padding: 4px 0 3px 10px;
  border: 0;
  color: #a6b7cd;
  background: transparent;
  font: inherit;
  font-size: 10px;
  cursor: pointer;
}
.chat-report:hover:not(:disabled) { color: #fff; text-decoration: underline; }
.chat-report:disabled { cursor: default; color: #91a2b8; }
#chat-error {
  flex-shrink: 0;
  margin: 0;
  padding: 8px 16px;
  color: #ffbaa9;
  font-size: 12px;
  overflow-wrap: anywhere;
}
#chat-error.chat-success { color: #c5ec9d; }
#chat-retry {
  align-self: flex-start;
  flex-shrink: 0;
  margin: 0 16px 8px;
  padding: 6px 9px;
  border: 1px solid #60768f;
  border-radius: 7px;
  color: #eff4fc;
  background: #213149;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
#chat-form {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 12px 14px 14px;
  border-top: 1px solid #2c3c52;
  background: #101a29;
}
#chat-form > label:not(.sr-only) {
  color: #b8c7da;
  font-size: 11px;
  font-weight: 600;
}
#chat-form input {
  min-width: 0;
  min-height: 39px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #435771;
  border-radius: 8px;
  color: #f2f6ff;
  background: #172539;
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
}
#chat-form input::placeholder { color: #a3b3c9; opacity: 1; }
#chat-form .chat-compose {
  display: flex;
  align-items: stretch;
  gap: 7px;
  margin-top: 4px;
}
#chat-text { flex: 1 1 auto; }
#chat-send {
  flex: 0 0 auto;
  min-width: 58px;
  min-height: 39px;
  padding: 8px 10px;
  border: 1px solid #c5ff52;
  border-radius: 8px;
  color: #0d1623;
  background: #c5ff52;
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}
#chat-send:hover:not(:disabled) { background: #d9ff96; }
#chat-send:disabled { color: #aebdd0; background: #26374c; border-color: #41536c; cursor: default; }
#chat-panel :is(button, input):focus-visible,
.chat-toggle:focus-visible {
  outline: 2px solid #c5ff52;
  outline-offset: 3px;
}
@media (max-width: 760px) {
  #chat-home > #chat-panel {
    right: max(14px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
    width: min(360px, calc(100vw - 28px));
    height: min(560px, 78vh);
    height: min(560px, 78svh);
  }
  #player-shell.has-chat .player-layout { flex-direction: column; }
  #player-chat-slot {
    flex: 0 0 auto;
    width: 100%;
    height: 380px;
    min-height: 320px;
    max-height: 60svh;
  }
  #player-chat-slot > #chat-panel { height: 100%; }
  #chat-form input { font-size: 16px; }
  #chat-close, #chat-send { min-height: 42px; }
  .chat-report { padding-top: 7px; padding-bottom: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  #chat-panel, #chat-panel * { scroll-behavior: auto !important; }
}
