/* ===== NAVIGATION ===== */
nav {
  background: linear-gradient(90deg, #050505 0%, #16213e 100%);
  color: #fff;
  padding: 2px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 2000;
  box-shadow: 0 2px 8px rgba(16,33,62,0.14);
  transition: box-shadow 0.3s ease;
}
nav.scrolled {
  box-shadow: 0 4px 16px rgba(16,33,62,0.22);
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 1.2px;
}

#navMenu {
  list-style: none;
  display: flex;
  gap: 18px;
  align-items: left;
}
#navMenu > li {
  position: relative;
}

/* Main nav links */
#navMenu a {
  color: #fff;
  text-decoration: none;
  padding: 8px 10px;
  display: block;
  border-radius: 6px;
  background: transparent;
  transition: background 0.35s cubic-bezier(0.63,0.04,0.23,1), color 0.22s linear, transform 0.22s cubic-bezier(.68,-0.55,.27,1.55);
}
#navMenu a:hover, #navMenu a:focus {
  background: linear-gradient(90deg, #16213e 0%, #272a3e 100%);
  color: #3789e1;
  /* Remove any transform that causes right shift */
  /* transform: scale(1.06); */
}

#navMenu a:active {
  background: linear-gradient(90deg, #16213e 0%, #272a3e 100%);
  color: #3789e1;
  /* Remove any transform that causes right shift */
  /* transform: scale(1.06); */
}

/* Submenu styles with glitch fix */
#navMenu li ul {
  position: absolute;
  top: 100%; /* submenu directly below parent */
  left: 0;
  min-width: 220px;
  background: linear-gradient(180deg, #111 80%, #222 100%);
  border-radius: 8px;
  display: none;
  flex-direction: column;
  box-shadow: 0 8px 18px rgba(0,0,0,.25);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, top 0.35s cubic-bezier(.68,-0.55,.27,1.55);
  z-index: 3000;
  margin-top: 0; /* Remove gap that causes flicker */
  max-width: calc(100vw - 20px); /* Prevent offscreen overflow */
}
/* Show submenu on hover and focus */
#navMenu li:hover > ul,
#navMenu li:focus-within > ul,
#navMenu li ul:hover {
  display: flex !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  top: 100%;
}

/* Prevent submenu overflow on right edge */
#navMenu li:hover > ul {
  left: 0;
  right: auto;
}
#navMenu li.submenu-right:hover > ul {
  left: auto;
  right: 0;
  max-width: calc(100vw - 20px);
}

#navMenu li ul a {
  padding: 10px 12px;
  transition: background 0.3s;
}
#navMenu li ul a:hover {
  background: #16213e;
  color: #3789e1;
}

/* Hamburger menu styles */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  width: 30px;
  height: 22px;
  cursor: pointer;
  transition: transform 0.32s cubic-bezier(.68,-0.55,.27,1.55);
}
.hamburger.active {
  transform: rotate(90deg);
}
.hamburger span {
  height: 4px;
  background: linear-gradient(90deg, #fff 0%, #3789e1 100%);
  border-radius: 3px;
  display: block;
  transition: background 0.25s;
}

/* Submenu toggle button (mobile only) */
.submenu-toggle {
  display: none;
  background: none;
  border: 0;
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 8px 6px;
  margin-left: 6px;
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  #navMenu {
    display: none;
    flex-direction: column;
    position: absolute;
    left: 0;
    top: 100%;
    width: 100%;
    background: linear-gradient(180deg, #050505 80%, #16213e 100%);
    padding: 8px 0;
    border-top: 1px solid #222;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.38s, transform 0.38s cubic-bezier(.68,-0.55,.27,1.55);
  }
  #navMenu.active {
    display: flex;
    opacity: 1;
    transform: translateY(0);
  }
  .hamburger {
    display: flex;
  }
  /* Disable hover submenu open on mobile */
  #navMenu li:hover > ul {
    display: none !important; /* prevent submenu showing on hover on mobile */
  }
  #navMenu li ul {
    position: static;
    border-radius: 0;
    box-shadow: none;
  }
  /* Open submenu only when li has 'open' class */
  #navMenu li.open > ul {
    display: flex !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }
  .submenu-toggle {
    display: inline-block;
  }
}
/* ===== END NAVIGATION ===== */
