/* ============================================
   Tablo — Backgammon Styles
   ============================================ */

.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px 20px;
  gap: 16px;
}

.game-wrapper::before {
  content: '';
  display: block;
  height: 12px;
  flex-shrink: 0;
}

.bg-stats {
  display: flex;
  gap: 24px;
  padding: 16px 24px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 600px;
  margin: 0 auto;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 80px;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: #2dd4bf;
}

.bg-board {
  display: grid;
  grid-template-columns: 1fr 40px 1fr;
  grid-template-rows: 1fr auto 1fr;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 3 / 2;
  background: #5b3a1e;
  border: 4px solid #3d2814;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  position: relative;
}

/* Quadrant positioning */
#quadrant-tl { grid-column: 1; grid-row: 1; }
#bg-bar-top { grid-column: 2; grid-row: 1; }
#quadrant-tr { grid-column: 3; grid-row: 1; }

#quadrant-bl { grid-column: 1; grid-row: 3; }
#bg-bar-bottom { grid-column: 2; grid-row: 3; }
#quadrant-br { grid-column: 3; grid-row: 3; }

.bg-quadrant {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  background: #4a3018;
}

.bg-point {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: background 0.15s ease;
  overflow: visible;
}

.bg-point:hover {
  background: rgba(255, 255, 255, 0.08);
}

.bg-point.selectable {
  background: rgba(45, 212, 211, 0.2);
}

.bg-point.selected {
  background: rgba(45, 212, 211, 0.4);
  box-shadow: inset 0 0 0 2px #2dd4bf;
}

.bg-point.valid-move {
  background: rgba(34, 197, 94, 0.25);
  box-shadow: inset 0 0 0 2px #22c55e;
}

/* Triangle shapes — z-index: 0 instead of -1 */
.bg-point.triangle-up::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  z-index: 0;
}

.bg-point.triangle-down::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  clip-path: polygon(0 100%, 100% 100%, 50% 0);
  z-index: 0;
}

.bg-point.dark-pt::before { background: #3d2814; }
.bg-point.light-pt::before { background: #6b4a2e; }

/* Checkers */
.bg-checker {
  width: 70%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.3);
  z-index: 2;
  position: relative;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease;
}

.bg-checker.player1 {
  background: radial-gradient(circle at 35% 35%, #f0f0f0, #c8c8c8);
  border-color: #999;
}

.bg-checker.player2 {
  background: radial-gradient(circle at 35% 35%, #2a2a2a, #0a0a0a);
  border-color: #444;
}

.bg-checker.count-label {
  background: rgba(45, 212, 211, 0.8);
  color: #0f1923;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
}

/* Stacking: top quadrant stacks downward */
.bg-top-left .bg-point,
.bg-top-right .bg-point {
  justify-content: flex-start;
}

.bg-bottom-left .bg-point,
.bg-bottom-right .bg-point {
  justify-content: flex-end;
}

/* Bar */
.bg-bar {
  width: 40px;
  background: #2a1810;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-left: 2px solid #1a0e08;
  border-right: 2px solid #1a0e08;
}

.bg-bar-slots {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
}

.bg-bar-checker {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.3);
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.bg-bar-checker.player1 {
  background: radial-gradient(circle at 35% 35%, #f0f0f0, #c8c8c8);
}

.bg-bar-checker.player2 {
  background: radial-gradient(circle at 35% 35%, #2a2a2a, #0a0a0a);
}

.bg-bar-checker.selectable {
  box-shadow: 0 0 8px #2dd4bf;
}

.bg-bar-checker.selected {
  box-shadow: 0 0 12px #2dd4bf;
  border-color: #2dd4bf;
}

/* Center area */
.bg-center {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2a1810;
  padding: 8px;
}

.bg-dice-area {
  display: flex;
  gap: 8px;
  align-items: center;
}

.bg-die {
  width: 36px;
  height: 36px;
  background: #e2e8f0;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #1e293b;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.bg-die.used {
  opacity: 0.3;
}

.bg-die.rolling {
  animation: bg-die-roll 0.4s ease;
}

@keyframes bg-die-roll {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.3); }
  100% { transform: rotate(360deg) scale(1); }
}

/* Controls */
.bg-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.game-btn {
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
  padding: 10px 20px;
  border-radius: 8px;
  font-family: var(--font-primary, sans-serif);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s ease;
}

.game-btn:hover:not(:disabled) {
  background: #243044;
  border-color: #2dd4bf;
  color: #2dd4bf;
}

.game-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.game-btn.primary {
  background: #2dd4bf;
  border-color: #2dd4bf;
  color: #0f1923;
}

.game-btn.primary:hover:not(:disabled) {
  background: #5eead4;
}

.game-hint {
  font-size: 12px;
  color: #64748b;
  text-align: center;
  margin: 8px auto;
  max-width: 400px;
  line-height: 1.5;
}

.winner-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
}

.winner-modal.visible { display: flex; }

.winner-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
}

.winner-content {
  position: relative;
  background: #1e293b;
  border: 2px solid #2dd4bf;
  border-radius: 12px;
  padding: 32px 24px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.6);
}

.winner-icon { font-size: 48px; margin-bottom: 16px; }
.winner-title { font-size: 24px; font-weight: 700; margin-bottom: 12px; color: #e2e8f0; }
.winner-message { font-size: 16px; color: #94a3b8; margin-bottom: 24px; }
.winner-buttons { display: flex; gap: 12px; justify-content: center; }

.tablo-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 10001;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.tablo-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 580px) {
  .bg-board {
    max-width: 100%;
  }

  .bg-bar {
    width: 26px;
  }

  .bg-bar-checker {
    width: 16px;
    height: 16px;
  }

  .bg-die {
    width: 28px;
    height: 28px;
    font-size: 16px;
  }

  .bg-stats { gap: 12px; padding: 12px 16px; }
  .bg-controls .game-btn { padding: 8px 12px; font-size: 12px; }
}