/* ============================================
   Book Layout Styles
   Two-column paginated book spread for posts
   ============================================ */

/* ---- Hide scrolling, fill viewport ---- */
.book-post {
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
    color: var(--color-primary-text, #15171a);
}

.book-post .gh-article {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ---- Hide the source content (JS reads from it) ---- */
.book-source {
    display: none;
}

/* ---- Measurer (off-screen, matches page width for accurate height calc) ---- */
.book-page-measurer {
    position: absolute;
    left: -9999px;
    top: 0;
    width: calc(50vw - 80px);
    padding: 0;
    visibility: hidden;
    font-family: "Times New Roman", Times, Georgia, serif;
    font-size: 1.7rem;
    line-height: 1.8;
}

@media (max-width: 768px) {
    .book-page-measurer {
        width: calc(100vw - 60px);
    }
}

/* ---- Book container ---- */
.book-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 20px 20px 0;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    position: relative;
}

/* ---- Book spread: two pages side by side ---- */
.book-spread {
    flex: 1;
    display: flex;
    min-height: 0;
    gap: 0;
}

/* ---- Book page ---- */
.book-page {
    flex: 1;
    overflow: hidden;
    padding: 40px;
    font-family: "Times New Roman", Times, Georgia, serif;
    font-size: 1.7rem;
    line-height: 1.8;
    color: inherit;
}

.book-page p {
    margin-bottom: 1.2em;
}

.book-page h2, .book-page h3, .book-page h4 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-family: inherit;
}

.book-page img {
    max-width: 100%;
    height: auto;
}

/* ---- Book header (title + meta, flows inline with content) ---- */
.book-header {
    margin-bottom: 1.5em;
}

.book-title {
    font-size: clamp(2.2rem, 3.5vw, 3.2rem);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.02em;
    margin: 0 0 0.4em;
    color: inherit;
}

.book-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 1.4rem;
    opacity: 0.55;
    padding-bottom: 1em;
    border-bottom: 1px solid currentColor;
    margin-bottom: 0;
}

.book-meta,
.book-meta .book-author,
.book-meta .book-date,
.book-meta a,
.book-meta span,
.book-meta time {
    color: inherit !important;
}

.book-author {
    font-weight: 600;
}

.book-date {
    font-style: italic;
}

/* ---- Spine divider between pages ---- */
.book-spine {
    width: 1px;
    background: #ddd;
    flex-shrink: 0;
}

/* ---- Click areas for page turning ---- */
.book-click-prev,
.book-click-next {
    position: absolute;
    top: 0;
    bottom: 60px;
    width: 25%;
    cursor: pointer;
    z-index: 5;
}

.book-click-prev {
    left: 0;
    cursor: w-resize;
}

.book-click-next {
    right: 0;
    cursor: e-resize;
}

/* ---- Controls bar ---- */
.book-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 15px 0;
    flex-shrink: 0;
}

.book-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    color: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s;
}

.book-btn:hover {
    color: var(--accent-orange, #FF4F00);
}

.book-btn:disabled {
    opacity: 0.25;
    cursor: default;
}

.book-btn:disabled:hover {
    color: inherit;
}

.book-btn svg {
    display: block;
}

.book-page-indicator {
    font-family: "Times New Roman", Times, Georgia, serif;
    font-size: 14px;
    color: inherit;
    opacity: 0.5;
    min-width: 60px;
    text-align: center;
    user-select: none;
}

/* ---- Cover page (feature image as book cover) ---- */
.book-cover-page {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    height: 100%;
}

.book-cover-img {
    max-width: 100%;
    flex: 1;
    object-fit: contain;
    min-height: 0;
}

.book-fullpage-content .book-cover-page {
    width: 100%;
    height: 100%;
}

/* ---- Back to homepage link ---- */
.book-back-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 10;
    width: 40px;
    height: 40px;
    margin-bottom: 12px;
    opacity: 0.5;
    transition: opacity 0.2s;
    pointer-events: auto;
    cursor: pointer;
    flex-shrink: 0;
    text-decoration: none;
}

.book-back-link:hover {
    opacity: 1;
}

.book-back-icon {
    width: 28px;
    height: 28px;
    display: block;
}

