/* ============================================================
   responsive-scale.css  –  Unified Mobile & Touch System
   Fikra Smart · v2 · 2026-04-17

   Philosophy: "Same interface, proportionally smaller"
   - JS in index.html applies CSS `zoom` to body for screens
     600-1439px so the ENTIRE UI scales down proportionally
   - CSS breakpoints below handle phone (<600px) responsive layouts
   - Enable native touch scrolling everywhere it's appropriate
   - Disable touch-action: none ONLY on the drawing canvas
   - Meet Apple/Google 44-48 px minimum touch-target guidelines
   ============================================================ */

/* ============================================================
   0-A. ZOOM SUPPORT — prevent horizontal overflow when body
        is set to DESIGN_W by the JS proportional-zoom script
   ============================================================ */
html {
    /* Clip to viewport so zoomed body doesn't cause page scroll */
    overflow: hidden;
}

/* When JS sets body.width = DESIGN_W and body.zoom = scale,
   the html element clips any overflow so no horizontal scroll  */
body {
    /* overflow-x must be hidden at body level too               */
    overflow-x: hidden;
}


/* ============================================================
   0-B. ZOOM VIEWPORT FIX — Universal override for vw/vh units
        when CSS zoom is active.

        Problem: CSS zoom makes vw/vh reference the ACTUAL
        viewport, not the zoomed body dimensions. Elements using
        100vw/100vh end up smaller than the zoomed body.

        Solution: Override ALL position:fixed full-screen elements
        to use 100% (which references the zoomed body) instead.
        Side panels with fixed widths only get height override.
   ============================================================ */

/* Universal: ANY element inside body.app-zoomed that has          *
 * position:fixed and 100vw/100vh in its inline style gets fixed. *
 * This catches JS-dynamically-created overlays automatically.    */
body.app-zoomed [style*="position: fixed"][style*="100vw"],
body.app-zoomed [style*="position: fixed"][style*="100vh"],
body.app-zoomed [style*="position:fixed"][style*="100vw"],
body.app-zoomed [style*="position:fixed"][style*="100vh"],

/* CSS-defined full-screen overlays (no inline style to match)    */
body.app-zoomed .student-dashboard,
body.app-zoomed .frozen-overlay,
body.app-zoomed .auth-modal-overlay,
body.app-zoomed #landing-page,
body.app-zoomed #app-loader,
body.app-zoomed .custom-modal-overlay,
body.app-zoomed #lessonCreateModal,
body.app-zoomed #worksheetModal,
body.app-zoomed #lessonPlanModal,
body.app-zoomed #wsPreviewOverlay,
body.app-zoomed #lpPreviewOverlay,
body.app-zoomed #wsSketchOverlay,
body.app-zoomed #lessonSlidesModal,
body.app-zoomed #lessonOpenModeModal,
body.app-zoomed .student-entry-overlay,
body.app-zoomed #snipping-overlay,
body.app-zoomed .theater-curtain-overlay,
body.app-zoomed .ai-sidebar-container,
body.app-zoomed .search-sidebar-container,
body.app-zoomed .quran-sidebar-container,
body.app-zoomed .activity-game-overlay,
body.app-zoomed .store-overlay,
body.app-zoomed .store-publish-overlay,
body.app-zoomed .store-detail-overlay,
body.app-zoomed .scp-lightbox {
    width: 100% !important;
    height: 100% !important;
}

/* Side panels — only height needs fixing.
   These have their own fixed widths (380px, 280px, 820px etc.)
   and must NOT be stretched to 100% width.                     */
body.app-zoomed .chat-slider,
body.app-zoomed .lesson-drawer,
body.app-zoomed #onenote-nav {
    height: 100% !important;
}



/* ============================================================
   0. CSS CUSTOM PROPERTIES – RESPONSIVE TOKENS
   ============================================================ */
