/* Memory Match Game Styles */

.memory-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-8);
  padding: var(--space-6);
  max-width: 1400px;
  margin: 0 auto;
}

.grid-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.grid-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  text-align: center;
  margin: 0;
  padding: var(--space-3);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: var(--space-3);
  height: 100%;
  min-height: min(32vh, 280px);
}

.card {
  position: relative;
  cursor: pointer;
  perspective: 1000px;
  aspect-ratio: 1;
  transition: transform 0.2s, opacity 0.2s;
}

.card:hover:not(.matched) {
  transform: scale(1.05);
}

.card:active:not(.matched) {
  transform: scale(0.95);
}

.card.matched {
  opacity: 1 !important;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}

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

.card-front,
.card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
  font-weight: 600;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-3);
  word-wrap: break-word;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.card-back {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: white;
  font-size: var(--text-3xl);
}

.answer-card .card-back {
  background: linear-gradient(135deg, #ec407a, #d81b60);
}

.card-front {
  background: var(--color-surface);
  color: var(--color-text);
  transform: rotateY(180deg);
  border: 2px solid var(--color-border);
}

.problem-card .card-front {
  background: linear-gradient(135deg, #e3f2fd, #bbdefb);
  border-color: var(--color-primary);
}

.answer-card .card-front {
  background: linear-gradient(135deg, #fce4ec, #f8bbd0);
  border-color: #e91e63;
}

.card.selected .card-front {
  background: linear-gradient(135deg, #fff3e0, #ffe0b2);
  border-color: var(--color-accent);
  border-width: 3px;
  box-shadow: 0 0 20px rgba(255, 152, 0, 0.5);
}

.card.matched .card-front {
  background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
  border-color: var(--color-success);
  border-width: 3px;
  animation: matchPulse 0.5s ease-in-out;
}

@keyframes matchPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

.card.matched::after {
  content: '✓';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: var(--color-success);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: bold;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.card-question {
  font-size: var(--text-sm);
  font-weight: 400;
  opacity: 0.7;
  margin-bottom: var(--space-1);
}

.card-answer {
  font-size: var(--text-xl);
  font-weight: 600;
}

/* Error Overlay */
.error-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: pointer;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.error-message {
  background: rgba(220, 38, 38, 0.2);
  color: white;
  padding: var(--space-8);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  text-align: center;
  animation: errorPop 0.3s ease-out;
  backdrop-filter: blur(2px);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

@keyframes errorPop {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.error-icon {
  font-size: 64px;
  margin-bottom: var(--space-4);
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-10px);
  }
  75% {
    transform: translateX(10px);
  }
}

.error-text {
  font-size: var(--text-3xl);
  font-weight: bold;
  margin-bottom: var(--space-3);
}

.error-hint {
  font-size: var(--text-base);
  opacity: 0.9;
  font-weight: normal;
}

/* Legacy Feedback Animation (kept for compatibility) */
.feedback-animation {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: var(--text-3xl);
  font-weight: bold;
  padding: var(--space-6);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  animation: feedbackPop 1s ease-out forwards;
  pointer-events: none;
}

.feedback-animation.wrong {
  background: var(--color-error);
  color: white;
}

@keyframes feedbackPop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
  }
  80% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }
}

/* Stats Display */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-6);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
  gap: var(--space-4);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex: 1;
}

.header-right {
  display: flex;
  gap: var(--space-6);
  align-items: center;
}

.header-controls {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.stat-label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: 500;
}

.stat-value {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-primary);
}

#timer.warning {
  color: var(--color-error);
  animation: timerPulse 1s infinite;
}

@keyframes timerPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

/* Results Screen */
.results-screen {
  padding: var(--space-6);
  max-width: 800px;
  margin: 0 auto;
}

.results-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.results-card {
  background: var(--color-surface);
  padding: var(--space-8);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.results-card.success {
  border: 3px solid var(--color-success);
}

.results-card.timeout {
  border: 3px solid var(--color-warning);
}

.result-icon {
  font-size: 64px;
  margin-bottom: var(--space-4);
}

.result-message {
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-6);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-6);
}

.stat-card {
  background: var(--color-background);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 2px solid var(--color-border);
}

.stat-card .stat-value {
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--color-primary);
  display: block;
  margin-bottom: var(--space-2);
}

.stat-card .stat-label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  display: block;
}

.perfect-score-banner {
  margin-top: var(--space-6);
  padding: var(--space-4);
  background: linear-gradient(135deg, #ffd700, #ffed4e);
  border-radius: var(--radius-lg);
  font-size: var(--text-xl);
  font-weight: bold;
  color: #333;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  box-shadow: var(--shadow-md);
  animation: perfectGlow 2s infinite;
}

@keyframes perfectGlow {
  0%, 100% {
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
  }
  50% {
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.8);
  }
}

