@use '../abstracts' as *;

// ============================================================
// Comments — comments.php, the alonely_comment() callback, comment_form()
// ============================================================

.comments {
  max-width: 700px; margin: 64px auto 0;
}

.comments-title {
  font-family: $font-serif; font-size: 26px; font-weight: 400;
  margin-bottom: 28px;
}

// The pings' group: smaller, after the comments
.pings-title {
  margin: 40px 0 6px;
  font-size: 19px;

  &:first-child { margin-top: 0; }
}

.comment-list,
.comment-list .children { list-style: none; }

// A rule between threads only; replies hang off a thread line (owner, D17)
.comment-list > li {
  padding: 22px 0;
  border-bottom: 1px solid var(--rule);

  &:first-child { padding-top: 0; }
}

.comment-inner {
  display: flex; gap: 18px;

  .avatar {
    @include circle(48px);
    object-fit: cover; flex-shrink: 0;
    border: 3px solid var(--ring);
  }
}

.comment-main {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere; // long words / links (PLAYBOOK §2)
}

.comment-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
}

.c-name {
  font-weight: 500; font-size: 15.5px; color: var(--ink);

  a { color: inherit; text-decoration: none; }
  a:hover { color: var(--accent-deep); }
}

.c-date {
  font-size: 13px; color: var(--ink-faint); text-decoration: none;

  &:hover { color: var(--accent-deep); }
}

.comment-edit-link {
  font-size: 13px; color: var(--ink-faint);
}

.comment-awaiting-moderation {
  margin-top: 4px;
  font-size: 13.5px;
  font-style: italic;
  color: var(--accent-deep);
}

// What a comment holds — the post's prose (wordpress/_prose.scss) at the
// comment's scale: same faces and tokens, smaller steps, plainer boxes
// (toolkit: "a post about comments is about what a comment holds too")
.c-text {
  font-size: 15px; font-weight: 300; color: var(--ink-soft); margin-top: 4px;

  :where(p, ul, ol, dl, figure, blockquote, pre, table, address, h1, h2, h3, h4, h5, h6) { margin: 0; }
  > * + * { margin-top: 0.8em; }

  :where(h1, h2, h3, h4, h5, h6) {
    font-family: $font-serif;
    font-weight: 400;
    line-height: 1.5;
    color: var(--ink);
  }

  h1 { font-size: 21px; }
  h2 { font-size: 19px; }
  h3 { font-size: 17.5px; }
  h4, h5, h6 { font-size: 16px; }
  h6 { color: var(--ink-soft); }

  > :is(h1, h2, h3, h4, h5, h6):not(:first-child) { margin-top: 1.4em; }

  a { color: var(--accent-deep); text-underline-offset: 3px; text-decoration-color: var(--rule-strong); }
  a:hover { text-decoration-color: currentColor; }

  strong, b { font-weight: 600; color: var(--ink); }

  ul, ol { padding-left: 1.4em; }
  li + li,
  li > :is(ul, ol) { margin-top: 0.35em; }
  li::marker { color: var(--accent); }

  dt { font-weight: 500; color: var(--ink); }
  dd { margin-left: 1.4em; }
  dd + dt { margin-top: 0.6em; }

  blockquote {
    padding-left: 14px;
    border-left: 3px solid var(--accent);
    font-style: italic;

    > * + * { margin-top: 0.6em; }
  }

  code, kbd, samp {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.88em;
  }

  :not(pre) > :is(code, kbd) {
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--glass-strong);
    color: var(--ink);
  }

  // Code keeps its layout and scrolls inside the column (PLAYBOOK §5)
  pre {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    background: var(--code-bg);
    color: var(--code-ink);
    font-size: 13.5px;
    line-height: 1.7;
    white-space: pre;
    overflow-wrap: normal;
    overflow-x: auto;

    code { padding: 0; background: none; color: inherit; font-size: inherit; }
  }

  // A table cannot shrink below its words: it scrolls instead, and its
  // words are not broken by .comment-main's overflow-wrap
  table {
    display: block;
    max-width: 100%;
    width: max-content;
    overflow-x: auto;
    border-collapse: collapse;
    font-size: 14px;
    overflow-wrap: normal;
  }

  th, td {
    padding: 7px 12px;
    border: 1px solid var(--rule-strong);
    text-align: left;
    vertical-align: top;
  }

  th { background: var(--glass); font-weight: 500; color: var(--ink); }

  hr {
    height: 0;
    border: 0;
    border-top: 1px solid var(--rule-strong);
  }

  img { max-width: 100%; height: auto; }
}

