/* INK-CENTRED ROWS (10.11, Ohad on the club's activity trail: "feels like not everything is vertically center aligned in
   all the rows with the time, checkbox, and text. this should be fixed everywhere and anywhere").

   THE CAUSE. A row centres its items' BOXES. A text item's box is its line box, and where the glyphs sit inside it is
   decided by the font's ascent and descent - which Chrome ROUNDS TO WHOLE PIXELS per font size before it places the
   baseline. So an 11px time, a 13px caps word and a 14px Hebrew name, each in an identical centred box, put their ink
   up to 0.6px above or below the box's centre, a different amount at every size (measured: -0.61 / +0.27 / -0.59 at
   11 / 12 / 14px): a 1px step between neighbours on his DPR-1 screen. Every hand nudge (top:-0.75px, 9/7 padding)
   corrected one size in one row and broke when the size changed.

   THE FIX, ONE RULE. Every text item of a centred row trims its box to its INK BAND - the first line's cap height down
   to the last line's baseline (text-box: trim-both cap alphabetic, which reads the font's real cap height, not a
   rounded ascent) - and gives back exactly what the trim took as EVEN padding: (1lh - 1cap) / 2 above and below. The
   item stays the height it was (one line = 1lh, n lines = n x 1lh), so no row moves, no ellipsis clips a descender, and
   the row's align-items:center now centres the ink itself. Nord caps, the EXPO digits (size-adjusted to Nord's cap
   height) and Heebo Hebrew (size-adjusted to the same) all land within 0.2px of the row's centre at 9-16px.

   WHICH ITEMS. A row is any element that centres its items (inline align-items:center, or .ink-row) and is not a
   column. Its items are the text elements directly inside it (or inside a display:contents group in it) that carry
   their own text: never a box in its own right - a flex/grid container, a framed or filled tag, an item with its own
   padding or height, an icon holder, a class-styled component - and never a WRAPPER (block children, or a child with
   its own font size): the trim reads the item's own font, so a wrapper would be trimmed by the wrong metrics and
   change height. A wrapper is judged by EVERY descendant, not only its children (10.11 B1: a SortHeader's two-line
   label sat two levels down, and the header was trimmed to one line while its second line hung on the rule). Those keep
   today's layout. .ink opts an element in by hand (it must hold its own text, as the
   activity trail's "words + x3"); .no-ink opts one out. Text straight inside a flex control (a bare text run) cannot be
   trimmed: give it its own <span>. Where text-box is unsupported (Firefox today) nothing applies and the page is
   exactly as before. [data-ink-off] on <html> switches the rule off (the break test).
   Gate: scripts/verify-ink-centre.mjs (ink centres + every box's size off vs on). Byte-identical in expo-il/public. */
/* SPEED (css-perf 11.11): the browser tries this rule on EVERY element on every style pass, testing its parts left to
   right, so the element's own cheap tests (its tag, its class) come first and the parent's style text second - a td, an
   svg path or a classed component is out before the parent is read. The clipping variant is its own rule with its own
   test first: as a nested `&` rule it re-ran the whole selector on every element to find the few that clip. Same
   elements, same specificity ((0,7,1) / (0,9,1)), same order. */
