.memory-match-page {
  background:
    radial-gradient(circle at top left, rgba(124, 255, 178, 0.16), transparent 34%),
    radial-gradient(circle at top right, rgba(255, 119, 198, 0.16), transparent 28%),
    linear-gradient(180deg, #071017 0%, #06080d 42%, #050608 100%);
}

.memory-main {
  width: min(1480px, calc(100% - 28px));
  padding: 12px 0 18px;
  gap: 10px;
}

.memory-top {
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 10px;
}

.memory-hero,
.memory-panel,
.memory-stage-wrap {
  position: relative;
  overflow: hidden;
}

.memory-hero::before,
.memory-panel::before,
.memory-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.06), transparent 42%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 18px);
  opacity: 0.45;
}

.memory-hero > *,
.memory-panel > *,
.memory-stage > * {
  position: relative;
  z-index: 1;
}

.memory-hero {
  padding: 12px 14px;
}

.memory-toolbar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px 18px;
}

.memory-toolbar-copy {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.memory-title-row {
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
}

.memory-hero h1 {
  margin: 0;
  font-size: clamp(22px, 2.3vw, 32px);
  line-height: 1;
}

.memory-hero p {
  margin: 0;
  max-width: 56rem;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.memory-hero kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5em;
  padding: 0 0.34em;
  border: 1px solid rgba(124, 255, 178, 0.28);
  border-radius: 999px;
  background: rgba(124, 255, 178, 0.08);
  color: #f7fffb;
  font: inherit;
  font-size: 0.92em;
}

.memory-rule-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 0;
}

.memory-rule-row .chip {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(124, 255, 178, 0.2);
  font-size: 11px;
}

.memory-controls {
  margin-top: 0;
  align-self: start;
  flex-shrink: 0;
}

.memory-toolbar-bottom {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(520px, 1.45fr);
  gap: 10px 14px;
  align-items: center;
  margin-top: 10px;
}

.memory-status {
  margin-top: 0;
  max-width: none;
  padding: 10px 12px;
  min-height: auto;
  border-radius: 12px;
  border: 1px solid rgba(124, 255, 178, 0.12);
  background: rgba(255, 255, 255, 0.03);
  font-size: 12px;
  line-height: 1.45;
}

.memory-panel {
  border: 0;
  padding: 0;
  background: transparent;
}

.memory-panel::before {
  display: none;
}

.memory-panel h3 {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.memory-hud-list {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.memory-hud-list li {
  padding: 8px 9px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
}

.memory-hud-list span {
  font-size: 10px;
  margin-bottom: 4px;
}

.memory-hud-list strong {
  font-size: 14px;
}

.memory-stage-wrap {
  overflow: visible;
  padding: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
    linear-gradient(135deg, rgba(124, 255, 178, 0.1), rgba(255, 119, 198, 0.08));
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.28);
}

.memory-stage {
  min-height: 0;
  padding: 14px 14px 18px;
  background:
    radial-gradient(circle at top center, rgba(124, 255, 178, 0.12), transparent 34%),
    linear-gradient(180deg, rgba(8, 12, 19, 0.98), rgba(3, 5, 8, 0.99));
  overflow: visible;
}

.memory-stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  margin-bottom: 10px;
}

.memory-stage-note {
  max-width: none;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  text-align: right;
}

.memory-board-zone {
  position: relative;
  width: min(100%, clamp(540px, calc((100vh - 350px) * 1.14), 920px));
  width: min(100%, clamp(540px, calc((100svh - 350px) * 1.14), 920px));
  margin: 0 auto;
  display: grid;
  place-items: center;
}

.memory-board {
  --memory-gap: clamp(6px, 0.68vw, 10px);
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--memory-gap);
  width: 100%;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.memory-card {
  position: relative;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  aspect-ratio: 1 / 1;
  perspective: 1200px;
  transition: transform 140ms ease;
}

.memory-card:hover {
  transform: translateY(-2px);
}

