#rin-chat,
#rin-chat * {
  box-sizing: border-box;
  touch-action: manipulation;
}

#rin-chat {
  position: fixed;
  z-index: 999999;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  width: min(348px, calc(100vw - 32px));
  color: #f4efe5;
  color-scheme: dark;
  font: 500 14px/1.5 "Segoe UI", Arial, sans-serif;
  text-align: left;
  pointer-events: none;
  user-select: text;
  -webkit-user-select: text;
}

#game-shell > #rin-chat {
  position: absolute;
}
#rin-chat-panel,
#rin-chat-toggle {
  pointer-events: auto;
}
#rin-chat[hidden],
#rin-chat [hidden] {
  display: none;
}
#rin-chat svg {
  display: block;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
#rin-chat button,
#rin-chat input {
  font: inherit;
}
#rin-chat button {
  cursor: pointer;
}
#rin-chat button:focus-visible,
#rin-chat input:focus-visible {
  outline: 2px solid #edc981;
  outline-offset: 3px;
}

#rin-chat-panel {
  display: flex;
  flex-direction: column;
  height: min(560px, calc(var(--viewport-height, 100dvh) - 84px));
  margin-bottom: 10px;
  overflow: hidden;
  border: 1px solid #cba65c45;
  border-radius: 18px;
  background: linear-gradient(155deg, #343027 0, #22231f 28%, #1b201e 100%);
  box-shadow: 0 16px 48px #0007, inset 0 1px #f8dfa51a;
}

#rin-chat header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid #d7b16d1c;
  background: linear-gradient(105deg, #caa25a12, transparent);
}

#rin-chat .rin-chat-heading {
  display: flex;
  align-items: center;
  gap: 11px;
}
#rin-chat .rin-chat-symbol {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid #dfbb7030;
  border-radius: 12px;
  background: #c8a36514;
  color: #e8c787;
}
#rin-chat h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
}
#rin-chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 0 0;
  color: #aaa99c;
  font-size: 11px;
}
#rin-chat-status::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #a69b7f;
  flex-shrink: 0;
}
#rin-chat[data-connected="true"] #rin-chat-status::before {
  background: #8ec4a0;
}
#rin-chat-hide {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid #ffffff0d;
  border-radius: 10px;
  background: #ffffff05;
  color: #bcb8ab;
}
#rin-chat-hide:hover {
  color: #f4e3bb;
  background: #ffffff0c;
}
#rin-chat-hide svg {
  width: 17px;
  height: 17px;
}

#rin-chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 16px;
  scrollbar-width: thin;
  scrollbar-color: #b69a6540 transparent;
}
#rin-chat-empty {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100%;
  padding: 12px;
  text-align: center;
}
#rin-chat-empty svg {
  width: 32px;
  height: 32px;
  margin-bottom: 14px;
  color: #bfa574;
}
#rin-chat-empty strong {
  color: #d7d1c0;
  font-size: 14px;
  font-weight: 600;
}
#rin-chat-empty span {
  max-width: 205px;
  margin-top: 5px;
  color: #8d9389;
  font-size: 12px;
}
#rin-chat-log p {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  column-gap: 9px;
  position: static;
  margin: 0 0 10px;
  padding: 9px 12px 10px;
  border: 1px solid #e8dec40c;
  border-radius: 3px 12px 12px;
  background: #ffffff05;
  overflow-wrap: anywhere;
}
#rin-chat-log p:last-child {
  margin-bottom: 0;
}
#rin-chat-log .rin-chat-avatar {
  grid-area: 1 / 1 / span 2 / 2;
  align-self: start;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid #dfbb7040;
  border-radius: 9px;
  background: #c8a36514;
  object-fit: cover;
}
#rin-chat-log p > strong {
  display: block;
  grid-area: 1 / 2;
  margin-bottom: 3px;
  color: #d9bc80;
  font-size: 11px;
  font-weight: 700;
}
#rin-chat-log .rin-chat-level,
#rin-chat-log .rin-chat-admin {
  display: inline-flex;
  align-items: center;
  margin-right: 6px;
  padding: 0 5px;
  border: 1px solid #dfbb7040;
  border-radius: 4px;
  background: #c8a36514;
  color: #e8c787;
  font-size: 10px;
  line-height: 1.5;
  vertical-align: baseline;
  white-space: nowrap;
}
#rin-chat-log .rin-chat-admin {
  border-color: #f5747470;
  background: #b6384038;
  color: #ffaba7;
}
#rin-chat-log p > span {
  display: block;
  grid-area: 2 / 2;
  color: #e9e8df;
  white-space: pre-wrap;
}

#rin-chat .rin-chat-compose {
  padding: 12px;
  border-top: 1px solid #d7b16d14;
  background: #0e151324;
}
#rin-chat form {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  border: 1px solid #e0c48d24;
  border-radius: 12px;
  background: #121915a6;
}
#rin-chat form:focus-within {
  border-color: #d9b57477;
  box-shadow: 0 0 0 2px #d9b57412;
}
#rin-chat input {
  flex: 1;
  min-width: 0;
  width: 0;
  min-height: 34px;
  padding: 6px 7px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #f4efe5;
  user-select: text;
  -webkit-user-select: text;
}
#rin-chat input::placeholder {
  color: #82897d;
}
#rin-chat input:focus-visible {
  outline: none;
}
#rin-chat-send {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid #f4d89b5c;
  border-radius: 8px;
  background: #ddbd7a;
  color: #33291b;
  font-size: 12px;
  font-weight: 700;
}
#rin-chat-send svg {
  width: 15px;
  height: 15px;
}
#rin-chat-send:hover {
  background: #eed29a;
}
#rin-chat-send:disabled {
  border-color: transparent;
  background: #635b473d;
  color: #938a75;
  cursor: default;
}

#rin-chat-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  margin-left: auto;
  padding: 10px 17px;
  border: 1px solid #dab97c77;
  border-radius: 24px;
  background: #282b23;
  color: #ecd39e;
  box-shadow: 0 4px 20px #0006, inset 0 1px #ffffff0c;
  font-weight: 600;
}
#rin-chat-toggle:hover {
  background: #36392c;
  border-color: #e4c68c;
}
#rin-chat-unread {
  display: grid;
  place-items: center;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 10px;
  background: #e4c68c;
  color: #30291d;
  font-size: 10px;
  font-weight: 700;
}

@media (pointer: coarse) {
  #rin-chat input {
    font-size: 16px;
  }
  #rin-chat-hide {
    width: 40px;
    height: 40px;
  }
}
