:root {
  --blog-index-title-size: clamp(1.875rem, 1.2rem + 2.4vw, 3rem);
  --blog-index-mobile-title-size: 1.875rem;
  --blog-article-title-size: clamp(1.5rem, 1.1rem + 1.4vw, 2rem);
  --blog-article-mobile-title-size: 1.5rem;
  --blog-lead-size: clamp(0.9375rem, 0.85rem + 0.45vw, 1.125rem);
  --blog-h2-size: clamp(1.25rem, 1.13rem + 0.45vw, 1.5rem);
  --blog-h3-size: clamp(1.0625rem, 1rem + 0.35vw, 1.25rem);
  --blog-meta-size: 13px;
  --blog-crumb-separator: color-mix(in srgb, var(--text) 35%, var(--bg));
  --blog-card-min: 300px;
  --blog-flow-space: 1rem;
  --blog-chapter-space: 2rem;
}

.blog-index-intro {
  padding-block: clamp(2rem, 1.4rem + 3vw, 4rem);
}

.blog-index-intro h1,
:is(.article-hero, main.wrap.reading > article > header) h1 {
  color: var(--text);
  font-family: var(--font-display);
  font-weight: var(--weight-normal);
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.blog-index-intro h1 {
  margin: 0;
  font-size: var(--blog-index-title-size);
}

.blog-index-intro p {
  max-width: var(--reading-width);
  margin: 1rem 0 0;
  color: var(--text-muted);
  font-size: var(--blog-lead-size);
  line-height: 1.7;
}

.blog-catalog {
  padding-block: 2rem 3rem;
}

.blog-catalog-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
}

.blog-catalog-head h2,
.post-related-heading {
  margin: 0;
  font-size: var(--blog-h2-size);
  line-height: 1.4;
}

.blog-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.blog-filters[hidden] {
  display: none;
}

.blog-filters button {
  min-height: var(--tap);
  padding: 0.375rem 0.875rem;
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--panel);
  color: var(--text-muted);
  font: inherit;
  font-size: var(--size-small);
  cursor: pointer;
}

.blog-filters button:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.blog-filters button[aria-pressed="true"] {
  border-color: var(--text);
  background: var(--panel-2);
  color: var(--text);
  font-weight: var(--weight-medium);
}

.blog-results {
  margin: 0.875rem 0;
  color: var(--text-muted);
  font-size: var(--blog-meta-size);
}

.blog-results:empty,
#related-posts:empty,
#post-nav:empty {
  display: none;
}

.blog-post-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  gap: var(--gap-cards);
}

.blog-list-card,
.post-related-card,
.post-nav-card {
  min-width: 0;
  padding: clamp(1rem, 0.8rem + 0.8vw, 1.5rem);
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow-wrap: anywhere;
}

.blog-list-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem 0.75rem;
  margin: 0;
  color: var(--text-muted);
  font-size: var(--blog-meta-size);
  line-height: 1.5;
}

.post-meta time {
  font-family: var(--font-mono);
}

.post-meta .post-tag {
  padding: 0.125rem 0.5rem;
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--panel-2);
  color: var(--text);
}

.post-card .post-title {
  margin: 0.75rem 0 0;
  color: var(--text);
  font-size: var(--blog-h3-size);
  line-height: 1.45;
}

.post-card .post-summary {
  margin: 0.625rem 0 0;
  color: var(--text-muted);
  line-height: 1.7;
}

.blog-list-card .post-summary {
  margin-bottom: 1rem;
}

.blog-read-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  margin-top: auto;
  color: var(--text);
  font-size: var(--size-small);
  font-weight: var(--weight-medium);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.blog-read-link:hover,
.post-title a:hover,
.post-nav-card:hover .post-nav-title {
  color: var(--accent-ink);
}

main.wrap.reading:has(> nav > [aria-current="page"]) {
  padding-block-start: 32px;
}

main.wrap.reading > nav:has(> [aria-current="page"]) {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-block: 0 20px;
  overflow: hidden;
  color: var(--text-muted);
  font-size: var(--blog-meta-size);
  line-height: 1.6;
  white-space: nowrap;
}

main.wrap.reading > nav:has(> [aria-current="page"]) a {
  flex: 0 0 auto;
  color: var(--text-muted);
  text-decoration: none;
}

main.wrap.reading > nav:has(> [aria-current="page"]) a:hover {
  color: var(--accent-ink);
}

main.wrap.reading > nav:has(> [aria-current="page"]) [aria-hidden="true"] {
  flex: 0 0 auto;
  color: var(--blog-crumb-separator);
}

main.wrap.reading > nav:has(> [aria-current="page"]) [aria-current="page"] {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 30ch;
  overflow: hidden;
  text-overflow: ellipsis;
}

:is(.article-hero, main.wrap.reading > article > header) {
  padding-block: 0 1.5rem;
}

:is(.article-hero, main.wrap.reading > article > header) :is(.post-meta, .article-meta) {
  margin: 0 0 14px;
  color: var(--text-muted);
  font-size: var(--blog-meta-size);
}

