/*  crapette.css — un tapis de feutre vert sombre dans la nuit du manoir,
 *  deux jeux de cartes, et rien qui ne tienne qu'à sa teinte.
 *
 *  ═══ LE JEU EST EN CANVAS ═══
 *
 *  Le tapis, les vingt-deux piles, les cartes, leurs vols et leurs ombres
 *  sont peints par le script dans un seul canvas (`#crapette`) : c'est un
 *  jeu de MANIPULATION — glisser, toucher, poser — et le doigt y vit.
 *  `touch-action: none` sur le canvas : ni défilement ni zoom depuis les
 *  cartes. Les commandes (piocher, défausser, « Crapette ! », nouvelle)
 *  restent en DOM : des boutons de 44 px, fixés en bas sur un téléphone
 *  debout, à droite couché.
 *
 *  ═══ L'ÉTAT N'EST JAMAIS PORTÉ PAR LA SEULE COULEUR ═══
 *
 *  La source choisie est cerclée d'or ET soulevée ; une destination
 *  possible est cerclée de vert clair ET en pointillé ; une obligation
 *  manquée clignote en rouge ET tremble ; les deux dos diffèrent par la
 *  couleur ET par la lettre du monogramme. Les jetons `--cr-*` sont
 *  MESURÉS par le banc : 4,5:1 pour les textes, 3:1 pour les repères (les
 *  cercles sur le tapis, les cases vides, le liseré d'or).
 */

:root {
  /*  Les six jetons communs aux salons récents, gardés tels quels. */
  --cr-nuit:     #1b1526;
  --cr-panneau:  #2a2338;
  --cr-liseré:   #6b5a90;
  --cr-texte:    #f0ead9;
  --cr-doux:     #c9c0dc;
  --cr-or:       #f0d68a;

  /*  Le tapis de feutre, et ce qu'on y trace. */
  --cr-tapis:    #1f4a36;   /* le feutre, au centre */
  --cr-tapis-b:  #173a2a;   /* le feutre, vers les bords */
  --cr-case:     #8fc4a4;   /* le pointillé d'une case vide, son libellé (repère, 3:1 sur le feutre) */
  --cr-aide:     #b9f0cc;   /* le cercle d'une destination possible, le point d'une source (repère, 3:1) */
  --cr-rouge:    #ff6b5e;   /* l'obligation manquée qui clignote (repère, 3:1 sur le feutre) */
  --cr-ombre:    #000000;
  --cr-cadre:    #4b3a63;
  --cr-cadre-b:  #2b2140;

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

  /*  Les commandes, en couleurs opaques — reprises des Sept Pièces, mesurées. */
  --cr-ctl:        #231b2d;
  --cr-ctl-vif:    #31293a;
  --cr-ctl-or:     #3d3033;
  --cr-ctl-or-vif: #4e413b;
  --cr-ctl-rouge:  #4a2530;   /* « Crapette ! » : un bouton à part, et un liseré alerte */
}

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

/*  `theme-manoir.css` peint `body.theme-manoir .bar` avec `!important` :
 *  fond, bordure, ombres. Déclarer ici un fond de barre serait du code mort. */
.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(--cr-liseré); margin: 0 2px; }

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

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

.cr-outils button kbd {
  font: 11px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--cr-doux);
  border: 1px solid var(--cr-bord); border-radius: 4px; padding: 1px 4px; margin-left: 2px;
}
.cr-outils button.gold { background: var(--cr-ctl-or); border-color: var(--cr-or); font-weight: bold; }
.cr-outils button.gold:hover:not(:disabled) { background: var(--cr-ctl-or-vif); }
/*  « Crapette ! » : le bouton qu'on ne presse pas par erreur. */
.cr-outils button.cri { background: var(--cr-ctl-rouge); border-color: var(--cr-alerte); font-weight: bold; }
.cr-outils button.cri:hover:not(:disabled) { background: var(--cr-ctl-or-vif); }
/*  Un refus se voit avant le clic : liseré en pointillé. */
.bar button:disabled, .cr-outils button:disabled, .cr-groupe button:disabled {
  background: transparent; color: var(--cr-doux);
  border-style: dashed; cursor: not-allowed; font-weight: normal;
}
.cr-outils button[hidden] { display: none; }

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