:root {
    /* Scale tokens written against a 1440-wide design baseline.
       JS can also update --vp-scale at runtime if needed.       */
    --vp-scale: 1;

    /* Touch target floors */
    --touch-min: 44px;
    --touch-ideal: 48px;

    /* Safe-area insets (iPhone notch / Dynamic Island) */
    --safe-top:    env(safe-area-inset-top,    0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left:   env(safe-area-inset-left,   0px);
    --safe-right:  env(safe-area-inset-right,  0px);
}


/* ============================================================
   1. HTML / BODY – UNIVERSAL TOUCH & SCROLL FOUNDATION
   ============================================================ */

html {
    /* Allow the landing page (fixed-positioned child) to scroll
       while the app remains clipped.                            */
    position: relative;
    overflow: hidden;
    overscroll-behavior: none;
    /* Respect device pixel density for sharp rendering          */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    /* pan-y pinch-zoom: vertical drag + pinch pass through to
       scrollable children; canvas blocks its own touch events   */
    touch-action: pan-y pinch-zoom;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
}

/* Drawing canvas: needs ALL pointer/touch events exclusively */
.canvas-layer,
canvas.upper-canvas,
canvas.lower-canvas {
    touch-action: none !important;
    -webkit-tap-highlight-color: transparent;
}


/* ============================================================
   2. GLOBAL TOUCH QUALITY-OF-LIFE
   ============================================================ */

/* Suppress the 300ms tap delay on everything interactive        */
a,
button,
[role="button"],
input,
label,
select,
textarea,
.tool-btn,
.nav-btn,
.nav-item,
.role-selector,
.landing-btn,
.ui-control-btn,
.side-tab,
.nav-tab,
.nav-book-item,
.icon-btn,
.action-btn,
.bulk-btn,
.modal-btn,
.auth-submit,
.auth-tab,
.orientation-card,
.iw-reaction,
.ss-tool-btn,
.ss-hint-btn,
.iw-fab,
.role-card,
.close-panel,
.close-btn-modern,
.bookshelf-toggle,
.nav-close-btn,
.ai-action-chip,
.ai-action-btn,
.ai-expand-toggle,
.ai-side-close-btn,
.new-chat-btn,
.close-ai-btn {
    touch-action: manipulation;          /* no 300ms delay        */
    -webkit-tap-highlight-color: transparent;
}

/* Prevent accidental text selection while tapping UI            */
.side-system,
.nav-system,
.pinned-bottom-bar,
.top-ui-layer,
.fixed-ui-controls,
.fixed-ui-controls-left,
.nav-bulk-bar {
    -webkit-user-select: none;
    user-select: none;
}

/* Allow input fields to select text */
input, textarea {
    -webkit-user-select: text !important;
    user-select: text !important;
}


/* ============================================================
   3. SCROLLABLE REGIONS – MOMENTUM + TOUCH
   ============================================================ */

/* Landing page (the whole page-level scroll)                    */
#landing-page {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y pinch-zoom;
}

/* OneNote navigation panel                                      */
#onenote-nav {
    touch-action: pan-y pan-x;
    -webkit-overflow-scrolling: touch;
}

.col-list,
.nav-book-list {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
}

.nav-column.bookshelf.expanded {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
}

