First of all, while I have no idea how many days you have in mind altogether... I would look into minimizing the # of base towns if possible
Stay in Cologne, do a day outing to Bonn and back.
Stay in Frankfurt, day trip to Idstein and Heidelberg (as planned.)
Stay in Gengenbach, day trip to Triberg and Offenburg (free day trips with the KONUS card.)
Stay in Munich, day trip to Innsbruck (probably a more expensive choice)
Stay in Berlin
You will need to research the cost of the individual day trips from your base towns on your own. Normally, a "day ticket" valid for the round trip (like Cologne > Bonn > Cologne) is available to keep your costs reasonable. Then compare the total cost of those with the cost of two Deutschland-Tickets.
You will ALSO need 4 point-to-point tickets for the long-distance trips between these 5 base towns. (These are not so doable by regional train with the D-ticket.) Check at DB for those. Alternative is the German Rail Pass sold by Eurail for $295. It provides 4 days of unrestricted train travel on any German trains, including the long-distance, high-speed ICE trains, during any 30-day period.
https://bahn.eurail.com/en/one-country-pass/german-rail-pass
Note that the GRP is also valid for travel from Munich into Italy on certain trains, a route which has a stop in Innsbruck. So a 5-day pass ($326) could perhaps cover an extra day for the round-trip one-day journey to Innsbruck.
German Rail Pass info flyer:
https://assets.static-bahn.de/dam/jcr:87153f1d-08e1-481e-8aae-b5fffe7090b5/German_Rail_Pass_brochure_2025.2025-04-08-06-23-03.pdf
Advantage of the GRP is the schedule flexibility you will not get with the point-to-point tickets from DB, which are train/time specific and non-refundable.
I am not especially onboard with the itinerary you are doing, generally speaking. If it's too costly, you might wish to do things differently. But then I really don't know what your unique travel goals might be, how important to you this place and that place might be.