/*  tour.css — une table de bois dans la nuit du manoir, des piquets de
 *  laiton et des disques peints au canvas, et rien qui ne tienne qu'à sa
 *  teinte.
 *
 *  ═══ LA TOUR EST UN CANVAS ═══
 *
 *  Le script la peint : la table de bois, les piquets de laiton, les disques
 *  de bois verni (chacun porte son NUMÉRO — jamais la seule couleur ni la
 *  seule taille), l'ombre portée, l'arc d'un déplacement, le halo d'or sur
 *  le piquet qui accepte le disque tenu, le tremblement d'un coup refusé,
 *  le feu d'artifice de la fin. La feuille ne pose que le CADRE et ses
 *  états, la ligne où parlent Oscar et Skelet, le bandeau d'état et ses
 *  commandes, le panneau des options. Les jetons `--tr-*` sont LUS par le
 *  script (`getPropertyValue`) : une couleur vit ici, et une seule fois.
 *
 *  ═══ L'ÉTAT N'EST JAMAIS PORTÉ PAR LA SEULE COULEUR ═══
 *
 *  Un disque porte son numéro ; le disque tenu est soulevé ET cerclé d'or ;
 *  le piquet choisi (clic ou touche) porte un halo ET un chevron ; l'indice
 *  est une flèche en pointillé. Le banc mesure les couples de la feuille à
 *  4,5:1 (textes, dont le numéro de chaque disque) et 3:1 (repères).
 */

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

  /*  La table, les piquets, ce qui s'y peint — lus par le script. */
  --tr-bois:       #4a3322;   /* la table, côté lumière */
  --tr-bois-b:     #2a1b12;   /* la table, côté ombre */
  --tr-veine:      #5c4130;   /* les veines du bois */
  --tr-laiton:     #8a6d3b;   /* le piquet de laiton, côté ombre */
  --tr-laiton-c:   #d9b86a;   /* le piquet de laiton, reflet */
  --tr-socle:      #3a2818;   /* le socle des piquets */
  --tr-encre:      #241a2e;   /* l’encre sombre : numéros des disques clairs, le « ? » sur l’or, le cerne des disques clairs */
  --tr-cerne:      #e6c98a;   /* l’aubier pâle : le cerne des disques foncés, pour qu’ils se détachent de la table */
  --tr-sur:        #7fd39a;   /* le verdict « bon », la tour arrivée */
  --tr-rouge:      #ef8a8a;   /* le verdict « refusé », le coup illicite */
  --tr-bord:       #8a78b0;   /* le bord des commandes et des puces (3:1 sur les fonds, mesuré) */
  --tr-cadre:      #4b3a63;   /* le bord du cadre, côté lumière */
  --tr-cadre-b:    #2b2140;   /* le bord du cadre, côté ombre */

  /*  ═══ LES DOUZE DISQUES ═══ du bois verni, de l’érable pâle au noyer :
      six clairs (numéro à l’encre), six foncés (numéro en texte clair). Le
      script prend, pour chaque disque, l’encre qui contraste le plus, et un
      cerne (l’encre ou l’aubier) qui contraste le plus — un disque de noyer
      sur une table de noyer se voit par son cerne. Le banc mesure les douze
      numéros à 4,5:1 et les cernes à 3:1. */
  --tr-d1:  #f6e4bc;
  --tr-d2:  #efd39d;
  --tr-d3:  #e8c17f;
  --tr-d4:  #dfae64;
  --tr-d5:  #d69c4d;
  --tr-d6:  #c98a3c;
  --tr-d7:  #9a5326;
  --tr-d8:  #7c3d1d;
  --tr-d9:  #6a321a;
  --tr-d10: #582a17;
  --tr-d11: #472214;
  --tr-d12: #371a10;

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

/* ═══════════════════════════════════ 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(--tr-liseré); margin: 0 2px; }

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

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

.tr-commandes { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-left: auto; }
.tr-commandes button kbd {
  font: 11px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--tr-doux);
  border: 1px solid var(--tr-bord); border-radius: 4px; padding: 1px 4px; margin-left: 2px;
}
.tr-commandes button.gold { background: var(--tr-ctl-or); border-color: var(--tr-or); font-weight: bold; }
.tr-commandes button.gold:hover:not(:disabled) { background: var(--tr-ctl-or-vif); }
/*  Un refus se voit avant le clic : liseré en pointillé. */
.bar button:disabled, .tr-commandes button:disabled {
  background: transparent; color: var(--tr-doux);
  border-style: dashed; cursor: not-allowed; font-weight: normal;
}
.tr-commandes .cout { font-size: 11px; color: var(--tr-or); font-weight: normal; margin-left: 4px; }
.tr-commandes button:disabled .cout { color: var(--tr-doux); }
.tr-commandes button[hidden] { display: none; }

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

