.memory-shell {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto 48px;
}

.memory-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin: 26px 0 22px;
  padding: 28px;
  border: 3px solid #ffffff;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 88% 22%, #fff4bd 0 34px, transparent 35px),
    linear-gradient(45deg, rgba(216, 220, 255, 0.32) 25%, transparent 25% 75%, rgba(216, 220, 255, 0.32) 75%),
    #fffefe;
  background-size: auto, 34px 34px, auto;
  box-shadow: 0 0 0 8px #6f86c8, 10px 10px 0 rgba(111, 134, 200, 0.24);
}

.memory-hero h1,
.memory-board-header h2 {
  margin: 0;
}

.memory-hero h1 {
  font-size: clamp(2.2rem, 8vw, 4.8rem);
  line-height: 0.95;
}

.memory-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  align-items: start;
}

.memory-board-panel,
.memory-panel {
  border: 3px solid #ffffff;
  border-radius: var(--radius);
  background: #fffefe;
  box-shadow: 0 0 0 7px #9fc8ee, 8px 8px 0 rgba(111, 134, 200, 0.22);
}

.memory-board-panel {
  position: relative;
  padding: 18px;
}

.memory-board-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.memory-board-header h2 {
  color: #52649d;
  font-size: clamp(1.6rem, 4vw, 2.6rem);
}

.memory-status {
  max-width: 340px;
  margin: 0;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.45;
  text-align: right;
}

.memory-board {
  --memory-columns: 4;
  --memory-card-size: clamp(88px, 11vw, 118px);
  display: grid;
  grid-template-columns: repeat(var(--memory-columns), minmax(64px, var(--memory-card-size)));
  justify-content: center;
  align-content: center;
  min-height: 520px;
  gap: clamp(8px, 1.6vw, 14px);
}

.memory-card {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  border-radius: 16px;
  background: transparent;
  cursor: pointer;
  perspective: 900px;
  transform: translateY(12px) scale(0.96);
  animation: cardDeal 420ms ease forwards;
}

.memory-card:disabled {
  cursor: default;
}

.memory-card-inner {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  transform-style: preserve-3d;
  transition: transform 520ms cubic-bezier(.2, .72, .18, 1);
}

.memory-card.is-flipped .memory-card-inner,
.memory-card.is-matched .memory-card-inner {
  transform: rotateY(180deg);
}

.memory-card.is-matched {
  animation: matchedPop 560ms ease both;
}

.memory-card.is-mismatch {
  animation: mismatchShake 260ms ease both;
}

.memory-card.is-new-match {
  animation: matchedPop 560ms ease both, matchFloat 780ms ease both;
}

.memory-card.is-new-match::before {
  content: "";
  position: absolute;
  inset: -14%;
  z-index: 3;
  border-radius: 22px;
  background:
    radial-gradient(circle at 20% 22%, rgba(255, 244, 189, 0.95) 0 5px, transparent 6px),
    radial-gradient(circle at 82% 18%, rgba(255, 183, 211, 0.95) 0 4px, transparent 5px),
    radial-gradient(circle at 74% 78%, rgba(157, 219, 248, 0.95) 0 5px, transparent 6px),
    radial-gradient(circle at 28% 82%, rgba(255, 244, 189, 0.82) 0 3px, transparent 4px);
  opacity: 0;
  pointer-events: none;
  animation: sparkleBurst 780ms ease-out both;
}

.memory-card.is-new-match .memory-card-face {
  animation: matchGlow 780ms ease both;
}

.memory-card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 3px solid #fffefe;
  border-radius: inherit;
  backface-visibility: hidden;
  box-shadow: 0 0 0 4px rgba(111, 134, 200, 0.75), 5px 5px 0 rgba(255, 183, 211, 0.2);
}

.memory-card-back {
  background:
    radial-gradient(circle at 68% 28%, rgba(255, 244, 189, 0.9) 0 14px, transparent 15px),
    linear-gradient(45deg, rgba(255, 183, 211, 0.3) 25%, transparent 25% 75%, rgba(255, 183, 211, 0.3) 75%),
    #d8dcff;
  background-size: auto, 18px 18px, auto;
}

.memory-card-back::after {
  content: "L";
  display: grid;
  place-items: center;
  width: 44%;
  aspect-ratio: 1;
  border: 3px solid #fffefe;
  border-radius: 50%;
  background: #fff7fb;
  color: #6f86c8;
  font-weight: 900;
  font-size: clamp(1.2rem, 4vw, 2rem);
  box-shadow: 4px 4px 0 rgba(111, 134, 200, 0.18);
}

.memory-card-front {
  background: #fff7fb;
  transform: rotateY(180deg);
}

.memory-card-front img {
  width: 86%;
  height: 86%;
  object-fit: contain;
  filter: drop-shadow(0 8px 0 rgba(111, 134, 200, 0.12));
}

