/* ===== 记忆翻牌 · 专用样式 ===== */

/* ========== 卡牌容器 ========== */
.memory-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  position: relative;
}

/* ========== 卡牌网格 ========== */
.memory-grid {
  display: grid;
  gap: 8px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
  padding: 20px;
  background: linear-gradient(135deg, rgba(255,253,249,0.9), rgba(255,248,240,0.9));
  border-radius: var(--ft-radius-sm);
  border: 1px solid var(--ft-rule);
  box-shadow: var(--ft-shadow);
}
.memory-grid.size-4x4 { grid-template-columns: repeat(4, 1fr); max-width: 380px; }
.memory-grid.size-5x5 { grid-template-columns: repeat(5, 1fr); max-width: 420px; }
.memory-grid.size-6x6 { grid-template-columns: repeat(6, 1fr); max-width: 480px; }
.memory-grid.size-7x7 { grid-template-columns: repeat(7, 1fr); max-width: 520px; }
.memory-grid.size-8x8 { grid-template-columns: repeat(8, 1fr); max-width: 540px; }
.memory-grid.size-9x9 { grid-template-columns: repeat(9, 1fr); max-width: 560px; }
.memory-grid.size-3x3 { grid-template-columns: repeat(3, 1fr); max-width: 280px; }

/* ========== 卡牌 ========== */
.memory-card {
  aspect-ratio: 1;
  width: 100%;
  cursor: pointer;
  perspective: 600px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.memory-card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--ft-radius-xs);
}
.memory-card.flipped .memory-card-inner,
.memory-card.matched .memory-card-inner {
  transform: rotateY(180deg);
}
.memory-card-face {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--ft-radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* 卡牌背面 */
.memory-card-back {
  background-image: url('../assets/focus-illus/memory-card-back.jpg');
  background-size: cover;
  background-position: center;
  border: 2px solid var(--ft-primary-100);
  box-shadow: var(--ft-shadow);
  z-index: 2;
  opacity: 1;
  transition: opacity 0.3s ease;
}
.memory-card-back::before {
  content: none;
}
.memory-card:hover .memory-card-back {
  border-color: var(--ft-primary);
  box-shadow: var(--ft-shadow-md);
  transform: scale(1.03);
}
.memory-card:hover .memory-card-inner {
  transform: scale(1.03);
}
.memory-card.flipped:hover .memory-card-inner {
  transform: rotateY(180deg) scale(1.03);
}

/* 背面纹理（轻度干扰） */
.memory-grid.distraction-light .memory-card-back {
  background-image:
    radial-gradient(circle at 25% 25%, rgba(224,122,95,0.08) 0%, transparent 50%),
    radial-gradient(circle at 75% 75%, rgba(58,155,143,0.06) 0%, transparent 50%);
}

/* 卡牌正面 */
.memory-card-front {
  transform: rotateY(180deg);
  background: #fff;
  border: 2px solid var(--ft-rule);
  box-shadow: var(--ft-shadow);
  font-size: 2.2rem;
  line-height: 1;
  padding: 8px;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.memory-grid.size-6x6 .memory-card-front,
.memory-grid.size-7x7 .memory-card-front,
.memory-grid.size-8x8 .memory-card-front,
.memory-grid.size-9x9 .memory-card-front {
  font-size: 1.5rem;
  padding: 4px;
}
.memory-grid.size-3x3 .memory-card-front {
  font-size: 3rem;
}

/* 配对成功动画 */
.memory-card.matched .memory-card-front {
  background: linear-gradient(135deg, var(--ft-green-soft), var(--ft-teal-50));
  border-color: var(--ft-teal);
  box-shadow: 0 3px 12px rgba(76,175,122,0.25);
  animation: memMatchPop 0.4s ease;
}
@keyframes memMatchPop {
  0% { transform: rotateY(180deg) scale(1); }
  40% { transform: rotateY(180deg) scale(1.12); }
  100% { transform: rotateY(180deg) scale(1); }
}

/* 配对失败动画 */
.memory-card.wrong .memory-card-front {
  border-color: #E53935;
  background: #FFEBEE;
  animation: memWrongShake 0.4s ease;
}
@keyframes memWrongShake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  25% { transform: rotateY(180deg) translateX(-4px); }
  75% { transform: rotateY(180deg) translateX(4px); }
}

/* 预览模式 */
.memory-card.preview .memory-card-inner {
  transform: rotateY(180deg);
}
.memory-card.preview .memory-card-front {
  border-color: var(--ft-blue);
  box-shadow: 0 0 8px rgba(91,155,213,0.2);
}

/* opacity 后备切换（兼容无 3D 变换环境） */
.memory-card.flipped .memory-card-front,
.memory-card.matched .memory-card-front,
.memory-card.preview .memory-card-front {
  opacity: 1;
}
.memory-card.flipped .memory-card-back,
.memory-card.matched .memory-card-back,
.memory-card.preview .memory-card-back {
  opacity: 0;
}

/* 禁用点击 */
.memory-card.disabled {
  pointer-events: none;
}

/* ========== 预览倒计时覆盖 ========== */
.memory-preview-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: var(--ft-radius);
  z-index: 20;
}
.memory-preview-overlay.show {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.memory-preview-text {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ft-blue);
}
.memory-preview-count {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--ft-primary);
  font-variant-numeric: tabular-nums;
  animation: memCountPulse 1s ease-in-out infinite;
}
@keyframes memCountPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
}

