/* Story and reader UI share the compact homepage typography and controls. */
body.library-layout:not(.home), body.chapter-reader-page {
    --font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-family: var(--font-family);
}
body.library-layout .story-detail-page {
    max-width: 1440px;
    padding: 20px clamp(12px, 2vw, 28px) 40px;
}
body.library-layout .story-detail-page .story-breadcrumb { font-size: 12px !important; line-height: 1.7; }
body.library-layout .story-detail-page .story-header {
    padding: 24px;
    gap: 28px;
    border-radius: 16px;
    box-shadow: none;
}
body.library-layout .story-detail-page .story-cover { width: 180px; flex: 0 0 180px; }
body.library-layout .story-detail-page .story-cover img { display: block; box-shadow: none !important; }
body.library-layout .story-detail-page .story-title {
    font-family: var(--font-family);
    font-size: 28px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: -.025em;
    margin-bottom: 18px;
}
body.library-layout .story-detail-page .story-meta-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px 20px;
    margin-bottom: 16px;
}
body.library-layout .story-detail-page .story-meta-list > div { display: flex; flex-direction: column; gap: 4px; }
body.library-layout .story-detail-page .story-meta-list dt { font-size: 12px; }
body.library-layout .story-detail-page .story-meta-list dd { font-size: 14px; }
body.library-layout .story-detail-page .story-badges { gap: 6px; margin-bottom: 12px; }
body.library-layout .story-detail-page .story-badges .badge { border-radius: 8px; padding: 5px 9px; font-size: 12px; }
body.library-layout .story-detail-page .story-actions { gap: 8px; }
/* These presentation wrappers leave the existing desktop flex items in place. */
.story-genres-section, .story-secondary-actions, .story-management { display: contents; }
.story-social-actions { display: flex; gap: 8px; }
.story-social-actions > .btn { flex: 1; }
.story-share-dialog:not([open]) { display: none; }
.story-share-dialog { inset: auto; left: 50%; top: 50%; max-height: calc(100dvh - 32px); overflow-y: auto; border-radius: 16px; font-family: var(--font-family); }
.story-share-dialog .reader-mobile-sheet-header h2 { font-family: inherit; }
.story-share-dialog::backdrop { background: rgb(0 0 0 / 45%); }
.story-share-links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.story-share-links .btn { min-width: 0; min-height: 44px; padding-inline: 8px; border-radius: 10px; font-size: 13px; }
.story-share-name { margin: 0; color: var(--muted-foreground); overflow-wrap: anywhere; }
.story-share-status { margin: 0; min-height: 1.5em; font-size: 12px; color: var(--muted-foreground); }
[data-facebook-web-share][hidden] { display: none !important; }
body.library-layout .story-detail-page .story-actions .btn,
.chapter-gate .combo-btn { border-radius: 10px; font-size: 13px; font-weight: 500; }
body.library-layout .story-detail-page .story-actions .combo-btn,
.chapter-gate .combo-btn {
    background: #D5AF6B !important;
    border-color: #B78A43 !important;
    color: #352718 !important;
}
body.library-layout .story-detail-page .story-actions .combo-btn:hover,
.chapter-gate .combo-btn:hover { background: #E3C38D !important; }
html:not([data-theme="dark"]) body.library-layout .story-detail-page .story-actions .combo-btn,
html:not([data-theme="dark"]) .chapter-gate .combo-btn {
    background: #EAB308 !important;
    border-color: #CA8A04 !important;
    color: #251A0D !important;
}
html:not([data-theme="dark"]) body.library-layout .story-detail-page .story-actions .combo-btn:hover,
html:not([data-theme="dark"]) .chapter-gate .combo-btn:hover { background: #D9A406 !important; }
body.library-layout .story-detail-page .story-actions .btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
html[data-theme="dark"] body.library-layout .story-detail-page .story-actions .btn-primary { color: var(--primary-foreground); }
body.library-layout .story-detail-page .story-content-columns { margin-top: 20px; border-radius: 16px; box-shadow: none; }
body.library-layout .story-detail-page .panel { border-radius: 16px; box-shadow: none; }
body.library-layout .story-detail-page .panel-pad { padding: 22px; }
body.library-layout .story-detail-page .story-panel-title {
    font-family: var(--font-family);
    font-size: 20px;
    font-weight: 600;
    padding-bottom: 12px;
    margin-bottom: 16px;
}
body.library-layout .story-detail-page .story-summary { font-size: 15px; line-height: 1.85; }
body.library-layout .story-detail-page .story-summary.is-collapsed { max-height: 280px; }
body.library-layout .story-detail-page .story-chapter-item { min-height: 56px; }
body.library-layout .story-detail-page .story-chapter-link { flex-direction: column; align-items: flex-start; gap: 4px; font-size: 13px; }
body.library-layout .story-detail-page .story-chapter-date { display: block; font-size: 12px; line-height: 1.5; }
body.library-layout .story-detail-page .chapter-access-label { font-size: 12px; }
body.library-layout .story-detail-page .chapter-access-free { color: #167348; }
html[data-theme="dark"] body.library-layout .story-detail-page .chapter-access-free { color: #6ee7b7; }
body.library-layout .story-detail-page .pagination .btn { min-height: 36px; min-width: 36px; font-size: 12px; }
body.library-layout .story-detail-page .pagination-summary,
body.library-layout .story-detail-page .combo-btn > span,
.chapter-gate .combo-btn > span { font-size: 12px !important; }
body.library-layout .story-detail-page .story-breadcrumb a { display: inline-flex; align-items: center; min-height: 32px; }
body.library-layout .story-detail-page .story-badges a { min-height: 32px; }
body.library-layout .story-detail-page .btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
html[data-theme="dark"] body.library-layout .story-detail-page .btn-primary { color: var(--primary-foreground); }

/* Wide reading surface; saved narrow mode and typography still take precedence. */
body.chapter-reader-page { --reader-wide-width: 1176px; }
body.chapter-reader-page .reader-page-shell { max-width: 1200px; padding-inline: 12px; }
body.chapter-reader-page .reader-heading { max-width: var(--reader-wide-width); margin-bottom: 18px; }
body.chapter-reader-page .reader-heading .reader-title {
    font-family: var(--font-family);
    font-size: clamp(22px, 2.2vw, 30px);
    font-weight: 600;
    line-height: 1.4;
}
body.chapter-reader-page .reader-story-link { min-height: 32px; font-size: 13px; font-weight: 500; letter-spacing: 0; }
body.chapter-reader-page .reader-heading-meta { font-size: 12px; letter-spacing: 0; }
body.chapter-reader-page .reader-chapter-nav { max-width: var(--reader-wide-width); }
body.chapter-reader-page .reader-chapter-nav-btn,
body.chapter-reader-page .reader-chapter-select-wrap { border-radius: 10px; font-size: 13px; font-weight: 500; letter-spacing: 0; }
body.chapter-reader-page .header-tool {
    max-width: var(--reader-wide-width);
    margin-inline: auto;
    padding-inline: 8px;
    border-radius: 12px;
    box-shadow: none;
    background: var(--color-bg);
    backdrop-filter: none;
}
body.chapter-reader-page .reader-tools-group { padding-inline: 4px; }
body.chapter-reader-page .reader-container {
    max-width: var(--reader-wide-width);
    padding: 32px;
    border-radius: 14px;
    border-color: var(--color-border-light);
}
body.chapter-reader-page .reader-container .chapter-body-text { padding-block: 0; }
body.chapter-reader-page .reader-container .chapter-body-text {
    overflow-wrap: anywhere;
    text-align: left;
}
body.chapter-reader-page .reader-content p { margin-bottom: 1.2em; }
body.chapter-reader-page .reader-action-wrapper,
body.chapter-reader-page .reader-comments { max-width: var(--reader-wide-width); margin-inline: auto; }
body.chapter-reader-page .reader-comments { border-radius: 14px; box-shadow: none; }
body.chapter-reader-page .reader-end-action-bar { font-family: var(--font-family); }
body.chapter-reader-page .reader-mobile-modal-overlay,
body.chapter-reader-page .toc-overlay { background: rgba(0, 0, 0, .55); }
body.chapter-reader-page .reader-end-action-bar span,
body.chapter-reader-page .reader-comment-login span,
body.chapter-reader-page .reader-comment-login a,
body.chapter-reader-page .reader-comments-empty span,
body.chapter-reader-page .reader-comments-header > div > span,
body.chapter-reader-page .reader-comment-filters a { font-size: 12px; }
body.chapter-reader-page .site-header .btn-primary,
body.library-layout:not(.home) .site-header .btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
html[data-theme="dark"] body.chapter-reader-page .site-header .btn-primary,
html[data-theme="dark"] body.library-layout:not(.home) .site-header .btn-primary { color: var(--primary-foreground); }

@media (max-width: 1024px) {
    body.library-layout .story-detail-page .story-meta-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
    .story-social-actions { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    body.library-layout .story-detail-page { padding-top: 16px; }
    body.library-layout .story-detail-page .story-header { padding: 18px; gap: 18px; }
    body.library-layout .story-detail-page .story-cover { width: 128px; flex: 0 0 auto; }
    body.library-layout .story-detail-page .story-title { font-size: 23px; margin-bottom: 16px; }
    body.library-layout .story-detail-page .story-meta-list { max-width: none; text-align: left; gap: 12px 16px; }
    body.library-layout .story-detail-page .story-actions .btn,
    .chapter-gate .combo-btn { padding: 9px 8px; }
    body.library-layout .story-detail-page .story-content-columns { gap: 16px; margin-top: 16px; }
    body.library-layout .story-detail-page .panel-pad { padding: 16px; }
    body.library-layout .story-detail-page .story-panel-title { font-size: 18px; }
    body.library-layout .story-detail-page .story-chapter-title {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        white-space: normal;
        overflow: hidden;
    }
    body.chapter-reader-page .reader-page-shell { padding-inline: 8px; }
    body.chapter-reader-page .reader-heading { margin-bottom: 16px; }
    body.chapter-reader-page .reader-chapter-select-wrap select { font-size: 12px; }
    body.chapter-reader-page .reader-container { padding: 20px 12px; border-radius: 12px; }
    body.chapter-reader-page .reader-chapter-nav-bottom .reader-chapter-nav-btn > span { font-size: 12px; }
    body.chapter-reader-page .hd-mobile-tools-inner {
        bottom: 0;
        left: 0;
        right: 0;
        gap: 8px;
        padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid var(--color-border-light);
        background: var(--color-bg);
    }
    body.chapter-reader-page .hd-mobile-tools-pill {
        max-width: none;
        height: 52px;
        padding: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        background: transparent;
        backdrop-filter: none;
    }
    body.chapter-reader-page .hd-mobile-tools-pill-btn { border-radius: 8px; font-size: 12px; font-weight: 500; letter-spacing: 0; }
    body.chapter-reader-page .hd-mobile-tools-tts-btn { flex-basis: 48px; width: 48px; height: 48px; border-radius: 12px; box-shadow: none; }
    body.chapter-reader-page .hd-mobile-tools-badge-dot { display: none; }
}
/* Only phones use the cover / information layout; the 768px layout stays intact. */
@media (max-width: 767px) {
    body.library-layout:has(.story-detail-page) {
        padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    }
    body.library-layout:has(.story-detail-page) .mobile-bottom-nav {
        height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    }
    body.library-layout .story-detail-page [id] {
        scroll-margin-top: calc(var(--header-top) + var(--header-height) + 16px);
        scroll-margin-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 16px);
    }
    body.library-layout .story-detail-page .story-header {
        display: grid;
        grid-template-columns: clamp(100px, 26vw, 115px) minmax(0, 1fr);
        align-items: start;
        gap: 12px;
        padding: 12px;
        text-align: left;
    }
    body.library-layout .story-detail-page .story-cover {
        grid-column: 1;
        grid-row: 1 / 3;
        width: 100%;
    }
    body.library-layout .story-detail-page .story-info { display: contents; }
    body.library-layout .story-detail-page .story-title {
        grid-column: 2;
        min-width: 0;
        margin: 0;
        font-size: clamp(18px, 5vw, 20px);
        line-height: 1.4;
        overflow-wrap: anywhere;
    }
    body.library-layout .story-detail-page .story-meta-list {
        grid-column: 2;
        grid-template-columns: minmax(0, 1fr);
        min-width: 0;
        gap: 6px;
        margin: 0;
    }
    body.library-layout .story-detail-page .story-meta-list > div {
        flex-direction: row;
        align-items: baseline;
        flex-wrap: wrap;
        min-width: 0;
        gap: 2px 6px;
    }
    body.library-layout .story-detail-page .story-meta-list > .story-meta-author {
        flex-direction: column;
        align-items: flex-start;
    }
    body.library-layout .story-detail-page .story-meta-list dt,
    body.library-layout .story-detail-page .story-meta-list dd { line-height: 1.5; }
    body.library-layout .story-detail-page .story-meta-list dd {
        max-width: 100%;
        font-size: 13px;
        overflow-wrap: anywhere;
    }
    body.library-layout .story-detail-page .story-meta-list .badge {
        max-width: 100%;
        white-space: normal;
    }
    body.library-layout .story-detail-page .story-genres-section {
        display: block;
        grid-column: 1 / -1;
        min-width: 0;
    }
    body.library-layout .story-detail-page .story-badges {
        justify-content: flex-start;
        margin: 0;
    }
    body.library-layout .story-detail-page .story-badges .badge {
        max-width: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
    }
    body.library-layout .story-detail-page .story-badges .is-mobile-hidden { display: none; }
    body.library-layout .story-detail-page .story-genres-toggle { padding-top: 8px; }
    body.library-layout .story-detail-page .rating-widget {
        grid-column: 1 / -1;
        justify-content: flex-start;
        min-width: 0;
    }
    body.library-layout .story-detail-page .story-actions {
        grid-column: 1 / -1;
        grid-template-columns: minmax(0, 1fr);
        align-items: stretch;
        margin-top: 0;
    }
    body.library-layout .story-detail-page .story-secondary-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        min-width: 0;
    }
    body.library-layout .story-detail-page .story-social-actions { display: contents; }
    /* An odd number of optional buttons makes the final share button a full row. */
    body.library-layout .story-detail-page .story-secondary-actions > .story-social-actions:nth-child(even) > .btn:last-child {
        grid-column: 1 / -1;
    }
    body.library-layout .story-detail-page .story-actions .btn {
        width: 100%;
        height: 100%;
        min-height: var(--touch-target);
        line-height: 1.5;
        overflow-wrap: anywhere;
    }
    body.library-layout .story-detail-page .story-management {
        display: flex;
        justify-content: flex-end;
        min-width: 0;
        margin-top: 4px;
        padding-top: 12px;
        border-top: 1px solid var(--library-border);
    }
    body.library-layout .story-detail-page .story-management .btn { width: auto; }
}
