/**
 * board.css - 7x7 Grid Layout, Cell States, Tokens & SVG Route Flow
 *
 * Implements a dynamic, square-preserving board that scales with BOTH viewport
 * width and vertical height, ensuring it never pushes controls off screen.
 */
.layout {
  flex: 1 1 0%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 330px);
  gap: clamp(8px, 1.2vw, 16px);
  align-items: stretch;
  overflow: hidden;
}

.layout > section {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.boardcard {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(
    140deg,
    #925b2e,
    #4b2918 17%,
    #6b3c22 70%,
    #9b6536
  );
  border: clamp(4px, 0.8vh, 7px) solid #4c2b19;
  border-radius: clamp(14px, 2.2vh, 26px);
  padding: clamp(4px, 0.8vh, 12px);
  box-shadow:
    0 16px 50px #08050280,
    inset 0 0 0 2px #d4a66d80;
  position: relative;
  overflow: hidden;
}

.boardcard:before {
  content: "✺";
  position: absolute;
  top: 4px;
  left: 10px;
  color: #e6b777;
  font-size: clamp(14px, 2vh, 20px);
  opacity: 0.8;
}

.boardcard:after {
  content: "✺";
  position: absolute;
  bottom: 4px;
  right: 10px;
  color: #e6b777;
  font-size: clamp(14px, 2vh, 20px);
  opacity: 0.8;
}

.board-qr-badge {
  position: absolute;
  top: 6px;
  right: 10px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(24px, 3.2vh, 32px);
  height: clamp(24px, 3.2vh, 32px);
  padding: 3px;
  border-radius: 6px;
  border: 1px solid #d49f64aa;
  background: #3e2213ee;
  box-shadow: 0 2px 5px #0006;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.board-qr-badge:hover {
  transform: scale(1.1);
  background: #542f1bee;
  border-color: #ffd899;
}

.board-qr-badge:active {
  transform: scale(0.95);
}

.board-qr-badge img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: brightness(0.95) contrast(1.1);
  border-radius: 2px;
}

.boardwrap {
  position: relative;
  /* Bounded by BOTH width and remaining vertical space */
  height: min(100%, calc(100dvh - 245px));
  width: auto;
  aspect-ratio: 1;
  max-width: 100%;
  margin: auto;
  display: grid;
  place-items: center;
}

.pathoverlay {
  position: absolute;
  inset: clamp(4px, 1vmin, 8px);
  width: calc(100% - clamp(8px, 2vmin, 16px));
  height: calc(100% - clamp(8px, 2vmin, 16px));
  z-index: 1;
  pointer-events: none;
  overflow: visible;
}

.pathbase {
  fill: none;
  stroke: #7b421f;
  stroke-width: clamp(10px, 2vmin, 20px);
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.26;
}

.pathflow {
  fill: none;
  stroke: #fff0ad;
  stroke-width: clamp(3px, 0.6vmin, 5px);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 18 22;
  opacity: 0.72;
  animation: pathFlow 2.4s linear infinite;
}

.pathapproach {
  stroke-width: clamp(8px, 1.5vmin, 15px);
}

.pathflow.pathapproach {
  stroke-width: clamp(2.5px, 0.5vmin, 4px);
}

