After beating an enemy, you'll be sent to a bonus stage for the area, the time limit for the area is directly proportional to how many yellow hourglasses you collect during the 3 rounds.
Each hourglass adds 5 seconds to the time limit, to a maximum of 60 seconds for 12 hourglasses.
Collecting every coloured orb in a bonus stage ends it immediately.
Bonus stages have 24 coloured orbs, 8 in green, 8 in red and 8 in blue.
Green orbs increase your base speed.
Red orbs increase your magic meter gain.
Blue orbs increase your "agility" and i have no clue on what it actually influences, frame counting didn't help much, my current theory is that it "shields" you from debuffs but i cannot confirm with current game knowledge.
The bonus stage usually incorporates some of the gimmicks from the main stage, for example: the game has boost pads in some stages, and those appear in that stage's bonus.
fun thing: if the timer ends while you are in a boost pad, the stage won't kick you out until the boost pad animation is done, this means you can afford to spend less time collecting hourglasses to get to the bonus faster, since the time limit won't matter as much.