/* Only the mobile navigation and document reader. Desktop uses the existing UI. */
@media (max-width: 991.98px), (hover: none) and (pointer: coarse) and (max-width: 1366px) {
    body { padding-bottom: 0; }
    /* Clip horizontal overflow without creating a scroll container that breaks sticky navigation. */
    body.overflow-x-hidden { overflow-x: clip !important; }
    body.mobile-pdf-open #cookieConsent { display: none; }

    /* Retain the original pill, logo, login and profile styling. */
    #mainStickyNav, #mainStickyNav.is-stuck {
        position: -webkit-sticky;
        position: sticky;
        top: calc(env(safe-area-inset-top, 0px) + 0.7rem);
    }
    #mainStickyNav .top-nav-container { flex-wrap: nowrap; gap: 0.3rem; }
    #mainStickyNav .top-nav-logo-full { width: 40px; height: 40px; max-height: none; }
    #mainStickyNav .mobile-primary-nav { display: flex; gap: 6px; }
    /* Keep the same compact navigation when a touch tablet crosses Bootstrap's lg breakpoint. */
    #mainStickyNav .mobile-primary-nav,
    #mainStickyNav .mobile-auth-controls { display: flex !important; }
    #mainStickyNav .top-nav-collapse,
    #mainStickyNav .top-nav-toggler,
    #mainStickyNav .top-nav-desktop-actions { display: none !important; }
    #mainStickyNav .top-nav-container {
        width: max-content;
        max-width: calc(100vw - 1.5rem);
        border-radius: 999px;
        border: 1px solid #d3d3cf;
        padding: 0.3rem 0.35rem 0.3rem 0.58rem;
        margin: 0 auto;
        background: #ecece8;
    }
    #mainStickyNav .top-nav-mobile-profile-btn { background: #fff; }
    #mobilePdfMount { display: block !important; }
    #mobilePdfViewer.show { display: flex !important; }
    #bookFrame.has-inline-mobile-pdf { border-radius: 24px; }
    #bookFrame.has-inline-mobile-pdf .document-detail-header h1 { display: block; }
    #mainStickyNav .mobile-primary-link {
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 40px;
        width: 40px;
        height: 40px;
        border: 0;
        border-radius: 50%;
        background: #fff;
        box-shadow: none;
        color: #000;
        text-decoration: none;
        font-size: 18px;
        line-height: 1;
        -webkit-tap-highlight-color: transparent;
    }
    #mainStickyNav .mobile-primary-link.active {
        background: #f4b51d;
        color: #000;
        border-radius: 50%;
    }
    #mainStickyNav .mobile-nav-icon { display: block; width: 24px; height: 24px; flex: none; }
    #mainStickyNav .mobile-icon-surface { fill: currentColor; fill-opacity: 0; }
    #mainStickyNav .mobile-primary-link.active .mobile-icon-surface { fill-opacity: 0.1; }
    #mainStickyNav .mobile-primary-link:focus-visible { outline: 2px solid #f3b100; outline-offset: 1px; }
    #mainStickyNav .top-nav-mobile-menu {
        max-height: calc(100dvh - 100px);
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    #mainStickyNav .mobile-profile-notifications summary {
        display: flex;
        align-items: center;
        list-style: none;
        cursor: pointer;
    }
    #mainStickyNav .mobile-profile-notifications summary::-webkit-details-marker { display: none; }
    #mainStickyNav .mobile-profile-notifications[open] summary > .bi-chevron-down { transform: rotate(180deg); }
    #mainStickyNav .mobile-profile-notification-count {
        margin-left: 8px;
        padding: 2px 6px;
        border-radius: 999px;
        background: #dc3545;
        color: #fff;
        font: 600 11px/1.4 system-ui, sans-serif;
    }
    #mainStickyNav .mobile-profile-notification-list {
        max-height: 240px;
        overflow-y: auto;
        overscroll-behavior: contain;
        border-block: 1px solid #ececec;
    }
    @media (max-width: 374.98px) {
        #mainStickyNav .top-nav-container { gap: 0.15rem; }
        #mainStickyNav .top-nav-brand { margin-right: 0; }
        #mainStickyNav .top-nav-logo-full { width: 32px; height: 32px; }
        #mainStickyNav .mobile-primary-nav { gap: 4px; }
        #mainStickyNav .mobile-primary-link { flex-basis: 32px; width: 32px; height: 32px; font-size: 16px; }
        #mainStickyNav .mobile-nav-icon { width: 22px; height: 22px; }
        #mainStickyNav .mobile-login-btn { padding-inline: 0.6rem; font-size: 0.8rem; }
    }

    .document-detail-modal .document-body {
        --bs-gutter-x: 0;
        margin-inline: 0;
        padding-inline: 12px;
    }

    #mobilePdfViewer {
        height: 100%;
        height: 100dvh;
        background: #eeece5;
        color: #283c36;
        font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
        font-size: 14px;
        line-height: 1.45;
        overscroll-behavior: contain;
    }
    #mobilePdfViewer .mobile-pdf-header {
        flex-shrink: 0;
        gap: 12px;
        padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
        background: #f9f7f1;
        border-bottom: 1px solid #ded9cd;
    }
    #mobilePdfViewer .mobile-pdf-heading { min-width: 0; flex: 1; }
    #mobilePdfViewer .mobile-pdf-title {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        margin: 0;
        font: 600 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
        color: #283c36;
    }
    #mobilePdfViewer .mobile-pdf-access { display: block; margin-top: 4px; color: #797568; font-size: 12px; }
    #mobilePdfViewer .mobile-pdf-close {
        flex: 0 0 44px;
        width: 44px;
        height: 44px;
        background: #eeece5;
        box-shadow: none;
        color: #0c3b2e;
        font-size: 22px;
    }
    #mobilePdfViewer .mobile-pdf-body {
        position: relative;
        min-height: 0;
        padding: 12px;
        overflow: hidden;
    }
    #mobilePdfViewer .mobile-pdf-canvas-wrap {
        width: 100%;
        height: 100%;
        min-height: 0;
        align-items: center;
    }
    #mobilePdfViewer .mobile-pdf-canvas {
        flex-shrink: 0;
        touch-action: pan-y pinch-zoom;
        border-radius: 4px;
        box-shadow: 0 4px 20px rgb(44 49 36 / 10%);
    }
    #mobilePdfViewer.is-loading .mobile-pdf-canvas { opacity: 0.4; }
    #mobilePdfViewer .mobile-pdf-status {
        position: absolute;
        inset: 0;
        z-index: 2;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        gap: 12px;
        padding: 24px;
        background: rgb(244 243 239 / 92%);
        text-align: center;
        color: #5d6156;
    }
    #mobilePdfViewer .mobile-pdf-status[hidden],
    #mobilePdfViewer .mobile-pdf-status button[hidden] { display: none; }
    #mobilePdfViewer .mobile-pdf-status.has-error .spinner-border { display: none; }
    #mobilePdfViewer #mobilePdfStatusText {
        max-width: 30ch;
        font: 400 14px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
        overflow-wrap: break-word;
    }
    #mobilePdfViewer:is(.is-loading, .has-load-error) .mobile-pdf-hint { visibility: hidden; }
    #mobilePdfViewer .mobile-pdf-lock {
        padding: 16px;
        border-radius: 8px;
        background: rgb(244 243 239 / 88%);
        overflow-y: auto;
        backdrop-filter: blur(8px);
    }
    #mobilePdfViewer .mobile-pdf-lock-card {
        width: min(100%, 330px);
        margin: auto;
        padding: 24px 20px 18px;
        border: 1px solid #fff;
        border-radius: 24px;
        background: #f9f7f1;
        box-shadow: 0 12px 36px rgb(44 49 36 / 10%);
    }
    #mobilePdfViewer .mobile-pdf-lock-icon {
        display: grid;
        place-items: center;
        width: 52px;
        height: 52px;
        margin: 0 auto 14px;
        border-radius: 18px;
        background: #fff0bf;
        color: #0c3b2e;
        font-size: 24px;
    }
    #mobilePdfViewer .mobile-pdf-lock-title { margin: 0 0 8px; font: 700 19px/1.3 system-ui, sans-serif; }
    #mobilePdfViewer .mobile-pdf-lock-copy { margin: 0 0 14px; color: #797568; font-size: 13px; }
    #mobilePdfViewer .mobile-pdf-lock-price { margin: 0 0 16px; font-size: 22px; font-weight: 700; }
    #mobilePdfViewer .mobile-pdf-primary {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-height: 44px;
        padding: 10px 18px;
        border: 0;
        border-radius: 14px;
        background: #f3b100;
        color: #263a30;
        text-decoration: none;
        font: 600 14px/1.4 system-ui, sans-serif;
        white-space: nowrap;
    }
    #mobilePdfViewer .mobile-pdf-lock-card .mobile-pdf-primary { width: 100%; }
    #mobilePdfViewer .mobile-pdf-secondary {
        min-height: 44px;
        margin-top: 6px;
        padding: 8px 12px;
        border: 0;
        border-radius: 12px;
        background: transparent;
        color: #5d6156;
        font: 500 13px/1.4 system-ui, sans-serif;
    }
    #mobilePdfViewer .mobile-pdf-footer {
        flex-shrink: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        border-top: 1px solid #ded9cd;
        background: #f9f7f1;
    }
    #mobilePdfViewer .mobile-pdf-controls { padding: 10px 16px 8px; border: 0; background: transparent; }
    #mobilePdfViewer .mobile-pdf-step {
        display: grid;
        place-items: center;
        width: 44px;
        height: 44px;
        padding: 0;
        border: 1px solid #ded9cd;
        border-radius: 14px;
        background: #f4f3ef;
        color: #0c3b2e;
        font-size: 20px;
        touch-action: manipulation;
    }
    #mobilePdfViewer .mobile-pdf-step:disabled { opacity: 0.35; }
    #mobilePdfViewer .mobile-pdf-step[data-locked="1"] { background: #fff0bf; border-color: #fff0bf; color: #0c3b2e; }
    #mobilePdfViewer .mobile-pdf-pagination { text-align: center; }
    #mobilePdfViewer .mobile-pdf-progress { font-size: 14px; color: #283c36; font-variant-numeric: tabular-nums; }
    #mobilePdfViewer .mobile-pdf-hint { display: block; margin-top: 2px; color: #827d70; font-size: 11px; }
    #mobilePdfViewer .mobile-pdf-track { display: block; width: calc(100% - 32px); height: 3px; margin: 0 16px 10px; border: 0; border-radius: 4px; overflow: hidden; appearance: none; background: #e6e2d7; }
    #mobilePdfViewer .mobile-pdf-track::-webkit-progress-bar { background: #e6e2d7; }
    #mobilePdfViewer .mobile-pdf-track::-webkit-progress-value { background: #0c3b2e; border-radius: 4px; }
    #mobilePdfViewer .mobile-pdf-track::-moz-progress-bar { background: #0c3b2e; border-radius: 4px; }
    #mobilePdfViewer .mobile-pdf-purchase { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 16px 12px; }
    #mobilePdfViewer .mobile-pdf-note { padding: 0; color: #797568; font-size: 11px; }
    #mobilePdfViewer .mobile-pdf-price { display: block; margin-top: 2px; font-size: 16px; font-weight: 700; }
    #mobilePdfViewer button:focus-visible,
    #mobilePdfViewer a:focus-visible { outline: 2px solid #b78408; outline-offset: 3px; }

    /* Embedded by default; the same reader can be expanded without duplicating it. */
    body.mobile-pdf-inline-visible .floating-contact-buttons { visibility: hidden; pointer-events: none; }
    #bookFrame.has-inline-mobile-pdf { padding: 0; overflow: hidden; }
    #bookFrame.has-inline-mobile-pdf > .document-detail-header {
        padding: 18px 16px 0;
        margin-bottom: 0 !important;
        gap: 0 !important;
    }
    #bookFrame.has-inline-mobile-pdf .document-detail-header h1 {
        margin: 0 !important;
        font-size: 1.25rem !important;
        line-height: 1.35;
        cursor: default;
    }
    #bookFrame.has-inline-mobile-pdf #mobileOpenPdfBtn,
    #bookFrame.has-inline-mobile-pdf > .document-viewer-shell { display: none !important; }
    #mobilePdfViewer:not(.is-expanded) {
        position: relative;
        inset: auto;
        z-index: auto;
        height: auto;
        max-width: 100%;
        overscroll-behavior: auto;
    }
    #mobilePdfViewer:not(.is-expanded) .mobile-pdf-header {
        padding: 4px 12px 8px 16px;
        background: #f4f3ef;
    }
    #mobilePdfViewer:not(.is-expanded) .mobile-pdf-title { display: none; }
    #mobilePdfViewer:not(.is-expanded) .mobile-pdf-access { margin-top: 0; }
    #mobilePdfViewer:not(.is-expanded) .mobile-pdf-body {
        flex: none;
        height: calc(var(--mobile-page-height, 440px) + 24px);
        touch-action: pan-y pinch-zoom;
    }
    #mobilePdfViewer:not(.is-expanded):is(.is-loading, .has-load-error) .mobile-pdf-body {
        height: clamp(220px, 32svh, 300px);
    }
    #mobilePdfViewer:not(.is-expanded) .mobile-pdf-footer { padding-bottom: 0; }
    #mobilePdfViewer:not(.is-expanded) .mobile-pdf-purchase { padding-bottom: 14px; }

    @media (max-height: 500px) and (orientation: landscape) {
        #mobilePdfViewer.is-expanded .mobile-pdf-header { padding-top: 6px; padding-bottom: 6px; }
        #mobilePdfViewer.is-expanded .mobile-pdf-title { -webkit-line-clamp: 1; }
        #mobilePdfViewer.is-expanded .mobile-pdf-access,
        #mobilePdfViewer.is-expanded .mobile-pdf-hint,
        #mobilePdfViewer.is-expanded .mobile-pdf-track { display: none; }
        #mobilePdfViewer.is-expanded .mobile-pdf-footer { display: flex; align-items: center; }
        #mobilePdfViewer.is-expanded .mobile-pdf-controls { flex: 1; padding: 6px 12px; }
        #mobilePdfViewer.is-expanded .mobile-pdf-purchase { padding: 6px 12px; }
        #mobilePdfViewer.is-expanded .mobile-pdf-lock-card { padding: 12px; }
        #mobilePdfViewer.is-expanded .mobile-pdf-lock-icon { display: none; }
    }
}
