/*  chandelles.css — une table de bois dans la nuit du manoir, des chandelles
 *  peintes au canvas, et rien qui ne tienne qu'à sa teinte.
 *
 *  ═══ LA GRILLE EST UN CANVAS ═══
 *
 *  Le script la peint : la table de bois, les chandelles (cire, coulures,
 *  mèche), la flamme (une FORME, deux à trois images qui vacillent), le halo
 *  chaud qui éclaire les voisines, la fumée à l'extinction, la vignette qui
 *  se referme à mesure que la pièce s'assombrit, le curseur, l'indice. La
 *  feuille ne pose que le CADRE et ses états, le menu du curseur, la ligne
 *  où parlent Oscar et Skelet, le bandeau d'état et ses commandes. Les
 *  jetons `--ch-*` sont LUS par le script (`getPropertyValue`) : une
 *  couleur vit ici, et une seule fois.
 *
 *  ═══ L'ÉTAT N'EST JAMAIS PORTÉ PAR LA SEULE COULEUR ═══
 *
 *  Une chandelle allumée a une flamme ; une chandelle éteinte n'en a pas et
 *  montre sa mèche noire. Le curseur est un cadre plein ; l'indice, un
 *  anneau en pointillé. Le banc mesure les couples de la feuille à 4,5:1
 *  (textes) et 3:1 (repères), étalonné sur 21,00:1 et 4,48:1.
 */

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

  /*  La table et ce qui s'y peint — lus par le script. */
  --ch-bois:       #4a3322;   /* la table, côté lumière */
  --ch-bois-b:     #2a1b12;   /* la table, côté ombre */
  --ch-veine:      #5c4130;   /* les veines du bois */
  --ch-cire:       #efe3c6;   /* la cire des chandelles */
  --ch-cire-b:     #b8a27c;   /* la cire dans l’ombre */
  --ch-meche:      #2b2118;   /* la mèche, et le pied de la chandelle */
  --ch-bougeoir:   #7a6237;   /* le bougeoir de laiton */
  --ch-flamme:     #ffb347;   /* la flamme, corps orangé */
  --ch-flamme-c:   #fff3b0;   /* la flamme, cœur clair */
  --ch-halo:       #ffb347;   /* le halo chaud (peint en transparence) */
  --ch-fumee:      #b9b3c4;   /* la fumée (peinte en transparence) */
  --ch-encre:      #241a2e;   /* l’encre sombre sur l’or ou la cire */
  --ch-sur:        #7fd39a;   /* le verdict « bon », le niveau résolu */
  --ch-rouge:      #ef8a8a;   /* le verdict « perdu », le chrono qui presse */
  --ch-bord:       #8a78b0;   /* le bord des commandes et des puces (3:1 sur les fonds, mesuré) */
  --ch-cadre:      #4b3a63;   /* le bord du cadre, côté lumière */
  --ch-cadre-b:    #2b2140;   /* le bord du cadre, côté ombre */

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

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

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

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

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

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

/*  ═══ L'ANNEAU DE TEMPS (La veillée) ═══
    Un disque dont le bord se vide en deux minutes (dégradé conique posé par
    le script), les secondes au centre. Sous dix secondes, le liseré rougit
    ET le chiffre clignote : deux signes, pas une couleur. */
.ch-anneau {
  position: relative; flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%; box-sizing: border-box;
  background: conic-gradient(var(--ch-or) 1turn, var(--ch-ctl) 0turn);
  border: 1px solid var(--ch-bord);
  display: inline-flex; align-items: center; justify-content: center;
}
.ch-anneau::before { content: ''; position: absolute; inset: 5px; border-radius: 50%; background: var(--ch-ctl); }
.ch-anneau b { position: relative; font-size: 12px; min-width: 0; color: var(--ch-texte); }
.ch-anneau.presse { border-color: var(--ch-rouge); border-width: 2px; }
.ch-anneau.presse b { color: var(--ch-rouge); animation: ch-cligne 1s steps(2, start) infinite; }
@keyframes ch-cligne { to { visibility: hidden; } }

.ch-choix { display: inline-flex; gap: 8px; align-items: center; position: relative; }
.ch-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(--ch-panneau); border: 1px solid var(--ch-or); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5); color: var(--ch-texte); font-size: 14px;
}
.ch-options[hidden] { display: none; }
.ch-options h4 { margin: 0 0 2px; font-size: 13px; color: var(--ch-or); text-transform: uppercase; letter-spacing: .04em; }
.ch-options .ch-option { display: flex; align-items: center; gap: 8px; cursor: pointer; min-height: 28px; }
.ch-options .ch-option input { accent-color: var(--ch-or); width: 18px; height: 18px; margin: 0; }
/*  La taille de la grille (classique seulement) : des boutons, pas une liste
    déroulante — la liste ouverte ne se style pas (mémoire du 12/09). */