.memory-placeholder {
  display: grid;
  place-items: center;
  width: 78%;
  aspect-ratio: 1;
  border-radius: 24px;
  background: linear-gradient(135deg, #ffb7d3, #9ddbf8);
  color: #fffefe;
  font-size: 2rem;
  font-weight: 900;
}

.memory-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.memory-stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 2px dashed rgba(111, 134, 200, 0.28);
}

.memory-stat-row span {
  color: var(--muted);
  font-weight: 800;
}

.memory-actions {
  display: grid;
  gap: 10px;
}

.memory-actions .button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.memory-toast {
  position: absolute;
  left: 50%;
  bottom: 22px;
  z-index: 5;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100% - 36px));
  padding: 18px;
  border: 3px solid #fffefe;
  border-radius: 18px;
  background:
    radial-gradient(circle at 88% 18%, rgba(255, 244, 189, 0.95) 0 18px, transparent 19px),
    #fff7fb;
  box-shadow: 0 0 0 6px rgba(111, 134, 200, 0.86), 8px 8px 0 rgba(255, 183, 211, 0.28);
  text-align: center;
  transform: translateX(-50%);
  animation: toastPop 260ms cubic-bezier(.2, .8, .2, 1) both;
}

.memory-toast[hidden] {
  display: none;
}

.memory-toast-kicker,
.memory-toast p,
.memory-toast h3 {
  margin: 0;
}

.memory-toast-kicker {
  color: #6f86c8;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.memory-toast h3 {
  color: #52649d;
  font-size: 1.45rem;
  line-height: 1.1;
}

.memory-toast p {
  color: var(--muted);
  font-weight: 800;
}

.memory-toast .button {
  justify-self: center;
  min-width: 150px;
}

.memory-status.is-praise {
  color: #d15f9b;
  font-family: "Comic Sans MS", "Trebuchet MS", cursive;
  font-size: clamp(1.15rem, 3vw, 1.6rem);
  font-weight: 900;
  text-shadow: 2px 2px 0 #fff4bd, 4px 4px 0 rgba(111, 134, 200, 0.14);
  animation: praisePop 420ms cubic-bezier(.2, .8, .2, 1) both;
}

.memory-results-list {
  display: grid;
  gap: 3px;
  margin-top: 8px;
  font-size: 0.9rem;
}

@keyframes cardDeal {
  to { transform: translateY(0) scale(1); }
}

@keyframes matchedPop {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.08); }
}

@keyframes matchFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-5px) scale(1.04); }
}

@keyframes matchGlow {
  0%, 100% { box-shadow: 0 0 0 4px rgba(111, 134, 200, 0.75), 5px 5px 0 rgba(255, 183, 211, 0.2); }
  45% { box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.95), 0 0 0 9px rgba(255, 183, 211, 0.45), 0 0 22px rgba(255, 244, 189, 0.8); }
}

@keyframes sparkleBurst {
  0% { opacity: 0; transform: scale(0.72) rotate(-4deg); }
  35% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.22) rotate(8deg); }
}

@keyframes praisePop {
  from { opacity: 0; transform: translateY(8px) rotate(-2deg) scale(0.9); }
  to { opacity: 1; transform: translateY(0) rotate(-1deg) scale(1); }
}

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

@keyframes toastPop {
  from { opacity: 0; transform: translateX(-50%) translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

@media (max-width: 900px) {
  .memory-layout {
    grid-template-columns: 1fr;
  }

  .memory-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .memory-actions {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 620px) {
  .memory-shell {
    width: min(100% - 24px, 1160px);
  }

  .memory-hero,
  .memory-board-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .memory-hero {
    padding: 22px;
  }

  .memory-status {
    max-width: none;
    text-align: left;
  }

  .memory-board-panel {
    padding: 12px;
  }

  .memory-board {
    --memory-card-size: clamp(44px, 12.5vw, 58px);
    grid-template-columns: repeat(var(--memory-columns), minmax(40px, var(--memory-card-size)));
    min-height: 252px;
    gap: 8px;
  }

  .memory-toast {
    bottom: 12px;
    width: min(320px, calc(100% - 24px));
    padding: 14px;
  }

  .memory-toast h3 {
    font-size: 1.2rem;
  }

  .memory-card {
    border-radius: 12px;
  }

  .memory-card-face {
    border-width: 2px;
    box-shadow: 0 0 0 3px rgba(111, 134, 200, 0.75), 3px 3px 0 rgba(255, 183, 211, 0.18);
  }

  .memory-panel {
    grid-template-columns: 1fr;
  }

  .memory-actions {
    grid-template-columns: 1fr;
  }
}
#memory-combo.is-hot {
  color: #d15f9b;
  text-shadow: 2px 2px 0 rgba(255, 244, 189, 0.9);
}