/* Modals & overlays                                             */
.custom-modal-overlay,
.auth-modal-overlay,
.student-entry-overlay {
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

.auth-modal,
.student-panel-content,
.premium-modal-box {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    /* vh fallback first: browsers without dvh support would otherwise drop this
       declaration entirely and leave the modal with no height cap at all, hiding
       whatever's below the fold (e.g. the Save button) with nothing to scroll it into view. */
    max-height: 90vh;
    max-height: 90dvh;
}

/* Tool panels, notification lists, student grids               */
.tools-scroll,
.student-grid,
.notif-list,
.share-suggestions,
.slide-thumbnails-list {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior: contain;
}

/* Horizontal-scroll UI control bars                            */
.fixed-ui-controls,
.fixed-ui-controls-left {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.fixed-ui-controls::-webkit-scrollbar,
.fixed-ui-controls-left::-webkit-scrollbar {
    display: none;
}


/* ============================================================
   4. FLUID TYPOGRAPHY – clamp() across all breakpoints
   ============================================================ */

:root {
    --fs-xs:   clamp(0.65rem,  1.2vw, 0.75rem);
    --fs-sm:   clamp(0.75rem,  1.5vw, 0.85rem);
    --fs-base: clamp(0.875rem, 1.8vw, 1rem);
    --fs-md:   clamp(1rem,     2vw,   1.2rem);
    --fs-lg:   clamp(1.2rem,   2.5vw, 1.6rem);
    --fs-xl:   clamp(1.5rem,   3.5vw, 2.2rem);
    --fs-2xl:  clamp(2rem,     5vw,   3.5rem);
    --fs-3xl:  clamp(2.5rem,   7vw,   4.8rem);
}

/* Apply fluid base font to html so rem follows along           */
html {
    font-size: clamp(14px, 1.2vw, 16px);
}


/* ============================================================
   5. TOUCH MINIMUM SIZES – enforce 44px everywhere interactive
   ============================================================ */

@media (pointer: coarse) {

    button,
    .tool-btn,
    .nav-btn,
    .nav-item,
    .role-selector,
    .landing-btn,
    .auth-submit,
    .modal-btn,
    .bulk-btn,
    .iw-sort-btn,
    .ss-tool-btn {
        min-height: var(--touch-min);
    }

    .ui-control-btn,
    .side-tab,
    .nav-tab,
    .nav-book-item,
    .icon-btn,
    .close-panel,
    .close-btn-modern,
    .nav-close-btn,
    .bookshelf-toggle {
        min-width:  var(--touch-min);
        min-height: var(--touch-min);
    }

    /* Pinch-friendly radio/checkbox hit areas                    */
    input[type="radio"],
    input[type="checkbox"] {
        min-width:  24px;
        min-height: 24px;
    }

    /* Better modal buttons on touch devices                      */
    .modal-btn {
        padding: 16px;
    }

    /* Auth submit                                                */
    .auth-submit {
        padding: 18px;
    }
}


/* ============================================================
   6.  LANDING PAGE  –  < 1024 px
   ============================================================ */

@media (max-width: 1024px) {

    .landing-hero-container {
        padding: clamp(40px, 8vw, 100px) 0;
    }

    .hero-split {
        grid-template-columns: 1fr;
        text-align: center;
        gap: clamp(32px, 6vw, 60px);
    }

    .hero-text {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .hero-role-actions {
        flex-direction: column;
        width: 100%;
        max-width: 420px;
        margin: 0 auto;
    }

    .role-selector {
        width: 100%;
    }

    .header-nav {
        display: none;
    }
}

@media (max-width: 640px) {

    .landing-header {
        height: 64px;
    }

    .header-logo {
        font-size: 1.3rem;
    }

    .hero-title {
        font-size: clamp(2rem, 10vw, 3rem);
        margin-bottom: 16px;
    }

    .hero-description {
        font-size: clamp(0.95rem, 3.5vw, 1.2rem);
        margin-bottom: 24px;
    }

    .role-selector {
        padding: 14px 18px;
        gap: 14px;
        border-radius: 20px;
    }

    .role-icon {
        width: 44px;
        height: 44px;
        font-size: 1.1rem;
    }

    .role-info strong {
        font-size: 1rem;
    }

    .role-info span {
        font-size: 0.8rem;
    }

    /* Student join panel                                         */
    .student-panel-content {
        padding: 28px 20px;
        border-radius: 24px;
        width: 96%;
    }

    .student-panel-content h3 {
        font-size: 1.5rem;
    }

    /* Landing Buttons                                            */
    .landing-btn {
        padding: 12px 22px;
        font-size: 0.95rem;
        border-radius: 14px;
    }

    .landing-btn.full {
        padding: 16px;
        font-size: 1rem;
    }
}


/* ============================================================
   7.  AUTH MODAL  –  mobile
   ============================================================ */

@media (max-width: 480px) {

    .auth-modal {
        width: 92%;
        padding: 28px 20px;
        border-radius: 24px;
        max-height: 92dvh;
        overflow-y: auto;
    }

    .auth-header h2 {
        font-size: 1.7rem;
    }

    .auth-close {
        top: 14px;
        right: 14px;
        width: 34px;
        height: 34px;
    }

    .role-selection-cards {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .role-card {
        padding: 14px 10px;
        gap: 8px;
    }

    .role-card i {
        font-size: 1.5rem;
    }

    .role-card span {
        font-size: 0.85rem;
    }
}


/* ============================================================
   8.  TOP UI LAYER  –  tablet + mobile
   ============================================================ */

@media (max-width: 1024px) {

    .top-ui-layer {
        top: 12px;
        left: 12px;
        right: 12px;
        gap: 8px;
    }

    .ui-control-btn {
        width: 40px;
        height: 40px;
        font-size: 0.9rem;
    }

    .zen-btn {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }

    .zen-controls {
        gap: 4px;
        margin-right: 6px;
    }
}

@media (max-width: 640px) {

    .top-ui-layer {
        top: 8px;
        left: 8px;
        right: 8px;
        gap: 4px;
    }

    .ui-control-btn {
        width: 36px;
        height: 36px;
        font-size: 0.85rem;
        border-radius: 12px;
    }

    /* Allow left bar to scroll horizontally if buttons overflow  */
    .fixed-ui-controls-left {
        max-width: 48%;
    }

    .fixed-ui-controls {
        max-width: 50%;
    }

    /* Zen controls compact on very small screens                 */
    .zen-controls {
        gap: 2px;
        margin-right: 4px;
    }

    .zen-btn {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
        border-radius: 8px;
    }
}

/* Disable hover lift on touch devices (no hover in touch)       */
@media (hover: none) {

    .ui-control-btn:hover {
        transform: none;
    }

    .role-selector:hover {
        transform: none;
    }
}

/* Active press feedback for touch                                */
.ui-control-btn:active {
    transform: scale(0.91) !important;
    opacity: 0.85;
}


/* ============================================================
   9.  ONENOTE NAVIGATION PANEL  –  tablet + mobile
   ============================================================ */

@media (max-width: 900px) {

    /* Navigation takes full width on tablet/mobile               */
    #onenote-nav {
        width: 100% !important;
        border-right: none;
        height: 100dvh;
        padding-top: var(--safe-top);
        padding-bottom: var(--safe-bottom);
    }

    #onenote-nav.bookshelf-expanded {
        width: 100% !important;
    }

    /* Col 1 – Bookshelf                                          */
    .nav-column.bookshelf {
        width: 64px;
        padding: 16px 0;
    }

    .nav-book-item {
        width: 44px;
        height: 44px;
        border-radius: 10px;
        font-size: 0.9rem;
    }

    .nav-book-item span:first-child {
        width: 44px;
        height: 44px;
    }

    .teacher-profile-mini {
        width: 48px;
        height: 48px;
        margin-bottom: 16px;
    }

    .teacher-profile-mini .avatar-circle {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }

    /* Expanded bookshelf acts as a sheet overlay on mobile       */
    .nav-column.bookshelf.expanded {
        position: absolute;
        top: 0;
        left: 0;
        width: 82% !important;
        max-width: 300px;
        height: 100%;
        z-index: 50;
        background: var(--bg-surface-solid);
        box-shadow: 12px 0 50px rgba(0, 0, 0, 0.5);
        border-right: 1px solid var(--border-glass);
    }

    /* Col 2 – Chapters                                           */
    .nav-column.chapters {
        width: 140px;
    }

    .col-header {
        padding: 16px 10px 8px;
        flex-wrap: wrap;
        gap: 6px;
    }

    .col-header h3 {
        font-size: 0.65rem;
    }

    .col-subtitle {
        padding: 0 10px 6px;
        font-size: 0.65rem;
    }

    .col-list {
        padding: 6px 6px 100px;
    }

    /* Nav items compact                                          */
    .nav-item {
        padding: 10px 8px;
        border-radius: 10px;
        margin-bottom: 4px;
        font-size: 0.85rem;
        gap: 10px;
    }

    /* Bulk bar wraps on small screens                            */
    .nav-bulk-bar {
        width: 92%;
        padding: 10px 14px;
        bottom: calc(16px + var(--safe-bottom));
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }

    .bulk-info {
        font-size: 0.8rem;
        padding: 6px 12px;
        width: 100%;
        justify-content: center;
    }

    .bulk-btn {
        height: 36px;
        font-size: 0.8rem;
        padding: 0 10px;
        flex: 1;
        justify-content: center;
        min-width: 0;
    }

    .bulk-close {
        width: 28px;
        height: 28px;
    }
}

@media (max-width: 480px) {

    .nav-column.chapters {
        width: 120px;
    }

    .nav-column.bookshelf {
        width: 56px;
        padding: 12px 0;
    }

    .nav-book-item {
        width: 40px;
        height: 40px;
    }
}


/* ============================================================
   10. LEFT TOOLBAR (side-system) & RIGHT NAV (nav-system)
       ─ Already handled in navigation.css; here we add missing
         safe-area and touch polish.
   ============================================================ */

@media (max-width: 768px) {

    .side-system {
        bottom: calc(12px + var(--safe-bottom));
        left: calc(12px + var(--safe-left));
    }

    .nav-system {
        bottom: calc(12px + var(--safe-bottom));
        right: calc(12px + var(--safe-right));
    }

    /* Bigger tap zones on side tabs                              */
    .side-tab {
        width: 36px;
        height: 48px;
        font-size: 1rem;
    }

    .nav-tab {
        width: 32px;
        height: 44px;
    }

    /* Tool buttons larger hit area                               */
    .tool-btn {
        width: 40px;
        height: 40px;
        font-size: 1.05rem;
    }

    /* Active state — ring + taller tab                           */
    .tool-btn.active {
        box-shadow: inset 0 0 0 2px var(--primary, #6366f1) !important;
    }
    .side-tab.active {
        height: 52px;
        margin: -2px 0;
        box-shadow: inset 0 0 0 2px var(--primary, #6366f1) !important;
    }
    .nav-tab.active {
        height: 50px;
        margin: -2px 0;
        box-shadow: inset 0 0 0 2px var(--primary, #6366f1) !important;
    }

    /* Tactile press feedback                                     */
    .tool-btn:active,
    .side-tab:active,
    .nav-tab:active {
        transform: scale(0.91) !important;
        opacity: 0.8;
    }
}

@media (max-width: 480px) {

    .side-system {
        bottom: calc(10px + var(--safe-bottom));
        left: calc(8px + var(--safe-left));
    }

    .nav-system {
        bottom: calc(10px + var(--safe-bottom));
        right: calc(8px + var(--safe-right));
    }
}


/* ============================================================
   11. PINNED BOTTOM BAR  –  float above safe-area chin
   ============================================================ */

.pinned-bottom-bar {
    bottom: calc(16px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
}

@media (max-width: 768px) {

    .pinned-bottom-bar {
        padding: 8px 14px !important;
        margin-bottom: 0 !important;
        gap: 10px !important;
        width: auto !important;
        max-width: 92vw;
        bottom: calc(20px + var(--safe-bottom));
        left: 50% !important;
        transform: translateX(-50%) !important;
        border-radius: 20px !important;
    }

    /* Compact pen-size dots                                      */
    .pen-size-dot {
        width: 10px;
        height: 10px;
    }
}


/* ============================================================
   12. PREMIUM MODALS  –  full mobile adaptation
   ============================================================ */

@media (max-width: 640px) {

    .premium-modal-box {
        width: 94%;
        padding: 20px 18px !important;
        border-radius: 20px !important;
        max-height: 88vh;
        max-height: 88dvh;
        overflow-y: auto;
    }

    .modal-header-modern {
        padding: 0 0 16px 0 !important;
        margin-bottom: 16px !important;
    }

    .modal-title-text {
        font-size: 1.25rem !important;
    }

    .orientation-selector {
        flex-direction: column;
        gap: 8px;
    }

    .orientation-card {
        padding: 12px;
    }

    .input-modern {
        padding: 13px !important;
        font-size: 16px !important; /* prevents iOS zoom */
    }

    .btn-create-modern {
        padding: 14px !important;
        font-size: 0.95rem !important;
    }
}

@media (max-width: 480px) {

    /* Lesson open-mode modal stacks buttons vertically           */
    #lessonOpenModeModal .premium-modal-box > div > div[style*="flex"] {
        flex-direction: column !important;
    }
}


/* ============================================================
   13. NOTIFICATIONS PANEL  –  mobile
   ============================================================ */

@media (max-width: 640px) {

    .notification-panel-premium {
        width: 94vw !important;
        max-height: 80dvh;
        border-radius: 20px !important;
    }

    .notif-list {
        max-height: 55dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }
}


/* ============================================================
   14. ACTIVITY-STORE  –  mobile
   ============================================================ */

@media (max-width: 768px) {

    .store-overlay {
        padding: 0 !important;
    }

    .store-panel {
        width: 100% !important;
        height: 100dvh !important;
        max-width: 100% !important;
        border-radius: 0 !important;
    }

    .store-header {
        padding: 14px 16px !important;
        flex-wrap: wrap;
        gap: 8px;
    }

    .store-filters {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x;
        flex-wrap: nowrap;
        padding-bottom: 4px;
    }

    .store-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
        padding: 12px !important;
    }

    .store-card {
        border-radius: 14px !important;
    }
}

@media (max-width: 480px) {

    .store-grid {
        grid-template-columns: 1fr !important;
    }
}


/* ============================================================
   15. STUDENT DASHBOARD PANEL – mobile
   ============================================================ */

@media (max-width: 768px) {

    .student-dashboard {
        width: 100vw !important;
        height: 100dvh !important;
        top: 0 !important;
        left: 0 !important;
        border-radius: 0 !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .dashboard-header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px 14px !important;
    }

    .header-actions {
        flex-wrap: wrap;
        gap: 6px;
    }

    .dash-btn {
        font-size: 0.8rem !important;
        padding: 8px 12px !important;
    }

    .student-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
        gap: 10px !important;
        padding: 12px !important;
    }
}


/* ============================================================
   16. AI SIDEBAR  –  mobile
   ============================================================ */

@media (max-width: 768px) {

    .ai-sidebar-container,
    .ai-sidebar {
        width: min(96vw, 360px) !important;
    }
}

@media (max-width: 480px) {

    .ai-sidebar-container,
    .ai-sidebar {
        width: 96vw !important;
        border-radius: 20px 20px 0 0 !important;
        bottom: 0 !important;
        top: auto !important;
        height: 70dvh !important;
    }
}


/* ============================================================
   17. SEARCH SIDEBAR  –  mobile
   ============================================================ */

@media (max-width: 768px) {

    .search-sidebar {
        width: min(96vw, 380px) !important;
    }
}


/* ============================================================
   18. PRESENCE NOTCH  –  safe screen
   ============================================================ */

.presence-notch {
    /* Add safe-area insets ON TOP of the expanded base padding */
    padding-top: calc(10px + var(--safe-top));
    padding-bottom: 10px;
    padding-left: calc(24px + var(--safe-left));
    padding-right: calc(24px + var(--safe-right));
}

@media (max-width: 640px) {

    .presence-notch {
        font-size: 0.8rem;
        /* Keep expanded width — only reduce font, not the padding */
        padding: calc(10px + var(--safe-top)) 24px 10px;
    }

    #digital-clock {
        font-size: 0.8rem;
    }

    #btn-live-session {
        font-size: 0.7rem !important;
        padding: 3px 8px !important;
    }
}


/* ============================================================
   19. AURA-JOIN.HTML GAME SCREENS  –  mobile first
   ============================================================ */

@media (max-width: 640px) {

    /* SketchSolve student panel – stack canvas + AI vertically   */
    .ss-stu-container {
        flex-direction: column !important;
    }

    .ss-ai-panel {
        width: 100% !important;
        min-width: 100% !important;
        max-height: 42dvh;
        border-left: none !important;
        border-top: 1px solid rgba(255, 255, 255, 0.08) !important;
        overflow: hidden;
    }

    .ss-toolbar {
        padding: 8px 10px;
        gap: 6px;
    }

    .ss-tool-btn {
        width: 38px;
        height: 38px;
    }

    .ss-question-bar {
        padding: 12px 14px;
    }

    /* Jigsaw HUD compact                                         */
    .jigsaw-hud {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    /* InsightWall note grid smaller columns                      */
    .iw-wall {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
        padding: 16px 12px 80px !important;
    }

    /* InsightWall FAB safe-area                                  */
    .iw-fab {
        bottom: calc(20px + var(--safe-bottom));
        right: calc(20px + var(--safe-right));
        width: 56px;
        height: 56px;
        font-size: 1.3rem;
    }

    /* AuraQuest option buttons                                   */
    .option-btn {
        padding: 16px 18px;
        font-size: clamp(0.9rem, 3.5vw, 1.2rem);
        gap: 10px;
    }

    .opt-letter {
        font-size: 1rem;
        width: 24px;
    }

    /* Game header compact                                        */
    .game-header {
        padding: 10px 16px;
        font-size: 0.9rem;
    }

    /* Join card compact                                          */
    .join-card {
        padding: 28px 20px !important;
        border-radius: 24px !important;
        max-width: 100%;
    }
}


/* ============================================================
   20. LANDSCAPE MODE  –  short Phones
   ============================================================ */

@media (max-width: 900px) and (orientation: landscape) {

    #landing-page .landing-header {
        height: 54px;
    }

    .landing-hero-container {
        padding: 20px 0;
    }

    .hero-split {
        gap: 24px;
    }

    /* Navigation collapses its column widths further             */
    #onenote-nav {
        width: 100% !important;
    }

    .nav-column.chapters {
        width: 120px;
    }

    /* Side/Nav toolbars anchor to mid-height in landscape        */
    .side-system,
    .nav-system {
        bottom: auto;
        top: 50%;
        transform: translateY(-50%);
    }

    /* AI sidebar in sheet mode in landscape                      */
    .ai-sidebar-container {
        height: 80dvh !important;
    }

    /* Game content padding in landscape                          */
    .game-content {
        padding: 20px 16px 60px !important;
    }
}


