The castles in Spain were built mainly for the country's defense, particularly with respect to fortification. During the Middle Ages, northern Christian kingdoms had to secure their borders with their Muslim southern neighbours, thus forcing both Christian and Muslim kings to grant border fiefs to their liege noblemen so as to keep and maintain defensive fortresses. When the Reconquista advanced, those border castles lost their initial purpose, and, as in the rest of medieval Europe, they were used as noble residences and fief-keeps. Sporadic threats of war maintained their initial military purposes as enemy invasions were common. In some locations, such as the Basque country, fiefdoms did not exist as such, and noble families could not afford nor did they need huge fortresses, giving rise to many tower houses. In Muslim Spain many castle-palaces were built: the petty taifa kingdoms that arose after the fall of the Caliphate of Córdoba were militarily weak thus castles began taking on a more aesthetic purpose. During the late Middle Ages, Christian kingdoms had secured and enriched themselves well enough to support a more courtly lifestyle, so more residential castles were built, such as the Alcázar of Segovia, which was used as the main residence of the kings of Castile, whereas the Castle of Olite, built in a luxurious gothic style, was the seat of the Kingdom of Navarre's royal court.