/**
 * Fact header. Measured from dal.ca's program pages: title 48px above the
 * tagline, 32px between the two halves, a 16px grid inside the box of facts
 * and 16px between the box and each button.
 *
 * The root is the size container; .fact-header__inner responds to it.
 */
.fact-header {
  container: fact-header / inline-size;
}

.fact-header__inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-l);
  width: 100%;
  max-width: var(--page-max-width);
  margin-inline: auto;
  padding: var(--space-s) var(--page-gutter) var(--space-xl);
}

.fact-header--has-background .fact-header__inner {
  padding-block: var(--space-l);
}

.fact-header__intro {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

.fact-header__title {
  font-size: var(--font-size-display);
  font-weight: var(--font-weight-black);
}

.fact-header__tagline {
  font-size: var(--font-size-lead);
  line-height: var(--line-height-snug);
}

/* A size container of its own: the facts respond to the width of this half. */
.fact-header__aside {
  display: flex;
  flex-direction: column;
  gap: var(--space-s);
  min-width: 0;
  container-type: inline-size;
}

/* A person's photo: square, cropped from the top so faces stay in. */
.fact-header__media {
  width: min(100%, 17.5rem);
}

.fact-header__image {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: cover;
  object-position: center top;
}

/*
 * Image beside the facts (dal.ca's program pages): a wide picture over the
 * facts while the header is narrow; from 36rem a column to their right, as
 * tall as the facts and buttons together, cropped to fit.
 */
.fact-header--image-beside .fact-header__media {
  width: 100%;
}

.fact-header--image-beside .fact-header__image {
  aspect-ratio: 3 / 2;
  object-position: center;
}

/* Only when there are facts or buttons for it to stand beside: on its own
 * the picture stays a wide one. */
@container fact-header (min-width: 36rem) {
  .fact-header--image-beside .fact-header__aside:has(> .fact-header__facts, > .fact-header__actions > *) {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    grid-auto-rows: min-content;
    column-gap: var(--space-s);
  }

  .fact-header--image-beside .fact-header__aside:has(> .fact-header__facts, > .fact-header__actions > *) > :not(.fact-header__media) {
    grid-column: 1;
  }

  /* The picture takes its height from the rows beside it, not the other
   * way round. */
  .fact-header--image-beside .fact-header__aside:has(> .fact-header__facts, > .fact-header__actions > *) > .fact-header__media {
    position: relative;
    grid-row: 1 / span 2;
    grid-column: 2;
    height: 100%;
    min-height: 10rem;
  }

  .fact-header--image-beside .fact-header__aside:has(> .fact-header__facts, > .fact-header__actions > *) > .fact-header__media > .fact-header__image {
    position: absolute;
    inset: 0;
    height: 100%;
    aspect-ratio: auto;
  }
}

/* Without a picture, facts or buttons the title stands alone. */
.fact-header__aside:not(:has(> .fact-header__media, > .fact-header__facts, > .fact-header__actions > *)) {
  display: none;
}

/* The box of facts takes the colours of a button on the same background
 * (gray on white, as on dal.ca), so it stands out on every surface. Links and
 * the focus ring inside it follow the box, not the surface around it. */
.fact-header__facts {
  --link-color: var(--control-fg);
  --focus-ring-color: var(--control-fg);
  display: grid;
  grid-template-columns: fit-content(45%) minmax(0, 1fr);
  gap: var(--space-s);
  margin: 0;
  padding: var(--space-s);
  background-color: var(--control-bg);
  color: var(--control-fg);
}

.fact-header__actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-s);
}

.fact-header__actions:not(:has(*)) {
  display: none;
}

/* Labels share a 200px column once the box has room for it; below that the
 * column is as wide as the longest label, up to 45% of the box. */
@container (min-width: 28rem) {
  .fact-header__facts {
    grid-template-columns: 12.5rem minmax(0, 1fr);
  }
}

/* Side by side from 60rem, as on dal.ca; the columns line up with a Titled
 * section's heading and content. */
@container (min-width: 60rem) {
  .fact-header__inner {
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    align-items: start;
  }
}