@supports (text-box: trim-both cap alphabetic) and (padding-top: 1cap) and (padding-top: 1lh) {
  :is(span, div, a, label, time, b, strong, small, em, p, bdi, h1, h2, h3, h4, h5, h6):is(:not([class]), [style*="font-"]):is(
    :root:not([data-ink-off]) :is([style*="align-items: center"], .ink-row):not([style*="flex-direction: column"]) > *,
    :root:not([data-ink-off]) :is([style*="align-items: center"], .ink-row):not([style*="flex-direction: column"]) > [style*="display: contents"] > *
  ):not(:empty, .no-ink,
      [style*="display: flex"], [style*="display: inline-flex"], [style*="display: grid"], [style*="display: inline-grid"], [style*="display: contents"],
      [style*="border"], [style*="background"], [style*="padding"], [style^="height"], [style*="; height"], [style*="min-height"],
      [style*="aspect-ratio"], [style*="text-box"], [style*="position: absolute"], [style*="position: fixed"],
      :has(svg, img, video, canvas, input, select, textarea, button, iframe),
      :has(div, p, ul, ol, li, br, style, table, section, header, footer, h1, h2, h3, h4, h5, h6),
      :has(> [class], [style*="display: block"], [style*="display: flex"], [style*="display: inline-flex"], [style*="display: grid"], [style*="display: inline-grid"], [style*="display: table"], [style*="font-size"])),
  :root:not([data-ink-off]) .ink {
    text-box: trim-both cap alphabetic;
    padding-block: calc((1lh - 1cap) / 2);
  }
  /* an item that CLIPS (an ellipsis, a clamp) clips at its padding box: 0.2em more each side, taken back by an equal
     negative margin, so a Hebrew qof or a g keeps its tail and the item still takes exactly its old box (the rule above,
     repeated inside :is() - exactly what its nested `&` meant - behind the clip test) */
  :is([style*="overflow: "], [style*="overflow-y: "], [style*="line-clamp"]):not([style*="margin"]):is(
    :is(span, div, a, label, time, b, strong, small, em, p, bdi, h1, h2, h3, h4, h5, h6):is(:not([class]), [style*="font-"]):is(
      :root:not([data-ink-off]) :is([style*="align-items: center"], .ink-row):not([style*="flex-direction: column"]) > *,
      :root:not([data-ink-off]) :is([style*="align-items: center"], .ink-row):not([style*="flex-direction: column"]) > [style*="display: contents"] > *
    ):not(:empty, .no-ink,
        [style*="display: flex"], [style*="display: inline-flex"], [style*="display: grid"], [style*="display: inline-grid"], [style*="display: contents"],
        [style*="border"], [style*="background"], [style*="padding"], [style^="height"], [style*="; height"], [style*="min-height"],
        [style*="aspect-ratio"], [style*="text-box"], [style*="position: absolute"], [style*="position: fixed"],
        :has(svg, img, video, canvas, input, select, textarea, button, iframe),
        :has(div, p, ul, ol, li, br, style, table, section, header, footer, h1, h2, h3, h4, h5, h6),
        :has(> [class], [style*="display: block"], [style*="display: flex"], [style*="display: inline-flex"], [style*="display: grid"], [style*="display: inline-grid"], [style*="display: table"], [style*="font-size"])),
    :root:not([data-ink-off]) .ink
  ) { padding-block: calc((1lh - 1cap) / 2 + 0.2em); margin-block: -0.2em; }
}

/* A MARKED BLOCK OF TEXT (10.11, Ohad on the club calendar: "Nothing is vertically center aligned with each other"): an
   event's coloured stripe is its border, so it spans the box - and the box was the line boxes' leading plus padding,
   taller than the words and lower than them. .ink-bar trims every line of the block to its ink (first line's cap top,
   last line's baseline), drops the block padding and keeps the lines apart by a gap instead, so the stripe runs exactly
   from the first cap to the last baseline and the time and the word share one cap-centre. .ink-corner trims a lone
   label (a calendar day number) so its caps sit on its cell's padding edge, not somewhere inside a line box. */
@supports (text-box: trim-both cap alphabetic) {
  :root:not([data-ink-off]) .ink-bar { padding-block: 0 !important; row-gap: 0.4em !important; align-items: center; }
  :root:not([data-ink-off]) .ink-bar * { text-box: trim-both cap alphabetic; padding-block: 0 !important; margin-block: 0 !important; }
  :where(:root:not([data-ink-off]) .ink-bar) > [style*="display: flex"] { display: block !important; }   /* a flex line cannot be trimmed: its words become one block line */
  :root:not([data-ink-off]) .ink-corner { text-box: trim-both cap alphabetic; }
}

/* A SMALLER WORD INSIDE A TRIMMED LINE (10.11: the activity trail's "x3" sat 0.6px under the words it counts). On a
   shared baseline a 10px word's caps centre lower than a 14px word's. Inside an .ink item, an inline child's baseline is
   raised by half the difference of the two cap heights, so both centre on one line: --pcap is the item's own cap height,
   registered as a length so it is computed (to px) where it is set and inherited as that number. */
@property --pcap { syntax: '<length>'; inherits: true; initial-value: 0px; }
@supports (text-box: trim-both cap alphabetic) and (padding-top: 1cap) {
  :root:not([data-ink-off]) .ink { --pcap: 1cap; }
  :root:not([data-ink-off]) .ink > :is(span, b, small, strong, em, bdi) { vertical-align: calc(0.5 * var(--pcap) - 0.5cap) !important; }
}
/* A FRAMED BOX'S TEXT (10.11, Ohad: "Make sure each border is the same vertical size away from the text. Above and below.
   Everywhere and anywhere"). A box's padding is equal above and below, but the text inside it is not: the first line
   carries the font's ascent over the caps, the last line its descent under the baseline - in Nord that put the ink
   1-2px low or high in every chip, button and banner (measured: week chips 12.7 / 13.8, number squares 4.5 / 6.0).
   .ink-box trims a block's first line to its cap height and its last line to its baseline, so the box's own padding IS
   the distance from each border to the ink. Put it on the block that holds the lines (a <button>, a <div>, a block
   <span> inside a flex box). Where text-box is unsupported nothing applies. */
