/* 扑克记忆 Card Memory · 独立样式（选择器统一前缀 .g-cardmemory） */

.g-cardmemory {
  justify-content: flex-start;
  gap: 10px;
}

/* ---------------- 顶部 ---------------- */

.g-cardmemory .cm-head {
  align-items: center;
  min-height: 40px;
  gap: 8px;
}

.g-cardmemory .cm-head .grow { width: 100%; }
.g-cardmemory .cm-head .seg { padding: 4px; }
.g-cardmemory .cm-head .seg-item { min-height: 36px; font-size: 12px; }
.g-cardmemory .btn:focus { outline: none; }
.g-cardmemory .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------- 数据 ---------------- */

.g-cardmemory .stats { gap: 8px; }
.g-cardmemory .stat { padding: 6px 6px; }
.g-cardmemory .stat-v { font-size: 16px; }
.g-cardmemory .cm-lives { color: #ff7ab8; letter-spacing: 0.08em; }
.g-cardmemory .cm-lives.low { color: #ff5c6c; }

/* ---------------- 主体 ---------------- */

.g-cardmemory .cm-bodywrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.g-cardmemory .cm-body {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  min-height: 0;
}

/* 牌面尺寸 */
.g-cardmemory {
  --cw: clamp(46px, 14.6vw, 58px);
  --ch: calc(var(--cw) * 1.4);
  --sw: clamp(22px, 7.2vw, 30px);
  --sh: calc(var(--sw) * 1.4);
}

.g-cardmemory .cm-stage {
  position: relative;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: calc(var(--ch) + var(--sh) + 26px);
  padding: 8px 8px 7px;
  border-radius: 16px;
  background:
    radial-gradient(120% 120% at 100% 0%, rgba(183, 140, 255, 0.1), transparent 58%),
    linear-gradient(160deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.018));
  border: 1px solid var(--line);
}

.g-cardmemory .cm-playback {
  position: relative;
  height: var(--ch);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.g-cardmemory .cm-playback:not(.has-card)::after {
  content: "按顺序点出";
  font-size: 12px;
  color: var(--faint);
  letter-spacing: 0.04em;
}

.g-cardmemory .cm-body.is-playing .cm-playback:not(.has-card)::after {
  content: "仔细看…";
  color: var(--accent);
  font-weight: 600;
  animation: cmBreath 1.1s ease-in-out infinite;
}

.g-cardmemory .cm-body.covered .cm-playback::after { content: none; }
.g-cardmemory .cm-body.covered .cm-cands-wrap,
.g-cardmemory .cm-body.covered .cm-slots { opacity: 0; pointer-events: none; }

@keyframes cmBreath {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

.g-cardmemory .cm-slots {
  transition: opacity 0.18s ease;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: var(--sh);
  width: 100%;
}

.g-cardmemory .cm-slot {
  width: var(--sw);
  height: var(--sh);
  border-radius: 5px;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.g-cardmemory .cm-slot.filled {
  border-style: solid;
  border-color: rgba(183, 140, 255, 0.55);
  box-shadow: 0 0 8px rgba(183, 140, 255, 0.25);
}

/* ---------------- 扑克牌 ---------------- */

.g-cardmemory .cm-card {
  position: relative;
  width: var(--cw);
  height: var(--ch);
  border-radius: calc(var(--cw) * 0.14);
  background: linear-gradient(160deg, #fbf8f1, #eee6d8);
  border: 1px solid rgba(0, 0, 0, 0.16);
  box-shadow: 0 4px 10px -2px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  color: #222a36;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

.g-cardmemory .cm-card.red { color: #c93d4a; }
.g-cardmemory .cm-card.black { color: #222a36; }

.g-cardmemory .cm-corner {
  position: absolute;
  top: 4%;
  left: 8%;
  font-size: calc(var(--cw) * 0.24);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.g-cardmemory .cm-corner-suit {
  position: absolute;
  top: 23%;
  left: 8%;
  font-size: calc(var(--cw) * 0.2);
  line-height: 1;
}

.g-cardmemory .cm-center-suit {
  position: absolute;
  left: 50%;
  top: 54%;
  transform: translate(-50%, -50%);
  font-size: calc(var(--cw) * 0.48);
  line-height: 1;
}

/* 大牌（闪现用） */
.g-cardmemory .cm-big {
  --cw: clamp(66px, 20vw, 84px);
  width: var(--cw);
  height: calc(var(--cw) * 1.4);
  box-shadow: 0 16px 34px -12px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(255, 255, 255, 0.2);
  animation: cmCardIn 0.16s cubic-bezier(0.2, 1.2, 0.4, 1);
}

@keyframes cmCardIn {
  from { transform: scale(0.82); opacity: 0.2; }
  to { transform: scale(1); opacity: 1; }
}

.g-cardmemory .cm-fly {
  --cw: clamp(46px, 14.6vw, 58px);
  transform-origin: center;
}

.g-cardmemory .cm-mini {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  box-shadow: none;
}

.g-cardmemory .cm-mini .cm-corner { font-size: calc(var(--sw) * 0.42); top: 5%; left: 8%; }
.g-cardmemory .cm-mini .cm-corner-suit { font-size: calc(var(--sw) * 0.34); top: 42%; left: 8%; }
.g-cardmemory .cm-mini .cm-center-suit { display: none; }

/* ---------------- 候选牌 ---------------- */

.g-cardmemory .cm-cands-wrap {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  transition: opacity 0.2s ease, filter 0.2s ease;
}

.g-cardmemory .cm-body.is-playing .cm-cands-wrap {
  opacity: 0.22;
  filter: grayscale(0.6);
  pointer-events: none;
}

.g-cardmemory .cm-cands {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 2px 0;
}

.g-cardmemory .cm-cand {
  position: relative;
  padding: 0;
  border: 0;
  background: none;
  border-radius: calc(var(--cw) * 0.16);
  touch-action: manipulation;
  transition: transform 0.12s ease, opacity 0.18s ease, filter 0.18s ease;
}

.g-cardmemory .cm-cand:active { transform: scale(0.96); }
.g-cardmemory .cm-cand:disabled { cursor: default; }
.g-cardmemory .cm-cand.used { opacity: 0.22; filter: grayscale(0.5); }

.g-cardmemory .cm-cand.wrong .cm-card {
  box-shadow: 0 0 0 2px var(--err), 0 0 18px rgba(255, 92, 108, 0.7);
  animation: cmWrong 0.4s ease;
}

@keyframes cmWrong {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.g-cardmemory .cm-cand:not(:disabled):hover .cm-card {
  box-shadow: 0 6px 16px -4px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(183, 140, 255, 0.6);
}

/* ---------------- 覆盖层 ---------------- */

.g-cardmemory .cm-cover {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-radius: 16px;
  background: rgba(8, 11, 18, 0.9);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s;
}

.g-cardmemory .cm-cover.show { opacity: 1; visibility: visible; }

.g-cardmemory .cm-cover-card {
  width: 100%;
  max-width: 280px;
  text-align: center;
}

.g-cardmemory .cm-cover-title {
  font-size: 19px;
  font-weight: 800;
  line-height: 1.3;
}

.g-cardmemory .cm-cover-sub {
  margin-top: 6px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--dim);
}

.g-cardmemory .cm-cover-stats {
  display: flex;
  gap: 8px;
  margin: 13px 0 4px;
}

.g-cardmemory .cm-cstat {
  flex: 1;
  min-width: 0;
  padding: 7px 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
}

.g-cardmemory .cm-cstat span {
  display: block;
  font-size: 10px;
  color: var(--faint);
  margin-bottom: 2px;
}

.g-cardmemory .cm-cstat b {
  display: block;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.g-cardmemory .cm-cover .btn { min-height: 44px; margin-top: 12px; }
.g-cardmemory .cm-cover-extra {
  margin-top: 8px;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--faint);
}

/* ---------------- 操作行 / 底部 ---------------- */

.g-cardmemory .cm-toolbar .btn { min-height: 42px; }

.g-cardmemory .cm-meta { padding: 7px 12px 8px; }
.g-cardmemory .cm-tip {
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--faint);
}

/* ---------------- 窄屏 / 动效偏好 ---------------- */

@media (max-width: 359px) {
  .g-cardmemory { --cw: 46px; --sw: 24px; }
  .g-cardmemory .cm-head .seg-item { font-size: 11px; }
  .g-cardmemory .stat-v { font-size: 15.5px; }
  .g-cardmemory .cm-cands { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .g-cardmemory .cm-body.is-playing .cm-playback:not(.has-card)::after { animation: none; opacity: 0.9; }
  .g-cardmemory .cm-big { animation: none; }
  .g-cardmemory .cm-cand.wrong .cm-card { animation: none; }
}
