% Copyright 2025 by Jason Kerwin
% Developed by Jason Kerwin with help from Claude AI
% based on beamerthemeFrankfurt.sty by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%




% Custom Beamer style file with configurable main color
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{kerwin}[2025/02/27 Custom Beamer style]

% This package must be loaded BEFORE the class to override geometry
\RequirePackage{geometry}

% Required packages
\RequirePackage{setspace}
\RequirePackage{grffile}
\RequirePackage{bm}
\RequirePackage{epstopdf}
\RequirePackage{amsmath}
\RequirePackage{amsfonts}
\RequirePackage{graphicx}
\RequirePackage{verbatim}
\RequirePackage{tikz}
\RequirePackage{caption}
\RequirePackage{etoolbox}
\RequirePackage[utf8]{inputenc}
\RequirePackage{newunicodechar}

% Define and process options
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
  family=kerwin,
  prefix=kerwin@
}
\DeclareStringOption[darkred]{color}
\ProcessKeyvalOptions*

% Ensure xcolor is loaded with all needed color options
% Must be done here, before we use any colors
\RequirePackage[table,dvipsnames,svgnames,x11names]{xcolor}

% Fix for hyperref bookmark warnings
\pdfstringdefDisableCommands{%
  \let\translate\relax
  \let\alert\relax
}

% Incorporate Frankfurt theme components directly
\mode<presentation>

% Set 16:9 aspect ratio
\setlength{\paperwidth}{16.0cm}
\setlength{\paperheight}{9.0cm}

% Use miniframes outer theme without dots
\useoutertheme{infolines}  % Changed to infolines theme
\useinnertheme[shadow=true]{rounded}
\usecolortheme{orchid}
\usecolortheme{whale}
\setbeamerfont{block title}{size={}}

% Customize the header to show only section titles
\setbeamertemplate{headline}{%
  \begin{beamercolorbox}[ht=2.5ex,dp=1.125ex]{section in head/foot}%
    \insertsectionnavigationhorizontal{\paperwidth}{}{}%
  \end{beamercolorbox}%
}

% Override with beaver theme colors
\usecolortheme{beaver}

% Override all colors with our custom color
\setbeamercolor{structure}{fg=\kerwin@color}
\setbeamercolor{alerted text}{fg=\kerwin@color}
\setbeamercolor{frametitle}{fg=\kerwin@color,bg=white}
\setbeamercolor{palette primary}{fg=\kerwin@color,bg=white}
\setbeamercolor{palette secondary}{fg=\kerwin@color,bg=white}
\setbeamercolor{palette tertiary}{fg=\kerwin@color,bg=white}
\setbeamercolor{palette quaternary}{bg=white}
\setbeamercolor{title}{bg=,fg=\kerwin@color}
\setbeamercolor{button}{bg=white,fg=\kerwin@color}
\setbeamercolor{button border}{bg=white,fg=\kerwin@color}
\setbeamercolor{enumerate item}{fg=\kerwin@color}
\setbeamercolor{section in head/foot}{fg=\kerwin@color,bg=white}
\setbeamercolor{subsection in head/foot}{fg=\kerwin@color,bg=white}
\setbeamercolor{mini frame}{fg=\kerwin@color}
\setbeamercolor{section in toc}{fg=\kerwin@color}
\setbeamercolor{subsection in toc}{fg=\kerwin@color}

% Template customizations
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{itemize items}{-}
\setbeamertemplate{enumerate items}[default]
\setbeamertemplate{page number in head/foot}[framenumber]

% Remove navigation elements
\beamertemplatenavigationsymbolsempty

% Set frame counter to 0 for the title page and exclude it from numbering
\AtBeginDocument{
    % Redefine the title page to reset frame counter to 0
    \let\oldtitlepage\titlepage
    \def\titlepage{\oldtitlepage\setcounter{framenumber}{0}}
}

% Customize footline for slide numbers (show on all slides except title)
\makeatletter
\setbeamertemplate{footline}{
  \ifnum\c@framenumber>0
    \raisebox{5pt}{\makebox[\paperwidth]{\hfill\makebox[20pt]{\textcolor{\kerwin@color!50!white}{\scriptsize\insertframenumber}}}}
  \fi
}
\makeatother

% Custom environments
\newenvironment{wideitemize}{\itemize\addtolength{\itemsep}{10pt}}{\enditemize}
\newenvironment{wideenumerate}{\enumerate\addtolength{\itemsep}{10pt}}{\endenumerate}

% Load the array package for custom column types
\RequirePackage{array}

% Custom column types
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

% Navigation dot fixes
\makeatletter
\@removefromreset{subsection}{section}
% Handle aspect ratio setting directly via \geometry
\geometry{paperwidth=16cm,paperheight=9cm}
\makeatother

% Okina character definition
\DeclareRobustCommand{\okina}{%
    \raisebox{\dimexpr\fontcharht\font`A-\height}{%
        \scalebox{0.8}{`}
    }
}

% Unicode character definition
\newunicodechar{ʻ}{\okina}

% Utility commands
\newcommand{\littlegray}[1]{{\scriptsize\color{gray} #1}}

% Hook for nice tables
\makeatletter
\AddToHook{env/threeparttable/begin}{\TPT@hookin{NiceTabular}\TPT@hookin{NiceTabular*}\TPT@hookin{NiceTabularX}}
\makeatother

% Title page customization
\addtobeamertemplate{title page}{\thispagestyle{empty}}{}

\mode<all>