/* ==========================================================================
   温室记忆配对 (Greenhouse Memory Match) 专属样式
   4x4 网格、3D 卡片翻转、无障碍键盘焦点环、prefers-reduced-motion 降级
   ========================================================================== */

/* 游戏弹窗/容器 */
.game-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(36, 54, 46, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.game-modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.game-greenhouse-frame {
  width: 100%;
  max-width: 680px;
  background: var(--color-bg);
  border: 2px solid var(--color-sage);
  border-radius: 120px 120px 24px 24px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.25);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 94vh;
}

/* 顶部温室拱顶饰条与关闭按钮 */
.game-frame-header {
  background: linear-gradient(180deg, var(--color-mint) 0%, rgba(243, 248, 237, 0.6) 100%);
  padding: 2.2rem 2rem 1.2rem;
  text-align: center;
  position: relative;
  border-bottom: 1px solid var(--color-glass-border);
}

.game-close-btn {
  position: absolute;
  top: 1.2rem;
  right: 1.4rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--color-sage);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--color-stem);
  transition: var(--transition-smooth);
}

.game-close-btn:hover, .game-close-btn:focus-visible {
  background: var(--color-stem);
  color: #fff;
  outline: 2px solid var(--color-stem);
  outline-offset: 2px;
}

.game-title-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.game-title-row h2 {
  font-family: var(--font-serif);
  font-size: 1.65rem;
  color: var(--color-stem);
}

.game-title-row p {
  font-size: 0.85rem;
  color: var(--color-stem-light);
}

/* 控制栏：步数、耗时、最佳纪录与操作按钮 */
.game-telemetry-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 2rem;
  background: rgba(255, 255, 255, 0.7);
  border-bottom: 1px solid var(--color-glass-border);
  flex-wrap: wrap;
  gap: 0.8rem;
}

.telemetry-stats {
  display: flex;
  gap: 1.5rem;
  font-size: 0.88rem;
  color: var(--color-stem);
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.stat-label {
  color: var(--color-stem-light);
  font-size: 0.8rem;
}

.stat-value {
  font-family: monospace;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--color-stem);
}

.telemetry-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.btn-game-ctl {
  padding: 0.4rem 0.85rem;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--color-sage);
  background: var(--color-bg);
  color: var(--color-stem);
  transition: var(--transition-smooth);
}

.btn-game-ctl:hover, .btn-game-ctl:focus-visible {
  background: var(--color-stem);
  color: #fff;
  outline: 2px solid var(--color-stem);
}

.btn-game-restart {
  background: var(--color-mint);
  border-color: rgba(184, 209, 187, 0.9);
}

/* 4x4 卡片网格主体 */
.game-board-container {
  padding: 1.5rem 2rem 2rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-grid-4x4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 0.85rem;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 1 / 1;
  perspective: 1000px; /* 3D 翻转透视 */
}