/* ============================================================
   21. GLASSMORPHISM BARS – touch-optimised on small screens
   ============================================================ */

@media (max-width: 768px) {

    .side-system .side-panel,
    .nav-system .nav-panel,
    .pinned-bottom-bar {
        background: rgba(255, 255, 255, 0.88) !important;
        backdrop-filter: blur(24px) saturate(180%) !important;
        -webkit-backdrop-filter: blur(24px) saturate(180%) !important;
        border: 1px solid rgba(255, 255, 255, 0.4) !important;
        box-shadow: 0 8px 32px rgba(31, 38, 135, 0.1) !important;
    }

    [data-theme="dark"] .side-system .side-panel,
    [data-theme="dark"] .nav-system .nav-panel,
    [data-theme="dark"] .pinned-bottom-bar {
        background: rgba(15, 23, 42, 0.88) !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45) !important;
    }
}


/* ============================================================
   22. ACTIVITY STORE MODALS (publish, preview) – mobile
   ============================================================ */

@media (max-width: 640px) {

    /* Any dialog that uses the generic .modal-actions row         */
    .modal-actions {
        flex-direction: column;
        gap: 8px;
    }

    .modal-actions .modal-btn {
        flex: none;
        width: 100%;
    }
}


/* ============================================================
   23. ACCESSIBILITY
   ============================================================ */

