/* =========================================================================
   benmilne.com
   A designed publication. Scale contrast creates drama.
   The gap between the largest and smallest element is the design.
   ========================================================================= */

:root {
  --color-bg: #f5f2ec;
  --color-text: #141310;
  --color-text-2: #3d3b36;
  --color-text-3: #7c796f;
  --color-rule: #141310;
  --color-rule-fine: rgba(20, 19, 16, 0.15);
  --color-code-bg: #eae6de;
  --color-accent: #8b4513;
  --color-accent-line: rgba(139, 69, 19, 0.3);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino,
    Georgia, "Times New Roman", serif;
  --mono: "SF Mono", ui-monospace, "Fira Mono", Menlo, Consolas, monospace;

  /* Scale — the range IS the design */
  --size-micro: 0.625rem;    /* 10px — dates, labels */
  --size-xs: 0.6875rem;      /* 11px */
  --size-sm: 0.8125rem;      /* 13px */
  --size-body: 1.125rem;     /* 18px */
  --size-lg: 1.3125rem;      /* 21px — opening para */
  --size-h3: 1.25rem;        /* 20px */
  --size-h2: 1.5rem;         /* 24px */
  --size-h1: 2.75rem;        /* 44px — article title */
  --size-display: 4rem;      /* 64px — homepage title */
  --size-chapter: 5rem;      /* 80px — chapter number */

  --lh-body: 1.8;
  --lh-tight: 1.08;

  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.25rem;
  --s6: 1.5rem;
  --s8: 2rem;
  --s10: 2.5rem;
  --s12: 3rem;
  --s16: 4rem;
  --s20: 5rem;
  --s24: 6rem;
  --s32: 8rem;

  --col: 36rem;
  --gutter: 1.5rem;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Table rules — one hairline, one “major” (header / section) */
  --table-rule: color-mix(in srgb, var(--color-rule) 18%, var(--color-bg));
  --table-rule-strong: color-mix(in srgb, var(--color-rule) 45%, var(--color-bg));

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0e0d0b;
    --color-text: #ede9e0;
    --color-text-2: #a8a49a;
    --color-text-3: #5a5750;
    --color-rule: #ede9e0;
    --color-rule-fine: rgba(237, 233, 224, 0.12);
    --color-code-bg: #1a1916;
    --color-accent: #d4943a;
    --color-accent-line: rgba(212, 148, 58, 0.35);
    --table-rule: color-mix(in srgb, var(--color-rule) 22%, var(--color-bg));
    --table-rule-strong: color-mix(in srgb, var(--color-rule) 55%, var(--color-bg));
  }
}

:root[data-theme="light"] {
  --color-bg: #f5f2ec;
  --color-text: #141310;
  --color-text-2: #3d3b36;
  --color-text-3: #7c796f;
  --color-rule: #141310;
  --color-rule-fine: rgba(20, 19, 16, 0.15);
  --color-code-bg: #eae6de;
  --color-accent: #8b4513;
  --color-accent-line: rgba(139, 69, 19, 0.3);
  --table-rule: color-mix(in srgb, var(--color-rule) 18%, var(--color-bg));
  --table-rule-strong: color-mix(in srgb, var(--color-rule) 45%, var(--color-bg));
  color-scheme: light;
}

:root[data-theme="dark"] {
  --color-bg: #0e0d0b;
  --color-text: #ede9e0;
  --color-text-2: #a8a49a;
  --color-text-3: #5a5750;
  --color-rule: #ede9e0;
  --color-rule-fine: rgba(237, 233, 224, 0.12);
  --color-code-bg: #1a1916;
  --color-accent: #d4943a;
  --color-accent-line: rgba(212, 148, 58, 0.35);
  --table-rule: color-mix(in srgb, var(--color-rule) 22%, var(--color-bg));
  --table-rule-strong: color-mix(in srgb, var(--color-rule) 55%, var(--color-bg));
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  hanging-punctuation: first last;
}

