/* =============================================================================
   blog.css — the blog index, the category/tag archives, and a single post.

   Loaded after styles.css (and therefore after the theme tokens), so it
   inherits the design tokens, the dark/light switch, and the shared primitives
   (.btn, .card, .tag, .chip, .crumbs, .pager, .reveal). Only the shapes the
   rest of the site does not have live here.

   Per-post accent: each post sets --case-hue inline, reusing the same hue
   ladder as the projects (Project::HUES) so a post and a case study of the
   same rank read as siblings rather than as two unrelated palettes.

   Structure:
     01 Index head & filters   03 Single post   05 Print
     02 Post cards             04 Prose         06 Themes
   ========================================================================== */

/* Each post carries --case-hue inline; --post-hue is the value a theme is
   allowed to shift, exactly the way case.css lets themes move --case-accent.
   Everything tinted below reads --post-hue, never --case-hue directly, so a
   theme retunes the whole blog with one declaration. */
.post-card,
.post {
  --post-hue: var(--case-hue);
  --post-accent: hsl(var(--post-hue) 70% 55%);
}
[data-theme="light"] .post-card,
[data-theme="light"] .post { --post-accent: hsl(var(--post-hue) 65% 34%); }

.blog-head { padding-block: clamp(2rem, 5vw, 3.5rem) clamp(2.5rem, 6vw, 4rem); }
.blog-head__intro {
  font-size: var(--fs-lg);
  color: var(--text-dim);
  max-inline-size: 62ch;
  margin-block-start: var(--sp-3);
}

/* ================================================ 01 FILTERS === */
.blog-filters {
  display: grid;
  gap: var(--sp-4);
  padding-block: var(--sp-5);
  margin-block-end: clamp(1.5rem, 4vw, var(--sp-6));
  border-block: 1px solid var(--border);
}
.blog-filters__group { display: grid; gap: 0.6rem; }
.blog-filters__label {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}
html[lang="fa"] .blog-filters__label { letter-spacing: 0; text-transform: none; font-size: var(--fs-sm); }
.blog-filters__list { display: flex; flex-wrap: wrap; gap: 0.45rem; }

.blog-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-block-size: 36px;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text-dim);
  font-size: var(--fs-sm);
  font-weight: 600;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease),
              background-color 0.2s var(--ease);
}
.blog-chip:hover {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.blog-chip.is-active {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}
.blog-chip.is-active:hover { color: var(--accent-ink); background: var(--accent-strong); }
.blog-chip__count {
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}
.blog-chip--tag { font-weight: 500; }
.blog-chip--tag::before { content: "#"; opacity: 0.5; }
html[lang="fa"] .blog-chip--tag::before { content: "#"; unicode-bidi: isolate; }

/* ============================================== 02 POST CARDS === */
.post-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: clamp(1rem, 2.5vw, var(--sp-5));
}

.post-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: border-color 0.3s var(--ease), transform 0.3s var(--ease-out),
              box-shadow 0.3s var(--ease);
}
.post-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}
.post-card:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }

.post-card__media {
  display: block;
  aspect-ratio: 16 / 10;
  background: var(--surface-2);
  border-block-end: 1px solid var(--border);
  overflow: hidden;
}
.post-card__media img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
  transition: transform 0.5s var(--ease-out);
}
.post-card:hover .post-card__media img { transform: scale(1.04); }

/* Generated cover for posts with no image — the same trick the case-study
   pages use, so an unillustrated blog still looks finished. */
