/*
 * The sticky glass header, Variant A (approved by Ariel, 9 November 2026), on every page with the header. Loaded after
 * the page's own stylesheets; header.js only toggles classes on the header (.top), never styles.
 *
 * At the top of the page the header is exactly today's (home.css, page.css). Once the visitor has scrolled more than
 * 24 px (.is-stuck), it becomes a slim fixed bar, 60 px tall on wide screens and 56 px on phones:
 * - Light glass: rgba(255, 253, 248, 0.55), blur(20px) saturate(160%), an ink hairline and a soft shadow.
 * - Over the dark parts of a page (.on-dark: any element marked data-header-tone="dark"), the same glass in ink,
 *   rgba(20, 32, 26, 0.6), with the light logo images (the footer's) and a dark Menu pill with light text.
 * - The lockup is smaller and starts where it starts at rest (--bar-gut, set beside each page's header rules), so it
 *   never moves sideways.
 * - "by" is a little stronger in the bar (ink 0.84, white 0.94 on dark) so it keeps 4.5:1 over the busiest photographs.
 * The glass lives on ::before, behind the header's content, so the header itself never becomes a backdrop root: the
 * Menu pill and the panel keep blurring the page, not an empty box. The short fade as the bar takes over runs on
 * ::before and the children (.is-fading), never on the header, and header.js removes the class when it ends: an
 * opacity animation left on the menu would make its open panel see-through.
 * Reduced motion: no fade. Reduced transparency, or no backdrop-filter: a solid, near-opaque bar.
 */

:root {
  --bar-h: 60px;
  --bar-tint: rgba(255, 253, 248, 0.55);
  --bar-tint-dark: rgba(20, 32, 26, 0.6);
  --bar-line: rgba(20, 32, 26, 0.09);
  --bar-line-dark: rgba(255, 255, 255, 0.1);
  --bar-solid: rgba(251, 248, 242, 0.97);
  --bar-solid-dark: rgba(20, 32, 26, 0.96);
  --bar-light: #fbfaf7;
}

@media (max-width: 599px) {
  :root {
    --bar-h: 56px;
  }
}

/* Anchored links and keyboard focus land below the bar. Only with scripting on: without it there is no bar. */
@media (scripting: enabled) {
  html {
    scroll-padding-top: calc(var(--bar-h) + 12px);
  }
}

/* The light logo images (the footer's) wait in the lockup until the bar is over a dark ground. */
.top .lockup-on-dark {
  display: none;
}

/* ---------------------------------------------------------------- the bar */

.top.is-stuck {
  position: fixed;
  z-index: 55;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--bar-gut, 48px), env(safe-area-inset-right)) 0
    max(var(--bar-gut, 48px), env(safe-area-inset-left));
  /* The intro fade stops here: an animating header would be its own backdrop root and the glass would see nothing. */
  animation: none;
}

.top.is-stuck::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: var(--bar-tint);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  border-bottom: 1px solid var(--bar-line);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 10px 30px -18px rgba(40, 45, 25, 0.35);
  transition:
    background-color 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease;
}

.top.is-stuck.is-fading::before,
.top.is-stuck.is-fading > * {
  animation: bar-fade 0.22s var(--ease) both;
}

@keyframes bar-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* A smaller lockup in the bar. */
.top.is-stuck .lockup {
  --lh: 28px;
  --by: 12px;
  --ph: 13px;
}

.top.is-stuck .lockup-by,
.top.is-stuck .menu-btn {
  transition:
    color 0.3s ease,
    background-color 0.3s ease,
    border-color 0.3s ease;
}

.top.is-stuck .lockup-by {
  color: rgba(20, 32, 26, 0.84);
}

