#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  height: var(--header-height);
  background: rgba(9, 9, 11, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid transparent;
  transition: background var(--transition-base), border-color var(--transition-base), height var(--transition-base);
  /* Force a dedicated GPU compositing layer so mobile browsers always paint
     the header above other compositing layers (hero orbs, blur effects, etc.)
     even when the z-index stacking order isn't honoured during compositing. */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

#header.scrolled {
  background: rgba(9, 9, 11, 0.95);
  border-bottom-color: rgba(124, 58, 237, 0.15);
  box-shadow: 0 1px 20px rgba(124, 58, 237, 0.08);
  height: 62px;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  gap: var(--space-xl);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-weight: var(--weight-bold);
  font-size: var(--text-xl);
  flex-shrink: 0;
  transition: opacity var(--transition-fast);
}
.logo:hover { opacity: 0.85; }

.logo-mark {
  flex-shrink: 0;
  border-radius: 6px;
}
.logo-text {
  color: var(--color-white);
  letter-spacing: -0.01em;
}

.nav-desktop {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.nav-link {
  position: relative;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-muted);
  transition: color var(--transition-fast);
  padding-bottom: 2px;
}
.nav-link::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--gradient-purple);
  border-radius: var(--radius-full);
  transition: width var(--transition-base);
}
.nav-link:hover,
.nav-link.active {
  color: var(--color-white);
}
.nav-link:hover::after,
.nav-link.active::after {
  width: 100%;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-shrink: 0;
}

.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  padding: 4px;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}
.hamburger:hover { background: var(--color-surface-2); }
.hamburger span {
  display: block;
  height: 2px;
  background: var(--color-white);
  border-radius: var(--radius-full);
  transition: all var(--transition-base);
  transform-origin: center;
}
.hamburger.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.active span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.hamburger.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.mobile-menu {
  display: none;
  flex-direction: column;
  gap: var(--space-sm);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  /* padding-block: 0 ensures the element truly collapses to 0 height when
     closed — prevents the border-top and background from bleeding through */
  padding-inline: var(--space-xl);
  padding-block: 0;
  overflow: hidden;
  max-height: 0;
  /* visibility: hidden removes ALL visual rendering (border, background, shadows)
     when closed. The 0s delay on close matches --transition-slow so visibility
     disappears only AFTER the max-height animation finishes. */
  visibility: hidden;
  transition:
    max-height var(--transition-slow),
    padding    var(--transition-base),
    visibility 0s var(--transition-slow);
}
.mobile-menu.open {
  max-height: 400px;
  padding-block: var(--space-lg);
  visibility: visible;
  /* On open: visibility becomes visible immediately (no delay) so the
     expanding animation is visible from the first frame. */
  transition:
    max-height var(--transition-slow),
    padding    var(--transition-base),
    visibility 0s;
}
.mobile-menu .nav-link {
  font-size: var(--text-base);
  padding-block: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-muted);
}
.mobile-menu .btn {
  margin-top: var(--space-sm);
  justify-content: center;
}

@media (max-width: 900px) {
  .nav-desktop { display: none; }
  .desktop-cta { display: none; }
  .hamburger   { display: flex; }
  .mobile-menu { display: flex; }
  /* Tighten the gap between logo and actions when nav is hidden */
  .header-inner { gap: var(--space-md); }
}

@media (max-width: 768px) {
  /* Match mobile-menu horizontal padding to the container's 16px padding
     so menu items align with the header logo */
  .mobile-menu { padding-inline: var(--space-md); }

  /* On mobile, make the header fully opaque. 97% opacity + backdrop-filter:blur
     causes the vivid purple hero gradient to visually bleed through, making it
     look like the gradient is above the header. 100% opacity eliminates this. */
  #header { background: #09090b; }
  #header.scrolled { background: #09090b; }
}