.memory-card:focus-visible {
  outline: 2px solid rgba(124, 255, 178, 0.85);
  outline-offset: 4px;
  border-radius: 20px;
}

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

.memory-card.is-intro {
  opacity: 0;
  transform: translateY(34px) scale(0.88);
  animation: memory-card-in 620ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: var(--entry-delay, 0ms);
}

.memory-card.is-intro:hover {
  transform: translateY(34px) scale(0.88);
}

.memory-card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 460ms cubic-bezier(0.22, 1, 0.36, 1), opacity 300ms ease, scale 300ms ease, filter 300ms ease;
}

.memory-card.is-revealed .memory-card-inner,
.memory-card.is-match .memory-card-inner,
.memory-card.is-cleared .memory-card-inner {
  transform: rotateY(180deg);
}

.memory-card.is-match {
  animation: memory-match-pop 420ms ease;
}

.memory-card.is-mismatch {
  animation: memory-mismatch 420ms ease;
}

.memory-card.is-cleared {
  pointer-events: none;
}

.memory-card.is-cleared .memory-card-inner {
  opacity: 0.1;
  scale: 0.88;
}

.memory-board.is-celebrating {
  overflow: visible;
}

.memory-board.is-celebrating .memory-card {
  z-index: 2;
}

.memory-board.is-celebrating .memory-card.is-cleared .memory-card-inner {
  opacity: 1;
  scale: 1;
  filter: saturate(1.16) brightness(1.08);
  animation: memory-card-launch 980ms cubic-bezier(0.18, 0.9, 0.2, 1) forwards;
  animation-delay: var(--fly-delay, 0ms);
  will-change: transform, opacity, filter;
}

.memory-card-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.memory-card-back {
  background:
    radial-gradient(circle at top left, rgba(124, 255, 178, 0.22), transparent 42%),
    linear-gradient(180deg, #121d29 0%, #0a1018 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    0 14px 34px rgba(0, 0, 0, 0.24);
}

.memory-card-back::before,
.memory-card-back::after {
  content: "";
  position: absolute;
  border-radius: 16px;
}

.memory-card-back::before {
  inset: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.memory-card-back::after {
  inset: 14px;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0 4px, transparent 4px 12px),
    radial-gradient(circle at center, rgba(124, 255, 178, 0.16), transparent 62%);
}

.memory-card-brand {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 8px;
  place-items: center;
  text-align: center;
}

.memory-card-brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(124, 255, 178, 0.9), rgba(255, 119, 198, 0.82));
  box-shadow: 0 10px 30px rgba(124, 255, 178, 0.22);
}

.memory-card-brand-text {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.84);
}

.memory-card-front {
  transform: rotateY(180deg);
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(circle at top, hsla(var(--pair-hue), 92%, 68%, 0.42), transparent 46%),
    linear-gradient(180deg, hsla(var(--pair-hue), 54%, 20%, 0.92), rgba(7, 11, 17, 0.98));
  border-color: hsla(var(--pair-hue), 88%, 70%, 0.42);
  box-shadow:
    inset 0 0 0 1px hsla(var(--pair-hue), 78%, 74%, 0.1),
    0 18px 44px rgba(0, 0, 0, 0.28);
}

.memory-card-front::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 14px;
  border: 1px solid hsla(var(--pair-hue), 88%, 70%, 0.18);
}

.memory-card-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(38px, 3.6vw, 52px);
  height: clamp(38px, 3.6vw, 52px);
  border-radius: 16px;
  background: hsla(var(--pair-hue), 95%, 72%, 0.18);
  box-shadow: 0 14px 32px hsla(var(--pair-hue), 88%, 54%, 0.18);
  font-size: clamp(22px, 2.3vw, 30px);
  line-height: 1;
}

.memory-card-label {
  padding: 0 8px;
  text-align: center;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.84);
}

