% ============================================================
%  STORES FROM GRAILHEART VOL. 2 — Master File
%  Compiler: XeLaTeX
%  Trim size: 6" x 9"  (KDP standard)
% ============================================================

\documentclass[12pt, twoside, openright]{book}

% ── Page geometry ────────────────────────────────────────────
\usepackage[
paperwidth  = 6in,
paperheight = 9in,
inner       = 1.02in,     % Gutter for binding
outer       = 36pt,     
top         = 48pt,     
bottom      = 67.5pt,   
includeheadfoot,
headsep     = 0.25in,
footskip    = 0.45in,    
]{geometry}

% ── Font (XeLaTeX) ───────────────────────────────────────────
\usepackage{fontspec}
\setmainfont{Caudex}[
UprightFont    = *,
BoldFont       = * Bold,
ItalicFont     = * Italic,
BoldItalicFont = * Bold Italic,
]

% ── Core packages ────────────────────────────────────────────
\usepackage[protrusion=true]{microtype}
\emergencystretch=1.25em
\usepackage{setspace}      
\usepackage{needspace}    
\usepackage{emptypage}         
\usepackage{titlesec}          
\usepackage{titletoc}          
\usepackage[skip=0.8em]{parskip}
\usepackage{fancyhdr}          
\usepackage{wrapfig}
\usepackage{comment}
\usepackage[
hang,
flushmargin,
norule,
multiple,
]{footmisc}                    
\usepackage{lettrine}
\usepackage{graphicx}

\usepackage[cam,letter,center,noinfo]{crop}   % CROP MARKS

% ── Hyperref ─────────────────────────────────────────────────
\usepackage[hidelinks]{hyperref}
\usepackage{bookmark}

% ── Line spacing ─────────────────────────────────────────────
\setstretch{1.15}

% ── Headers & footers (Dynamic Chapter Footers) ────────────────
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}

\fancyfoot[RO]{\small\thepage}
\fancyfoot[LE]{\small\thepage}

\fancypagestyle{plain}{%
    \fancyhf{}
    \fancyfoot[C]{\small\thepage}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
}

% ── TOC Customization (Maximum Tightness) ─────────────────────
\titlecontents{chapter}
[3.8em]                           % left indent    
{\addvspace{0.1pc}\normalfont}        
{\contentslabel{3.8pt}}               
{\hspace{-3.8em}}                     
{\titlerule*[0.8pc]{.}\contentspage} 
[] 

% Use this instead?
%\titlecontents{chapter}
%[0pt] % Left indent
%{\addvspace{0.6em}\normalfont} % Space above entries
%{} % Formatting for numbered entries (left blank)
%{} % Formatting for unnumbered entries
%{\titlerule*[0.8pc]{.}\contentspage} % Leader dots and page number
%[]

% ── Chapter Logic Flags ──────────────────────────────────────
\newif\ifintoc
\newif\ifinsuggested 

% ── Minimal Chapter Style (To work with \herosection) ─────────
\titleformat{\chapter}[display]
{\normalfont} 
{\vspace{-5em}} 
{0pt}
{\phantom} 
[]

\titlespacing*{\chapter}{0pt}{0pt}{0pt}

