/*
 * Answer block: ```page - a whole explainer page in one reply. Tokens in
 * blocks.css; this sheet mints none but two font stacks (--abp-serif,
 * --abp-sans) and reads colour only from --ab-*.
 *
 *   .ab-page            the card in the chat: a strip of actions, then the doc
 *   .ab-page-doc        the document itself; it moves into .ab-reader when
 *                       opened, and is cloned into .ab-page-print and into a
 *                       downloaded file, so its rules never need .ab-page
 *   .ab-reader          the full-screen reader
 *   .ab-page-print      the print-only copy (light, no app chrome)
 *   .ab-toc             the "Jump to" row on an ordinary long reply
 *
 * Text rules carry body:not(#_) (one ID's weight), as chatclean.css does:
 * styles.css sets every h2, p, table and blockquote under .msg-content at
 * (0,3,2), and a page's own typography has to win over that.
 * Chrome text (chips, actions) is CSS generated content from data-label, so
 * copying the reply copies the page, not its buttons.
 */

.ab-page,
.ab-page-doc,
.ab-reader,
.ab-page-print {
  --abp-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --abp-sans: var(--ab-font-ui);
}

/* ── The card ─────────────────────────────────────────────────────────── */
.ab-page {
  margin: 18px 0 22px;
  border: 1px solid var(--ab-hair);
  border-radius: calc(var(--ab-radius) + 4px);
  background: var(--ab-card);
  color: var(--ab-ink);
  overflow: hidden;
  font-family: var(--abp-sans);
}

.ab-page-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 8px 6px 16px;
  border-bottom: 1px solid var(--ab-hair);
  background: var(--ab-paper);
}
.ab-page-kind {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-right: auto;
  color: var(--ab-muted);
  font: 500 12.5px/1.2 var(--abp-sans);
  white-space: nowrap;
}
.ab-page-kind .ab-page-ico { color: var(--ab-ink); opacity: 0.8; }
.ab-page-kind-text::before { content: attr(data-label); color: var(--ab-ink); font-weight: 600; }
.ab-page-kind-text[data-sub]:not([data-sub=""])::after { content: "  ·  " attr(data-sub); white-space: pre; }
.ab-page.is-writing .ab-page-kind-text::after {
  animation: abp-breathe 1.6s ease-in-out infinite;
}

.ab-page-ico { display: inline-flex; width: 16px; height: 16px; flex: none; }
.ab-page-ico svg { width: 100%; height: 100%; display: block; }

.ab-page-acts { display: flex; align-items: center; gap: 2px; flex: none; }
.ab-page-act {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ab-muted);
  font: 500 12.5px/1 var(--abp-sans);
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}
.ab-page-act::after { content: attr(data-label); }
.ab-page-act:hover { color: var(--ab-ink); background: var(--ab-card); border-color: var(--ab-hair); }
.ab-page-act[data-act="open"] { color: var(--ab-ink); }
.ab-page-act.is-done { color: var(--ab-good); }
.ab-page-act:focus-visible,
.ab-page-chip:focus-visible,
.ab-page-more-btn:focus-visible,
.ab-reader-close:focus-visible,
.ab-toc-chip:focus-visible,
.ab-page-table:focus-visible {
  outline: 2px solid var(--ab-calc);
  outline-offset: 2px;
}
/* On a phone the icons carry the strip; the open action keeps its words. */
@media (max-width: 560px) {
  .ab-page-act:not([data-act="open"])::after { content: none; }
  .ab-page-act:not([data-act="open"]) { width: 34px; padding: 0; justify-content: center; }
}
@media (max-width: 380px) {
  .ab-page-act[data-act="open"]::after { content: "Open"; }
  .ab-page-kind-text::after { content: none !important; }
}

/* ── The document ─────────────────────────────────────────────────────── */
.ab-page-doc {
  display: block;
  padding: 30px 34px 34px;
  color: var(--ab-ink);
  font-family: var(--abp-serif);
  min-width: 0;
}
@media (max-width: 600px) {
  .ab-page-doc { padding: 22px 18px 26px; }
}

