:root {
  --apple-red: #d32f2f;
  --blueberry-blue: #7b1fa2;
  /* Changed to Grape Purple */
  --banana-yellow: #fbc02d;
  --kiwi-green: #388e3c;
  --board-bg: #fff;
  --text-color: #333;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  /* Vertical center handled by flex, but footer might push it */
  flex-direction: column;
  height: 100vh;
  background-color: #f0f4f8;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  overflow: hidden;
}

/* Main Layout */
#main-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 600px;
  /* Limit width on desktop */
  background: #e0e0e0;
  position: relative;
}

#game-area {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: 10px;
}

#ludo-board {
  display: grid;
  /* 6 Base cols (smaller), 3 Path cols (bigger), 6 Base cols (smaller) */
  grid-template-columns: repeat(6, 1fr) repeat(3, 1.5fr) repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr) repeat(3, 1.5fr) repeat(6, 1fr);
  width: 98vmin;
  height: 98vmin;
  max-width: 85vh;
  /* Much larger on desktop */
  max-height: 85vh;
  background-color: #fff;
  border: 4px solid #333;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  transition: transform 1s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  margin: auto;
  /* Force center in flex parent */
}

.token-icon {
  display: block;
  transform: rotate(calc(var(--board-rotation, 0deg) * -1));
  transition: transform 1s;
}

/* Modals / Overlays */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 200;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: white;
  text-align: center;
}

.hidden {
  display: none !important;
}

.fruit-select-btn {
  background: white;
  border: none;
  padding: 15px 30px;
  margin: 10px;
  font-size: 1.5rem;
  border-radius: 50px;
  cursor: pointer;
  transition: transform 0.2s;
  width: 80%;
  max-width: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  color: #333;
  font-weight: bold;
}

.fruit-select-btn:hover {
  transform: scale(1.05);
}

/* Footer Controls */
#footer-controls {
  height: auto;
  min-height: 120px;
  background: white;
  border-top: 2px solid #ccc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px 90px 20px !important;
  /* Extra bottom padding for mobile bars, increased to 90px */
  z-index: 100;
  width: 100%;
}

.token.mini {
  position: absolute !important;
  width: 60% !important;
  height: 60% !important;
  font-size: 1.5vmin !important;
  transition: transform 0.3s;
}

/* Offsetting stacked tokens so they don't just overlap perfectly or shrink too much into a grid */
.token.mini:nth-child(1) {
  transform: translate(-20%, -20%);
  z-index: 11;
}

.token.mini:nth-child(2) {
  transform: translate(20%, -20%);
  z-index: 12;
}

.token.mini:nth-child(3) {
  transform: translate(-20%, 20%);
  z-index: 13;
}

.token.mini:nth-child(4) {
  transform: translate(20%, 20%);
  z-index: 14;
}

.token.mini:nth-child(n+5) {
  transform: translate(0, 0) scale(0.8);
  z-index: 15;
}


#player-info {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

#turn-badge {
  padding: 5px 15px;
  border-radius: 15px;
  color: white;
  font-weight: bold;
  text-transform: uppercase;
  font-size: 0.9rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#afk-status {
  font-size: 0.8rem;
  color: #f57c00;
  font-weight: bold;
  display: none;
}

#dice-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

#dice-btn {
  background: #eee;
  border: 2px solid #333;
  border-radius: 12px;
  width: 70px;
  height: 70px;
  font-size: 2.5rem;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background 0.2s;
}

#dice-btn:active {
  background: #ccc;
}

#dice-btn.disabled {
  opacity: 0.5;
  pointer-events: none;
}

#dice-btn.pulse-active {
  animation: btn-pulse 1s infinite alternate;
  border-color: #ff9800;
  /* Highlight */
  background: #fff3e0;
}

@keyframes btn-pulse {
  from {
    transform: scale(1);
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
  }

  to {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255, 152, 0, 0.6);
  }
}

#afk-btn {
  background: #0288d1;
  color: white;
  border: none;
  padding: 10px 15px;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }

  100% {
    opacity: 1;
  }
}

/* Re-use previous board styles */
.cell {
  border: 1px solid #ddd;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.base {
  grid-column: span 6;
  grid-row: span 6;
  border: 4px solid #333;
  padding: 10%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.base-inner {
  width: 100%;
  height: 100%;
  border-radius: 15px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  padding: 15%;
  gap: 15%;
}

.token-spot {
  background: white;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.1);
  width: 100%;
  height: 100%;
}

