/* @svelte-lean/styles — progress (Tier 0, native <progress>).
 * Markup: <label for="upload">Uploading</label> <progress id="upload" data-slean="progress"
 * value="40" max="100">40%</progress>. Without a value the element is :indeterminate. The track
 * is the element; the value is ::-webkit-progress-value (Chromium, WebKit, whose
 * ::-webkit-progress-bar is made transparent) and ::-moz-progress-bar (Firefox). The
 * indeterminate state is diagonal stripes on the track: they move when motion is allowed and
 * stay drawn under reduced motion, where the duration tokens are 0ms. Color: data-color (primary by
 * default). Sizes: data-size="small|large". Variant (data-variant): linear (default) or circular,
 * a ring drawn on the element itself: a conic gradient of the color over a tint of it, masked to a
 * ring whose thickness is a fifth of the radius at every size. A determinate ring reads the value
 * as a percentage from --slean-value, an inline style the author writes next to value (until typed
 * attr() is in every engine); an indeterminate ring is a quarter arc turned by a keyframe animation
 * of --slean-duration-indicator, which reduced motion slows instead of stopping, so it never reads
 * as a stuck page. */
@layer slean.reset, slean.tokens, slean.base, slean.components, slean.compositions, slean.utilities;

@layer slean.components {
	:where([data-slean='progress']) {
		appearance: none;
		display: block;
		inline-size: 100%;
		block-size: 0.5rem;
		margin: 0;
		padding: 0;
		border: 0;
		border-radius: var(--slean-radius-full);
		background: var(--slean-muted);
		color: var(--slean-color-main);
		overflow: hidden;
	}

	:where([data-slean='progress'])::-webkit-progress-bar {
		border-radius: inherit;
		background: transparent;
	}

	:where([data-slean='progress'])::-webkit-progress-value {
		border-radius: inherit;
		background: currentColor;
		transition: inline-size var(--slean-duration-slow) var(--slean-ease);
	}

	:where([data-slean='progress'])::-moz-progress-bar {
		border-radius: inherit;
		background: currentColor;
	}

	/* Indeterminate: stripes of the color over its soft tint, one tile per 1rem. */
	:where([data-slean='progress']:indeterminate) {
		background-image: linear-gradient(
			135deg,
			currentColor 25%,
			var(--slean-color-soft) 25% 50%,
			currentColor 50% 75%,
			var(--slean-color-soft) 75%
		);
		background-size: 1rem 1rem;
		animation: slean-progress-stripes calc(var(--slean-duration-slow) * 4) linear infinite;
	}

	:where([data-slean='progress']:indeterminate)::-webkit-progress-value {
		background: transparent;
	}

	:where([data-slean='progress']:indeterminate)::-moz-progress-bar {
		background: transparent;
	}

	:where([data-slean='progress']:indeterminate:dir(rtl)) {
		animation-direction: reverse;
	}

	@keyframes slean-progress-stripes {
		from {
			background-position: 0 0;
		}

		to {
			background-position: 1rem 0;
		}
	}

	/* Sizes. */
	:where([data-slean='progress'][data-size='small']) {
		block-size: 0.25rem;
	}

	:where([data-slean='progress'][data-size='large']) {
		block-size: 0.75rem;
	}

	/* Circular: the ring is the element; the vendor pseudo-elements draw nothing. */
	:where([data-slean='progress'][data-variant='circular']) {
		display: inline-block;
		flex: none;
		inline-size: 1.5rem;
		block-size: 1.5rem;
		border-radius: 50%;
		background: conic-gradient(
			currentColor calc(var(--slean-value) * 1%),
			color-mix(in oklch, currentColor 20%, transparent) 0
		);
		mask: radial-gradient(farthest-side, transparent calc(80% - 0.5px), currentColor 80%);
		vertical-align: middle;
		animation: none;
	}

	:where([data-slean='progress'][data-variant='circular'])::-webkit-progress-bar {
		background: transparent;
	}

	:where([data-slean='progress'][data-variant='circular'])::-webkit-progress-value {
		background: transparent;
	}

	:where([data-slean='progress'][data-variant='circular'])::-moz-progress-bar {
		background: transparent;
	}

	:where([data-slean='progress'][data-variant='circular']:indeterminate) {
		background: conic-gradient(
			currentColor 0 0.25turn,
			color-mix(in oklch, currentColor 20%, transparent) 0
		);
		animation: slean-progress-rotate var(--slean-duration-indicator) linear infinite;
	}

	@keyframes slean-progress-rotate {
		to {
			rotate: 1turn;
		}
	}

	:where([data-slean='progress'][data-variant='circular'][data-size='small']) {
		inline-size: 1rem;
		block-size: 1rem;
	}

	:where([data-slean='progress'][data-variant='circular'][data-size='large']) {
		inline-size: 2.5rem;
		block-size: 2.5rem;
	}

	/* Forced colors replace the backgrounds with Canvas; draw the track with a border and the
	 * value in Highlight. */
	@media (forced-colors: active) {
		:where([data-slean='progress']) {
			forced-color-adjust: none;
			border: 1px solid CanvasText;
			background-color: Canvas;
			color: Highlight;
		}

		:where([data-slean='progress']:indeterminate) {
			background-image: linear-gradient(
				135deg,
				Highlight 25%,
				Canvas 25% 50%,
				Highlight 50% 75%,
				Canvas 75%
			);
		}

		:where([data-slean='progress'][data-variant='circular']) {
			border: 0;
			background: conic-gradient(Highlight calc(var(--slean-value) * 1%), GrayText 0);
		}

		:where([data-slean='progress'][data-variant='circular']:indeterminate) {
			background: conic-gradient(Highlight 0 0.25turn, GrayText 0);
		}
	}
}
