/* すべての要素で、paddingとborderを幅・高さに含めて計算します。 */
* {
  box-sizing: border-box;
}

/* ページ全体の高さを画面いっぱいに使います。 */
html {
  margin: 0;
  height: 100%;
}

/* bodyはゲーム画面を中央に配置し、背景を作ります。 */
body {
  margin: 0;
  height: 100vh;
  font-family: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic", sans-serif;
  background:
    radial-gradient(1px 1px at 10% 20%, rgba(255, 255, 255, 0.65) 100%, transparent),
    radial-gradient(1px 1px at 28% 64%, rgba(255, 255, 255, 0.45) 100%, transparent),
    radial-gradient(1px 1px at 48% 18%, rgba(255, 255, 255, 0.7) 100%, transparent),
    radial-gradient(1.5px 1.5px at 74% 34%, rgba(238, 185, 92, 0.7) 100%, transparent),
    linear-gradient(160deg, #08110f 0%, #143026 56%, #050807 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* ゲーム本体の外枠です。 */
.container {
  margin: 0 auto;
  width: 100%;
  max-width: 1196px;
  height: 540px;
  background: linear-gradient(160deg, #101b17 0%, #1f3a2f 56%, #090d0c 100%);
  border: 2px solid #73542b;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 18px 44px rgba(11, 4, 24, 0.45), inset 0 0 42px rgba(0, 0, 0, 0.24);
}

/* 上部のヘッダーを3列に分けて配置します。 */
.game-header {
  height: 50px;
  flex: 0 0 50px;
  padding: 0 16px;
  background: linear-gradient(90deg, #4b1f16, #9b3d24);
  border-bottom: 1px solid rgba(238, 205, 150, 0.28);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  color: #fff;
}

/* 左右のヘッダー文字の共通設定です。 */
.header-left,
.header-right {
  min-width: 0;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

/* 現在の問題番号を左側に表示します。 */
.header-left {
  color: #f2dfb5;
  justify-self: start;
}

/* ゲームタイトルを中央に表示します。 */
.header-center {
  color: #ffffff;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0;
  text-shadow: 0 0 12px rgba(238, 185, 92, 0.72);
  justify-self: center;
}

/* 正解数を右側に表示します。 */
.header-right {
  color: #ffd36f;
  justify-self: end;
}

/* スタート、問題、結果の各画面を重ねるための領域です。 */
.game-main {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

/* スタートボタンとリトライボタンの共通デザインです。 */
.btn {
  min-width: 148px;
  min-height: 48px;
  padding: 11px 28px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #b8482a, #763018);
  color: #fff;
  font: inherit;
  font-size: 19px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 5px #35170f, 0 0 20px rgba(184, 72, 42, 0.36);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  touch-action: manipulation;
}

/* ボタンにマウスを重ねたとき、少し明るくします。 */
.btn:hover {
  filter: brightness(1.08);
}

/* ボタンを押したとき、下に沈むように見せます。 */
.btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px #35170f;
}

/* 各画面の基本サイズです。 */
.screen {
  width: 100%;
  height: 100%;
}

/* スタート画面を中央寄せで表示します。 */
.start-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
}

/* スタート画面の丸いアイコンです。 */
.start-icon {
  width: 82px;
  height: 82px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(238, 205, 150, 0.44);
  color: #ffd36f;
  font-size: 42px;
  font-weight: 900;
  animation: float 2s ease-in-out infinite;
}

/* アイコンを上下にゆっくり動かすアニメーションです。 */
@keyframes float {
  0%,
  100% {
    transform: translateY(0) rotate(-3deg);
  }

  50% {
    transform: translateY(-12px) rotate(3deg);
  }
}

/* スタート画面のタイトルです。 */
.start-title {
  margin: 0;
  font-size: 34px;
  line-height: 1.2;
  text-shadow: 0 0 18px rgba(238, 185, 92, 0.7);
}

/* スタート画面の説明文です。 */
.start-sub {
  max-width: 520px;
  margin: 0;
  color: #d7c39a;
  font-size: 17px;
  line-height: 1.7;
}

/* 問題画面は、showクラスが付くまで非表示にします。 */
.question-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  padding: 14px 20px;
}

/* JavaScriptでshowクラスを付けると問題画面を表示します。 */
.question-screen.show {
  display: flex;
}

/* よみふだを表示する枠です。 */
.yomifuda {
  width: 100%;
  flex: 0 0 auto;
  padding: 12px 20px;
  border: 2px solid rgba(185, 151, 91, 0.56);
  border-radius: 8px;
  background: rgba(8, 16, 13, 0.62);
  text-align: center;
}

/* よみふだの小さなラベルです。 */
.yomi-label {
  margin-bottom: 4px;
  color: #d8b06a;
  font-size: 12px;
  font-weight: 700;
}

/* よみふだの本文です。 */
.yomi-text {
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.45;
  text-shadow: 0 0 10px rgba(238, 185, 92, 0.46);
}

/* 4枚のカードを横並びのグリッドで表示します。 */
.cards-grid {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

/* 妖怪カードの基本デザインです。 */
.yokai-card {
  min-width: 0;
  min-height: 0;
  padding: 10px 8px;
  border: 2px solid #b9975b;
  border-radius: 8px;
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.72) 0 1px, transparent 1.5px),
    radial-gradient(circle at 78% 62%, rgba(164, 123, 65, 0.18) 0 1px, transparent 1.5px),
    linear-gradient(180deg, #fff8df 0%, #f2ddae 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
}

/* カードにマウスを重ねたとき、少し浮かせます。 */
.yokai-card:hover {
  transform: translateY(-4px) scale(1.02);
  border-color: #e0bd6c;
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.72) 0 1px, transparent 1.5px),
    radial-gradient(circle at 78% 62%, rgba(164, 123, 65, 0.18) 0 1px, transparent 1.5px),
    linear-gradient(180deg, #fffbe9 0%, #f7e4b9 100%);
  box-shadow: 0 8px 22px rgba(59, 34, 11, 0.34);
}

/* 正解したカードの表示です。 */
.yokai-card.correct {
  border-color: #ffe278;
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.72) 0 1px, transparent 1.5px),
    radial-gradient(circle at 78% 62%, rgba(164, 123, 65, 0.18) 0 1px, transparent 1.5px),
    linear-gradient(180deg, #fffbe9 0%, #f7e4b9 100%);
  box-shadow: 0 0 26px rgba(255, 226, 120, 0.55);
  animation: correctPop 0.4s ease;
  pointer-events: none;
}

/* 不正解で選んだカードの表示です。 */
.yokai-card.wrong {
  border-color: #ff6363;
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.62) 0 1px, transparent 1.5px),
    radial-gradient(circle at 78% 62%, rgba(164, 123, 65, 0.15) 0 1px, transparent 1.5px),
    linear-gradient(180deg, #fff1df 0%, #efc9b7 100%);
  animation: wrongShake 0.38s ease;
  pointer-events: none;
}