.base.apple {
  background: var(--apple-red);
  grid-column: 1/7;
  grid-row: 1/7;
  border-right: 2px solid #333;
  border-bottom: 2px solid #333;
}

.base.kiwi {
  background: var(--kiwi-green);
  grid-column: 10/16;
  grid-row: 1/7;
  border-left: 2px solid #333;
  border-bottom: 2px solid #333;
}

.base.blueberry {
  background: var(--blueberry-blue);
  grid-column: 1/7;
  grid-row: 10/16;
  border-right: 2px solid #333;
  border-top: 2px solid #333;
}

.base.banana {
  background: var(--banana-yellow);
  grid-column: 10/16;
  grid-row: 10/16;
  border-left: 2px solid #333;
  border-top: 2px solid #333;
}

.center-home {
  grid-column: 7/10;
  grid-row: 7/10;
  position: relative;
  border: 2px solid #333;
}

.center-triangle {
  position: absolute;
  width: 0;
  height: 0;
}

.tri-apple {
  border-top: 13vmin solid transparent;
  border-bottom: 13vmin solid transparent;
  border-left: 13vmin solid var(--apple-red);
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}

.tri-kiwi {
  border-left: 13vmin solid transparent;
  border-right: 13vmin solid transparent;
  border-top: 13vmin solid var(--kiwi-green);
  top: 0;
  left: 50%;
  transform: translateX(-50%);
}

.tri-banana {
  border-top: 13vmin solid transparent;
  border-bottom: 13vmin solid transparent;
  border-right: 13vmin solid var(--banana-yellow);
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

.tri-blueberry {
  border-left: 13vmin solid transparent;
  border-right: 13vmin solid transparent;
  border-bottom: 13vmin solid var(--blueberry-blue);
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

/* Media query for triangle size on desktop limits */
@media (min-width: 600px) {
  .tri-apple {
    border-width: 78px;
  }

  /* 600 * 0.95 / 15 * 6 / 2 ~ Not exact but close enough for visual */
  .tri-kiwi {
    border-width: 78px;
  }

  .tri-banana {
    border-width: 78px;
  }

  .tri-blueberry {
    border-width: 78px;
  }
}

.home-stretch.apple {
  background-color: var(--apple-red);
}

.home-stretch.kiwi {
  background-color: var(--kiwi-green);
}

.home-stretch.blueberry {
  background-color: var(--blueberry-blue);
}

.home-stretch.banana {
  background-color: var(--banana-yellow);
}

.safe-zone::after {
  content: '★';
  color: rgba(0, 0, 0, 0.2);
  font-size: 2em;
  position: absolute;
}

.start-square {
  background-size: 60%;
  background-repeat: no-repeat;
  background-position: center;
}

.start-square.apple {
  background-color: var(--apple-red);
}

.start-square.kiwi {
  background-color: var(--kiwi-green);
}

.start-square.blueberry {
  background-color: var(--blueberry-blue);
}

.start-square.banana {
  background-color: var(--banana-yellow);
}

.token {
  width: 90%;
  height: 90%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: min(5vmin, 35px);
  /* Increased size */
  position: relative;
  z-index: 10;
  cursor: pointer;
  background: transparent;
  margin: auto;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3));
  /* Shadow on the fruit itself */
}

.token.apple {
  /* background-color: var(--apple-red); removed */
  /* color: white; removed */
}

.token.blueberry {
  /* background-color: var(--blueberry-blue); removed */
  /* color: white; removed */
}

.token.banana {
  /* background-color: var(--banana-yellow); removed */
  /* color: black; removed */
}

.token.kiwi {
  /* background-color: var(--kiwi-green); removed */
  /* color: white; removed */
}

.token.can-move {
  animation: bounce 0.8s infinite;
  box-shadow: 0 0 0 3px white, 0 0 10px rgba(0, 0, 0, 0.3);
  /* Uses shadow instead of border to avoid layout shift */
  border-radius: 50%;
  z-index: 100;
}

@keyframes bounce {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.2);
  }
}

/* Revert Animation if possible, but JS will handle jump */