\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{leelavati_defs}[2025/12/08 v1.0 Leelavati Shared Definitions]

% -------------------------------
% 1. Requirements for Definitions
% -------------------------------
% Packages needed by commands defined *within* this file.
\RequirePackage{booktabs}
\RequirePackage{amsthm, amssymb}
\RequirePackage{array}
\RequirePackage{ucharclasses}
\RequirePackage{tikz}
\RequirePackage{tkz-euclide}
\RequirePackage{microtype}
\usetikzlibrary{calc,patterns,intersections,through, decorations, decorations.fractals, arrows.meta}
\RequirePackage[dvipsnames,svgnames,table]{xcolor}
\RequirePackage[nodisplayskipstretch]{setspace} %nodisplayskipstretch keeps space above and below math equations constant, without stretch
\RequirePackage{tcolorbox}
\tcbuselibrary{breakable,skins}
\RequirePackage{fontawesome5}
\RequirePackage{needspace}
\RequirePackage{polyglossia}     % For language setup commands
\RequirePackage{fontspec}        % For font commands
\RequirePackage{mathtools}
\RequirePackage{unicode-math}
\RequirePackage{graphicx}
\RequirePackage{subcaption}
\RequirePackage{float}
\RequirePackage{microtype}
\setlength{\emergencystretch}{2em}
\RequirePackage{wrapfig}
\RequirePackage{caption}
\RequirePackage{scrlayer-scrpage}
\RequirePackage{chessboard}
\RequirePackage{xskak}
\RequirePackage[normalem]{ulem}
\RequirePackage{bm}
\RequirePackage{tfrupee}


% -------------------------------
% 2. Colors and Constants
% -------------------------------
%\definecolor{magHighlight}{HTML}{00AEEF} % Duotone CYAN
%\definecolor{magHighlight}{HTML}{FF00FF} % Duotone MAGENTA
\definecolor{magHighlight}{HTML}{005F99} % Duotone format ready

 
\definecolor{indigo}{RGB}{0,0,120}
\newcommand{\sbseries}{\fontseries{sb}\selectfont}
\newcommand{\mbseries}{\fontseries{mb}\selectfont}

\DeclareTextFontCommand{\textsb}{\sbseries}
\DeclareTextFontCommand{\textmb}{\mbseries}

% -------------------------------
% 3. Languages and Fonts
% -------------------------------
\setmainlanguage{english}
\setotherlanguage[numerals=odia,changecounternumbering=true]{odia}

\newcommand*\LeelaFontPath{../Fonts/NotoSans/}
\newcommand*\LeelaHeaderFontPath{../Fonts/Anek/}
\newcommand*\DejavuFontsPath{../Fonts/dejavu-sans-mono/}
\newcommand*\LibreFontsPath{../Fonts/Libre/}
\newcommand*\FontsPath{../Fonts/}

%change math env to noto sans as well
\setmathfont[Path=\LeelaFontPath,Extension=.otf]{NotoSansMath-Regular}
\setmonofont[Path=\DejavuFontsPath,Extension=.ttf,UprightFont=*,BoldFont=*-Bold,ItalicFont=*-Oblique,BoldItalicFont=*-BoldOblique]{DejaVuSansMono}

\setmainfont[Path=\LeelaFontPath, Extension=.ttf,UprightFont=*-Regular, BoldFont=*-Bold,ItalicFont=*-Italic,  BoldItalicFont=*-BoldItalic,FontFace={mb}{n}{Font={*-Medium}},FontFace={sb}{n}{*-SemiBold}]{NotoSans}

\newfontfamily\englishfont[Path=\LeelaFontPath, Extension=.ttf,UprightFont=*-Regular, BoldFont=*-Bold,ItalicFont=*-Italic,  BoldItalicFont=*-BoldItalic,FontFace={mb}{n}{Font={*-Medium}}, FontFace={sb}{n}{*-SemiBold}]{NotoSans}

\newfontfamily\dispatchfont[Path=\LibreFontsPath,Extension=.ttf,UprightFont=*-Regular, BoldFont=*-Bold,ItalicFont=*-Italic,  BoldItalicFont=*-BoldItalic,FontFace={mb}{n}{Font={*-Medium}}]{LibreBaskerville}

