/* Échecs et go (public/js/plateaux.js) : le plateau en pixel art, agrandi sans lissage, et à côté
   la pendule, les coups et les commandes, sur le verre de la fenêtre. Mêmes jetons que app.css et
   jeux.css. Le plateau lui-même reste net : aplats, aucun effet. */

.tg-stage.tg-echecs,
.tg-stage.tg-go {
  background: none;
  box-shadow: none;
  overflow: visible;
}

.pl-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 228px);
  gap: 14px;
  align-items: start;
}
.pl-board {
  position: relative;
  justify-self: center;
  width: min(100%, var(--pl-size, 444px), calc(100vh - 330px));
  min-width: 240px;
  aspect-ratio: 1;
}
/* Trois pixels d'écran par pixel du dessin : des pièces et des pierres nettes. */
.pl-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  image-rendering: pixelated;
  touch-action: none;
  cursor: pointer;
  box-shadow:
    0 1px 2px rgba(31, 23, 53, 0.12),
    0 10px 28px rgba(31, 23, 53, 0.14);
}
.pl-canvas:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
/* Annonces pour les lecteurs d'écran (case sous le cadre, coup de l'autre). */
.pl-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --- Panneau : pendule, coups, commandes ------------------------------------------------------ */

.pl-side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.pl-clock {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 10px;
  padding: 8px 12px;
  border-radius: var(--r-lg);
  background: var(--fill);
  transition:
    background var(--dur-base) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out);
}
/* Le joueur qui a le trait : fond teinté, filet, et une flèche (pas seulement une couleur). */
.pl-clock.turn {
  background: color-mix(in srgb, var(--accent) 13%, var(--fill));
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent);
}
.pl-clock-who {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.pl-clock-who b {
  font-size: var(--fs-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pl-clock-who b::before {
  content: "▸ ";
  display: inline-block;
  width: 0;
  overflow: hidden;
  vertical-align: bottom;
  color: var(--accent);
  transition: width var(--dur-base) var(--ease-out);
}
.pl-clock.turn .pl-clock-who b::before {
  width: 1em;
}
.pl-clock-side,
.pl-clock-who span {
  font-size: var(--fs-footnote);
  color: var(--text-3);
}
.pl-time {
  font: 700 22px / 1 var(--font);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.pl-clock:not(.turn) .pl-time {
  color: var(--text-3);
}
/* Moins de vingt secondes : le chiffre passe au rouge et grossit un peu. */
.pl-clock.low .pl-time {
  color: #c4262e;
  transform: scale(1.06);
  transition: transform var(--dur-base) var(--ease-out);
}
:root[data-theme="dark"] .pl-clock.low .pl-time {
  color: #ff7d84;
}
.pl-taken {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  min-height: 16px;
}
.pl-taken .pl-piece {
  width: 16px;
  height: 16px;
  margin-right: -5px;
  image-rendering: pixelated;
}
.pl-taken small {
  margin-left: 9px;
  font-size: var(--fs-footnote);
  font-weight: 700;
  color: var(--text-2);
}

.pl-moves {
  min-height: 72px;
  max-height: 228px;
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  border-radius: var(--r-md);
  background: var(--glass-strong);
  box-shadow: inset 0 0 0 1px var(--hairline);
  font-size: var(--fs-sub);
  font-variant-numeric: tabular-nums;
}
.pl-moves li {
  display: grid;
  grid-template-columns: 2.2em 1fr 1fr;
  gap: 4px;
  padding: 1px 4px;
}
.pl-moves li small {
  color: var(--text-3);
}
.pl-move {
  padding: 0 4px;
  border-radius: 4px;
}
.pl-move.last {
  font-weight: 700;
  background: color-mix(in srgb, #ffd65c 45%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #2a2135 40%, transparent);
}
.pl-moves .pl-empty {
  display: block;
  color: var(--text-3);
  padding: 6px 4px;
}

.pl-result {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: var(--r-lg);
  background: color-mix(in srgb, #ffd23f 22%, var(--fill));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #b8860b 35%, transparent);
  animation: pl-in var(--dur-slow) var(--ease-out) both;
}
.pl-result b {
  font-size: var(--fs-headline);
}
.pl-result span {
  font-size: var(--fs-sub);
  color: var(--text-2);
}
@keyframes pl-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.pl-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pl-tools .btn {
  flex: 1 1 auto;
}
.pl-offer {
  width: 100%;
  margin: 0;
  font-size: var(--fs-sub);
  color: var(--text-2);
}
.pl-resign.armed {
  background: #c4262e;
  color: #fff;
}

/* --- Promotion : les quatre pièces au-dessus de l'échiquier --------------------------------- */

.pl-promo {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  border-radius: 8px;
  background: rgba(20, 14, 36, 0.42);
  animation: pl-fade var(--dur-fast) var(--ease-out) both;
}
.pl-promo[hidden] {
  display: none;
}
.pl-promo p {
  margin: 0 0 8px;
  text-align: center;
  font-weight: 600;
  color: #fff;
}
.pl-promo-row {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-radius: var(--r-lg);
  background: var(--glass-strong);
  box-shadow: 0 12px 32px rgba(20, 14, 36, 0.35);
  animation: pl-in var(--dur-base) var(--ease-spring) both;
}
.pl-promo-btn {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 6px 8px 4px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--fill);
  color: var(--text);
  font: 600 var(--fs-footnote) / 1.2 var(--font);
  cursor: pointer;
  transition:
    background var(--dur-fast) var(--ease-out),
    transform var(--dur-press) var(--ease-out);
}
.pl-promo-btn:hover,
.pl-promo-btn:focus-visible {
  background: color-mix(in srgb, var(--accent) 18%, var(--fill));
}
.pl-promo-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.pl-promo-btn:active {
  transform: scale(0.95);
}
.pl-promo-cancel {
  justify-self: center;
  margin-top: 10px;
  background: var(--glass-strong);
  color: var(--text);
  box-shadow: 0 8px 24px rgba(20, 14, 36, 0.3);
}
.pl-promo-btn .pl-piece {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
}
@keyframes pl-fade {
  from {
    opacity: 0;
  }
}

/* --- Go : les deux joueurs, chacun sa pierre ------------------------------------------------ */

.pl-go-player {
  grid-template-columns: auto minmax(0, 1fr);
}
.pl-stone {
  width: 18px;
  height: 18px;
  border-radius: 50%;
}
.pl-stone.black {
  background: #25202e;
  box-shadow: 0 0 0 2px #0f0c14;
}
.pl-stone.white {
  background: #f7f4ec;
  box-shadow: 0 0 0 2px #4a4155;
}
:root[data-theme="dark"] .pl-stone.black {
  box-shadow: 0 0 0 2px #8e86a3;
}
.pl-go-info {
  margin: 0;
  min-height: 2.6em;
  font-size: var(--fs-sub);
  color: var(--text-2);
}
.pl-go-info:empty {
  display: none;
}
/* Un coup refusé (ko, suicide) : la raison, en clair, avec un signe. */
.pl-go-info.warn {
  font-weight: 600;
  color: #a3222a;
}
.pl-go-info.warn::before {
  content: "✕ ";
}
:root[data-theme="dark"] .pl-go-info.warn {
  color: #ff8f95;
}

@media (max-width: 680px) {
  .pl-wrap {
    grid-template-columns: 1fr;
  }
  .pl-moves {
    max-height: 120px;
  }
  /* Cartes des joueurs étroites : « Noirs · à son tour » tient sur une ligne. */
  .modal.table-game:has(.tg-echecs, .tg-go) .tg-who span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pl-result,
  .pl-promo,
  .pl-promo-row {
    animation: none;
  }
}