.memory-win-overlay {
  inset: clamp(10px, 1.6vw, 18px);
  z-index: 4;
  border-radius: 24px;
  background:
    radial-gradient(circle at center, rgba(124, 255, 178, 0.14), rgba(4, 8, 12, 0.78) 44%, rgba(3, 7, 12, 0.84) 100%);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.memory-win-overlay::before {
  content: "";
  position: absolute;
  inset: 8% 12%;
  border-radius: 999px;
  border: 1px solid rgba(124, 255, 178, 0.14);
  pointer-events: none;
}

.memory-celebration-rings {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.memory-celebration-rings span {
  position: absolute;
  border-radius: 999px;
  border: 1px solid rgba(124, 255, 178, 0.24);
  box-shadow: 0 0 40px rgba(124, 255, 178, 0.1);
  animation: memory-ring-pulse 2.6s ease-out infinite;
}

.memory-celebration-rings span:nth-child(1) {
  width: min(58vw, 340px);
  height: min(58vw, 340px);
}

.memory-celebration-rings span:nth-child(2) {
  width: min(74vw, 430px);
  height: min(74vw, 430px);
  border-color: rgba(255, 119, 198, 0.2);
  animation-delay: 0.22s;
}

.memory-celebration-rings span:nth-child(3) {
  width: min(88vw, 520px);
  height: min(88vw, 520px);
  border-color: rgba(114, 214, 255, 0.18);
  animation-delay: 0.44s;
}

.memory-win-overlay:not(.hidden) .memory-win-card {
  animation: memory-overlay-pop 540ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.memory-win-card {
  position: relative;
  overflow: hidden;
  width: min(500px, calc(100% - 8px));
  padding: 20px 20px 22px;
  background:
    radial-gradient(circle at top, rgba(124, 255, 178, 0.16), transparent 38%),
    linear-gradient(180deg, rgba(13, 17, 27, 0.98), rgba(7, 9, 15, 0.98));
  box-shadow:
    0 30px 90px rgba(0, 0, 0, 0.45),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.memory-win-card::before {
  content: "";
  position: absolute;
  inset: -10% 18% auto;
  height: 220px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(124, 255, 178, 0.2), transparent 68%);
  pointer-events: none;
}

.memory-win-card::after {
  content: "";
  position: absolute;
  inset: auto -8% -32%;
  height: 160px;
  background: radial-gradient(circle, rgba(255, 119, 198, 0.18), transparent 66%);
  pointer-events: none;
}

.memory-final-copy {
  max-width: 30rem;
  margin: 0 auto;
}

.memory-finish-stats {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.memory-finish-stats article {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.memory-finish-stats span {
  display: block;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.memory-finish-stats strong {
  font-size: clamp(24px, 4vw, 34px);
  color: var(--accent);
}

.memory-celebration-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.memory-celebration-burst span {
  --burst-rotate: 0deg;
  --burst-color: #7cffb2;
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--burst-color);
  box-shadow: 0 0 24px var(--burst-color);
  animation: memory-burst 1.8s ease-in-out infinite;
  animation-delay: var(--burst-delay, 0s);
}

.memory-celebration-burst span:nth-child(1) {
  --burst-rotate: 0deg;
  --burst-color: #7cffb2;
}

.memory-celebration-burst span:nth-child(2) {
  --burst-rotate: 36deg;
  --burst-color: #ff77c6;
  --burst-delay: 0.08s;
}

.memory-celebration-burst span:nth-child(3) {
  --burst-rotate: 72deg;
  --burst-color: #ffd36a;
  --burst-delay: 0.16s;
}

.memory-celebration-burst span:nth-child(4) {
  --burst-rotate: 108deg;
  --burst-color: #72d6ff;
  --burst-delay: 0.24s;
}

.memory-celebration-burst span:nth-child(5) {
  --burst-rotate: 144deg;
  --burst-color: #c690ff;
  --burst-delay: 0.32s;
}

.memory-celebration-burst span:nth-child(6) {
  --burst-rotate: 180deg;
  --burst-color: #7cffb2;
  --burst-delay: 0.4s;
}

.memory-celebration-burst span:nth-child(7) {
  --burst-rotate: 216deg;
  --burst-color: #ff8f6a;
  --burst-delay: 0.48s;
}

.memory-celebration-burst span:nth-child(8) {
  --burst-rotate: 252deg;
  --burst-color: #56f0d1;
  --burst-delay: 0.56s;
}

.memory-celebration-burst span:nth-child(9) {
  --burst-rotate: 288deg;
  --burst-color: #ffe66b;
  --burst-delay: 0.64s;
}

.memory-celebration-burst span:nth-child(10) {
  --burst-rotate: 324deg;
  --burst-color: #ff77c6;
  --burst-delay: 0.72s;
}

.memory-bottom-nav {
  display: flex;
  justify-content: center;
  margin-top: 0;
}

.memory-stage-wrap:fullscreen,
.memory-stage-wrap:-webkit-full-screen {
  overflow: hidden;
  padding: 18px;
}

.memory-stage-wrap:fullscreen .memory-stage,
.memory-stage-wrap:-webkit-full-screen .memory-stage {
  padding: 20px;
}

.memory-stage-wrap:fullscreen .memory-board-zone,
.memory-stage-wrap:-webkit-full-screen .memory-board-zone {
  width: min(100%, clamp(620px, calc((100vh - 210px) * 1.16), 1120px));
  width: min(100%, clamp(620px, calc((100svh - 210px) * 1.16), 1120px));
}

.memory-stage-wrap:fullscreen .memory-board,
.memory-stage-wrap:-webkit-full-screen .memory-board {
  height: auto;
  align-content: start;
  max-width: none;
}

@keyframes memory-card-in {
  0% {
    opacity: 0;
    transform: translateY(34px) scale(0.88);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes memory-match-pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes memory-mismatch {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-6px);
  }
  60% {
    transform: translateX(6px);
  }
}

@keyframes memory-burst {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--burst-rotate)) translateY(-20px) scale(0.5);
  }
  15% {
    opacity: 1;
  }
  85% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--burst-rotate)) translateY(-140px) scale(1.1);
  }
}