\newfontfamily\symbolafont[Path=\FontsPath, Extension=.ttf]{Symbola}

%add FakeSlant=0.12 later to imitate italics
\newfontfamily\odiafont[Path=\LeelaFontPath, Extension=.ttf, Script=Odia, Mapping=odianumerals,UprightFont=*-Regular, BoldFont=*-Bold,ItalicFont=*-Regular, BoldItalicFont=*-Bold,FontFace={mb}{n}{Font={*-Medium}}, FontFace={sb}{n}{*-SemiBold}]{NotoSansOriya}

\newfontfamily\odiafontsf[Path=\LeelaFontPath, Extension=.ttf, Script=Odia, UprightFont=*-Regular, BoldFont=*-Bold,ItalicFont=*-Regular, BoldItalicFont=*-Bold, FontFace={mb}{n}{Font={*-Medium}}, FontFace={sb}{n}{*-SemiBold}]{NotoSansOriya}

\newfontfamily\odiafonttt[Path=\LeelaFontPath, Extension=.ttf, Script=Odia,UprightFont=*-Regular, BoldFont=*-Bold,ItalicFont=*-Regular, BoldItalicFont=*-Bold, FontFace={mb}{n}{Font={*-Medium}}, FontFace={sb}{n}{*-SemiBold}]{NotoSansOriya}

\newfontfamily\anekfont[Path=\LeelaHeaderFontPath, Extension=.ttf, Script=Odia, Mapping=odianumerals,UprightFont=*-Regular, BoldFont=*-Bold, FontFace={mb}{n}{Font={*-Medium}}, FontFace={sb}{n}{*-SemiBold}]{AnekOdia}

