/* Explain: CSS styling for the classic book page, including cover, table of contents, chapter layout, and download button styles. */
/* ============================================================
   Book — classic paper reading experience
   ============================================================ */

/* Reading progress bar */
.book-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 100;
    background: linear-gradient(90deg, var(--secondary-color), var(--primary-color));
    transform: scaleX(0);
    transform-origin: right center;
    transition: transform 0.12s linear;
    pointer-events: none;
}

/* Back to top */
.book-top {
    position: fixed;
    left: 1.25rem;
    bottom: 1.25rem;
    z-index: 90;
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 9999px;
    border: 1px solid var(--gold-line);
    background: rgba(11, 11, 13, 0.85);
    color: var(--primary-color);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease, background 0.25s ease, color 0.25s ease;
}

.book-top.is-visible {
    opacity: 1;
    visibility: visible;
    transform: none;
}

.book-top:hover {
    background: var(--primary-color);
    color: #12100a;
}

/* ---------- Cover ---------- */
.book-cover-section {
    position: relative;
    overflow: hidden;
    border-bottom: 1px solid var(--border-color);
}

.book-cover {
    position: relative;
    width: min(100%, 26rem);
    min-height: 33rem;
    margin-inline: auto;
    padding: 2.5rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
    text-align: center;
    border-radius: 0.4rem;
    background:
        linear-gradient(135deg, rgba(201, 162, 39, 0.18), transparent 58%),
        linear-gradient(180deg, #1b1710, #0e0c09);
    border: 1px solid var(--gold-line);
    box-shadow: 0 34px 70px rgba(0, 0, 0, 0.6);
}

.book-cover::before {
    content: '';
    position: absolute;
    inset: 0.85rem;
    border: 1px solid rgba(201, 162, 39, 0.38);
    border-radius: 0.2rem;
    pointer-events: none;
    z-index: 0;
}

.book-cover::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: 1.5rem;
    border-radius: 0 0.4rem 0.4rem 0;
    background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.55));
    pointer-events: none;
    z-index: 0;
}

.book-cover > * {
    position: relative;
    z-index: 1;
}

.book-cover-portrait {
    width: 7rem;
    height: 7rem;
    border-radius: 9999px;
    overflow: hidden;
    border: 2px solid var(--gold-line);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
}

.book-cover-portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-cover-orn {
    color: var(--primary-color);
    font-size: 1rem;
    letter-spacing: 0.3em;
}

.book-cover-title {
    font-family: var(--font-heading);
    font-weight: 900;
    font-size: clamp(2rem, 7vw, 2.9rem);
    line-height: 1.12;
    background: linear-gradient(135deg, #f7e9b8, var(--primary-color) 55%, #a8841b);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.book-cover-sub {
    color: #d9d5c8;
    font-size: 1.05rem;
}

.book-cover-rule {
    display: block;
    width: 4.5rem;
    height: 1px;
    background: var(--gold-line);
    margin-block: 0.35rem;
}

.book-cover-author {
    color: var(--primary-color);
    font-family: var(--font-heading);
    font-size: 1rem;
    letter-spacing: 0.08em;
}

.book-cover-statement {
    margin-top: 0.5rem;
    color: #e7dfcb;
    font-family: var(--font-heading);
    font-size: 0.98rem;
    font-style: italic;
    line-height: 1.6;
    max-width: 20rem;
}

/* ---------- Paper surface ---------- */
.book-reader {
    position: relative;
}

.book-paper {
    position: relative;
    max-width: 52rem;
    margin-inline: auto;
    padding: 2rem 1.4rem;
    border-radius: 0.75rem;
    border: 1px solid var(--paper-border);
    background: var(--paper-color);
    color: var(--ink-color);
    box-shadow: 0 28px 60px rgba(0, 0, 0, 0.55);
}

@media (min-width: 768px) {
    .book-paper {
        padding: 3.75rem 3.5rem;
    }
}

.book-paper::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background:
        radial-gradient(circle at 16% 6%, rgba(120, 95, 45, 0.07), transparent 42%),
        radial-gradient(circle at 84% 94%, rgba(120, 95, 45, 0.06), transparent 42%);
}

.book-reader .book-paper + .book-paper {
    margin-top: 2.5rem;
}

/* ---------- Table of contents ---------- */
.book-ornament {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin: 0;
    color: #8a6d14;
    font-size: 1rem;
}

.book-ornament span {
    display: inline-block;
    width: 3rem;
    height: 1px;
    background: var(--paper-rule);
}

.book-toc-title {
    margin-top: 0.75rem;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(1.6rem, 4vw, 2rem);
    text-align: center;
    color: var(--ink-color);
}

