/* ============================================================
   SINAPTIQUE — ADAPTATEUR MOBILE
   Toutes les règles sont dans @media (max-width: 768px)
   → ZÉRO impact sur la version desktop
   ============================================================ */

@media (max-width: 768px) {

  /* ── GLOBAL ── */
  body {
    overflow: auto !important;
    overflow-x: hidden !important;
    -webkit-text-size-adjust: 100%;
  }

  * {
    -webkit-tap-highlight-color: transparent;
  }

  /* Empêcher le zoom sur les inputs iOS */
  input, select, textarea {
    font-size: 16px !important;
  }

  /* Cibles tactiles minimum 44x44px (Apple HIG) */
  button, .speak-btn, .tab, a[href] {
    min-height: 44px;
    min-width: 44px;
  }

  /* ── GAME AREA : layouts fixes → viewport ── */
  #game-area,
  .game-area,
  [style*="width: 100vw; height: 100vh"] {
    width: 100vw !important;
    height: auto !important;
    min-height: 100vh;
    overflow-y: auto !important;
  }

  /* Countdown géant → proportionnel */
  .pre-game-countdown-text,
  [style*="font-size: 200px"] {
    font-size: 25vw !important;
  }

  /* ── DRAG-AND-DROP : layout horizontal → vertical ── */
  /* Container des associations (targets + draggables côte à côte) */
  [style*="display: flex"][style*="gap: 30px"],
  [style*="display: flex"][style*="gap: 20px"] {
    flex-direction: column !important;
    align-items: center !important;
    width: 100% !important;
    padding: 10px !important;
  }

  /* Zone des targets */
  [style*="width: 600px"],
  [style*="width: 500px"] {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Zone des draggables */
  [style*="width: 350px"],
  [style*="width: 300px"] {
    width: 100% !important;
    max-width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    gap: 6px !important;
  }

  /* Éléments draggables : plus gros, tactiles */
  .draggable-item {
    min-height: 48px !important;
    min-width: 80px !important;
    padding: 10px 14px !important;
    font-size: 18px !important;
    cursor: pointer !important;
    user-select: none;
    -webkit-user-select: none;
  }

  /* Sélection tactile (remplace le drag) */
  .draggable-item.mobile-selected {
    background-color: #FFD700 !important;
    border: 3px solid #8B0000 !important;
    box-shadow: 0 0 12px rgba(139, 0, 0, 0.5) !important;
    transform: scale(1.05);
  }

  /* Zones de dépôt : plus grandes */
  .char-drop-zone {
    min-height: 50px !important;
    min-width: 80px !important;
    padding: 8px !important;
    font-size: 16px !important;
  }

  /* ── PANIER TONS ── */
  #game-area[style*="800px"],
  [style*="width: 800px; height: 600px"] {
    width: 100vw !important;
    height: 80vh !important;
  }

  #basket,
  [id="basket"] {
    bottom: 60px !important;
  }

  /* D-pad mobile (injecté par JS) */
  .mobile-dpad {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    background: rgba(0, 0, 0, 0.85);
    z-index: 99999;
    padding: 10px;
  }

  .mobile-dpad button {
    width: 80px;
    height: 50px;
    font-size: 28px;
    background: #FFD700;
    color: #8B0000;
    border: 2px solid #8B4513;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    -webkit-user-select: none;
    user-select: none;
  }

  .mobile-dpad button:active {
    background: #FFA000;
    transform: scale(0.95);
  }

  /* ── DACTYLO : QCM mobile ── */
  .mobile-qcm-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 15px;
    max-width: 400px;
    margin: 10px auto;
  }

  .mobile-qcm-btn {
    padding: 16px 12px;
    font-size: 20px;
    font-family: 'KaiTi', 'STKaiti', serif;
    background: white;
    border: 3px solid #8B4513;
    border-radius: 12px;
    cursor: pointer;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-user-select: none;
    user-select: none;
  }

  .mobile-qcm-btn:active {
    background: #FFD700;
  }

  .mobile-qcm-btn.correct {
    background: #C8E6C9 !important;
    border-color: #2E7D32 !important;
  }

  .mobile-qcm-btn.wrong {
    background: #FFCDD2 !important;
    border-color: #C62828 !important;
  }

  /* ── PACMAN ── */
  .mobile-validate-btn {
    padding: 12px 24px;
    font-size: 16px;
    font-weight: bold;
    background: #FFD700;
    color: #8B0000;
    border: 2px solid #8B4513;
    border-radius: 8px;
    margin-left: 8px;
    cursor: pointer;
  }

  /* ── FLASHCARDS / LEARNING ── */
  /* Réduire les tailles fixes des sinogrammes pour mobile */
  [style*="font-size: 120px"] {
    font-size: 60px !important;
  }

  [style*="font-size: 96px"] {
    font-size: 48px !important;
  }

  /* Vidéos de décomposition */
  video[data-char-video] {
    max-width: 40vw !important;
    max-height: 40vw !important;
  }

  /* Canvas d'écriture */
  #write-canvas,
  canvas[style*="border: 3px solid"] {
    max-width: 80vw !important;
    max-height: 80vw !important;
  }

  /* ── MENUS DE JEUX ── */
  /* Boutons de menu : pleine largeur en colonne */
  [style*="display: flex"][style*="gap: 30px"][style*="flex-wrap: wrap"] {
    flex-direction: column !important;
    align-items: stretch !important;
    width: 90% !important;
    margin: 0 auto !important;
  }

  /* Boutons ovales de menu → rectangles pleine largeur */
  button[style*="border-radius: 50%"][style*="width: 200px"],
  button[style*="border-radius: 50%"][style*="width: 280px"] {
    border-radius: 15px !important;
    width: 100% !important;
    height: auto !important;
    min-height: 60px !important;
    padding: 15px !important;
  }

  /* Bouton retour fixe */
  button[style*="position: fixed"][style*="bottom: 30px"] {
    position: fixed !important;
    bottom: 10px !important;
    right: 10px !important;
    width: auto !important;
    min-width: 120px !important;
    height: auto !important;
    min-height: 44px !important;
    padding: 10px 15px !important;
    font-size: 12px !important;
    border-radius: 10px !important;
  }

  /* ── VOLUME WIDGETS ── */
  #menu-volume-widget,
  #seq0-volume-widget,
  [id$="-volume-widget"] {
    bottom: 5px !important;
    left: 5px !important;
    padding: 8px !important;
    transform: scale(0.85);
    transform-origin: bottom left;
  }

  /* ── TABS BAR (cours) ── */
  .tabs-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tab {
    padding: 8px 10px !important;
    font-size: 11px !important;
  }

  .tab-icon {
    font-size: 18px !important;
  }

  .tab-label {
    font-size: 9px !important;
  }

  /* ── TABLEAUX ── */
  .data-table, .vocab-table, table {
    font-size: 13px !important;
  }

  .vocab-table td, .vocab-table th {
    padding: 4px 3px !important;
  }

  /* ── ORIENTATION OVERLAY ── */
  .mobile-landscape-warning {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.95);
    z-index: 999999;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: white;
    font-family: 'Times New Roman', serif;
    text-align: center;
    padding: 30px;
  }

  .mobile-landscape-warning .icon {
    font-size: 60px;
    margin-bottom: 20px;
  }

  .mobile-landscape-warning .msg {
    font-size: 18px;
    line-height: 1.6;
  }
}

