/* @svelte-lean/styles — avatar (Tier 0, an <img> with initials behind it).
 * Markup: <span data-slean="avatar"><img alt="Ada Okafor" src="…"> <span
 * data-slean-part="fallback" aria-hidden="true">AO</span></span>. Image and initials share one grid
 * cell and the image is on top: an image that has not painted yet shows the initials, a loaded one
 * covers them. Nothing handles load errors: a failed image shows the browser's broken-image
 * rendering over the initials until the application removes the <img>. Sizes: data-size="small|
 * medium|large" (medium by default). Variant (data-variant): circular (default), rounded (the
 * medium radius), square (no radius). Color: data-color tints the initials' surface with the
 * color's soft tones (neutral by default). A wrapper avatar root that contains avatar roots
 * (role="group" and a label) is a group: its avatars overlap. */
@layer slean.reset, slean.tokens, slean.base, slean.components, slean.compositions, slean.utilities;

@layer slean.components {
	:where([data-slean='avatar']:not(:has(> [data-slean='avatar']))) {
		display: inline-grid;
		place-items: center;
		flex: none;
		inline-size: 2.5rem;
		block-size: 2.5rem;
		border-radius: var(--slean-radius-full);
		overflow: clip;
		background: var(--slean-muted);
		color: var(--slean-fg-muted);
		font-size: var(--slean-text-sm);
		font-weight: var(--slean-font-weight-semibold);
		line-height: 1;
		vertical-align: middle;
		user-select: none;
	}

	/* A transparent text color keeps the alt text of an image that failed from painting over the
	 * initials; a broken-image icon (Chrome draws one) still shows. */
	:where([data-slean='avatar'] > img) {
		grid-area: 1 / 1;
		z-index: 1;
		inline-size: 100%;
		block-size: 100%;
		object-fit: cover;
		color: transparent;
	}

	:where([data-slean='avatar'] > [data-slean-part='fallback']) {
		grid-area: 1 / 1;
		text-transform: uppercase;
	}

	:where([data-slean='avatar'][data-variant='rounded']) {
		border-radius: var(--slean-radius-md);
	}

	:where([data-slean='avatar'][data-variant='square']) {
		border-radius: 0;
	}

	:where([data-slean='avatar'][data-color]) {
		background: var(--slean-color-soft);
		color: var(--slean-color-soft-text);
	}

	/* Sizes. */
	:where([data-slean='avatar'][data-size='small']) {
		inline-size: 1.5rem;
		block-size: 1.5rem;
		font-size: var(--slean-text-xs);
	}

	:where([data-slean='avatar'][data-size='large']) {
		inline-size: 3.5rem;
		block-size: 3.5rem;
		font-size: var(--slean-text-lg);
	}

	/* Group: a wrapper root (role="group" and a label) that contains avatar roots, whose avatars
	 * overlap; a ring in the page color keeps each outline visible where they meet. */
	:where([data-slean='avatar']:has(> [data-slean='avatar'])) {
		display: inline-flex;
		align-items: center;
		vertical-align: middle;
	}

	:where([data-slean='avatar']:has(> [data-slean='avatar']) > [data-slean='avatar']) {
		box-shadow: 0 0 0 2px var(--slean-bg);
	}

	:where(
		[data-slean='avatar']:has(> [data-slean='avatar'])
			> [data-slean='avatar']
			+ [data-slean='avatar']
	) {
		margin-inline-start: -0.6em;
	}

	@media (forced-colors: active) {
		:where([data-slean='avatar']:not(:has(> [data-slean='avatar']))) {
			border: 1px solid CanvasText;
		}
	}
}