@keyframes memory-card-launch {
  0% {
    opacity: 1;
    filter: saturate(1.16) brightness(1.08);
    transform: rotateY(180deg) rotate(0deg) translate3d(0, 0, 0) scale(1);
  }
  18% {
    opacity: 1;
    transform: rotateY(180deg) rotate(var(--fly-rotate)) translate3d(0, -16px, 0) scale(1.08);
  }
  100% {
    opacity: 0;
    filter: blur(1.4px) saturate(1.35) brightness(1.28);
    transform: rotateY(180deg) rotate(var(--fly-spin)) translate3d(var(--fly-x), var(--fly-y), 0) scale(0.6);
  }
}

@keyframes memory-ring-pulse {
  0% {
    opacity: 0;
    transform: scale(0.76);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(1.08);
  }
}

@keyframes memory-overlay-pop {
  0% {
    opacity: 0;
    transform: translateY(22px) scale(0.88);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 1180px) {
  .memory-toolbar-top {
    flex-wrap: wrap;
  }

  .memory-controls {
    width: 100%;
  }

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

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

  .memory-board-zone {
    width: min(100%, 860px);
  }
}

@media (max-width: 920px) {
  .memory-board {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .memory-board-zone {
    width: min(100%, 900px);
  }
}

@media (max-width: 760px) {
  .memory-main {
    width: min(100%, calc(100% - 20px));
  }

  .memory-title-row,
  .memory-stage-head {
    flex-direction: column;
    align-items: start;
  }

  .memory-stage-note {
    text-align: left;
  }

  .memory-hud-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .memory-board-zone {
    width: 100%;
  }

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

  .memory-card-label {
    font-size: 9px;
    letter-spacing: 0.12em;
  }
}

@media (max-width: 520px) {
  .memory-toolbar-top,
  .memory-controls {
    gap: 8px;
  }

  .memory-controls .btn {
    width: 100%;
  }

  .memory-stage,
  .memory-stage-wrap {
    padding: 10px;
  }

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

  .memory-card-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    font-size: 24px;
  }

  .memory-card-label {
    display: none;
  }
}