.actions {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
  justify-content: center;
}

/* Welcome Screen */
.welcome-screen {
  padding: var(--space-6);
  max-width: 700px;
  margin: 0 auto;
}

.welcome-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.welcome-card {
  background: var(--color-surface);
  padding: var(--space-8);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.difficulty-badge {
  display: inline-block;
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius-full);
  font-weight: 600;
  margin-bottom: var(--space-6);
}

.instructions {
  text-align: left;
  margin: var(--space-6) 0;
  padding: var(--space-6);
  background: var(--color-background);
  border-radius: var(--radius-lg);
  border: 2px solid var(--color-border);
}

.instructions h3 {
  margin-top: 0;
  margin-bottom: var(--space-4);
  color: var(--color-primary);
}

.instructions ul {
  margin: 0;
  padding-left: var(--space-6);
}

.instructions li {
  margin-bottom: var(--space-3);
  line-height: 1.6;
}

.instructions strong {
  color: var(--color-primary);
}

/* Scoreboard Container */
.scoreboard-container {
  background: var(--color-surface);
  padding: var(--space-6);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}

.scoreboard-container h3 {
  margin-top: 0;
  margin-bottom: var(--space-4);
  text-align: center;
  color: var(--color-primary);
}

/* Responsive Design */
@media (max-width: 1024px) {
  .memory-container {
    gap: var(--space-6);
    padding: var(--space-4);
  }

  .card-grid {
    min-height: min(28vh, 240px);
  }

  .card-front,
  .card-back {
    font-size: var(--text-lg);
  }

  .card-back {
    font-size: var(--text-2xl);
  }
}

@media (max-width: 767px) {
  /* Layout */
  .memory-container {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 4px;
  }

  .grid-section {
    max-width: 100%;
    width: 100%;
  }

  .grid-title {
    font-size: var(--text-sm);
    padding: 4px;
  }

  /* Card Grid */
  .card-grid {
    gap: 2px;
  }

  .card {
    width: 100%;
    height: auto;
  }

  .card-inner {
    width: 100%;
    height: 100%;
  }

  /* Card Styling */
  .card-front,
  .card-back {
    padding: 2px;
    font-size: 16px;
    border-radius: 4px;
    width: 100%;
    height: 100%;
  }

  .card-back {
    font-size: 24px;
  }

  .card-question {
    font-size: 11px;
    margin-bottom: 2px;
  }

  .card-answer {
    font-size: 18px;
  }

  .card.matched::after {
    width: 18px;
    height: 18px;
    font-size: 11px;
    top: 4px;
    right: 4px;
  }

  /* Header */
  .game-header {
    flex-direction: column;
    padding: var(--space-3);
    gap: var(--space-2);
  }

  .header-left,
  .header-right {
    width: 100%;
    justify-content: center;
  }

  .header-right {
    gap: var(--space-3);
  }

  .stat-value {
    font-size: var(--text-base);
  }

  .stat-label {
    font-size: var(--text-xs);
  }

  /* Feedback */
  .feedback-animation {
    font-size: var(--text-lg);
    padding: var(--space-3);
  }

  .error-message {
    padding: var(--space-4);
    margin: var(--space-3);
  }

  .error-icon {
    font-size: 40px;
  }

  .error-text {
    font-size: var(--text-lg);
  }

  .error-hint {
    font-size: var(--text-xs);
  }

  /* Results & Welcome Screens */
  .results-screen,
  .welcome-screen {
    padding: var(--space-3);
  }

  .results-card,
  .welcome-card {
    padding: var(--space-4);
  }

  .result-icon {
    font-size: 40px;
  }

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

  .actions {
    flex-direction: column;
  }

  .actions .btn {
    width: 100%;
  }
}

@media (max-width: 480px) {
  /* Card Grid */
  .card-grid {
    gap: 1px;
  }

  /* Card Styling */
  .card-front,
  .card-back {
    font-size: 14px;
  }

  .card-back {
    font-size: 20px;
  }

  .card-question {
    font-size: 10px;
  }

  .card-answer {
    font-size: 16px;
  }

  .card.matched::after {
    width: 16px;
    height: 16px;
    font-size: 10px;
    top: 3px;
    right: 3px;
  }

  /* Layout */
  .grid-title {
    font-size: var(--text-xs);
    padding: var(--space-1);
  }

  /* Feedback */
  .error-message {
    padding: var(--space-3);
    margin: var(--space-2);
  }

  .error-icon {
    font-size: 36px;
    margin-bottom: var(--space-2);
  }

  .error-text {
    font-size: var(--text-base);
    margin-bottom: var(--space-2);
  }

  .error-hint {
    font-size: 11px;
  }
}
