/* ---------- Article header ---------- */

.article-header { padding: var(--sp-7) 0 var(--sp-6); }

.article-header__breadcrumb {
  display: flex; align-items: center; gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}
.article-header__breadcrumb a { text-decoration: none !important; color: var(--muted); }
.article-header__breadcrumb a:hover { color: var(--accent-ink); }

.article-header__title {
  font-size: clamp(30px, 5.2vw, 54px);
  max-width: 900px;
  margin: 0 0 var(--sp-4);
}

.article-header__desc {
  font-size: 18px;
  color: var(--muted);
  max-width: var(--reading-width);
  margin-bottom: var(--sp-6);
}

.article-header__byline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-4);
  padding: var(--sp-5) 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.article-header__author { display: flex; align-items: center; gap: var(--sp-3); text-decoration: none !important; color: inherit; }
.article-header__author-name { font-weight: 600; font-size: 14.5px; }
.article-header__author-role { font-size: 12.5px; color: var(--muted); }

.article-header__stats {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  flex-wrap: wrap;
}
.article-header__stats .dot::before { content: "\00b7"; margin: 0 2px; }

.article-header__tags { margin-top: var(--sp-5); }

/* ---------- Layout: body + TOC rail ---------- */

.article-layout {
  display: grid;
  grid-template-columns: minmax(0, var(--reading-width)) 240px;
  gap: var(--sp-8);
  justify-content: center;
  align-items: start;
}

.article-toc {
  position: sticky;
  top: 90px;
  border-left: 1px solid var(--border);
  padding-left: var(--sp-4);
}
.article-toc__label {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin-bottom: var(--sp-3);
}
.article-toc ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.article-toc li[data-level="3"] { padding-left: var(--sp-3); }
.article-toc a {
  text-decoration: none !important;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  transition: color var(--transition-fast);
  display: block;
}
.article-toc a:hover, .article-toc a.is-active { color: var(--accent-ink); }

.article-toc-mobile { display: none; margin-bottom: var(--sp-6); }
.article-toc-mobile summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  padding: var(--sp-3) var(--sp-4);
}
.article-toc-mobile[open] summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.article-toc-mobile ol {
  list-style: none; margin: 0; padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border); border-top: none;
  display: flex; flex-direction: column; gap: var(--sp-2);
}
.article-toc-mobile a { text-decoration: none; color: var(--fg); font-size: 14px; }
.article-toc-mobile li[data-level="3"] { padding-left: var(--sp-4); color: var(--muted); }

/* ---------- Prose ---------- */

.article-body {
  font-size: 17.5px;
  line-height: 1.75;
  min-width: 0; /* belt-and-braces: a grid/flex item's default min-width is its content's
    intrinsic size, so without this a wide code line or table can stretch the column itself
    instead of scrolling inside it (see the mobile grid-template-columns fix in responsive.css) */
}
/* scroll-margin-top on every in-body heading: the header is sticky (layout.css, 64px), so jumping
   straight to a TOC target's #id would otherwise land it flush against the top of the viewport,
   tucked right under (or behind) the header - this reserves the header's height plus breathing
   room. h1 needs its own rule (not just inherited spacing) since an in-body H1 used to never
   appear in the TOC at all - see MarkdownRenderer's TocItem level filter - so this was never
   exercised until H1 became a valid jump target (reported bug: clicking an H1 TOC entry landed
   the right place, but the heading text itself was hidden under the header). */
.article-body h1 { font-size: 31px; margin-top: var(--sp-8); scroll-margin-top: 90px; }
.article-body h2 { font-size: 27px; margin-top: var(--sp-8); scroll-margin-top: 90px; }
.article-body h3 { font-size: 21px; margin-top: var(--sp-7); scroll-margin-top: 90px; }
.article-body h4 { font-size: 17px; margin-top: var(--sp-6); }
.article-body > *:first-child { margin-top: 0; }

.article-body p { margin-bottom: var(--sp-5); }
.article-body ul.md-list, .article-body ol.md-list { margin-bottom: var(--sp-5); }
.article-body li { margin-bottom: var(--sp-2); }