% Convenience & Auto Switching
\DeclareRobustCommand{\textodia}[1]{{\odiafont #1}}
\newcommand{\textodialang}[1]{\bgroup\selectlanguage{odia}#1\egroup}
\setDefaultTransitions{\englishfont}{}
\setTransitionsFor{Oriya}{\odiafont}{\englishfont}

% -------------------------------
% 4. Sectioning & Heading Fonts (KOMA-native)
% -------------------------------
\setkomafont{chapter}{\XeTeXinterchartokenstate=0\anekfont\color{magHighlight}\large\sbseries\selectfont}

% For Sections
\setkomafont{section}{%
    \XeTeXinterchartokenstate=0%
    \anekfont%
    \color{magHighlight}%
    \normalsize%
    \fontseries{sb}\selectfont%  <-- Use the series switch directly
}

\RedeclareSectionCommand[beforeskip=.1\baselineskip,afterskip=.1\baselineskip]{section}
\RedeclareSectionCommand[beforeskip=.1\baselineskip,afterskip=.1\baselineskip]{subsection}
\RedeclareSectionCommand[beforeskip=.1\baselineskip,afterskip=0.0\baselineskip]{subsubsection}

\newcommand{\en}[1]{{\englishfont #1}}
\newcommand{\od}[1]{{\odiafont #1}}


% -------------------------------
% 5. Spacing & Typographic Robustness
% -------------------------------
\setlength{\parskip}{0.4em}
\setlength{\parindent}{0pt}

\RequirePackage{etoolbox}

% Column separation must stay here
\setlength{\columnsep}{6mm}

\makeatletter
\newtoks\leela@everydisplay
\leela@everydisplay=\everydisplay
\everydisplay{%
  \the\leela@everydisplay
  \setlength{\parskip}{0pt}%
  \setlength{\baselineskip}{\normalbaselineskip}%
  \abovedisplayskip=3pt plus 2pt minus 2pt
  \belowdisplayskip=3pt plus 2pt minus 2pt
  \abovedisplayshortskip=1pt plus 1pt minus 1pt
  \belowdisplayshortskip=1pt plus 1pt minus 1pt
}
\makeatother

\AtBeginDocument{%
  % Permissive settings for non-hyphenating Odia text
  \pretolerance=2000 \tolerance=6000 \emergencystretch=2em \hyphenpenalty=200 \exhyphenpenalty=100 \widowpenalty=10000 \clubpenalty=10000 \righthyphenmin=2
  \hfuzz=0.5pt \vfuzz=5pt \hbadness=10000 \vbadness=10000
  \lineskiplimit=-2pt
  \lineskip=0pt%0.6ex
  \XeTeXuseglyphmetrics=1\relax
  % float hygiene (2-col)
  \setcounter{topnumber}{2}
  \setcounter{totalnumber}{3}
  \renewcommand{\topfraction}{0.9}
  \renewcommand{\textfraction}{0.07}
  \renewcommand{\floatpagefraction}{0.8}
  \setcounter{dbltopnumber}{2}
  \renewcommand{\dbltopfraction}{0.9}
  \renewcommand{\dblfloatpagefraction}{0.8}
}

% -------------------------------
% 6. Localized Numerals in counters (Relies on polyglossia)
% -------------------------------
\makeatletter
\renewcommand{\thepage}{\localnumeral*{page}}
\renewcommand{\thesection}{\localnumeral*{section}}
\renewcommand{\thesubsection}{\thesection.\localnumeral*{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection.\localnumeral*{subsubsection}}
\renewcommand{\thefigure}{\localnumeral*{figure}}
\renewcommand{\thetable}{\localnumeral*{table}}
\renewcommand{\theequation}{\localnumeral*{equation}}
\renewcommand{\theenumi}{\localnumeral*{enumi}}
\renewcommand{\theenumii}{\localnumeral*{enumii}}
\renewcommand{\theenumiii}{\localnumeral*{enumiii}}
\renewcommand{\theenumiv}{\localnumeral*{enumiv}}
\renewcommand{\thefootnote}{\localnumeral*{footnote}}
\makeatother

% -------------------------------
% 7. Tcolorbox and Caption Styles
% -------------------------------
\tcbset{
  leela/.style={
    enhanced,
    breakable,
    boxrule=0.8pt,
    arc=1mm,
    colback=white,
    colframe=black!20,
    % Title Styling for default (Non-Accent)
    colbacktitle=white,      % Background of the title bar
    coltitle=black,          % Color of the title text    
    fonttitle={\XeTeXinterchartokenstate=0\anekfont\large\sbseries}, % Removed \color{white}
    left=3pt, right=3pt, top=5pt, bottom=5pt,
    center title, 
    before skip=8pt, after skip=8pt  
  },
  leelaAccent/.style={
    colback=magHighlight!10,
    colframe=magHighlight,
    % Override title colors for the Accent version
    colbacktitle=magHighlight, 
    coltitle=white,
    center title,
    before skip=8pt, after skip=8pt  
  }
}

\newtcolorbox{leelabox}[1][]{leela,#1}
\newtcolorbox{leelaauthor}[1][]{leela,colback=black!3,colframe=black!25,#1}

\DeclareCaptionFont{leelaMB}{\sbseries}
\DeclareCaptionFont{leelaHL}{\color{magHighlight}}
\DeclareCaptionFont{leelaSmall}{\small}
\captionsetup{font=small,labelfont = {leelaHL,leelaMB}, labelsep=colon, textfont  = leelaSmall, position  = bottom,labelsep  = colon,aboveskip = 6pt,belowskip = 0pt}

% -------------------------------
% 8. Footer Definition
% -------------------------------
\newcommand{\JournalName}{Leelavati $\;\;\bullet\;\;$ ଲୀଳାବତୀ}
\newsavebox{\leelaFooterBox}
\tikzset{
  konark/.style    ={draw=black!100, fill=black!60},
  footerwave/.style={draw=black!100, line width=1pt, smooth},
  footerline/.style={draw=black!100, line width=1pt, smooth}
}
\AtBeginDocument{%
  \sbox{\leelaFooterBox}{%
    \begin{tikzpicture}[x=1pt,y=1pt,baseline=0]
      \pgfmathsetlengthmacro{\HalfTW}{0.5*\textwidth}
      \def\Yline{0}
      \useasboundingbox (-\HalfTW,-5) rectangle (\HalfTW,5);
      \begin{scope}[xshift=-12]
        \draw[konark, even odd rule] (0,0) circle (10) (0,0) circle (8);
        \draw[konark] (0,0) circle (3);
        \foreach \x in {0,...,7}{
          \draw[konark] (22.5+45*\x:10) circle (1);
          \draw[konark, rotate=45*\x] (0,0)--(3:10)--(10,0)--(-3:10)--cycle;
        }
      \end{scope}
      \begin{scope}[xshift=12]
        \draw[konark, even odd rule] (0,0) circle (10) (0,0) circle (8);
        \draw[konark] (0,0) circle (3);
        \foreach \x in {0,...,7}{
          \draw[konark] (22.5+45*\x:10) circle (1);
          \draw[konark, rotate=45*\x] (0,0)--(3:10)--(10,0)--(-3:10)--cycle;
        }
      \end{scope}
      \draw[footerwave,domain=-60:0,variable=\t,samples=60]
        plot({\t-25},{ 10*exp(\t/30)*sin(-15*(\t))});
      \draw[footerwave,domain=0:60,variable=\t,samples=60]
        plot({\t+25},{ 10*exp(-\t/30)*sin( 15*(\t))});
      \draw[footerline] (-\HalfTW,\Yline) -- (-85,\Yline);
      \draw[footerline] (\HalfTW,\Yline) -- (85,\Yline);
    \end{tikzpicture}%
  }%
}
\newcommand{\footerlogo}{\raisebox{4mm}[0pt][0pt]{\usebox{\leelaFooterBox}}}

\clearpairofpagestyles 
\setkomafont{pagefoot}{\normalfont\sffamily\upshape}
\newcommand{\footerfont}{\fontsize{8}{10}\selectfont}

\cfoot*{\footerlogo}
\ifoot*{\footerfont\textsf{\textbf{\JournalName}}}
\ofoot*{\footerfont\bfseries \pagemark}

\makeatletter
\pretocmd{\@maketitle}{\vspace*{1cm}}{}{}
\makeatother

\pagestyle{scrheadings}
\KOMAoptions{headsepline=false,footsepline=false}


% -------------------------------
% 9. Author and Content Helpers
% -------------------------------
\DeclareRobustCommand{\AuthorDual}[2]{%
    \par % Ensure we are in a new paragraph
    \noindent
    % Create a box spanning the full line width to center its contents
    \makebox[\textwidth][c]{%
    \kern -1mm
        % 1. LEFT NAME: Put in a zero-width box aligned to the Right (r).
        %    This pushes the text to the LEFT of the center point.
        \makebox[0pt][r]{%
            % Use a parbox to allow wrapping if the name is long
            \parbox{0.45\linewidth}{\raggedleft\odiafont\color{magHighlight}\bfseries #1}%
            \hspace{4mm}% The gap between Left Name and Bullet
        }%
        %
        % 2. THE BULLET: Sits exactly at the center
        \makebox[0pt][c]{
        \raisebox{-0.2ex}{\textperiodcentered}%
        }
        %
        % 3. RIGHT NAME: Put in a zero-width box aligned to the Left (l).
        %    This pushes the text to the RIGHT of the center point.
        \makebox[0pt][l]{%
            \hspace{4mm}% The gap between Bullet and Right Name
            % Use a parbox to allow wrapping if the name is long
            \parbox{0.45\linewidth}{\raggedright\englishfont\color{magHighlight}\bfseries #2}%
        }%
    }%
}


% Author Note Environment
\makeatletter
\newcommand{\AuthorNote}[1]{%
  \par\medskip % Ensure it starts on a new line with some spacing
  \Needspace{6\baselineskip} % Prevents the box from being cut off at the bottom
  \begin{tcolorbox}[
    enhanced,
    boxrule=0.5pt,
    arc=2mm,
    colback=white,
    colframe=black,
    left=6pt,
    right=6pt,
    top=4pt,
    bottom=4pt,
    breakable=true, % Allows it to break across columns if very long
    width=\linewidth % Forces the box to match the current column width
  ]
    \noindent\footnotesize
    #1
  \end{tcolorbox}
  \par\medskip
}
\makeatother


% Hook for Odia
\gappto\captionsodia{%
  \def\abstractname{Abstract}%
}
% Hook for English
\gappto\captionsenglish{%
  \def\abstractname{ସାରାଂଶ}%
}

\newenvironment{abstract}{%
\par\small\vspace{0pt}
{\noindent\color{magHighlight}\rule[\ht\strutbox]{\linewidth}{1.0pt}\par\vspace{-.4cm}}
\noindent\textbf{\color{magHighlight}\abstractname. }\ignorespaces
}{\par\vspace{-0.35cm}
{\noindent\color{magHighlight}\rule{\linewidth}{1.0pt}\par}}

\newcommand{\sectionheader}[2]{%
    \par\addvspace{1em} % Adds space above the section
    {\color{magHighlight}\hrule height 1.0pt}
    \vspace{2pt}
    \noindent
    \textbf{\color{magHighlight}%
        #1 \hfill #2%
    }
    \par\vspace{2pt}
    {\color{magHighlight}\hrule height 1.0pt}
    \addvspace{0.5em} % Space below the section
}

\newcommand{\algebra}{\sectionheader{Algebra}{ବୀଜଗଣିତ}}

\newcommand{\numbertheory}{\sectionheader{Number Theory}{ସଂଖ୍ୟା ତତ୍ତ୍ୱ}}

\newcommand{\geometryh}{\sectionheader{Geometry}{ଜ୍ୟାମିତି}}

\newcommand{\trigonometry}{\sectionheader{Trigonometry}{ତ୍ରିକୋଣମିତି}}

\newcommand{\calculus}{\sectionheader{Calculus}{କଳନ ଗଣିତ}}

\newcommand{\combinatorics}{\sectionheader{Combinatorics}{ସଂଯୋଗ ଗଣିତ}}

\newcommand{\probability}{\sectionheader{Probability}{ସମ୍ଭାବ୍ୟତା ଗଣିତ}}



\newcommand{\funfactname}{\iflanguage{odia}{ତୁମେ ଜାଣିଛ କି?}{Did you know ?}}
\NewDocumentEnvironment{funfact}{O{\funfactname}}{%
  \begin{leelabox}[leelaAccent, title={\faLightbulb\;\;#1}]
}{%
  \end{leelabox}
}

% Author Info Macros
\newcommand{\affiliation}[2][1.8em]{%
  \par
  \hangindent=#1
  \hangafter=1
  \scalebox{1.1}{\color{magHighlight}\faUniversity}\, #2\par
}

\newcommand{\email}[1]{%
  \scalebox{1.1}{\color{magHighlight}\faEnvelope}\, 
  \href{mailto:#1}{#1}
}
\newcommand{\phone}[1]{%
  \scalebox{1.1}{\color{magHighlight}\faPhone}\, #1\par
}

\newtcolorbox{quotebox}[2][]{ % Added an optional argument for the attribution
  enhanced jigsaw,
  breakable,
  colback=magHighlight!10,
  colframe=white,
  boxrule=1pt,
  left=7mm, right=2mm, top=1mm, bottom=1.5mm,
  before=\vspace{1.25mm},
  after=\vspace{0mm},
  % This adds the attribution at the bottom if the argument is provided
  after upper={
    \ifstrempty{#1}{}{ % If argument #1 is not empty
    \nopagebreak\vspace{#2}
      \begin{flushright}
        \textemdash\ \textbf{#1}
      \end{flushright}
    }
  },
  overlay={
    \node[anchor=north west, 
          font=\fontsize{12pt}{12pt}\selectfont, 
          text=magHighlight!80] 
          at ([xshift=.5mm, yshift=1.75mm]frame.north west) {\faQuoteLeft};
  }
}

\newenvironment{transtable}
{\begin{tcolorbox}[
  colback=magHighlight!10,
  colframe=magHighlight,
  boxrule=1pt,
  arc=1mm,
  fontupper=\footnotesize,
  boxsep=0pt,
  left=1mm, 
  right=1.5mm, 
  top=.5mm, 
  bottom=.5mm,
  before upper=\par\noindent,
]
\setlength{\extrarowheight}{0pt}
\begin{tabular*}{\linewidth}{%
  @{} l @{\extracolsep{\fill}} r 
  !{\extracolsep{0pt}\hspace{0.0em}\vrule\hspace{0.0em}} % Forces space on BOTH sides of the line
  l @{\extracolsep{\fill}} r 
  @{\extracolsep{0pt}} % Resets the filler for the last edge
  @{}
}
}
{\end{tabular*}\end{tcolorbox}}

% Hook for Odia
\gappto\captionsodia{%
  \def\artprobname{ସମସ୍ୟା}%
}
% Hook for English
\gappto\captionsenglish{%
  \def\artprobname{Problem}%
}

\newtcolorbox[auto counter, number within=chapter, number freestyle={\noexpand\arabic{\tcbcounter}}]{artproboxtemplate}[2]{%
  enhanced,
  breakable,
  colback=magHighlight!10,
  colframe=white,
  boxrule=1pt,
  left=1mm,
  right=1mm,
  top=.5mm,
  bottom=.5mm,
  attach title to upper,
  after title={\vskip 0.05in},
  fonttitle=\fontsize{12pt}{12pt}\selectfont\bfseries,
  % --- Manual Title Construction ---
  title={%
    \tcbox[
    on line, 
    boxrule=0pt, 
    colback=white, 
    colframe=magHighlight, 
    arc=1pt,
    size=small,
    top=1pt, bottom=.5pt, left=1pt, right=1pt
    ]{%\color{black}\artprobname~\arabic{\tcbcounter}%
    \color{black}\artprobname~\thetcbcounter%
      \ifstrempty{#1}{}{ (#1)}% Add subtitle in () only if #1 is provided
    }%
  },
  label={artprob:#2}
}

\NewDocumentEnvironment{artprobox}{o}
{%
  \IfNoValueTF{#1}
    {\begin{artproboxtemplate}{}{}}
    {\begin{artproboxtemplate}{}{#1}}
}
{%
  \end{artproboxtemplate}
}

\newtcolorbox[auto counter, number within = chapter, number freestyle={\noexpand\arabic{\tcbcounter}}]{comprobox}{
  enhanced,
  breakable,
  colback=magHighlight!10,
  colframe=white,
  boxrule=1pt,
  left=1mm, right=1mm, top=.5mm, bottom=.5mm,
  before=\vspace{1.25mm},
  after=\vspace{0mm},
  %title={\color{black}\arabic{\tcbcounter}.},
  title={\color{black}\thetcbcounter.},
  fonttitle=\fontsize{12pt}{12pt}\selectfont\bfseries,
  attach title to upper,  
  after title={\hspace{2mm}},
}
\newenvironment{compsol}[1][S]{%
  \pushQED{\qed}%
  \noindent $\blacktriangleright \blacktriangleright$\quad%
\raggedright%
}{%
  \popQED%
  \medskip%
}

% Define question box style
\newtcolorbox{questionbox}{
  enhanced,
  breakable,
  colback=magHighlight!10,
  colframe=white,
  boxrule=1pt,
  left=1mm, right=1mm, top=1mm, bottom=.5mm,
  before=\vspace{1.25mm},
  after=\vspace{0mm},
  title={\tcbox[
    on line, 
    boxrule=0pt, 
    colback=magHighlight, 
    colframe=magHighlight, 
    arc=1pt, 
    boxsep=1.2pt,
    top=0pt, bottom=0pt, left=0pt, right=0pt
  ]{\color{white}\faQuestionCircle}},
  fonttitle=\fontsize{12pt}{12pt}\selectfont\bfseries,
  attach title to upper,
  after title={\enspace},
}


% Problem/Solution Zone
\newtcolorbox{problem}[2][]{%
  colback=white,
  colframe=magHighlight!75,
  boxrule=0.5pt,
  arc=1mm,
  left=4pt, right=4pt, top=2pt, bottom=1mm,
  fontupper=\small,
  after=\vspace{-3mm},
  title={\textbf{Problem~#2}},
   #1
}
\newenvironment{solution}[1][Solution]{%
  \par\medskip
  \noindent\textbf{#1.} \quad
}{%
  \hfill$\square$\par\medskip
}

% Solid header

\newtcolorbox{solidheader}{
  colback=magHighlight,
  colframe=magHighlight,
  width=\textwidth,
  arc=0mm,
  boxrule=0pt,
  left=4mm,
  right=3mm,
  top=4mm,
  bottom=4mm
}

% Float spacing tweaks
\setlength{\textfloatsep}{8pt}
\setlength{\floatsep}{8pt}
\setlength{\intextsep}{8pt}

\newcommand{\fixedtt}[1]{%
{\XeTeXinterchartokenstate=0\texttt{#1}}%
}

\endinput