/* The one site header.
 *
 * This file is the SINGLE source of truth for the masthead on every surface:
 * the hand-written landing page (web/public/index.html) and every Astro page in
 * the blog (web/blog/layouts/Base.astro) both link this exact file and use the
 * same markup, so the header can never drift between them again. Two hand-synced
 * copies is what put the rule at a different height on home vs blog; there is
 * now one copy.
 *
 * It is deliberately self-contained: the header owns its own spacing and never
 * inherits it from a page's layout (the old bug was the landing page nesting the
 * nav inside a flex column with a 56px gap while the blog stacked it tight, so
 * the same header sat 42px lower on one page). Drop `<header class="site-header">`
 * as the first child of <body> on any page and it lands in exactly the same
 * place.
 *
 * Depends only on tokens both surfaces define: --paper --ink --line --coral
 * --muted-aa --sans --mono. --muted-aa is defined here so the value is shared
 * rather than copied (the landing page's raw --muted is below AA on paper).
 */

:root {
  /* --muted darkened until it clears WCAG AA on paper; used for the nav labels
   * and the CTA on both surfaces so the two match exactly. */
  --muted-aa: #6b7074;
  --header-draw-ms: 700ms;
}

/* Full-bleed band. The inner bar is what gets the content width, so the header
 * background (and one day a sticky border) can run edge to edge while the logo
 * and CTA line up with the page body. */
.site-header {
  position: relative;
  z-index: 20;
}

/* The shared content container: max-width 1080 with 24px gutters (20px on
 * phones) resolves to a 1032px content column, identical to the landing page's
 * .page and the blog's .wrap--wide, so the header lines up with the body of
 * every page and does not jump when you navigate between them. */
.site-header__inner {
  position: relative; /* anchor for the mobile menu dropdown */
  max-width: 1080px;
  margin: 0 auto;
  padding-inline: 20px;
}

@media (min-width: 721px) {
  .site-header__inner {
    padding-inline: 24px;
  }
}

/* Three zones: brand left, nav centred against the page, actions right. The
 * 1fr auto 1fr grid centres the nav on the page rather than between the brand
 * and the CTA, which is the standard product-nav arrangement. */
.site-header__bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding-block: 22px 0;
}

@media (min-width: 721px) {
  .site-header__bar {
    padding-block: 28px 0;
  }
}

/* ---- brand ------------------------------------------------------------- */

.site-header__brand {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  text-decoration: none;
  color: var(--ink);
}

.site-header__logo {
  width: 26px;
  height: 26px;
  display: inline-flex;
  flex: none;
}

.site-header__logo svg {
  width: 100%;
  height: 100%;
  display: block;
}

.site-header__word {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.02em;
  line-height: 1; /* not the body's 1.72, which inflated the bar height */
  color: var(--ink);
}

/* ---- centre nav (desktop) --------------------------------------------- */

.site-header__nav {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 4px;
}

.site-header__link {
  position: relative;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: uppercase;
  color: var(--muted-aa);
  text-decoration: none;
  min-height: 44px;
  padding-inline: 12px;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  transition: color 0.2s;
}

.site-header__link:hover {
  color: var(--ink);
}

/* The active tab is named by aria-current, so the underline renders real state
 * instead of a second source of truth. A page sets aria-current="page" on the
 * tab that IS the current page, or "true" on the tab whose SECTION is current
 * (a blog post marks Blog). Both are styled the same. */
.site-header__link[aria-current] {
  color: var(--ink);
}

.site-header__link[aria-current]::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 8px;
  height: 2px;
  border-radius: 2px;
  background: var(--coral);
}

/* Hover previews the same underline in a lighter weight, so the affordance and
 * the selected state are visibly the same mechanism. */
.site-header__link:not([aria-current])::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 8px;
  height: 2px;
  border-radius: 2px;
  background: var(--line);
  opacity: 0;
  transition: opacity 0.2s;
}

.site-header__link:not([aria-current]):hover::after {
  opacity: 1;
}

/* ---- right actions ----------------------------------------------------- */

