(CNN) — Predjama is one of the most extraordinary castles in the world, built in the mouth of a cave complex at the end of a valley in southwest Slovenia.
Set halfway up a 400-foot (123-meter) vertical cliff face, it appears in records from 1202 and is listed by Guinness World Records as the world's largest cave castle.
With a Renaissance facade dating back to the 1580s, the word "majestic" doesn't even begin to describe it. Yet for tour guide and historian Vojko Jurca, one of the highlights is, on first appearances, a little underwhelming.
"This is it," he says proudly, indicating an outhouse toilet with a sloping roof and a boarded-up door.
It may look unremarkable, but the story behind it isn't.
The story focuses on robber baron Erasmus von Lueg, a local Robin Hood hero who fled to the castle in the mid-1480s after killing Count Pappenheim, Marshal of the imperial Habsburg Court, in a duel whose legitimacy was disputed.
In retaliation, a siege was ordered on Predjama by Habsburg Emperor Frederick III.
But Erasmus stood firm, aided by a network of secret tunnels burrowed into the rocks that allowed him to bring in provisions and collect rainwater.
He mocked his opponents by sending them fresh cherries brought in from the Vipava Valley, 13 miles west, using those underground passages.
The end would come, after a year and a day, when Erasmus was betrayed by a servant.
As Jurca tells it, when Erasmus went to the outhouse located on a third-floor terrace, the servant lit a wooden torch as a signal. Moments later, a cannonball came whistling through the air, killing Erasmus in the middle of his last bowel movement.
The outhouse has clearly been rebuilt in the intervening years.
From Slovenia to Westeros
Final movements: Erasmus was killed when a cannonball hit the castle's outhouse.
The manner of Erasmus's death hasn't escaped the attention of "Game of Thrones" fans who point at the similar, undignified end of Lord Tywin Lannister, who was shot with a crossbow while on his bathroom throne.
They also note that Predjama's last owners, the Windisch-Grätz family, who used the castle as a hunting lodge until the end of World War II, have on their coat of arms a wolf, the seal of the Stark noble house.
As it happens, author George R. R. Martin visited the castle one evening in June 2011, after a book signing event in Trieste.
"On the way home, we stopped at the most amazing castle, built into the mouth of a huge cave. Definitely have to model some castle in Westeros on this one, it was an eyeful, especially by night," he says in a blog post.
Legend and history are only part of the appeal of Predjama castle. You really have to visit to comprehend how human enterprise was so organically bound to nature.
Approaching the castle from any direction, it's almost completely hidden, only visible at the last moment -- whereas sentries around the castle would've been able to spot anyone coming immediately.
Once inside, it's obvious that safety rather than comfort was the biggest concern in the Middle Ages -- the castle is impregnable but the cold and damp make it almost unlivable.
Nowadays, entering the castle involves passing through a drawbridge. The original entrance was higher up where two faint doors can be glimpsed. They were reached via ladders that could quickly be withdrawn.
Back in the day, visitors would first enter the courtroom, where rough justice was dispensed. Few of the ruler's subjects would be allowed further than this, unless they were unlucky.
Behind a thick wooden door there's a torture room, which, uniquely, is situated in an actual cavernous dungeon. The preferred punishments here were the rack, on which prisoners were stretched, and the horse, a painfully pointed triangular device they were made to straddle.
One of the most pleasant spaces follows. The dining room is insulated by walls that are nearly five and a half feet thick, and warmed by the small but functional kitchen, in which a fissure doubles as a natural extractor hood.
You can also inspect an original latrine, a protruding seat over the cliff that allows gravity to do its dirty work. Erasmus would have used straw, dried moss and cabbage leaves instead of toilet paper, or at least he would have before he was blown to smithereens.
The castle's barracks is now an armory museum.
A climb up more stairs to the third floor reveals the gun loops, arrow slits and murder holes used to pour boiling oil or molten resin on to the besiegers.
That's where the open terrace is located. Here there's a view of the whole valley, as well as the most famous outhouse in Slovenian history.
Next to it is the bedroom. It's the warmest room, as it's the only one with a fireplace. Castle keepers lived here until the 1980s.
Upstairs is an attic that served as a barracks and a lookout. The views down the Lokva Valley are uninterrupted and gorgeous.
The barracks have been converted to an armory museum showcasing medieval weapons like battleaxes, halberds, crossbows and flails.
Interestingly, a passage here leads straight to the torture room. Presumably anyone sleeping on duty could be unceremoniously dragged down into it.
From here you can also enter the innards of the cave, exploring until the light from the entrance dwindles to a speck, letting you contemplate the surroundings.
The extensive limestone cave system in southern Slovenia is called karst, after the Latin name Carsus given to the plateau above Trieste.
As it was the best-known limestone terrain for centuries, the word has become generic, describing any limestone terrain with cavities like a Swiss cheese with holes.
Beneath the castle, one large cave stretches for 8.7 miles, second in length to the nearby complex of Postojna.
There's no tourist infrastructure at this large cavern, but it is possible to visit during summer months with proper caving gear, lamps and a specialist guide. It's closed in winter because a colony of Schreiber's long-fingered bats uses it to mate and hibernate.
The castle's Renaissance facade dates to the 1580s.
JURE MAKOVEC/AFP via Getty Images
Back in the castle, a one-way system leads back down to the knights' room, notable for its Gothic niches and a ceiling painted with oxblood.
There are glimpses here and there of how the structure's builders made efficient use of their rocky situation. One small shaft near the exit became a kennel for hunting dogs, while a cave mouth under the castle served as stables.
Leaving the castle, guide Vojko has one more stop on his tour -- a nearby village where an ailing linden tree is being propped up in the cemetery of Our Lady of Sorrows.
The church was consecrated around 1450 by the bishop of Trieste, future Pope Pius II.
"Legend has it that this linden tree was planted on top of Erasmus' grave," Vojko says.
The tree was badly damaged by fire in 2001, but it meant so much to the villagers that tree surgeons were called in, and its trunk split and repaired.
It still proudly survives, like Predjama castle itself.
Correction: An earlier version of this story misstated the nationality of Emperor Frederik III.