/* Bloom: the ink coming up out of the paper as the page opens (kit/bloom.js). Each letter comes up as a
   hairline, Inter at its thinnest, and thickens in place to its own weight. While it's thin, the wet ink
   feathers out along the paper's fibers, then the letter grows over it and takes it in. The text's ink edge
   is a filter on its parent (kit/ink.js), so each piece of text is wrapped in .ink-in and only the wrapper
   changes, and once it's unwrapped the page is exactly as it was. When the logo is clicked, the same runs
   backwards. */

/* How far into its fill each piece of text or drawing is, from 0 to 1 */
@property --ink-in {
  syntax: '<number>';
  inherits: true;
  initial-value: 1;
}

/* How far into its fill a link's highlight in the words is, on its own, a little after its words */
@property --mark-in {
  syntax: '<number>';
  inherits: true;
  initial-value: 1;
}

/* Waiting for Inter, on a slow first visit: nothing shows yet, and nothing changes size, so the letters
   are still where Bloom measures them */
.ink-waiting :is(.hero-heading, .hero-body, .hero-actions, .footer) {
  opacity: 0;
}

/* A whole paragraph's wrapper is a block, the same size as the paragraph */
.ink-in-block {
  display: block;
}

/* --thick is how far through its thickening a letter is, from Inter's thinnest to its own weight. Most of
   the weight comes early, so there's a body for the ink to bleed from. It moves every frame: steps, even
   fine ones, land as small jumps. --stroke is the letter's stroke as a part of its finished width. The bleed
   is held under two limits: half the stroke, or a blur that wide would thin the letter past the ink edge's
   cut and break it up, and half the room left to 85% of the finished stroke, so the letter grows over all
   of it and it's gone by about 80% of the thickness. In em, so a heading bleeds as far as its size. The
   hairline comes in through the ink edge first, so it starts from nothing. */
.ink-blooming .ink-in {
  --thick: pow(var(--ink-in), 0.6);
  --stroke: calc(0.25 + 0.75 * var(--thick));
  --bleed: max(0, min(calc(0.5 * var(--stroke)), calc((0.85 - var(--stroke)) / 2)));
  font-weight: calc(100 + (var(--swell-to, 500) - 100) * var(--thick));
  /* The lines are held by bloom.js's own breaks, where they broke when finished */
  white-space: nowrap;
  opacity: clamp(0, calc(var(--ink-in) * 5), 1);
  filter: blur(calc(var(--bleed) * 0.15em));
}

/* The heading thickens at a steadier pace than the rest and shows sooner, so it comes up from its hairline
   instead of arriving half done */
.ink-blooming .hero-heading .ink-in {
  --thick: pow(var(--ink-in), 0.85);
  opacity: clamp(0, calc(var(--ink-in) * 8), 1);
}

/* The ink is darker while it's wet */
.ink-blooming :is(.hero-heading, .hero-body) .ink-in {
  color: color-mix(in srgb, var(--color-text-primary) calc(100% - 140% * var(--bleed)), black);
}

/* A link in the words has its own weight in the kit, so it'd stay at full weight while the words round it
   thicken, and come out bold first. It thickens with them instead, and its highlight follows them. */
.ink-blooming .ink-in a.link {
  font-weight: inherit;
}

.ink-blooming .ink-in a.link::after {
  opacity: var(--mark-in);
}

/* Words added after, over a caret: the caret goes down first, then the pen writes the words in over it,
   stroke by stroke (kit/tokens.css) */
.ink-blooming .mark-insert > .mark {
  opacity: clamp(0, calc(var(--ink-in) * 8), 1);
}

.ink-blooming .mark-insert > .mark-written {
  --pen: calc((var(--ink-in) - 0.15) / 0.85);
}

/* In WebKit the words' ink is drawn on the GPU (kit/ink-gl.js), which Bloom drives instead, so the words
   themselves, see-through, keep their own weight, lines and colour, and nothing about them is worked out
   again. The GPU darkens the wet ink itself, from their own colour. */
.ink-blooming .ink-gl .ink-in {
  color: inherit;
  font-weight: inherit;
  white-space: inherit;
  opacity: 1;
  filter: none;
}

/* Each letter in a box at its finished place (bloom.js). A thin letter starts half its missing width in
   from the left, centered on the full letter. */
.ink-letter {
  display: inline-block;
  box-sizing: border-box;
  padding-left: calc((1 - var(--thick, 1)) * var(--grow, 0px));
}

/* The buttons' marker thickens the same way: each stroke starts as a line and widens to the marker, at
   the widths in buttons.css */
.ink-blooming .btn-drawn > .btn-drawn-marks path {
  stroke-width: calc(6px * var(--ink-in));
}

.ink-blooming .btn-drawn > .btn-drawn-marks .btn-shade-rim {
  stroke-width: calc(1.5px * var(--ink-in));
}

.ink-blooming .btn-drawn > .btn-drawn-marks .btn-shade-shine {
  stroke-width: calc(2px * var(--ink-in));
}

/* And thinly first, through the same filter. Not the logo, which is always there. */
.ink-blooming .btn-drawn > .btn-drawn-marks path {
  stroke-opacity: calc(0.08 + 0.92 * var(--ink-in));
}
