/**
 * @info The header — breadcrumb, languages, and on a question the stuck question
 * @path assets/css/snippets/header.css
 * @snippet site/snippets/header.php
 *
 * Sticky. Scrolling down, the breadcrumb and the languages shrink to the
 * small size and a rule appears under them; once the big question has gone
 * ([data-here], timed by the <h1>'s view timeline, templates/question.css),
 * it comes back small and bold under the rule with Text / Links / …, closed
 * by a second rule. Scroll-driven, no script. Without scroll timelines
 * (Firefox for now) or with reduced motion: a plain sticky breadcrumb.
 */

body > header {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: var(--space-gap);
  padding: var(--space-gutter) var(--space-gutter) var(--space-rule);
  background: var(--color-white);
}

/*----------  Breadcrumb: logo / Fragen / 2026  ----------*/

[data-crumbs],
[data-langs] {
  font-size: var(--size-text);
  line-height: 1.25;
  letter-spacing: -.01em;
}

[data-crumbs] {
  position: relative;   /* the questions' list hangs from here */
  flex: 1 1 auto;
  min-inline-size: 0;   /* may shrink below its content: the crumbs truncate */

  /* one line at every width: logo and menu keep their size, the crumbs after
     them give way with an ellipsis, the one in the middle first. The page's
     heading says the same in full */
  & > ol {
    display: flex;
    align-items: center;
    gap: .4em;
    white-space: nowrap;
  }

  & > ol > li {
    flex: none;
    min-inline-size: 0;
  }

  /* a <details> is a block: its crumb is a row of its slash and itself */
  & > ol > li:has(details) { display: flex; align-items: center; }

  & > ol > li:not(:first-child, :has(details)) {
    flex: 0 1 auto;
    min-inline-size: 4.5em;   /* a word's start stays readable */
    overflow: hidden;
    text-overflow: ellipsis;

    @media (width < 22.5rem) { min-inline-size: 2.5em; }   /* 320px: room for the languages */
  }

  /* the middle one gives way first; on a narrow phone it goes, the heading
     under the header names the question anyway */
  & > ol > li:not(:first-child, :has(details), :last-child) {
    flex-shrink: 4;

    @media (width < 30rem) { display: none; }
  }

  /* the menu's list wraps again */
  & [data-questions] { white-space: normal; }

  & > ol > li + li::before {
    content: "/" / "";
    margin-inline-end: .4em;
  }

}

/* "Fragen" and the language: a <details>, its summary underlined like a link */
:is([data-crumbs], [data-langs]) {
  & summary {
    display: inline;
    cursor: pointer;
    list-style: none;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: .15em;

    &::-webkit-details-marker { display: none; }
  }

  & summary:hover,
  & details[open] summary { text-decoration: none; }
}

[data-logo] {
  display: block;
  inline-size: var(--size-logo);
  margin-inline-end: .2em;

  & img { inline-size: 100%; }
}

/* every year's question, under "Fragen" */
[data-questions] {
  position: absolute;
  z-index: 1;   /* over the stuck question */
  inset-block-start: calc(100% + var(--space-rule));
  inset-inline-start: 0;
  inline-size: min(32rem, 100%);
  padding: var(--space-rule);
  border: var(--rule);
  background: var(--color-white);
  font-size: var(--size-ui);
  line-height: 1.35;

  & li + li { border-block-start: var(--rule); }

  & a {
    display: grid;
    grid-template-columns: 3.5em minmax(0, 1fr);
    gap: var(--space-gap);
    padding-block: .5rem;
    text-decoration: none;
  }

  & a:hover span,
  & a[aria-current] span {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: .15em;
  }
}

/*----------  Languages: DE, opening Deutsch / English / …  ----------*/

