  We prove a $p$-converse theorem for elliptic curves $E/\mathbb{Q}$ with
complex multiplication by the ring of integers $\mathcal{O}_K$ of an imaginary
quadratic field $K$ in which $p$ is ramified. Namely, letting $r_p =
\mathrm{corank}_{\mathbb{Z}_p}\mathrm{Sel}_{p^{\infty}}(E/\mathbb{Q})$, we show
that $r_p \le 1 \implies \mathrm{rank}_{\mathbb{Z}}E(\mathbb{Q}) =
\mathrm{ord}_{s = 1}L(E/\mathbb{Q},s) = r_p$ and $\#\mathrm{Sha}(E/\mathbb{Q})
< \infty$. In particular, this has applications to two classical Diophantine
problems. First, it resolves Sylvester's conjecture on rational sums of cubes,
showing that for all primes $\ell \equiv 4,7,8 \pmod{9}$, there exists $(x,y)
\in \mathbb{Q}^{\oplus 2}$ such that $x^3 + y^3 = \ell$. Second, combined with
work of Smith, it resolves the congruent number problem in 100\% of cases and
establishes Goldfeld's conjecture on ranks of quadratic twists for the
congruent number family. The method for showing the above $p$-converse theorem
relies on new interplays between Iwasawa theory for imaginary quadratic fields
at nonsplit primes and relative $p$-adic Hodge theory. In particular, we show
that a certain de Rham period $q_{\mathrm{dR}}$ can be used to construct
anticyclotomic $p$-adic $L$-functions for Hecke characters and newforms,
interpolating anticyclotomic twists of positive Hodge-Tate weight in the
central critical range. Moreover, one can relate the Iwasawa module of elliptic
units to these anticyclotomic $p$-adic $L$-functions via a new "Coleman map",
which is, roughly speaking, the $q_{\mathrm{dR}}$-expansion of the Coleman
power series map. Using this, we formulate and prove a new Rubin-type main
conjecture for elliptic units, which is eventually related to Heegner points in
order to prove the $p$-converse theorem.