.site-header__actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 6px;
}

.site-header__cta {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: uppercase;
  color: var(--muted-aa);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 16px;
  background: var(--paper);
  white-space: nowrap;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.site-header__cta:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* Hamburger: hidden on desktop, shown on phones. A real button for a11y. */
.site-header__burger {
  display: none;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.site-header__burger svg {
  display: block;
}

.site-header__burger-bar {
  transition: transform 0.24s ease, opacity 0.18s ease;
  transform-origin: center;
}

/* ---- the drawn rule ---------------------------------------------------- */

.site-header__rule {
  padding-top: 14px;
  padding-bottom: 8px;
}

.site-header__rule .sketch-rule {
  display: block;
  width: 100%;
}

.site-header__rule .sketch-rule svg {
  display: block;
  width: 100%;
  height: 10px;
  overflow: visible;
}

/* The reveal is a clip-path wipe on the inner svg. Not a stroke-dash offset:
 * the 600-unit viewBox is stretched to the container, so a non-scaling stroke
 * resolves dash lengths in screen px and the line paints short then repeats.
 * Not on the .sketch-rule box either: Chrome resolves an IntersectionObserver
 * rect after the target's own clip-path, so a fully clipped rule reports ratio
 * 0 and is never told to draw. */
.js-draw .site-header__rule .sketch-rule svg {
  clip-path: inset(0 100% 0 0);
  transition: clip-path var(--header-draw-ms) cubic-bezier(0.22, 0.61, 0.36, 1);
}

.js-draw .site-header__rule .sketch-rule.is-drawn svg {
  clip-path: inset(0 0 0 0);
}

/* ---- mobile menu panel ------------------------------------------------- */

/* The dropdown the hamburger opens. Absolutely positioned so opening it does
 * not shove the page down, anchored just under the rule. Hidden and inert on
 * desktop, where the inline nav is used instead. */
.site-header__menu {
  position: absolute;
  top: calc(100% - 6px);
  left: 20px;
  right: 20px;
  z-index: 20;
  padding: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 48px -28px rgba(51, 56, 60, 0.55);
  display: none;
  flex-direction: column;
  gap: 2px;
}

.site-header__menu[data-open='true'] {
  display: flex;
}

.site-header__menu-link {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding-inline: 14px;
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
}

.site-header__menu-link[aria-current] {
  color: var(--coral-ink, var(--coral));
  background: var(--line-soft, #e8e5df);
}

.site-header__menu-link:not([aria-current]):active {
  background: var(--line-soft, #e8e5df);
}

/* The CTA repeated as a full-width button at the foot of the menu, so the
 * primary action stays reachable and prominent once the menu is open. */
.site-header__menu-cta {
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  border-radius: 12px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--paper);
  background: var(--ink);
  text-decoration: none;
}

/* ---- responsive switch ------------------------------------------------- */

/* Below 40rem the centre nav gives way to the hamburger: two inline tabs plus a
 * pill waste a whole row of height on a phone, so navigation collapses behind
 * the button (standard practice) and the bar is just brand + burger. */
@media (max-width: 40rem) {
  .site-header__nav,
  .site-header__cta {
    display: none;
  }

  .site-header__bar {
    grid-template-columns: 1fr auto;
  }

  .site-header__burger {
    display: inline-flex;
  }
}

@media (min-width: 40.0625rem) {
  .site-header__menu {
    display: none !important;
  }
}

/* Burger morphs into a close (X) when its menu is open. */
.site-header__burger[aria-expanded='true'] .site-header__burger-bar--top {
  transform: translateY(6px) rotate(45deg);
}

.site-header__burger[aria-expanded='true'] .site-header__burger-bar--mid {
  opacity: 0;
}

.site-header__burger[aria-expanded='true'] .site-header__burger-bar--bot {
  transform: translateY(-6px) rotate(-45deg);
}

@media (prefers-reduced-motion: reduce) {
  .js-draw .site-header__rule .sketch-rule svg {
    clip-path: none;
    transition: none;
  }

  .site-header__burger-bar {
    transition: none;
  }
}
