/* Front matter section styles */

section.front-matter-content {
    break-before: right;
}

/* Section assignment */
.front-matter {
    page: front-matter;
}

/* Page numbering for front matter */
.front-matter .page-number {
    counter-increment: page;
}

.front-matter.toc-page-ref{

}

.front-matter .page-number::after {
    content: counter(page, lower-roman);
}

/* Front matter page layouts */
@page front-matter:left {
    @top-left {
        content: string(book-title);
    }

    @bottom-center {
        content: counter(page, lower-roman);
    }
}

@page front-matter:right {
    @top-right {
        content: string(book-title);
    }

    @bottom-center {
        content: counter(page, lower-roman);
    }
}

/* Table of Contents styling */
.table-of-contents {
    margin: 1em 0;
}

.toc-entry {
    display: flex;
    align-items: baseline;
    margin-bottom: 0.5em;
    line-height: 1.4;
}

.toc-entry.toc-level-1 {
    font-weight: bold;
    margin-top: 1em;
}

.toc-entry.toc-level-2 {
    margin-left: 1em;
    font-weight: normal;
}

.toc-entry.toc-level-3 {
    margin-left: 2em;
    font-weight: normal;
    font-size: 0.9em;
}

.toc-link {
    text-decoration: none;
    color: inherit;
    flex-grow: 1;
}

.toc-link:hover {
    text-decoration: underline;
}

.toc-page-ref {
    margin-left: auto;
    text-align: right;
    min-width: 2em;
}

/* PagedJS page numbering for TOC */
/* .toc-page-ref::after {
    content: target-counter(attr(href), page);
}
 */
/* Dotted leading for TOC entries */
.toc-entry.toc-dotted .toc-link::after {
    content: "";
    flex-grow: 1;
    border-bottom: 1px dotted currentColor;
    margin: 0 0.5em;
    height: 0;
    min-width: 1em;
}

.toc-entry.toc-dotted {
    display: flex;
    align-items: baseline;
}

.toc-entry.toc-dotted .toc-page-ref {
    margin-left: 0;
}

.toc-page-ref::after { 
    content: target-counter(attr(data-target), page); 
}

/* Section-specific TOC page number formatting */
.toc-entry.toc-front-matter .toc-page-ref::after,
.toc-page-ref.toc-front-matter::after { 
    content: target-counter(attr(data-target), page, lower-roman); 
}

/* Backward compatibility with old class names */
.toc-page-ref.front::after { 
    content: target-counter(attr(data-target), page, lower-roman); 
}

/* Arc title styling for show-arcs-as-top-level */
.toc-entry.toc-arc {
    font-weight: bold;
    margin-top: 1.5em;
    margin-bottom: 0.3em;
}

.toc-arc-title {
    font-style: italic;
    color: #666;
}

.toc-entry.toc-arc .toc-arc-title {
    flex-grow: 1;
}
