I recently went to a beach, and I noticed that the sand seemed to have a few distinct regions. I'm wondering what would cause this, and how it works.

One region is the part of the beach which is kept wet by the waves, but is far enough away that most waves don't seem to reach all the way to the end of it. This part consisted of small-grained, "soft" sand.

This region is followed by a region with a lot of small rocks (mostly the size of, say, someone's smallest toe). This region was located a bit past (i.e.: further into the water) the lowest point the water tended to reach. This size of the grains of sand of this region blends smoothly into the previous region, so they get progressively larger as you walk further out to the water.

The last region is another one of fine-grain sand, and it also had ripples in it (I'm assuming that this is just because of the waves, because I noticed that the waves picked up sand from the peaks of the ripples and pulled it back out to sea).

The first two distinct regions seem to be the result of some type of sorting mechanism induced by the wave. If so, how does this work?

And why was there a second region of fine-grain sand *after* the coarse-grain region?