/*  cochonnet.css — une table de bois sombre dans la nuit du manoir, un dé
 *  (ou deux) avec la tête de Skelet sur le 1, deux boutons, et rien qui
 *  ne tienne qu'à sa teinte.
 *
 *  ═══ LE JEU EST EN CANVAS, LES COMMANDES EN DOM ═══
 *
 *  La table, les dés, le lancer et la pastille des points du tour sont
 *  peints par le script dans un seul canvas (`#cochonnet`) ; toucher le
 *  canvas lance aussi. Les décisions sont deux BOUTONS de 44 px — Lancer,
 *  Je garde — fixés en bas sur un téléphone debout, à droite couché.
 *
 *  ═══ 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 ; un 1 est rouge ET dit « le tour est
 *  perdu » ; le 1 sur le dé est une tête, pas un point. Les jetons
 *  `--co-*` 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. */
  --co-nuit:     #1b1526;
  --co-panneau:  #2a2338;
  --co-liseré:   #6b5a90;
  --co-texte:    #f0ead9;
  --co-doux:     #c9c0dc;
  --co-or:       #f0d68a;

  /*  La table de bois, et ce qu'on y trace. */
  --co-tapis:    #4a2c1e;
  --co-tapis-b:  #2e1a10;
  --co-trace:    #d9b48a;   /* la piste, les veines, la pastille au repos (repère, 3:1 sur le bois) */
  --co-rouge:    #ff8a7a;   /* « le tour est perdu » sur le bois (texte, 4,5:1) */
  --co-cadre:    #4b3a63;
  --co-cadre-b:  #2b2140;

  /*  Le dé : papier, ombre du papier, les points, le crâne. */
  --co-de:       #f6efdf;
  --co-de-b:     #d8ccae;
  --co-point:    #241033;
  --co-crane:    #3b2a52;

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

  /*  Les commandes, en couleurs opaques — reprises de la crapette, mesurées. */
  --co-ctl:        #231b2d;
  --co-ctl-vif:    #31293a;
  --co-ctl-or:     #3d3033;
  --co-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(--co-liseré); margin: 0 2px; }

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

.bar button, .co-outils button, .co-groupe button {
  font-family: inherit; font-size: 13px; color: var(--co-texte);
  background: var(--co-ctl);
  border: 1px solid var(--co-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), .co-outils button:hover:not(:disabled), .co-groupe button:hover:not(:disabled):hover:not(:disabled) { background: var(--co-ctl-vif); border-color: var(--co-or); }
.co-outils button:active:not(:disabled) { transform: translateY(1px); }
.bar button:focus-visible, .co-outils button:focus-visible, .co-groupe button:focus-visible:focus-visible { outline: 3px solid var(--co-or); outline-offset: 2px; }
@media (pointer: coarse) { .bar button, .co-outils button, .co-groupe button { min-height: 44px; } }

.co-outils button kbd {
  font: 11px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--co-doux);
  border: 1px solid var(--co-bord); border-radius: 4px; padding: 1px 4px; margin-left: 2px;
}
.co-outils button.gold { background: var(--co-ctl-or); border-color: var(--co-or); font-weight: bold; }
.co-outils button.gold:hover:not(:disabled) { background: var(--co-ctl-or-vif); }
.bar button:disabled, .co-outils button:disabled, .co-groupe button:disabled {
  background: transparent; color: var(--co-doux);
  border-style: dashed; cursor: not-allowed; font-weight: normal;
}
.co-outils button[hidden] { display: none; }