body {
  font-family: var(--serif);
  font-size: var(--size-body);
  line-height: var(--lh-body);
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  width: 100%;
  max-width: var(--col);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

a { color: inherit; text-decoration: none; }

/* === Header — visible only on interior pages === */

.site-header {
  width: 100%;
  max-width: var(--col);
  margin-inline: auto;
  padding: var(--s4) var(--gutter) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.site-header--home .site-title { display: none; }
.site-header--home .site-nav { margin-left: auto; }

.site-title,
.site-nav a {
  font-family: var(--mono);
  font-size: var(--size-micro);
  font-weight: 400;
  color: var(--color-text-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 0.15s ease;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.site-title:hover,
.site-nav a:hover { color: var(--color-text); }
.site-nav { display: flex; gap: var(--s6); }

/* === Skip / Focus === */

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--gutter);
  padding: var(--s2) var(--s4);
  font-family: var(--mono);
  font-size: var(--size-xs);
  background: var(--color-text);
  color: var(--color-bg);
  border-radius: var(--radius-sm);
  z-index: 100;
}
.skip-link:focus { top: var(--s2); }

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* =========================================================================
   Homepage — the cover
   ========================================================================= */

.home-header {
  padding-top: var(--s32);
  padding-bottom: var(--s8);
}

.home-title {
  font-family: var(--serif);
  font-size: var(--size-display);
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: -0.03em;
  color: var(--color-text);
}

.home-subtitle {
  margin-top: var(--s6);
  font-family: var(--serif);
  font-size: var(--size-body);
  font-weight: 400;
  font-style: italic;
  line-height: 1.55;
  color: var(--color-text-2);
}

/* === Contents === */

.chapter-list {
  list-style: none;
  margin-top: var(--s16);
  padding-top: var(--s12);
  border-top: 3px solid var(--color-rule);
  padding-bottom: var(--s24);
}

.chapter-item a {
  display: flex;
  align-items: baseline;
  gap: var(--s6);
  padding-block: var(--s6);
  min-height: 44px;
  transition: color 0.15s ease;
}

.chapter-item a:hover {
  color: var(--color-accent);
}

.chapter-num {
  font-family: var(--mono);
  font-size: var(--size-micro);
  color: var(--color-text-3);
  letter-spacing: 0.04em;
  flex-shrink: 0;
  width: 1.75rem;
}

.chapter-title {
  font-family: var(--serif);
  font-size: var(--size-lg);
  font-weight: 400;
  line-height: 1.3;
}

/* === Infinite scroll sentinel === */

.scroll-sentinel {
  height: 1px;
  margin-top: var(--s4);
}

.scroll-sentinel--loading {
  height: auto;
  display: flex;
  justify-content: center;
  padding: var(--s8) 0;
}

.scroll-sentinel--loading::after {
  content: "";
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-rule-fine);
  border-top-color: var(--color-text-3);
  border-radius: 50%;
  animation: sentinel-spin 0.6s linear infinite;
}

@keyframes sentinel-spin {
  to { transform: rotate(360deg); }
}

.chapter-item--loaded {
  animation: chapter-fade-in 0.3s ease both;
}

@media (prefers-reduced-motion: reduce) {
  .chapter-item--loaded { animation: none; }
  .scroll-sentinel--loading::after { animation: none; }
}

/* === Pagination fallback (noscript) === */

.pagination-fallback {
  display: flex;
  gap: var(--s3);
  justify-content: center;
  padding: var(--s8) 0 var(--s16);
  font-family: var(--mono);
  font-size: var(--size-sm);
}

.pagination-fallback a,
.pagination-fallback .pagination-current {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
  padding: var(--s1) var(--s2);
  border-radius: var(--radius-sm);
  color: var(--color-text-3);
  transition: color 0.15s ease;
}

.pagination-fallback a:hover { color: var(--color-accent); }
.pagination-fallback .pagination-current { color: var(--color-text); font-weight: 600; }

@keyframes chapter-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =========================================================================
   Article
   ========================================================================= */

.post-header {
  padding-top: var(--s8);
  margin-bottom: var(--s16);
}

/* The chapter number — the dramatic moment */
.post-chapter-num {
  font-family: var(--serif);
  font-size: var(--size-chapter);
  font-weight: 300;
  line-height: 0.85;
  color: var(--color-text-3);
  letter-spacing: -0.04em;
  margin-bottom: var(--s3);
}

.post-header h1 {
  font-family: var(--serif);
  font-size: var(--size-h1);
  font-weight: 400;
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
  text-wrap: balance;
  color: var(--color-text);
}

.post-header time {
  display: block;
  margin-top: var(--s4);
  font-family: var(--mono);
  font-size: var(--size-micro);
  color: var(--color-text-3);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* =========================================================================
   Content
   ========================================================================= */

.post-content > * + * { margin-top: var(--s8); }

.post-content > p:first-child {
  font-size: var(--size-lg);
  line-height: 1.6;
}

.post-content h2 {
  font-family: var(--serif);
  font-size: var(--size-h2);
  font-weight: 600;
  line-height: var(--lh-tight);
  letter-spacing: -0.015em;
  text-wrap: balance;
  margin-top: var(--s20);
  margin-bottom: var(--s2);
  scroll-margin-top: var(--s8);
}

.post-content h3 {
  font-family: var(--serif);
  font-size: var(--size-h3);
  font-weight: 600;
  line-height: var(--lh-tight);
  text-wrap: balance;
  margin-top: var(--s12);
  scroll-margin-top: var(--s8);
}

.post-content h4 {
  font-family: var(--serif);
  font-size: var(--size-body);
  font-weight: 600;
  line-height: var(--lh-tight);
  text-wrap: balance;
  margin-top: var(--s8);
  scroll-margin-top: var(--s8);
}

.post-content p { text-wrap: pretty; }
.post-content strong { font-weight: 600; }

.post-content ul,
.post-content ol {
  padding-left: var(--s6);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}
.post-content li::marker { color: var(--color-text-3); }

/* Pull quote — blockquotes become dramatic */
.post-content blockquote {
  margin-block: var(--s12);
  margin-left: 0;
  padding-left: var(--s6);
  border-left: 3px solid var(--color-accent);
  font-family: var(--serif);
  font-size: var(--size-h2);
  font-weight: 400;
  font-style: italic;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--color-text);
}

.post-content blockquote p {
  font-size: inherit;
  line-height: inherit;
}

/* Tables
   Borders: Vercel-style crisp edge = hairline + slight outer lift; 3-col comparison
   uses border-collapse: collapse so a full-width tr border (section bands) is one line,
   not per-cell box-shadow (which broke when empty cells were width-collapsed). */
.post-content .wp-block-table {
  margin-block: var(--s10);
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  /* Crisp frame only — no card drop-shadow (feels off-brand; border carries edge) */
  border: 1px solid var(--table-rule-strong);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  box-shadow: none;
}

.post-content .wp-block-table table {
  width: 100%;
  min-width: min(100%, 20rem);
  border-collapse: separate;
  border-spacing: 0;
  margin-block: 0;
  /* Match publication body (design-system: 18px, lh 1.8) — scale down slightly in narrow viewports for fit */
  font-family: var(--serif);
  font-size: clamp(0.9375rem, 0.9rem + 0.2vw, var(--size-body));
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

/* 3-column WordPress comparison: merged borders, full-width section rules */
.post-content
  .wp-block-table
  table:has(> tbody > tr:first-child > td:nth-child(3)) {
  border-collapse: collapse;
}

/* Default table (e.g. no figure wrapper) */
.post-content > table,
.post-content table:only-of-type {
  border-collapse: separate;
  border-spacing: 0;
}
.post-content > table,
.post-content :not(.wp-block-table) > table {
  margin-block: var(--s8);
  width: 100%;
  font-family: var(--serif);
  font-size: clamp(0.9375rem, 0.9rem + 0.2vw, var(--size-body));
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--color-rule-fine);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.post-content th,
.post-content td {
  text-align: left;
  vertical-align: top;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--table-rule);
  hyphens: auto;
}
.post-content .wp-block-table td,
.post-content .wp-block-table th {
  padding: var(--s4) var(--s5);
}
.post-content th {
  font-weight: 600;
  color: var(--color-text-2);
  font-size: var(--size-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--color-code-bg);
}

/* WordPress: first row = column titles but marked as <td> (empty first cell) */
.post-content
  .wp-block-table
  table:has(> tbody > tr:first-child > td:nth-child(3))
  > tbody
  > tr:first-child:has(> td:first-child:empty)
  > td {
  /* Column titles — h3 scale, wayfinding (design-system: heading lh ~1.08) */
  font-family: var(--serif);
  font-size: clamp(1.05rem, 1rem + 0.2vw, var(--size-h3));
  font-weight: 600;
  line-height: var(--lh-tight);
  color: var(--color-text);
  text-transform: none;
  letter-spacing: 0.01em;
  padding: var(--s5) var(--s5) var(--s4);
  border-bottom: 2px solid var(--table-rule-strong);
  background: var(--color-code-bg);
  text-wrap: balance;
}
.post-content
  .wp-block-table
  table:has(> tbody > tr:first-child > td:nth-child(3))
  > tbody
  > tr:first-child:has(> td:first-child:empty)
  > td:nth-child(2),
.post-content
  .wp-block-table
  table:has(> tbody > tr:first-child > td:nth-child(3))
  > tbody
  > tr:first-child:has(> td:first-child:empty)
  > td:nth-child(3) {
  text-align: center;
}
.post-content
  .wp-block-table
  table:has(> tbody > tr:first-child > td:nth-child(3))
  > tbody
  > tr:first-child:has(> td:first-child:empty)
  > td:first-child:empty {
  border-bottom: 2px solid var(--table-rule-strong);
  background: var(--color-code-bg);
  width: 12%;
  min-width: 3.5rem;
  padding-inline: 0;
}

/* Section bands: top + bottom on the <tr> so rules span full width. Per-cell
   borders fail here: empty 2nd/3rd <td> use border:none for layout, which
   removed their bottom border — only column 1 showed a line (short "underline"). */
.post-content
  .wp-block-table
  table:has(> tbody > tr:first-child > td:nth-child(3))
  > tbody
  > tr:not(:first-child):has(> td:nth-child(2):empty):has(> td:nth-child(3):empty) {
  border-top: 1px solid var(--table-rule-strong);
  border-bottom: 1px solid var(--table-rule);
}
/* First band (e.g. Attributes) sits under the 2px header rule — no second top line */
.post-content
  .wp-block-table
  table:has(> tbody > tr:first-child > td:nth-child(3))
  > tbody
  > tr:nth-child(2):has(> td:nth-child(2):empty):has(> td:nth-child(3):empty) {
  border-top: none;
}

/* No double line: body row before a section band drops its bottom border */
.post-content
  .wp-block-table
  table:has(> tbody > tr:first-child > td:nth-child(3))
  > tbody
  > tr:not(:first-child):has(
    + tr:not(:first-child):has(> td:nth-child(2):empty):has(> td:nth-child(3):empty)
  )
  > td {
  border-bottom: none;
}

/* Section rows: label in col1, empty col2+3 (Attributes / Revenue / Costs) */
.post-content
  .wp-block-table
  table:has(> tbody > tr:first-child > td:nth-child(3))
  > tbody
  > tr:not(:first-child):has(> td:nth-child(2):empty):has(> td:nth-child(3):empty)
  > td {
  /* Section overlines — one step above micro, still subordinate to column headers */
  font-family: var(--serif);
  font-weight: 600;
  font-size: var(--size-sm);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-2);
  line-height: 1.25;
  padding: var(--s6) var(--s4) var(--s2);
  /* Tr uses border-top / border-bottom — cells must not draw their own bottom */
  border-top: 0;
  border-bottom: 0;
  background: color-mix(in srgb, var(--color-code-bg) 32%, var(--color-bg));
  box-shadow: none;
  vertical-align: middle;
  text-align: left;
  text-wrap: balance;
}
.post-content
  .wp-block-table
  table:has(> tbody > tr:first-child > td:nth-child(3))
  > tbody
  > tr:not(:first-child):has(> td:nth-child(2):empty):has(> td:nth-child(3):empty)
  > td
  strong {
  font-weight: 600;
}
.post-content
  .wp-block-table
  table:has(> tbody > tr:first-child > td:nth-child(3))
  > tbody
  > tr:not(:first-child):has(> td:nth-child(2):empty):has(> td:nth-child(3):empty)
  > td:empty {
  width: 0.01px;
  max-width: 0;
  padding: 0;
  /* Not border: none — that was part of the short-line bug; tr owns full-width rules */
  border: 0;
  overflow: hidden;
  font-size: 0;
  line-height: 0;
  vertical-align: top;
}

