.chat-header {
  padding: 0.8rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(37, 29, 53, 0.55);
}

.chat-header-title {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.05em;
}

.chat-header-sub {
  font-size: 0.78rem;
  color: var(--ok);
}

.chat-header-sub::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 0.4rem;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
  vertical-align: middle;
}

.chat-log-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.jump-latest {
  position: absolute;
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.chat-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1.25rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.msg {
  display: flex;
  gap: 0.6rem;
  max-width: 78%;
  margin-top: 0.7rem;
  animation: msg-in 0.28s ease-out both;
}

.msg.msg-long {
  animation: msg-fade 0.15s ease-out both;
}

.msg.msg-cont {
  margin-top: 0;
}

.msg-in {
  align-self: flex-start;
}

.msg-out {
  align-self: flex-end;
}

.msg-avatar {
  cursor: pointer;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-raised);
}

.msg-cont .msg-avatar {
  visibility: hidden;
  height: 0;
}

.msg-cont .msg-meta {
  display: none;
}

.msg-body {
  min-width: 0;
}

.msg-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
  font-size: 0.78rem;
}

.msg-name {
  font-weight: 600;
}

.msg-char {
  color: var(--text-muted);
}

.msg-name-title {
  font-weight: 400;
  color: var(--text-muted);
}

.msg-badge {
  padding: 0.05rem 0.4rem;
  border-radius: 6px;
  background: var(--crimson);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.msg-bubble {
  padding: 0.55rem 0.85rem;
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: var(--bg-raised);
  line-height: 1.4;
  overflow-wrap: anywhere;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.msg-out .msg-bubble {
  border-radius: var(--radius) 4px var(--radius) var(--radius);
  border-color: transparent;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  color: var(--gold-ink);
  font-weight: 500;
}

.msg-character .msg-bubble {
  background: linear-gradient(135deg, var(--parchment), #d9c79c);
  color: var(--parchment-ink);
  font-family: Georgia, 'Times New Roman', serif;
  font-style: italic;
}

.msg-tag {
  display: block;
  margin-bottom: 0.15rem;
  font-family: var(--font-body);
  font-size: 0.66rem;
  font-style: normal;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
}

.msg-dm .msg-bubble {
  border: 1px solid var(--crimson);
  box-shadow: 0 0 18px rgba(179, 39, 63, 0.3);
}

/* Declines get a red border and tag so a "no" is obvious at a glance, whatever the bubble style. */
.msg-no .msg-bubble,
.msg-dm.msg-no .msg-bubble {
  border: 2px solid var(--danger);
  box-shadow: 0 0 14px rgba(224, 80, 74, 0.35);
}

.msg-tag-no {
  color: var(--danger);
  font-weight: 700;
  opacity: 1;
}

.msg-character .msg-tag-no {
  color: #a3192e;
}

.msg-system {
  align-self: center;
  margin: 0.8rem 0 0.2rem;
  padding: 0.25rem 0.8rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: center;
}

.msg-sanity {
  max-width: 92%;
  border: 1px solid rgba(160, 120, 255, 0.45);
  background: rgba(123, 92, 255, 0.14);
  color: var(--text);
  font-size: 0.82rem;
  border-radius: var(--radius);
  padding: 0.4rem 0.9rem;
}

.msg-typing-label {
  margin-bottom: 0.2rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-style: italic;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 0.75rem 0.9rem;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

@keyframes msg-fade {
  from {
    opacity: 0;
  }
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 767.98px) {
  /* The page scrolls on phones (see layout.css), so the log just grows to fit its messages. */
  .chat-log-wrap,
  .chat-log {
    flex: 1 0 auto;
  }

  .chat-log {
    overflow-y: visible;
  }

  .jump-latest {
    position: fixed;
    bottom: calc(var(--planner-height, 5rem) + 0.75rem);
    z-index: 21;
  }

  /* The group name and online count cost a lot of height; the chat itself matters more. */
  .chat-header {
    display: none;
  }

  .chat-log {
    padding: 0.5rem 0.75rem;
  }

  .msg {
    max-width: 94%;
    gap: 0.45rem;
  }

  .msg-avatar {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
  }

  .msg-char,
  .msg-name-title {
    display: none;
  }

  .show-char .msg-char,
  .show-char .msg-name-title {
    display: inline;
  }
}