.post-card__generated {
  position: relative;
  display: grid;
  place-items: center;
  inline-size: 100%;
  block-size: 100%;
  background:
    radial-gradient(ellipse at 70% 15%, hsl(var(--post-hue) 70% 55% / 0.16), transparent 60%),
    linear-gradient(150deg, hsl(var(--post-hue) 45% 12%), hsl(calc(var(--post-hue) + 22) 40% 9%));
}
[data-theme="light"] .post-card__generated {
  background:
    radial-gradient(ellipse at 70% 15%, hsl(var(--post-hue) 65% 34% / 0.1), transparent 60%),
    linear-gradient(150deg, hsl(var(--post-hue) 30% 96%), hsl(calc(var(--post-hue) + 22) 32% 91%));
}
.post-card__grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, currentColor 1px, transparent 1px),
    linear-gradient(to bottom, currentColor 1px, transparent 1px);
  background-size: 40px 40px;
  color: var(--post-accent);
  opacity: 0.12;
  mask-image: radial-gradient(ellipse 70% 70% at 50% 40%, #000, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 70% 70% at 50% 40%, #000, transparent 75%);
}
.post-card__mono {
  position: relative;
  display: grid;
  place-items: center;
  inline-size: 58px;
  block-size: 58px;
  border-radius: 16px;
  font-family: var(--font-latin);
  font-size: 1.3rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(140deg,
    hsl(var(--post-hue) 72% 48%), hsl(calc(var(--post-hue) + 24) 70% 42%));
  box-shadow: 0 12px 28px -12px hsl(var(--post-hue) 70% 40% / 0.75);
}

.post-card__body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: var(--sp-5);
  flex: 1;
}
.post-card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  font-size: var(--fs-xs);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.post-card__cat {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.04em;
}
.post-card__dot { opacity: 0.6; }

.post-card__title { font-size: var(--fs-lg); }
.post-card__link { color: inherit; }
.post-card__link::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
}
.post-card__link:focus-visible { outline: none; }
.post-card:hover .post-card__title { color: var(--accent); }

.post-card__excerpt {
  font-size: var(--fs-base);
  color: var(--text-dim);
  flex: 1;
}
.post-card__tags { margin-block-start: auto; padding-block-start: 0.3rem; }

/* ============================================== 03 SINGLE POST === */
/* A post with no related list and no neighbours ends at its tags, which sat
   flush against the footer. */
.post { padding-block-end: clamp(2rem, 5vw, var(--sp-7)); }
.post__head { padding-block: clamp(1.5rem, 4vw, var(--sp-6)) clamp(1rem, 3vw, var(--sp-5)); }
.post__head-inner { max-inline-size: 760px; }

.post__cat {
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-block-end: var(--sp-3);
}
html[lang="fa"] .post__cat { letter-spacing: 0; text-transform: none; }
.post__cat a { color: var(--post-accent); }

.post__title {
  font-size: clamp(1.9rem, 1.3rem + 2.8vw, 3.2rem);
  letter-spacing: -0.03em;
  line-height: 1.08;
}
html[lang="fa"] .post__title { letter-spacing: 0; line-height: 1.35; }

