/* ─────────────────────────────────────────────────────────────────
   css/responsive-topbar.css

   Wave 7.1 (2026-05-09) — 100% mobile-friendly topbar across the
   builder + use surfaces. Documented breakpoints (kept in sync
   with docs/responsive-breakpoints.md):

     xs   ≤ 360px   — iPhone SE 1st gen, oldest Android
     sm   361-480   — std phone portrait
     md   481-768   — phone landscape / iPad mini portrait
     lg   769-1024  — iPad landscape / narrow laptop
     xl   1025-1280 — std laptop
     2xl  ≥ 1281    — desktop

   THE BUG THIS FIXES (Luke 2026-05-09):
     "huge issue its not mobile friendly — half the shit, the bar
      at the top, once it gets smaller I can't access anything."

   THE FIX:
     1. Pills don't shrink past readability. Past audit had them
        going to 0.72rem font-size + 0.4rem padding on phone —
        unreadable AND tap-targets below WCAG 44px floor.
     2. Topbar-actions becomes a horizontal scroller on ≤768px
        with momentum scroll on iOS (-webkit-overflow-scrolling).
        Swipe to access every pill.
     3. Right-edge fade gradient hints "more content →" so the
        user knows there's swipe room. Without this hint, NN/g
        research shows ~40% of users miss horizontal scroll.
     4. Push to Devices (primary CTA) + user pill stay PINNED to
        the right edge OUTSIDE the scroll, so the ship action is
        always one tap away.
     5. ⋯ "More" overflow menu (mounted by topbar-overflow.js)
        gives a non-swipe path to every control — accessibility
        for users with motor difficulties + dwell-click users.

   Loaded LAST in the cascade so its !important overrides win
   over wave7-mobile.css's tap-target floor (we keep the floor,
   but enforce it on the scrollable pills with stronger sizing).

   LABEL: PILOT-READY. Live test on iOS Safari + Android Chrome
   + iPad Safari before PRODUCTION-READY (overflow-x: auto +
   sticky positioning interact subtly across browsers).
───────────────────────────────────────────────────────────────── */

/* ── Builder topbar — collapse to ⋯ menu on ≤768px ──────────
   2026-05-09 (Luke flag v2): the prior horizontal-scroll approach
   hid pills behind a fade gradient that desktop users don't
   naturally swipe past. They saw "everything's gone." Real fix:
   on phone + small tablet, HIDE every secondary pill (display:
   none) and surface the SINGLE primary action (Push to Devices)
   inline. ⋯ More button is the obvious + universal path to
   everything else — no scrolling, no hidden gradient, no
   guesswork. The topbar-overflow.js BottomSheet lists every
   action including the hidden ones, so nothing's lost. */
