/* ========== 全局样式 ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ========== 头部 ========== */
header {
  text-align: center;
  padding: 30px 20px 10px;
}

header h1 {
  font-size: 2.4rem;
  background: linear-gradient(90deg, #f7971e, #ffd200);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  margin-top: 8px;
  font-size: 1rem;
  color: #aaa;
}

/* ========== 控制面板 ========== */
main {
  width: 100%;
  max-width: 700px;
  padding: 0 20px;
}

.control-panel {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  margin: 20px 0;
  flex-wrap: wrap;
}

.difficulty-selector label {
  font-size: 0.95rem;
  margin-right: 6px;
}

.difficulty-selector select {
  padding: 8px 16px;
  border-radius: 8px;
  border: 2px solid #ffd200;
  background: #1a1a2e;
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.3s;
}

.difficulty-selector select:hover {
  border-color: #f7971e;
}

.btn-restart {
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #f7971e, #ffd200);
  color: #1a1a2e;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-restart:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(255, 210, 0, 0.4);
}

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

/* ========== 统计面板 ========== */
.stats-panel {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-item {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 12px 18px;
  text-align: center;
  min-width: 100px;
  backdrop-filter: blur(10px);
}

.stat-icon {
  display: block;
  font-size: 1.4rem;
  margin-bottom: 4px;
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: #999;
  margin-bottom: 4px;
}

.stat-value {
  display: block;
  font-size: 1.3rem;
  font-weight: bold;
  color: #ffd200;
}

/* ========== 最佳记录 ========== */
.best-record {
  text-align: center;
  margin-bottom: 20px;
  padding: 10px 20px;
  background: rgba(255, 210, 0, 0.08);
  border: 1px solid rgba(255, 210, 0, 0.2);
  border-radius: 10px;
  font-size: 0.9rem;
  color: #ccc;
}

.best-icon {
  margin-right: 4px;
}

.best-separator {
  margin: 0 10px;
  color: #555;
}

.best-record span:nth-child(3),
.best-record span:nth-child(6) {
  color: #ffd200;
  font-weight: bold;
}

/* ========== 连击提示 ========== */
.combo-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  font-size: 2.5rem;
  font-weight: bold;
  color: #ff6b35;
  text-shadow: 0 0 20px rgba(255, 107, 53, 0.6);
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  animation: comboPopup 0.8s ease forwards;
}

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

/* ========== 预览倒计时 ========== */
.preview-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 50;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  backdrop-filter: blur(2px);
}

.preview-overlay.active {
  display: flex;
  animation: fadeIn 0.3s ease;
}

.preview-text {
  font-size: 1.6rem;
  font-weight: bold;
  color: #ffd200;
  margin-bottom: 12px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.preview-countdown {
  font-size: 4rem;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 30px rgba(255, 210, 0, 0.5);
  animation: pulse 1s ease infinite;
}

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

/* ========== 新纪录提示 ========== */
.new-record {
  font-size: 1.3rem;
  color: #ffd200;
  margin-bottom: 12px;
  animation: newRecordBlink 0.6s ease infinite alternate;
}

@keyframes newRecordBlink {
  from { opacity: 0.6; transform: scale(1); }
  to { opacity: 1; transform: scale(1.08); }
}

/* ========== 游戏面板 ========== */
.game-board {
  display: grid;
  gap: 12px;
  justify-content: center;
  margin: 0 auto 30px;
  perspective: 1000px;
}

.game-board.cols-3 {
  grid-template-columns: repeat(3, 100px);
}

.game-board.cols-4 {
  grid-template-columns: repeat(4, 100px);
}

.game-board.cols-5 {
  grid-template-columns: repeat(5, 100px);
}

/* ========== 卡牌 ========== */
.card {
  width: 100px;
  height: 120px;
  position: relative;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}

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

.card.matched {
  animation: matchBounce 0.5s ease;
}

.card.matched .card-front {
  background: linear-gradient(135deg, #00b09b, #96c93d);
  border-color: #96c93d;
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 255, 255, 0.15);
}

.card-back {
  background: linear-gradient(135deg, #667eea, #764ba2);
  font-size: 2rem;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.card-back::after {
  content: "?";
  font-size: 2.2rem;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.7);
}

.card-front {
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  transform: rotateY(180deg);
  font-size: 2.8rem;
  border-color: rgba(255, 210, 0, 0.3);
}

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

.card.matched {
  cursor: default;
}

/* ========== 匹配弹跳动画 ========== */
@keyframes matchBounce {
  0% { transform: rotateY(180deg) scale(1); }
  30% { transform: rotateY(180deg) scale(1.15); }
  60% { transform: rotateY(180deg) scale(0.95); }
  100% { transform: rotateY(180deg) scale(1); }
}

/* ========== 不匹配抖动动画 ========== */
@keyframes shake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  20% { transform: rotateY(180deg) translateX(-8px); }
  40% { transform: rotateY(180deg) translateX(8px); }
  60% { transform: rotateY(180deg) translateX(-5px); }
  80% { transform: rotateY(180deg) translateX(5px); }
}

.card.wrong {
  animation: shake 0.4s ease;
}

.card.wrong .card-front {
  border-color: #e74c3c;
}

/* ========== 加载动画 ========== */
.loading {
  display: none;
  text-align: center;
  padding: 60px 20px;
}

.loading.active {
  display: block;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #ffd200;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========== 胜利弹窗 ========== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(5px);
}

.modal-overlay.active {
  display: flex;
  animation: fadeIn 0.3s ease;
}

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

.modal-content {
  background: linear-gradient(135deg, #1a1a2e, #302b63);
  border: 2px solid rgba(255, 210, 0, 0.3);
  border-radius: 20px;
  padding: 40px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  animation: popIn 0.4s ease;
}

@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-content h2 {
  font-size: 2rem;
  margin-bottom: 20px;
  background: linear-gradient(90deg, #f7971e, #ffd200);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-stats {
  margin-bottom: 16px;
}

.modal-stats p,
.score-breakdown p {
  font-size: 1.05rem;
  margin: 8px 0;
  color: #ccc;
}

.score-breakdown {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 24px;
}

.score-breakdown p {
  font-size: 0.9rem;
}

.highlight-score {
  font-size: 1.8rem !important;
  font-weight: bold;
  color: #ffd200 !important;
}

.modal-content .btn-restart {
  margin-top: 10px;
  padding: 12px 36px;
  font-size: 1.1rem;
}

/* ========== 页脚 ========== */
footer {
  margin-top: auto;
  padding: 20px;
  text-align: center;
  color: #666;
  font-size: 0.85rem;
}

/* ========== 响应式 ========== */
@media (max-width: 600px) {
  header h1 {
    font-size: 1.8rem;
  }

  .game-board {
    gap: 8px;
  }

  .card {
    width: 75px;
    height: 95px;
  }

  .card-front {
    font-size: 2rem;
  }

  .card-back::after {
    font-size: 1.6rem;
  }

  .game-board.cols-3 {
    grid-template-columns: repeat(3, 75px);
  }

  .game-board.cols-4 {
    grid-template-columns: repeat(4, 75px);
  }

  .game-board.cols-5 {
    grid-template-columns: repeat(5, 75px);
  }

  .stat-item {
    min-width: 80px;
    padding: 8px 12px;
  }

  .stat-value {
    font-size: 1.1rem;
  }
}
