/* ==========================================================================
   Header: sticky bar with logo + primary nav
   - Hides on scroll down, returns on scroll up (scripts/features/scroll-chrome.js)
   - Below 900px the nav collapses behind a Menu button once JS has loaded
     (scripts/features/navigation.js). Without JS the links stay visible.
   ========================================================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding: calc(16px + env(safe-area-inset-top, 0px)) var(--gutter) 16px;
  border-bottom: 1px solid var(--color-line);
  background: rgb(var(--paper-rgb) / .94);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: transform 250ms var(--ease);
}

.site-header.is-hidden:not(:focus-within):not(.is-open) {
  transform: translateY(-100%);
}

/* The logo takes the free space, so everything else sits on the right */
.site-header__logo {
  min-height: 44px;
  margin-right: auto;
}

/* ---- Light / dark switch: round icon button ---- */
.theme-toggle {
  order: 2;                 /* after the nav on wide screens */
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--color-line);
  border-radius: 50%;
  background: transparent;
  color: var(--color-ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 160ms ease, border-color 160ms ease, transform 140ms var(--ease);
}

.theme-toggle svg {
  transition: rotate 500ms var(--ease);
}

/* The half-filled icon flips sides in the dark theme */
.theme-toggle[aria-pressed="true"] svg {
  rotate: 180deg;
}

.theme-toggle:active {
  transform: scale(.94);
}

@media (hover: hover) and (pointer: fine) {
  .theme-toggle:hover { border-color: var(--color-ink); background: var(--color-stone); }
}

.site-nav {
  order: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 28px;
}

/* ---- Mobile menu button ---- */
.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-ink);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.menu-toggle:active {
  transform: scale(.97);
}

.menu-toggle__icon {
  width: 14px;
  height: 8px;
  border-block: 1px solid currentColor;
}

.menu-toggle[aria-expanded="true"] .menu-toggle__icon {
  height: 0;
  border-bottom: 0;
}

@media (max-width: 900px) {
  .site-header {
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    padding-bottom: 10px;
  }

  .site-header__logo .wordmark { font-size: 12px; }
  .menu-toggle:not([hidden]) { display: inline-flex; }
  /* Small screens: logo, theme switch, Menu button, then the nav on its own row */
  .theme-toggle { order: 0; }
  .site-nav { order: 3; width: 100%; gap: 4px 20px; }

  .site-header.is-enhanced .site-nav { display: none; }

  .site-header.is-open {
    max-height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .site-header.is-open .site-nav {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 8px 0;
  }

  .site-header.is-open .site-nav .nav-link { min-height: 48px; }
  .site-header.is-open .site-nav .btn { justify-content: center; margin-top: 8px; }
}

/* Phones: logo, theme switch and Menu stay on ONE row. The Menu button
   becomes a round icon button like the theme switch; its "Menu" label is
   kept for screen readers only. */
@media (max-width: 560px) {
  .site-header { column-gap: 8px; }
  .site-header__logo { gap: 10px; }
  .site-header__logo .wordmark { font-size: 11px; letter-spacing: .14em; }

  .menu-toggle {
    width: 44px;
    padding: 0;
    border-radius: 50%;
  }

  .menu-toggle > span:first-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .menu-toggle__icon { width: 16px; height: 9px; }
}

/* ---- With ScrollSmoother (scripts/features/smooth-scroll.js) ----
   Sticky positioning can't work inside the transformed content, so the
   header is fixed and the content starts below it. */
.has-smooth .site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}

.has-smooth #smooth-content {
  padding-top: var(--header-h, 0px);
}