/* Respect "prefers-reduced-motion" – collapse all animations    */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High-contrast overrides                                        */
@media (prefers-contrast: high) {
    :root {
        --border-glass: rgba(255, 255, 255, 0.35);
        --border-strong: rgba(255, 255, 255, 0.55);
    }
}

/* Focus rings for keyboard navigation (coarser outline on touch)*/
:focus-visible {
    outline: 2px solid var(--primary, #6366f1);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Suppress focus ring entirely on touch (pointer: coarse)       */
@media (pointer: coarse) {
    :focus-visible {
        outline: none;
    }
}


/* ============================================================
   24. UTILITY CLASSES
   ============================================================ */

/* Force enable scrolling */
.scroll-enabled {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
}

/* Force enable touch manipulation */
.touch-enabled {
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent !important;
}

/* Disable all scrolling (painting canvas container, etc.) */
.scroll-disabled {
    overflow: hidden !important;
    touch-action: none !important;
}

/* Horizontal scroll helper (filter bars, etc.) */
.scroll-x {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-x !important;
    scrollbar-width: none;
}

.scroll-x::-webkit-scrollbar {
    display: none;
}


/* ============================================================
   26. PORTRAIT PHONE  (< 430 px wide, portrait)
       These screens skip zoom → need manual responsive layout
   ============================================================ */

/* ── Portrait phone — general fixes ──────────────────────── */
@media (max-width: 429px) and (orientation: portrait) {

    /* Landing page flows naturally */
    #landing-page {
        overflow-y: auto !important;
    }

    .landing-hero-container {
        padding: 28px 0 40px !important;
        justify-content: flex-start;
    }

    .hero-split {
        gap: 28px !important;
    }

    .hero-title {
        font-size: clamp(1.8rem, 9vw, 2.6rem) !important;
        margin-bottom: 12px !important;
    }

    .hero-description {
        font-size: clamp(0.88rem, 4vw, 1.05rem) !important;
        margin-bottom: 20px !important;
    }

    .role-selector {
        padding: 12px 16px !important;
        gap: 12px !important;
        border-radius: 18px !important;
    }

    .role-icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 1rem !important;
    }

    .role-info strong { font-size: 0.95rem !important; }
    .role-info span   { font-size: 0.78rem !important; }

    /* Student join panel */
    .student-panel-content {
        padding: 24px 16px !important;
        border-radius: 20px !important;
        width: 97% !important;
    }

    /* Auth modal */
    .auth-modal {
        padding: 24px 16px !important;
        border-radius: 20px !important;
        width: 96% !important;
    }

    /* Top controls really tight */
    .top-ui-layer {
        top: 6px !important;
        left: 6px !important;
        right: 6px !important;
    }

    .ui-control-btn {
        width: 34px !important;
        height: 34px !important;
        font-size: 0.8rem !important;
    }

    /* Zen controls hidden on portrait phone (use bottom bar) */
    #zen-mode-controls {
        display: none !important;
    }

    /* Side toolbar + nav: portrait phone – float at bottom corners */
    .side-system {
        bottom: calc(8px + var(--safe-bottom)) !important;
        left: calc(8px + var(--safe-left)) !important;
        top: auto !important;
        transform: none !important;
    }

    .nav-system {
        bottom: calc(8px + var(--safe-bottom)) !important;
        right: calc(8px + var(--safe-right)) !important;
        top: auto !important;
        transform: none !important;
    }

    .side-panel  { max-height: 48dvh !important; }
    .nav-panel   { max-height: 48dvh !important; }

    /* Pinned bottom bar centred & smaller */
    .pinned-bottom-bar {
        left: 50% !important;
        transform: translateX(-50%) !important;
        bottom: calc(14px + var(--safe-bottom)) !important;
        padding: 6px 10px !important;
        gap: 8px !important;
        max-width: 88vw !important;
    }

    /* OneNote nav takes full height */
    #onenote-nav {
        width: 100% !important;
        height: 100dvh !important;
    }

    /* Modals */
    .premium-modal-box {
        width: 97% !important;
        padding: 16px 14px !important;
        border-radius: 18px !important;
    }

    /* Store grid: 1 column */
    .store-grid {
        grid-template-columns: 1fr !important;
    }

    /* Student grid cards */
    .student-grid {
        grid-template-columns: 1fr 1fr !important;
    }
}