/* 3-col comparison: row labels in first column */
.post-content
  .wp-block-table
  table:has(> tbody > tr:first-child > td:nth-child(3))
  > tbody
  > tr:not(:first-child):not(:has(> td:nth-child(2):empty))
  > td:first-child {
  font-weight: 600;
  color: var(--color-text);
  padding-right: var(--s5);
  width: 28%;
  min-width: 7.5em;
  line-height: 1.5;
  text-wrap: pretty;
}
.post-content
  .wp-block-table
  table:has(> tbody > tr:first-child > td:nth-child(3))
  > tbody
  > tr:not(:first-child):not(:has(> td:nth-child(2):empty))
  > td:not(:first-child) {
  /* Data cells: comfortable scan, still tied to table font-size */
  line-height: 1.6;
  color: var(--color-text-2);
  text-wrap: pretty;
  font-weight: 400;
}

/* alignwide: a touch wider than the main column (WP block class) */
.post-content .wp-block-table.alignwide {
  max-width: min(100%, 40rem);
  margin-inline: auto;
  width: 100%;
}

.post-content .wp-block-table tbody tr:last-child td,
.post-content > table tbody tr:last-child td {
  border-bottom: none;
}

/* Vercel guidelines: interactions increase contrast — subtle row affordance (tables are not interactive; hover clarifies scan) */
@media (hover: hover) {
  .post-content .wp-block-table tbody tr:hover td {
    background-color: color-mix(in srgb, var(--color-code-bg) 45%, var(--color-bg));
  }
  .post-content
    .wp-block-table
    tbody
    > tr:first-child:hover
    > td,
  .post-content
    .wp-block-table
    tbody
    > tr:not(:first-child):has(> td:nth-child(2):empty):has(> td:nth-child(3):empty):hover
    > td {
    /* Keep header & section band treatment on hover */
    background-color: color-mix(in srgb, var(--color-code-bg) 70%, var(--color-bg));
  }
}