/* 回答後、選べないカードを薄く表示します。 */
.yokai-card.disabled {
  pointer-events: none;
  opacity: 0.55;
}

/* 不正解時に、正しいカードを強調します。 */
.yokai-card.highlight {
  opacity: 1;
  border-color: #ffd24f;
  border-width: 4px;
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.76) 0 1px, transparent 1.5px),
    radial-gradient(circle at 78% 62%, rgba(164, 123, 65, 0.18) 0 1px, transparent 1.5px),
    linear-gradient(180deg, #fffbe9 0%, #f7e4b9 100%);
  box-shadow: 0 0 0 3px rgba(255, 210, 79, 0.35), 0 0 24px rgba(255, 210, 79, 0.7);
}

/* 正解カードを少し大きくして戻すアニメーションです。 */
@keyframes correctPop {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.07);
  }

  100% {
    transform: scale(1);
  }
}

/* 不正解カードを左右に揺らすアニメーションです。 */
@keyframes wrongShake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-6px);
  }

  75% {
    transform: translateX(6px);
  }
}

/* カード内の画像を中央に置くための枠です。 */
.card-img-wrap {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 妖怪画像のサイズと影を設定します。 */
.card-img {
  max-width: 100%;
  max-height: 210px;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
  transition: filter 0.2s ease;
}

/* 正解時は画像の影を明るくします。 */
.yokai-card.correct .card-img {
  filter: drop-shadow(0 0 12px rgba(255, 226, 120, 0.85));
}

/* 画像が読み込めないときの代替表示です。 */
.card-placeholder {
  width: 82px;
  height: 82px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 226, 120, 0.42);
  color: #ffe278;
  font-size: 36px;
  font-weight: 900;
}

/* カード下部の妖怪名です。 */
.card-name {
  max-width: 100%;
  color: #3e2515;
  font-size: 15px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

/* 正解・不正解の記号をカード中央に重ねます。 */
.judge-mark {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 5;
  transform: translate(-50%, -50%);
  width: auto;
  height: auto;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  font-size: 96px;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  opacity: 0;
  text-shadow: 0 3px 0 rgba(255, 248, 223, 0.92), 0 0 14px rgba(0, 0, 0, 0.55);
  transition: opacity 0.2s ease;
}

/* 正解マークの色です。 */
.yokai-card.correct .judge-mark {
  color: #128447;
}

/* 不正解マークの色です。 */
.yokai-card.wrong .judge-mark {
  color: #c82924;
}

/* 正解・不正解の状態になったときだけ記号を表示します。 */
.yokai-card.correct .judge-mark,
.yokai-card.wrong .judge-mark {
  opacity: 1;
}

/* 結果画面は、showクラスが付くまで非表示にします。 */
.result-screen {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  background: rgba(7, 13, 11, 0.96);
  text-align: center;
}

/* JavaScriptでshowクラスを付けると結果画面を表示します。 */
.result-screen.show {
  display: flex;
}

/* 結果画面のアイコンです。 */
.result-icon {
  color: #ffd36f;
  font-size: 28px;
  font-weight: 900;
  animation: float 2s ease-in-out infinite;
}

/* 結果画面のタイトルです。 */
.result-title {
  margin: 0;
  color: #fff;
  font-size: 30px;
  line-height: 1.2;
  text-shadow: 0 0 16px rgba(238, 185, 92, 0.72);
}

/* 結果画面の正解数です。 */
.result-score {
  color: #ffd36f;
  font-size: 42px;
  font-weight: 900;
  text-shadow: 0 0 20px rgba(255, 226, 120, 0.66);
}

/* 結果画面のメッセージです。 */
.result-msg {
  margin: 0;
  color: #d7c39a;
  font-size: 18px;
}

/* 画面幅が720px以下のとき、スマートフォン向けの配置にします。 */
@media (max-width: 720px) {
  .game-header {
    padding: 0 10px;
    gap: 8px;
  }

  .header-left,
  .header-right {
    font-size: 12px;
  }

  .header-center {
    font-size: 17px;
  }

  .question-screen {
    padding: 12px;
  }

  .cards-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .yomi-text {
    font-size: 18px;
  }

  .card-img {
    max-height: 120px;
  }
}
