Connecting planet formation and astrochemistry. Refractory carbon depletion leading to super-stellar C/O in giant planetary atmospheres