/* ================= 1. GLOBAL ZERO-OVERFLOW & SAFE WRAP ================= */
html, body {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    touch-action: pan-y pinch-zoom !important;
}

html body #m3_reader_modal,
html body #m3_reader_modal .m3-reader-container,
html body #m3_reader_modal .m3-reader-workspace,
html body #m3_reader_modal #m3_reader_viewport {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

/* সব ধরনের লেখা ও টেবিল যাতে স্ক্রিনের ডানে কোনোভাবেই উপচে না পড়ে */
html body #m3_reader_modal #m3_reader_viewport * {
    max-width: 100% !important;
    box-sizing: border-box !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
}

html body #m3_reader_modal #m3_reader_viewport pre,
html body #m3_reader_modal #m3_reader_viewport code {
    white-space: pre-wrap !important;
    word-break: break-all !important;
}

/* টেবিল রেসপনসিভ কনটেইনার */
html body #m3_reader_modal #m3_reader_viewport table {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    border-collapse: collapse !important;
    -webkit-overflow-scrolling: touch !important;
}

/* ছবি কখনো স্ক্রিনের বাইরে যাবে না */
html body #m3_reader_modal #m3_reader_viewport img,
html body #m3_reader_modal #m3_reader_viewport svg {
    max-width: 100% !important;
    height: auto !important;
    object-fit: contain !important;
}

/* আল্ট্রা-ক্ল্যাম্পড নন-ইন্ট্রুসিভ ওয়াটারমার্ক */
html body #m3_reader_modal .m3-page-watermark {
    font-size: clamp(12px, 3.8vw, 24px) !important;
    letter-spacing: clamp(0.06em, 0.4vw, 0.16em) !important;
    max-width: 82vw !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    pointer-events: none !important;
}

/* ================= 2. FLUID TYPOGRAPHY ENGINE (CLAMP) ================= */
html body #m3_reader_modal #m3_reader_viewport section.docx p,
html body #m3_reader_modal #m3_reader_viewport section.docx li,
html body #m3_reader_modal #m3_reader_viewport .m3-md-page-sheet p,
html body #m3_reader_modal #m3_reader_viewport .m3-md-page-sheet li {
    line-height: clamp(1.48, 0.2vw + 1.45, 1.78) !important;
}

html body #m3_reader_modal #m3_reader_viewport section.docx h1,
html body #m3_reader_modal #m3_reader_viewport .m3-md-page-sheet h1,
html body #m3_reader_modal #m3_reader_viewport [class*="heading-1"],
html body #m3_reader_modal #m3_reader_viewport [class*="Heading1"] {
    line-height: 1.28 !important;
    margin-top: clamp(12px, 2vw, 24px) !important;
    margin-bottom: clamp(6px, 1vw, 14px) !important;
}

html body #m3_reader_modal #m3_reader_viewport section.docx h2,
html body #m3_reader_modal #m3_reader_viewport .m3-md-page-sheet h2,
html body #m3_reader_modal #m3_reader_viewport [class*="heading-2"],
html body #m3_reader_modal #m3_reader_viewport [class*="Heading2"] {
    line-height: 1.3 !important;
    margin-top: clamp(10px, 1.6vw, 20px) !important;
    margin-bottom: clamp(5px, 0.8vw, 12px) !important;
}

html body #m3_reader_modal #m3_reader_viewport section.docx h3,
html body #m3_reader_modal #m3_reader_viewport .m3-md-page-sheet h3,
html body #m3_reader_modal #m3_reader_viewport [class*="heading-3"],
html body #m3_reader_modal #m3_reader_viewport [class*="Heading3"] {
    line-height: 1.34 !important;
    margin-top: clamp(8px, 1.2vw, 16px) !important;
    margin-bottom: clamp(4px, 0.6vw, 10px) !important;
}

