/* ══ Mobile navigation, dataset jump menu, and phone type scale ══════════
   One shared file rather than a copy inside each page's <style>, because
   this site has 67 generated pages and four that nothing generates
   (index, compare, blog, avalanche). Every previous sitewide change has
   had to be applied to those four by hand, and the build's coverage audit
   exists precisely because they kept falling behind. A linked file cannot
   drift.

   The two menus are PROGRESSIVE ENHANCEMENTS. Their styles are gated on
   html.mobile-ui, a class mobile-ui.js adds on load, so a phone with
   JavaScript off keeps exactly the horizontally-scrolling nav row it has
   today rather than losing navigation altogether. The type scale below is
   not gated, since it needs no script.

   Colour comes from each page's own custom properties, with fallbacks: the
   mountain and hub pages expose --bg2/--white, while avalanche.html names
   the same two --card/--text. Hard-coding either would break one of them. */


/* ── 10% larger type on phones ──────────────────────────────────────────
   Applied at the root so everything in rem scales together: 94 of the 97
   font-size declarations in the generator are already rem, as are the
   spacing tokens --pad and --max. The three that were px (body on the hub
   shell, and body on compare and blog) were converted to their rem
   equivalents in the same commit, so this rule reaches them too.

   Breakpoints are unaffected: every media query on this site is in px, so
   changing the root font size cannot move the point at which this rule
   itself applies. */
@media (max-width: 640px) {
  html { font-size: 110%; }
}


/* ── Shared dropdown chrome ─────────────────────────────────────────── */
.mui-toggle {
  display: none;
  align-items: center;
  gap: 0.45em;
  font-family: inherit;
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted, #6b7280);
  background: none;
  border: 1px solid var(--border, rgba(11, 29, 58, 0.14));
  border-radius: 6px;
  padding: 0.42rem 0.7rem;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
}
.mui-toggle:hover,
.mui-toggle:focus-visible {
  color: var(--accent, #002147);
  border-color: var(--accent, #002147);
}
/* A caret that rotates rather than two glyphs swapped by script. */
.mui-toggle::after {
  content: "";
  width: 0.42em;
  height: 0.42em;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-0.12em) rotate(45deg);
  transition: transform 0.18s ease;
}
.mui-toggle[aria-expanded="true"]::after {
  transform: translateY(0.1em) rotate(-135deg);
}


@media (max-width: 640px) {

  /* ── Site navigation dropdown ──────────────────────────────────────
     Replaces the horizontal scroller the nav has used on phones. That
     row worked -- it kept the bar near 50px and stopped the document
     scrolling sideways -- but it hid most of the links off-screen with
     no affordance saying so, and the site now has nine state hubs and
     six top-level pages to reach. */
  html.mobile-ui .top-nav {
    position: relative;
    flex-wrap: nowrap;
    gap: 0.6rem;
  }
  html.mobile-ui .mui-toggle { display: inline-flex; margin-left: auto; }

  html.mobile-ui .nav-links {
    display: none;
    position: absolute;
    top: calc(100% + 0.45rem);
    right: 0;
    left: auto;
    z-index: 60;
    min-width: 13rem;
    max-width: min(20rem, calc(100vw - 2rem));
    max-height: min(70vh, 26rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0;
    padding: 0.3rem;
    background: var(--bg2, var(--card, #ffffff));
    border: 1px solid var(--border, rgba(11, 29, 58, 0.14));
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(11, 29, 58, 0.14);
  }
  html.mobile-ui .top-nav[data-mui-open="true"] .nav-links { display: flex; }

  /* The links inherit a 0.58rem uppercase style from the scroller rule.
     In a stacked panel they are list rows and want to read as such. */
  html.mobile-ui .nav-links .nav-link {
    display: block;
    width: 100%;
    white-space: normal;
    text-align: left;
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    padding: 0.62rem 0.7rem;
    border-radius: 5px;
  }
  html.mobile-ui .nav-links .nav-link + .nav-link {
    border-top: 1px solid var(--border, rgba(11, 29, 58, 0.09));
  }


  /* ── Dataset jump menu ─────────────────────────────────────────────
     A mountain page is roughly 4,000px tall on a phone: current
     conditions, the depth chart, the NWS forecast, three elevation
     zones each with a forecast and a wind rose, the station records,
     and the FAQ. Reaching the records meant scrolling past all of it.
     mobile-ui.js builds this from the sections actually present, so a
     page with no webcams and no FAQ does not advertise either. */
  html.mobile-ui .mui-jump {
    position: sticky;
    top: 0;
    z-index: 55;
    display: flex;
    justify-content: flex-end;
    padding: 0.5rem var(--pad, 1.25rem);
    background: linear-gradient(
      var(--bg, #f6f7f9) 68%, rgba(255, 255, 255, 0));
  }
  html.mobile-ui .mui-jump > .mui-toggle {
    display: inline-flex;
    background: var(--bg2, var(--card, #ffffff));
  }
  html.mobile-ui .mui-jump-list {
    display: none;
    position: absolute;
    top: calc(100% - 0.1rem);
    right: var(--pad, 1.25rem);
    z-index: 56;
    min-width: 13rem;
    max-width: min(22rem, calc(100vw - 2rem));
    max-height: min(70vh, 28rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    flex-direction: column;
    margin: 0;
    padding: 0.3rem;
    list-style: none;
    background: var(--bg2, var(--card, #ffffff));
    border: 1px solid var(--border, rgba(11, 29, 58, 0.14));
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(11, 29, 58, 0.14);
  }
  html.mobile-ui .mui-jump[data-mui-open="true"] .mui-jump-list { display: flex; }
  html.mobile-ui .mui-jump-list a {
    display: block;
    font-size: 0.72rem;
    line-height: 1.3;
    color: var(--white, var(--text, #0b1d3a));
    text-decoration: none;
    padding: 0.62rem 0.7rem;
    border-radius: 5px;
  }
  html.mobile-ui .mui-jump-list li + li a {
    border-top: 1px solid var(--border, rgba(11, 29, 58, 0.09));
  }
  html.mobile-ui .mui-jump-list a:hover,
  html.mobile-ui .mui-jump-list a:focus-visible {
    color: var(--accent, #002147);
    background: rgba(0, 33, 71, 0.06);
  }

  /* Both menus are sticky, so an anchor jump must clear them or the
     heading lands underneath. */
  html.mobile-ui [data-mui-target] { scroll-margin-top: 4.6rem; }
}

/* The jump menu is a phone affordance; desktop has the whole page in view
   and its own layout for these sections. */
@media (min-width: 641px) {
  .mui-jump { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .mui-toggle::after { transition: none; }
}
