/* ==========================================================================
    Font Declarations
    ========================================================================== */
@font-face {
    font-family: charter;
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("/fonts/charter_regular.woff2") format("woff2");
}

@font-face {
    font-family: charter;
    font-style: italic;
    font-weight: 400;
    font-display: swap;
    src: url("/fonts/charter_italic.woff2") format("woff2");
}

@font-face {
    font-family: charter;
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("/fonts/charter_bold.woff2") format("woff2");
}

@font-face {
    font-family: charter;
    font-style: italic;
    font-weight: 700;
    font-display: swap;
    src: url("/fonts/charter_bold_italic.woff2") format("woff2");
}

/* ==========================================================================
       Reset & Design Tokens
       ========================================================================== */
:root {
    --bg-color: #f7f1e5;
    --bg-surface: #efe7d6;
    --text-main: #2e261f;
    --text-muted: #807164;
    --accent: #b4691e;
    --accent-light: rgba(180, 105, 30, 0.12);
    --border-color: rgba(60, 40, 20, 0.12);
    --shadow-cover: 0 16px 36px rgba(46, 38, 31, 0.18), 0 2px 6px rgba(46, 38, 31, 0.08);
    --shadow-desktop: 0 12px 32px rgba(46, 38, 31, 0.1);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ==========================================================================
       Mobile-First Base Layout
       ========================================================================== */
html {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: charter, Georgia, Cambria, serif;
    font-size: 17px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    min-height: 100vh;
}

.index-page {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 32px 20px 80px;
}

/* Cover section */
.cover-panel {
    display: flex;
    justify-content: center;
    margin-bottom: 2.5rem;
}

.book-cover {
    width: 220px;
    height: auto;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    display: block;
    border-radius: 6px;
    box-shadow: var(--shadow-cover);
    border: 1px solid var(--border-color);
}

/* TOC list */
.toc-panel {
    width: 100%;
}

.toc-header {
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--border-color);
}

.toc-title {
    font-size: 1.4rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 700;
}

.toc-list {
    list-style: none;
    display: flex;
    flex-direction: column;
}

.toc-item {
    display: flex;
    align-items: baseline;
    text-decoration: none;
    color: var(--text-main);
    padding: 8px 6px;
    border-radius: 6px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.toc-item:hover {
    background-color: var(--accent-light);
    color: var(--accent);
}

.toc-chapter {
    flex-shrink: 0;
    max-width: 80%;
    line-height: 1.4;
    font-size: 1rem;
}

/* Dotted leader connection */
.toc-leader {
    flex-grow: 1;
    border-bottom: 1px dotted var(--text-muted);
    margin: 0 10px;
    opacity: 0.45;
    transform: translateY(-4px);
}

.toc-page {
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    font-size: 0.95rem;
    color: var(--text-muted);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-weight: 500;
}

.toc-item:hover .toc-page {
    color: var(--accent);
}

/* Italic styling for frontmatter and backmatter items */
.toc-list li:first-child .toc-chapter,
.toc-list li:nth-child(2) .toc-chapter,
.toc-list li:nth-last-child(-n+2) .toc-chapter {
    font-style: italic;
    color: var(--text-muted);
}

.toc-list li:first-child .toc-item:hover .toc-chapter,
.toc-list li:nth-child(2) .toc-item:hover .toc-chapter,
.toc-list li:nth-child(3) .toc-item:hover .toc-chapter,
.toc-list li:nth-last-child(-n+5) .toc-item:hover .toc-chapter {
    color: var(--accent);
}

/* ==========================================================================
       Desktop Dual-Pane Layout (min-width: 1000px)
       Cover: 400px (Fixed Left) | TOC: 500px (Scrollable Right)
       ========================================================================== */
@media (min-width: 1000px) {

    html,
    body {
        height: 100%;
        overflow: hidden;
        background-color: #eee7d8;
    }

    .index-page {
        position: relative;
        width: 900px;
        max-width: 900px;
        height: 100vh;
        margin: 0 auto;
        padding: 0;
        background-color: var(--bg-color);
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
        box-shadow: var(--shadow-desktop);
        display: flex;
        overflow: hidden;
    }

    /* Fixed 400px Cover on the Left */
    .cover-panel {
        position: fixed;
        top: 0;
        width: 400px;
        height: 100vh;
        margin: 0;
        border-right: 1px solid var(--border-color);
        background-color: var(--bg-surface);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 10;
    }

    .book-cover {
        width: 270px;
        border-radius: 8px;
        box-shadow: 0 20px 42px rgba(46, 38, 31, 0.24);
    }

    /* Scrollable 500px Navigation on the Right */
    .toc-panel {
        width: 500px;
        margin-left: 400px;
        height: 100vh;
        overflow-y: auto;
        padding: 40px 35px 80px;
        scrollbar-gutter: stable;
    }

    .toc-header {
        position: sticky;
        top: 0;
        background-color: var(--bg-color);
        padding-top: 10px;
        z-index: 5;
    }
}

/* Bottom Jump Bar */
.toc-footer {
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
}

.jump-form {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.88rem;
}

.jump-label {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.jump-input {
    width: 76px;
    padding: 6px 10px;
    font-family: inherit;
    font-size: 0.88rem;
    color: var(--text-main);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    text-align: center;
    outline: none;
    -moz-appearance: textfield;
}

.jump-input::-webkit-outer-spin-button,
.jump-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.jump-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.jump-btn {
    padding: 6px 12px;
    background-color: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.jump-btn:hover {
    background-color: var(--accent-light);
    border-color: rgba(180, 105, 30, 0.3);
    color: var(--accent);
}

.jump-btn:active {
    transform: scale(0.96);
}

.jump-btn-random {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}