:root {
  --nav-total-height: 64px;
  --keyboard-inset: 0px;
  --chat-bottom: var(--nav-total-height);
}

body:has(.chat-messages) {
  height: 100dvh;
  margin: 0;
  overflow: hidden;
}

body:has(.chat-messages) .container {
  max-width: 800px;
  margin: 0 auto;
  padding-top: 0;
  padding-bottom: 0;
}

.chat-page {
  padding: 0 4px;
  padding-bottom: var(--chat-bottom);
  box-sizing: border-box;
  background: var(--bg);
  flex-direction: column;
  transition: padding-bottom .1s ease-out;
  display: flex;
}

.chat-header {
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 16px 0;
}

.chat-post-link {
  color: var(--text);
  text-decoration: none;
  display: inline-block;
}

.chat-post-link h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.5;
}

.chat-messages {
  -webkit-overflow-scrolling: touch;
  flex-direction: column;
  flex: auto;
  min-height: 0;
  padding: 16px 0;
  display: flex;
  overflow-y: auto;
}

.chat-messages:before {
  content: "";
  flex-grow: 1;
}

.chat-msg {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  border-bottom: 1px solid var(--border);
  touch-action: pan-y;
  flex-direction: column;
  gap: 6px;
  padding: 12px 0;
  transition: transform .2s ease-out, background-color .2s;
  display: flex;
  position: relative;
}

.chat-msg:last-child {
  border-bottom: none;
}

.chat-msg.swiping {
  background-color: var(--tag-bg);
  transition: none;
}

.msg-header {
  align-items: center;
  gap: 8px;
  display: flex;
}

.msg-avatar {
  background: var(--border);
  width: 32px;
  height: 32px;
  color: var(--text);
  border-radius: 50%;
  flex-shrink: 0;
  justify-content: center;
  align-items: center;
  font-size: .9em;
  font-weight: bold;
  display: flex;
}

.msg-author {
  color: var(--text);
  font-size: 1em;
  font-weight: 600;
}

.msg-time {
  color: var(--muted);
  font-size: .8em;
}

.msg-edited {
  color: var(--muted);
  margin-left: 4px;
  font-size: .8em;
  font-style: italic;
}

.msg-body {
  flex-direction: column;
  margin-top: 4px;
  display: flex;
}

.msg-content {
  color: var(--text);
  word-wrap: break-word;
  font-size: 16px;
  line-height: 1.5;
}

.msg-deleted {
  color: var(--muted);
  opacity: .7;
  font-style: italic;
  text-decoration: none;
}

.msg-quote {
  background: var(--tag-bg);
  border-left: 3px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
  padding: 8px 12px;
  font-size: .85em;
  display: flex;
}

.quote-author {
  color: var(--link);
  font-weight: 600;
}

.quote-text {
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
}

.chat-date-divider {
  align-items: center;
  margin: 24px 0;
  display: flex;
}

.chat-date-divider:before, .chat-date-divider:after {
  content: "";
  border-bottom: 1px solid var(--border);
  flex: 1;
}

.chat-date-divider span {
  color: var(--muted);
  text-transform: uppercase;
  padding: 0 12px;
  font-size: .8em;
  font-weight: 600;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(5px) scale(.95);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-input-area {
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex: none;
  padding: 10px 0;
}

#chat-form {
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 0;
  display: flex;
}

#chat-message-input {
  border: 1px solid var(--border);
  background: var(--bg);
  min-width: 0;
  min-height: 44px;
  max-height: 150px;
  color: var(--text);
  resize: none;
  field-sizing: content;
  border-radius: 20px;
  outline: none;
  flex: 1;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  overflow-y: hidden;
}

#chat-message-input::-webkit-scrollbar {
  display: none;
}

.btn-send-icon {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  background-color: #0056b3;
  border: none;
  border-radius: 50%;
  outline: none;
  flex-shrink: 0;
  justify-content: center;
  align-items: center;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  display: flex;
}

.btn-send-icon:focus, .btn-send-icon:active, .btn-send-icon:hover {
  background-color: #0056b3;
  outline: none;
}

.btn-send-icon svg {
  stroke: #fff;
  stroke-width: 2.5px;
  fill: none;
  width: 22px;
  height: 22px;
  display: block;
}

.reply-banner {
  background: var(--tag-bg);
  border-radius: 8px;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 8px 12px;
  font-size: .9em;
  display: flex;
}

.reply-banner[hidden] {
  display: none;
}

.cancel-reply {
  cursor: pointer;
  color: var(--muted);
  background: none;
  border: none;
  margin-left: auto;
  font-size: 1.2em;
}

