

% ── Page geometry ──────────────────────────────────────────────────────────────
\usepackage[margin=1in]{geometry}

% ── Fonts & encoding ───────────────────────────────────────────────────────────
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{microtype}

% ── Math ───────────────────────────────────────────────────────────────────────
\usepackage{amsmath, amssymb, amsthm, amsfonts}
\usepackage{mathtools}
\usepackage{mathrsfs}
\usepackage{nicefrac}
\usepackage{xfrac}
\usepackage{cancel}

% ── Theorem environments ───────────────────────────────────────────────────────
\usepackage{thmtools}
\usepackage[framemethod=TikZ]{mdframed}

% ── Colors ─────────────────────────────────────────────────────────────────────
\usepackage[dvipsnames]{xcolor}

% ── Graphics & figures ─────────────────────────────────────────────────────────
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

% ── Tables ─────────────────────────────────────────────────────────────────────
\usepackage{booktabs}
\usepackage{array}
\usepackage{multirow}

% ── Layout & formatting ────────────────────────────────────────────────────────
\usepackage{enumerate}
\usepackage{ragged2e}
\usepackage{titlesec}
\usepackage{fancyhdr}
\usepackage{appendix}
\usepackage{comment}
\usepackage{import}
\usepackage{todonotes}

% ── Algorithms ─────────────────────────────────────────────────────────────────
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{varwidth}

% ── References & links ─────────────────────────────────────────────────────────
\usepackage[hidelinks]{hyperref}
\usepackage{url}
\usepackage{cite}
\usepackage[capitalize]{cleveref}

% ── Misc ───────────────────────────────────────────────────────────────────────
\usepackage{svg}

\titleformat{\subsubsection}[runin]
  {\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}

\numberwithin{equation}{section}

% ==============================================================================
%  Theorem styles  (thmtools + mdframed)
% ==============================================================================

%% ── Blue box — Theorem ────────────────────────────────────────────────────────
\newcommand{\envLineWidth}{1.5pt}

\mdfdefinestyle{mdbluebox}{
  roundcorner=6pt, linewidth=\envLineWidth,
  skipabove=10pt, skipbelow=4pt,
  innertopmargin=6pt, innerbottommargin=8pt,
  innerleftmargin=8pt, innerrightmargin=8pt,
  linecolor=Blue!80, backgroundcolor=blue!5, nobreak=false,
}
\declaretheoremstyle[
  headfont=\bfseries\sffamily\color{Blue!80},
  bodyfont=\slshape,
  mdframed={style=mdbluebox},
  headpunct={\\[3pt]}, postheadspace=0pt,
]{thmbluebox}

%% ── Red box — Definition ──────────────────────────────────────────────────────
\mdfdefinestyle{mdredbox}{
  roundcorner=6pt, linewidth=\envLineWidth,
  skipabove=10pt, skipbelow=4pt,
  innertopmargin=6pt, innerbottommargin=8pt,
  innerleftmargin=8pt, innerrightmargin=8pt,
  linecolor=BrickRed, backgroundcolor=red!5, nobreak=false,
}
\declaretheoremstyle[
  headfont=\bfseries\sffamily\color{BrickRed},
  bodyfont=\slshape,
  mdframed={style=mdredbox},
  headpunct={\\[3pt]}, postheadspace=0pt,
]{thmredbox}

%% ── Magenta box — Proposition ─────────────────────────────────────────────────
\mdfdefinestyle{mdmagentabox}{
  roundcorner=6pt, linewidth=\envLineWidth,
  skipabove=10pt, skipbelow=4pt,
  innertopmargin=6pt, innerbottommargin=8pt,
  innerleftmargin=8pt, innerrightmargin=8pt,
  linecolor=Fuchsia, backgroundcolor=RedViolet!5, nobreak=false,
}
\declaretheoremstyle[
  headfont=\bfseries\sffamily\color{Fuchsia!100},
  bodyfont=\slshape,
  mdframed={style=mdmagentabox},
  headpunct={\\[3pt]}, postheadspace=0pt,
]{thmmagentabox}

%% ── Orange box — Lemma ────────────────────────────────────────────────────────
\mdfdefinestyle{mdorangebox}{
  roundcorner=6pt, linewidth=\envLineWidth,
  skipabove=10pt, skipbelow=4pt,
  innertopmargin=6pt, innerbottommargin=8pt,
  innerleftmargin=8pt, innerrightmargin=8pt,
  linecolor=Bittersweet, backgroundcolor=RedOrange!5, nobreak=false,
}
\declaretheoremstyle[
  headfont=\bfseries\sffamily\color{Bittersweet},
  bodyfont=\slshape,
  mdframed={style=mdorangebox},
  headpunct={\\[3pt]}, postheadspace=0pt,
]{thmorangebox}

