/* 51-specimens.css - the Specimens page.
   Every stylesheet is linked on every page, so each rule here hangs on an sp- class.
   Colour is Vlak's custom properties only. Sizes are the site's ladder, the two display
   sizes of the ledger (a word, a line) and the waterfall's own steps. Class prefix: sp-. */

/* The page is the size container. A ledger cell is a fixed share of the page, so the
   fluid sizes of a sample and of the strut beside it can be written once and agree. */
.sp-page { container-type: inline-size; }

/* Weights are data: the script reads the same attribute to know what a style must have. */
.sp [data-w="300"] { font-weight: 300; }
.sp [data-w="400"] { font-weight: 400; }
.sp [data-w="500"] { font-weight: 500; }
.sp [data-w="600"] { font-weight: 600; }
.sp [data-w="700"] { font-weight: 700; }
/* a weight the chosen style does not have is not faked */
.sp [data-sp-off] { visibility: hidden; }

/* a control reached by keyboard stops clear of the fixed bar and of the style row that stays under it
   (86px: the control and the cell's insets), and its ring clear of the window's lower edge */
.sp :is(a, button, input, pre) { scroll-margin: calc(var(--pl-bar) + 86px + var(--gutter)) 0 var(--pl-cell-pad); }

/* What belongs to one style is shown while that style is on show (data-sp-style on the grid;
   data-sp-for names the styles of a cell or a sentence). */
.sp[data-sp-style="sans"] [data-sp-for]:not([data-sp-for~="sans"]),
.sp[data-sp-style="serif"] [data-sp-for]:not([data-sp-for~="serif"]),
.sp[data-sp-style="slab"] [data-sp-for]:not([data-sp-for~="slab"]),
.sp[data-sp-style="mono"] [data-sp-for]:not([data-sp-for~="mono"]) { display: none; }

/* ── The opening ─────────────────────────────────────────────────────────────
   The page's name. Nine letters: one step under pe-word (.19 of the cell where pe-word
   takes .21), so the name stays under the specimen words at every width. The size is
   written once. */
.sp { --sp-name: clamp(3.5rem, 19cqw, 8.125rem); }
/* On four columns the name has the row and the words three fields of it (.21 of 3/4 of the row):
   the name keeps under them here too. */
@media (min-width: 816px) and (max-width: 1223.98px) {
  .sp { --sp-name: clamp(3.5rem, calc(15.75cqw - 4px), 8.125rem); }
}
/* On six columns it has three fields and grows with them. Here the size is read from the
   page, not from the cell (which is half the page less 40.5px): the law's cell reads the
   same length, and two cells of one row can differ by a fraction of a pixel. */
@media (min-width: 1224px) {
  .sp > .sp-open { container-type: normal; }
  .sp { --sp-name: clamp(3.5rem, calc(9.5cqw - 7.7px), 15rem); }
}
/* The tail of the p hangs .196em under the baseline (the family's descender). The line box
   of pe-word ends .073em under it (leading .86 on line metrics of .957 and .243), so the
   tail would cross .123em of the cell's inset, to within 4px of the hairline. As on Glyphs
   and Try it, the word is lifted until the tail clears the hairline under the cell by 8px.
   This is the one place that sets the clearance: the law follows the name by itself. */
.sp-name, .sp-level::before { font-size: var(--sp-name); padding-bottom: max(0px, calc(.123em - 12px)); }
/* Beside the name, on six columns, the law stands on the name's baseline. Its cell holds
   a strut: the name's own box (its size, leading and lift) with nothing to say, on the
   line of the law's last line. One rule sets both boxes, so the two baselines agree at
   every width and nothing is measured. */
@media (min-width: 1224px) {
  .sp-level { font-size: 0; }            /* the line holds the strut and the law, and no space between them */
  .sp-level::before {
    content: "x";
    visibility: hidden;                  /* a strut: it takes its box and says nothing */
    display: inline-block;
    width: 0;
    font-family: var(--pe-spec);
    font-weight: 600;
    line-height: .86;                    /* the leading of pe-word */
  }
  .sp-level > .pl-law { display: inline-block; }   /* an inline block stands on its last line */
}


