.cg-wrap {
    box-sizing: content-box;
    position: relative;
    display: block;
}

/* 8x8 */
.cg-wrap.cg-512 {
    padding-bottom: 100%;
}
.cg-wrap.cg-512.mini {
  width: 256px;
}
/* 6x8 */
.cg-wrap.cg-384-512 {
    padding-bottom: 133.333%; 
}
.cg-wrap.cg-384-512.mini {
    width: 192px; /* 384px / 2 */
}
/* 10x8 */
.cg-wrap.cg-640 {
    padding-bottom: calc(512 * 100% / 640);
}
.cg-wrap.cg-640.mini {
  width: 320px;
}

/* 9x9 */
.cg-wrap.cg-576 {
    padding-bottom: calc(1200 * 100% / 1100);
}
.cg-wrap.cg-576.mini {
  width: 304px;
}
/* 7x7 shogi */
.cg-wrap.cg-448-516 {
    padding-bottom: calc(420 * 100% / 364);
}
.cg-wrap.cg-448-516.mini {
  width: 224px;
}
/* 5x6 */
.cg-wrap.cg-260-360 {
    padding-bottom: calc(540 * 100% / 390);
}
.cg-wrap.cg-260-360.mini {
  width: 192px;
}
/* 5x5 */
.cg-wrap.cg-260 {
    padding-bottom: calc(450 * 100% / 390);
}
.cg-wrap.cg-260.mini {
  width: 192px;
}
/* 3x4 */
.cg-wrap.cg-156 {
    padding-bottom: calc(480 * 100% / 312);
}
.cg-wrap.cg-156.mini {
  width: 132px;
}

/* 7x7 */
.cg-wrap.cg-448 {
    padding-bottom: 100%;
}
.cg-wrap.cg-448.mini {
  width: 224px;
}
/* 9x10 */
.cg-wrap.cg-576-640, .cg-wrap.cg-borderlands {
    padding-bottom: calc(640 * 100% / 576);
}
.cg-wrap.cg-576-640.mini, .cg-wrap.cg-borderlands.mini {
  width: 288px;
}
/* 9x10 Janggi */
.cg-wrap.cg-janggi {
    padding-bottom: 100%;
}
.cg-wrap.cg-janggi.mini {
    width: 320px;
}
/* 10x10 */
.cg-wrap.cg-640-640 {
    padding-bottom: 100%;
}
.cg-wrap.cg-640-640.mini {
  width: 320px;
}
/* 9x9 chak */
.cg-wrap.cg-540 {
    padding-bottom: 100%;
}
.cg-wrap.cg-540.mini {
  width: 270px;
}

/* tooltip board in seek table */
.cg-wrap.minitooltip {
  width: 200px;
}

cg-container {
    position: absolute;
    width: 100%;
    height: 100%;
    display: block;
    top: 0;
    right: 0;
}

cg-board {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  line-height: 0;
  background-size: cover;
  cursor: pointer;
}
cg-board square {
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
  pointer-events: none;
}
.cg-384-512 cg-board square {
  width: 16.666%;
  height: 12.5%;
}
.cg-640 cg-board square{
  width: 10%;
  height: 12.5%;
}
.cg-576 cg-board square{
  width: 11.11%;
  height: 11.11%;
}
/* 7x7 shogi */
.cg-448-516 cg-board square{
  width: 14.2857%;
  height: 14.2857%;
}
.cg-260-360 cg-board square{
  width: 20%;
  height: 16.66%;
}
.cg-260 cg-board square{
  width: 20%;
  height: 20%;
}
.cg-156 cg-board square{
  width: 33.33%;
  height: 25%;
}
.cg-448 cg-board square{
  width: 14.28%;
  height: 14.28%;
}
.cg-576-640 cg-board square, .cg-borderlands cg-board square{
  width: 11.11%;
  height: 10%;
}
.cg-janggi cg-board square{
  width: 11.11%;
  height: 10%;
}
.cg-640-640 cg-board square{
  width: 10%;
  height: 10%;
}
/* 9x9 chak */
.cg-540 cg-board square{
  width: 11.11%;
  height: 11.11%;
}

