/* @svelte-lean/styles — input (ADR 0011 §1.9). Two forms share the field's look:
 * - Bare (Tier 0): <input data-slean="input"> of any type or <textarea data-slean="input">. The
 *   type is the mode: text-like types, number (native spin buttons), the date and time types
 *   (the browser's segments and picker, themed through color-scheme), color (a swatch in the
 *   box), file (::file-selector-button), and a one-time code (autocomplete="one-time-code": one
 *   cell per character, data-slean-length="4|6|8", 6 without it).
 * - Field shell (Tier 1, @svelte-lean/primitives/input/register): <div data-slean="input"> around
 *   one <input> or <textarea> (matched by element) with optional parts prefix and suffix
 *   (adornments: text or an <svg>), clear (<button tabindex="-1">, generated with
 *   data-slean-clearable; shown on hover or focus while the field is not :placeholder-shown, so
 *   give the input a placeholder, " " when none shows), reveal (<button aria-pressed>: an eye from
 *   --slean-icon-eye / -eye-off while empty, else the author's icon or text) and decrement / increment (<button tabindex="-1">, minus and plus
 *   icons; the native spin buttons give way to them while scripting is on, and they are hidden
 *   without it). The root is the field; the input inside it is borderless.
 * State: :disabled, :read-only, :focus-visible, :user-invalid and aria-invalid="true" on the
 * input (the shell reads them with :has()); data-status="warning" on the root (an error is
 * aria-invalid="true" or :user-invalid). A read-only field looks like an editable one. A textarea
 * grows with its content where field-sizing is supported (a three-line minimum).
 * Looks: data-variant="outlined" (default), "filled" or "standard"; data-color picks the focus
 * color (primary by default); data-size="small|large"; data-full-width. */
@layer slean.reset, slean.tokens, slean.base, slean.components, slean.compositions, slean.utilities;

