\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{kartsstyle}[2023/05/08 Class for KaRTS books]

%
% Start from KOMA book
%
\LoadClass[a4paper,12pt,openany]{scrbook}
\KOMAoptions{
    numbers=noenddot,
    chapterprefix,
    parskip=half,
    pagesize=auto
}
\setlength{\footskip}{2.5em}

%
% Load for later
%
\RequirePackage{etoolbox}

%
% Page geometry and PDF settings
%
\RequirePackage[a4paper,bottom=3.2cm,outer=2cm, inner=1.5cm, footskip=2.0cm]{geometry}
\RequirePackage[hidelinks]{hyperref}
\hypersetup{pdfpagelayout=TwoColumnRight,pdfstartview={XYZ null null 1.00}}

\raggedbottom

%
% Microtype and fonts
%
\RequirePackage{microtype}
\RequirePackage[scaled]{helvet}
\RequirePackage[]{scholax}
\RequirePackage{anyfontsize}

%
% Colors
%
\RequirePackage[dvipsnames]{xcolor}
\definecolor{chapterbrown}{RGB}{ 89, 25,  9}
\definecolor{sectionbrown}{RGB}{140, 39, 14}

%
% Headers and footers
%
\RequirePackage{scrlayer-scrpage}

\addtokomafont{pagenumber}{\normalshape}

\renewcommand\chapterpagestyle{plain}
\renewcommand\partpagestyle{empty}

\setkomafont{pagehead}{\footnotesize\sffamily}

\ihead[]{}
\makeatletter
\lehead[]{\@title}
\makeatother
\cehead[]{}
\rohead[]{\leftmark}

\ofoot[\pagemark]{\pagemark}

\AtBeginEnvironment{document}{\pagestyle{scrheadings}}

%
% Chapter headings
%
\addtokomafont{section}{\color{sectionbrown}}
\addtokomafont{subsection}{\color{sectionbrown}}
\addtokomafont{subsubsection}{\color{sectionbrown}}

\renewcommand{\chapterlineswithprefixformat}[3]{%
    \color{chapterbrown}#2\MakeUppercase{#3}%
}
\renewcommand*{\chapterheadmidvskip}{\par\nobreak\vspace{0em}}

\newcommand{\clearpart}[1]{\cleardoubleevenpage\part{#1}}

%
% Stat and dice typesetting
%
\RequirePackage{relsize}

\newcommand{\dc}[1]{\textsc{\larger d}#1}

\newcommand*{\stat}[1]{\textsc{\larger[2]\MakeLowercase{#1}}}

%
% Firstpar environment for the first paragraph of the chapter. Adds drop-capital, increases font size and add line spacing
%
\RequirePackage[loversize=0.2,nindent=0.0em]{lettrine}
\RequirePackage{setspace}

\newenvironment{firstpar}{\onehalfspacing\large\lettrine}{\normalsize\par}

%
% Multicol package. Change font size to \small.
%
\RequirePackage{multicol}

\setlength{\columnsep}{0.75cm}

\raggedcolumns

\AtBeginEnvironment{multicols}{\small}

%
% Graphics
%
\RequirePackage{graphicx}

%
% Metaphysics require complex math typesetting
%
\RequirePackage{amsmath}

%
% Cleveref -- Must be loaded after hyperref and amsmath
%
\RequirePackage[capitalize]{cleveref}

%
% Siunitx because what a TTRPG needs is precise metric typesetting
%
\RequirePackage[mode=match]{siunitx}

%
% For side boxes
% 
\RequirePackage{framed}

\newenvironment{boxnote}[1][Note]{\begin{framed}\textbf{\sffamily #1} }{\end{framed}}