/* Storyteller — Beautiful Manuscript Reader (Phase 3.6) */

#screen-chapter-reader {
    padding: 0;
    align-items: stretch;
    justify-content: flex-start;
    background: #fff;
    /* Document scroll: grow with the chapter; no nested viewport scroller. */
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    max-height: none;
    overflow: visible;
    box-sizing: border-box;
}

/* Shared brand bar sits above manuscript chrome; page pad only on the bar. */
#screen-chapter-reader > .brand-bar {
    width: 100%;
    box-sizing: border-box;
    padding: var(--st-page-pad-y) var(--st-page-pad-x) 8px;
    background: var(--st-bg);
}

.chapter-reader {
    --reader-ink: var(--st-ink-soft);
    --reader-muted: #8a8a8a;
    --reader-rule: var(--st-border);
    --reader-measure: var(--st-measure-reader);
    --reader-serif: var(--st-font-serif);
    --reader-sans: var(--st-font-sans);

    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--st-bg);
    color: var(--reader-ink);
}

/* Minimal chrome — top right only */

.chapter-reader-chrome {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 14px 28px 10px;
    background: #fff;
    border-bottom: 1px solid #f2f2f2;
}

/*
 * Calm Read Manuscript: hide version-management chrome in normal read mode.
 * Controls remain in the DOM for handlers; Version History / history mode
 * keeps its own full chrome. Manuscript should dominate the page.
 */
.chapter-reader[data-reader-mode="read"] .chapter-reader-read-mgmt {
    display: none !important;
}

.chapter-reader[data-reader-mode="read"] .chapter-reader-chrome-read {
    justify-content: space-between;
    border-bottom-color: transparent;
}

.chapter-reader[data-reader-mode="read"] .chapter-reader-chrome-read .chapter-reader-chrome-controls {
    margin-left: auto;
}

.chapter-reader-read-nav {
    flex: 0 1 auto;
    min-width: 0;
}

.chapter-reader-read-nav[hidden] {
    display: none !important;
}

.chapter-reader-section-nav {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.chapter-reader-section-nav-label {
    font-family: var(--reader-sans);
    font-size: 13px;
    color: var(--reader-muted);
}

.chapter-reader-section-select {
    min-height: 36px;
    max-width: min(280px, 42vw);
    padding: 6px 10px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    font-family: var(--reader-sans);
    font-size: 14px;
    color: var(--reader-ink);
    cursor: pointer;
}

.chapter-reader-section-select:hover,
.chapter-reader-section-select:focus {
    border-color: #e5e5e5;
    background: #fff;
    outline: none;
}

/*
 * Mode isolation — History / Compare chrome must never leak into Read.
 *
 * .chapter-reader-chrome and .chapter-reader-compare-bar use display:flex,
 * which outranks the bare [hidden] attribute (same bug class as AppScreen /
 * ProjectHome). Force collapse so empty bars leave no height, padding, or
 * border separators in the Read layout.
 */
.chapter-reader-chrome-read[hidden],
.chapter-reader-chrome-history[hidden],
.chapter-reader-compare-bar[hidden],
.chapter-reader[data-reader-mode="read"] .chapter-reader-chrome-history,
.chapter-reader[data-reader-mode="read"] .chapter-reader-compare-bar,
.chapter-reader[data-reader-mode="history"] .chapter-reader-compare-bar,
.chapter-reader[data-reader-mode="history"] .chapter-reader-chrome-read,
.chapter-reader[data-reader-mode="compare"] .chapter-reader-chrome-read {
    display: none !important;
    height: auto;
    min-height: 0;
    max-height: none;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    overflow: hidden;
    pointer-events: none;
}

.chapter-reader-chrome-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    min-width: 0;
}

.chapter-reader-version {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.chapter-reader-history-title {
    margin: 0 0 6px;
    font-family: var(--reader-sans);
    font-size: 15px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--reader-ink);
}

.chapter-reader-history-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 18px;
}

.chapter-reader-compare-bar {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
    padding: 10px 28px;
    background: #fff;
    border-bottom: 1px solid #f2f2f2;
}

.chapter-reader-compare-side {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}

.chapter-reader-compare-version-wrap[hidden] {
    display: none !important;
}

.chapter-reader-compare-view {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 28px 28px 80px;
    box-sizing: border-box;
}

.chapter-reader-compare-shell {
    width: 100%;
}

.chapter-reader-compare-mobile-toggle {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 20px;
}

.chapter-reader-compare-mobile-toggle .chapter-reader-history-btn.is-active {
    background: #f0f0f0;
    border-color: #cfcfcf;
}

.chapter-reader-compare-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 28px;
    align-items: start;
}

.chapter-reader-compare-column h2 {
    margin: 0 0 16px;
    font-family: var(--reader-sans);
    font-size: 15px;
    font-weight: 500;
    color: var(--reader-muted);
}

