/* Noria header: screens desktop-header-sticky.jpg (top and scrolled) and mobile-menu-open.jpg. */
@property --header-bg { syntax: "<color>"; inherits: true; initial-value: #e5d5cc; }
@property --header-fg { syntax: "<color>"; inherits: true; initial-value: #282828; }
@property --header-accent { syntax: "<color>"; inherits: true; initial-value: #7a5730; }
@property --header-pill-bg { syntax: "<color>"; inherits: true; initial-value: #424c3d; }
@property --header-pill-fg { syntax: "<color>"; inherits: true; initial-value: #e5d5cc; }

@layer components {
  .skip-link {
    position: absolute;
    top: -100px;
    left: var(--space-4);
    z-index: 1000;
    padding: var(--space-2) var(--space-4);
    background: var(--noria-green);
    color: var(--noria-sand);
    text-decoration: none;
    font-weight: 500;

    &:focus-visible { top: var(--space-4); }
  }

  /* The header keeps its height while the bar inside shrinks, so the page under it never jumps. */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--noria-header-height-top, 8.75rem);
    pointer-events: none;
  }

  .site-header__bar {
    pointer-events: auto;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: min(100%, var(--noria-page));
    margin-inline: auto;
    padding: 2.25rem var(--noria-edge) 1.5rem;
    background: var(--header-bg);
    color: var(--header-fg);
    border-radius: 0;
  }

  /* Scrolled: the dark-green rounded bar with the gold pill. The shape follows the scroll; the colours switch in one step at
     the end of the range, so text and background never pass through a low-contrast mix. Browsers without scroll timelines
     keep the sand bar (D-007). */
  @supports (animation-timeline: scroll()) {
    .site-header__bar {
      animation: site-header-shape linear both, site-header-colours step-end both;
      animation-timeline: scroll(root), scroll(root);
      animation-range: 0 6rem, 0 6rem;
    }
  }

  @keyframes site-header-shape {
    to {
      width: min(100% - 1.5rem, var(--noria-page) - 1.5rem);
      translate: 0 0.75rem;
      padding-block: 1.125rem;
      padding-inline: 1.5rem;
      border-radius: 3rem;
    }
  }

  @keyframes site-header-colours {
    to {
      --header-bg: #424c3d;
      --header-fg: #e5d5cc;
      --header-accent: #d9b88c;
      --header-pill-bg: #b78e5d;
      --header-pill-fg: #2e221b;
    }
  }

  .site-header__logo {
    justify-self: start;
    display: inline-flex;
    color: var(--noria-gold);
    border-radius: 0.25rem;
  }

  .site-header__logo-mark {
    width: 3.625rem;
    height: auto;
    aspect-ratio: 57.5 / 35.4;
  }

  .site-header__nav-list {
    display: flex;
    gap: clamp(1.5rem, 4.2vw, 3.75rem);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .site-header__link {
    position: relative;
    display: inline-block;
    padding-block: 0.5rem;
    font-size: var(--noria-text-small);
    font-weight: 500;
    letter-spacing: var(--noria-track-nav);
    line-height: 1;
    color: inherit;
    text-decoration: none;

    &:hover { text-decoration: underline; text-underline-offset: 0.4em; }

    &[aria-current="page"] {
      font-style: italic;
      font-weight: 600;
      color: var(--header-accent);

      &::after {
        content: "";
        position: absolute;
        left: 0.125rem;
        bottom: -0.125rem;
        width: 0.75rem;
        height: 2px;
        background: currentColor;
      }

      &:hover { text-decoration: none; }
    }
  }

  .site-header__actions {
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 0.125rem;
    height: 3rem;
    padding-inline: 0.875rem;
    background: var(--header-pill-bg);
    color: var(--header-pill-fg);
    border-radius: var(--radius-pill);
  }

  .site-header__action,
  .site-header__cart {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 2.125rem;
    height: 2.75rem;
    color: inherit;
    text-decoration: none;
    border-radius: var(--radius-pill);

    &:hover { opacity: 0.8; }
  }

  .site-header__icon {
    width: 0.875rem;
    height: 0.875rem;
  }

  .site-header__cart-count {
    position: absolute;
    top: 0.25rem;
    right: -0.125rem;
    min-width: 1.125rem;
    padding-inline: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.125rem;
    text-align: center;
    color: var(--noria-brown);
    background: var(--noria-gold-on-dark);
    border-radius: var(--radius-pill);

    &[hidden] { display: none; }
  }

  .site-header__menu-button { display: none; }

  :is(.site-header__bar, .site-menu) :focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
  }

  /* Phones and tablets: logo and hamburger; the menu is a full-screen popover. */
  @media (max-width: 63.99rem) {
    .site-header { height: var(--noria-header-height-top-phone, 6.5rem); }

    .site-header__bar {
      grid-template-columns: 1fr auto;
      padding: 2rem var(--noria-gutter) 1rem;
    }

    .site-header__nav { display: none; }

    /* Phones show logo and hamburger only (mobile-menu-open.jpg); search, account and cart sit in the menu. Only the icon
       links are hidden, not the pill: the cart drawer is a dialog beside the cart link inside the CartWidget island and
       must keep a shown ancestor to open. */
    .site-header__actions {
      position: absolute;
      height: 0;
      padding: 0;
      background: none;
    }

    .site-header__action,
    .site-header__cart { display: none; }

    .site-header__menu-button {
      display: inline-grid;
      place-items: center;
      justify-self: end;
      width: var(--touch-target);
      height: var(--touch-target);
      margin-right: -0.5rem;
      padding: 0;
      background: none;
      border: 0;
      color: inherit;
      cursor: pointer;
    }

    .site-header__burger,
    .site-header__burger::before,
    .site-header__burger::after {
      display: block;
      width: 1.5rem;
      height: 2px;
      background: currentColor;
    }

    .site-header__burger { position: relative; }
    .site-header__burger::before,
    .site-header__burger::after { content: ""; position: absolute; left: 0; }
    .site-header__burger::before { top: -0.5rem; }
    .site-header__burger::after { top: 0.5rem; }
  }

  .site-menu {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    padding: 6.5rem 3.75rem 3rem;
    overflow-y: auto;
    border: 0;
    background: var(--noria-green);
    color: var(--noria-sand);

    &::backdrop { background: var(--noria-green); }
  }

  .site-menu__close {
    position: absolute;
    top: 2rem;
    right: var(--noria-gutter);
    display: grid;
    place-items: center;
    width: var(--touch-target);
    height: var(--touch-target);
    padding: 0;
    font-size: 2.75rem;
    font-weight: 300;
    line-height: 1;
    color: var(--noria-gold);
    background: none;
    border: 0;
    cursor: pointer;
  }

  .site-menu__list {
    display: grid;
    gap: 1.75rem;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .site-menu__link {
    position: relative;
    display: inline-block;
    font-size: 1.5rem;
    font-weight: 500;
    letter-spacing: var(--noria-track-nav);
    line-height: 1.2;
    color: var(--noria-sand);
    text-decoration: none;

    &[aria-current="page"] {
      font-style: italic;
      font-weight: 600;
      color: var(--noria-gold-on-dark);

      &::after {
        content: "";
        position: absolute;
        left: 0.125rem;
        bottom: -0.5rem;
        width: 1rem;
        height: 2px;
        background: currentColor;
      }
    }
  }

  .site-menu__actions {
    display: inline-flex;
    gap: 0.5rem;
    margin-top: 3rem;
    padding: 0.375rem 1.25rem;
    background: var(--noria-gold);
    color: var(--noria-brown);
    border-radius: var(--radius-pill);
  }

  .site-menu__action {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: var(--touch-target);
    height: var(--touch-target);
    color: inherit;

    .site-header__icon { width: 1.125rem; height: 1.125rem; }
  }

  .site-menu__count {
    position: absolute;
    top: 0.25rem;
    right: 0.125rem;
    min-width: 1.125rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.125rem;
    text-align: center;
    color: var(--noria-sand);
    background: var(--noria-green);
    border-radius: var(--radius-pill);
  }

  .site-menu__locales { margin-top: 2.5rem; }

  .locale-switcher__list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .locale-switcher__link {
    display: inline-block;
    padding-block: 0.5rem;
    font-size: var(--noria-text-small);
    font-weight: 500;
    letter-spacing: var(--noria-track-nav);
    color: inherit;
  }
}
