.aa-memory {
  --aa-radius: 18px;
  --aa-card-radius: 2px;
  --aa-shadow: 0 18px 50px rgba(0,0,0,0.18);
  --aa-soft-shadow: 0 10px 30px rgba(0,0,0,0.10);
  --aa-bg: rgba(255,255,255,0.82);
  --aa-text: #121212;
  --aa-muted: rgba(18,18,18,0.64);
  --aa-border: rgba(18,18,18,0.10);
  --aa-player: #2B6CB0;
  color: var(--aa-text);
}

.aa-memory__app {
  border-radius: var(--aa-radius);
  background: radial-gradient(1200px 600px at 10% 0%, rgba(255,255,255,0.80), rgba(255,255,255,0.55)),
    radial-gradient(900px 500px at 90% 20%, rgba(255,255,255,0.55), rgba(255,255,255,0.35));
  box-shadow: inset 0 0 0 1px var(--aa-border);
  overflow: hidden;
  position: relative;
}

.aa-memory__app::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(900px 520px at 30% 20%, color-mix(in srgb, var(--aa-player) 18%, transparent), transparent 62%),
    radial-gradient(900px 520px at 80% 60%, color-mix(in srgb, var(--aa-player) 10%, transparent), transparent 60%);
  opacity: 0.75;
  pointer-events: none;
}

.aa-memory-ui,
.aa-memory-start {
  position: relative;
  z-index: 1;
}

.aa-memory__footer {
  margin-top: 10px;
  font-size: 12px;
  color: var(--aa-muted);
}

.aa-memory__footer a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.aa-memory-ui {
  padding: clamp(14px, 2.5vw, 22px);
}

.aa-memory-ui__topbar {
  display: grid;
  gap: 10px;
  align-items: center;
  grid-template-columns: 1fr;
  margin-bottom: 14px;
}

@media (min-width: 720px) {
  .aa-memory-ui__topbar {
    grid-template-columns: 1fr auto auto;
  }
}

.aa-memory-ui__scores {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.aa-memory-ui__score {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.70);
  box-shadow: inset 0 0 0 1px var(--aa-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 15px;
}

.aa-memory-ui__pill {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--aa-player);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.75);
}

.aa-memory-ui__turn {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(255,255,255,0.85), rgba(255,255,255,0.55));
  box-shadow: inset 0 0 0 1px var(--aa-border), var(--aa-soft-shadow);
}

.aa-memory-ui__turnBadge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--aa-player);
  color: white;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.18);
}

.aa-memory-ui__turnText {
  font-size: 15px;
  color: var(--aa-muted);
}

.aa-memory-ui__actions {
  display: flex;
  gap: 10px;
  justify-self: start;
}

@media (min-width: 720px) {
  .aa-memory-ui__actions {
    justify-self: end;
  }
}