.chapter-reader-compare-column .chapter-reader-body {
    /* Reuse manuscript typography from the reader body. */
    font-family: var(--reader-serif);
}

/*
 * Side by Side: true two-column manuscript compare from 1024px up
 * (iPad landscape / large tablet / desktop). Narrow portrait tablets
 * and phones keep the existing single-pane + toggle.
 */
@media (max-width: 1023px) {
    .chapter-reader-compare-view {
        width: min(var(--reader-measure), 100%);
        max-width: var(--reader-measure);
    }

    .chapter-reader-compare-mobile-toggle {
        display: flex;
    }

    .chapter-reader-compare-columns {
        display: block;
        grid-template-columns: none;
    }

    /* One readable manuscript at a time — no compressed twin columns. */
    .chapter-reader-compare-shell[data-mobile-side="left"]
        .chapter-reader-compare-column[data-compare-side="right"],
    .chapter-reader-compare-shell[data-mobile-side="right"]
        .chapter-reader-compare-column[data-compare-side="left"] {
        display: none;
    }
}

.chapter-reader[data-reader-mode="history"] .chapter-reader-chrome-history:not([hidden]),
.chapter-reader[data-reader-mode="compare"] .chapter-reader-chrome-history:not([hidden]) {
    display: flex;
    pointer-events: auto;
}

.chapter-reader[data-reader-mode="compare"] .chapter-reader-compare-bar:not([hidden]) {
    display: flex;
    pointer-events: auto;
}

.chapter-reader-history-btn {
    min-height: 36px;
    padding: 6px 12px;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    background: #fff;
    font-family: var(--reader-sans);
    font-size: 13px;
    color: var(--reader-ink);
    cursor: pointer;
}

.chapter-reader-history-btn:hover:not(:disabled) {
    background: #f7f7f7;
    border-color: #d8d8d8;
}

.chapter-reader-history-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.chapter-reader-version-label {
    font-family: var(--reader-sans);
    font-size: 13px;
    color: var(--reader-muted);
}

.chapter-reader-version-select {
    min-height: 36px;
    padding: 6px 10px;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    background: #fff;
    font-family: var(--reader-sans);
    font-size: 14px;
    color: var(--reader-ink);
}

.chapter-reader-status-meta {
    margin: 0;
    font-family: var(--reader-sans);
    font-size: 13px;
    color: #888;
}

.chapter-reader-chrome-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px 18px;
}

.chapter-reader-chrome-btn {
    border: none;
    background: transparent;
    min-height: var(--st-touch);
    padding: 6px 4px;
    font-family: var(--reader-sans);
    font-size: 14px;
    font-weight: 400;
    color: #ccc;
    cursor: default;
    transition: color var(--st-duration) var(--st-ease);
}

.chapter-reader-chrome-btn.is-active {
    color: var(--reader-ink);
    cursor: pointer;
}

.chapter-reader-chrome-btn.is-active:hover {
    color: #000;
}

/* Available in history, but not selected until comparison mode is active. */
.chapter-reader-chrome-btn[data-action="history-compare"]:not(.is-active) {
    color: #c4c4c4;
    cursor: pointer;
}

.chapter-reader-chrome-btn[data-action="history-compare"]:not(.is-active):hover {
    color: #9a9a9a;
}

.chapter-reader-chrome-btn:disabled {
    color: #d4d4d4;
    cursor: default;
}

/* Scrollable manuscript page */

.chapter-reader-scroll {
    flex: 1 1 auto;
    overflow: auto;
    min-height: 0;
}

.chapter-reader-page {
    width: min(var(--reader-measure), 100%);
    margin: 0 auto;
    padding: 56px 48px 96px;
    opacity: 0;
    transition: opacity var(--st-duration-slow) var(--st-ease);
}

.chapter-reader-page.is-visible {
    opacity: 1;
}

/* Masthead */

.chapter-reader-masthead {
    text-align: center;
    margin-bottom: 56px;
}

.chapter-reader-project {
    font-family: var(--reader-sans);
    font-size: 13px;
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--reader-muted);
    margin: 0 0 28px;
}

.chapter-reader-number {
    font-family: var(--reader-serif);
    font-size: 15px;
    font-weight: 400;
    letter-spacing: 0.04em;
    color: #777;
    margin: 0 0 14px;
}

.chapter-reader-number:empty {
    display: none;
}

.chapter-reader-title {
    font-family: var(--reader-serif);
    font-size: 42px;
    font-weight: 400;
    letter-spacing: -0.03em;
    line-height: 1.2;
    color: var(--reader-ink);
    margin: 0 0 36px;
}

/*
 * Calm Read only: book name stays quiet; chapter number is a small
 * structural kicker; the detected title is the large primary heading.
 * Version History / Side by Side keep the unscoped rules above.
 */
