This article describes the story of Legacy of Lunatic Kingdom in detail.
Once, there was a being named Junko, a divine spirit with a grudge against the lunarians, especially Chang'e. This grudge came from the fact that Chang'e's husband killed Junko's son. Since then, she purified her grudge to the point where she's nothing more than pure resentment. Junko calmed her rage by repeatedly attacking the Lunar Capital, but none of her attacks have been successful. Then she met with Hecatia Lapislazuli, a goddess of Hell who sympathized with her because she also had a grudge against Chang'e. Hecatia allowed Junko to use fairies such as Clownpiece in her plan to invade the Lunar Capital and leave Chang'e vulnerable. Junko purified the Hell fairies into pure life force so they can wreak havoc on the Lunar Capital while also being immune to the lunarians' purifying weaponry.
Because of this, the lunarian goddess Sagume Kishin and the moon sages froze the Lunar Capital and asked Doremy Sweet to make a replica Lunar Capital in the Dream World. Since the Lunarians couldn't stay in the Dream World forever, Sagume developed the "Lunar Capital Transfer Plan", which involved purifiying Gensokyo so it could be inhabited by the lunarians. But youkai were also living in Gensokyo, so Sagume created an Occult Orb that could spread a particular urban legend called the "Apollo Project Coverup Theory", so the Lunar Capital could materialize in Gensokyo, prompting the events of Urban Legend in Limbo, which would later turn into the events of Legacy of Lunatic Kingdom.
Following the events of Urban Legend in Limbo, a weird spider-looking probe crashes into Youkai Mountain and starts to roam around. Reimu and Sanae decided to investigate the probe and found out it was of otherworldly origin. And worse, trees wither and mist fades as the probe passes by. At Eientei, Eirin Yagokoro and Kaguya Houraisan are fully aware that this day would come for the Lunarians to take action to invade Gensokyo. In response, as they refuse to take part in the incident directly since they believe that's what the Lunarians would want, they prepared a special medicine known as the Ultramarine Orb Elixir and asked Reisen to deliver it to Reimu and her friends. Meanwhile, Marisa is still studying about the Occult Balls, finding out why one of them is different from the others as Reisen appears with the medicine. With Gensokyo facing a new crisis, Reimu and the others must stop the one behind the incident.
The heroine first encounters Seiran, who is a member of the "Eagle Ravi" Earth Recon Unit sent to purify Earth. Seiran tries to stop the heroines from reaching the lake, but is defeated in the end.
The heroine proceeds her journey up the mountain where she meets Ringo, who is a member alongside Seiran of the "Eagle Ravi" Earth Recon Unit. Ringo claims to have heard of her from Seiran who said she engaged an interesting person. The heroine asks to use the Kaian Passageway, but Ringo forbids them to and attacks them to keep them from using the passage, but ultimately fails. Ringo proceeds to let the heroine into the passageway.
When the heroine arrives in the Dream World, they encounter Doremy Sweet, who is surprised at the fact that the heroine managed to enter the Dream World with their physical body and asks if they've been caught in a trap of some sort. After Doremy's defeat, she tells the heroine that she's in a dream herself, which is called the "Lunatic Dream". She then lets them proceed to the Lunar Capital as they requested because she "wanted a little bit of payback".
Once the heroine arrives at the Lunar Capital, they find it's completely frozen over. Then, Sagume Kishin appears, not saying very much to the heroine, but when she's defeated, Sagume explains that was part of the plan to relocate the Lunar Capital to Gensokyo. Then Sagume's ability to reverse an event with her words starts to go into effect, making it so the relocation never occurred. Sagume proceeds to tell the heroine that they're the only one that can solve the incident at this point and tells them to advance to the Sea of Tranquility.
At the Sea of Tranquility, the heroine discovers that what would normally be lifeless is overrun with Hell fairies. After taking care of them, their leader, Clownpiece, congratulates the heroine for getting past the fairies she inflicted with madness. A while afterwards, Clownpiece remembers what she was told by her master's friend, "If anyone comes from the Lunar Capital, do what you want with them" and proceeds to attack the heroine. Clownpiece then laments her defeat afterwards, saying that as long as the Hell fairies controlled the Sea of Tranquility, the lunarians wouldn't react. After the heroine says they're from Earth, Clownpiece is surprised and says she never thought an earthling would arrive on the Moon.
Once the heroine arrives at the Underside of the Sea of Tranquility, Junko appears to the heroine and tells the heroine everything about her plan. Whether said plan succeeds or not depends on if you've taken Eirin's medicine (PointDevice), managed to clear the game without getting hit (No-Death Clear Legacy Mode), or not (Legacy Mode with deaths). For example, if the player is on PointDevice Mode or manages to No-Death Clear Legacy Mode, she'll surrender before the fight, but you'll still have to fight her anyways. But if the player is on Legacy Mode and has lost a life, she'll mock the heroine instead.
The difference between the endings in other official games and the endings in Legacy of Lunatic Kingdom is that you don't get a "bad ending" once you have continued, but rather you get one if you play Legacy Mode and lose a life. You'll still get a "good ending" if you manage to clear the game on Pointdevice Mode or No-Death-Clear Legacy Mode.
Reimu's Ending (PointDevice Mode or Legacy Mode with No Misses)
Show Ending Summary
At Eientei, Reimu is talking with Eirin Yagokoro about the events of the game. Reimu asks why she had to save the Lunar Capital with Eirin replying if she rescued the capital, she'd also rescue Gensokyo. Reimu complains that she thinks the Lunarians should've solved the problem themselves and Eirin tells her that only humans could solve it. Eirin then states she didn't tell her earlier because she thought if she said it's for the sake of the Lunar Capital, she'd refuse. Eirin regretted not telling her earlier, and Reimu left Eientei unsatisfied with that outcome. Along the way, Tewi Inaba asks Reimu questions related to the lunarians. Tewi states her reason for asking was for reference and she wanted to know the weak points of the lunarians. Tewi also mentioned she wanted to do some business with the lunarians.
Reimu didn't know what she was planning, but she knew the earth rabbit was going to get beaten up or use lucrative words, so she was interested, but at the same time, she didn't care because she didn't want anymore business with the lunarians.
Reimu's Ending (Legacy Mode with Misses)
Show Ending Summary
At the Hakurei Shrine, Sanae tells Reimu that moon rabbits are still invading the mountain. Reimu afterwards tells her that they weren't meant to defend against the lunarians, but actually managed to get caught in the story and it turned into saving the lunarians from Junko. Sanae says she now understands what the Ultramarine Orb Elixir was for. Reimu then says she didn't use it because she didn't know what was in it and,as a result, lost to Junko. A few days afterwards, the rabbits arrived at the Hakurei Shrine, where Ringo says the shrine is really popular amongst the moon rabbits while Reimu wonders why a being that despises impurities is on an Earthly surface. Ringo says only Lunarians despise impurity while moon rabbits don't care about that. Then the youkai came as usual, but somehow, they can see the moon rabbits with their own eyes. Apparently, the probe from the Moon was designed to prevent impure beings from approaching the moon rabbits. In the end, it was decided that Sagume and the lunar sages decided to purify Gensokyo so they wouldn't have to fight the youkai living there themselves.
Marisa's Ending (PointDevice Mode or Legacy Mode with no Misses)
Show Ending Summary
Back at her house, Marisa is discussing to herself about matters such as the Occult Orbs and the incident until Yukari Yakumo appears via gap and talks to Marisa a bit. Then, Yukari asks Marisa show her the Lunar Capital's Occult Orb. Marisa asks if she's going to break the orb because it was a dangerous object that could cause Gensokyo to fall into chaos. Yukari denies that claim and says it wouldn't be enough to bring Gensokyo into chaos, and she tells Marisa instead the orb could "change Gensokyo even more" and that they're lucky to have gained such information and magical power. After talking some more, Yukari left without touching the Orb. Marisa wondered why Yukari would show up at her house. Yukari's goal was to protect Gensokyo, but was she also considering using the Occult Orb to invade the Outside World or the Lunar Capital? Marisa thought that was impossible, but even so, the thought sent chills down her spine.
Marisa's Ending (Legacy Mode with Misses)
Show Ending Summary
At Marisa's house, Reisen is talking with Marisa about why the plan to chase away the moon rabbits has failed, with Reisen regretting having relied on Marisa for the job. Reisen also said that the only reason Marisa accepted the potion because of the fact that it had side effects, but didn't take it (Marisa denies that claim, saying she was excited that time because she had received a rare treasure). Reisen then laments the fact that none of the humans she offered the potion to could manage to solve the incident. Reisen then decides to solve the incident herself and Marisa asks why she didn't do so in the first place. Reisen then replied she didn't want to drink the Ultramarine Orb Elixir. (Marisa didn't tell Reisen everything that happened, though). Marisa thought she'd been deceived by the rabbit because there were some things she could not understand, but Reisen didn't know the truth either and Marisa thought she was right to not use the elixir. The only person that knew the truth was none other than Eirin. As such, Marisa didn't want to take part in such a plan.
Sanae's Ending (PointDevice Mode or Legacy Mode with no Misses)
Show Ending Summary
Back at the Moriya Shrine, Sanae is busy writing her report to Kanako Yasaka about what happened. After she finished, Kanako read Sanae's report, which was only 80% true. When they finished talking about the report, the conversation quickly turned into one about Sagume Kishin, with Kanako saying if she's the Sagume, then the lunarians are akin to the heavenly gods. Afterwards, Kanako went into thinking. Since some of the lunarians had divine lineages, and they were going to come down to Earth (although reluctantly), it would be like the second coming of the Divine Emperor. Although Sanae didn't know this, a native god preventing such an event deserved to be praised. Kanako then thought, "This girl really does have it in her."
Sanae's Ending (Legacy Mode with Misses)
Show Ending Summary
At the Moriya Shrine, Kanako Yasaka is training Sanae to be better at danmaku dodging by throwing various balls at her of various types. After she fails to dodge them, Kanako asks her to run a lap around the lake. After Kanako declares her to be "too slow", she tells Sanae to prepare for the next "danmaku" set. Sanae declares herself to be too tired and thinks she should take a break, but Kanako denies her request and says that attitude is the reason she lost against the lunarians and asks if she wanted to come back beat up like last time. After one last discussion, Suwako Moriya arrives with a conclusion from the analysis she's done with the Ultramarine Orb Elixir (which explains why Sanae went to the Moon without it) and declared it dangerous. Suwako declares that while it gives the user the ability to see the future, it had the strong side effect of purifying the past if it were used on an ancient, native god and that it had a strong influence on the Earth's creatures. Sanae asked if it'd be dangerous if she used it. Suwako replied that nothing deadly would've happen, but her impurities would be washed away, leaving her a "pure human". The difference between lunarians and earthlings isn't whether of not they have impurity to begin with, but lunarians were once earthlings that now live on the Moon. Even then, they can't live on earth because the concept of life and death is considered impurity in their understanding. The Ultramarine Orb removed the chance of getting hit by danmaku, along with the chance of being tainted with impurity. Since those that take it don't follow the concept of "extra lives", misses don't feel as heavy. Perhaps the Ultramarine Orb Elixir really is dangerous.
Reisen's Ending (PointDevice Mode or Legacy Mode with no Misses)
Show Ending Summary
At Eientei, similar to Reimu's ending, Eirin is talking to Reisen about the events of the game. After a short conversation, they start talking about Junko. Eirin tells Reisen that Junko wholeheartedly hates someone on the Moon. Eirin explained Chang'e's husband killed Junko's son, and then she killed the husband as revenge. The husband's wife was none other was Chang'e, a criminal who drank the Hourai Elixir and is imprisoned in the Lunar Capital. Junko hated Chang'e, and consequently, the lunarians as a whole. When she tried to attack the Lunar Capital, she was tricked by the lunarians in several contests of wit, but only a small amount of lunarians knew that. Reisen was amazed that the Lunar Capital was under attack, and yet, she still didn't know about the people's role. Eirin then asked Reisen not to tell the other moon rabbits about it, since they can be used to overthrow Chang'e herself. Eirin didn't hide anything from Reisen in her explanation, and after talking with Eirin, Reisen felt a bit closer with her teacher. Afterwards, she realized she will no longer be able to communicate with the other moon rabbits like she could before.
Reisen's Ending (Legacy Mode with Misses)
Show Ending Summary
Outside of Eientei, Reisen panics and fears she's going to get scolded for not solving the incident and regrets not taking the Ultramarine Orb Elixir. Reisen finally decides to avoid Eientei and sleep outside. This is when Kaguya Houraisan appears to her and tell her to come home. Kaguya also tells her that while Eirin is pleased with the information Reisen brought her, she's also angry at her for not taking the elixir. And Kaguya tells her that there was something else that not even Eirin knows about and wants Reisen to tell her more about it. Reisen then talks to Kaguya about matters related to Clownpiece. And thanks to Kaguya's favors, Reisen finally decided to return to Eientei, and by the time she got there, Eirin didn't seem so angry anymore. Reisen reported as much detailed information about the lampad to Eirin as possible, but nobody was able to grasp the lampad's true identity. When the opponent's identities finally revealed themselves, the atmosphere grew even eerier and thus, the events of the Extra stage took place.
After the events of the game, the heroines return to their ordinary lives, only to hear from Sagume Kishin that the lunarians haven't returned from the Dream World and rabbits are still invading the Youkai Mountain. Not wanting the lunarians to find out that the Lunar Capital they're in right now is fake, she asks the heroines to return to the Dream World to find out what's going on. The investigation leads them to Doremy Sweet, and eventually Junko and Hecatia Lapislazuli, who revealed that they knew the lunarians would retreat to the Dream World and thus filled the surroundings of the fake Lunar Capital with life, leaving the lunarians completely suppressed. Then, the heroines engage in a long battle with Hecatia switching between her Otherworld, Earth, and Moon bodies, and Junko occasionally jumping in. Afterwards, Reimu tells them not to cause any more trouble or she'd exterminate them, Marisa decides to learn more about the goddess, Sanae talks to them about their attack strategies, and Reisen arranges for Hecatia to get to know more about Gensokyo's residents.