/* === Rummi : le plateau (table, chevalet, tuiles) et l'habillage d'une partie ===
   Chargé après le socle partagé css-jeu.php, qui fournit la carte #app, les boutons,
   la barre du haut et l'overlay. Ici, seulement ce qui est propre au jeu.

   Sert au solo, à l'entraînement, au multijoueur, au défi du jour et au tutoriel. */

:root {
  --rm-tuile-l: 42px;
  --rm-tuile-h: 56px;
  --rm-rouge: #d42a20;
  --rm-bleu: #1a56d6;
  --rm-noir: #14171c;
  --rm-orange: #e8780a;
  --rm-ivoire: #f6f1e4;
}

/* L'attribut hidden doit l'emporter sur les display du socle (.btn est en inline-flex). */
body.page-rummi [hidden] {
  display: none !important;
}

/* Table + chevalet : ce jeu a besoin de plus que le plancher de 800 px du socle. */
body.page-rummi #app {
  max-width: 1100px;
}

.top-bar-outils {
  min-width: 60px;
  display: flex;
  justify-content: flex-end;
}

.rm-bouton-son {
  font: inherit;
  font-size: 1.05rem;
  line-height: 1;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--texte-doux);
  cursor: pointer;
}

.rm-bouton-son:hover {
  border-color: var(--color-light);
  color: var(--texte);
}

/* --- Réglages de la partie (niveau, nombre d'adversaires) ----------------- */
.rm-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 18px;
  margin: 0 0 14px;
}

.rm-options-groupe {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.rm-option {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--texte-doux);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
}

.rm-option:hover {
  border-color: var(--color-mid);
  color: var(--texte);
}

.rm-option.actif {
  background: color-mix(in srgb, var(--color-light) 14%, var(--surface-2));
  border-color: var(--color-light);
  color: #f0f3f6;
}

/* --- Joueurs autour de la table ------------------------------------------- */
.rm-joueurs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.rm-joueur {
  position: relative;
  flex: 1 1 130px;
  min-width: 0;
  padding: 7px 12px 9px;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.rm-joueur.rm-actif {
  border-color: var(--color-light);
}

.rm-joueur.rm-parti {
  opacity: 0.65;
}

.rm-joueur-nom {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--texte);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rm-joueur.rm-moi .rm-joueur-nom {
  color: var(--color-light);
}

.rm-joueur-detail {
  display: block;
  font-size: 0.74rem;
  color: var(--texte-doux);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Temps restant du joueur dont c'est le tour, visible de tous */
.rm-joueur-temps {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: transparent;
}

.rm-joueur-temps i {
  display: none;
  height: 100%;
  width: 100%;
  background: #4a9a67;
  transition: width 0.5s linear;
}

.rm-joueur.rm-actif .rm-joueur-temps i {
  display: block;
}

.rm-joueur-temps i.rm-bientot {
  background: #c99a2e;
}

.rm-joueur-temps i.rm-urgent {
  background: #c9494b;
}

/* --- Pioche, tour, chrono : à droite des joueurs ---------------------------- */
.rm-entete {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 8px;
}

.rm-entete .rm-joueurs {
  flex: 1 1 auto;
  min-width: 0;
  margin-bottom: 0;
}

.rm-pile {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 118px;
  padding: 6px 12px;
  text-align: right;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.76rem;
  color: var(--texte-doux);
}

.rm-pile strong {
  color: var(--texte);
  font-variant-numeric: tabular-nums;
}

.rm-pile .timer {
  margin-left: 8px;
  font-weight: 700;
}

.rm-tour {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--texte-doux);
  white-space: nowrap;
}

.rm-tour.rm-a-moi {
  color: #64ab7c;
}
.rm-message {
  min-height: 2.4em;
  margin: 0 0 8px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--texte-doux);
}

.rm-message.rm-visible {
  background: var(--surface-2);
  border-color: var(--line);
}

.rm-message.rm-erreur {
  color: #e08a8a;
  border-color: #6b3136;
}

.rm-message.rm-succes {
  color: #7fc296;
}

.rm-message.rm-coup {
  color: var(--texte);
}

