/* blog.pdj.dev - research-document components (brutalist).
   Loaded after blog.css on post pages. Single-column paper layout.
   Auto-numbering via CSS counters; math via native MathML (zero JS). */

.article {
  max-width: var(--read);
  margin: 0 auto;
  counter-reset: section figure equation table;
}

/* ----- Header ----- */
.article-header {
  padding: var(--s6) 0 var(--s5);
  border-bottom: 1px solid var(--hairline);
  margin-bottom: var(--s5);
}

.article-eyebrow {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: var(--s3);
}

.article-eyebrow .topic { color: var(--accent-soft); }

.article-eyebrow .dot {
  width: 3px; height: 3px;
  background: var(--raise-line);
}

.article-title {
  font-family: var(--font-sans);
  font-size: clamp(2rem, 5.2vw, 3rem);
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1.04;
  color: var(--text);
  text-wrap: balance;
}

.article-byline {
  margin-top: var(--s3);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.article-byline strong {
  color: var(--body);
  font-weight: 500;
}

/* ----- Abstract ----- */
.abstract {
  margin: var(--s5) 0;
  padding: var(--s1) 0 var(--s1) var(--s4);
  border-left: 2px solid var(--accent);
}

.abstract-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent-soft);
  margin-bottom: var(--s2);
}

.abstract p {
  font-size: 1.14rem;
  line-height: 1.62;
  color: var(--text);
}

.abstract p + p { margin-top: var(--s2); }

/* ----- Body typography (sans, reading-grade) ----- */
.prose {
  font-size: 1.12rem;
  line-height: 1.72;
  color: var(--body);
}

.prose > p { margin: var(--s3) 0; }
.prose > p:first-of-type { margin-top: 0; }

.prose a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--accent);
  transition: color 0.15s linear, border-color 0.15s linear;
}

.prose a:hover { color: var(--accent-soft); border-color: var(--accent-soft); }

.prose strong { color: var(--text); font-weight: 600; }
.prose em { color: var(--text); }