/*  ═══ LES JETONS DU BANDEAU ═══
    Les coups et l'optimum, les disques, le score en cours, le meilleur ;
    à l'aveugle, les rallumages. Chaque jeton porte un `title` ET un
    libellé : l'icône seule ne dit rien. */
.tr-jeton {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px 3px 4px; border-radius: 999px;
  background: var(--tr-ctl); border: 1px solid var(--tr-bord);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 1px 3px rgba(0, 0, 0, .45);
  color: var(--tr-doux); font-size: .88rem; white-space: nowrap;
}
.tr-jeton b { font-size: 1rem; min-width: 1.2em; text-align: center; }
.tr-jeton[hidden] { display: none; }
.tr-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(--tr-or);
  background: radial-gradient(circle at 35% 30%, #5a4a78, var(--tr-ctl-or) 70%);
  border: 1px solid var(--tr-or);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), inset 0 -2px 0 rgba(0, 0, 0, .35);
}
.tr-ico-or { background: radial-gradient(circle at 35% 30%, #fff1c0, var(--tr-or) 45%, #b8962e); color: var(--tr-encre); font-size: 13px; }

.tr-choix { display: inline-flex; gap: 8px; align-items: center; position: relative; }
.tr-options {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 30; min-width: 250px;
  display: flex; flex-direction: column; gap: 8px; padding: 10px 12px;
  background: var(--tr-panneau); border: 1px solid var(--tr-or); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5); color: var(--tr-texte); font-size: 14px;
}
.tr-options[hidden] { display: none; }
.tr-options h4 { margin: 0 0 2px; font-size: 13px; color: var(--tr-or); text-transform: uppercase; letter-spacing: .04em; }
.tr-options .tr-option { display: flex; align-items: center; gap: 8px; cursor: pointer; min-height: 28px; }
.tr-options .tr-option input { accent-color: var(--tr-or); width: 18px; height: 18px; margin: 0; }
/*  Le nombre de disques : des boutons engendrés par le script selon la
    variante, pas une liste déroulante — la liste ouverte ne se style pas
    (mémoire du 12/09). */
.tr-taille { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tr-taille span { color: var(--tr-doux); font-size: 13px; margin-right: 2px; }
.tr-taille button { min-width: 40px; padding: 5px 8px; min-height: 36px; }
.tr-taille button[aria-pressed="true"] { background: var(--tr-ctl-or); border-color: var(--tr-or); font-weight: 700; }
.tr-puce {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
  background: var(--tr-ctl-or); border: 1px solid var(--tr-or); color: var(--tr-texte);
  font: inherit; font-size: .92rem; font-weight: 600;
}
.tr-puce:hover { background: var(--tr-ctl-or-vif); }
.tr-puce:focus-visible { outline: 3px solid var(--tr-or); outline-offset: 2px; }
@media (pointer: coarse) { .tr-puce { min-height: 44px; } }
.tr-chevron { color: var(--tr-or); font-size: .8em; }

/*  ═══ LE VERDICT FLOTTE SUR LA LIGNE DES VOIX ═══ */
.tr-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(--tr-panneau); border: 1px solid var(--tr-or);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .55); overflow: hidden;
}
#verdict.bon   { color: var(--tr-sur); }
#verdict.tiede { color: var(--tr-or); }
#verdict.dur   { color: var(--tr-rouge); }

/* ─────────────────────────────────────────────────────────────── 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);
}
.tr-colonne { display: flex; flex-direction: column; gap: 8px; align-items: center; min-width: 0; max-width: 100%; position: relative; width: 100%; }

/*  Le cadre : un bord épais, deux lumières, un liseré. Le canvas dedans,
    dimensionné par le script. */
.tr-cadre {
  position: relative; box-sizing: border-box; max-width: 100%; overflow: visible;
  padding: 6px; border-radius: 12px;
  background: linear-gradient(145deg, var(--tr-cadre), var(--tr-cadre-b));
  border: 2px solid var(--tr-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;
}
.tr-cadre canvas {
  display: block; border-radius: 6px; background: var(--tr-bois-b);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, .6);
  /*  `touch-action: none` : depuis la tour, ni défilement, ni zoom au
      double-toucher — le doigt prend un disque, c'est un coup. */
  cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
  max-width: 100%;
}
.tr-cadre canvas:focus-visible { outline: 3px solid var(--tr-or); outline-offset: 3px; }
.tr-cadre.gagne { box-shadow: 0 0 0 2px var(--tr-or), 0 0 22px rgba(240, 214, 138, .45), 0 10px 28px rgba(0, 0, 0, .55); }
.tr-cadre.refus { animation: tr-refus .3s ease; }
@keyframes tr-refus {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-4px); }
  70% { transform: translateX(4px); }
}