/* --- Table ----------------------------------------------------------------- */
.rm-table {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  min-height: 170px;
  padding: 10px;
  margin-bottom: 10px;
  background: color-mix(in srgb, #1d5a3f 22%, var(--surface-0));
  border: 1px solid var(--line-forte);
  border-radius: 10px;
}

.rm-table-vide {
  flex: 1 1 100%;
  align-self: center;
  margin: 22px 0;
  font-size: 0.86rem;
  color: var(--texte-doux);
}

.rm-groupe {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  max-width: 100%;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
}

.rm-groupe.rm-incomplet {
  border-style: dashed;
  border-color: #b98a2c;
}

.rm-groupe.rm-invalide,
.rm-groupe.rm-erreur {
  border-color: #c9494b;
  background: rgba(201, 73, 75, 0.14);
}

.rm-groupe.rm-erreur {
  outline: 2px solid #c9494b;
  outline-offset: 1px;
}

/* Une sélection est en main : les combinaisons où l'on peut la poser se signalent,
   y compris au doigt où il n'y a pas de survol. */
.rm-table.rm-a-selection .rm-groupe:not(.rm-fige) {
  border-color: var(--color-light);
  cursor: pointer;
}

.rm-table.rm-a-selection .rm-groupe:not(.rm-fige):hover,
.rm-groupe.rm-cible {
  background: color-mix(in srgb, var(--color-light) 18%, transparent);
  border-color: var(--color-light);
}

.rm-table.rm-cible,
.rm-chevalet.rm-cible {
  outline: 2px dashed var(--color-light);
  outline-offset: -3px;
}

.rm-nouveau {
  flex: 0 0 auto;
  width: var(--rm-tuile-l);
  min-width: 44px;
  min-height: calc(var(--rm-tuile-h) + 10px);
  border: 2px dashed rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  background: transparent;
  color: var(--texte-doux);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.rm-table.rm-a-selection .rm-nouveau,
.rm-nouveau.rm-cible,
.rm-nouveau:hover {
  border-color: var(--color-light);
  color: var(--color-light);
}

/* --- Tuiles ---------------------------------------------------------------- */
.rm-tuile {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: var(--rm-tuile-l);
  height: var(--rm-tuile-h);
  padding: 0;
  font-family: 'Inter', sans-serif;
  font-size: 1.22rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: var(--rm-ivoire);
  border: 1px solid #cfc7b2;
  border-bottom-width: 3px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

div.rm-tuile {
  cursor: default;
}

.rm-num {
  pointer-events: none;
}

/* Chaque couleur a aussi sa forme : on les distingue sans percevoir les couleurs. */
.rm-forme {
  width: 8px;
  height: 8px;
  margin-top: 5px;
  background: currentColor;
  pointer-events: none;
}

.rm-c-r { color: var(--rm-rouge); }
.rm-c-u { color: var(--rm-bleu); }
.rm-c-k { color: var(--rm-noir); }
.rm-c-o { color: var(--rm-orange); }

.rm-c-r .rm-forme { border-radius: 50%; }
.rm-c-u .rm-forme { border-radius: 1px; }
.rm-c-k .rm-forme { clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.rm-c-o .rm-forme { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }

.rm-joker {
  color: #7c3aed;
  font-size: 1.3rem;
}

.rm-joker .rm-forme {
  display: none;
}

button.rm-tuile:hover {
  border-color: #a59c84;
}

.rm-tuile.rm-selectionnee {
  transform: translateY(-5px);
  border-color: var(--color-dark);
  box-shadow: 0 0 0 2px var(--color-dark);
}

/* Tuile posée ce tour-ci : elle peut encore être reprise */
.rm-table .rm-tuile.rm-posee {
  background: #fffbe9;
  border-color: #d8b24a;
}

.rm-tuile.rm-neuve {
  box-shadow: 0 0 0 2px #e8c14a;
  animation: rm-eclat 1.2s ease-out 2;
}

.rm-tuile.rm-piochee {
  box-shadow: 0 0 0 2px #4a9a67;
}

.rm-tuile.rm-indice {
  box-shadow: 0 0 0 3px #e8c14a;
  animation: rm-eclat 1s ease-out 3;
}

.rm-tuile.rm-en-glisse {
  opacity: 0.35;
}

@keyframes rm-eclat {
  0% { background-color: #ffe9a3; }
  100% { background-color: var(--rm-ivoire); }
}

.rm-fantome {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 3000;
  display: flex;
  gap: 2px;
  pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5));
}

body.rm-glisse-en-cours {
  cursor: grabbing;
  user-select: none;
  -webkit-user-select: none;
}

/* --- Première pose : compteur dans l'entête du chevalet --------------------- */
.rm-pose {
  flex: 1 1 auto;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--texte-doux);
}

.rm-pose strong {
  color: var(--texte);
  font-variant-numeric: tabular-nums;
}

.rm-pose.rm-atteint strong {
  color: #64ab7c;
}
/* --- Chevalet -------------------------------------------------------------- */
.rm-chevalet {
  padding: 10px 12px 12px;
  margin-bottom: 10px;
  background: color-mix(in srgb, #7a5230 26%, var(--surface-1));
  border: 1px solid var(--line-forte);
  border-radius: 10px;
}

.rm-chevalet-tete {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 10px;
  margin-bottom: 8px;
}

.rm-chevalet-titre {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--texte-doux);
}

.rm-tris {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rm-tri {
  font-family: 'Inter', sans-serif;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 6px 10px;
  border: 1px solid var(--line-forte);
  border-radius: 6px;
  background: transparent;
  color: var(--texte);
  cursor: pointer;
}

.rm-tri:hover {
  border-color: var(--color-light);
}

.rm-rack {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: calc(var(--rm-tuile-h) + 6px);
  padding: 2px;
}

.rm-espace {
  flex: 0 0 auto;
  width: 20px;
  height: var(--rm-tuile-h);
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: transparent;
  color: transparent;
  font-size: 0.9rem;
  cursor: pointer;
}

.rm-espace:hover {
  border-color: #c9494b;
  color: #c9494b;
}

/* --- Actions --------------------------------------------------------------- */
.rm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.rm-actions .btn {
  flex: 1 1 130px;
  padding: 13px 12px;
}

.rm-sous-plateau {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px 16px;
  margin: 4px 0 16px;
}

.rm-lien {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--texte-doux);
}

.rm-lien:hover {
  color: var(--color-light);
}

/* --- Aide aux gestes ------------------------------------------------------- */
.rm-aide {
  margin: 0 0 14px;
  padding: 10px 14px;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.84rem;
  color: var(--texte-doux);
}

.rm-aide summary {
  font-weight: 700;
  color: var(--texte);
  cursor: pointer;
}

.rm-aide ul {
  margin: 8px 0 2px 18px;
  line-height: 1.5;
}

.rm-texte {
  margin: 6px 0 16px;
  text-align: left;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--texte-doux);
}

.rm-texte h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: #f0f3f6;
  margin: 18px 0 8px;
}