@media (max-width: 768px) {
  /* 2026-06-01 (Luke, 3rd pass — Codex stop-gate): EVERYTHING in this
     ≤768px block is SCOPED TO #topbar (the BUILDER topbar). This file is
     ALSO loaded by use.html (the runtime player), whose topbar is a bare
     `.topbar` with NO id and a totally different child set (Back / title /
     speech-mode toggle / + Save). The blanket `.topbar > * {display:none}`
     hide-then-reshow approach below is correct for the builder but would
     ANNIHILATE use.html's runtime controls on phones (Back + Save + mode
     toggle all gone — a stroke-patient core-path regression). builder's
     topbar is the ONLY `#topbar`, so `#topbar` scoping makes these rules
     physically unable to touch use.html. use.html keeps its own inline
     ≤820px wrap rules. (#topbar = specificity 1,x,0 also cleanly beats
     builder-mobile.css's .topbar rules we intentionally supersede.) */

  /* 2026-06-01 (Luke, 4th pass): SINGLE ROW, exact order Luke specified —
       [🌍 earth] [📝 Worksheet]   ( logo )   [☰ hamburger] [⋯ 3 dots]
     ONE row, never wrap. The builder layout sizes off --topbar-h (builder.css
     .app-layout calc(100vh - --topbar-h), sidebar top:, backdrops); a single
     row fits 60px, so keep the variable there. Only builder CSS consumes
     --topbar-h; use.html consumes it nowhere, so :root is inert there. */
  :root {
    --topbar-h: 60px;
  }
  #topbar {
    overflow: visible;
    flex-wrap: nowrap;          /* ONE row — never wrap (Luke) */
    min-height: var(--topbar-h);
    height: var(--topbar-h);
    column-gap: 0.4rem;
    align-items: center;
    /* 2026-06-01 (Luke): PIN the topbar to the viewport. It used to be
       position:relative (in flow), so a small spurious window-scroll drifted
       it UP while the position:fixed side rails (anchored at top:var(--topbar-h))
       stayed put — opening a gap above the rails ("spacing at the top" on
       scroll). Fixed topbar (0→60) + .app-layout offset below keeps the
       topbar and BOTH rails perfectly flush on any scroll. z-index 60 sits
       above the rails (49/50) so it's never covered. Verified with a
       headless mobile render: post-scroll gap = 0. */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 60;
  }
  /* Topbar is now out of flow — push the layout down by its height so the
     content starts below it (net position unchanged at rest, but pinned on
     scroll). builder-only: .app-layout doesn't exist on use.html. */
  .app-layout {
    margin-top: var(--topbar-h);
  }

  /* Hide EVERY topbar child, then re-show + order ONLY the five Luke wants. */
  #topbar > * {
    display: none !important;
  }

  /* 1 — 🌍 earth (community-nav), left edge. */
  #topbar > #leftRailToggle {
    display: inline-flex !important;
    order: 1;
    flex: 0 0 auto;
  }

  /* 2 — 📝 Worksheet. It lives INSIDE .topbar-actions, so re-show that
     container INLINE (not a row) and reveal ONLY Worksheet within it; every
     other action in there (Students/Device/Symbols/quickfire) stays collapsed
     into ⋯. */
  #topbar > .topbar-actions {
    display: flex !important;
    order: 2;
    flex: 0 0 auto;
    min-width: 0;
    overflow: visible;
    -webkit-mask-image: none;
            mask-image: none;
  }
  #topbar .topbar-actions > * {
    display: none !important;
  }
  #topbar .topbar-actions > #worksheetBtn {
    display: inline-flex !important;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  /* 3 — logo (brand), centered in the flexible middle. */
  #topbar > .topbar-brand {
    display: inline-flex !important;
    order: 3;
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
    text-align: center;
    text-decoration: none;
  }
  #topbar > .topbar-brand .topbar-brand-name {
    font-size: 0.95rem;
    line-height: 1.05;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* Keep the "Board Builder" tag visible (builder-mobile.css hides it at
     0,1,0; this 1,2,0 selector wins). */
  #topbar > .topbar-brand .topbar-brand-tag {
    display: block;
    font-size: 0.58rem;
    line-height: 1.05;
  }

  /* 4 — ☰ boards hamburger. */
  #topbar > #sidebarHamburger {
    display: inline-flex !important;
    order: 4;
    flex: 0 0 auto;
  }

  /* 5 — ⋯ More: every other tool (Students / Device / Accessibility /
     Settings / account / Sign in / quickfire build…) lives here, so
     collapsing the rest never strands an action (Codex). Right edge. */
  #topbar > .topbar-overflow-pinned {
    display: flex !important;
    order: 5;
    flex: 0 0 auto;
  }
}

/* 2026-06-01 (Luke): the editor-toolbar (Share / Preview / Rotate / Undo /
   Redo / Symbols / Language) is clutter above the tiles on a phone — hide
   the whole section ≤768px. Its actions are surfaced in the ⋯ More menu
   ("Tools" section, topbar-overflow.js) so NOTHING is stranded — especially
   Language, which bilingual AAC users depend on. */
@media (max-width: 768px) {
  .editor-toolbar { display: none !important; }
}

/* xs — extra-small phones ≤360px get the most aggressive layout.
   #topbar-scoped (builder only) — use.html shares this file. */
@media (max-width: 360px) {
  #topbar { gap: 0.25rem; padding: 0 0.4rem; }
  #topbar .topbar-brand-name { font-size: 0.92rem; }
  #topbar .topbar-actions > .topbar-btn-primary {
    font-size: 0.75rem !important;
    padding: 0.5rem 0.6rem !important;
  }
  #topbar .board-name-input { max-width: 30vw; min-width: 60px; font-size: 0.85rem !important; }
  /* On the smallest phones, hide Sign Up too — Sign In + ⋯ menu
     get the user to signup via a /signup link. */
  #topbar > #topbarSignUp {
    display: none !important;
  }
}

/* lg+ — restore everything inline on tablet landscape and larger. */
@media (min-width: 769px) and (max-width: 1024px) {
  /* In this band, decide which pills stay inline. Currently we
     show ALL inline above 768px; ⋯ button is hidden via the rule
     below. Future split could collapse Print/Worksheet here. */
}

