Hi,
Have you tried replacing the camshaft position sensor B on bank 1?
I recently had the code P0340 for camshaft position sensor A on bank 1. Brought a new sensor for $50 from Rockauto (sensor and postage), replaced the faulty one and now my Outback runs like it used to.
https://www.yourmechanic.com/article/p0365-obd-ii-trouble-code-camshaft-position-sensor-b-circuit-bank-1-by-valerie-johnston