/*  corse.css — un tapis de feutre dans la nuit du manoir, trois paquets face
 *  cachée, un tas au milieu, et rien qui ne tienne qu'à sa teinte.
 *
 *  ═══ LE JEU EST EN PHASER, LES COMMANDES EN DOM ═══
 *
 *  Le tapis, les paquets, le tas, la main qui s'abat et l'onde de choc sont
 *  peints par Phaser dans `#table` ; les cinquante-deux faces viennent du
 *  peintre partagé (assets/ludi-cartes-phaser.js), qui les grave UNE FOIS
 *  dans des textures. Les décisions sont trois BOUTONS de 44 px — Taper,
 *  Poser, Nouvelle — fixés en bas sur un téléphone debout, à droite couché.
 *
 *  ═══ TOUT LE TAPIS EST LA ZONE DE TAPE ═══
 *
 *  Sur un téléphone, une petite zone de tape n'est pas une zone de tape,
 *  c'est un test d'adresse. Le canevas ENTIER reçoit le doigt ; « Poser »
 *  est un bouton séparé, plus bas, hors du tapis.
 *
 *  ═══ L'ÉTAT N'EST JAMAIS PORTÉ PAR LA SEULE COULEUR ═══
 *
 *  Le joueur dont c'est le tour est doré ET porte un point ; le gagnant est
 *  doré ET porte une couronne ; « Poser » est DÉSACTIVÉ en bord pointillé
 *  quand ce n'est pas à vous, et son titre dit pourquoi ; le motif, quand le
 *  prof le montre, est entouré d'un liseré — pas teinté. Les jetons `--ba-*`
 *  sont MESURÉS par le banc : 4,5:1 (textes), 3:1 (repères).
 */
:root {
  /*  Les six jetons communs aux salons récents, gardés tels quels. */
  --ba-nuit:     #1b1526;
  --ba-panneau:  #2a2338;
  --ba-liseré:   #6b5a90;
  --ba-texte:    #f0ead9;
  --ba-doux:     #c9c0dc;
  --ba-or:       #f0d68a;

  /*  Le tapis de feutre, et ce qu'on y trace. */
  --ba-tapis:    #22303f;
  --ba-tapis-b:  #141d27;
  --ba-trace:    #8fb6d2;   /* les repères de place sur le feutre (repère, 3:1) */
  --ba-rouge:    #ff8a7a;   /* « tape à tort » (texte, 4,5:1) */
  --ba-cadre:    #4b3a63;
  --ba-cadre-b:  #2b2140;

  /*  Le tas, la main, les motifs. */
  --ba-main:     #e8cfae;   /* la main qui s’abat */
  --ba-main-b:   #b08c62;
  --ba-motif:    #f0d68a;   /* le liseré du motif, quand le prof le montre */
  --ba-dos:      #3b2a52;   /* le dos des cartes du peintre partagé */

  --ba-sur:    #7fd39a;
  --ba-alerte: #ef8a8a;
  --ba-bord:   #8a78b0;

  /*  Les commandes, en couleurs opaques — reprises du cochonnet, mesurées. */
  --ba-ctl:        #231b2d;
  --ba-ctl-vif:    #31293a;
  --ba-ctl-or:     #3d3033;
  --ba-ctl-or-vif: #4e413b;
}

/* ═══════════════════════════════════ LA BARRE, ET SES COMMANDES ═════════ */

.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px clamp(10px, 2vw, 16px);
}
.sep { width: 1px; align-self: stretch; background: var(--ba-liseré); margin: 0 2px; }

.bar a {
  font-size: 13px; color: var(--ba-texte); text-decoration: none;
  border: 1px solid var(--ba-bord); border-radius: 8px;
  padding: 7px 11px;
  transition: background .16s, border-color .16s;
}
.bar a:hover { background: var(--ba-ctl-vif); border-color: var(--ba-or); }
.bar a:focus-visible { outline: 3px solid var(--ba-or); outline-offset: 2px; }

.bar button, .ba-outils button, .ba-groupe button {
  font-family: inherit; font-size: 13px; color: var(--ba-texte);
  background: var(--ba-ctl);
  border: 1px solid var(--ba-bord); border-radius: 8px;
  padding: 7px 11px; cursor: pointer; min-height: 40px;
  transition: background .16s, border-color .16s, transform .1s;
}
.bar button:hover:not(:disabled), .ba-outils button:hover:not(:disabled), .ba-groupe button:hover:not(:disabled) { background: var(--ba-ctl-vif); border-color: var(--ba-or); }
.ba-outils button:active:not(:disabled) { transform: translateY(1px); }
.bar button:focus-visible, .ba-outils button:focus-visible, .ba-groupe button:focus-visible { outline: 3px solid var(--ba-or); outline-offset: 2px; }
@media (pointer: coarse) { .bar button, .ba-outils button, .ba-groupe button { min-height: 44px; } }