/* ================= 3. MOBILE & TABLETS (<= 992px) ================= */
@media (max-width: 992px) {
    /* পেজ ভিউপোর্ট ও প্যাডিং সমন্বয় */
    html body #m3_reader_modal #m3_reader_viewport {
        padding-top: 8px !important;
        padding-left: clamp(8px, 2.5vw, 20px) !important;
        padding-right: clamp(8px, 2.5vw, 20px) !important;
        padding-bottom: max(95px, calc(80px + env(safe-area-inset-bottom, 0px))) !important;
    }

    html body #m3_reader_modal #m3_reader_viewport .docx-wrapper {
        width: 100% !important;
        max-width: clamp(320px, 94vw, 820px) !important;
        margin: 0 auto !important;
    }

    html body #m3_reader_modal #m3_reader_viewport section.docx,
    html body #m3_reader_modal #m3_reader_viewport .m3-md-page-sheet {
        width: 100% !important;
        max-width: 100% !important;
        padding: clamp(14px, 3.5vw, 32px) clamp(10px, 2.8vw, 24px) clamp(24px, 4vw, 42px) clamp(10px, 2.8vw, 24px) !important;
    }

    /* টপ বার ও প্লেয়ার পিল রেসপন্সিভ সাইজিং */
    html body #m3_reader_modal .m3-chrome-top-bar {
        padding: 4px clamp(8px, 2vw, 16px) !important;
        height: auto !important;
        min-height: 44px !important;
        gap: 6px !important;
    }

    html body #m3_reader_modal .m3-mini-player-pill {
        height: clamp(30px, 4.5vw, 36px) !important;
        padding: 2px clamp(4px, 1.5vw, 8px) !important;
        gap: clamp(4px, 1.2vw, 8px) !important;
    }

    html body #m3_reader_modal .pill-btn.play-pause-main {
        width: clamp(24px, 3.8vw, 28px) !important;
        height: clamp(24px, 3.8vw, 28px) !important;
    }

    html body #m3_reader_modal .pill-btn.nav-arrow,
    html body #m3_reader_modal .pill-btn.more-menu {
        width: clamp(26px, 4vw, 30px) !important;
        height: clamp(26px, 4vw, 30px) !important;
    }

    /* সব টুল পপআপ বটম-শীট হিসেবে পারফেক্ট স্ক্রোলিং */
    html body #m3_reader_modal .m3-custom-tool-popup.open,
    html body #m3_reader_modal .m3-appearance-popup.open,
    html body #m3_reader_modal .m3-appearance-sub.open,
    html body #m3_reader_modal .m3-voice-dropdown-menu.open {
        max-height: clamp(260px, 68vh, 540px) !important;
        width: 100vw !important;
        max-width: 100vw !important;
        border-radius: 24px 24px 0 0 !important;
        padding-bottom: max(16px, env(safe-area-inset-bottom, 0px)) !important;
    }

    /* মোবাইল ও ট্যাবে সাইডবার ড্রয়ার */
    html body #m3_reader_modal .ar-side-panel.open-mobile-drawer {
        width: clamp(260px, 80vw, 340px) !important;
        max-width: 86vw !important;
    }
}

/* ================= 4. PHONES IN LANDSCAPE MODE ================= */
/* যখন ফোন আড়াআড়ি (Landscape) থাকে এবং উচ্চতা কম থাকে */
@media (max-height: 540px) and (orientation: landscape) {
    html body #m3_reader_modal .m3-chrome-top-bar {
        min-height: 36px !important;
        height: 36px !important;
        padding: 2px 10px !important;
    }

    html body #m3_reader_modal .m3-chrome-top-bar > div:first-child svg {
        width: 22px !important;
        height: 22px !important;
    }

    html body #m3_reader_modal .m3-mini-player-pill {
        height: 28px !important;
    }

    html body #m3_reader_modal .m3-mobile-fs-btn,
    html body #m3_reader_modal .m3-mobile-3dot-btn {
        width: 28px !important;
        height: 28px !important;
    }

    /* ল্যান্ডস্কেপে রিডিং স্ক্রিনের উচ্চতা সর্বোচ্চ করা */
    html body #m3_reader_modal #m3_reader_viewport {
        padding-top: 4px !important;
        padding-bottom: 60px !important;
    }

    html body #m3_reader_modal #m3_reader_viewport section.docx,
    html body #m3_reader_modal #m3_reader_viewport .m3-md-page-sheet {
        padding-top: 14px !important;
        padding-bottom: 20px !important;
    }

    /* বটম শীট যেন স্ক্রিন ঢেকে না ফেলে এবং স্ক্রোল করা যায় */
    html body #m3_reader_modal .m3-mobile-tools-sheet {
        max-height: 88vh !important;
        padding-top: 8px !important;
        padding-bottom: 14px !important;
    }

    html body #m3_reader_modal .m3-sheet-tools-grid {
        grid-template-columns: repeat(6, 1fr) !important;
        gap: 6px !important;
    }

    html body #m3_reader_modal .m3-sheet-tool-item {
        padding: 6px 4px !important;
        border-radius: 10px !important;
    }

    html body #m3_reader_modal .m3-custom-tool-popup.open,
    html body #m3_reader_modal .m3-appearance-popup.open,
    html body #m3_reader_modal .m3-appearance-sub.open {
        max-height: 84vh !important;
    }

    /* HUD বারের সাইজ ল্যান্ডস্কেপে স্লিম রাখা */
    html body #m3_reader_modal .m3-reading-hud__row {
        height: 22px !important;
        font-size: 10.5px !important;
    }
}

