\documentclass[tikz,border=5pt]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta, positioning, calc, backgrounds, fit, shapes.symbols, shadows}

\begin{document}
\begin{tikzpicture}[
    % Node styles
    component/.style={
        rectangle,
        draw=black,
        line width=1pt,
        minimum width=2.2cm,
        minimum height=0.8cm,
        text centered,
        rounded corners=3pt,
        fill=white,
        font=\small
    },
    qbox/.style={
        rectangle,
        draw=black,
        line width=1pt,
        minimum width=1.5cm,
        minimum height=0.8cm,
        text centered,
        rounded corners=2pt,
        fill=white,
        font=\small
    },
    poolbox/.style={
        rectangle,
        draw=black,
        line width=1pt,
        minimum width=2.5cm,
        minimum height=1.2cm,
        text centered,
        fill=white,
        font=\small,
        rounded corners=5pt
    },
    arrow/.style={
        ->,
        >=Stealth,
        line width=1.2pt
    },
    labeltext/.style={
        font=\footnotesize,
        text centered
    },
    section/.style={
        rectangle,
        rounded corners=10pt,
        minimum height=5cm,
        draw=none,
        inner sep=4pt,
        drop shadow
    }
]

% ==========================================
% EXPERIENCE REPLAY SECTION (Left)
% ==========================================
\node[component] (env) at (0,0) {Environment};
\node[poolbox, below=2.7cm of env] (pool) {Experience Replay Buffer};
% Arrows for experience replay
\draw[arrow] (env.south) -- (pool.north) node[midway, right, font=\scriptsize, align=center] {Sample\\[4pt]$s^t, a^t, r^t, s^{t+1}$};

