/* 기억력 테스트 세 개(숫자 기억력 · 순서 기억 · 침팬지)가 같이 쓰는 판 모양.
   판은 늘 진한 파란 바탕 + 흰 글자라서 밝은/어두운 화면 모두 같은 대비를 쓴다. */
.mem {
  --mem-bg: #3a57f5;
  --mem-ok: #138a4d;
  --mem-bad: #c2333f;
  --mem-pause: #b86e00;
  --mem-cell: rgba(255, 255, 255, 0.16);
  margin-top: 22px;
}

/* 판 위 상태 줄: 단계 · 목숨 · 최고 기록 */
.mem-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.mem-stat {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.mem-stat b {
  color: var(--ink);
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}
.mem-stat .lives {
  font-variant-emoji: text;
  font-family: 'Segoe UI Symbol', 'Apple Symbols', var(--font);
  letter-spacing: 0.08em;
  font-size: 1.05rem;
  color: var(--wait);
}
.lives .lost {
  color: var(--muted);
  opacity: 0.55;
}

/* 판 */
.mem-board {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: clamp(300px, 50vh, 420px);
  padding: clamp(14px, 3vw, 24px);
  border-radius: 26px;
  background: var(--mem-bg);
  color: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s ease;
}
.mem-board.flash-ok {
  background: var(--mem-ok);
}
.mem-board.shake {
  animation: mem-shake 0.36s ease-in-out;
}
@keyframes mem-shake {
  20%,
  60% {
    transform: translateX(-7px);
  }
  40%,
  80% {
    transform: translateX(7px);
  }
}

/* 판을 덮는 안내 화면(시작 · 정답 · 틀림 · 멈춤) */
.mem-cover {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  background: var(--mem-bg);
  color: #fff;
}
.mem-cover[data-tone='ok'] {
  background: var(--mem-ok);
}
.mem-cover[data-tone='bad'] {
  background: var(--mem-bad);
}
.mem-cover[data-tone='pause'] {
  background: var(--mem-pause);
}
.mem-icon {
  font-size: 2.6rem;
  line-height: 1;
}
.mem-title {
  font-size: clamp(1.5rem, 6vw, 2.2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
.mem-sub {
  font-size: 1rem;
  opacity: 0.92;
  max-width: 26em;
}
.mem-btn {
  margin-top: 10px;
  min-width: 160px;
  background: #fff;
  color: #1d2a7a;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}
.mem-btn:focus-visible {
  outline-color: #fff;
}
.mem-msg {
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
  min-height: 1.6em;
  margin: 12px 0 0;
}
.mem-newbest {
  display: inline-block;
  margin: 0 0 10px;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 800;
  font-size: 0.9rem;
}

/* ── 숫자 기억력 ── */
.nm-show {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  width: 100%;
}
.nm-num {
  margin: 0;
  max-width: 100%;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
  overflow-wrap: anywhere;
}
.nm-bar {
  width: min(100%, 360px);
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
}
.nm-bar span {
  display: block;
  height: 100%;
  background: #fff;
  transform-origin: left center;
}
.nm-ask {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(100%, 440px);
}
.nm-ask-label {
  font-weight: 800;
  font-size: 1.2rem;
}
.nm-input {
  appearance: none;
  width: 100%;
  font: inherit;
  font-size: clamp(1.4rem, 6vw, 2rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: #141824;
  background: #fff;
  border: 3px solid transparent;
  border-radius: 16px;
  padding: 10px 12px;
  min-height: 60px;
  user-select: text;
  -webkit-user-select: text;
}
.nm-input:focus {
  outline: none;
  border-color: #ffd34d;
}
.nm-ask .mem-btn {
  margin-top: 0;
}
.nm-compare {
  margin: 22px 0 0;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface-2);
  text-align: left;
}
.nm-row {
  display: grid;
  grid-template-columns: 3.4em 1fr;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.nm-row-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}
.nm-digits {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.nm-digits .d {
  display: inline-grid;
  place-items: center;
  min-width: 1.45em;
  height: 1.9em;
  border-radius: 6px;
  background: var(--surface);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  border-bottom: 3px solid transparent;
}
.nm-digits .d.bad {
  color: var(--wait);
  border-bottom-color: var(--wait);
}
.nm-digits .d.miss {
  border-bottom-color: var(--muted);
}
.nm-compare .fine {
  margin: 8px 0 0;
}

/* ── 순서 기억 ── */
.seq-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 2.4vw, 14px);
  width: min(100%, 380px);
  aspect-ratio: 1;
}
.seq-cell {
  appearance: none;
  border: 0;
  border-radius: 18px;
  background: var(--mem-cell);
  color: #1d2a7a;
  font: inherit;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.12s ease, transform 0.12s ease;
}
.seq-cell.on,
.seq-cell.hit {
  background: #fff;
  transform: scale(0.96);
}
.seq-cell.bad {
  background: var(--mem-bad);
  color: #fff;
  font-size: 1.8rem;
}
.seq-cell.want {
  background: rgba(255, 255, 255, 0.35);
  outline: 3px dashed #fff;
  outline-offset: -6px;
  color: #fff;
}
.seq-grid[aria-busy='true'] .seq-cell {
  cursor: default;
}
.seq-cell:focus-visible {
  outline: 3px solid #ffd34d;
  outline-offset: 2px;
}

/* ── 침팬지 ── */
.chimp-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: clamp(5px, 1.2vw, 9px);
  width: 100%;
}
@media (max-width: 560px) {
  .chimp-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}
.ch-cell {
  aspect-ratio: 1;
  border-radius: 12px;
}
button.ch-cell {
  appearance: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font: inherit;
  font-weight: 800;
  font-size: clamp(1.15rem, 4.2vw, 1.7rem);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button.ch-cell.masked {
  background: #fff;
  color: transparent;
}
button.ch-cell.bad {
  background: var(--mem-bad);
  border-color: var(--mem-bad);
  color: #fff;
}
button.ch-cell.done {
  visibility: hidden;
}
button.ch-cell:focus-visible {
  outline: 3px solid #ffd34d;
  outline-offset: 2px;
}
.chimp-board {
  min-height: 0;
}

@media (prefers-reduced-motion: reduce) {
  .mem-board.shake {
    animation: none;
  }
}
