The line of succession is determined by the Presidential Succession Act, which was passed in 1947. This law outlines the order in which people can take over as President, and it's based on the idea that the Vice President should be next in line, followed by other government officials in a specific order. It's kind of like a game of musical chairs, but with much higher stakes.
One of the quirky things about the line of succession is that it's not always straightforward. For example, if the Vice President is unable to serve, the Speaker of the House is next in line - but only if they're a member of the same party as the President. It's like a big game of politics, where the rules can change depending on the circumstances.