/* =====================================================================================================================
   PERSONAL AND PRIVATE SOFTWARE - NOT OPEN TO THE PUBLIC.
   Developed by a fantastic team, with the help of friendly and fun FABs.
   Reader: please use the immense power of this software to do good for things and people,
   while always making sure it does no harm to anything or anyone.
   =====================================================================================================================
   Coach Maths (mrh-formation.fr) — shared responsive layer (2026-11-29, version 0.1.2).

   Why: every page keeps its own inline <style>; most of them already wrap on narrow screens, but on a phone the menus
   take 3 lines, nested cards eat the width, tables push the page sideways and form fields make iOS zoom in.
   This single file fixes those points for EVERY page (children's maths, Académie, Brevet, revision, admin).

   How it is loaded: one <link rel="stylesheet" href="/css/responsive.css"> placed just before </head>, i.e. AFTER the
   page's own styles, so that rules of the same specificity here win. Root-relative path: the site is served at the
   domain root (OVH folder MRH = mrh-formation.fr, local copy tools/dev/serve.sh = 127.0.0.1:8779).

   Breakpoints:  --phone  ≤ 640px (phones in portrait) ; --small ≤ 380px (small phones: extra tightening).
   Escape hatch: add class "rs-keep" on an element to keep its desktop behaviour (tables: no horizontal scroller).
   Checked with tools/dev/responsive_check.py (headless Chrome, 390 px wide iframe).
   ===================================================================================================================== */

/* ---------- All widths: safety rules that never hurt on desktop ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img, video { max-width: 100%; height: auto; }
svg, canvas, iframe { max-width: 100%; }
/* Long words (URLs, chained formulas) wrap instead of widening the page. */
body { overflow-wrap: break-word; }

/* ---------- Phones (≤ 640px) ---------- */
@media (max-width: 640px) {

    /* iOS zooms into any field whose text is smaller than 16px: keep fields at 16px minimum. */
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea {
        font-size: max(16px, 1em);
        max-width: 100%;
    }

    /* Wide tables scroll inside themselves instead of pushing the whole page sideways
       (display:block keeps the table layout in an anonymous box, the block becomes the scroller). */
    table:not(.rs-keep) {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Code / preformatted blocks: same treatment. */
    pre { max-width: 100%; overflow-x: auto; }

    /* ----- Top menus: one line that scrolls sideways instead of 3 wrapped lines ----- */
    /* Académie (v3_layout.php) */
    .v3-topbar { padding: 8px 10px; gap: 6px; }
    .v3-topbar .brand { font-size: 1rem; }
    .v3-topbar nav {
        margin-left: 0; width: 100%;
        flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
        scrollbar-width: none; padding-bottom: 2px;
    }
    .v3-topbar nav::-webkit-scrollbar { display: none; }
    .v3-topbar nav a { white-space: nowrap; flex: 0 0 auto; padding: 7px 12px; }
    /* Brevet (brevet/css/brevet.css) */
    .b-top { padding: 8px 10px; gap: 4px; }
    .b-top nav {
        width: 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .b-top nav::-webkit-scrollbar { display: none; }
    .b-top nav a, .b-top nav span { white-space: nowrap; flex: 0 0 auto; }
    /* Exercise page (next_skill.php) */
    .topbar { padding: 8px 10px; gap: 6px; }

    /* ----- Page containers: less side padding, the content gets the width ----- */
    .v3-page { padding: 14px 10px 48px; }
    .b-page { padding: 12px 10px 40px; }
    .page { padding: 12px 8px 40px; }
    .b-card { padding: 12px 12px; }
    .v3-card, .v3-mission { padding: 14px 12px; border-radius: 14px; }
    .v3-grid { grid-template-columns: 1fr; gap: 12px; }
    .v3-hero h1 { font-size: 1.35rem; }
    .v3-xpbar { width: 100%; max-width: 240px; }

    /* ----- Exercise card (next_skill.php): nested blocks lose their big paddings ----- */
    .card { border-radius: 14px; }
    .card-top { padding: 12px 12px; }
    .card-body { padding: 16px 10px 20px; }
    .question-block { margin-bottom: 18px; }
    /* "Lire la question" + "Un indice" side by side, each half of the line. */
    .v3-toolbar { gap: 6px; }
    .v3-toolbar .read-aloud-btn, .v3-toolbar .v3-hint-btn { flex: 1 1 40%; text-align: center; }
    /* Lesson comic strip: compact faces, title may wrap above the "Replier" button. */
    .v3-lesson { padding: 10px 8px; }
    .v3-lesson-title { flex-wrap: wrap; gap: 6px; }
    .v3-lesson-panels { grid-template-columns: 1fr; gap: 8px; }
    .v3-panel { padding: 8px; min-height: 0; }
    .v3-panel .v3-panel-face { font-size: 1.6rem; }

    /* ----- Classic path (app.php) header ----- */
    .header { padding-left: 10px; padding-right: 10px; }

    /* ----- Generic: buttons in a row may wrap, long labels allowed to break ----- */
    .v3-btn, .btn { max-width: 100%; white-space: normal; }
}

/* ---------- Small phones (≤ 380px) ---------- */
@media (max-width: 380px) {
    .v3-page, .b-page { padding-left: 8px; padding-right: 8px; }
    .card-body { padding-left: 6px; padding-right: 6px; }
    .v3-avatar { width: 56px; height: 56px; font-size: 1.7rem; }
}
