/* ============================================================
   拾光游戏厅 · 记忆翻牌（memory）
   牌桌 / 木牌 / 翻牌动画 / 记录
   ============================================================ */

.mem-wrap { width: 100%; }

.mem-layout { align-items: stretch; }

.mem-stage {
  align-content: start;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 14%, rgba(235, 207, 150, .12), transparent 56%),
    repeating-linear-gradient(35deg, rgba(0, 0, 0, .06) 0 2px, transparent 2px 4px),
    linear-gradient(150deg, #235441, #123a2d 72%, #0d2c23);
}

.mem-stage::after {
  content: "";
  position: absolute;
  inset: 9px;
  border: 1px solid rgba(198, 160, 90, .08);
  pointer-events: none;
  border-radius: 2px;
}

.mem-table {
  position: relative;
  width: 100%;
  max-width: 610px;
  margin: 0 auto;
  padding: 17px 18px 14px;
  border-radius: 9px;
  border: 1px solid rgba(198, 160, 90, .28);
  background:
    radial-gradient(ellipse at 30% -10%, rgba(255, 229, 182, .1), transparent 46%),
    repeating-linear-gradient(88deg, rgba(0, 0, 0, .04) 0 2px, transparent 2px 11px),
    linear-gradient(155deg, #154a38, #0e3226 75%);
  box-shadow:
    0 22px 38px rgba(0, 0, 0, .38),
    inset 0 1px 0 rgba(255, 229, 182, .1),
    inset 0 0 40px rgba(0, 0, 0, .32);
}
.mem-table::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(198, 160, 90, .16);
  border-radius: 5px;
  pointer-events: none;
}

.mem-table-top,
.mem-table-bottom {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: rgba(226, 204, 161, .46);
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: .18em;
}
.mem-table-top { padding: 0 3px 11px; }
.mem-table-bottom { padding: 10px 3px 0; }
.mem-table-label { display: inline-flex; align-items: center; gap: 7px; }
.mem-table-label i {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--green-phosphor);
  box-shadow: 0 0 7px rgba(158, 228, 147, .7);
}
.mem-table-no { color: rgba(226, 204, 161, .28); }
.mem-table-tip { letter-spacing: .08em; font-family: var(--font-body); font-size: 9px; }
.mem-pairs { display: inline-flex; gap: 4px; }
.mem-pairs i {
  width: 5px; height: 5px;
  border-radius: 50%;
  border: 1px solid rgba(198, 160, 90, .35);
  transition: background .3s ease, box-shadow .3s ease, border-color .3s ease;
}
.mem-pairs i.on {
  background: var(--brass-hi);
  border-color: var(--brass-hi);
  box-shadow: 0 0 5px rgba(230, 201, 130, .7);
}