.ba-outils button kbd {
  font: 11px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--ba-doux);
  border: 1px solid var(--ba-bord); border-radius: 4px; padding: 1px 4px; margin-left: 2px;
}
.ba-outils button.gold { background: var(--ba-ctl-or); border-color: var(--ba-or); font-weight: bold; }
.ba-outils button.gold:hover:not(:disabled) { background: var(--ba-ctl-or-vif); }
/*  ═══ L'INTERDIT SE VOIT ═══ bord pointillé, texte doux, et le `title` dit
    pourquoi. Aucune commande n'est cachée : une commande qui disparaît
    n'enseigne rien. */
.bar button:disabled, .ba-outils button:disabled, .ba-groupe button:disabled {
  background: transparent; color: var(--ba-doux);
  border-style: dashed; cursor: not-allowed; font-weight: normal; opacity: .85;
}
.ba-outils button[hidden] { display: none; }

body.ludi-scene { background: var(--ba-nuit); color: var(--ba-texte); }
h1 { font-family: Fraunces, Georgia, 'Times New Roman', serif; letter-spacing: .3px; }

/* ─────────────────────────────────────────────────────── le bandeau d’état ── */

.etat {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center;
  flex: 0 0 100%; box-sizing: border-box;
  margin: 0 auto 10px; max-width: 1100px; padding: 6px 14px;
  background: var(--ba-panneau); border: 1px solid var(--ba-liseré);
  border-radius: 10px; color: var(--ba-doux); font-size: .94rem;
}
.etat b { color: var(--ba-texte); font-variant-numeric: tabular-nums; }

.ba-jeton {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px 3px 4px; border-radius: 999px;
  background: var(--ba-ctl); border: 1px solid var(--ba-bord);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 1px 3px rgba(0, 0, 0, .45);
  color: var(--ba-doux); font-size: .88rem; white-space: nowrap;
}
.ba-jeton b { font-size: 1rem; min-width: 1.2em; text-align: center; }
.ba-jeton[hidden] { display: none; }
/*  À vous : le jeton se dore ET porte un point ; le gagnant, une couronne ;
    celui qui a quitté la table est barré. */
.ba-jeton.a-vous { border-color: var(--ba-or); }
.ba-jeton.a-vous b::after { content: ' ●'; color: var(--ba-or); font-size: .7em; }
.ba-jeton.gagnant { border-color: var(--ba-or); }
.ba-jeton.gagnant b::after { content: ' ♛'; color: var(--ba-or); font-size: .8em; }
.ba-jeton.sorti { opacity: .55; }
.ba-jeton.sorti b { text-decoration: line-through; }
.ba-ico {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%; box-sizing: border-box;
  display: inline-flex; align-items: center; justify-content: center;
  font: 700 12px/1 Georgia, 'Times New Roman', serif; font-style: normal; color: var(--ba-or);
  background: radial-gradient(circle at 35% 30%, #5a4a78, var(--ba-ctl-or) 70%);
  border: 1px solid var(--ba-or);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), inset 0 -2px 0 rgba(0, 0, 0, .35);
}

.ba-choix { display: inline-flex; gap: 8px; align-items: center; position: relative; margin-left: auto; }
.ba-options {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 30; min-width: 280px; max-width: min(92vw, 420px);
  display: flex; flex-direction: column; gap: 8px; padding: 10px 12px;
  background: var(--ba-panneau); border: 1px solid var(--ba-or); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5); color: var(--ba-texte); font-size: 14px;
  max-height: min(70vh, 560px); overflow: auto; text-align: left;
}
.ba-options[hidden] { display: none; }
.ba-options h4 { margin: 0 0 2px; font-size: 13px; color: var(--ba-or); text-transform: uppercase; letter-spacing: .04em; }
.ba-options .ba-option { display: flex; align-items: center; gap: 8px; cursor: pointer; min-height: 28px; }
.ba-options .ba-option input { accent-color: var(--ba-or); width: 18px; height: 18px; margin: 0; }
.ba-groupe { display: flex; align-items: center; gap: 6px 10px; flex-wrap: wrap; }
.ba-groupe > span { color: var(--ba-doux); font-size: 13px; margin-right: 2px; min-width: 72px; }
.ba-groupe label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; min-height: 28px; }
.ba-groupe label input { accent-color: var(--ba-or); width: 16px; height: 16px; margin: 0; }
.ba-groupe button { min-width: 40px; padding: 5px 9px; min-height: 36px; }
.ba-note { color: var(--ba-doux); font-size: 12.5px; font-style: italic; min-height: 1em; }
.ba-puce {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
  background: var(--ba-ctl-or); border: 1px solid var(--ba-or); color: var(--ba-texte);
  font: inherit; font-size: .92rem; font-weight: 600;
}
.ba-puce:hover { background: var(--ba-ctl-or-vif); }
.ba-puce:focus-visible { outline: 3px solid var(--ba-or); outline-offset: 2px; }
@media (pointer: coarse) { .ba-puce { min-height: 44px; } }
.ba-chevron { color: var(--ba-or); font-size: .8em; }