/* ========== 星级评价 ========== */
.memory-stars {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 12px 0;
}
.memory-star {
  font-size: 2rem;
  transition: all 0.3s ease;
  opacity: 0.3;
  transform: scale(0.8);
}
.memory-star.earned {
  opacity: 1;
  transform: scale(1);
  animation: memStarPop 0.4s ease;
}
@keyframes memStarPop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

/* ========== 配对统计条 ========== */
.memory-stats-bar {
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  padding: 14px 24px;
  background: linear-gradient(135deg, rgba(255,253,249,0.95), rgba(255,248,240,0.95));
  border-radius: var(--ft-radius-sm);
  border: 1px solid var(--ft-rule);
  width: 100%;
  position: relative;
  overflow: hidden;
  box-shadow: var(--ft-shadow);
}
.memory-stats-bar::after {
  content: '';
  position: absolute;
  bottom: -15px;
  right: -15px;
  width: 55px;
  height: 55px;
  background-image: url('../assets/focus-illus/stat-target.jpg');
  background-size: contain;
  background-repeat: no-repeat;
  opacity: 0.2;
  pointer-events: none;
}
.memory-stats-bar .mem-stat {
  text-align: center;
  min-width: 56px;
}
.memory-stats-bar .mem-stat-label {
  display: block;
  font-size: 0.7rem;
  color: var(--ft-muted);
  font-weight: 600;
  letter-spacing: 0.5px;
}
.memory-stats-bar .mem-stat-value {
  display: block;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--ft-ink);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.memory-timer {
  font-size: 2.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--ft-primary), #D4533B);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-variant-numeric: tabular-nums;
  min-width: 120px;
  letter-spacing: 2px;
  line-height: 1;
  text-align: center;
}
.memory-timer.running {
  animation: ftPulse 1.5s ease-in-out infinite;
}

/* ========== 主题选择 ========== */
.memory-theme-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ========== 记录 ========== */
.memory-best-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.memory-best-card {
  background: #fff;
  border-radius: var(--ft-radius-xs);
  padding: 14px;
  border: 1px solid var(--ft-rule);
  transition: var(--ft-transition);
}
.memory-best-card:hover { box-shadow: var(--ft-shadow); }
.memory-best-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.memory-best-card-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ft-text);
}
.memory-best-card-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 100px;
  background: var(--ft-blue-soft);
  color: var(--ft-blue);
}
.memory-best-card-value {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--ft-blue);
}
.memory-best-card-sub {
  font-size: 0.72rem;
  color: var(--ft-muted);
  margin-top: 2px;
}

