/* Single post (templates/single.html), loaded only on posts.
   A neo-brutalist frame (back link, tags, title, hero, Older/Newer cards) around a quiet
   reading column: Atkinson Hyperlegible Next at ~23px (19px on mobile; its x-height is ~4% lower than Plex), ~65-70 characters per line, near-black text and
   sentence-case headings. Code, images and embeds may run wider than the text. */
.post-single {
  --read: 44rem;
  --read-wide: 52rem;
  --font-read: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-code: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --text: color-mix(in srgb, var(--fg) 88%, var(--bg));
}
.post-single > * { margin-block: 0; }

/* Frame */
.post-back { font-family: var(--font-mono); font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; }
.post-back a { text-decoration: underline; text-decoration-color: var(--lime); text-decoration-thickness: 3px; text-underline-offset: 3px; }
.post-back a:hover { background: var(--lime); color: #000; }
.post-single .post-meta { gap: 0.5rem; align-items: center; margin-top: 2rem; font-family: var(--font-mono); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.post-meta .wp-block-post-date { font-weight: 700; }
.post-meta .wp-block-post-terms { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.post-meta .wp-block-post-terms a { padding: 0.1rem 0.45rem; border: var(--bw-sm) solid #000; background: var(--lime); color: #000; font-weight: 700; }
.post-meta .wp-block-post-terms__separator { display: none; }
.post-single .post-heading { max-width: 22ch; margin-top: 0.75rem; font-size: clamp(2.2rem, 1.4rem + 3.4vw, 4rem); line-height: 0.98; }
.post-single .post-hero { max-width: var(--read-wide); margin-top: 1.75rem; border: var(--bw) solid var(--line); box-shadow: var(--shadow); background: #111; }
.post-single .post-hero img { display: block; }

/* Reading column */
.post-body {
  max-width: var(--read-wide);
  margin-top: 3rem;
  color: var(--text);
  font-family: var(--font-read);
  font-size: clamp(1.1875rem, 1.07rem + 0.6vw, 1.4375rem);
  line-height: 1.65;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}
.post-body > * { max-width: var(--read); margin-block: 0 1.25em; }
.post-body > :is(.wp-block-image, .wp-block-gallery, .wp-block-embed, .wp-block-video, .wp-block-code, .wp-block-preformatted, .wp-block-kevinbatdorf-code-block-pro, .wp-block-table, .wp-block-telex-block-mermaid-diagram, .wp-block-merpress-mermaidjs, .wp-block-columns) { max-width: var(--read-wide); margin-block: 1.75em; }
.post-body :is(strong, b) { font-weight: 600; color: var(--fg); }
.post-body em { font-style: italic; }

.post-body :is(h2, h3, h4) {
  color: var(--fg);
  font-family: var(--font-sans);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.2;
  text-transform: none;
  text-wrap: balance;
  scroll-margin-top: 1.5rem;
}
.post-body h2 { margin: 2.1em 0 0.6em; font-size: clamp(1.625rem, 1.35rem + 1.1vw, 2.125rem); }
.post-body h3 { margin: 2em 0 0.5em; font-size: clamp(1.3125rem, 1.15rem + 0.6vw, 1.625rem); }
.post-body h4 { margin: 1.75em 0 0.4em; font-size: 1em; }
.post-body > :first-child { margin-top: 0; }
.post-body :is(h2, h3, h4) + * { margin-top: 0; }
.post-single .post-body :is(h2, h3, h4) code { padding: 0; background: none; font-size: 0.92em; font-weight: 700; }

.post-body a { color: var(--fg); text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 0.18em; text-decoration-color: color-mix(in srgb, var(--fg) 40%, transparent); transition: background-color 0.12s ease, text-decoration-color 0.12s ease; }
.post-body a:hover { background: var(--lime); color: #000; text-decoration-color: #000; }

.post-body :is(ul, ol) { padding-left: 1.3em; }
.post-body li { padding-left: 0.2em; }
.post-body li + li { margin-top: 0.4em; }
.post-body li > :is(ul, ol) { margin: 0.4em 0 0; }
.post-body li::marker { color: var(--fg-soft); }

/* Inline code: a quiet tint, sized to sit on the serif's x-height */
.post-body :not(pre) > code { padding: 0.08em 0.32em; background: color-mix(in srgb, var(--fg) 7%, transparent); color: var(--fg); font-family: var(--font-code); font-size: 0.8em; overflow-wrap: anywhere; }

/* Code blocks */
.post-body pre.wp-block-code,
.post-body pre.wp-block-preformatted { padding: 1.1rem 1.25rem; border: var(--bw) solid var(--line); background: #1e1e1e; color: #e8e8e3; box-shadow: var(--shadow); overflow-x: auto; font-family: var(--font-code); font-size: 16px; line-height: 1.6; }
.post-body pre code { padding: 0; background: none; color: inherit; font-size: inherit; }
.post-body .wp-block-kevinbatdorf-code-block-pro { border: var(--bw) solid var(--line); box-shadow: var(--shadow); font-size: 16px !important; line-height: 1.6 !important; }
.post-body .wp-block-kevinbatdorf-code-block-pro pre { margin: 0; padding: 1.1rem 1.25rem !important; }

/* Media */
.post-body :is(.wp-block-image, .wp-block-gallery) img { border: var(--bw) solid var(--line); box-shadow: var(--shadow); }
.post-body figcaption { margin-top: 0.7rem; color: var(--fg-soft); font-size: 0.85em; font-style: italic; text-align: left; }
.post-body .wp-block-embed iframe { max-width: 100%; border: var(--bw) solid var(--line); box-shadow: var(--shadow); }

/* Quotes, callouts, details, tables, rules */
.post-body .wp-block-quote { margin-inline: 0; padding: 0.1rem 0 0.1rem 1.25rem; border-left: 4px solid var(--lime); font-style: italic; }
.post-body .wp-block-quote > :last-child { margin-bottom: 0; }
/* Boxes with their own background: the theme tags them by how dark the background is (functions.php),
   and each redefines the text tokens inside, so inline code, links and markers stay readable in dark mode. */
.post-body .is-bg-light { --fg: #111; --fg-soft: #3d3d3d; --text: #1a1a1a; }
.post-body .is-bg-light:not(.has-text-color) { color: #1a1a1a; }
.post-body .is-bg-dark { --fg: #f5f5f0; --fg-soft: #c4c4bc; --text: #ecece6; }
.post-body .is-bg-dark:not(.has-text-color) { color: #ecece6; }
.post-body .wp-block-roelmagdaleno-callout-block { padding: 1.1rem 1.3rem; border: var(--bw) solid var(--line); box-shadow: var(--shadow); font-size: 0.95em; }
.post-body .wp-block-roelmagdaleno-callout-block a { color: inherit; }
.post-body .wp-block-roelmagdaleno-callout-block p { margin: 0; }
.post-body .wp-block-roelmagdaleno-callout-block p + p { margin-top: 0.75em; }
.post-body .has-background:not(.wp-block-roelmagdaleno-callout-block) { padding: 1rem 1.2rem; border: var(--bw-sm) solid var(--line); }
.post-body .wp-block-table { overflow-x: auto; }
.post-body .wp-block-table table { width: 100%; border-collapse: collapse; font-family: var(--font-sans); font-size: 15px; line-height: 1.45; }
.post-body .wp-block-table :is(th, td) { padding: 0.55rem 0.75rem; border: var(--bw-sm) solid var(--line); text-align: left; vertical-align: top; }
.post-body .wp-block-table th { background: var(--lime); color: #000; }
.post-body .wp-block-details { padding: 0.8rem 1.1rem; border: var(--bw-sm) solid var(--line); background: var(--card); }
.post-body .wp-block-details summary { cursor: pointer; font-family: var(--font-sans); font-weight: 700; }
.post-body hr.wp-block-separator { width: 6rem; margin: 3em 0; border: 0; border-top: var(--bw) solid var(--line); opacity: 1; }

/* After the post */
.post-single .post-tags { max-width: var(--read-wide); margin-top: 3.5rem; padding-top: 1.25rem; border-top: var(--bw) solid var(--line); color: var(--fg-soft); font-family: var(--font-mono); font-size: 12px; text-transform: uppercase; }
.post-tags a { display: inline-block; margin: 0.15rem 0; padding: 0 0.35rem; border: 1px solid var(--line); color: var(--fg); }
.post-tags a:hover { background: var(--lime); color: #000; }
.post-tags .wp-block-post-terms__separator { display: none; }
.post-single .post-engage { max-width: var(--read-wide); margin-top: 2rem; }
.post-engage .post-engage-title { margin: 1.5rem 0 0.75rem; font-size: 1rem; text-transform: uppercase; }
.post-engage .post-engage-title:first-child { margin-top: 0; }
.post-engage .wp-block-jetpack-sharing-buttons { margin: 0; gap: 0.5rem; }
.post-single .post-nav { max-width: var(--read-wide); margin-top: 1.5rem; gap: 1rem; }
.post-nav > * { position: relative; display: flex; flex: 1 1 16rem; gap: 0.6rem; align-items: baseline; margin: 0; padding: 0.8rem 1rem; border: var(--bw) solid var(--line); background: var(--card); box-shadow: var(--shadow); font-weight: 600; line-height: 1.35; transition: transform 0.12s ease, box-shadow 0.12s ease; }
.post-nav > *:hover { transform: translate(-2px, -2px); box-shadow: 8px 8px 0 var(--line); }
.post-nav a::after { content: ""; position: absolute; inset: 0; }
.post-nav .post-navigation-link-next { flex-direction: row-reverse; text-align: right; }
.post-nav [class*="__arrow"] { font-family: var(--font-mono); }

@media (prefers-reduced-motion: reduce) {
  .post-nav > *, .post-body a { transition: none; }
  .post-nav > *:hover { transform: none; }
}

/* Table of contents (inc/toc.php + assets/post-toc.js).
   A card before the first section; once it scrolls away, a floating copy marks the
   section being read in bold: a column right of the text on wide screens (>=1300px),
   a corner button that opens the list everywhere else. Hand-written TOCs are hidden. */
.post-body .jmg-manual-toc { display: none; }
.post-body { position: relative; }
@media (prefers-reduced-motion: no-preference) { html:has(.jmg-toc) { scroll-behavior: smooth; } }

.jmg-toc ol, .jmg-toc-float ol { margin: 0; padding: 0; list-style: none; }
.jmg-toc a, .jmg-toc-float a { display: flex; gap: 0.6em; color: inherit; text-decoration: none; }
.jmg-toc__title {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.jmg-toc__num { flex: none; min-width: 2ch; font-family: var(--font-mono); font-size: 0.8em; font-weight: 700; line-height: inherit; color: var(--fg-soft); padding-top: 0.12em; }
.jmg-toc .is-active, .jmg-toc-float .is-active { font-weight: 700; color: var(--fg); }

/* The card */
.post-body > .jmg-toc {
  margin-block: 2.25em 2.5em;
  border: var(--bw) solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
  font-family: var(--font-sans);
  font-size: 0.82em;
  line-height: 1.35;
}
.jmg-toc > .jmg-toc__title { padding: 0.65rem 1.1rem; border-bottom: var(--bw) solid var(--line); background: var(--yellow); color: #000; }
.jmg-toc > .jmg-toc__list { padding: 1rem 1.1rem 1.15rem; }
.jmg-toc .is-h2 + .is-h2 { margin-top: 0.55rem; }
.jmg-toc .is-h2 > a { font-weight: 700; color: var(--fg); }
.jmg-toc .jmg-toc__sub { margin: 0.3rem 0 0 calc(2ch + 0.6em + 0.15em); padding-left: 0.85rem; border-left: var(--bw-sm) solid var(--line); }
.jmg-toc .is-h3 { font-size: 0.92em; color: var(--fg-soft); }
.jmg-toc .is-h3 + .is-h3 { margin-top: 0.2rem; }
/* Hover: the site's link highlight (lime block, black text) in every mode, numbers included. */
.post-body .jmg-toc a, .post-body .jmg-toc-float a { padding-inline: 0.3em; margin-inline: -0.3em; }
.post-body .jmg-toc-float .jmg-toc__list a { padding-left: 0.6rem; margin-left: 0; }
.post-body :is(.jmg-toc, .jmg-toc-float) a:hover,
.post-body :is(.jmg-toc, .jmg-toc-float) a:hover .jmg-toc__num { background: var(--lime); color: #000; text-decoration: none; }
.post-body .jmg-toc-float .jmg-toc__list a.is-active:hover { border-left-color: #000; }

/* Floating copy: shared */
.jmg-toc-float { font-family: var(--font-sans); font-size: 14px; line-height: 1.35; opacity: 0; visibility: hidden; transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s; }
.jmg-toc-float.is-shown { opacity: 1; visibility: visible; }
.jmg-toc-float .jmg-toc__title { padding-bottom: 0.6rem; margin-bottom: 0.6rem; border-bottom: var(--bw-sm) solid var(--line); }
.jmg-toc-float .jmg-toc__list a { padding: 0.28rem 0 0.28rem 0.6rem; border-left: 3px solid transparent; color: var(--fg-soft); }
.jmg-toc-float .jmg-toc__list a.is-active { border-left-color: var(--fg); color: var(--fg); font-weight: 700; }
.jmg-toc-float .has-active > a .jmg-toc__num { color: var(--fg); }
.jmg-toc-float .jmg-toc__sub { padding-left: calc(2ch + 0.6em); }
.jmg-toc-float .is-h3 { font-size: 13px; }

/* Floating copy: corner button + panel (below 1300px) */
.jmg-toc-float {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  width: min(22rem, calc(100vw - 2rem));
  transform: translateY(0.5rem);
}
.jmg-toc-float.is-shown { transform: none; }
.jmg-toc-float__toggle {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  max-width: 100%;
  padding: 0.5rem 0.85rem;
  border: var(--bw) solid #000;
  background: var(--yellow);
  box-shadow: 4px 4px 0 #000;
  color: #000;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.jmg-toc-float__toggle:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 #000; }
.jmg-toc-float__toggle:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 #000; }
.jmg-toc-float__kicker { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.jmg-toc-float__kicker::after { content: " ▴"; }
.jmg-toc-float.is-open .jmg-toc-float__kicker::after { content: " ▾"; }
.jmg-toc-float__current { max-width: 100%; overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.jmg-toc-float__current:empty { display: none; }
.jmg-toc-float__panel {
  display: none;
  order: -1;
  width: 100%;
  max-height: min(60vh, 32rem);
  margin-bottom: 0.75rem;
  padding: 0.9rem 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: var(--bw) solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
}
.jmg-toc-float.is-open .jmg-toc-float__panel { display: block; }

/* Floating copy: column right of the text (1300px and up) */
@media (min-width: 81.25rem) {
  .jmg-toc-float {
    position: absolute;
    top: 0;
    right: auto;
    bottom: 0;
    left: calc(100% + 2.5rem);
    display: block;
    width: min(18rem, calc(50vw - 25.5rem));
    transform: translateX(0.5rem);
  }
  .jmg-toc-float__toggle { display: none; }
  .jmg-toc-float__panel {
    position: sticky;
    top: 2rem;
    display: block;
    max-height: calc(100vh - 4rem);
    margin: 0;
    padding: 0 0.25rem 0 0;
    border: 0;
    background: none;
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .jmg-toc-float, .jmg-toc-float__toggle { transition: none; transform: none; }
}
