/* ===== Ludo board + side panel ===== */

/* Seat colours: jewel tones on walnut + gold, Patogame's own palette. */
.c-red    { --tok: #d9483f; --tok-dark: #8a1f1a; --tok-light: #ff9a8e; --tint: #f3c9c2; }
.c-green  { --tok: #2fae6a; --tok-dark: #135a33; --tok-light: #8ff0b8; --tint: #c3ead2; }
.c-yellow { --tok: #e9b72c; --tok-dark: #8a6510; --tok-light: #ffe39a; --tint: #f6e4ae; }
.c-blue   { --tok: #3f82d8; --tok-dark: #173f78; --tok-light: #9cc6ff; --tint: #c5d9f3; }

.ludo-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.ludo-table {
  flex: 1;
  display: flex;
  gap: clamp(14px, 3vw, 32px);
  align-items: flex-start;
  justify-content: center;
  padding: clamp(10px, 2.5vw, 24px);
  min-height: 0;
  overflow-y: auto;
}

.ludo-board-area {
  /* Fit the viewport height on desktop so the whole board is visible. */
  width: min(92vw, calc(100vh - 170px), 640px);
  min-width: 280px;
  flex: 0 0 auto;
}

/* Outer square box. Height also comes from the per-cell aspect-ratio below,
   so the board can't collapse if a browser ignores this one (see chess fix). */
.ludo-board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: #2a1c10;
  padding: 0;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55), 0 0 0 3px #2a1c10, 0 0 0 4px rgba(212, 175, 55, 0.45);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.ludo-board.shake { animation: ludo-shake 0.36s ease; }
@keyframes ludo-shake {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 1px); }
  50% { transform: translate(3px, -1px); }
  75% { transform: translate(-2px, 0); }
}

.ludo-board-inner {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  grid-template-rows: repeat(15, auto);
  gap: 0;
  border-radius: 10px;
  overflow: hidden;
  background: #e9dcbc;
  transition: transform 0.45s ease;
  transform-origin: 50% 50%;
}

/* ----- squares ----- */
.ludo-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  min-width: 0;
  background: #f2e7cb;
  box-shadow: inset 0 0 0 0.5px rgba(90, 62, 30, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ludo-cell.homecol { background: var(--tok); box-shadow: inset 0 0 0 0.5px var(--tok-dark); }
.ludo-cell.start   { background: var(--tint); }
.ludo-cell .mark {
  font-size: clamp(9px, 2.6vw, 20px);
  line-height: 1;
  color: #b08a3c;
  pointer-events: none;
}
.ludo-cell.star { background: #efe0b4; }
.ludo-cell .start-mark {
  width: 56%;
  height: 56%;
  border-radius: 50%;
  border: 2px solid var(--tok);
  box-shadow: inset 0 0 0 2px var(--tint), inset 0 0 0 9px var(--tok);
  opacity: 0.85;
}

/* ----- bases (6×6 corners) ----- */
.ludo-base {
  position: relative;
  background:
    radial-gradient(circle at 30% 25%, var(--tok-light) 0%, transparent 55%),
    var(--tok);
  box-shadow: inset 0 0 0 1px var(--tok-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.ludo-base.inactive { filter: grayscale(0.85) brightness(0.55); }

/* ----- turn signal -----
   The whole 6×6 base of the seat to move flashes: ::before brightens the base
   colour, ::after draws a thick white-gold ring with an inner glow (dark edge
   keeps it readable on yellow). Only opacity is animated, so it stays on the
   compositor. Other playing bases dim a little so the contrast does the work.
   `.mine` (the seat this device controls right now) pulses faster and harder
   and gets a "YOUR TURN" tag. */
.ludo-base { isolation: isolate; }
.ludo-base::before,
.ludo-base::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}
.ludo-base::before {
  z-index: 0;
  /* A brighter, more saturated copy of the base's own colour (keeps the hue). */
  background: radial-gradient(circle at 50% 45%, var(--tok-light) 0%, var(--tok) 72%);
  filter: saturate(1.6) brightness(1.1);
}
.ludo-base::after {
  z-index: 1;
  box-shadow:
    inset 0 0 0 1.5px rgba(60, 35, 0, 0.8),
    inset 0 0 0 6px #fff7d6,
    inset 0 0 16px 8px rgba(255, 214, 92, 0.8);
}
.ludo-yard { position: relative; z-index: 1; }
.ludo-base-label { z-index: 2; }
.ludo-base.turn .ludo-base-name { bottom: 4.5%; }
.ludo-base.turn.mine .ludo-base-name { bottom: 6%; }

.ludo-board-inner.has-turn .ludo-base:not(.turn):not(.inactive) { filter: brightness(0.8) saturate(0.8); }

.ludo-base.turn::before { animation: ludo-turn-pulse 1.2s ease-in-out infinite; }
.ludo-base.turn::after  { animation: ludo-turn-ring 1.2s ease-in-out infinite; }
.ludo-base.turn.mine::before { animation-duration: 0.9s; }
.ludo-base.turn.mine::after {
  animation-duration: 0.9s;
  box-shadow:
    inset 0 0 0 1.5px rgba(60, 35, 0, 0.85),
    inset 0 0 0 9px #fffbe8,
    inset 0 0 24px 12px rgba(255, 220, 100, 0.9);
}
.ludo-base.turn.mine .ludo-yard { animation: ludo-yard-bump 0.9s ease-in-out infinite; }
@keyframes ludo-turn-pulse {
  0%, 100% { opacity: 0; }
  50% { opacity: 0.85; }
}
@keyframes ludo-turn-ring {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}
.ludo-base.turn.mine::before { animation-name: ludo-turn-pulse-strong; }
@keyframes ludo-turn-pulse-strong {
  0%, 100% { opacity: 0.1; }
  50% { opacity: 1; }
}
@keyframes ludo-yard-bump {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* "YOUR TURN" tag on the base of the seat this device plays right now. */
.ludo-turn-tag {
  position: absolute;
  top: 3%;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.12em 0.65em;
  border-radius: 999px;
  font-size: clamp(9px, 2.3vw, 14px);
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1.3;
  color: #1f150c;
  background: #fff3c4;
  box-shadow: 0 0 0 1.5px rgba(70, 40, 0, 0.7), 0 1px 4px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  pointer-events: none;
  display: none;
}
.ludo-base.turn.mine .ludo-turn-tag { display: block; }

@media (prefers-reduced-motion: reduce) {
  .ludo-base.turn::before,
  .ludo-base.turn::after,
  .ludo-base.turn.mine .ludo-yard { animation: none; }
  .ludo-base.turn::before { opacity: 0.8; }
  .ludo-base.turn::after { opacity: 1; }
}
.ludo-yard {
  width: 68%;
  height: 68%;
  border-radius: 14%;
  background: #1f150c;
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.6), 0 0 0 2px rgba(212, 175, 55, 0.55);
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  place-items: center;
}
.ludo-yard .slot {
  width: 52%;
  height: 52%;
  border-radius: 50%;
  border: 2px dashed rgba(212, 175, 55, 0.45);
}
.ludo-base-name {
  position: absolute;
  left: 0; right: 0;
  bottom: 2%;
  text-align: center;
  font-size: clamp(8px, 2.1vw, 13px);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 6%;
  pointer-events: none;
}
/* Full-size overlay holding the name; counter-rotated against the board so
   the name always sits upright along the base's visual bottom edge. */
.ludo-base-label { position: absolute; inset: 0; pointer-events: none; }
.ludo-board-inner[data-rot="1"] .ludo-base-label { transform: rotate(-90deg); }
.ludo-board-inner[data-rot="2"] .ludo-base-label { transform: rotate(180deg); }
.ludo-board-inner[data-rot="3"] .ludo-base-label { transform: rotate(90deg); }

/* Finishing place ("1st", "2nd"…) on a finished seat's base. */
.ludo-place-badge {
  position: absolute;
  top: 3%;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.1em 0.6em;
  border-radius: 999px;
  font-size: clamp(9px, 2.3vw, 14px);
  font-weight: 800;
  line-height: 1.3;
  color: #1f150c;
  background: #e8d6a8;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  white-space: nowrap;
}
.ludo-place-badge:empty { display: none; }
.ludo-place-badge[data-place="1"] { background: var(--gold, #d4af37); }
.ludo-place-badge[data-place="2"] { background: #d8dde8; }
.ludo-place-badge[data-place="3"] { background: #d79a63; }

/* ----- centre: four triangles (top=seat 2, right=3, bottom=0, left=1) ----- */
.ludo-centre {
  position: relative;
  background: conic-gradient(from -45deg,
    #e9b72c 0 25%, #3f82d8 0 50%, #d9483f 0 75%, #2fae6a 0 100%);
  box-shadow: inset 0 0 0 1px rgba(60, 40, 20, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ludo-centre-gem {
  width: 30%;
  height: 30%;
  transform: rotate(45deg);
  background: linear-gradient(135deg, #fff3c4, var(--gold) 60%, #8a6a1c);
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
}

/* ----- tokens ----- */
.ludo-tokens {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.ludo-token {
  --s: 1;
  position: absolute;
  width: 5.1%;
  height: 5.1%;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(var(--s));
  background:
    radial-gradient(circle at 35% 30%, var(--tok-light) 0 18%, transparent 42%),
    radial-gradient(circle at 50% 50%, var(--tok) 0 48%, var(--tok-dark) 50% 60%, var(--tok) 62% 100%);
  border: 2px solid #f6eccd;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.45);
  transition: top 0.11s linear, left 0.11s linear, transform 0.2s ease;
  z-index: 2;
  pointer-events: none;
}
.ludo-token.in-base { z-index: 3; }
.ludo-token.hopping { z-index: 8; transform: translate(-50%, -62%) scale(1.15); }
.ludo-token.flying { transition: top 0.45s cubic-bezier(.5, -0.3, .5, 1.3), left 0.45s cubic-bezier(.5, -0.3, .5, 1.3), transform 0.2s; z-index: 7; }
.ludo-token.captured { opacity: 0.85; }
.ludo-token.movable {
  z-index: 6;
  animation: ludo-pulse 0.9s ease-in-out infinite;
  cursor: pointer;
  pointer-events: auto;   /* tap hit-testing: the tapped token (or its ring) is the one moved */
}
.ludo-token.movable::after {
  content: '';
  position: absolute;
  inset: -45%;
  border-radius: 50%;
  border: 3px solid var(--gold);
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.8);
}
@keyframes ludo-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(var(--s)); }
  50% { transform: translate(-50%, -58%) scale(calc(var(--s) * 1.12)); }
}
.ludo-tokens.choosing .ludo-token:not(.movable) { filter: brightness(0.82); }
.ludo-board:has(.ludo-tokens.choosing) { cursor: pointer; }

/* ----- side panel ----- */
.ludo-side {
  width: min(92vw, 320px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 150px);
  overflow-y: auto;
}

.ludo-dice-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 10px;
  padding: 10px 12px;
}
.ludo-dice {
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  padding: 0;
  border-radius: 16px;
  background: #fbf6e8;
  border: 3px solid var(--tok, var(--gold));
  box-shadow: 0 4px 0 #b9a77a, 0 6px 14px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}
.ludo-dice[data-color="red"]    { --tok: #d9483f; }
.ludo-dice[data-color="green"]  { --tok: #2fae6a; }
.ludo-dice[data-color="yellow"] { --tok: #e9b72c; }
.ludo-dice[data-color="blue"]   { --tok: #3f82d8; }
.ludo-dice:hover:not(:disabled) { background: #fffaf0; border-color: var(--tok, var(--gold)); }
.ludo-dice:disabled { opacity: 0.75; cursor: default; }
.ludo-dice.ready { animation: ludo-ready 1.2s ease-in-out infinite; opacity: 1; }
@keyframes ludo-ready {
  0%, 100% { box-shadow: 0 4px 0 #b9a77a, 0 0 0 0 rgba(250, 204, 21, 0.0); }
  50% { box-shadow: 0 4px 0 #b9a77a, 0 0 0 6px rgba(250, 204, 21, 0.45); }
}
.ludo-dice.rolling .ludo-die { animation: ludo-roll 0.36s linear; }
@keyframes ludo-roll {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(0.85); }
  100% { transform: rotate(360deg) scale(1); }
}
.ludo-die {
  width: 76%;
  height: 76%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
}
.ludo-die .pip { width: 11px; height: 11px; border-radius: 50%; background: transparent; }
.ludo-die .pip.on { background: #1f150c; box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.25); }

.ludo-dice-text { flex: 1; min-width: 0; }
.ludo-status { font-size: 15px; color: var(--text); line-height: 1.35; }
.ludo-dice-hint { font-size: 12px; color: var(--gold); margin-top: 4px; min-height: 15px; }

.ludo-players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ludo-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid transparent;
  font-size: 14px;
}
.ludo-player.turn { border-color: var(--gold); background: rgba(212, 175, 55, 0.12); }
.ludo-player.winner { border-color: var(--gold); background: rgba(212, 175, 55, 0.25); }
.ludo-player .swatch {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--tok);
  border: 2px solid #f6eccd;
  flex: 0 0 auto;
}
.ludo-player .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ludo-player .you { color: var(--gold); font-weight: 700; }
.ludo-player .tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--muted);
  vertical-align: middle;
}
.ludo-player .tag.off { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.ludo-player .phome { color: var(--muted); font-variant-numeric: tabular-nums; }
.ludo-player .pplace {
  font-size: 12px;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: 999px;
  color: #1f150c;
  background: #e8d6a8;
}
.ludo-player.winner .pplace { background: var(--gold); }
.ludo-player.placed:not(.winner) { opacity: 0.85; }

.ludo-controls { display: flex; gap: 8px; }
.ludo-controls button { flex: 1; min-height: 44px; font-size: 15px; }

.ludo-setup {
  background: rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  padding: 10px 12px;
}
.ludo-setup label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.ludo-setup select {
  background: #1a1410;
  color: var(--text);
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: 5px;
  padding: 6px 10px;
  font-size: 14px;
  min-height: 34px;
}

.ludo-rules {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}
.ludo-rules summary {
  cursor: pointer;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 4px 0;
}
.ludo-rules ul { margin: 6px 0 4px; padding-left: 18px; }
.ludo-rules li { margin: 4px 0; }
.ludo-rules b { color: var(--text); }

/* ----- responsive ----- */
@media (max-width: 760px) {
  .ludo-table { flex-direction: column; align-items: center; overflow: visible; }
  .ludo-board-area { width: min(96vw, 600px); min-width: 0; }
  .ludo-side { width: min(96vw, 600px); max-height: none; overflow: visible; }
  .ludo-players { display: grid; grid-template-columns: 1fr 1fr; }
  .ludo-player { font-size: 13px; padding: 8px; }
  .ludo-token { border-width: 1.5px; }
  .ludo-cell .start-mark { border-width: 1.5px; box-shadow: inset 0 0 0 1px var(--tint), inset 0 0 0 5px var(--tok); }
}
@media (max-width: 400px) {
  .ludo-dice { width: 64px; height: 64px; }
  .ludo-die .pip { width: 9px; height: 9px; }
  .ludo-status { font-size: 14px; }
}