.prose .lead {
  font-size: 1.28rem;
  line-height: 1.55;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* ----- Section headings (auto-numbered) ----- */
.section-title {
  counter-increment: section;
  counter-reset: subsection;
  font-family: var(--font-sans);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.2;
  color: var(--text);
  margin: var(--s6) 0 var(--s3);
  scroll-margin-top: 5rem;
}

.section-title::before {
  content: counter(section) "\00a0\00a0";
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.86em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.subsection-title {
  counter-increment: subsection;
  font-family: var(--font-sans);
  font-size: 1.18rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: var(--s4) 0 var(--s2);
  scroll-margin-top: 5rem;
}

.subsection-title::before {
  content: counter(section) "." counter(subsection) "\00a0\00a0";
  font-family: var(--font-mono);
  font-size: 0.86em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ----- Lists ----- */
.prose ul, .prose ol { margin: var(--s3) 0; padding-left: 1.6rem; }
.prose li { margin: 0.5rem 0; }
.prose ul li::marker { color: var(--accent); }
.prose ol li::marker { color: var(--muted); }

.prose blockquote {
  margin: var(--s4) 0;
  padding: var(--s1) 0 var(--s1) var(--s3);
  border-left: 2px solid var(--hairline);
  color: var(--muted);
  font-style: italic;
}

/* ----- Formal blocks: definitions, propositions, theorems, proofs ----- */
.claim {
  margin: var(--s4) 0;
  padding: var(--s3);
  background: var(--raise);
  border: 1px solid var(--raise-line);
  border-left: 2px solid var(--accent);
}

.claim-label {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.01em;
  color: var(--accent-soft);
}

.claim-body {
  font-style: italic;
  color: var(--text);
  line-height: 1.62;
}

.claim-body math { font-style: normal; }

.proof {
  margin: var(--s2) 0 var(--s4);
  font-size: 1.05rem;
  line-height: 1.68;
  color: var(--body);
}

.proof::before {
  content: "Proof.\00a0";
  font-style: italic;
  color: var(--muted);
}

.proof.sketch::before { content: "Proof sketch.\00a0"; }

.proof .qed { float: right; color: var(--muted); }

/* ----- Figures (auto-numbered) ----- */
.figure { margin: var(--s5) 0; }

.figure img { display: block; width: 100%; height: auto; }

.figure-frame {
  background: var(--raise);
  border: 1px solid var(--raise-line);
  padding: var(--s4) var(--s3);
  overflow-x: auto;
}

.figure svg { display: block; width: 100%; height: auto; }
/* Brutalist: square the corners of hand-authored inline-SVG diagram nodes */
.figure svg rect { rx: 0; ry: 0; }

.figure figcaption {
  counter-increment: figure;
  margin-top: var(--s2);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--muted);
  text-align: left;
}

.figure figcaption::before {
  content: "Figure\00a0" counter(figure) "\00a0\00a0";
  color: var(--text);
  font-weight: 600;
}

/* Inline SVG diagram primitives (hand-authored figures) */
.dg-node-fill { fill: var(--raise); }
.dg-node-stroke { stroke: var(--raise-line); }
.dg-accent-fill { fill: rgba(0, 122, 255, 0.14); }
.dg-accent-stroke { stroke: var(--accent); }
.dg-edge { stroke: #3a3a3d; }
.dg-edge-accent { stroke: var(--accent); }
.dg-label { fill: var(--text); font-family: var(--font-sans); }
.dg-sub { fill: var(--muted); font-family: var(--font-mono); }
.dg-mono { fill: var(--body); font-family: var(--font-mono); }

/* ----- Tables (auto-numbered via caption) ----- */
.table-wrap { margin: var(--s5) 0; overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.data-table caption {
  counter-increment: table;
  caption-side: bottom;
  margin-top: var(--s2);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  text-align: left;
}

.data-table caption::before {
  content: "Table\00a0" counter(table) "\00a0\00a0";
  color: var(--text);
  font-weight: 600;
}

.data-table th, .data-table td {
  padding: 0.65rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--hairline);
}

.data-table thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--raise-line);
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table td.num, .data-table th.num { text-align: right; }
.data-table .accent { color: var(--accent-soft); }

/* ----- Math (native MathML, zero JS) ----- */
math { font-size: 1.05em; }

.equation {
  counter-increment: equation;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--s2);
  margin: var(--s4) 0;
  padding: var(--s1) 0;
  overflow-x: auto;
}

/* Do NOT override the math element's `display` - that strips the MathML
   formatting context and makes children stack. Center via grid instead. */
.equation > math { justify-self: center; max-width: 100%; }

.equation::after {
  content: "(" counter(equation) ")";
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

/* ----- Code (pre-rendered, hand-tokenized) ----- */
.code {
  margin: var(--s4) 0;
  background: var(--raise);
  border: 1px solid var(--raise-line);
  padding: var(--s3);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: 1.7;
  color: var(--body);
  -webkit-font-smoothing: auto;
}

.code code { font-family: inherit; }

.code .tok-com { color: #6e6e73; font-style: italic; }
.code .tok-kw  { color: #ff7ab2; }
.code .tok-str { color: #9ecbff; }
.code .tok-fn  { color: #82d9ff; }
.code .tok-num { color: #d2a8ff; }
.code .tok-cls { color: #f0c674; }
.code .tok-op  { color: var(--muted); }

.code-caption {
  margin-top: calc(-1 * var(--s2));
  margin-bottom: var(--s4);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
}

.code-caption::before {
  content: "Listing\00a0";
  color: var(--text);
  font-weight: 600;
}

/* ----- Citations & footnotes ----- */
.cite, .fn-ref {
  font-family: var(--font-mono);
  font-size: 0.72em;
  vertical-align: super;
  line-height: 0;
  text-decoration: none;
  color: var(--accent-soft);
  font-variant-numeric: tabular-nums;
  padding: 0 0.05em;
}

.cite:hover, .fn-ref a:hover { color: var(--text); }
.fn-ref a { color: var(--accent-soft); text-decoration: none; }

:target { scroll-margin-top: 5rem; }
.references li:target,
.footnotes li:target { background: rgba(0, 122, 255, 0.08); }

/* ----- Apparatus: references & footnotes ----- */
.apparatus {
  margin-top: var(--s6);
  padding-top: var(--s4);
  border-top: 1px solid var(--hairline);
}

.apparatus-title {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: var(--s3);
}

.references, .footnotes {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--muted);
  padding-left: 2.4rem;
}

.references li, .footnotes li {
  margin: 0.7rem 0;
  scroll-margin-top: 5rem;
}

.references li::marker { color: var(--faint); font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.footnotes li::marker { color: var(--faint); font-family: var(--font-mono); }

.references cite { color: var(--body); font-style: normal; }
.references em { color: var(--body); font-style: italic; }
.references a, .footnotes a {
  color: var(--accent-soft);
  text-decoration: none;
  word-break: break-word;
}
.references a:hover, .footnotes a:hover { color: var(--text); }

.fn-back { margin-left: 0.4rem; }

/* ----- Article footer nav ----- */
.article-footer {
  margin-top: var(--s6);
  padding-top: var(--s4);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
}

.back-link {
  text-decoration: none;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  transition: color 0.15s linear;
}

.back-link::before { content: "\2190\00a0"; color: var(--faint); }
.back-link:hover { color: var(--text); }

.article-footer .byline-end {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--faint);
}

/* ----- Mobile ----- */
@media (max-width: 768px) {
  .article-header { padding: var(--s5) 0 var(--s4); margin-bottom: var(--s4); }
  .prose, .abstract p { font-size: 1.04rem; }
  .abstract { padding-left: var(--s3); }
  .figure-frame { padding: var(--s3) var(--s2); }
  .equation { font-size: 0.95rem; }
}