.article-body code {
  font-family: var(--font-mono);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-1);
  padding: 0.15em 0.4em;
  font-size: 0.86em;
}

.article-body img {
  border: 1px solid var(--border);
  margin: var(--sp-6) 0;
}
.article-body figcaption, .article-body em.caption {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  margin-top: -var(--sp-4);
}

.md-quote {
  margin: var(--sp-6) 0;
  padding-left: var(--sp-5);
  border-left: 2px solid var(--accent);
  color: var(--muted);
  font-style: italic;
  font-size: 1.05em;
}

.md-hr { margin: var(--sp-8) 0; border-top: 1px solid var(--border); }
.md-hr::after { content: "///"; display: block; text-align: center; margin-top: -11px; color: var(--muted); background: var(--bg); width: fit-content; margin-inline: auto; padding: 0 var(--sp-3); font-family: var(--font-mono); font-size: 12px; }

.md-table-wrap { overflow-x: auto; margin: var(--sp-6) 0; border: 1px solid var(--border); }
.md-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.md-table th, .md-table td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); text-align: left; }
.md-table th { font-family: var(--font-mono); font-size: 11.5px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); background: var(--surface); }
.md-table tr:last-child td { border-bottom: none; }

/* ---------- Callouts ---------- */

.callout {
  margin: var(--sp-6) 0;
  padding: var(--sp-4) var(--sp-5);
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: var(--r-2);
  font-size: 15px;
}
.callout__label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  font-weight: 700;
  margin-bottom: 6px;
}
.callout__body { color: var(--fg); }
.callout--info { border-left-color: var(--accent-ink); background: var(--accent-soft); }
.callout--info .callout__label { color: var(--accent-ink); }
.callout--warning { border-left-color: var(--warning); background: var(--warning-soft); }
.callout--warning .callout__label { color: var(--warning); }
.callout--tip { border-left-color: var(--success); background: var(--success-soft); }
.callout--tip .callout__label { color: var(--success); }

/* ---------- Code blocks ---------- */