/*  ═══ LE VERDICT FLOTTE SUR LA LIGNE DES VOIX ═══ */
.ba-voix { position: relative; width: 100%; max-width: 100%; }
#verdict { display: none; }
#verdict:not(:empty) {
  display: flex; align-items: center; box-sizing: border-box;
  position: absolute; left: 0; top: 0; right: 0; bottom: 0; z-index: 6;
  padding: 5px 10px; border-radius: 9px; font-weight: 700; font-size: .9rem; line-height: 1.3;
  background: var(--ba-panneau); border: 1px solid var(--ba-or);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .55); overflow: hidden;
}
#verdict.bon   { color: var(--ba-sur); }
#verdict.tiede { color: var(--ba-or); }
#verdict.dur   { color: var(--ba-alerte); }

/* ─────────────────────────────────────────────────────────────── le plateau ── */

.plateau {
  display: flex; flex-wrap: wrap; gap: clamp(10px, 2vw, 20px);
  justify-content: center; align-items: flex-start; align-content: flex-start;
  margin: 0 auto; max-width: min(1500px, 98vw);
  min-height: var(--plateau, auto);
}
.ba-colonne { display: flex; flex-direction: column; gap: 8px; align-items: center; min-width: 0; max-width: 100%; position: relative; width: 100%; }

.ba-cadre {
  position: relative; box-sizing: border-box; max-width: 100%; overflow: hidden;
  display: inline-block; line-height: 0;
  padding: 6px; border-radius: 12px;
  background: linear-gradient(145deg, var(--ba-cadre), var(--ba-cadre-b));
  border: 2px solid var(--ba-liseré);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .16),
    inset 0 -3px 0 rgba(0, 0, 0, .45),
    0 10px 28px rgba(0, 0, 0, .55);
  transition: box-shadow .2s;
}
.ba-cadre.refus { animation: ba-refus .3s ease; }
@keyframes ba-refus {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-4px); }
  70% { transform: translateX(4px); }
}
/*  ═══ UNE TAPE À TORT SE VOIT SUR LE CADRE ═══ le tapis rougit un instant :
    l'information n'est pas seulement écrite, elle est aussi ressentie. */
.ba-cadre.tort { animation: ba-tort .45s ease; }
@keyframes ba-tort {
  0% { box-shadow: 0 0 0 0 var(--ba-alerte), 0 10px 28px rgba(0, 0, 0, .55); }
  35% { box-shadow: 0 0 0 5px var(--ba-alerte), 0 10px 28px rgba(0, 0, 0, .55); }
  100% { box-shadow: 0 0 0 0 var(--ba-alerte), 0 10px 28px rgba(0, 0, 0, .55); }
}
/*  L'hôte de Phaser : tout le tapis prend le doigt, et la page ne bouge pas. */
#table {
  display: block; border-radius: 8px; background: var(--ba-tapis);
  cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
  overflow: hidden;
}
#table canvas { display: block; border-radius: 8px; }
#table:focus-visible { outline: 3px solid var(--ba-or); outline-offset: -3px; }