.ab-page-head { display: flex; flex-direction: column; gap: 0; }
body:not(#_) .ab-page-doc .ab-page-eyebrow {
  margin: 0 0 10px;
  font: 500 11.5px/1.45 var(--ab-font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ab-muted);
}
body:not(#_) .ab-page-doc .ab-page-title {
  margin: 0;
  font-family: var(--abp-serif);
  font-size: clamp(26px, 3.4vw, 34px);
  font-weight: 600;
  line-height: 1.14;
  letter-spacing: -0.012em;
  color: var(--ab-ink);
  text-wrap: balance;
  outline: none;
}
body:not(#_) .ab-page-doc .ab-page-lede {
  margin: 14px 0 0;
  max-width: 62ch;
  font-family: var(--abp-serif);
  font-size: 18px;
  line-height: 1.55;
  color: var(--ab-ink);
  text-wrap: pretty;
}
.ab-page-doc .ab-page-title .katex,
.ab-page-doc .ab-page-lede .katex,
.ab-page-doc .ab-page-h .katex { font-size: 1em; }
.ab-page-intro { margin-top: 20px; }
/* The page's key equation, set like a title card under the lede. */
body:not(#_) .ab-page-doc .ab-page-intro > .math-block {
  margin: 4px 0 0;
  padding: 22px 18px;
  border: 1px solid var(--ab-hair);
  border-radius: var(--ab-radius);
  background: var(--ab-paper);
  font-size: 1.28em;
  text-align: center;
}
body:not(#_) .ab-page-doc .ab-page-intro > .math-block + .math-block { margin-top: 10px; }

body:not(#_) .ab-page-doc .ab-page-key {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  font: 400 13.5px/1.4 var(--abp-sans);
  color: var(--ab-muted);
}
body:not(#_) .ab-page-doc .ab-page-key-item { display: inline-flex; align-items: center; gap: 7px; margin: 0; }
.ab-page-key-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--ab-ignore); }
.ab-page-key-item[data-role="measure"] .ab-page-key-dot { background: var(--ab-measure); }
.ab-page-key-item[data-role="calc"] .ab-page-key-dot { background: var(--ab-calc); }
.ab-page-key-item[data-role="given"] .ab-page-key-dot { background: var(--ab-given); }

/* Step chips: a table of contents you can tap. */
.ab-page-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 22px;
}
.ab-page-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  min-height: 30px;
  padding: 6px 12px 6px 10px;
  border: 1px solid var(--ab-rule);
  border-radius: 999px;
  background: var(--ab-card);
  color: var(--ab-ink);
  font: 500 12.5px/1.2 var(--ab-font-mono);
  text-decoration: none;
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease, background-color 140ms ease;
}
.ab-page-chip::before { content: attr(data-n); color: var(--ab-muted); font-weight: 500; }
.ab-page-chip::after { content: attr(data-label); }
.ab-page-chip:hover,
.ab-page-chip[aria-current="true"] { border-color: var(--ab-calc); color: var(--ab-calc); }
.ab-page-chip[aria-current="true"] { background: var(--ab-calc-soft); }
.ab-page-chip.is-writing::after { animation: abp-breathe 1.6s ease-in-out infinite; }

/* Sections */
.ab-page-sec {
  margin-top: 44px;
  scroll-margin-top: 84px;
  min-width: 0;
}
.ab-page-head + .ab-page-sec,
.ab-page-chips + .ab-page-sec,
.ab-page-more + .ab-page-sec { margin-top: 40px; }
body:not(#_) .ab-page-doc .ab-page-h {
  margin: 0 0 14px;
  font-family: var(--abp-serif);
  font-size: clamp(21px, 2.6vw, 25px);
  font-weight: 600;
  line-height: 1.22;
  letter-spacing: -0.008em;
  color: var(--ab-ink);
  text-wrap: balance;
  outline: none;
}
.ab-page-step {
  display: block;
  margin-bottom: 7px;
  font: 500 11.5px/1.3 var(--ab-font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ab-calc);
}
.ab-page-h-text { display: block; }
.ab-page-sec.is-writing .ab-page-body::after {
  content: "";
  display: block;
  width: 36%;
  height: 8px;
  margin-top: 10px;
  border-radius: 999px;
  background-image: linear-gradient(90deg, var(--ab-hair), var(--ab-rule), var(--ab-hair));
  background-size: 200% 100%;
  animation: ab-sheen 1.4s ease-in-out infinite;
}

