/* The chat stays above the reserved control dock, inside the game viewport. */
body.peer-chat-enabled .chatarea:empty {
  display: none;
}

body.peer-chat-enabled #inputTextDiv {
  position: absolute;
  inset: auto 14px 14px auto;
  width: min(360px, calc(100% - 28px));
  max-height: min(440px, calc(100% - 28px));
  padding: 0;
  margin: 0;
  overflow: hidden;
  border: 1px solid #495443;
  border-radius: 18px;
  background: #16271ff5;
  box-shadow: 0 18px 60px #0006;
  color: #f3f0e6;
  pointer-events: auto;
  cursor: default;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  user-select: text;
  touch-action: auto;
  z-index: 2600;
}

body.peer-chat-enabled #inputTextDiv[open] {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}

.peer-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: 0 0 auto;
  padding: 17px 17px 14px;
  border-bottom: 1px solid #34483b;
}

.peer-chat-header > div {
  flex: 1 1 auto;
  min-width: 0;
}

.danmaku-toggle {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 5px;
  min-height: 44px;
  color: #d8d5c6;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}

.danmaku-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: #dfbd7c;
}

.peer-danmaku {
  position: absolute;
  inset: 48px 12px auto;
  height: 64px;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  z-index: 1200;
}

.danmaku-message {
  position: absolute;
  top: calc(var(--danmaku-lane) * 30px);
  left: 100%;
  width: max-content;
  max-width: 95%;
  padding: 4px 10px;
  overflow: hidden;
  border-radius: 12px;
  background: #10251db8;
  color: #f5f3e9;
  font:
    500 13px/20px "Segoe UI",
    "PingFang SC",
    "Microsoft YaHei",
    sans-serif;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 3px #000c;
  pointer-events: none;
  animation: peer-danmaku-pass 6.5s linear both;
}

.danmaku-message.is-own {
  color: #f2d39b;
}

.danmaku-message.is-still {
  left: 50%;
  transform: translateX(-50%);
  animation: none;
}

@keyframes peer-danmaku-pass {
  to {
    left: 0;
    transform: translateX(-100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .danmaku-message {
    left: 50%;
    transform: translateX(-50%);
    animation: none;
  }
}

.peer-chat-header h2 {
  margin: 0;
  color: #f3f0e6;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.4px;
}

.peer-chat-header p {
  margin: 6px 0 0;
  color: #a8b6ac;
  font-size: 10px;
}

body.peer-chat-enabled #inputClose {
  flex: 0 0 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid #425340;
  border-radius: 11px;
  background: #25372c;
  color: #d9cbae;
  font-size: 25px;
  line-height: 1;
}

body.peer-chat-enabled #chatoutput {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  min-height: 80px;
  max-height: min(260px, 35dvh);
  padding: 16px;
  overflow: hidden auto;
  color: #f3f0e6;
  text-shadow: none;
  text-align: left;
  font-size: 13px;
  line-height: 1.65;
  cursor: text;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: #596d54 transparent;
}

body.peer-chat-enabled #chatoutput:empty::before {
  content: "还没有消息，先和朋友打个招呼吧。";
  padding: 14px 0;
  color: #a8b6ac;
  font-size: 11px;
}

body.peer-chat-enabled .chat-message {
  flex: 0 0 auto;
  max-width: 87%;
  padding: 9px 12px;
  border: 1px solid #3c5140;
  border-radius: 3px 13px 13px;
  background: #283b2e;
  color: #f3f0e6;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  touch-action: pan-y;
}

body.peer-chat-enabled .chat-message::before {
  content: attr(data-author);
  display: block;
  max-width: 100%;
  margin-bottom: 4px;
  overflow: hidden;
  color: #b2c3ac;
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.peer-chat-enabled .chat-message.is-own {
  align-self: flex-end;
  border-color: #786948;
  border-radius: 13px 3px 13px 13px;
  background: #51472e;
}

body.peer-chat-enabled .chat-message.is-own::before {
  color: #e4c990;
}

body.peer-chat-enabled #inputTextDivInner {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
  width: auto;
  max-width: none;
  margin: 0;
  padding: 11px;
  border: 0;
  border-top: 1px solid #34483b;
  border-radius: 0;
  background: #122018;
  filter: none;
}

body.peer-chat-enabled #inputText {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #3e513e;
  border-radius: 10px;
  background: #1c2d22;
  color: #f3f0e6;
  font-size: 14px;
  line-height: 1.4;
}

body.peer-chat-enabled #inputText::placeholder {
  color: #9cac9c;
}

body.peer-chat-enabled #inputTextDiv #inputSend,
body.peer-chat-enabled #inputTextDiv #toggleChatMode {
  display: grid;
  flex: 0 0 44px;
  place-items: center;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid #4a5d43;
  border-radius: 10px;
  background: #2a3d2d;
  color: #e4cf9e;
}

body.peer-chat-enabled #inputTextDiv #inputSend {
  border-color: #d4b479;
  background: #dfbd7c;
  color: #25301f;
  font-size: 20px;
}

body.peer-chat-enabled #inputTextDiv.emoji-mode #inputSend {
  display: none;
}

body.peer-chat-enabled #inputTextDiv.emoji-mode #chatEmojiList {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
}

body.peer-chat-enabled #inputTextDiv .chat-emoji {
  display: grid;
  place-items: center;
  min-height: 44px;
  border-radius: 8px;
  font-size: 21px;
}

#comment {
  position: relative;
}

#comment .chat-unread {
  position: absolute;
  top: -4px;
  right: -4px;
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border: 2px solid #14221c;
  border-radius: 10px;
  background: #e1bc79;
  color: #15211a;
  font:
    600 9px/1 "Segoe UI",
    sans-serif;
}

#comment .chat-unread[hidden] {
  display: none;
}

body.peer-chat-enabled #inputTextDiv :focus-visible {
  outline: 2px solid #e1bc79;
  outline-offset: 2px;
}

@media (width <= 600px) {
  body.peer-chat-enabled #inputTextDiv {
    right: 10px;
    bottom: 10px;
    width: calc(100% - 20px);
    max-width: 380px;
    max-height: calc(100% - 20px);
    border-radius: 15px;
  }

  body.peer-chat-enabled #inputText {
    font-size: 16px;
  }
}

@media (height <= 500px) and (orientation: landscape) {
  body.peer-chat-enabled #inputTextDiv {
    right: 8px;
    bottom: 8px;
    max-height: calc(100% - 16px);
    width: min(340px, calc(100% - 16px));
  }

  .peer-chat-header {
    padding: 6px 10px;
  }

  .peer-chat-header p {
    display: none;
  }

  body.peer-chat-enabled #chatoutput {
    min-height: 44px;
    max-height: 24dvh;
    padding: 8px 12px;
  }

  body.peer-chat-enabled #inputTextDivInner {
    padding: 7px;
  }
}

body.peer-chat-enabled #toggleChatMode svg {
  display: block;
  width: 20px;
  height: 20px;
}
