/* La barre d'onglets au téléphone : 600 px et moins seulement (maquette docs/maquettes/phone-tabs-mockup.html).
   Au-dessus de 600 px rien ne change : la rangée d'onglets reste celle de bordure.css, sans icône, sans « Plus ». */
.barre-bas { display: contents; }   /* au-dessus de 600 px le conteneur n'existe pas : la rangée d'onglets est celle d'aujourd'hui */
.onglets .ic, .plus-onglets, .pt { display: none; }
.onglets .lib-court { display: none; }   /* « Port » : seulement au téléphone (ci-dessous) */

@media (max-width: 600px) {
  :root { --barre: 56px; --zone: env(safe-area-inset-bottom, 0px); }
  html { scroll-padding-bottom: calc(var(--barre) + var(--zone) + 16px); }   /* un Tab sur un élément du bas le fait défiler au-dessus de la barre */
  body:has(#vue-jeu:not([hidden])) .pied { padding-bottom: calc(32px + var(--barre) + var(--zone)); }

  /* L'en-tête tient en trois lignes courtes (98 px au lieu de 160) : titre plus petit, pastilles serrées, sans « au Hutt »
     ni le numéro de saison (.large, gardés pour les lecteurs d'écran). Les pastilles restent à gauche du bouton du son. */
  .en-jeu .entete-in { padding: 8px 12px; gap: 4px 8px; }
  .en-jeu .entete h1 { font-size: 1rem; }
  .en-jeu .resume { gap: 4px; margin: 0; padding-right: 52px; }   /* la place du bouton du son, jusqu'à 320 px */
  .en-jeu .resume .puce { padding: 1px 9px; font-size: .82rem; }
  /* hors de la vue, mais toujours lu par un lecteur d'écran (le numéro de saison n'est écrit nulle part ailleurs) */
  .en-jeu .resume .puce .large { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

  /* L'accueil : « Passer l'intro » et le son montent dans le coin du haut, ils ne couvrent plus le bouton d'entrée. */
  .accueil-pied { top: calc(env(safe-area-inset-top, 0px) + 10px); right: 12px; bottom: auto; }

  /* La barre : une ligne, toujours en bas, sous le dé (40), l'intro (60) et le décollage ; la zone du système s'ajoute dessous. */
  .barre-bas {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
    padding: 0 env(safe-area-inset-right, 0px) var(--zone) env(safe-area-inset-left, 0px);
    background: var(--fond); border-top: 1px solid var(--bord);
  }
  .onglets { display: flex; flex: 1 1 0; min-width: 0; gap: 0; margin: 0; }
  .onglets button, .plus-onglets {
    position: relative; flex: 1 1 0; min-width: 0; min-height: var(--barre); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    padding: 6px 2px 5px; border: 0; border-radius: 0; background: transparent; color: var(--texte-doux);
    font-size: .8rem; line-height: 1.15; text-align: center; overflow-wrap: anywhere;
  }
  .onglets button:focus-visible, .plus-onglets:focus-visible, .rg:focus-visible, .fermer-plus:focus-visible { outline-offset: -3px; }
  .onglets .ic, .plus-onglets .ic { display: block; flex: none; }
  .onglets button[aria-selected="true"], .plus-onglets.actif {   /* le fond, le trait doré et le gras : jamais la couleur seule */
    background: #241d30; color: var(--or-clair); box-shadow: inset 0 3px 0 var(--or); font-weight: 700;
  }
  .onglets [data-plus] { display: none; }
  @media (max-width: 400px) { .onglets button { font-size: .7rem; padding-inline: 1px; } .onglets .ic, .plus-onglets .ic { width: 22px; height: 22px; } }   /* sept cases de 51 px à 360 px (six onglets et « Plus ») : « Vaisseau » tient sans être coupé */
  .onglets .lib-court { display: inline; }   /* six onglets dans la barre : « Port » à vue ; « Spatioport » reste lu par le lecteur d'écran (caché à l'œil, pas retiré) */
  .onglets .lib-long { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .plus-onglets:not([hidden]) { display: flex; flex: 0 0 calc(100% / 7); }   /* « Plus » : une case sur sept, comme chacun des six onglets (il n'apparaît qu'au septième onglet) */

  /* Les pastilles : le nombre de rapports à lire (or, texte sombre), ou un point « Nouveau » sur « Plus ». */
  .pt:not([hidden]) {
    display: block; position: absolute; top: 2px; left: auto; right: calc(50% - 20px); min-width: 18px; height: 18px; padding: 0 4px; box-sizing: border-box;   /* posée sur le coin haut droit de l'icône : ni sur le mot dessous ni sur l'onglet voisin (B14) */
    border: 2px solid var(--fond); border-radius: 9px; background: var(--or); color: #1a1208;
    font-size: .72rem; font-weight: 700; line-height: 18px; text-align: center; margin-left: 0;
  }
  .pt.pt-panne:not([hidden]) { background: var(--rouge); color: #fff; }
  .pt.pt-n { min-width: 0; width: 10px; height: 10px; padding: 0; border-radius: 50%; }

  /* Rien n'est caché derrière la barre : le message d'action et la barre d'essai montent au-dessus. */
  .message { bottom: calc(var(--barre) + var(--zone) + 16px); }
  .barre-essai { bottom: calc(var(--barre) + var(--zone)); }
  .avec-barre-essai { padding-bottom: calc(110px + var(--barre) + var(--zone)); }
  html:has(body.avec-barre-essai) { scroll-padding-bottom: calc(110px + var(--barre) + var(--zone) + 16px); }
  .avec-barre-essai .message { bottom: calc(104px + var(--barre) + var(--zone)); }

  /* Le clavier du téléphone prend le bas de l'écran : tant qu'un champ de texte a le focus, la barre se cache (cases et boutons radio exceptés). */
  body:has(:is(input:not([type="checkbox"], [type="radio"], [type="button"], [type="submit"], [type="range"], [type="file"]), textarea, select):focus) .barre-bas { display: none; }

  /* La feuille « Plus » : un écran par ligne de 56 px, montée depuis la barre. */
  .feuille-plus {
    position: fixed; inset: auto 0 0 0; width: 100%; max-width: none; max-height: 85vh; margin: 0; padding: 0; overflow: auto;
    border: 0; border-top: 2px solid var(--or); border-radius: 16px 16px 0 0; background: rgb(22, 18, 33); color: var(--texte);   /* opaque : la page dessous ne transparaît plus (B4) */
  }
  .feuille-plus::backdrop { background: rgba(0, 0, 0, .6); }
  .feuille-in { padding: 14px 0 calc(14px + var(--zone)); }
  .feuille-plus h2 { margin: 0 0 6px; padding: 0 14px; font-size: 1.05rem; }
  .feuille-plus ul { margin: 0; padding: 0; list-style: none; }
  .rg {
    display: flex; align-items: center; gap: 12px; width: 100%; min-height: var(--barre); padding: 6px 14px; text-align: left;
    border: 0; border-top: 1px solid var(--bord); border-radius: 0; background: transparent; color: var(--texte); justify-content: flex-start;
  }
  .rg[aria-current="true"] { background: #241d30; box-shadow: inset 4px 0 0 var(--or); font-weight: 700; color: var(--or-clair); }
  .rg .chip { margin-left: auto; padding: 0 10px; border: 1px solid var(--or); border-radius: 99px; background: #2a2326; color: var(--or-clair); font-size: .82rem; font-weight: 400; }
  .fermer-plus { width: calc(100% - 28px); margin: 10px 14px 0; min-height: 44px; }

  /* Le cadre « À faire » : la phrase, le pourquoi, puis le bouton dessous ; l'écran défilé, il ne garde que la phrase et le bouton. */
  .afaire { grid-template-columns: minmax(0, 1fr); grid-template-areas: "phrase" "pourquoi" "action" "cours"; gap: 2px; margin-top: 0; padding: 8px 12px; }
  .afaire-phrase { font-size: .94rem; }
  .afaire-pourquoi { font-size: .82rem; }
  .afaire-action { justify-self: start; max-width: none; min-height: 40px; margin-top: 6px; padding: 6px 14px; }
  .afaire-cours { font-size: .8rem; }
  .afaire.replie .afaire-pourquoi, .afaire.replie .afaire-cours, .afaire.replie .afaire-des { display: none; }
  /* Défilé : une ligne (la phrase, le bouton) ; toucher la phrase déplie le détail (classe « deplie », afaire.js). */
  .afaire.replie { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "phrase action"; align-items: center; gap: 0 8px; padding: 2px 8px; }
  .afaire.replie .afaire-phrase { font-size: .86rem; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; padding-block: 8px; }
  .afaire.replie .afaire-action { margin-top: 0; padding: 4px 10px; font-size: .84rem; white-space: nowrap; }
  .afaire.replie.deplie { grid-template-areas: "phrase action" "pourquoi action" "cours cours"; gap: 2px 8px; padding: 4px 8px; }
  .afaire.replie.deplie .afaire-phrase { white-space: normal; overflow: visible; }
  .afaire.replie.deplie .afaire-pourquoi, .afaire.replie.deplie .afaire-cours, .afaire.replie.deplie .afaire-des { display: block; font-size: .8rem; }
  /* Les sous-onglets de la Carte tiennent côte à côte (Tableau n'est plus coupé) ; au pire, la barre défile. */
  #panneau-carte .sous-onglets button, #panneau-spatioport .sous-onglets button, #panneau-marche .sous-onglets button { flex: 1 1 0; min-width: 0; gap: 4px; padding: 6px 4px; font-size: .76rem; letter-spacing: 0; }
  #panneau-carte .sous-onglets, #panneau-spatioport .sous-onglets, #panneau-marche .sous-onglets { gap: 3px; padding: 4px; }
  .sous-nav { gap: 4px; margin-bottom: 10px; }
  .sous-nav-choix { padding: 6px 12px; font-size: .86rem; }
  .sous-onglets { display: flex; flex-wrap: wrap; gap: 6px; }
  .sous-onglets button { flex: 1 1 auto; padding: 8px 12px; font-size: .9rem; }
  .portee-missions button { flex: 1 1 0; }
  .pied button { margin: 4px 6px; }
}

@media (max-width: 600px) and (prefers-reduced-motion: no-preference) {
  .feuille-plus[open] { animation: feuille-monte .16s ease-out; }
  @keyframes feuille-monte { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
}
@media (prefers-reduced-motion: reduce) { .feuille-plus[open] { animation: none; } }

@media (max-width: 600px) and (forced-colors: active) {   /* couleurs forcées : l'écran choisi garde un cadre et un soulignement */
  .onglets button[aria-selected="true"], .plus-onglets.actif, .rg[aria-current="true"] { border: 3px solid CanvasText; text-decoration: underline; }
  .pt { border-color: CanvasText; }
  .feuille-plus { border-color: CanvasText; }
}

/* Paysage bas sur téléphone (orientation paysage et hauteur ≤ 500 px) : en-tête sur une ligne, cadre « À faire » réduit à une ligne
   (son titre et son bouton, le détail caché ou repliable au toucher), onglets plus bas avec boutons ≥ 40 px, sous-onglets sur une ligne défilante. */
@media (orientation: landscape) and (max-height: 500px) {
  html { scroll-padding-top: 12px; }
  .en-jeu .entete { margin-bottom: 2px; }
  .en-jeu .entete-in { flex-wrap: nowrap; padding: 2px 12px; gap: 8px; }
  .en-jeu .entete h1 { font-size: .95rem; white-space: nowrap; flex: none; }
  .en-jeu .resume { flex-wrap: nowrap; gap: 4px; margin: 0; padding-right: 46px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .en-jeu .resume::-webkit-scrollbar { display: none; }
  .en-jeu .resume .puce { flex: none; padding: 1px 8px; font-size: .76rem; white-space: nowrap; }
  .en-jeu .resume .puce .large { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .commande-son { top: calc(env(safe-area-inset-top, 0px) + 1px); }
  #son-global { width: 40px; height: 40px; min-width: 40px; min-height: 40px; }
  .haut-jeu { position: static; padding: 12px 0 2px; gap: 4px; }   /* sous le bouton du son (coin haut droit) : plus de chevauchement avec le bouton du cadre */
  .monde-choisi, #monde-choisi, .sous-onglets, .panneau > [role="tabpanel"], .carte > h2[id], .panneau article > h2[id] { scroll-margin-top: 12px; }
  .afaire {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "phrase action";
    align-items: center;
    padding: 2px 8px;
    gap: 0 8px;
  }
  .afaire-phrase {
    font-size: .86rem;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    padding-block: 11px;   /* une cible de 40 px : la phrase se touche pour déplier */
  }
  .afaire-pourquoi, .afaire-cours, .afaire-des { display: none; }
  .afaire.deplie {
    grid-template-areas: "phrase action" "pourquoi action" "cours cours";
    gap: 2px 8px;
    padding: 4px 8px;
  }
  .afaire.deplie .afaire-phrase { white-space: normal; overflow: visible; }
  .afaire.deplie .afaire-pourquoi, .afaire.deplie .afaire-cours, .afaire.deplie .afaire-des { display: block; font-size: .8rem; }
  .afaire-action {
    min-height: 40px;
    max-width: none;
    margin-top: 0;
    padding: 4px 10px;
    font-size: .84rem;
    white-space: nowrap;
  }
  .sous-nav, .sous-onglets, .filtres-missions {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 4px;
    margin: 0 0 4px;
    scrollbar-width: none;
  }
  .sous-nav { padding-inline-end: 44px; }   /* de la place derrière la flèche « › » collante : le dernier onglet (Bande) n'est plus coupé */
  .sous-nav::-webkit-scrollbar, .sous-onglets::-webkit-scrollbar, .filtres-missions::-webkit-scrollbar { display: none; }
  .sous-nav-choix, .sous-onglets button, .filtre-mission {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 4px 12px;
    font-size: .84rem;
    white-space: nowrap;
  }
  .bandeau-page { margin-bottom: 6px; }
  .bandeau-page img { max-height: 76px; }
  .bandeau-page figcaption { padding: 12px 12px 6px; }
  .bandeau-page h2 { font-size: 1.2rem; }
  .barre-essai { padding: 4px 12px; gap: 6px; font-size: .8rem; }
  .barre-essai button { min-height: 40px; min-width: 40px; padding: 4px 10px; }
  .avec-barre-essai { padding-bottom: 64px; }
}
@media (orientation: landscape) and (max-height: 500px) and (min-width: 601px) {
  .onglets { margin: 2px 0 4px; gap: 4px; }
  .onglets button { min-height: 40px; padding: 4px 8px; font-size: .86rem; }
}
@media (orientation: landscape) and (max-height: 500px) and (max-width: 600px) {
  :root { --barre: 42px; }
  .onglets button, .plus-onglets { min-height: 40px; flex-direction: row; gap: 6px; padding: 2px 6px; }
  .onglets .ic, .plus-onglets .ic { width: 18px; height: 18px; }
  .avec-barre-essai { padding-bottom: calc(64px + var(--barre) + var(--zone)); }
}

/* Les zones à toucher : une carte de choix (espèce, carrière, case à cocher) fait au moins 44 px, et un mot du glossaire
   gagne de la hauteur à toucher sans changer sa ligne de texte (le padding d'un élément en ligne ne bouge pas les lignes). */
@media (max-width: 600px) {
  label.choix { min-height: 44px; box-sizing: border-box; }
  .terme { padding-block: 12px; }
  .repli-tel { margin: 10px 0; }
  .repli-tel > summary { display: flex; align-items: center; min-height: 48px; padding: 8px 14px; cursor: pointer; border: 1px solid var(--bord); border-radius: 10px; background: var(--fond-carte); color: var(--or-clair); font-weight: 600; }
  .repli-tel[open] > summary { margin-bottom: 10px; }
}
.gains.gains-texte li { display: block; }
.gains-texte .bon .terme { color: var(--texte); font-weight: normal; }
