.avatar {
  /* v2 squircle: 9px at the 36px message size, scaling with the avatar so
     smaller ones (22px sidebar DMs, 17px boost chips) keep the same shape */
  --avatar-border-radius: 25%;

  aspect-ratio: 1;
  border-radius: var(--avatar-border-radius);
  display: grid;
  inline-size: var(--avatar-size, 5ch);
  margin: 0;
  overflow: hidden;
  place-items: center;
  position: relative;

  > img {
    aspect-ratio: 1;
    block-size: auto;
    border-radius: var(--avatar-border-radius);
    grid-area: 1/1;
    inline-size: var(--avatar-size, 5ch);
    max-inline-size: 100%;
    object-fit: cover;

    .banned & {
      opacity: 0.5;
    }
  }

  .banned &:after {
    background: url("/assets/cancel-c6dfeb78.svg") no-repeat center center;
    block-size: auto;
    content: "";
    filter: invert(0%);
    inline-size: var(--avatar-size, 5ch);
    inset: 0;
    max-inline-size: 100%;
    position: absolute;

    @media (prefers-color-scheme: dark) {
      filter: invert(100%);
    }

    :root[data-theme="light"] & {
      filter: invert(0%);
    }

    :root[data-theme="dark"] & {
      filter: invert(100%);
    }
  }
}

.avatar__group {
  --avatar-size: 2.5ch;

  block-size: 5ch;
  display: grid;
  gap: 1px;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: min-content;
  inline-size: 5ch;
  place-content: center;

  .avatar {
    margin: auto;
  }

  &:where(:has(> :last-child:nth-child(2))) {
    --avatar-size: 3.5ch;

    > :first-child {
      margin-block-end: 1.5ch;
      margin-inline-end: -0.75ch;
    }

    > :last-child {
      margin-block-start: 1.5ch;
      margin-inline-start: -0.75ch;
    }
  }

  &:where(:has(> :last-child:nth-child(3))) {
    > :last-child {
      margin-inline: 1.25ch -1.25ch;
    }
  }
}

/* Account logo */
.account-logo {
  --avatar-border-radius: 0.5em;

  #nav & {
    block-size: var(--btn-size);
    inline-size: auto;
  }
}

.account-logo--display {
  --avatar-size: var(--btn-size);
}

/* Initial fallback when no logo is uploaded — the accent-tinted tile the
   sidebar header uses, sized to fill the avatar box. */
.account-logo__initial {
  align-items: center;
  aspect-ratio: 1;
  background-color: var(--color-accent-brand);
  border-radius: var(--avatar-border-radius);
  box-shadow: 0 0 0 1px oklch(var(--lch-always-black) / 0.15);
  color: var(--color-text-reversed);
  display: flex;
  font-size: calc(var(--avatar-size, 5ch) / 2);
  font-weight: 700;
  grid-area: 1 / 1;
  /* Fill the avatar box exactly. Re-deriving the width from --avatar-size (a
     ch value) would resolve it against this element's own enlarged font-size,
     not the avatar's, so with a large-type figure the tile overflows the box
     that clips it and the initial drifts off-centre. */
  inline-size: 100%;
  justify-content: center;
  text-transform: uppercase;
}
