/* ==========================================================================
   PEXESO MEMORY MATCH GAME - VIBRANT PALETTE STYLESHEET
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS VARIABLES & THEMING (Vibrant Palette)
   -------------------------------------------------------------------------- */
:root {
  --bg-color: #FFFAEC;
  --surface-color: #ffffff;
  --surface-card: #ffffff;
  --text-main: #1F2937;
  --text-muted: #6B7280;
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-light: #EEF2FF;
  --secondary: #F59E0B;
  --accent: #10B981;
  --danger: #EF4444;
  --success: #10B981;
  --success-light: #D1FAE5;
  --warning: #F59E0B;
  --border-color: #E5E7EB;
  --shadow-sm: 0 4px 6px -1px rgba(0,0,0,0.05);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.12);
  --shadow-card: 0 8px 16px -4px rgba(0, 0, 0, 0.12);

  /* Card Back Gradient */
  --card-back-from: #3B82F6;
  --card-back-to: #1D4ED8;
  --card-back-pattern: rgba(255, 255, 255, 0.2);

  /* Animation speed */
  --flip-duration: 0.6s;
  
  /* Grid configuration */
  --cols: 4;
  --rows: 3;
  --max-board-width: 820px;
}

[data-theme="dark"] {
  --bg-color: #0f172a;
  --surface-color: #1e293b;
  --surface-card: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #312e81;
  --secondary: #fbbf24;
  --accent: #22d3ee;
  --success: #10b981;
  --success-light: #064e3b;
  --warning: #fbbf24;
  --border-color: #334155;
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 8px 16px -4px rgba(0, 0, 0, 0.4);

  --card-back-from: #1e40af;
  --card-back-to: #0f172a;
  --card-back-pattern: rgba(255, 255, 255, 0.1);
}

/* --------------------------------------------------------------------------
   2. RESET & BASE STYLES
   -------------------------------------------------------------------------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
  user-select: none;
}

button, select, input {
  font-family: inherit;
  font-size: 1rem;
}

button {
  cursor: pointer;
  border: none;
  outline: none;
  background: none;
  transition: all 0.2s ease;
}

button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   3. APP CONTAINER & HEADER
   -------------------------------------------------------------------------- */
.app-container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background-color: var(--surface-color);
  border-radius: 20px;
  box-shadow: var(--shadow-sm);
  border-bottom: 4px solid var(--border-color);
  border-top: 1px solid var(--border-color);
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  margin-bottom: 1rem;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  font-size: 1.75rem;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

.brand-title h1 {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--primary);
  letter-spacing: -0.03em;
  text-transform: uppercase;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-wrap: wrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background-color: var(--bg-color);
  color: var(--text-main);
  border: 2px solid var(--border-color);
  font-size: 1.2rem;
  font-weight: 700;
}

.icon-btn:hover {
  background-color: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  background-color: var(--primary);
  color: white;
  font-weight: 800;
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(79, 70, 229, 0.4);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  background-color: var(--bg-color);
  color: var(--text-main);
  font-weight: 700;
  border-radius: 12px;
  border: 2px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* --------------------------------------------------------------------------
   4. SCOREBOARD & HUD
   -------------------------------------------------------------------------- */
.hud-panel {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  margin-bottom: 1.25rem;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1.25rem;
  align-items: center;
}

.player-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 1rem 1.25rem;
  background-color: var(--surface-color);
  border-radius: 24px;
  border: 4px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.player-card.active {
  border-color: var(--secondary);
  background-color: #FFFBEB;
  box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.25);
}

[data-theme="dark"] .player-card.active {
  background-color: #1e293b;
  border-color: var(--secondary);
  box-shadow: 0 0 0 6px rgba(251, 191, 36, 0.25);
}

/* Active Turn Badge */
.turn-badge {
  display: none;
  position: absolute;
  top: -14px;
  left: 20px;
  background: var(--secondary);
  color: white;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  box-shadow: 0 2px 4px rgba(245, 158, 11, 0.4);
}

.player-card.active .turn-badge {
  display: block;
}