/*  ═══ LES JETONS DU BANDEAU ═══ le tour, les cartes de chacun (crapette ·
    talon · défausse), le niveau, la pendule, le record. Chaque jeton porte
    un `title` ET un libellé. */
.cr-jeton {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px 3px 4px; border-radius: 999px;
  background: var(--cr-ctl); border: 1px solid var(--cr-bord);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 1px 3px rgba(0, 0, 0, .45);
  color: var(--cr-doux); font-size: .88rem; white-space: nowrap;
}
.cr-jeton b { font-size: 1rem; min-width: 1.2em; text-align: center; }
.cr-jeton[hidden] { display: none; }
/*  À vous : le jeton du tour se dore ET porte un point. */
.cr-jeton.a-vous { border-color: var(--cr-or); }
.cr-jeton.a-vous b::after { content: ' ●'; color: var(--cr-or); font-size: .7em; }
/*  La pendule du duel : or, puis alerte (ET un sablier qui clignote) sous cinq secondes. */
.cr-jeton-chrono { border-color: var(--cr-or); }
.cr-jeton-chrono.presse { border-color: var(--cr-alerte); }
.cr-jeton-chrono.presse b { color: var(--cr-alerte); }
.cr-jeton-chrono.presse .cr-ico { animation: cr-cligne 1s steps(2) infinite; }
@keyframes cr-cligne { 50% { opacity: .35; } }
.cr-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(--cr-or);
  background: radial-gradient(circle at 35% 30%, #5a4a78, var(--cr-ctl-or) 70%);
  border: 1px solid var(--cr-or);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), inset 0 -2px 0 rgba(0, 0, 0, .35);
}

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

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

/*  Le cadre : du bois sombre, deux lumières, un liseré. Le canvas dedans,
    dimensionné par le script — le cadre épouse le canvas, jamais l'inverse. */
.cr-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(--cr-cadre), var(--cr-cadre-b));
  border: 2px solid var(--cr-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;
}
.cr-cadre.refus { animation: cr-refus .3s ease; }
@keyframes cr-refus {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-4px); }
  70% { transform: translateX(4px); }
}
/*  ═══ LE CANVAS ═══ `touch-action: none` : le doigt y glisse les cartes ;
    ni défilement ni zoom depuis le tapis. */
#crapette {
  display: block; border-radius: 8px; background: var(--cr-tapis);
  cursor: grab; touch-action: none; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
#crapette.saisi { cursor: grabbing; }
#crapette:focus-visible { outline: 3px solid var(--cr-or); outline-offset: -3px; }

/*  ═══ L'ANNONCE TRAVERSE L'ÉCRAN ═══ (Crapette !, la pendule, la fin) */
.cr-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(--cr-or);
  letter-spacing: .04em; text-shadow: 0 0 16px rgba(0, 0, 0, .9), 0 2px 0 var(--cr-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(--cr-or); border-bottom: 1px solid var(--cr-or);
}
.cr-annonce.dur { color: var(--cr-alerte); border-color: var(--cr-alerte); }
.cr-annonce.on { animation: cr-annonce 1.6s linear forwards; }
@keyframes cr-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 OUTILS ═══ piocher, défausser, « Crapette ! », nouvelle partie.
    Sur un ordinateur : une rangée sous le cadre. */
.cr-outils { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 100%; }
.cr-outils button { min-width: 44px; min-height: 44px; font-size: 1rem; font-weight: 700; padding: 6px 12px; }
.cr-outils button .lib { font-size: .8rem; font-weight: 400; }
.cr-outils button .ico { font-size: 1.15rem; }

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

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

/*  Au-dessus de 1 081 px, LudiDuo pose ses deux tribunes dans les coins du
    bas : la ligne des voix et la légende leur laissent la place. */
@media (min-width: 1081px) {
  .cr-voix, .cr-legende { max-width: calc(100vw - 360px); }
}

/*  ═══ LA HAUTEUR EST COMPTÉE ═══ sous 1 500 px, les libellés des jetons
    et les rappels de touches s'effacent — l'icône et le `title` restent. */
@media (max-width: 1500px) {
  .etat { gap: 6px 8px; padding: 6px 10px; }
  .cr-jeton { padding: 3px 8px 3px 3px; }
  .cr-jeton .cr-lib { display: none; }
  .cr-outils button kbd { display: none; }
}
@media (max-height: 860px) {
  .cr-legende { display: none; }
}

/*  Le pied « Sur Ludicademy » : un séparateur en bloc en ligne. */
.lb-sur .lb-sep { display: inline-block; }

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

/*  Un téléphone : étroit, OU bas (tourné, 812 × 375 n'est pas étroit). Le
    script dit la même chose (`telephone()`). Debout, le tapis entier tient
    dans le premier écran et les outils restent FIXÉS EN BAS : la barre du
    site s'efface, le titre se serre. */
@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; }
  .cr-jeton { padding: 1px 6px 1px 2px; font-size: 12px; gap: 3px; }
  .cr-jeton .cr-lib { display: none; }
  .cr-jeton b { font-size: 13px; min-width: 0; }
  .cr-ico { width: 18px; height: 18px; font-size: 10px; }
  #jeton-meilleur { display: none; }
  .cr-choix { margin-left: 0; }
  .cr-puce#variantes { max-width: min(46vw, 220px); }
  .cr-puce#variantes #titre-variante { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .cr-puce#options { padding-left: 8px; padding-right: 8px; }
  .cr-options { right: auto; left: 0; min-width: min(92vw, 340px); }
  .cr-legende { display: none; }
  .plateau { gap: 4px; max-width: none; width: calc(100% + 16px); margin-left: -8px; }
  .cr-colonne { width: 100%; gap: 4px; }
  .cr-cadre { padding: 2px; border-radius: 8px; }
  .cr-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;
  }
  .cr-voix { max-width: calc(100vw - 8px); }
  #verdict:not(:empty) { font-size: 12px; padding: 4px 8px; }
  .cr-dit, #verdict:not(:empty) { padding-right: 112px; }
}
@media (max-width: 640px) and (orientation: portrait) {
  /*  Les outils fixés en bas : une rangée de quatre, 44 px chacun, sur le
      fond du panneau ; le corps de la page garde la place dessous. */
  .cr-outils {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 5px 6px calc(5px + env(safe-area-inset-bottom));
    background: var(--cr-panneau); border-top: 1px solid var(--cr-liseré); box-shadow: 0 -6px 18px rgba(0, 0, 0, .5);
  }
  .cr-outils button { min-width: 0; padding: 4px 2px; font-size: 1rem; }
  .cr-outils button .lib { font-size: .7rem; }
  body.ludi-scene { padding-bottom: var(--cr-outils-h, 60px); }
  /*  Le bouton « Plein écran » du site flotte en bas à droite : il
      recouvrirait les outils. Il remonte au-dessus. */
  #ludiPlein { bottom: calc(var(--cr-outils-h, 60px) + 8px) !important; }
}

/*  ═══ LE TÉLÉPHONE TOURNÉ ═══
    375 px de haut : le titre s'efface, le bandeau se serre À GAUCHE, le
    canvas au centre, les outils À DROITE en colonne, la ligne des voix
    sous le bandeau. */
@media (max-height: 480px) and (orientation: landscape) {
  h1 { display: none; }
  .plateau {
    display: grid; grid-template-columns: 190px auto 64px;
    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 .cr-choix { width: 100%; flex-wrap: wrap; gap: 4px; }
  .etat .cr-puce#variantes { max-width: 100%; }
  .cr-options { left: 0; right: auto; }
  .cr-colonne { display: contents; }
  .cr-cadre { grid-area: cadre; justify-self: center; }
  .cr-outils { grid-area: outils; display: grid; grid-template-columns: 1fr; gap: 4px; align-self: start; position: static; }
  .cr-outils button { min-width: 0; padding: 4px 2px; }
  .cr-outils button .lib { display: none; }
  .cr-voix { grid-area: dit; width: auto; max-width: none; align-self: stretch; }
  .cr-dit { width: auto; max-width: none; min-height: 0; height: 100%; -webkit-line-clamp: 8; font-size: 12px; }
}

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

/*  L'aide à cocher, dans la barre avant que le panneau ne l'adopte. */
.bar .cr-option { display: inline-flex; align-items: center; gap: 5px; color: var(--cr-doux); font-size: 13px; cursor: pointer; white-space: nowrap; }
.bar .cr-option input { accent-color: var(--cr-or); width: 16px; height: 16px; margin: 0; }