/* ========== 翻牌网格尺寸控制 ========== */
.memory-grid.size-4x4 { max-width: 380px; }
.memory-grid.size-5x5 { max-width: 440px; }
.memory-grid.size-6x6 { max-width: 500px; }
.memory-grid.size-7x7 { max-width: 540px; }
.memory-grid.size-8x8 { max-width: 560px; }
.memory-grid.size-9x9 { max-width: 580px; }
.memory-grid.size-3x3 { max-width: 300px; }

/* ========== 响应式 ========== */
@media (max-width: 768px) {
  .memory-grid { gap: 6px; }
  .memory-grid.size-4x4 { max-width: 300px; }
  .memory-grid.size-4x4 .memory-card { max-width: 68px; }
  .memory-grid.size-5x5 { max-width: 340px; }
  .memory-grid.size-5x5 .memory-card { max-width: 62px; }
  .memory-grid.size-6x6 { max-width: 380px; }
  .memory-grid.size-6x6 .memory-card { max-width: 56px; }
  .memory-grid.size-7x7 { max-width: 400px; }
  .memory-grid.size-7x7 .memory-card { max-width: 50px; }
  .memory-grid.size-8x8 { max-width: 420px; }
  .memory-grid.size-8x8 .memory-card { max-width: 46px; }
  .memory-grid.size-9x9 { max-width: 440px; }
  .memory-grid.size-9x9 .memory-card { max-width: 44px; }
  .memory-grid.size-3x3 { max-width: 240px; }
  .memory-grid.size-3x3 .memory-card { max-width: 72px; }
  .memory-card-front { font-size: 1.8rem !important; }
  .memory-grid.size-6x6 .memory-card-front,
  .memory-grid.size-7x7 .memory-card-front,
  .memory-grid.size-8x8 .memory-card-front,
  .memory-grid.size-9x9 .memory-card-front { font-size: 1.2rem !important; }
  .memory-stats-bar { gap: 14px; padding: 10px 14px; }
  .memory-timer { font-size: 1.5rem; min-width: 80px; }
}

@media (max-width: 480px) {
  .memory-grid { gap: 4px; }
  .memory-grid.size-4x4 { max-width: 260px; }
  .memory-grid.size-5x5 { max-width: 290px; }
  .memory-grid.size-6x6 { max-width: 320px; }
  .memory-grid.size-7x7 { max-width: 340px; }
  .memory-grid.size-8x8 { max-width: 360px; }
  .memory-grid.size-9x9 { max-width: 380px; }
  .memory-grid.size-3x3 { max-width: 210px; }
  .memory-card-back::before { font-size: 1.3rem; }
  .memory-card-front { font-size: 1.5rem !important; }
  .memory-grid.size-7x7 .memory-card-front,
  .memory-grid.size-8x8 .memory-card-front,
  .memory-grid.size-9x9 .memory-card-front { font-size: 1rem !important; }
}

/* 动态干扰效果 */
.memory-grid.distraction-heavy {
  position: relative;
}
.memory-grid.distraction-heavy::before {
  content: '';
  position: absolute;
  top: -10px; left: -10px; right: -10px; bottom: -10px;
  background: linear-gradient(45deg, rgba(224,122,95,0.03), rgba(91,155,213,0.03), rgba(155,126,216,0.03));
  border-radius: var(--ft-radius);
  animation: memBgShift 8s ease-in-out infinite;
  z-index: -1;
}
@keyframes memBgShift {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* 连击特效 */
.memory-combo {
  position: fixed;
  pointer-events: none;
  z-index: 3000;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--ft-primary);
  animation: memComboFloat 1s ease forwards;
}
@keyframes memComboFloat {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-60px) scale(1.3); }
}
