/*
  Styles for sanitized article HTML only. Authors cannot supply a class or a stylesheet, so every
  rule here is an element selector inside .prose.

  Sharp prose: images, rules, quotes, and code blocks are square. Controls are round elsewhere.
*/

.prose {
  font-family: var(--font-article);
  font-size: var(--text-lg);
  line-height: var(--text-lg-lh);
  letter-spacing: var(--tracking-body);
  overflow-wrap: break-word;
  color: var(--fg);
}

/*
  Browser margins off for everything this file renders: vertical rhythm belongs to the flow rules
  below. :where() keeps this at zero specificity, so a per-element rule never has to fight it — an
  element rule with `margin: 0` would otherwise also cancel the centring and the spacing.
*/
.prose :where(h1, h2, h3, p, ul, ol, li, blockquote, figure, figcaption, pre, table, hr) {
  margin: 0;
}

/*
  The prose container is as wide as --measure-media; text is centred inside it at the reading
  measure, and only images take the full width. That is how a body image outgrows the column
  without negative margins, viewport maths, or colliding with the table of contents beside it.
*/
.prose > * {
  max-width: var(--measure-article);
  margin-inline: auto;
}

.prose > * + * {
  margin-top: var(--space-8);
}

/* A heading belongs to the text under it: air above, little below. No negative margins. */
.prose > * + :is(h1, h2, h3) {
  margin-top: var(--space-16);
}

.prose > :is(h1, h2, h3) + * {
  margin-top: var(--space-3);
}

.prose h1,
.prose h2,
.prose h3 {
  font-family: var(--font-article);
  font-weight: 700;
  letter-spacing: var(--tracking-title);
  scroll-margin-top: var(--space-16);
}

.prose h1 {
  font-size: var(--text-3xl);
  line-height: var(--text-3xl-lh);
}

.prose h2 {
  font-size: var(--text-2xl);
  line-height: var(--text-2xl-lh);
}

.prose h3 {
  font-size: var(--text-xl);
  line-height: var(--text-xl-lh);
  font-weight: 600;
}

.prose a {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 0.15em;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--muted);
}

.prose a:hover {
  text-decoration-color: currentColor;
  text-decoration-thickness: 2px;
}

.prose strong {
  font-weight: 600;
}

.prose ul,
.prose ol {
  padding-left: var(--space-6);
}

.prose li + li {
  margin-top: var(--space-3);
}

.prose blockquote {
  padding-left: var(--space-6);
  border-left: 3px solid var(--accent);
  font-style: italic;
  color: var(--fg);
}

.prose blockquote p + p {
  margin-top: var(--space-4);
}

/* Photography carries this reader, so a body image is allowed to outgrow the text measure. */
.prose > figure,
.prose > img,
.prose > p:has(> img:only-child) {
  max-width: none;
}

/* An image is an event in the page, so it gets more air than a paragraph break. */
.prose > figure,
.prose > p:has(> img:only-child),
.prose > figure + *,
.prose > p:has(> img:only-child) + * {
  margin-top: var(--space-16);
}

.prose img {
  display: block;
  width: 100%;
  border-radius: var(--radius-none);
  background: var(--media-wash);
  cursor: zoom-in;
}

/*
  Several photographs as one block: a centred grid on the image measure. Column count comes from
  the gallery fence (2–5). Format (landscape / portrait / square) sets the tile crop. Click opens
  the photograph at its real size in a viewer; arrows move within that gallery. Alt under a tile is
  the gallery reference.
*/
.prose > figure[data-gallery-columns] {
  display: grid;
  gap: var(--space-2);
  justify-content: center;
}

.prose > figure[data-gallery-columns="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.prose > figure[data-gallery-columns="3"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.prose > figure[data-gallery-columns="4"] {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.prose > figure[data-gallery-columns="5"] {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.prose > figure[data-gallery-columns] a {
  display: flex;
  flex-direction: column;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  cursor: zoom-in;
}

.prose > figure[data-gallery-columns] a:hover {
  text-decoration: none;
}

.prose > figure[data-gallery-columns] img {
  aspect-ratio: var(--ratio-media);
  width: 100%;
  height: auto;
  object-fit: cover;
}

.prose > figure[data-gallery-format="portrait"] img,
.prose > figure[data-gallery-format="vertical"] img {
  aspect-ratio: var(--ratio-portrait);
}

.prose > figure[data-gallery-format="square"] img {
  aspect-ratio: var(--ratio-thumb);
}

.prose > figure[data-gallery-columns] [data-gallery-ref] {
  display: block;
  margin-top: var(--space-2);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  line-height: var(--text-xs-lh);
  letter-spacing: 0;
  color: var(--muted);
  text-align: left;
  cursor: zoom-in;
}

@media (max-width: 40rem) {
  .prose > figure[data-gallery-columns="3"],
  .prose > figure[data-gallery-columns="4"],
  .prose > figure[data-gallery-columns="5"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 28rem) {
  .prose > figure[data-gallery-columns] {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Caption stays on the text measure even when the image is wider — a credit line is not a banner. */
.prose figcaption {
  max-width: var(--measure-article);
  margin: var(--space-4) auto 0;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  line-height: var(--text-xs-lh);
  letter-spacing: 0;
  color: var(--muted);
  text-align: center;
}

.prose code {
  font-family: var(--font-code, var(--font-mono));
  font-size: 0.9em;
  letter-spacing: 0;
  background: var(--bg-sunken);
  padding: 0.1em 0.3em;
  border-radius: var(--radius-control);
}

.prose pre {
  font-family: var(--font-code, var(--font-mono));
  font-size: 0.9em;
  line-height: 1.6;
  letter-spacing: 0;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-none);
  padding: var(--space-5);
  overflow-x: auto;
}

.prose pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 1em;
}

.prose table {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
  letter-spacing: 0;
  border-radius: var(--radius-none);
}

.prose th,
.prose td {
  text-align: left;
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.prose th {
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}

/* `auto` on the inline axis, or the rule drops off the reading measure like the paragraphs did. */
.prose hr {
  margin: var(--space-16) auto;
  border-top: 1px solid var(--border);
}

@media (max-width: 40rem) {
  .prose {
    font-size: var(--text-lg-narrow);
  }

  .prose h2 {
    font-size: var(--text-xl);
    line-height: var(--text-xl-lh);
  }
}