.book-toc {
    list-style: none;
    margin: 2rem 0 0;
    padding: 0;
}

.book-toc-item + .book-toc-item {
    border-top: 1px dashed var(--paper-rule);
}

.book-toc-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 0.25rem;
    color: var(--ink-color);
    text-decoration: none;
    transition: color 0.25s ease;
}

.book-toc-link:hover {
    color: #8a6d14;
}

.book-toc-num {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 9999px;
    border: 1px solid var(--paper-border);
    font-family: var(--font-heading);
    font-weight: 700;
    color: #8a6d14;
}

.book-toc-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.book-toc-chapter {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.12rem;
    line-height: 1.35;
}

.book-toc-sub {
    margin-top: 0.15rem;
    font-size: 0.85rem;
    color: var(--ink-muted);
}

.book-toc-arrow {
    margin-inline-start: auto;
    color: var(--paper-rule);
    transition: transform 0.25s ease, color 0.25s ease;
}

.book-toc-link:hover .book-toc-arrow {
    color: #8a6d14;
    transform: translateX(-4px);
}

.book-empty {
    margin-top: 1.5rem;
    text-align: center;
    color: var(--ink-muted);
}

/* ---------- Chapter ---------- */
.book-chapter-head {
    text-align: center;
    margin-bottom: 2rem;
}

.book-chapter-num {
    display: inline-block;
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: #8a6d14;
}

.book-chapter-title {
    margin-top: 0.6rem;
    font-family: var(--font-heading);
    font-weight: 900;
    font-size: clamp(1.7rem, 4.5vw, 2.5rem);
    line-height: 1.15;
    color: var(--ink-color);
}

.book-chapter-sub {
    margin-top: 0.5rem;
    color: var(--ink-muted);
    font-size: 1rem;
    font-style: italic;
}

/* ---------- Body text ---------- */
.book-body {
    margin-top: 1.75rem;
    font-size: 1.08rem;
    line-height: 1.95;
    color: var(--ink-color);
    text-align: justify;
}

.book-body p {
    margin-top: 1.15rem;
}

.book-body p:first-of-type {
    margin-top: 0;
}

.book-body h3 {
    margin-top: 1.75rem;
    font-family: var(--font-heading);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--ink-color);
}

.book-body ul,
.book-body ol {
    margin-top: 1rem;
    padding-inline-start: 1.5rem;
}

.book-body li {
    margin-top: 0.4rem;
}

.book-body a {
    color: #8a6d14;
}

.book-body > p:first-of-type::first-letter {
    float: right;
    margin: 0.2rem 0 0 0.6rem;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 3.2rem;
    line-height: 0.82;
    color: #8a6d14;
}

/* ---------- Pull quote ---------- */
.book-quote {
    margin-top: 2rem;
    padding: 1.4rem 1.6rem;
    border-inline-start: 3px solid var(--primary-color);
    border-radius: 0.5rem;
    background: rgba(201, 162, 39, 0.1);
}

.book-quote i {
    color: #8a6d14;
    font-size: 1.1rem;
}

.book-quote p {
    margin-top: 0.5rem;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    line-height: 1.7;
    color: var(--ink-color);
}

/* ---------- Chapter images ---------- */
.book-figure {
    margin: 2rem 0 0;
}

.book-figure-btn {
    display: block;
    width: 100%;
    padding: 0;
    border: 1px solid var(--paper-border);
    border-radius: 0.5rem;
    overflow: hidden;
    background: var(--paper-color-alt);
    cursor: pointer;
}

.book-figure-btn img {
    width: 100%;
    aspect-ratio: 3 / 2;
    object-fit: cover;
    transition: transform 0.6s ease;
}

.book-figure-btn:hover img {
    transform: scale(1.03);
}

.book-gallery {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 1.75rem;
}

