/* Traditional Ludo cross board rendered on a 15x15 CSS grid.
   Only cells that are part of the layout (home bases, track, home columns,
   center) get visible backgrounds — the rest are transparent. */

.dice-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 0;
  flex-wrap: wrap;
}

.die {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 64px;
  height: 64px;
  padding: 8px;
  background: linear-gradient(135deg, var(--card) 0%, var(--card-2) 100%);
  border: 1px solid var(--secondary);
  border-radius: 14px;
  box-shadow:
    inset 0 -3px 0 rgba(15, 23, 42, 0.08),
    inset 0 2px 0 rgba(255, 255, 255, 0.8),
    0 6px 14px rgba(15, 23, 42, 0.18);
  gap: 2px;
  /* GPU-accelerated for smooth animation */
  will-change: transform;
  transform: translateZ(0);
  transition: transform 0.12s ease-out;
}

.die-spot { display: block; }
.die-pip {
  background: radial-gradient(circle at 30% 30%, #475569, #0f172a 70%);
  border-radius: 50%;
  width: 10px; height: 10px;
  place-self: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Tumbling roll — multi-axis rotate + translate with easing that decelerates. */
@keyframes die-roll {
  0%   { transform: rotate(0deg) scale(1); }
  15%  { transform: rotate(120deg) translate(-8px, -14px) scale(1.18); }
  30%  { transform: rotate(280deg) translate(10px, -18px) scale(1.22); }
  45%  { transform: rotate(460deg) translate(-12px, -10px) scale(1.18); }
  60%  { transform: rotate(620deg) translate(8px, -6px) scale(1.14); }
  75%  { transform: rotate(780deg) translate(-4px, 0) scale(1.08); }
  90%  { transform: rotate(900deg) translate(2px, 2px) scale(1.04); }
  100% { transform: rotate(960deg) scale(1); }
}

.die.die-rolling {
  animation: die-roll 0.8s cubic-bezier(0.32, 0.72, 0.36, 1) forwards;
  box-shadow:
    inset 0 -3px 0 rgba(15, 23, 42, 0.08),
    inset 0 2px 0 rgba(255, 255, 255, 0.8),
    0 16px 26px rgba(15, 23, 42, 0.32);
}

/* Landing bounce — a quick squash/stretch as the die "settles" on the table. */
@keyframes die-settle {
  0%   { transform: scale(1.0) translateY(0); }
  35%  { transform: scale(1.12, 0.88) translateY(2px); }
  60%  { transform: scale(0.94, 1.06) translateY(-3px); }
  100% { transform: scale(1) translateY(0); }
}

.die.die-settle {
  animation: die-settle 0.28s cubic-bezier(0.4, 0, 0.6, 1.4);
}

@media (prefers-reduced-motion: reduce) {
  .die.die-rolling, .die.die-settle { animation: none !important; }
}

.dice-hint {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
  width: 100%;
}

/* --------- Board --------- */

.lu-board-wrap {
  display: flex;
  justify-content: center;
  padding: 4px 0;
}

.lu-board {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  width: min(96vw, 52vh, 520px);
  aspect-ratio: 1;
  background: var(--card);
  border: 3px solid var(--text);
  border-radius: 8px;
  box-shadow: var(--shadow);
  /* allow the active-base glow to extend slightly beyond the board edge */
  overflow: visible;
  position: relative;
  user-select: none;
  touch-action: manipulation;
}

/* Pulsing colored frame around the home base of whoever's turn it is.
   Absolutely positioned so it doesn't compete with the 15×15 grid cells
   for layout space. The board has `position: relative` so 0/0/40%/40%
   places this exactly over each 6×6 corner base. */
.lu-base-overlay {
  position: absolute;
  width: 40%;
  height: 40%;
  pointer-events: none;
  border: 4px solid transparent;
  border-radius: 8px;
  z-index: 3;
  transition: border-color 0.25s ease-out;
}
.lu-base-overlay[data-color="R"] { top: 0;    left: 0; }
.lu-base-overlay[data-color="B"] { top: 0;    right: 0; }
.lu-base-overlay[data-color="G"] { bottom: 0; left: 0; }
.lu-base-overlay[data-color="Y"] { bottom: 0; right: 0; }

.lu-base-overlay.active {
  animation: lu-base-glow 1.4s ease-in-out infinite;
}
.lu-base-overlay.active[data-color="R"] { border-color: #ef4444; box-shadow: 0 0 22px rgba(239,68,68,0.7); }
.lu-base-overlay.active[data-color="B"] { border-color: #3b82f6; box-shadow: 0 0 22px rgba(59,130,246,0.7); }
.lu-base-overlay.active[data-color="G"] { border-color: #10b981; box-shadow: 0 0 22px rgba(16,185,129,0.7); }
.lu-base-overlay.active[data-color="Y"] { border-color: #eab308; box-shadow: 0 0 22px rgba(234,179,8,0.7); }

@keyframes lu-base-glow {
  0%, 100% { transform: scale(1.0); filter: brightness(1.0); }
  50%      { transform: scale(1.015); filter: brightness(1.15); }
}

@media (prefers-reduced-motion: reduce) {
  .lu-base-overlay.active { animation: none; }
  .lu-tok.movable .lu-pawn { animation: none; }
}

.lu-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--secondary);
  background: var(--card);
  box-sizing: border-box;
}

/* Home base cells — the thick colored quadrants */
.lu-base {
  border-color: rgba(255, 255, 255, 0.4);
}
.lu-base.R { background: #ef4444; }
.lu-base.G { background: #10b981; }
.lu-base.Y { background: #eab308; }
.lu-base.B { background: #3b82f6; }

/* The 4 token-rest seats inside each colored home base — a white circle
   that sits behind the token. Always visible so empty seats read as "open". */
.lu-base-spot {
  position: relative;
}
/* White seat for a token at rest. Must be LARGER than the token so it reads
   as a visible halo around same-colored tokens on same-colored bases
   (otherwise red-on-red / yellow-on-yellow etc. blend together). */
.lu-base-spot::after {
  content: "";
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(15, 23, 42, 0.2);
  pointer-events: none;
  z-index: 0;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
}

/* Entry/safe squares on the track colored per player */
.lu-track.entry-R { background: #fecaca; }
.lu-track.entry-G { background: #bbf7d0; }
.lu-track.entry-Y { background: #fef08a; }
.lu-track.entry-B { background: #bfdbfe; }

/* Home column cells */
.lu-home-col.R { background: #fecaca; }
.lu-home-col.G { background: #bbf7d0; }
.lu-home-col.Y { background: #fef08a; }
.lu-home-col.B { background: #bfdbfe; }

/* Safe (star) squares */
.lu-track.safe::after {
  content: "★";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 0.9em;
  pointer-events: none;
}

/* Center 3x3 "home" triangles — drawn as tinted cells */
.lu-center {
  border: none;
}
.lu-center.R { background: linear-gradient(135deg, #ef4444 50%, transparent 50%); }
.lu-center.G { background: linear-gradient(225deg, #10b981 50%, transparent 50%); }
.lu-center.Y { background: linear-gradient(315deg, #eab308 50%, transparent 50%); }
.lu-center.B { background: linear-gradient(45deg,  #3b82f6 50%, transparent 50%); }
.lu-center.mid { background: var(--card); border: 1px solid var(--secondary); }

/* Token container — transparent button that holds an inline SVG pawn.
   inset 5% so the pawn fills most of the cell while leaving a small gap to
   the cell border; the white base-spot halo (inset 4%) still frames it. */
.lu-tok {
  position: absolute;
  inset: 5%;
  border: none;
  background: transparent;
  padding: 0;
  pointer-events: none;
  cursor: default;
  z-index: 2;
  /* `transform` is used at runtime for (a) stacking offset when multiple
     tokens share a cell and (b) FLIP slide animation on moves. */
}

.lu-tok .lu-pawn {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
  /* Clicks go to the button, not the SVG (needed for the pulse/click overlap). */
  pointer-events: none;
}

/* The white shine highlight at the top-left of the head — same for all colors. */
.lu-tok .p-shine {
  fill: rgba(255, 255, 255, 0.65);
  pointer-events: none;
}

/* Per-color pawn fills: darker for base/neck (in shadow), brighter for head. */
.lu-tok.R .p-base, .lu-tok.R .p-neck { fill: #7f1d1d; }
.lu-tok.R .p-body { fill: #dc2626; }
.lu-tok.R .p-head { fill: #ef4444; }

.lu-tok.B .p-base, .lu-tok.B .p-neck { fill: #1e3a8a; }
.lu-tok.B .p-body { fill: #2563eb; }
.lu-tok.B .p-head { fill: #3b82f6; }

.lu-tok.G .p-base, .lu-tok.G .p-neck { fill: #065f46; }
.lu-tok.G .p-body { fill: #059669; }
.lu-tok.G .p-head { fill: #10b981; }

.lu-tok.Y .p-base, .lu-tok.Y .p-neck { fill: #854d0e; }
.lu-tok.Y .p-body { fill: #ca8a04; }
.lu-tok.Y .p-head { fill: #eab308; }

.lu-tok.movable {
  cursor: pointer;
  pointer-events: auto;
}
/* Pulse on the SVG's drop-shadow rather than a scale transform, so the
   slide animation (which uses transform) and the movable indicator don't
   fight for the same property. */
.lu-tok.movable .lu-pawn {
  animation: lu-pulse-glow 1.2s ease-in-out infinite;
}
@keyframes lu-pulse-glow {
  0%, 100% {
    filter: drop-shadow(0 0 3px #fbbf24) drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
  }
  50% {
    filter: drop-shadow(0 0 10px #fbbf24) drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
  }
}

/* Setup card */
#setup { text-align: center; }
#setup h2 { margin-bottom: 10px; }
#setup .row { justify-content: center; }