.chapter-reader[data-reader-mode="read"] .chapter-reader-project {
    font-size: 12px;
    letter-spacing: 0.08em;
    margin-bottom: 22px;
}

.chapter-reader[data-reader-mode="read"] .chapter-reader-number {
    font-size: 13px;
    letter-spacing: 0.06em;
    color: #8a8a8a;
    margin: 0 0 10px;
}

.chapter-reader[data-reader-mode="read"] .chapter-reader-title {
    font-size: 42px;
    line-height: 1.15;
    margin: 0 0 36px;
}

.chapter-reader[data-reader-mode="read"] .chapter-reader-masthead.is-untitled-chapter .chapter-reader-number {
    display: none;
}

.chapter-reader-rule {
    width: 48px;
    height: 1px;
    margin: 0 auto;
    background: #cfcfcf;
}

/* Body typography */

.chapter-reader-body {
    text-align: left;
    font-family: var(--reader-serif);
}

.chapter-reader-p {
    font-size: 20px;
    font-weight: 400;
    line-height: var(--st-line-reader);
    color: var(--reader-ink);
    margin: 0 0 1.4em;
}

.chapter-reader-p:last-child {
    margin-bottom: 0;
}

.chapter-reader-h {
    font-family: var(--reader-serif);
    font-weight: 400;
    letter-spacing: -0.02em;
    color: var(--reader-ink);
    margin: 2.2em 0 0.8em;
    line-height: 1.25;
}

.chapter-reader-h1 {
    font-size: 30px;
}

.chapter-reader-h2 {
    font-size: 26px;
}

.chapter-reader-h3 {
    font-size: 22px;
}

.chapter-reader-h4,
.chapter-reader-h5,
.chapter-reader-h6 {
    font-size: 20px;
}

.chapter-reader-body em {
    font-style: italic;
}

.chapter-reader-body strong {
    font-weight: 600;
}

.chapter-reader-blockquote {
    margin: 2em 0;
    padding: 0 0 0 1.25em;
    border-left: 2px solid #ddd;
    color: #444;
}

.chapter-reader-blockquote p {
    font-family: var(--reader-serif);
    font-size: 20px;
    line-height: 1.75;
    font-style: italic;
    margin: 0;
}

.chapter-reader-list {
    margin: 0 0 1.6em;
    padding-left: 1.4em;
    font-size: 20px;
    line-height: 1.8;
}

.chapter-reader-list li {
    margin: 0 0 0.45em;
}

.chapter-reader-list li:last-child {
    margin-bottom: 0;
}

.chapter-reader-list-ordered {
    list-style-type: decimal;
}

.chapter-reader-list:not(.chapter-reader-list-ordered) {
    list-style-type: disc;
}

/* Reserved future manuscript slots (hidden until implemented) */

.chapter-reader-photo,
.chapter-reader-pullquote,
.chapter-reader-footnotes {
    display: none;
}

.chapter-reader-photo:not([hidden]),
.chapter-reader-pullquote:not([hidden]),
.chapter-reader-footnotes:not([hidden]) {
    display: block;
}

.chapter-reader-photo {
    margin: 2.8em 0;
}

.chapter-reader-photo-frame {
    width: 100%;
    min-height: 12rem;
    background: #f7f7f7;
}

.chapter-reader-caption {
    margin-top: 0.75em;
    font-family: var(--reader-sans);
    font-size: 13px;
    line-height: 1.5;
    color: var(--reader-muted);
    text-align: center;
}

.chapter-reader-pullquote {
    margin: 2.8em 1.5em;
    padding: 0;
    border: none;
    font-family: var(--reader-serif);
    font-size: 26px;
    line-height: 1.45;
    letter-spacing: -0.02em;
    text-align: center;
    color: #333;
}

.chapter-reader-footnotes {
    margin-top: 4em;
    padding-top: 1.5em;
    border-top: 1px solid var(--reader-rule);
    font-family: var(--reader-serif);
    font-size: 15px;
    line-height: 1.65;
    color: #555;
}

/* Loading / missing */

.chapter-reader-state {
    width: min(480px, 100%);
    margin: 0 auto;
    padding: 120px 32px;
    text-align: center;
    animation: st-fade-in var(--st-duration-slow) var(--st-ease) both;
}

.chapter-reader-loading-text,
.chapter-reader-missing p {
    font-family: var(--reader-serif);
    margin: 0;
}

.chapter-reader-loading-text {
    color: var(--st-muted);
}

.chapter-reader-text-btn {
    margin-top: 28px;
    font-family: var(--reader-sans);
    font-size: var(--st-size-meta);
}

/* Bottom navigation */

.chapter-reader-nav {
    flex-shrink: 0;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    padding: 22px 28px 32px;
    border-top: 1px solid #f2f2f2;
    background: #fff;
}

