/* ==========================================================================
   Header — fixed, transparent over the hero, solid once it ends.

   The logo is rendered as a CSS mask rather than an <img>. The supplied PNG is
   a solid white box with no alpha, so it could never sit on a transparent
   header; tools/build-logo.mjs rebuilds its alpha from luminance and this file
   paints through it with `background-color`. One asset, any colour, and the
   colour can animate between states — which two exported PNGs could not do.
   ========================================================================== */

.header {
  position: fixed;
  inset-inline: 0;
  top: 0;
  z-index: 50;
  height: var(--header-height);
  color: var(--color-fg-inverse);
  transition:
    background-color var(--duration-base) var(--ease-out),
    color var(--duration-base) var(--ease-out),
    border-color var(--duration-base) var(--ease-out);
  border-bottom: 1px solid transparent;
}

/*
   Legibility wash behind the transparent header.

   The hero's closing footage is a pale GCAGRI interface with its own toolbar
   along the top edge, and white nav links over it are unreadable — two
   competing menus in the same 70px. This gradient guarantees contrast over any
   frame, and disappears once the header takes its own solid background.
*/
.header::before {
  content: "";
  position: absolute;
  inset: 0;
  bottom: -2.5rem;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgb(8 9 11 / 0.62) 0%,
    rgb(8 9 11 / 0.34) 55%,
    rgb(8 9 11 / 0) 100%
  );
  transition: opacity var(--duration-base) var(--ease-out);
}

.header[data-solid="true"]::before {
  opacity: 0;
}

.header__inner {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  height: 100%;
  padding-inline: var(--gutter);
  margin-inline: auto;
}

/* --- Solid state --------------------------------------------------------- */

.header[data-solid="true"] {
  color: var(--color-fg);
  background-color: var(--color-paper-050);
  border-bottom-color: rgb(88 72 72 / 0.12);
}

/* Translucency reads as a premium surface, but only where the blur is real —
   without it the copy behind would show through and hurt legibility. */
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .header[data-solid="true"] {
    background-color: rgb(247 245 243 / 0.82);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    backdrop-filter: blur(16px) saturate(1.4);
  }
}

/* --- Logo ---------------------------------------------------------------- */

.header__logo {
  flex: none;
  display: block;
  color: inherit;
}

.header__logo-mark {
  display: block;
  width: var(--header-logo-width);
  /* Intrinsic ratio of the trimmed mask — keeps layout stable before paint. */
  aspect-ratio: 461 / 216;
  background-color: currentColor;
  -webkit-mask-image: url("../../assets/brand/geocarta-mask.png");
  mask-image: url("../../assets/brand/geocarta-mask.png");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: left center;
  mask-position: left center;
  transition: background-color var(--duration-base) var(--ease-out);
}

.header[data-solid="true"] .header__logo-mark {
  background-color: var(--color-brand);
}

/* --- Navigation ---------------------------------------------------------- */

.header__nav {
  margin-inline-start: auto;
}

.header__list {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 2.2vw, 2.25rem);
  list-style: none;
  padding: 0;
}

.header__link {
  position: relative;
  display: block;
  padding-block: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-tight);
  color: inherit;
  opacity: 0.82;
  transition: opacity var(--duration-fast) var(--ease-out);
  white-space: nowrap;
}

.header__link:hover,
.header__link:focus-visible {
  opacity: 1;
}

/* Hairline that grows from the left. Subtler than a colour change and it
   reads as precision rather than decoration. */
.header__link::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  height: 1px;
  background-color: currentColor;
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform var(--duration-base) var(--ease-out);
}

.header__link:hover::after,
.header__link:focus-visible::after {
  transform: scaleX(1);
}

/* --- Actions ------------------------------------------------------------- */

.header__actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.lang {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wide);
}

.lang__current {
  opacity: 1;
}

.lang__sep {
  opacity: 0.35;
}

.lang__link {
  opacity: 0.55;
  transition: opacity var(--duration-fast) var(--ease-out);
}

.lang__link:hover,
.lang__link:focus-visible {
  opacity: 1;
}

/* --- Menu toggle --------------------------------------------------------- */

.header__toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 2.75rem;
  height: 2.75rem;
  margin-inline-end: -0.75rem;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
  color: inherit;
}

.header__toggle-bar {
  display: block;
  width: 22px;
  height: 1.5px;
  margin-inline: auto;
  background-color: currentColor;
  transition:
    transform var(--duration-base) var(--ease-out),
    opacity var(--duration-fast) var(--ease-out);
}

/* Two bars become an X: the pair converge, then counter-rotate. */
.header__toggle[aria-expanded="true"] .header__toggle-bar:first-child {
  transform: translateY(3.25px) rotate(45deg);
}

.header__toggle[aria-expanded="true"] .header__toggle-bar:last-child {
  transform: translateY(-3.25px) rotate(-45deg);
}

/* ==========================================================================
   Collapsed navigation
   ========================================================================== */

@media (max-width: 68rem) {
  .header__nav {
    display: none;
  }

  .header__toggle {
    display: flex;
  }

  .header__actions {
    margin-inline-start: auto;
  }
}

/* --- Full-screen menu ---------------------------------------------------- */

.menu {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-12);
  padding: calc(var(--header-height) + var(--space-8)) var(--gutter) var(--space-16);
  background-color: var(--color-ink-950);
  color: var(--color-fg-inverse);
  overflow-y: auto;
  opacity: 0;
  transition: opacity var(--duration-base) var(--ease-out);
}

/*
   CRITICAL. `display: flex` above defeats the `hidden` attribute — an author
   `display` declaration beats the UA stylesheet's `[hidden] { display: none }`.
   Without this rule the overlay stays in the layout at opacity 0, fixed across
   the whole viewport at z-index 45, and silently swallows every click and
   wheel event in <main> on every page of the site. The header sits above it so
   navigation still worked, which is what made the fault so hard to see.
*/
.menu[hidden] {
  display: none;
}

.menu[data-open="true"] {
  opacity: 1;
}

.menu__list {
  list-style: none;
  padding: 0;
}

.menu__item {
  overflow: clip; /* clips the item's own rise, so it wipes into view */
  border-bottom: 1px solid rgb(246 246 244 / 0.1);
}

.menu__link {
  display: block;
  padding-block: var(--space-4);
  font-size: var(--text-xl);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-tight);
  transform: translate3d(0, 110%, 0);
  transition: transform var(--duration-slow) var(--ease-out);
  /* Staggered by index — set inline by header.js so the cascade survives any
     future change to the number of items. */
  transition-delay: calc(var(--i, 0) * 45ms);
}

.menu[data-open="true"] .menu__link {
  transform: translate3d(0, 0, 0);
}

.menu__lang {
  font-size: var(--text-sm);
  letter-spacing: var(--tracking-wide);
  color: var(--color-fg-inverse-muted);
}

.menu__lang:hover,
.menu__lang:focus-visible {
  color: var(--color-fg-inverse);
}

/* Locks the page behind the overlay without a layout-shifting overflow:hidden. */
body[data-menu-open="true"] {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .header,
  .header__logo-mark,
  .header__link::after,
  .header__toggle-bar,
  .menu,
  .menu__link {
    transition-duration: 1ms;
  }

  .menu__link {
    transform: none;
  }
}