/* Inline code */
.post-content code {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--color-code-bg);
  padding: 0.15em 0.35em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-rule-fine);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: auto;
  translate: no;
}

/* Code blocks */
.post-content pre {
  background: var(--color-code-bg);
  padding: var(--s6);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-rule-fine);
  overflow-x: auto;
  font-size: var(--size-sm);
  line-height: 1.65;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: auto;
  tab-size: 2;
}
.post-content pre code {
  background: none;
  padding: 0;
  border: none;
  font-size: inherit;
}

/* Code block with header (wrapper) */
.code-block {
  position: relative;
  margin-block: var(--s10);
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--s2) var(--s4);
  background: var(--color-code-bg);
  border: 1px solid var(--color-rule-fine);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.code-block-lang {
  font-family: var(--mono);
  font-size: var(--size-micro);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-3);
}

.code-block-copy {
  font-family: var(--mono);
  font-size: var(--size-micro);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-3);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--s1) var(--s3);
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, opacity 0.15s ease;
  opacity: 0;
  min-height: 28px;
  display: inline-flex;
  align-items: center;
}

.code-block:hover .code-block-copy,
.code-block-copy:focus-visible {
  opacity: 1;
}

.code-block-copy:hover {
  color: var(--color-accent);
}

.code-block pre {
  margin: 0;
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.post-content img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-md);
}

