/*
 * Page head: breadcrumb, H1, info line, intro, optional anchor chips, and one of two image variants:
 *  - aside (page-head--aside): image next to the text on desktop, above it on phones;
 *  - straddle (page-head--straddle): image below the text, lying across the transition into the next section.
 * All spacing comes from the --page-head-* tokens in layout.css (rules in docs/design-backport.md).
 */
@layer components {
  /* The home hero (hero.css) is the page head of the home page: same rhythm as the aside variant. */
  .section:is(.page-head, .hero) {
    padding-block: var(--page-head-pad-top) var(--page-head-pad-bottom);
  }

  /* Followed by a section in the same tone (e.g. a hero image on Der Ort): no wave, the head flows into it. */
  .section.page-head:has(+ .section[data-bg="strong"]) {
    padding-block-end: var(--page-head-gap-media);
  }

  /* First section after the head: one value for every page type; the same-tone case above keeps its own rule (layouts.css). */
  :is(.page-head, .hero) + .section {
    padding-block-start: var(--page-head-next-pad);
  }

  /* The padding alone sets the distance: no extra margin on the section's first element (e.g. the team's card grid). */
  :is(.page-head, .hero) + .section > .container > :first-child {
    margin-block-start: 0;
  }

  .page-head__text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    min-inline-size: 0;
  }

  /*
   * Rule "wide image, narrower content" (design-backport.md): with data-content the text column is as wide as the
   * content below and centred in the head container, so its left edge equals the left edge of that content. The
   * image / media keeps the head container width. On narrow viewports both widths collapse to 100 %.
   */
  .page-head__text[data-content] {
    inline-size: 100%;
    margin-inline: auto;
  }

  .page-head__text[data-content="wide"] { max-inline-size: var(--layout-container-wide); }
  .page-head__text[data-content="medium"] { max-inline-size: var(--layout-container-medium); }
  .page-head__text[data-content="text"] { max-inline-size: var(--layout-container-text); }

  /* Children never grow past the column: a long breadcrumb or title wraps instead of widening the page (reflow at 320 px). */
  .page-head__text > * {
    max-inline-size: 100%;
  }

  .page-head__text > * + * {
    margin-block-start: var(--page-head-gap-extra);
  }

  .page-head__text > .breadcrumb + * {
    margin-block-start: var(--page-head-gap-meta);
  }

  /* Status badge (past events) above the title; it stays with it. */
  .page-head__badge {
    margin: 0;
  }

  .page-head__text > .page-head__badge + * {
    margin-block-start: var(--page-head-gap-eyebrow);
  }

  .page-head__text > .page-head__title + .page-head__intro {
    margin-block-start: var(--page-head-gap-intro);
  }

  .page-head__title {
    overflow-wrap: anywhere;
  }

  /* Info line under the title ("Teil der Reihe Dumte Filmzeit · Film · Bildung · Kultur", or a role or source): the same
     quiet style as the breadcrumb, so the head has three type styles only (small lines, title, intro). Links are
     underlined, not bold. */
  .page-head__text > .page-head__title + .page-head__info {
    margin-block-start: var(--space-12);
  }

  .page-head__info {
    margin: 0;
    color: var(--color-text-subtle);
    font-weight: var(--font-weight-regular);
    font-size: var(--type-label-s-size);
    line-height: var(--type-label-s-line-height);
  }

  .page-head__info-sep {
    padding-inline: var(--space-4);
  }

  .page-head__info a {
    color: var(--color-text-default);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
  }

  .page-head__info a:hover {
    text-decoration-thickness: 2px;
  }

  .page-head__text > .page-head__info + .page-head__intro {
    margin-block-start: var(--space-16);
  }

  .page-head__intro {
    max-inline-size: var(--layout-container-text);
    color: var(--color-text-subtle);
    font-size: var(--text-intro-size);
    line-height: var(--text-intro-line-height);
  }

  .page-head__chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-8);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  /* ---------- aside: above the text on phones, right column on desktop ---------- */
  .page-head--aside > .container {
    display: grid;
    gap: var(--page-head-gap-aside);
  }

  .page-head__aside {
    order: -1;
    min-inline-size: 0;
  }

  /* Phones: breadcrumb first, then the image, then title, info line and intro. The text column dissolves into the grid. */
  @media (max-width: 1023.98px) {
    .page-head--aside > .container {
      gap: 0;
    }

    .page-head--aside .page-head__text {
      display: contents;
    }

    .page-head--aside .page-head__text > .breadcrumb {
      order: -2;
    }

    .page-head--aside .page-head__aside {
      margin-block-end: var(--page-head-gap-aside);
    }

    .page-head--aside .page-head__text > .breadcrumb + * {
      margin-block-start: 0;
    }

    .page-head--aside:has(.breadcrumb) .page-head__aside {
      margin-block-start: var(--page-head-gap-meta);
    }
  }

  @media (min-width: 1024px) {
    .page-head--aside > .container {
      grid-template-columns: repeat(5, minmax(0, 1fr)) repeat(7, minmax(0, 1fr));
      column-gap: var(--layout-grid-gap);
      align-items: center;
    }

    .page-head--aside .page-head__text {
      grid-column: 1 / span 5;
    }

    /* The text keeps its five columns; the image gives up one column, so the gap is the gutter plus one column (see docs/layout-widths.md). */
    .page-head__aside {
      order: 0;
      grid-column: 7 / span 6;
    }
  }

  /*
   * ---------- straddle: the image lies across the transition into the next section ----------
   * Same mechanism as the "Bild über den Übergang" option of content sections (layouts.css): the head ends flush
   * with the image, behind the lower part of the image a full-bleed band in the next section's tone
   * (--straddle-bg) starts at --straddle-split, and the wave in the head's tone is drawn over that band.
   */
  .section.page-head--straddle {
    --straddle-split: 60%;
    --straddle-bg: var(--color-background-default);
    padding-block-end: 0;
    overflow-x: clip;
  }

  .page-head--straddle[data-straddle="subtle"] { --straddle-bg: var(--color-background-subtle); }
  .page-head--straddle[data-straddle="muted"] { --straddle-bg: var(--color-background-muted); }
  .page-head--straddle[data-straddle="accent"] { --straddle-bg: var(--color-background-accent); }

  .section.page-head--straddle::after {
    display: none;
  }

  .page-head__media {
    position: relative;
    z-index: var(--z-content);
    margin-block-start: var(--page-head-gap-media);
  }

  .page-head__media::before,
  .page-head__media::after {
    content: "";
    position: absolute;
    z-index: var(--z-below);
    inset-inline: -100vmax;
    pointer-events: none;
  }

  .page-head__media::before {
    inset-block: var(--straddle-split) 0;
    background-color: var(--straddle-bg);
  }

  .page-head__media::after {
    top: calc(var(--straddle-split) - 1px);
    block-size: calc(var(--layout-wave-height) + 1px);
    background-color: var(--section-bg);
    -webkit-mask: url("../../svg/wave.svg") center / 100% 100% no-repeat;
    mask: url("../../svg/wave.svg") center / 100% 100% no-repeat;
  }

  @media (min-width: 1024px) {
    .section.page-head--straddle {
      --straddle-split: 50%;
    }
  }
}
