/**
 * @file
 * Typography, focus and motion for the Ágora Transparency Theme - task T-607.
 *
 * THE TYPEFACE IS PUBLIC SANS, and it is a licence decision rather than a taste
 * one - D-030 in the site template's specs/000-project/DECISIONS.md. The full
 * manifest line, naming version, licence and source URL, is in README.md under
 * "Third-party assets"; this header does not repeat it, so that there is one
 * place to correct if it ever changes.
 *
 * SELF-HOSTED, AND NOT NEGOTIABLE. Both files are served from this theme. There
 * is no link to a font CDN here or anywhere else in the repository, because
 * loading a font from a third party sends every visitor's IP address to that
 * third party, and for a Spanish town hall publishing its own contracts that is
 * a data-protection liability rather than a performance trade-off. The absence
 * is asserted, not merely intended: T-607's success criterion sweeps the whole
 * repository for the two Google font hostnames and for a remote CSS import, and
 * requires zero matching lines.
 *
 * That criterion is described here in words and NOT quoted as a pattern, which
 * is not fastidiousness - quoting it verbatim in this comment made the sweep
 * return one line, and the one line was this file. A check whose own
 * documentation trips it teaches people to add exceptions to the check.
 *
 * NOT SUBSET, DELIBERATELY. These are the upstream webfont builds, byte for
 * byte, with no unicode-range and no glyph stripping. Subsetting would save
 * about thirty kilobytes across two files and would put the Spanish alphabet one
 * careless range away from disappearing: the demo content is bilingual ES/EN, so
 * dropping the accented Latin block would render the Spanish half as tofu boxes,
 * and the first place anyone would see that is a marketplace screenshot. The
 * whole cost of not subsetting is 66 KB for the two faces together, which is
 * less than one photograph.
 *
 * TWO WEIGHTS ONLY - 400 and 700. No italic, no intermediate weights. Every
 * additional face is another file on every page load and another line in the
 * licence manifest, and a table of salaries needs a body weight and a header
 * weight. If a component later needs italic, that is a task row, not an import.
 *
 * TABULAR FIGURES ARE THE REASON THIS FONT WAS CHECKED RATHER THAN ASSUMED.
 * Public Sans ships proportional old-style figures as well as lining ones, so a
 * column of euro amounts will not align by default: the digits have different
 * widths and the decimal points wander. The rule on `table` below pins lining,
 * tabular figures so that numbers in a column line up vertically. That is a
 * legibility property of financial tables, which are this portal's core content.
 */

