% ============================================================
%  LONGING — Master File
%  Compiler: XeLaTeX
%  Trim size: 6" x 9"  (KDP standard)
% ============================================================

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

% ── Page geometry ────────────────────────────────────────────
\usepackage[
  paperwidth  = 6in,
  paperheight = 9in,
  inner       = 0.9in,   % Total margin on binding side
  outer       = 36pt,
  top         = 48pt,
  bottom      = 67.5pt,
  includeheadfoot,
  headsep     = 0.25in,
  footskip    = 0.45in, % Ensure comma here if you add more keys later
]{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{lettrine}          
\usepackage{comment}
\usepackage[
hang,
flushmargin,
norule,
multiple,
]{footmisc}                    
\usepackage{lettrine}
\usepackage{graphicx}
\graphicspath{{../fern/}}


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

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

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

% Recto (odd/right): Section name (inside) / Page number (outside)
\fancyfoot[RO]{\small\thepage}
\fancyfoot[LO]{\small\itshape\nouppercase{\rightmark}}

% Verso (even/left): Page number (outside) / Chapter name (inside)
\fancyfoot[LE]{\small\thepage}
\fancyfoot[RE]{\small\itshape\nouppercase{\leftmark}}

% Plain style for chapter-opening pages (centered page number)
\fancypagestyle{plain}{%
	\fancyhf{}
	\fancyfoot[C]{\small\thepage}
	\renewcommand{\headrulewidth}{0pt}
	\renewcommand{\footrulewidth}{0pt}
}

% ── TOC Customization (Suppress Chapter Page Numbers) ────────
\titlecontents{chapter}
[0pt]                               
{\addvspace{1.5pc}\bfseries}        
{\contentslabel{0pt}}               
{}                                  
{}                                  
[\addvspace{2pt}]                   

% ── Solo Page Chapter Style ──────────────────────────────────
\newif\ifintoc
\newif\ifinsuggested 

%\titleformat{\chapter}[display]
%{\normalfont\large\bfseries\centering}
%{\ifintoc\else\ifinsuggested\else\vspace*{\fill}\fi\fi}            
%{0em}
%{\LARGE}
%[\ifintoc\else\ifinsuggested\else\vspace*{\fill}\thispagestyle{empty}\clearpage\fi\fi]

\titlespacing*{\chapter}{0pt}{\ifintoc 0pt \else \ifinsuggested 0pt \else -3em \fi \fi}{3em}

% ── Section heading style ────────────────────────────────────
%\titleformat{\section}
%{\normalfont\large\bfseries\centering}
%{}
%{0em}
%}
%titlespacing*{\section}{0pt}{2.5em}{1em}
%\newcommand{\sectionbreak}{\clearpage}
% ── Solo Page Chapter Style with Ornament ────────────────────
\newcommand{\chapterornament}{../art/13LineCollectionSqueebCreative.eps} % Default ornament

\newcommand{\sectionbreak}{\cleardoublepage}

\titleformat{\chapter}[display]
{\normalfont\centering}
{\ifintoc\else\vspace*{\fill}\fi} % Top stretch
{0em}
{\LARGE\scshape} % Large Small-Caps for the Title
[{
	\ifintoc\else
	\vspace{1.5ex}
	\begin{center}
		\includegraphics[width=0.25\textwidth]{\chapterornament}
	\end{center}
	\vspace*{\fill}
	\thispagestyle{empty}
	\cleardoublepage
	\fi
}]

% Reset spacing to handle the fill logic correctly
\titlespacing*{\chapter}{0pt}{0pt}{0pt}

\titleformat{\subsubsection}[block]
{\normalfont\bfseries}
{}
{0em}
{\noindent}

\titlespacing*{\subsubsection}{0pt}{1em}{0.5em}

\setlength{\parindent}{0pt}


% ── Misc Settings ────────────────────────────────────────────
\setlength{\footnotesep}{0.5em}
\setcounter{tocdepth}{1}
\setcounter{secnumdepth}{-1}