[data-langs] {
  position: relative;   /* the list hangs from here, right-aligned */
  flex: none;
  white-space: nowrap;   /* the globe and DE stay together */

  /* the globe: black lines, as tall as a capital, shrinking with the text */
  & [data-globe] {
    display: inline-block;
    inline-size: .8em;
    block-size: .8em;
    margin-inline-end: .3em;
    vertical-align: -.05em;
    fill: none;
    stroke: currentColor;
    stroke-width: 1;
    vector-effect: non-scaling-stroke;

    & * { vector-effect: non-scaling-stroke; }
  }

  & ul {
    position: absolute;
    z-index: 1;   /* over the stuck question */
    inset-block-start: calc(100% + var(--space-rule));
    inset-inline-end: 0;
    inline-size: max-content;   /* as wide as its longest entry, no wrapping */
    min-inline-size: 10rem;
    padding: var(--space-rule);
    border: var(--rule);
    background: var(--color-white);
    font-size: var(--size-ui);
    line-height: 1.35;
  }

  & li + li { border-block-start: var(--rule); }

  /* "Help translate": no language, so set off by a heavier gap */
  & [data-help] { margin-block-start: var(--space-rule); }

  & a {
    display: block;
    padding-block: .5rem;
    text-decoration: none;
  }

  & a:hover,
  & a[aria-current] {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: .15em;
  }
}

/*----------  Small screens: small type, the menus as panels  ----------*/

/* Below the grid's breakpoint the breadcrumb starts at the small size it
   otherwise shrinks to, and both menus drop as a full-width panel from the
   header's lower edge instead of hanging from their word. The header is
   sticky, so it is the panels' containing block. */
@media (width < 52rem) {
  [data-crumbs],
  [data-langs] {
    position: static;
    font-size: var(--size-ui);
  }

  :is([data-questions], [data-langs] ul) {
    inset-block-start: 100%;
    inset-inline: var(--space-gutter);
    inline-size: auto;
    min-inline-size: 0;
  }
}

/*----------  Stuck  ----------*/

[data-here] { display: none; }

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: scroll()) {

    html { scroll-padding-block-start: 9rem; }
    body { timeline-scope: --question; }

    body > header {
      border-block-end: 1px solid transparent;
      animation: header-compact linear both, header-rule linear both;
      animation-timeline: scroll(root), scroll(root);
      animation-range: 0 8rem, 0 1px;
    }

    /* the margin gives back what the header loses, so the page doesn't jump */
    @keyframes header-compact {
      to {
        padding-block-start: var(--space-rule);
        margin-block-end: calc(var(--space-gutter) - var(--space-rule) + var(--size-logo) - var(--size-logo-stuck));
      }
    }
    @keyframes header-rule { to { border-block-end-color: var(--color-rule); } }

    [data-crumbs],
    [data-langs] { animation: crumbs-compact linear both; animation-timeline: scroll(root); animation-range: 0 8rem; }
    [data-logo]  { animation: logo-compact linear both;   animation-timeline: scroll(root); animation-range: 0 8rem; }
    @keyframes crumbs-compact { to { font-size: var(--size-ui); } }
    @keyframes logo-compact   { to { inline-size: var(--size-logo-stuck); } }

    [data-here] {
      position: absolute;
      inset-block-start: calc(100% + 1px);   /* below the header's rule, not over it */
      inset-inline: 0;
      z-index: 0;
      display: grid;
      grid-template-columns: repeat(12, minmax(0, 1fr));
      column-gap: var(--space-gap);
      padding: var(--space-rule) var(--space-gutter);
      border-block-end: var(--rule);
      background: var(--color-white);
      animation: here-in linear both;
      animation-timeline: --question;
      animation-range: exit 60% exit 100%;

      & > * { grid-column: 1 / -1; }
      & > p { font-weight: 700; }
      & [data-toc] { margin-block-start: .2em; }

      @media (width >= 52rem) {
        & > * { grid-column: 4 / 13; }
      }
    }

    @keyframes here-in {
      from { opacity: 0; visibility: hidden; }
      to   { opacity: 1; visibility: visible; }
    }
  }
}
