#social-chat {
  position: fixed;
  right: 24px;
  bottom: 18px;
  width: 300px;
  z-index: 35;
  font:
    12px/1.45 Inter,
    Arial,
    sans-serif;
  color: #dceaf4;
  pointer-events: none;
}
#social-chat button,
#social-chat input,
#social-chat summary {
  font: inherit;
}
#social-chat button {
  cursor: pointer;
  color: inherit;
}
.chat-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid #6db5dd33;
  background: #071421df;
  backdrop-filter: blur(14px);
  font-size: 10px !important;
  letter-spacing: 1.1px;
  pointer-events: auto;
}
.chat-toggle i {
  width: 5px;
  height: 5px;
  background: #70d2fa;
  border-radius: 50%;
}
.chat-count {
  font-size: 9px;
  color: #91aabb;
  margin-left: auto;
}
.chat-chevron {
  color: #75d3fc;
}
.chat-unread {
  background: #76d5fb;
  color: #061424;
  padding: 1px 5px;
  border-radius: 3px;
}
.chat-panel {
  pointer-events: auto;
  background: #081522f5;
  border: 1px solid #6db5dd33;
  box-shadow: 0 12px 35px #0006;
  backdrop-filter: blur(16px);
  padding: 10px;
  position: absolute;
  bottom: 39px;
  width: 100%;
  box-sizing: border-box;
}
.chat-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-tabs {
  display: flex;
  gap: 14px;
}
.chat-tabs button {
  padding: 7px 0;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  font-size: 10px !important;
  font-weight: 800 !important;
  letter-spacing: 1.2px;
  color: #8098a9 !important;
}
.chat-tabs [aria-selected="true"] {
  border-color: #6ad2fb;
  color: #e5f5ff !important;
}
.chat-tabs button:disabled {
  opacity: 0.4;
  cursor: default !important;
}
.chat-close {
  background: none;
  border: 0;
  font-size: 22px !important;
}
.chat-identity {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid #abc8dd15;
  color: #7ed7fc;
}
.chat-nickname {
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
  white-space: nowrap;
}
.chat-edit,
.chat-help {
  padding: 0;
  background: none;
  border: 0;
  font-size: 9px !important;
  color: #93acbf !important;
}
.chat-edit {
  margin-left: auto;
}
.chat-help {
  font-size: 13px !important;
}
.chat-log {
  height: 160px;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: #365368 transparent;
}
.chat-message {
  position: relative;
  margin-bottom: 8px;
  overflow-wrap: anywhere;
  padding-right: 21px;
}
.chat-message b {
  display: block;
  font-size: 10px;
  letter-spacing: 0.2px;
  color: #73ccef;
  margin-bottom: 1px;
}
.chat-message-meta {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 1px;
}
.chat-message-meta b {
  min-width: 0;
  overflow-wrap: anywhere;
  margin-bottom: 0;
}
.chat-message-time {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 400;
  color: #91aabb;
  font-variant-numeric: tabular-nums;
}
.chat-message span {
  font-size: 12px;
  color: #dbe8f0;
}
.chat-message details {
  position: absolute;
  right: 0;
  top: 0;
  z-index: 2;
}
.chat-message details[open] {
  z-index: 4;
}
.chat-message summary {
  list-style: none;
  cursor: pointer;
  color: #9cbed1;
}
.chat-message details > div {
  position: absolute;
  right: 0;
  top: 18px;
  width: 150px;
  padding: 5px;
  background: #142637;
  border: 1px solid #35556b;
  box-shadow: 0 5px 18px #0008;
}
.chat-message details button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 6px;
  font-size: 10px !important;
}
.chat-message details button:hover {
  background: #25445a;
}
.chat-empty {
  color: #819aab;
  font-size: 11px;
}
.chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 0 8px;
}
.chat-quick button {
  background: #142839;
  border: 1px solid #284458;
  border-radius: 3px;
  padding: 4px 6px;
  font-size: 9px !important;
  color: #a7c1d2 !important;
}
.chat-quick button:hover {
  color: #fff !important;
  border-color: #71c8ef;
}
.chat-compose,
.chat-rename {
  display: flex;
  gap: 5px;
}
.chat-compose input,
.chat-rename input {
  width: 0;
  flex: 1;
  min-width: 0;
  background: #020c15;
  color: #fff;
  border: 1px solid #345367;
  border-radius: 3px;
  padding: 9px 7px;
  font-size: 12px !important;
  outline: none;
}
.chat-compose input:focus,
.chat-rename input:focus {
  border-color: #72d2f9;
}
.chat-compose button,
.chat-rename button {
  background: #16354a;
  border: 1px solid #365a70;
  padding: 4px 9px;
}
.chat-rename {
  padding: 7px 0;
}
.chat-rename button {
  font-size: 9px !important;
  padding: 3px;
}
.chat-status {
  font-size: 9px;
  color: #90aabc;
  padding-top: 7px;
  min-height: 13px;
}
.chat-policy {
  font-size: 11px;
  color: #a5bdce;
  max-height: 145px;
  overflow: auto;
  margin: 8px 0;
}
.chat-toast {
  position: absolute;
  top: 38px;
  width: 100%;
  opacity: 0;
  transition: opacity 0.4s;
}
.chat-toast.show {
  opacity: 1;
}
.chat-toast p {
  background: #071421a8;
  padding: 4px 8px;
  border-left: 2px solid #70c8eb;
  font-size: 11px;
  overflow-wrap: anywhere;
  margin: 4px 0;
}
.expanded .chat-toast {
  display: none;
}
#social-chat.during-game {
  left: 24px;
  right: auto;
  top: 190px;
  bottom: auto;
  width: 280px;
}
#social-chat.during-game .chat-toggle {
  background: #0714219c;
  border-color: #6db5dd20;
}
#social-chat.during-game .chat-panel {
  top: 39px;
  bottom: auto;
}
#social-chat [hidden] {
  display: none !important;
}
@media (max-width: 700px) {
  #social-chat {
    right: 16px;
    bottom: 12px;
    width: 230px;
  }
  #social-chat.during-game {
    left: 16px;
    top: 128px;
    width: 220px;
  }
  .chat-panel {
    width: 290px;
    right: 0;
  }
  .during-game .chat-panel {
    left: 0;
    right: auto;
  }
  .chat-log {
    height: 130px;
  }
  .chat-toggle {
    height: 30px;
    font-size: 9px !important;
  }
  .chat-compose input,
  .chat-rename input {
    font-size: 16px !important;
  }
  .chat-toast p {
    font-size: 10px;
  }
  .chat-count {
    font-size: 8px;
  }
}

