% =============================================================================
% dag-mediation.tex — Mediation DAG: X → M → Y with direct path X → Y
%
% Shows: treatment X affects outcome Y both indirectly (via mediator M) and
% directly. Direct path rendered as a bent arrow below to avoid colliding
% with the indirect path through M.
%
% Compiles standalone via: xelatex dag-mediation.tex
% =============================================================================

\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}

\definecolor{node-fill}{HTML}{E8EDF5}
\definecolor{node-border}{HTML}{012169}
\definecolor{arrow}{HTML}{1A1A1A}
\definecolor{direct}{HTML}{B23A48}

\tikzset{
  dag-node/.style={
    draw=node-border, fill=node-fill, rounded corners=2pt,
    minimum width=1.2cm, minimum height=0.9cm, align=center, font=\small
  },
  dag-edge/.style={-{Latex[length=2.5mm]}, thick, draw=arrow},
  direct-edge/.style={-{Latex[length=2.5mm]}, thick, draw=direct}
}

% -----------------------------------------------------------------------------
% Diagram: X → M → Y mediation path; direct effect X → Y bent below.
% Coordinates:
%   X at (0, 0)    -- treatment, left
%   M at (3, 1.6)  -- mediator, top center
%   Y at (6, 0)    -- outcome, right
% Bend angle 25° on direct path; chord X-Y = 6cm.
%   Bézier max depth = 3.0 × tan(12.5°) ≈ 3.0 × 0.222 = 0.67cm below baseline.
%   Safe distance = 0.67 + 0.5 = 1.17cm. Label "direct" sits at y ≈ -1.3 ✓.
% -----------------------------------------------------------------------------

\begin{document}
\begin{tikzpicture}
  \node[dag-node] (X) at (0, 0)    {$X$};
  \node[dag-node] (M) at (3, 1.6)  {$M$};
  \node[dag-node] (Y) at (6, 0)    {$Y$};

  \draw[dag-edge]    (X) -- (M) node[midway, above left]  {\small $a$};
  \draw[dag-edge]    (M) -- (Y) node[midway, above right] {\small $b$};
  \draw[direct-edge] (X) to[bend right=25] node[midway, below=0.55cm] {\small $c'$ (direct)} (Y);
\end{tikzpicture}
\end{document}