.aa-memory-ui__iconBtn {
  all: unset;
  cursor: pointer;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.70);
  box-shadow: inset 0 0 0 1px var(--aa-border), var(--aa-soft-shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.aa-memory-ui__iconBtn:focus-visible {
  outline: 3px solid rgba(0,0,0,0.18);
  outline-offset: 2px;
}

.aa-memory-ui__iconBtn:hover {
  background: rgba(255,255,255,0.86);
}

.aa-memory-fs {
  position: fixed;
  inset: 0;
  z-index: 9997;
  display: none;
  padding: 16px;
  background: radial-gradient(1200px 700px at 10% 0%, rgba(255,255,255,0.85), rgba(255,255,255,0.60)),
    radial-gradient(900px 600px at 90% 20%, rgba(255,255,255,0.60), rgba(255,255,255,0.40));
}

.aa-memory-fs.is-on {
  display: grid;
  grid-template-rows: 1fr;
  gap: 0;
}

.aa-memory-fs__stage {
  overflow: hidden;
  border-radius: 16px;
  box-shadow: inset 0 0 0 1px var(--aa-border), var(--aa-shadow);
  background: rgba(255,255,255,0.70);
  height: 100%;
}

body.aa-memory-noScroll {
  overflow: hidden;
  touch-action: none;
}

/* Fullscreen layout: ensure grid can fit without scrollbars */
.aa-memory-fs .aa-memory__app {
  height: 100%;
}

.aa-memory-fs .aa-memory-ui {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.aa-memory-fs .aa-memory-ui__topbar {
  margin-bottom: 10px;
}

.aa-memory-fs .aa-memory-ui__grid {
  flex: 1;
  align-content: start;
  margin-top: auto;
  margin-bottom: auto;
}

.aa-memory-ui__grid {
  display: grid;
  gap: var(--aa-gap, clamp(10px, 1.8vw, 14px));
  grid-template-columns: repeat(auto-fit, minmax(clamp(86px, 18vw, 132px), 1fr));
}

.aa-memory-ui__grid[data-aa-cols] {
  grid-template-columns: repeat(var(--aa-cols), var(--aa-cell, minmax(0, 1fr)));
  justify-content: center;
  width: max-content;
  max-width: 100%;
  margin-inline: auto;
}

.aa-memory-card {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--aa-card-radius);
  perspective: 900px;
}

.aa-memory-card button {
  all: unset;
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border-radius: var(--aa-card-radius);
}

.aa-memory-card__inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 640ms cubic-bezier(.18,.95,.12,1);
}

.aa-memory-card.is-revealed .aa-memory-card__inner,
.aa-memory-card.is-matched .aa-memory-card__inner {
  transform: rotateY(180deg);
}

.aa-memory-card__face {
  position: absolute;
  inset: 0;
  border-radius: var(--aa-card-radius);
  backface-visibility: hidden;
  overflow: hidden;
  box-shadow: var(--aa-soft-shadow);
  transform: translateZ(0);
}

.aa-memory-card__back {
  background: linear-gradient(135deg, rgba(0,0,0,0.06), rgba(0,0,0,0.02));
  box-shadow: inset 0 0 0 1px var(--aa-border), var(--aa-soft-shadow);
}

.aa-memory-card__backBg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  filter: saturate(1.05) contrast(1.05);
  opacity: 0.98;
}

.aa-memory-card__backGlow {
  position: absolute;
  inset: -40%;
  background: radial-gradient(circle at 30% 20%, rgba(255,255,255,0.55), rgba(255,255,255,0) 55%);
  transform: rotate(18deg);
  mix-blend-mode: screen;
  opacity: 0.55;
}

.aa-memory-card__front {
  transform: rotateY(180deg);
  background: rgba(255,255,255,0.88);
  box-shadow: inset 0 0 0 1px var(--aa-border), var(--aa-soft-shadow);
}

.aa-memory-card__frontFrame {
  position: absolute;
  inset: 0;
  border-radius: var(--aa-card-radius);
  box-shadow: inset 0 0 0 var(--aa-front-border, 6px) var(--aa-outline, #fff);
}

.aa-memory-card__frontImage {
  position: absolute;
  inset: 10px;
  border-radius: 1px;
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
}

.aa-memory-card.is-matched {
  opacity: 0.92;
}

.aa-memory-card.is-matched .aa-memory-card__front {
  box-shadow: inset 0 0 0 1px rgba(18,18,18,0.06), 0 12px 30px rgba(0,0,0,0.10);
}

.aa-memory-card.is-matched .aa-memory-card__frontImage {
  filter: saturate(1.06) contrast(1.03);
}

.aa-memory-card.is-matchPulse {
  animation: aa-memory-pulse 520ms cubic-bezier(.2,.9,.2,1);
}

@keyframes aa-memory-pulse {
  0% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-2px) scale(1.03); }
  100% { transform: translateY(0) scale(1); }
}

.aa-memory-start {
  padding: clamp(14px, 4vw, 28px);
}

.aa-memory-start__panel {
  border-radius: 20px;
  background: rgba(255,255,255,0.78);
  box-shadow: inset 0 0 0 1px var(--aa-border), var(--aa-shadow);
  padding: clamp(16px, 2.8vw, 24px);
}

