/* The top bar (STORY-04.49; SN :134-140; the mock, TN :134-193), its menus, the slim footer and the floating Help button.
   One background with the page (--paper), a line under it; its row in the one container (shell.css). Every control has at
   least 44 × 44 px to press. Corners from the radius tokens only (or 50% for the round avatar and Help), never square and never
   a pill (SN :19, :137): tests/theme-tokens.test.mjs reads this file's border-radius values. Colours from tokens.css only. */

/* From 861 px the bar stays at the top as the page scrolls (--bar-top: where a page's own sticky parts start, under it); what
   is brought into view clears it. On a phone it scrolls away with the page, as the phone's header did before: the tab bar
   stays at the foot, and the screen keeps its room for the field typed in and its button when the keyboard is open (the
   phone-first rule: the keyboard never hides the field or the button that submits it). */
:root { --bar-top: calc(var(--bar-h) + env(safe-area-inset-top)); }
html { scroll-padding-top: calc(var(--bar-top) + var(--s2)); }
.topbar { position: sticky; top: 0; z-index: 40; padding-top: env(safe-area-inset-top); background: var(--paper); border-bottom: 1px solid var(--line); }
.topbar__in { position: relative; display: flex; align-items: center; gap: var(--s3); height: var(--bar-h); }

.brand {
  display: flex; align-items: center; gap: var(--s3); flex: none; min-height: 44px; border-radius: var(--r-s);
  color: var(--ink); font-family: var(--display); font-weight: 700; font-size: var(--fs-m); line-height: 1.1;
  letter-spacing: -0.01em; text-decoration: none; white-space: nowrap;
}
.brand svg { width: 36px; height: 36px; }

/* Today · Study ▾ · Library ▾ · Progress */
.topnav { margin-inline: auto; }
.topnav > ul { display: flex; align-items: center; gap: var(--s1); }
.topnav__b {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 var(--s3);
  border: 0; border-radius: var(--r-s); background: transparent; color: var(--ink);
  font: inherit; font-weight: 600; font-size: var(--fs-m); text-decoration: none; white-space: nowrap; user-select: none;
  transition: background-color 140ms ease;
}
.topnav__b .chev { width: 16px; height: 16px; margin-inline-end: -3px; color: var(--ink-2); transition: transform 160ms ease; }
.topnav__b[aria-expanded="true"] { background: var(--paper-2); }
.topnav__b[aria-expanded="true"] .chev { transform: rotate(180deg); color: var(--teal); }
/* The current page: a quiet tint, not a filled pill (TN :575). */
.topnav__b[aria-current="page"] { background: var(--teal-tint); color: var(--teal); }
.topnav__b[aria-current="page"] .chev { color: var(--teal); }
@media (hover: hover) and (pointer: fine) {
  .topnav__b:hover { background: var(--paper-2); }
  .topnav__b[aria-current="page"]:hover { background: var(--teal-soft); }
}

/* The right group: the test chip, points and streak, Badges, Upgrade or the diamond, the avatar. */
.topbar__r { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex: none; min-width: 0; margin-inline-start: auto; }
.topnav + .topbar__r { margin-inline-start: 0; }
.tb-dd { position: relative; display: flex; align-items: center; }
.tb-dd--study { position: static; } /* the wide panel is placed against the bar's row, not the button */
.tb-chip {
  display: inline-flex; align-items: center; gap: var(--s2); min-height: 44px; max-width: 240px; padding: 0 var(--s3);
  border: 1px solid var(--edge); border-radius: var(--r-s); background: transparent; color: var(--ink);
  font: inherit; font-weight: 600; font-size: var(--fs-s); white-space: nowrap; text-align: start;
}
.tb-chip__t { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tb-chip--text { border-color: var(--line-2); }
.tb-chip .chev { width: 16px; height: 16px; flex: none; color: var(--ink-2); transition: transform 160ms ease; }
.tb-chip[aria-expanded="true"] { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.tb-chip[aria-expanded="true"] .chev { transform: rotate(180deg); color: var(--teal); }
.tb-pts { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s1); border-radius: var(--r-s); color: var(--ink); font-size: var(--fs-s); text-decoration: none; white-space: nowrap; }
.tb-pts__i { display: inline-flex; align-items: center; gap: 5px; padding: 0 6px; }
.tb-pts__i b { font-weight: 700; font-variant-numeric: tabular-nums; }
.tb-pts__i .i { color: var(--coral-deep); }
.tb-pts__w { display: none; color: var(--ink-2); }
.tb-ibtn {
  position: relative; display: grid; place-items: center; flex: none; width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--edge); border-radius: var(--r-s); background: transparent; color: var(--ink-2); text-decoration: none;
}
.tb-ibtn__n {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: var(--r-s);
  background: var(--sun); color: var(--on-sun); font-size: 0.6875rem; font-weight: 700; line-height: 18px; text-align: center;
  font-variant-numeric: tabular-nums; box-shadow: 0 0 0 2px var(--paper);
}
.tb-ibtn--paid { border-color: var(--sun-ink); color: var(--sun-ink); } /* its edge 3:1 on the bar (04.49 review S3) */
.gem--paid { fill: var(--sun); stroke: var(--sun-ink); }
.tb-upg {
  display: inline-flex; align-items: center; gap: 6px; flex: none; min-height: 44px; padding: 0 var(--s4);
  border-radius: var(--r-s); background: var(--teal); color: var(--surface); font-size: var(--fs-s); font-weight: 700;
  text-decoration: none; white-space: nowrap;
}
.tb-upg .i { display: none; }
.avatar {
  display: grid; place-items: center; flex: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%;
  background: var(--sun); color: var(--on-sun); font-family: var(--display); font-weight: 700; font-size: var(--fs-base);
}
.avatar[aria-expanded="true"] { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--teal); }
.avatar--l { width: 48px; height: 48px; font-size: var(--fs-l); }
@media (hover: hover) and (pointer: fine) {
  .tb-chip:not(.tb-chip--text):hover, .tb-ibtn:hover { border-color: var(--ink-2); color: var(--ink); }
  .tb-pts:hover { background: var(--paper-2); }
  .tb-upg:hover { background: var(--teal-deep); }
}

