Have a look at a charger IC like
MP2672A :
https://www.monolithicpower.com/en/mp2672a.htmlDatasheet :
https://www.monolithicpower.com/en/documentview/productdocument/index/version/2/document_type/Datasheet/lang/en/sku/MP2672AGD/document_id/9059/Link
https://www.digikey.com/en/products/detail/monolithic-power-systems-inc/MP2672AGD-0000-Z/13572801 or
https://www.digikey.com/en/products/detail/monolithic-power-systems-inc/MP2672GD-0000-Z/13159530It's a 2 cell charger IC that works with 5v input - it boosts the input voltage to whatever voltage is needed to charge the 2 cells (at least around 6.7v, at most around 8.4v) and makes this voltage available on a system out pin while there's DC in present and the battery is charged at the same time.
When the DC input is gone, the chip connects the battery to the system out pin.
So you still need your step-up regulators but you don't need to complicate your life with diodes, you can just use the system out pin all the time.
So basically you could use 4 cells, 2 cells in parallel, connected in series with another 2 cells in parallel ... boosting 6v ..8.4 to 9v would be very efficient , boosting to 12v would be a bit less.
Another option ... use
MP2759 / MP2759A:
https://www.monolithicpower.com/en/products/battery-management/chargers/1-series-cell-chargers/mp2759a.htmlLink :
https://www.digikey.com/en/products/detail/monolithic-power-systems-inc/MP2759AGQ-0000-Z/15861759Datasheet:
https://www.monolithicpower.com/en/documentview/productdocument/index/version/2/document_type/Datasheet/lang/en/sku/MP2759AGQ/document_id/9670/It's a charger IC that can charge up to 6 cells in series. It can take up to 36v input, and has a built in step-down regulator to produce the voltage required to charge the cells.
You can set the number of cells and the charge voltage per cell using resistors so it's very easy to use (no i2c or programming eeprom/flash inside chip)
The way I'd use it would be with 4 cells in series and a 18-20v laptop adapter to power it, or 20v from a usb charger if it supports it . The battery charger IC would buck the 18-20v to 4x4.2 = ~17v and charge the batteries.
You could use it with only 3 cells in series, in which case you could go down to maybe 15v as you only need more than 13v to charge 3 cells in series. But, you'd need a buck-boost regulator to produce 12v in that case.
There's no system out pin, but you could use a power switch like TPS2120 or TPS2121 to automatically switch between two inputs, selecting the highest voltage or a giving priority to one input if both inputs are present
TPS2120 : 2 inputs, up to 22v input , up to 3A output, switches within 100us :
https://www.digikey.com/short/r82t8v84TPS2121 : same but up to 4.5A output, switches between 5us :
https://www.digikey.com/short/trnwm3j8The TPS2121 makes more sense especially as it's easier to solder on a board (TPS2121 is only available as WCSP package, very small)
So you could have the power adapter as one input, battery voltage as second input - while the adapter is plugged in, the 18v-20v is higher than battery voltage so it will be powering everything. When input is gone (power loss), it switches to battery.
As the battery pack is always higher than 12v (if you use 4 cells in series), you could use more efficient step-down regulators for 9v , 12v and 5v.