.mem-board {
  position: relative;
  z-index: 1;
  width: min(100%, 480px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(7px, 1.1vw, 12px);
}

.mem-card {
  position: relative;
  aspect-ratio: 3 / 4;
  min-width: 0;
  border-radius: 5px;
  background: transparent;
  perspective: 900px;
  -webkit-tap-highlight-color: transparent;
  transition: transform .18s ease;
  color: #3d2a18;
}
.mem-card:hover { transform: translateY(-3px); }
.mem-card:active { transform: translateY(0) scale(.985); }
.mem-card-inner {
  position: absolute;
  inset: 0;
  display: block;
  transform-style: preserve-3d;
  transition: transform .55s cubic-bezier(.22, .68, .28, 1);
  border-radius: 5px;
}
.mem-card.is-flipped .mem-card-inner,
.mem-card.is-open .mem-card-inner { transform: rotateY(180deg); }

.mem-card-back,
.mem-card-front {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 5px;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transform: translateZ(0);
}

/* 牌背：漆木 + 铜线 + 朱印 */
.mem-card-back {
  align-items: center;
  justify-content: center;
  border: 1px solid #7c3527;
  background:
    radial-gradient(ellipse at 35% 20%, rgba(255, 204, 163, .18), transparent 40%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .018) 0 2px, transparent 2px 7px),
    linear-gradient(150deg, #873728, #5e2119 62%, #471711);
  box-shadow:
    0 7px 12px rgba(0, 0, 0, .4),
    inset 0 1px 0 rgba(255, 218, 178, .26),
    inset 0 -5px 10px rgba(34, 8, 4, .36);
}
.mem-card-back::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(235, 202, 148, .34);
  border-radius: 3px;
}
.mem-card-back-frame {
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  border: 1px solid rgba(235, 202, 148, .23);
}
.mem-card-back-frame::before,
.mem-card-back-frame::after {
  content: "✦";
  position: absolute;
  color: rgba(235, 202, 148, .4);
  font-size: 7px;
  line-height: 1;
}
.mem-card-back-frame::before { left: -4px; top: 50%; transform: translateY(-50%); }
.mem-card-back-frame::after { right: -4px; top: 50%; transform: translateY(-50%); }
.mem-back-seal {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: clamp(30px, 35%, 44px);
  aspect-ratio: 1;
  border: 1px solid rgba(241, 216, 168, .4);
  border-radius: 2px;
  color: #eed9b1;
  font-family: var(--font-display);
  font-size: clamp(16px, 3.4vw, 24px);
  line-height: 1;
  background: rgba(43, 10, 6, .2);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, .2), 0 0 0 3px rgba(235, 202, 148, .06);
  text-shadow: 0 1px 2px rgba(45, 8, 3, .6);
}
.mem-back-corner {
  position: absolute;
  width: 8px;
  height: 8px;
  border-color: rgba(235, 202, 148, .35);
  border-style: solid;
}
.mem-back-corner.tl { left: 8px; top: 8px; border-width: 1px 0 0 1px; }
.mem-back-corner.tr { right: 8px; top: 8px; border-width: 1px 1px 0 0; }
.mem-back-corner.bl { left: 8px; bottom: 8px; border-width: 0 0 1px 1px; }
.mem-back-corner.br { right: 8px; bottom: 8px; border-width: 0 1px 1px 0; }

/* 牌面：旧纸 + 铜版小画 */
.mem-card-front {
  --face: #ecdcbd;
  --face-deep: #dcc6a0;
  --face-accent: #79542e;
  transform: rotateY(180deg);
  align-items: center;
  justify-content: center;
  gap: 5%;
  border: 1px solid #c4a778;
  background:
    radial-gradient(ellipse at 30% 12%, rgba(255, 252, 234, .8), transparent 42%),
    repeating-linear-gradient(0deg, rgba(112, 79, 39, .028) 0 1px, transparent 1px 3px),
    linear-gradient(155deg, #f1e3c6, var(--face) 68%, var(--face-deep));
  box-shadow:
    0 7px 12px rgba(0, 0, 0, .4),
    inset 0 1px 0 rgba(255, 255, 255, .6),
    inset 0 0 24px rgba(106, 71, 31, .1);
}
.mem-card-front::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(112, 78, 37, .18);
  border-radius: 3px;
}
.mem-card-front::after {
  content: "";
  position: absolute;
  inset: 9px;
  border: 1px dashed rgba(112, 78, 37, .12);
  border-radius: 2px;
  pointer-events: none;
}
.mem-face-icon {
  position: relative;
  z-index: 1;
  width: 56%;
  max-width: 64px;
  color: var(--face-accent);
  filter: drop-shadow(0 1px 0 rgba(255, 250, 232, .75)) drop-shadow(0 2px 2px rgba(87, 57, 24, .12));
}
.mem-face-icon svg { width: 100%; height: auto; }
.mem-face-label {
  position: relative;
  z-index: 1;
  color: rgba(72, 48, 22, .76);
  font-family: var(--font-display);
  font-size: clamp(7px, 1vw, 10px);
  letter-spacing: .12em;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .55);
}
.mem-face-stamp {
  position: absolute;
  right: 9px;
  bottom: 8px;
  z-index: 1;
  padding: 1px 3px;
  color: rgba(160, 51, 36, .6);
  border: 1px solid rgba(160, 51, 36, .35);
  font-family: var(--font-mono);
  font-size: 5.5px;
  letter-spacing: .06em;
  transform: rotate(-6deg);
  border-radius: 1px;
}