/* ---------- the menus (nav-menus.js) ---------- */
.topscrim { position: fixed; inset: calc(var(--bar-h) + env(safe-area-inset-top)) 0 0 0; z-index: 35; background: var(--scrim-menu); }
.mega, .tb-pop { position: absolute; z-index: 45; background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--float); }
.mega[hidden], .tb-pop[hidden] { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .mega:not([hidden]), .tb-pop:not([hidden]) { animation: tb-open 140ms ease-out; }
}
@keyframes tb-open { from { opacity: 0; } }

.mega { top: calc(100% + 6px); left: 0; right: 0; overflow: hidden; border-radius: var(--r-l); }
/* A short window (a laptop at 600 px, a phone on its side): a panel scrolls inside itself, every link reachable (04.49 review M2). */
.mega, .tb-pop { max-height: calc(100dvh - var(--bar-h) - env(safe-area-inset-top) - 24px); overflow-y: auto; overscroll-behavior: contain; }
.mega__cols { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mm { display: flex; flex-direction: column; min-width: 0; padding: var(--s4) var(--s5) var(--s3); }
.mm + .mm { border-inline-start: 1px solid var(--line); }
.mm__head { display: flex; align-items: center; gap: var(--s3); min-height: 52px; margin: 0 calc(-1 * var(--s2)) var(--s2); padding: var(--s1) var(--s2); border-radius: var(--r-s); color: var(--ink); text-decoration: none; }
.mm__ico { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: var(--r-s); background: var(--teal-tint); color: var(--teal); }
.mm__ttl { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.mm__ttl b { font-family: var(--display); font-size: var(--fs-l); }
.mm__ttl small { font-size: var(--fs-xs); color: var(--ink-2); }
.mm__go { margin-inline-start: auto; width: 18px; height: 18px; color: var(--ink-2); }
.mm__parts { display: grid; gap: 0; margin-bottom: var(--s3); }
.mm__part { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 0 calc(-1 * var(--s2)); padding: 0 var(--s2); border-radius: var(--r-s); color: var(--ink); font-size: var(--fs-m); line-height: 1.25; text-decoration: none; }
.mm__code { display: grid; place-items: center; flex: none; min-width: 32px; height: 24px; padding: 0 6px; border-radius: var(--r-s); background: var(--teal-tint); color: var(--teal); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }
.mm__pt { min-width: 0; }
.mm__foot { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: auto; padding-top: var(--s3); border-top: 1px solid var(--line); }
.mm__link { display: flex; align-items: center; gap: 7px; min-height: 44px; padding: 0 var(--s2); border-radius: var(--r-s); color: var(--teal); font-size: var(--fs-s); font-weight: 700; white-space: nowrap; text-decoration: none; }
.mega__foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: var(--s1) var(--s5); border-top: 1px solid var(--line); background: var(--paper); }
.mf { display: inline-flex; align-items: center; gap: var(--s2); min-height: 44px; padding: 0 10px; margin-inline: -10px; border-radius: var(--r-s); color: var(--ink-2); font-size: var(--fs-s); font-weight: 600; text-decoration: none; }
.mf--main { color: var(--teal); font-weight: 700; font-size: var(--fs-m); }

.tb-pop { top: calc(100% + 10px); padding: var(--s2); border-radius: var(--r-m); }
.tb-pop--lib { left: 0; width: 340px; }
.tb-pop--test, .tb-pop--me { right: 0; }
.tb-pop--test { width: 300px; }
.tb-pop--me { width: 312px; }
.tb-pop__h { padding: 6px 10px; font-family: var(--text); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
.tb-pop__all { display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: 0 10px; margin-bottom: 6px; border-bottom: 1px solid var(--line); border-radius: var(--r-s); color: var(--teal); font-weight: 700; text-decoration: none; }
.tb-pop__grp + .tb-pop__grp { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
.tb-row {
  display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 44px; padding: 4px 10px; border: 0; border-radius: var(--r-s);
  background: transparent; color: var(--ink); text-align: start; font: inherit; font-weight: 600; font-size: var(--fs-m); line-height: 1.25; text-decoration: none;
}
.tb-row__ico { display: grid; place-items: center; flex: none; color: var(--ink-2); }
.tb-row__t { display: flex; flex-direction: column; min-width: 0; }
.tb-row__t small { font-size: var(--fs-xs); font-weight: 500; color: var(--ink-2); }
.tb-pop--lib .tb-row__ico { width: 36px; height: 36px; border-radius: var(--r-s); background: var(--teal-tint); color: var(--teal); }
.tb-row[aria-current] { background: var(--teal-tint); font-weight: 700; }
.tb-pop--test .tb-row { justify-content: space-between; }
@media (hover: hover) and (pointer: fine) {
  .mm__head:hover, .mm__part:hover, .mm__link:hover, .mf:hover, .tb-row:not([aria-current]):hover, .tb-pop__all:hover { background: var(--paper-2); }
}
.tb-me { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) 10px var(--s3); margin-bottom: 6px; border-bottom: 1px solid var(--line); }
.tb-me__t { min-width: 0; line-height: 1.3; }
.tb-me__t b { font-family: var(--display); }
.tb-me__rank { color: var(--teal); font-size: var(--fs-s); font-weight: 700; }
.tb-me__mail { color: var(--ink-2); font-size: var(--fs-s); overflow-wrap: anywhere; }
.tb-me__pts { display: none; color: var(--ink-2); font-size: var(--fs-s); }

/* ---------- the footer and Help ---------- */
.appfoot { padding-bottom: 76px; background: var(--paper); border-top: 1px solid var(--line); } /* room under the last row for Help */
.appfoot__in p { padding-block: var(--s2); font-size: var(--fs-s); line-height: 1.45; color: var(--ink-2); }
.appfoot__in a { display: inline-flex; align-items: center; min-height: 44px; color: var(--ink); font-weight: 600; }
.help-fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 30; display: grid; place-items: center; width: 44px; height: 44px;
  border: 1px solid var(--edge); border-radius: 50%; background: var(--surface); color: var(--ink-2); box-shadow: var(--float); text-decoration: none;
}
.help-fab:empty { display: none; }
/* Over a page with its own bar at the foot (a lesson's Back and Next), Help floats above that bar; before onboarding there is
   nothing to ask for help with yet that the welcome screens do not show, and their main button sits at the foot: no Help. */
body:has(.lp-nav) .help-fab { bottom: 100px; }
body.no-nav .help-fab { display: none; }

/* ---------- widths ---------- */
@media (min-width: 1500px) {
  .tb-pts__w { display: inline; }
  .tb-upg .i { display: block; }
}
@media (max-width: 1099px) {
  .brand__w, .tb-pts, .tb-ibtn--badges { display: none; }
  .tb-me__pts { display: block; }
}
@media (max-width: 860px) {
  .topbar__in { gap: var(--s3); }
  .brand svg { width: 44px; height: 44px; }
  .topbar__r { flex: 1; min-width: 0; gap: var(--s3); margin-inline-start: 0; }
  .topbar__r > .tb-chip, .topbar__r > .tb-dd--test { flex: 1; min-width: 0; max-width: none; }
  .tb-dd--test .tb-chip { width: 100%; max-width: none; }
  .topbar__plan { display: none; }
  .tb-pop--test { left: 0; right: auto; width: min(300px, calc(100vw - 2 * var(--gutter))); }
  .tb-pop--me { width: min(312px, calc(100vw - 2 * var(--gutter))); }
  .appfoot { padding-bottom: calc(64px + 72px + env(safe-area-inset-bottom)); } /* the tab bar, then Help above it */
  .help-fab { right: var(--gutter); bottom: calc(64px + 12px + env(safe-area-inset-bottom)); }
  body:has(.lp-nav) .help-fab { bottom: calc(64px + 88px + env(safe-area-inset-bottom)); }
}
body.no-nav .appfoot { padding-bottom: 76px; }
@media (max-width: 860px) {
  :root { --bar-top: 0px; }
  .topbar { position: relative; }
}
/* Before onboarding the bar holds the brand only and scrolls away with the page (the onboarding screens are pictured from
   their heading, STORY-04.9). */
:root:has(body.no-nav) { --bar-top: 0px; }
body.no-nav .topbar { position: relative; }
