Traditional ECG baseline removal faces a frequency trade-off: aggressive cutoffs destroy T wave morphology because the T wave and baseline overlap in frequency, while conservative cutoffs leave contaminating drift. We propose a per-lead template fitting algorithm that jointly estimates beat morphology and the baseline by gradient descent on a cost function encoding simple ECG invariants. The ECG recording is modeled as a smoothly-drifting baseline plus beats temporally localized around each R peak, with the residual treated as noise. On 200 LUDB records, the fit removed baseline wander with a +10.0 dB SNR gain at 0 dB input while keeping T wave morphology stable (Pearson ≥ 0.95), and reproduced simulated ground-truth morphology at Pearson 0.98 on 90 MedalCare-XL records across four pathology classes. As a cross-lead consistency check, the fitted morphology reduced the Einthoven residual II− I− III on 199 of 200 records even though the model fits leads separately.