.chapter-reader-nav[hidden] {
    display: none;
}

.chapter-reader-nav-btn {
    border: none;
    background: transparent;
    min-height: var(--st-touch);
    padding: 8px 0;
    font-family: var(--reader-sans);
    font-size: 14px;
    font-weight: 400;
    color: var(--reader-ink);
    cursor: pointer;
    text-align: left;
    text-decoration: none;
    transition: color var(--st-duration) var(--st-ease), opacity var(--st-duration) var(--st-ease);
}

.chapter-reader-nav-btn:hover:not(:disabled) {
    color: #000;
}

.chapter-reader-nav-btn.is-center {
    text-align: center;
    justify-self: center;
}

.chapter-reader-nav-btn[data-action="next"] {
    text-align: right;
    justify-self: end;
}

.chapter-reader-nav-btn:disabled {
    color: #d0d0d0;
    cursor: default;
}

@media (max-width: 768px) {
    .chapter-reader-chrome {
        flex-direction: column;
        align-items: stretch;
        padding: 14px 18px 10px;
    }

    .chapter-reader-chrome-controls {
        gap: 8px 14px;
        justify-content: flex-start;
    }

    .chapter-reader-page {
        padding: 40px 24px 72px;
    }

    .chapter-reader-title,
    .chapter-reader[data-reader-mode="read"] .chapter-reader-title {
        font-size: 32px;
        margin-bottom: 28px;
    }

    .chapter-reader-masthead {
        margin-bottom: 40px;
    }

    .chapter-reader-p,
    .chapter-reader-blockquote p,
    .chapter-reader-list {
        font-size: 18px;
        line-height: 1.75;
    }

    .chapter-reader-nav {
        grid-template-columns: 1fr;
        gap: 10px;
        padding: 18px 20px 28px;
        text-align: center;
    }

    .chapter-reader-nav-btn,
    .chapter-reader-nav-btn.is-center,
    .chapter-reader-nav-btn[data-action="next"] {
        text-align: center;
        justify-self: center;
    }
}


/* Widened Read Manuscript canvas (preserve current desktop improvement) */
@media (min-width: 1024px) {
    .chapter-reader-page {
        padding: 64px 56px 112px;
    }

    .chapter-reader-nav {
        padding: 24px 40px 40px;
    }
}

@media (min-width: 1200px) {
    .chapter-reader {
        --reader-measure: var(--st-desktop-canvas);
    }
}

@media (min-width: 1440px) {
    .chapter-reader {
        --reader-measure: var(--st-desktop-canvas);
    }
}


/* ------------------------------------------------------------------ */
/* Focus mode — desktop / large-tablet distraction-free manuscript     */
/* In-app only (not browser fullscreen). Keeps Storyfellow wordmark.   */
/* ------------------------------------------------------------------ */

.chapter-reader-focus-enter {
    display: none;
}

.chapter-reader-focus-exit {
    display: none;
    position: fixed;
    top: 18px;
    right: 28px;
    z-index: 40;
    margin: 0;
    padding: 8px 12px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    font-family: var(--reader-sans, var(--st-font-sans));
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: #9a9a9a;
    cursor: pointer;
}

.chapter-reader-focus-exit:hover,
.chapter-reader-focus-exit:focus-visible {
    color: var(--reader-ink, var(--st-ink-soft));
    background: rgba(0, 0, 0, 0.03);
    outline: none;
}

@media (min-width: 768px) {
    .chapter-reader-focus-enter {
        display: inline-flex;
        align-items: center;
    }

    /* Side by Side is a separate workspace — no Focus entry there. */
    .chapter-reader[data-reader-mode="compare"] .chapter-reader-focus-enter {
        display: none !important;
    }

    #screen-chapter-reader.is-focus-mode .chapter-reader-focus-exit:not([hidden]) {
        display: inline-flex;
        align-items: center;
    }

    #screen-chapter-reader.is-focus-mode > .brand-bar .menu-toggle,
    #screen-chapter-reader.is-focus-mode > .brand-bar .brand-search,
    #screen-chapter-reader.is-focus-mode > .brand-bar .brand-note {
        visibility: hidden;
        pointer-events: none;
    }

    #screen-chapter-reader.is-focus-mode .chapter-reader-chrome,
    #screen-chapter-reader.is-focus-mode .chapter-reader-chrome-read,
    #screen-chapter-reader.is-focus-mode .chapter-reader-chrome-history,
    #screen-chapter-reader.is-focus-mode .chapter-reader-compare-bar,
    #screen-chapter-reader.is-focus-mode .chapter-reader-chapter-index,
    #screen-chapter-reader.is-focus-mode .chapter-reader-read-nav,
    #screen-chapter-reader.is-focus-mode .chapter-reader-nav {
        display: none !important;
    }
}
