/* nevis content stylesheet
 *
 * The CSS for article HTML produced by the API. Served at /nevis-content.css so
 * that the admin preview and a published article are styled by the same file:
 * "what the editor sees" and "what the reader sees" are then the same thing by
 * construction rather than by two teams keeping two stylesheets in step.
 *
 * A site includes it with one link and overrides whatever it likes — everything
 * here is a single class selector, so any site rule wins on specificity alone.
 *
 * Scope: wrap article HTML in an element carrying .prose-fa.
 */

.prose-fa {
  /* Persian needs more leading than Latin, and tracking breaks cursive joins —
   * letter-spacing on Persian is a legibility bug, not a style choice. */
  line-height: 1.9;
  letter-spacing: 0;
  text-align: start;
  overflow-wrap: break-word;

  /* The article responds to its own column, not to the browser window.
   *
   * A viewport media query is the wrong question to ask here. The same article
   * HTML is rendered in a full-width page, in a two-column layout beside a
   * sidebar, and inside the admin's device preview — and in the last two the
   * window is wide while the column is narrow. A viewport query would leave
   * eight steps of indentation in a 390px column on a 4K monitor.
   *
   * Declaring the containment costs a site nothing: it applies to this element
   * only, and a site that does not use container queries never notices. */
  container-type: inline-size;
  container-name: nevis-article;
}

.prose-fa :is(h1, h2, h3, h4) {
  line-height: 1.5;
  margin-block: 1.6em 0.6em;
}

.prose-fa p {
  margin-block: 0 1em;
}

/* ── Lists ────────────────────────────────────────────────────────────────── */

.prose-fa :is(ul, ol) {
  /* Logical, so the markers sit on the correct side in both directions without
   * anything needing to be mirrored. */
  padding-inline-start: 1.6em;
  padding-inline-end: 0;
  margin-block: 0 1em;
}

/* Persian numerals come from the predefined CSS counter style rather than from
 * digits written into the markup: numbering stays correct when a list is
 * reordered, and a screen reader still announces item numbers as numbers. */
.prose-fa ol.nevis-ol-fa {
  list-style-type: persian;
}

/* A list explicitly flipped to LTR holds English or code, where ۱ reads worse
 * than 1. */
.prose-fa ol[dir='ltr'] {
  list-style-type: decimal;
}

/* ── Indentation ──────────────────────────────────────────────────────────── */

/* Emitted as classes so the document carries no inline styles and the value can
 * only ever be one of these eight steps. margin-inline-start indents from the
 * right in RTL and from the left in LTR with no per-direction rule. */
.prose-fa .nevis-indent-1 { margin-inline-start: 2em; }
.prose-fa .nevis-indent-2 { margin-inline-start: 4em; }
.prose-fa .nevis-indent-3 { margin-inline-start: 6em; }
.prose-fa .nevis-indent-4 { margin-inline-start: 8em; }
.prose-fa .nevis-indent-5 { margin-inline-start: 10em; }
.prose-fa .nevis-indent-6 { margin-inline-start: 12em; }
.prose-fa .nevis-indent-7 { margin-inline-start: 14em; }
.prose-fa .nevis-indent-8 { margin-inline-start: 16em; }

/* ── Code ─────────────────────────────────────────────────────────────────── */