/* ================= 5. TABLETS & IPADS (601px to 1024px) ================= */
@media (min-width: 601px) and (max-width: 1024px) {
    html body #m3_reader_modal #m3_reader_viewport .docx-wrapper {
        max-width: clamp(560px, 84vw, 780px) !important;
    }

    html body #m3_reader_modal .m3-mobile-drawer-tabs {
        grid-template-columns: repeat(5, 1fr) !important;
    }

    html body #m3_reader_modal .m3-sheet-tools-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 12px !important;
    }

    html body #m3_reader_modal .m3-sheet-tool-item {
        padding: 14px 10px !important;
    }
}

/* ================= 6. VERY SMALL PHONES (<= 360px) ================= */
@media (max-width: 360px) {
    html body #m3_reader_modal .m3-chrome-top-bar {
        padding: 0 4px !important;
    }

    html body #m3_reader_modal .m3-mini-player-pill {
        gap: 2px !important;
        padding: 1px 4px !important;
    }

    html body #m3_reader_modal .m3-mobile-top-actions {
        gap: 3px !important;
    }

    html body #m3_reader_modal .m3-sheet-tools-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 6px !important;
    }
}

/* ================= 7. FLOATING DOCKS & POPUPS Z-INDEX GUARD ================= */
html body #m3_reader_modal #m3_focus_floating_pill,
html body #m3_reader_modal #m3_2page_nav_dock {
    max-width: calc(100vw - 24px) !important;
    bottom: max(14px, calc(10px + env(safe-area-inset-bottom, 0px))) !important;
}

html body #m3_reader_modal .m3-selection-popover {
    max-width: 95vw !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
}

/* ডেস্কটপে পড়ার কলাম আগের মতো ফিক্সড চওড়া ও মাঝখানে থাকবে */
@media (min-width: 993px) {
  html body #m3_reader_modal #m3_reader_viewport .docx-wrapper {
    width: 100% !important;
    max-width: 780px !important;
    margin: 0 auto !important;
    padding: 0 24px !important;
  }
}

/* বোল্ড/সেন্টারড শিরোনাম-প্যারাগ্রাফে আগে-পরে ফাঁক ও বড় সাইজ */
html body #m3_reader_modal #m3_reader_viewport section.docx p[style*="text-align: center"],
html body #m3_reader_modal #m3_reader_viewport section.docx p[style*="text-align:center"],
html body #m3_reader_modal #m3_reader_viewport section.docx p:has(> span[style*="font-weight: bold"]:only-child),
html body #m3_reader_modal #m3_reader_viewport section.docx p:has(> b:only-child),
html body #m3_reader_modal #m3_reader_viewport section.docx p:has(> strong:only-child) {
  margin-top: 1.4em !important;
  margin-bottom: 0.9em !important;
  line-height: 1.35 !important;
}

/* মোবাইলে URL বার সহ আসল দৃশ্যমান উচ্চতা ব্যবহার */
html body #m3_reader_modal {
  align-items: stretch !important;
  height: 100vh !important;
  height: 100dvh !important;
}
html body #m3_reader_modal .m3-reader-container {
  height: 100% !important;
  max-height: 100% !important;
}
html, body {
  height: 100%;
  overflow: hidden !important;
}

html body .m3-selection-popover {
  width: max-content !important;     /* জায়গা কম হলেও লেখা ভাঙবে না */
  max-width: 94vw !important;
  flex-wrap: wrap !important;        /* জায়গা না হলে বাটনসহ পুরো বাটন নিচের সারিতে যাবে */
  justify-content: center !important;
}
html body .m3-selection-popover .m3-pop-btn {
  white-space: nowrap !important;    /* বাটনের ভেতরের লেখা কখনো ভাঙবে না */
  flex-shrink: 0 !important;
}