@layer slean.components {
	/* The box: a bare field or the shell. */
	:where(input[data-slean='input']),
	:where(textarea[data-slean='input']),
	:where(div[data-slean='input']) {
		box-sizing: border-box;
		min-inline-size: 0;
		min-block-size: var(--slean-control-height-md);
		padding-inline: var(--slean-space-3);
		border: 1px solid var(--slean-control-border);
		border-radius: var(--slean-field-radius);
		background: var(--slean-control-bg);
		color: var(--slean-fg);
		font-size: var(--slean-text-sm);
		line-height: var(--slean-leading);
		transition:
			border-color var(--slean-duration-fast) var(--slean-ease),
			box-shadow var(--slean-duration-fast) var(--slean-ease);
	}

	:where(input[data-slean='input']),
	:where(textarea[data-slean='input']) {
		appearance: none;
		padding-block: var(--slean-space-1);
		caret-color: var(--slean-color-main);
	}

	:where(div[data-slean='input']) {
		display: inline-flex;
		align-items: center;
		gap: var(--slean-space-2);
		padding-block: 0;
		vertical-align: middle;
		cursor: text;
	}

	/* The shell's field: borderless, transparent, filling the line. The ring is the shell's; the
	 * field keeps the shared outline, transparent, for forced colors. */
	:where(div[data-slean='input'] > input),
	:where(div[data-slean='input'] > textarea) {
		flex: 1 1 auto;
		align-self: stretch;
		min-inline-size: 0;
		margin: 0;
		padding: 0;
		border: 0;
		border-radius: 0;
		background: transparent;
		color: inherit;
		caret-color: var(--slean-color-main);
		font: inherit;
	}

	:where(div[data-slean='input'] > input:focus-visible),
	:where(div[data-slean='input'] > textarea:focus-visible) {
		outline-color: transparent;
	}

	:where(input[data-slean='input'])::placeholder,
	:where(textarea[data-slean='input'])::placeholder,
	:where(div[data-slean='input'] > input)::placeholder,
	:where(div[data-slean='input'] > textarea)::placeholder {
		color: var(--slean-fg-muted);
		opacity: 1;
	}

	/* Sizes. */
	:where(input[data-slean='input'][data-size='small']),
	:where(textarea[data-slean='input'][data-size='small']),
	:where(div[data-slean='input'][data-size='small']) {
		min-block-size: var(--slean-control-height-sm);
		padding-inline: var(--slean-space-2);
		border-radius: var(--slean-radius-sm);
	}

	:where(div[data-slean='input'][data-size='small']) {
		gap: var(--slean-space-1);
	}

	:where(input[data-slean='input'][data-size='large']),
	:where(textarea[data-slean='input'][data-size='large']),
	:where(div[data-slean='input'][data-size='large']) {
		min-block-size: var(--slean-control-height-lg);
		padding-inline: var(--slean-space-4);
		font-size: var(--slean-text-md);
	}

	/* Textarea: full width of its container, three lines at least, growing with the content
	 * where field-sizing is supported. The lh unit resolves against the textarea's own line. */
	:where(textarea[data-slean='input']) {
		inline-size: 100%;
		min-block-size: calc(3lh + 2 * var(--slean-space-2) + 2px);
		padding-block: var(--slean-space-2);
		vertical-align: top;
		resize: vertical;
		field-sizing: content;
	}

	:where(div[data-slean='input']:has(> textarea)) {
		align-items: flex-start;
		inline-size: 100%;
		padding-block: var(--slean-space-2);
	}

	:where(div[data-slean='input'] > textarea) {
		min-block-size: 3lh;
		resize: vertical;
		field-sizing: content;
	}

	/* The field states every form control shares (control.css draws the same ones): the border
	 * takes the field's color (data-color, primary by default) on hover and focus, focus adds the
	 * soft halo (the shared outline stays, transparent, for forced colors, where the halo is not
	 * drawn), a status recolors both, and a disabled field sits on the muted surface. */
	@media (hover: hover) {
		:where(input[data-slean='input']:hover:not(:disabled)),
		:where(textarea[data-slean='input']:hover:not(:disabled)),
		:where(div[data-slean='input']:hover:not(:has(> :disabled))) {
			border-color: var(--slean-control-border-hover, var(--slean-color-main));
		}
	}

	:where(input[data-slean='input']:focus-visible),
	:where(textarea[data-slean='input']:focus-visible),
	:where(div[data-slean='input']:has(> :is(input, textarea):focus-visible)) {
		border-color: var(--slean-color-main);
		outline-color: transparent;
		box-shadow: 0 0 0 3px color-mix(in oklch, var(--slean-color-main) 22%, transparent);
	}

	:where(input[data-slean='input'][data-status='warning']),
	:where(textarea[data-slean='input'][data-status='warning']),
	:where(div[data-slean='input'][data-status='warning']) {
		border-color: var(--slean-warning-main);
	}

	:where(input[data-slean='input'][data-status='warning']:focus-visible),
	:where(textarea[data-slean='input'][data-status='warning']:focus-visible),
	:where(div[data-slean='input'][data-status='warning']:has(> :is(input, textarea):focus-visible)) {
		box-shadow: var(--slean-control-ring-warning);
	}

	:where(input[data-slean='input']:user-invalid),
	:where(input[data-slean='input'][aria-invalid='true']),
	:where(textarea[data-slean='input']:user-invalid),
	:where(textarea[data-slean='input'][aria-invalid='true']),
	:where(
		div[data-slean='input']:has(> :is(input, textarea):is(:user-invalid, [aria-invalid='true']))
	) {
		border-color: var(--slean-error-main);
	}

	:where(input[data-slean='input']:user-invalid:focus-visible),
	:where(input[data-slean='input'][aria-invalid='true']:focus-visible),
	:where(textarea[data-slean='input']:user-invalid:focus-visible),
	:where(textarea[data-slean='input'][aria-invalid='true']:focus-visible),
	:where(
		div[data-slean='input']:has(
				> :is(input, textarea):is(:user-invalid, [aria-invalid='true']):focus-visible
			)
	) {
		box-shadow: var(--slean-control-ring-error);
	}

	:where(input[data-slean='input']:disabled),
	:where(textarea[data-slean='input']:disabled),
	:where(div[data-slean='input']:has(> :disabled)) {
		border-color: var(--slean-control-border-disabled);
		background: var(--slean-control-bg-disabled);
		color: var(--slean-fg-muted);
		cursor: not-allowed;
	}

	/* The shell's own cursor reaches its children by inheritance; the field and the parts set their
	 * own, so they are named (a `*` here was tried against every element of the page). */
	:where(div[data-slean='input']:has(> :disabled) > input),
	:where(div[data-slean='input']:has(> :disabled) > textarea),
	:where(div[data-slean='input']:has(> :disabled) [data-slean-part]) {
		cursor: not-allowed;
	}

	/* data-full-width: the field fills its container. */
	:where(input[data-slean='input'][data-full-width]),
	:where(textarea[data-slean='input'][data-full-width]),
	:where(div[data-slean='input'][data-full-width]) {
		inline-size: 100%;
		max-inline-size: none;
	}

	/* Looks (ADR 0011 §3.3): data-variant="filled" is a tinted surface with a bottom line and
	 * rounded top corners, "standard" the bottom line alone (no horizontal padding); the line takes
	 * the field's color (data-color, primary by default) on focus, the status colors on warning
	 * and error. */
	:where(input[data-slean='input'][data-variant='filled']),
	:where(input[data-slean='input'][data-variant='standard']),
	:where(textarea[data-slean='input'][data-variant='filled']),
	:where(textarea[data-slean='input'][data-variant='standard']),
	:where(div[data-slean='input'][data-variant='filled']),
	:where(div[data-slean='input'][data-variant='standard']) {
		border-color: transparent;
		border-block-end-color: var(--slean-control-border);
		border-radius: 0;
	}

	:where(input[data-slean='input'][data-variant='filled']),
	:where(textarea[data-slean='input'][data-variant='filled']),
	:where(div[data-slean='input'][data-variant='filled']) {
		border-start-start-radius: var(--slean-field-radius);
		border-start-end-radius: var(--slean-field-radius);
		background-color: var(--slean-control-filled-bg);
	}

	:where(input[data-slean='input'][data-variant='standard']),
	:where(textarea[data-slean='input'][data-variant='standard']),
	:where(div[data-slean='input'][data-variant='standard']) {
		background-color: transparent;
		padding-inline: 0;
	}

	@media (hover: hover) {
		:where(input[data-slean='input'][data-variant='filled']:not(:disabled):hover),
		:where(input[data-slean='input'][data-variant='standard']:not(:disabled):hover),
		:where(textarea[data-slean='input'][data-variant='filled']:not(:disabled):hover),
		:where(textarea[data-slean='input'][data-variant='standard']:not(:disabled):hover),
		:where(div[data-slean='input'][data-variant='filled']:not(:has(> :disabled)):hover),
		:where(div[data-slean='input'][data-variant='standard']:not(:has(> :disabled)):hover) {
			border-color: transparent;
			border-block-end-color: var(--slean-fg);
		}

		:where(input[data-slean='input'][data-variant='filled']:not(:disabled):hover),
		:where(textarea[data-slean='input'][data-variant='filled']:not(:disabled):hover),
		:where(div[data-slean='input'][data-variant='filled']:not(:has(> :disabled)):hover) {
			background-color: var(--slean-control-filled-bg-hover);
		}
	}

	:where(input[data-slean='input'][data-variant='filled']:focus-visible),
	:where(input[data-slean='input'][data-variant='standard']:focus-visible),
	:where(textarea[data-slean='input'][data-variant='filled']:focus-visible),
	:where(textarea[data-slean='input'][data-variant='standard']:focus-visible),
	:where(div[data-slean='input'][data-variant='filled']:has(> :is(input, textarea):focus-visible)),
	:where(
		div[data-slean='input'][data-variant='standard']:has(> :is(input, textarea):focus-visible)
	) {
		border-color: transparent;
		border-block-end-color: var(--slean-color-main);
		box-shadow: inset 0 -1px 0 var(--slean-color-main);
	}

	:where(input[data-slean='input'][data-variant='filled'][data-status='warning']),
	:where(input[data-slean='input'][data-variant='standard'][data-status='warning']),
	:where(textarea[data-slean='input'][data-variant='filled'][data-status='warning']),
	:where(textarea[data-slean='input'][data-variant='standard'][data-status='warning']),
	:where(div[data-slean='input'][data-variant='filled'][data-status='warning']),
	:where(div[data-slean='input'][data-variant='standard'][data-status='warning']) {
		border-color: transparent;
		border-block-end-color: var(--slean-warning-main);
	}

	:where(input[data-slean='input'][data-variant='filled'][data-status='warning']:focus-visible),
	:where(input[data-slean='input'][data-variant='standard'][data-status='warning']:focus-visible),
	:where(textarea[data-slean='input'][data-variant='filled'][data-status='warning']:focus-visible),
	:where(
		textarea[data-slean='input'][data-variant='standard'][data-status='warning']:focus-visible
	),
	:where(
		div[data-slean='input'][data-variant='filled'][data-status='warning']:has(
				> :is(input, textarea):focus-visible
			)
	),
	:where(
		div[data-slean='input'][data-variant='standard'][data-status='warning']:has(
				> :is(input, textarea):focus-visible
			)
	) {
		box-shadow: inset 0 -1px 0 var(--slean-warning-main);
	}

	:where(input[data-slean='input'][data-variant='filled']:user-invalid),
	:where(input[data-slean='input'][data-variant='filled'][aria-invalid='true']),
	:where(input[data-slean='input'][data-variant='standard']:user-invalid),
	:where(input[data-slean='input'][data-variant='standard'][aria-invalid='true']),
	:where(textarea[data-slean='input'][data-variant='filled']:user-invalid),
	:where(textarea[data-slean='input'][data-variant='filled'][aria-invalid='true']),
	:where(textarea[data-slean='input'][data-variant='standard']:user-invalid),
	:where(textarea[data-slean='input'][data-variant='standard'][aria-invalid='true']),
	:where(
		div[data-slean='input'][data-variant='filled']:has(
				> :is(input, textarea):is(:user-invalid, [aria-invalid='true'])
			)
	),
	:where(
		div[data-slean='input'][data-variant='standard']:has(
				> :is(input, textarea):is(:user-invalid, [aria-invalid='true'])
			)
	) {
		border-color: transparent;
		border-block-end-color: var(--slean-error-main);
	}

	:where(input[data-slean='input'][data-variant='filled']:user-invalid:focus-visible),
	:where(input[data-slean='input'][data-variant='filled'][aria-invalid='true']:focus-visible),
	:where(input[data-slean='input'][data-variant='standard']:user-invalid:focus-visible),
	:where(input[data-slean='input'][data-variant='standard'][aria-invalid='true']:focus-visible),
	:where(textarea[data-slean='input'][data-variant='filled']:user-invalid:focus-visible),
	:where(textarea[data-slean='input'][data-variant='filled'][aria-invalid='true']:focus-visible),
	:where(textarea[data-slean='input'][data-variant='standard']:user-invalid:focus-visible),
	:where(textarea[data-slean='input'][data-variant='standard'][aria-invalid='true']:focus-visible),
	:where(
		div[data-slean='input'][data-variant='filled']:has(
				> :is(input, textarea):is(:user-invalid, [aria-invalid='true']):focus-visible
			)
	),
	:where(
		div[data-slean='input'][data-variant='standard']:has(
				> :is(input, textarea):is(:user-invalid, [aria-invalid='true']):focus-visible
			)
	) {
		box-shadow: inset 0 -1px 0 var(--slean-error-main);
	}

	:where(input[data-slean='input'][data-variant='filled']:disabled),
	:where(input[data-slean='input'][data-variant='standard']:disabled),
	:where(textarea[data-slean='input'][data-variant='filled']:disabled),
	:where(textarea[data-slean='input'][data-variant='standard']:disabled),
	:where(div[data-slean='input'][data-variant='filled']:has(> :disabled)),
	:where(div[data-slean='input'][data-variant='standard']:has(> :disabled)) {
		border-color: transparent;
		border-block-end-color: var(--slean-control-border-disabled);
		border-block-end-style: dotted;
	}

	:where(input[data-slean='input'][data-variant='standard']:disabled),
	:where(textarea[data-slean='input'][data-variant='standard']:disabled),
	:where(div[data-slean='input'][data-variant='standard']:has(> :disabled)) {
		background-color: transparent;
	}

	/* The shell's adornments: muted text or a 1rem icon, never shrinking. The parts after the
	 * field keep their order, after a generated clear button. */
	:where(div[data-slean='input'] [data-slean-part='prefix']),
	:where(div[data-slean='input'] [data-slean-part='suffix']) {
		flex: none;
		display: inline-flex;
		align-items: center;
		gap: var(--slean-space-1);
		color: var(--slean-fg-muted);
		white-space: nowrap;
		user-select: none;
	}

	:where(
		div[data-slean='input'] :is([data-slean-part='prefix'], [data-slean-part='suffix']) > svg
	) {
		flex: none;
		inline-size: 1rem;
		block-size: 1rem;
	}

	/* The parts after the field (contract: a shell's children are the field and its parts). */
	:where(div[data-slean='input'] > input ~ [data-slean-part]),
	:where(div[data-slean='input'] > textarea ~ [data-slean-part]) {
		order: 2;
	}

	/* The shell's buttons: a 1.5rem square around a 1rem icon (a mask from the tokens, or the
	 * author's icon or text inside a reveal button). */
	:where(div[data-slean='input'] [data-slean-part='clear']),
	:where(div[data-slean='input'] [data-slean-part='reveal']),
	:where(div[data-slean='input'] [data-slean-part='decrement']),
	:where(div[data-slean='input'] [data-slean-part='increment']) {
		appearance: none;
		flex: none;
		display: inline-grid;
		place-items: center;
		min-inline-size: 1.5rem;
		block-size: 1.5rem;
		margin: 0;
		padding: 0;
		border: 0;
		border-radius: var(--slean-radius-sm);
		background: transparent;
		color: var(--slean-control-icon);
		cursor: pointer;
		-webkit-tap-highlight-color: transparent;
	}

	:where(div[data-slean='input'] [data-slean-part='clear'])::before,
	:where(div[data-slean='input'] [data-slean-part='decrement'])::before,
	:where(div[data-slean='input'] [data-slean-part='increment'])::before {
		content: '';
		inline-size: 1rem;
		block-size: 1rem;
		background: currentColor;
		mask: var(--slean-icon-clear) center / contain no-repeat;
	}

	:where(div[data-slean='input'] [data-slean-part='decrement'])::before {
		mask-image: var(--slean-icon-minus);
	}

	:where(div[data-slean='input'] [data-slean-part='increment'])::before {
		mask-image: var(--slean-icon-plus);
	}

	@media (hover: hover) {
		:where(div[data-slean='input'] [data-slean-part='clear']:not(:disabled):hover),
		:where(div[data-slean='input'] [data-slean-part='reveal']:not(:disabled):hover),
		:where(div[data-slean='input'] [data-slean-part='decrement']:not(:disabled):hover),
		:where(div[data-slean='input'] [data-slean-part='increment']:not(:disabled):hover) {
			background: var(--slean-muted);
			color: var(--slean-fg);
		}
	}

	/* An empty reveal button draws the eye from the tokens; the author's icon or text replaces it. */
	:where(div[data-slean='input'] [data-slean-part='reveal']:empty)::before {
		content: '';
		inline-size: 1rem;
		block-size: 1rem;
		background: currentColor;
		mask: var(--slean-icon-eye) center / contain no-repeat;
	}

	:where(div[data-slean='input'] [data-slean-part='reveal'][aria-pressed='true']:empty)::before {
		mask-image: var(--slean-icon-eye-off);
	}

	:where(div[data-slean='input'] [data-slean-part='reveal'][aria-pressed='true']) {
		color: var(--slean-color-main);
	}

	:where(div[data-slean='input'] [data-slean-part='reveal']:disabled),
	:where(div[data-slean='input'] [data-slean-part='decrement']:disabled),
	:where(div[data-slean='input'] [data-slean-part='increment']:disabled),
	:where(div[data-slean='input']:has(> :disabled) button[data-slean-part]) {
		color: var(--slean-fg-muted);
		opacity: 0.5;
	}

	/* The clear button shows while the pointer is over a field that has a value, or while the
	 * field has focus, right after the field. */
	:where(div[data-slean='input'] [data-slean-part='clear']) {
		display: none;
		order: 1;
	}

	:where(
		div[data-slean='input']:is(:hover, :focus-within):has(
				> :is(input, textarea):not(:placeholder-shown, :disabled, :read-only)
			)
			[data-slean-part='clear']
	) {
		display: inline-grid;
	}

	/* A clearable search field keeps one clear button: the shell's, not the engine's (which stays
	 * without scripting, where the shell's is not created). */
	@media (scripting: enabled) {
		:where(
			div[data-slean='input']:is([data-slean-clearable], :has([data-slean-part='clear'])) > input
		)::-webkit-search-cancel-button {
			appearance: none;
		}
	}

	/* The steppers replace the platform's spin buttons while scripting runs; without it they are
	 * hidden and the spin buttons stay. */
	@media (scripting: enabled) {
		:where(
			div[data-slean='input']:has([data-slean-part='increment'], [data-slean-part='decrement'])
				> input
		) {
			appearance: textfield;
		}

		:where(div[data-slean='input'] > input)::-webkit-inner-spin-button {
			appearance: none;
			margin: 0;
		}
	}

	@media (scripting: none) {
		:where(div[data-slean='input'] [data-slean-part='clear']),
		:where(div[data-slean='input'] [data-slean-part='decrement']),
		:where(div[data-slean='input'] [data-slean-part='increment']) {
			display: none;
		}
	}

	/* Number, date and time: tabular digits; the picker indicator of the date and time types sits
	 * after the segments and follows color-scheme. */
	:where(input[data-slean='input'][type='number']),
	:where(input[data-slean='input'][type='date']),
	:where(input[data-slean='input'][type='time']),
	:where(input[data-slean='input'][type='datetime-local']),
	:where(input[data-slean='input'][type='month']),
	:where(input[data-slean='input'][type='week']),
	:where(div[data-slean='input'] > input[type='number']),
	:where(div[data-slean='input'] > input[type='date']),
	:where(div[data-slean='input'] > input[type='time']),
	:where(div[data-slean='input'] > input[type='datetime-local']),
	:where(div[data-slean='input'] > input[type='month']),
	:where(div[data-slean='input'] > input[type='week']) {
		font-variant-numeric: tabular-nums;
	}

	:where(input[data-slean='input'])::-webkit-datetime-edit-fields-wrapper {
		padding: 0;
	}

	:where(input[data-slean='input'])::-webkit-calendar-picker-indicator {
		margin-inline-start: var(--slean-space-2);
		opacity: 0.7;
		cursor: pointer;
	}

	/* Color: a swatch in a square box. The swatch pseudo-elements differ per engine, each in its
	 * own rule because a selector list with an unknown pseudo-element is dropped whole. */
	:where(input[data-slean='input'][type='color']) {
		inline-size: var(--slean-control-height-md);
		block-size: var(--slean-control-height-md);
		padding: var(--slean-space-1);
		vertical-align: middle;
		cursor: pointer;
	}

	:where(input[data-slean='input'][type='color'][data-size='small']) {
		inline-size: var(--slean-control-height-sm);
		block-size: var(--slean-control-height-sm);
		padding: var(--slean-space-1);
	}

	:where(input[data-slean='input'][type='color'][data-size='large']) {
		inline-size: var(--slean-control-height-lg);
		block-size: var(--slean-control-height-lg);
		padding: var(--slean-space-1);
	}

	:where(input[data-slean='input'][type='color'])::-webkit-color-swatch-wrapper {
		padding: 0;
	}

	:where(input[data-slean='input'][type='color'])::-webkit-color-swatch {
		border: 1px solid var(--slean-border);
		border-radius: var(--slean-radius-sm);
	}

	:where(input[data-slean='input'][type='color'])::-moz-color-swatch {
		border: 1px solid var(--slean-border);
		border-radius: var(--slean-radius-sm);
	}

	:where(input[data-slean='input'][type='color']:disabled)::-webkit-color-swatch {
		opacity: 0.5;
	}

	:where(input[data-slean='input'][type='color']:disabled)::-moz-color-swatch {
		opacity: 0.5;
	}

	/* File: the browser's selector button, inside a 3px inset, and its file name text. */
	:where(input[data-slean='input'][type='file']) {
		max-inline-size: 100%;
		padding: calc(var(--slean-space-1) - 1px);
		padding-inline-end: var(--slean-space-3);
		color: var(--slean-fg-muted);
		line-height: 1.25;
		cursor: pointer;
	}

	:where(input[data-slean='input'][type='file'])::file-selector-button {
		min-block-size: calc(var(--slean-control-height-md) - 2 * var(--slean-space-1));
		margin-block: 0;
		margin-inline: 0 var(--slean-space-3);
		padding-block: 0;
		padding-inline: var(--slean-space-3);
		border: 0;
		border-radius: calc(var(--slean-field-radius) - var(--slean-space-1));
		background: var(--slean-muted);
		color: var(--slean-fg);
		font: inherit;
		font-weight: var(--slean-font-weight-medium);
		cursor: inherit;
		transition: background-color var(--slean-duration-fast) var(--slean-ease);
	}

	:where(input[data-slean='input'][type='file'][data-size='small'])::file-selector-button {
		min-block-size: calc(var(--slean-control-height-sm) - 2 * var(--slean-space-1));
	}

	:where(input[data-slean='input'][type='file'][data-size='large'])::file-selector-button {
		min-block-size: calc(var(--slean-control-height-lg) - 2 * var(--slean-space-1));
	}

	@media (hover: hover) {
		:where(input[data-slean='input'][type='file']:not(:disabled):hover)::file-selector-button {
			background: var(--slean-muted-hover);
		}
	}

	/* A one-time code (autocomplete="one-time-code"): one cell per character, drawn, not
	 * rendered. A monospace font gives every character the advance of 1ch, letter-spacing puts the
	 * characters 2.5ch apart, and a repeating gradient draws one slot mark under each position;
	 * the gradient layer ends inside the gap after the last mark, so rounding never shows a mark
	 * too many. The content box is length × 2.5ch plus a quarter ch for the caret, so the input
	 * never scrolls; the start padding (1.75ch) centers the slots. The text runs left to right in
	 * every document direction because the geometry starts at the first character. */
	:where(input[data-slean='input'][autocomplete~='one-time-code']) {
		box-sizing: content-box;
		inline-size: 15.25ch;
		block-size: calc(var(--slean-control-height-lg) + var(--slean-space-2) - 2px);
		padding-block: 0;
		padding-inline: 1.75ch 0;
		background-image: repeating-linear-gradient(
			90deg,
			var(--slean-control-border) 0 1.75ch,
			transparent 0 2.5ch
		);
		background-origin: content-box;
		background-position: -0.375ch calc(100% - var(--slean-space-2));
		background-size: 14.5ch 2px;
		background-repeat: no-repeat;
		direction: ltr;
		font-family: var(--slean-font-mono);
		font-size: calc(var(--slean-text-lg) * 1.25);
		font-variant-numeric: tabular-nums;
		letter-spacing: 1.5ch;
		text-align: start;
	}

	:where(input[data-slean='input'][autocomplete~='one-time-code'][data-slean-length='4']) {
		inline-size: 10.25ch;
		background-size: 9.5ch 2px;
	}

	:where(input[data-slean='input'][autocomplete~='one-time-code'][data-slean-length='8']) {
		inline-size: 20.25ch;
		background-size: 19.5ch 2px;
	}

	:where(input[data-slean='input'][autocomplete~='one-time-code']:focus-visible) {
		background-image: repeating-linear-gradient(
			90deg,
			var(--slean-color-main) 0 1.75ch,
			transparent 0 2.5ch
		);
	}

	/* Touch: the control heights grow (tokens.css), and 16px text keeps iOS Safari from zooming the
	 * page when a field takes focus. */
	@media (pointer: coarse) {
		:where(input[data-slean='input']),
		:where(textarea[data-slean='input']),
		:where(div[data-slean='input']) {
			font-size: var(--slean-text-md);
		}
	}

	@media (forced-colors: active) {
		:where(input[data-slean='input']),
		:where(textarea[data-slean='input']),
		:where(div[data-slean='input']) {
			border-color: FieldText;
		}

		:where(input[data-slean='input'])::placeholder,
		:where(textarea[data-slean='input'])::placeholder,
		:where(div[data-slean='input'] > input)::placeholder,
		:where(div[data-slean='input'] > textarea)::placeholder {
			color: GrayText;
		}

		:where(input[data-slean='input']:disabled),
		:where(textarea[data-slean='input']:disabled),
		:where(div[data-slean='input']:has(> :disabled)) {
			border-color: GrayText;
			color: GrayText;
		}

		:where(div[data-slean='input'] [data-slean-part='clear'])::before,
		:where(div[data-slean='input'] [data-slean-part='decrement'])::before,
		:where(div[data-slean='input'] [data-slean-part='increment'])::before {
			forced-color-adjust: none;
			background: ButtonText;
		}

		:where(input[data-slean='input'][type='file'])::file-selector-button {
			border-color: ButtonText;
		}

		:where(div[data-slean='input'] [data-slean-part='reveal']:disabled),
		:where(div[data-slean='input'] [data-slean-part='decrement']:disabled),
		:where(div[data-slean='input'] [data-slean-part='increment']:disabled),
		:where(div[data-slean='input']:has(> :disabled) button[data-slean-part]) {
			color: GrayText;
			opacity: 1;
		}

		/* The swatch keeps its own color: it is the value. */
		:where(input[data-slean='input'][type='color'])::-webkit-color-swatch {
			forced-color-adjust: none;
			border-color: ButtonText;
		}

		:where(input[data-slean='input'][type='color'])::-moz-color-swatch {
			forced-color-adjust: none;
			border-color: ButtonText;
		}

		:where(input[data-slean='input'][type='color']:disabled)::-webkit-color-swatch {
			opacity: 1;
		}

		:where(input[data-slean='input'][type='color']:disabled)::-moz-color-swatch {
			opacity: 1;
		}

		/* Forced colors drop gradient backgrounds; the slots of a code are redrawn in system colors. */
		:where(input[data-slean='input'][autocomplete~='one-time-code']) {
			forced-color-adjust: none;
			background-color: Field;
			background-image: repeating-linear-gradient(90deg, FieldText 0 1.75ch, transparent 0 2.5ch);
			color: FieldText;
			caret-color: FieldText;
		}

		:where(input[data-slean='input'][autocomplete~='one-time-code']:focus-visible) {
			background-image: repeating-linear-gradient(90deg, Highlight 0 1.75ch, transparent 0 2.5ch);
		}

		:where(input[data-slean='input'][autocomplete~='one-time-code']:disabled) {
			background-image: repeating-linear-gradient(90deg, GrayText 0 1.75ch, transparent 0 2.5ch);
			color: GrayText;
		}
	}
}