/* ── Portrait phone — "Rotate for best experience" hint ───── */
/* Shows a gentle banner when teacher opens the canvas in portrait
   phone mode. Can be dismissed. Students never see it.         */
@media (max-width: 429px) and (orientation: portrait) {

    /* Injected by CSS, no JS needed */
    body.is-teacher .zen-workspace::before {
        content: "↺  Rotate for the best teaching experience";
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: rgba(15, 23, 42, 0.92);
        color: #94a3b8;
        font-size: 0.8rem;
        font-weight: 600;
        padding: 10px 18px;
        border-radius: 20px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        white-space: nowrap;
        z-index: 5;
        pointer-events: none;
        letter-spacing: 0.02em;
        backdrop-filter: blur(8px);
        opacity: 0.85;
    }
}


/* ============================================================
   27. SMALL TABLET PORTRAIT (430–899 px wide, portrait)
       JS applies zoom from 900px baseline.
       These styles apply when zoom is NOT engaged (> 900px).
   ============================================================ */

@media (min-width: 430px) and (max-width: 899px) and (orientation: portrait) {

    /* When zoom IS engaged, body has class app-zoomed.
       When not, apply fallback responsive styles.              */
    body:not(.app-zoomed) #onenote-nav {
        width: 100% !important;
    }

    body:not(.app-zoomed) .nav-column.chapters {
        width: 160px !important;
    }

    body:not(.app-zoomed) .nav-bulk-bar {
        width: 92% !important;
        flex-wrap: wrap !important;
    }

    /* Ensure pinned bar doesn't overflow */
    body:not(.app-zoomed) .pinned-bottom-bar {
        max-width: 90vw !important;
    }
}