.rm-texte p {
  margin-bottom: 10px;
}

.rm-texte a {
  color: var(--color-light);
}

/* --- Fin de manche --------------------------------------------------------- */
.rm-fin-box {
  position: relative;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.overlay-fermer {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--texte-doux);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.overlay-fermer:hover {
  color: var(--texte);
  background: var(--surface-2);
}

.rm-fin-message {
  font-size: 0.92rem;
  color: var(--texte-doux);
  margin-bottom: 12px;
}

.rm-fin-table {
  width: 100%;
  margin: 0 0 12px;
  border-collapse: collapse;
  font-size: 0.84rem;
  text-align: left;
}

.rm-fin-table th {
  padding: 6px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--texte-faible);
  border-bottom: 1px solid var(--line);
}

.rm-fin-table td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  color: var(--texte);
  font-variant-numeric: tabular-nums;
}

.rm-fin-table th:nth-child(n+3),
.rm-fin-table td:nth-child(n+3) {
  text-align: right;
}

.rm-fin-table tr.rm-fin-gagnant td {
  font-weight: 700;
}

.rm-fin-table tr.rm-fin-moi td:first-child {
  color: var(--color-light);
}

.fin-rang {
  margin: 0 0 12px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #d2973a;
}

.fin-note {
  margin: 0 0 12px;
  font-size: 0.82rem;
  color: var(--texte-doux);
}

.cta-score-msg {
  font-size: 0.86rem;
  color: var(--texte-doux);
  margin-bottom: 10px;
}

.cta-auth-btns {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

/* --- Écrans étroits -------------------------------------------------------- */
@media (max-width: 700px) {

  :root {
    --rm-tuile-l: 36px;
    --rm-tuile-h: 48px;
  }

  body.page-rummi #app {
    padding: 16px 10px 12px;
  }

  .rm-tuile {
    font-size: 1.05rem;
  }

  /* Sur la table les tuiles sont un peu plus petites : une suite de 13 tient sur
     deux lignes au lieu de déborder. */
  .rm-table {
    --rm-tuile-l: 31px;
    --rm-tuile-h: 42px;
    padding: 8px;
    gap: 6px;
    min-height: 150px;
  }

  .rm-table .rm-tuile {
    font-size: 0.95rem;
  }

  .rm-table .rm-forme {
    width: 6px;
    height: 6px;
    margin-top: 3px;
  }

  /* Les joueurs sur une seule ligne, quel que soit leur nombre */
  .rm-joueurs {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .rm-joueur {
    flex: 1 1 0;
    padding: 6px 8px 8px;
  }

  .rm-joueur-nom {
    font-size: 0.78rem;
  }

  .rm-joueur-detail {
    font-size: 0.68rem;
  }

  .rm-message {
    min-height: 0;
    padding: 7px 10px;
    font-size: 0.82rem;
  }

  .rm-chevalet {
    padding: 8px;
  }

  /* Les boutons restent sous le pouce pendant qu'on fait défiler la table */
  .rm-actions {
    position: sticky;
    bottom: 0;
    z-index: 20;
    margin: 0 -10px 10px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: var(--surface-1);
    border-top: 1px solid var(--line-forte);
  }

  .rm-actions .btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 13px 6px;
    font-size: 0.82rem;
  }

  .rm-actions .rm-action-secondaire {
    flex: 0 1 auto;
  }
}

/* Téléphone tenu couché : la hauteur manque, on la rend à la table */
@media (max-height: 480px) and (orientation: landscape) {

  body.page-rummi {
    padding-top: 46px;
  }

  body.page-rummi .top-bar {
    margin-bottom: 8px;
    padding-bottom: 6px;
  }

  body.page-rummi h1 {
    font-size: 1.1rem;
  }

  .rm-options,
  .rm-aide {
    display: none;
  }

  .rm-table {
    min-height: 110px;
  }
}

@media (max-width: 700px) {

  .rm-entete {
    flex-wrap: wrap;
    gap: 6px;
  }

  .rm-pile {
    flex: 1 1 100%;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    min-width: 0;
    padding: 5px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {

  .rm-tuile.rm-neuve,
  .rm-tuile.rm-indice {
    animation: none;
  }
}