/* ── The ledger ──────────────────────────────────────────────────────────────
   Rows of two cells on the page's own columns: a label in the first field, the
   sample in the fields beside it. A row is as high as its sample, so the bands
   narrow as the type gets smaller. Cells are paper on the grid's ground, as
   everywhere; the ledger itself is transparent. */
.sp-ledger {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  row-gap: var(--pl-hairline);
  /* the width of a sample cell's content, for sizes that follow the cell */
  --sp-w: calc(100cqw - 2 * var(--pl-cell-pad));
}
@media (min-width: 816px) {
  .sp-ledger { --sp-w: calc((100cqw - 3 * var(--pl-hairline)) * 3 / 4 + 2 * var(--pl-hairline) - 2 * var(--pl-cell-pad)); }
}
@media (min-width: 1224px) {
  .sp-ledger { --sp-w: calc((100cqw - 5 * var(--pl-hairline)) * 5 / 6 + 4 * var(--pl-hairline) - 2 * var(--pl-cell-pad)); }
}

/* Below four columns a row is one cell: the label over its sample. */
.sp-row {
  grid-column: 1 / -1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: var(--pl-cell-pad);
  background: var(--bg);
}
.sp-key, .sp-val { min-width: 0; }

@media (min-width: 816px) {
  .sp-row { display: contents; }
  .sp-key, .sp-val {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: var(--pl-cell-pad);
    background: var(--bg);
  }
  .sp-val { grid-column: span 3; }
  /* The label stands on the baseline of its sample: a strut of the sample's
     own family, size and leading opens the label's line to the same box. */
  .sp-key .pe-label { align-items: baseline; gap: 0; line-height: 1; }
  .sp-key .pe-label::before {
    content: "x";
    visibility: hidden;                  /* a strut: it takes its line and says nothing */
    flex: none;
    width: 0;
    font-family: var(--pe-spec);
    font-size: var(--sp-fs);
    line-height: var(--sp-lh);
  }
  .sp-key .pe-label b { margin-right: auto; }
  .sp-key .pe-label span { margin-left: 12px; }
}
@media (min-width: 1224px) {
  .sp-val { grid-column: span 5; }
}

/* A sample hangs left by its first letter's own side bearing, so every first stem
   stands on the cell's edge. */
.sp-sample {
  margin: 0 0 0 calc(-1 * var(--sp-hang, 0em));
  font-family: var(--pe-spec);
  font-size: var(--sp-fs);
  line-height: var(--sp-lh);
  letter-spacing: var(--sp-ls);        /* the tracking its label names */
  white-space: nowrap;
}
/* The bearing of each first letter in this build, in em, by letter and weight. The script
   measures the font really in use and corrects it (a rebuilt font, another style). */
.sp [data-sp-hang="W"][data-w="300"] { --sp-hang: .027em; }
.sp [data-sp-hang="W"][data-w="400"] { --sp-hang: .025em; }
.sp [data-sp-hang="P"][data-w="400"] { --sp-hang: .094em; }
.sp [data-sp-hang="V"][data-w="500"] { --sp-hang: .014em; }
.sp [data-sp-hang="D"][data-w="700"] { --sp-hang: .08em; }
.sp [data-sp-hang="L"][data-w="300"] { --sp-hang: .098em; }
.sp [data-sp-hang="L"][data-w="400"] { --sp-hang: .094em; }
.sp [data-sp-hang="L"][data-w="500"] { --sp-hang: .09em; }
.sp [data-sp-hang="L"][data-w="600"] { --sp-hang: .086em; }
.sp [data-sp-hang="L"][data-w="700"] { --sp-hang: .08em; }
.sp [data-sp-hang="H"][data-w="400"] { --sp-hang: .094em; }
.sp [data-sp-hang="E"][data-w="400"] { --sp-hang: .094em; }

/* a word, as large as the cell allows; the leading leaves room for p, g and j.
   Sizes and leadings are whole pixels, so every hairline of the ledger falls on one. */
.sp-row-word {
  --sp-fs: clamp(var(--sp-word-min, 3.5rem), round(down, calc(var(--sp-w) * var(--sp-word-k, .21)), 1px), 20rem);
  --sp-lh: round(up, calc(var(--sp-fs) * 1.1), 1px);
  --sp-ls: -.04em;
}
/* a line */
.sp-row-line {
  --sp-fs: clamp(1.75rem, round(down, calc(var(--sp-w) * var(--sp-line-k, .103)), 1px), 10rem);
  --sp-lh: 1;
  --sp-ls: -.035em;
}
/* a step of the waterfall: true pixels, the tracking loosening as the size falls.
   Three registers, each one line in two or three steps: a display line, a title, a subhead.
   Where the cell is narrower than the line it runs on, balanced; the label keeps to the
   baseline of the last line. Text sizes follow in the cells under the ledger. */
.sp-row-step { --sp-lh: round(calc(var(--sp-fs) * 1.2), 1px); }
.sp-row-step .sp-sample { white-space: normal; text-wrap: balance; }
.sp-row-step[data-px="120"] { --sp-fs: 120px; --sp-ls: -.035em; }
.sp-row-step[data-px="96"] { --sp-fs: 96px; --sp-ls: -.035em; }
.sp-row-step[data-px="72"] { --sp-fs: 72px; --sp-ls: -.035em; }
.sp-row-step[data-px="56"] { --sp-fs: 56px; --sp-ls: -.03em; }
.sp-row-step[data-px="44"] { --sp-fs: 44px; --sp-ls: -.03em; }
.sp-row-step[data-px="34"] { --sp-fs: 34px; --sp-ls: -.025em; }
.sp-row-step[data-px="26"] { --sp-fs: 26px; --sp-ls: -.02em; }
.sp-row-step[data-px="22"] { --sp-fs: 22px; --sp-ls: -.02em; }
/* A step is shown where it stands a clear step under the line above it (the line is
   a fraction of the cell, the steps are true pixels). */
@media (max-width: 1659.98px) { .sp-row-step[data-px="120"] { display: none; } }
@media (max-width: 1339.98px) { .sp-row-step[data-px="96"] { display: none; } }
@media (max-width: 1129.98px) { .sp-row-step[data-px="72"] { display: none; } }
@media (max-width: 534.98px)  { .sp-row-step[data-px="44"] { display: none; } }
@media (max-width: 419.98px)  { .sp-row-step[data-px="34"] { display: none; } }
@media (max-width: 329.98px)  { .sp-row-step[data-px="26"] { display: none; } }
/* And going down, a step never runs on more lines than the one above it, so the bands only
   narrow. The title at 56px is wider than the display line at 72px and than three fields
   ever are, in every style: it waits for six columns. Past that the widths differ by style
   (the Slab runs wider than the Sans, the Mono wider still), so the script counts the lines
   in the font on show and leaves out a step that runs on more lines than the step above it. */
@media (max-width: 1223.98px) { .sp-row-step[data-px="56"] { display: none; } }
.sp-row-step[data-sp-skip] { display: none; }

/* The Mono is tracked less at display sizes and not at all in text, as in its own job;
   its letters are all one width, so a word and a line are sized to its longest. */
.sp[data-sp-style="mono"] .sp-row-word { --sp-word-k: .178; --sp-word-min: 2.75rem; --sp-ls: -.02em; }
.sp[data-sp-style="mono"] .sp-row-line { --sp-line-k: .098; --sp-ls: -.02em; }
.sp[data-sp-style="mono"] .sp-row-step { --sp-ls: -.02em; }
.sp[data-sp-style="mono"] .sp-row-step:is([data-px="34"], [data-px="26"], [data-px="22"]) { --sp-ls: -.01em; }
.sp[data-sp-style="mono"] .sp-texts .pe-text,
.sp[data-sp-style="mono"] .sp-lines { letter-spacing: 0; }


/* ── The style row: the page's spine ─────────────────────────────────────────
   As high as its control; the label on the baseline of the control's text. It stays
   under the fixed bar while the page scrolls, on the grid's own columns. Where the row
   is one cell (below four columns) the label and the note stand over the control and
   slide under the bar: the script measures how far (--sp-lift); without it the whole
   row stays. The hairline under it is the grid's, drawn by the row while it travels. */
/* The page's grid gives every row at least one field. The first rows here are the opening,
   the style row and the ledger, each as high as its content: the style row is as high as its control. */
.sp { grid-template-rows: auto auto auto; }
.sp-bar {
  grid-column: 1 / -1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: var(--pl-cell-pad);
  background: var(--bg);
  position: sticky;
  top: calc(var(--pl-bar) - var(--sp-lift, 0px));
  z-index: 100;
  /* Vlak's divider is translucent: paper under it, so nothing that passes behind shows through */
  box-shadow: 0 var(--pl-hairline) 0 var(--divider), 0 var(--pl-hairline) 0 var(--bg);
  --sp-fs: 13px;
  --sp-lh: 46px;
}
@media (max-width: 640px) {
  .sp-bar { top: calc(var(--pl-bar-phone) + env(safe-area-inset-top, 0px) - var(--sp-lift, 0px)); }
}
@media (min-width: 816px) {
  .sp-bar { display: grid; grid-template-columns: subgrid; gap: 0 var(--pl-hairline); padding: 0; background: linear-gradient(var(--divider), var(--divider)) var(--bg); }
}
.sp-style { display: flex; align-items: center; gap: 12px var(--gutter); }
.sp-style .rs-toggle-group { flex: none; }
.sp-style .pl-meta { flex: 1 1 0; min-width: 0; max-width: 44em; text-wrap: pretty; }
@media (max-width: 815.98px) {
  .sp-bar { padding-bottom: 12px; }      /* 12px over the control while it travels, 12px under it */
  .sp-style { flex-direction: column-reverse; align-items: flex-start; }
  .sp-style .pl-meta { flex: none; }
}


/* ── Running text ────────────────────────────────────────────────────────────
   Six cells in the order a phone reads them: each size in Regular, then in Medium,
   one text in its two languages. On six columns they flow down the columns, so
   Regular is one row and Medium the next. */
.sp-texts {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  grid-auto-rows: minmax(var(--pl-field), auto);
  row-gap: var(--pl-hairline);
}
@media (min-width: 1224px) {
  .sp-texts { grid-template-rows: repeat(2, minmax(var(--pl-field), auto)); grid-auto-flow: column; }
}
/* On two columns of a phone's width a text takes the row, as on one column: two abreast
   would set the 17px text on lines of 22 to 30 characters. */
@media (max-width: 640px) {
  .sp-texts > .pl-cell { --pl-two: 2; }
}


/* ── Figures ─────────────────────────────────────────────────────────────────
   The table is the site's pe-table. With 16px between its four columns it needs 292px.
   On the narrowest phones the columns may stand as close as 8px, so the table still
   ends on the cell's inset; the table takes the cell's width, so they stand closer
   only as far as the cell asks. */
@media (max-width: 359.98px) {
  .sp-figures td + td, .sp-figures th + th,
  .sp-data td + td, .sp-data th + th { padding-left: 8px; }
  /* the Mono runs wider: there its table is set a step smaller, the size of its own job */
  .sp[data-sp-style="mono"] .sp-figures { font-size: 13px; }
}


/* ── Label lines: the rhythm of the table beside them ────────────────────── */
.sp-lines {
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--pe-spec);
  font-size: 13px;
  line-height: 19.5px;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}
.sp-lines li { padding: 9px 0; border-top: 1px solid var(--divider); }
/* a label breaks after a middle dot or not at all */
.sp-nb { white-space: nowrap; }


/* ── At work ─────────────────────────────────────────────────────────────────
   One grammar for the four styles: a key cell that names the job, then five fields of
   specimen. On four columns the key and three fields make the first row and the rest
   the second; on two columns every cell takes the row. */
.sp-job-key { --pl-two: 2; }
.sp-job-two { --pl-two: 2; }
.sp-job-three { --pl-four: 3; --pl-two: 2; }
.sp-job-rest { --pl-four: 4; --pl-two: 2; }
.sp-job-key .pl-meta { max-width: 22em; text-wrap: pretty; }

/* a paragraph for reading: the Serif's larger size, on the widest measure the page has */
.sp-read { font-size: 22px; line-height: 1.4; letter-spacing: -.015em; }
/* a heading over text */
.sp-head {
  margin: 0 0 10px -.02em;
  font-family: var(--pe-spec);
  font-size: 26px; line-height: 1.15; letter-spacing: -.02em;
  text-wrap: balance;
}
/* a pull line */
.sp-pull {
  margin: 0 0 0 -.02em;
  font-family: var(--pe-spec);
  font-size: 34px; line-height: 1.15; letter-spacing: -.025em;
  max-width: 14em;
  text-wrap: balance;
}
/* a term from the source inside a sentence: the Mono at the size of the text around it
   (one x-height), untracked */
.sp-term { font-family: var(--pe-mono); font-size: 1em; letter-spacing: 0; white-space: nowrap; }
/* a table of figures from the build */
.sp-data { font-size: 13px; }
.sp-together .sp-data { font-size: 15px; }
.sp-together .pe-text { max-width: 36em; }

/* Vlak's controls, in the Sans */
.sp-kit { min-width: 0; font-family: var(--pe-spec); }
/* tabs and field stand two fields wide where the row has four */
.sp-wide { --pl-four: 2; }
.sp-choice { min-height: var(--hit); }
/* the line under the tabs is set as the hint under the field, and as far below */
.sp-kit [role="tabpanel"] { margin-top: 8px; }
.sp-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--hit);
  font-size: var(--control-fs);
  letter-spacing: -.01em;
}


/* ── The spacing proof ───────────────────────────────────────────────────────
   Straight and round letters in a row at the spacing as drawn: no kerning, no tracking.
   Every letter is a span of its own advance width. A hairline stands on each edge of it,
   from the ascender line to the descender line, so the side bearings can be read off.
   The first hairline stands on the cell's edge; the letters do not hang here. */
.sp-rhythm { container-type: inline-size; }
.sp-rhythm {
  /* the line and its longer word in em, at the spacing as drawn, with a little to spare */
  --sp-proof-line: 11.2; --sp-proof-word: 6.2;
}
.sp[data-sp-style="slab"] .sp-rhythm { --sp-proof-line: 11.65; --sp-proof-word: 6.4; }
.sp[data-sp-style="mono"] .sp-rhythm { --sp-proof-line: 10.3; --sp-proof-word: 6.2; }
.sp-proof {
  margin: 0;
  font-family: var(--pe-spec);
  font-size: clamp(1.25rem, round(down, calc((100cqw - 2 * var(--pl-cell-pad)) / var(--sp-proof-line)), 1px), 10rem);
  line-height: 1;
  letter-spacing: 0;
  font-kerning: none;                  /* side bearings only: that is what a spacing proof shows */
  white-space: nowrap;
  /* the family's lines in em (docs/DESIGN.md): line ascent .957, ascender .73, descender .196 */
  --sp-rule: linear-gradient(var(--divider), var(--divider));
  --sp-rule-top: .227em;               /* .957 - .73: from the top of the letter's box to the ascender line */
  --sp-rule-size: 1px .926em;          /* .73 + .196: ascender line to descender line */
}
.sp-proof-word > span {
  background: var(--sp-rule) no-repeat 0 var(--sp-rule-top) / var(--sp-rule-size);
}
.sp-proof-word > span:last-child {
  background:
    var(--sp-rule) no-repeat 0 var(--sp-rule-top) / var(--sp-rule-size),
    var(--sp-rule) no-repeat 100% var(--sp-rule-top) / var(--sp-rule-size);
}
/* On a phone the line is recut, not shrunk: a row for each word. */
@media (max-width: 640px) {
  .sp-proof { font-size: clamp(1.25rem, round(down, calc((100cqw - 2 * var(--pl-cell-pad)) / var(--sp-proof-word)), 1px), 10rem); }
  .sp-proof-word { display: block; }
  .sp-proof-word + .sp-proof-word { margin-top: .2em; }
}

/* The way on is a link inside a sentence. Its hairline stays under its words at every
   width; a transparent box gives it the 44px target. The focus ring is Vlak's 2px of ink,
   1px off the words instead of 2px: a word space is 3.2px wide here, and the ring stays
   clear of the full stop before the link. */
.sp .pl-meta a { position: relative; white-space: nowrap; }
.sp .pl-meta a::after { content: ""; position: absolute; inset: calc(50% - var(--hit) / 2) 0; }
.sp .pl-meta a:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
@media (max-width: 640px) {
  .sp .pl-meta a { display: inline; min-width: 0; min-height: 0; }
}
