Impossible castle


You're also not allowed to castle through check - e.g. queenside castling by black is not legal if d8 is attacked by an enemy piece.
The simple way to think of it is if you break it down into multiple moves at once. The king starts at e8, moves to d8 and then c8, and finally the rook moves to d8, jumping over the king. If any square that the king is on during those moves is under attack, then castling is not legal.