%% ── Cyan box — Corollary ──────────────────────────────────────────────────────
\mdfdefinestyle{mdcyanbox}{
  roundcorner=6pt, linewidth=\envLineWidth,
  skipabove=10pt, skipbelow=4pt,
  innertopmargin=6pt, innerbottommargin=8pt,
  innerleftmargin=8pt, innerrightmargin=8pt,
  linecolor=Periwinkle, backgroundcolor=cyan!5, nobreak=false,
}
\declaretheoremstyle[
  headfont=\bfseries\sffamily\color{Periwinkle},
  bodyfont=\slshape,
  mdframed={style=mdcyanbox},
  headpunct={\\[3pt]}, postheadspace=0pt,
]{thmcyanbox}

%% ── Green box — Remark ────────────────────────────────────────────────────────
\mdfdefinestyle{mdgreenbox}{
  roundcorner=6pt, linewidth=\envLineWidth,
  skipabove=10pt, skipbelow=4pt,
  innertopmargin=6pt, innerbottommargin=8pt,
  innerleftmargin=8pt, innerrightmargin=8pt,
  linecolor=OliveGreen, backgroundcolor=green!3, nobreak=false,
}
\declaretheoremstyle[
  headfont=\bfseries\sffamily\color{OliveGreen},
  bodyfont=\slshape,
  mdframed={style=mdgreenbox},
  headpunct={\\[3pt]}, postheadspace=0pt,
]{thmgreenbox}

%% ── Gray box — Problem ────────────────────────────────────────────────────────
\mdfdefinestyle{mdgraybox}{
  roundcorner=6pt, linewidth=\envLineWidth,
  skipabove=10pt, skipbelow=4pt,
  innertopmargin=6pt, innerbottommargin=8pt,
  innerleftmargin=8pt, innerrightmargin=8pt,
  linecolor=black, backgroundcolor=black!5, nobreak=false,
}
\declaretheoremstyle[
  headfont=\bfseries\sffamily\color{black!90},
  bodyfont=\slshape,
  mdframed={style=mdgraybox},
  headpunct={\\[3pt]}, postheadspace=0pt,
]{thmgraybox}

%% ── Yellow box — Algorithm ────────────────────────────────────────────────────
\mdfdefinestyle{mdyellowbox}{
  roundcorner=6pt, linewidth=\envLineWidth,
  skipabove=10pt, skipbelow=4pt,
  innertopmargin=6pt, innerbottommargin=8pt,
  innerleftmargin=8pt, innerrightmargin=8pt,
  linecolor=YellowOrange, backgroundcolor=yellow!4, nobreak=false,
}
\declaretheoremstyle[
  headfont=\bfseries\sffamily\color{YellowOrange},
  bodyfont=\slshape,
  mdframed={style=mdyellowbox},
  headpunct={\\[3pt]}, postheadspace=0pt,
]{thmyellowbox}

%% ── Pink box — Example ────────────────────────────────────────────────────────
\mdfdefinestyle{mdpinkbox}{
  roundcorner=6pt, linewidth=\envLineWidth,
  skipabove=10pt, skipbelow=4pt,
  innertopmargin=6pt, innerbottommargin=8pt,
  innerleftmargin=8pt, innerrightmargin=8pt,
  linecolor=WildStrawberry, backgroundcolor=CarnationPink!5, nobreak=false,
}
\declaretheoremstyle[
  headfont=\bfseries\sffamily\color{WildStrawberry},
  bodyfont=\slshape,
  mdframed={style=mdpinkbox},
  headpunct={\\[3pt]}, postheadspace=0pt,
]{thmpinkbox}

%% ── Violet box — Assumption ───────────────────────────────────────────────────
\mdfdefinestyle{mdvioletbox}{
  roundcorner=6pt, linewidth=\envLineWidth,
  skipabove=10pt, skipbelow=4pt,
  innertopmargin=6pt, innerbottommargin=8pt,
  innerleftmargin=8pt, innerrightmargin=8pt,
  linecolor=Brown, backgroundcolor=Brown!5, nobreak=false,
}
\declaretheoremstyle[
  headfont=\bfseries\sffamily\color{Brown},
  bodyfont=\slshape,
  mdframed={style=mdvioletbox},
  headpunct={\\[3pt]}, postheadspace=0pt,
]{thmvioletbox}

