/* Manifest Avatars */

@layer base, components, utilities;

@layer utilities {

    :where(.avatar) {
        position: relative;
        display: flex;
        flex-flow: row wrap;
        flex-shrink: 0;
        justify-content: center;
        align-items: center;
        width: var(--spacing-field-height, 2.25rem);
        height: var(--spacing-field-height, 2.25rem);
        font-weight: bold;
        text-align: center;
        text-transform: uppercase;
        color: var(--color-field-inverse, oklch(43.9% 0 0));
        /* surface-3, not field-surface: an avatar is content, not a control.
           Themes are free to make fields translucent, and a see-through avatar
           bleeds the one stacked behind it. Same value in both modes today. */
        background-color: var(--color-surface-3, oklch(87% 0 0));
        background-clip: content-box;
        background-size: cover;
        background-position: center;
        border-radius: 50%;

        /* Icon */
        &[x-icon] {
            color: var(--color-content-subtle, oklch(55.6% 0 0))
        }

        /* Profile pic */
        :where(img) {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            object-position: center;
            border-radius: inherit;
            transition: var(--transition, all .05s ease-in-out)
        }

        /* Status indictor */
        :where(figure) {
            position: absolute;
            bottom: -3px;
            right: -3px;
            width: 9px;
            height: 9px;
            z-index: 1;
            background-color: var(--color-surface-3, oklch(87% 0 0));
            border: 1px solid var(--color-page, oklch(98.5% 0 0));
            border-radius: 50%
        }
    }

    /* Button & label versions */
    :where(button.avatar, [role=button].avatar, label.avatar):not(.unstyle) {
        padding: 0;
        background-blend-mode: normal;

        &:hover {
            /* Steps off the avatar's own surface, not a field token — darkens in
               light mode, lightens in dark, and never goes translucent. */
            background-color: color-mix(in oklch, var(--color-surface-3, oklch(87% 0 0)) 88%, var(--color-content-stark, oklch(20.5% 0 0)));
            background-blend-mode: multiply;

            & img {
                filter: brightness(0.9)
            }
        }

        & span {
            padding: 0
        }
    }

    /* Sizes */
    :where(.avatar.sm) {
        width: 1.5rem;
        height: 1.5rem;
        font-size: 0.75rem
    }

    :where(.avatar.lg) {
        width: 3rem;
        height: 3rem;
        font-size: 1.25rem
    }

    /* Wide version */
    :where(.avatar-wide) {
        display: flex;
        flex-flow: row;
        justify-content: start;
        align-items: center;
        gap: 1.5ch;
        width: 100%;
        max-width: 100%;
        overflow: hidden;

        & span {
            max-width: 100%;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden
        }
    }

    /* Wide button version */
    :where(button.avatar-wide) {
        height: fit-content;
        padding: var(--spacing, 0.25rem);
        padding-inline-end: 1.5ch;

        &:hover .avatar {
            background-color: color-mix(in oklch, var(--color-surface-3, oklch(87% 0 0)) 88%, var(--color-content-stark, oklch(20.5% 0 0)));
            transition: var(--transition, all .05s ease-in-out)
        }
    }

    /* Group wrapper */
    :where([role=group]:has(.avatar, button.avatar)) {
        display: flex;
        flex-flow: row nowrap;
        align-items: center;

        :where(.avatar) {
            margin-inline-end: calc(var(--spacing-field-height, 2.25rem) * -0.3);
            box-shadow: 0 0 0 3px var(--color-page, oklch(98.5% 0 0))
        }
    }
}