/* Keep game menu button sizing out of the compact chat overlay. */
#social-chat button {
  min-height: 0;
  letter-spacing: normal;
}
#social-chat button:hover {
  transform: none;
}
#social-chat button span {
  float: none;
}
#social-chat .chat-close {
  padding: 0 5px;
}
#social-chat .chat-toggle {
  min-height: 34px;
}
#social-chat .chat-compose button {
  min-width: 34px;
}
#social-chat .chat-quick button {
  min-height: 26px;
}
@media (pointer: coarse) {
  #social-chat .chat-quick button {
    min-height: 34px;
  }
  #social-chat .chat-tabs button {
    min-height: 38px;
  }
}

/* The chat owns one compact hit target; the open panel always fits the viewport. */
#social-chat,
#social-chat.during-game {
  width: 48px;
  z-index: 110;
  right: 20px;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: auto;
  top: auto;
}
#social-chat.during-game {
  left: max(16px, env(safe-area-inset-left));
  right: auto;
  top: 120px;
  bottom: auto;
}
#social-chat .chat-toggle {
  width: 48px;
  height: 48px;
  min-height: 48px;
  padding: 12px;
  border: 1px solid #72d2f980;
  border-radius: 14px;
  background: #071725f2;
  box-shadow: 0 4px 18px #0006;
  position: relative;
}
.chat-toggle svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: #87ddff;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chat-toggle .chat-unread {
  position: absolute;
  right: -5px;
  top: -5px;
  font-size: 10px;
  min-width: 17px;
  border-radius: 8px;
}
#social-chat .chat-panel {
  width: min(320px, calc(100vw - 32px));
  right: 0;
  left: auto;
  bottom: 56px;
  top: auto;
  max-height: calc(100dvh - 98px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 12px;
  padding: 12px;
  border-color: #62badd70;
}
#social-chat.during-game .chat-panel {
  top: 0;
  bottom: auto;
  left: 56px;
  right: auto;
  max-height: calc(100dvh - 138px);
}
.chat-presence {
  display: flex;
  justify-content: space-between;
  margin: 8px 0;
  color: #7996ab;
  font-size: 9px;
  letter-spacing: 0.6px;
}
.chat-presence .chat-count {
  margin: 0;
  color: #9be6ff;
}
#social-chat .chat-quick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
#social-chat .chat-quick button {
  min-height: 42px;
  font-size: 11px !important;
  padding: 8px;
  border-radius: 7px;
  text-align: left;
}
#social-chat .chat-quick button:first-child {
  border-color: #79d5ff88;
  background: #173d53;
}
#social-chat .chat-close {
  width: 40px;
  min-height: 40px;
}
#social-chat button:focus-visible {
  outline: 2px solid #8bddff;
  outline-offset: 2px;
}
#social-chat .chat-toast {
  width: min(280px, calc(100vw - 32px));
  right: 0;
  top: auto;
  bottom: 56px;
  pointer-events: none;
}
#social-chat.during-game .chat-toast {
  left: 0;
  right: auto;
  top: 54px;
  bottom: auto;
}
@media (max-width: 600px) {
  #social-chat.during-game {
    top: 116px;
  }
  #social-chat.during-game .chat-panel {
    left: 0;
    top: 56px;
    max-height: calc(100dvh - 190px);
  }
}
@media (max-height: 500px) and (min-width: 601px) {
  #social-chat.during-game {
    top: 108px;
  }
  #social-chat.during-game .chat-panel {
    max-height: calc(100dvh - 126px);
  }
}

