/* Comments: rounded bubbles, replies tucked under the comment they answer. */

.ai-comments {
  --ai-comment-bubble: var(--ai-bg-sunken);
  --ai-comment-avatar: 2.5rem;
  --ai-comment-indent: calc(var(--ai-comment-avatar) + var(--ai-space-2));

  max-width: var(--ai-prose-max);
  margin-block: var(--ai-space-8);
  margin-inline: auto;
}

[data-theme='dark'] .ai-comments {
  --ai-comment-bubble: var(--ai-bg-raised);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .ai-comments {
    --ai-comment-bubble: var(--ai-bg-raised);
  }
}

.ai-comments__title {
  display: flex;
  align-items: center;
  gap: var(--ai-space-2);
}

.ai-comments__count {
  font-size: var(--ai-fs-xs);
  font-weight: var(--ai-fw-semibold);
  color: var(--ai-text-muted);
}

/* ---- Box ---- */

.ai-comments .comment-respond {
  margin-block: var(--ai-space-4) var(--ai-space-6);
}

.ai-comments__reply-title {
  margin: 0 0 var(--ai-space-2);
  font-size: var(--ai-fs-xs);
  font-weight: var(--ai-fw-semibold);
  color: var(--ai-text-muted);
}

.ai-comments__reply-title small {
  margin-inline-start: var(--ai-space-2);
  font-size: inherit;
}

.ai-comments__reply-title small a {
  color: var(--ai-brand-text);
}

.ai-comments__form {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: var(--ai-space-2);
}

.ai-comments__form > p {
  margin: 0;
}

.ai-comments__me {
  grid-column: 1;
  align-self: start;
}

.ai-comments__field {
  grid-column: 2;
  min-width: 0;
}

.ai-comments__field textarea {
  display: block;
  width: 100%;
  min-height: 2.75rem;
  max-height: 12rem;
  padding: 0.6rem var(--ai-space-4);
  font: inherit;
  font-size: var(--ai-fs-sm);
  line-height: 1.5;
  color: var(--ai-text);
  background: var(--ai-comment-bubble);
  border: 1px solid transparent;
  border-radius: 1.375rem;
  resize: none;
  overflow-y: auto;
}

.ai-comments__field textarea:focus {
  border-color: var(--ai-border-strong);
  outline: none;
  box-shadow: var(--ai-focus-ring);
}

.ai-comments__submit {
  grid-column: 3;
}

.ai-comments__send {
  min-height: 2.75rem;
  border-radius: var(--ai-radius-pill);
}

.ai-comments__login {
  padding: var(--ai-space-5);
  background: var(--ai-comment-bubble);
  border-radius: var(--ai-radius-lg);
}

.ai-comments__login > p {
  margin: 0 0 var(--ai-space-3);
}

.ai-comments__login-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ai-space-2);
}

.ai-comments__login .mea-identity {
  margin-block-start: var(--ai-space-3);
}

/* ---- Thread ---- */

.ai-comments__list,
.ai-comments .children {
  margin: 0;
  padding: 0;
  list-style: none;
}

.ai-comment {
  margin-block: var(--ai-space-3);
}

.ai-comment__row {
  display: flex;
  align-items: flex-start;
  gap: var(--ai-space-2);
}

.ai-comment__avatar {
  flex: none;
  display: inline-grid;
  place-items: center;
  inline-size: var(--ai-comment-avatar);
  block-size: var(--ai-comment-avatar);
  font-size: var(--ai-fs-sm);
  font-weight: var(--ai-fw-bold);
  line-height: 1;
  color: #fff;
  border-radius: 50%;
}