@media (min-width: 640px) {
    .book-gallery {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.book-gallery-item {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    padding: 0;
    border: 1px solid var(--paper-border);
    border-radius: 0.4rem;
    overflow: hidden;
    background: var(--paper-color-alt);
    cursor: pointer;
}

.book-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.book-gallery-item:hover img {
    transform: scale(1.06);
}

@media (prefers-reduced-motion: reduce) {
    .book-figure-btn img,
    .book-gallery-item img {
        transition: none;
    }
}

/* ============================================================
   Autobiographical typography & preface
   ============================================================ */
.book-reader .book-body,
.book-reader .book-chapter-title,
.book-reader .book-toc-title,
.book-reader .book-toc-chapter,
.book-reader .book-body > p:first-of-type::first-letter,
.book-preface .book-body,
.book-preface .book-toc-title,
.book-preface .book-body > p:first-of-type::first-letter {
    font-family: 'David Libre', 'Frank Ruhl Libre', serif;
}

.book-reader .book-paper,
.book-preface .book-paper {
    background: linear-gradient(180deg, #f8f2e6, #eee4cd);
}

.book-preface .book-chapter-sub {
    margin-top: 0.5rem;
    color: var(--ink-muted);
    font-size: 1rem;
    font-style: italic;
    text-align: center;
}

.book-preface .book-body {
    margin-top: 1.75rem;
}

/* ============================================================
   Listen button (chapter read-aloud)
   ============================================================ */
.book-listen-wrap {
    display: flex;
    justify-content: center;
    margin-top: 1.4rem;
}

.book-listen-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    padding: 0.7rem 1.45rem;
    min-height: 44px;
    border-radius: 9999px;
    border: 1px solid var(--paper-border);
    background: rgba(201, 162, 39, 0.12);
    color: #8a6d14;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.98rem;
    cursor: pointer;
    transition: background 0.25s ease, border-color 0.25s ease, color 0.25s ease, transform 0.25s ease;
}

.book-listen-btn:hover {
    background: rgba(201, 162, 39, 0.22);
    border-color: #8a6d14;
    transform: translateY(-2px);
}

.book-listen-btn:focus-visible {
    outline: 2px solid #8a6d14;
    outline-offset: 3px;
}

.book-listen-btn.is-playing {
    background: #8a6d14;
    border-color: #8a6d14;
    color: #f8f2e6;
}

.book-listen-btn.is-playing .fa-solid {
    animation: book-listen-pulse 1.1s ease-in-out infinite;
}

.book-listen-btn.is-paused {
    background: rgba(201, 162, 39, 0.22);
    border-color: #8a6d14;
    color: #8a6d14;
}

.book-listen-btn.is-loading {
    opacity: 0.7;
    cursor: progress;
}

@keyframes book-listen-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.18); opacity: 0.75; }
}

/* ============================================================
   Download the book / a chapter as a PDF
   ============================================================ */
.book-toc-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.book-pdf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    padding: 0.7rem 1.45rem;
    min-height: 44px;
    border-radius: 9999px;
    border: 1px solid var(--paper-border);
    background: rgba(46, 196, 182, 0.1);
    color: #177f75;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.98rem;
    cursor: pointer;
    transition: background 0.25s ease, border-color 0.25s ease, color 0.25s ease, transform 0.25s ease;
}

.book-pdf-btn:hover {
    background: rgba(46, 196, 182, 0.2);
    border-color: #177f75;
    transform: translateY(-2px);
}

.book-pdf-btn:focus-visible {
    outline: 2px solid #177f75;
    outline-offset: 3px;
}

.book-pdf-btn.is-loading {
    opacity: 0.7;
    cursor: progress;
}

.book-pdf-btn.is-done {
    background: #177f75;
    border-color: #177f75;
    color: #f8f2e6;
}

.book-pdf-btn.is-error {
    border-color: #b4463d;
    color: #b4463d;
    background: rgba(180, 70, 61, 0.1);
}

.book-listen-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    padding: 0.7rem 1.45rem;
    min-height: 44px;
    border-radius: 9999px;
    border: 1px solid #177f75;
    background: rgba(46, 196, 182, 0.12);
    color: #177f75;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.98rem;
    text-decoration: none;
    transition: background 0.25s ease, color 0.25s ease, transform 0.25s ease;
}

.book-listen-link:hover {
    background: rgba(46, 196, 182, 0.22);
    color: #0f5f58;
    transform: translateY(-2px);
}

.book-listen-link:focus-visible {
    outline: 2px solid #177f75;
    outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
    .book-listen-btn,
    .book-listen-btn .fa-solid,
    .book-pdf-btn {
        transition: none;
        animation: none;
    }
}

/* ============================================================
   Chapter comments
   ============================================================ */
.book-comments {
    margin-top: 2.5rem;
    padding-top: 2rem;
    border-top: 1px dashed var(--paper-rule);
}

.book-comments-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0;
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--ink-color);
}

.book-comments-title .fa-solid {
    color: #8a6d14;
    font-size: 1.05rem;
}

.book-comments-count {
    display: inline-grid;
    place-items: center;
    min-width: 1.85rem;
    height: 1.85rem;
    padding-inline: 0.45rem;
    border-radius: 9999px;
    border: 1px solid var(--paper-border);
    background: rgba(201, 162, 39, 0.16);
    color: #8a6d14;
    font-size: 0.82rem;
    font-weight: 700;
}

