/* Design Variables & Theme Tokens */
:root {
  --font-primary: 'Cairo', sans-serif;

  /* Dark Theme Palette (Default) */
  --bg-app: radial-gradient(circle at 50% 50%, #033c46 0%, #012a31 100%);
  --bg-card: rgba(1, 42, 49, 0.65);
  --border-card: 1px solid rgba(47, 247, 122, 0.15);
  --shadow-neon: 0 8px 32px 0 rgba(0, 0, 0, 0.5), 0 0 15px rgba(47, 247, 122, 0.2);

  --text-main: #f0f0ff;
  --text-muted: #a2cbd2;

  --color-primary: #2ff77a;
  /* Neon Green */
  --color-primary-glow: rgba(47, 247, 122, 0.4);
  --color-secondary: #2ff77a;
  /* Neon Green */
  --color-secondary-glow: rgba(47, 247, 122, 0.4);

  --color-triangle: #2ff77a;
  /* Neon Green */
  --color-circle: #00f0ff;
  /* Neon Cyan */
  --color-square: #aaff00;
  /* Neon Lime */

  --color-success: #2ff77a;
  --color-error: #ff1744;
  --color-warning: #ffea00;

  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme overrides */
[data-theme="light"] {
  --bg-app: linear-gradient(135deg, #eef2f3 0%, #8e9eab 100%);
  --bg-card: rgba(255, 255, 255, 0.85);
  --border-card: 1px solid rgba(0, 0, 0, 0.08);
  --shadow-neon: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
  --text-main: #1f1f2e;
  --text-muted: #5b5b70;
  --color-primary: #6200ea;
  --color-primary-glow: rgba(98, 0, 234, 0.2);
  --color-secondary: #00b0ff;
  --color-secondary-glow: rgba(0, 176, 255, 0.2);
}

/* Reset and Global Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

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

/* Particle Canvas Backdrop */
#particle-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
}

/* Main Container */
.app-container {
  width: 92%;
  max-width: 900px;
  min-height: 85vh;
  margin: 20px auto;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* Header Styles */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 25px;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 16px;
  border: var(--border-card);
  box-shadow: var(--shadow-neon);
  margin-bottom: 20px;
}

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

.logo-icon {
  font-size: 24px;
  color: var(--color-secondary);
  text-shadow: 0 0 10px var(--color-secondary-glow);
  animation: logo-float 3s ease-in-out infinite;
}

.logo h1 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(120deg, var(--text-main), var(--color-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.controls-top {
  display: flex;
  gap: 10px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 16px;
  transition: var(--transition-smooth);
}

.icon-btn:hover {
  background: var(--color-primary);
  box-shadow: 0 0 12px var(--color-primary-glow);
  transform: scale(1.1);
}

/* Main Content Area */
.main-content {
  flex-grow: 1;
  display: flex;
  align-items: stretch;
  margin-bottom: 20px;
}

/* Game Card (Translucent glass style) */
.game-card {
  width: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 24px;
  border: var(--border-card);
  box-shadow: var(--shadow-neon);
  padding: 30px;
  display: none;
  flex-direction: column;
  justify-content: space-between;
  animation: card-appear 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.game-card.active {
  display: flex;
}

/* Welcome Section */
.welcome-section {
  text-align: center;
  margin-bottom: 25px;
}

.welcome-section h2 {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 12px;
  color: var(--color-secondary);
}

.welcome-section p {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}

/* Mode Selection Grid */
.setup-group {
  margin-bottom: 25px;
}

.setup-group h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-main);
  border-right: 3px solid var(--color-primary);
  padding-right: 10px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 15px;
}

.mode-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  padding: 20px;
  cursor: pointer;
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: var(--transition-smooth);
}

.mode-icon {
  font-size: 28px;
  margin-bottom: 5px;
  transition: var(--transition-smooth);
}

.mode-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.mode-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.mode-card:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-3px);
}

.mode-card.active {
  background: linear-gradient(135deg, rgba(138, 43, 226, 0.2), rgba(0, 240, 255, 0.1));
  border-color: var(--color-primary);
  box-shadow: 0 0 15px rgba(138, 43, 226, 0.25);
}

.mode-card.active .mode-icon {
  transform: scale(1.2);
  text-shadow: 0 0 10px var(--color-primary-glow);
}

/* Difficulty Selector */
.difficulty-selector {
  display: flex;
  gap: 12px;
}

.diff-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  padding: 12px 15px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  transition: var(--transition-smooth);
}

.diff-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.diff-btn.active {
  background: var(--color-secondary);
  color: #080613;
  font-weight: 800;
  box-shadow: 0 0 12px var(--color-secondary-glow);
  border-color: var(--color-secondary);
}

/* Stats Overview */
.stats-overview {
  display: flex;
  gap: 20px;
  margin-bottom: 25px;
}

.stat-box {
  flex: 1;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

.stat-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--color-secondary);
}

/* Buttons */
.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 24px;
  font-family: var(--font-primary);
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: var(--transition-smooth);
}