.aa-memory-start__panel--setup {
  padding: clamp(22px, 5vw, 44px) clamp(18px, 4vw, 40px);
  max-width: 920px;
  margin-inline: auto;
}

.aa-memory-start__title {
  font-size: clamp(28px, 6vw, 44px);
  font-weight: 900;
  letter-spacing: -0.03em;
  text-align: center;
  margin: 0 0 clamp(28px, 5vw, 48px);
  line-height: 1.05;
}

.aa-memory-start__section {
  margin-bottom: clamp(32px, 6vw, 56px);
}

.aa-memory-start__section:last-of-type {
  margin-bottom: 0;
}

.aa-memory-start__section + .aa-memory-start__section {
  padding-top: clamp(24px, 5vw, 40px);
  border-top: 1px solid var(--aa-border);
  margin-top: clamp(8px, 2vw, 16px);
}

.aa-memory-start__label {
  font-size: clamp(16px, 2.6vw, 20px);
  font-weight: 750;
  color: var(--aa-text);
  margin-bottom: clamp(14px, 3vw, 22px);
  letter-spacing: -0.02em;
}

.aa-memory-choice {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.aa-memory-choice--tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(10px, 2.5vw, 16px);
  width: 100%;
}

.aa-memory-choice--tiles.aa-memory-choice--tilesCount {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  max-width: 420px;
}

@media (max-width: 520px) {
  .aa-memory-choice--tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .aa-memory-choice--tiles:not(.aa-memory-choice--tilesCount) {
    max-width: 560px;
  }
}

.aa-memory-choice__tile {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  aspect-ratio: 1 / 1;
  min-height: clamp(64px, 18vw, 112px);
  display: grid;
  place-items: center;
  border-radius: 2px;
  background: rgba(255,255,255,0.88);
  box-shadow: inset 0 0 0 1px var(--aa-border), var(--aa-soft-shadow);
  font-size: clamp(22px, 6vw, 40px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  transition: transform 120ms ease, box-shadow 200ms ease, background 200ms ease;
}

.aa-memory-choice__tile:focus-visible {
  outline: 3px solid rgba(0,0,0,0.22);
  outline-offset: 3px;
}

.aa-memory-choice__tile:hover {
  background: rgba(255,255,255,0.96);
  box-shadow: inset 0 0 0 1px rgba(18,18,18,0.12), 0 14px 32px rgba(0,0,0,0.12);
}

.aa-memory-choice__tile.is-active {
  background: rgba(255,255,255,0.98);
  box-shadow: inset 0 0 0 2px var(--aa-player), 0 16px 36px rgba(0,0,0,0.16);
  transform: translateY(-2px);
}

.aa-memory-start__cta {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  align-items: center;
  flex-wrap: wrap;
}

.aa-memory-start__cta--setup {
  flex-direction: column;
  align-items: center;
  margin-top: clamp(36px, 7vw, 56px);
  gap: clamp(14px, 3vw, 20px);
}

.aa-memory-start__hint {
  text-align: center;
  max-width: 520px;
  margin-inline: auto;
}

.aa-memory-start__hint:empty,
.aa-memory-start__hint[hidden] {
  display: none;
}

.aa-memory-finish {
  padding: clamp(26px, 6vw, 54px) clamp(18px, 4vw, 44px);
  text-align: center;
}

.aa-memory-finish__headline {
  font-size: clamp(34px, 7vw, 56px);
  font-weight: 950;
  letter-spacing: -0.04em;
  margin: 0 0 14px;
  line-height: 1.02;
  color: var(--aa-player, var(--aa-text));
}

.aa-memory-finish__winner {
  font-size: clamp(22px, 4.2vw, 32px);
  font-weight: 900;
  letter-spacing: -0.03em;
  margin: 0 0 10px;
}

.aa-memory-finish__sub {
  font-size: clamp(16px, 3vw, 20px);
  color: var(--aa-muted);
  margin: 0 0 28px;
}

.aa-memory-finish__scoreList {
  display: grid;
  gap: 10px;
  justify-content: center;
  margin: -8px 0 22px;
}

.aa-memory-finish__scoreLine {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.78);
  box-shadow: inset 0 0 0 1px var(--aa-border);
  font-size: 16px;
  font-weight: 750;
}