.about-photos {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s4);
  margin-top: var(--s10);
}
.about-photos img {
  flex: 1 1 calc((100% - 2 * var(--s4)) / 3);
  min-width: calc((100% - 2 * var(--s4)) / 3);
  max-width: calc((100% - var(--s4)) / 2);
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-md);
}
@media (max-width: 600px) {
  .about-photos img {
    flex-basis: calc((100% - var(--s4)) / 2);
    min-width: calc((100% - var(--s4)) / 2);
    max-width: 100%;
  }
}

/* Figures — images and video embeds */
.post-content figure {
  margin-block: var(--s10);
  margin-inline: 0;
}

.post-content figure img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-rule-fine);
}

.post-content figure figcaption {
  margin-top: var(--s3);
  font-family: var(--mono);
  font-size: var(--size-xs);
  color: var(--color-text-3);
  letter-spacing: 0.02em;
}

/* WordPress gallery block — nested figures in a grid (e.g. side-by-side comparisons) */
.post-content .wp-block-gallery.has-nested-images {
  display: grid;
  gap: var(--s4) var(--s5);
  align-items: start;
  margin-block: var(--s10);
  margin-inline: 0;
  width: 100%;
}

.post-content .wp-block-gallery.has-nested-images > figure {
  margin-block: 0;
  margin-inline: 0;
  min-width: 0;
}

/*
 * Same-sized tiles as .about-photos: column width (grid) + aspect-ratio + object-fit.
 * height:100% on an unfilled fr chain collapses to 0; aspect-ratio sizes from width instead.
 */
.post-content .wp-block-gallery.has-nested-images > figure > a {
  display: block;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.post-content .wp-block-gallery.has-nested-images > figure > a > img {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: cover;
  object-position: top center;
  display: block;
}

.post-content .wp-block-gallery.columns-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.post-content .wp-block-gallery.columns-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.post-content .wp-block-gallery.columns-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.post-content .wp-block-gallery.columns-default {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
}

.post-content .wp-block-gallery.alignwide {
  max-width: min(100%, 40rem);
  margin-inline: auto;
}

@media (max-width: 720px) {
  .post-content .wp-block-gallery.columns-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .post-content .wp-block-gallery.columns-3 {
    grid-template-columns: 1fr;
  }

  .post-content .wp-block-gallery.columns-2 {
    grid-template-columns: 1fr;
  }
}

/* WordPress “lightbox” → click-to-expand (see renderer: cleanWordPressLightboxArtifacts) */
.post-content figure.post-figure--zoom a,
.post-content figure.post-figure--zoom img[role="button"] {
  cursor: zoom-in;
}

/* Video embeds — responsive 16:9 (YouTube, Vimeo, self-hosted) */
.post-content .video-embed,
.post-content .wp-block-embed,
.post-content .wp-block-video {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin-block: var(--s10);
  background: var(--color-code-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-rule-fine);
  overflow: hidden;
}
.post-content .wp-block-embed .wp-block-embed__wrapper {
  position: absolute;
  inset: 0;
}
.post-content .video-embed iframe,
.post-content .wp-block-embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}
.post-content .wp-block-video video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: var(--radius-md);
}

/* Mermaid diagrams */
.mermaid-wrapper {
  position: relative;
  margin-block: var(--s10);
  border: 1px solid var(--color-rule-fine);
  border-radius: var(--radius-md);
  background: var(--color-bg);
}

.mermaid-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--s2) var(--s3);
}

.mermaid-toolbar-label {
  font-family: var(--mono);
  font-size: var(--size-micro);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-3);
  line-height: 1;
}

.mermaid-toolbar-actions {
  display: flex;
}

.mermaid-toolbar button {
  font-family: var(--mono);
  font-size: var(--size-micro);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-3);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--s1) var(--s2);
  transition: color 0.15s ease;
  line-height: 1;
}

.mermaid-toolbar button:hover {
  color: var(--color-accent);
}

.post-content pre.mermaid {
  background: var(--color-bg);
  padding: var(--s4);
  border-radius: var(--radius-md);
  overflow-x: auto;
  text-align: center;
  margin-block: var(--s10);
  border: 1px solid var(--color-rule-fine);
}

.mermaid-wrapper pre.mermaid {
  background: transparent;
  padding: 0;
  overflow-x: auto;
  text-align: center;
  margin: 0;
  border: none;
  border-radius: 0;
}

pre.mermaid svg {
  max-width: 100%;
  height: auto;
  display: block;
}

.mermaid-wrapper pre.mermaid svg text {
  font-family: var(--mono) !important;
}