.player-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 800;
  flex-shrink: 0;
  border: 3px solid var(--border-color);
}

.player-avatar.robot {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #92400e;
  border-color: var(--secondary);
}

.player-details {
  display: flex;
  flex-direction: column;
}

.player-name {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text-main);
  line-height: 1.2;
}

.player-score {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

.player-score strong {
  color: var(--primary);
  font-size: 1.2rem;
  font-weight: 900;
}

.game-stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  align-items: center;
  background-color: #1F2937;
  color: white;
  padding: 0.75rem 1rem;
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.25rem 0.5rem;
  border-right: 1px solid rgba(255, 255, 255, 0.15);
}

.stat-item:last-child {
  border-right: none;
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9CA3AF;
  font-weight: 800;
  white-space: nowrap;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 900;
  color: #FFFFFF;
  white-space: nowrap;
}

/* Category Badge (Centered Below HUD Stats Bar) */
.category-badge-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0.625rem 0 0.875rem 0;
  width: 100%;
}

.category-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem;
  background-color: var(--surface-color);
  border: 2px solid var(--border-color);
  border-radius: 9999px;
  box-shadow: var(--shadow-sm);
  text-align: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.category-badge:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.15);
}

.category-icon-emoji {
  font-size: 1.25rem;
  line-height: 1;
}

.category-label-text {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
}

.category-name-text {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary);
}

/* Robot Speech Bubble */
.robot-speech-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
}

.speech-bubble {
  position: relative;
  background: var(--surface-color);
  color: var(--text-main);
  border: 2px solid var(--border-color);
  padding: 0.4rem 1.2rem;
  border-radius: 16px;
  font-size: 0.875rem;
  font-weight: 700;
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 8px 8px 0;
  border-style: solid;
  border-color: var(--border-color) transparent;
  display: block;
  width: 0;
}

/* Turn Transition Banner */
.turn-banner {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: #1F2937;
  color: white;
  padding: 1rem 2.5rem;
  border-radius: 50px;
  font-size: 1.5rem;
  font-weight: 900;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  border: 3px solid var(--secondary);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.turn-banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* --------------------------------------------------------------------------
   5. MEMORY GRID BOARD & CARDS
   -------------------------------------------------------------------------- */
.game-board-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0;
  width: 100%;
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 1rem;
  width: 100%;
  max-width: var(--max-board-width);
  margin: 0 auto;
  perspective: 1000px;
}

.card {
  aspect-ratio: 1 / 1;
  position: relative;
  cursor: pointer;
  perspective: 1000px;
  border-radius: 16px;
  touch-action: manipulation;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.08));
  z-index: 1;
}

.card:hover,
.card:focus-visible,
.card.flipped,
.card.matched {
  z-index: 10;
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform var(--flip-duration) cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 16px;
}

.card.flipped .card-inner,
.card.matched .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 4px solid white;
}

[data-theme="dark"] .card-face {
  border-color: #334155;
}

/* CARD BACK DESIGN */
.card-back {
  background: var(--card-back-from);
  background: linear-gradient(135deg, var(--card-back-from) 0%, var(--card-back-to) 100%);
  color: white;
  transform: rotateY(0deg);
}

.card-back::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px dashed var(--card-back-pattern);
  border-radius: 10px;
  pointer-events: none;
}

.card-back-question {
  font-size: 2.5rem;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.4);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.card:hover:not(.flipped):not(.matched) .card-back-question {
  transform: scale(1.18) rotate(5deg);
  color: rgba(255, 255, 255, 0.9);
}

.card:hover:not(.flipped):not(.matched) .card-inner {
  transform: translateY(-3px);
}

/* CARD FRONT DESIGN */
.card-front {
  background-color: var(--surface-card);
  color: var(--text-main);
  transform: rotateY(180deg);
  padding: 0.5rem;
  justify-content: space-between;
}

.image-wrapper {
  width: 100%;
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 10px;
  background-color: #F3F4F6;
}

[data-theme="dark"] .image-wrapper {
  background-color: rgba(15, 23, 42, 0.5);
}

