/*
 * Intro Header.
 *
 * The band's height and the headline's size are both derived from one design
 * width, so they scale together and cannot drift apart at any viewport. The
 * Neither ratio is arbitrary: the band's frames the video (see
 * --hero-anchor) and the headline's is set by its longest line (see
 * --hero-type).
 *
 * Successor's faces are declared in styles/fonts.css, loaded once for the whole
 * site, so this file only uses the stack.
 */

.wp-block-tsm-intro-header {
  /*
   * Scales with the viewport between 800 and 1920, and is pinned outside that
   * range: below 800 the video crops rather than shrinking, above 1920 nothing
   * grows any further.
   */
  --hero-width: clamp(800px, 100vw, 1920px);
  --hero-band: 0.15;
  --hero-leading: 1;

  /*
   * The type ratio is set by the longest line, not by the mockup. "End with a
   * fortune." renders at 10.181x its font size in Successor Bold, so at the
   * largest size this scales to it needs a 958px line — inside the 1024px
   * column below, with about 6% to spare. The mockup's 0.0688 measured true at
   * 1280 but kept growing past the column, and the line dropped in two on a
   * wide screen.
   *
   * Three numbers are tied here: max ratio = measure / (10.181 * 1920), so
   * 0.0524 is the ceiling today. Widening --hero-measure raises it, and
   * changing the bold face changes the multiplier — Successor Black was
   * 10.675x, which is 4.6% wider and put the ceiling at 0.0499.
   */
  --hero-type: 0.049;

  /*
   * Which slice of the square the band shows, measured from its top edge as a
   * share of the video's height. The two things worth framing sit at fixed
   * heights and never move: the icons run across 29–38.5%, and the opening dot
   * and line are on the centre line at 50%. A window starting at 25% puts the
   * icons across the top third and the dot at about three-quarters down, clear
   * of the headline. 0% would top-align the video, which drops the dot out of
   * shot entirely and pushes the icons down into the words.
   *
   * --hero-band cannot go much below 0.30 while this holds: the headline
   * covers the bottom (1.09 - 0.16) * --hero-type of the band, and at
   * 0.297 the dot disappears behind it.
   */
  --hero-anchor: 25%;

  /* How far the band's lower edge falls past the first baseline. */
  --hero-overlap: 0.095em;

  /*
   * The column the headline shares with everything below it, and the gutter
   * that column keeps at the edges. Both come from the global presets now that
   * contentSize and root padding are filled in — the fallbacks are the values
   * theme.json holds, so the type ratio above still describes a 1024px column
   * if the properties ever go missing.
   */
  --hero-measure: var(--wp--style--global--content-size, 64rem);
  --hero-gutter: var(
    --wp--style--root--padding-right,
    clamp(1rem, 4vw, 2.5rem)
  );

  /*
   * The video's own last frame. Anywhere this colour meets the video it has to
   * be exactly right, so it is stated here rather than taken from the palette,
   * whose yellow is a slightly different value.
   */
  --hero-settled: #f5f63f;
}

.wp-block-tsm-intro-header__frame {
  display: grid;
  place-items: start center;
  height: calc(var(--hero-width) * var(--hero-band));

  /* The video's first frame, so there is no flash before it starts. */
  background-color: #000;

  /* clip rather than hidden: nothing here should become a scroll container. */
  overflow: clip;
}

/*
 * A square in a wide band. Below 800px it keeps rendering at 800 and is cropped
 * left and right, which is what object-fit can't do on its own — `cover` on a
 * square source in a wide frame only ever crops top and bottom, so the
 * composition would shrink on a phone instead of cropping.
 */
.wp-block-tsm-intro-header__video {
  display: block;
  grid-area: 1 / 1;
  width: max(100%, 800px);
  max-width: none;
  height: auto;
  aspect-ratio: 1;

  /*
   * Percentages here resolve against the video's own height, and the band is
   * always 41% of that height, so one number holds the framing at every
   * viewport.
   */
  translate: 0 calc(var(--hero-anchor) * -1);
}

.wp-block-tsm-intro-header__heading {
  position: relative;
  z-index: 1;
  box-sizing: content-box;
  max-width: var(--hero-measure);
  margin-block: calc((var(--hero-leading) * 1em - var(--hero-overlap)) * -1) 0;
  margin-inline: auto;
  padding-inline: var(--hero-gutter);
  font-family: var(--font-stack-headings);
  font-size: clamp(24px, calc(var(--hero-width) * var(--hero-type)), 88px);
  font-weight: 300;
  line-height: var(--hero-leading);

  /* A missing face must not be faked: the weights are the design. */
  font-synthesis: none;
  transition: opacity 600ms ease-out;
}

.wp-block-tsm-intro-header__heading strong,
.wp-block-tsm-intro-header__heading b {
  font-weight: 700;
}

/*
 * `is-armed` is added by the server, never by JS: hiding the headline from a
 * script would show it for as long as hydration takes, and hiding it in CSS
 * alone would lose it for anyone without JS. render.php pairs this with a
 * <noscript> block that undoes it.
 */
.wp-block-tsm-intro-header.is-armed .wp-block-tsm-intro-header__heading {
  opacity: 0;
}

.wp-block-tsm-intro-header.is-revealed .wp-block-tsm-intro-header__heading {
  opacity: 1;
}

/*
 * The video is not going to play — refused, failed, or reduced motion. Its last
 * frame is a flat colour, so the band paints that colour itself and the
 * headline arrives without a fade.
 */
.wp-block-tsm-intro-header.is-still .wp-block-tsm-intro-header__frame {
  background-color: var(--hero-settled);
}

.wp-block-tsm-intro-header.is-still .wp-block-tsm-intro-header__video {
  display: none;
}

.wp-block-tsm-intro-header.is-still .wp-block-tsm-intro-header__heading {
  opacity: 1;
  transition: none;
}

@media (prefers-reduced-motion: reduce) {
  .wp-block-tsm-intro-header__heading {
    transition: none;
  }
}
