/* =========================================================================
 * Site Header — companion to assets/js/site-header.js.
 *
 * Two states keyed off `.site-header.is-floating`:
 *   docked   — top of page, hairline border under the bar
 *   floating — past threshold, capsule pinned near the top, soft shadow
 * ====================================================================== */

:root {
  --sh-fg: #0a0a0a;
  --sh-fg-muted: #0a0a0a;
  --sh-border: var(--border-primary, #e9e8ea);
  --sh-bg: var(--bg-primary, #fff);
  --sh-bg-soft: var(--bg-secondary, #f4f3f5);
  --sh-shadow: 0 1px 1px rgba(0, 0, 0, 0.04),
               0 12px 28px rgba(15, 12, 28, 0.10),
               0 2px 8px rgba(15, 12, 28, 0.06);
}

[data-theme="dark"] {
  --sh-fg: var(--dm-text-primary, #f0f0f0);
  --sh-fg-muted: var(--dm-text-tertiary, #808080);
  --sh-border: var(--dm-border-primary, #2a2a2a);
  --sh-bg: rgba(20, 20, 22, 0.86);
  --sh-bg-soft: rgba(255, 255, 255, 0.06);
  --sh-shadow: 0 1px 0 rgba(255, 255, 255, 0.04),
               0 14px 32px rgba(0, 0, 0, 0.55),
               0 2px 10px rgba(0, 0, 0, 0.4);
}

/* A 1px sentinel sits in flow just above the sticky header. While it's in
 * the viewport the header is docked; when scrolled past, it leaves the
 * viewport and the IntersectionObserver flips the header into capsule mode. */
.site-header__sentinel {
  position: relative;
  width: 100%;
  height: 1px;
  pointer-events: none;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  font-family: var(--font-family-ui, system-ui, sans-serif);
  --sh-margin: 0px;
  --sh-radius: 0px;
  transition:
    padding 360ms cubic-bezier(0.22, 1, 0.36, 1),
    background-color 240ms ease;
  padding: var(--sh-margin) clamp(16px, 4vw, 40px);
}

.site-header__bar {
  border-bottom: 1px solid var(--sh-border);
  background: color-mix(in srgb, var(--sh-bg) 78%, transparent);
  backdrop-filter: saturate(140%) blur(16px);
  -webkit-backdrop-filter: saturate(140%) blur(16px);
  border-radius: var(--sh-radius);
  transition:
    background-color 240ms ease,
    border-color 240ms ease,
    box-shadow 360ms cubic-bezier(0.22, 1, 0.36, 1),
    border-radius 360ms cubic-bezier(0.22, 1, 0.36, 1),
    max-width 360ms cubic-bezier(0.22, 1, 0.36, 1);
  max-width: 100%;
  margin: 0 auto;
}

@supports not (background: color-mix(in srgb, red 50%, transparent)) {
  .site-header__bar { background: var(--sh-bg); }
}

.site-header__inner {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 28px;
  height: 56px;
  padding: 0 20px;
  color: var(--sh-fg);
}

/* --- floating capsule state --- */
.site-header.is-floating {
  --sh-margin: 8px;
  --sh-radius: 999px;
}

.site-header.is-floating .site-header__bar {
  max-width: min(960px, calc(100% - 32px));
  border-color: transparent;
  box-shadow: var(--sh-shadow);
}

.site-header.is-floating .site-header__inner {
  height: 52px;
  padding: 0 14px 0 18px;
}

/* --- brand: portrait avatar + name (Ben Lang style) --- */
.site-header__brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--sh-fg);
  text-decoration: none;
}

.site-header__portrait {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--sh-border);
  background: var(--sh-bg-soft);
  flex-shrink: 0;
}

.site-header__portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 24%;
  display: block;
  /* Make the dot-pattern portrait read in either theme */
  filter: contrast(1.05);
}

[data-theme="dark"] .site-header__portrait img {
  filter: contrast(1.05) invert(1) hue-rotate(180deg);
}

.site-header__brand-label {
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: -0.012em;
  color: var(--sh-fg);
}

/* Slight squish in floating-capsule mode so the brand stays balanced */
.site-header.is-floating .site-header__portrait {
  width: 26px;
  height: 26px;
}

/* --- primary nav --- */
.site-header__nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.site-header__right {
  justify-self: end;
}

.site-header__link {
  display: inline-block;
  padding: 7px 12px;
  font-size: 0.875rem;
  font-weight: 300;
  color: var(--sh-fg);
  text-decoration: none;
  border-radius: 8px;
  transition: background-color 160ms ease;
}

/* Hover / active links pick up the site's dotted-underline treatment
 * (mirrors .link-dotted) instead of a filled pill. */
.site-header__link:hover,
.site-header__link[aria-current="page"] {
  background: transparent;
  color: var(--sh-fg);
  text-decoration: underline dotted;
  text-decoration-color: var(--sh-fg);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.site-header__link[aria-current="page"] {
  font-weight: 600;
}

/* --- right cluster --- */
.site-header__right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.site-header__search {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 6px 0 10px;
  border: 1px solid var(--sh-border);
  border-radius: 999px;
  background: transparent;
  color: var(--sh-fg-muted);
  font-family: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.site-header__search:hover,
.site-header__search.is-active {
  color: var(--sh-fg);
  border-color: color-mix(in srgb, var(--sh-fg) 30%, transparent);
}

.site-header__search-icon svg { width: 14px; height: 14px; }

.site-header__search-label {
  display: none;
}

.site-header__kbd {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  font-family: inherit;
}

.site-header__kbd span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--sh-fg-muted);
  background: var(--sh-bg-soft);
  border-radius: 4px;
}

.site-header__github {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 10px;
  height: 30px;
  border-radius: 999px;
  color: var(--sh-fg);
  text-decoration: none;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  transition: background-color 160ms ease, color 160ms ease;
}

.site-header__github:hover {
  background: color-mix(in srgb, var(--sh-fg) 6%, transparent);
}

.site-header__github-icon svg { width: 16px; height: 16px; }

.site-header__divider {
  width: 1px;
  height: 18px;
  background: var(--sh-border);
  margin: 0 2px;
}

/* The theme switcher gets injected into the slot anchor by theme-toggle.js.
 * Its own styles take over; the slot just reserves space so there's no jump. */
.site-header__theme-slot {
  display: inline-flex;
}

/* --- hamburger (mobile only) --- */
.site-header__menu-toggle {
  display: none;          /* revealed in the mobile media query below */
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--sh-fg);
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 160ms ease;
}

.site-header__menu-toggle:hover {
  background: color-mix(in srgb, var(--sh-fg) 8%, transparent);
}

.site-header__menu-toggle svg {
  width: 22px;
  height: 22px;
}

/* --- mobile full-screen overlay menu (Apple-style) --- */
.site-header__overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;          /* above the sticky header */
  display: flex;
  flex-direction: column;
  background: var(--bg-primary, #fff);
  opacity: 0;
  transition: opacity 280ms ease;
  font-family: var(--font-family-ui, system-ui, sans-serif);
}

.site-header__overlay[hidden] {
  display: none;
}

.site-header__overlay.is-open {
  opacity: 1;
}

.site-header__overlay-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 56px;
  flex-shrink: 0;
  padding: 0 calc(clamp(16px, 4vw, 40px) + 20px);
}

