We can in principle find the optimal first $n$ moments for a polynomial approximation of $f$. This reduces the problem to a truncated Hausdorff moment problem, for which solutions exist. Let $f \colon [0,1]^d \to \mathbb{R}$ be a continuous function. Approximate $|f|$ with the multivariate Bernstein polynomials of order $n$ (writing $f_{k_1\cdots k_d} = f(k_1/n, \ldots k_d/n)$ for short), $$|f_n|(x) = \sum_{k_1 \cdots k_d} |f_{k_1\cdots k_d}| \prod_{i=1}^{d} \binom{n}{k_i} \, x_i^{k_i} (1-x_i)^{n-k_i} \;.$$ Let $S_{lm} = E[X^m (1-X)^{l-m}]$. The expectation of the approximant is then $$E[|f_n|(X)] = \sum_{k_1 \cdots k_d} |f_{k_1\cdots k_d}| \prod_{i=1}^{d} \binom{n}{k_i} \, S_{nk_i} \;,$$ which should be maximal. The value of $S_{nk}$ is a linear combination on the first $n$ moments $M$ of the resulting distribution. Expanding $$S_{lm} = \sum_{r=0}^{l} \binom{l-m}{r-m} (-1)^{r-m} \, M_r \;,$$ the expectation in terms of the moments is $$E[|f_n|(X)] = \sum_{k_1 \cdots k_d} \sum_{r_1 \cdots r_d} |f_{k_1\cdots k_d}| \prod_{i=1}^{d} \binom{n}{r_i} \binom{r_i}{k_i} (-1)^{r_i-k_i} \, M_{r_i} \;.$$ The problem is hence the constrained multilinear optimisation $$ \begin{aligned} \max_{M_1 \cdots M_n} \;&\; \sum_{k_1 \cdots k_d} \sum_{r_1 \cdots r_d} |f_{k_1\cdots k_d}| \prod_{i=1}^{d} \binom{n}{r_i} \binom{r_i}{k_i} (-1)^{r_i-k_i} \, M_{r_i} \;, \\ \text{s.t.} \;&\; \sum_{r=0}^{l} \binom{l-m}{r-m} (-1)^{r-m} \, M_r \ge 0 \;, \\ &\; M_r \in [0,1] \;, \quad M_0 = 1 \;. \end{aligned} $$ Once the moments are found, it is necessary to construct an approximate distribution $g_n$ with first moments $M_r$, $r = 1, \ldots, n$, matching the optimal moments. This is the truncated Hausdorff moment problem. From a cursory Google search, multilinear optimisation appears difficult (but I have no idea, really). Nevertheless, it is a recipe for calculations: For the baby problem, I find the moments (with $n = 12$) 0.5, 0.40042, 0.35063, 0.323633, 0.308033, 0.298489, 0.292331, 0.288158, 0.2852, 0.283021, 0.28136, 0.280058 using a quick _Mathematica_ test run, and the numbers are relatively robust against changes in $n$ and match the distributions suggestions from the comments.