/* ==========================================================================
   MANCALA ELITE - STYLE DEFINITIONS & DESIGN SYSTEM
   ========================================================================== */

/* --- Modern Theme Tokens --- */
:root {
  /* Dark Theme Variables (Default) */
  --bg-color-1: #0b0f19;
  --bg-color-2: #1e2640;
  --bg-gradient: linear-gradient(135deg, var(--bg-color-1), var(--bg-color-2));
  
  --board-bg: rgba(30, 41, 59, 0.45);
  --board-border: rgba(255, 255, 255, 0.08);
  --board-highlight: rgba(99, 102, 241, 0.2);
  --board-glow: 0 25px 60px -15px rgba(0, 0, 0, 0.6);
  
  --pit-bg: rgba(15, 23, 42, 0.65);
  --pit-border: rgba(255, 255, 255, 0.05);
  --pit-inner-shadow: inset 0 8px 16px rgba(0, 0, 0, 0.6), inset 0 1px 3px rgba(0, 0, 0, 0.4);
  
  --player-glow: 0 0 20px rgba(99, 102, 241, 0.45);
  --ai-glow: 0 0 20px rgba(244, 63, 94, 0.45);
  
  --pit-playable-hover: rgba(99, 102, 241, 0.12);
  --pit-playable-border: rgba(99, 102, 241, 0.4);
  --pit-playable-glow: 0 0 15px rgba(99, 102, 241, 0.25);
  
  /* Stone Materials (3D Glossy Gradients) */
  --stone-blue-1: #60a5fa;
  --stone-blue-2: #1d4ed8;
  --stone-red-1: #f87171;
  --stone-red-2: #b91c1c;
  --stone-neutral-1: #34d399;
  --stone-neutral-2: #047857;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-accent: #6366f1;
  --badge-bg: rgba(99, 102, 241, 0.15);
  
  /* Interface UI Glassmorphism */
  --card-bg: rgba(30, 41, 59, 0.35);
  --card-border: rgba(255, 255, 255, 0.06);
  
  /* Global Constants */
  --font-family-title: 'Outfit', 'Inter', sans-serif;
  --font-family-body: 'Inter', sans-serif;
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Light Theme Variables */
[data-theme="light"] {
  --bg-color-1: #e2e8f0;
  --bg-color-2: #cbd5e1;
  --bg-gradient: linear-gradient(135deg, #f8fafc, #cbd5e1);
  
  --board-bg: rgba(255, 255, 255, 0.7);
  --board-border: rgba(0, 0, 0, 0.08);
  --board-highlight: rgba(99, 102, 241, 0.1);
  --board-glow: 0 25px 60px -15px rgba(15, 23, 42, 0.15);
  
  --pit-bg: rgba(203, 213, 225, 0.6);
  --pit-border: rgba(0, 0, 0, 0.06);
  --pit-inner-shadow: inset 0 6px 12px rgba(0, 0, 0, 0.18), inset 0 1px 2px rgba(0, 0, 0, 0.1);
  
  --player-glow: 0 0 20px rgba(99, 102, 241, 0.3);
  --ai-glow: 0 0 20px rgba(244, 63, 94, 0.3);
  
  --pit-playable-hover: rgba(99, 102, 241, 0.08);
  --pit-playable-border: rgba(99, 102, 241, 0.5);
  --pit-playable-glow: 0 0 12px rgba(99, 102, 241, 0.2);
  
  --stone-blue-1: #3b82f6;
  --stone-blue-2: #1e3a8a;
  --stone-red-1: #ef4444;
  --stone-red-2: #7f1d1d;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-accent: #4f46e5;
  --badge-bg: rgba(99, 102, 241, 0.08);
  
  --card-bg: rgba(255, 255, 255, 0.45);
  --card-border: rgba(0, 0, 0, 0.06);
}

/* --- Reset & Base Layout --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: var(--font-family-body);
  color: var(--text-primary);
  background: var(--bg-gradient);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  position: relative;
  transition: background 0.5s ease;
}

/* --- Decorative Ambient Glows --- */
.ambient-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  z-index: 0;
  pointer-events: none;
  opacity: 0.35;
  transition: var(--transition-smooth);
}

.glow-1 {
  width: 400px;
  height: 400px;
  background: #6366f1;
  top: -100px;
  left: -100px;
}

.glow-2 {
  width: 500px;
  height: 500px;
  background: #f43f5e;
  bottom: -150px;
  right: -100px;
}

[data-theme="light"] .ambient-glow {
  opacity: 0.15;
}

/* --- General Utilities --- */
.hidden {
  display: none !important;
}

/* --- Buttons & UI Elements --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-family: var(--font-family-title);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition-bounce);
  white-space: nowrap;
}

.btn svg {
  width: 18px;
  height: 18px;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.45);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--card-bg);
  border-color: var(--card-border);
  color: var(--text-primary);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--text-accent);
  transform: translateY(-2px);
}

.btn-large {
  padding: 14px 28px;
  font-size: 1.1rem;
  border-radius: 16px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition-bounce);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--text-accent);
  color: var(--text-accent);
  transform: scale(1.08);
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* Badge style */
.badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 30px;
  background: var(--badge-bg);
  color: var(--text-accent);
  border: 1px solid rgba(99, 102, 241, 0.2);
}