body.dark-mode .book-back-icon {
    filter: invert(1);
}

.book-back-link:hover {
    opacity: 1;
}

.book-back-only {
    margin-bottom: 0;
}

/* ---- Drop cap image ---- */
.book-dropcap {
    float: left;
    width: 4.5em;
    height: 4.5em;
    margin: 0.55em 0.4em 0 0;
    shape-outside: margin-box;
    display: block;
    vertical-align: top;
}

/* ---- Full-page content ---- */
.book-fullpage-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
}

.book-fullpage-content .kg-image-card,
.book-fullpage-content .kg-gallery-card {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-fullpage-content .kg-image-card img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* ---- Inline embeds within a single page column ---- */
.book-page .kg-embed-card,
.book-page .kg-video-card {
    width: 100%;
    margin: 1em 0;
}

.book-page .kg-embed-card iframe,
.book-page .kg-video-card video {
    width: 100%;
    height: auto;
    aspect-ratio: auto;
}

/* Vertical video: constrain height so it doesn't overflow the page */
.book-page .kg-embed-card iframe[height],
.book-page .kg-video-card video {
    max-height: 70%;
}

/* ---- Full-spread page (spans both columns, toggled per-spread) ---- */
.book-spread.book-spread-full .book-spine,
.book-spread.book-spread-full .book-page-right {
    display: none;
}

.book-spread.book-spread-full .book-page-left {
    max-width: 100%;
    padding: 40px 60px;
}

.book-spread.book-spread-full .book-fullpage-content {
    width: 100%;
    height: 100%;
}

/* Embedded videos/iframes in full spread */
.book-spread.book-spread-full iframe,
.book-spread.book-spread-full video,
.book-spread.book-spread-full .kg-video-card,
.book-spread.book-spread-full .kg-embed-card {
    width: 100%;
    max-height: 80vh;
}

/* ---- Wide layout (video/game posts — always single page) ---- */
.book-wide .book-spine,
.book-wide .book-page-right {
    display: none;
}

.book-wide .book-page-left {
    max-width: 100%;
}

.book-wide .book-page {
    padding: 40px 60px;
}

@media (max-width: 768px) {
    .book-wide .book-page {
        padding: 25px 20px;
    }
}

/* ---- Mobile: single page ---- */
@media (max-width: 768px) {
    .book-spread {
        flex-direction: column;
    }

    .book-page-right,
    .book-spine {
        display: none;
    }

    .book-page {
        padding: 25px 20px;
    }

    .book-page-measurer {
        width: calc(100vw - 40px);
    }

    .book-container {
        padding: 10px 10px 0;
    }

    .book-click-prev,
    .book-click-next {
        width: 30%;
    }

    .book-controls {
        gap: 15px;
        padding: 10px 0;
    }

    .book-title {
        font-size: clamp(2rem, 6vw, 2.8rem);
    }

    .book-dropcap {
        width: 4.8em;
        height: 4.8em;
    }
}

/* ---- Dark mode ---- */
body.dark-mode .book-post,
body.dark-mode .book-post .book-page,
body.dark-mode .book-post .book-header,
body.dark-mode .book-post .book-title,
body.dark-mode .book-post .book-meta,
body.dark-mode .book-post .book-meta a,
body.dark-mode .book-post .book-author,
body.dark-mode .book-post .book-date,
body.dark-mode .book-post .book-controls,
body.dark-mode .book-post .book-page-indicator {
    color: #e0e0e0 !important;
}

body.dark-mode .book-spine {
    background: #444;
}

body.dark-mode .book-meta {
    border-bottom-color: rgba(255, 255, 255, 0.2);
}

body.dark-mode .book-dropcap {
    filter: invert(1);
}

/* ---- Ghost paywall / members CTA font overrides ---- */
.gh-post-upgrade-cta,
.gh-post-upgrade-cta-content {
    font-family: "Times New Roman", Times, Georgia, serif !important;
}

.gh-post-upgrade-cta h2 {
    font-family: 'Chicago', var(--font-sans) !important;
}

.gh-post-upgrade-cta p,
.gh-post-upgrade-cta small,
.gh-post-upgrade-cta a {
    font-family: "Times New Roman", Times, Georgia, serif !important;
}
