* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}


body {
  min-height: 100vh;

  display: flex;
  justify-content: center;
  align-items: center;

  padding: 20px;

  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Hiragino Kaku Gothic ProN",
    "Yu Gothic",
    sans-serif;

  background:
    linear-gradient(
      135deg,
      #667eea,
      #764ba2
    );

  color: #333;
}


/* =========================
   ゲーム全体
========================= */

.game {
  width: min(100%, 650px);

  padding: 30px 20px;

  text-align: center;

  background: rgba(255, 255, 255, 0.96);

  border-radius: 24px;

  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.2);
}


h1 {
  margin-bottom: 8px;

  font-size:
    clamp(28px, 7vw, 40px);
}


.subtitle {
  margin-bottom: 20px;

  color: #666;

  font-size: 14px;
}


/* =========================
   難易度
========================= */

.difficulty {
  margin-bottom: 18px;
}


.difficulty-title {
  margin-bottom: 10px;

  font-weight: bold;

  font-size: 14px;
}


.difficulty-buttons {
  display: flex;

  justify-content: center;

  gap: 8px;

  flex-wrap: wrap;
}


.difficulty-button {
  border: 2px solid #e4e4ee;

  padding: 9px 14px;

  background: white;

  color: #555;

  border-radius: 999px;

  font-size: 13px;

  font-weight: bold;

  cursor: pointer;

  transition: 0.2s;
}


.difficulty-button:hover {
  transform: translateY(-2px);

  border-color: #aaa;
}


.difficulty-button.active {
  background: #5b5bd6;

  border-color: #5b5bd6;

  color: white;
}


/* =========================
   情報
========================= */

.info {
  display: grid;

  grid-template-columns:
    repeat(3, 1fr);

  gap: 8px;

  max-width: 440px;

  margin: 0 auto 12px;
}


.info-box {
  padding: 8px;

  background: #f4f4ff;

  border-radius: 12px;
}


.info-box span {
  display: block;

  margin-bottom: 3px;

  color: #777;

  font-size: 11px;
}


.info-box strong {
  color: #5b5bd6;

  font-size: 18px;
}


/* =========================
   ペア情報
========================= */

.pair-info {
  margin-bottom: 18px;

  color: #777;

  font-size: 13px;
}


.pair-info strong {
  color: #5b5bd6;

  font-size: 16px;
}


/* =========================
   ゲームボード
========================= */

.game-board {
  display: grid;

  width: 100%;

  max-width: 560px;

  margin: 0 auto 24px;

  gap: 10px;
}


.game-board.size-4 {
  grid-template-columns:
    repeat(4, 1fr);
}


.game-board.size-6 {
  grid-template-columns:
    repeat(6, 1fr);

  gap: 7px;
}


.game-board.size-8 {
  grid-template-columns:
    repeat(8, 1fr);

  gap: 5px;
}


/* =========================
   カード
========================= */

.card {
  aspect-ratio: 1 / 1;

  border: none;

  padding: 0;

  background: transparent;

  perspective: 700px;

  cursor: pointer;
}


.card-inner {
  position: relative;

  width: 100%;
  height: 100%;

  transform-style: preserve-3d;

  transition:
    transform 0.45s ease;
}


.card.flipped .card-inner,
.card.matched .card-inner {
  transform: rotateY(180deg);
}


.card-front,
.card-back {
  position: absolute;

  inset: 0;

  display: flex;

  justify-content: center;
  align-items: center;

  border-radius: 12px;

  backface-visibility: hidden;

  -webkit-backface-visibility: hidden;
}


.card-front {
  background:
    linear-gradient(
      135deg,
      #5b5bd6,
      #8b5cf6
    );

  box-shadow:
    0 4px 8px rgba(0, 0, 0, 0.15);

  color: white;

  font-size:
    clamp(18px, 5vw, 30px);
}


.card-front::after {
  content: "?";

  font-weight: bold;
}


.card-back {
  transform: rotateY(180deg);

  background: white;

  border: 2px solid #eee;

  font-size:
    clamp(20px, 5vw, 40px);

  box-shadow:
    0 4px 8px rgba(0, 0, 0, 0.1);
}


.card.matched .card-back {
  border-color: #7ddf9b;

  background: #edfff2;
}


@media (hover: hover) {

  .card:not(.flipped):not(.matched):hover {
    transform: translateY(-3px);
  }

}


/* =========================
   ボタン
========================= */

.restart-button {
  border: none;

  padding: 12px 24px;

  background: #5b5bd6;

  color: white;

  border-radius: 999px;

  font-size: 15px;

  font-weight: bold;

  cursor: pointer;

  transition: 0.2s;
}


.restart-button:hover {
  background: #4848c4;

  transform: translateY(-2px);
}


.restart-button:active {
  transform: translateY(0);
}


/* =========================
   クリアモーダル
========================= */

.modal {
  position: fixed;

  inset: 0;

  display: flex;

  justify-content: center;
  align-items: center;

  padding: 20px;

  background:
    rgba(0, 0, 0, 0.55);
}


.modal.hidden {
  display: none;
}


.modal-content {
  width: min(100%, 380px);

  padding: 35px 25px;

  background: white;

  border-radius: 24px;

  text-align: center;

  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.3);

  animation: pop 0.35s ease;
}


.clear-icon {
  margin-bottom: 10px;

  font-size: 60px;
}


.modal-content h2 {
  margin-bottom: 10px;

  font-size: 32px;
}


.modal-content p {
  margin-bottom: 20px;

  line-height: 1.8;

  color: #666;
}


/* =========================
   結果
========================= */

.result {
  display: flex;

  justify-content: center;

  gap: 12px;

  margin-bottom: 18px;
}


.result-item {
  min-width: 110px;

  padding: 10px;

  background: #f4f4ff;

  border-radius: 12px;
}


.result-item span {
  display: block;

  margin-bottom: 4px;

  color: #777;

  font-size: 12px;
}


.result-item strong {
  color: #5b5bd6;

  font-size: 24px;
}


.new-record {
  color: #e5a500 !important;

  font-weight: bold;

  font-size: 18px;
}


.hidden {
  display: none !important;
}


@keyframes pop {

  from {
    opacity: 0;

    transform:
      scale(0.8);
  }

  to {
    opacity: 1;

    transform:
      scale(1);
  }

}


/* =========================
   スマホ
========================= */

@media (max-width: 500px) {

  body {
    padding: 10px;
  }


  .game {
    padding: 22px 12px;
  }


  .game-board.size-6 {
    gap: 5px;
  }


  .game-board.size-8 {
    gap: 3px;
  }


  .card-front,
  .card-back {
    border-radius: 8px;
  }


  .info-box strong {
    font-size: 16px;
  }

}


@media (max-width: 360px) {

  .difficulty-button {
    padding: 8px 10px;

    font-size: 11px;
  }


  .game-board.size-6 {
    gap: 4px;
  }


  .game-board.size-8 {
    gap: 2px;
  }

}