/* Technical publications (templates/publication.html): a centred heading and
   one reading column. Every publication uses these classes and adds none of
   its own.

   THE TYPE IS MEASURED
   Figtree at weight 400 has an x-height of 0.50em and an average character
   0.434em wide. Body text is 18px, so its x-height is 9px. The column is
   40rem (640px): about 82 characters per line. Don't size it in ch: in
   Figtree a "0" is 0.64em, half again an average letter.

   THE RHYTHM IS CALCULATED
   One line of body text is the unit. Its height comes from Pearson's
   golden-ratio formula, with f the font size, w the measure and p = 1.618:
       line = f * (p - (1 / 2p) * (1 - w / (f * p)^2))
   For 18px on 640px that is 27.8px, set as 28px (--pub-line).
   - Every line-height, margin and padding is a whole number of quarter lines
     (7px). Line-heights are written as calc(line / size) so they land on it
     exactly: 70/64, 35/30, 28/20, 28/18, 28/16, 21/14.
   - Space is added below things, never above: this file sets no top margin.
     The space between sections belongs to the section.
   - Rules are drawn with box-shadow, so a 1px line adds no height.
   tests/integration/api/test_publication_rhythm.py holds these rules.

   WHY A LINE, AND HOW MANY
   A reader judges a gap against the distance between two lines of text, so
   the line is the only unit that means anything on the page. The line itself
   is as tall as it is because of the measure: the longer the line, the more
   room the eye needs to find the start of the next one.
   Space then says what belongs together. The closer two things are, the
   more they are one thing:
     1/2 line   a label and what it labels: a heading and its text, one list
                item and the next
     1 line     neighbours in one group: paragraph to paragraph, title to
                summary, summary to the section links
     1 1/2      a change of voice inside a section: prose to an offset block
     2 lines    a new section. Twice the paragraph gap, so it reads as a
                break, and no more, so the article stays one piece
     3 lines    the three parts of the page: heading, article, closing panel
   The section links belong to the heading, so they sit one line under the
   summary, and the three lines come after them.

   OFFSETS
   Prose keeps to the reading column. Tables, pairs and the closing panel are
   offset:
   they reach 6rem past the column on each side. Add .pub-wide to offset
   anything else. Offset blocks are information to look up, not the voice of
   the article, so their text is two steps below the body on the scale.

   A publication has six kinds of content and no others: prose, a list, a
   value to copy (pre), a table (table.pub-table), pairs (dl.pub-pairs) and
   one closing panel. The body is a series of <section>s; a section starts
   with its <h2>.

   QUOTES
   Figtree draws ' and " marks as straight wedges, set tight against the
   letters, and has no alternate for them. So the four curly quote characters
   alone come from a curled face on the reader's device: Georgia, then
   Trebuchet MS, then Helvetica Neue. A device with none of them keeps
   Figtree's. The borrowed face is given Figtree's own line metrics, so it
   cannot move a line off the rhythm.

   Sizes are in rem so the reader's font size applies. Colours have
   fallbacks because a publication must stay readable when sdk.css is
   missing. Every headline is weight 600. */
