Ignoring simultaneous deaths the aggregate estate is £1.035m and as pqtaxtion indicates the IHT charge on both deaths would be £154K.
1) .... Gifting the £165K flat in which you/wife haven't lived means CGT but as you're both non-UK resident then no CGT. .....No CGT on transfers (as you're non-UK resident); £235K falls within you're nil rate bands; limited IHT on trusts on on-going basis.
2) ..... Re dying simultaneously, my understanding is that under Scottish law the general rule (ie older dies first) does not apply to spouses (ie both held to die at same time). This means that neither spouse can inherit under the other spouse's will; thus IHT charged on each spouse's estate (ie £154K in total as above). Under English law in the same circumstances IHT would be charged only on estate of younger spouse which would be nil; saving £154K.
Maybe others may express their views on my comments.
Maths
Re 1) OP says nothing about being non-UK resident - he & his wife appear to be resident in Scotland.
Re2) as cumulatively 2 NRBs (one transferrable if there is a survivor) would be available to set against cumulative death estates irrespective of deemed order of deaths (whether older first, simultaneous, younger first), I can't see how IHT payable would differ dependent on how that order is deemed when all material assets in their two death estates are held jointly and pass to surviving spouse (if any, otherwise to children). Please explain in more detail your thnking.