.card-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.card-img.loaded {
  opacity: 1;
}

.img-spinner {
  position: absolute;
  width: 24px;
  height: 24px;
  border: 3px solid rgba(79, 70, 229, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.img-fallback-icon {
  font-size: 2rem;
  color: var(--text-muted);
}

.card-word {
  font-size: 0.85rem;
  font-weight: 800;
  text-align: center;
  line-height: 1.1;
  margin-top: 0.3rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  padding: 0 0.2rem;
  color: var(--text-main);
  text-transform: capitalize;
}

/* MATCHED CARD STATE */
.card.matched {
  cursor: default;
}

.card.matched .card-face.card-front {
  border: 4px solid var(--accent);
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

.card.matched::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--accent);
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 900;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.card.matched.celebrate .card-inner {
  animation: cardMatchPulse 1s ease-in-out;
}

@keyframes cardMatchPulse {
  0% { transform: rotateY(180deg) scale(1); }
  30% { transform: rotateY(180deg) scale(1.12); box-shadow: 0 0 25px rgba(16, 185, 129, 0.7); }
  60% { transform: rotateY(180deg) scale(0.98); }
  100% { transform: rotateY(180deg) scale(1); }
}

/* Floating "+1 Pair" Badge Animation */
.floating-match-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(135deg, #10B981, #059669);
  color: white;
  font-weight: 900;
  font-size: 1.1rem;
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
  pointer-events: none;
  z-index: 100;
  animation: floatUp 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(0.5); }
  30% { opacity: 1; transform: translate(-50%, -60%) scale(1.2); }
  80% { opacity: 1; transform: translate(-50%, -100%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -130%) scale(0.8); }
}

/* --------------------------------------------------------------------------
   6. MODALS & SETUP CONTROLS
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(31, 41, 55, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background-color: var(--surface-color);
  border-radius: 24px;
  padding: 2rem;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  border: 4px solid var(--border-color);
  transform: translateY(20px) scale(0.95);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-overlay.active .modal-card {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.modal-header h2 {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--primary);
  text-transform: uppercase;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-weight: 800;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}

.form-select, .form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 2px solid var(--border-color);
  background-color: var(--bg-color);
  color: var(--text-main);
  outline: none;
  font-weight: 600;
  transition: border-color 0.2s ease;
}

.form-select:focus, .form-input:focus {
  border-color: var(--primary);
}

/* Victory Dialog Styling */
.victory-card {
  text-align: center;
}

.victory-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: bounce 1s infinite alternate;
}

.victory-title {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.victory-subtitle {
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 1.5rem;
}

.victory-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  background-color: #1F2937;
  color: white;
  padding: 1.25rem;
  border-radius: 18px;
  margin-bottom: 1.5rem;
}

.victory-stats-grid .stat-label {
  color: #9CA3AF;
}

.victory-stats-grid .stat-value {
  color: white;
}

/* --------------------------------------------------------------------------
   7. CONFETTI CANVAS / OVERLAY
   -------------------------------------------------------------------------- */
#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 2500;
}

/* --------------------------------------------------------------------------
   8. ANIMATION KEYFRAMES
   -------------------------------------------------------------------------- */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-12px); }
}

/* --------------------------------------------------------------------------
   9. RESPONSIVE MEDIA QUERIES
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
  }

  .header-controls {
    justify-content: space-between;
  }

  .scoreboard {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .player-card {
    padding: 0.75rem 0.875rem;
  }

  .player-avatar {
    width: 38px;
    height: 38px;
    font-size: 1.1rem;
  }

  .memory-grid {
    gap: 0.625rem;
  }

  .card-word {
    font-size: 0.75rem;
  }

  .card-back-question {
    font-size: 1.8rem;
  }

  .game-stats-bar {
    padding: 0.75rem 1rem;
  }
}

@media (max-width: 480px) {
  .memory-grid {
    gap: 0.4rem;
  }

  .card-face {
    padding: 0.25rem;
    border-width: 2px;
  }

  .card-word {
    font-size: 0.65rem;
  }
}

