.memory-stage {
  --memory-gold: #f3d394;
  --memory-line: #806648;
  position: relative;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 12px;
  padding: 0 14px 14px;
  overflow: hidden;
  border-color: #615072;
  background: radial-gradient(ellipse at 50% 12%, #24224d, #0d0e20 72%);
}

.memory-heading {
  display: grid;
  align-content: end;
  align-self: start;
  width: calc(100% + 28px);
  min-height: 146px;
  padding: 18px 12px 14px;
  text-align: center;
  background:
    linear-gradient(180deg, rgb(13 14 32 / 10%), #0d0e20),
    url('./table.webp') center 28% / cover;
}

.memory-heading h1 {
  margin: 0;
  color: #fff0cc;
  font: bold clamp(2rem, 5vw, 3.25rem)/1.08 Georgia, serif;
  text-shadow: 0 2px 12px #05050b;
}

.memory-heading p {
  margin: 6px 0 0;
  color: #f2e8d9;
  text-shadow: 0 1px 6px #05050b;
}

.memory-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.memory-controls select,
.memory-controls button {
  min-height: 44px;
  border: 1px solid var(--memory-line);
  border-radius: 7px;
  background: #211d39;
  color: #fff0cc;
  font: inherit;
  padding: 6px 10px;
}

.memory-controls label,
.memory-stats dt {
  color: #ddd0c6;
  font-size: .85rem;
}

.memory-controls select:focus-visible {
  outline: 3px solid #83decd;
  outline-offset: 2px;
}

.memory-stats {
  display: grid;
  width: min(100%, 560px);
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 2fr);
  margin: 0;
  border: 1px solid #54425d;
  border-radius: 8px;
  background: #16142a;
  text-align: center;
}

.memory-stats div {
  padding: 5px 3px;
}

.memory-stats div + div {
  border-left: 1px solid #54425d;
}

.memory-stats dd {
  margin: 0;
  color: var(--memory-gold);
  font-size: .9rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.memory-stage .memory-grid {
  grid-template-columns: repeat(var(--memory-columns), minmax(0, 1fr));
  gap: clamp(5px, 1vw, 10px);
  width: 100%;
  max-width: calc(var(--memory-columns) * 86px);
}

.memory-stage .memory-card {
  display: grid;
  place-items: center;
  position: relative;
  min-width: 0;
  padding: 0;
  border: 1px solid var(--memory-line);
  border-radius: 7px;
  background: radial-gradient(circle at 50% 38%, #332661, #181431 73%);
  color: var(--memory-gold);
  font: bold clamp(23px, 6.6vw, 42px)/1 'Segoe UI Symbol', Georgia, serif;
  box-shadow: 0 3px 0 #080813;
}

.memory-card::before {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px solid currentColor;
  border-radius: 4px;
  opacity: .48;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .memory-stage .memory-card:hover[data-state='hidden'] {
    border-color: #fff0cc;
    background: #382965;
    color: #fff0cc;
  }
}

.memory-stage .memory-card[data-state='revealed'],
.memory-stage .memory-card[data-state='matched'] {
  border-color: currentColor;
  background: radial-gradient(circle at 50% 40%, #27374f, #10172b 75%);
  color: var(--memory-face);
}

.memory-stage .memory-card[data-state='matched'] {
  background: radial-gradient(circle at 50% 40%, #1b4b4b, #102832 75%);
  border-color: #83decd;
  cursor: default;
}

.memory-card[data-state='matched']::after {
  content: '';
  position: absolute;
  inset: auto 8px 8px auto;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #83decd;
}

.memory-status {
  min-height: 1.5em;
  margin: 0;
  color: #f8e7c5;
  text-align: center;
}

@media (max-width: 480px) {
  .memory-stage { gap: 8px; padding-inline: 8px; }
  .memory-heading { width: calc(100% + 16px); min-height: 95px; padding: 8px; align-content: center; }
  .memory-heading h1 { font-size: clamp(1.55rem, 8vw, 2rem); }
  .memory-heading p { font-size: .85rem; line-height: 1.32; }
  .memory-controls select, .memory-controls button { font-size: .85rem; padding-inline: 7px; }
  .memory-status { min-height: 2.7em; font-size: .9rem; }
  .memory-stage .memory-grid {
    max-width: 302px;
  }
}
@media (max-width: 360px) {
  .memory-stage { padding-inline: 4px; }
  .memory-heading { width: calc(100% + 8px); min-height: 76px; }
  .memory-controls { gap: 4px; }
  .memory-controls label { font-size: .8rem; }
  .memory-stage .memory-grid { max-width: 256px; gap: 4px; }
  .memory-stage .memory-grid[data-mode='expert'] { max-width: 278px; gap: 2px; }
  .memory-stage .memory-card:focus-visible { outline-offset: -3px; }
}
@media (max-width: 319px) {
  .memory-stage .memory-grid[data-mode='expert'] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .memory-stage .memory-grid[data-mode='expert'] .memory-card { aspect-ratio: auto; min-height: 44px; }
}

@media (min-width: 700px) and (max-height: 780px) {
  .memory-heading {
    min-height: 124px;
  }

  .memory-stage .memory-grid {
    max-width: calc(var(--memory-columns) * 76px);
  }
}