.code-block {
  margin: var(--sp-6) 0;
  border-radius: var(--r-2);
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: var(--code-bg);
}
.code-block__bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px var(--sp-4);
  background: var(--code-bar-overlay);
  border-bottom: 1px solid var(--code-bar-border);
}
.code-block__lang {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
.code-block__copy {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase;
  background: transparent; border: 1px solid var(--border-strong); color: var(--muted);
  padding: 4px 10px; border-radius: var(--r-1);
  transition: border-color var(--transition-fast), color var(--transition-fast);
}
.code-block__copy:hover { border-color: var(--accent-ink); color: var(--accent-ink); }
.code-block__copy.is-copied { border-color: var(--accent-ink); color: var(--accent-ink); }

/* font-size and line-height live on the <pre> (the block container), not only on <code>: an inline
   <code> can't shrink the line boxes its parent block creates, so the lines were stepping at the
   inherited .article-body rhythm (~26.8px) while the Prism line-number rows, which are children
   of <code>, stepped at 21.6px - the numbers drifted further from their lines on every row. */
.code-block pre {
  margin: 0; padding: var(--sp-4); overflow-x: auto; background: transparent !important;
  font-size: 13.5px; line-height: 1.6;
}
.code-block code {
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  background: transparent !important;
  color: var(--code-fg);
  /* Undo the inline `.article-body code` treatment (border/padding/radius) - it's meant for
     single-line `` `code` `` spans, and a border on a multi-line inline element draws a
     separate fragment per wrapped line, i.e. a stray line under every row (reported bug). */
  border: none;
  padding: 0;
  border-radius: 0;
}

.code-block pre.line-numbers { padding-left: 4em; position: relative; }   /* em now follows the 13.5px above */

/* ---------- Video embeds ---------- */

.video-embed {
  position: relative;
  aspect-ratio: 16 / 9;
  margin: var(--sp-6) 0;
  border: 1px solid var(--border);
  background: #000;
}
.video-embed iframe { width: 100%; height: 100%; border: 0; }

/* ---------- Prism token colours (no stock Prism theme loaded - kept on-brand) ----------
   All theme-aware via variables.css (--code-*), so code blocks follow the site's light/dark
   mode like everything else instead of being permanently dark (reported bug: base text was
   inheriting --fg while the background stayed dark, so light mode was unreadable). */
.code-block .token.comment,
.code-block .token.prolog,
.code-block .token.doctype,
.code-block .token.cdata { color: var(--code-comment); font-style: italic; }
.code-block .token.string,
.code-block .token.attr-value,
.code-block .token.char { color: var(--code-string); }
.code-block .token.number,
.code-block .token.boolean,
.code-block .token.constant { color: var(--code-number); }
.code-block .token.keyword,
.code-block .token.selector,
.code-block .token.atrule { color: var(--code-keyword); }
.code-block .token.function,
.code-block .token.class-name { color: var(--code-function); }
.code-block .token.operator,
.code-block .token.punctuation { color: var(--code-operator); }
.code-block .token.tag,
.code-block .token.property { color: var(--code-tag); }
.code-block .token.attr-name { color: var(--code-string); }
.code-block .token.deleted { color: var(--code-deleted); }
.code-block .token.inserted { color: var(--code-inserted); }
.code-block .line-numbers-rows { border-right-color: var(--code-bar-border); }
.code-block .line-numbers-rows > span:before { color: var(--muted); }

/* ---------- Mermaid ---------- */
.article-body pre.mermaid { background: var(--bg-raised); border: 1px solid var(--border); padding: var(--sp-5); margin: var(--sp-6) 0; text-align: center; }

/* ---------- Footer of article: author + related ---------- */

.article-footer { max-width: var(--reading-width); margin: var(--sp-8) auto 0; }
.article-share { display: flex; justify-content: flex-end; margin-bottom: var(--sp-6); }

.article-author-card {
  display: flex; gap: var(--sp-4); align-items: flex-start;
  padding: var(--sp-5);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  margin-bottom: var(--sp-8);
}
.article-author-card .avatar { width: 56px; height: 56px; flex-shrink: 0; }
.article-author-card__body { min-width: 0; }
.article-author-card__name {
  display: block;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  text-decoration: none !important;
  color: var(--fg);
}
.article-author-card__name:hover { color: var(--accent-ink); }

.related-articles { max-width: var(--content-width); margin: 0 auto; padding: 0 var(--sp-5) var(--sp-9); }
.related-articles__grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-6); }

/* ---------- Homepage editorial grid ---------- */

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: var(--sp-7);
  align-items: start;
}

.home-grid__featured .article-card__media { aspect-ratio: 16/11; }

.home-grid__list { display: flex; flex-direction: column; }
.home-secondary-item {
  display: flex; gap: var(--sp-4);
  padding: var(--sp-5) 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none !important;
  color: inherit;
}
.home-grid__list .home-secondary-item:first-child { padding-top: 0; }
.home-secondary-item__index {
  font-family: var(--font-mono); font-size: 12px; color: var(--muted); flex-shrink: 0; padding-top: 3px;
}
.home-secondary-item__title {
  font-family: var(--font-display); font-weight: 600; font-size: 16.5px; line-height: 1.3; margin: 0 0 6px;
  transition: color var(--transition-fast);
}
.home-secondary-item:hover .home-secondary-item__title { color: var(--accent-ink); }
.home-secondary-item__meta { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }
.home-secondary-item__eyebrow { font-family: var(--font-mono); font-size: 11px; color: var(--accent-ink); letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 4px; }

.article-index-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-6) var(--sp-6);
}

.topic-pill-grid { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
.topic-pill {
  text-decoration: none !important;
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  padding: var(--sp-4) var(--sp-5);
  display: flex; flex-direction: column; gap: 4px;
  color: inherit;
  transition: border-color var(--transition-fast);
  min-width: 160px;
}
.topic-pill:hover { border-color: var(--accent-ink); }
.topic-pill__name { font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.topic-pill__count { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }
