/*
 * PureCSS.com
 * https://purecss.com/detect-scrollable/
 * Detect whether an element can scroll, and in which direction, with CSS alone:
 * scroll-state container queries, a scroll-driven flag, and background scroll shadows.
 */

/* the demo: a pick of how much is in the list, and the list itself */
.demo-detect-scrollable .ds {
	display: grid;
	gap: 1rem;
	width: min(100%, 26rem);
}

.demo-detect-scrollable .ds-amount {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: .4rem;
	margin: 0;
	padding: 0;
	border: 0;
}

.demo-detect-scrollable .ds-amount legend {
	float: left;
	margin-right: .35rem;
	padding: 0;
	font: 500 .72rem/1.2 var(--font-mono);
	letter-spacing: .04em;
	text-transform: uppercase;
	color: var(--text-muted);
}

/* the radios are clipped, not hidden, so they stay in the tab order */
.demo-detect-scrollable .ds-pick {
	position: relative;
	padding: .4rem .8rem;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: var(--surface);
	color: var(--text);
	font: 600 .8rem/1 var(--font-sans);
	cursor: pointer;
}

.demo-detect-scrollable .ds-pick input {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: 0;
	opacity: 0;
	pointer-events: none;
}

.demo-detect-scrollable .ds-pick:has(:checked) {
	border-color: var(--accent);
	background: var(--accent);
	color: var(--bg);
}

.demo-detect-scrollable .ds-pick:has(:focus-visible) {
	outline: 2px solid var(--accent);
	outline-offset: 3px;
}

/* three items fit, so nothing scrolls and the cues stay off */
.demo-detect-scrollable .ds:has(.ds-few:checked) .ds-extra {
	display: none;
}

.demo-detect-scrollable .ds:has(.ds-few:checked) .ds-list li:nth-child(3) {
	border-bottom: 0;
}

/*
 * The scroller is its own scroll-state container. A container query styles
 * the container's descendants and its ::before and ::after, never the
 * container itself, so the cues sit inside it.
 */
.demo-detect-scrollable .ds-scroller {
	height: 15rem;
	overflow-y: auto;
	container-type: scroll-state;
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	background: var(--surface);
}

.demo-detect-scrollable .ds-scroller:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 3px;
}

/* the cues ride at the top of the box as the list scrolls under them */
.demo-detect-scrollable .ds-state {
	position: sticky;
	top: 0;
	z-index: 2;
	display: flex;
	justify-content: flex-end;
	gap: .4rem;
	margin: 0;
	padding: .55rem .75rem;
	border-bottom: 1px solid var(--border);
	background: var(--surface);
}

.demo-detect-scrollable .ds-cue {
	display: inline-flex;
	align-items: center;
	gap: .35em;
	padding: .3rem .6rem;
	border: 1px solid var(--border);
	border-radius: 999px;
	color: var(--text-muted);
	font: 500 .72rem/1 var(--font-mono);
	opacity: .5;
	transition: opacity .2s, background-color .2s, color .2s;
}

.demo-detect-scrollable .ds-cue .fa-icon {
	width: .9em;
	height: .9em;
}

/* the shadow under the cues: there is more above. A strong accent glow,
   labeled, so it says what it means (owner, 2026-11-15) */
.demo-detect-scrollable .ds-state::after {
	content: "more above";
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	display: flex;
	justify-content: center;
	align-items: flex-start;
	height: 2.5rem;
	padding-top: .35rem;
	box-sizing: border-box;
	background: linear-gradient(color-mix(in srgb, var(--accent) 45%, transparent), transparent);
	color: var(--text);
	font: 600 .66rem/1 var(--font-mono);
	letter-spacing: .08em;
	text-transform: uppercase;
	opacity: 0;
	transition: opacity .2s;
	pointer-events: none;
}

/* the shadow at the foot of the box: there is more below. Sticky, so it
   stays at the bottom edge however far the list has scrolled */
.demo-detect-scrollable .ds-scroller::after {
	content: "more below";
	position: sticky;
	bottom: 0;
	display: flex;
	justify-content: center;
	align-items: flex-end;
	height: 2.5rem;
	margin-top: -2.5rem;
	padding-bottom: .35rem;
	box-sizing: border-box;
	background: linear-gradient(transparent, color-mix(in srgb, var(--accent) 45%, transparent));
	color: var(--text);
	font: 600 .66rem/1 var(--font-mono);
	letter-spacing: .08em;
	text-transform: uppercase;
	opacity: 0;
	transition: opacity .2s;
	pointer-events: none;
}

.demo-detect-scrollable .ds-list {
	margin: 0;
	padding: .25rem .9rem .5rem;
	list-style: none;
}

.demo-detect-scrollable .ds-list li {
	display: flex;
	justify-content: space-between;
	gap: 1rem;
	padding: .65rem 0;
	border-bottom: 1px solid var(--border);
	color: var(--text);
	font: 500 .9rem/1.3 var(--font-sans);
}

.demo-detect-scrollable .ds-list li:last-child {
	border-bottom: 0;
}

.demo-detect-scrollable .ds-list time {
	flex: none;
	color: var(--text-muted);
	font: .75rem/1.7 var(--font-mono);
}

/* the queries: each direction the box can still scroll lights its cue */
@container scroll-state(scrollable: top) {
	.demo-detect-scrollable .ds-up {
		border-color: var(--accent);
		background: var(--accent);
		color: var(--bg);
		opacity: 1;
	}

	.demo-detect-scrollable .ds-state::after {
		opacity: 1;
	}
}

@container scroll-state(scrollable: bottom) {
	.demo-detect-scrollable .ds-down {
		border-color: var(--accent);
		background: var(--accent);
		color: var(--bg);
		opacity: 1;
	}

	.demo-detect-scrollable .ds-scroller::after {
		opacity: 1;
	}
}

/* ── Variant: a flag from a scroll-driven animation ── */

.demo-detect-scrollable .dsf {
	display: grid;
	gap: 1rem;
	width: min(100%, 24rem);
}

.demo-detect-scrollable .dsf:has(.dsf-few:checked) .dsf-extra {
	display: none;
}

/*
 * A scroll timeline is inactive when its scroller has nothing to scroll.
 * The animation sets --can-scroll to 1 at both ends, so it reads 1 wherever
 * the box overflows and keeps its default 0 where it doesn't. The flag
 * inherits, so anything inside the box can use it. animation-timeline comes
 * after the animation shorthand, which would otherwise reset it.
 */
.demo-detect-scrollable .dsf-box {
	--can-scroll: 0;
	height: 11rem;
	overflow-y: auto;
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	background: var(--surface);
	outline: calc(3px * var(--can-scroll)) solid var(--accent);
	outline-offset: 3px;
}

.demo-detect-scrollable .dsf-box:focus-visible {
	outline: 2px solid var(--text);
}

.demo-detect-scrollable .dsf-flag {
	position: sticky;
	top: 0;
	display: grid;
	justify-items: end;
	margin: 0;
	padding: .5rem .75rem;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	font: 600 .72rem/1 var(--font-mono);
}

/* the two words share one cell; the flag picks which one shows */
.demo-detect-scrollable .dsf-yes,
.demo-detect-scrollable .dsf-no {
	grid-area: 1 / 1;
	padding: .3rem .6rem;
	border-radius: 999px;
}

.demo-detect-scrollable .dsf-yes {
	background: var(--accent);
	color: var(--bg);
	opacity: var(--can-scroll);
}

.demo-detect-scrollable .dsf-no {
	border: 1px solid var(--border);
	color: var(--text-muted);
	opacity: calc(1 - var(--can-scroll));
}

.demo-detect-scrollable .dsf-box p:not(.dsf-flag) {
	margin: 0;
	padding: .6rem .9rem;
	border-bottom: 1px solid var(--border);
	color: var(--text);
	font: 500 .875rem/1.4 var(--font-sans);
}

@supports (animation-timeline: scroll()) {
	.demo-detect-scrollable .dsf-box {
		animation: ds-can-scroll linear;
		animation-timeline: scroll(self);
	}

	/* switching the item count swaps in a copy of the animation, so the
	   browser starts it fresh and checks the overflow again, rather than
	   relying on it to notice the change on its own */
	.demo-detect-scrollable .dsf:has(.dsf-few:checked) .dsf-box {
		animation-name: ds-can-scroll-again;
	}
}

@keyframes ds-can-scroll {
	from,
	to {
		--can-scroll: 1;
	}
}

@keyframes ds-can-scroll-again {
	from,
	to {
		--can-scroll: 1;
	}
}

/* ── Variant: background scroll shadows that work everywhere ── */

.demo-detect-scrollable .dsb {
	display: grid;
	gap: 1rem;
	width: min(100%, 24rem);
}

.demo-detect-scrollable .dsb:has(.dsb-few:checked) .dsb-extra {
	display: none;
}

/*
 * Four layers on the box. The two shadows are fixed to the box (scroll).
 * The two covers, in the box's own color, are fixed to the content (local):
 * at the top of the content the top cover hides the top shadow, and once the
 * content scrolls the cover moves away with it. When nothing overflows, both
 * covers sit on both shadows and none shows.
 */
.demo-detect-scrollable .dsb-box {
	height: 9.5rem;
	overflow-y: auto;
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	background:
		linear-gradient(var(--surface) 30%, transparent) top / 100% 2.5rem no-repeat local,
		linear-gradient(transparent, var(--surface) 70%) bottom / 100% 2.5rem no-repeat local,
		radial-gradient(farthest-side at 50% 0, var(--accent), transparent) top / 100% 1.1rem no-repeat scroll,
		radial-gradient(farthest-side at 50% 100%, var(--accent), transparent) bottom / 100% 1.1rem no-repeat scroll,
		var(--surface);
}

.demo-detect-scrollable .dsb-box:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 3px;
}

.demo-detect-scrollable .dsb-box p {
	margin: 0;
	padding: .6rem .9rem;
	color: var(--text);
	font: 500 .875rem/1.4 var(--font-sans);
}

/* ── Variant: a row of chips that fades only where there is more ── */

.demo-detect-scrollable .dsh {
	width: 26rem;
	max-width: 100%;
}

/* the fades are the row's own ::before and ::after, sticky at each end, so
   they can query the row's scroll state */
.demo-detect-scrollable .dsh-row {
	display: flex;
	gap: .5rem;
	padding: 0;
	overflow-x: auto;
	container-type: scroll-state;
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	background: var(--surface);
	scrollbar-width: thin;
	scrollbar-color: var(--border) transparent;
}

.demo-detect-scrollable .dsh-row:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 3px;
}

.demo-detect-scrollable .dsh-row::before,
.demo-detect-scrollable .dsh-row::after {
	content: "";
	position: sticky;
	z-index: 1;
	flex: none;
	width: 2.5rem;
	opacity: 0;
	transition: opacity .2s;
	pointer-events: none;
}

.demo-detect-scrollable .dsh-row::before {
	left: 0;
	margin-right: -3rem;
	background: linear-gradient(to right, color-mix(in srgb, var(--accent) 45%, var(--surface)), transparent);
}

.demo-detect-scrollable .dsh-row::after {
	right: 0;
	margin-left: -3rem;
	background: linear-gradient(to left, color-mix(in srgb, var(--accent) 45%, var(--surface)), transparent);
}

/* the row has no padding, because a sticky fade stops at the padding edge:
   at the sides a chip showed bright beside it, and above and below the fade
   stopped short of the row's edges (owner, 2026-11-15). The chips carry the
   space instead */
.demo-detect-scrollable .dsh-chip:first-of-type {
	margin-left: .75rem;
}

.demo-detect-scrollable .dsh-chip:last-of-type {
	margin-right: .75rem;
}

.demo-detect-scrollable .dsh-chip {
	flex: none;
	margin-block: .75rem;
	padding: .45rem .8rem;
	border: 1px solid var(--border);
	border-radius: 999px;
	color: var(--text);
	font: 500 .85rem/1 var(--font-sans);
	white-space: nowrap;
}

@container scroll-state(scrollable: left) {
	.demo-detect-scrollable .dsh-row::before {
		opacity: 1;
	}
}

@container scroll-state(scrollable: right) {
	.demo-detect-scrollable .dsh-row::after {
		opacity: 1;
	}
}

@media (prefers-reduced-motion: reduce) {
	.demo-detect-scrollable .ds-cue,
	.demo-detect-scrollable .ds-state::after,
	.demo-detect-scrollable .ds-scroller::after,
	.demo-detect-scrollable .dsh-row::before,
	.demo-detect-scrollable .dsh-row::after {
		transition: none;
	}
}
