/*
 * OLS frost bar (Mo, 16 Nov 2026): ONE shared component for every row of pills or chips that should never stack.
 * "Apply the glass frosted effect ... make it scrollable horizontally like the 3D card button so it doesn't stack
 * vertically" and "apply that frost scrollable bar to all desktop, tablets, phones, everything".
 *
 * The look is the 3D card step bar (agents/3da/kit/parts/stepbar.js): a frosted glass track (blur + saturate with a
 * solid fallback, hairline border, soft inner highlight), round glass chevrons, soft fades on the overflowing edge(s).
 * At every width the row is ONE line; when it does not fit it slides sideways (swipe, trackpad, shift-wheel, mouse
 * drag, chevrons). When it fits there is no scrolling UI, only the glass bar. On paper it is a plain wrapping row.
 *
 * Groups (assets/js/frostbar.js holds the same list):
 *   nav[aria-label="Breadcrumb"], nav.ols-live-crumbs   every breadcrumb trail (pill styles in buttons.css)
 *   .ols-hc nav.ols-hc__crumbs                          topic map trail (game-map.php), its own blue pills stay
 *   .ols-badges                                         revision page hero pills (Paper / Topic / paper code)
 *   ul.ols-ls__chips                                    spec-code chips (ols-reengagement lesson-specs.php)
 *   .ols-ssr-filters, .ols-ssr-boards                   site search result filters
 *   [data-frostbar]                                     anything new: add the attribute ("off" opts out)
 * Glass look only, no sliding (section 3): landing tab bars (.ols-ltabs-list) and related-topic pills.
 *
 * Two states:
 *   before the script: the group itself is the glass track and slides (overflow-x), so it never wraps either way;
 *   after the script: .ols-fb is the glass track (not scrolling), .ols-fb-s inside it is the one-row scroller,
 *   .ols-fb-nav are the chevrons; fl / fr on the track = more to scroll left / right. Lists (ul/ol) keep their
 *   markup: the script wraps them in a div.ols-fb.ols-fb-w and the list itself becomes the scroller.
 * The scroller reaches a few pixels above and well below the track (padding with matching negative margins), so
 * focus rings, the hover lift and pill shadows are never clipped.
 * Tokens per group: --fb-r (track radius), --fb-pad (gap between track and items), --fb-gap, --fb-fade.
 *
 * House rules (fix of 16 Nov 2026, from the Gradebook print view):
 *   - The bar sets display on a group only at zero specificity (section 0), so a page's own [hidden], display:none,
 *     print and toggle rules win. Only the script's own wrapper and chevrons get a stronger display.
 *   - !important only where a rule must beat another !important: flex-wrap (an old badge rule forces wrap), and the
 *     breadcrumb links' hover look (buttons.css). Everything else wins on specificity (html:root body ...).
 *   - Scoped to the groups above; no bare html/body rules. The page's vertical scroll is never moved by the script.
 */

/* ---------- tokens per group ---------- */
html:root body :is(nav[aria-label="Breadcrumb"], nav.ols-live-crumbs) {
	--fb-r: 16px;
	--fb-gap: 4px;
}
html:root body :is(.ols-hc__crumbs, .ols-badges, .ols-ls__chips, .ols-ssr-filters, .ols-ssr-boards, .ols-fb-w) {
	--fb-r: 999px;
}
html:root body .ols-badges {
	--fb-gap: 8px;
}
html:root body :is(.ols-ls__chips, .ols-hc__crumbs) {
	--fb-gap: 6px;
}

/* ---------- 0. a row by default, at zero specificity: any display rule of the page (none, block, its own
   toggles and print rules) wins over this, and [hidden] stays hidden ---------- */
:where(nav[aria-label="Breadcrumb"], nav.ols-live-crumbs, .ols-badges, ul.ols-ls__chips, .ols-ssr-filters, .ols-ssr-boards, [data-frostbar], .ols-fb-s):where(:not([hidden])) {
	display: flex;
}

html:root body :is(nav[aria-label="Breadcrumb"], nav.ols-live-crumbs, .ols-badges, ul.ols-ls__chips, .ols-ssr-filters, .ols-ssr-boards, [data-frostbar])[hidden] {
	display: none;
}

/* Everything that makes the bar a bar is for screens only: on paper the groups fall back to their own styles
   and section 4 makes them plain wrapping rows. */
