% \iffalse meta-comment -------------------------------------------------------
% Copyright 2015 Matthias Vogelgesang and the LaTeX community. A full list of
% contributors can be found at
%
%     https://github.com/matze/mtheme/graphs/contributors
%
% and the original template was based on the HSRM theme by Benjamin Weiss.
%
% This work is licensed under a Creative Commons Attribution-ShareAlike 4.0
% International License (https://creativecommons.org/licenses/by-sa/4.0/).
%% --------------------------------------------------------------------------- 
%% Copyright 2024 Johan Larsson and contributors
% ------------------------------------------------------------------------- \fi
% \iffalse
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamercolorthememoloch}[2025-12-05 v2.0.0 Moloch color theme]
%</package>
% \fi
% \CheckSum{0}
% \StopEventually{}
% \iffalse
%<*package>
% ------------------------------------------------------------------------- \fi
%
% \subsection{Moloch Color Theme}
%
%
%
% \subsubsection{Package Dependencies}
%    \begin{macrocode}
\RequirePackage{pgfopts}
%    \end{macrocode}
%
%
%
% \subsubsection{Options}
%
% \begin{macro}{block}
%    Optionally adds a light grey background to block environments like
%    \verb|theorem| and \verb|example|.
%    \begin{macrocode}
\pgfkeys{
  /moloch/color/block/.cd,
  .is choice,
  transparent/.code=\moloch@block@transparent,
  fill/.code=\moloch@block@fill,
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{Variant tracking}
%    Boolean to track whether we're in dark or light variant.
%    \begin{macrocode}
\newif\ifmoloch@variant@dark
\moloch@variant@darkfalse  % Default to light variant
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{colors}
%    Provides the option to have a dark background and light foreground instead
%    of the reverse.
%    \begin{macrocode}
\pgfkeys{
  /moloch/color/background/.cd,
  .is choice,
  dark/.code={%
      \PackageWarning{beamercolorthememoloch}{%
        Option 'background' is deprecated.\MessageBreak
        Use 'colortheme variant=light/dark' instead
      }%
      \moloch@colors@dark
    },
  light/.code={%
      \moloch@colors@light
    },
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\moloch@color@setdefaults}
%    Sets default values for color theme options.
%    \begin{macrocode}
\newcommand{\moloch@color@setdefaults}{
  \pgfkeys{/moloch/color/.cd,
    background=light,
  }
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Base Colors}
%
% These are the base colors used in the default Moloch color theme.
% They are kept here mostly for backwards compatibility, and colors
% for the themes are now defined in the preset commands below.
%
%    \begin{macrocode}
\definecolor{mDarkBrown}{HTML}{604c38}
\definecolor{mDarkTeal}{HTML}{23373b}
\definecolor{mLightBrown}{HTML}{EB811B}
\definecolor{mLightGreen}{RGB}{0,128,128}
%    \end{macrocode}
%
% \subsubsection{Hooks for Color Themes}
%
% Moloch color themes can register light and dark color schemes using the
% commands below. The registered colors will be stored in the macros
% \verb|\moloch@define@light@colors| and \verb|\moloch@define@dark@colors| respectively.
% These macros are invoked when the \verb|variant=light| or \verb|variant=dark|
% options are selected, allowing theme presets to define complete color schemes
% for both variants.
%
% \begin{macro}{\moloch@define@light@colors}
% \begin{macro}{\moloch@define@dark@colors}
%    Storage macros for the light and dark color definitions. Initialized
%    empty and filled by color theme presets via the registration commands.
%    \begin{macrocode}
\newcommand{\moloch@define@light@colors}{}
\newcommand{\moloch@define@dark@colors}{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\moloch@register@light@colors}
%    Allows color theme presets to register their light variant color scheme.
%    The argument should contain \verb|\setbeamercolor| commands that define
%    all necessary colors for the light variant.
%    \begin{macrocode}
\newcommand{\moloch@register@light@colors}[1]{%
  \renewcommand{\moloch@define@light@colors}{#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\moloch@register@dark@colors}
%    Allows color theme presets to register their dark variant color scheme.
%    The argument should contain \verb|\setbeamercolor| commands that define
%    all necessary colors for the dark variant.
%    \begin{macrocode}
\newcommand{\moloch@register@dark@colors}[1]{%
  \renewcommand{\moloch@define@dark@colors}{#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\moloch@setup@block@colors}
%    Configures the colors for block environments to derive from normal text
%    and alerted/example text colors. This is called after switching variants
%    to ensure block colors stay consistent with the current color scheme.
%    Block titles inherit from normal text foreground, while alerted and
%    example block titles additionally use their respective text colors.
%    \begin{macrocode}
\newcommand{\moloch@setup@block@colors}{%
  \setbeamercolor{block title}{%
    use=normal text,
    fg=normal text.fg,
    bg=
  }%
  \setbeamercolor{block title alerted}{%
    use={block title, alerted text}
  }%
  \setbeamercolor{block title example}{%
    use={block title, example text}
  }%
  \setbeamercolor{block body alerted}{use=block body, parent=block body}%
  \setbeamercolor{block body example}{use=block body, parent=block body}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\moloch@setup@text@colors}
%    Configures title-related colors to derive from normal text. This ensures
%    that when normal text color changes (e.g., during variant switching),
%    all title elements automatically adapt. Institute and thanks use a
%    slightly muted version (80\% mix) for visual hierarchy.
%    \begin{macrocode}
\newcommand{\moloch@setup@text@colors}{%
  \setbeamercolor{titlelike}{use=normal text, parent=normal text}%
  \setbeamercolor{author}{use=normal text, parent=normal text}%
  \setbeamercolor{date}{use=normal text, parent=normal text}%
  \setbeamercolor{institute}{%
    use=normal text, fg=normal text.fg!80!normal text.bg}%
  \setbeamercolor{structure}{use=normal text, fg=normal text.fg}%
  \setbeamercolor{thanks}{%
    use=normal text,fg=normal text.fg!80!normal text.bg}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\moloch@setup@progressbar@parents}
%    Updates colors that derive from the progress bar color. This includes
%    the title separator (horizontal rule on title page) and progress bars
%    in various locations (head, foot, section pages). Called whenever the
%    progress bar foreground or background color is customized.
%    \begin{macrocode}
\newcommand{\moloch@setup@progressbar@parents}{%
  \setbeamercolor{progress bar in head/foot}{%
    use=progress bar,
    parent=progress bar
  }%
  \setbeamercolor{progress bar in section page}{%
    use=progress bar,
    parent=progress bar
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Variant Switching Commands}
%
% \begin{macro}{\moloch@colors@dark}
%    Switches to the dark variant color scheme. This command:
%    \begin{enumerate}
%    \item Sets the dark variant flag
%    \item Applies the registered dark colors from the current theme preset
%    \item Ensures normal text color is active
%    \item Updates dependent colors (blocks, text) to match
%    \item Applies any stored user customizations for the dark variant
%    \end{enumerate}
%    \begin{macrocode}
\newcommand{\moloch@colors@dark}{
  \moloch@variant@darktrue
  \moloch@define@dark@colors
  \usebeamercolor[fg]{normal text}

  \moloch@setup@block@colors
  \moloch@setup@text@colors

  % Apply stored dark variant colors
  \moloch@apply@store@dark@colors
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\moloch@colors@light}
%    Switches to the light variant color scheme. Mirrors the dark variant
%    command but applies light colors instead. The sequence ensures that
%    user customizations override theme defaults.
%    \begin{macrocode}
\newcommand{\moloch@colors@light}{
  \moloch@variant@darkfalse
  \moloch@define@light@colors
  \usebeamercolor[fg]{normal text}

  \moloch@setup@block@colors
  \moloch@setup@text@colors

  \setbeamercolor{title separator}{
    use=progress bar,
    parent=progress bar
  }
  \moloch@setup@progressbar@parents

  % Apply stored light variant colors AFTER block definitions
  \moloch@apply@store@light@colors
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\moloch@apply@current@variant}
%    Helper command that applies the appropriate variant based on the
%    \verb|\ifmoloch@variant@dark| boolean flag. Used during initialization
%    and when switching color theme presets to ensure the correct variant
%    is applied.
%    \begin{macrocode}
\newcommand{\moloch@apply@current@variant}{%
  \ifmoloch@variant@dark
    \moloch@colors@dark
  \else
    \moloch@colors@light
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Color Customization Storage System}
%
% The storage system allows users to customize individual colors while
% preserving those customizations across variant switches. Each color option
% has separate storage for light and dark variants. When a user sets a color,
% it's both applied immediately and stored. When switching variants, stored
% customizations are reapplied on top of the theme defaults.
%
% \begin{macro}{\moloch@apply@store@light@colors}
%    Applies stored user customizations for the light variant. Checks each
%    storage macro and applies it if non-empty. This is called after applying
%    the theme's light colors to override with user preferences. For colors
%    that affect multiple elements (like \texttt{alerted text} affecting both
%    inline text and block titles), both are updated. Setup functions are
%    called when needed to propagate changes to dependent colors.
%    \begin{macrocode}
\newcommand{\moloch@apply@store@light@colors}{%
  \ifx\moloch@store@light@alerted@text\empty\else
    \setbeamercolor{alerted text}{fg=\moloch@store@light@alerted@text}%
    \setbeamercolor{block title alerted}{fg=\moloch@store@light@alerted@text}%
  \fi
  \ifx\moloch@store@light@example@text\empty\else
    \setbeamercolor{example text}{fg=\moloch@store@light@example@text}%
    \setbeamercolor{block title example}{fg=\moloch@store@light@example@text}%
  \fi
  \ifx\moloch@store@light@frametitle@fg\empty\else
    \setbeamercolor{frametitle}{fg=\moloch@store@light@frametitle@fg}%
  \fi
  \ifx\moloch@store@light@frametitle@bg\empty\else
    \setbeamercolor{frametitle}{bg=\moloch@store@light@frametitle@bg}%
  \fi
  \ifx\moloch@store@light@progressbar@fg\empty\else
    \setbeamercolor{progress bar}{fg=\moloch@store@light@progressbar@fg}%
    \moloch@setup@progressbar@parents
  \fi
  \ifx\moloch@store@light@progressbar@bg\empty\else
    \setbeamercolor{progress bar}{bg=\moloch@store@light@progressbar@bg}%
    \moloch@setup@progressbar@parents
  \fi
  \ifx\moloch@store@light@standout@fg\empty\else
    \setbeamercolor{standout}{fg=\moloch@store@light@standout@fg}%
  \fi
  \ifx\moloch@store@light@standout@bg\empty\else
    \setbeamercolor{standout}{bg=\moloch@store@light@standout@bg}%
  \fi
  \ifx\moloch@store@light@normal@text@fg\empty\else
    \setbeamercolor{normal text}{fg=\moloch@store@light@normal@text@fg}%
    \moloch@setup@text@colors
    \moloch@setup@block@colors
  \fi
  \ifx\moloch@store@light@normal@text@bg\empty\else
    \setbeamercolor{normal text}{bg=\moloch@store@light@normal@text@bg}%
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\moloch@apply@store@dark@colors}
%    Applies stored user customizations for the dark variant. Mirrors the
%    light variant application but for dark colors. The logic is identical:
%    check each storage macro, apply if non-empty, and call setup functions
%    for colors that affect dependent elements.
%    \begin{macrocode}
\newcommand{\moloch@apply@store@dark@colors}{%
  \ifx\moloch@store@dark@alerted@text\empty\else
    \setbeamercolor{alerted text}{fg=\moloch@store@dark@alerted@text}%
    \setbeamercolor{block title alerted}{fg=\moloch@store@dark@alerted@text}%
  \fi
  \ifx\moloch@store@dark@example@text\empty\else
    \setbeamercolor{example text}{fg=\moloch@store@dark@example@text}%
    \setbeamercolor{block title example}{fg=\moloch@store@dark@example@text}%
  \fi
  \ifx\moloch@store@dark@frametitle@fg\empty\else
    \setbeamercolor{frametitle}{fg=\moloch@store@dark@frametitle@fg}%
  \fi
  \ifx\moloch@store@dark@frametitle@bg\empty\else
    \setbeamercolor{frametitle}{bg=\moloch@store@dark@frametitle@bg}%
  \fi
  \ifx\moloch@store@dark@progressbar@fg\empty\else
    \setbeamercolor{progress bar}{fg=\moloch@store@dark@progressbar@fg}%
    \moloch@setup@progressbar@parents
  \fi
  \ifx\moloch@store@dark@progressbar@bg\empty\else
    \setbeamercolor{progress bar}{bg=\moloch@store@dark@progressbar@bg}%
    \moloch@setup@progressbar@parents
  \fi
  \ifx\moloch@store@dark@standout@fg\empty\else
    \setbeamercolor{standout}{fg=\moloch@store@dark@standout@fg}%
  \fi
  \ifx\moloch@store@dark@standout@bg\empty\else
    \setbeamercolor{standout}{bg=\moloch@store@dark@standout@bg}%
  \fi
  \ifx\moloch@store@dark@normal@text@fg\empty\else
    \setbeamercolor{normal text}{fg=\moloch@store@dark@normal@text@fg}%
    \moloch@setup@text@colors
    \moloch@setup@block@colors
  \fi
  \ifx\moloch@store@dark@normal@text@bg\empty\else
    \setbeamercolor{normal text}{bg=\moloch@store@dark@normal@text@bg}%
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{Semantic Color Helper}
%
% \begin{macro}{\moloch@apply@semantic@colors}
%    Maps semantic color names to Beamer color definitions. This helper expects
%    the following colors to be defined (via \verb|\definecolor| or \verb|\colorlet|)
%    before being called:
%
%    \begin{itemize}
%      \item \texttt{mNormaltextFg} - Normal text foreground
%      \item \texttt{mNormaltextBg} - Normal text background
%      \item \texttt{mFrametitleFg} - Frame title foreground
%      \item \texttt{mFrametitleBg} - Frame title background
%      \item \texttt{mAlertFg} - Alerted text foreground
%      \item \texttt{mExampleFg} - Example text foreground
%      \item \texttt{mProgressbarFg} - Progress bar foreground
%      \item \texttt{mProgressbarBg} - Progress bar background
%      \item \texttt{mStandoutFg} - Standout frame foreground
%      \item \texttt{mStandoutBg} - Standout frame background
%      \item \texttt{mFootnoteFg} - Footnote foreground
%    \end{itemize}
%
%    Color themes should define all these colors (using any color specification
%    method: HTML, RGB, color names, or color expressions), then call this
%    helper to apply them to the appropriate Beamer color elements.
%    \begin{macrocode}
\newcommand{\moloch@apply@semantic@colors}{%
  % Apply semantic colors to Beamer color definitions
  \setbeamercolor{normal text}{fg=mNormaltextFg, bg=mNormaltextBg}%
  \setbeamercolor{frametitle}{fg=mFrametitleFg, bg=mFrametitleBg}%
  \setbeamercolor{palette primary}{use=frametitle, parent=frametitle}%
  \setbeamercolor{alerted text}{fg=mAlertFg}%
  \setbeamercolor{example text}{fg=mExampleFg}%
  \setbeamercolor{progress bar}{fg=mProgressbarFg, bg=mProgressbarBg}%
  \setbeamercolor{title separator}{fg=mTitleseparatorFg}%
  \setbeamercolor{footnote}{fg=mFootnoteFg}%
  \setbeamercolor{footnote mark}{fg=.}%
  \setbeamercolor{standout}{fg=mStandoutFg, bg=mStandoutBg}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Color Theme Presets}
%
% These commands define complete color schemes that can be switched between.
% Each preset registers both light and dark variants.
%
% \begin{macro}{\moloch@colortheme@default}
%    The default moloch color scheme.
%    \begin{macrocode}
\newcommand{\moloch@colortheme@default}{%
  \moloch@register@light@colors{%
    \definecolor{mNormaltextFg}{HTML}{23373b}
    \colorlet{mNormaltextBg}{black!2}
    \definecolor{mAlertFg}{HTML}{EB811B}
    \definecolor{mExampleFg}{RGB}{0,128,128}
    \colorlet{mFrametitleFg}{mNormaltextBg}
    \colorlet{mFrametitleBg}{mNormaltextFg}
    \colorlet{mProgressbarFg}{mAlertFg}
    \colorlet{mProgressbarBg}{mProgressbarFg!50!black!30}
    \colorlet{mTitleseparatorFg}{mProgressbarFg}
    \colorlet{mStandoutFg}{mNormaltextBg}
    \colorlet{mStandoutBg}{mNormaltextFg}
    \colorlet{mFootnoteFg}{mNormaltextFg!90}

    \moloch@apply@semantic@colors
  }%

  % Register dark variant - use brighter colors for better contrast
  \moloch@register@dark@colors{%
    \colorlet{mNormaltextFg}{black!2}
    \definecolor{mNormaltextBg}{HTML}{23373b}
    \definecolor{mAlertFg}{HTML}{EF9F76}
    \definecolor{mExampleFg}{HTML}{5ABFB5}
    \colorlet{mFrametitleFg}{mNormaltextBg}
    \colorlet{mFrametitleBg}{black!15}
    \colorlet{mProgressbarFg}{mAlertFg}
    \colorlet{mProgressbarBg}{mProgressbarFg!50!black!30}
    \colorlet{mTitleseparatorFg}{mProgressbarFg}
    \colorlet{mStandoutFg}{mNormaltextBg}
    \colorlet{mStandoutBg}{black!15}
    \colorlet{mFootnoteFg}{mNormaltextFg!90}

    \moloch@apply@semantic@colors
  }%

  % Apply current variant after registering both
  \moloch@apply@current@variant
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\moloch@colortheme@tomorrow}
%    The Tomorrow color scheme by Chris Kempson.
%    \begin{macrocode}
\newcommand{\moloch@colortheme@tomorrow}{%
  \moloch@register@light@colors{%
    \definecolor{mNormaltextFg}{HTML}{1d1f21}
    \colorlet{mNormaltextBg}{white}
    \definecolor{mAlertFg}{HTML}{cc6666}
    \definecolor{mExampleFg}{HTML}{4271ae}
    \colorlet{mFrametitleFg}{white}
    \definecolor{mFrametitleBg}{HTML}{1d1f21}
    \definecolor{mProgressbarFg}{HTML}{8959a8}
    \colorlet{mProgressbarBg}{mProgressbarFg!50!black!30}
    \definecolor{mTitleseparatorFg}{HTML}{8959a8}
    \colorlet{mStandoutFg}{white}
    \definecolor{mStandoutBg}{HTML}{1d1f21}
    \definecolor{mFootnoteFg}{HTML}{1d1f21}

    \moloch@apply@semantic@colors
  }

  \moloch@register@dark@colors{%
    \colorlet{mNormaltextFg}{white}
    \definecolor{mNormaltextBg}{HTML}{282a2e}
    \definecolor{mAlertFg}{HTML}{de935f}
    \definecolor{mExampleFg}{HTML}{7aa6da}
    \colorlet{mFrametitleFg}{white}
    \definecolor{mFrametitleBg}{HTML}{1d1f21}
    \definecolor{mProgressbarFg}{HTML}{b294bb}
    \colorlet{mProgressbarBg}{mProgressbarFg!50!black!30}
    \definecolor{mTitleseparatorFg}{HTML}{b294bb}
    \colorlet{mStandoutFg}{white}
    \definecolor{mStandoutBg}{HTML}{1d1f21}
    \definecolor{mFootnoteFg}{HTML}{1d1f21}

    \moloch@apply@semantic@colors
  }%

  % Apply current variant after registering both
  \moloch@apply@current@variant
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\moloch@colortheme@paper}
%    A crisp and clean color scheme with white frametitle
%    background and high contrast.
%
%    \begin{macrocode}
\newcommand{\moloch@colortheme@paper}{%
  \moloch@register@light@colors{%
    \colorlet{mNormaltextFg}{black}
    \colorlet{mNormaltextBg}{white}
    \definecolor{mAlertFg}{HTML}{E5276F}
    \definecolor{mExampleFg}{HTML}{265DAB}
    \colorlet{mFrametitleFg}{black}
    \colorlet{mFrametitleBg}{white}
    \definecolor{mProgressbarFg}{HTML}{60BD68}
    \colorlet{mProgressbarBg}{black!20}
    \definecolor{mTitleseparatorFg}{HTML}{F15854}
    \colorlet{mStandoutFg}{white}
    \colorlet{mStandoutBg}{black!60}
    \colorlet{mFootnoteFg}{black!90}

    \moloch@apply@semantic@colors
  }%

  \moloch@register@dark@colors{%
    \colorlet{mNormaltextFg}{white}
    \colorlet{mNormaltextBg}{black!80}
    \definecolor{mAlertFg}{HTML}{F17CB0}
    \definecolor{mExampleFg}{HTML}{88BDE6}
    \colorlet{mFrametitleFg}{white}
    \colorlet{mFrametitleBg}{black!80}
    \definecolor{mProgressbarFg}{HTML}{90CD97}
    \colorlet{mProgressbarBg}{black!70}
    \definecolor{mTitleseparatorFg}{HTML}{F15854}
    \colorlet{mStandoutFg}{white}
    \colorlet{mStandoutBg}{black!60}
    \colorlet{mFootnoteFg}{black!90}

    \moloch@apply@semantic@colors
  }%

  % Apply current variant after registering both
  \moloch@apply@current@variant
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\moloch@colortheme@highcontrast}
%    High contrast color scheme for better accessibility.
%    \begin{macrocode}
\newcommand{\moloch@colortheme@highcontrast}{%
  % Define high contrast colors
  \definecolor{mAlert}{HTML}{AD003D}%
  \definecolor{mExample}{HTML}{005580}%

  % Register light variant
  \moloch@register@light@colors{%
    \colorlet{mNormaltextFg}{black}
    \colorlet{mNormaltextBg}{white}
    \definecolor{mAlertFg}{HTML}{C66526}
    \definecolor{mExampleFg}{HTML}{3070AD}
    \colorlet{mFrametitleFg}{white}
    \colorlet{mFrametitleBg}{black}
    \colorlet{mProgressbarFg}{mAlertFg}
    \colorlet{mProgressbarBg}{mProgressbarFg!50!black!30}
    \colorlet{mTitleseparatorFg}{mAlertFg}
    \colorlet{mStandoutFg}{black}
    \colorlet{mStandoutBg}{white}
    \colorlet{mFootnoteFg}{mNormaltextFg!90}

    \moloch@apply@semantic@colors
  }%
  \definecolor{mAlertDark}{HTML}{F7768E}%
  \definecolor{mExampleDark}{HTML}{7AA2F7}%

  % Register dark variant
  \moloch@register@dark@colors{%
    \colorlet{mNormaltextFg}{white}
    \colorlet{mNormaltextBg}{black}
    \definecolor{mAlertFg}{HTML}{DCA237}
    \definecolor{mExampleFg}{HTML}{6FB2E4}
    \colorlet{mFrametitleFg}{black}
    \colorlet{mFrametitleBg}{white}
    \colorlet{mProgressbarFg}{mAlertFg}
    \colorlet{mProgressbarBg}{mProgressbarFg!50!black!70}
    \colorlet{mTitleseparatorFg}{mAlertFg}
    \colorlet{mStandoutFg}{white}
    \colorlet{mStandoutBg}{black}
    \colorlet{mFootnoteFg}{mNormaltextFg!90}

    \moloch@apply@semantic@colors
  }%

  % Apply current variant after registering both
  \moloch@apply@current@variant
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\moloch@colortheme@catppuccin}
%    A color theme with soothing pastels and
%    light contrasts.
%
%    \begin{macrocode}
\newcommand{\moloch@colortheme@catppuccin}{%
  \moloch@register@light@colors{%
    \definecolor{mNormaltextFg}{HTML}{4C4F69}
    \definecolor{mNormaltextBg}{HTML}{EFF1F5}
    \definecolor{mAlertFg}{HTML}{D20F39}
    \definecolor{mExampleFg}{HTML}{1E66F5}
    \definecolor{mFrametitleFg}{HTML}{CAD3F5}
    \definecolor{mFrametitleBg}{HTML}{303446}
    \definecolor{mProgressbarFg}{HTML}{DC8A78}
    \colorlet{mProgressbarBg}{mProgressbarFg!50!black!30}
    \definecolor{mTitleseparatorFg}{HTML}{40A02B}
    \definecolor{mStandoutFg}{HTML}{CAD3F5}
    \definecolor{mStandoutBg}{HTML}{303446}
    \colorlet{mFootnoteFg}{mNormaltextFg!90}

    \moloch@apply@semantic@colors
  }%

  \moloch@register@dark@colors{%
    \definecolor{mNormaltextFg}{HTML}{CAD3F5}
    \definecolor{mNormaltextBg}{HTML}{24273A}
    \definecolor{mAlertFg}{HTML}{ED8796}
    \definecolor{mExampleFg}{HTML}{8AADF4}
    \definecolor{mFrametitleFg}{HTML}{CAD3F5}
    \definecolor{mFrametitleBg}{HTML}{24273A}
    \definecolor{mProgressbarFg}{HTML}{EED49F}
    \colorlet{mProgressbarBg}{mProgressbarFg!20!black!90}
    \definecolor{mTitleseparatorFg}{HTML}{A6DA95}
    \definecolor{mStandoutFg}{HTML}{4C4F69}
    \definecolor{mStandoutBg}{HTML}{CCD0DA}
    \colorlet{mFootnoteFg}{mNormaltextFg!90}

    \moloch@apply@semantic@colors
  }%

  % Apply current variant after registering both
  \moloch@apply@current@variant
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{New Color System}
%
% The color system provides a unified interface for theme selection, variant
% switching, and granular color customization. It uses pgfkeys to organize
% options into a \texttt{/moloch/colors/} namespace.
%
% The system supports three layers of customization:
% \begin{enumerate}
% \item Theme presets (default, tomorrow, highcontrast)
% \item Variant switching (light/dark)
% \item Per-variant color overrides for individual elements
% \end{enumerate}
%
% All customizations are preserved when switching between variants, allowing
% users to set up colors once and then freely toggle between light and dark
% modes without losing their customizations.
%
% \begin{macro}{Color theme and variant options}
%    The main pgfkeys tree defines theme selection, variant switching, and
%    the storage system for user customizations. Storage keys are defined
%    first to declare the macros, then initialized to empty, and finally
%    the actual color setting commands reference these storage macros.
%    
%    The storage system uses a convention: for each customizable color,
%    there are separate storage macros for light and dark variants named
%    \verb|\moloch@store@<variant>@<color>@<property>|. For example:
%    \verb|\moloch@store@light@progressbar@fg| stores the light variant's
%    progress bar foreground color.
%    \begin{macrocode}
\pgfkeys{
  /moloch/colors/.cd,
  theme/.is choice,
  theme/default/.code=\moloch@colortheme@default,
  theme/tomorrow/.code=\moloch@colortheme@tomorrow,
  theme/highcontrast/.code=\moloch@colortheme@highcontrast,
  theme/paper/.code=\moloch@colortheme@paper,
  theme/catppuccin/.code=\moloch@colortheme@catppuccin,
  variant/.is choice,
  variant/light/.code={%
      \moloch@variant@darkfalse
      \moloch@colors@light
    },
  variant/dark/.code={%
      \moloch@variant@darktrue
      \moloch@colors@dark
    },
  % Storage keys - store in macros
  % These define the storage macros that will hold user customizations
  store/light/alerted text/.store in=\moloch@store@light@alerted@text,
  store/dark/alerted text/.store in=\moloch@store@dark@alerted@text,
  store/light/frametitle fg/.store in=\moloch@store@light@frametitle@fg,
  store/dark/frametitle fg/.store in=\moloch@store@dark@frametitle@fg,
  store/light/frametitle bg/.store in=\moloch@store@light@frametitle@bg,
  store/dark/frametitle bg/.store in=\moloch@store@dark@frametitle@bg,
  store/light/example text/.store in=\moloch@store@light@example@text,
  store/dark/example text/.store in=\moloch@store@dark@example@text,
  store/light/progressbar fg/.store in=\moloch@store@light@progressbar@fg,
  store/dark/progressbar fg/.store in=\moloch@store@dark@progressbar@fg,
  store/light/progressbar bg/.store in=\moloch@store@light@progressbar@bg,
  store/dark/progressbar bg/.store in=\moloch@store@dark@progressbar@bg,
  store/light/standout fg/.store in=\moloch@store@light@standout@fg,
  store/dark/standout fg/.store in=\moloch@store@dark@standout@fg,
  store/light/standout bg/.store in=\moloch@store@light@standout@bg,
  store/dark/standout bg/.store in=\moloch@store@dark@standout@bg,
  store/light/normal text fg/.store in=\moloch@store@light@normal@text@fg,
  store/dark/normal text fg/.store in=\moloch@store@dark@normal@text@fg,
  store/light/normal text bg/.store in=\moloch@store@light@normal@text@bg,
  store/dark/normal text bg/.store in=\moloch@store@dark@normal@text@bg,
  % Initialize storage macros as empty
  % This prevents errors when checking if macros are set
  store/light/alerted text=,
  store/dark/alerted text=,
  store/light/frametitle fg=,
  store/dark/frametitle fg=,
  store/light/frametitle bg=,
  store/dark/frametitle bg=,
  store/light/example text=,
  store/dark/example text=,
  store/light/progressbar fg=,
  store/dark/progressbar fg=,
  store/light/progressbar bg=,
  store/dark/progressbar bg=,
  store/light/standout fg=,
  store/dark/standout fg=,
  store/light/standout bg=,
  store/dark/standout bg=,
  store/light/normal text fg=,
  store/dark/normal text fg=,
  store/light/normal text bg=,
  store/dark/normal text bg=,
  % Color setting commands
  % Each color has three variants:
  % 1. Variant-agnostic: sets current variant + stores for current
  % 2. light/<color>: sets if in light mode, always stores for light
  % 3. dark/<color>: sets if in dark mode, always stores for dark
  progressbar fg/.code={%
      \setbeamercolor{progress bar}{fg=#1}%
      \moloch@setup@progressbar@parents
      \ifmoloch@variant@dark
        \pgfkeys{/moloch/colors/store/dark/progressbar fg=#1}%
      \else
        \pgfkeys{/moloch/colors/store/light/progressbar fg=#1}%
      \fi
    },
  light/progressbar fg/.code={%
      \pgfkeys{/moloch/colors/store/light/progressbar fg=#1}%
      \ifmoloch@variant@dark\else
        \setbeamercolor{progress bar}{fg=#1}%
        \moloch@setup@progressbar@parents
      \fi
    },
  dark/progressbar fg/.code={%
      \pgfkeys{/moloch/colors/store/dark/progressbar fg=#1}%
      \ifmoloch@variant@dark
        \setbeamercolor{progress bar}{fg=#1}%
        \moloch@setup@progressbar@parents
      \fi
    },
  progressbar bg/.code={%
      \setbeamercolor{progress bar}{bg=#1}%
      \moloch@setup@progressbar@parents
      \ifmoloch@variant@dark
        \pgfkeys{/moloch/colors/store/dark/progressbar bg=#1}%
      \else
        \pgfkeys{/moloch/colors/store/light/progressbar bg=#1}%
      \fi
    },
  light/progressbar bg/.code={%
      \pgfkeys{/moloch/colors/store/light/progressbar bg=#1}%
      \ifmoloch@variant@dark\else
        \setbeamercolor{progress bar}{bg=#1}%
        \moloch@setup@progressbar@parents
      \fi
    },
  dark/progressbar bg/.code={%
      \pgfkeys{/moloch/colors/store/dark/progressbar bg=#1}%
      \ifmoloch@variant@dark
        \setbeamercolor{progress bar}{bg=#1}%
        \moloch@setup@progressbar@parents
      \fi
    },
  normal text fg/.code={%
      \setbeamercolor{normal text}{fg=#1}%
      \moloch@setup@text@colors
      \moloch@setup@block@colors
      \ifmoloch@variant@dark
        \pgfkeys{/moloch/colors/store/dark/normal text fg=#1}%
      \else
        \pgfkeys{/moloch/colors/store/light/normal text fg=#1}%
      \fi
    },
  light/normal text fg/.code={%
      \pgfkeys{/moloch/colors/store/light/normal text fg=#1}%
      \ifmoloch@variant@dark\else
        \setbeamercolor{normal text}{fg=#1}%
        \moloch@setup@text@colors
        \moloch@setup@block@colors
      \fi
    },
  dark/normal text fg/.code={%
      \pgfkeys{/moloch/colors/store/dark/normal text fg=#1}%
      \ifmoloch@variant@dark
        \setbeamercolor{normal text}{fg=#1}%
        \moloch@setup@text@colors
        \moloch@setup@block@colors
      \fi
    },
  normal text bg/.code={%
      \setbeamercolor{normal text}{bg=#1}%
      \ifmoloch@variant@dark
        \pgfkeys{/moloch/colors/store/dark/normal text bg=#1}%
      \else
        \pgfkeys{/moloch/colors/store/light/normal text bg=#1}%
      \fi
    },
  light/normal text bg/.code={%
      \pgfkeys{/moloch/colors/store/light/normal text bg=#1}%
      \ifmoloch@variant@dark\else
        \setbeamercolor{normal text}{bg=#1}%
      \fi
    },
  dark/normal text bg/.code={%
      \pgfkeys{/moloch/colors/store/dark/normal text bg=#1}%
      \ifmoloch@variant@dark
        \setbeamercolor{normal text}{bg=#1}%
      \fi
    },
  alerted text/.code={%
      \setbeamercolor{alerted text}{fg=#1}%
      \setbeamercolor{block title alerted}{fg=#1}%
      \ifmoloch@variant@dark
        \pgfkeys{/moloch/colors/store/dark/alerted text=#1}%
      \else
        \pgfkeys{/moloch/colors/store/light/alerted text=#1}%
      \fi
    },
  light/alerted text/.code={%
      \pgfkeys{/moloch/colors/store/light/alerted text=#1}%
      \ifmoloch@variant@dark\else
        \setbeamercolor{alerted text}{fg=#1}%
        \setbeamercolor{block title alerted}{fg=#1}%
      \fi
    },
  dark/alerted text/.code={%
      \pgfkeys{/moloch/colors/store/dark/alerted text=#1}%
      \ifmoloch@variant@dark
        \setbeamercolor{alerted text}{fg=#1}%
        \setbeamercolor{block title alerted}{fg=#1}%
      \fi
    },
  example text/.code={%
      \setbeamercolor{example text}{fg=#1}%
      \setbeamercolor{block title example}{fg=#1}%
      \ifmoloch@variant@dark
        \pgfkeys{/moloch/colors/store/dark/example text=#1}%
      \else
        \pgfkeys{/moloch/colors/store/light/example text=#1}%
      \fi
    },
  light/example text/.code={%
      \pgfkeys{/moloch/colors/store/light/example text=#1}%
      \ifmoloch@variant@dark\else
        \setbeamercolor{example text}{fg=#1}%
        \setbeamercolor{block title example}{fg=#1}%
      \fi
    },
  dark/example text/.code={%
      \pgfkeys{/moloch/colors/store/dark/example text=#1}%
      \ifmoloch@variant@dark
        \setbeamercolor{example text}{fg=#1}%
        \setbeamercolor{block title example}{fg=#1}%
      \fi
    },
  frametitle fg/.code={%
      \setbeamercolor{frametitle}{fg=#1}%
      \ifmoloch@variant@dark
        \pgfkeys{/moloch/colors/store/dark/frametitle fg=#1}%
      \else
        \pgfkeys{/moloch/colors/store/light/frametitle fg=#1}%
      \fi
    },
  frametitle bg/.code={%
      \setbeamercolor{frametitle}{bg=#1}%
      \ifmoloch@variant@dark
        \pgfkeys{/moloch/colors/store/dark/frametitle bg=#1}%
      \else
        \pgfkeys{/moloch/colors/store/light/frametitle bg=#1}%
      \fi
    },
  light/frametitle fg/.code={%
      \pgfkeys{/moloch/colors/store/light/frametitle fg=#1}%
      \ifmoloch@variant@dark\else
        \setbeamercolor{frametitle}{fg=#1}%
      \fi
    },
  dark/frametitle fg/.code={%
      \pgfkeys{/moloch/colors/store/dark/frametitle fg=#1}%
      \ifmoloch@variant@dark
        \setbeamercolor{frametitle}{fg=#1}%
      \fi
    },
  light/frametitle bg/.code={%
      \pgfkeys{/moloch/colors/store/light/frametitle bg=#1}%
      \ifmoloch@variant@dark\else
        \setbeamercolor{frametitle}{bg=#1}%
      \fi
    },
  dark/frametitle bg/.code={%
      \pgfkeys{/moloch/colors/store/dark/frametitle bg=#1}%
      \ifmoloch@variant@dark
        \setbeamercolor{frametitle}{bg=#1}%
      \fi
    },
  standout fg/.code={%
      \setbeamercolor{standout}{fg=#1}%
    },
  light/standout fg/.code={%
      \pgfkeys{/moloch/colors/store/light/standout fg=#1}%
      \ifmoloch@variant@dark\else
        \setbeamercolor{standout}{fg=#1}%
      \fi
    },
  dark/standout fg/.code={%
      \pgfkeys{/moloch/colors/store/dark/standout fg=#1}%
      \ifmoloch@variant@dark
        \setbeamercolor{standout}{fg=#1}%
      \fi
    },
  standout bg/.code={%
      \setbeamercolor{standout}{bg=#1}%
    },
  light/standout bg/.code={%
      \pgfkeys{/moloch/colors/store/light/standout bg=#1}%
      \ifmoloch@variant@dark\else
        \setbeamercolor{standout}{bg=#1}%
      \fi
    },
  dark/standout bg/.code={%
      \pgfkeys{/moloch/colors/store/dark/standout bg=#1}%
      \ifmoloch@variant@dark
        \setbeamercolor{standout}{bg=#1}%
      \fi
    },
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\molochcolors}
%    User-facing command for color customization.
%    \begin{macrocode}
\newcommand{\molochcolors}[1]{\pgfkeys{/moloch/colors/.cd,#1}}
%    \end{macrocode}
% \end{macro}
%
% The Moloch inner or outer themes optionally display progress
% bars in various locations. Their color is set by \verb|progress bar| but the two
% different kinds can be customized separately. The horizontal rule on the
% title page is also set based on the progress bar color and can be customized
% with \verb|title separator|.
%
%    \begin{macrocode}
\setbeamercolor{progress bar}{%
  use=alerted text,
  fg=alerted text.fg,
  bg=alerted text.fg!50!black!30
}
\setbeamercolor{title separator}{
  use=progress bar,
  parent=progress bar
}
\setbeamercolor{progress bar in head/foot}{%
  use=progress bar,
  parent=progress bar
}
\setbeamercolor{progress bar in section page}{
  use=progress bar,
  parent=progress bar
}
%    \end{macrocode}
%
% Block environments such as \verb|theorem| and \verb|example| have no background color
% by default. The option \verb|block=fill| sets a background color based on the
% background and foreground of \verb|normal text|. The option \verb|block=transparent|
% reverts the block environments to an empty background, which can be useful
% if changing colors mid-presentation.
%
%    \begin{macrocode}
\newcommand{\moloch@block@transparent}{
  \setbeamercolor{block title}{bg=}
  \setbeamercolor{block body}{bg=}
  \setbeamercolor{block title alerted}{bg=}
  \setbeamercolor{block title example}{bg=}
}
\newcommand{\moloch@block@fill}{
  \setbeamercolor{block title}{%
    bg=normal text.bg!80!fg
  }
  \setbeamercolor{block body}{%
    use=block title,
    bg=block title.bg!50!normal text.bg
  }
  \setbeamercolor{block title alerted}{%
    bg=block title.bg,
  }
  \setbeamercolor{block title example}{%
    bg=block title.bg,
  }
}
%
% We also reset the bibliography colors in order to pick up the surrounding
% colors at the time of use. This prevents us having to set the correct color in
% normal and standout mode.
%
%    \begin{macrocode}
\setbeamercolor{bibliography entry author}{fg=, bg=}
\setbeamercolor{bibliography entry title}{fg=, bg=}
\setbeamercolor{bibliography entry location}{fg=, bg=}
\setbeamercolor{bibliography entry note}{fg=, bg=}
%    \end{macrocode}
%
% \subsubsection{Process Package Options}
%
%    \begin{macrocode}
\moloch@colortheme@default
\moloch@color@setdefaults
\ProcessPgfPackageOptions{/moloch/color}
%    \end{macrocode}
%
%    \begin{macrocode}
\mode<all>
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
% \Finale
\endinput