/* Landscape detection (outside main media query) */
@media (max-width: 768px) and (orientation: landscape) {
  .mobile-landscape-warning {
    display: flex !important;
  }
}

/* ============================================================
   ADAPTATIONS RÉSOLUTION DESKTOP — SCÈNES DE JEU
   Ces règles s'appliquent à TOUTES les résolutions (pas seulement mobile)
   pour garantir une expérience homogène.
   ============================================================ */

/* ── PANIER TONS : garder 800x600 fixe, scaler le conteneur ── */
/* Le JS du panier utilise des coordonnées en px calibrées pour 800x600.
   On scale le game-container entier plutôt que de changer les dimensions. */

/* ── COUNTDOWNS GÉANTS : 200px → clamp responsive ── */
.pre-game-countdown-text,
[style*="font-size: 200px"],
[style*="font-size:200px"] {
  font-size: clamp(80px, 15vw, 200px) !important;
}

/* ── CARRÉ MNÉSIQUE : character square responsive ── */
[style*="width: 300px; height: 300px"][style*="position: fixed"] {
  width: min(300px, 40vw) !important;
  height: min(300px, 40vw) !important;
}

/* ── BOUTONS DE JEU : taille minimale garantie ── */
[style*="width: 120px"][style*="height: 80px"] {
  min-width: 100px;
  min-height: 60px;
}

/* ── Adaptation pour les écrans < 1400px de large (résolution courante) ── */
@media (max-width: 1400px) {

  /* Grilles de correspondance : réduire les gaps */
  [style*="grid-template-columns"][style*="repeat"] {
    gap: 8px !important;
  }
}

/* ── Adaptation pour les écrans < 1100px de large ── */
@media (max-width: 1100px) {

  /* Boutons de jeu plus petits */
  [style*="border-radius: 50%"][style*="width: 180px"] {
    width: 150px !important;
    height: 70px !important;
    font-size: 14px !important;
  }

  /* Score et timer : repositionner */
  [style*="position: fixed"][style*="font-size: 24px"] {
    font-size: 18px !important;
  }
}

/* ── Adaptation pour les très petits écrans desktop (1024px) ── */
@media (max-width: 1024px) and (min-width: 769px) {

  /* Réduire le character square */
  [style*="width: 300px; height: 300px"] {
    width: 250px !important;
    height: 250px !important;
  }

  /* Compteurs et scores */
  [style*="font-size: 96px"] {
    font-size: 64px !important;
  }
}
