.public-chat {
  position: fixed;
  z-index: 20;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + var(--chat-keyboard-offset, 0px));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  font-size: 13px;
}
.public-chat-toggle,
.public-chat button:not(.public-chat-message-name, .public-chat-rank) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 33px;
  padding: 5px 10px;
  border: 1px solid #36525c;
  border-radius: 6px;
  color: #c8eee8;
  background: #20363e;
  cursor: pointer;
}
.public-chat .public-chat-toggle {
  gap: 9px;
  min-height: 41px;
  padding-inline: 14px;
  box-shadow: 0 3px 14px #080c12a6;
  font-weight: 650;
}
.public-chat-toggle-arrow {
  width: 8px;
  height: 8px;
  margin-top: 3px;
  border-top: 1.5px solid currentColor;
  border-right: 1.5px solid currentColor;
  transform: rotate(-45deg);
}
.public-chat-toggle[aria-expanded="true"] .public-chat-toggle-arrow { margin-top: -3px; transform: rotate(135deg); }
.public-chat button:hover:not(:disabled) { filter: brightness(1.14); }
.public-chat button:disabled { color: #8b9ea8; cursor: default; }
.public-chat-panel {
  display: flex;
  flex-direction: column;
  width: min(360px, calc(100vw - 32px));
  height: min(470px, calc(var(--chat-viewport-height, 100dvh) - 79px - env(safe-area-inset-bottom)));
  overflow: hidden;
  border: 1px solid #324452;
  border-radius: 10px;
  background: #161e27;
  box-shadow: 0 8px 36px #080c12a0;
}
.public-chat-header { padding: 10px 13px; border-bottom: 1px solid var(--line); }
.public-chat-header-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.public-chat-header h2 { margin: 0; color: #e8edf5; font-size: 14px; }
.public-chat-channel { display: flex; min-width: 0; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.public-chat-channel select {
  min-width: 0;
  max-width: 185px;
  min-height: 30px;
  padding: 3px 7px;
  border: 1px solid #37565e;
  border-radius: 6px;
  background: #1d3038;
  color: #d8efec;
  font: inherit;
  font-size: 12px;
}
.public-chat-channel-blind {
  display: grid;
  flex: 1;
  place-items: center;
  padding: 16px;
  background: #131c25;
  color: #d8e5ed;
  font-weight: 650;
  text-align: center;
}
.public-chat-profile { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 6px; color: var(--muted); font-size: 11px; }
.public-chat-profile b { min-width: 0; color: #e8edf5; overflow-wrap: anywhere; }
.public-chat-log {
  flex: 1;
  min-height: 0;
  padding: 8px 12px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #4b6575 #111923;
  scrollbar-width: thin;
}
.public-chat-empty { margin: 11px 0; color: var(--muted); font-size: 12px; }
.public-chat-message { display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 8px; }
.public-chat-message[data-own] { align-items: flex-end; }
.public-chat-message-head { display: flex; max-width: 100%; flex-wrap: wrap; align-items: center; gap: 3px 5px; margin-bottom: 2px; }
.public-chat-message[data-own] .public-chat-message-head { justify-content: flex-end; }
.public-chat-message-name {
  min-width: 0;
  padding: 0;
  border: 0;
  outline-offset: 1px;
  background: transparent;
  color: #e8edf5;
  font-size: 11px;
  font-weight: 650;
  text-align: left;
  overflow-wrap: anywhere;
}
button.public-chat-message-name { cursor: pointer; }
button.public-chat-message-name:disabled { cursor: default; }
.public-chat :is(span, button).public-chat-staff {
  max-width: 100%;
  padding: 1px 5px;
  border: 1px solid #79643c;
  border-radius: 4px;
  background: #3a3020;
  color: #f4d79a;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.public-chat .public-chat-staff[data-staff-role='deputy'] { border-color: #46696d; background: #23383e; color: #aee0d8; }
.public-chat-message-head time { flex: none; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.public-chat-bubble {
  max-width: 93%;
  padding: 5px 9px;
  border-radius: 7px;
  color: #fff;
  background: #232d39;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.public-chat-message[data-own] .public-chat-bubble { background: #1f3a3e; }
.public-chat-message[data-staff-role] .public-chat-bubble { color: #ff858d; }
.public-chat-rank { display: inline-flex; flex: none; align-items: center; gap: 3px; color: #e7ce97; font-size: 10px; }
.public-chat-rank-icon {
  width: 16px;
  height: 16px;
  background: url('./chat-ranks.png') no-repeat var(--rank-x, 0%) 50% / 600% 100%;
}
.public-chat-rank[data-rank="0"] { color: #bac2cc; }
[data-rank="0"] > .public-chat-rank-icon { background: url('./chat-rank-commoner.png') no-repeat center / contain; }
[data-king-icon] > .public-chat-rank-icon {
  background: url('./chat-king-icons.png') no-repeat var(--king-x) var(--king-y) / var(--king-size);
}
button.public-chat-rank {
  min-height: 24px;
  padding: 1px 5px 1px 2px;
  border: 1px solid #455361;
  border-radius: 5px;
  background: #242f3a;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}
.public-chat-rank[data-seed-rank] {
  border: 1px solid #41635f;
  background: #20343c;
  color: #c6f0e8;
}
.public-chat-seed-rank-icon {
  flex: none;
  width: 20px;
  height: 20px;
  background: url('./chat-seed-ranks.webp') no-repeat var(--seed-rank-x, 0%) var(--seed-rank-y, 0%) / 600% 300%;
}
.public-chat-seed-rank-dialog {
  width: min(340px, calc(100% - 24px));
  max-height: calc(var(--chat-viewport-height, 100dvh) - 24px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 1px solid #54736f;
  border-radius: 10px;
  background: #182530;
  color: #e5edf5;
  box-shadow: 0 10px 45px #0c141ac0;
}
.public-chat-seed-rank-dialog::backdrop { background: #090d16a0; }
.public-chat-seed-rank-details { display: grid; gap: 12px; padding: 14px; }
.public-chat-seed-rank-heading { display: flex; align-items: center; gap: 11px; }
.public-chat-rank-artwork { display: flex; }
.public-chat-rank-artwork > span { width: 46px; height: 46px; }
.public-chat-seed-rank-heading h2 { margin: 0 0 3px; color: #d5f7ef; font-size: 16px; }
.public-chat-seed-rank-details p { margin: 0; line-height: 1.55; word-break: keep-all; overflow-wrap: anywhere; }
#public-chat-seed-rank-range { color: #95dfcf; font-weight: 650; }
.public-chat-rank-counts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; }
.public-chat-rank-counts > div { padding: 6px 8px; border: 1px solid #344b57; border-radius: 6px; background: #14212b; }
.public-chat-rank-counts dt, .public-chat-rank-help, .public-chat-rank-status { color: #b1c5ce; font-size: 11px; }
.public-chat-rank-counts dd { margin: 4px 0 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.public-chat-rank-help { display: grid; gap: 5px; }
.public-chat-seed-rank-details form { justify-self: end; margin: 0; }
.public-chat-controls { padding: 7px 10px 9px; border-top: 1px solid var(--line); background: #19232e; }
.public-chat-form { display: flex; align-items: end; gap: 6px; }
.public-chat-form textarea {
  flex: 1;
  min-width: 0;
  min-height: 35px;
  max-height: 95px;
  padding: 8px;
  resize: vertical;
  border: 1px solid #3a4b5b;
  border-radius: 6px;
  color: #fff;
  background: #131b24;
  font: inherit;
  font-size: 13px;
}
.public-chat-form textarea:focus-visible { outline: 2px solid var(--accent); }
.public-chat-form textarea:disabled { color: var(--muted); }
.public-chat-form button { flex: none; height: 35px; }
.public-chat-count { display: block; margin-top: 5px; color: var(--muted); text-align: right; font-size: 11px; }
.public-chat-status { margin: 0 0 5px; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.public-chat-restriction { margin: 0 0 5px; color: #ffb3bb; font-size: 11px; }
.public-chat-reaction { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }
.public-chat-reaction b { flex: 1; min-width: 0; color: #d7e8ee; font-size: 11px; overflow-wrap: anywhere; }
.public-chat .public-chat-reaction button,
.public-chat .public-chat-retry { min-height: 27px; padding: 2px 7px; font-size: 11px; }
.public-chat .public-chat-retry { margin-bottom: 6px; }

@media (max-width: 520px) {
  html:has(.public-chat) {
    --public-chat-reserve: calc(50px + max(8px, env(safe-area-inset-bottom)));
    scroll-padding-block-end: var(--public-chat-reserve);
  }
  body:has(> .public-chat) { padding-block-end: var(--public-chat-reserve); }
  .public-chat {
    right: max(8px, env(safe-area-inset-right));
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + var(--chat-keyboard-offset, 0px));
  }
  .public-chat button.public-chat-toggle { gap: 6px; min-height: 40px; padding-inline: 9px; }
  .public-chat-panel {
    width: min(360px, calc(100vw - max(8px, env(safe-area-inset-left)) - max(8px, env(safe-area-inset-right))));
    height: min(425px, calc(var(--chat-viewport-height, 100dvh) - 76px - env(safe-area-inset-bottom)));
  }
  .public-chat-form textarea { font-size: 16px; }
  .public-chat-channel select { font-size: 16px; }
}

/* Delete controls, shown to operators and deputies only. */
.public-chat .public-chat-message-delete { display: none; }
.public-chat[data-can-delete] .public-chat-message-delete {
  display: inline-block; min-height: 0; padding: 1px 6px; border: 1px solid #5a3a42; border-radius: 999px;
  background: transparent; color: #f0a6ae; font-size: 10px; line-height: 1.5; cursor: pointer; opacity: .75;
}
.public-chat[data-can-delete] .public-chat-message-delete:hover { opacity: 1; background: #3a2329; }
.public-chat .public-chat-clear {
  display: block; margin: 0 0 6px auto; min-height: 24px; padding: 2px 8px; border: 1px solid #5a3a42; border-radius: 6px;
  background: transparent; color: #f0a6ae; font-size: 11px; cursor: pointer;
}
.public-chat .public-chat-clear[data-armed] { background: #6a2a34; border-color: #b9515f; color: #fff; }