.chat-backdrop {
  display: none;
}
@media (pointer: coarse), (max-width: 600px) {
  .chat-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 109;
    padding: 0;
    border: 0;
    background: #020b16b8;
    pointer-events: none;
  }
  body.chat-open #touch {
    visibility: hidden;
  }
  #social-chat,
  #social-chat.during-game {
    top: 16px;
    right: 16px;
    bottom: auto;
    left: auto;
  }
  body.in-match #social-chat {
    top: 101px;
  }
  #top-tools,
  body.in-match #top-tools {
    right: 76px;
  }
  #social-chat .chat-toggle {
    width: 44px;
    height: 44px;
    min-height: 44px;
    border-radius: 10px;
    padding: 10px;
  }
  #social-chat.expanded .chat-toggle {
    visibility: hidden;
  }
  #social-chat .chat-panel,
  #social-chat.during-game .chat-panel {
    position: fixed;
    left: 8px;
    right: 8px;
    top: auto;
    bottom: max(
      8px,
      calc(100% - var(--chat-vtop, 0px) - var(--chat-vheight, 100dvh) + 8px)
    );
    width: auto;
    height: min(520px, calc(var(--chat-vheight, 100dvh) - 16px));
    max-height: calc(var(--chat-vheight, 100dvh) - 16px);
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow: hidden;
    border-radius: 18px;
    background: #081826;
    box-shadow: 0 -12px 48px #0008;
  }
  #social-chat .chat-panel > header {
    flex: 0 0 44px;
  }
  #social-chat .chat-panel > header .chat-close {
    min-height: 44px;
    width: 44px;
  }
  #social-chat .chat-tabs button {
    min-height: 44px;
  }
  #social-chat .chat-presence {
    flex: 0 0 auto;
    margin: 0;
  }
  #social-chat .chat-quick {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    align-content: start;
    overscroll-behavior: contain;
    padding: 4px 2px;
    scrollbar-width: thin;
  }
  #social-chat .chat-quick button {
    min-height: 46px;
    font-size: 12px !important;
  }
  #social-chat .chat-status {
    flex: 0 0 auto;
    min-height: 12px;
    padding: 0;
  }
  #social-chat .chat-details {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    gap: 6px;
    overflow: hidden;
  }
  #social-chat .chat-identity {
    flex: 0 0 auto;
    padding: 3px 0;
    min-height: 32px;
  }
  #social-chat .chat-log {
    flex: 1 1 auto;
    min-height: 30px;
    height: auto;
    padding: 4px 0;
  }
  #social-chat .chat-compose {
    flex: 0 0 48px;
  }
  #social-chat .chat-compose input,
  #social-chat .chat-rename input {
    font-size: 16px !important;
  }
  #social-chat .chat-compose button {
    width: 48px;
    min-height: 48px;
  }
  #social-chat.keyboard-visible .chat-presence,
  #social-chat.keyboard-visible .chat-identity,
  #social-chat.keyboard-visible .chat-status {
    display: none;
  }
  #social-chat .chat-policy {
    flex: 0 1 80px;
    margin: 0;
  }
  #social-chat .chat-rename {
    flex: 0 0 auto;
    padding: 0;
    min-height: 44px;
  }
  #social-chat .chat-toast,
  #social-chat.during-game .chat-toast {
    top: 52px;
    bottom: auto;
    right: 0;
    left: auto;
  }
  #controller-status {
    display: none;
  }
}
@media (pointer: coarse) and (min-width: 601px) {
  body.in-match #social-chat {
    top: 16px;
  }
  #social-chat .chat-panel,
  #social-chat.during-game .chat-panel {
    width: min(380px, calc(100vw - 16px));
    left: auto;
  }
  #top-tools,
  body.in-match #top-tools {
    top: 16px;
  }
}
@media (pointer: coarse) {
  body.in-match #top-tools #sound {
    display: none;
  }
}
@media (pointer: coarse), (max-width: 600px) {
  #social-chat.keyboard-visible .chat-log {
    min-height: 0;
  }
}