.post__excerpt {
  font-size: var(--fs-lg);
  color: var(--text-dim);
  margin-block-start: var(--sp-4);
}
.post__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-block-start: var(--sp-4);
  font-size: var(--fs-sm);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.post__cover {
  max-inline-size: 900px;
  margin-inline: auto;
  margin-block-end: clamp(1.5rem, 4vw, var(--sp-6));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.post__cover img { inline-size: 100%; block-size: auto; }

.post__tags {
  max-inline-size: 760px;
  margin-inline: auto;
  margin-block: var(--sp-6) 0;
  padding-block-start: var(--sp-5);
  border-block-start: 1px solid var(--border);
}
.tag--link { transition: color 0.2s var(--ease), border-color 0.2s var(--ease); }
.tag--link::before { content: "#"; opacity: 0.5; }
.tag--link:hover { color: var(--accent); border-color: var(--accent-line); }

.post__nav { margin-block: clamp(2rem, 5vw, var(--sp-7)) 0; }
.post__related { margin-block-start: clamp(2rem, 5vw, var(--sp-7)); }
.post__back { margin-block-start: clamp(1.5rem, 4vw, var(--sp-6)); }

.post-grid--related { grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }

.blog-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  margin-block-start: clamp(2rem, 5vw, var(--sp-7));
}
.blog-pager__status {
  font-size: var(--fs-sm);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.blog-empty {
  text-align: center;
  padding-block: clamp(2.5rem, 6vw, var(--sp-8));
}
.blog-empty__title { font-size: var(--fs-lg); font-weight: 600; }
.blog-empty__hint { color: var(--text-faint); margin-block-start: 0.4rem; }

/* ==================================================== 04 PROSE === */
/* The one place on the site that renders authored rich text. Everything is
   scoped under .prose so post markup can never leak into the layout. */
.prose {
  max-inline-size: 760px;
  margin-inline: auto;
  font-size: var(--fs-lg);
  line-height: 1.8;
  color: var(--text-dim);
}
.prose > * + * { margin-block-start: var(--sp-4); }

.prose h2,
.prose h3,
.prose h4 {
  color: var(--text);
  margin-block-start: var(--sp-7);
  scroll-margin-block-start: calc(var(--header-h) + 16px);
}
.prose h2 { font-size: var(--fs-xl); }
.prose h3 { font-size: var(--fs-lg); }
.prose h4 { font-size: var(--fs-md); }

.prose strong { color: var(--text); font-weight: 600; }
.prose a { text-decoration: underline; text-underline-offset: 0.2em; }

.prose ul,
.prose ol {
  display: grid;
  gap: 0.5rem;
  padding-inline-start: 1.4rem;
}
.prose ul { list-style: disc; }
.prose ol { list-style: decimal; }
.prose li::marker { color: var(--accent); }
.prose li > ul, .prose li > ol { margin-block-start: 0.5rem; }

.prose blockquote {
  padding-inline-start: var(--sp-5);
  border-inline-start: 3px solid var(--accent-line);
  color: var(--text);
  font-style: italic;
}

.prose code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.1rem 0.35rem;
  /* Code is Latin even inside Persian prose. */
  direction: ltr;
  unicode-bidi: isolate;
}
.prose pre {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: var(--sp-4);
  overflow-x: auto;
  direction: ltr;
  text-align: start;
}
.prose pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1.7;
}

.prose img {
  border-radius: var(--r);
  border: 1px solid var(--border);
}
.prose hr {
  border: none;
  border-block-start: 1px solid var(--border);
  margin-block: var(--sp-6);
}

.prose table {
  inline-size: 100%;
  border-collapse: collapse;
  font-size: var(--fs-base);
  display: block;
  overflow-x: auto;
}
.prose th, .prose td {
  text-align: start;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
}
.prose th { color: var(--text); font-weight: 600; background: var(--surface-2); }

/* ==================================================== 05 PRINT === */
/* A post prints as a clean article: screen chrome and navigation go, the prose
   drops to a readable point size. The résumé's own print rules in styles.css
   are untouched — no blog element appears on the home or project pages. */