/* --- Container Core --- */
.game-container {
  width: 100%;
  max-width: 1100px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  z-index: 10;
}

/* --- Header Area --- */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-area h1 {
  font-family: var(--font-family-title);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.logo-area h1 span {
  background: linear-gradient(135deg, #6366f1, #f43f5e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-left: 2px;
}

.control-buttons {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* --- Scoreboard & Dashboard --- */
.game-dashboard {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.player-card {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-radius: 18px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: var(--transition-bounce);
}

.player-card.active-turn {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.35);
  box-shadow: var(--player-glow);
}

#ai-card.active-turn {
  background: rgba(244, 63, 94, 0.08);
  border-color: rgba(244, 63, 94, 0.35);
  box-shadow: var(--ai-glow);
}

.player-avatar {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-family-title);
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.user-avatar {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
}

.ai-avatar {
  background: linear-gradient(135deg, #f43f5e, #e11d48);
}

.player-info {
  flex: 1;
}

.player-info h3 {
  font-family: var(--font-family-title);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.player-info.align-right {
  text-align: right;
}

.role-desc {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.player-score {
  font-family: var(--font-family-title);
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* Status Panel */
.status-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-width: 220px;
}

.status-message {
  font-family: var(--font-family-title);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
  animation: pulse 2.5s infinite;
}

.status-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* --- The Mancala Board Style --- */
.board-area {
  position: relative;
  width: 100%;
}

.board-outer {
  position: relative;
  background: var(--board-bg);
  border: 1px solid var(--board-border);
  border-radius: 36px;
  padding: 24px;
  box-shadow: var(--board-glow);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition: border-color 0.5s ease;
}

.board-wood {
  display: grid;
  grid-template-columns: 140px 1fr 140px;
  gap: 20px;
  align-items: stretch;
}

/* Store Containers */
.store-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 28px;
  padding: 16px 12px;
  min-height: 320px;
}

.store-label {
  font-family: var(--font-family-title);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.1em;
  opacity: 0.6;
}

.store-counter {
  font-family: var(--font-family-title);
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text-primary);
}

/* Pits Grid Container (Center layout) */
.pits-grid-container {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 20px;
}

.pits-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
}

/* Pit wrapper holds the elements vertically */
.pit-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
}

.pit-tag {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  opacity: 0.5;
}

.pit-counter {
  font-family: var(--font-family-title);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-secondary);
  transition: var(--transition-smooth);
}

.pit-wrapper:hover .pit-counter {
  color: var(--text-primary);
}

