/* =================================================================
   AI Discovery Lab - phone and tablet layout
   Loaded on every page after the main styles. Desktop (> 900px) is
   untouched; everything here is inside a max-width media query.
   ================================================================= */

/* ---------- Tablets and phones ---------- */
@media (max-width: 900px) {
    html, body { overflow-x: hidden; }
    html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

    /* Top bar: brand on one line, menu as one sideways-scrolling row */
    .topbar {
        position: sticky; top: 0; z-index: 1000;
        flex-direction: column !important; align-items: stretch !important;
        gap: 8px !important; padding: 10px 12px !important;
    }
    .topbar-nav {
        display: flex !important; flex-wrap: nowrap !important;
        overflow-x: auto; -webkit-overflow-scrolling: touch;
        gap: 6px !important; padding-bottom: 2px; scrollbar-width: none;
    }
    .topbar-nav::-webkit-scrollbar { display: none; }
    .topbar-nav > * { flex: 0 0 auto; white-space: nowrap; }

    /* The lab page owns its own hero, movie and steps: the generic
       wrapper sections above it are shortened on small screens. */
    .lab-page .lab-hero-right { display: none !important; }
    .lab-page .lab-hero { grid-template-columns: 1fr !important; }
    body.aidl-own-movie .lab-page #watch-section { display: none !important; }

    /* Lab content fills the screen width */
    .lab-page #dynamic-lab-workspace,
    .lab-page #dynamic-lab-workspace > * { max-width: 100% !important; min-width: 0 !important; }
    .lab-page #dynamic-lab-workspace img,
    .lab-page #dynamic-lab-workspace video,
    .lab-page #dynamic-lab-workspace canvas { max-width: 100%; height: auto; }
    .lab-page #dynamic-lab-workspace table { max-width: 100%; }
    .lab-page #dynamic-lab-workspace input,
    .lab-page #dynamic-lab-workspace select,
    .lab-page #dynamic-lab-workspace textarea { max-width: 100%; font-size: 16px; } /* 16px stops iPhone zooming on tap */

    /* Let every box inside a lab shrink to the screen (zero specificity,
       so a lab's own sizes still win) */
    :where(.lab-page #dynamic-lab-workspace) * { min-width: 0; }
    :where(.lab-page #dynamic-lab-workspace) :where([class*="chart"], [id*="chart"], [class*="table-wrap"], pre) {
        max-width: 100%; overflow-x: auto;
    }

    /* Comfortable tap targets */
    .lab-page #dynamic-lab-workspace button,
    .lab-page #dynamic-lab-workspace .btn { min-height: 40px; touch-action: manipulation; }

    /* Student assignment bar */
    .m-track { flex-direction: column; align-items: stretch !important; gap: 8px; }
}

/* ---------- Phones ---------- */
@media (max-width: 600px) {
    .page-shell { padding-left: 6px !important; padding-right: 6px !important; margin-left: 0 !important; margin-right: 0 !important; }

    .lab-page .lab-hero { padding: 16px !important; gap: 10px !important; }
    .lab-page .lab-hero h1 { font-size: 1.6rem !important; line-height: 1.15 !important; }
    .lab-page .lab-hero p { font-size: .95rem !important; }
    .lab-page .lab-story-banner { display: none !important; }
    .lab-page .lab-hero-left > p { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
    .lab-page .honesty-banner { padding: 12px !important; gap: 10px !important; font-size: .9rem; }

    /* Wrapper sections: thin padding so the lab gets the width */
    .lab-page .lab-section { padding: 8px 4px !important; border-radius: 18px !important; }
    .lab-page .lab-section > .lab-section-header { padding: 6px 8px !important; }
    .lab-page .practice-card { padding: 14px !important; }

    /* Lab root and panels: thinner frames */
    .lab-page #dynamic-lab-workspace [class$="-root"] { padding: 4px !important; border-radius: 16px !important; }
    .lab-page #dynamic-lab-workspace [class$="-panel"],
    .lab-page #dynamic-lab-workspace [class*="-panel "] { padding: 10px !important; margin-left: 0 !important; margin-right: 0 !important; }
    .lab-page #dynamic-lab-workspace [class*="-movie-stage"] { margin-left: 0 !important; margin-right: 0 !important; }

    /* ---- NOVA's movie (all labs use the same film structure) ---- */
    .lab-page [class*="-cfilm"] { min-height: 680px; }
    .lab-page [class*="-cfilm"] > [class*="-top"] { left: 10px !important; right: 62px !important; top: 10px !important; }
    .lab-page [class*="-cfilm"][dir="rtl"] > [class*="-top"] { right: 10px !important; left: 62px !important; }
    .lab-page [class*="-cfilm"] > [class*="-top"] h3 { font-size: 15px !important; line-height: 1.2 !important; }
    .lab-page [class*="-cfilm"] > [class*="-top"] [class$="-step-pill"] { display: none !important; }
    .lab-page [class*="-cfilm"] > [class*="-story"] { left: 10px !important; right: 10px !important; }

    /* Narration box: full width at the bottom, NOVA moves to its corner */
    .lab-page [class*="-cfilm"] > [class*="-caption"] {
        left: 8px !important; right: 8px !important; bottom: 8px !important; top: auto !important;
        min-height: 150px !important; max-height: 210px !important; overflow-y: auto !important;
        padding: 30px 12px 10px !important; font-size: 14.5px !important; line-height: 1.5 !important;
        text-align: start !important;
    }
    .lab-page [class*="-cfilm"] > [class*="-caption"] > * { display: block; max-width: 100%; }
    .lab-page [class*="-cfilm"] > [class*="-cnova"] {
        animation: none !important; /* Safari lets the floating animation win over the size below */
        transform: scale(.36) !important; transform-origin: top right !important;
        right: 4px !important; left: auto !important; top: 4px !important; bottom: auto !important;
    }
    .lab-page [class*="-cfilm"][dir="rtl"] > [class*="-cnova"] {
        transform-origin: top left !important; left: 4px !important; right: auto !important;
    }
    /* The picture area sits between the title and the narration box */
    .lab-page [class*="-cfilm"] > [class*="-board-wrap"] {
        left: 6px !important; right: 6px !important; top: 76px !important; bottom: 222px !important;
        overflow: hidden !important;
    }
}

/* ---------- Very small phones ---------- */
@media (max-width: 380px) {
    .lab-page [class*="-cfilm"] > [class*="-caption"] { font-size: 13.5px !important; }
}

/* Screen-reader-only helpers must never widen the page (Arabic layout) */
.lab-page [class$="-sr"] {
    position: absolute !important; left: 0 !important; right: auto !important;
    width: 1px !important; height: 1px !important; overflow: hidden !important;
    clip: rect(0 0 0 0) !important; clip-path: inset(50%) !important; white-space: nowrap !important;
}