/* ── Pinned-right primary CTA + user pill ──────────────────── */
/* On ≤768px, the user pill area + Push to Devices need to stay
   visible so the ship-action and account access aren't buried
   in the scroller. The .topbar-overflow-pinned wrapper is added
   by JS (topbar-overflow.js); CSS pins it to the right side
   OUTSIDE the scrolling area. */
@media (max-width: 768px) {
  .topbar-overflow-pinned {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.3rem;
  }
  /* The ⋯ More button sits inside .topbar-overflow-pinned.
     Made eye-catching (amber accent) so users find it without
     needing a tooltip. NN/g #6 recognition — the button needs
     to LOOK like the path to "everything else" or users assume
     features were removed. */
  .topbar-overflow-btn {
    flex-shrink: 0;
    background: rgba(232, 168, 56, 0.15);
    border: 1.5px solid var(--amber, #E8A838);
    color: var(--amber, #E8A838);
    border-radius: 10px;
    padding: 0.55rem 0.85rem;
    font-size: 1.25rem;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    min-height: 44px;
    min-width: 48px;
    /* Subtle glow so the button is the first thing the eye lands
       on after the brand. */
    box-shadow: 0 2px 8px rgba(232, 168, 56, 0.2);
  }
  .topbar-overflow-btn:hover,
  .topbar-overflow-btn[aria-expanded="true"] {
    background: var(--amber, #E8A838);
    color: #1A1A2E;
    box-shadow: 0 4px 14px rgba(232, 168, 56, 0.4);
  }
  .topbar-overflow-btn:active {
    transform: translateY(1px);
  }
}
@media (min-width: 769px) {
  /* On lg+, no overflow menu needed — all pills inline. Hide the
     ⋯ button if the JS module decided to mount it anyway. */
  .topbar-overflow-btn { display: none; }
  /* Quickfire bar is a MOBILE-only affordance — on desktop the AI rail
     has its own quick-build input, so hide the topbar duplicate. */
  .topbar-quickbuild { display: none !important; }
  /* Strip the mask-image fade on desktop; not needed when nothing
     is scrolling. */
  .topbar-actions {
    -webkit-mask-image: none;
            mask-image: none;
  }
}

/* ── BottomSheet content for the ⋯ menu ────────────────────── */
.topbar-overflow-sheet {
  width: min(360px, 92vw);
  background: #FFF;
  border-radius: 16px;
  padding: 0.5rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
  max-height: 70vh;
  overflow-y: auto;
}
.topbar-overflow-sheet h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(0, 0, 0, 0.55);
  margin: 0.5rem 0.6rem 0.4rem;
  font-weight: 700;
}
.topbar-overflow-sheet button {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  background: transparent;
  border: none;
  text-align: left;
  padding: 0.85rem 0.85rem;
  border-radius: 10px;
  font-size: 0.95rem;
  color: #1A1A2E;
  cursor: pointer;
  min-height: 44px;
}
.topbar-overflow-sheet button:hover {
  background: rgba(232, 168, 56, 0.08);
}
.topbar-overflow-sheet button:active {
  background: rgba(232, 168, 56, 0.16);
}

/* ── Use.html topbar — same horizontal-scroll pattern ──────── */
/* Use.html topbar markup is different (no .topbar-actions wrapper)
   but the same pile-up problem exists once the language pill +
   network pill mount. Apply the same scrollable-row pattern by
   targeting the .topbar itself on phone. */
@media (max-width: 600px) {
  /* Only when use.html is the surface — the .topbar-mode +
     .topbar-install combination only exists there. Builder's
     topbar uses .topbar-actions. */
  body:has(.topbar-mode) .topbar {
    overflow-x: hidden;
    overflow-y: hidden;
    flex-wrap: nowrap;
    /* 2026-06-02 (Luke: "huge white line at the top on all devices"). This
       block predates use-topbar-hamburger.js, which now collapses EVERY pill
       into the ☰ — so the topbar never scrolls horizontally. The right-edge
       scroll-fade mask had nothing to hint at; it just faded the topbar's last
       20px to transparent, exposing the white page behind it = the "white
       line/glow" on the right. Mask removed; overflow-x:auto → hidden since
       there's nothing to scroll. */
  }
  body:has(.topbar-mode) .topbar::-webkit-scrollbar { display: none; }
  body:has(.topbar-mode) .topbar > * {
    flex-shrink: 0;
  }
  body:has(.topbar-mode) .topbar-title {
    /* Title can shrink — it's the variable-width element; pills
       around it are fixed-shape. */
    flex-shrink: 1;
    min-width: 60px;
  }
}