/* Pit Cup Style */
.pit {
  width: 100%;
  aspect-ratio: 1;
  background: var(--pit-bg);
  border: 1px solid var(--pit-border);
  border-radius: 50%;
  position: relative;
  box-shadow: var(--pit-inner-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  transition: var(--transition-bounce);
  overflow: visible; /* Allows stones to overflow slightly rather than clipping */
}

/* Store Pit is elongated */
.store {
  width: 90px;
  height: 200px;
  border-radius: 45px;
  aspect-ratio: auto;
}

/* Playable Pit States */
.pit-player.playable {
  cursor: pointer;
  border-color: rgba(255, 255, 255, 0.1);
}

.pit-player.playable:hover {
  background: var(--pit-playable-hover);
  border-color: var(--pit-playable-border);
  box-shadow: var(--pit-inner-shadow), var(--pit-playable-glow);
  transform: scale(1.04) translateY(-2px);
}

.pit-player.playable:active {
  transform: scale(0.96);
}

/* Highlighting Active Sowing Targets */
.pit.highlight-sow {
  animation: flash-border 0.4s ease;
}

/* --- Organic Stone Rendering --- */
.stones-grid {
  position: absolute;
  width: 80%;
  height: 80%;
  top: 10%;
  left: 10%;
  pointer-events: none;
}

.stone {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: inset -2px -2px 5px rgba(0, 0, 0, 0.45), 0 3px 5px rgba(0, 0, 0, 0.35);
  transition: var(--transition-bounce);
}

/* Glossy highlight overlay on stones */
.stone::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  pointer-events: none;
}

/* Stone Color variations */
.stone-blue {
  background: radial-gradient(circle at 35% 35%, var(--stone-blue-1), var(--stone-blue-2));
}

.stone-red {
  background: radial-gradient(circle at 35% 35%, var(--stone-red-1), var(--stone-red-2));
}

.stone-neutral {
  background: radial-gradient(circle at 35% 35%, var(--stone-neutral-1), var(--stone-neutral-2));
}

/* Sowing animations */
.stone.flying {
  z-index: 1000 !important;
  transition: left 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94), top 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* --- Footer Area --- */
.game-footer {
  margin-top: 10px;
  display: flex;
  justify-content: center;
}

.rules-hint {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  padding: 12px 20px;
  border-radius: 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-width: 750px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  line-height: 1.4;
}

.rules-hint svg {
  width: 20px;
  height: 20px;
  color: var(--text-accent);
  flex-shrink: 0;
}

.rules-hint strong {
  color: var(--text-primary);
}

/* --- Full Screen Modal Overlays --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(11, 15, 25, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  transition: opacity 0.3s ease;
}

.modal-content {
  background: var(--board-bg);
  border: 1px solid var(--board-border);
  border-radius: 28px;
  padding: 40px;
  width: 100%;
  max-width: 480px;
  text-align: center;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.winner-trophy {
  width: 80px;
  height: 80px;
  background: rgba(251, 191, 36, 0.1);
  color: #fbbf24;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(251, 191, 36, 0.2);
  margin-bottom: 8px;
  animation: float 3s ease-in-out infinite;
}

.winner-trophy svg {
  width: 44px;
  height: 44px;
}

.modal-content h2 {
  font-family: var(--font-family-title);
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
}

.modal-content p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

.modal-scoreboard {
  width: 100%;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 10px 0;
}

.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px;
}

.score-row .name {
  font-weight: 600;
  font-size: 0.95rem;
}

.score-row .score {
  font-family: var(--font-family-title);
  font-size: 1.6rem;
  font-weight: 800;
}

.score-player-row {
  color: #60a5fa;
}

.score-ai-row {
  color: #f87171;
}

/* Trajectory Animation Overlay */
.animation-container-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

/* --- Orientation Overlay for Mobile Landscape Recommendation --- */
.orientation-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #0f172a;
  z-index: 10000;
  display: none; /* Checked via JS/CSS */
  justify-content: center;
  align-items: center;
  padding: 30px;
  text-align: center;
}

.phone-rotate-icon {
  width: 80px;
  height: 80px;
  color: var(--text-accent);
  margin-bottom: 24px;
  animation: rotate-phone 2s infinite ease-in-out;
}

.phone-rotate-icon svg {
  width: 100%;
  height: 100%;
}

.overlay-content h2 {
  font-family: var(--font-family-title);
  font-size: 1.8rem;
  margin-bottom: 12px;
  color: #fff;
}

.overlay-content p {
  color: #94a3b8;
  max-width: 320px;
  line-height: 1.5;
  font-size: 0.95rem;
}

/* --- Keyframes & Micro-Animations --- */
@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.02);
    opacity: 0.85;
  }
}