@media screen {
	/* ---------- 1. before the script: the group is the glass track and slides by itself ---------- */
	html:root body :is(nav[aria-label="Breadcrumb"], nav.ols-live-crumbs, .ols-hc nav.ols-hc__crumbs, .ols-badges, ul.ols-ls__chips, .ols-ssr-filters, .ols-ssr-boards, [data-frostbar]:not([data-frostbar="off"])):not(.ols-fb):not(.ols-fb-s) {
		flex-direction: row;
		flex-wrap: nowrap !important;
		align-items: center;
		gap: var(--fb-gap, 6px);
		box-sizing: border-box;
		width: fit-content;
		max-width: 100%;
		min-width: 0;
		padding: var(--fb-pad, 4px);
		border-radius: var(--fb-r, 16px);
		background: rgba(246, 248, 253, 0.62);
		-webkit-backdrop-filter: blur(14px) saturate(1.5);
		backdrop-filter: blur(14px) saturate(1.5);
		border: 1px solid rgba(28, 36, 75, 0.12);
		box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.95), inset 0 -1px 0 rgba(28, 36, 75, 0.04), 0 8px 22px rgba(28, 36, 75, 0.07);
		overflow-x: auto;
		overflow-y: hidden;
		scrollbar-width: none;
		-ms-overflow-style: none;
		overscroll-behavior-x: contain;
		list-style: none;
	}
	html:root body :is(nav[aria-label="Breadcrumb"], nav.ols-live-crumbs, .ols-hc nav.ols-hc__crumbs, .ols-badges, ul.ols-ls__chips, .ols-ssr-filters, .ols-ssr-boards, [data-frostbar]):not(.ols-fb)::-webkit-scrollbar {
		display: none;
	}
	html:root body :is(nav[aria-label="Breadcrumb"], nav.ols-live-crumbs, .ols-hc nav.ols-hc__crumbs, .ols-badges, ul.ols-ls__chips, .ols-ssr-filters, .ols-ssr-boards, [data-frostbar]:not([data-frostbar="off"])):not(.ols-fb):not(.ols-fb-s) > * {
		flex: 0 0 auto;
		white-space: nowrap;
	}

	/* ---------- 2. after the script: the glass track ---------- */
	html:root body .ols-fb.ols-fb {
		position: relative;
		flex-direction: row;
		flex-wrap: nowrap !important;
		align-items: center;
		box-sizing: border-box;
		width: fit-content;
		max-width: 100%;
		min-width: 0;
		padding: 0;
		border-radius: var(--fb-r, 16px);
		background: rgba(246, 248, 253, 0.62);
		-webkit-backdrop-filter: blur(14px) saturate(1.5);
		backdrop-filter: blur(14px) saturate(1.5);
		border: 1px solid rgba(28, 36, 75, 0.12);
		box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.95), inset 0 -1px 0 rgba(28, 36, 75, 0.04), 0 8px 22px rgba(28, 36, 75, 0.07);
		overflow: visible;
	}
	/* the wrapper round a list is the script's own element: it shows only while the list shows */
	html:root body .ols-fb-w.ols-fb-w {
		display: flex;
	}
	html:root body .ols-fb-w.ols-fb-w.ols-fb-off,
	html:root body .ols-fb-w.ols-fb-w:has(> .ols-fb-s[hidden]) {
		/* the list is hidden by the page: the empty track disappears but keeps its (empty) box, so the script sees
		   the list come back */
		border-color: transparent;
		background: none;
		-webkit-backdrop-filter: none;
		backdrop-filter: none;
		box-shadow: none;
	}
	@supports not ((backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px))) {
		html:root body :is(nav[aria-label="Breadcrumb"], nav.ols-live-crumbs, .ols-hc nav.ols-hc__crumbs, .ols-badges, ul.ols-ls__chips, .ols-ssr-filters, .ols-ssr-boards, [data-frostbar]):not(.ols-fb-s),
		html:root body .ols-fb.ols-fb {
			background: #f4f6fb;
		}
	}

	/* the one-row scroller */
	html:root body .ols-fb.ols-fb > .ols-fb-s {
		position: relative;
		flex: 1 1 auto;
		flex-direction: row;
		flex-wrap: nowrap !important;
		align-items: center;
		gap: var(--fb-gap, 6px);
		box-sizing: border-box;
		width: auto;
		min-width: 0;
		max-width: 100%;
		margin: -5px 0 -18px;
		padding: calc(var(--fb-pad, 4px) + 5px) var(--fb-pad, 4px) calc(var(--fb-pad, 4px) + 18px);
		border: 0;
		border-radius: 0;
		background: transparent;
		box-shadow: none;
		-webkit-backdrop-filter: none;
		backdrop-filter: none;
		list-style: none;
		overflow-x: auto;
		overflow-y: hidden;
		scrollbar-width: none;
		-ms-overflow-style: none;
		overscroll-behavior-x: contain;
		scroll-behavior: smooth;
		touch-action: pan-x pan-y;
	}
	html:root body .ols-fb.ols-fb > .ols-fb-s::-webkit-scrollbar {
		display: none;
	}
	html:root body .ols-fb.ols-fb > .ols-fb-s:focus-visible {
		outline: 2px solid #2563eb;
		outline-offset: -2px;
		border-radius: var(--fb-r, 16px);
	}
	html:root body .ols-fb.ols-fb > .ols-fb-s > :not(.ols-breadcrumb-sep):not(.ols-live-crumb-sep):not(.ols-hc__sep) {
		flex: 0 0 auto;
		white-space: nowrap;
		margin-top: 0;
		margin-bottom: 0;
	}
	html:root body .ols-fb.ols-fb > .ols-fb-s > .ols-hc__sep {
		flex: 0 0 auto;
	}
	html:root body .ols-fb.ols-fb > .ols-fb-s.is-drag {
		scroll-behavior: auto;
		cursor: grabbing;
	}
	html:root body .ols-fb.ols-fb > .ols-fb-s.is-drag * {
		cursor: grabbing;
	}

	/* fades on the overflowing edge(s) */
	html:root body .ols-fb.ols-fb.fl > .ols-fb-s {
		-webkit-mask-image: linear-gradient(to right, transparent 0, #000 var(--fb-fade, 34px));
		mask-image: linear-gradient(to right, transparent 0, #000 var(--fb-fade, 34px));
	}
	html:root body .ols-fb.ols-fb.fr > .ols-fb-s {
		-webkit-mask-image: linear-gradient(to left, transparent 0, #000 var(--fb-fade, 34px));
		mask-image: linear-gradient(to left, transparent 0, #000 var(--fb-fade, 34px));
	}
	html:root body .ols-fb.ols-fb.fl.fr > .ols-fb-s {
		-webkit-mask-image: linear-gradient(to right, transparent 0, #000 var(--fb-fade, 34px), #000 calc(100% - var(--fb-fade, 34px)), transparent 100%);
		mask-image: linear-gradient(to right, transparent 0, #000 var(--fb-fade, 34px), #000 calc(100% - var(--fb-fade, 34px)), transparent 100%);
	}

	/* the chevrons: round glass buttons, only when there is more to scroll that way (--fb-cs set by the script) */
	html:root body .ols-fb.ols-fb > .ols-fb-nav {
		position: absolute;
		top: 50%;
		z-index: 3;
		box-sizing: border-box;
		width: var(--fb-cs, 30px);
		height: var(--fb-cs, 30px);
		min-width: 0;
		min-height: 0;
		margin: calc(var(--fb-cs, 30px) / -2) 0 0;
		padding: 0;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		cursor: pointer;
		color: #1c244b;
		font: inherit;
		line-height: 1;
		text-transform: none;
		background: rgba(255, 255, 255, 0.86);
		-webkit-backdrop-filter: blur(10px);
		backdrop-filter: blur(10px);
		border: 1px solid rgba(28, 36, 75, 0.16);
		box-shadow: 0 4px 12px rgba(28, 36, 75, 0.14), inset 0 1px 0 #fff;
		opacity: 0;
		visibility: hidden;
		transition: opacity 0.2s ease, visibility 0.2s, transform 0.18s ease;
		-webkit-tap-highlight-color: transparent;
	}
	html:root body .ols-fb.ols-fb > .ols-fb-nav svg {
		width: calc(var(--fb-cs, 30px) * 0.47);
		height: calc(var(--fb-cs, 30px) * 0.47);
		display: block;
		pointer-events: none;
	}
	html:root body .ols-fb.ols-fb > .ols-fb-prev {
		left: 3px;
	}
	html:root body .ols-fb.ols-fb > .ols-fb-next {
		right: 3px;
	}
	html:root body .ols-fb.ols-fb.fl > .ols-fb-prev,
	html:root body .ols-fb.ols-fb.fr > .ols-fb-next {
		opacity: 1;
		visibility: visible;
	}
	html:root body .ols-fb.ols-fb > .ols-fb-nav:hover {
		transform: scale(1.06);
	}
	html:root body .ols-fb.ols-fb > .ols-fb-nav:focus-visible {
		outline: 2px solid #2563eb;
		outline-offset: 2px;
	}
	@supports not ((backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px))) {
		html:root body .ols-fb.ols-fb > .ols-fb-nav {
			background: #ffffff;
		}
	}

	/* breadcrumbs: the step bar's hover lift and sheen on the links (mouse only). The !important here beats the
	   links' own !important hover look in buttons.css. */
	@media (hover: hover) {
		html:root body .ols-fb--crumbs.ols-fb > .ols-fb-s > a {
			overflow: hidden;
		}
		html:root body .ols-fb--crumbs.ols-fb > .ols-fb-s > a::before {
			content: "" !important;
			position: absolute;
			top: 0;
			bottom: 0;
			left: -60%;
			width: 50%;
			pointer-events: none;
			border-radius: inherit;
			background: linear-gradient(105deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.75) 50%, rgba(255, 255, 255, 0) 100%);
			transform: translateX(0);
			opacity: 0;
		}
		html:root body .ols-fb--crumbs.ols-fb > .ols-fb-s > a:hover {
			transform: translateY(-1px);
			background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(232, 239, 255, 0.78)) !important;
			box-shadow: 0 6px 14px rgba(37, 99, 235, 0.14), inset 0 1px 0 #fff, inset 0 0 0 1px rgba(37, 99, 235, 0.14) !important;
			color: #1c244b !important;
		}
		html:root body .ols-fb--crumbs.ols-fb > .ols-fb-s > a:hover::before {
			opacity: 1;
			transform: translateX(330%);
			transition: transform 0.75s ease, opacity 0.2s ease;
		}
	}
	html:root body .ols-fb--crumbs.ols-fb > .ols-fb-s > a:focus-visible {
		transform: translateY(-1px);
	}

	/* phones: the compact breadcrumb (ols-mobile-compact: 22 px pills, 1 px inset) keeps its 44 px tap areas */
	@media (max-width: 640px) {
		html:root body :is(nav[aria-label="Breadcrumb"], nav.ols-live-crumbs) {
			--fb-r: 10px;
			--fb-gap: 1px;
			--fb-pad: 1px;
		}
		html:root body .ols-fb.ols-fb {
			--fb-fade: 28px;
		}
		html:root body .ols-fb--crumbs.ols-fb > .ols-fb-s {
			margin: -10px 0;
			padding: 11px 1px;
		}
	}

	/* ---------- 3. glass only, no sliding (Mo, 16 Nov 2026) ----------
	 * Landing tab bars (landing tabs, board landing units, topic map units: .ols-ltabs-list) keep their layout, three
	 * across on phones; the related-topic pills in the revision page footer all stay visible. Both get the frost bar's
	 * glass track only. The hairline is an inset shadow, so no bar changes size. */
	html:root body .ols-ltabs-list,
	html:root body .ols-page-foot .ols-related-grid {
		background: rgba(246, 248, 253, 0.62);
		-webkit-backdrop-filter: blur(14px) saturate(1.5);
		backdrop-filter: blur(14px) saturate(1.5);
		box-shadow: inset 0 0 0 1px rgba(28, 36, 75, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.95), inset 0 -1px 0 rgba(28, 36, 75, 0.04), 0 8px 22px rgba(28, 36, 75, 0.07);
	}
	html:root body .ols-page-foot .ols-related-grid {
		box-sizing: border-box;
		padding: 5px;
		border-radius: 16px;
	}
	@supports not ((backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px))) {
		html:root body .ols-ltabs-list,
		html:root body .ols-page-foot .ols-related-grid {
			background: #f4f6fb;
		}
	}

	@media (prefers-reduced-motion: reduce) {
		html:root body .ols-fb.ols-fb > .ols-fb-s {
			scroll-behavior: auto;
		}
		html:root body .ols-fb.ols-fb > .ols-fb-s > *,
		html:root body .ols-fb.ols-fb > .ols-fb-nav {
			transition: none;
		}
		html:root body .ols-fb.ols-fb > .ols-fb-s > a:hover,
		html:root body .ols-fb.ols-fb > .ols-fb-s > a:focus-visible,
		html:root body .ols-fb.ols-fb > .ols-fb-nav:hover {
			transform: none;
		}
		html:root body .ols-fb--crumbs.ols-fb > .ols-fb-s > a::before {
			display: none;
		}
	}
}

/* ---------- 4. paper: every bar is a plain wrapping row ----------
 * The screen look above does not apply on paper; this turns the trails and rows into wrapping rows with no
 * chevrons, fades or link addresses. !important only where buttons.css sets the pills with !important. */
@media print {
	html:root body :is(nav[aria-label="Breadcrumb"], nav.ols-live-crumbs, .ols-hc nav.ols-hc__crumbs, .ols-badges, ul.ols-ls__chips, .ols-ssr-filters, .ols-ssr-boards, [data-frostbar], .ols-fb-s) {
		flex-wrap: wrap;
		width: auto;
		max-width: 100%;
		overflow: visible;
		-webkit-mask-image: none;
		mask-image: none;
	}
	html:root body .ols-fb > .ols-fb-nav {
		display: none;
	}
	html:root body :is(nav[aria-label="Breadcrumb"], nav.ols-live-crumbs) :is(a, span) {
		white-space: normal !important;
		overflow: visible !important;
		text-overflow: clip !important;
		box-shadow: none !important;
		transform: none;
	}
	html:root body :is(nav[aria-label="Breadcrumb"], nav.ols-live-crumbs, .ols-hc nav.ols-hc__crumbs, .ols-badges, ul.ols-ls__chips, .ols-ssr-filters, .ols-ssr-boards, [data-frostbar]) a::after {
		content: none !important;
	}
}
