* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  touch-action: manipulation;
}

body {
  min-height: 100dvh;
  background: #0f1012;
  color: #fff;
  font-family: Arial, sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 32px 20px 20px;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 760px;
  background: #1c1d22;
  border-radius: 24px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  padding: 18px;
}

.topbar {
  display: grid;
  grid-template-columns: 100px 1fr 100px;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.topbar-spacer {
  min-height: 40px;
}

.topbar h1 {
  margin: 0;
  text-align: center;
  font-size: 28px;
  line-height: 1.1;
  text-shadow: 0 0 14px rgba(111, 93, 255, 0.75);
}

.nav-btn {
  appearance: none;
  border: none;
  text-decoration: none;
  background: #3a3b40;
  color: #fff;
  border-radius: 10px;
  min-height: 40px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.stats-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 12px;
  font-size: 18px;
  font-weight: 700;
}

.stats-bar div:first-child {
  justify-self: start;
}

.stats-bar div:last-child {
  justify-self: end;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.share-btn {
  background: #538d4e;
}

.sound-btn {
  min-width: 44px;
  background: #2f3037;
}

.sound-btn.muted {
  background: #6b3030;
}

.info-panel {
  background: #17181b;
  border: 1px solid #2d2f36;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 14px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: #d7d7ff;
}

.mode-panel {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.mode-option {
  background: #4a4b50;
}

.mode-option.active {
  background: #3f6db3;
}

.game-wrap {
  display: flex;
  justify-content: center;
}

.board-shell {
  position: relative;
  width: 100%;
  max-width: 760px;
}

.board {
  width: 100%;
  display: grid;
  gap: 8px;
  background: #0b0b0d;
  border: 3px solid #6c63ff;
  border-radius: 12px;
  padding: 10px;
  box-shadow:
    0 0 16px rgba(40, 123, 255, 0.45),
    0 0 28px rgba(139, 44, 255, 0.35);
}

.board-16 {
  grid-template-columns: repeat(8, 1fr);
}

.board-24 {
  grid-template-columns: repeat(8, 1fr);
}

.board-32 {
  grid-template-columns: repeat(8, 1fr);
}

.board-48 {
  grid-template-columns: repeat(12, 1fr);
}

.start-btn {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  border: 2px solid #8f8fff;
  background: #161820;
  color: white;
  border-radius: 16px;
  min-width: 170px;
  min-height: 58px;
  padding: 14px 22px;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  box-shadow:
    0 0 14px rgba(40, 123, 255, 0.75),
    0 0 28px rgba(139, 44, 255, 0.65);
}

.start-btn:hover {
  transform: translate(-50%, -50%) scale(1.04);
}

.card {
  appearance: none;
  border: none;
  padding: 0;
  width: 100%;
  min-width: 0;
  aspect-ratio: 1 / 1;
  background: transparent;
  perspective: 800px;
  cursor: pointer;
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.42s ease;
}

.card.flipped .card-inner,
.card.matched .card-inner {
  transform: rotateY(180deg);
}

.card-front,
.card-back {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #5c63ff;
}

.card-back {
  background:
    radial-gradient(circle at top left, rgba(83, 141, 78, 0.18), transparent 35%),
    linear-gradient(135deg, #25262d, #17181d);
  box-shadow:
    0 0 10px rgba(40, 123, 255, 0.45),
    0 0 18px rgba(139, 44, 255, 0.35);
}

.card-back::after {
  content: "?";
  color: #fff;
  font-size: clamp(14px, 3vw, 28px);
  font-weight: 700;
  text-shadow: 0 0 12px rgba(111, 93, 255, 0.9);
}

.card-front {
  background: #2b2c31;
  transform: rotateY(180deg);
  font-size: clamp(16px, 3vw, 30px);
  box-shadow:
    0 0 12px rgba(40, 123, 255, 0.65),
    0 0 22px rgba(139, 44, 255, 0.5);
}

.card.matched .card-front {
  background: #263a2a;
  border-color: #538d4e;
  box-shadow:
    0 0 12px rgba(83, 141, 78, 0.85),
    0 0 24px rgba(83, 141, 78, 0.45);
}

.card.locked {
  pointer-events: none;
}

.card.shuffle-anim {
  animation: shufflePop 0.75s ease both;
}

@keyframes shufflePop {
  0% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }

  35% {
    transform: scale(0.85) rotate(var(--shuffle-rotate));
    opacity: 0.75;
  }

  70% {
    transform: translate(var(--shuffle-x), var(--shuffle-y)) scale(1.08);
    opacity: 1;
  }

  100% {
    transform: translate(0, 0) scale(1) rotate(0deg);
    opacity: 1;
  }
}

.message {
  min-height: 24px;
  text-align: center;
  margin-top: 14px;
  font-size: 16px;
  font-weight: 700;
}

.copy-toast {
  position: fixed;
  top: 18px;
  right: 18px;
  background: #2f2f31;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  border: 1px solid #4a4a4d;
  z-index: 999;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 2000;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: #1c1d22;
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  border: 1px solid #2d2f36;
  text-align: center;
}

.modal-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 10px;
}

.modal-text {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 18px;
}

.modal-actions.single {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-yes {
  background: #538d4e;
}

.share-result-btn {
  background: #4d7dff;
}

@media (max-width: 600px) {
  body {
    padding: 22px 12px 12px;
  }

  .app {
    padding: 14px;
    border-radius: 20px;
  }

  .topbar {
    grid-template-columns: 78px 1fr 78px;
    gap: 8px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .nav-btn {
    min-height: 36px;
    font-size: 12px;
    padding: 8px 10px;
  }

  .stats-bar {
    font-size: 13px;
    gap: 8px;
  }

  .top-actions {
    gap: 6px;
  }

  .mode-panel {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .board {
    gap: 7px;
    padding: 8px;
  }

  .board-16 {
    grid-template-columns: repeat(4, 1fr);
  }

  .board-24 {
    grid-template-columns: repeat(6, 1fr);
  }

  .board-32 {
    grid-template-columns: repeat(8, 1fr);
  }

  .board-48 {
    grid-template-columns: repeat(8, 1fr);
  }

  .start-btn {
    min-width: 145px;
    min-height: 50px;
    font-size: 17px;
  }

  .card-front {
    font-size: clamp(20px, 7vw, 34px);
  }

  .card-back::after {
    font-size: clamp(18px, 6vw, 28px);
  }

  .message,
  .info-panel {
    font-size: 14px;
  }
}