/* ============================================================
 * GitQuest — Responsive design (mobile / tablette)
 * Ajouté en fin de style.css — surcharge les règles existantes
 * via des media queries (pas de modification du reste du CSS).
 *
 * Stratégie mobile (< 860px):
 *   - Layout jeu: onglets en bas (Mission / Fichiers / État / Historique)
 *     au lieu des 3 colonnes côte à côte (illisible sur téléphone).
 *   - Le terminal reste toujours visible (c'est le cœur du jeu).
 *   - Topbar: titre tronqué, XP compact, badges en icône seule.
 *   - Accueil: carte des niveaux en colonne, stats en grille 2x2.
 *   - Modales: plein écran sur mobile, boutons empilés.
 *   - Touch: cibles tactiles >= 44px, pas de hover.
 *   - 100dvh au lieu de 100vh (évite le bug de la barre d'URL mobile).
 * ============================================================ */

/* ---------- Base: hauteur dynamique (barre d'URL mobile) ---------- */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
  .screen { height: 100dvh; }
  #game-layout { height: calc(100dvh - 52px); }
}

/* ---------- Tablette (860–1100px): colonnes plus étroites ---------- */
@media (max-width: 1100px) {
  #game-layout { grid-template-columns: 200px 1fr 220px; }
  .logo { font-size: 42px; }
  .home-card { max-width: 90%; }
}

/* ---------- Mobile (< 860px) ---------- */
@media (max-width: 860px) {

  /* ===== Accueil ===== */
  .home-card { padding: 20px 12px; }
  .logo { font-size: 36px; }
  .tagline { font-size: 15px; margin-bottom: 16px; }
  .home-stats { gap: 10px; margin-bottom: 18px; }
  .home-stat { min-width: 0; flex: 1 1 40%; padding: 10px 12px; }
  .home-stat .num { font-size: 20px; }
  .level-row { flex-direction: column; }
  .level-connector { width: auto; height: 20px; transform: rotate(90deg); font-size: 14px; }
  .level-node { padding: 12px; }
  .level-node .lv-name { font-size: 14px; }
  .home-actions { flex-direction: column; align-items: stretch; }
  .home-actions .btn { width: 100%; padding: 12px; font-size: 15px; }
  .home-footer { font-size: 11px; }

  /* ===== Topbar ===== */
  #topbar { height: auto; min-height: 48px; padding: 6px 8px; flex-wrap: wrap; gap: 6px; }
  .tb-left { gap: 6px; flex: 1 1 100%; min-width: 0; }
  .tb-right { gap: 8px; flex: 1 1 100%; justify-content: space-between; }
  .scenario-title { font-size: 13px; }
  .xp-bar { width: 60px; }
  .xp-text { font-size: 10px; }
  .total-xp { font-size: 11px; }
  #btn-badges { padding: 6px 10px; }
  #btn-back { padding: 6px 10px; font-size: 12px; }

  /* ===== Layout jeu: onglets ===== */
  #game-layout {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 96px); /* topbar peut prendre 2 lignes */
    overflow: hidden;
  }
  @supports (height: 100dvh) {
    #game-layout { height: calc(100dvh - 96px); }
  }

  /* Le terminal prend tout l'espace disponible */
  #terminal-pane { flex: 1; min-height: 0; order: 1; }

  /* Les panneaux latéraux deviennent des onglets (voir JS mobile-tabs) */
  #sidebar, #state-pane {
    order: 2;
    max-height: 38vh;
    overflow-y: auto;
    border: none;
    border-top: 1px solid var(--border);
    padding: 8px;
    display: none; /* caché par défaut, activé par les onglets */
  }
  #sidebar.active, #state-pane.active { display: flex; }
  /* L'onglet Mission est le plus chargé (gros scénarios des niveaux 4-5) : plus de place */
  #sidebar.active { max-height: 62vh; }
  #mission-story { font-size: 14px; line-height: 1.6; }
  .mission-goal { font-size: 13px; }

  /* Barre d'onglets mobile (injectée par JS) */
  .mobile-tabs {
    order: 3;
    display: flex;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }
  .mobile-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
    background: transparent;
    border: none;
    border-top: 2px solid transparent;
    color: var(--text-dim);
    font-family: var(--font-sans);
    font-size: 11px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-tab .mt-icon { font-size: 18px; line-height: 1; }
  .mobile-tab .mt-label { font-size: 11px; }
  .mobile-tab.active { color: var(--accent); border-top-color: var(--accent); background: rgba(88,166,255,0.06); }

  /* ===== Terminal ===== */
  .terminal { padding: 10px 12px; font-size: 12px; line-height: 1.5; }
  #terminal-input { font-size: 16px; } /* évite le zoom auto iOS */
  .terminal-input-line { padding: 8px 0 4px; gap: 6px; }
  .prompt { font-size: 12px; }

  /* ===== Panneaux ===== */
  .panel { padding: 10px; border-radius: 6px; }
  .panel h3 { font-size: 11px; margin-bottom: 6px; }
  #mission-story { font-size: 13px; }

  /* Boutons tactiles: min 44px de hauteur */
  .btn { padding: 10px 14px; font-size: 14px; min-height: 40px; }
  .btn-validate { font-size: 15px; padding: 12px 16px; min-height: 46px; }
  .hint-buttons { flex-direction: row; }
  .hint-buttons .btn { flex: 1; font-size: 13px; padding: 10px 8px; }
  .mini-btn { width: 32px; height: 32px; font-size: 14px; }

  /* ===== Modales: plein écran ===== */
  .modal { align-items: flex-end; }
  .modal-card {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
  }
  .modal-header { padding: 14px 16px; font-size: 14px; }
  .modal-actions { flex-direction: column-reverse; padding: 12px 16px 20px; gap: 8px; }
  .modal-actions .btn { width: 100%; padding: 12px; font-size: 15px; }
  #modal-file-content { min-height: 50vh; font-size: 14px; padding: 12px; }
  .modal-win { padding: 24px 16px; }
  .modal-flash { width: 100%; }
  .flash-zone { padding: 14px; }
  .flash-q { font-size: 14px; }
  .flash-choice { font-size: 13px; padding: 12px; min-height: 44px; }
  .win-emoji { font-size: 48px; }
  .modal-win h2 { font-size: 20px; }

  /* ===== Toast ===== */
  .toast {
    bottom: 80px; /* au-dessus de la barre d'onglets */
    width: calc(100% - 32px);
    max-width: 400px;
    text-align: center;
    font-size: 13px;
    padding: 12px 16px;
  }

  /* ===== Scrollbars tactiles: plus besoin de barre visible ===== */
  ::-webkit-scrollbar { width: 4px; height: 4px; }
}

