\definecolor{exercicepage}{HTML}{ffffff}
\definecolor{exercicenumbg}{HTML}{b31949}
\definecolor{sectionnn}{HTML}{f24b00}
\definecolor{subsectionnn}{HTML}{c55b0a}
\definecolor{partie}{HTML}{344b7c}
\definecolor{courbe}{HTML}{31769e}
\definecolor{courbe2}{HTML}{d74909}
\definecolor{courbe3}{HTML}{f10b3f}
\definecolor{courbe4}{HTML}{229509}

% Méthode (ligne 13)
% \exercices (ligne 49)
% \sectionnn (ligne 73)
% \subsectionnn (ligne 89)
% \partie (ligne 102)
% \fancypagestyle{exercices} (ligne 115)
% exocor (ligne 129)

%%%%%%%
% Méthode
%%%%%%%%%%%%%%

\newtcbtheorem{tcbmethode}{Methode}
{%
	enhanced,	
	breakable,
	separator sign none,
	before skip = 2mm,
	after skip = 3mm,
	boxrule = 0.4pt,
	left = 2mm,
	right = 2mm,
	top = 1mm,
	bottom = 1mm,
	colback = gray!20,
	colframe = black,
	sharp corners,
	fonttitle = \fontfamily{lmss}\selectfont\bfseries\faCogs~,
	drop fuzzy shadow
}
{methode}

\newenvironment{methode}[1][]
{%
	\itemclass{black}
	\arrayrulecolor{black}
	\begin{tcbmethode}{\if\@empty#1\else(#1)\fi}{}
}
{%
	\end{tcbmethode}
}


%%%%%%%%%%%%%%%%%%%%%%%
% \exercices 
%%%%%%%%%%%%%%%%%%%%%%%

\newcommand\exercices{
	\newpage
	\pagestyle{exercices}
	\begin{tikzpicture}[remember picture,overlay]
		\fill[exercicenumbg!20] (current page.north west) rectangle ($(current page.north east)+(0,-2.5cm)$);
		\fill[exercicenumbg!20,decorate, decoration={zigzag, segment length=4mm, amplitude=0.5mm}] ($(current page.north west)+(0,-2.3cm)$) rectangle ($(current page.north east)+(0,-2.7cm)$);
		% Ellipse rouge en haut à gauche
		\node[fill=exercicenumbg, text=white, ellipse, minimum height=1cm, minimum width=2cm, anchor=north west, scale=4] (num)
			at ([xshift=0cm,yshift=0cm]current page.north west) {\fontfamily{lmss}\fontsize{20}{18}\selectfont \bfseries \thechapter};
			% Titre
			\node[font=\Huge\bfseries\color{exercicenumbg}\fontfamily{lmss}\selectfont, align=right] at ([xshift=2cm,yshift=0cm]num.east) {Exercices};
    \end{tikzpicture}%
	\itemclass{exercicenumbg}
	\arrayrulecolor{exercicenumbg}
	\phantomsection
	\addcontentsline{toc}{section}{\color{exercicenumbg}\fontfamily{lmss}\selectfont\large Exercices}
	\hypersetup{linkcolor=sectioncolor}
	\vspace*{2cm}
	\tcbstartrecording
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Définition de sectionnn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand*\sectionnn[1]{%
\bgroup
\color{sectionnn}
\Large\fontfamily{lmss}\selectfont\bfseries #1
\phantomsection
\addcontentsline{toc}{subsection}{\fontfamily{lmss}\selectfont #1}
\egroup
\bigskip 
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Définition de subsectionnn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand*\subsectionnn[1]{%
\bgroup
\color{subsectionnn}
\large\fontfamily{lmss}\selectfont\bfseries #1
\egroup
\bigskip 
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Définition de partie
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand*\partie[1]{%
\bgroup
\color{partie}
\large\fontfamily{lmss}\selectfont\bfseries Partie #1
\egroup
\bigskip 
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Définition des styles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\fancypagestyle{exercices}
{
	\pagecolor{exercicepage}
	\fancyhf{}
	\fancyfoot[C]{%
		\tikz\node[fill=exercicenumbg,text=white,rectangle,rounded corners=5pt,inner sep=2mm]{\fontfamily{lmss}\bfseries\thepage};%
	}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% exocor 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\AtBeginEnvironment{exocor}{\stepcounter{nb@exos@mathweb}}

\NewTColorBox[auto counter,number within=chapter]{exocor}{mO{0}O{}}{%
    enhanced,
    breakable,
    separator sign none,
    before skip=2mm,
    after skip=2mm,
    colback=exercicepage,
    colframe=exercicepage,
    boxrule=0mm,
	left = 5pt,
	right= 1cm,
    watermark text={\rotatebox{30}{mathweb.fr}},
    title={Exercice \thetcbcounter\ifx\hfuzz#1\hfuzz\else~(#1)\fi\arrayrulecolor{exercicenumbg}},
    label={exercice:\thetcbcounter},
    attach boxed title to top left ={xshift=-10pt, yshift = 0pt},
    boxed title style={
        frame code={
            \fill[color=exercicepage] (frame.north west) rectangle (frame.south east);
        },
        interior engine=empty
    },
	underlay = {
		\draw[exercicenumbg] (frame.south east) -- (frame.south west) -- (frame.north west);
		% Mettre ici le code pour insérer les étoiles
		\ifnum#2>0
			\node[%
				above left,%
				inner sep=2pt,%
				outer sep=0pt,%
				fill=exercicenumbg!30,%
				draw=exercicenumbg,%
				rounded corners=1mm]
				at (frame.north east) {
						\foreach \i in {1,...,#2} {%
							\textcolor{exercicenumbg}{\faStar}%
						}
				};
		\fi	
		\node[inner sep=2pt, outer sep=0pt, text=exercicenumbg, draw=exercicenumbg, rounded corners=1mm] at ([xshift=-8pt,yshift=-5mm]frame.north east) {
            \href{https://mathweb.fr/traitement_erreur.php?livre=\jobname&exercice=\thetcbcounter}{\large\faCommentingO}
        };
	},
    fonttitle=\fontfamily{lmss}\selectfont\bfseries\color{exercicenumbg},
    after upper={\par\hfill\textcolor{exercicenumbg}{\itshape Solution page~\pageref{solution:\thetcbcounter}}},
    lowerbox=ignored,
	watermark zoom=1,
    watermark color=gray,
    watermark opacity=.1,
    clip watermark,
    savelowerto=corriges/exercice-\thetcbcounter.tex,
    record={\string\solution{\thetcbcounter}{corriges/exercice-\thetcbcounter.tex}},
    #3
}