/* The open panel never runs past the foot of the screen: on a short screen its links scroll inside it. */
.top.is-stuck .menu-panel {
  max-height: calc(100vh - var(--bar-h) - env(safe-area-inset-top) - 16px);
  max-height: calc(100dvh - var(--bar-h) - env(safe-area-inset-top) - 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

@media (max-width: 599px) {
  .top.is-stuck .lockup {
    --lh: 22px;
    --by: 11px;
    --ph: 11px;
  }

  .top.is-stuck .menu-btn {
    height: 32px;
  }

  /* The touch area stays 44 px tall around the 32 px pill. */
  .top.is-stuck .menu-btn::after {
    inset: -6px -4px;
  }

  /* The panel spans the screen inside the gutter, under the bar. */
  .top.is-stuck .menu-panel {
    left: var(--bar-gut);
    right: var(--bar-gut);
    top: calc(100% + 10px);
  }
}

/* ---------------------------------------------------------------- dark ground */

.top.is-stuck.on-dark::before {
  background: var(--bar-tint-dark);
  border-bottom-color: var(--bar-line-dark);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 10px 30px -18px rgba(0, 0, 0, 0.6);
}

/*
 * The light lockup and the dark Menu pill serve two places: the bar over a dark part of the page, and today's header
 * at the top of a page whose first section is marked data-header-rest-tone="dark": a photograph that is dark where the
 * header rests (/packhouses, /processors, /security), where the ink lockup could not be read. At the top there is
 * still no bar and no glass: only the logo and the Menu change. Found from the page itself, so it holds without
 * JavaScript. Home, /about and /co-ops (cream sky at the top of its photograph) keep the ink.
 */
:is(
  .top.is-stuck.on-dark,
  body:has(> main > [data-header-rest-tone="dark"]:first-child) > .top:not(.is-stuck)
) .lockup-on-light {
  display: none;
}

:is(
  .top.is-stuck.on-dark,
  body:has(> main > [data-header-rest-tone="dark"]:first-child) > .top:not(.is-stuck)
) .lockup-on-dark {
  display: inline-block;
}

/* The mock-up's 0.9 measured 4.41:1 at the bright top of the /co-ops photograph; 0.94 keeps 4.5:1 there. */
:is(
  .top.is-stuck.on-dark,
  body:has(> main > [data-header-rest-tone="dark"]:first-child) > .top:not(.is-stuck)
) .lockup-by {
  color: rgba(255, 255, 255, 0.94);
}

:is(
  .top.is-stuck.on-dark,
  body:has(> main > [data-header-rest-tone="dark"]:first-child) > .top:not(.is-stuck)
) .lockup-pomodor {
  opacity: 0.86;
}

:is(
  .top.is-stuck.on-dark,
  body:has(> main > [data-header-rest-tone="dark"]:first-child) > .top:not(.is-stuck)
) .menu-btn {
  color: var(--bar-light);
  /* A darker glass pill with a light rim: light text keeps 4.5:1 even where a lit window shows through. */
  background: rgba(20, 32, 26, 0.3);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 6px 18px -10px rgba(0, 0, 0, 0.5);
}

:is(
  .top.is-stuck.on-dark,
  body:has(> main > [data-header-rest-tone="dark"]:first-child) > .top:not(.is-stuck)
) .menu-btn:hover {
  background: rgba(20, 32, 26, 0.45);
}

:is(
  .top.is-stuck.on-dark,
  body:has(> main > [data-header-rest-tone="dark"]:first-child) > .top:not(.is-stuck)
) .menu-btn[aria-expanded="true"] {
  background: rgba(20, 32, 26, 0.55);
}

:is(
  .top.is-stuck.on-dark,
  body:has(> main > [data-header-rest-tone="dark"]:first-child) > .top:not(.is-stuck)
) .menu-btn::before {
  background: rgba(255, 255, 255, 0.24);
}

:is(
  .top.is-stuck.on-dark,
  body:has(> main > [data-header-rest-tone="dark"]:first-child) > .top:not(.is-stuck)
) .menu-btn:focus-visible {
  outline-color: var(--bar-light);
}

/* ---------------------------------------------------------------- reduced motion: no fade */

@media (prefers-reduced-motion: reduce) {
  .top.is-stuck,
  .top.is-stuck::before,
  .top.is-stuck > *,
  .top.is-stuck .lockup-by,
  .top.is-stuck .menu-btn {
    animation: none;
    transition: none;
  }

  /* Back at the top, today's header returns at once: the opening fade does not run again. */
  .top.was-stuck {
    animation: none;
  }
}

/* ---------------------------------------------------------------- no glass: a solid, near-opaque bar */

@media (prefers-reduced-transparency: reduce) {
  .top.is-stuck::before {
    background: var(--bar-solid);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .top.is-stuck.on-dark::before {
    background: var(--bar-solid-dark);
  }
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .top.is-stuck::before {
    background: var(--bar-solid);
  }

  .top.is-stuck.on-dark::before {
    background: var(--bar-solid-dark);
  }
}