/* 卡片单元 */
.memory-card {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  background: transparent;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

/* 键盘明确焦点状态 */
.memory-card:focus-visible {
  outline: 3px solid #2B4237;
  outline-offset: 3px;
}

/* 翻开与配对成功状态 */
.memory-card.is-flipped {
  transform: rotateY(180deg);
}

.memory-card.is-matched {
  transform: rotateY(180deg);
  cursor: default;
}

.memory-card.is-matched .card-face-front {
  background: linear-gradient(135deg, rgba(216, 238, 229, 0.9) 0%, rgba(201, 221, 197, 0.95) 100%);
  border: 2px solid #3BA374;
}

/* 卡片正面与背面公用属性 */
.card-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(54, 74, 64, 0.08);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

/* 卡片背面（未翻开时面向玩家：薄荷温室雕花纹路） */
.card-face-back {
  background: linear-gradient(135deg, #E2EFE7 0%, #C9DDC5 100%);
  border: 1.5px solid #AFC8AC;
}

.card-face-back::after {
  content: "🌿";
  font-size: 1.4rem;
  opacity: 0.65;
  filter: grayscale(0.2);
}

.memory-card:hover .card-face-back {
  border-color: var(--color-stem);
  box-shadow: 0 6px 14px rgba(54, 74, 64, 0.16);
}

/* 卡片正面（翻开展示：植物图标 + 植物名称，绝不单纯依赖颜色识别） */
.card-face-front {
  background: #ffffff;
  border: 1.5px solid var(--color-sage);
  transform: rotateY(180deg);
  padding: 0.4rem;
  text-align: center;
}

.botanical-card-icon {
  width: 38px;
  height: 38px;
  margin-bottom: 0.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.botanical-card-icon svg {
  width: 100%;
  height: 100%;
  stroke: var(--color-stem);
  fill: var(--color-mint);
}

.botanical-card-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-stem);
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.botanical-card-latin {
  font-size: 0.62rem;
  color: var(--color-stem-light);
  font-style: italic;
  line-height: 1;
}

/* 规则浮层 / 帮助对话框 */
.game-rules-dialog {
  display: none;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--color-sage);
  border-radius: 12px;
  padding: 1.2rem;
  margin-top: 1rem;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--color-stem);
  width: 100%;
  max-width: 480px;
}

.game-rules-dialog.active {
  display: block;
  animation: fadeIn 0.25s ease;
}

.game-rules-dialog h4 {
  font-family: var(--font-serif);
  font-size: 1rem;
  margin-bottom: 0.4rem;
  color: var(--color-stem);
}

.game-rules-dialog ul {
  padding-left: 1.2rem;
  margin-top: 0.4rem;
}

/* 获胜庆祝浮层 */
.game-victory-banner {
  display: none;
  background: linear-gradient(135deg, var(--color-mint) 0%, var(--color-apricot) 100%);
  border: 2px solid var(--color-stem);
  border-radius: 16px;
  padding: 1.6rem;
  text-align: center;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 420px;
  box-shadow: 0 15px 40px rgba(0,0,0,0.2);
  z-index: 10;
}

.game-victory-banner.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.game-victory-banner h3 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  color: var(--color-stem);
}

.game-victory-banner p {
  font-size: 0.92rem;
  color: var(--color-stem-light);
  line-height: 1.5;
}

.victory-metric-highlight {
  font-family: monospace;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-stem);
  background: rgba(255, 255, 255, 0.8);
  padding: 0.3rem 0.8rem;
  border-radius: 8px;
  border: 1px dashed var(--color-stem);
}

@keyframes popIn {
  from { opacity: 0; transform: translate(-50%, -46%) scale(0.92); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   无障碍与减少动画降级模式 (prefers-reduced-motion)
   取消 3D 翻转动画，直接瞬时切换可见性，保留完整游戏逻辑
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .memory-card {
    transition: none !important;
    transform-style: flat !important;
  }
  
  .memory-card .card-face-front {
    display: none;
    transform: none !important;
  }
  
  .memory-card.is-flipped .card-face-back,
  .memory-card.is-matched .card-face-back {
    display: none;
  }
  
  .memory-card.is-flipped .card-face-front,
  .memory-card.is-matched .card-face-front {
    display: flex;
  }
  
  .game-victory-banner.active {
    animation: none !important;
  }
}

/* 手机端尺寸适配 */
@media (max-width: 540px) {
  .game-greenhouse-frame {
    border-radius: 60px 60px 16px 16px;
  }
  .game-frame-header {
    padding: 1.6rem 1rem 0.8rem;
  }
  .game-telemetry-bar {
    padding: 0.6rem 1rem;
  }
  .game-board-container {
    padding: 1rem;
  }
  .game-grid-4x4 {
    gap: 0.5rem;
    max-width: 320px;
  }
  .botanical-card-icon {
    width: 26px;
    height: 26px;
  }
  .botanical-card-label {
    font-size: 0.65rem;
  }
  .botanical-card-latin {
    display: none;
  }
}