% ── Section/Hero Settings ────────────────────────────────────
\newcommand{\herosection}[2]{%
    \cleardoublepage
    \addcontentsline{toc}{chapter}{#1} 
    \begin{figure}[h!]
        \centering
        \includegraphics[width=\textwidth]{#2}
    \end{figure}
    \vspace{0.25em}
    {\Large\bfseries #1\par}
    \vspace{0.25em}
}

\newcommand{\textchapter}[1]{%
    \cleardoublepage
    \addcontentsline{toc}{chapter}{#1} 
    % We change \baselineskip to a fixed 0.6em to avoid the "double-line" look
    %\addtocontents{toc}{\protect\vspace{0.6em}} 
    %\vspace*{2\baselineskip}           
    {\centering \LARGE\bfseries #1\par} 
    \vspace{3ex}                       
}

\newcommand{\DROPCAP}[1]{%
    \setlength{\columnsep}{0.2em}%
    \begin{wrapfigure}[3]{l}{0pt}
        \raisebox{-2.2\baselineskip}[0pt][0pt]{ 
            \includegraphics[height=3.0\baselineskip]{#1}%
        }%
    \end{wrapfigure}%
}

% ── Typography Cleanup ───────────────────────────────────────
\setlength{\parindent}{0pt}
\setlength{\footnotesep}{0.5em}
\setcounter{tocdepth}{1}
\setcounter{secnumdepth}{-1}

\makeatletter
\def\@afterheading{}
\makeatother

\raggedbottom
\widowpenalty=10000
\clubpenalty=10000

\makeatletter
\renewcommand{\@pnumwidth}{2.0em} % Increases space for page numbers
\renewcommand{\@tocrmarg}{3.0em}  % Adjusts the right margin to match
\makeatother

% ============================================================
%  DOCUMENT
% ============================================================
\begin{document}
    
    % ── Front matter ─────────────────────────────────────────────
    \frontmatter
    \pagestyle{empty}
    
    \input{frontmatter/titlepage}
    \input{frontmatter/copyrightpage}
    \cleardoublepage
    
    \pagestyle{fancy}
    \intoctrue                  
    
    % Manual TOC Title logic
    \cleardoublepage
    {\centering \LARGE\scshape Contents \par}
    \vspace{1ex} % Tightened header-to-first-entry space
    
    \begingroup
    \let\clearpage\relax      
    \setstretch{1.0}          
    \setlength{\parskip}{0pt} 
    \tableofcontents
    \endgroup
    
    \intocfalse                 
    \cleardoublepage

    % ── Main matter ──────────────────────────────────────────────
    \mainmatter

    \cleardoublepage
    \null
    \thispagestyle{empty}
    \cleardoublepage
    
    \input{chapters/JourneyContinues.tex}

    \cleardoublepage
    \null
    \thispagestyle{empty}
    \cleardoublepage
    
    \input{chapters/2025.10.28-TailorOfTheSky.tex}     % KEEP FIRST
    \input{chapters/2025.09.09-TheLostSheep.tex}
    \input{chapters/2026.05.16-TheBooksOfTorin.tex}     % KEEP BEGIN + 3
    \input{chapters/2025.09.16-SongOfTheThirdWay.tex}
    \input{chapters/2025.09.28-TheGardenThatWouldNotHurry.tex}
    \input{chapters/2025.10.06-TheWaywardGift.tex}
    \input{chapters/2025.10.21-TheMirrorThatKnew.tex}
    \input{chapters/2025.10.23-TheShepherdOfSouls.tex}     
    \input{chapters/2025.11.04-TheAtlasOfTheHumanHeart.tex}
    \input{chapters/2025.11.11-WarmBread.tex}
    \input{chapters/2025.11.20-TheLanternOfDanger.tex}
    \input{chapters/2025.12.02-TheUnknownPath.tex}
    \input{chapters/2025.12.09-TheLedger.tex}    
    \input{chapters/2025.12.16-CarryingTheDream.tex}
    \input{chapters/2025.12.23-TheBoneFlute.tex}
    \input{chapters/2025.12.24-TheMagesWheels.tex}
    \input{chapters/2025.12.30-TheMusicCritic.tex}
    \input{chapters/2026.01.14-TheBoyAtTheBellows.tex}
    \input{chapters/2026.01.21-TheySimplyLightTheWay.tex}
    \input{chapters/2026.01.27-TheWomanWhoHeardMore.tex}
    \input{chapters/2026.01.28-TheDinnerParty.tex}
    \input{chapters/2026.02.03-TheWardenAtTheGate.tex}
    \input{chapters/2026.02.11-TheCinderSweeper.tex}
    \input{chapters/2026.04.21-TheHive.tex}
    \input{chapters/2026.02.24-StoneAndLight.tex}
    \input{chapters/2026.03.03-TheSage.tex}
    \input{chapters/2026.03.04-ThreeOffenses.tex}
    \input{chapters/2026.03.24-TheMasonAndTheTower.tex}
    \input{chapters/2025.11.10-TheLifeOfARock.tex}    % KEEP END -3
    \input{chapters/2026.04.07-TheForgottenLamp.tex}
    \input{chapters/2026.02.16-Devotion.tex}

    \cleardoublepage
    \null
    \thispagestyle{empty}
    \cleardoublepage

    \input{backmatter/AboutTheAuthor.tex}
    \input{backmatter/EndBlurb.tex}

\end{document}
