/* ---- the family chat (public/chat.js) ------------------------------------------------------- */

/* The 💬 button in the top bar, with its unread badge. */
.chat-btn {
  position: relative;
}
.chat-badge {
  position: absolute;
  top: -5px;
  right: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--red-bright), var(--red));
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 0 0 2px #0a1a33;
  animation: chat-badge-in 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
}
@keyframes chat-badge-in {
  from {
    transform: scale(0);
  }
}

/* A full-height sheet: header, the messages, then the composer. */
.chat-sheet .sheet-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}
.chat-header {
  flex: none;
  padding: 22px 64px 10px 22px;
  border-bottom: 1px solid var(--line);
}
.chat-header h2 {
  margin: 0;
  font-size: 22px;
}
.chat-header p {
  margin: 2px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-main {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 14px 14px;
}
.chat-more {
  margin: 10px 0 4px;
  text-align: center;
}
.chat-empty {
  padding-top: 40px;
}

.chat-day {
  margin: 16px 0 8px;
  text-align: center;
}
.chat-day span,
.chat-event > span {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  background: #e6f0fb;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
}

/* Event lines from the game: small, centred, a little bit smug. */
.chat-event {
  position: relative;
  margin: 8px auto;
  max-width: 92%;
  text-align: center;
}
.chat-event > span {
  padding: 5px 12px;
  border-radius: 14px;
  background: #fff7dc;
  color: #6a4a00;
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.chat-event .chat-time {
  margin-left: 4px;
  color: #a08a55;
}
.chat-event.deleted > span {
  background: #eef3f9;
  color: var(--ink-faint);
  font-style: italic;
}

/* A run of messages from one person: their head, their name, the bubbles. */
.chat-group {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
}
.chat-group.me {
  justify-content: flex-end;
}
.chat-pic {
  flex: none;
  width: 36px;
  height: 36px;
  margin-top: 12px;
}
.chat-pic .head.still {
  width: 36px;
  height: 36px;
}
.chat-pic .head .bubble {
  box-shadow: 0 0 0 2px #fff, 0 2px 6px rgba(0, 10, 40, 0.2);
}
.chat-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-width: 0;
  max-width: min(78%, 340px);
}
.chat-group.me .chat-col {
  align-items: flex-end;
}
.chat-name {
  padding-left: 4px;
  font-size: 13px;
  font-weight: 900;
}

.chat-bubble {
  position: relative;
  max-width: 100%;
  padding: 8px 12px 6px;
  border-radius: 18px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 0 #d9e7f6, 0 2px 6px rgba(16, 38, 74, 0.06);
  line-height: 1.4;
  cursor: default;
}
.chat-group.them .chat-bubble:first-of-type {
  border-top-left-radius: 6px;
}
.chat-group.me .chat-bubble {
  background: linear-gradient(180deg, var(--red-bright), var(--red));
  color: #fff;
  box-shadow: 0 2px 6px rgba(200, 16, 46, 0.25);
}
.chat-group.me .chat-bubble:first-child {
  border-top-right-radius: 6px;
}
.chat-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-time {
  margin-left: 8px;
  float: right;
  position: relative;
  top: 5px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-faint);
}
.chat-group.me .chat-time {
  color: rgba(255, 255, 255, 0.78);
}
.chat-event .chat-time {
  float: none;
  top: 0;
}
.chat-group .chat-bubble.jumbo {
  padding: 0 2px;
  background: none;
  box-shadow: none;
}
.chat-bubble.jumbo .chat-text {
  font-size: 40px;
  line-height: 1.15;
}
.chat-group .chat-bubble.jumbo .chat-time {
  top: 14px;
  color: var(--ink-faint);
}
.chat-bubble.deleted {
  background: #eef3f9;
  color: var(--ink-faint);
  font-style: italic;
  box-shadow: none;
}
.chat-group.me .chat-bubble.deleted {
  background: #f6e3e6;
  color: #9a5a64;
  box-shadow: none;
}
.chat-group.me .chat-bubble.deleted .chat-time {
  color: #b48a91;
}

/* Tap a message you can delete and its 🗑️ button appears beside it. */
.chat-bubble[tabindex],
.chat-event[tabindex] {
  cursor: pointer;
}
.chat-bubble[tabindex]:focus-visible,
.chat-event[tabindex]:focus-visible {
  outline: 3px solid #6fb6ff;
  outline-offset: 2px;
}
.chat-delete {
  display: none;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  padding: 5px 10px;
  border: 0;
  border-radius: 999px;
  background: #fff0f2;
  color: #b0142b;
  font-size: 13px;
  font-weight: 800;
  font-style: normal;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1.5px #f5c2ca, 0 4px 10px rgba(0, 10, 40, 0.15);
  cursor: pointer;
}
.picked > .chat-delete {
  display: block;
}
.chat-group.me .chat-delete,
.chat-event .chat-delete {
  right: calc(100% + 8px);
}
.chat-group.them .chat-delete {
  left: calc(100% + 8px);
}
.chat-event .chat-delete {
  right: auto;
  left: 50%;
  top: calc(100% + 4px);
  transform: translateX(-50%);
  z-index: 1;
}

.chat-jump {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  box-shadow: 0 6px 16px rgba(0, 10, 40, 0.3);
  cursor: pointer;
}

/* The composer: emoji, the message, send. */
.chat-composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  border-radius: 0 0 28px 28px;
}
.chat-field {
  position: relative;
  flex: 1;
  min-width: 0;
}
.chat-sheet textarea.chat-input {
  display: block;
  padding: 10px 14px;
  border-radius: 20px;
  resize: none;
  max-height: 140px;
  line-height: 1.35;
}
.chat-count {
  position: absolute;
  right: 12px;
  bottom: -2px;
  transform: translateY(100%);
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-faint);
}
.chat-send,
.chat-tray-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.chat-send {
  background: linear-gradient(180deg, var(--red-bright), var(--red));
  color: #fff;
  font-size: 19px;
  box-shadow: 0 6px 14px rgba(200, 16, 46, 0.3);
  transition: transform 0.12s, opacity 0.15s;
}
.chat-send:active {
  transform: scale(0.92);
}
.chat-send:disabled {
  opacity: 0.4;
  box-shadow: none;
  cursor: default;
}
.chat-tray-btn {
  background: #eef5fd;
  font-size: 22px;
}
.chat-tray-btn[aria-expanded='true'] {
  background: #dfeaf8;
}
.chat-tray {
  flex: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 2px;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  background: #f7fbff;
}
.chat-emoji {
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: none;
  font-size: 24px;
  cursor: pointer;
}
.chat-emoji:hover {
  background: #e6f0fb;
}

/* New messages while the chat is shut: a toast with the sender's head. */
.toast.chat {
  pointer-events: auto;
  cursor: pointer;
  max-width: 100%;
  text-align: left;
}
.chat-toast-body {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-toast-body .chat-pic {
  margin: 4px 0 0;
}
.chat-toast-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.chat-toast-text strong {
  filter: brightness(1.9) saturate(0.8);
}
.chat-toast-text small {
  opacity: 0.7;
}

@media (max-width: 640px) {
  .chat-sheet {
    top: calc(10px + env(safe-area-inset-top));
    max-height: none;
  }
  .chat-composer {
    border-radius: 0;
  }
}
