/* ==================== 全局变量 ==================== */
:root {
  --pink-primary: #ff6b9d;
  --pink-light: #ffb3c6;
  --pink-dark: #e84a7f;
  --purple-primary: #a78bfa;
  --purple-light: #c4b5fd;
  --blue-primary: #60a5fa;
  --blue-light: #93c5fd;
  --yellow-primary: #fbbf24;
  --yellow-light: #fcd34d;
  --green-primary: #34d399;
  --green-light: #6ee7b7;
  --bg-cream: #fff8f0;
  --bg-pink: #fff0f5;
  --text-dark: #4a4a5a;
  --text-light: #8a8a9a;
  --shadow-soft: 0 4px 15px rgba(255, 107, 157, 0.15);
  --shadow-medium: 0 8px 25px rgba(255, 107, 157, 0.25);
}

/* ==================== 重置 ==================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Nunito', 'Fredoka', sans-serif;
  background: linear-gradient(135deg, var(--bg-cream) 0%, var(--bg-pink) 50%, #ffe4ec 100%);
  color: var(--text-dark);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
  position: relative;
}

/* ==================== 背景装饰 ==================== */
.bg-decoration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.bubble {
  position: absolute;
  border-radius: 50%;
  opacity: 0.4;
  animation: bubbleFloat 8s ease-in-out infinite;
}

.b1 { width: 80px; height: 80px; background: var(--pink-light); top: 10%; left: 5%; animation-delay: 0s; }
.b2 { width: 60px; height: 60px; background: var(--purple-light); top: 20%; right: 10%; animation-delay: -2s; }
.b3 { width: 100px; height: 100px; background: var(--blue-light); bottom: 15%; left: 10%; animation-delay: -4s; }
.b4 { width: 50px; height: 50px; background: var(--yellow-light); bottom: 25%; right: 5%; animation-delay: -6s; }
.b5 { width: 70px; height: 70px; background: var(--green-light); top: 50%; left: 50%; animation-delay: -3s; }

@keyframes bubbleFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-30px) rotate(180deg); }
}

/* ==================== 主容器 ==================== */
.game-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

/* ==================== 标题 ==================== */
.game-header {
  text-align: center;
  margin-bottom: 5px;
}

.game-title {
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(1.8rem, 6vw, 2.5rem);
  font-weight: 700;
  background: linear-gradient(135deg, var(--pink-primary), var(--purple-primary), var(--blue-primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
  letter-spacing: 2px;
}

/* ==================== 游戏状态栏 ==================== */
.game-stats {
  display: flex;
  justify-content: center;
  gap: 12px;
  width: 100%;
  flex-wrap: wrap;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: white;
  border-radius: 20px;
  box-shadow: var(--shadow-soft);
  border: 2px solid transparent;
  transition: all 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-medium);
}

.score-card { border-color: var(--yellow-primary); }
.time-card { border-color: var(--blue-primary); flex: 1; max-width: 200px; }
.pairs-card { border-color: var(--green-primary); }

.stat-icon {
  font-size: 1.5rem;
}

.stat-content {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stat-value {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-dark);
}

/* 时间条 */
.time-bar {
  width: 100%;
  height: 6px;
  background: #eee;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 5px;
}

.time-progress {
  height: 100%;
  background: linear-gradient(90deg, var(--green-primary), var(--yellow-primary), var(--pink-primary));
  border-radius: 3px;
  transition: width 1s linear;
}

/* ==================== 游戏区域 ==================== */
.game-board-wrapper {
  position: relative;
  background: white;
  padding: 15px;
  border-radius: 25px;
  box-shadow: var(--shadow-medium);
  border: 3px solid var(--pink-light);
}

.game-board {
  display: grid;
  gap: 6px;
  background: linear-gradient(145deg, #fff5f8, #fff0f5);
  border-radius: 15px;
  padding: 10px;
}

/* 卡片样式 */
.game-card {
  width: 60px;
  height: 60px;
  background: white;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 3px 10px rgba(0,0,0,0.08);
  border: 3px solid transparent;
  position: relative;
  overflow: hidden;
}

.game-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.4), transparent);
  opacity: 0;
  transition: opacity 0.2s;
}

.game-card:hover {
  transform: scale(1.08) rotate(2deg);
  box-shadow: 0 8px 20px rgba(255, 107, 157, 0.3);
}

.game-card:hover::before {
  opacity: 1;
}

.game-card.selected {
  border-color: var(--pink-primary);
  background: linear-gradient(135deg, #fff0f5, white);
  transform: scale(1.1);
  animation: selectedPulse 0.5s ease;
}

.game-card.matched {
  animation: matchedPop 0.4s ease forwards;
}

.game-card.hint {
  border-color: var(--yellow-primary);
  animation: hintGlow 0.8s ease infinite;
}

.game-card.disabled {
  opacity: 0;
  pointer-events: none;
}

@keyframes selectedPulse {
  0%, 100% { transform: scale(1.1); }
  50% { transform: scale(1.15); }
}

@keyframes matchedPop {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.8; }
  100% { transform: scale(0); opacity: 0; }
}