\makeatletter
\def\@afterheading{}
\makeatother

\raggedbottom

\widowpenalty=10000
\clubpenalty=10000

\hyphenation{Through-out}


% ============================================================
%  DOCUMENT
% ============================================================
\begin{document}
	
	% ── Front matter ─────────────────────────────────────────────
	\frontmatter
	\pagestyle{empty}
	
	\input{frontmatter/titlepage.tex}
	\input{frontmatter/copyrightpage.tex}
	\cleardoublepage
	
	\pagestyle{fancy}
	\intoctrue                  
	\tableofcontents
	\intocfalse                 
	\cleardoublepage

	
	% ── Main matter ──────────────────────────────────────────────
	\mainmatter
	
	\input{chapters/ch_Prologue.tex}
	\input{chapters/se_AlexanderLonging.tex}
	\input{chapters/se_PreludeToLonging.tex}
	
	\input{chapters/ch_CosmicLonging.tex}
	\input{chapters/se_SecondLawOfThermodynamics.tex}
	\input{chapters/se_BigBangToHeavyElements.tex}
	\input{chapters/se_AminoAcidSoupToItAlive.tex}
	\input{chapters/se_TheGreatOxidationExtinction.tex}
	\input{chapters/se_TheCambrianExplosion.tex}
	\input{chapters/se_HoldThatThought.tex}
	
	\input{chapters/ch_TwoWorlds.tex}
	\input{chapters/se_InnerAndOuterWorlds.tex}
	\input{chapters/se_TheImportanceOfOurInnerWorld.tex}
	\input{chapters/se_Transformation.tex}
	\input{chapters/se_TheHeraldsOfLonging.tex}
	
	\input{chapters/ch_TwoKindsOfPull.tex}
	\input{chapters/se_DesireSeeksStatis.tex}
	\input{chapters/se_TheGreeksAlreadyKnew.tex}
	\input{chapters/se_Plato.tex}
	\input{chapters/se_ErosInEarlyChristianity.tex}
	\input{chapters/se_LongingAndDesireADevelopmentalArc.tex}
	\input{chapters/se_TheSpeciesThatLongs.tex}
	\input{chapters/se_LongingBeforeConsciousness.tex}
	
	\input{chapters/ch_WhenceLonging.tex}
	\input{chapters/se_SomeSeemBornWithLonging.tex}
	\input{chapters/se_OthersHadLongingThrustUponThem.tex}
	\input{chapters/se_ArchetypePersephone.tex}
	\input{chapters/se_PersephoneConsidered.tex}
	\input{chapters/se_ArchetypeParzifal.tex}
	\input{chapters/se_ParzifalConsidered.tex}
	\input{chapters/se_TheHeroJourney.tex}
	\input{chapters/se_TheHeroJourneyConsidered.tex}
	\input{chapters/se_AnArchetypeTheShaman.tex}
	\input{chapters/se_TheSpectrumOfLonging.tex}
	\input{chapters/se_TheShapeOfAbsence.tex}
	
	\input{chapters/ch_DarkLonging.tex}
    \input{chapters/se_LongingIsNotAlwaysNoble.tex}
	\input{chapters/se_LongingsShadow.tex}
	
	\input{chapters/ch_NowWhat.tex}
	\input{chapters/se_LivingWithLonging.tex}
	\input{chapters/se_TheUnripenessProblem.tex}
	\input{chapters/se_TheReturnIsNotRestoration.tex}
	\input{chapters/se_TheChangingRelationship.tex}
	\input{chapters/se_ModernityMistake.tex}
	\input{chapters/se_WhyIsThereSomthing.tex}
	\input{chapters/se_PreludeToACreationStory.tex}
	\input{chapters/se_ACreationStory.tex}
	\input{chapters/coda.tex}

	\input{backmatter/ch_Epilogue.tex}
	\input{backmatter/se_SuggestedReading.tex}
	\input{backmatter/se_AboutTheAuthor.tex}
	
	\input{backmatter/EndBlurb.tex}
	
	
\end{document}