.site-header__overlay-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--sh-fg);
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 160ms ease;
}

.site-header__overlay-close:hover {
  background: color-mix(in srgb, var(--sh-fg) 8%, transparent);
}

.site-header__overlay-close svg {
  width: 24px;
  height: 24px;
}

.site-header__overlay-nav {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 2vw, 14px);
  padding: clamp(8px, 3vw, 24px) calc(clamp(16px, 4vw, 40px) + 20px) 48px;
  overflow-y: auto;
}

.site-header__overlay-link {
  display: block;
  padding: 6px 0;
  font-size: clamp(1.75rem, 8vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--sh-fg);
  text-decoration: none;
  /* staggered entrance, mirrors Apple's menu */
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 300ms ease, transform 320ms cubic-bezier(0.22, 1, 0.36, 1);
  transition-delay: calc(var(--i, 0) * 45ms + 80ms);
}

.site-header__overlay.is-open .site-header__overlay-link {
  opacity: 1;
  transform: none;
}

.site-header__overlay-link:hover,
.site-header__overlay-link[aria-current="page"] {
  color: var(--sh-fg);
  text-decoration: underline dotted;
  text-decoration-color: var(--sh-fg);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 6px;
}

/* Lock background scroll while the overlay is open */
html.site-menu-open,
html.site-menu-open body {
  overflow: hidden;
}

/* The overlay is a mobile affordance only */
@media (min-width: 821px) {
  .site-header__overlay {
    display: none !important;
  }
}

/* --- responsive --- */
@media (max-width: 820px) {
  /* Links collapse into the hamburger overlay */
  .site-header__nav {
    display: none;
  }
  .site-header__menu-toggle {
    display: inline-flex;
  }
  /* Logo only — drop the "Lewis" wordmark */
  .site-header__brand-label {
    display: none;
  }
  .site-header__inner {
    grid-template-columns: auto 1fr;
    gap: 14px;
  }
  .site-header__github-count,
  .site-header__kbd {
    display: none;
  }
  .site-header.is-floating .site-header__bar {
    max-width: calc(100% - 24px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .site-header,
  .site-header__bar {
    transition: none !important;
  }
}