% ==========================================
% ACTOR NETWORKS SECTION (Middle)
% ==========================================
\node[component, right=3cm of env] (actor) {Actor};
\node[qbox, right=0.6cm of actor] (policy) {$\pi(\phi)$};
\node[component, below=2.835cm of actor] (target_actor) {Target\_Actor};
\node[qbox, below=2.835cm of policy] (target_policy) {$\pi(\phi')$};

% Dashed boxes around actor groups
\node[draw, dashed, blue!50, thick, fit=(actor)(target_actor), inner sep=4pt](actorDash) {};
\node[draw, dashed, blue!50, thick, fit=(policy)(target_policy), inner sep=4pt](policyDash) {};

% Soft update arrow
\draw[arrow, ->, blue!55, thick] (actor.south) -- (target_actor.north) node[midway, right, font=\scriptsize] {soft\_update};

% ==========================================
% CRITIC NETWORKS SECTION (Right)
% ==========================================
\node[component, right=4cm of actor, yshift=0] (critic1) {Critic1};
\node[qbox, right=0.6cm of critic1] (q1) {$Q_{\theta_1}$};
\node[qbox, right=0.6cm of q1] (td1) {TD-error1};

\node[component, below=0.8cm of critic1] (critic2) {Critic2};
\node[qbox, right=0.6cm of critic2] (q2) {$Q_{\theta_2}$};
\node[qbox, right=0.6cm of q2] (td2) {TD-error2};

\node[component, below=1.2cm of critic2] (target_c1) {Target\_Critic1};
\node[qbox, right=0.6cm of target_c1] (tq1) {$Q_{\theta_1'}$};

\node[component, below=0.8cm of target_c1] (target_c2) {Target\_Critic2};
\node[qbox, right=0.6cm of target_c2] (tq2) {$Q_{\theta_2'}$};


% Dashed boxes around critic groups
\node[draw, dashed, red!50, thick, fit=(critic1)(critic2), inner sep=4pt](criticDash) {};
\node[draw, dashed, red!50, thick, fit=(td1)(td2), inner sep=4pt](tdDash) {};

% Dashed boxes around target critic groups
\node[draw, dashed, red!50, thick, fit=(target_c1)(target_c2), inner sep=4pt](targetCriticDash) {};
\node[draw, dashed, red!50, thick, fit=(tq1)(tq2), inner sep=4pt](tqDash) {};

% Soft update arrow
\draw[arrow, ->, red!50, thick] ([xshift=-10pt]criticDash.south) -- ([xshift=-10pt]targetCriticDash.north) node[midway, left, font=\scriptsize] {soft\_update};

% Min operation and Q_target
\node[qbox, right=1cm of tqDash] (qtarget) {$Q_{\text{target}}$};



% ==========================================
% ARROWS BETWEEN SECTIONS
% ==========================================

% Environment to Actor
\draw[arrow] ([yshift=4pt]env.east) -- ([yshift=56pt]actorDash.west)
node[midway, above, font=\scriptsize] {$s^t$};
\draw[arrow] ([yshift=48pt]actorDash.west) -- ([yshift=-4pt]env.east)
node[midway, below, font=\scriptsize] {$a^t$};

% Experience pool to networks
\draw[arrow] (pool.east) -- ([yshift=-54pt]actorDash.west) node[midway, above, font=\scriptsize, align=center] {$s^t, s^{t+1}$};
\draw[arrow] 
  (pool.south) -- ($(pool.south)+(0,-1)$) -- ([yshift=-25pt, xshift=-7.5pt]targetCriticDash.west)
  node[midway, below=2pt, font=\scriptsize, align=center] {$s^t,a^t,r^t,s^{t+1}$};
  
% Actor to Policy
\draw[arrow] (actor.east) -- (policy.west);

% Target Actor to Target Policy
\draw[arrow] (target_actor.east) -- (target_policy.west);

% Actor to Critic
\draw[arrow] (policy.east) -- ([yshift=23.25pt]criticDash.west);

% Target Actor to Target Critics  
\draw[arrow] (target_policy.east) -- ([yshift=23pt]targetCriticDash.west)node[midway, above, font=\scriptsize] {$a^{t+1}$};

% Critic internal flows
\draw[arrow] (critic1.east) -- (q1.west);
\draw[arrow] (q1.east) -- (td1.west);
\draw[arrow] (critic2.east) -- (q2.west);
\draw[arrow] (q2.east) -- (td2.west);

% Target Critic flows
\draw[arrow] (target_c1.east) -- (tq1.west);
\draw[arrow] (target_c2.east) -- (tq2.west);

% Min operation
\draw[arrow] (tqDash.east) -- (qtarget.west)node[midway, above, font=\scriptsize] {min} ;

% Target value equation
\draw[arrow] (qtarget.north) -- ([xshift=14pt]tdDash.south)node[midway, left, font=\scriptsize, yshift=7pt] {$y = r + \gamma Q_{\text{target}}$};

% Optimize feedback arrows
\draw[arrow, red!55, thick] (td1.north) -- ($(td1.north)+(0,0.4)$) -- node[midway, below, font=\scriptsize, align=center](optimize1) {optimize}($(critic1.north)+(0,0.4)$) --(critic1.north);

\draw[arrow, red!55, thick] (td2.south) -- ($(td2.south)+(0,-0.5)$) -- node[midway, above, font=\scriptsize, align=center](optimize2) {optimize}($(critic2.south)+(0,-0.5)$) --(critic2.south);

% ==========================================
% COLORED BACKGROUND SECTIONS
% ==========================================
\begin{scope}[on background layer]
    
\node (Envtopspace) at ($(env.north)!0.5!(env.north)+(0,0.90)$) {};
\node (Envbottomspace) at ($(pool.south)!0.5!(pool.south)+(0,-1.5)$) {};
\node (Actortopspace) at ($(actorDash.north)!0.5!(actorDash.north)+(0,0.75)$) {};
\node (Actorbottomspace) at ($(actorDash.south)!0.5!(actorDash.south)+(0,-0.2)$) {};
\node (Critictopspace) at ($(optimize1.north)!0.5!(optimize1.north)+(0,0.5)$) {};
\node (Criticbottomspace) at ($(tqDash.south)!0.5!(tqDash.south)+(0,0)$) {};
\node (CriticLeftspace) at ($(targetCriticDash.west)!0.5!(targetCriticDash.west)+(0,0)$) {};

% Experience Replay (Yellow)
\node(ExperienceBufferBox)[
    section,
    fill=yellow!20,
    fit=(env)(pool)(Envtopspace)(Envbottomspace),
    ] {};
\node[
    font=\bfseries\color{orange!80},
    anchor=north,
    yshift=-1pt
] at (ExperienceBufferBox.north) {Experience replay};
    
    % Actor Networks (Blue)
\node (actorbox) [
    section,
    fill=blue!15,
    fit=(actor)(policy)(target_actor)(target_policy)
        (actorDash)(policyDash)(Actortopspace)(Actorbottomspace)
] {};

\node[
    font=\bfseries\color{blue!80},
    anchor=north,
    yshift=-1pt
] at (actorbox.north) {Actor networks};
    
    % Critic Networks (Red/Pink)
    \node[section, fill=red!15, fit=(critic1)(td1)(critic2)(td2)
    (target_c1)(target_c2)(qtarget)
    (Critictopspace)(Criticbottomspace)
    (optimize1)(criticDash)(tdDash)
    (targetCriticDash)(tqDash)(CriticLeftspace),
          xshift=0cm, yshift=0cm,
          label={[yshift=-15pt]north:\textcolor{red!80}{\textbf{Critic networks}}}] {};
\end{scope}

\end{tikzpicture}
\end{document}