.mermaid-wrapper pre.mermaid svg rect.actor {
  fill: var(--color-code-bg) !important;
  stroke: var(--color-rule-fine) !important;
}

.mermaid-wrapper pre.mermaid svg .actor > tspan {
  fill: var(--color-text) !important;
}

.mermaid-wrapper pre.mermaid svg .actor-line {
  stroke: var(--color-rule-fine) !important;
}

.mermaid-wrapper pre.mermaid svg .messageLine0,
.mermaid-wrapper pre.mermaid svg .messageLine1 {
  stroke: var(--color-text-3) !important;
}

.mermaid-wrapper pre.mermaid svg .messageText {
  fill: var(--color-text-2) !important;
}

.mermaid-wrapper pre.mermaid svg .marker {
  fill: var(--color-text-3) !important;
  stroke: var(--color-text-3) !important;
}

/* Fullscreen (standard + webkit) */
.mermaid-wrapper:fullscreen,
.mermaid-wrapper:-webkit-full-screen {
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  padding: var(--s6) var(--s4) var(--s4);
  border: none;
  border-radius: 0;
}

.mermaid-wrapper:fullscreen .mermaid-toolbar,
.mermaid-wrapper:-webkit-full-screen .mermaid-toolbar {
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.mermaid-wrapper:fullscreen pre.mermaid,
.mermaid-wrapper:-webkit-full-screen pre.mermaid {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
  overflow: auto;
}

.mermaid-wrapper:fullscreen pre.mermaid svg {
  max-width: 90vw;
  max-height: 85vh;
}

/* Mermaid → CSF JSON + image lightbox: shared modal shell */
.csf-overlay,
.image-zoom-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

@media (prefers-reduced-motion: reduce) {
  .csf-overlay,
  .image-zoom-overlay {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

.csf-panel,
.image-zoom-panel {
  background: var(--color-bg);
  border: 1px solid var(--color-rule-fine);
  border-radius: var(--radius-lg);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2);
}

.csf-panel {
  width: min(90vw, 48rem);
}

.image-zoom-panel {
  width: min(96vw, 56rem);
}

.csf-panel-header,
.image-zoom-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--s4) var(--s6);
  border-bottom: 1px solid var(--color-rule-fine);
  flex-shrink: 0;
  gap: var(--s4);
}

.image-zoom-panel-header .image-zoom-panel-title {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.csf-panel-title,
.image-zoom-panel-title {
  font-family: var(--mono);
  font-size: var(--size-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-3);
}

.csf-panel-actions,
.image-zoom-panel-actions {
  display: flex;
  gap: var(--s3);
}

.csf-panel-actions button,
.image-zoom-panel-actions button,
.image-zoom-panel-close {
  font-family: var(--mono);
  font-size: var(--size-micro);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-3);
  background: none;
  border: 1px solid var(--color-rule-fine);
  cursor: pointer;
  padding: var(--s1) var(--s3);
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, border-color 0.15s ease;
  min-height: 32px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.csf-panel-actions button:hover,
.image-zoom-panel-actions button:hover,
.image-zoom-panel-close:hover {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.csf-panel-actions button:focus-visible,
.image-zoom-panel-actions button:focus-visible,
.image-zoom-panel-close:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
  border-color: var(--color-accent);
}

.image-zoom-panel-body {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: var(--s5) var(--s6) var(--s6);
  flex: 1;
  min-height: 0;
}

.image-zoom-panel-img {
  max-width: 100%;
  max-height: min(75vh, 56rem);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-rule-fine);
  background: var(--color-code-bg);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
  .image-zoom-panel-img {
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
  }
}

.csf-panel-body {
  overflow: auto;
  padding: var(--s6);
}

.csf-panel-body pre {
  font-family: var(--mono);
  font-size: var(--size-sm);
  line-height: 1.65;
  color: var(--color-text);
  white-space: pre;
  margin: 0;
  tab-size: 2;
}

.csf-panel-body .json-key { color: var(--color-accent); }
.csf-panel-body .json-string { color: var(--color-text-2); }
.csf-panel-body .json-number { color: var(--color-accent); }
.csf-panel-body .json-bool { color: var(--color-accent); }
.csf-panel-body .json-null { color: var(--color-text-3); }

/* === WordPress video embeds (YouTube etc.) === */

.post-content .wp-block-embed.wp-has-aspect-ratio {
  position: relative;
  width: 100%;
  margin-block: var(--s10);
}

.post-content .wp-block-embed.wp-embed-aspect-16-9 .wp-block-embed__wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--color-code-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-rule-fine);
  overflow: hidden;
}

.post-content .wp-block-embed.wp-embed-aspect-4-3 .wp-block-embed__wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--color-code-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-rule-fine);
  overflow: hidden;
}

.post-content .wp-block-embed .wp-block-embed__wrapper .embed-youtube {
  display: block;
  position: absolute;
  inset: 0;
}

