/* ---------- phone menu: an "Explore" pill and a die; tapping it stretches the pill across the top and drops the menu down
   (adapted from the dice navbar files, in Mench colors and Space Grotesk). Phones only: 640px and below. ---------- */
.mnav {
  display: none;
}
@media (max-width: 640px) {
  .mnav {
    display: block;
    --g: 16px;
    --h: 44px;
    --gap: 3px;
    --main-w: 92px; /* fits "Explore" (about 55px) inside 16px padding and the 2px border */
    --ease: cubic-bezier(0.77, 0, 0.175, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  }
  body.nav-locked {
    overflow: hidden;
  }

  .mnav__toggle {
    position: fixed;
    z-index: 82;
    top: calc(env(safe-area-inset-top, 0px) + 25px);
    right: var(--g);
    display: flex;
    gap: var(--gap);
    height: var(--h);
    padding: 0;
    border: 0;
    background: none;
    font: 700 15px/1 var(--font-body);
    color: var(--ink);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition:
      top 0.35s var(--ease),
      right 0.35s var(--ease);
  }
  .mnav.is-scrolled .mnav__toggle,
  .mnav[data-open="true"] .mnav__toggle {
    top: calc(env(safe-area-inset-top, 0px) + 14px);
  }
  .mnav__main {
    display: flex;
    align-items: center;
    width: var(--main-w);
    padding: 0 16px;
    overflow: hidden;
    white-space: nowrap;
    background: var(--surface);
    color: var(--ink);
    border: 2px solid var(--edge);
    border-radius: 12px 0 0 12px;
    box-shadow: 4px 4px 0 var(--edge);
    /* closing: wait for the menu to roll back up, then shrink */
    transition:
      width 0.35s var(--ease) 0.35s,
      background-color 0.35s ease 0.35s,
      color 0.35s ease 0.35s,
      border-color 0.35s ease 0.35s,
      box-shadow 0.35s ease 0.35s;
  }
  .mnav[data-open="true"] .mnav__main {
    width: calc(100vw - 2 * var(--g) - var(--h) - var(--gap));
    background: var(--yellow);
    color: var(--on-yellow);
    box-shadow: 0 0 0 var(--edge);
    /* opening: stretch and turn yellow first, the menu follows */
    transition:
      width 0.35s var(--ease),
      background-color 0.35s ease,
      color 0.35s ease,
      border-color 0.35s ease,
      box-shadow 0.35s ease;
  }
  .mnav__die {
    position: relative;
    flex: none;
    width: var(--h);
    height: var(--h);
    background: var(--yellow);
    color: #1a1714;
    border: 2px solid var(--edge);
    border-radius: 0 12px 12px 0;
    box-shadow: 4px 4px 0 var(--edge);
    transition:
      transform 150ms var(--boing),
      box-shadow 0.35s ease;
  }
  .mnav__toggle:active .mnav__die {
    transform: scale(0.92);
  }
  .mnav__pips {
    position: absolute;
    inset: 10px;
    transition: transform 0.4s var(--ease);
  }
  .mnav[data-open="true"] .mnav__pips {
    transform: rotate(90deg);
  }
  .mnav__pips i {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    transition:
      transform 0.4s var(--ease),
      opacity 0.3s ease;
  }
  .mnav__pips .tl {
    top: 0;
    left: 0;
  }
  .mnav__pips .tr {
    top: 0;
    right: 0;
  }
  .mnav__pips .bl {
    bottom: 0;
    left: 0;
  }
  .mnav__pips .br {
    bottom: 0;
    right: 0;
  }
  .mnav__pips .c {
    top: calc(50% - 3px);
    left: calc(50% - 3px);
  }
  /* five pips turn into four: the centre one drops out */
  .mnav[data-open="true"] .mnav__pips .c {
    transform: scale(0);
    opacity: 0;
  }
  /* night: light outline instead of the hard shadow */
  [data-mode="night"] .mnav__main {
    border-color: var(--surface);
    box-shadow: none;
  }
  [data-mode="night"] .mnav__die {
    border-color: var(--yellow);
    box-shadow: none;
  }
  [data-mode="night"] .mnav[data-open="true"] .mnav__main {
    border-color: var(--yellow);
    box-shadow: none;
  }

  /* the menu: rolls down from the top */
  .mnav__panel {
    position: fixed;
    inset: 0;
    z-index: 81;
    height: 100vh;
    height: 100dvh;
    padding: calc(env(safe-area-inset-top, 0px) + 14px + var(--h) + 18px) var(--g)
      calc(24px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg);
    color: var(--ink);
    clip-path: inset(0 0 100% 0);
    visibility: hidden;
    transition:
      clip-path 0.5s var(--ease),
      visibility 0s linear 0.5s;
  }
  .mnav[data-open="true"] .mnav__panel {
    clip-path: inset(0 0 0 0);
    visibility: visible;
    transition:
      clip-path 0.6s var(--ease) 0.2s,
      visibility 0s;
  }
  .mnav__list {
    margin: 0;
    padding: 8px 0 0;
    list-style: none;
    flex: 1;
  }
  .mnav__item {
    border-bottom: 1.5px solid var(--hair);
    opacity: 0;
    transform: translateY(24px);
    transition:
      opacity 0.3s ease,
      transform 0.3s ease;
  }
  .mnav[data-open="true"] .mnav__item {
    opacity: 1;
    transform: none;
    transition:
      opacity 0.6s var(--ease-out),
      transform 0.8s var(--ease-out);
    transition-delay: calc(0.4s + var(--i, 0) * 0.07s);
  }
  .mnav__row {
    width: 100%;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 20px;
    align-items: center;
    padding: 18px 0;
    border: 0;
    background: none;
    color: var(--ink);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    font: inherit;
    -webkit-tap-highlight-color: transparent;
  }
  .mnav__index {
    justify-self: start;
    display: grid;
    place-items: center;
    width: 30px;
    height: 26px;
    border-radius: 8px;
    background: var(--c);
    color: var(--on-c);
    border: 2px solid var(--edge);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    transform: rotate(-4deg);
  }
  [data-mode="night"] .mnav__index {
    border-color: var(--c);
  }
  .mnav__label {
    font-size: 34px;
    font-weight: 500;
    line-height: 1.1;
    letter-spacing: -0.03em;
    transition:
      font-weight 0.5s cubic-bezier(0.22, 1, 0.36, 1),
      color 0.3s ease;
  }
  .mnav__row[aria-expanded="true"] .mnav__label {
    font-weight: 700;
  }
  [data-mode="night"] .mnav__row[aria-expanded="true"] .mnav__label {
    color: var(--c);
  }
  /* plus turns into minus; direct links get an arrow */
  .mnav__plus {
    position: relative;
    justify-self: end;
    width: 16px;
    height: 16px;
  }
  .mnav__plus::before,
  .mnav__plus::after {
    content: "";
    position: absolute;
    top: calc(50% - 1px);
    left: 0;
    width: 100%;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
    transition: transform 0.4s var(--ease);
  }
  .mnav__plus::after {
    transform: rotate(90deg);
  }
  .mnav__row[aria-expanded="true"] .mnav__plus::after {
    transform: rotate(0deg);
  }
  .mnav__go {
    justify-self: end;
    width: 20px;
    height: 20px;
  }
  /* accordion: smooth height with the grid-rows trick */
  .mnav__sub {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.5s var(--ease);
  }
  .mnav__sub > ul {
    overflow: hidden;
    margin: 0;
    padding: 0 0 0 44px;
    list-style: none;
  }
  .mnav__row[aria-expanded="true"] + .mnav__sub {
    grid-template-rows: 1fr;
  }
  .mnav__sub li:last-child {
    padding-bottom: 18px;
  }
  .mnav__sub a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    font-size: 18px;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--muted);
    text-decoration: none;
    transition: color 0.2s ease;
  }
  .mnav__sub a::after {
    content: "→";
    font-size: 16px;
    font-weight: 700;
    color: var(--c);
    opacity: 0;
    transform: translateX(-6px);
    transition:
      opacity 0.2s ease,
      transform 0.2s ease;
  }
  .mnav__sub a:hover,
  .mnav__sub a:focus-visible,
  .mnav__sub a:active {
    color: var(--ink);
  }
  .mnav__sub a:hover::after,
  .mnav__sub a:focus-visible::after,
  .mnav__sub a:active::after {
    opacity: 1;
    transform: none;
  }
  /* bottom of the menu */
  .mnav__foot {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-top: 30px;
    opacity: 0;
    transition: opacity 0.3s ease;
  }
  .mnav[data-open="true"] .mnav__foot {
    opacity: 1;
    transition: opacity 0.6s var(--ease-out) 0.75s;
  }
  .mnav__modeicon {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .mnav__index--icon {
    padding: 0;
  }
  /* a small on/off switch: knob on the right when dark mode is on */
  .mnav__row:has(.mnav__switch) {
    grid-template-columns: 44px minmax(0, 1fr) 42px;
  }
  .mnav__switch {
    justify-self: end;
    position: relative;
    width: 42px;
    height: 24px;
    border-radius: 12px;
    background: var(--surface);
    border: 2px solid var(--edge);
  }
  .mnav__switch i {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--ink);
    transition:
      transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
      background-color 0.3s ease;
  }
  /* each switch is "on" for its own reason: light mode (the site opens dark, so it starts off), or sound on */
  :root:not([data-mode="night"]) #mnav-mode .mnav__switch,
  :root:not([data-sound="off"]) #mnav-sound .mnav__switch {
    background: var(--yellow);
    border-color: var(--yellow);
  }
  :root:not([data-mode="night"]) #mnav-mode .mnav__switch i,
  :root:not([data-sound="off"]) #mnav-sound .mnav__switch i {
    transform: translateX(18px);
    background: #1a1714;
  }
  .mnav__foot .btn {
    width: 100%;
    justify-content: space-between;
    min-height: 56px;
    font-size: 1.05rem;
  }
  .mnav__meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    font-size: 13px;
    line-height: 1.55;
    color: var(--muted);
  }
  .mnav__meta > span {
    max-width: 190px;
  }
  .mnav__social {
    display: flex;
    gap: 16px;
  }
  .mnav__social a {
    border-bottom: 2px solid var(--hair);
    font: 700 13px/1.6 var(--font-body);
    color: var(--ink);
    text-decoration: none;
  }
  .mnav__social a:hover {
    border-color: var(--yellow);
  }
}
@media (max-width: 640px) and (prefers-reduced-motion: reduce) {
  .mnav *,
  .mnav *::before,
  .mnav *::after {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}