.ai-avatar--0 { background: #086AF5; }
.ai-avatar--1 { background: #0E7C66; }
.ai-avatar--2 { background: #B54708; }
.ai-avatar--3 { background: #6941C6; }
.ai-avatar--4 { background: #C11574; }
.ai-avatar--5 { background: #1D2939; }
.ai-avatar--6 { background: #027A48; }
.ai-avatar--7 { background: #B42318; }

.ai-comment__main {
  min-width: 0;
  flex: 1;
}

.ai-comment__bubble {
  display: inline-block;
  max-width: 100%;
  padding: var(--ai-space-2) var(--ai-space-4);
  background: var(--ai-comment-bubble);
  border-radius: 1.125rem;
}

.ai-comment__author {
  margin: 0;
  font-size: var(--ai-fs-xs);
  font-weight: var(--ai-fw-bold);
  color: var(--ai-text-strong, var(--ai-text));
}

.ai-comment__badge {
  margin-inline-start: var(--ai-space-1);
  padding: 0 0.4rem;
  font-size: var(--ai-fs-2xs);
  font-weight: var(--ai-fw-semibold);
  color: var(--ai-brand-text);
  border: 1px solid currentColor;
  border-radius: var(--ai-radius-pill);
}

.ai-comment__text {
  font-size: var(--ai-fs-sm);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.ai-comment__text p {
  margin: 0;
}

.ai-comment__text p + p {
  margin-block-start: var(--ai-space-2);
}

.ai-comment__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ai-space-3);
  margin: var(--ai-space-1) 0 0;
  padding-inline-start: var(--ai-space-3);
  font-size: var(--ai-fs-2xs);
  font-weight: var(--ai-fw-semibold);
  color: var(--ai-text-muted);
}

.ai-comment__actions a {
  color: inherit;
  text-decoration: none;
}

.ai-comment__actions a:hover,
.ai-comment__actions a:focus-visible {
  text-decoration: underline;
}

.ai-comment__pending {
  margin: var(--ai-space-1) 0 0;
  padding-inline-start: var(--ai-space-3);
  font-size: var(--ai-fs-2xs);
  color: var(--ai-text-muted);
}

.bypostauthor > .ai-comment__row .ai-comment__bubble {
  box-shadow: inset 0 0 0 1px var(--ai-border);
}

/* Replies: smaller, indented under the parent's text, with a thread line. */

.ai-comments .children {
  --ai-comment-avatar: 2rem;

  position: relative;
  margin-inline-start: var(--ai-comment-indent);
}

.ai-comments .children::before {
  content: '';
  position: absolute;
  inset-block: 0 var(--ai-space-4);
  inset-inline-start: calc(var(--ai-space-4) * -1);
  border-inline-start: 2px solid var(--ai-border);
  border-end-start-radius: var(--ai-radius-md);
}

.ai-comments .children .ai-comment {
  margin-block: var(--ai-space-2);
}

.ai-comments .children .ai-comment__avatar {
  font-size: var(--ai-fs-2xs);
}

/* The box when it moves under a comment to answer it. */
.ai-comment .comment-respond {
  margin-block: var(--ai-space-2);
  margin-inline-start: var(--ai-comment-indent);
}

.ai-comments__more {
  margin-inline-start: var(--ai-comment-indent);
  padding: var(--ai-space-1) 0;
  font: inherit;
  font-size: var(--ai-fs-2xs);
  font-weight: var(--ai-fw-semibold);
  color: var(--ai-text-muted);
  background: none;
  border: 0;
  cursor: pointer;
}

.ai-comments__more:hover,
.ai-comments__more:focus-visible {
  color: var(--ai-brand-text);
  text-decoration: underline;
}

.ai-comments .children.is-collapsed > .ai-comment:nth-child(n + 3) {
  display: none;
}

.ai-comments__empty,
.ai-comments__closed {
  color: var(--ai-text-muted);
}

.ai-comments .comment-navigation,
.ai-comments .navigation.comments-pagination {
  margin-block: var(--ai-space-4);
}

@media (max-width: 767px) {
  .ai-comments {
    --ai-comment-avatar: 2.25rem;
  }

  .ai-comments .children {
    --ai-comment-avatar: 1.75rem;
  }

  .ai-comments__form {
    grid-template-columns: auto 1fr;
  }

  .ai-comments__submit {
    grid-column: 2;
    justify-self: end;
  }
}