.primary-btn {
  background: linear-gradient(135deg, var(--color-primary), #1ce066);
  color: #012a31;
  font-weight: 800;
  box-shadow: 0 4px 15px var(--color-primary-glow);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(47, 247, 122, 0.5);
}

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

.primary-btn.disabled,
.primary-btn:disabled {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  box-shadow: none;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.secondary-btn.disabled,
.secondary-btn:disabled {
  opacity: 0.3;
  pointer-events: none;
}

.btn-lg {
  padding: 16px 36px;
  font-size: 17px;
  border-radius: 16px;
}

/* -------------------------------------------------------------------------- */
/* GAME SCREEN STYLING                                                        */
/* -------------------------------------------------------------------------- */

/* Turn Indicator Bar */
.turn-indicator-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 16px;
  padding: 15px 25px;
  margin-bottom: 25px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  text-align: center;
  transition: var(--transition-smooth);
}

/* Turn glows */
.turn-indicator-bar.player1-turn {
  border-color: rgba(47, 247, 122, 0.35);
  box-shadow: 0 0 15px rgba(47, 247, 122, 0.2);
}

.turn-indicator-bar.player2-turn {
  border-color: rgba(0, 240, 255, 0.35);
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.2);
}

.turn-indicator-bar.ai-turn {
  border-color: rgba(170, 255, 0, 0.35);
  box-shadow: 0 0 15px rgba(170, 255, 0, 0.2);
}

.turn-status {
  display: flex;
  align-items: center;
  gap: 10px;
}

.turn-icon {
  font-size: 22px;
  animation: logo-float 2s ease-in-out infinite;
}

#current-turn-text {
  font-size: 20px;
  font-weight: 800;
}

.turn-rules {
  font-size: 12px;
  color: var(--text-muted);
}

/* Nim Board */
.nim-board-container {
  flex-grow: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 280px;
  margin-bottom: 25px;
}

.nim-board {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 650px;
}

.nim-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: transparent;
  border: none;
  padding: 10px 0;
  transition: var(--transition-smooth);
  position: relative;
}

.nim-row.faded {
  opacity: 0.25;
  pointer-events: none;
  filter: blur(1px);
}

.nim-row.active-row {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 16px;
  padding: 10px 15px;
}

.row-shapes-container {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
  min-height: 70px;
}

/* Nim Shape */
.nim-shape {
  width: 60px;
  height: 60px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.2s;
  animation: shape-pop-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.nim-shape svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
  transition: filter 0.2s;
}

/* Glowing effects for shapes */
.nim-shape[data-type="triangle"] svg {
  filter: drop-shadow(0 0 6px var(--color-triangle));
}

.nim-shape[data-type="circle"] svg {
  filter: drop-shadow(0 0 6px var(--color-circle));
}

.nim-shape[data-type="square"] svg {
  filter: drop-shadow(0 0 6px var(--color-square));
}

.nim-shape:hover {
  transform: scale(1.2);
}

.nim-shape:active {
  transform: scale(0.9);
}

/* Fade out on remove (instant removal) */
.nim-shape.removed {
  pointer-events: none;
  opacity: 0 !important;
  transform: scale(0) !important;
  transition: none !important;
  animation: none !important;
}

/* Actions */
.turn-actions {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 20px;
}

.game-footer-controls {
  text-align: center;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 15px;
}

/* -------------------------------------------------------------------------- */
/* GAMEOVER SCREEN STYLING                                                    */
/* -------------------------------------------------------------------------- */
.gameover-header {
  text-align: center;
  margin-bottom: 25px;
}

.trophy-badge {
  font-size: 55px;
  margin-bottom: 15px;
  animation: logo-float 3s ease-in-out infinite;
}

#gameover-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--color-secondary);
  margin-bottom: 8px;
}

#gameover-subtitle {
  color: var(--text-muted);
  font-size: 14px;
}

.gameover-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
  margin-bottom: 30px;
}

.gameover-stat-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 16px;
  padding: 15px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.g-label {
  font-size: 12px;
  color: var(--text-muted);
}

.g-val {
  font-size: 20px;
  font-weight: 800;
  color: var(--color-secondary);
}

.gameover-actions {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.app-footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 10px 0;
  z-index: 1;
}

/* -------------------------------------------------------------------------- */
/* ANIMATIONS                                                                 */
/* -------------------------------------------------------------------------- */
@keyframes logo-float {
  0% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-6px);
  }

  100% {
    transform: translateY(0);
  }
}

@keyframes card-appear {
  0% {
    opacity: 0;
    transform: translateY(20px) scale(0.97);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes shape-pop-in {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }

  70% {
    transform: scale(1.1);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Wrong match flash */
.wrong-flash {
  animation: flash-red 0.4s ease-out;
}

@keyframes flash-red {
  0% {
    border-color: rgba(255, 23, 68, 0.5);
    box-shadow: 0 0 20px rgba(255, 23, 68, 0.4);
  }

  100% {
    border-color: var(--border-card);
    box-shadow: var(--shadow-neon);
  }
}

@keyframes pulse-border {
  0% {
    border-color: rgba(0, 240, 255, 0.2);
  }

  100% {
    border-color: rgba(138, 43, 226, 0.4);
  }
}

/* Responsive adjustments */
@media (max-width: 600px) {
  .app-container {
    margin: 10px auto;
    min-height: 95vh;
  }

  .game-card {
    padding: 20px;
  }

  .welcome-section h2 {
    font-size: 20px;
  }

  .mode-grid {
    grid-template-columns: 1fr;
  }

  .difficulty-selector {
    flex-direction: column;
  }

  .nim-shape {
    width: 48px;
    height: 48px;
  }

  .gameover-stats-grid {
    grid-template-columns: 1fr;
  }

  .gameover-actions,
  .turn-actions {
    flex-direction: column;
    width: 100%;
  }

  .gameover-actions .btn,
  .turn-actions .btn {
    width: 100%;
  }
}