Attaining the vaunted S-rank in each stage hinges on four requirements: acquiring all gems, taking no damage, using no retries, and collecting the sun fragment for each stage. However, there's a trick to getting around one of these requirements. If you're stumped or otherwise irreversibly stuck on any particular screen (i.e. a block is where it shouldn't be and can't be recovered) simply leave the screen and come back. The enemies, blocks and monster pots will be reset to their original position, but it won't count as a retry when your final score is tallied!
(Note: there are a few rooms in the game where you can become physically stuck and unable to leave the room at all, however, these rooms are few and far between.)
There is actually a purpose to collecting those Sun Fragments in each stage. If you get all of them in a world, an EX level is unlocked for you to play. In order to play the EX Stages, you must beat the game and have every Sun Fragment from every level of the game. Only then will you be able to play the EX stages.