/* ============================================
   记忆配对 · AI 探险家 儿童版主题
   （与概念2048同一套皮肤体系：科技蓝/森林绿/糖果粉）
   ============================================ */

html, body {
  background: #e7f1ff;          /* 科技蓝 */
  color: #274c77;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
               "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  margin: 0;
  padding: 0;
}
body.theme-forest { background: #e9f7e6; color: #2f5d3a; }  /* 森林绿 */
body.theme-candy  { background: #fff0f5; color: #8a3b5c; }  /* 糖果粉 */

.container {
  max-width: 520px;
  margin: 0 auto;
  padding: 18px 14px 30px;
}

/* ---------- 标题 ---------- */
.heading {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  -webkit-box-align: start;
  -webkit-align-items: flex-start;
  align-items: flex-start;
}
h1.title { font-size: 44px; margin: 0; line-height: 1.1; }
h1.title .title-sub {
  display: block;
  font-size: 15px;
  letter-spacing: 5px;
  font-weight: normal;
  opacity: .7;
  margin-top: 2px;
}

/* ---------- 计分面板 ---------- */
.scores-container {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  gap: 8px;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
}
.score-container, .best-container {
  background: #5b7db1;
  color: #fff;
  border-radius: 6px;
  padding: 6px 12px;
  text-align: center;
  font-size: 20px;
  font-weight: bold;
  min-width: 58px;
}
body.theme-forest .score-container, body.theme-forest .best-container { background: #5c9a5f; }
body.theme-candy  .score-container, body.theme-candy  .best-container { background: #e58bb3; }
.score-container:after { content: "步数"; display: block; font-size: 11px; font-weight: normal; opacity: .9; margin-top: 2px; }
.best-container:after  { content: "最少步数"; display: block; font-size: 11px; font-weight: normal; opacity: .9; margin-top: 2px; }

/* ---------- 顶部说明 & 按钮 ---------- */
.above-game {
  margin: 16px 0 10px;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  gap: 10px;
}
.game-intro { margin: 0; font-size: 14px; line-height: 1.5; }
.restart-button {
  background: #4f7cbe;
  color: #fff;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}
body.theme-forest .restart-button { background: #4c8a50; }
body.theme-candy  .restart-button { background: #e07aa8; }

/* ---------- 皮肤切换栏（与2048一致） ---------- */
.theme-bar {
  margin: 4px 0 12px;
  text-align: right;
  font-size: 14px;
  line-height: 30px;
}
.theme-label { opacity: .7; margin-right: 4px; vertical-align: middle; }
.theme-btn {
  display: inline-block;
  width: 28px; height: 28px;
  margin-left: 6px;
  border: 3px solid rgba(255, 255, 255, .9);
  border-radius: 50%;
  cursor: pointer;
  vertical-align: middle;
  outline: none;
  padding: 0;
  box-sizing: border-box;
}
.theme-btn.theme-tech   { background: #4f7cbe; }
.theme-btn.theme-forest { background: #4c8a50; }
.theme-btn.theme-candy  { background: #e07aa8; }
body.theme-tech   .theme-btn.theme-tech,
body.theme-forest .theme-btn.theme-forest,
body.theme-candy  .theme-btn.theme-candy {
  box-shadow: 0 0 0 2px currentColor;
}

/* ---------- 游戏面板 ---------- */
.game-container {
  background: #b7d0f2;
  border-radius: 12px;
  padding: 12px;
  position: relative;
}
body.theme-forest .game-container { background: #a9d6a0; }
body.theme-candy  .game-container { background: #f6c8da; }

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

/* ---------- 卡片（3D 翻转） ---------- */
.card {
  position: relative;
  aspect-ratio: 1 / 1;
  -webkit-perspective: 600px;
  perspective: 600px;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  outline: none;
}
.card:focus-visible .card-inner { box-shadow: 0 0 0 3px rgba(255, 255, 255, .9); }

.card-inner {
  position: absolute;
  inset: 0;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  -webkit-transition: -webkit-transform .4s ease;
  transition: transform .4s ease;
  border-radius: 12px;
}
.card.flipped .card-inner { -webkit-transform: rotateY(180deg); transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: 12px;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .12);
  text-align: center;
  padding: 4px;
  box-sizing: border-box;
}

/* 卡背（统一图案：AI探险家） */
.card-back {
  background: #4f7cbe;
  color: #fff;
}
body.theme-forest .card-back { background: #4c8a50; }
body.theme-candy  .card-back { background: #e07aa8; }
.card-back .back-emoji { font-size: 34px; line-height: 1; }
.card-back .back-name  { font-size: 10px; letter-spacing: 3px; opacity: .92; margin-top: 4px; }

/* 卡面（正面） */
.card-front {
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
  background: #ffffff;
  color: #274c77;
}
body.theme-forest .card-front { color: #2f5d3a; }
body.theme-candy  .card-front { color: #8a3b5c; }
.card-front .card-emoji { font-size: 30px; line-height: 1; }
.card-front .card-text  { font-size: 15px; font-weight: bold; margin-top: 4px; line-height: 1.3; }
.card-front.def .card-text { font-size: 13px; font-weight: normal; }

/* 配对成功：变绿打勾 + 原地定格（“消除”=不能再翻） */
.card.matched { cursor: default; }
.card.matched .card-inner {
  -webkit-animation: pop .45s ease;
  animation: pop .45s ease;
}
.card.matched .card-front {
  background: #b9e4c9;
  color: #14532d;
}
body.theme-forest .card.matched .card-front { background: #a3d9a8; color: #14532d; }
body.theme-candy  .card.matched .card-front { background: #f8d7e8; color: #8a3b5c; }
.card.matched .card-front:after {
  content: "✓";
  position: absolute;
  top: 3px;
  right: 9px;
  font-size: 20px;
  font-weight: bold;
  color: #2e8b57;
}

/* 配错：抖动提醒 */
.card.wrong .card-inner {
  -webkit-animation: shake .4s ease;
  animation: shake .4s ease;
}

@-webkit-keyframes pop {
  0%   { -webkit-transform: rotateY(180deg) scale(1); transform: rotateY(180deg) scale(1); }
  50%  { -webkit-transform: rotateY(180deg) scale(1.12); transform: rotateY(180deg) scale(1.12); }
  100% { -webkit-transform: rotateY(180deg) scale(1); transform: rotateY(180deg) scale(1); }
}
@keyframes pop {
  0%   { transform: rotateY(180deg) scale(1); }
  50%  { transform: rotateY(180deg) scale(1.12); }
  100% { transform: rotateY(180deg) scale(1); }
}
@-webkit-keyframes shake {
  0%, 100% { -webkit-transform: rotateY(180deg) translateX(0); transform: rotateY(180deg) translateX(0); }
  25% { -webkit-transform: rotateY(180deg) translateX(-6px); transform: rotateY(180deg) translateX(-6px); }
  75% { -webkit-transform: rotateY(180deg) translateX(6px); transform: rotateY(180deg) translateX(6px); }
}
@keyframes shake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  25% { transform: rotateY(180deg) translateX(-6px); }
  75% { transform: rotateY(180deg) translateX(6px); }
}

/* ---------- 配对成功提示 toast ---------- */
.match-toast {
  position: absolute;
  top: 14px;
  left: 50%;
  -webkit-transform: translateX(-50%) scale(.85);
  transform: translateX(-50%) scale(.85);
  z-index: 200;
  pointer-events: none;
  background: rgba(20, 30, 60, .88);
  color: #fff;
  border-radius: 999px;
  padding: 9px 18px;
  text-align: center;
  white-space: nowrap;
  font-size: 14px;
  opacity: 0;
  -webkit-transition: opacity .25s ease, -webkit-transform .25s ease;
  transition: opacity .25s ease, transform .25s ease;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.match-toast.show {
  opacity: 1;
  -webkit-transform: translateX(-50%) scale(1);
  transform: translateX(-50%) scale(1);
}

/* ---------- 过关弹层 ---------- */
.game-container .game-message {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, .75);
  border-radius: 12px;
  z-index: 100;
  text-align: center;
  -webkit-box-orient: vertical;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
}
.game-container .game-message.game-won { display: -webkit-box; display: -webkit-flex; display: flex; }
.game-container .game-message p {
  font-size: 30px;
  line-height: 1.4;
  margin: 0 0 18px;
  padding: 0 20px;
  color: #274c77;
}
body.theme-forest .game-container .game-message p { color: #2f5d3a; }
body.theme-candy  .game-container .game-message p { color: #8a3b5c; }
.game-container .game-message .stat-line { font-size: 16px; font-weight: normal; opacity: .85; }
.game-container .game-message a {
  background: #4f7cbe;
  color: #fff;
  border-radius: 6px;
  padding: 10px 22px;
  font-size: 16px;
  cursor: pointer;
}
body.theme-forest .game-container .game-message a { background: #4c8a50; }
body.theme-candy  .game-container .game-message a { background: #e07aa8; }

/* ---------- 说明 & 页脚 ---------- */
.game-explanation { margin-top: 18px; font-size: 14px; line-height: 1.7; }
.credit { font-size: 12px; opacity: .65; margin-top: 14px; }

/* ---------- 手机小屏适配 ---------- */
@media screen and (max-width: 520px) {
  .container { padding: 12px 10px 24px; }
  h1.title { font-size: 30px; }
  h1.title .title-sub { font-size: 11px; letter-spacing: 3px; }
  .score-container, .best-container { font-size: 16px; padding: 4px 8px; min-width: 46px; }
  .game-intro { font-size: 12px; }
  .board { gap: 7px; }
  .game-container { padding: 9px; border-radius: 10px; }
  .card-face { border-radius: 9px; }
  .card-back .back-emoji { font-size: 24px; }
  .card-front .card-emoji { font-size: 22px; }
  .card-front .card-text { font-size: 12px; }
  .card-front.def .card-text { font-size: 10px; }
  .game-container .game-message p { font-size: 20px; }
  .game-container .game-message .stat-line { font-size: 13px; }
}