/* --- Animation Keyframes (Conservés) --- */

@keyframes pulse-blood-inset {
  0% { box-shadow: inset 0 0 10px 4px rgba(205, 50, 50, 0.6); }
  50% { box-shadow: inset 0 0 14px 7px rgba(205, 50, 50, 0.8); }
  100% { box-shadow: inset 0 0 10px 4px rgba(205, 50, 50, 0.6); }
}

@keyframes shimmer-bronze-inset {
  0% { box-shadow: inset 0 0 12px 4px rgba(200, 160, 50, 0.2); }
  50% { box-shadow: inset 0 0 16px 8px rgba(220, 180, 70, 0.35); }
  100% { box-shadow: inset 0 0 12px 4px rgba(200, 160, 50, 0.2); }
}


/* --- Styles des Cases --- */

cg-board square {
  background: none;
  transition: background 0.1s ease-out, box-shadow 0.1s ease-out;
}

cg-board square.selected {
  background-color: rgba(255, 215, 0, 0.05);
  box-shadow: inset 0 0 15px 5px rgba(255, 200, 100, 0.4);
}

cg-board square.move-dest {
  background: radial-gradient(
    circle at center,
    transparent 18%,
    rgba(164, 139, 114, 0.7) 30%,
    transparent 35%
  );
  z-index: 10;
  pointer-events: auto;
}

/* * CORRIGÉ AVEC Z-INDEX *
 * On remet le z-index pour que la case soit
 * au-dessus de la pièce et capture le :hover.
 */
cg-board square.oc.move-dest {
  animation: none;
  background: radial-gradient(
    circle at center,
    transparent 18%,
    rgba(155, 40, 40, 0.9) 25%,
    rgba(155, 40, 40, 0.9) 30%,
    transparent 35%
  );
  z-index: 10;
  pointer-events: auto;
}

/* Le 'last-move' anime le box-shadow,
   il peut donc se combiner avec le 'background' de .oc.move-dest */
cg-board square.last-move {
  will-change: box-shadow;
  animation: shimmer-bronze-inset 2s infinite alternate;
}

cg-board square.check {
  background: none !important; 
  will-change: box-shadow;
  animation: pulse-blood-inset 1.2s infinite alternate;
}

/* --- Styles Premove --- */
cg-board square.premove-dest {
  background: radial-gradient(circle, rgba(255, 200, 80, 0.3) 0%, transparent 30%);
  z-index: 10;
}

cg-board square.oc.premove-dest {
  background: radial-gradient(transparent 80%, rgba(205, 50, 50, 0.3) 80%);
  z-index: 10; /* Ajout du z-index ici aussi */
}

cg-board square.current-premove {
  background-color: rgba(200, 150, 50, 0.2);
}


/* --- HOVER (Fonctionne maintenant) --- */

cg-board square.move-dest:hover, cg-board square.move-dest.drag-over {
  
  background: radial-gradient(
    circle at center,
    transparent 18%,
    rgba(164, 139, 114, 0.9) 30%,
    transparent 45%
  );
  box-shadow: 0 0 15px 5px rgba(164, 139, 114, 0.7);
}

/* Le :hover de capture n'a plus de conflit */
cg-board square.oc.move-dest:hover, cg-board square.oc.move-dest.drag-over {
  
  /* On s'assure que le fond (coins rouges) reste */
  background: radial-gradient(
    circle at center,
    transparent 18%,
    rgba(155, 40, 40, 0.9) 25%,
    rgba(155, 40, 40, 0.9) 30%,
    transparent 45%
  );
  /* On ajoute le halo externe */
  box-shadow: 0 0 15px 5px rgba(155, 40, 40, 0.9);
}




