/* ============================================================
   Pieces & Dice — Royal Game of Ur
   ============================================================ */

/* ============================================================
   On-board piece tokens
   ============================================================ */

.piece {
  position: absolute;
  width: 80%;
  height: 80%;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: default;
  user-select: none;
  transition:
    box-shadow 0.2s,
    transform 0.15s,
    filter 0.15s;
  z-index: 10;

  /* Subtle inner highlight to give a 3-D coin look */
  background-image: radial-gradient(
    circle at 35% 30%,
    rgba(255, 255, 255, 0.22) 0%,
    transparent 65%
  );
}

/* Player 1 — blue/lapis */
.piece.p1 {
  background-color: var(--p1-bg);
  color: var(--p1-color);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* Player 2 — red/coral */
.piece.p2 {
  background-color: var(--p2-bg);
  color: var(--p2-color);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* Piece label (e.g. "1" "2" or a small icon character) */
.piece-label {
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 1;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  user-select: none;
}

/* ============================================================
   Movable pieces — can be clicked this turn
   ============================================================ */

.piece.movable {
  cursor: pointer;
  animation: piece-pulse 1.2s ease-in-out infinite;
}

.piece.p1.movable {
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.5),
    0 0 14px var(--p1-glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.piece.p2.movable {
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.5),
    0 0 14px var(--p2-glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.piece.movable:hover {
  transform: scale(1.15);
  filter: brightness(1.2);
}

/* ============================================================
   Selected piece (after clicking to choose which to move)
   ============================================================ */

.piece.selected {
  transform: scale(1.2);
  filter: brightness(1.25);
  z-index: 15;
}

.piece.p1.selected {
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.6),
    0 0 20px var(--p1-glow),
    0 0 0 3px var(--p1-color);
}

.piece.p2.selected {
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.6),
    0 0 20px var(--p2-glow),
    0 0 0 3px var(--p2-color);
}

/* ============================================================
   Non-interactive pieces (hitbox fix for valid-move tiles)
   ============================================================ */

.piece.no-interact {
  pointer-events: none;
}

/* ============================================================
   Ghost piece — shown at entry tile when a home piece can enter
   ============================================================ */

.ghost-piece {
  opacity: 0.4;
  cursor: pointer !important;
  animation: ghost-pulse 1.4s ease-in-out infinite;
  border-style: dashed;
  pointer-events: auto;
}

.ghost-piece:hover {
  opacity: 0.7;
  transform: scale(1.1);
}

.ghost-piece .piece-label {
  font-size: 1rem;
  font-weight: 900;
  opacity: 0.9;
}

@keyframes ghost-pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.95); }
  50%      { opacity: 0.55; transform: scale(1.02); }
}

/* ============================================================
   Home pieces — clickable state when entry is possible
   ============================================================ */

.home-pieces.home-clickable {
  cursor: pointer;
  border-radius: 6px;
  box-shadow: 0 0 0 2px var(--accent), 0 0 12px var(--accent-glow);
  animation: home-glow 1.2s ease-in-out infinite;
  padding: 2px 4px;
}

@keyframes home-glow {
  0%, 100% { box-shadow: 0 0 0 2px var(--accent), 0 0 8px var(--accent-glow); }
  50%      { box-shadow: 0 0 0 2px var(--accent), 0 0 18px var(--accent-glow); }
}

/* ============================================================
   Piece on a rosette — subtle shield/safe indicator
   ============================================================ */

.piece.on-rosette::after {
  content: '⬡';
  position: absolute;
  bottom: -4px;
  right: -4px;
  font-size: 0.7rem;
  color: var(--rosette-accent);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  line-height: 1;
  pointer-events: none;
}

/* ============================================================
   Home pieces — smaller, stacked with overlap (info bars)
   ============================================================ */

.home-piece {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  font-weight: 700;
  flex-shrink: 0;
  background-image: radial-gradient(
    circle at 35% 30%,
    rgba(255, 255, 255, 0.2) 0%,
    transparent 60%
  );
  transition: transform 0.15s;
}