@keyframes flash-border {
  0% {
    box-shadow: var(--pit-inner-shadow), 0 0 0 rgba(99, 102, 241, 0);
    border-color: var(--pit-border);
  }
  50% {
    box-shadow: var(--pit-inner-shadow), 0 0 25px rgba(99, 102, 241, 0.7);
    border-color: rgba(99, 102, 241, 0.9);
  }
  100% {
    box-shadow: var(--pit-inner-shadow), 0 0 0 rgba(99, 102, 241, 0);
    border-color: var(--pit-border);
  }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

@keyframes rotate-phone {
  0% {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(-90deg);
  }
  100% {
    transform: rotate(0deg);
  }
}

.animate-pop {
  animation: pop-in 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes pop-in {
  0% {
    transform: scale(0.7);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* --- MOBILE RESPONSIVE OVERRIDES --- */

/* Portrait Mobile check - Display rotation warning */
@media (max-width: 899px) and (orientation: portrait) {
  .orientation-overlay {
    display: flex;
  }
  .game-container {
    display: none;
  }
}

/* Landscape / General Responsive Scaling */
@media (max-width: 1024px) {
  .game-container {
    padding: 16px;
    gap: 14px;
  }
  
  .logo-area h1 {
    font-size: 1.6rem;
  }
  
  .board-outer {
    padding: 16px;
    border-radius: 28px;
  }
  
  .board-wood {
    grid-template-columns: 100px 1fr 100px;
    gap: 12px;
  }
  
  .store-container {
    padding: 12px 6px;
    min-height: 260px;
    border-radius: 20px;
  }
  
  .store {
    width: 70px;
    height: 180px;
    border-radius: 35px;
  }
  
  .pits-grid-container {
    gap: 12px;
  }
  
  .pits-row {
    gap: 8px;
  }
  
  .pit-wrapper {
    gap: 4px;
  }
  
  .pit-counter {
    font-size: 0.95rem;
  }
  
  .stone {
    width: 10px;
    height: 10px;
  }
}

/* Small screen Landscape details (phones) */
@media (max-height: 600px) and (orientation: landscape) {
  body {
    align-items: flex-start;
    padding: 10px 0;
  }
  
  .game-container {
    gap: 8px;
    max-width: 95vw;
  }
  
  .game-header {
    height: auto;
  }
  
  .logo-area h1 {
    font-size: 1.3rem;
  }
  
  .badge {
    padding: 2px 6px;
    font-size: 0.65rem;
  }
  
  .icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
  }
  
  .icon-btn svg {
    width: 16px;
    height: 16px;
  }
  
  .btn {
    padding: 6px 14px;
    font-size: 0.8rem;
    border-radius: 8px;
  }
  
  .game-dashboard {
    gap: 10px;
  }
  
  .player-card {
    padding: 8px 12px;
    border-radius: 12px;
    gap: 8px;
  }
  
  .player-avatar {
    width: 32px;
    height: 32px;
    font-size: 0.85rem;
    border-radius: 8px;
  }
  
  .player-info h3 {
    font-size: 0.85rem;
  }
  
  .role-desc {
    font-size: 0.65rem;
  }
  
  .player-score {
    font-size: 1.5rem;
  }
  
  .status-panel {
    min-width: 140px;
  }
  
  .status-message {
    font-size: 0.95rem;
    margin-bottom: 0;
  }
  
  .status-sub {
    font-size: 0.7rem;
  }
  
  .board-outer {
    padding: 10px;
    border-radius: 20px;
  }
  
  .board-wood {
    grid-template-columns: 70px 1fr 70px;
    gap: 8px;
  }
  
  .store-container {
    padding: 6px 2px;
    min-height: 160px;
    border-radius: 14px;
  }
  
  .store-label {
    font-size: 0.55rem;
  }
  
  .store-counter {
    font-size: 1.4rem;
  }
  
  .store {
    width: 50px;
    height: 120px;
    border-radius: 25px;
  }
  
  .pits-grid-container {
    gap: 8px;
  }
  
  .pits-row {
    gap: 6px;
  }
  
  .pit-tag {
    font-size: 0.55rem;
  }
  
  .pit-counter {
    font-size: 0.8rem;
  }
  
  .stone {
    width: 8px;
    height: 8px;
  }
  
  .game-footer {
    display: none; /* Hide rules hint on small height landscape to maximize board size */
  }
}
