/* Fléchoria 3.2 — charger EN DERNIER. Correctifs de mise en ligne :
   anti-décalage au chargement, messages visibles, grille ajustée à l'écran,
   clavier virtuel repliable sur ordinateur, pages d'information. */

/* 1. Anti-décalage (CLS). route-early.js pose data-view avant le premier rendu ;
      app.mjs le retire quand la vue est prête. */
html[data-view=game] #home,
html[data-view=game] #catalogue,
html[data-view=game] #manifesto,
html[data-view=game] .level-paths,
html[data-view=game] .ad-slot,
html[data-view=level] #home,
html[data-view=catalogue] #home { display: none !important; }
html[data-view=game] #game[hidden] { display: block !important; }
html[data-view=game] #game { visibility: hidden; min-height: 100vh; }
#catalog-list:empty { min-height: 120vh; }
@media screen and (max-width:700px), screen and (max-height:620px) {
  html[data-view=game] .site-header { display: none; }
}

/* 2. Messages du jeu : toujours visibles, sur mobile comme sur ordinateur. */
.toast {
  position: fixed; z-index: 30; top: 12px; left: 50%; transform: translateX(-50%);
  box-sizing: border-box; width: max-content; max-width: min(560px, calc(100% - 24px));
  margin: 0; padding: 12px 16px; border-radius: 10px;
  background: #28392f; color: #f6f2e9; font-size: .9rem; line-height: 1.45;
  box-shadow: 0 6px 24px #0005; cursor: pointer; overflow-wrap: anywhere;
}
.toast[hidden] { display: none; }
body.mobile-playing .toast { top: 152px; }
@media print { .toast { display: none !important; } }

/* 3. Échec de chargement d'une grille : message et boutons visibles dans la zone de jeu. */
.load-error { margin: 12px 0; }
.load-error p { margin: 0 0 12px; }
.load-error .dialog-actions { justify-content: flex-start; margin-top: 0; flex-wrap: wrap; }
#game.grid-unavailable .play-panel,
#game.grid-unavailable .board-tools,
#game.grid-unavailable .board-help,
#game.grid-unavailable .mobile-original-tools,
#game.grid-unavailable #timer-display { display: none !important; }
#game.grid-unavailable:not(.mobile-game-active) #play-workspace { display: none !important; }
/* Mode compact : la barre « ← Grilles / Aide » reste en haut, le message vient juste dessous. */
#game.grid-unavailable.mobile-game-active { display: flex; flex-direction: column; }
#game.grid-unavailable.mobile-game-active > .game-layout { order: -1; }
#game.grid-unavailable.mobile-game-active #play-workspace { display: block; height: auto; min-height: 0; }
#game.grid-unavailable.mobile-game-active #play-workspace > :not(.mobile-topbar) { display: none !important; }
#game.mobile-game-active > .load-error { margin: 12px 8px; }

/* 4. Chronomètre : le libellé ne recouvre plus que la case à cocher. */
.timer-control label { display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }

/* 5. Ordinateur et tablette (mise en page large). */
@media screen and (min-width:701px) and (min-height:621px) {
  /* Dix touches par rangée, sans retour à la ligne (tablette 768 px). */
  .play-workspace .key-row { flex-wrap: nowrap; }
  .play-workspace .key { min-width: 0; flex: 1 1 0; }
  /* Clavier virtuel repliable : la grille récupère la hauteur. */
  .play-workspace.keyboard-collapsed { grid-template-rows: minmax(180px, 1fr); }
  .play-workspace.keyboard-collapsed > .keyboard { display: none; }
  .board-tools #keyboard-toggle { margin-left: auto; }
  .board-tools #keyboard-toggle + #print { margin-left: 0; }
  /* Définitions dans les cases : césure française plutôt que coupure au milieu d'un mot. */
  .clue-button span:first-child { overflow-wrap: break-word; hyphens: auto; }
}
#game.mobile-game-active #keyboard-toggle { display: none; }

/* 6. Panneau d'aide : les trois aides sont visibles d'emblée. */
#player-help-dialog .player-help-actions { margin: .25rem 0 .5rem; }
#player-help-dialog .player-help-actions p { margin: .25rem 0 .75rem; font-size: .85rem; color: var(--muted, #576054); }
#player-help-dialog [hidden] { display: none !important; }

/* 7. Pages d'information (aide, mentions légales, confidentialité, sources, 404). */
.document .updated { color: var(--muted); font-size: .85rem; }
.document address { font-style: normal; line-height: 1.7; margin: 0 0 1rem; }
.document table { border-collapse: collapse; width: 100%; margin: 1rem 0 1.5rem; font-size: .9rem; line-height: 1.5; }
.document th, .document td { text-align: left; vertical-align: top; padding: 10px 12px; border: 1px solid var(--line); }
.document th { background: var(--sage); font-weight: 650; }
.document .table-scroll { overflow-x: auto; }
.document a { overflow-wrap: anywhere; }
.document .actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 24px 0; }
.site-footer nav { flex-wrap: wrap; }

/* 8. Liens « grille précédente / niveau / grille suivante » sous une grille. */
.page-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px 24px; margin: 8px 0 24px; padding-top: 18px; border-top: 1px solid var(--line); font-size: .85rem; }
.page-links a { min-height: 44px; display: inline-flex; align-items: center; }
body.mobile-playing .page-links, html[data-view=game] .page-links { display: none; }
@media print { .page-links { display: none !important; } }
