I'm an electrical engineer with some experience with lithium, nickel cadmium, nickel metal hydride cells.
With Li-Ion (or really Li-Polymer in your iPhone) with the latest versions of iOS it's totally safe. They learn your charging pattern (when you sleep) and charge up to 80% quickly and hold it there until just before you wake where it will charge the last 20%. That way the phone minimized the length of time the battery will spend above 80% which over years and years of use can really add up, a small change that will probably provide a considerable boost to cell life. Basically 5 or so hours each day less the cell spends at 100% x perhaps over 1000 days is a lot of wear saved.
Most of the damage done to cells is 80%. The closer you are to 0% or 100% the more you are causing chemical damage (like dendrite formation) to the cell. Of course number of cycles is a thing too. Ideally you'd keep a battery permanently charged at 50% at perfect operating temperature but that isn't realistic.
TLR if you are on the latest iOS just put it on charge when you go to sleep, the phone will take care of the rest and avoid running it down below 10% as much as possible.
I don't use battery optimization on my 12 Pro Max. I charge to 100% each charging with a fast charger. I've had it for 8 months, and the battery is still at 100% battery health. And I'm a heavy user.