:root {
  --fg: #1a1a1a;
  --muted: #6b7280;
  --accent: #2563eb;
  --border: #e5e7eb;
  --pending-bg: #fffbeb;
  --pending-border: #fcd34d;

  /* Serif reading face for prose; sans for UI chrome and headings. Both are
     system stacks — no web-font request, no FOUT. Charter ships on macOS/iOS,
     Sitka on Windows, Georgia/Cambria as the universal fallback. */
  --font-serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--fg);
  margin: 0;
  background: #fff;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Headings run in the sans face for editorial contrast against serif prose. */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  line-height: 1.15;
  text-wrap: balance;               /* avoid lonely last-line words */
}

/* Book layout: collapsible sidebar + readable main column. */
.book {
  margin: 0;                                       /* top-left, not centered */
  padding: 1.5rem 1.25rem 4rem;
  display: grid;
  grid-template-columns: minmax(0, 40rem) 15rem;   /* content | contents — just two columns */
  gap: 2.5rem;
  align-items: start;
}

/* ~40rem holds the prose to a comfortable ~68-char measure for the serif face. */
.post { grid-column: 1; grid-row: 1; max-width: 40rem; min-width: 0; }

/* UI chrome stays in the sans face; only the article prose is serif. */
.sidebar, .pager, .site-footer, .meta, .comment-head, .comment-badge,
.comment-form, .leave-comment, .comment-form-status {
  font-family: var(--font-sans);
}
.sidebar { font-size: .9375rem; }

@media (max-width: 64rem) {
  /* Flex (not grid) so the desktop `grid-column` rules can't re-position items. */
  .book {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1.25rem;
  }
  .post { width: 100%; align-self: center; }   /* full-width, capped + centered */
}

a {
  color: var(--accent);
  text-underline-offset: 0.15em;
  text-decoration-thickness: 0.08em;
}

/* Article prose: larger, looser reading rhythm and old-style figures. */
.content {
  font-size: 1.125rem;
  line-height: 1.6;
  font-variant-numeric: oldstyle-nums proportional-nums;
}
.content > :first-child { margin-top: 0; }
.content p { text-wrap: pretty; }                  /* even ragged edge, no orphans */

/* Modular type scale (~1.25). Headings get more space above than below so a
   heading binds to the text it introduces. */
.post header h1 { font-size: 2.25rem; margin: 0 0 1.5rem; letter-spacing: -0.01em; }
/* When `page_title` overrides the heading, the post's own title sits under it. */
.post header h1:has(+ .post-title) { margin-bottom: .4rem; }
.post header .post-title {
  font-size: 1.35rem;
  font-weight: 500;
  color: var(--muted);
  margin: 0 0 1.5rem;
}
.content h2 { font-size: 1.55rem; margin: 2.5rem 0 .6rem; }
.content h3 { font-size: 1.25rem; margin: 1.9rem 0 .5rem; }
.content h4 { font-size: 1.05rem; margin: 1.6rem 0 .4rem; }

.content blockquote {
  margin: 1.5rem 0;
  padding: .2rem 0 .2rem 1.25rem;
  border-left: 3px solid var(--border);
  color: var(--muted);
  font-style: italic;
}
.content blockquote > :first-child { margin-top: 0; }
.content blockquote > :last-child { margin-bottom: 0; }

/* Sidebar / table of contents — right rail on desktop, sticky banner on mobile */
.sidebar { grid-column: 2; grid-row: 1; position: sticky; top: 1.5rem; }
.sidebar-toggle {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
}
.sidebar-toggle > summary {
  cursor: pointer;
  padding: .55rem .8rem;
  font-weight: 600;
  list-style: none;
}
.sidebar-toggle > summary::-webkit-details-marker { display: none; }
.sidebar-toggle > summary::before { content: "\25B8  "; color: var(--muted); }
.sidebar-toggle[open] > summary::before { content: "\25BE  "; }
.toc { padding: 0 .5rem .5rem; }

/* Desktop: open by default (via the `open` attribute); the summary reads as a
   static heading rather than a toggle. */
@media (min-width: 64.01rem) {
  .sidebar-toggle > summary { cursor: default; }
  .sidebar-toggle > summary::before { content: ""; }
}
.toc ol { margin: 0; padding-left: 1.5rem; }
.toc li { padding: .15rem 0; }
.toc li.is-current > a { font-weight: 700; color: var(--fg); text-decoration: none; }

/* Mobile: the contents is a full-width sticky banner; tapping it drops the
   table of contents down as an overlay panel instead of pushing the article. */
@media (max-width: 64rem) {
  .sidebar {
    position: sticky;              /* containing block is the tall .book grid */
    top: 0;
    z-index: 20;
    margin: -1.5rem -1.25rem 0;    /* full-bleed past .book's padding */
  }
  .sidebar-toggle {
    position: relative;            /* anchor for the drop-down panel */
    border-width: 0 0 1px;
    border-radius: 0;
    background: #fff;
  }
  .sidebar-toggle > summary {
    padding: .85rem 1.25rem;
  }
  .sidebar-toggle > .toc {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    margin: 0;
    padding: .5rem 1.25rem 1rem;
    background: #fff;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 16px rgba(0, 0, 0, .12);
    max-height: 70vh;
    overflow-y: auto;
  }
}

