a, Schematic and representative confocal image of CA1 hippocampal PV neurons expressing ChRmine-YFP (white) costained with DAPI (blue). b, Epileptic mice were subjected to 24-h video EEG recordings, where 50% of detected seizures were set to trigger transcranial optogenetic intervention. c, Representative recording of electrographic seizures with no light (gray bar) or with light (red bar) treatment. d-f, Cumulative distribution and (inset) histogram of postdetection seizure duration for PV-targeted (E2-ChRmine) (d) and broader GABAergic-targeted (Dlx5/6-ChRmine) (e) or YFP control animals (f) (N = 1,369/1,267/1,008 seizures, respectively, n = 4 mice per group, Mann-Whitney U test). g, Mean seizure duration with light treatment, normalized to mean seizure duration without light treatment, for ChRmine targeted to PV GABAergic (E2), GABAergic (Dlx5/6) and control (YFP) neurons (n = 4 mice per group; one-way ANOVA with Bonferroni post hoc tests: F(2,9) =23.7, P = 0.0003). h, Schematic of AAVPHP.eB-TPH2::ChRmine-eYFP systemic delivery to target serotonergic neurons in the brainstem. Confocal images depict ChRmine-YFP neurons (white), DAPI (blue) and TPH2 (red) in the raphe. White arrows denote example YFP+/TPH2+ neurons. Scale bar, 100 μm. i, Example path-tracing of a wild-type mouse from two sessions with (ON) and without (OFF) deep transcranial photostimulation during the three-chamber sociability assay. Tracks are color coded for velocity. Light at 635 nm was delivered at 20 Hz and 800 mW mm−2 with 5-ms pulse width over 10-s repeated intervals. j, Ratio of time spent in the chamber containing the juvenile mouse, relative to time spent in the empty chamber, with and without photostimulation for YFP (gray) and ChRmine-YFP (red) mice (n = 8 mice; paired t-test). *P<0.05; **P<0.01; ***P<0.01; ****P<0.0001. Data are mean±s.e.m. Amp, amplifier.