@media (max-width: 991.98px) {
  #mainNav {
    max-height: 100vh;
    max-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* Preserve the original two rows of three main navigation icons. */
  #mainNav #navbarResponsive .navbar-nav > .div {
    flex-direction: row !important;
    justify-content: space-between;
    align-items: flex-start;
  }

  #mainNav #navbarResponsive .nav-item {
    width: 72px;
    height: 72px;
    flex: 0 0 72px;
  }

  /* The open panel scrolls independently without stretching the icon grid. */
  #mainNav #navbarResponsive .nav-item > .dropdown-menu {
    position: fixed !important;
    inset: auto !important;
    top: min(160px, 25vh) !important;
    top: min(160px, 25dvh) !important;
    left: 16px !important;
    right: 16px !important;
    transform: none !important;
    width: auto;
    min-width: 0;
    max-height: calc(100vh - min(160px, 25vh) - 16px);
    max-height: calc(100dvh - min(160px, 25dvh) - 16px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* Nested lists share the panel's scroll area. */
  #mainNav #navbarResponsive .dropdown-menu .dropdown-menu {
    position: static !important;
    inset: auto !important;
    transform: none !important;
    width: 100%;
    min-width: 0;
    max-height: none;
    overflow: visible;
  }

  #mainNav #navbarResponsive .dropdown-item {
    white-space: normal;
    overflow-wrap: anywhere;
  }
}