@font-face {
  font-family: "Publication Quotes";
  src: local("Georgia"), local("Trebuchet MS"), local("Helvetica Neue");
  unicode-range: U+2018-2019, U+201C-201D;
  ascent-override: 95%;
  descent-override: 25%;
  line-gap-override: 0%;
}
@font-face {
  font-family: "Publication Quotes";
  font-weight: 500 900;
  src: local("Georgia Bold"), local("Trebuchet MS Bold"), local("Helvetica Neue Bold");
  unicode-range: U+2018-2019, U+201C-201D;
  ascent-override: 95%;
  descent-override: 25%;
  line-gap-override: 0%;
}
@font-face {
  font-family: "Publication Quotes";
  font-style: italic;
  src: local("Georgia Italic"), local("Trebuchet MS Italic"), local("Helvetica Neue Italic");
  unicode-range: U+2018-2019, U+201C-201D;
  ascent-override: 95%;
  descent-override: 25%;
  line-gap-override: 0%;
}
.pub {
  --pub-ink: var(--uas--typography--color, #16191c);
  --pub-muted: var(--uas--typography--color-secondary, #626970);
  --pub-link: var(--uas--typography--color-link, #006fc9);
  --pub-rule: var(--uas--color--border, #d9dde1);
  --pub-tint: #f5f6f8;
  --pub-measure: 40rem;
  --pub-wide: 52rem;

  /* The unit, and its quarter. */
  --pub-line: 1.75rem;
  --pub-q: calc(var(--pub-line) / 4);

  /* The scale, by role. Text sizes step by 2px: 14, 16, 18, 20. */
  --pub-display: 4rem;
  --pub-title: 1.875rem;
  --pub-lead: 1.25rem;
  --pub-body: 1.125rem;
  --pub-small: 1rem;
  --pub-caption: 0.875rem;
  /* Offset blocks: two steps below the body. */
  --pub-offset: var(--pub-caption);

  color: var(--pub-ink);
  font-family: "Publication Quotes", var(--uas--typography--body-large-font-family, var(--font));
  padding-block: calc(var(--pub-line) * 3) calc(var(--pub-line) * 4);
}
/* Start every block from no margin. :where() keeps this from outranking the
   rules below. */
.pub :where(h1, h2, h3, p, ul, ol, dl, dt, dd, pre) { margin: 0; }

/* Where a failed sign-in from the header is reported; hidden until then. */
.pub-notice { max-width: var(--pub-measure); margin: 0 auto var(--pub-line); padding-top: var(--pub-line); }

/* Heading: the title, then one or two sentences. A category line above the
   title is optional. */
.pub-head { max-width: var(--pub-wide); margin: 0 auto calc(var(--pub-line) * 3); text-align: center; }
.pub-head:has(+ .pub-contents) { margin-bottom: var(--pub-line); }
.pub-head .pub-meta { margin-bottom: var(--pub-line); color: var(--pub-muted); font-size: var(--pub-caption); line-height: calc(21 / 14); }
.pub-head h1 { margin-bottom: var(--pub-line); font-size: var(--pub-display); font-weight: 600; line-height: calc(70 / 64); letter-spacing: -0.03em; text-wrap: balance; }
/* The summary runs wide, in two or three long lines, never a narrow block. */
.pub-dek { max-width: 46rem; margin-inline: auto; font-size: var(--pub-lead); line-height: calc(28 / 20); text-wrap: pretty; }

/* Optional section links: one quiet row under a rule. They close the
   heading, so the break before the article comes after them. */
.pub-contents { max-width: var(--pub-measure); margin: 0 auto calc(var(--pub-line) * 3); padding-top: calc(var(--pub-q) * 3); box-shadow: inset 0 1px 0 var(--pub-rule); }
.pub-contents ul { display: flex; flex-wrap: wrap; gap: 0 2rem; padding: 0; list-style: none; font-size: var(--pub-caption); line-height: calc(21 / 14); }
.pub-contents a { color: var(--pub-ink); font-weight: 500; }
.pub-contents a:hover { text-decoration: underline; text-underline-offset: 0.2em; }

/* The article: sections two lines apart. Each section is a grid of three
   tracks; prose sits in the middle one and offsets span all three. */
.pub-body { max-width: var(--pub-wide); margin: 0 auto calc(var(--pub-line) * 3); font-size: var(--pub-body); line-height: calc(28 / 18); }
.pub-body > section { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, var(--pub-measure)) minmax(0, 1fr); margin-bottom: calc(var(--pub-line) * 2); scroll-margin-top: var(--pub-line); }
.pub-body > section > * { grid-column: 2; min-width: 0; margin-bottom: var(--pub-line); }
.pub-body > section:last-child, .pub-body > section > :last-child { margin-bottom: 0; }
.pub-body :is(p, li, dd) { text-wrap: pretty; }
/* Scan helpers. Bold marks the point of a paragraph; an underline in ink
   marks an action to take; italics carry the stress of a spoken sentence.
   Links are underlined in the link colour, so they are never confused with
   an underlined action. Italics use Figtree's own italic face. */
.pub em { font-style: italic; }
.pub-body strong, .pub-closing strong { font-weight: 600; }
.pub-body u { text-decoration: underline; text-decoration-thickness: from-font; text-underline-offset: 0.2em; }
/* Links read as part of the sentence: the text weight, underlined. */
.pub-body a, .pub-closing a { color: var(--pub-link); font-weight: inherit; text-decoration: underline; text-decoration-thickness: from-font; text-underline-offset: 0.2em; }

/* A heading sits half a line above the text it introduces. */
.pub-body > section > h2 { margin-bottom: calc(var(--pub-q) * 2); font-size: var(--pub-title); font-weight: 600; line-height: calc(35 / 30); letter-spacing: -0.015em; text-wrap: balance; }
.pub-body > section > h3 { margin-bottom: calc(var(--pub-q) * 2); font-size: var(--pub-lead); font-weight: 600; line-height: calc(28 / 20); text-wrap: balance; }

/* Lists: half a line between items, a full line after the list. */
.pub-body :is(ul, ol) { padding-left: 1.5em; }
.pub-body li { margin-bottom: calc(var(--pub-q) * 2); }
.pub-body li:last-child { margin-bottom: 0; }

/* Code in a sentence is only a change of face, with no box around it. A name
   such as a header or a path stays whole: it never breaks at a hyphen or a
   slash. Its own line-height is 1 so it can never stretch the line. */
.pub-body code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; line-height: 1; white-space: nowrap; }
/* A value to copy, such as an address or a User-Agent, on its own lines. */
.pub-body pre { padding: calc(var(--pub-q) * 2) 1.25rem; border-radius: 0.75rem; background: var(--pub-tint); font-size: var(--pub-small); line-height: calc(28 / 16); white-space: pre-wrap; overflow-wrap: anywhere; }
.pub-body pre code { font-size: inherit; line-height: inherit; white-space: inherit; }

/* Offset blocks span all three tracks, a line and a half clear of the prose
   on both sides. The space above is the bottom margin of whatever comes
   before. */
.pub-body > section > :is(.pub-table, .pub-pairs, .pub-wide) { grid-column: 1 / -1; margin-bottom: calc(var(--pub-q) * 6); font-size: var(--pub-offset); line-height: calc(21 / 14); }
.pub-body > section > :has(+ :is(.pub-table, .pub-pairs, .pub-wide)) { margin-bottom: calc(var(--pub-q) * 6); }
.pub-body > section > :is(.pub-table, .pub-pairs, .pub-wide):last-child { margin-bottom: 0; }

/* A table: named columns, one ruled row each. The first column is the thing
   a reader looks for. On phones each row stacks, and the column names are
   kept for screen readers only. */
.pub-table { width: 100%; border-collapse: separate; border-spacing: 0; box-shadow: inset 0 -1px 0 var(--pub-rule); text-align: left; }
.pub-table :is(th, td) { padding: calc(var(--pub-q) * 2) 0; box-shadow: inset 0 1px 0 var(--pub-rule); vertical-align: top; }
.pub-table thead th { color: var(--pub-muted); font-weight: 500; box-shadow: none; }
.pub-table tbody th { padding-right: 3rem; font-weight: 600; white-space: nowrap; }
.pub-table tbody th code { font-weight: 400; }
.pub-table code { font-size: 0.95em; }

/* Pairs: a name on the left and what it means on the right, one ruled row
   each. For anything a reader looks up by name. Stacked on phones. */
.pub-pairs { display: grid; grid-template-columns: fit-content(20rem) minmax(0, 1fr); box-shadow: inset 0 -1px 0 var(--pub-rule); }
.pub-pairs :is(dt, dd) { padding-block: calc(var(--pub-q) * 2); box-shadow: inset 0 1px 0 var(--pub-rule); }
.pub-pairs dt { padding-right: 3rem; font-weight: 600; }
.pub-pairs dt code { font-weight: 400; }
.pub-pairs code { font-size: 0.95em; }
.pub-pairs dd > p { margin-bottom: calc(var(--pub-q) * 2); }
.pub-pairs dd > p:last-child { margin-bottom: 0; }

/* The closing panel: where the reader goes next. Its text lines up with the
   reading column. */
.pub-closing { max-width: var(--pub-wide); margin-inline: auto; padding: calc(var(--pub-q) * 6) 6rem; border-radius: 1rem; background: var(--pub-tint); font-size: var(--pub-offset); line-height: calc(21 / 14); }
.pub-closing h2 { margin-bottom: var(--pub-q); font-size: var(--pub-body); font-weight: 600; line-height: calc(28 / 18); }

@media (max-width: 767px) {
  .pub { --pub-display: 2.5rem; padding-block: calc(var(--pub-line) * 2) calc(var(--pub-line) * 2); }
  .pub-head { text-align: left; }
  .pub-head h1 { line-height: calc(42 / 40); }
  .pub-dek { margin-inline: 0; font-size: var(--pub-body); line-height: calc(28 / 18); }
  .pub-table, .pub-table :is(tbody, tr, th, td) { display: block; }
  .pub-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .pub-table tbody tr { box-shadow: inset 0 1px 0 var(--pub-rule); }
  .pub-table tbody :is(th, td) { box-shadow: none; }
  .pub-table tbody th { padding-bottom: 0; padding-right: 0; white-space: normal; }
  .pub-table tbody td { padding-top: var(--pub-q); }
  .pub-pairs { grid-template-columns: minmax(0, 1fr); }
  .pub-pairs dt { padding-bottom: 0; padding-right: 0; }
  .pub-pairs dd { padding-top: var(--pub-q); box-shadow: none; }
  .pub-closing { padding: calc(var(--pub-q) * 4) 1.5rem; }
}
