The Solar Dynamo and Its Phase Transitions during the Last Millennium