.chat-entry {
  position: relative;
  display: inline-flex;
  min-height: 2.75rem;
  align-items: center;
  gap: .42rem;
  padding: .42rem .74rem;
  border: 1px solid #ffd8c2;
  border-radius: 99rem;
  background: #ffb69e;
  color: #321612;
  font-size: .85rem;
  font-weight: 800;
  white-space: nowrap;
  touch-action: manipulation;
}

.chat-glyph {
  position: relative;
  display: inline-grid;
  width: 1.02rem;
  height: .81rem;
  flex: none;
  place-items: center;
  border: 1.6px solid currentColor;
  border-radius: .27rem;
}

.chat-glyph::before {
  position: absolute;
  bottom: -.23rem;
  left: .12rem;
  width: .29rem;
  height: .24rem;
  border-left: 1.6px solid currentColor;
  transform: skewY(-40deg);
  content: '';
}

.chat-glyph::after {
  width: .2rem;
  height: .14rem;
  margin-right: .22rem;
  border-radius: 100%;
  background: currentColor;
  box-shadow: .28rem 0 currentColor;
  content: '';
}

.chat-unread {
  position: absolute;
  top: -.37rem;
  right: -.31rem;
  display: grid;
  min-width: 1.18rem;
  min-height: 1.18rem;
  place-items: center;
  padding-inline: .21rem;
  border: 1px solid #551f20;
  border-radius: 99rem;
  background: #ffdd9f;
  color: #482015;
  font-size: .67rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.chat-sheet {
  position: fixed;
  inset: auto 0 var(--chat-offset, 0px);
  width: min(100%, 31rem);
  max-width: none;
  height: min(40rem, 77dvh, calc(var(--chat-height, 100dvh) - .4rem));
  max-height: none;
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid #daa08a70;
  border-bottom: 0;
  border-radius: 1.35rem 1.35rem 0 0;
  background: #241416;
  color: var(--milk);
  box-shadow: 0 -.7rem 3rem #11060799;
}

.chat-sheet[open] { animation: chat-enter .18s ease-out; }
.chat-sheet::backdrop { background: #16080ca3; backdrop-filter: blur(2px); }
body:has(.chat-sheet[open]) { overflow: hidden; }

@keyframes chat-enter {
  from { transform: translateY(.75rem); opacity: .5; }
  to { transform: none; opacity: 1; }
}

.chat-sheet-inner {
  display: grid;
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.chat-sheet-head {
  position: relative;
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .8rem 1rem .58rem;
  border-bottom: 1px solid #dc9d8c37;
  background: radial-gradient(ellipse at 77% 0%, #7f3b425e, transparent 74%), #381c21;
}

.chat-sheet-head h2 { font: 760 1.32rem/1.2 var(--serif); }
.chat-sheet-head p { margin-top: .13rem; color: #f5b7a6; font-size: .74rem; font-variant-numeric: tabular-nums; }

.chat-dismiss {
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  flex: none;
  place-items: center;
  padding: 0;
  border: 1px solid #d9998d68;
  border-radius: 50%;
  background: #fff5ee0d;
  color: #ffe2d4;
  font-size: 1.4rem;
  line-height: 1;
}

.chat-transcript { position: relative; display: grid; min-height: 0; grid-template-rows: minmax(0, 1fr); }

.chat-log {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  gap: .65rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-anchor: none;
  padding: .7rem 1rem;
}

.chat-log:focus-visible { outline: 2px solid var(--gold); outline-offset: -3px; }
.chat-date { align-self: center; padding-block: .12rem; color: #d4aaa2; font-size: .7rem; font-variant-numeric: tabular-nums; }
.chat-message { display: flex; max-width: min(90%, 24rem); align-self: flex-start; align-items: flex-start; gap: .48rem; }
.chat-message > div { min-width: 0; }
.chat-message .avatar { --size: 1.9rem; margin-top: .06rem; }
.chat-message small { display: block; margin: 0 .22rem .13rem; color: #ffd0bd; font-size: .73rem; overflow-wrap: anywhere; }
.chat-message.is-grouped { margin-top: -.35rem; padding-inline-start: 2.38rem; }
.chat-message.is-own { flex-direction: row-reverse; align-self: flex-end; }
.chat-message.is-own small { text-align: right; }
.chat-message.is-own.is-grouped { padding-inline: 0 2.38rem; }

.chat-message p {
  width: fit-content;
  padding: .44rem .67rem;
  border-radius: .26rem .88rem .88rem .88rem;
  background: #503038;
  color: #fff0ec;
  font-size: .92rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.chat-message.is-own p { margin-left: auto; border-radius: .88rem .26rem .88rem .88rem; background: #fbb5a6; color: #311821; }
.chat-message.is-grouped p { border-radius: .78rem; }

.chat-blank {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .72rem;
  color: #deb6ad;
  font-size: .9rem;
}
.chat-bell { width: 3.1rem; height: 3.1rem; object-fit: contain; }

.chat-jump {
  position: absolute;
  right: 1rem;
  bottom: .55rem;
  min-height: 2.75rem;
  padding: .28rem .7rem;
  border: 1px solid #f4a58c;
  border-radius: 99rem;
  background: #401f24;
  color: #ffdece;
  font-size: .78rem;
  font-weight: 700;
  box-shadow: 0 .18rem .75rem #13070890;
}

.chat-controls {
  display: grid;
  min-width: 0;
  gap: .47rem;
  padding: .49rem max(.85rem, env(safe-area-inset-right)) max(.7rem, env(safe-area-inset-bottom)) max(.85rem, env(safe-area-inset-left));
  border-top: 1px solid #dc9d8c37;
  background: #341e23;
}

.chat-reactions { display: grid; width: min(100%, 19.2rem); grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .25rem; }
.chat-react {
  display: grid;
  min-height: 2.75rem;
  place-items: center;
  padding: 0;
  border: 1px solid #e9ad973b;
  border-radius: .83rem;
  background: #57333b;
  font-size: 1.15rem;
  line-height: 1;
  touch-action: manipulation;
}

.chat-compose-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .4rem; }
.chat-message-input, .chat-send { min-height: 2.82rem; border-radius: .85rem; }
.chat-message-input { width: 100%; min-width: 0; padding: .55rem .68rem; border: 1px solid #d7a1916b; background: #211116; color: #fff2eb; font-size: 1rem; }
.chat-message-input::placeholder { color: #cca69d; opacity: 1; }
.chat-send { padding: .45rem .86rem; border: 1px solid #ffd3bd; background: #ffb69e; color: #381922; font-size: .87rem; font-weight: 800; touch-action: manipulation; }
.chat-send:disabled { border-color: #e8b8ad26; background: #573a42; color: #c9a8a3; }
.chat-react:disabled { opacity: .55; }
.chat-react img { width: 1.62rem; height: 1.62rem; object-fit: contain; }
.chat-emoji-still { font-size: 1.75rem; line-height: 1; }
.chat-message p > img { width: 2.15rem; height: 2.15rem; object-fit: contain; }
.chat-error { margin-top: .45rem; color: #ffbaa9; font-size: .79rem; }

.chat-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (hover: hover) {
  .chat-entry:hover, .chat-send:hover:not(:disabled) { background: #ffccb9; }
  .chat-react:hover:not(:disabled), .chat-dismiss:hover { background: #70414b; }
}

@media (min-width: 47rem) {
  .chat-sheet { bottom: max(.85rem, var(--chat-offset, 0px)); border-bottom: 1px solid #daa08a70; border-radius: 1.35rem; }
}

@media (max-height: 29rem) {
  .chat-sheet { height: min(88dvh, calc(var(--chat-height, 100dvh) - .2rem)); }
  .chat-sheet-head { padding-top: .75rem; }
}