.cg-wrap piece {
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
  background-size: cover;
  z-index: 2;
  will-change: transform;
  pointer-events: auto;
}
.shogi .cg-wrap piece, .kyoto .cg-wrap piece, .dobutsu .cg-wrap piece, .tori .cg-wrap piece, .cannonshogi .cg-wrap piece, .janggi .cg-wrap piece {
  background-position: center;
}
.cg-wrap.cg-384-512 piece {
  width: 16.666%;
  height: 12.5%;
}
.cg-wrap.cg-640 piece {
  width: 10%;
  height: 12.5%;
}
.cg-wrap.cg-576 piece {
  width: 11.11%;
  height: 11.11%;
}
/* 7x7 shogi */
.cg-wrap.cg-448-516 piece{
  width: 14.2857%;
  height: 14.2857%;
}
.cg-wrap.cg-260-360 piece {
  width: 20%;
  height: 16.66%;
}
.cg-wrap.cg-260 piece {
  width: 20%;
  height: 20%;
}
.cg-wrap.cg-156 piece {
  width: 33.33%;
  height: 25%;
}
.cg-wrap.cg-448 piece {
  width: 14.28%;
  height: 14.28%;
}
.cg-wrap.cg-576-640 piece, .cg-wrap.cg-borderlands piece{
  width: 11.11%;
  height: 10%;
}
.cg-wrap.cg-janggi piece{
  width: 11.11%;
  height: 10%;
}
.cg-wrap.cg-640-640 piece{
  width: 10%;
  height: 10%;
}
.cg-wrap.cg-540 piece{
  width: 11.11%;
  height: 11.11%;
}

cg-board piece.dragging {
  cursor: move;
  z-index: 9;
}

piece.anim {
  z-index: 8;
}

piece.fading {
  z-index: 1;
  opacity: 0.5;
}

.cg-wrap piece.ghost {
  opacity: 0.3;
}

.cg-wrap piece svg {
  overflow: hidden;
  position: relative;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  opacity: 0.6;
}

.cg-wrap cg-auto-pieces,
.cg-wrap .cg-shapes,
.cg-wrap .cg-custom-svgs {
  overflow: hidden;
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.cg-wrap cg-auto-pieces {
  z-index: 2;
}

.cg-wrap cg-auto-pieces piece {
  opacity: 0.3;
}

.cg-wrap .cg-shapes {
  overflow: hidden;
  opacity: 0.6;
  z-index: 2;
}

.cg-wrap .cg-custom-svgs {
  /* over piece.anim = 8, but under piece.dragging = 10 */
  z-index: 9;
}

.cg-wrap .cg-custom-svgs svg {
  overflow: visible;
}

.cg-wrap coords {
  position: absolute;
  display: flex;
  pointer-events: none;
  opacity: 0.8;
  font-size: 0.85em;
  font-weight: bold;
}
/* hide coords */
@media (max-width: 799px) and (orientation: portrait) {
    .cg-wrap coords {
        display: none;
    }
}
.cg-wrap coords.side {
  right: var(--ranks-right);
  top: var(--ranks-top);
  height: 100%;
  width: 12px;
}
.cg-wrap coords.side.forward, .cg-wrap coords.side.backward.black {
  flex-flow: column-reverse;
}
.cg-wrap coords.side.backward, .cg-wrap coords.side.forward.black {
  flex-flow: column;
}
.cg-wrap coords.bottom {
  bottom: var(--files-bottom);
  left: var(--files-left);
  width: 100%;
  height: 16px;
  text-align: center;
}
.cg-wrap coords.top {
  top: var(--files-top);
  left: var(--files-left);
  width: 100%;
  height: 16px;
  text-align: center;
}
.cg-wrap coords.bottom.forward, .cg-wrap coords.bottom.backward.black, .cg-wrap coords.top.forward, .cg-wrap coords.top.backward.black {
  flex-flow: row;
}
.cg-wrap coords.bottom.backward, .cg-wrap coords.bottom.forward.black, .cg-wrap coords.top.backward, .cg-wrap coords.top.forward.black {
  flex-flow: row-reverse;
}
.cg-wrap coords coord {
  flex: 1 1 auto;
}
@media (min-width: 800px) and (min-height: 500px) {
    .cg-wrap coords.side coord {
      transform: translateY(39%);
    }
}