/* ============================================================
   28. LANDSCAPE PHONE (< 600 px wide, landscape)
       JS skips zoom → responsive CSS handles it.
   ============================================================ */

@media (max-width: 599px) and (orientation: landscape) {

    /* Very short – collapse landing to minimal height */
    .landing-header {
        height: 50px !important;
    }

    .landing-hero-container {
        padding: 12px 0 !important;
    }

    .hero-split {
        gap: 16px !important;
    }

    .hero-title {
        font-size: clamp(1.4rem, 6vw, 2rem) !important;
        margin-bottom: 8px !important;
    }

    .hero-description {
        font-size: 0.85rem !important;
        margin-bottom: 14px !important;
    }

    /* Role selectors side-by-side in landscape phone */
    .hero-role-actions {
        flex-direction: row !important;
        flex-wrap: wrap;
        gap: 10px !important;
    }

    .role-selector {
        flex: 1;
        min-width: 140px;
        padding: 10px 14px !important;
    }

    /* Toolbars: anchor mid-height (more natural in landscape) */
    .side-system,
    .nav-system {
        top: 50% !important;
        bottom: auto !important;
        transform: translateY(-50%) !important;
    }

    /* Bottom bar: ensure it clears keyboard */
    .pinned-bottom-bar {
        bottom: calc(10px + var(--safe-bottom)) !important;
    }

    /* Side panel shorter in landscape phone */
    .side-panel,
    .nav-panel {
        max-height: 70vh !important;
    }
}


/* ============================================================
   29. TOP BAR — stop overlap + shrink in portrait / small screens
       Bottom bar — scrollable horizontal strip
   ============================================================ */

/* ── Top bar: shared shrink logic ──────────────────────────── */
/*
   The top bar has two sides:
     LEFT:  #main-ui-controls-left  (AI, search, students, store…)
     RIGHT: #main-ui-controls       (raise hand, theme, zen, profile…)
   On small / portrait screens they overlap because they grow
   wider than the viewport. Fix: shrink each button AND limit
   each half to ~50% of the viewport so they can never collide.
*/

/* Tablet landscape (≤ 1024px) — mild shrink */
@media (max-width: 1024px) {
    .top-ui-layer {
        top: 10px !important;
        left: 10px !important;
        right: 10px !important;
    }

    .ui-control-btn {
        width: 38px !important;
        height: 38px !important;
        font-size: 0.85rem !important;
    }

    .zen-btn {
        width: 28px !important;
        height: 28px !important;
        font-size: 0.75rem !important;
    }

    .zen-controls {
        gap: 3px !important;
        margin-right: 4px !important;
    }
}