.post-content .wp-block-embed .wp-block-embed__wrapper iframe {
  width: 100% !important;
  height: 100% !important;
  position: absolute;
  inset: 0;
  border: none;
}

/* === Offsite CTA (Google Sheet — link only, no embed) === */

.post-content .offsite-cta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-block: var(--s12);
  padding: var(--s8) var(--s6);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  border: 1px solid var(--color-rule-fine);
  border-left: 3px solid var(--color-accent);
  background: var(--color-code-bg);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 1px 2px rgba(0, 0, 0, 0.04),
    0 16px 32px -10px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
  .post-content .offsite-cta {
    background: #131210;
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.05) inset,
      0 2px 4px rgba(0, 0, 0, 0.35),
      0 20px 48px -8px rgba(0, 0, 0, 0.5);
  }
}

.post-content .offsite-cta__kicker {
  margin: 0 0 var(--s2);
  font-family: var(--mono);
  font-size: var(--size-micro);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-3);
  line-height: 1.4;
  font-synthesis: none;
}

.post-content .offsite-cta__lede {
  margin: 0 0 var(--s6);
  max-width: 34rem;
  font-family: var(--serif);
  font-size: var(--size-sm);
  line-height: 1.7;
  color: var(--color-text-2);
  text-wrap: pretty;
}

.post-content a.offsite-cta__link,
.post-content .offsite-cta__link {
  width: 100%;
  min-height: 48px;
  box-sizing: border-box;
  padding: var(--s3) var(--s6);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  font-family: var(--mono);
  font-size: var(--size-xs);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  color: #faf6ef;
  background: var(--color-accent);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.12) inset;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(139, 69, 19, 0.35);
  transition: filter 0.15s ease, transform 0.15s ease;
}

.post-content a.offsite-cta__link:hover,
.post-content .offsite-cta__link:hover {
  filter: brightness(1.08);
}

.post-content a.offsite-cta__link:focus-visible,
.post-content .offsite-cta__link:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .post-content a.offsite-cta__link,
  .post-content .offsite-cta__link {
    transition: none;
  }
}

.post-content .offsite-cta__link-text {
  flex: 0 1 auto;
}

.post-content .offsite-cta__ext {
  font-size: 1.1em;
  line-height: 1;
  opacity: 0.9;
  transform: translateY(-0.04em);
}

/* === Embed cards (other external links only) === */

.post-content .embed-card {
  margin-block: var(--s12);
  margin-inline: 0;
  max-width: none;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-rule-fine);
  background: var(--color-code-bg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}

.post-content .embed-card-chrome--compact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4) var(--s6);
  padding: var(--s4) var(--s6);
  min-height: 56px;
}

.post-content .embed-card-kicker {
  font-family: var(--mono);
  font-size: var(--size-micro);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-3);
  line-height: 1.2;
  margin: 0;
}

.post-content a.embed-card-cta,
.post-content .embed-card-cta {
  font-family: var(--mono);
  font-size: var(--size-micro);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--color-text-2);
  background: var(--color-bg);
  border: 1px solid var(--color-rule-fine);
  border-radius: var(--radius-sm);
  padding: var(--s2) var(--s4);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(139, 69, 19, 0.2);
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.post-content a.embed-card-cta:hover,
.post-content .embed-card-cta:hover {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.post-content a.embed-card-cta:focus-visible,
.post-content .embed-card-cta:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}

.post-content .embed-card--link {
  box-shadow: none;
}

.post-content hr {
  border: none;
  margin-block: var(--s16);
  height: 3px;
  background: var(--color-rule);
  width: 3rem;
}

.post-content a {
  text-decoration: underline;
  text-decoration-color: var(--color-accent-line);
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
  transition: text-decoration-color 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: color-mix(in srgb, var(--color-accent) 28%, transparent);
}
.post-content a:hover { text-decoration-color: var(--color-accent); }
.post-content a:focus-visible {
  text-decoration-color: var(--color-accent);
  border-radius: var(--radius-sm);
}

/* =========================================================================
   Chapter nav
   ========================================================================= */

.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: var(--s8);
  margin-top: var(--s24);
  padding-top: var(--s10);
  border-top: 3px solid var(--color-rule);
}

.chapter-nav-link {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}
.chapter-nav-link--next { text-align: right; margin-left: auto; }

.chapter-nav-label {
  font-family: var(--mono);
  font-size: var(--size-micro);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-3);
}
.chapter-nav-title {
  font-family: var(--serif);
  font-size: var(--size-body);
  font-weight: 400;
  color: var(--color-text);
  line-height: 1.35;
  transition: color 0.15s ease;
}
.chapter-nav-link:hover .chapter-nav-title { color: var(--color-accent); }

/* =========================================================================
   Footer
   ========================================================================= */

