/* QBH blog comments: a prominent discussion panel at the end of an article.
   Collapsible header, scrollable thread. Colours follow the article theme
   tokens where a page defines them, with plain fallbacks for older pages. */

.qbh-comments {
  --qbh-c-line: var(--line, #d9d3c6);
  --qbh-c-paper: var(--paper, #fffdf9);
  --qbh-c-ink: var(--ink, #111827);
  --qbh-c-muted: var(--muted, #475569);
  --qbh-c-accent: var(--blue, #0b2f58);
  --qbh-c-gold: var(--gold, #f2c230);
  max-width: 76ch;
  margin: 3.5rem auto 4rem;
  padding: 0 1rem;
  color: var(--qbh-c-ink);
  font-family: inherit;
  scroll-margin-top: 5rem;
}

/* A rule across the page so the section reads as its own destination. */
.qbh-comments::before {
  content: "";
  display: block;
  height: 3px;
  margin-bottom: 1.75rem;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--qbh-c-accent), var(--qbh-c-gold));
}

.qbh-comments-toggle {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--qbh-c-line);
  border-radius: 14px 14px 0 0;
  border-bottom-color: transparent;
  background: var(--qbh-c-paper);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.qbh-comments:not(.is-open) .qbh-comments-toggle {
  border-radius: 14px;
  border-bottom-color: var(--qbh-c-line);
}
.qbh-comments-toggle:hover { border-color: var(--qbh-c-accent); }
.qbh-comments-toggle:focus-visible { outline: 2px solid var(--qbh-c-accent); outline-offset: 2px; }

.qbh-comments-heading { flex: 1 1 auto; display: grid; gap: .15rem; min-width: 0; }
.qbh-comments-title {
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: -.01em;
  line-height: 1.2;
}
.qbh-comments-sub {
  color: var(--qbh-c-muted);
  font-size: .82rem;
  font-weight: 500;
}

.qbh-comments-count:not(:empty) {
  min-width: 2rem;
  padding: .2rem .65rem;
  border-radius: 999px;
  background: var(--qbh-c-accent);
  color: #fff;
  font-size: .9rem;
  font-weight: 800;
  text-align: center;
}

.qbh-comments-chevron { font-size: 1.1rem; color: var(--qbh-c-muted); transition: transform .18s ease; }
.qbh-comments.is-open .qbh-comments-chevron { transform: rotate(180deg); }

.qbh-comments-panel {
  padding: 1.25rem;
  border: 1px solid var(--qbh-c-line);
  border-top: 0;
  border-radius: 0 0 14px 14px;
  background: var(--qbh-c-paper);
}

.qbh-comments-status { margin: 0 0 1rem; color: var(--qbh-c-muted); font-size: .92rem; }
.qbh-comments-status:empty { display: none; }

/* The scrollable thread. */
.qbh-comments-list {
  max-height: 30rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.qbh-comments-list:not(:empty) {
  padding-right: .5rem;
  margin-bottom: 1.75rem;
}
.qbh-comments-list:focus-visible { outline: 2px solid var(--qbh-c-accent); outline-offset: 3px; }

.qbh-comment {
  padding: .9rem 0 .9rem 1rem;
  border-left: 3px solid var(--qbh-c-line);
  border-bottom: 1px solid var(--qbh-c-line);
}
.qbh-comment:last-child { border-bottom: 0; }
.qbh-comments.has-comments .qbh-comment:first-child { border-left-color: var(--qbh-c-accent); }

.qbh-comment-title {
  margin: 0 0 .2rem;
  font-size: 1.02rem;
  font-weight: 800;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.qbh-comment-author { font-weight: 700; }

.qbh-comment-meta {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  margin-bottom: .35rem;
  font-size: .85rem;
}
.qbh-comment-meta strong { font-weight: 800; }
.qbh-comment-meta time { color: var(--qbh-c-muted); font-size: .8rem; }

.qbh-comment-body {
  margin: 0;
  font-size: .97rem;
  line-height: 1.65;
  white-space: pre-wrap;   /* keep the commenter's line breaks */
  overflow-wrap: anywhere; /* a pasted URL must not widen the page */
}

.qbh-comments-form {
  display: grid;
  gap: .75rem;
  padding-top: 1.25rem;
  border-top: 2px solid var(--qbh-c-line);
}
.qbh-comments-prompt {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
}

.qbh-field { display: grid; gap: .3rem; font-size: .82rem; font-weight: 700; }
.qbh-field input,
.qbh-field textarea {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--qbh-c-line);
  border-radius: 8px;
  background: var(--qbh-c-paper);
  color: inherit;
  font: inherit;
  font-size: .95rem;
  font-weight: 400;
}
.qbh-field textarea { resize: vertical; min-height: 6rem; }
.qbh-field input:focus-visible,
.qbh-field textarea:focus-visible { outline: 2px solid var(--qbh-c-accent); outline-offset: 1px; }

.qbh-comments-submit {
  justify-self: start;
  padding: .65rem 1.6rem;
  border: 0;
  border-radius: 999px;
  background: var(--qbh-c-accent);
  color: #fff;
  font: inherit;
  font-size: .95rem;
  font-weight: 800;
  cursor: pointer;
}
.qbh-comments-submit[disabled] { opacity: .6; cursor: default; }

.qbh-comments-note,
.qbh-comments-formmsg { margin: 0; color: var(--qbh-c-muted); font-size: .82rem; }
.qbh-comments-formmsg:not(:empty) {
  padding: .6rem .8rem;
  border-radius: 8px;
  background: color-mix(in srgb, var(--qbh-c-accent) 10%, transparent);
  color: var(--qbh-c-ink);
  font-weight: 700;
}

/* Honeypot: off-screen rather than display:none, which some bots skip. */
.qbh-trap { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

@media (max-width: 680px) {
  .qbh-comments { margin: 2.5rem auto 3rem; }
  .qbh-comments-title { font-size: 1.15rem; }
  .qbh-comments-list { max-height: 24rem; }
  .qbh-comments-submit { justify-self: stretch; text-align: center; }
}

/* Rail tab that rides down the side of long politics pieces and jumps to the
   discussion. Legible as a comments button without competing with the article:
   it reads as a quiet control until hovered, then fills with the accent. */
.qbh-comments-jump {
  position: fixed;
  top: 50%;
  right: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .7rem .9rem .7rem .85rem;
  border: 1px solid color-mix(in srgb, var(--blue, #0b2f58) 35%, var(--line, #d9d3c6));
  border-right: 0;
  border-radius: 12px 0 0 12px;
  background: var(--paper, #fffdf9);
  color: var(--blue, #0b2f58);
  font: inherit;
  font-size: .85rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 20px -10px rgba(0, 0, 0, .45);
  opacity: 0;
  transform: translate(105%, -50%);
  transition: opacity .22s ease, transform .22s ease, background .18s ease, color .18s ease;
  pointer-events: none;
}
.qbh-comments-jump.is-visible {
  opacity: 1;
  transform: translate(0, -50%);
  pointer-events: auto;
}
.qbh-comments-jump:hover,
.qbh-comments-jump:focus-visible {
  background: var(--blue, #0b2f58);
  color: #fff;
  border-color: var(--blue, #0b2f58);
}
.qbh-comments-jump:focus-visible { outline: 2px solid var(--blue, #0b2f58); outline-offset: 3px; }

.qbh-comments-jump-icon { width: 18px; height: 18px; display: block; flex: 0 0 auto; }
.qbh-comments-jump-label { white-space: nowrap; }

.qbh-comments-jump-count:not(:empty) {
  min-width: 1.35rem;
  padding: .12rem .4rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--blue, #0b2f58) 14%, transparent);
  font-size: .76rem;
  text-align: center;
}
.qbh-comments-jump:hover .qbh-comments-jump-count:not(:empty),
.qbh-comments-jump:focus-visible .qbh-comments-jump-count:not(:empty) {
  background: rgba(255, 255, 255, .22);
}

@media (max-width: 680px) {
  /* Bottom corner on phones, and the word drops so it never crowds the text. */
  .qbh-comments-jump {
    top: auto;
    bottom: 1.1rem;
    padding: .65rem .8rem;
    border-radius: 999px 0 0 999px;
    transform: translate(105%, 0);
  }
  .qbh-comments-jump.is-visible { transform: translate(0, 0); }
  .qbh-comments-jump-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .qbh-comments-jump { transition: opacity .01s linear; transform: translate(0, -50%); }
}

/* One-line taste of the discussion, above the article's title block. */
.qbh-comment-peek {
  --qbh-c-line: var(--line, #d9d3c6);
  --qbh-c-muted: var(--muted, #475569);
  --qbh-c-accent: var(--blue, #0b2f58);
  display: flex;
  align-items: center;
  gap: .5rem;
  max-width: 76ch;
  margin: 1rem auto .25rem;
  padding: .5rem .85rem;
  border: 1px solid var(--qbh-c-line);
  border-left: 3px solid var(--qbh-c-accent);
  border-radius: 4px;
  background: color-mix(in srgb, var(--qbh-c-accent) 5%, transparent);
  color: inherit;
  font-size: .86rem;
  line-height: 1.4;
  text-decoration: none;
  overflow: hidden;
}
.qbh-comment-peek:hover,
.qbh-comment-peek:focus-visible {
  background: color-mix(in srgb, var(--qbh-c-accent) 11%, transparent);
  border-left-color: var(--qbh-c-accent);
}
.qbh-comment-peek:focus-visible { outline: 2px solid var(--qbh-c-accent); outline-offset: 2px; }

.qbh-comment-peek-icon { width: 16px; height: 16px; flex: 0 0 auto; color: var(--qbh-c-accent); }

.qbh-comment-peek-label {
  flex: 0 0 auto;
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--qbh-c-accent);
}

/* The quote takes whatever room is left and truncates rather than wrapping,
   so the strip is always exactly one line. */
.qbh-comment-peek-quote {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qbh-comment-peek-who {
  flex: 0 0 auto;
  color: var(--qbh-c-muted);
  font-size: .78rem;
  font-weight: 700;
}

@media (max-width: 680px) {
  .qbh-comment-peek { margin-inline: 1rem; font-size: .82rem; }
  .qbh-comment-peek-label, .qbh-comment-peek-who { display: none; }
}

/* Articles carry their own stylesheets, and a stale cache can arrive without
   this file at all. Pin the two pieces that look worst when unstyled. */
.qbh-comment-peek{ box-sizing:border-box; max-height:3.2rem; }
.qbh-comment-peek-icon{ width:16px !important; height:16px !important; flex:0 0 16px !important; }
.qbh-comments-jump-icon{ width:18px !important; height:18px !important; flex:0 0 18px !important; }
.qbh-comment-peek-label, .qbh-comment-peek-who, .qbh-comment-peek-quote{ font-size:inherit; }

/* ---------------------------------------------------------------------- dark
 *
 * The panel deliberately takes its colours from the article's own tokens, with
 * light literals as the fallback for older pages. That works on the eleven
 * articles which define dark tokens; on the other thirty-three the fallbacks
 * were the only thing in play, so the discussion stayed a white box at the
 * bottom of a dark page. These give the fallbacks a dark counterpart without
 * taking the choice away from a page that does define its own.
 */
:root[data-theme="dark"] .qbh-comments,
:root[data-theme="dark"] .qbh-comment-peek,
:root[data-theme="dark"] .qbh-comments-jump {
  --qbh-c-line: var(--line, #344239);
  --qbh-c-paper: var(--paper, #111915);
  --qbh-c-ink: var(--ink, #f3f6f1);
  --qbh-c-muted: var(--muted, #c7d0d8);
  --qbh-c-gold: var(--gold, #ffd95a);
  /* Not var(--blue), which the rest of this file uses. In a dark palette --blue
     is a pale link colour, and this token is a BACKGROUND for the count badge
     and the submit button, both of which put #fff on it. A pale fill would
     leave those two labels unreadable, which is worse than not matching the
     page exactly. */
  --qbh-c-accent: #1a5f9e;
}

/* The rail tab reads --blue and --paper directly rather than through the tokens
   above, so it needs saying twice. */
:root[data-theme="dark"] .qbh-comments-jump {
  background: var(--qbh-c-paper);
  color: #bcd9f2;
  border-color: color-mix(in srgb, var(--qbh-c-accent) 55%, var(--qbh-c-line));
  box-shadow: 0 6px 20px -10px rgba(0, 0, 0, .8);
}
:root[data-theme="dark"] .qbh-comments-jump:hover,
:root[data-theme="dark"] .qbh-comments-jump:focus-visible {
  background: var(--qbh-c-accent);
  color: #fff;
  border-color: var(--qbh-c-accent);
}
:root[data-theme="dark"] .qbh-comments-jump:focus-visible { outline-color: #bcd9f2; }