.book-comment-form {
    display: grid;
    gap: 0.9rem;
    margin-top: 1.35rem;
    padding: 1.2rem 1.25rem 1.3rem;
    border: 1px solid var(--paper-border);
    border-radius: 0.7rem;
    background: rgba(255, 255, 255, 0.45);
}

.book-comment-label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink-color);
}

.book-comment-input {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border-radius: 0.5rem;
    border: 1px solid var(--paper-border);
    background: #fffdf7;
    color: var(--ink-color);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.book-comment-input::placeholder {
    color: #9c9382;
}

.book-comment-input:focus {
    outline: none;
    border-color: #8a6d14;
    box-shadow: 0 0 0 3px rgba(138, 109, 20, 0.14);
}

.book-comment-status {
    min-height: 1.2rem;
    margin: 0;
    font-size: 0.9rem;
    color: var(--ink-muted);
}

.book-comment-status.is-ok {
    color: #177f75;
}

.book-comment-status.is-err {
    color: #b4463d;
}

.book-comment-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    padding: 0.7rem 1.45rem;
    min-height: 44px;
    border-radius: 9999px;
    border: 1px solid #8a6d14;
    background: #8a6d14;
    color: #f8f2e6;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.98rem;
    cursor: pointer;
    transition: background 0.25s ease, transform 0.25s ease;
}

.book-comment-btn:hover {
    background: #6f5710;
    transform: translateY(-2px);
}

.book-comment-btn:focus-visible {
    outline: 2px solid #8a6d14;
    outline-offset: 3px;
}

.book-comment-btn:disabled {
    opacity: 0.65;
    cursor: progress;
}

.book-comment-list {
    list-style: none;
    margin: 1.6rem 0 0;
    padding: 0;
    display: grid;
    gap: 0.85rem;
}

.book-comment {
    padding: 1rem 1.1rem;
    border: 1px solid var(--paper-border);
    border-inline-start: 3px solid #8a6d14;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.5);
}

.book-comment-head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.book-comment-avatar {
    display: grid;
    place-items: center;
    width: 2.2rem;
    height: 2.2rem;
    flex: 0 0 auto;
    border-radius: 9999px;
    border: 1px solid var(--paper-border);
    background: rgba(201, 162, 39, 0.18);
    color: #8a6d14;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1rem;
}

.book-comment-name {
    font-family: var(--font-heading);
    font-weight: 700;
    color: var(--ink-color);
    overflow-wrap: anywhere;
}

.book-comment-date {
    margin-inline-start: auto;
    flex: 0 0 auto;
    color: var(--ink-muted);
    font-size: 0.78rem;
}

.book-comment-text {
    margin: 0.55rem 0 0;
    color: var(--ink-color);
    font-size: 1rem;
    line-height: 1.75;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.book-comments-empty {
    margin-top: 1.1rem;
    color: var(--ink-muted);
    font-size: 0.92rem;
}

@media (prefers-reduced-motion: reduce) {
    .book-comment-btn {
        transition: none;
        transform: none;
    }
}

/* ============================================================
   Read-aloud player (sticky bar)
   ============================================================ */
.book-player {
    position: fixed;
    z-index: 95;
    inset-inline: 1rem;
    bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    max-width: 46rem;
    margin-inline: auto;
    padding: 0.7rem 0.9rem;
    border: 1px solid var(--gold-line);
    border-radius: 9999px;
    background: rgba(11, 11, 13, 0.94);
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow-soft);
}

.book-player[hidden] {
    display: none !important;
}

.book-player-btn {
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    flex: 0 0 auto;
    border-radius: 9999px;
    border: 1px solid var(--border-color);
    background: var(--surface-2);
    color: var(--text-color);
    cursor: pointer;
    transition: border-color 0.25s ease, color 0.25s ease, background 0.25s ease;
}

.book-player-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.book-player-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.book-player-info {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
}

.book-player-label {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-player-status {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-player-track {
    position: relative;
    flex: 1 1 9rem;
    min-width: 4rem;
    height: 0.55rem;
    border-radius: 9999px;
    border: 1px solid var(--border-color);
    background: var(--surface-2);
    direction: ltr;
    cursor: pointer;
}

.book-player-track:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 3px;
}

.book-player-fill {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 0;
    border-radius: 9999px;
    background: linear-gradient(90deg, var(--secondary-color), var(--primary-color));
}

.book-player-time {
    flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
    font-size: 0.78rem;
    color: var(--text-muted);
}

@media (max-width: 40rem) {
    .book-player {
        border-radius: 1rem;
    }

    .book-player-info {
        display: none;
    }
}

.book-player-open .book-top,
.book-player-open .a11y-widget {
    bottom: 6.5rem;
}

@media (prefers-reduced-motion: reduce) {
    .book-player-btn {
        transition: none;
    }
}