/* Presence shares chat's signed-identity heartbeat. */
#menu .title-online {
  margin: -8px 0 18px;
  color: #9bb4c3;
  font-size: 12px;
  letter-spacing: 0.4px;
}
#menu .title-online::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 8px;
  border-radius: 50%;
  background: #718391;
}
#menu .title-online.available::before {
  background: #7ee5bd;
}
#social-chat.has-unread .chat-toggle {
  border-color: #ffd278;
  background: #3b2b15;
}
#social-chat.has-unread .chat-toggle svg {
  stroke: #ffe1a0;
}
#social-chat .chat-unread {
  background: #ffd278;
  color: #211707;
}
#social-chat .chat-tabs .has-unread::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: #ffd278;
}

/* One conversation: history scrolls above the composer and quick replies. */
#social-chat .chat-panel {
  display: flex;
  flex-direction: column;
  height: min(580px, calc(100dvh - 98px));
  overflow: hidden;
}
#social-chat.during-game .chat-panel {
  height: min(580px, calc(100dvh - 138px));
}
#social-chat .chat-panel > header,
#social-chat .chat-presence,
#social-chat .chat-status {
  flex-shrink: 0;
}
#social-chat .chat-details {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  gap: 6px;
  overflow: hidden;
}
#social-chat .chat-identity,
#social-chat .chat-compose,
#social-chat .chat-rename {
  flex-shrink: 0;
}
#social-chat .chat-log {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}
#social-chat .chat-quick {
  flex: 0 0 auto;
  max-height: 102px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px;
  align-content: start;
  scrollbar-width: thin;
}
#social-chat .chat-policy {
  flex: 0 1 100px;
  min-height: 0;
}
@media (pointer: coarse), (max-width: 600px) {
  #social-chat .chat-panel,
  #social-chat.during-game .chat-panel {
    height: min(580px, calc(var(--chat-vheight, 100dvh) - 16px));
  }
  #social-chat .chat-quick {
    max-height: 104px;
  }
  #social-chat.keyboard-visible .chat-quick {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: 48px;
  }
  #social-chat.keyboard-visible .chat-quick button {
    flex: 0 0 auto;
    min-height: 40px;
    white-space: nowrap;
    padding: 6px 10px;
  }
  #social-chat.keyboard-visible .chat-panel {
    gap: 2px;
    padding-top: 6px;
    padding-bottom: 6px;
  }
  #social-chat.keyboard-visible .chat-details {
    gap: 2px;
  }
}

/* Reserve a separate lower pane when a phone menu and chat are both open. */
@media (max-width: 600px) {
  body.chat-open:has(.screen:not(.hidden)) #social-chat:not(.keyboard-visible) .chat-panel {
    height: calc(50dvh - 12px);
    max-height: calc(50dvh - 12px);
  }
  body.chat-open:has(.screen:not(.hidden)) #social-chat:not(.keyboard-visible) .chat-quick {
    max-height: 72px;
  }
  body.chat-open:has(.screen:not(.hidden)) .chat-backdrop {
    background: transparent;
  }
}
@media (max-width: 600px) and (min-height: 501px) {
  body.in-match #social-chat { top: 136px; }
}