.c-reply {
  display: inline-block; margin-top: 8px; font-size: 13.5px;

  a { color: var(--accent-deep); text-decoration: none; }
  a:hover { text-decoration: underline; text-underline-offset: 3px; }
}

// The post author's own comments (.bypostauthor): a label after the name
// (alonely_comment())
.bypostauthor > .comment-inner .c-badge {
  align-self: center;
  padding: 1px 9px;
  border-radius: $pill-radius;
  background: var(--glass-strong);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--accent-deep);
}

// Replies: a thread line under the parent's avatar, no rules between them
.comment-list .children {
  margin: 20px 0 0 23px;
  padding-left: 24px;
  border-left: 2px solid var(--rule);

  > li + li { margin-top: 20px; }

  @include below(mobile) { margin-left: 17px; padding-left: 14px; }
}

// Ten-level threads leave the tenth reply a few pixels wide: stop stepping in
// after the fifth level (WordPress's default depth), the third on a phone
// (unit-test-findings "Comments")
.comment-list .depth-5 .children {
  margin-left: 0;
  padding-left: 0;
  border-left: 0;
}

@include below(mobile) {
  .comment-list .depth-3 .children {
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
  }
}

// Pingbacks / trackbacks — one line each
.comment-list .pingback,
.comment-list .trackback {
  padding: 14px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 14.5px;
  color: var(--ink-soft);

  a { color: var(--accent-deep); }
}

// the_comments_pagination(): the post's page-link chips
.comments-pagination {
  margin-top: 24px;
  font-size: 14.5px;

  .nav-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }

  .page-numbers { @include page-chip; }
}

.no-comments {
  margin-top: 24px;
  font-size: 14.5px;
  color: var(--ink-faint);
}

// ---- Comment form ----
.comment-respond {
  margin-top: 36px;

  // When replying, the form moves under the comment
  .comment-list & { margin: 20px 0 0; }
}

.comment-reply-title {
  margin-bottom: 14px;
  font-family: $font-serif;
  font-size: 20px;
  font-weight: 400;
  color: var(--ink);

  // "Leave a Reply to <name>": the name reads as part of the title
  > a {
    color: inherit;
    text-decoration-color: var(--rule-strong);
    text-underline-offset: 4px;

    &:hover { color: var(--accent-deep); text-decoration-color: currentColor; }
  }

  // Text, link and "Cancel reply" in one line of text — as flex items the
  // words would be spaced apart by the gap
  small {
    margin-left: 10px;
    font-family: $font-sans;
    font-size: 13.5px;
    white-space: nowrap;
  }
  small a { color: var(--accent-deep); }
}

.comment-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;

  @include below(mobile) { grid-template-columns: minmax(0, 1fr); }

  > p { grid-column: 1 / -1; }

  .comment-form-author,
  .comment-form-email,
  .comment-form-url {
    grid-column: auto;

    @include below(mobile) { grid-column: 1 / -1; }
  }

  .logged-in-as,
  .comment-notes {
    font-size: 13.5px;
    color: var(--ink-faint);

    a { color: var(--accent-deep); }
  }

  label {
    display: block;
    margin-bottom: 4px;
    font-size: 13.5px;
    color: var(--ink-soft);
  }

  .required { color: var(--accent-deep); }

  textarea,
  input[type="text"],
  input[type="email"],
  input[type="url"] {
    width: 100%;
    border-radius: var(--radius-md);
    border: 1px solid var(--hairline);
    background: var(--glass-strong);
    font-family: $font-sans;
    font-size: 15.5px; color: var(--ink); outline: none;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;

    &::placeholder { color: var(--ink-faint); }

    &:focus {
      border-color: var(--accent);
      box-shadow: 0 0 0 4px var(--rule);
    }

    // Replaces outline: none — a clear ring on keyboard focus
    &:focus-visible { box-shadow: 0 0 0 2px var(--accent-deep); }
  }

  textarea {
    display: block;
    min-height: 130px; resize: vertical;
    padding: 18px 22px;
  }

  input[type="text"],
  input[type="email"],
  input[type="url"] {
    height: 48px;
    padding: 0 18px;
  }

  .comment-form-cookies-consent {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 13.5px;
    color: var(--ink-soft);

    input { margin-top: 6px; accent-color: var(--accent-deep); }
    label { margin: 0; font-size: inherit; }
  }

  .submit {
    height: 50px; padding: 0 32px;
    border: none; border-radius: $pill-radius;
    background: var(--btn-grad);
    color: var(--on-accent); font-family: $font-sans;
    font-size: 15.5px; font-weight: 500; cursor: pointer;
    box-shadow: var(--shadow-btn);
    transition: transform 0.25s ease;

    &:hover { transform: translateY(-2px); }
  }
}