/*  ═══ L'ANNONCE TRAVERSE LA TOUR ═══ (tour arrivée, optimal, refusé) */
.tr-annonce {
  position: absolute; left: 0; right: 0; top: 34%; 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(--tr-or);
  letter-spacing: .04em; text-shadow: 0 0 16px rgba(0, 0, 0, .9), 0 2px 0 var(--tr-encre);
  padding: 10px 0;
  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(--tr-or); border-bottom: 1px solid var(--tr-or);
}
.tr-annonce.dur { color: var(--tr-rouge); border-color: var(--tr-rouge); }
.tr-annonce.on { animation: tr-annonce 1.6s linear forwards; }
@keyframes tr-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%); }
}

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

/*  La légende : les touches, et ce que veulent dire le halo et la flèche. */
.tr-legende { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .84rem; color: var(--tr-doux); justify-content: center; }
.tr-legende span { display: inline-flex; align-items: center; gap: 7px; }
.tr-legende i {
  flex: 0 0 auto; width: 18px; height: 18px; border-radius: 4px; box-sizing: border-box;
  display: inline-flex; align-items: center; justify-content: center; font-style: normal;
  border: 2px dashed var(--tr-or); color: var(--tr-or); font: 700 11px/1 Georgia, serif;
}
.tr-legende i.plein { border-style: solid; }
.tr-legende kbd {
  font: 11px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--tr-doux);
  border: 1px solid var(--tr-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) {
  .tr-voix, .tr-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; }
  .tr-jeton { padding: 3px 8px 3px 3px; }
  .tr-jeton .tr-lib { display: none; }
  .tr-commandes { gap: 6px; }
  .tr-commandes button kbd { display: none; }
}
@media (max-height: 860px) {
  .tr-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()`). */
@media (max-width: 640px), (max-height: 480px) {
  h1 { font-size: 1.15rem; margin: 6px 0 6px; }
  .bar { gap: 6px; padding: 4px 8px; }
  .bar .sep { display: none; }
  .etat { font-size: 13px; gap: 3px 6px; padding: 3px 8px 4px; margin-bottom: 5px; }
  .tr-jeton { padding: 1px 7px 1px 2px; font-size: 12px; gap: 4px; }
  .tr-jeton .tr-lib { display: none; }
  .tr-jeton b { font-size: 13px; }
  .tr-ico { width: 18px; height: 18px; font-size: 10px; }
  #jeton-meilleur { display: none; }
  .tr-commandes { margin-left: 0; gap: 6px; }
  .tr-commandes button kbd { display: none; }
  .tr-commandes button .lib { display: none; }
  .tr-commandes button { padding: 7px 10px; min-width: 44px; }
  .tr-taille button { min-width: 44px; min-height: 44px; }
  .tr-choix { order: 5; }
  .tr-puce#variantes { max-width: min(56vw, 240px); }
  .tr-puce#variantes #titre-variante { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .tr-legende { display: none; }
  /*  La tour prend toute la largeur de l'écran. Pas `100vw` : il compte
      la barre de défilement quand elle existe. */
  .plateau { gap: 6px; max-width: none; width: calc(100% + 16px); margin-left: -8px; }
  .tr-colonne { width: 100%; gap: 6px; }
  .tr-cadre { padding: 4px; border-radius: 8px; }
  .tr-dit {
    max-width: calc(100vw - 8px); font-size: 12px; line-height: 1.3;
    min-height: 0; height: calc(2 * 1.3em + 10px); overflow: hidden;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  }
  .tr-voix { max-width: calc(100vw - 8px); }
  #verdict:not(:empty) { font-size: 12px; padding: 4px 8px; }
}

/*  ═══ LE TÉLÉPHONE TOURNÉ ═══
    375 px de haut : le titre et la barre s'effacent, le bandeau se serre
    À GAUCHE, la tour au centre, la ligne des voix à droite — la tour
    reçoit toute la hauteur (même remède que les Chandelles, mesuré). */
@media (max-height: 480px) and (orientation: landscape) {
  h1 { display: none; }
  .bar { display: none; }
  .plateau {
    display: grid; grid-template-columns: 170px auto minmax(110px, 140px);
    grid-template-areas: "etat tour dit"; column-gap: 8px; row-gap: 0;
    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 .tr-choix { width: 100%; flex-wrap: wrap; gap: 4px; }
  .etat .tr-puce#variantes { max-width: 100%; }
  .etat .tr-commandes { width: 100%; gap: 4px; }
  .tr-colonne { display: contents; }
  .tr-cadre { grid-area: tour; justify-self: center; }
  .tr-voix { grid-area: dit; width: auto; max-width: none; align-self: stretch; }
  .tr-dit { width: auto; max-width: none; min-height: 0; height: 100%; -webkit-line-clamp: 8; font-size: 12px; }
}

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

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