\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[most]{tcolorbox}
\usepackage{emoji}
\usepackage{chessfss}
\usepackage{xcolor}

\definecolor{BlogCalloutNoteBack}{HTML}{FFF8D7}
\definecolor{BlogCalloutNoteFrame}{HTML}{D4A72C}
\definecolor{BlogCalloutTipBack}{HTML}{E7F6EC}
\definecolor{BlogCalloutTipFrame}{HTML}{3A8F64}
\definecolor{BlogCalloutWarningBack}{HTML}{FFF0E5}
\definecolor{BlogCalloutWarningFrame}{HTML}{C4662D}
\definecolor{BlogCalloutCautionBack}{HTML}{FDECEC}
\definecolor{BlogCalloutCautionFrame}{HTML}{B94A48}
\definecolor{BlogCalloutAsideBack}{HTML}{EEF3FA}
\definecolor{BlogCalloutAsideFrame}{HTML}{5D7FA3}

\tcbset{
  blog callout/.style={
    enhanced,
    breakable,
    boxrule=0.45pt,
    leftrule=2.2pt,
    arc=1.6mm,
    outer arc=1.6mm,
    left=7pt,
    right=7pt,
    top=6pt,
    bottom=6pt,
    before skip=10pt,
    after skip=10pt,
    fonttitle=\bfseries\sffamily\small,
    coltitle=black,
    attach boxed title to top left={xshift=7pt,yshift=-2.4mm},
    boxed title style={
      enhanced,
      boxrule=0pt,
      arc=1.2mm,
      left=5pt,
      right=5pt,
      top=2pt,
      bottom=2pt
    }
  }
}

\NewDocumentEnvironment{blognotebox}{O{} m}{%
  \if\relax\detokenize{#2}\relax
    \begin{tcolorbox}[
      blog callout,
      colback=BlogCalloutNoteBack,
      colframe=BlogCalloutNoteFrame,
      boxed title style={colback=BlogCalloutNoteBack},
      #1
    ]%
  \else
    \begin{tcolorbox}[
      blog callout,
      title={#2},
      colback=BlogCalloutNoteBack,
      colframe=BlogCalloutNoteFrame,
      boxed title style={colback=BlogCalloutNoteBack},
      #1
    ]%
  \fi
}{%
  \end{tcolorbox}%
}

\NewDocumentEnvironment{blogtipbox}{O{} m}{%
  \if\relax\detokenize{#2}\relax
    \begin{tcolorbox}[
      blog callout,
      colback=BlogCalloutTipBack,
      colframe=BlogCalloutTipFrame,
      boxed title style={colback=BlogCalloutTipBack},
      #1
    ]%
  \else
    \begin{tcolorbox}[
      blog callout,
      title={#2},
      colback=BlogCalloutTipBack,
      colframe=BlogCalloutTipFrame,
      boxed title style={colback=BlogCalloutTipBack},
      #1
    ]%
  \fi
}{%
  \end{tcolorbox}%
}

\NewDocumentEnvironment{blogwarningbox}{O{} m}{%
  \if\relax\detokenize{#2}\relax
    \begin{tcolorbox}[
      blog callout,
      colback=BlogCalloutWarningBack,
      colframe=BlogCalloutWarningFrame,
      boxed title style={colback=BlogCalloutWarningBack},
      #1
    ]%
  \else
    \begin{tcolorbox}[
      blog callout,
      title={#2},
      colback=BlogCalloutWarningBack,
      colframe=BlogCalloutWarningFrame,
      boxed title style={colback=BlogCalloutWarningBack},
      #1
    ]%
  \fi
}{%
  \end{tcolorbox}%
}

\NewDocumentEnvironment{blogcautionbox}{O{} m}{%
  \if\relax\detokenize{#2}\relax
    \begin{tcolorbox}[
      blog callout,
      colback=BlogCalloutCautionBack,
      colframe=BlogCalloutCautionFrame,
      boxed title style={colback=BlogCalloutCautionBack},
      #1
    ]%
  \else
    \begin{tcolorbox}[
      blog callout,
      title={#2},
      colback=BlogCalloutCautionBack,
      colframe=BlogCalloutCautionFrame,
      boxed title style={colback=BlogCalloutCautionBack},
      #1
    ]%
  \fi
}{%
  \end{tcolorbox}%
}

\NewDocumentEnvironment{blogasidebox}{O{} m}{%
  \if\relax\detokenize{#2}\relax
    \begin{tcolorbox}[
      blog callout,
      colback=BlogCalloutAsideBack,
      colframe=BlogCalloutAsideFrame,
      boxed title style={colback=BlogCalloutAsideBack},
      #1
    ]%
  \else
    \begin{tcolorbox}[
      blog callout,
      title={#2},
      colback=BlogCalloutAsideBack,
      colframe=BlogCalloutAsideFrame,
      boxed title style={colback=BlogCalloutAsideBack},
      #1
    ]%
  \fi
}{%
  \end{tcolorbox}%
}

\ExplSyntaxOn
\NewDocumentCommand{\BlogEmojiText}{m}{{\emoji_font: #1}}
\ExplSyntaxOff

\newcommand{\BlogChessWhite}[1]{\textcolor{black!55}{#1}}
\newcommand{\BlogChessBlack}[1]{\textcolor{black}{#1}}
\newcommand{\BlogCardRed}[1]{\textcolor{red!65!black}{#1}}
\newcommand{\BlogCardBlack}[1]{\textcolor{black}{#1}}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

\newcommand{\SemanticLoadCleveref}{%
  \usepackage{cleveref}%
  \crefname{theorem}{theorem}{theorems}%
  \Crefname{theorem}{Theorem}{Theorems}%
  \crefname{lemma}{lemma}{lemmas}%
  \Crefname{lemma}{Lemma}{Lemmas}%
  \crefname{proposition}{proposition}{propositions}%
  \Crefname{proposition}{Proposition}{Propositions}%
  \crefname{corollary}{corollary}{corollaries}%
  \Crefname{corollary}{Corollary}{Corollaries}%
  \crefname{definition}{definition}{definitions}%
  \Crefname{definition}{Definition}{Definitions}%
  \crefname{example}{example}{examples}%
  \Crefname{example}{Example}{Examples}%
  \crefname{remark}{remark}{remarks}%
  \Crefname{remark}{Remark}{Remarks}%
  \crefname{figure}{figure}{figures}%
  \Crefname{figure}{Figure}{Figures}%
}

\makeatletter
\@ifpackageloaded{hyperref}{%
  \SemanticLoadCleveref
}{%
  \AddToHook{package/hyperref/after}{\SemanticLoadCleveref}%
}
\makeatother
