/* Mobile layer — chrome. Loaded AFTER site.css so these rules override the desktop
   design. Everything here lives behind a mobile media query; desktop is never
   affected. Use design tokens only (no hardcoded values). Owned by one zone so
   parallel work never collides: do not put chrome rules in any other mobile file. */

@media (max-width: 768px) {
  /* ----- Header bar --------------------------------------------------------
     One 64px row: brand left, controls right. The desktop nav (which wrapped
     onto three rows down here) is replaced by the hamburger in MobileNav. */
  .site-header__inner {
    flex-wrap: nowrap;
    gap: var(--space-3);
    min-height: var(--space-16);
    padding-block: var(--space-2);
  }
  /* min-width: 0 lets the brand shrink instead of pushing the controls out of
     the viewport (no horizontal overflow, ever). */
  .site-header__brand { min-width: 0; }
  .site-header__brand .brand { font-size: var(--text-lg); }
  .site-header__brand .actual-text,
  .site-header__brand .hover-text { white-space: nowrap; }

  /* The desktop nav row is hidden below the breakpoint; its links and auth
     controls live in the mobile panel instead. */
  .site-header .nav { display: none; }

  /* ----- Mobile nav: the bar controls --------------------------------------
     MobileNav's root ships with the `hidden` attribute, so it is display:none
     above this breakpoint without a desktop rule of our own. This re-displays
     it, which keeps the whole desktop/mobile split inside the media query. */
  .mnav[hidden] {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: none;
  }

  /* Hamburger. 48px square: past the 44px touch-target floor, and the same
     height as the account circle beside it. */
  .mnav__toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: var(--space-12);
    height: var(--space-12);
    min-height: var(--space-12);
    flex: none;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    background: var(--color-bg-subtle);
    color: var(--color-text-secondary);
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: var(--transition-base);
  }
  .mnav__toggle:hover,
  .mnav__toggle[aria-expanded="true"] { color: var(--color-text-primary); }
  /* Exactly one focus indicator: the native outline is replaced, not doubled. */
  .mnav__toggle:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
  }

  /* The account circle (signed in) shares the row with the hamburger, so it
     matches its height and pill radius exactly. */
  .mnav .acct__circle {
    box-sizing: border-box;
    width: var(--space-12);
    height: var(--space-12);
    min-height: var(--space-12);
    border-radius: var(--radius-pill);
    -webkit-user-select: none;
    user-select: none;
  }
  .mnav .acct__menu { top: calc(100% + var(--space-3)); }
  .mnav .acct__item {
    display: flex;
    align-items: center;
    min-height: var(--space-12);
  }

  /* ----- Mobile nav: the slide-down panel ----------------------------------
     Both layers are portalled to <body>, so they position against the viewport.
     The panel hangs off the bottom edge of the 64px bar; the overlay dims
     everything below it and closes the menu on tap. */
  .mnav__overlay {
    position: fixed;
    inset: var(--space-16) 0 0 0;
    z-index: var(--z-overlay);
    background: color-mix(in srgb, var(--color-text-primary) 45%, transparent);
    animation: mnav-fade-in var(--duration-base) var(--ease-out) both;
  }
  /* While the menu is open the header must read as the SAME surface as the panel.
     It is normally translucent (88% chrome) with a backdrop blur, so the cream page
     tints through it and it lands a shade off the panel's solid chrome; its
     border-bottom then draws a seam between the two. Go solid and drop the rule for
     the duration, so bar + panel are one continuous sheet. */
  .site-header:has(.mnav__toggle[aria-expanded="true"]) {
    background: var(--color-bg-chrome);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    border-bottom-color: transparent;
  }
  .mnav__panel {
    position: fixed;
    top: var(--space-16);
    left: 0;
    right: 0;
    /* Fill the rest of the screen: a full-page menu, not a dropped shelf. */
    bottom: 0;
    z-index: var(--z-modal);
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
    /* Scrolls when a long panel meets a short phone, and never shows a bar. */
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    -ms-overflow-style: none;
    /* Same gutter as .container, so the panel lines up with the bar above it. */
    padding: var(--space-5) var(--space-6) calc(var(--space-8) + env(safe-area-inset-bottom, 0px));
    background: var(--color-bg-chrome);
    animation: mnav-drop-in var(--duration-base) var(--ease-out) both;
  }
  .mnav__panel::-webkit-scrollbar { width: 0; height: 0; }

  /* The panel takes focus on open (tabindex=-1) so no LINK gets a ring; the panel
     itself must not paint one either. Focus is still trapped inside it. */
  .mnav__panel:focus,
  .mnav__panel:focus-visible { outline: none; }

  .mnav__links { display: flex; flex-direction: column; }
  /* Sign out is a <button> but sits in the link column, so strip the button
     chrome and let it inherit the row treatment below. */
  button.mnav__link {
    width: 100%;
    background: none;
    border: 0;
    padding-inline: 0;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
  }
  .mnav__link {
    display: flex;
    align-items: center;
    min-height: var(--space-12);
    padding-block: var(--space-3);
    color: var(--color-text-primary);
    font-size: var(--text-xl);
    font-weight: var(--weight-semibold);
    letter-spacing: var(--tracking-tight);
    text-decoration: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .mnav__link:hover { color: var(--color-text-primary); text-decoration: none; }
  .mnav__link:active,
  .mnav__link[aria-current="page"] { color: var(--color-accent); }
  .mnav__link:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
  }

  /* Auth actions: full-width pills pinned to the FOOT of the now full-height
     panel. margin-top:auto eats the free space above them, so the links sit at the
     top and the CTAs sit at the bottom of the screen. */
  .mnav__actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
    margin-top: auto;
  }
  .mnav__cta {
    box-sizing: border-box;
    width: 100%;
    min-height: var(--space-12);
    padding-block: var(--space-3);
    border-radius: var(--radius-pill);
    font-size: var(--text-base);
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .mnav__actions .nav__usage {
    text-align: center;
    padding-block: var(--space-1);
  }
  .mnav__actions .nav__auth-skeleton {
    width: 100%;
    height: var(--space-12);
  }

  @keyframes mnav-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
  }
  @keyframes mnav-drop-in {
    from { opacity: 0; transform: translateY(calc(-1 * var(--space-3))); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* ----- Footer ------------------------------------------------------------
     Desktop is a 5-column grid (brand + 4 link columns) with 96px gaps, which
     unrolled into a very tall stack on a phone. Here: brand across the top, the
     four link columns 2-up beneath it, and a stacked bottom bar. */
  .site-footer__inner {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-8) var(--space-6);
    padding-block: var(--space-10);
  }
  .site-footer__brandcol { grid-column: 1 / -1; }
  .site-footer__tag { margin-top: var(--space-2); }
  .site-footer__col { gap: var(--space-2); }
  .site-footer__col a {
    display: inline-flex;
    align-items: center;
    min-height: var(--space-8);
  }
  /* The hover arrow is dead weight on touch, and it widens every link. */
  .site-footer__col a::after { content: none; }

  /* Bottom bar: copyright over the preference controls, which take the row. */
  .site-footer__bottom {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-4);
    padding-block: var(--space-6) calc(var(--space-10) + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--color-divider);
  }
  .footer-prefs {
    width: 100%;
    justify-content: space-between;
    gap: var(--space-3);
  }
  /* Rule 7: the two pills share this row, so they resolve to one height (48px)
     whatever their padding and border add. */
  .footer-prefs .themesw,
  .footer-prefs .lang__toggle {
    box-sizing: border-box;
    min-height: var(--space-12);
    height: auto;
  }
  .footer-prefs .themesw { padding-inline: var(--space-1); }
  .themesw__opt {
    width: var(--space-10);
    height: var(--space-10);
    -webkit-tap-highlight-color: transparent;
  }
  .themesw__opt svg { width: var(--space-5); height: var(--space-5); }
  .footer-prefs .lang__toggle {
    padding-inline: var(--space-4);
    font-size: var(--text-base);
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .footer-prefs .lang__opt {
    display: flex;
    align-items: center;
    min-height: var(--space-12);
  }
}

/* Motion: the panel appears at once for anyone who asks for less motion. */
@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  .mnav__overlay,
  .mnav__panel { animation: none; }
}

/* ----- Small phones (<= 480px) --------------------------------------------- */
@media (max-width: 480px) {
  /* Tighter footer grid: 2-up still fits, the 96px-scale gaps do not. */
  .site-footer__inner { gap: var(--space-6) var(--space-4); }
  .site-footer__brand .brand { font-size: var(--text-lg); }
  .footer-prefs { gap: var(--space-2); }
}
