/*
 * Group headings (brief sections 25 and 26): sticky group headers like the Calendar app.
 * Heading font, sentence case, heading/m, regular weight (the same in all four presets) on a solid bar in the section
 * colour. The bar sticks to the top while its group scrolls and the next group's bar pushes it out (the group wrapper
 * `.group` is its containing block). The module group-heading.js adds .is-stuck, which shows a fine bottom rule.
 * Without JavaScript the bar still sticks, only the rule is missing.
 * Row hover tokens for the text-only list rows (press, series dates, FAQ) live here too.
 */
@layer components {
  :root {
    --group-heading-block: var(--space-12);
    /* Stuck: the text keeps its place, the bar grows upwards, so 16 px of colour sit above the first line at the viewport edge. */
    --group-heading-stuck-top: var(--space-16);
    /*
     * The bar reaches beyond the content edge on both sides (text stays on the edge) so rows and images that lift on hover
     * (4 px up-left, shadow 8 px down-right, see --transform-hover-media / --shadow-hover-media) slide fully under it. 16 px
     * covers lift plus shadow with a margin; on phones the page margin caps it so the bar never exceeds the viewport.
     */
    --group-heading-bleed: min(var(--space-16), var(--layout-margin));
    --group-heading-gap: var(--space-24);
    --list-row-bar-width: 3px;
    --list-row-bar-inset: var(--space-8);
    --list-row-bar-color: var(--color-text-default);
    --list-row-bar-gap: var(--space-12);
    --list-row-focus-reach: var(--space-8);
  }

  /* Focused elements and anchors never end up under a stuck bar. */
  html {
    scroll-padding-top: max(var(--layout-header-height), calc(var(--type-heading-m-line-height) + var(--group-heading-stuck-top) + var(--group-heading-block) + var(--space-16)));
  }

  /*
   * Text-only list rows (press, series dates, FAQ): on hover and keyboard focus a slim bar appears in the page margin,
   * left of the content edge. The text never moves. Bar colour: text/default (warm-gray-950), 17.7:1 against white (needs 3:1).
   * Phones have no margin room (12 px page margin): no bar there, the focus ring stays. Rows opt in with .list-row.
   */
  .list-row {
    position: relative;
  }

  @media (min-width: 768px) {
    .list-row::before {
      content: "";
      position: absolute;
      inset-block: var(--list-row-bar-inset);
      inset-inline-start: calc(-1 * (var(--list-row-bar-gap) + var(--list-row-bar-width)));
      inline-size: var(--list-row-bar-width);
      border-radius: var(--radius-pill);
      background-color: var(--list-row-bar-color);
      opacity: 0;
      transition: opacity var(--duration-fast) ease-out;
      pointer-events: none;
    }

    .list-row:is(:hover, :focus-visible, :has(:focus-visible))::before {
      opacity: 1;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .list-row::before {
      transition: none;
    }
  }

  .group + .group {
    margin-block-start: var(--group-heading-gap);
  }

  .group-heading {
    position: sticky;
    inset-block-start: 0;
    z-index: var(--z-sticky);
    margin: calc(var(--group-heading-block) - var(--group-heading-stuck-top)) calc(-1 * var(--group-heading-bleed)) 0;
    padding: var(--group-heading-stuck-top) var(--group-heading-bleed) var(--group-heading-block);
    border-block-end: var(--border-width-thin) solid transparent;
    background-color: var(--section-bg, var(--color-background-default));
    color: var(--color-text-default);
    font-weight: var(--font-weight-regular);
    font-size: var(--type-heading-m-size);
    line-height: var(--type-heading-m-line-height);
    overflow-wrap: anywhere;
  }

  .group-heading.is-stuck {
    border-block-end-color: var(--color-border-default);
  }

  @media (min-width: 1024px) {
    :root {
      --group-heading-gap: var(--space-32);
    }
  }
}
