/* Site navigation.
   Markup: layouts/_partials/site-navigation.html (override of ananke's).

   The site is RTL, so the menu belongs at the right — the reading start — and
   the site title at the left. Below ananke's `-l` breakpoint (60em) the menu
   collapses behind a hamburger button, kept at the right so it lines up with
   the items it opens. */

.nav-inner {
  position: relative; /* containing block for the checkbox and the open menu */
  z-index: 1; /* keep the open menu above the cover header it hangs over */
}

/* The checkbox is the control: kept in the accessibility tree and the keyboard
   focus order (so it toggles with Space), but never painted — only the label
   next to it is. Hence opacity rather than display: none. */
.nav-toggle {
  position: absolute;
  top: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.nav-toggle-label {
  display: none;
  padding: 0.75rem;
  margin: -0.75rem; /* a 44px tap target that does not push the bar taller */
  cursor: pointer;
  color: rgba(255, 255, 255, 0.9);
}

.nav-toggle:focus-visible + .nav-toggle-label {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* Three bars: the middle one is the span, the outer two its pseudo-elements.
   They stay put when the menu opens — the button is a plain toggle, not a
   morphing close icon. */
.nav-toggle-bars {
  position: relative;
  display: block;
  width: 1.5rem;
  height: 2px;
  background: currentColor;
}

.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: currentColor;
}

.nav-toggle-bars::before { top: -0.5rem; }
.nav-toggle-bars::after  { top: 0.5rem; }

/* Above the breakpoint ananke's own `flex-l` lays the row out; all that is
   needed is to pull the menu ahead of the title, i.e. to the RTL start. */
@media screen and (min-width: 60em) {
  .nav-menu {
    order: -1;
  }
}

@media screen and (max-width: 59.99em) {
  /* Source order is toggle, title, menu — which in an RTL row already gives
     [button at the right … title at the left]. The menu is positioned out of
     flow below, so the row only ever holds those two. */
  .nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .nav-toggle-label {
    display: block;
  }

  /* The open menu hangs over the page instead of sitting in the flow: taken
     out of flow it cannot grow the nav, which was pushing the cover image
     down as it opened. Anchored to .nav-inner's right edge, under the button.
     No `left`, so the panel shrink-wraps to the widest item rather than
     blacking out the full width of the header. */
  .nav-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: rgba(0, 0, 0, 0.92);
  }

  .nav-toggle:checked ~ .nav-menu {
    display: block;
  }

  /* Stack the items instead of letting ananke's `dib` spread them. */
  .nav-menu ul {
    margin: 0;
    padding: 0.25rem 1.25rem;
  }

  .nav-menu li {
    display: block;
    padding: 0;
  }

  .nav-menu li a {
    display: block;
    padding: 0.6rem 0;
  }
}