:is(.article-hero, main.wrap.reading > article > header) h1 {
  max-width: 100%;
  margin: 0 0 12px;
  font-size: var(--blog-article-title-size);
}

:is(.article-hero, main.wrap.reading > article > header) :is(.article-lead, .post-lead, .article-summary, h1 + p) {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--blog-lead-size);
  line-height: 1.7;
}

:is(.article-body, .post-body, .article-hero ~ .prose) {
  color: var(--text);
  font-size: var(--size-body);
  line-height: 1.8;
  overflow-wrap: anywhere;
}

:is(.article-body, .post-body, .article-hero ~ .prose) section {
  padding-block: 0;
}

:is(.article-body, .post-body, .article-hero ~ .prose) :where(p, ul, ol, dl, blockquote, pre, figure, h2, h3, section) {
  margin-block: 0;
}

:is(.article-body, .post-body, .article-hero ~ .prose) > :where(p, ul, ol, dl, blockquote, pre, figure, h2, h3) + *,
:is(.article-body, .post-body, .article-hero ~ .prose) section > :where(p, ul, ol, dl, blockquote, pre, figure, h2, h3) + * {
  margin-block-start: var(--blog-flow-space);
}

:is(.article-body, .post-body, .article-hero ~ .prose) section + section,
:is(.article-body, .post-body, .article-hero ~ .prose) :where(p, ul, ol, dl, blockquote, pre, figure) + h2 {
  margin-block-start: var(--blog-chapter-space);
}

:is(.article-body, .post-body, .article-hero ~ .prose) > h2:first-of-type,
:is(.article-body, .post-body, .article-hero ~ .prose) section > h2:first-child {
  margin-block-start: 0;
}

:is(.article-body, .post-body, .article-hero ~ .prose) h2 {
  font-size: var(--blog-h2-size);
  line-height: 1.42;
}

:is(.article-body, .post-body, .article-hero ~ .prose) h3 {
  font-size: var(--blog-h3-size);
  line-height: 1.45;
}

:is(.article-body, .post-body, .article-hero ~ .prose) :where(ul, ol) {
  padding-inline-start: 1.5em;
}

:is(.article-body, .post-body, .article-hero ~ .prose) li + li {
  margin-block-start: 0.375rem;
}

:is(.article-body, .post-body, .article-hero ~ .prose) blockquote {
  margin-inline: 0;
  padding: 0.75rem 1rem;
  border-inline-start: var(--stroke) solid var(--border-strong);
  background: var(--panel-2);
}

:is(.article-body, .post-body, .article-hero ~ .prose) pre {
  max-width: 100%;
  padding: 0.875rem 1rem;
  overflow-x: auto;
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  white-space: pre;
}

:is(.article-body, .post-body, .article-hero ~ .prose) code {
  font-family: var(--font-mono);
}

:is(.article-body, .post-body, .article-hero ~ .prose) :not(pre) > code {
  padding: 0.1em 0.3em;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text);
}

:is(.article-body, .post-body, .prose) a:not([class*="btn"]):not([class*="button"]) {
  color: var(--accent-ink);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

:is(.article-body, .post-body, .prose) a:not([class*="btn"]):not([class*="button"]):hover {
  color: var(--text);
}

.card.article-download {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.875rem 1.25rem;
  margin-block: var(--blog-chapter-space) 0;
  padding: clamp(1rem, 0.8rem + 0.8vw, 1.5rem);
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

.article-download h2 {
  margin: 0;
  font-size: var(--blog-h2-size);
  line-height: 1.42;
}

.article-download p {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
}

.article-download .cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
}

#related-posts,
#post-nav {
  margin-block-start: var(--blog-chapter-space);
  padding-block-start: 1.25rem;
  border-block-start: var(--stroke) solid var(--border);
}

.post-related-grid,
#post-nav:not(:empty) {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.post-related-grid {
  margin-block-start: 1rem;
}

/* Use a single track whenever two cards would fall below 300px. */
#related-posts,
#post-nav {
  container-type: inline-size;
}

.post-title a,
.post-nav-card {
  color: var(--text);
  text-decoration: none;
}

#post-nav:not(:empty) {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--blog-card-min)), 1fr));
}

.post-nav-card {
  display: block;
}

.post-nav-card:hover,
.post-related-card:focus-within,
.blog-list-card:focus-within {
  border-color: var(--border-strong);
}

.post-nav-label {
  display: block;
  color: var(--text-muted);
  font-size: var(--blog-meta-size);
  line-height: 1.5;
}

.post-nav-title {
  display: block;
  margin-block-start: 0.375rem;
  font-weight: var(--weight-medium);
  line-height: 1.5;
}

.blog-filters button:focus-visible,
.blog-read-link:focus-visible,
main.wrap.reading > nav:has(> [aria-current="page"]) a:focus-visible,
.post-title a:focus-visible,
.post-nav-card:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
}

@container (width < 616px) {
  .post-related-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 767px) {
  .blog-index-intro h1 {
    font-size: var(--blog-index-mobile-title-size);
  }

  :is(.article-hero, main.wrap.reading > article > header) h1 {
    font-size: var(--blog-article-mobile-title-size);
  }
}