A three-act structure nobody asked for.
A player is offside if they are nearer the opponent’s goal line than both the ball and the second-last defender at the moment a teammate plays the ball, and they are then involved in active play. Position alone is not an offence; involvement is.