.ch-taille { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ch-taille span { color: var(--ch-doux); font-size: 13px; margin-right: 2px; }
.ch-taille button { min-width: 40px; padding: 5px 8px; min-height: 36px; }
.ch-taille button[aria-pressed="true"] { background: var(--ch-ctl-or); border-color: var(--ch-or); font-weight: 700; }
.ch-taille button:disabled { opacity: .55; }
.ch-puce {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
  background: var(--ch-ctl-or); border: 1px solid var(--ch-or); color: var(--ch-texte);
  font: inherit; font-size: .92rem; font-weight: 600;
}
.ch-puce:hover { background: var(--ch-ctl-or-vif); }
.ch-puce:focus-visible { outline: 3px solid var(--ch-or); outline-offset: 2px; }
@media (pointer: coarse) { .ch-puce { min-height: 44px; } }
.ch-chevron { color: var(--ch-or); font-size: .8em; }

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

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

/*  ═══ LE MENU SUR LE CURSEUR ═══
    Quatre commandes (annuler, recommencer, indice, niveau suivant) dans une
    boîte posée par le script à côté de la case du curseur ; M, Échap ou un
    appui long l'ouvrent, Échap le ferme, les flèches y circulent. */
.ch-menu {
  position: absolute; z-index: 20; display: flex; flex-direction: column; gap: 4px;
  min-width: 190px; padding: 6px; border-radius: 10px;
  background: var(--ch-panneau); border: 1px solid var(--ch-or);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .6);
}
.ch-menu[hidden] { display: none; }
.ch-menu button { display: flex; align-items: center; gap: 8px; text-align: left; justify-content: flex-start; }
.ch-menu button kbd { margin-left: auto; }
.ch-menu .ico { width: 1.3em; text-align: center; }

/*  ═══ L'ANNONCE TRAVERSE LA GRILLE ═══ (niveau résolu, optimal, chrono) */
.ch-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(--ch-or);
  letter-spacing: .04em; text-shadow: 0 0 16px rgba(0, 0, 0, .9), 0 2px 0 var(--ch-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(--ch-or); border-bottom: 1px solid var(--ch-or);
}
.ch-annonce.dur { color: var(--ch-rouge); border-color: var(--ch-rouge); }
.ch-annonce.on { animation: ch-annonce 1.6s linear forwards; }
@keyframes ch-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 grille. */
.ch-dit {
  box-sizing: border-box; width: 100%; max-width: 100%; min-height: 2.6em;
  padding: 5px 10px; border-radius: 9px;
  background: var(--ch-panneau); border: 1px dashed var(--ch-bord);
  color: var(--ch-doux); font: 13.5px/1.35 Georgia, 'Times New Roman', serif;
  transition: border-color .3s, color .3s;
}
.ch-dit b { color: var(--ch-or); font-weight: 700; margin-right: 4px; }
.ch-dit.skelet b { color: var(--ch-doux); }
.ch-dit.on { border-style: solid; border-color: var(--ch-or); color: var(--ch-texte); }
.ch-dit.on.skelet { border-color: var(--ch-bord); }

/*  La légende : les touches, et ce que veut dire l'anneau en pointillé. */
.ch-legende { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .84rem; color: var(--ch-doux); justify-content: center; }
.ch-legende span { display: inline-flex; align-items: center; gap: 7px; }
.ch-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(--ch-or); color: var(--ch-or); font: 700 11px/1 Georgia, serif;
}
.ch-legende i.plein { border-style: solid; }
.ch-legende kbd {
  font: 11px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--ch-doux);
  border: 1px solid var(--ch-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) {
  .ch-voix, .ch-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; }
  .ch-jeton { padding: 3px 8px 3px 3px; }
  .ch-jeton .ch-lib { display: none; }
  .ch-commandes { gap: 6px; }
  .ch-commandes button kbd { display: none; }
}
@media (max-height: 860px) {
  .ch-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; }
  .ch-jeton { padding: 1px 7px 1px 2px; font-size: 12px; gap: 4px; }
  .ch-jeton .ch-lib { display: none; }
  .ch-jeton b { font-size: 13px; }
  .ch-ico { width: 18px; height: 18px; font-size: 10px; }
  #jeton-meilleur { display: none; }
  .ch-commandes { margin-left: 0; gap: 6px; }
  .ch-commandes button kbd { display: none; }
  .ch-commandes button .lib { display: none; }
  .ch-commandes button { padding: 7px 10px; min-width: 44px; }
  .ch-taille button { min-width: 44px; min-height: 44px; }
  .ch-choix { order: 5; }
  .ch-puce#variantes { max-width: min(56vw, 240px); }
  .ch-puce#variantes #titre-variante { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .ch-legende { display: none; }
  /*  La grille 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; }
  .ch-colonne { width: 100%; gap: 6px; }
  .ch-cadre { padding: 4px; border-radius: 8px; }
  .ch-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;
  }
  .ch-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 grille au centre, la ligne des voix à droite — la grille
    reçoit toute la hauteur (même remède que les Bulles, 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 grille 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 .ch-choix { width: 100%; flex-wrap: wrap; gap: 4px; }
  .etat .ch-puce#variantes { max-width: 100%; }
  .etat .ch-commandes { width: 100%; gap: 4px; }
  .ch-colonne { display: contents; }
  .ch-cadre { grid-area: grille; justify-self: center; }
  .ch-voix { grid-area: dit; width: auto; max-width: none; align-self: stretch; }
  .ch-dit { width: auto; max-width: none; min-height: 0; height: 100%; -webkit-line-clamp: 8; font-size: 12px; }
}

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

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