.memory-image img {
  width: min(100%, 390px);
  height: auto;
  max-width: 390px;
  padding-left: 20px;
  animation: potionFloat 3.4s infinite ease-in-out;
  filter: drop-shadow(0 24px 24px rgba(0, 0, 0, 0.38))
    drop-shadow(0 0 18px rgba(120, 255, 154, 0.3))
    drop-shadow(0 0 30px rgba(66, 232, 255, 0.24));
}

.memory-image::before {
  content: "";
  position: absolute;
  width: min(80vw, 390px);
  aspect-ratio: 1;
  border: 2px solid rgba(120, 255, 154, 0.42);
  transform: rotate(-8deg);
  box-shadow:
    0 0 40px rgba(120, 255, 154, 0.14),
    inset 0 0 35px rgba(66, 232, 255, 0.12);
}

@keyframes potionFloat {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }

  50% {
    transform: translateY(-10px) rotate(5deg);
  }
}

.game-info {
  width: min(calc(100% - 40px), 1200px);
  max-width: 1200px;
  margin: 54px auto;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.075),
      rgba(255, 255, 255, 0.025)
    ),
    var(--panel);
  box-shadow:
    10px 10px 0 var(--shadow),
    0 0 42px rgba(66, 232, 255, 0.12);
  text-align: center;
}

.game-info h2 {
  margin-bottom: 24px;
  color: var(--yellow);
  font-family: "Press Start 2P", cursive;
  font-size: clamp(20px, 3vw, 28px);
  line-height: 1.35;
  text-transform: uppercase;
  text-shadow: 3px 3px 0 var(--shadow);
}

.game-info-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 24px;
}

.rules,
.game-settings {
  min-height: 100%;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(8, 7, 20, 0.28);
  text-align: left;
}

.rules h3,
.game-settings h3 {
  margin-bottom: 14px;
  color: var(--cyan);
  font-family: "Press Start 2P", cursive;
  font-size: clamp(16px, 2.4vw, 20px);
  line-height: 1.45;
  text-transform: uppercase;
}

.rules ul {
  list-style: none;
  color: var(--muted);
  font-size: 16px;
}

.rules ul li {
  position: relative;
  margin-bottom: 10px;
  padding-left: 26px;
}

.rules ul li::before {
  content: ">";
  position: absolute;
  left: 0;
  color: var(--green);
  font-family: "Press Start 2P", cursive;
  font-size: 12px;
}

.game-settings p {
  color: var(--muted);
}

.settings-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
}

.select-wrapper {
  position: relative;
  flex: 0 0 166px;
  display: block;
}

.select-wrapper::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 18px;
  width: 9px;
  height: 9px;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  pointer-events: none;
  transform: translateY(-65%) rotate(45deg);
  filter: drop-shadow(0 0 6px rgba(66, 232, 255, 0.35));
}

#difficulty {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  width: 100%;
  min-height: 50px;
  padding: 0 48px 0 16px;
  border: 2px solid var(--cyan);
  border-radius: 6px;
  background: linear-gradient(135deg, #111022, #151329);
  color: var(--ink);
  font:
    600 15px "Poppins",
    sans-serif;
  box-shadow:
    5px 5px 0 var(--shadow),
    0 0 22px rgba(66, 232, 255, 0.18);
  cursor: pointer;
}

.settings-controls .btn {
  margin-top: 0;
}

#difficulty:focus {
  outline: 2px solid var(--yellow);
  outline-offset: 3px;
}

#difficulty option {
  background: #151329;
  color: var(--ink);
}

#difficulty:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.memory-game {
  margin: 40px 0 84px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.memory-hud {
  width: min(calc(100% - 40px), 820px);
  margin-bottom: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  gap: 16px;
}

.memory-stat {
  min-width: 0;
  min-height: 74px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(8, 7, 20, 0.38);
  display: grid;
  place-items: center;
  box-shadow:
    6px 6px 0 var(--shadow),
    0 0 22px rgba(66, 232, 255, 0.12);
}

.memory-stat span {
  color: var(--cyan);
  font-family: "Press Start 2P", cursive;
  font-size: 11px;
  line-height: 1.4;
  text-transform: uppercase;
}

.memory-stat strong {
  color: var(--yellow);
  font-family: "Press Start 2P", cursive;
  font-size: clamp(18px, 3vw, 24px);
  line-height: 1.2;
}

.memory-actions {
  margin-bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}

.memory-actions .btn {
  margin-top: 0;
}

.btn-secondary {
  border-color: rgba(66, 232, 255, 0.62);
  background: linear-gradient(
    135deg,
    rgba(66, 232, 255, 0.3),
    rgba(255, 255, 255, 0.08)
  );
  color: var(--ink);
}

.btn-secondary::after {
  content: "";
  margin-left: 0;
}

.game-board {
  --memory-card-size: clamp(82px, 9vw, 120px);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, var(--memory-card-size)));
  justify-content: center;
  width: min(100%, 880px);
  max-width: 100%;
  gap: clamp(10px, 1.6vw, 18px);
  padding: clamp(12px, 2.4vw, 20px);
}

.game-board.cols-6 {
  grid-template-columns: repeat(6, minmax(0, var(--memory-card-size)));
}

.card {
  position: relative;
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  appearance: none;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: 1;
  min-width: 0;
  aspect-ratio: 3 / 4;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.6s ease;
}

.card:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 4px;
}

.card[aria-disabled="true"] {
  opacity: 1;
}

.card.locked {
  cursor: default;
}

.card:not(.locked):not(.flipped):not(.matched):not(.preview):hover {
  transform: translateY(-4px);
}

.card.flipped,
.card.preview {
  transform: rotateY(180deg);
}

.card.matched {
  animation: matchPulse 0.5s ease;
}

