/* The text block: a rendered markdown file (M3's Markdown model), in <article class="c-markdown">. Its children are --measure wide
   and centred; tables and code blocks may be wider, centred on it. The classes the renderer emits inside it are c-markdown__subhead,
   c-markdown__subtitle, c-markdown__table-wrap, and the components c-caps, c-extract, c-equation, c-link, c-heading-anchor, c-footnote-ref, c-footnotes, and on a
   public page c-figure and c-language-link (Page). */

.c-markdown { overflow-wrap: break-word; hanging-punctuation: first allow-end; }
.c-markdown > * { max-width: var(--measure); margin-inline: auto; }

/* Running text: justified and hyphenated, paragraphs indented with no space between them, the first after a break set flush. */
.c-markdown p { margin-block: 0; text-align: justify; hyphens: auto; text-wrap: pretty; }
.c-markdown p + p { text-indent: var(--indent); }
.c-markdown :is(li, td, th) p, .c-markdown .c-extract p + p { text-indent: 0; }

/* Everything that is not a paragraph is a break in the running text and gets one line of space around it. */
.c-markdown > :is(ul, ol, .c-extract, pre, .c-markdown__table-wrap, hr, .c-figure, .c-equation), .c-markdown > p:has(> img:only-child) { margin-block: var(--line); }
.c-markdown > :is(ul, ol, .c-extract, pre, .c-markdown__table-wrap, hr, .c-figure, .c-equation, .c-language-link) + p { text-indent: 0; }

/* Headings. The document title is centred and closed by the ornament, section heads are centred small capitals, subsections italic. */
.c-markdown :is(h1, h2, h3, h4, h5, h6) { font-weight: 400; line-height: 1.25; text-wrap: balance; hyphens: manual; scroll-margin-top: calc(var(--topbar-height) + var(--space-5)); }
.c-markdown h1 { margin-top: var(--line); margin-bottom: calc(var(--line) * 1.25); font-size: 1.75em; line-height: 1.2; text-align: center; }
/* The renderer appends a c-ornament to each h1. At 0.6em of the title it is 0.79em of the text, as in the static site; its margins
   put it where the static site's line box put it (0.35em above a 1em box with the sign centred in it). */
.c-markdown h1 > .c-ornament { margin-top: 0.475em; margin-bottom: 0.125em; font-size: 0.6em; }
.c-markdown h2 { margin-top: calc(var(--line) * 2.5); margin-bottom: var(--line); font-size: 1.1em; font-variant-caps: all-small-caps; letter-spacing: var(--tracking-caps); text-align: center; }
.c-markdown h3 { margin-top: calc(var(--line) * 1.5); margin-bottom: calc(var(--line) * 0.5); font-size: 1.05em; font-style: italic; }
.c-markdown :is(h4, h5, h6) { margin-top: var(--line); margin-bottom: 0; font-size: 1em; font-style: italic; }
.c-markdown > h1:first-child { margin-top: 0; }

/* A paragraph that is nothing but bold text is a minor heading: flush, with space above, and the paragraph after it flush. */
.c-markdown .c-markdown__subhead { margin-top: var(--line); text-indent: 0; text-align: left; hyphens: manual; }
.c-markdown > .c-markdown__subhead:first-child { margin-top: 0; }
.c-markdown .c-markdown__subhead + p { text-indent: 0; }

/* The italic line under a document's title ("In the manner of Jules Verne."): centred under the ornament, a line of space after. */
.c-markdown .c-markdown__subtitle { margin-top: calc(var(--line) * -0.5); margin-bottom: calc(var(--line) * 1.5); text-align: center; text-wrap: balance; }
.c-markdown .c-markdown__subtitle + p { text-indent: 0; }

/* Lists hang in the margin so their text lines up with the text block. */
.c-markdown :is(ul, ol) { padding-left: 1.1em; }
.c-markdown li { margin: 0.15em 0; padding-left: 0.2em; text-align: justify; hyphens: auto; }
.c-markdown li::marker { color: var(--color-ink-muted); }
.c-markdown ul > li::marker { content: '–  '; }
.c-markdown li > :is(ul, ol) { margin: 0.15em 0 0; }
.c-markdown li:has(> input[type='checkbox']) { list-style: none; }

/* A section break: three asterisms, no line. */
.c-markdown hr { height: auto; border: 0; text-align: center; }
.c-markdown hr::before { content: '⁎   ⁎   ⁎'; color: var(--color-ink-muted); white-space: pre; }

.c-markdown img { max-width: 100%; }

/* Code blocks: a quiet tint, at least as wide as the text block, wider when their lines need it. */
.c-markdown > pre { width: fit-content; min-width: min(100%, var(--measure)); max-width: 100%; padding: 0.9em 1.1em; overflow-x: auto; background: var(--color-code-background); line-height: 1.5; hyphens: none; }
.c-markdown pre code { padding: 0; background: none; font-size: 1em; overflow-wrap: normal; }
/* A display equation is never wider than the text block, so that a line too long for a phone scrolls within it (c-equation) rather than widening the page. */
.c-markdown > .c-equation { max-width: 100%; }

/* Tables: rules above and below, a hairline under the head and between rows, no vertical lines; centred, and as wide as they need. */
.c-markdown > .c-markdown__table-wrap { width: fit-content; max-width: 100%; overflow-x: auto; }
.c-markdown table { border-collapse: collapse; border-block: var(--stroke-table) solid var(--color-ink); font-size: 0.8em; line-height: 1.35; font-variant-numeric: lining-nums tabular-nums; }
.c-markdown :is(th, td) { padding: 0.45em 0.8em; text-align: left; vertical-align: top; hyphens: auto; }
.c-markdown th { border-bottom: var(--stroke-hair) solid var(--color-ink); font-weight: 600; }
.c-markdown tbody tr + tr td { border-top: var(--stroke-hair) solid var(--color-rule-faint); }
.c-markdown :is(th, td):first-child { padding-left: 0.2em; }
.c-markdown :is(th, td):last-child { padding-right: 0.2em; }

/* The line a search result opened (M6): tinted, with the tint spread a little beyond the text. */
.c-markdown .is-search-target { background: var(--color-target); box-shadow: 0 0 0 0.35em var(--color-target); scroll-margin-top: calc(var(--topbar-height) + var(--space-5)); }

/* A phone is too narrow to justify without wide gaps between words. */
@media (max-width: 36rem) {
  .c-markdown :is(p, li) { text-align: left; }
}