@font-face {
  font-family: "Public Sans";
  src: url("../fonts/PublicSans-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Public Sans";
  src: url("../fonts/PublicSans-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/**
 * The type scale.
 *
 * A 1.2 ratio - a minor third - from a 1rem base, rounded to three decimals.
 * Sober rather than dramatic: the largest step is a little over twice the body
 * size, which is what an institutional page wants and what keeps a long heading
 * from wrapping into a wall.
 *
 * EVERY SIZE IS IN rem AND THE ROOT IS A PERCENTAGE. That combination is what
 * makes the browser's own font-size setting work. Setting a px size on :root
 * would silently override the preference of every reader who has raised it, and
 * those readers are exactly the ones this theme exists for. WCAG 2.2 SC 1.4.4
 * needs 200% zoom without loss of content, and a rem scale gets it for free.
 */
:root {
  --agora-font-family-base: "Public Sans", system-ui, -apple-system, "Segoe UI", roboto, arial, sans-serif;
  --agora-font-size-xs: 0.833rem;
  --agora-font-size-sm: 0.917rem;
  --agora-font-size-base: 1rem;
  --agora-font-size-md: 1.2rem;
  --agora-font-size-lg: 1.44rem;
  --agora-font-size-xl: 1.728rem;
  --agora-font-size-2xl: 2.074rem;
  --agora-font-size-3xl: 2.488rem;

  /* One more step of the same 1.2 ratio, for the front page's headline alone.
     Added rather than written as a bare rem in the component: every size in
     this theme is a step on this scale, and a headline that is not on it is a
     headline nobody can move with the rest. */
  --agora-font-size-4xl: 2.986rem;

  /* WCAG 2.2 SC 1.4.12 asks that 1.5 line height be possible without breakage;
     shipping it as the default is cheaper than shipping something tighter and
     testing whether it survives being loosened. */
  --agora-line-height-body: 1.5;
  --agora-line-height-heading: 1.25;
  --agora-font-weight-normal: 400;
  --agora-font-weight-bold: 700;

  /* Focus ring geometry. The colour lives in tokens.css with every other
     colour; only the measurements are here. 3px at 2px offset clears the
     2px minimum perimeter WCAG 2.2 SC 2.4.13 asks for with room to spare. */
  --agora-focus-ring-width: 3px;
  --agora-focus-ring-offset: 2px;

  /* How far the ring reaches outside the box of the element it marks, and so
     the room anything that scrolls or clips has to leave around a focused
     element for all four sides of the ring to be seen. Derived, never typed:
     it has to move whenever either measurement above does. */
  --agora-focus-ring-extent: calc(var(--agora-focus-ring-width) + var(--agora-focus-ring-offset));
}

html {
  /* Percentage, never px - see the note on the scale above. */
  font-size: 100%;
}

body {
  font-family: var(--agora-font-family-base);
  font-size: var(--agora-font-size-base);
  font-weight: var(--agora-font-weight-normal);
  line-height: var(--agora-line-height-body);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  letter-spacing: -0.01em;
  font-weight: var(--agora-font-weight-bold);
  line-height: var(--agora-line-height-heading);
}

h1 {
  font-size: var(--agora-font-size-2xl);
}

h2 {
  font-size: var(--agora-font-size-xl);
}

h3 {
  font-size: var(--agora-font-size-lg);
}

h4 {
  font-size: var(--agora-font-size-md);
}

h5 {
  font-size: var(--agora-font-size-base);
}

h6 {
  font-size: var(--agora-font-size-sm);
}

small,
caption {
  font-size: var(--agora-font-size-sm);
}

/**
 * Tabular figures in tables. See the header note: without this, a column of
 * amounts does not align, because the font's default figures are proportional.
 * `lining-nums` is set alongside `tabular-nums` on purpose - old-style figures
 * are present in this font and would otherwise be free to appear.
 */
table {
  font-variant-numeric: lining-nums tabular-nums;
}

/**
 * Visible focus.
 *
 * `:focus-visible` rather than `:focus`, so that a mouse click on a button does
 * not leave a ring behind while keyboard traversal always shows one.
 *
 * NOTHING IN THIS THEME MAY SET `outline: none` OR `outline: 0`. Removing the
 * outline is how focus indication dies, and it usually dies in a component
 * stylesheet written months later by someone who found the ring ugly. If a
 * component needs a different indicator it replaces this one with something
 * that also meets 3:1 against its background - which is why the focus colours
 * carry declared contrast pairs in tokens.css rather than being chosen by eye.
 *
 * THE SCROLL MARGIN IS THE RING'S OWN EXTENT, and it is here because the
 * browser's focus scrolling does not know the ring exists. Chrome scrolls a
 * PARTLY visible element only until its box meets the nearest edge, and the
 * ring is drawn outside that box, so the side it was scrolled from was cut; an
 * element already inside the window by less than the ring is not scrolled at
 * all, and its ring overhangs the edge. A margin on the focused element is
 * honoured by every scrolling box above it - the window, a table scroller, and
 * the reveal js/table-scroll.js asks for - which a scroll padding on any one
 * box is not.
 *
 * IT USED TO EXIST ONLY INSIDE TABLE SCROLLERS, and it was moved here rather
 * than copied. Swept with real Tab and Shift+Tab over every stop on ten pages
 * of the preview at 320, 390 and 1280, the table-only rule still left 137
 * stops outside tables losing a side of the ring: 116 links, buttons and
 * fields at the window's edge, and 21 visits to a table scroller's own wrapper
 * - a tab stop the table-only selector never matched. With the margin here all
 * 137 read 0 and the 2,436 stops inside tables still read 0. What is left is
 * under a pixel, because a scroll offset is whole and an element's edge need
 * not be: at most 0.45px in the Chrome the preview was swept with, and 0.8px
 * in the one CI runs, on the one stop its test measures. A scroller taller
 * than the window cannot show its whole ring and nothing can; the margin
 * brings the top of it on screen, on 34 of its 42 visits.
 */
:focus-visible {
  outline: var(--agora-focus-ring-width) solid var(--agora-color-focus);
  outline-offset: var(--agora-focus-ring-offset);
  scroll-margin: var(--agora-focus-ring-extent);
}

/**
 * Reduced motion.
 *
 * `prefers-reduced-motion: reduce` is a request from a reader whose vestibular
 * system is affected by movement, and it is not a preference to be weighed
 * against a design. Durations are collapsed rather than set to zero: a genuinely
 * zero duration stops transitionend and animationend events from firing, and
 * scripts that wait for them then hang forever. 0.01ms is imperceptible and
 * still fires.
 *
 * `!important` is used here and is justified: this block has to beat whatever a
 * later component stylesheet declares, and losing that fight is the whole
 * failure mode.
 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
