/* ==========================================================================
   westie.blog — article typography. Loaded on post pages only.
   Everything is scoped to .prose (the rendered Markdown in post.njk) and
   uses the variables from base.css.

   Order: text · headings · lists · quotes · tables · figures · code · maths
   ========================================================================== */

/* === Text =============================================================== */

/* No max-width here: the text is exactly as wide as the page column
   (--measure in base.css), so it lines up with the header and footer. */
.prose {
  font-size: var(--fs-prose);
  line-height: 1.8;
  overflow-wrap: break-word; /* long URLs never widen the page */
}

/* Latin letters need a slightly larger size than full-width Chinese glyphs. */
html[lang="en"] .prose {
  font-size: var(--fs-prose-en);
  line-height: 1.7;
}

/* Chinese punctuation and mixed-script spacing. */
.prose:lang(zh) {
  /* Punctuation never starts a line */
  line-break: strict;
  /* A thin gap between Chinese and Latin/digits, where the browser supports
     it (ignored elsewhere; spaces typed by hand are left as they are). */
  text-autospace: normal;
}

.prose p {
  margin: 0 0 1.1em;
}

/* Chinese paragraphs are justified: with full-width characters the extra
   space is spread between characters, so lines do not show the "rivers"
   that justified English gets. English stays ragged-right. */
.prose:lang(zh) p,
.prose:lang(zh) li {
  text-align: justify;
  text-justify: inter-character;
}

/* Links in running text are underlined: colour alone is not enough to
   tell them from the surrounding text (WCAG 1.4.1). */
.prose a {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}
.prose a:hover {
  text-decoration-thickness: 2px;
}

.prose strong {
  color: var(--color-name);
  font-weight: 700;
}

.prose hr {
  margin: 2.2em 0;
  border: 0;
  border-top: 1px dashed var(--color-rule);
}

.prose > :last-child {
  margin-bottom: 0;
}

/* === Headings =========================================================== */

/* Dark red h2s provide emphasis without the page-level title's hairline.
   Smaller blue-grey h3s form the next level down. */
.prose h2 {
  margin: 2em 0 0.5em;
  color: var(--color-accent);
  border-bottom: none;
  font-size: var(--fs-prose-h2);
  font-weight: 700;
  line-height: 1.4;
}

.prose h3 {
  margin: 1.6em 0 0.4em;
  color: var(--color-name);
  font-size: var(--fs-prose-h3);
  font-weight: 700;
  line-height: 1.4;
}

.prose h2,
.prose h3 {
  text-align: left;
  scroll-margin-top: var(--space-16); /* breathing room when jumped to from the TOC */
}

/* "#" permalink after h2/h3: hidden until the heading is hovered or the
   link is focused. Touch screens have no hover, so there it stays visible. */
.heading-anchor {
  margin-left: 0.2em;
  color: var(--color-muted);
  font-weight: 400;
  text-decoration: none !important;
  opacity: 0;
}
.prose h2:hover .heading-anchor,
.prose h3:hover .heading-anchor,
.heading-anchor:focus-visible {
  opacity: 1;
}
@media (hover: none) {
  .heading-anchor {
    opacity: 0.6;
  }
}

/* === Lists ============================================================== */

.prose ul,
.prose ol {
  margin: 0 0 1.15em;
  padding-left: 1.5em;
}
.prose ul {
  list-style: disc;
}
.prose ol {
  list-style: decimal;
}
.prose li {
  margin: 0.25em 0;
}
.prose li::marker {
  color: var(--color-muted);
}
.prose li > ul,
.prose li > ol {
  margin: 0.25em 0;
}

/* === Quotes ============================================================= */

.prose blockquote {
  margin: 1.5em 0;
  padding: 0 0 0 1em;
  border-left: 3px solid var(--color-accent);
  color: var(--color-muted);
}
.prose blockquote p:last-child {
  margin-bottom: 0;
}

/* === Tables ============================================================= */

/* display: block lets a wide table scroll sideways inside the column
   instead of stretching the page. */
.prose table {
  display: block;
  max-width: 100%;
  margin: 1.5em 0;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.92em;
  line-height: 1.5;
}
.prose th,
.prose td {
  padding: var(--space-6) var(--space-14) var(--space-6) 0;
  text-align: left;
  vertical-align: top;
}
.prose th {
  border-bottom: 1px solid var(--color-muted);
  color: var(--color-name);
  font-weight: 700;
  white-space: nowrap;
}
.prose td {
  border-bottom: 1px dashed var(--color-rule);
}

/* === Images and figures ================================================= */

.prose img {
  display: block;
  margin: 0 auto;
}

/* ![alt](file.png "caption") -> <figure> with <figcaption> */
.prose figure {
  margin: 1.8em 0;
}
.prose figure img {
  border: 1px solid var(--color-rule);
}
.prose figcaption {
  margin-top: var(--space-8);
  color: var(--color-muted);
  font-size: 0.85em;
  line-height: 1.5;
  text-align: center;
}

/* === Code =============================================================== */
/* Colours of the highlighted tokens are in highlight.css. */

/* (Font and ligature settings for code are in base.css.) */
.prose code {
  font-size: 0.86em;
}

/* Inline code */
.prose :not(pre) > code {
  padding: 0.1em 0.35em;
  background: var(--color-code-bg);
  overflow-wrap: anywhere;
}

/* Code block: scrolls sideways, never wraps */
.prose pre {
  margin: 1.5em 0;
  padding: var(--space-14) var(--space-16);
  overflow-x: auto;
  background: var(--color-code-bg);
  border: 1px solid var(--color-rule);
  font-size: var(--fs-code-block);
  line-height: 1.6;
  text-align: left;
  tab-size: 4;
}
.prose pre code {
  font-size: inherit;
}

/* === Maths (KaTeX) ====================================================== */

.prose .katex {
  font-size: 1.08em;
}

/* Block formulas wider than the column scroll sideways */
.prose .katex-block {
  margin: 1.4em 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: var(--space-2) 0;
  text-align: center;
}
.prose .katex-block > .katex-display {
  margin: 0;
}

/* === Narrow screens (≤ 640px) =========================================== */

@media (max-width: 640px) {
  .prose pre {
    /* Let code blocks use the full screen width */
    margin-left: calc(-1 * var(--gutter));
    margin-right: calc(-1 * var(--gutter));
    padding: var(--space-12) var(--gutter);
    border-left: 0;
    border-right: 0;
  }
  .prose ul,
  .prose ol {
    padding-left: 1.25em;
  }
}
