/* ── Game board frame ────────────────────────────────────────────────── */

.board {
  position: relative;
  border-radius: var(--board-radius);
  background: linear-gradient(135deg, rgba(255, 248, 230, 0.6), rgba(198, 155, 90, 0.4)),
    url('../assets/img/bg-wood.webp') center/cover;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.25), inset 0 0 0 10px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  transition: transform 0.6s ease-in-out;
}

.board--rotated {
  transform: rotate(180deg);
}

.board::after {
  content: "";
  position: absolute;
  inset: var(--board-frame-inset);
  border: var(--board-frame-border) solid rgba(0, 0, 0, 0.12);
  border-radius: var(--board-frame-radius);
  pointer-events: none;
}

.board.board--finished {
  pointer-events: none;
}

.board.board--finished.board--finished--loser {
  filter: grayscale(0.8) brightness(0.6);
}

.board.board--finished.board--finished--winner {
  filter: saturate(1.06) brightness(1.02);
}

.gunzi-logo {
  position: absolute;
  bottom: var(--board-logo-offset-y);
  right: var(--board-logo-offset-x);
  width: var(--hex-radius);
  height: auto;
  opacity: 0.6;
  pointer-events: none;
  z-index: 0;
}

.board--rotated .gunzi-logo {
  bottom: auto;
  right: auto;
  top: var(--board-logo-offset-y);
  left: var(--board-logo-offset-x);
  transform: rotate(180deg);
}

/* ── Confetti ────────────────────────────────────────────────────────── */

.confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 120;
}

.confetti-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 121;
}

.confetti-particle {
  will-change: transform, opacity;
  backface-visibility: hidden;
  transform-origin: center;
}

.board.board--rotated .confetti-canvas,
.board.board--rotated .confetti-container {
  transform: rotate(-180deg);
  transform-origin: center;
}

@media (prefers-reduced-motion: reduce) {
  .confetti-particle {
    animation-play-state: paused !important;
    opacity: 1 !important;
  }
}

/* ── Status badge: game-end variants (override #status via !important) ─ */

.status--winner,
.status--win,
.status--lose {
  font-weight: 700;
  font-size: 1.25rem;
  border: 2px solid currentColor;
  animation: pulse-winner 2s infinite;
}

.status--winner,
.status--lose {
  color: var(--color-alert);
  background: rgba(255, 253, 246, 1) !important;
  box-shadow: 0 4px 16px rgba(217, 83, 79, 0.3) !important;
}

.status--win {
  color: var(--hex-highlight);
  background: rgba(255, 255, 255, 1) !important;
  box-shadow: 0 4px 16px rgba(46, 139, 87, 0.22) !important;
}

@keyframes pulse-winner {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* ── Hex cells ───────────────────────────────────────────────────────── */

.hex {
  position: absolute;
  width: var(--hex-width);
  height: var(--hex-height);
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  background-position: center;
  background-size: cover;
  transform: translateZ(0);
  backface-visibility: hidden;
  will-change: transform, box-shadow;
}

.hex--light {
  background-image: url('../assets/svg/hex-piece-light.svg');
}

.hex--dark {
  background-image: url('../assets/svg/hex-piece-dark.svg');
}

.hex:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(60, 30, 5, 0.24);
}

.hex--highlight,
.hex--opponent-highlight {
  box-shadow: 0 0 0 6px rgba(46, 139, 87, 0.35), 0 10px 22px rgba(0, 0, 0, 0.25);
  transform: translateZ(0);
  will-change: transform, box-shadow;
}

.hex--highlight::after,
.hex--opponent-highlight::after {
  content: "";
  position: absolute;
  inset: 8%;
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
  background: rgba(46, 139, 87, 0.28);
  pointer-events: none;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.hex.is-blocked {
  cursor: not-allowed;
}

/* ── Pieces ──────────────────────────────────────────────────────────── */

.piece {
  width: calc(var(--hex-width) * 0.72);
  height: calc(var(--hex-height) * 0.78);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  filter: none;
  -webkit-filter: none;
  transform: translateZ(0);
  backface-visibility: hidden;
  will-change: transform, filter;
  outline: none;
}

.piece:focus-visible {
  outline: 2px solid rgba(46, 139, 87, 0.6);
  outline-offset: 2px;
}

.piece__icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.piece--selected {
  transform: scale(1.08) translateY(-3px);
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.4)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
  -webkit-filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.4)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
  z-index: 10;
}

.piece--opponent-selected {
  transform: scale(1.05) translateY(-2px);
  filter: drop-shadow(0 0 6px rgba(255, 204, 92, 0.8)) drop-shadow(0 10px 16px rgba(0, 0, 0, 0.35));
  -webkit-filter: drop-shadow(0 0 6px rgba(255, 204, 92, 0.8)) drop-shadow(0 10px 16px rgba(0, 0, 0, 0.35));
  z-index: 9;
}

.piece--promoted {
  display: none;
}

/* ── Promotion Crown ─────────────────────────────────────────────────── */

.crown-marker,
.crown-promoted {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 70%;
  height: 70%;
  pointer-events: none;
}

.crown-marker {
  opacity: 0.15;
  z-index: 0;
  mix-blend-mode: multiply;
}

.crown-promoted {
  opacity: 0;
  z-index: 20;
  transition: opacity 0.5s ease;
}

.crown-promoted.is-active {
  opacity: 1;
}

.crown--hidden {
  display: none;
}

.crown--rotated {
  transform: translate(-50%, -50%) rotate(180deg);
}
