/* ==========================================================================
   articles.css: Articles archive, single article and print layout.
   Loaded only on article pages, after style.css and refresh.css.
   To undo the redesign: stop enqueuing this file (inc/articles-assets.php).
   ========================================================================== */

:root {
  --art-rule: var(--border-soft, #EAE2D3);
  --art-card: #FBF8F1;
  --art-wrap: 1100px;
  --art-read: 700px;
}

/* ---------- Shared bits ---------- */
.articles-page .eyebrow,
.article-head__eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 14px;
}

/* ==========================================================================
   ARCHIVE
   ========================================================================== */
.articles-page { max-width: var(--art-wrap); margin: 0 auto; padding: 56px 24px 88px; }

.articles-head { padding-bottom: 28px; border-bottom: 1px solid var(--art-rule); }
.articles-head h1 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  line-height: 1.1;
  letter-spacing: -0.025em;
  margin: 0 0 14px;
}
.articles-head__lead {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.12rem;
  line-height: 1.6;
  color: var(--muted);
  max-width: none;
  margin: 0 0 16px;
}
.articles-head__count {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}

/* Filter bar: same markup as before, restyled as quiet tabs */
.articles-filter { padding: 18px 0 6px; }
.articles-filter .article-filter-bar { margin: 0; padding-bottom: 8px; gap: 6px; }
.articles-filter .article-filter-pill {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 999px;
}
.articles-filter .article-filter-pill:hover { border-color: var(--ink); color: var(--ink); }
.articles-filter .article-filter-pill.is-active { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.articles-filter .article-filter-count,
.articles-filter .article-filter-pill:not(.is-active) .article-filter-count {
  background: transparent;
  color: inherit;
  opacity: 0.6;
  padding: 0;
  font-size: 0.7rem;
}
.articles-filter .subcategory-bar { margin-top: 10px; }

/* Grid */
.articles-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 40px 32px;
  margin-top: 32px;
}

/* Card */
.art-card { display: flex; flex-direction: column; min-width: 0; }
.art-card__media {
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 6px;
  background: var(--paper-2);
  border: 1px solid var(--art-rule);
}
.art-card__media img,
.art-card__media .thumb-placeholder {
  width: 100%; height: 100%;
  object-fit: contain; /* whole image always visible, nothing trimmed */
  display: block;
}
.art-card__body { padding-top: 16px; display: flex; flex-direction: column; flex: 1; }
.art-card__eyebrow {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.art-card__eyebrow a, .art-card__eyebrow span { color: var(--chinar); }
.art-card__eyebrow a:hover { color: var(--chinar-ink); }
.art-card__title {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1.28rem;
  line-height: 1.28;
  letter-spacing: -0.015em;
  margin: 0 0 10px;
}
.art-card__title a { color: var(--ink); background: linear-gradient(currentColor, currentColor) 0 100% / 0 1px no-repeat; transition: background-size 0.3s ease; }
.art-card__title a:hover { background-size: 100% 1px; color: var(--ink); }
.art-card__excerpt {
  font-family: var(--font-serif);
  font-size: 0.98rem;
  line-height: 1.6;
  color: var(--muted);
  margin: 0 0 14px;
}
.art-card__meta {
  margin-top: auto;
  display: flex; gap: 10px; flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.art-card__meta > * + *::before { content: "\00B7"; margin-right: 10px; }

/* Lead article on page 1 */
.art-card--featured {
  grid-column: 1 / -1;
  flex-direction: row;
  gap: 40px;
  align-items: center;
  padding-bottom: 40px;
  border-bottom: 1px solid var(--art-rule);
}
.art-card--featured .art-card__media { flex: 1.25; aspect-ratio: 16 / 9; }
.art-card--featured .art-card__body { flex: 1; padding-top: 0; }
.art-card--featured .art-card__title { font-size: clamp(1.7rem, 3vw, 2.35rem); line-height: 1.15; }
.art-card--featured .art-card__excerpt { font-size: 1.08rem; }
.art-card--featured .art-card__meta { margin-top: 4px; }

/* Pagination */
.articles-pagination { margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--art-rule); }
.articles-pagination .nav-links { display: flex; justify-content: center; align-items: center; gap: 6px; flex-wrap: wrap; }
.articles-pagination .page-numbers {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  min-width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--ink);
}
.articles-pagination a.page-numbers:hover { border-color: var(--ink); }
.articles-pagination .page-numbers.current { background: var(--ink); color: var(--bg); }
.articles-pagination .screen-reader-text { display: none; }
.articles-empty { padding: 48px 0; color: var(--muted); font-family: var(--font-serif); font-style: italic; }

