Glamorgan 240 for 4 (Lloyd 84) trail Derbyshire 368 (Guest 109, Madsen 70, Masood 60) by 128 runs
David Lloyd led from the front as Glamorgan fought back on the second day of the LV=Insurance County Championship Division Two match against Derbyshire at Derby.
After Michael Hogan and Michael Neser each took four wickets to bowl Derbyshire out for 368, the Glamorgan captain scored 84 from 104 balls, sharing an opening stand of 103 with Andrew Salter.
Marnus Labuschagne made an unbeaten 53 and Sam Northeast 49 as Glamorgan closed on 240 for 4, 128 runs behind.
Glamorgan's bowlers completed the recovery started by the second new ball on the previous evening with Neser striking in the second over of the morning.
Mattie McKiernan edged a defensive push into the gloves of Chris Cooke and Neser continued to cause problems in tandem with Timm van der Gugten.
The runs dried up until a wayward spell by James Harris from the Racecourse End relieved the pressure on Leus du Plooy and Anuj Dal.
Harris leaked 22 runs in four overs and the seventh wicket pair had added 50 before the belated introduction of Hogan broke through.
The 40-year-old found just enough away movement to have Dal taken at first slip and du Plooy followed two overs before lunch when he was lbw shuffling across to the off-spin of Salter.
The game meandered after the interval with Derbyshire adding only eight more runs in seven overs with Suranga Lakmal's attempt to raise the tempo by hitting Salter over the top ending in a well-judged catch by Labuschagne running back at midwicket.
When Neser had Ryan Sidebottom snared at first slip, Derbyshire had lost their last eight wickets for 92 runs which was a disappointing decline on a good batting pitch.
Even so, it was still a total that could put pressure on Glamorgan if they lost early wickets but Lloyd and Salter batted watchfully before accelerating in the afternoon sunshine.
Salter survived a big appeal for a catch behind off Sam Conners but the makeshift opener grew into the role as the pair passed Glamorgan's previous best opening stand this season of 41.
Lloyd drove fluently to reach 50 from 79 balls and Salter swept Alex Thomson's off-spin for four to bring up the century stand in the 26th over.
But a farcical mix-up in the same over gifted Derbyshire a wicket when Salter set off a second run and found himself stranded at the same end as his captain.
Lloyd looked in no mood to throw his wicket away but after driving Conners for three fours in an over, he went for another big drive at Dal and Wayne Madsen held a sharp catch at slip.
Madsen has been one of the best slip fielders on the county circuit but he missed several chances in the previous home game against Sussex and he spilled another catch here to reprieve Northeast.
Conners was the unlucky bowler as Madsen failed to hold on at second slip with Northeast on 5 and the score 126 for 2.
That was proving to be costly as Labuschagne and Northeast added 93 in 22 overs but Madsen responded by beating Northeast's attempted sweep.
Labuschagne drove Madsen over the ropes at long on but Kiran Carlson edged a loose drive at Lakmal to leave the match finely poised