/* Site footer (blog description + author byline) */
.site-footer {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .875rem;
}
.site-footer p { margin: .2rem 0; }
.footer-byline { font-style: italic; }

/* Prev / next pager */
.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}
.pager a {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  text-decoration: none;
  max-width: 48%;
}
.pager-next { margin-left: auto; text-align: right; }
.pager-label { font-size: .8rem; color: var(--muted); }
.pager-title { font-weight: 600; }

.meta, .comment-date { color: var(--muted); font-size: .875rem; }

/* Images are centered standalone figures by default. Tag an image in Markdown
   to override: ![alt](file){.left}, {.right}, {.float-left}, or {.float-right}. */
.content img { display: block; max-width: 100%; height: auto; margin-inline: auto; }
.content img.left  { margin-inline: 0 auto; }
.content img.right { margin-inline: auto 0; }
.content img.float-left  { float: left;  max-width: 50%; margin: .3rem 1.25rem .6rem 0; }
.content img.float-right { float: right; max-width: 50%; margin: .3rem 0 .6rem 1.25rem; }

/* Animated GIF/WebP: static poster by default; anim-player.js autoplays once
   when fully scrolled into view and adds a play/stop control. Clicking the
   image toggles too. Before JS runs, it's just a centered still. */
.content .anim-player-wrap { position: relative; display: block; width: fit-content; max-width: 100%; margin-inline: auto; }
.content .anim-player-wrap img { display: block; margin: 0; cursor: pointer; }
.anim-toggle {
  position: absolute;
  left: .55rem;
  bottom: .55rem;                    /* lower-left corner */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0 0 0 .1em;               /* optical-center the ▶ glyph */
  font-family: var(--font-sans);
  font-size: .95rem;
  color: #fff;
  background: rgba(0, 0, 0, .5);
  border: 1.5px solid rgba(255, 255, 255, .85);
  border-radius: 999px;
  cursor: pointer;
  opacity: 0;                        /* hidden until hover (or keyboard focus) */
  transition: opacity .15s ease, background .15s ease;
}
.anim-player-wrap:hover .anim-toggle { opacity: 1; }
.anim-toggle:hover { background: rgba(0, 0, 0, .7); }
.anim-toggle:focus-visible { opacity: 1; outline: 3px solid var(--accent); outline-offset: 2px; }

.content pre {
  background: #f6f8fa;
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
}
.content code { background: #f6f8fa; padding: .1em .3em; border-radius: 4px; }
.content pre code { background: none; padding: 0; }

.content table { border-collapse: collapse; font-variant-numeric: tabular-nums lining-nums; }
.content th, .content td { border: 1px solid var(--border); padding: .4rem .6rem; }

.post-index { list-style: none; padding: 0; }
.post-index li { padding: .4rem 0; border-bottom: 1px solid var(--border); }

/* Comments */
.comments { margin-top: 3rem; border-top: 2px solid var(--border); padding-top: 1.5rem; }
.comment {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem 1rem;
  margin: .75rem 0;
}
.comment--pending {
  background: var(--pending-bg);
  border-color: var(--pending-border);
}
.comment-head { display: flex; align-items: baseline; gap: .5rem; margin-bottom: .35rem; }
.comment-author { font-weight: 600; }
.comment-badge {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: var(--pending-border);
  color: #7c5e00;
  padding: .1rem .45rem;
  border-radius: 999px;
}
.comment-body > :first-child { margin-top: 0; }
.comment-body > :last-child { margin-bottom: 0; }

/* Collapsed (no comments): just a button that reveals the form. */
.comments-empty { border: 0; }
.leave-comment {
  display: inline-block;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border-radius: 6px;
  padding: .55rem 1.1rem;
  list-style: none;
}
.leave-comment::-webkit-details-marker { display: none; }
.comments-empty[open] > .leave-comment { margin-bottom: 1.25rem; }

/* Form */
.comment-form { margin-top: 2rem; display: grid; gap: .75rem; }
/* Honeypot: pull it off-screen rather than display:none, which bots skip. */
.cf-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.comment-form label { display: grid; gap: .3rem; font-weight: 600; }
.comment-form .hint, .form-note { font-weight: 400; color: var(--muted); font-size: .875rem; }
.comment-form input, .comment-form textarea {
  font: inherit;
  padding: .5rem .6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.comment-form button {
  justify-self: start;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  padding: .55rem 1.1rem;
  cursor: pointer;
}
.comment-form button:disabled { opacity: .6; cursor: default; }
.comment-form-status { min-height: 1.2em; font-size: .9rem; margin: 0; }
.comment-form-status.is-error { color: #b91c1c; }
.comment-form-status.is-ok { color: #15803d; }