.aa-memory-finish__dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.75);
}

.aa-memory-finish__actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 10px;
}

.aa-memory-finish__primary {
  border-radius: 2px;
  padding: 16px 22px;
  font-size: 18px;
  font-weight: 900;
}

.aa-memory-linkBtn {
  all: unset;
  cursor: pointer;
  padding: 14px 18px;
  border-radius: 2px;
  background: rgba(255,255,255,0.86);
  box-shadow: inset 0 0 0 1px var(--aa-border), var(--aa-soft-shadow);
  color: var(--aa-text);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.aa-memory-linkBtn:hover {
  background: rgba(255,255,255,0.96);
}

.aa-memory-linkBtn:focus-visible {
  outline: 3px solid rgba(0,0,0,0.22);
  outline-offset: 3px;
}

.aa-memory-btn {
  all: unset;
  cursor: pointer;
  padding: 12px 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--aa-player), rgba(0,0,0,0.55));
  color: white;
  font-weight: 750;
  letter-spacing: -0.01em;
  box-shadow: 0 14px 30px rgba(0,0,0,0.18);
  transition: transform 120ms ease, filter 180ms ease;
}

/* Start button: override base reset safely (base uses all: unset) */
.aa-memory-btn.aa-memory-start__btn-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  text-align: center;
  padding: clamp(16px, 3.5vw, 22px) clamp(24px, 5vw, 36px);
  font-size: clamp(18px, 3.2vw, 24px);
  font-weight: 850;
  border-radius: 2px;
  letter-spacing: -0.02em;
}

.aa-memory-btn:hover {
  filter: brightness(1.03);
}

.aa-memory-btn:active {
  transform: translateY(1px);
}

.aa-memory-btn:focus-visible {
  outline: 3px solid rgba(0,0,0,0.18);
  outline-offset: 2px;
}

.aa-memory-note {
  font-size: 14px;
  color: var(--aa-muted);
  line-height: 1.4;
}

.aa-memory-toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 9999;
  max-width: min(520px, calc(100vw - 26px));
  padding: 18px 20px;
  border-radius: 16px;
  background: #111827;
  color: rgba(255,255,255,0.94);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  box-shadow: 0 18px 50px rgba(0,0,0,0.28);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  --aa-toast-accent: #111827;
}

.aa-memory-toast.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(-2px);
}

.aa-memory-toast--neutral {
  background: #111827;
}

.aa-memory-toast--success {
  background: #16a34a;
}

.aa-memory-toast--turn {
  background: var(--aa-toast-accent, #2B6CB0);
}

/* Stage: bring the actual card to front */
.aa-memory-stage {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: none;
}

.aa-memory-stage.is-on {
  display: grid;
  place-items: center;
}

.aa-memory-stage__backdrop {
  position: absolute;
  inset: 0;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.aa-memory-stage__panel {
  position: relative;
  width: min(720px, calc(100vw - 26px));
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}

.aa-memory-stage__slot {
  display: grid;
  place-items: center;
  padding: 0;
}

.aa-memory-stage__slotInner {
  width: min(56vmin, calc(100vw - 26px));
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
}

.aa-memory-stage__desc {
  margin: 0;
  padding: 12px 0 0 0;
  font-size: 15px;
  line-height: 1.45;
  color: var(--aa-muted);
  text-align: center;
  text-wrap: balance;
}

.aa-memory-card.is-staged {
  width: 100%;
  max-width: min(56vmin, calc(100vw - 26px));
}

@media (prefers-reduced-motion: reduce) {
  .aa-memory-card__inner,
  .aa-memory-choice button,
  .aa-memory-choice__tile,
  .aa-memory-btn,
  .aa-memory-toast {
    transition: none !important;
  }
}