/*  ═══ L'ANNONCE TRAVERSE L'ÉCRAN ═══ (Doublé !, Sandwich !, Raté !, la fin) */
.ba-annonce {
  position: absolute; left: 0; right: 0; top: 38%; z-index: 5;
  transform: translateX(-100%); opacity: 0; pointer-events: none; text-align: center;
  font: 700 clamp(1.2rem, 4.2vw, 2rem)/1 Fraunces, Georgia, 'Times New Roman', serif; color: var(--ba-or);
  letter-spacing: .04em; text-shadow: 0 0 16px rgba(0, 0, 0, .9), 0 2px 0 var(--ba-cadre-b);
  padding: 10px 0; line-height: 1;
  background: linear-gradient(90deg, rgba(27, 21, 38, 0), rgba(27, 21, 38, .94) 12%, rgba(27, 21, 38, .94) 88%, rgba(27, 21, 38, 0));
  border-top: 1px solid var(--ba-or); border-bottom: 1px solid var(--ba-or);
}
.ba-annonce.dur { color: var(--ba-alerte); border-color: var(--ba-alerte); }
.ba-annonce.on { animation: ba-annonce 1.4s linear forwards; }
@keyframes ba-annonce {
  0%      { opacity: 0; transform: translateX(-100%); animation-timing-function: cubic-bezier(.2, .8, .3, 1); }
  16%     { opacity: 1; transform: translateX(0); }
  80%     { opacity: 1; transform: translateX(0); animation-timing-function: cubic-bezier(.6, 0, .8, .4); }
  100%    { opacity: 0; transform: translateX(100%); }
}

/*  ═══ LES COMMANDES ═══ Taper, Poser, Nouvelle. */
.ba-outils { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; max-width: 100%; }
.ba-outils button { min-width: 44px; min-height: 44px; font-size: 1rem; font-weight: 700; padding: 6px 12px; }
.ba-outils button .lib { font-size: .8rem; font-weight: 400; }
.ba-outils button .ico { font-size: 1.15rem; }
/*  « Taper » est la commande du salon : elle est plus grande que les autres. */
.ba-outils button[data-cmd="taper"] { min-height: 52px; font-size: 1.1rem; padding: 6px 20px; }
@media (pointer: coarse) { .ba-outils button[data-cmd="taper"] { min-height: 56px; } }

.ba-dit {
  box-sizing: border-box; width: 100%; max-width: 100%; min-height: 2.6em;
  padding: 5px 10px; border-radius: 9px;
  background: var(--ba-panneau); border: 1px dashed var(--ba-bord);
  color: var(--ba-doux); font: 13.5px/1.35 Georgia, 'Times New Roman', serif;
  transition: border-color .3s, color .3s;
}
.ba-dit b { color: var(--ba-or); font-weight: 700; margin-right: 4px; }
.ba-dit.skelet b { color: var(--ba-doux); }
.ba-dit.on { border-style: solid; border-color: var(--ba-or); color: var(--ba-texte); }
.ba-dit.on.skelet { border-color: var(--ba-doux); }

.ba-legende { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .84rem; color: var(--ba-doux); justify-content: center; }
.ba-legende span { display: inline-flex; align-items: center; gap: 7px; }
.ba-legende b { color: var(--ba-or); font-weight: 700; }
.ba-legende code {
  font: 12px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--ba-texte);
  background: var(--ba-ctl); border: 1px solid var(--ba-bord); border-radius: 4px; padding: 2px 5px;
}
.ba-legende kbd {
  font: 11px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--ba-doux);
  border: 1px solid var(--ba-bord); border-radius: 4px; padding: 1px 4px;
}

@media (min-width: 1081px) {
  .ba-voix, .ba-legende { max-width: calc(100vw - 360px); }
}
@media (max-width: 1500px) {
  .etat { gap: 6px 8px; padding: 6px 10px; }
  .ba-jeton { padding: 3px 8px 3px 3px; }
  .ba-jeton .ba-lib { display: none; }
  .ba-outils button kbd { display: none; }
}
@media (max-height: 860px) {
  .ba-legende { display: none; }
}

.lb-sur .lb-sep { display: inline-block; }

/* ─────────────────────────────────────────────────────────── petits écrans ── */

