/* ============================================================
   account-phone-menu.css: the account sidebar on phones
   (owner 2026-11-22: "make the experience for the mobile users as
   well a very good experience").

   On a phone the sidebar used to become one row of 18 links under the
   bar: two and a half of them fitted, the page's own item was off-screen
   (Past Papers the 9th, Notes the 11th), the row pushed every page down
   to 162px, and it slid away behind the bar as soon as the student
   scrolled. Measured at 390px on 2026-11-22.

   Now the bar carries the same ☰ a visitor sees in the full bar
   (includes/site-topnav.php), and pressing it slides the SAME sidebar in
   from the left: every group, the page's own item lit and in view, the
   name and Log out at the foot. The bar is pinned on these pages, so the
   menu is one tap away anywhere down a page. The script is beside the
   sidebar in includes/account-shell.php.

   Loaded by includes/header.php on every page that draws the account
   bar. Nothing here shows above 680px. The study room keeps its own
   phone layout (study.css hides its sidebar there), so it is left out.

   ⛔ THIS IS THE ONE PLACE THE PHONE MENU LIVES. The one-row strip in
   committee-control-center.css is the phone layout of the admin and
   committee pages, which draw their own sidebars; these rules outrank it
   for the account sidebar. The copy that was in account-rail.css is gone.

   ⭐ IPHONE SAFARI (owner 2026-11-22: "Fix it for them as well"). Three
   things a slide-in menu gets wrong there, handled on purpose:
   - The page behind could still be dragged: Safari has long ignored
     overflow:hidden for touch scrolling. The dimmed backdrop and the menu's
     head and foot take no drag (touch-action: none), the link list keeps its
     own scrolling (overscroll-behavior: contain), and the script refuses
     any other drag while the menu is open.
   - The ☰ shows only once the script beside the sidebar has started
     (html.mn-acct-menu-ready), so it never appears where it cannot open a
     menu (the study room, or a phone too old for the script), and nothing
     depends on :has(), which iPhones before iOS 15.4 do not read.
   - The lit item is brought into view by scrolling the list itself, never
     with scrollIntoView, which in Safari can also scroll the page.
   ============================================================ */

.mn-acct-drawer-head,
.mn-acct-scrim {
  display: none;
}

.mn-res-topnav .mn-res-nav-toggle.mn-res-acct-menu {
  display: none;
}

@media (max-width: 680px) {
  /* ---- The bar: brand, page name, any action, then ☰ at the right edge,
     on one row. The page name gives way first. */
  .mn-res-topnav-account .mn-res-topnav-inner {
    flex-wrap: nowrap;
  }

  .mn-res-topnav-account .mn-res-crumb {
    flex: 1 1 auto;
  }

  html.mn-acct-menu-ready .mn-res-topnav .mn-res-nav-toggle.mn-res-acct-menu {
    display: inline-flex;
    margin-left: auto;
    -webkit-tap-highlight-color: transparent;
  }

  .mn-res-topnav-account .mn-res-crumb-action + .mn-res-acct-menu {
    margin-left: 0;
  }

  /* ---- The menu: the sidebar, off the left edge until opened. */
  html :not(.mn-study-shell) > aside.sidebar.mn-acct-drawer {
    position: fixed;
    top: 0;
    right: auto;
    bottom: 0;
    left: 0;
    width: min(19rem, 86vw);
    height: auto;
    max-height: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1200;
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
    box-shadow: 12px 0 32px rgba(4, 16, 31, 0.35);
  }

  html.mn-acct-menu-open :not(.mn-study-shell) > aside.sidebar.mn-acct-drawer {
    transform: none;
    visibility: visible;
    transition: transform 0.22s ease, visibility 0s;
  }

  html :not(.mn-study-shell) > .mn-acct-drawer .mn-acct-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    padding: 0.7rem 0.75rem 0.7rem 1.3rem;
    padding-top: calc(0.7rem + env(safe-area-inset-top, 0px));
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    touch-action: none;
  }

  html :not(.mn-study-shell) > .mn-acct-drawer .mn-acct-drawer-title {
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
  }

  html :not(.mn-study-shell) > .mn-acct-drawer .mn-acct-drawer-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  /* The groups and their links, as on a computer, with room for a thumb. */
  html :not(.mn-study-shell) > .mn-acct-drawer .sidebar-nav {
    display: block;
    flex: 1 1 auto;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0.4rem 0 1rem;
  }

  html :not(.mn-study-shell) > .mn-acct-drawer .nav-section-label {
    display: block;
    padding: 0.95rem 1.3rem 0.35rem;
    font-size: 0.62rem;
    color: rgba(255, 255, 255, 0.42);
  }

  html :not(.mn-study-shell) > .mn-acct-drawer .nav-item {
    display: flex;
    min-height: 46px;
    margin: 2px 0.65rem;
    padding: 0.7rem 1rem;
    font-size: 0.95rem;
    white-space: normal;
    color: rgba(255, 255, 255, 0.74);
  }

  html :not(.mn-study-shell) > .mn-acct-drawer .nav-item.active {
    color: #fff;
  }

  /* A touch screen keeps the last touched link in its hover look, so on an
     iPhone the item a scroll started on stayed highlighted (seen in the iOS
     simulator, 2026-11-22). Hover shows only where there is a real pointer. */
  @media (hover: none) {
    html :not(.mn-study-shell) > .mn-acct-drawer .nav-item:not(.active):hover {
      background: transparent;
      color: rgba(255, 255, 255, 0.74);
    }
  }

  html :not(.mn-study-shell) > .mn-acct-drawer .nav-item.active::before {
    top: 50%;
    bottom: auto;
    left: -0.65rem;
    width: 3px;
    height: 1.4rem;
    transform: translateY(-50%);
    border-radius: 0 3px 3px 0;
  }

  html :not(.mn-study-shell) > .mn-acct-drawer .nav-icon {
    width: 1.15rem;
    height: 1.15rem;
  }

  html :not(.mn-study-shell) > .mn-acct-drawer .sidebar-footer {
    display: block;
    flex-shrink: 0;
    touch-action: none;
    padding-bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
  }

  /* The page behind dims and stays still while the menu is open. */
  /* ⛔ The colour itself fades, never the opacity. Safari on iPhone tints its
     own bottom bar from whatever is fixed at the bottom edge of the page, and it
     read this backdrop's colour even at opacity 0: after the menu closed, the
     strip behind Safari's bar stayed grey (seen in the iOS simulator,
     2026-11-22). Closed, the backdrop has no colour and is hidden. */
  .mn-acct-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1190;
    background-color: rgba(4, 16, 31, 0);
    visibility: hidden;
    pointer-events: none;
    touch-action: none;
    transition: background-color 0.22s ease, visibility 0s linear 0.22s;
  }

  html.mn-acct-menu-open .mn-acct-scrim {
    background-color: rgba(4, 16, 31, 0.55);
    visibility: visible;
    pointer-events: auto;
    transition: background-color 0.22s ease, visibility 0s;
  }

  html.mn-acct-menu-open,
  html.mn-acct-menu-open body {
    overflow: hidden;
  }
}

@media (max-width: 680px) and (prefers-reduced-motion: reduce) {
  html :not(.mn-study-shell) > aside.sidebar.mn-acct-drawer,
  html.mn-acct-menu-open :not(.mn-study-shell) > aside.sidebar.mn-acct-drawer,
  .mn-acct-scrim {
    transition: none;
  }
}