@keyframes hintGlow {
  0%, 100% { box-shadow: 0 0 10px var(--yellow-light); }
  50% { box-shadow: 0 0 25px var(--yellow-primary); }
}

/* ==================== 连接线 SVG ==================== */
.connection-svg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.connection-line {
  stroke: var(--pink-primary);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  filter: drop-shadow(0 0 6px var(--pink-primary));
  animation: lineDraw 0.3s ease forwards;
}

@keyframes lineDraw {
  from { stroke-dasharray: 1000; stroke-dashoffset: 1000; }
  to { stroke-dasharray: 1000; stroke-dashoffset: 0; }
}

/* ==================== 控制按钮 ==================== */
.game-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--pink-primary), var(--pink-dark));
  border: none;
  border-radius: 25px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(255, 107, 157, 0.3);
}

.btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(255, 107, 157, 0.4);
}

.btn:active {
  transform: translateY(0);
}

.btn-hint { background: linear-gradient(135deg, var(--yellow-primary), #f59e0b); }
.btn-shuffle { background: linear-gradient(135deg, var(--purple-primary), #8b5cf6); }
.btn-restart { background: linear-gradient(135deg, var(--blue-primary), #3b82f6); }

/* ==================== 难度选择 ==================== */
.difficulty-select {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: white;
  border-radius: 25px;
  box-shadow: var(--shadow-soft);
}

.difficulty-label {
  font-weight: 600;
  color: var(--text-dark);
}

.diff-btn {
  padding: 6px 16px;
  font-family: 'Nunito', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-light);
  background: #f5f5f5;
  border: 2px solid transparent;
  border-radius: 15px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.diff-btn:hover {
  color: var(--pink-primary);
  background: #fff0f5;
}

.diff-btn.active {
  color: white;
  background: linear-gradient(135deg, var(--pink-primary), var(--pink-dark));
  border-color: var(--pink-primary);
}

/* ==================== 弹窗 ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: all 0.4s ease;
  backdrop-filter: blur(5px);
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: white;
  padding: 40px;
  border-radius: 30px;
  text-align: center;
  max-width: 90%;
  width: 380px;
  transform: scale(0.8) translateY(20px);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal-overlay.show .modal-content {
  transform: scale(1) translateY(0);
}

.modal-icon {
  font-size: 4rem;
  margin-bottom: 15px;
  animation: iconBounce 0.6s ease;
}

@keyframes iconBounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

.modal-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.8rem;
  color: var(--pink-primary);
  margin-bottom: 25px;
}

.modal-stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 20px;
}

.modal-stat {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.modal-stat-label {
  font-size: 0.8rem;
  color: var(--text-light);
}

.modal-stat-value {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-dark);
}

.modal-stars {
  font-size: 2rem;
  margin-bottom: 25px;
  letter-spacing: 5px;
}

.modal-stars span {
  opacity: 0.3;
  filter: grayscale(1);
  transition: all 0.5s ease;
}

.modal-stars span.active {
  opacity: 1;
  filter: grayscale(0);
  animation: starPop 0.4s ease forwards;
}

@keyframes starPop {
  0% { transform: scale(0); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.btn-play-again {
  font-size: 1.1rem;
  padding: 14px 40px;
  background: linear-gradient(135deg, var(--green-primary), #10b981);
}

/* ==================== 响应式 ==================== */
@media (max-width: 500px) {
  body {
    padding: 10px;
  }

  .game-stats {
    gap: 8px;
  }

  .stat-card {
    padding: 8px 12px;
  }

  .stat-icon {
    font-size: 1.2rem;
  }

  .stat-value {
    font-size: 1.1rem;
  }

  .game-board-wrapper {
    padding: 10px;
  }

  .game-card {
    width: 45px;
    height: 45px;
    font-size: 1.6rem;
  }

  .game-controls {
    gap: 8px;
  }

  .btn {
    padding: 8px 14px;
    font-size: 0.85rem;
  }

  .difficulty-select {
    padding: 8px 12px;
    gap: 6px;
  }

  .diff-btn {
    padding: 5px 10px;
    font-size: 0.75rem;
  }
}

@media (max-width: 380px) {
  .game-card {
    width: 38px;
    height: 38px;
    font-size: 1.4rem;
  }
}

/* ==================== 禁用选择 ==================== */
.game-board,
.btn,
.diff-btn {
  -webkit-user-select: none;
  user-select: none;
}