/* Portrait tablet (≤ 900px) — more aggressive */
@media (max-width: 900px) {
    .ui-control-btn {
        width: 34px !important;
        height: 34px !important;
        font-size: 0.8rem !important;
    }

    /* Constrain each side to half viewport max */
    .fixed-ui-controls-left {
        max-width: 48vw !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x !important;
        scrollbar-width: none !important;
        flex-shrink: 0;
    }

    .fixed-ui-controls {
        max-width: 50vw !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x !important;
        scrollbar-width: none !important;
        flex-shrink: 0;
    }

    .fixed-ui-controls-left::-webkit-scrollbar,
    .fixed-ui-controls::-webkit-scrollbar { display: none; }
}

/* Portrait phone (≤ 600px) — maximum shrink, both bars scroll */
@media (max-width: 600px) {
    .top-ui-layer {
        top: 6px !important;
        left: 6px !important;
        right: 6px !important;
        gap: 4px !important;
    }

    .ui-control-btn {
        width: 30px !important;
        height: 30px !important;
        font-size: 0.75rem !important;
        border-radius: 10px !important;
    }

    /* Hide the student-count text label, keep the icon */
    .student-count-badge {
        font-size: 0.6rem !important;
        padding: 1px 3px !important;
    }

    /* Zen controls: hide in portrait to save space, keep in landscape */
    #zen-mode-controls {
        display: none !important;
    }

    .zen-controls { display: none !important; }

    .fixed-ui-controls-left {
        max-width: 50vw !important;
    }

    .fixed-ui-controls {
        max-width: 50vw !important;
    }
}


/* ── Bottom bar: scrollable horizontal strip ───────────────── */
/*
   On small screens the full bar overflows horizontally.
   Solution:
     • Give the bar a fixed max-width (100% of viewport)
     • Make .pinned-tools-container scroll horizontally
     • Keep .pinned-actions (collapse / unpin) always visible on the right
     • Shrink tool buttons to fit the bar height
*/

@media (max-width: 1024px) {
    .pinned-bottom-bar {
        /* Stay centred but allow full width */
        left: 50% !important;
        transform: translateX(-50%) !important;
        max-width: min(94vw, 900px) !important;
        padding: 5px 10px !important;
        gap: 0 !important;
        border-radius: 18px !important;
        /* Prevent bar itself from scrolling — only the container inside scrolls */
        overflow: hidden !important;
        /* Keep bar as a flex row */
        display: flex !important;
        align-items: center !important;
    }

    /* Scrollable tool strip */
    .pinned-tools-container {
        flex: 1 1 0 !important;
        min-width: 0 !important;          /* allow it to shrink */
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x !important;
        scroll-snap-type: x proximity;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
        gap: 8px !important;
        padding: 4px 4px !important;      /* breathing room at ends */
        /* Fade edges to hint there's more content */
        mask-image: linear-gradient(
            to right,
            transparent 0px,
            black 10px,
            black calc(100% - 10px),
            transparent 100%
        );
        -webkit-mask-image: linear-gradient(
            to right,
            transparent 0px,
            black 10px,
            black calc(100% - 10px),
            transparent 100%
        );
    }

    .pinned-tools-container::-webkit-scrollbar { display: none; }

    /* Lock the pinned-actions (collapse + unpin) to the right edge */
    .pinned-actions {
        flex-shrink: 0 !important;
        margin-left: 6px !important;
        padding-left: 8px !important;
    }

    /* Shrink tool buttons */
    .pinned-bottom-bar .tool-btn {
        width: 34px !important;
        height: 34px !important;
        font-size: 0.9rem !important;
        flex-shrink: 0 !important;      /* never let buttons collapse */
    }

    .pinned-bottom-bar .active-color-btn {
        width: 28px !important;
        height: 28px !important;
        flex-shrink: 0 !important;
    }

    /* Pen-size dots in the bottom bar smaller */
    .pinned-bottom-bar .pen-size-dot {
        width: 8px !important;
        height: 8px !important;
    }

    /* Dividers stay thin */
    .pinned-bottom-bar .divider {
        flex-shrink: 0 !important;
        margin: 0 4px !important;
    }
}

/* Small tablet / portrait — even tighter */
@media (max-width: 768px) {
    .pinned-bottom-bar {
        max-width: 96vw !important;
        padding: 4px 8px !important;
        bottom: calc(14px + var(--safe-bottom)) !important;
    }

    .pinned-bottom-bar .tool-btn {
        width: 32px !important;
        height: 32px !important;
        font-size: 0.85rem !important;
    }

    .pinned-tools-container {
        gap: 6px !important;
    }
}

/* Portrait phone — smallest */
@media (max-width: 480px) {
    .pinned-bottom-bar {
        max-width: 98vw !important;
        padding: 3px 6px !important;
        border-radius: 16px !important;
        bottom: calc(12px + var(--safe-bottom)) !important;
    }

    .pinned-bottom-bar .tool-btn {
        width: 30px !important;
        height: 30px !important;
        font-size: 0.8rem !important;
    }

    .pinned-bottom-bar .active-color-btn {
        width: 24px !important;
        height: 24px !important;
    }

    .pinned-tools-container {
        gap: 5px !important;
    }

    /* Collapse & unpin buttons compact */
    .pinned-collapse-btn,
    .unpin-btn {
        width: 26px !important;
        height: 26px !important;
        font-size: 0.75rem !important;
    }
}