I booked tickets as I went along in Portugal - I booked nothing in advance for maximum flexibility. Unlike in other European countries, even the fast AP trains are not that expensive booked at the last minute. They are certainly cheaper if booked in advance but not with the extreme discounts you get in say France or Italy.
The trains in Portugal worked well for me, but many trains do not go directly to the city centers. E.g. in Coimbra and Porto, you need to connect to the smaller city center trains. But some local trains may be direct. I found that from Coimbra to Porto, I could take a local train from Coimbra "A" (the city center station) to Porto without the change at Coimbra B. It was a slower train with more stops, but I avoided one of the connections. (Still had to connect in Porto.) And honestly, the local trains I rode on were not very full, whereas the high speed trains I took in Portugal were pretty full.
Here's the official trains website for Portugal. They have a phone app too which I found very helpful, if you will have a smart phone with you.
https://www.cp.pt/passageiros/en