.mem-tone-0 .mem-card-front { --face: #ecdcbd; --face-deep: #dbc49c; --face-accent: #6f4d26; }
.mem-tone-1 .mem-card-front { --face: #e8d9bc; --face-deep: #d4bd97; --face-accent: #70532e; }
.mem-tone-2 .mem-card-front { --face: #e8dbbd; --face-deep: #d7c09a; --face-accent: #80602d; }
.mem-tone-3 .mem-card-front { --face: #e3d6b8; --face-deep: #cdb891; --face-accent: #5e4a2f; }
.mem-tone-4 .mem-card-front { --face: #e5d9bd; --face-deep: #d2bd99; --face-accent: #65523a; }
.mem-tone-5 .mem-card-front { --face: #e9dcbf; --face-deep: #d6c19e; --face-accent: #704b3b; }
.mem-tone-6 .mem-card-front { --face: #e5d7b9; --face-deep: #d2b99a; --face-accent: #4f5238; }
.mem-tone-7 .mem-card-front { --face: #eadcbe; --face-deep: #d7c19b; --face-accent: #68513b; }

.mem-card.is-matched { cursor: default; }
.mem-card.is-matched .mem-card-front {
  box-shadow:
    0 0 0 1px rgba(230, 201, 130, .7),
    0 0 18px rgba(230, 201, 130, .3),
    inset 0 0 28px rgba(198, 160, 90, .16);
  opacity: .88;
}
.mem-card.is-matched::after {
  content: "✓";
  position: absolute;
  z-index: 5;
  right: -3px;
  top: -3px;
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #2c1c0b;
  background: linear-gradient(160deg, #f1d28b, #bd944b);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
  font-size: 9px;
  font-weight: 700;
  animation: mem-stamp-in .28s cubic-bezier(.2, .8, .3, 1) both;
}

.mem-card.is-miss .mem-card-inner {
  animation: mem-miss-shake .34s ease both;
}
.mem-card.is-open .mem-card-inner { transform: rotateY(180deg); }

.mem-deal {
  animation: mem-deal .52s cubic-bezier(.2, .8, .3, 1) both;
  animation-delay: calc(var(--deal-i) * 28ms);
}
.mem-card.mem-deal .mem-card-inner {
  animation: mem-deal-inner .52s cubic-bezier(.2, .8, .3, 1) both;
  animation-delay: calc(var(--deal-i) * 28ms);
}

@keyframes mem-deal {
  from { opacity: 0; transform: translateY(-18px) scale(.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes mem-deal-inner {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes mem-miss-shake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  20% { transform: rotateY(180deg) translateX(-5px); }
  40% { transform: rotateY(180deg) translateX(4px); }
  60% { transform: rotateY(180deg) translateX(-3px); }
  80% { transform: rotateY(180deg) translateX(2px); }
}
@keyframes mem-stamp-in {
  from { opacity: 0; transform: scale(1.8) rotate(-30deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

/* 庆祝飘屑 */
.mem-celebration {
  position: absolute;
  inset: 0;
  z-index: 8;
  overflow: hidden;
  pointer-events: none;
}
.mem-celebration span {
  position: absolute;
  top: -12px;
  color: var(--brass-hi);
  text-shadow: 0 0 8px rgba(230, 201, 130, .5);
  animation-name: mem-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: both;
}
@keyframes mem-fall {
  0% { opacity: 0; transform: translateY(-10px) rotate(0deg); }
  12% { opacity: 1; }
  100% { opacity: 0; transform: translateY(620px) rotate(260deg); }
}

/* 侧栏 */
.mem-side .paper-card { padding: 15px 15px 14px; }
.mem-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin: 2px 0 11px;
  border: 1px solid rgba(100, 67, 32, .18);
  border-radius: 2px;
  background: rgba(100, 67, 32, .16);
}
.mem-stat {
  min-width: 0;
  padding: 9px 7px 8px;
  text-align: center;
  background: rgba(255, 249, 232, .36);
}
.mem-stat-label {
  display: block;
  color: rgba(82, 56, 27, .48);
  font-family: var(--font-mono);
  font-size: 7.5px;
  letter-spacing: .13em;
  margin-bottom: 2px;
}
.mem-stat-value {
  display: block;
  color: #4b3119;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: .02em;
}
.mem-stat:first-child .mem-stat-value { font-family: var(--font-mono); font-size: 16px; letter-spacing: -.03em; }
.mem-message {
  min-height: 36px;
  margin-bottom: 12px;
  color: rgba(74, 49, 23, .62);
  font-size: 11px;
  line-height: 1.65;
}
.mem-actions { display: flex; gap: 7px; }
.mem-actions .btn { flex: 1; justify-content: center; }

.mem-record {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px;
  border-bottom: 1px dashed rgba(101, 69, 34, .16);
  color: rgba(76, 51, 25, .62);
  font-size: 11.5px;
}
.mem-record:first-of-type { padding-top: 2px; }
.mem-record:last-of-type { border-bottom: 0; }
.mem-record b {
  color: #503319;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .03em;
}
.mem-rules-card .rules-details summary { padding-bottom: 0; }
.mem-rules-card .rules-details[open] summary { margin-bottom: 7px; }

/* 胜利弹窗 */
.mem-win { text-align: center; }
.mem-win-stats {
  display: flex;
  justify-content: center;
  gap: 0;
  margin: 3px 0 14px;
  border: 1px solid rgba(100, 67, 32, .2);
  border-radius: 2px;
  background: rgba(255, 250, 235, .3);
}
.mem-win-stats > div {
  flex: 1;
  padding: 10px 6px 8px;
  border-right: 1px solid rgba(100, 67, 32, .13);
}
.mem-win-stats > div:last-child { border-right: 0; }
.mem-win-stats span {
  display: block;
  color: rgba(79, 54, 25, .48);
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: .12em;
}
.mem-win-stats b {
  display: block;
  margin-top: 2px;
  color: #4a2f17;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
}
.mem-win p { color: rgba(57, 37, 17, .68); font-size: 11.5px; line-height: 1.8; }
.mem-new-record { color: #9a3828; font-weight: 600; }

/* 响应式 */
@media (max-width: 1080px) {
  .mem-table { max-width: 600px; }
  .mem-board { max-width: 470px; }
}

@media (max-width: 900px) {
  .mem-stage { padding: 14px; }
  .mem-side { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: 10px; }
  .mem-side .mem-rules-card { grid-column: 1 / -1; }
  .mem-table { max-width: 580px; }
  .mem-board { max-width: 450px; }
}

@media (max-width: 600px) {
  .mem-stage { padding: 8px; }
  .mem-table { padding: 11px 10px 9px; border-radius: 6px; }
  .mem-table::before { inset: 4px; }
  .mem-table-top { padding-bottom: 8px; font-size: 6.5px; letter-spacing: .12em; }
  .mem-table-bottom { padding-top: 7px; }
  .mem-table-tip { font-size: 8px; }
  .mem-pairs { gap: 3px; }
  .mem-pairs i { width: 4px; height: 4px; }
  .mem-board { gap: 6px; }
  .mem-card { border-radius: 4px; }
  .mem-card-back-frame { inset: 7px; }
  .mem-back-seal { border-radius: 1px; font-size: 17px; }
  .mem-back-corner { width: 6px; height: 6px; }
  .mem-back-corner.tl { left: 6px; top: 6px; }
  .mem-back-corner.tr { right: 6px; top: 6px; }
  .mem-back-corner.bl { left: 6px; bottom: 6px; }
  .mem-back-corner.br { right: 6px; bottom: 6px; }
  .mem-face-label { font-size: 6.5px; letter-spacing: .04em; }
  .mem-face-stamp { display: none; }
  .mem-card-front::before { inset: 4px; }
  .mem-card-front::after { inset: 7px; }
  .mem-side { grid-template-columns: minmax(0, 1fr); }
  .mem-side .mem-rules-card { grid-column: auto; }
  .mem-stat-value { font-size: 16px; }
  .mem-stat:first-child .mem-stat-value { font-size: 14px; }
  .mem-message { min-height: 0; margin-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .mem-card, .mem-card-inner { transition-duration: .01ms !important; }
  .mem-card.is-miss .mem-card-inner { animation: none !important; }
  .mem-deal, .mem-card.mem-deal .mem-card-inner { animation: none !important; opacity: 1 !important; }
  .mem-celebration { display: none; }
}
