.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface-glass);
  backdrop-filter: blur(16px) saturate(1.6);
  -webkit-backdrop-filter: blur(16px) saturate(1.6);
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur-base) var(--ease), box-shadow var(--dur-base) var(--ease);
}
.site-header.is-stuck {
  border-bottom-color: var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.nav-container {
  width: 100%;
  max-width: var(--w-wide);
  margin-inline: auto;
  padding-inline: var(--gutter);
  height: var(--header-h, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
}

.nav-brand { display: flex; align-items: center; flex-shrink: 0; }
.nav-logo { height: 30px; width: auto; }
.nav-logo.logo-dark { display: none; }
:root[data-theme="dark"] .nav-logo.logo-light { display: none; }
:root[data-theme="dark"] .nav-logo.logo-dark { display: block; }

.nav-menu { display: flex; align-items: center; gap: var(--space-5); }
.nav-links { display: flex; align-items: center; gap: var(--space-1); }

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-secondary);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  transition: color var(--dur-base) var(--ease), background var(--dur-base) var(--ease);
}
.nav-link:hover { color: var(--text-primary); background: var(--surface-2); }
.nav-link.is-active { color: var(--text-primary); font-weight: 600; }
.nav-link .icon { transition: transform var(--dur-base) var(--ease); opacity: .6; }
/* Chevron flips on hover (desktop) or when the submenu is open (mobile). */
@media (min-width: 961px) {
  .nav-has-menu:hover .nav-link .icon { transform: rotate(180deg); }
}
.nav-has-menu.is-open .nav-link .icon { transform: rotate(180deg); }

.nav-cta { margin-left: var(--space-2); }

/* ---- Mega menu --------------------------------------------------------- */
.nav-has-menu { position: relative; }
.nav-dropdown {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: 50%;
  min-width: 620px;
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: var(--space-6);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-6);
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(6px);
  transition:
    opacity var(--dur-base) var(--ease),
    transform var(--dur-base) var(--ease),
    visibility var(--dur-base);
}
.nav-dropdown--single { min-width: 320px; grid-template-columns: 1fr; }
/*
  Desktop-only. On a phone, tapping "Platform" focuses the link (and touch
  browsers leave a sticky :hover behind), so without this media query these
  rules - which are more specific than the mobile `.nav-dropdown` reset -
  would re-apply translateX(-50%) and shove the open submenu half its width
  off the left edge of the drawer.
*/
@media (min-width: 961px) {
  .nav-has-menu:hover .nav-dropdown,
  .nav-has-menu:focus-within .nav-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
  }
}

.nav-dropdown-col h5 {
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-tertiary);
  margin-bottom: var(--space-3);
  padding-inline: var(--space-3);
}
.nav-dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-dropdown-item .icon { color: var(--brand-fg); flex-shrink: 0; }
.nav-dropdown-item:hover { background: var(--surface-1); color: var(--text-primary); }

/* ---- Theme toggle ------------------------------------------------------ */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  transition: color var(--dur-base) var(--ease), border-color var(--dur-base) var(--ease);
}
.theme-toggle:hover { color: var(--text-primary); border-color: var(--border-strong); }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ---- Mobile ------------------------------------------------------------ */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 42px; height: 42px;
  border-radius: var(--radius-sm);
}
.hamburger {
  display: block; width: 20px; height: 2px;
  background: var(--text-primary); border-radius: 2px;
  transition: transform var(--dur-base) var(--ease), opacity var(--dur-base) var(--ease);
}
.nav-toggle.active .hamburger:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.active .hamburger:nth-child(2) { opacity: 0; }
.nav-toggle.active .hamburger:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 960px) {
  .nav-toggle { display: flex; }
  .nav-menu {
    position: fixed;
    top: var(--header-h, 72px);
    left: 0;
    right: 0;
    /*
      Deliberately explicit rather than relying on `bottom: 0` to imply
      height: a position:fixed box with only top/bottom set (no explicit
      height) does not reliably auto-compute its height from the viewport
      across browsers (most notably WebKit/Safari) — it can collapse to
      content size instead of filling down to the bottom edge. Setting
      height directly sidesteps that.
    */
    height: calc(100vh - var(--header-h, 72px));
    height: calc(100dvh - var(--header-h, 72px));
    background: var(--surface-0);
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    padding: var(--space-6) var(--gutter) var(--space-12);
    transform: translateX(100%);
    transition: transform var(--dur-slow) var(--ease-out-expo);
    /*
      overflow-y alone would silently make overflow-x auto too (the spec
      forces the other axis off `visible`), leaving the drawer sideways-
      scrollable. Nothing in it should ever scroll horizontally.
    */
    overflow-y: auto;
    overflow-x: hidden;
    max-width: 100vw;
  }
  .nav-menu.active { transform: translateX(0); }
  .nav-links { flex-direction: column; align-items: stretch; gap: 0; width: 100%; }
  .nav-link {
    padding: var(--space-4) var(--space-2);
    border-bottom: 1px solid var(--border-subtle);
    border-radius: 0;
    font-size: var(--fs-base);
    justify-content: space-between;
  }
  .nav-cta { margin-left: 0; margin-top: var(--space-6); }
  .nav-dropdown {
    position: static;
    transform: none;
    min-width: 0;
    grid-template-columns: 1fr;
    gap: var(--space-4);
    box-shadow: none;
    border: none;
    border-bottom: 1px solid var(--border-subtle);
    border-radius: 0;
    opacity: 1;
    visibility: visible;
    display: none;
    padding: var(--space-2) 0 var(--space-4);
    background: transparent;
  }
  .nav-has-menu.is-open .nav-dropdown { display: grid; }
  .theme-toggle { align-self: flex-start; margin-top: var(--space-6); }
}