/* Section bodies: the reply's reading voice. */
.ab-page-body { min-width: 0; }
/* Only the body's own prose: a nested widget or answer block keeps its own
   type, colour and spacing (every rule here is a direct-child rule). */
body:not(#_) .ab-page-doc .ab-page-body > :is(p, ul, ol, h4, h5, h6, blockquote:not([class])) {
  font-family: var(--abp-serif);
  color: var(--ab-ink);
  letter-spacing: 0;
}
body:not(#_) .ab-page-doc .ab-page-body > :is(p, ul, ol) {
  font-size: 16.5px;
  line-height: 1.68;
  margin: 0 0 0.9em;
  max-width: 70ch;
}
body:not(#_) .ab-page-doc .ab-page-body > :is(ul, ol) { padding-left: 1.4em; }
body:not(#_) .ab-page-doc .ab-page-body > :is(ul, ol) li { margin: 0 0 0.35em; }
body:not(#_) .ab-page-doc .ab-page-body > :is(ul, ol) li::marker { color: var(--ab-muted); }
body:not(#_) .ab-page-doc .ab-page-body > ol > li::marker { font-family: var(--ab-font-mono); font-size: 0.86em; }
body:not(#_) .ab-page-doc .ab-page-body > :last-child { margin-bottom: 0; }
body:not(#_) .ab-page-doc .ab-page-body > :is(h4, h5, h6) {
  margin: 1.5em 0 0.5em;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
}
body:not(#_) .ab-page-doc .ab-page-body > :is(h5, h6) { font-size: 16.5px; }
body:not(#_) .ab-page-doc .ab-page-body > :is(h4, h5, h6):first-child { margin-top: 0; }
body:not(#_) .ab-page-doc .ab-page-body > :is(p, ul, ol, blockquote:not([class])) strong { font-weight: 600; color: var(--ab-ink); }
body:not(#_) .ab-page-doc .ab-page-body > hr {
  border: 0;
  border-top: 1px solid var(--ab-hair);
  margin: 1.8em 0;
}
body:not(#_) .ab-page-doc .ab-page-body > blockquote:not([class]) {
  margin: 1.1em 0;
  padding: 12px 16px 12px 18px;
  border: 0;
  border-radius: var(--ab-radius-sm);
  background: var(--ab-calc-soft);
  box-shadow: inset 3px 0 0 var(--ab-calc);
  color: var(--ab-ink);
  font-size: 16px;
  line-height: 1.6;
}
body:not(#_) .ab-page-doc .ab-page-body > blockquote:not([class]) > :last-child { margin-bottom: 0; }
body:not(#_) .ab-page-doc .ab-page-body > blockquote:not([class]) > p { margin: 0 0 0.6em; }
body:not(#_) .ab-page-doc .ab-page-body > .math-block { margin: 1em 0; overflow-x: auto; overflow-y: hidden; }
body:not(#_) .ab-page-doc .ab-page-body > img { max-width: 100%; height: auto; border-radius: var(--ab-radius-sm); }
.ab-page-plain { white-space: pre-wrap; font: 14px/1.6 var(--ab-font-mono); }

/* A markdown table: quiet rules, mono headers, scrolls inside on a phone. */
.ab-page-table {
  margin: 1.1em 0;
  overflow-x: auto;
  border: 1px solid var(--ab-hair);
  border-radius: var(--ab-radius-sm);
  background: var(--ab-card);
  -webkit-overflow-scrolling: touch;
}
body:not(#_) .ab-page-doc .ab-page-table > table {
  display: table;
  width: 100%;
  min-width: 420px;
  margin: 0;
  border: 0;
  border-radius: 0;
  border-collapse: collapse;
  overflow: visible;
  font: 400 14.5px/1.5 var(--abp-sans);
  color: var(--ab-ink);
}
/* Its own rule: a font-* longhand after a font shorthand that holds var()
   serializes as empty values in Chrome's CSSOM, which Download HTML reads. */
body:not(#_) .ab-page-doc .ab-page-table td { font-variant-numeric: tabular-nums; }
body:not(#_) .ab-page-doc .ab-page-table thead { position: static; }
body:not(#_) .ab-page-doc .ab-page-table :is(th, td) {
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
  border: 0;
  border-bottom: 1px solid var(--ab-hair);
  background: none;
}
body:not(#_) .ab-page-doc .ab-page-table th {
  font: 500 11.5px/1.35 var(--ab-font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ab-muted);
  background: var(--ab-paper);
  border-bottom: 1px solid var(--ab-rule);
}
body:not(#_) .ab-page-doc .ab-page-table tbody tr,
body:not(#_) .ab-page-doc .ab-page-table tbody tr:hover { background: none; }
body:not(#_) .ab-page-doc .ab-page-table tbody tr:last-child td { border-bottom: 0; }
body:not(#_) .ab-page-doc .ab-page-table td:first-child { font-weight: 600; }
body:not(#_) .ab-page-doc .ab-page-table :is(th, td)[align="right"],
body:not(#_) .ab-page-doc .ab-page-table :is(th, td)[style*="right"] { text-align: right; }
body:not(#_) .ab-page-doc .ab-page-table :is(th, td)[align="center"],
body:not(#_) .ab-page-doc .ab-page-table :is(th, td)[style*="center"] { text-align: center; }

.ab-page-foot {
  margin-top: 40px;
  padding-top: 14px;
  border-top: 1px solid var(--ab-hair);
  font: 400 13.5px/1.55 var(--abp-sans);
  color: var(--ab-muted);
}
.ab-page-overflow { margin-top: 28px; font: 400 13.5px/1.5 var(--abp-sans); color: var(--ab-muted); }
.ab-page-overflow summary { cursor: pointer; border-radius: var(--ab-radius-sm); }
.ab-page-overflow pre {
  margin: 10px 0 0;
  padding: 12px;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  font: 12.5px/1.5 var(--ab-font-mono);
  background: var(--ab-paper);
  border-radius: var(--ab-radius-sm);
}

/* A long page from history: two steps, then this. */
.ab-page-more {
  display: flex;
  justify-content: center;
  margin-top: 30px;
  padding-top: 26px;
  border-top: 1px dashed var(--ab-rule);
}
.ab-page-more-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px 0 18px;
  border: 1px solid var(--ab-rule);
  border-radius: 999px;
  background: var(--ab-card);
  color: var(--ab-ink);
  font: 500 13.5px/1 var(--abp-sans);
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease;
}
.ab-page-more-btn::before { content: attr(data-label); }
.ab-page-more-btn::after { content: attr(data-sub); color: var(--ab-muted); font-weight: 400; }
.ab-page-more-btn .ab-page-ico { order: 3; width: 15px; height: 15px; color: var(--ab-muted); }
.ab-page-more-btn:hover { border-color: var(--ab-calc); color: var(--ab-calc); }

/* Where the page sat while it is open in the reader. */
.ab-page-away {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  color: var(--ab-muted);
  font: 500 13px/1.4 var(--abp-sans);
}
.ab-page-away::before { content: attr(data-label); }

/* ── The reader ───────────────────────────────────────────────────────── */
html.ab-reader-open,
html.ab-reader-open body { overflow: hidden !important; }

.ab-reader {
  position: fixed;
  inset: 0;
  z-index: 9400;
  display: flex;
  flex-direction: column;
  background: var(--bg, var(--ab-paper));
  color: var(--ab-ink);
  animation: abp-in 180ms ease-out both;
}
.ab-reader-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--ab-hair);
  background: var(--ab-card);
}
.ab-reader-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex: none;
  border: 1px solid var(--ab-hair);
  border-radius: 50%;
  background: var(--ab-card);
  color: var(--ab-ink);
  cursor: pointer;
}
.ab-reader-close:hover { background: var(--ab-paper); }
.ab-reader-close .ab-page-ico { width: 18px; height: 18px; }
.ab-reader-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font: 600 14px/1.3 var(--abp-sans);
  color: var(--ab-ink);
}
.ab-reader-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.ab-reader-col {
  max-width: 800px;
  margin: 0 auto;
  padding: 28px 20px calc(96px + env(safe-area-inset-bottom, 0px));
}
.ab-reader .ab-page-doc {
  padding: 36px 44px 48px;
  border: 1px solid var(--ab-hair);
  border-radius: calc(var(--ab-radius) + 4px);
  background: var(--ab-card);
}
.ab-reader .ab-page-chips {
  position: sticky;
  top: -1px;
  z-index: 2;
  margin: 22px -44px 0;
  padding: 10px 44px;
  border-radius: 0;
  background: var(--ab-card);
  box-shadow: 0 1px 0 var(--ab-hair);
}
.ab-reader .ab-page-sec { scroll-margin-top: 72px; }
@media (max-width: 600px) {
  .ab-reader-col { padding: 0 0 calc(72px + env(safe-area-inset-bottom, 0px)); }
  .ab-reader .ab-page-doc { padding: 24px 18px 32px; border: 0; border-radius: 0; }
  .ab-reader .ab-page-chips { margin: 20px -18px 0; padding: 8px 18px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .ab-reader .ab-page-chips::-webkit-scrollbar { display: none; }
  .ab-reader .ab-page-chip { flex: none; }
}

/* ── The "Jump to" row on an ordinary long reply ─────────────────────── */
.ab-toc {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 18px;
}
.ab-toc::before {
  content: attr(data-label);
  margin-right: 4px;
  font: 500 11.5px/1 var(--ab-font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ab-muted);
}
.ab-toc-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 11px;
  border: 1px solid var(--ab-hair);
  border-radius: 999px;
  background: transparent;
  color: var(--ab-ink);
  font: 500 12.5px/1.2 var(--ab-font-ui);
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease;
}
.ab-toc-chip::after { content: attr(data-label); }
.ab-toc-chip.is-sub { color: var(--ab-muted); }
.ab-toc-chip:hover { border-color: var(--ab-calc); color: var(--ab-calc); }
.msg-content > :is(h2, h3)[id^="ab-toc"] { scroll-margin-top: 84px; }
/* On a phone the row is one line that scrolls sideways, not a wall of pills. */
@media (max-width: 560px) {
  .ab-toc {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 2px;
    margin-left: -2px;
    margin-right: -2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .ab-toc::-webkit-scrollbar { display: none; }
  .ab-toc::before, .ab-toc-chip { flex: none; }
}

/* ── Motion ───────────────────────────────────────────────────────────── */
@keyframes abp-breathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes abp-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .ab-reader { animation: none; }
  .ab-page.is-writing .ab-page-kind-text::after,
  .ab-page-chip.is-writing::after,
  .ab-page-sec.is-writing .ab-page-body::after { animation: none; }
  .ab-page-act, .ab-page-chip, .ab-page-more-btn, .ab-toc-chip { transition: none; }
}

/* ── Print: only the page, in light colours ───────────────────────────── */
.ab-page-print { display: none; }
@media print {
  html.ab-page-printing,
  html.ab-page-printing body {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    position: static !important;
    background: none !important;
  }
  html.ab-page-printing body > :not(.ab-page-print) { display: none !important; }
  html.ab-page-printing .ab-page-print {
    display: block !important;
    color: var(--ab-ink);
    background: var(--ab-card);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .ab-page-print .ab-page-doc { padding: 0; }
  .ab-page-print .ab-page-chip { border-color: var(--ab-rule); }
  .ab-page-print .ab-page-sec { margin-top: 28px; }
  .ab-page-print :is(.ab-page-h, h4, h5, h6) { break-after: avoid; }
  .ab-page-print :is(tr, img, svg, figure, pre, .math-block, .katex-display, .ab-block) { break-inside: avoid; }
  .ab-page-print .ab-page-table { overflow: visible; }
  .ab-page-print .ab-page-table > table { min-width: 0; }
  @page { margin: 16mm 14mm; }
}
