/* The section bar (build six G5-U1; lib/site/subnav.ts prints it after the header, js/pages/subnav.js moves it).
   A second sticky row under the site header: paper like the header, quiet links like the header's nav items, the
   current page underlined in Jinn amber. Hidden while the reader scrolls down (it slides up behind the header,
   which sits one layer above it); shown on scroll up, at the top, with the mouse at the top and on keyboard focus.
   Every selector starts with .subnav, so nothing else on a page is touched. --subnav-top and --subnav-h are the
   header's and the bar's measured heights (the script sets them; the fallbacks are the 68px bar plus its rule);
   --subnav-gap is the room an anchored heading leaves for the bar: its height while shown, 0 while hidden.
   Build six part two (S1): a grouped bar (Compare, .subnav[data-grouped]) shows headings that each open a small panel. */

.subnav {
  position: sticky; top: var(--subnav-top, 69px); z-index: 99;
  background: var(--paper); color: var(--ink); border-bottom: 1px solid rgba(21,23,28,.1);
  transition: transform .28s var(--ease);
}
.subnav[data-hidden] { transform: translateY(-100%); }
.subnav__bar { position: relative; width: min(1380px, 100% - 2 * var(--gutter)); margin-inline: auto; display: flex; align-items: center; gap: 14px; min-height: 48px; }
.subnav__name { flex: 0 0 auto; margin: 0; font-family: var(--ui); font-size: .74rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--amber-ink); white-space: nowrap; }
.subnav__list {
  position: relative; flex: 1 1 auto; min-width: 0; display: flex; gap: 2px; margin: 0; padding: 2px 0; list-style: none;
  overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
}
.subnav__list::-webkit-scrollbar { display: none; }
.subnav__list li { flex: 0 0 auto; display: flex; }
.subnav__link {
  position: relative; display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 10px;
  font-family: var(--ui); font-size: .88rem; font-weight: 600; line-height: 1.2; white-space: nowrap;
  color: var(--ink-2); text-decoration: none;
}
.subnav__link:hover { background: rgba(21,23,28,.06); color: var(--ink); }
.subnav__link:focus-visible { outline: 3px solid var(--amber); outline-offset: -3px; }
.subnav__link[aria-current="page"] { color: var(--ink); }
.subnav__link[aria-current="page"]::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 7px; height: 2px; border-radius: 2px; background: var(--amber); }

/* A row longer than its space (Compare's nineteen, any bar on a phone) fades at the edge it continues past; the
   script marks which edges have more. With a mouse, a thin scrollbar shows the row moves. */
.subnav:not([data-grouped]) .subnav__list[data-more~="end"] { mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); }
.subnav:not([data-grouped]) .subnav__list[data-more~="start"] { mask-image: linear-gradient(to left, #000 calc(100% - 40px), transparent); }
.subnav:not([data-grouped]) .subnav__list[data-more~="start"][data-more~="end"] { mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent); }
@media (hover: hover) and (pointer: fine) {
  .subnav__list { scrollbar-width: thin; scrollbar-color: rgba(21,23,28,.22) transparent; }
}

/* ---------- The grouped bar (Compare, Q33): Overview, then one heading per Jinn feature, each opening its pages ----
   The list stays unpositioned so each panel is placed against the bar (.subnav__bar), outside the row's sideways
   scroll: the row may scroll on a phone and the panel is never clipped by it. For the same reason the row's edge fade
   is drawn by the bar, not as a mask on the row. */
.subnav[data-grouped] .subnav__list { position: static; }
.subnav__toggle { gap: 8px; border: 0; background: none; cursor: pointer; }
.subnav__caret { display: block; width: 7px; height: 7px; margin-top: -3px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); transition: transform .2s var(--ease); }
.subnav__toggle[aria-expanded="true"] { background: rgba(21,23,28,.06); color: var(--ink); }
.subnav__toggle[aria-expanded="true"] .subnav__caret { transform: translateY(3px) rotate(225deg); }
.subnav__group[data-current] > .subnav__toggle { color: var(--ink); }
.subnav__group[data-current] > .subnav__toggle::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 7px; height: 2px; border-radius: 2px; background: var(--amber); }
.subnav__panel {
  position: absolute; top: calc(100% + 1px); left: var(--subnav-panel-x, 0); z-index: 2;
  min-width: 248px; margin: 0; padding: 6px; list-style: none;
  background: var(--paper); border: 1px solid rgba(21,23,28,.12); border-radius: 14px;
  box-shadow: 0 18px 36px -18px rgba(21,23,28,.32), 0 2px 6px rgba(21,23,28,.06);
  transition: opacity .16s var(--ease), translate .16s var(--ease);
}
.subnav__panel[hidden] { display: none; }
.subnav__panel li { display: block; }
.subnav__panel .subnav__link { display: flex; width: 100%; padding: 0 14px; border-radius: 9px; }
.subnav__panel .subnav__link[aria-current="page"]::after { content: none; }
.subnav__panel .subnav__link[aria-current="page"] { text-decoration: underline 2px var(--amber); text-underline-offset: 6px; }
@starting-style {
  .subnav__panel { opacity: 0; translate: 0 -4px; }
}
.subnav[data-grouped] .subnav__bar::before, .subnav[data-grouped] .subnav__bar::after {
  content: ""; position: absolute; top: 0; bottom: 0; z-index: 1; width: 40px; pointer-events: none; opacity: 0; transition: opacity .2s var(--ease);
}
.subnav[data-grouped] .subnav__bar::before { left: 0; background: linear-gradient(to right, var(--paper), transparent); }
.subnav[data-grouped] .subnav__bar::after { right: 0; background: linear-gradient(to left, var(--paper), transparent); }
.subnav[data-grouped][data-more~="start"] .subnav__bar::before, .subnav[data-grouped][data-more~="end"] .subnav__bar::after { opacity: 1; }

/* An anchored heading lands below the header, and below the bar while it shows (site.css gives 88px for the header
   alone); while the bar is hidden the script sets the gap to 0, so a jump leaves no empty band over the heading. */
.subnav ~ * [id] { scroll-margin-top: calc(88px + var(--subnav-gap, var(--subnav-h, 48px))); }

/* On a phone the row is the whole width; the section's name stays as the bar's spoken name only. */
@media (max-width: 700px) {
  .subnav__bar { width: 100%; gap: 0; }
  .subnav__name { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  .subnav__list { padding-inline: calc(var(--gutter) - 12px); scroll-padding-inline: var(--gutter); }
  /* the grouped row is six short items: tighter so it fits a phone's width; its panel is a sheet across the bar */
  .subnav[data-grouped] .subnav__link { padding: 0 9px; }
  .subnav[data-grouped] .subnav__toggle { gap: 6px; }
  .subnav[data-grouped] .subnav__group[data-current] > .subnav__toggle::after { left: 9px; right: 9px; }
  .subnav__panel { left: var(--gutter); right: var(--gutter); min-width: 0; }
  .subnav__panel .subnav__link { padding: 0 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .subnav, .subnav__panel, .subnav__caret { transition: none; }
}
