/* OFWZ R14B — Adaptive editorial page fitting */

.ofwz-fit-content {
    box-sizing:border-box;
    min-width:0;
    min-height:0;
    display:block;
    container-type:inline-size;
    overflow-wrap:anywhere;
}

/* Preserve the existing physical page dimensions.
   Fit content inside them, not beyond them. */

#book.natural-book .sheet > .ofwz-fit-content,
#book.enhanced .sheet > .ofwz-fit-content {
    position:absolute;
    top:4%;
    right:6%;
    bottom:8%;
    left:6%;
    overflow-x:hidden;
    overflow-y:auto;
    overscroll-behavior:contain;
    scrollbar-width:thin;
    padding:0 3px 6px 0;
}

.sheet:has(> .ofwz-fit-content) > .page-number {
    position:absolute;
    right:6%;
    bottom:2.5%;
    margin:0;
    z-index:2;
}

.ofwz-fit-content .page-brand {
    font-size:clamp(24px,7cqw,42px);
    line-height:1;
    margin:0 0 8px;
}

.ofwz-fit-content .page-label {
    font-size:10px;
    letter-spacing:1.2px;
    margin:0 0 7px;
}

.ofwz-fit-content h2 {
    font-size:clamp(19px,5.5cqw,32px);
    line-height:1.15;
    margin:0 0 8px;
    overflow-wrap:anywhere;
}

.ofwz-fit-content .page-subtitle {
    font-size:clamp(12px,3.5cqw,17px);
    line-height:1.3;
    margin:0 0 12px;
}

.ofwz-fit-content .page-body {
    display:block !important;
    height:auto !important;
    max-height:none !important;
    overflow:visible !important;
    font-size:clamp(13px,3.6cqw,17px);
    line-height:1.45;
    margin:8px 0 0;
    white-space:normal;
    text-overflow:clip;
    -webkit-line-clamp:unset;
}

/* Compact fitting: preserve every word. */

.ofwz-fit-content.fit-compact .page-brand {
    font-size:27px;
}

.ofwz-fit-content.fit-compact h2 {
    font-size:clamp(17px,4.7cqw,26px);
    margin-bottom:6px;
}

.ofwz-fit-content.fit-compact .page-subtitle {
    font-size:13px;
    margin-bottom:7px;
}

.ofwz-fit-content.fit-compact .page-body {
    font-size:clamp(12px,3.2cqw,15px);
    line-height:1.35;
    margin-top:5px;
}

/* Tight fitting: never shrink below 12px.
   Extra-long content remains scrollable. */

.ofwz-fit-content.fit-tight .page-brand {
    font-size:24px;
}

.ofwz-fit-content.fit-tight .page-label {
    margin-bottom:4px;
}

.ofwz-fit-content.fit-tight h2 {
    font-size:clamp(16px,4.2cqw,23px);
    margin-bottom:4px;
}

.ofwz-fit-content.fit-tight .page-subtitle {
    font-size:12px;
    margin-bottom:6px;
}

.ofwz-fit-content.fit-tight .page-body {
    font-size:clamp(12px,3cqw,14px);
    line-height:1.3;
    margin-top:4px;
}

/* Artwork and multimedia retain their proportions. */

.ofwz-fit-content .magazine-media {
    max-width:100%;
    margin-top:8px;
    margin-bottom:8px;
}

.ofwz-fit-content .magazine-media img,
.ofwz-fit-content .magazine-media video {
    display:block;
    max-width:100%;
    width:100%;
    height:auto;
    max-height:220px;
    object-fit:contain;
}

.front_cover .ofwz-fit-content .magazine-media img,
.back_cover .ofwz-fit-content .magazine-media img,
.advertisement .ofwz-fit-content .magazine-media img {
    max-height:340px;
}

.ofwz-fit-content.fit-compact .magazine-media img,
.ofwz-fit-content.fit-compact .magazine-media video {
    max-height:180px;
}

.ofwz-fit-content.fit-tight .magazine-media img,
.ofwz-fit-content.fit-tight .magazine-media video {
    max-height:140px;
}

.ofwz-fit-content audio {
    max-width:100%;
}

.ofwz-fit-content:focus-visible {
    outline:2px solid #b49a62;
    outline-offset:-2px;
}

/* Continuous reading remains unrestricted. */

.ofwz-explore-continuous .sheet > .ofwz-fit-content {
    position:static !important;
    height:auto !important;
    max-height:none !important;
    overflow:visible !important;
}

.ofwz-explore-continuous .sheet > .page-number {
    position:static;
    margin-top:15px;
}

@media(max-width:600px) {

    #book.natural-book .sheet > .ofwz-fit-content,
    #book.enhanced .sheet > .ofwz-fit-content {
        top:3%;
        left:5%;
        right:5%;
        bottom:9%;
    }

    .ofwz-fit-content .magazine-media img,
    .ofwz-fit-content .magazine-media video {
        max-height:180px;
    }
}