@media (max-width: 640px), (max-height: 480px) {
  h1 { font-size: 1.05rem; margin: 4px 0 4px; }
  .bar { display: none; }
  .etat { font-size: 13px; gap: 3px 5px; padding: 3px 6px 3px; margin-bottom: 4px; }
  .ba-jeton { padding: 1px 6px 1px 2px; font-size: 12px; gap: 3px; }
  .ba-jeton .ba-lib { display: none; }
  .ba-jeton b { font-size: 13px; min-width: 0; }
  .ba-ico { width: 18px; height: 18px; font-size: 10px; }
  #jeton-meilleur, #jeton-coups { display: none; }
  .ba-choix { margin-left: 0; }
  .ba-puce#variantes { max-width: min(40vw, 200px); }
  .ba-puce#variantes #titre-variante { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .ba-puce#options { padding-left: 8px; padding-right: 8px; }
  .ba-options { right: auto; left: 0; min-width: min(92vw, 340px); }
  .ba-legende { display: none; }
  .plateau { gap: 4px; max-width: none; width: calc(100% + 16px); margin-left: -8px; }
  .ba-colonne { width: 100%; gap: 4px; }
  .ba-cadre { padding: 2px; border-radius: 8px; }
  .ba-dit {
    max-width: calc(100vw - 8px); font-size: 12px; line-height: 1.25;
    min-height: 0; height: calc(2 * 1.25em + 8px); padding: 4px 8px; overflow: hidden;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  }
  .ba-voix { max-width: calc(100vw - 8px); }
  #verdict:not(:empty) { font-size: 12px; padding: 4px 8px; }
  .ba-dit, #verdict:not(:empty) { padding-right: 112px; }
}
@media (max-width: 640px) and (orientation: portrait) {
  /*  ═══ LA TAPE OCCUPE LA MOITIÉ DE LA BARRE ═══
      C'est la commande du jeu ; c'est aussi celle qu'on presse en panique.
      Elle prend donc la largeur d'une colonne entière et 60 px de haut, à
      portée du pouce, et « Poser » se tient à côté — jamais dessous, pour
      qu'un doigt qui glisse ne pose pas une carte à la place de taper. */
  .ba-outils {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    display: grid; grid-template-columns: 3fr 2fr 1fr; gap: 5px;
    padding: 5px 6px calc(5px + env(safe-area-inset-bottom));
    background: var(--ba-panneau); border-top: 1px solid var(--ba-liseré); box-shadow: 0 -6px 18px rgba(0, 0, 0, .5);
  }
  .ba-outils button { min-width: 0; padding: 4px 2px; font-size: 1rem; }
  .ba-outils button[data-cmd="taper"] { min-height: 60px; font-size: 1.15rem; padding: 4px 2px; }
  .ba-outils button .lib { font-size: .74rem; }
  body.ludi-scene { padding-bottom: var(--ba-outils-h, 76px); }
  #ludiPlein { bottom: calc(var(--ba-outils-h, 76px) + 8px) !important; }
}

/*  ═══ LE TÉLÉPHONE TOURNÉ ═══
 *
 *  La première version mettait les commandes en COLONNE, à droite. Mesuré
 *  sur un iPhone 13 couché : le bouton flottant « plein écran » (#ludiPlein,
 *  posé par ludi-plein.js dans le coin bas droit) se trouvait PAR-DESSUS la
 *  commande du salon — `elementsFromPoint` le disait, et le doigt passait à
 *  travers. Couché, la barre du bas reste donc une barre du bas, et le
 *  bouton flottant est relevé au-dessus d'elle.
 *
 *  **Une colonne de commandes dans un coin partage ce coin avec tout ce que
 *    le manoir y pose : il faut le mesurer, pas l'espérer.**  */
@media (max-height: 480px) and (orientation: landscape) {
  h1 { display: none; }
  .plateau { gap: 3px; }
  .ba-outils {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    display: grid; grid-template-columns: 3fr 2fr 1fr; gap: 5px;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    background: var(--ba-panneau); border-top: 1px solid var(--ba-liseré); box-shadow: 0 -6px 18px rgba(0, 0, 0, .5);
  }
  .ba-outils button { min-width: 44px; min-height: 44px; padding: 3px 2px; }
  .ba-outils button[data-cmd="taper"] { min-height: 52px; font-size: 1.05rem; }
  .ba-outils button .lib { font-size: .72rem; }
  /*  Couché, la ligne des voix tient sur UNE ligne : chaque pixel rendu
      ici est un pixel de table en plus, et la table est ce qu'on regarde. */
  .ba-dit { height: calc(1.3em + 8px); -webkit-line-clamp: 1; font-size: 11px; padding: 3px 8px; }
  body.ludi-scene { padding-bottom: var(--ba-outils-h, 62px); }
  #ludiPlein { bottom: calc(var(--ba-outils-h, 62px) + 8px) !important; }
}

@media (prefers-reduced-motion: reduce) {
  .ba-cadre.refus, .ba-cadre.tort { animation: none; }
  .ba-annonce.on { animation: none; opacity: 1; transform: none; }
  .ba-cadre, .bar button, .bar a, .ba-dit { transition: none; }
}

.bar .ba-option { display: inline-flex; align-items: center; gap: 5px; color: var(--ba-doux); font-size: 13px; cursor: pointer; white-space: nowrap; }
.bar .ba-option input { accent-color: var(--ba-or); width: 16px; height: 16px; margin: 0; }