body.ludi-scene { background: var(--co-nuit); color: var(--co-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(--co-panneau); border: 1px solid var(--co-liseré);
  border-radius: 10px; color: var(--co-doux); font-size: .94rem;
}
.etat b { color: var(--co-texte); font-variant-numeric: tabular-nums; }

.co-jeton {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px 3px 4px; border-radius: 999px;
  background: var(--co-ctl); border: 1px solid var(--co-bord);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 1px 3px rgba(0, 0, 0, .45);
  color: var(--co-doux); font-size: .88rem; white-space: nowrap;
}
.co-jeton b { font-size: 1rem; min-width: 1.2em; text-align: center; }
.co-jeton[hidden] { display: none; }
/*  À vous : le jeton du joueur se dore ET porte un point ; le gagnant, une couronne. */
.co-jeton.a-vous { border-color: var(--co-or); }
.co-jeton.a-vous b::after { content: ' ●'; color: var(--co-or); font-size: .7em; }
.co-jeton.gagnant { border-color: var(--co-or); }
.co-jeton.gagnant b::after { content: ' ♛'; color: var(--co-or); font-size: .8em; }
.co-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(--co-or);
  background: radial-gradient(circle at 35% 30%, #5a4a78, var(--co-ctl-or) 70%);
  border: 1px solid var(--co-or);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), inset 0 -2px 0 rgba(0, 0, 0, .35);
}

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



/*  ═══ LE VERDICT FLOTTE SUR LA LIGNE DES VOIX ═══ */
.co-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(--co-panneau); border: 1px solid var(--co-or);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .55); overflow: hidden;
}
#verdict.bon   { color: var(--co-sur); }
#verdict.tiede { color: var(--co-or); }
#verdict.dur   { color: var(--co-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);
}
.co-colonne { display: flex; flex-direction: column; gap: 8px; align-items: center; min-width: 0; max-width: 100%; position: relative; width: 100%; }

.co-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(--co-cadre), var(--co-cadre-b));
  border: 2px solid var(--co-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;
}
.co-cadre.refus { animation: co-refus .3s ease; }
@keyframes co-refus {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-4px); }
  70% { transform: translateX(4px); }
}
/*  Le canvas : un toucher lance ; la page ne bouge pas sous le doigt. */
#cochonnet {
  display: block; border-radius: 8px; background: var(--co-tapis);
  cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
#cochonnet:focus-visible { outline: 3px solid var(--co-or); outline-offset: -3px; }

/*  ═══ L'ANNONCE TRAVERSE L'ÉCRAN ═══ (Un 1 !, Soufflé !, la fin) */
.co-annonce {
  position: absolute; left: 0; right: 0; top: 40%; 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(--co-or);
  letter-spacing: .04em; text-shadow: 0 0 16px rgba(0, 0, 0, .9), 0 2px 0 var(--co-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(--co-or); border-bottom: 1px solid var(--co-or);
}
.co-annonce.dur { color: var(--co-alerte); border-color: var(--co-alerte); }
.co-annonce.on { animation: co-annonce 1.6s linear forwards; }
@keyframes co-annonce {
  0%      { opacity: 0; transform: translateX(-100%); animation-timing-function: cubic-bezier(.2, .8, .3, 1); }
  18%     { opacity: 1; transform: translateX(0); }
  82%     { opacity: 1; transform: translateX(0); animation-timing-function: cubic-bezier(.6, 0, .8, .4); }
  100%    { opacity: 0; transform: translateX(100%); }
}

/*  ═══ LES COMMANDES ═══ Lancer, Je garde, Nouvelle. */
.co-outils { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 100%; }
.co-outils button { min-width: 44px; min-height: 44px; font-size: 1rem; font-weight: 700; padding: 6px 12px; }
.co-outils button .lib { font-size: .8rem; font-weight: 400; }
.co-outils button .ico { font-size: 1.15rem; }

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

.co-legende { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .84rem; color: var(--co-doux); justify-content: center; }
.co-legende span { display: inline-flex; align-items: center; gap: 7px; }
.co-legende i { flex: 0 0 auto; width: 14px; height: 14px; border-radius: 3px; box-sizing: border-box; display: inline-block; font-style: normal; }
.co-legende i.co-leg-or { border: 2px solid var(--co-or); }
.co-legende i.co-leg-rouge { background: var(--co-rouge); border: 2px solid var(--co-rouge); }
.co-legende kbd {
  font: 11px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--co-doux);
  border: 1px solid var(--co-bord); border-radius: 4px; padding: 1px 4px;
}