.home-piece.p1 {
  background-color: var(--p1-bg);
  color: var(--p1-color);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.home-piece.p2 {
  background-color: var(--p2-bg);
  color: var(--p2-color);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* Stacking overlap effect */
.home-piece + .home-piece {
  margin-left: -5px;
}

/* ============================================================
   Scored pieces — in the info bar, with a star overlay
   ============================================================ */

.scored-piece {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  flex-shrink: 0;
  position: relative;
  background-image: radial-gradient(
    circle at 35% 30%,
    rgba(255, 255, 255, 0.18) 0%,
    transparent 60%
  );
}

.scored-piece.p1 {
  background-color: var(--p1-bg);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.scored-piece.p2 {
  background-color: var(--p2-bg);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

/* Star/check overlay on scored pieces */
.scored-piece::after {
  content: '★';
  font-size: 0.65rem;
  color: var(--rosette-accent);
  line-height: 1;
}

/* Stacking overlap */
.scored-piece + .scored-piece {
  margin-left: -5px;
}

/* Piece count badge (when too many pieces to show individually) */
.piece-count-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 0 4px;
}

/* ============================================================
   Dice
   ============================================================ */

.die {
  width: 40px;
  height: 40px;
  background: var(--die-bg);
  border: 2px solid var(--die-border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* Die with a marked pip (value = 1) */
.die.marked {
  border-color: var(--die-marked);
  background: color-mix(in srgb, var(--die-bg) 80%, var(--die-marked) 20%);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.4),
    0 0 10px color-mix(in srgb, transparent 60%, var(--die-marked) 40%),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* Tetrahedron pip symbol */
.die::after {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: transparent;
  transition: background 0.15s;
}

.die.marked::after {
  background: var(--die-marked);
  box-shadow: 0 0 6px var(--die-marked);
}

/* Blank die pip (dim dot) */
.die.blank::after {
  background: var(--die-border);
  opacity: 0.4;
}

/* ============================================================
   Rolling state on dice
   ============================================================ */

.die.rolling {
  animation: dice-tumble 0.63s ease-in-out;
  border-color: var(--accent);
}

/* ============================================================
   Dice total display
   ============================================================ */

#dice-total {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  min-height: 1.4em;
  text-align: center;
  letter-spacing: 0.06em;
}

#dice-total.no-move {
  color: #f87171;
}

/* ============================================================
   Piece animation classes (applied by JS during moves)
   ============================================================ */

.piece.moving {
  animation: piece-move 0.56s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
  z-index: 20;
  pointer-events: none;
}

.piece.capturing {
  animation: piece-capture 0.63s ease-in forwards;
  z-index: 20;
  pointer-events: none;
}

.piece.entering {
  animation: piece-enter 0.44s ease-out forwards;
}

.piece.scoring {
  animation: piece-score 0.63s ease-out forwards;
  z-index: 20;
}

/* ============================================================
   Extra-turn flash (applied to the active player info bar)
   ============================================================ */

.player-info.extra-turn {
  animation: extra-turn-flash 0.55s ease-out;
}

/* ============================================================
   Keyframe animations
   ============================================================ */

@keyframes piece-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.08); }
}

@keyframes piece-move {
  0%   { transform: scale(1.1) translateY(-6px); opacity: 0.9; }
  60%  { transform: scale(1.15) translateY(-10px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes piece-capture {
  0%   { transform: scale(1); opacity: 1; }
  40%  { transform: scale(1.3) rotate(20deg); opacity: 0.8; }
  100% { transform: scale(0.3) rotate(-30deg) translateY(-20px); opacity: 0; }
}

@keyframes piece-enter {
  0%   { transform: scale(0.5); opacity: 0; }
  70%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes piece-score {
  0%   { transform: scale(1); opacity: 1; }
  50%  { transform: scale(1.3) translateY(-8px); opacity: 0.9; }
  100% { transform: scale(0.6) translateY(-30px); opacity: 0; }
}

@keyframes dice-tumble {
  0%   { transform: rotate(0deg) scale(1); }
  20%  { transform: rotate(-25deg) scale(1.08); }
  45%  { transform: rotate(18deg) scale(0.95); }
  70%  { transform: rotate(-12deg) scale(1.05); }
  85%  { transform: rotate(6deg) scale(1.02); }
  100% { transform: rotate(0deg) scale(1); }
}

@keyframes extra-turn-flash {
  0%   { box-shadow: 0 0 0 0 var(--accent-glow); }
  30%  {
    box-shadow:
      0 0 0 6px var(--accent-glow),
      0 0 28px var(--accent-glow);
    border-color: var(--accent);
  }
  100% {
    box-shadow:
      0 0 18px var(--accent-glow);
    border-color: var(--accent);
  }
}

/* ============================================================
   Responsive dice / piece sizes
   ============================================================ */

@media (max-width: 768px) {
  .die {
    width: 32px;
    height: 32px;
    border-radius: 6px;
  }
  .die::after {
    width: 8px;
    height: 8px;
  }
  .home-piece,
  .scored-piece {
    width: 14px;
    height: 14px;
    font-size: 0.5rem;
  }
  #dice-total { font-size: 0.95rem; }
}

@media (max-width: 480px) {
  .die {
    width: 26px;
    height: 26px;
    border-radius: 5px;
  }
  .die::after {
    width: 6px;
    height: 6px;
  }
  .home-piece,
  .scored-piece {
    width: 12px;
    height: 12px;
    font-size: 0.45rem;
  }
  .dice-group { gap: 6px; }
}