.prose-fa :is(pre, code) {
  /* @noflip — code is Latin and must not be mirrored. */
  direction: ltr;
  text-align: left;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.prose-fa pre {
  overflow-x: auto;
  padding: 1em;
  border-radius: 8px;
  background: rgba(127, 127, 127, 0.12);
}

.prose-fa blockquote {
  margin-inline: 0;
  padding-inline-start: 1em;
  border-inline-start: 3px solid rgba(127, 127, 127, 0.4);
  color: inherit;
  opacity: 0.9;
}

/* ── Media ────────────────────────────────────────────────────────────────── */

.prose-fa :is(img, video, audio, iframe) {
  max-width: 100%;
}

.prose-fa :is(img, video) {
  height: auto;
}

.prose-fa figure {
  margin-inline: 0;
  margin-block: 1.5em;
}

.prose-fa figcaption {
  margin-block-start: 0.5em;
  font-size: 0.875em;
  opacity: 0.75;
  text-align: center;
}

.prose-fa .nevis-video video,
.prose-fa .nevis-audio audio {
  width: 100%;
  border-radius: 8px;
}

/* An embedded player has no intrinsic size, so it needs an explicit aspect
 * ratio or it collapses to nothing. */
.prose-fa .nevis-embed,
.prose-fa .nevis-video-embed iframe {
  aspect-ratio: 16 / 9;
  width: 100%;
  border: 0;
  border-radius: 8px;
}

.prose-fa .nevis-embed iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

/* A wide table must scroll inside its own box; without this the page itself
 * scrolls sideways, which on a phone breaks every other element on it. */
.prose-fa .nevis-table-scroll {
  overflow-x: auto;
  margin-block: 1.5em;
}

.prose-fa table {
  border-collapse: collapse;
  min-width: 100%;
}

.prose-fa :is(th, td) {
  border: 1px solid rgba(127, 127, 127, 0.35);
  padding: 0.5em 0.75em;
  text-align: start;
}

/* ── Callouts ─────────────────────────────────────────────────────────────── */

.prose-fa .nevis-callout {
  margin-block: 1.5em;
  padding: 1em 1.25em;
  border-radius: 8px;
  border-inline-start: 4px solid currentColor;
  background: rgba(127, 127, 127, 0.08);
}

.prose-fa .nevis-callout > :last-child { margin-block-end: 0; }
.prose-fa .nevis-callout-tip     { color: #1b7f4b; }
.prose-fa .nevis-callout-warning { color: #a86500; }
.prose-fa .nevis-callout-danger  { color: #b3261e; }

/* ── Gallery ──────────────────────────────────────────────────────────────── */

/* A carousel with no JavaScript.
 *
 * The track is a scroll-snap row and the navigation is ordinary anchor links to
 * each slide, so it works with scripting disabled, inside a feed reader, and on
 * a phone where the native gesture is a swipe. Without this stylesheet it
 * degrades to a scrollable row of images whose jump links still work — a worse
 * gallery, never a broken page. */
.prose-fa .nevis-gallery {
  margin-block: 1.5em;
}

.prose-fa .nevis-gallery-track {
  display: flex;
  gap: 0.75em;
  padding: 0;
  margin: 0;
  list-style: none;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: thin;
}

.prose-fa .nevis-gallery-slide {
  flex: 0 0 100%;
  scroll-snap-align: center;
  margin: 0;
}

.prose-fa .nevis-gallery-slide figure {
  margin: 0;
}

.prose-fa .nevis-gallery-slide img {
  width: 100%;
  border-radius: 8px;
  object-fit: cover;
}

.prose-fa .nevis-gallery-nav {
  display: flex;
  gap: 0.4em;
  justify-content: center;
  margin-block-start: 0.75em;
  flex-wrap: wrap;
}

.prose-fa .nevis-gallery-nav a {
  min-width: 2em;
  min-height: 2em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid rgba(127, 127, 127, 0.5);
  text-decoration: none;
  color: inherit;
  /* Persian numerals for the slide numbers, matching the ordered-list rule. */
  font-variant-numeric: normal;
}

.prose-fa .nevis-gallery-nav a:hover,
.prose-fa .nevis-gallery-nav a:focus-visible {
  border-color: currentColor;
  background: rgba(127, 127, 127, 0.15);
}

/* Respect a reader who has asked for less motion: smooth scrolling is exactly
 * the kind of movement that setting exists for. */
@media (prefers-reduced-motion: reduce) {
  .prose-fa .nevis-gallery-track {
    scroll-behavior: auto;
  }
}

/* ── Links ────────────────────────────────────────────────────────────────── */

/* Underlined rather than colour-only: colour alone is not a distinguishable
 * cue for a reader who cannot see the difference. */
.prose-fa a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.prose-fa a:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* A highlight or colour an author set must stay legible against either page
 * background, so marks keep an explicit foreground. */
.prose-fa mark {
  background-color: rgba(255, 235, 59, 0.45);
  color: inherit;
  padding-inline: 0.15em;
  border-radius: 3px;
}

/* ── Narrow screens ───────────────────────────────────────────────────────── */

/* Everything above is already fluid — images cap at 100%, tables and code
 * scroll inside their own boxes. What does not survive a narrow column is
 * indentation measured in ems of body text: eight steps of 2em is 16em, which
 * in a 360px column leaves about four characters. The steps are halved rather
 * than dropped, because an indent that disappears changes what the document
 * means.
 *
 * A container query, not a media query — see the container declaration on
 * .prose-fa. This fires on a narrow column inside a wide window, which is
 * exactly the case the admin's preview creates. */
@container nevis-article (max-width: 40em) {
  .prose-fa .nevis-indent-1 { margin-inline-start: 1em; }
  .prose-fa .nevis-indent-2 { margin-inline-start: 2em; }
  .prose-fa .nevis-indent-3 { margin-inline-start: 3em; }
  .prose-fa .nevis-indent-4 { margin-inline-start: 4em; }
  .prose-fa .nevis-indent-5 { margin-inline-start: 4.5em; }
  .prose-fa .nevis-indent-6 { margin-inline-start: 5em; }
  .prose-fa .nevis-indent-7 { margin-inline-start: 5.5em; }
  .prose-fa .nevis-indent-8 { margin-inline-start: 6em; }

  /* Blockquotes and callouts lose their outer margin rather than their rule:
   * the marker is what identifies them, the whitespace is not. */
  .prose-fa .nevis-callout {
    padding: 0.85em 1em;
  }
}

/* Heading sizes as a ratio of the body, so an article scales with whatever
 * container it is dropped into — including the preview's phone frame — instead
 * of carrying pixel sizes that were right for one width. */
.prose-fa h1 { font-size: 1.75em; }
.prose-fa h2 { font-size: 1.45em; }
.prose-fa h3 { font-size: 1.2em; }
.prose-fa h4 { font-size: 1.05em; }