@media (min-width: 1081px) {
  .co-voix, .co-legende { max-width: calc(100vw - 360px); }
}
@media (max-width: 1500px) {
  .etat { gap: 6px 8px; padding: 6px 10px; }
  .co-jeton { padding: 3px 8px 3px 3px; }
  .co-jeton .co-lib { display: none; }
  .co-outils button kbd { display: none; }
}
@media (max-height: 860px) {
  .co-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; }
  .co-jeton { padding: 1px 6px 1px 2px; font-size: 12px; gap: 3px; }
  .co-jeton .co-lib { display: none; }
  .co-jeton b { font-size: 13px; min-width: 0; }
  .co-ico { width: 18px; height: 18px; font-size: 10px; }
  #jeton-meilleur { display: none; }
  .co-choix { margin-left: 0; }
  .co-puce#variantes { max-width: min(40vw, 200px); }
  .co-puce#variantes #titre-variante { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .co-puce#options { padding-left: 8px; padding-right: 8px; }
  .co-options { right: auto; left: 0; min-width: min(92vw, 340px); }
  .co-legende { display: none; }
  .plateau { gap: 4px; max-width: none; width: calc(100% + 16px); margin-left: -8px; }
  .co-colonne { width: 100%; gap: 4px; }
  .co-cadre { padding: 2px; border-radius: 8px; }
  .co-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;
  }
  .co-voix { max-width: calc(100vw - 8px); }
  #verdict:not(:empty) { font-size: 12px; padding: 4px 8px; }
  .co-dit, #verdict:not(:empty) { padding-right: 112px; }
}
@media (max-width: 640px) and (orientation: portrait) {
  /*  Les commandes fixées en bas : trois boutons, 44 px chacun. */
  .co-outils {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    display: grid; grid-template-columns: 2fr 2fr 1fr; gap: 4px; padding: 5px 6px calc(5px + env(safe-area-inset-bottom));
    background: var(--co-panneau); border-top: 1px solid var(--co-liseré); box-shadow: 0 -6px 18px rgba(0, 0, 0, .5);
  }
  .co-outils button { min-width: 0; padding: 4px 2px; font-size: 1rem; }
  .co-outils button .lib { font-size: .7rem; }
  body.ludi-scene { padding-bottom: var(--co-outils-h, 60px); }
  #ludiPlein { bottom: calc(var(--co-outils-h, 60px) + 8px) !important; }
}

/*  ═══ LE TÉLÉPHONE TOURNÉ ═══ le bandeau à gauche, le tapis au centre,
    les commandes à droite en colonne. */
@media (max-height: 480px) and (orientation: landscape) {
  h1 { display: none; }
  .plateau {
    display: grid; grid-template-columns: 190px auto 72px;
    grid-template-areas: "etat cadre outils" "dit cadre outils"; column-gap: 6px; row-gap: 4px;
    align-items: start; justify-content: center; width: calc(100% + 16px); margin-left: -8px;
  }
  .etat {
    grid-area: etat; margin: 0; max-width: none; padding: 4px 6px; gap: 4px;
    flex-wrap: wrap; align-content: start;
  }
  .etat .co-choix { width: 100%; flex-wrap: wrap; gap: 4px; }
  .etat .co-puce#variantes { max-width: 100%; }
  .co-options { left: 0; right: auto; }
  .co-colonne { display: contents; }
  .co-cadre { grid-area: cadre; justify-self: center; }
  /*  Le bouton ☰ du bandeau flotte dans le coin haut droit : la colonne
      des commandes commence sous lui. */
  .co-outils { grid-area: outils; display: grid; grid-template-columns: 1fr; gap: 4px; align-self: start; position: static; margin-top: 48px; }
  .co-outils button { min-width: 0; padding: 4px 2px; }
  .co-outils button .lib { display: none; }
  .co-voix { grid-area: dit; width: auto; max-width: none; align-self: stretch; }
  .co-dit { width: auto; max-width: none; min-height: 0; height: 100%; -webkit-line-clamp: 8; font-size: 12px; }
}

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

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