.site-footer {
  width: 100%;
  max-width: var(--col);
  margin-inline: auto;
  padding: var(--s8) var(--gutter) var(--s12);
  font-family: var(--mono);
  font-size: var(--size-micro);
  color: var(--color-text-3);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* =========================================================================
   Motion & selection
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

::selection { background: var(--color-accent); color: var(--color-bg); }

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 768px) {
  :root {
    --size-display: 3rem;
    --size-h1: 2.25rem;
    --size-h2: 1.375rem;
    --size-chapter: 4rem;
    --gutter: 1.25rem;
  }
  .home-header { padding-top: var(--s20); }
}

@media (max-width: 480px) {
  :root {
    --size-micro: 0.6875rem; /* 11px — up from 10px for mobile legibility */
    --size-xs: 0.75rem;      /* 12px — up from 11px */
    --size-body: 1.0625rem;
    --size-display: 2.5rem;
    --size-h1: 1.875rem;
    --size-h2: 1.25rem;
    --size-lg: 1.125rem;
    --size-h3: 1.125rem;    /* 18px — still above mobile body (17px) */
    --size-chapter: 3rem;
    --gutter: 1rem;
  }
  .home-header { padding-top: var(--s12); }
  .post-header { padding-top: var(--s4); }
  .post-content > p:first-child {
    font-size: var(--size-body);
    line-height: var(--lh-body);
  }
  .post-content blockquote {
    font-size: var(--size-lg);
  }
  .chapter-nav {
    flex-direction: column;
    gap: var(--s6);
  }
  .chapter-nav-link--next { text-align: left; margin-left: 0; }
}

/* -------------------------------------------------------------------------
   Book product — same column as chapters (no full-width hero slab)
   ------------------------------------------------------------------------- */
.book-product .post-header {
  text-wrap: balance;
}

.book-product .post-header .book-product__deck {
  display: block;
  margin-top: var(--s4);
  font-family: var(--mono);
  font-size: var(--size-micro);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-3);
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}

.book-product .post-content figure.book-product__figure {
  max-width: 11rem;
  width: 100%;
  margin-inline: auto;
  margin-block: var(--s6) var(--s8);
}

.book-product .post-content figure.book-product__figure img {
  width: 100%;
}

.book-product .post-content .book-product__synopsis {
  color: var(--color-text-2);
  text-wrap: pretty;
}

.book-product .post-content .book-product__price {
  font-family: var(--mono);
  font-size: var(--size-h3);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
  letter-spacing: -0.02em;
}

.book-product .post-content .book-product__price-currency {
  font-weight: 500;
}

.book-product .post-content .book-product__vat-hint {
  font-family: var(--serif);
  font-size: var(--size-sm);
  color: var(--color-text-3);
  font-variant-numeric: normal;
  font-weight: 400;
  letter-spacing: 0;
}

.book-product .post-content .book-product__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s4);
}

.book-product .post-content .book-product__buy,
.book-product .post-content .book-product__dl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: var(--s3) var(--s8);
  font-family: var(--mono);
  font-size: var(--size-micro);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-radius: var(--radius-sm);
  text-decoration: none;
  box-sizing: border-box;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(139, 69, 19, 0.2);
  transition: filter 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
  .book-product .post-content .book-product__buy,
  .book-product .post-content .book-product__dl {
    transition: none;
  }
}

.book-product .post-content .book-product__buy {
  border: 1px solid var(--color-accent);
  color: var(--color-bg);
  background: var(--color-accent);
  box-shadow: 0 1px 0 rgba(255 255 255 / 0.12) inset;
}

.book-product .post-content .book-product__buy:hover {
  filter: brightness(1.06);
}

.book-product .post-content .book-product__dl {
  background: var(--color-bg);
  color: var(--color-text-2);
  border: 1px solid var(--color-rule-fine);
}

.book-product .post-content .book-product__dl:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.book-product .post-content .book-product__buy:focus-visible,
.book-product .post-content .book-product__dl:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}

.book-product .post-content h2.book-product__jump-target {
  scroll-margin-top: var(--s8);
}

/* -------------------------------------------------------------------------
   Offsite / embed CTAs: win over .post-content a (file order last)
   ------------------------------------------------------------------------- */
.post-content .offsite-cta a.offsite-cta__link,
.post-content .offsite-cta a.offsite-cta__link:hover,
.post-content .embed-card a.embed-card-cta,
.post-content .embed-card a.embed-card-cta:hover,
.post-content a.book-product__buy,
.post-content a.book-product__buy:hover,
.post-content a.book-product__dl,
.post-content a.book-product__dl:hover {
  text-decoration: none;
  text-underline-offset: 0;
  text-decoration-thickness: 0;
  text-decoration-skip-ink: auto;
}

.post-content .offsite-cta .offsite-cta__kicker,
.book-product .post-header .book-product__deck {
  font-family: "SF Mono", ui-monospace, "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-synthesis: none;
  font-style: normal;
}

.post-content .offsite-cta a.offsite-cta__link,
.post-content a.book-product__buy,
.post-content a.book-product__dl {
  font-family: "SF Mono", ui-monospace, "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
}