@media print {
  .blog-filters, .blog-pager, .post__nav, .post__related,
  .post-card__media, .post__back { display: none !important; }

  .blog-head { padding-block: 0 0.8rem; }
  .post__head { padding-block: 0 0.6rem; }
  .post__title { font-size: 20pt; }
  .post__excerpt { font-size: 10.5pt; }
  .post__meta { font-size: 8.5pt; }

  .prose { font-size: 10pt; line-height: 1.55; max-inline-size: none; }
  .prose h2 { font-size: 13pt; margin-block-start: 0.9rem; }
  .prose h3 { font-size: 11pt; margin-block-start: 0.7rem; }
  .prose pre { background: #f4f4f4; border-color: #ddd; }
  .prose a::after { content: " (" attr(href) ")"; font-size: 8pt; color: #666; }

  .post__cover { box-shadow: none; border-color: #ddd; }
  .post-card { border-color: #ddd; break-inside: avoid; }
  .post-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
}

/* =================================================== 06 THEMES === */
/* Themes restyle the blog through the same tokens they restyle everything else
   with; only shapes that the token system cannot reach need a rule here.
   Both blocks are screen-only for the same reason the theme sheets are. */
@media screen {
  /* Blueprint: square, ink rules, hard offset shadows, monospaced labels. */
  [data-skin="blueprint"] .post-card,
  [data-skin="blueprint"] .post__cover,
  [data-skin="blueprint"] .prose pre,
  [data-skin="blueprint"] .prose img,
  [data-skin="blueprint"] .blog-empty {
    border: 2px solid var(--ink);
    border-radius: 0;
    box-shadow: var(--shadow-sm);
  }
  [data-skin="blueprint"] .post-card:hover {
    transform: translate(-3px, -3px);
    border-color: var(--ink);
    box-shadow: var(--shadow);
  }
  html[dir="rtl"][data-skin="blueprint"] .post-card:hover { transform: translate(3px, -3px); }
  [data-skin="blueprint"] .post-card__mono,
  [data-skin="blueprint"] .blog-chip {
    border-radius: 0;
    border: 1px solid var(--ink);
    font-family: var(--font-mono);
  }
  [data-skin="blueprint"] .post-card__meta,
  [data-skin="blueprint"] .blog-filters__label,
  [data-skin="blueprint"] .blog-pager__status { font-family: var(--font-mono); }
  [data-skin="blueprint"] .post-card__title,
  [data-skin="blueprint"] .post__title { text-transform: uppercase; }
  html[lang="fa"][data-skin="blueprint"] .post-card__title,
  html[lang="fa"][data-skin="blueprint"] .post__title { text-transform: none; }
  [data-skin="blueprint"] .prose code { border-radius: 0; }
  /* Same warm shift Blueprint applies to the case-study hues: 168…232 → 23…87,
     rust to ochre. Without it the generated covers stayed brand teal on paper
     stock, which read as a different site. */
  [data-skin="blueprint"] .post-card,
  [data-skin="blueprint"] .post { --post-hue: calc(var(--case-hue) - 145); }

  /* Nocturne: glass tiles, larger radii, indigo→violet, display face. */
  [data-skin="nocturne"] .post-card,
  [data-skin="nocturne"] .post__cover,
  [data-skin="nocturne"] .blog-empty,
  [data-skin="nocturne"] .prose pre {
    background: var(--surface);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    box-shadow: var(--shadow-sm), inset 0 1px 0 var(--glass-top);
  }
  [data-skin="nocturne"] .post-card:hover {
    border-color: var(--accent-line);
    box-shadow: var(--shadow), 0 0 50px -24px var(--glow), inset 0 1px 0 var(--glass-top);
  }
  [data-skin="nocturne"] .post-card__title,
  [data-skin="nocturne"] .post__title,
  [data-skin="nocturne"] .prose h2,
  [data-skin="nocturne"] .prose h3 { font-family: var(--font-display); }
  [data-skin="nocturne"] .post-card__mono {
    border-radius: 14px;
    background: linear-gradient(140deg, var(--accent-fill), var(--violet));
  }
  /* Same indigo→violet shift Nocturne applies to the case-study hues. */
  [data-skin="nocturne"] .post-card,
  [data-skin="nocturne"] .post { --post-hue: calc(var(--case-hue) + 62); }
  [data-skin="nocturne"] .blog-chip { background: var(--surface); }
  [data-skin="nocturne"] .blog-chip.is-active {
    background: linear-gradient(140deg, var(--btn-a), var(--btn-b));
    color: var(--btn-ink);
    border-color: transparent;
  }
  /* The rail already carries the identity, so the blog's own head sits closer
     to the top and the grid gets the narrower measure the board uses. */
  [data-skin="nocturne"] .blog-head { padding-block: clamp(1.25rem, 3vw, 2rem) clamp(1.5rem, 4vw, 2.5rem); }
  [data-skin="nocturne"] .post-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  }
}
