:root {
  --bg: #fff8ee;
  --card-radius: 16px;
  --accent1: #ff6b6b;
  --accent2: #ffd93d;
  --accent3: #6bcb77;
  --accent4: #4d96ff;
  --accent5: #ff922b;
  --text: #2d2d2d;
  --muted: #888;
  --panel: #ffffff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  align-items: center;
  background-color: var(--bg);
  background-image:
    radial-gradient(
      circle at 10% 20%,
      rgba(255, 107, 107, 0.12) 0%,
      transparent 40%
    ),
    radial-gradient(
      circle at 90% 80%,
      rgba(77, 150, 255, 0.12) 0%,
      transparent 40%
    ),
    radial-gradient(
      circle at 50% 50%,
      rgba(107, 203, 119, 0.08) 0%,
      transparent 60%
    );
  color: var(--text);
  display: flex;
  font-family: "Nunito", sans-serif;
  justify-content: center;
  min-height: 100vh;
  overflow-x: hidden;
  padding: 20px 16px 40px;
}

button {
  font: inherit;
}

.game-shell {
  align-items: center;
  display: flex;
  flex-direction: column;
  width: min(100%, 760px);
}

.hero {
  margin-bottom: 24px;
  text-align: center;
}

.title-row {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: center;
}

.hero h1 {
  color: var(--accent1);
  font-family: "Fredoka One", cursive;
  font-size: clamp(2rem, 6vw, 3.2rem);
  letter-spacing: 1px;
  line-height: 1;
  text-shadow: 3px 3px 0 rgba(255, 107, 107, 0.2);
}

.info-btn {
  align-items: center;
  background: linear-gradient(135deg, var(--accent4), #845ef7);
  border: 0;
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(77, 150, 255, 0.28);
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  flex: 0 0 auto;
  font-family: "Fredoka One", cursive;
  font-size: 1rem;
  height: 38px;
  justify-content: center;
  line-height: 1;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
  width: 38px;
}

.info-btn:hover {
  box-shadow: 0 9px 22px rgba(77, 150, 255, 0.34);
  transform: translateY(-2px);
}

.hero p {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
  margin-top: 6px;
}

.controls,
.stats,
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.controls {
  margin-bottom: 20px;
}

.diff-btn {
  background: var(--panel);
  border: 3px solid transparent;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  color: #555;
  cursor: pointer;
  font-family: "Fredoka One", cursive;
  font-size: 1rem;
  padding: 10px 24px;
  transition:
    transform 0.2s,
    box-shadow 0.2s,
    background-color 0.2s;
}

.diff-btn:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.13);
  transform: translateY(-2px);
}

.diff-btn.active[data-diff="easy"] {
  background: var(--accent3);
  border-color: #4da85a;
  color: #ffffff;
}

.diff-btn.active[data-diff="medium"] {
  background: var(--accent2);
  border-color: #e6c200;
  color: #7a6000;
}

.diff-btn.active[data-diff="hard"] {
  background: var(--accent1);
  border-color: #e04040;
  color: #ffffff;
}

.stats {
  margin-bottom: 24px;
}

.stat-box {
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  min-width: 110px;
  padding: 12px 24px;
  text-align: center;
}

.stat-label {
  color: #aaa;
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.stat-value {
  color: var(--text);
  display: block;
  font-family: "Fredoka One", cursive;
  font-size: 2rem;
  line-height: 1.1;
}

#timer-val {
  color: var(--accent4);
}

#score-val {
  color: var(--accent3);
}

#moves-val {
  color: var(--accent5);
}

.board-wrap {
  margin-bottom: 28px;
  width: 100%;
}

#board {
  display: grid;
  gap: 12px;
  justify-content: center;
  margin-inline: auto;
  width: 100%;
}

.card {
  background: transparent;
  border: 0;
  aspect-ratio: 1 / 1.25;
  cursor: pointer;
  display: block;
  padding: 0;
  perspective: 900px;
  width: 100%;
}

.card-inner {
  border-radius: var(--card-radius);
  display: block;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.42s cubic-bezier(0.4, 0, 0.2, 1);
  width: 100%;
}

.card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card.matched .card-inner {
  transform: rotateY(180deg);
}

.card.matched {
  cursor: default;
}

.card-face {
  align-items: center;
  backface-visibility: hidden;
  border-radius: var(--card-radius);
  display: flex;
  inset: 0;
  justify-content: center;
  position: absolute;
  user-select: none;
}