@supports (text-box: trim-both cap alphabetic) {
  :root:not([data-ink-off]) .ink-box { text-box: trim-both cap alphabetic; }
  /* .ink-stack: a flex column of lines (a stat tile centred in a row a neighbour stretched): every line trimmed to its
     ink, the column's gap is the space between them and its padding the space to each border */
  :root:not([data-ink-off]) .ink-stack > * { text-box: trim-both cap alphabetic; }
}
/* A FRAMED BOX'S EDGES ARE ITS INK (14.11, Ohad on the WARM-UP (0) card: "the space above it till the border is much
   larger then the space between the bottom border of the 'add warm-up' till the bottom cyan border beneath it. this
   spaces needs to match"). A box pads evenly, but its first line carries the font's ascent over the caps and its last
   line the descent under the baseline, so a card that opens on words and ends on a button read 3-5px taller on top.
   .ink-band: the element IS its ink (cap top to baseline) - a title or a line whose box should be exactly its letters.
   .inset-trim and the marketing site's one card surface (padding: var(--card-pad)): the box's FIRST child trims its
   first line's top, its LAST child its last line's bottom - only a child of WORDS: never the box itself, and never a
   child holding a control, an image or any inline box (a trimmed line is cut to the letters' baseline, and a button on
   that line would hang out through the padding - measured: 20px under a button became 4), nor a framed / filled /
   padded child (its own box is its edge). Gate: scripts/verify-inset-symmetry.mjs. */
@supports (text-box: trim-both cap alphabetic) {
  :root:not([data-ink-off]) .ink-band { text-box: trim-both cap alphabetic; padding-block: 0 !important; }
  /* a line of facts (FactLine, src/ui.jsx) wearing .ink-band: its words sit in an inner flex row, so the trim goes
     to each fact (and its drawn dot), and wrapped lines get back exactly the leading the trim took (visual audit 1115f:
     the billing KPI subs and the demo footer grew 6-7.5px when the trim stopped reaching the words) */
  :root:not([data-ink-off]) [data-factline].ink-band .fact-row, :root:not([data-ink-off]) .ink-bar [data-factline] .fact-row { row-gap: calc(1lh - 1cap); }   /* .ink-bar trims every descendant: a FactLine inside one gets its leading back the same way (code audit 1115g, the month cell venue) */
  :root:not([data-ink-off]) [data-factline].ink-band .fact-row > *, :root:not([data-ink-off]) [data-factline].ink-band .fact-sep { text-box: trim-both cap alphabetic; }
  /* .ink-start / .ink-end (14.11 round 2): ONE edge of an element is its ink - the first line's cap top, or the last line's
     baseline - and the other keeps its line box, so the gap on that side (a bar over a month label, a number over its
     caption) is untouched. For the first / last line of a box whose children are flex or grid items, which a trim on
     the box cannot reach. */
  :root:not([data-ink-off]) .ink-start { text-box-trim: trim-start; text-box-edge: cap alphabetic; }
  :root:not([data-ink-off]) .ink-end { text-box-trim: trim-end; text-box-edge: cap alphabetic; }
  :root:not([data-ink-off]) .ink-start.ink-end { text-box-trim: trim-both; }
  :root:not([data-ink-off]) :is(.inset-trim, [style*="padding: var(--card-pad)"]) > :first-child:not(:has(button, a, input, select, textarea, img, svg, video, canvas, iframe, [style*="inline-"], [style*="display: flex"], [style*="display: grid"]), [style*="border"], [style*="background"], [style*="padding"], [style*="display: flex"], [style*="display: grid"], [style*="inline-"], button, a, input, select, img, svg) { text-box-trim: trim-start; text-box-edge: cap alphabetic; }
  :root:not([data-ink-off]) :is(.inset-trim, [style*="padding: var(--card-pad)"]) > :last-child:not(:has(button, a, input, select, textarea, img, svg, video, canvas, iframe, [style*="inline-"], [style*="display: flex"], [style*="display: grid"]), [style*="border"], [style*="background"], [style*="padding"], [style*="display: flex"], [style*="display: grid"], [style*="inline-"], button, a, input, select, img, svg) { text-box-trim: trim-end; text-box-edge: cap alphabetic; }
  :root:not([data-ink-off]) :is(.inset-trim, [style*="padding: var(--card-pad)"]) > :first-child:last-child:not(:has(button, a, input, select, textarea, img, svg, video, canvas, iframe, [style*="inline-"], [style*="display: flex"], [style*="display: grid"]), [style*="border"], [style*="background"], [style*="padding"], [style*="display: flex"], [style*="display: grid"], [style*="inline-"], button, a, input, select, img, svg) { text-box-trim: trim-both; }
}
