/* ═══════════════════════════════════════════════════════════
   TYPOGRAPHY & LAYOUT -- designed for long-form reading
   ═══════════════════════════════════════════════════════════ */

:root {
    --bg: #fdfbf7;
    --text: #2c2c2c;
    --text-light: #555;
    --accent: #8b4513;
    --accent-light: #a0522d;
    --border: #e0d5c7;
    --blockquote-bg: #f5f0e8;
    --nav-bg: #f8f5f0;
    --hover-bg: #ede4d8;
    --max-width: 700px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1a1a1a;
        --text: #d4d4d4;
        --text-light: #999;
        --accent: #c9956b;
        --accent-light: #daa87c;
        --border: #333;
        --blockquote-bg: #252525;
        --nav-bg: #1e1e1e;
        --hover-bg: #2a2a2a;
    }
}

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

html {
    font-size: 18px;
    scroll-behavior: smooth;
}

body {
    font-family: Georgia, "Times New Roman", "Noto Serif", serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.8;
    -webkit-font-smoothing: antialiased;
}

/* ── Top navigation bar ── */
.top-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 48px;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    z-index: 100;
    gap: 8px;
    font-size: 0.8rem;
}

.top-bar a, .top-bar .nav-label {
    color: var(--text-light);
    text-decoration: none;
    padding: 4px 10px;
    border-radius: 4px;
    white-space: nowrap;
    border: 1px solid transparent;
}

.top-bar a:hover { background: var(--hover-bg); color: var(--accent); }

.top-bar .book-title {
    flex: 1;
    text-align: center;
    font-weight: bold;
    color: var(--accent);
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-bar .nav-arrow { font-size: 1.1rem; padding: 4px 8px; }

.top-bar .theme-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-light);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.75rem;
}

.top-bar .theme-btn:hover { background: var(--hover-bg); }

.top-bar .reading-time {
    font-size: 0.7rem;
    color: var(--text-light);
    opacity: 0.6;
    white-space: nowrap;
}

/* ── Voice selector ── */
.top-bar .voice-select {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-light);
    padding: 3px 6px;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.7rem;
    cursor: pointer;
    max-width: 100px;
}

.top-bar .voice-select:hover { background: var(--hover-bg); }

/* ── Right-margin click-to-speak ── */
main p, main blockquote { position: relative; }

.tts-indicator {
    position: fixed;
    pointer-events: none;
    width: 48px;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.15s;
    border-radius: 0 4px 4px 0;
    background: linear-gradient(to right, rgba(139,69,19,0.03) 0%, rgba(139,69,19,0.10) 100%);
}

@media (hover: hover) {
    .tts-indicator.active { opacity: 1; }
}

main p.speaking,
main blockquote.speaking {
    background: rgba(139, 69, 19, 0.08);
    border-left: 3px solid var(--accent);
    padding-left: 12px !important;
    margin-left: -15px;
    border-radius: 0 4px 4px 0;
    transition: background 0.2s, border-color 0.2s;
}

/* ── Progress bar ── */
.progress-bar {
    position: fixed;
    top: 48px; left: 0;
    height: 3px;
    background: var(--accent);
    z-index: 150;
    transition: width 0.1s linear;
}

/* ── Main content ── */
main {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 70px 24px 40px;
}

/* ── Chapter headings ── */
.part-label {
    text-align: center;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--accent);
    margin: 20px 0 6px;
}

.part-subtitle {
    text-align: center;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text);
    margin-bottom: 30px;
}

.chapter-num {
    text-align: center;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent);
    margin-bottom: 4px;
}

.chapter-title {
    text-align: center;
    font-size: 1.4rem;
    font-weight: bold;
    margin-bottom: 28px;
    color: var(--text);
}

.front-matter-title {
    text-align: center;
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--accent);
    letter-spacing: 0.08em;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

/* ── Body text ── */
p {
    margin-bottom: 1em;
    text-indent: 1.5em;
    text-align: justify;
    hyphens: auto;
}

p.no-indent,
.chapter-num + p, .chapter-title + p, .part-label + p,
.part-subtitle + p, .front-matter-title + p,
.section-break + p, hr + p,
blockquote + p:not(.no-indent) {
    text-indent: 0;
}

/* Drop cap for first paragraph */
.chapter-num + p::first-letter,
.chapter-title + p::first-letter,
.part-subtitle + p::first-letter {
    float: left;
    font-size: 3.1em;
    line-height: 0.8;
    padding-right: 8px;
    padding-top: 4px;
    color: var(--accent);
    font-weight: bold;
}

/* ── Section break ── */
.section-break {
    text-align: center;
    margin: 30px 0;
    border: none;
}

.section-break::before {
    content: "* * *";
    color: var(--border);
    letter-spacing: 0.5em;
}

/* ── Blockquotes ── */
blockquote {
    margin: 1.2em 0 1.2em 2em;
    padding: 8px 0 8px 20px;
    border-left: 3px solid var(--accent);
    font-size: 0.92em;
    color: var(--text-light);
    background: var(--blockquote-bg);
}

blockquote p {
    text-indent: 0;
    margin-bottom: 0.4em;
}

/* ── Images ── */
figure {
    text-align: center;
    margin: 30px 0;
}

figure img, p img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

figure figcaption, p:has(img) + p {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 6px;
    font-style: italic;
    text-indent: 0;
    text-align: center;
}

/* ── Footnotes ── */
sup, .footnote-ref {
    font-size: 0.7em;
    line-height: 0;
}

sup a, .footnote-ref a {
    color: var(--accent-light);
    text-decoration: none;
}

sup a:hover { text-decoration: underline; }

/* ── Front/back matter ── */
.front-matter p { text-indent: 0; }

.reference p {
    text-indent: 0;
    margin-bottom: 0.3em;
    font-size: 0.85rem;
    line-height: 1.5;
}

/* ── Bottom navigation ── */
.bottom-nav {
    max-width: var(--max-width);
    margin: 50px auto 30px;
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
}

.bottom-nav a {
    color: var(--accent);
    text-decoration: none;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.bottom-nav a:hover { background: var(--hover-bg); }

.bottom-nav .toc-link {
    color: var(--text-light);
    border-color: transparent;
}

/* ── Scroll to top ── */
.scroll-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--nav-bg);
    color: var(--text-light);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 200;
}

.scroll-top.visible { opacity: 1; }
.scroll-top:hover { background: var(--hover-bg); }

/* ── Responsive ── */
@media (max-width: 600px) {
    html { font-size: 16px; }
    main { padding: 60px 16px 30px; }
    .chapter-title { font-size: 1.2rem; }
    .part-subtitle { font-size: 1.05rem; }
    blockquote { margin-left: 0.8em; padding-left: 12px; }
}

@media print {
    .top-bar, .bottom-nav, .scroll-top, .progress-bar { display: none !important; }
    main { margin-top: 0 !important; padding-top: 20px !important; }
    body { font-size: 12pt; color: #000; background: #fff; }
    a { color: #000; text-decoration: none; }
}
