/* 全要素のサイズ計算にborderとpaddingを含めます。 */
* {
  box-sizing: border-box;
}

/* ページ全体の高さ計算の基準を作ります。 */
html {
  margin: 0;
  height: 100%;
}

/* 画面中央にゲームを配置し、ページ全体の基本デザインを決めます。 */
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
  background: #e7f5dd;
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
}

/* ゲーム全体の外枠と固定サイズを決めます。 */
.container {
  width: 100%;
  max-width: 1196px;
  height: 540px;
  margin: 0 auto;
  background: #fffdf1;
  border: 2px solid #2e4325;
  display: flex;
  flex-direction: column;
}

/* 時間、タイトル、最高記録を横並びにするヘッダーです。 */
.game-header {
  height: 50px;
  flex: 0 0 50px;
  padding: 0 14px;
  background: #f8ffef;
  border-bottom: 2px solid #9bc37d;
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto minmax(120px, 1fr);
  align-items: center;
  gap: 8px;
  color: #263c1f;
  font-weight: 700;
}

/* 左側の時間表示を左寄せにします。 */
.header-left {
  justify-self: start;
  font-size: 16px;
  white-space: nowrap;
}

/* 中央の説明文を中央寄せにします。 */
.header-title {
  justify-self: center;
  text-align: center;
  font-size: 20px;
  line-height: 1.2;
}

/* 右側の最高記録表示を右寄せにします。 */
.header-right {
  justify-self: end;
  min-height: 1em;
  font-size: 15px;
  white-space: nowrap;
}

/* ゲームの背景と、重ねて配置する要素の基準位置を作ります。 */
.game-main {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: grid;
  place-items: center;
  background:
    linear-gradient(rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.04)),
    url("assets/bg.png") center / cover no-repeat,
    #5b9b4a;
}

/* 共通ボタンの見た目を指定します。 */
.btn {
  padding: 13px 28px;
  border: 0;
  border-radius: 8px;
  background: #ffb629;
  color: #3b2600;
  box-shadow: 0 5px 0 #cc7d13;
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  touch-action: manipulation;
}

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

/* 押している間だけボタンを少し下げます。 */
.btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #cc7d13;
}

/* スタートボタンだけ少し大きく表示します。 */
.start-btn {
  z-index: 2;
  font-size: 22px;
  padding: 16px 42px;
}

/* キノコを置くためのゲームステージです。 */
.stage {
  position: absolute;
  inset: 0 0 96px;
  display: none;
  overflow: hidden;
  touch-action: manipulation;
}

/* 画面下に表示するキノコのヒント一覧です。 */
.hint-list {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 96px;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(255, 253, 241, 0.92);
  border-top: 2px solid rgba(46, 67, 37, 0.35);
  overflow-x: auto;
  z-index: 10;
}

/* ヒント内の1つ分のキノコ表示です。 */
.hint-item {
  width: 104px;
  min-width: 86px;
  height: 78px;
  display: grid;
  grid-template-rows: 45px 1fr;
  place-items: center;
  gap: 2px;
  color: #263c1f;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

/* ヒント用のキノコ画像を枠内に収めます。 */
.hint-item img {
  max-width: 46px;
  max-height: 46px;
  object-fit: contain;
}

/* ヒントのキノコ名が長くても折り返せるようにします。 */
.hint-name {
  width: 100%;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

/* 毒キノコの名前の横に付ける赤い印です。 */
.poison-mark {
  margin-left: 3px;
  color: #d7193f;
  font-size: 17px;
  font-weight: 900;
  line-height: 1;
  vertical-align: -1px;
}

/* JavaScriptで作るキノコボタンの基本スタイルです。 */
.mushroom {
  --mushroom-scale: 1;
  position: absolute;
  width: 90px;
  height: 90px;
  padding: 0;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  animation: spawn 0.35s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
  transform-origin: center;
  transition: transform 0.16s ease, filter 0.16s ease, opacity 0.2s ease;
  touch-action: manipulation;
}

/* キノコにマウスを乗せたとき、少し大きくして影を付けます。 */
.mushroom:hover {
  --mushroom-scale: 1.18;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.25));
  z-index: 5;
}

/* 食べられるキノコをタッチした後の消える動きです。 */
.mushroom.is-touched {
  animation: none;
  cursor: default;
  opacity: 0;
  transform: scale(0.35);
  filter: grayscale(0.35);
}

/* 消える途中のキノコはホバーしても大きくしません。 */
.mushroom.is-touched:hover {
  transform: scale(0.35);
  filter: grayscale(0.35);
}