.card.matched .card-back {
  border-color: rgba(120, 255, 154, 0.9);
  box-shadow:
    6px 6px 0 var(--shadow),
    0 0 24px rgba(120, 255, 154, 0.3);
}

.card.mismatch {
  animation: mismatchShake 0.42s ease;
}

.card-front,
.card-back {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  backface-visibility: hidden;
  box-shadow:
    6px 6px 0 var(--shadow),
    0 0 18px rgba(66, 232, 255, 0.14);
  overflow: hidden;
}

.card-front {
  display: grid;
  place-items: center;
  border-color: rgba(66, 232, 255, 0.78);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.1), transparent 36%),
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(145deg, #111022, #211d36 60%, #151329);
  background-size:
    auto,
    14px 14px,
    14px 14px,
    auto;
  box-shadow:
    6px 6px 0 var(--shadow),
    0 0 22px rgba(66, 232, 255, 0.2);
}

.card-front::before {
  content: "";
  width: 54px;
  height: 54px;
  border: 3px solid var(--yellow);
  background: linear-gradient(
    135deg,
    rgba(255, 79, 163, 0.9),
    rgba(66, 232, 255, 0.82)
  );
  box-shadow:
    0 0 22px rgba(255, 216, 77, 0.22),
    inset 0 0 18px rgba(8, 7, 20, 0.28);
  transform: rotate(45deg);
}

.card-front::after {
  content: "ICL";
  position: absolute;
  color: var(--ink);
  font-family: "Press Start 2P", cursive;
  font-size: 11px;
  line-height: 1;
  text-shadow: 2px 2px 0 var(--shadow);
}

.card-back {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #151326, #24203b);
  color: var(--ink);
  font-size: 48px;
  transform: rotateY(180deg);
}

.memory-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  padding: 24px;
  display: grid;
  place-items: center;
  background: rgba(8, 7, 20, 0.68);
  backdrop-filter: blur(4px);
}

.memory-overlay.hidden {
  display: none;
}

.memory-overlay-card {
  width: min(100%, 520px);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.08),
      rgba(255, 255, 255, 0.03)
    ),
    rgba(18, 15, 31, 0.96);
  box-shadow:
    10px 10px 0 var(--shadow),
    0 0 42px rgba(66, 232, 255, 0.16);
  text-align: center;
}

.memory-overlay-card h2 {
  margin-bottom: 14px;
  color: var(--yellow);
  font-family: "Press Start 2P", cursive;
  font-size: clamp(22px, 4vw, 34px);
  line-height: 1.35;
  text-shadow: 3px 3px 0 var(--shadow);
}

.memory-overlay-card p:not(.eyebrow) {
  color: var(--muted);
}

.memory-overlay-card .btn {
  margin-top: 24px;
}

@keyframes matchPulse {
  0%,
  100% {
    transform: rotateY(180deg) scale(1);
  }

  50% {
    transform: rotateY(180deg) scale(1.06);
  }
}

@keyframes mismatchShake {
  0%,
  100% {
    transform: rotateY(180deg) translateX(0);
  }

  25% {
    transform: rotateY(180deg) translateX(-8px);
  }

  75% {
    transform: rotateY(180deg) translateX(8px);
  }
}

@media (max-width: 1200px) {
  .game-info {
    width: min(calc(100% - 80px), 1200px);
    margin-left: auto;
    margin-right: auto;
  }
}

@media (max-width: 768px) {
  .hero {
    gap: 24px;
    padding-bottom: 16px;
  }

  .memory-image {
    width: min(100%, 360px);
    margin-bottom: -18px;
  }

  .memory-image img {
    width: min(78vw, 330px);
    margin-bottom: 0;
    padding-left: 0;
  }

  .memory-image::before {
    width: min(80vw, 340px);
  }

  .game-info {
    margin-top: 14px;
  }

  .game-info-content {
    grid-template-columns: 1fr;
  }

  .rules,
  .game-settings {
    text-align: center;
  }

  .rules ul {
    text-align: left;
  }

  .settings-controls {
    justify-content: center;
  }

  .game-board {
    --memory-card-size: 100px;
    grid-template-columns: repeat(4, minmax(0, var(--memory-card-size)));
    gap: 15px;
  }

  .game-board.cols-6 {
    grid-template-columns: repeat(4, minmax(0, var(--memory-card-size)));
  }

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

@media (max-width: 480px) {
  .hero {
    padding-bottom: 12px;
  }

  .hero h1 {
    font-size: clamp(21px, 6.7vw, 26px);
  }

  .memory-image {
    width: min(100%, 330px);
    margin-bottom: -10px;
  }

  .memory-image img {
    width: min(64vw, 260px);
  }

  .memory-image::before {
    width: min(68vw, 270px);
  }

  .game-info {
    width: min(calc(100% - 32px), 1200px);
    margin-top: 10px;
    margin-left: auto;
    margin-right: auto;
    padding: 22px;
  }

  .settings-controls {
    align-items: stretch;
  }

  .select-wrapper,
  .settings-controls .btn {
    width: 100%;
    flex-basis: auto;
  }

  .game-board {
    --memory-card-size: clamp(72px, 24vw, 90px);
    grid-template-columns: repeat(3, minmax(0, var(--memory-card-size)));
    gap: 10px;
    padding: 14px;
  }

  .game-board.cols-6 {
    grid-template-columns: repeat(3, minmax(0, var(--memory-card-size)));
  }

  .memory-hud {
    width: min(calc(100% - 32px), 820px);
    grid-template-columns: 1fr;
  }

  .memory-actions {
    width: calc(100% - 32px);
  }

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

  .card-back {
    font-size: clamp(34px, 11vw, 42px);
  }
}