@media (max-width: 960px) {
  .articles-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .art-card--featured { gap: 28px; }
}
@media (max-width: 680px) {
  .articles-page { padding: 36px 20px 64px; }
  .articles-grid { grid-template-columns: 1fr; gap: 36px; }
  .art-card--featured { flex-direction: column; align-items: stretch; gap: 0; }
  .art-card--featured .art-card__body { padding-top: 16px; }
}

/* ==========================================================================
   SINGLE ARTICLE
   ========================================================================== */
.reading-progress {
  position: fixed; top: 0; left: 0; right: 0;
  height: 3px;
  z-index: 1200;
  pointer-events: none;
}
.reading-progress span {
  display: block; height: 100%;
  width: 100%;
  background: var(--chinar);
  transform: scaleX(0);
  transform-origin: left;
}

.article-page { padding-bottom: 24px; }

/* Header */
.article-head { max-width: var(--art-wrap); margin: 0 auto; padding: 48px 24px 0; }
.article-head__eyebrow a { color: var(--muted); }
.article-head__eyebrow a:hover { color: var(--ink); }
.article-head__eyebrow a.is-cat { color: var(--chinar); }
.article-head__eyebrow .sep { margin: 0 8px; opacity: 0.5; }
.article-head__title {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(2rem, 4.6vw, 3.4rem);
  line-height: 1.12;
  letter-spacing: -0.025em;
  max-width: none;
  margin: 0 0 18px;
}
.article-head__dek {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(1.05rem, 1.6vw, 1.25rem);
  line-height: 1.6;
  color: var(--muted);
  max-width: none;
  margin: 0 0 28px;
}
.article-byline {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 0;
  border-top: 1px solid var(--art-rule);
  border-bottom: 1px solid var(--art-rule);
}
.article-byline__who { display: flex; align-items: center; gap: 12px; }
.article-byline__avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.article-byline__name { display: block; font-size: 0.88rem; font-weight: 600; line-height: 1.2; }
.article-byline__meta {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 3px;
}
.article-byline__meta .dot { margin: 0 4px; }

.print-link {
  display: inline-flex; align-items: center; gap: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 0.8rem; font-weight: 500;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.print-link:hover { border-color: var(--ink); background: var(--paper-2); }

/* Cover image */
.article-cover { margin: 0 0 2em; padding: 0; }
.article-cover img {
  width: 100%; height: auto;
  display: block;
  border-radius: 6px;
  border: 1px solid var(--art-rule);
}

/* Layout: contents list + reading column */
.article-layout {
  max-width: var(--art-wrap);
  margin: 0 auto;
  padding: 40px 24px 24px;
  display: grid;
  grid-template-columns: 210px minmax(0, var(--art-read));
  gap: 64px;
  justify-content: center;
  align-items: start;
}
.article-layout--no-toc { grid-template-columns: minmax(0, var(--art-read)); }

/* Contents list */
.article-toc { position: sticky; top: 96px; align-self: start; }
.article-toc summary {
  list-style: none;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 14px;
  pointer-events: none;
  cursor: default;
}
.article-toc summary::-webkit-details-marker { display: none; }
.article-toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.article-toc li { margin: 0; }
.article-toc a {
  display: block;
  padding: 7px 0 7px 16px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  font-size: 0.84rem;
  line-height: 1.4;
  color: var(--muted);
  transition: color 0.15s ease, border-color 0.15s ease;
}
.article-toc a:hover { color: var(--ink); }
.article-toc a.is-active { color: var(--ink); font-weight: 600; border-left-color: var(--chinar); }

/* Prose */
.article-prose {
  font-family: var(--font-serif);
  font-size: 1.14rem;
  line-height: 1.8;
  color: var(--ink);
  overflow-wrap: break-word;
}
.article-prose > *:first-child { margin-top: 0; }
.article-prose p { margin: 0 0 1.35em; }
.article-prose h2 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1.85rem;
  line-height: 1.25;
  letter-spacing: -0.02em;
  margin: 2.1em 0 0.7em;
  scroll-margin-top: 96px;
}
.article-prose h3 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1.35rem;
  line-height: 1.3;
  margin: 1.8em 0 0.6em;
  scroll-margin-top: 96px;
}
.article-prose a {
  color: var(--chinar);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.article-prose a:hover { color: var(--chinar-ink); }
.article-prose ul, .article-prose ol { margin: 0 0 1.35em; padding-left: 1.4em; }
.article-prose li { margin-bottom: 0.45em; }
.article-prose img { border-radius: 6px; margin: 1.8em auto; height: auto; }
.article-prose figure { margin: 1.8em 0; }
.article-prose figcaption {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  margin-top: 8px;
}
.article-prose hr { border: 0; border-top: 1px solid var(--art-rule); margin: 2.4em 0; }

/* Quote / callout */
.article-prose blockquote {
  margin: 1.8em 0;
  padding: 2px 0 2px 22px;
  border-left: 3px solid var(--chinar);
  font-style: italic;
  color: var(--muted);
}
.article-prose blockquote p:last-child { margin-bottom: 0; }

/* Tables */
.article-prose table { width: 100%; border-collapse: collapse; margin: 1.8em 0; font-size: 0.95rem; display: block; overflow-x: auto; }
.article-prose th, .article-prose td { padding: 10px 14px; border-bottom: 1px solid var(--art-rule); text-align: left; }
.article-prose th { font-family: var(--font-body); font-size: 0.8rem; font-weight: 600; background: var(--art-card); }

/* Inline code */
.article-prose :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--paper-2);
  padding: 0.12em 0.4em;
  border-radius: 4px;
}