/* 毒キノコをタッチしたときに目立たせます。 */
.mushroom.is-poison-hit {
  animation: none;
  opacity: 1;
  transform: scale(var(--mushroom-scale));
  z-index: 15;
  cursor: default;
  filter: drop-shadow(0 0 12px rgba(215, 25, 63, 0.9)) saturate(1.6);
}

/* 毒キノコの画像だけ左右に揺らします。 */
.mushroom.is-poison-hit img {
  animation: poisonShake 0.3s ease-in-out 4;
}

/* 毒キノコをタッチしたときの名前メッセージです。 */
.mushroom.is-poison-hit::after {
  content: attr(data-message);
  position: absolute;
  left: 50%;
  top: -22px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #d7193f;
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  transform: translateX(-50%);
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.28);
}

/* キノコ画像をボタンいっぱいに表示します。 */
.mushroom img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* キノコを取ったときに浮かび上がるメッセージです。 */
.found-popup {
  position: absolute;
  z-index: 20;
  color: #fff;
  font-size: 26px;
  font-weight: 900;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  animation: floatUp 0.85s ease-out forwards;
}

/* クリアや失敗を表示する結果画面です。 */
.result {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  background: rgba(255, 253, 241, 0.48);
  color: #263c1f;
  text-align: center;
}

/* 失敗時だけ結果画面の色と出方を変えます。 */
.result.is-failed {
  background: rgba(14, 12, 18, 0.48);
  color: #fff;
  transform-origin: top;
  animation: shutterDown 0.45s cubic-bezier(0.19, 1, 0.22, 1) both;
}

/* 失敗時のタイトルを赤く目立たせます。 */
.result.is-failed .result-title {
  color: #ff6b6b;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

/* 失敗時の説明文を暗い背景でも読みやすくします。 */
.result.is-failed .result-text {
  color: #ffe1e1;
}

/* 結果画面の大きなタイトルです。 */
.result-title {
  margin: 0;
  font-size: 34px;
}

/* 結果画面の説明文です。 */
.result-text {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

/* 最高記録を更新したときだけ表示するメッセージです。 */
.new-record {
  display: none;
  margin: 0;
  color: #d56b00;
  font-size: 22px;
  font-weight: 900;
}

/* キノコが出現するときのアニメーションです。 */
@keyframes spawn {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  100% {
    opacity: 1;
    transform: scale(var(--mushroom-scale));
  }
}

/* ゲットしたメッセージが上に浮いて消えるアニメーションです。 */
@keyframes floatUp {
  0% {
    opacity: 0;
    transform: translate(-50%, 8px) scale(0.8);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -44px) scale(1.15);
  }
}

/* 毒キノコをタッチしたときの横揺れアニメーションです。 */
@keyframes poisonShake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-8px, 0);
  }
  75% {
    transform: translate(8px, 0);
  }
}

/* 失敗時の結果画面を上から開くアニメーションです。 */
@keyframes shutterDown {
  0% {
    clip-path: inset(0 0 100% 0);
  }
  100% {
    clip-path: inset(0 0 0 0);
  }
}

/* 画面幅が狭いときのスマートフォン向け調整です。 */
@media (max-width: 640px) {
  /* スマートフォンでもゲーム領域の高さを保ちます。 */
  .container {
    height: 540px;
  }

  /* ヘッダーの余白と列幅を小さい画面向けにします。 */
  .game-header {
    grid-template-columns: 1fr auto 1fr;
    padding: 0 8px;
  }

  /* 左右のヘッダー文字を小さくします。 */
  .header-left,
  .header-right {
    font-size: 12px;
  }

  /* 中央タイトルを小さい画面向けにします。 */
  .header-title {
    font-size: 15px;
  }

  /* スマートフォンではキノコを少し小さくします。 */
  .mushroom {
    width: 76px;
    height: 76px;
  }

  /* ヒント一覧の高さに合わせてステージ下部を空けます。 */
  .stage {
    inset: 0 0 86px;
  }

  /* ヒント一覧を横スクロールしやすい配置にします。 */
  .hint-list {
    height: 86px;
    justify-content: flex-start;
    gap: 8px;
  }

  /* スマートフォン用にヒント1つ分を小さくします。 */
  .hint-item {
    width: 82px;
    grid-template-rows: 40px 1fr;
    font-size: 11px;
  }

  /* スマートフォン用にヒント画像を小さくします。 */
  .hint-item img {
    max-width: 40px;
    max-height: 40px;
  }
}
