/* @svelte-lean/styles — layer order, scoped reset, shared focus ring and icon sizing.
 * The reset touches only elements that carry data-slean or data-slean-part. Content nested
 * inside a primitive (dialog body, tab panel, popover content) is left alone, except for one rule:
 * an <svg> that is a direct child of a control (a button, link, summary, menu item, option or tab
 * of a primitive) is 1rem square and never shrinks, whatever width and height attributes an icon
 * library writes; one inside an icon part is 1em. Primitive files may size their icons differently (a
 * component rule wins over this base rule); an application sizes one with its own CSS. The base
 * layer also holds the typography variants (data-typography="h1" … "overline"). */
@layer slean.reset, slean.tokens, slean.base, slean.components, slean.compositions, slean.utilities;

@layer slean.reset {
	:where([data-slean]),
	:where([data-slean-part]),
	:where([data-slean])::before,
	:where([data-slean-part])::before,
	:where([data-slean])::after,
	:where([data-slean-part])::after {
		box-sizing: border-box;
	}

	/* Form controls do not inherit typography by default; primitives do. */
	:where(button[data-slean]),
	:where(button[data-slean-part]),
	:where(input[data-slean]),
	:where(input[data-slean-part]),
	:where(select[data-slean]),
	:where(select[data-slean-part]),
	:where(textarea[data-slean]),
	:where(textarea[data-slean-part]),
	:where(a[data-slean]),
	:where(a[data-slean-part]) {
		margin: 0;
		font: inherit;
		letter-spacing: inherit;
		color: inherit;
	}
}

@layer slean.base {
	:where([data-slean]) {
		color-scheme: var(--slean-color-scheme);
	}

	:where([data-slean]:focus-visible),
	:where([data-slean-part]:focus-visible) {
		outline: var(--slean-focus-ring);
		outline-offset: var(--slean-focus-ring-offset);
	}

	:where(
		:is(button, a, summary, [role^='menuitem'], [role='option'], [role='tab']):is(
				[data-slean],
				[data-slean-part],
				[data-slean] *
			)
			> svg
	) {
		flex: none;
		inline-size: 1rem;
		block-size: 1rem;
	}

	:where([data-slean-part='icon'] > svg) {
		flex: none;
		inline-size: 1em;
		block-size: 1em;
	}

	/* Typography variants (MUI's Typography): data-typography="h1" … on any element sets its font
	 * from the theme's scale and removes the user-agent margin. */

	:where([data-typography='h1']) {
		margin: 0;
		font-family: var(--slean-font-sans);
		font-size: var(--slean-typography-h1-size);
		font-weight: var(--slean-typography-h1-weight);
		line-height: var(--slean-typography-h1-line-height);
	}

	:where([data-typography='h2']) {
		margin: 0;
		font-family: var(--slean-font-sans);
		font-size: var(--slean-typography-h2-size);
		font-weight: var(--slean-typography-h2-weight);
		line-height: var(--slean-typography-h2-line-height);
	}

	:where([data-typography='h3']) {
		margin: 0;
		font-family: var(--slean-font-sans);
		font-size: var(--slean-typography-h3-size);
		font-weight: var(--slean-typography-h3-weight);
		line-height: var(--slean-typography-h3-line-height);
	}

	:where([data-typography='h4']) {
		margin: 0;
		font-family: var(--slean-font-sans);
		font-size: var(--slean-typography-h4-size);
		font-weight: var(--slean-typography-h4-weight);
		line-height: var(--slean-typography-h4-line-height);
	}

	:where([data-typography='h5']) {
		margin: 0;
		font-family: var(--slean-font-sans);
		font-size: var(--slean-typography-h5-size);
		font-weight: var(--slean-typography-h5-weight);
		line-height: var(--slean-typography-h5-line-height);
	}

	:where([data-typography='h6']) {
		margin: 0;
		font-family: var(--slean-font-sans);
		font-size: var(--slean-typography-h6-size);
		font-weight: var(--slean-typography-h6-weight);
		line-height: var(--slean-typography-h6-line-height);
	}

	:where([data-typography='subtitle1']) {
		margin: 0;
		font-family: var(--slean-font-sans);
		font-size: var(--slean-typography-subtitle1-size);
		font-weight: var(--slean-typography-subtitle1-weight);
		line-height: var(--slean-typography-subtitle1-line-height);
	}

	:where([data-typography='subtitle2']) {
		margin: 0;
		font-family: var(--slean-font-sans);
		font-size: var(--slean-typography-subtitle2-size);
		font-weight: var(--slean-typography-subtitle2-weight);
		line-height: var(--slean-typography-subtitle2-line-height);
	}

	:where([data-typography='body1']) {
		margin: 0;
		font-family: var(--slean-font-sans);
		font-size: var(--slean-typography-body1-size);
		font-weight: var(--slean-typography-body1-weight);
		line-height: var(--slean-typography-body1-line-height);
	}

	:where([data-typography='body2']) {
		margin: 0;
		font-family: var(--slean-font-sans);
		font-size: var(--slean-typography-body2-size);
		font-weight: var(--slean-typography-body2-weight);
		line-height: var(--slean-typography-body2-line-height);
	}

	:where([data-typography='caption']) {
		margin: 0;
		font-family: var(--slean-font-sans);
		font-size: var(--slean-typography-caption-size);
		font-weight: var(--slean-typography-caption-weight);
		line-height: var(--slean-typography-caption-line-height);
	}

	:where([data-typography='overline']) {
		margin: 0;
		font-family: var(--slean-font-sans);
		font-size: var(--slean-typography-overline-size);
		font-weight: var(--slean-typography-overline-weight);
		line-height: var(--slean-typography-overline-line-height);
		letter-spacing: 0.08em;
		text-transform: var(--slean-typography-overline-transform);
	}

	:where([data-typography='button']) {
		margin: 0;
		font-family: var(--slean-font-sans);
		font-size: var(--slean-typography-button-size);
		font-weight: var(--slean-typography-button-weight);
		line-height: var(--slean-typography-button-line-height);
		text-transform: var(--slean-typography-button-transform);
	}
}