.chat-dialog {
  background: var(--bg);
  color: var(--text);
  border: none;
  border-radius: 16px;
  width: 90%;
  max-width: 320px;
  margin: 0;
  padding: 24px;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 10px 40px #0003;
}

.chat-dialog::backdrop {
  backdrop-filter: blur(2px);
  background: #00000080;
}

.chat-dialog h3 {
  margin-top: 0;
  font-size: 1.2em;
}

.chat-dialog p {
  color: var(--muted);
  margin-bottom: 24px;
  font-size: 16px;
}

.dialog-actions {
  justify-content: flex-end;
  gap: 12px;
  display: flex;
}

.dialog-actions button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 16px;
  font-weight: 600;
}

.dialog-actions .btn-cancel {
  background: var(--tag-bg);
  color: var(--text);
}

.dialog-actions .btn-danger {
  color: #fff;
  background: #dc2626;
}

@starting-style {
  .msg-actions:popover-open {
    opacity: 0;
    transform: translateY(10px) scale(.95);
  }
}

.msg-actions button {
  height: 32px;
  color: var(--text);
  cursor: pointer;
  background: none;
  border: none;
  border-radius: 8px;
  justify-content: center;
  align-items: center;
  margin: 0;
  padding: 0 12px;
  font-size: .9em;
  font-weight: 500;
  line-height: 1;
  display: flex;
}

.msg-actions button:hover {
  background: var(--tag-bg);
}

.msg-actions .msg-del-btn {
  color: #dc2626;
}

.msg-actions .msg-del-btn:hover {
  background: #dc26261a;
}

.chat-input-area:has(#chat-message-input:placeholder-shown) .btn-send-icon {
  opacity: .4;
  pointer-events: none;
  cursor: default;
}

.msg-actions {
  background: var(--bg);
  border: 1px solid var(--border);
  white-space: nowrap;
  inset: auto;
  top: anchor(top);
  right: anchor(right);
  position-try-fallbacks: flip-block, flip-inline;
  opacity: 0;
  transition: opacity .15s ease-out, transform .15s ease-out, overlay .15s allow-discrete, display .15s allow-discrete;
  border-radius: 12px;
  align-items: center;
  gap: 4px;
  margin: -40px 0 0;
  padding: 4px;
  transform: translateY(5px) scale(.95);
  box-shadow: 0 4px 20px #00000026;
}

.msg-actions:popover-open {
  opacity: 1;
  display: flex;
  transform: translateY(0) scale(1);
}

@starting-style {
  .msg-actions:popover-open {
    opacity: 0;
    transform: translateY(5px) scale(.95);
  }
}

body:has(#chat-message-input:focus) footer.toolbar {
  display: none;
}

body:has(#chat-message-input:focus) .chat-page {
  height: 100dvh;
  padding-bottom: 0;
}

.chat-messages {
  flex: auto;
  min-height: 0;
  padding-bottom: 16px;
  overflow-y: auto;
}

body:has(#chat-message-input:focus) .chat-header {
  display: none;
}

body:has(#chat-message-input:focus) .chat-messages {
  padding-top: env(safe-area-inset-top, 16px);
}

.chat-header-badge {
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-bottom: 8px;
  padding: 24px 0;
  display: flex;
}

.chat-main-title {
  color: #888;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: -.03em;
  margin: 0;
  font-size: 2em;
  font-weight: 800;
  line-height: 1;
}

a.room-card {
  border-bottom: 1px solid var(--border);
  color: var(--text);
  background: none;
  flex-direction: column;
  padding: 16px 0;
  text-decoration: none;
  transition: background-color .2s;
  display: flex;
}

a.room-card:hover {
  background-color: var(--tag-bg);
  text-decoration: none;
}

a.room-card:last-child {
  border-bottom: none;
}

.room-card-header {
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 6px;
  display: flex;
}

.room-card-title {
  color: var(--text);
  margin: 0;
  font-size: 1.1em;
  font-weight: 600;
  line-height: 1.3;
}

.room-card-count {
  background: var(--tag-bg);
  min-width: 24px;
  height: 24px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 12px;
  flex-shrink: 0;
  justify-content: center;
  align-items: center;
  padding: 0 6px;
  font-size: .75em;
  font-weight: 600;
  display: inline-flex;
}

.room-card-preview {
  color: var(--muted);
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-size: .95em;
  line-height: 1.4;
  display: -webkit-box;
  overflow: hidden;
}

.chat-page {
  box-sizing: border-box;
  flex-direction: column;
  display: flex;
}

.chat-messages {
  flex-direction: column;
  flex: auto;
  min-height: 0;
  display: flex;
  overflow-y: auto;
}

.chat-input-area {
  flex: none;
}

body:has(.chat-messages) .chat-page {
  height: 100dvh;
}