/* Code blocks (header + Copy are added by articles.js) */
.code-block {
  margin: 1.8em 0;
  border-radius: 10px;
  background: #1B1714;
  color: #EDE6D8;
  overflow: hidden;
}
.code-block__bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.code-block__lang {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(237, 230, 216, 0.6);
}
.code-block__copy {
  font-family: var(--font-body);
  font-size: 0.72rem; font-weight: 500;
  color: #EDE6D8;
  background: rgba(255, 255, 255, 0.1);
  border: 0;
  padding: 4px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.code-block__copy:hover { background: rgba(255, 255, 255, 0.2); }
.article-prose .code-block pre {
  margin: 0;
  padding: 16px 18px;
  background: transparent;
  border: 0;
  border-radius: 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 400;
  line-height: 1.7;
  color: inherit;
  white-space: pre;
}
.article-prose .code-block pre code { background: transparent; padding: 0; font-size: inherit; color: inherit; }

/* Display equations (MathJax) sit on a quiet panel */
.article-prose mjx-container[display="true"] {
  display: block !important;
  margin: 1.6em 0 !important;
  padding: 18px 16px;
  background: var(--paper-2);
  border-radius: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
}

/* Source link */
.article-source { margin: 2em 0 0; font-size: 0.9rem; font-family: var(--font-body); }
.article-source a { color: var(--ink); border-bottom: 1px solid var(--border); padding-bottom: 2px; }
.article-source a:hover { border-color: var(--ink); }

.print-source { display: none; }

/* Keep a copy */
.keep-copy {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  margin: 48px 0 0;
  padding: 24px 28px;
  background: var(--paper-2);
  border-radius: 12px;
}
.keep-copy h2 { font-family: var(--font-serif); font-weight: 500; font-size: 1.25rem; margin: 0 0 4px; }
.keep-copy p { margin: 0 0 8px; font-family: var(--font-body); font-size: 0.86rem; color: var(--muted); }
.keep-copy__host { font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.08em; color: var(--muted); }
.keep-copy__btn {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--ink); color: var(--bg);
  border: 0;
  padding: 13px 22px;
  border-radius: 999px;
  font-size: 0.86rem; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.keep-copy__btn:hover { background: var(--chinar); transform: translateY(-1px); }

/* Share + author */
.article-share { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 22px 0; margin: 32px 0 0; border-top: 1px solid var(--art-rule); }
.author-card {
  display: flex; gap: 18px; align-items: flex-start;
  padding: 24px 0 0;
  margin-top: 8px;
  border-top: 1px solid var(--art-rule);
}
.author-card__avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.author-card h3 { font-family: var(--font-serif); font-weight: 500; font-size: 1.1rem; margin: 0 0 4px; }
.author-card p { margin: 0; font-family: var(--font-body); font-size: 0.9rem; line-height: 1.6; color: var(--muted); }

/* Series navigation keeps its existing classes; just align it */
.article-main .series-nav-buttons { margin-top: 32px; }

/* Related */
.article-related { margin-top: 56px; border-top: 1px solid var(--art-rule); }
.article-related__inner { max-width: var(--art-wrap); margin: 0 auto; padding: 48px 24px 24px; }
.article-related h2 { font-family: var(--font-serif); font-weight: 500; font-size: 1.6rem; margin: 0; }

/* Responsive */
@media (max-width: 960px) {
  .article-layout { grid-template-columns: minmax(0, var(--art-read)); gap: 8px; padding-top: 24px; }
  .article-toc {
    position: static;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--art-card);
  }
  .article-toc summary { padding: 14px 16px; pointer-events: auto; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
  .article-toc summary::after { content: "+"; font-size: 1rem; letter-spacing: 0; }
  .article-toc details[open] summary::after { content: "\2212"; }
  .article-toc ol { border-left: 0; padding: 0 16px 12px; }
  .article-toc a { padding-left: 12px; margin-left: 0; border-left-width: 2px; }
}
@media (max-width: 640px) {
  .article-head { padding: 32px 20px 0; }
  .article-layout { padding: 20px 20px 16px; }
  .article-prose { font-size: 1.04rem; line-height: 1.75; }
  .article-prose h2 { font-size: 1.5rem; }
  .print-link span { display: none; }
  .print-link { padding: 8px 10px; }
  .keep-copy { flex-direction: column; align-items: flex-start; padding: 22px; }
  .keep-copy__btn { width: 100%; justify-content: center; }
  .article-related__inner { padding: 36px 20px 16px; }
}

/* ==========================================================================
   PRINT / SAVE AS PDF
   Black on white, classic serif, no site chrome. Page number and site name
   in the footer of every sheet (Chrome, Edge, Safari; Firefox omits them).
   ========================================================================== */
@page {
  size: A4;
  margin: 20mm 20mm 24mm;
  @bottom-left {
    content: "farhanpaal.com";
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 8pt;
    letter-spacing: 0.08em;
    color: #8a8378;
  }
  @bottom-right {
    content: counter(page);
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 8pt;
    color: #8a8378;
  }
}

@media print {
  html, body { background: #fff !important; color: #000; }
  body { font-size: 11pt; }

  /* Remove everything except <main> (header, footer, newsletter, chat, cart...) */
  body > *:not(.site-main) { display: none !important; }
  .reading-progress,
  .breadcrumbs,
  .article-toc,
  .article-cover,
  .print-link,
  .keep-copy,
  .article-share,
  .author-card,
  .series-nav-buttons,
  .article-related,
  .article-source,
  .code-block__copy { display: none !important; }

  .article-head { max-width: none; padding: 0; }
  .article-head__eyebrow { color: #B5341F; font-size: 8pt; margin-bottom: 8pt; }
  .article-head__eyebrow a { color: #B5341F; }
  .article-head__eyebrow .sep { opacity: 1; margin: 0 6px; }
  .article-head__title { font-size: 26pt; line-height: 1.12; margin-bottom: 8pt; max-width: none; }
  .article-head__dek { font-size: 12pt; color: #5b554b; margin-bottom: 14pt; max-width: none; }
  .article-byline { padding: 8pt 0; border-color: #cfc8b8; }
  .article-byline__avatar { display: none; }
  .article-byline__name { display: inline; font-weight: 400; }
  .article-byline__name::after { content: " \00B7  "; }
  .article-byline__meta { display: inline; }
  .article-byline__who > div { display: block; font-size: 9pt; }

  .article-layout, .article-layout--no-toc { display: block; max-width: none; padding: 14pt 0 0; }
  .article-prose { font-size: 11pt; line-height: 1.65; color: #000; }
  .article-prose h2 { font-size: 15pt; margin: 18pt 0 6pt; break-after: avoid; }
  .article-prose h3 { font-size: 12.5pt; break-after: avoid; }
  .article-prose a { color: #000; text-decoration: none; }
  .article-prose p, .article-prose li { orphans: 3; widows: 3; }
  .article-prose img, .article-prose table, .article-prose blockquote, .code-block { break-inside: avoid; }

  .article-prose blockquote { border-left: 2pt solid #B5341F; color: #333; }

  /* Light code panel, as on paper */
  .code-block { background: #f3efe6 !important; color: #111 !important; border: 0.5pt solid #cfc8b8; border-radius: 4pt; }
  .code-block__bar { display: none; }
  .article-prose .code-block pre { white-space: pre-wrap; word-break: break-word; font-size: 8.5pt; line-height: 1.55; padding: 8pt 10pt; color: #111; }

  .article-prose mjx-container[display="true"] { background: transparent; padding: 6pt 0; text-align: center; }

  .print-source {
    display: block;
    margin: 22pt 0 0;
    padding-top: 8pt;
    border-top: 0.5pt solid #cfc8b8;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 7.5pt;
    color: #6b655a;
    word-break: break-all;
  }
}

/* ==========================================================================
   Whole card is clickable (image, title, description, date)
   The category label stays a separate link.
   ========================================================================== */
.art-card { position: relative; }
.art-card__title a::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}
.art-card__eyebrow a { position: relative; z-index: 2; }
.art-card:hover .art-card__title a { background-size: 100% 1px; }