/* Mobile menu redo: NOT full-screen. A narrow slide-in drawer from the
   right (max 320px) with a dimmed backdrop, a slide + fade transition,
   staggered links, and a hamburger that morphs into an X.
   Fixes: (a) the previous full-screen panel, (b) the instant pop-in/out
   (display:none toggle cannot animate), (c) tapping the theme-toggle
   button inside the menu never closed it (JS only listened to <a>).
   Loaded last on homepage + admin, so it beats the audit-fix panel. */
.menu-backdrop {
  position: fixed !important; inset: 0 !important; z-index: 1000 !important;
  background: rgba(0, 0, 0, 0.5) !important;
  opacity: 0 !important; visibility: hidden !important; pointer-events: none !important;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s !important;
}
.menu-backdrop.active {
  opacity: 1 !important; visibility: visible !important; pointer-events: auto !important;
  transition: opacity 0.35s ease !important;
}
@media (max-width: 1024px) {
  body .nav-links {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    position: fixed !important;
    top: 72px !important; right: 0 !important; bottom: auto !important; left: auto !important;
    width: min(320px, 84vw) !important; max-width: none !important;
    height: auto !important; max-height: calc(100dvh - 88px) !important;
    margin: 0 !important; padding: 20px 20px 28px !important; gap: 6px !important;
    border-radius: 0 0 0 16px !important;
    overflow-y: auto !important;
    background: #181733 !important; background-image: none !important;
    border: none !important; box-shadow: -15px 0 40px rgba(0, 0, 0, 0.4) !important;
    transform: translateX(105%) !important;
    visibility: hidden !important; opacity: 1 !important; pointer-events: none !important;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear 0.35s !important;
    z-index: 1001 !important;
  }
  body .nav-links.active {
    /* MUST re-assert every size here: the audit-fix .nav-links.active
       rule is more specific and !important, so the base .nav-links
       sizes above lose to its width:100% / inset:0 / height:100dvh.
       That specificity loss is exactly why the menu stayed full-screen. */
    width: min(320px, 84vw) !important;
    top: 72px !important; right: 0 !important; bottom: auto !important; left: auto !important;
    height: auto !important; max-height: calc(100dvh - 88px) !important;
    padding: 20px 20px 28px !important;
    border-radius: 0 0 0 16px !important;
    transform: translateX(0) !important;
    visibility: visible !important; pointer-events: auto !important;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }
  body .nav-links.active li { animation: menuItemIn 0.4s ease both !important; }
  body .nav-links.active li:nth-child(1) { animation-delay: 0.05s !important; }
  body .nav-links.active li:nth-child(2) { animation-delay: 0.10s !important; }
  body .nav-links.active li:nth-child(3) { animation-delay: 0.15s !important; }
  body .nav-links.active li:nth-child(4) { animation-delay: 0.20s !important; }
  body .nav-links.active li:nth-child(5) { animation-delay: 0.25s !important; }
  body .nav-links.active li:nth-child(6) { animation-delay: 0.30s !important; }
  body .nav-links.active li:nth-child(7) { animation-delay: 0.35s !important; }
  body .nav-links.active li:nth-child(8) { animation-delay: 0.40s !important; }
  body .nav-links.active li:nth-child(9) { animation-delay: 0.45s !important; }
  /* Hamburger morphs into an X (three bars, not a swapped glyph). */
  body .navbar .menu-toggle {
    flex-direction: column !important; gap: 5px !important;
  }
  body .navbar .menu-toggle .bar {
    display: block !important; width: 20px !important; height: 2px !important;
    background: currentColor !important; border-radius: 2px !important;
    transition: transform 0.3s ease, opacity 0.2s ease !important;
  }
  body .navbar .menu-toggle.active .bar:nth-child(1) { transform: translateY(7px) rotate(45deg) !important; }
  body .navbar .menu-toggle.active .bar:nth-child(2) { opacity: 0 !important; }
  body .navbar .menu-toggle.active .bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg) !important; }
}
@keyframes menuItemIn {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Scroll lock fallback: if the drawer is open, the page behind cannot scroll,
   so the menu can never scroll away up the page. */
body:has(.nav-links.active) { overflow: hidden !important; }

/* Navbar must stay pinned while the menu is open. Root cause of the
   "navbar goes up" bug: position:sticky STOPS sticking once an ancestor
   (body) gets overflow:hidden for scroll-lock — the sticky element then
   scrolls away with the page. While the menu is open the navbar is
   therefore fixed to the viewport top instead, above the backdrop. */
body.menu-open .navbar,
html.menu-open .navbar,
body:has(.nav-links.active) .navbar {
  position: fixed !important; top: 0 !important; left: 0 !important; right: 0 !important;
  width: 100% !important; z-index: 1003 !important;
}
/* Lock BOTH html and body: body-only overflow:hidden does not stop
   scrolling on mobile browsers (the document element still scrolls). */
html.menu-open, body.menu-open,
html:has(.nav-links.active), body:has(.nav-links.active) {
  overflow: hidden !important; overscroll-behavior: none !important;
}
html.menu-open, html:has(.nav-links.active) { height: 100% !important; }