.card-back-face {
  background: linear-gradient(135deg, #ff6b6b 0%, #ff922b 100%);
  border: 3px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.35);
}

.card-back-face::after {
  color: rgba(255, 255, 255, 0.85);
  content: "?";
  font-family: "Fredoka One", cursive;
  font-size: 2rem;
}

.card-front-face {
  border: 3px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  font-size: 2.2rem;
  transform: rotateY(180deg);
}

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

.card.wrong .card-inner {
  animation: wrongShake 0.45s ease;
}

.card.hint .card-front-face {
  box-shadow:
    0 0 0 4px rgba(255, 217, 61, 0.55),
    0 0 28px rgba(255, 217, 61, 0.65);
}

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

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

  100% {
    transform: rotateY(180deg) scale(1);
  }
}

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

  20% {
    transform: rotateY(180deg) translateX(-6px);
  }

  60% {
    transform: rotateY(180deg) translateX(6px);
  }

  80% {
    transform: rotateY(180deg) translateX(-3px);
  }
}

.theme-0 .card-front-face {
  background: linear-gradient(135deg, #ffd93d, #ff922b);
}

.theme-1 .card-front-face {
  background: linear-gradient(135deg, #6bcb77, #38a3a5);
}

.theme-2 .card-front-face {
  background: linear-gradient(135deg, #4d96ff, #845ef7);
}

.theme-3 .card-front-face {
  background: linear-gradient(135deg, #ff6b6b, #ff922b);
}

.theme-4 .card-front-face {
  background: linear-gradient(135deg, #f783ac, #cc5de8);
}

.theme-5 .card-front-face {
  background: linear-gradient(135deg, #63e6be, #4d96ff);
}

.theme-6 .card-front-face {
  background: linear-gradient(135deg, #ff922b, #fab005);
}

.theme-7 .card-front-face {
  background: linear-gradient(135deg, #845ef7, #ff6b6b);
}

.theme-8 .card-front-face {
  background: linear-gradient(135deg, #38a3a5, #6bcb77);
}

.btn-row {
  margin-top: 4px;
}

.btn {
  border: 0;
  border-radius: 999px;
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.13);
  cursor: pointer;
  font-family: "Fredoka One", cursive;
  font-size: 1.1rem;
  letter-spacing: 0.5px;
  padding: 12px 32px;
  transition:
    transform 0.2s,
    box-shadow 0.2s,
    opacity 0.2s;
}

.btn-primary {
  background: linear-gradient(135deg, #ff6b6b, #ff922b);
  color: #ffffff;
}

.btn-secondary {
  background: linear-gradient(135deg, #4d96ff, #845ef7);
  color: #ffffff;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.btn:not(:disabled):hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  transform: translateY(-3px);
}

#win-overlay {
  align-items: center;
  animation: fadeIn 0.4s ease;
  background: rgba(255, 248, 238, 0.92);
  backdrop-filter: blur(6px);
  display: none;
  flex-direction: column;
  gap: 20px;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 100;
}

#win-overlay.show {
  display: flex;
}

.win-card {
  background: #ffffff;
  border-radius: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  max-width: 380px;
  padding: 40px 48px;
  text-align: center;
  width: 90%;
}

.win-emoji {
  animation: bounce 0.7s ease infinite alternate;
  font-size: 4rem;
  margin-bottom: 8px;
}

.win-title {
  color: var(--accent1);
  font-family: "Fredoka One", cursive;
  font-size: 2.4rem;
  margin-bottom: 8px;
}

.stars {
  font-size: 2rem;
  letter-spacing: 4px;
  margin-bottom: 8px;
}

.win-stats {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin: 20px 0;
}

.win-stat {
  text-align: center;
}

.win-stat-n {
  color: var(--accent4);
  display: block;
  font-family: "Fredoka One", cursive;
  font-size: 2rem;
}

.win-stat-l {
  color: #aaa;
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.confetti-piece {
  animation: confettiFall linear forwards;
  border-radius: 2px;
  height: 14px;
  pointer-events: none;
  position: fixed;
  top: -20px;
  width: 10px;
  z-index: 200;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes bounce {
  from {
    transform: translateY(0);
  }

  to {
    transform: translateY(-14px);
  }
}

@keyframes confettiFall {
  to {
    opacity: 0;
    transform: translateY(110vh) rotate(720deg);
  }
}

.popup-overlay {
  align-items: center;
  background: rgba(45, 45, 45, 0.68);
  display: none;
  inset: 0;
  justify-content: center;
  overflow: hidden;
  padding: 20px;
  position: fixed;
  z-index: 300;
}

.popup-overlay.active {
  animation: fadeIn 0.3s ease;
  display: flex;
}

.popup-content {
  background: linear-gradient(135deg, #ffffff 0%, #fff8ee 100%);
  border-radius: 24px;
  box-shadow: 0 22px 70px rgba(45, 45, 45, 0.28);
  display: flex;
  flex-direction: column;
  max-height: 86vh;
  max-width: 720px;
  overflow: hidden;
  width: 100%;
}

.popup-header {
  background: linear-gradient(135deg, var(--accent1), var(--accent5));
  border-radius: 24px 24px 0 0;
  color: #ffffff;
  padding: 30px;
  text-align: center;
}

.popup-header h2 {
  font-family: "Fredoka One", cursive;
  font-size: 2rem;
  line-height: 1.15;
  margin-bottom: 10px;
}

.popup-subtitle {
  font-size: 1.08rem;
  font-weight: 700;
  opacity: 0.92;
}

.popup-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(255, 107, 107, 0.7) rgba(255, 107, 107, 0.12);
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.popup-body::-webkit-scrollbar {
  width: 10px;
}

.popup-body::-webkit-scrollbar-track {
  background: rgba(255, 107, 107, 0.08);
  border-radius: 999px;
  margin: 14px 8px;
}

.popup-body::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--accent1), var(--accent5));
  border: 2px solid #fff8ee;
  border-radius: 999px;
}

.popup-body::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, var(--accent5), var(--accent1));
}

.popup-section {
  border-bottom: 1px solid rgba(255, 107, 107, 0.16);
  padding: 24px 30px;
}

.popup-section:last-of-type {
  border-bottom: 0;
}

.popup-section h3 {
  align-items: center;
  color: var(--text);
  display: flex;
  font-size: 1.18rem;
  gap: 10px;
  margin-bottom: 14px;
}

.popup-section p,
.popup-section li {
  color: #6f6a64;
  font-size: 0.95rem;
  line-height: 1.65;
}

.popup-section ul {
  margin: 10px 0 0;
  padding-left: 20px;
}

.popup-section li {
  margin-bottom: 8px;
}

.popup-section strong {
  color: var(--text);
}

.highlight-box {
  background: linear-gradient(
    135deg,
    rgba(255, 107, 107, 0.07),
    rgba(255, 217, 61, 0.12)
  );
  border-left: 4px solid var(--accent1);
  border-radius: 12px;
  padding: 18px;
}

.tech-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.tech-tag {
  background: linear-gradient(135deg, var(--accent1), var(--accent5));
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(255, 107, 107, 0.22);
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 800;
  padding: 8px 16px;
}

.close-popup-btn {
  background: linear-gradient(135deg, var(--accent3), #38a3a5);
  border: 0;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(107, 203, 119, 0.32);
  color: #ffffff;
  cursor: pointer;
  display: block;
  font-family: "Fredoka One", cursive;
  font-size: 1.05rem;
  margin: 28px auto;
  padding: 14px 30px;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}

.close-popup-btn:hover {
  box-shadow: 0 8px 25px rgba(107, 203, 119, 0.42);
  transform: translateY(-2px);
}

@media (max-width: 520px) {
  body {
    padding-inline: 12px;
  }

  .stat-box {
    flex: 1 1 94px;
    min-width: 94px;
    padding-inline: 16px;
  }

  .diff-btn,
  .btn {
    padding-inline: 20px;
  }

  #board {
    gap: 9px;
    max-width: calc(100vw - 24px);
  }

  .card-front-face {
    font-size: clamp(1.3rem, 8vw, 2.2rem);
  }

  .title-row {
    align-items: flex-start;
  }

  .info-btn {
    height: 34px;
    margin-top: 2px;
    width: 34px;
  }

  .popup-overlay {
    padding: 12px;
  }

  .popup-header {
    padding: 24px 20px;
  }

  .popup-header h2 {
    font-size: 1.5rem;
  }

  .popup-subtitle {
    font-size: 0.98rem;
  }

  .popup-section {
    padding: 20px;
  }
}

@media (max-width: 620px) {
  .game-shell {
    overflow-x: hidden;
  }

  .controls {
    max-width: 360px;
  }
}