/* ---------- Très petit écran (< 400px) ---------- */
@media (max-width: 400px) {
  .logo { font-size: 30px; }
  .scenario-title { font-size: 12px; }
  .level-pill { display: none; }
  .xp-text { display: none; }
  .terminal { font-size: 11px; padding: 8px 10px; }
  .mobile-tab { font-size: 10px; padding: 6px 2px; }
  .mobile-tab .mt-icon { font-size: 16px; }
  .home-stat { padding: 8px 10px; }
  .home-stat .num { font-size: 18px; }
  .home-stat .lbl { font-size: 10px; }
}

/* ---------- Paysage téléphone (hauteur faible) ---------- */
@media (max-width: 860px) and (max-height: 480px) {
  #game-layout { height: calc(100vh - 80px); }
  @supports (height: 100dvh) {
    #game-layout { height: calc(100dvh - 80px); }
  }
  #sidebar, #state-pane { max-height: 30vh; }
  .terminal { font-size: 11px; }
  .logo { font-size: 28px; }
  .tagline { font-size: 13px; margin-bottom: 10px; }
  .home-stats { margin-bottom: 12px; }
}

/* ---------- Touch: désactiver le hover sticky sur mobile ---------- */
@media (hover: none) {
  .btn:hover { border-color: var(--border); }
  .btn-primary:hover { background: var(--accent); }
  .btn-ghost:hover { background: transparent; color: var(--text); }
  .level-node:hover:not(.locked) { transform: none; box-shadow: none; }
  .file-item:hover { background: transparent; }
}