/* ===== মোবাইলে sticky hover বন্ধ: টাচ ডিভাইসে hover স্টাইল আটকে থাকবে না ===== */
@media (hover: none), (pointer: coarse) {
    html body #m3_reader_modal .ar-tree-item:hover,
    html body #m3_reader_modal .ar-item-card:hover,
    html body #m3_reader_modal .ar-thumb-card:hover,
    html body #m3_reader_modal .ar-rail-btn:hover:not(.active) {
        background: transparent !important;
        box-shadow: none !important;
        transform: none !important;
        color: inherit !important;
    }

    /* চাপ দেওয়ার মুহূর্তে হালকা ফিডব্যাক (আঙুল তুললেই চলে যাবে) */
    html body #m3_reader_modal .ar-tree-item:active,
    html body #m3_reader_modal .ar-item-card:active {
        background: rgba(0, 0, 0, 0.06) !important;
    }

    html body #m3_reader_modal .ar-tree-item,
    html body #m3_reader_modal .ar-item-card {
        -webkit-tap-highlight-color: transparent;
    }

    /* মোবাইলে পেজ বুকমার্ক রিবনের Sticky Hover বন্ধ ও ট্যাপ এরিয়া বড় করা */
    html body #m3_reader_modal .m3-page-ribbon-btn {
        width: 20px !important;
        height: 30px !important;
        right: 12px !important;
    }

    html body #m3_reader_modal .m3-page-ribbon-btn:hover:not(.bookmarked),
    html body #m3_reader_modal .m3-page-ribbon-btn:focus:not(.bookmarked) {
        background: rgba(128, 128, 128, 0.35) !important;
        opacity: 0.65 !important;
    }

    html body #m3_reader_modal .m3-page-ribbon-btn.bookmarked {
        background: #eab308 !important;
        opacity: 1 !important;
    }
}


/* ==========================================================================
   TABLET MODE ONLY: 3-DOT BOTTOM SHEET HEIGHT & SPACING BOOST
   ========================================================================== */
@media (min-width: 601px) and (max-width: 1024px) {
    /* ১. ৩-ডট বটম শিটের নিজস্ব হাইট ও প্যাডিং বৃদ্ধি */
    html body #m3_mobile_tools_sheet,
    html body .m3-mobile-tools-sheet {
        min-height: 310px !important;               /* শিটের মিনিমাম হাইট বাড়ানো হলো */
        max-height: 85vh !important;
        padding: 20px 24px 38px 24px !important;    /* উপরে-নিচে আরামদায়ক ফাঁকা জায়গা */
        box-sizing: border-box !important;
    }

    /* হ্যান্ডেল বার আরেকটু প্রমিনেন্ট করা */
    html body #m3_mobile_tools_sheet .m3-sheet-handle {
        width: 48px !important;
        height: 5px !important;
        margin-bottom: 20px !important;
    }

    /* ২. বাটনগুলোর গ্রিড গ্যাপ বৃদ্ধি */
    html body #m3_mobile_tools_sheet .m3-sheet-tools-grid {
        gap: 16px 14px !important;
    }

    /* ৩. ভেতরের প্রতিটি টুল কার্ডের নিজস্ব হাইট বাড়ানো */
    html body #m3_mobile_tools_sheet .m3-sheet-tool-item {
        min-height: 86px !important;               /* কার্ডগুলো লম্বা ও বড় দেখাবে */
        padding: 16px 12px !important;
        border-radius: 18px !important;
        gap: 8px !important;
    }

    /* কার্ডের আইকন ও ফন্ট সামান্য বড় করা যাতে ট্যাবলেটে স্পষ্ট বোঝা যায় */
    html body #m3_mobile_tools_sheet .m3-sheet-tool-item svg {
        width: 26px !important;
        height: 26px !important;
    }

    html body #m3_mobile_tools_sheet .m3-sheet-tool-item span {
        font-size: 12.5px !important;
        font-weight: 600 !important;
    }
}

/* মোবাইলে কোনো ব্যাকড্রপই দেখাবে না */
@media (max-width: 992px) {
    #m3_popup_backdrop_mobile,
    #m3_mobile_sheet_backdrop,
    #m3_mobile_drawer_backdrop,
    #ar_drawer_backdrop {
        display: none !important;
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }
}

html body #m3_reader_viewport .m3-word-page-footer,
.m3-word-page-footer {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4px !important;
    text-align: center !important;
}