.patharrows {
  fill: none;
  stroke: #fff8c9;
  stroke-width: clamp(2px, 0.4vmin, 4px);
  stroke-linecap: round;
  opacity: 0.9;
  marker-end: url(#routeArrow);
  filter: drop-shadow(0 1px 1px #4b2815);
}

@keyframes pathFlow {
  to {
    stroke-dashoffset: -40;
  }
}

.board {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(7, minmax(0, 1fr));
  gap: clamp(1px, 0.3vmin, 3px);
  aspect-ratio: 1;
  width: 100%;
  height: 100%;
  background: #7c4c2c;
  border: clamp(2px, 0.4vmin, 4px) solid #c38d50;
  border-radius: clamp(6px, 1vmin, 12px);
  padding: clamp(2px, 0.3vmin, 4px);
  box-shadow: inset 0 0 0 clamp(1px, 0.3vmin, 3px) #4b2d1b;
  box-sizing: border-box;
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  background: linear-gradient(145deg, #f5d8a4, #e6bf80);
  border: 1px solid #b48a55;
  border-radius: 4px;
  color: #8d5d34;
  padding: 0;
  transition:
    filter 0.15s,
    outline 0.15s;
}

.cell.inner {
  background: linear-gradient(140deg, #e8c68f, #dcb67b);
}

.cell.approach {
  background: linear-gradient(140deg, #f0d5a3, #e5bf85);
  box-shadow: inset 0 0 10px rgba(255, 215, 0, 0.35);
  border-color: rgba(255, 215, 0, 0.5);
}

.cell.safe {
  background: linear-gradient(140deg, #a97647, #754527);
  color: #f4d59d;
}

.cell.goal {
  background: radial-gradient(circle, #ffe396, #f2c775 45%, #8e552f 85%);
  color: #422613;
  box-shadow: 0 0 16px rgba(255, 215, 0, 0.5), inset 0 0 12px rgba(255, 220, 100, 0.4);
}

.cell.startN {
  box-shadow: inset 0 0 0 clamp(2px, 0.5vmin, 5px) #e74c3c;
}

.cell.startE {
  box-shadow: inset 0 0 0 clamp(2px, 0.5vmin, 5px) #2389da;
}

.cell.startS {
  box-shadow: inset 0 0 0 clamp(2px, 0.5vmin, 5px) #f4b400;
}

.cell.startW {
  box-shadow: inset 0 0 0 clamp(2px, 0.5vmin, 5px) #2e9d57;
}

.cell.legal {
  outline: clamp(2px, 0.4vmin, 4px) solid #fff8a5;
  outline-offset: -3px;
  cursor: pointer;
  z-index: 2;
  animation: pulse 1.3s infinite;
  filter: brightness(1.12);
}

.cell.legal:after {
  content: "MOVE";
  position: absolute;
  bottom: 2px;
  font-size: clamp(6px, 0.8vmin, 8.5px);
  font-weight: 900;
  letter-spacing: 0.3px;
  color: #3b200d;
  background: #fff4a4e0;
  border: 1px solid #754522;
  border-radius: 4px;
  padding: 0 2px;
  line-height: 1.1;
  pointer-events: none;
  box-shadow: 0 1px 2px #0004;
}

.cell.legal:hover {
  filter: brightness(1.2);
}

.direction {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(14px, 2.8vmin, 26px);
  line-height: 1;
  color: #925828;
  opacity: 0.35;
  pointer-events: none;
  user-select: none;
  transition: opacity 0.2s;
}

.cell.safe .direction {
  opacity: 0.16;
}

.motif {
  font-size: clamp(20px, 4.8vmin, 46px);
  opacity: 0.88;
  line-height: 1;
}

.cell.safe .motif {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(22px, 5.2vmin, 50px);
  pointer-events: none;
}

.cell.goal .motif {
  font-size: clamp(26px, 6.2vmin, 58px);
  filter: drop-shadow(0 0 10px #ff9500aa);
}

.tokens {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(2px, 0.4vmin, 4px);
  padding: clamp(2px, 0.5vmin, 4px);
  z-index: 3;
  pointer-events: none;
}

.token {
  position: relative;
  width: clamp(32px, 7.8vmin, 68px);
  height: clamp(32px, 7.8vmin, 68px);
  max-width: 82%;
  max-height: 82%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: clamp(2px, 0.4vmin, 3.5px) solid #fffbe0;
  box-shadow:
    0 4px 10px #00000088,
    inset 0 2px 5px #ffffffaa;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(20px, 4.8vmin, 42px);
  line-height: 1;
  color: #23140b;
  font-weight: 800;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  pointer-events: auto;
  user-select: none;
}

/* Scaling adjustments when multiple player groups share a safe square or goal */
.tokens.count-2 {
  flex-direction: row;
  flex-wrap: wrap;
  gap: clamp(2px, 0.4vmin, 4px);
}

.tokens.count-2 .token {
  width: clamp(22px, 4.8vmin, 42px);
  height: clamp(22px, 4.8vmin, 42px);
  font-size: clamp(14px, 2.8vmin, 24px);
  border-width: clamp(1.5px, 0.3vmin, 2.5px);
}

.tokens.count-3,
.tokens.count-4 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  place-items: center;
  gap: clamp(1px, 0.3vmin, 3px);
}

.tokens.count-3 .token,
.tokens.count-4 .token {
  width: clamp(16px, 3.5vmin, 30px);
  height: clamp(16px, 3.5vmin, 30px);
  font-size: clamp(10px, 2vmin, 18px);
  border-width: 1px;
}

.tokenemoji {
  display: block;
  line-height: 1;
  transform: translateY(-0.5px);
  pointer-events: none;
}

.tokenids {
  position: absolute;
  bottom: -2px;
  right: -3px;
  background: #2b160be6;
  color: #ffeed1;
  border: 1px solid #ffda99;
  border-radius: 7px;
  font-size: clamp(7.5px, 1.2vmin, 10.5px);
  font-weight: 900;
  line-height: 1;
  padding: 1px 3px;
  letter-spacing: -0.2px;
  box-shadow: 0 1px 3px #0009;
}

.token.crowded {
  box-shadow: 2px -2px 0 1px rgba(0, 0, 0, 0.45), 4px -4px 0 1px rgba(255, 255, 255, 0.28), 0 3px 8px rgba(0, 0, 0, 0.55);
}

.token.selectable {
  box-shadow:
    0 0 0 clamp(2px, 0.4vmin, 3.5px) #fff899,
    0 4px 10px #000c;
  cursor: pointer;
  transform: scale(1.08);
  filter: drop-shadow(0 0 6px #ffe57f99);
}

.token.selectable:hover {
  transform: scale(1.18);
  filter: drop-shadow(0 0 10px #ffe57fdd);
}

.token.selectable:active {
  transform: scale(0.96);
}

.token.moving {
  box-shadow:
    0 0 0 3px #fff8ba,
    0 4px 10px #000c;
  animation: pulseMoving 0.6s ease-in-out infinite alternate;
}

@keyframes pulseMoving {
  from {
    transform: scale(1.05);
  }
  to {
    transform: scale(1.22);
  }
}

.token.captured {
  animation: capturedPiece 0.75s ease-in forwards;
}

@keyframes capturedPiece {
  0% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  40% {
    transform: scale(1.3) rotate(35deg);
    opacity: 0.9;
  }
  100% {
    transform: scale(0.2) rotate(180deg);
    opacity: 0;
  }
}

.capture-splash {
  position: absolute;
  transform: translate(-50%, -50%) scale(0.6);
  opacity: 0;
  pointer-events: none;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: rgba(160, 20, 20, 0.95);
  backdrop-filter: blur(4px);
  color: #fff;
  padding: 8px 18px;
  border-radius: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5), 0 0 18px rgba(239, 68, 68, 0.7);
  font-family: inherit;
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  animation: captureSplashAnim 2.4s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
  max-width: 90%;
  text-align: center;
}

.capture-splash.centered {
  left: 50% !important;
  top: 50% !important;
}

.capture-splash-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #fff;
}

.capture-splash-detail {
  font-size: 0.82rem;
  font-weight: 600;
  color: #ffecd2;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.capture-splash-icon {
  font-size: 1.15rem;
}

@keyframes captureSplashAnim {
  0% {
    transform: translate(-50%, -35%) scale(0.6);
    opacity: 0;
  }
  12% {
    transform: translate(-50%, -50%) scale(1.08);
    opacity: 1;
  }
  20% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  75% {
    transform: translate(-50%, -55%) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -75%) scale(0.92);
    opacity: 0;
  }
}

/* Goal Splash: Celebratory banner when a coin reaches the sacred center (D4 / Goal) */
.goal-splash {
  position: absolute;
  transform: translate(-50%, -50%) scale(0.6);
  opacity: 0;
  pointer-events: none;
  z-index: 105;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: linear-gradient(135deg, rgba(217, 119, 6, 0.95), rgba(180, 83, 9, 0.95));
  backdrop-filter: blur(6px);
  color: #fff;
  padding: 10px 22px;
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6), 0 0 24px rgba(245, 158, 11, 0.85);
  font-family: inherit;
  border: 2px solid rgba(254, 243, 199, 0.7);
  animation: captureSplashAnim 2.8s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
  max-width: 90%;
  text-align: center;
}

.goal-splash.centered {
  left: 50% !important;
  top: 50% !important;
}

.goal-splash-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.96rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #fffbeb;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.goal-splash-detail {
  font-size: 0.84rem;
  font-weight: 700;
  color: #fef3c7;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.goal-splash-bonus {
  font-size: 0.78rem;
  font-weight: 700;
  color: #ffe082;
  background: rgba(0, 0, 0, 0.25);
  padding: 2px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 238, 187, 0.4);
}

.boardlegend {
  flex: 0 0 auto;
  margin-top: clamp(3px, 0.5vh, 6px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.2vw, 14px);
  flex-wrap: wrap;
  font-size: clamp(9px, 1.2vh, 11px);
  color: #f1dfca;
  background: #1e130c52;
  border: 1px solid #f8dfb11c;
  border-radius: 10px;
  padding: clamp(3px, 0.4vh, 5px) clamp(6px, 1vw, 10px);
}

.legenditem {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.legendarrow {
  color: #ffe89e;
}

.legendmove {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: #fff8a5;
  box-shadow: 0 0 0 1px #9c6e3b;
}

.legendsafe {
  color: #f8db9f;
}

.legendplayers {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.legendplayer {
  width: clamp(11px, 1.4vh, 14px);
  height: clamp(11px, 1.4vh, 14px);
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-size: clamp(7px, 1vh, 9px);
  color: #170d06;
  border: 1px solid #fff9;
}

/* Progressive proportional brightness for inner circuits and center goal */
.token.tier-inner2 {
  filter: brightness(1.22) drop-shadow(0 0 5px rgba(255, 215, 0, 0.5));
  border-color: #ffe600e6 !important;
}

.token.tier-inner3 {
  filter: brightness(1.42) drop-shadow(0 0 9px rgba(255, 220, 80, 0.8));
  border-color: #fff275 !important;
  animation: inner3Pulse 1.8s ease-in-out infinite alternate;
}

.token.tier-center {
  filter: brightness(1.65) drop-shadow(0 0 15px rgba(255, 230, 80, 0.95));
  border-color: #ffffff !important;
  animation: centerRadiance 1.4s ease-in-out infinite alternate;
}

@keyframes inner3Pulse {
  0% {
    box-shadow: 0 0 4px rgba(255, 215, 0, 0.4);
    transform: scale(1);
  }
  100% {
    box-shadow: 0 0 12px rgba(255, 235, 120, 0.85);
    transform: scale(1.06);
  }
}

@keyframes centerRadiance {
  0% {
    box-shadow: 0 0 8px rgba(255, 220, 50, 0.6), inset 0 0 4px #fff;
    transform: scale(1.02);
  }
  100% {
    box-shadow: 0 0 18px rgba(255, 240, 100, 1), inset 0 0 8px #fff;
    transform: scale(1.12);
  }
}

/* Slow animated capture returning from board cell to family table */
.captured-flying-piece {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55), 0 0 16px rgba(239, 68, 68, 0.8);
  border: 2px solid #fff;
  transition: transform 0.95s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.95s cubic-bezier(0.22, 1, 0.36, 1);
}

.player.reserve-bounce {
  animation: reserveBounce 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes reserveBounce {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.08);
    box-shadow: 0 0 18px rgba(239, 68, 68, 0.55);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 2px 5px #0004;
  }
}
