.memory-game,
.memory-game * {
  box-sizing: border-box;
}

.memory-game {
  --mg-ink: #202124;
  --mg-muted: #686d76;
  --mg-panel: #ffffff;
  --mg-line: #d8d2c4;
  --mg-blue: #005f89;
  --mg-blue-dark: #004765;
  --mg-green: #8aa63b;
  --mg-green-dark: #6f8730;
  --mg-aqua: #2fa5ad;
  --mg-shadow: 0 18px 50px rgba(0, 95, 137, 0.16);
  width: min(100%, 920px);
  margin: 48px auto 72px;
  padding: 0 16px;
  color: var(--mg-ink);
  font-family: Arial, Helvetica, sans-serif;
}

.memory-game button,
.memory-game select {
  font: inherit;
}

.memory-game__top,
.memory-game__score {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--mg-line);
  border-radius: 8px;
  box-shadow: var(--mg-shadow);
}

.memory-game__top {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.memory-game__brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.memory-game__mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 8px;
  background:
    linear-gradient(135deg, var(--mg-blue) 0 49%, transparent 50%),
    linear-gradient(315deg, var(--mg-green) 0 49%, var(--mg-aqua) 50%);
  border: 3px solid #fff;
}

.memory-game h2,
.memory-game p {
  margin: 0;
}

.memory-game h2 {
  font-size: clamp(1.45rem, 3vw, 2.25rem);
  line-height: 1;
  letter-spacing: 0;
}

.memory-game p {
  margin-top: 5px;
  color: var(--mg-muted);
  line-height: 1.4;
}

.memory-game__controls {
  display: flex;
  align-items: end;
  gap: 10px;
}

.memory-game__field {
  display: grid;
  gap: 6px;
  color: var(--mg-muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.memory-game select {
  min-width: 128px;
  height: 42px;
  color: var(--mg-ink);
  border: 1px solid var(--mg-line);
  border-radius: 8px;
  background: #fff;
  padding: 0 12px;
  cursor: pointer;
}

.memory-game__restart {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--mg-blue);
  cursor: pointer;
}

.memory-game__restart:hover,
.memory-game__restart:focus-visible {
  background: var(--mg-blue-dark);
}

.memory-game__restart svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.memory-game__score {
  margin: 14px 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
}

.memory-game__score div {
  padding: 13px 16px;
  display: grid;
  gap: 5px;
  border-right: 1px solid var(--mg-line);
}

.memory-game__score div:last-child {
  border-right: 0;
}

.memory-game__score span {
  color: var(--mg-muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.memory-game__score strong {
  font-size: clamp(1.15rem, 3vw, 1.7rem);
  line-height: 1;
}

.memory-game__board {
  display: grid;
  grid-template-columns: repeat(var(--mg-cols), minmax(0, 1fr));
  gap: clamp(8px, 1.4vw, 14px);
}

.memory-game__card {
  position: relative;
  display: block;
  aspect-ratio: 1;
  min-width: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  perspective: 900px;
  cursor: pointer;
}

.memory-game__card:focus-visible {
  outline: 4px solid rgba(20, 125, 126, 0.35);
  outline-offset: 4px;
}

.memory-game__card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 420ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

.memory-game__face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.72);
  box-shadow: 0 12px 24px rgba(32, 33, 36, 0.16);
  backface-visibility: hidden;
}

.memory-game__back {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16) 25%, transparent 25% 50%, rgba(255, 255, 255, 0.16) 50% 75%, transparent 75%),
    linear-gradient(135deg, var(--mg-blue-dark), var(--mg-aqua));
  background-size: 24px 24px, auto;
}

.memory-game__back::before {
  content: "";
  width: 42%;
  height: 42%;
  border-radius: 8px;
  border: 3px solid rgba(255, 255, 255, 0.8);
  transform: rotate(45deg);
}

.memory-game__front {
  transform: rotateY(180deg);
  background: var(--mg-panel);
}

.memory-game__card.is-matched .memory-game__front {
  border-color: rgba(79, 143, 69, 0.55);
  box-shadow: 0 12px 26px rgba(79, 143, 69, 0.2);
}

.memory-game__icon {
  width: 54%;
  height: 54%;
  fill: none;
  stroke: var(--mg-asset-color);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.memory-game__message {
  margin-top: 14px;
  padding: 14px 16px;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(138, 166, 59, 0.45);
  border-radius: 8px;
  background: rgba(138, 166, 59, 0.12);
}

.memory-game__message.is-visible {
  display: flex;
}

.memory-game__message strong {
  display: block;
  margin-bottom: 3px;
}

.memory-game__message button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: #fff;
  background: var(--mg-green-dark);
  font-weight: 700;
  cursor: pointer;
}

.elementor-widget-html:has(.memory-game) {
  width: 100%;
}

.cognitive-games-page {
  width: min(100%, 1060px);
  margin: 42px auto 72px;
  padding: 0 16px;
  font-family: Arial, Helvetica, sans-serif;
}

.cognitive-games-hero {
  margin: 0 auto 24px;
  text-align: center;
}

.cognitive-games-hero h1 {
  margin: 0;
  color: #005f89;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.cognitive-games-hero p {
  width: min(100%, 720px);
  margin: 12px auto 0;
  color: #686d76;
  font-size: 1.05rem;
  line-height: 1.6;
}

.cognitive-games-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0 auto 24px;
}

.cognitive-game-card {
  min-height: 96px;
  padding: 16px;
  display: grid;
  align-content: center;
  gap: 6px;
  border: 1px solid #d8d2c4;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 32px rgba(0, 95, 137, 0.1);
}

.cognitive-game-card strong {
  color: #005f89;
  font-size: 1.05rem;
}

.cognitive-game-card span {
  color: #686d76;
  font-size: 0.9rem;
  line-height: 1.35;
}

.cognitive-game-card.is-active {
  border-color: rgba(138, 166, 59, 0.65);
  background: rgba(138, 166, 59, 0.08);
}

@media (max-width: 800px) {
  .cognitive-games-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .cognitive-games-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .memory-game__top {
    align-items: stretch;
    flex-direction: column;
  }

  .memory-game__field {
    flex: 1 1 auto;
  }

  .memory-game select {
    width: 100%;
  }

  .memory-game__score div {
    padding: 12px 10px;
  }
}

@media (max-width: 430px) {
  .memory-game p {
    display: none;
  }

  .memory-game__board {
    gap: 7px;
  }

  .memory-game__message {
    align-items: stretch;
    flex-direction: column;
  }
}