%% ── Declare all environments ──────────────────────────────────────────────────
\declaretheorem[style=thmbluebox,    name=Theorem,     numberwithin=section]{theorem}
\declaretheorem[style=thmredbox,     name=Definition,  numberwithin=section]{definition}
\declaretheorem[style=thmmagentabox, name=Proposition, numberwithin=section]{proposition}
\declaretheorem[style=thmorangebox,  name=Lemma,       numberwithin=section]{lemma}
\declaretheorem[style=thmcyanbox,    name=Corollary,   numberwithin=section]{corollary}
\declaretheorem[style=thmgreenbox,   name=Remark,      numberwithin=section]{remark}
\declaretheorem[style=thmgraybox,    name=Problem,     numberwithin=section]{problem}
\declaretheorem[style=thmyellowbox,  name=Algorithm,   numberwithin=section]{algo}
\declaretheorem[style=thmpinkbox,    name=Example,     numberwithin=section]{example}
\declaretheorem[style=thmvioletbox,  name=Assumption,  numberwithin=section]{assumption}

% ==============================================================================
%  Math macros
% ==============================================================================
\newcommand{\tr}{\mathrm{Tr}}
\newcommand{\vect}{\mathbf{vec}}
\newcommand{\cI}{\mathcal{I}}
\newcommand{\cX}{\mathcal{X}}
\newcommand{\cB}{\mathcal{B}}
\newcommand{\F}{\mathbb{F}}
\newcommand{\bcdot}{\ {\bf \cdot} \ }
\newcommand{\cE}{\mathcal{E}}
\newcommand{\norm}[1]{\left\| #1 \right\|}
\newcommand{\opnorm}[1]{\norm{#1}_{\mathrm{op}}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Lcal}{\mathcal{L}}
\newcommand{\Fscr}{\mathscr{F}}
\newcommand{\Holder}{H\"older }
\newcommand{\inner}[2]{\left\langle {#1}, {#2} \right\rangle}
\newcommand{\Dim}{\text{dim }}
\newcommand{\spann}{\text{span}}
\newcommand{\im}{\text{Im }}
\newcommand{\gph}{{\rm gph}\,}
\newcommand{\diag}{{\rm diag}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\cA}{\mathcal{A}}
\newcommand{\cU}{\mathcal{U}}
\newcommand{\cS}{\mathcal{S}}
\newcommand{\EE}{\mathbb{E}}
\newcommand{\trace}{\mathrm{Tr}}
\newcommand{\sign}{\mathrm{sign}}
\newcommand{\lip}{\mathrm{lip}}
\newcommand{\var}{\mathrm{var}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\rank}{\mathrm{rank}}
\newcommand{\supp}{{\mathrm{supp}}}
\newcommand{\op}{\mathrm{op}}
\newcommand{\abs}[1]{\left| #1 \right|}
\newcommand{\eps}{\varepsilon}
% Convex analysis
\newcommand{\prox}{\text{prox}}
\newcommand{\proj}{\mathrm{proj}}
\newcommand{\dom}[1]{\mathrm{dom}(#1)}
\newcommand{\epi}{\text{epi }}
\newcommand{\hypo}{\text{hypo }}
\newcommand{\interior}{\text{int }}
\newcommand{\bdry}{\text{bdy }}
\newcommand{\relint}{\text{ri }}
\newcommand{\argmin}{\operatornamewithlimits{argmin}}
\newcommand{\mini}{\operatornamewithlimits{minimize}}
\newcommand{\ls}{\operatornamewithlimits{limsup}}
\newcommand{\Diag}{{\rm Diag}}
\newcommand{\argmax}{\operatornamewithlimits{argmax}}
\newcommand{\NN}{\mathbb{N}}
\newcommand{\St}{{\mathrm{subject~to}}}
% Probability
\newcommand{\Expect}{\mathbb{E}}
\newcommand{\Prob}[1]{\mathbb{P}\left( #1 \right)}
\newcommand{\Expec}[1]{\mathbb{E}\left( #1 \right)}
\newcommand{\matrx}[1]{\begin{bmatrix} #1 \end{bmatrix}}
% Misc
\newcommand{\bvec}[1]{{\bf #1}}
\newcommand{\dist}{\mathrm{\bf dist}}

\newcommand{\solution}[1]{
    \vspace{0.2cm}
    \noindent\underline{\textit{Solution:}}\\
    \noindent{\color{red} #1}\\ \\
}
\newcommand{\question}[1]{
    \fbox{\parbox{\dimexpr\linewidth-4\fboxsep-2\fboxrule}{\small #1}}
}

% ── Header / footer ────────────────────────────────────────────────────────────
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{\small CLASS NAME}
\lhead{\small SECTION}
\cfoot{\thepage}

\setlength{\fboxrule}{1.2pt}
\setlength{\fboxsep}{2pt}
