/* ===============================================================
   基本スタイル & 背景
   =============================================================== */
body, html {
  height: 100%;
  overflow: hidden; /* ページ全体のスクロールを禁止 */
}

body {
  background-image: url("images/background/background_all.webp");
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  background-position: left center;
  margin: 0;
  padding: 0;
  font-family: sans-serif;
  text-align: center;
  touch-action: manipulation;
}

#back-to-title-btn {
  position: fixed;
  top: 40px;
  left: calc(50% - 150px);
  z-index: 200;
  padding: 8px 16px;
  font-size: 14px;
  white-space: nowrap;
  text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff;
  display: none;
}

/* ===============================================================
   汎用ボタンスタイル
   =============================================================== */
.btn-effect {
  display: inline-block;
  background: #b0c5e9;
  border: 1px solid white;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  color: black;
  text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff;
  font-weight: bold;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  transition: background-color 0.2s;
  padding: 0;
}

.btn-effect:hover {
  background-color: #9aadc7;
}

.btn-effect span {
  display: block;
  padding: inherit;
  font-size: inherit;
}

/* ===============================================================
   画面別レイアウト
   =============================================================== */

/* --- モード選択ボタンなどのスタイル --- */
#title-screen .button-group button,
#difficulty-selection-screen .button-group button,
#puyo-selection-screen #reset-selection-btn,
.popup-content button {
  padding: 12px 20px;
  text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff;
  font-size: 20px;
  min-width: 180px;
}

#title-screen .button-group button,
#difficulty-selection-screen .button-group button {
    font-size: 22px;
}

.button-group {
  display: flex;
  justify-content: center;
  gap: 25px;
  flex-wrap: wrap; 
}

/* --- 画面全体に適用されるオーバーレイの基本スタイル --- */
.fullscreen-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 10px;
  box-sizing: border-box;
}

/* --- タイトル画面 & 難易度選択画面 --- */
#title-screen h1, #difficulty-selection-screen h2, #puyo-selection-screen h2 {
  font-size: 2.5em;
  margin-bottom: 30px;
  color: white;
  text-shadow: 1px 1px 3px #333;
}
#puyo-selection-screen h2 {
  font-size: clamp(1.5rem, 6vw, 2.5rem);
}
#title-screen .button-group button,
#difficulty-selection-screen .button-group button {
  margin: 0 10px;
}
/* テキストの背景スタイル */
.text-bg {
    background: rgba(255, 255, 255, 0.7);
    color: black;
    font-weight: bold;
    text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff;
    padding: 5px 10px;
    border-radius: 8px;
}
/* --- Bモード: ぷよ選択画面 --- */
#puyo-choices-container {
  display: grid;
  grid-template-columns: repeat(5, minmax(55px, 1fr));
  gap: 20px;
  max-width: 600px;
  width: 100%;
}

.puyo-choice-item {
  position: relative;
  height: auto;
  cursor: pointer;
  border: 4px solid transparent;
  border-radius: 12px;
  transition: all 0.2s;
  background: rgba(255, 255, 255, 0.5);
  padding: 5px ;
}

.puyo-choice-item img {
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.puyo-choice-item.selected {
  border-color: red;
  box-shadow: 0 0 20px red;
}

.puyo-name {
    margin: 5px 0 0 0;
    padding: 0;
    font-size: clamp(8px, 2vw, 14px);
    font-weight: bold;
    white-space: nowrap;
    color: black;
    text-align: center;
    text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff; 
}
#image-display-area, #game-screen, #side-panel {
  box-sizing: border-box;
}
#reset-selection-btn {
  margin-top: 30px; 
}


.button-group.vertical {
  flex-direction: column;
  gap: 20px; 
}

#pause-btn {
  width: 100%; 
  padding: 5px 0;
  box-sizing: border-box;
  font-size: 16px;
  margin-top: 20px; 
}
.popup-content {
  background-color: rgba(255, 255, 255, 0.9);
  padding: 40px 60px;
  border-radius: 15px;
  border: 2px solid #ccc;
  text-align: center;
}
.popup-content p {
  font-size: 1.8em;
  margin-bottom: 30px;
  color: #333;
  line-height: 1.5;
}

#credits {
    position: absolute;
    bottom: 20px;
    left: 20px;
    font-size: 14px;
    color: white;
    text-shadow: 1px 1px 2px black;
    text-align: left;
}

#credits a {
  color: #a9d8ff;
}
/* --- ゲーム中の画面 --- */
#game-container {
  display: none;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  color: white;
  box-sizing: border-box;
  
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  transform-origin: center center;
  
  transition: transform 0.2s ease;
}
#game-screen p {
    font-size: 1em;
}

#image-display-area {
  width: 120px;
  padding-top: 50px;
}

#side-panel {
    width: 160px;
    padding-top: -30px;
    text-align: center;
}

#left-panel {
 width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
  box-sizing: border-box;
}
#image-display-area img {
  width: 40px;
  height: 40px;
  display: block;
  margin: 10px auto;
  border: 1px solid white;
}

#side-panel h3:nth-of-type(2) {
  margin-top: 40px;
}
#score-display {
font-size: clamp(1.6em, 2.5vw, 1.9em);
  font-weight: bold;
  background-color: #333;
  border: 1px solid white;
  padding: 10px;
  border-radius: 8px;
  min-height: 1.5em;
  margin-top: 20px;
  margin-bottom: -20px;
  text-shadow: 2px 2px 4px #000;
}

#gameCanvas {
  width: 240px;
  height: 480px;
  background: #000;
  border: 2px solid #fff;
}
canvas {
  display: block;
  margin: 0 auto;
}

.canvas-bg {
  background: rgba(255, 255, 255, 0.7);
  padding: 5px;
  border-radius: 8px;
  display: inline-block;
}
#nextCanvas {
    border-radius: 4px;
}


/* --- ゲーム中操作ボタンのスタイル --- */
#controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  margin-top: 15px;
}

.main-controls {
  display: flex;
  justify-content: center;
  gap: 15px;
  width: 100%;
}

#controls button {
  text-decoration: none;
  background: #668ad8;
  color: #FFF;
  text-shadow: none;
  border-bottom: solid 6px #627295;
  border-radius: 3px;
  cursor: pointer;
  border-left: none;
  border-right: none;
  border-top: none;
  position: relative;
  transition: all 0.1s;
}
#controls button:hover {
  background: #7a9ce2;
}
#controls button:active {
  transform: translateY(6px);
  border-bottom: none;
}

.main-controls button {
  width: 70px;
  height: 70px;
  padding: 0;
}

#controls button span {
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
/* --- サイドパネル内ボタンのスタイル --- */
#side-panel .btn-effect {
  width: 100%;
  padding: 10px 0;
  box-sizing: border-box;
  font-size: 16px;
  border-width: 1px;
}
#ingame-back-to-title-btn {
  margin-top: 0px;
}

#reset {
  margin-top: 25px;
}
#side-panel .btn-effect span {
  font-size: inherit;
  white-space: nowrap;
  position: static;
  transform: none;
  padding: 0;
}


/* --- スコア加算ポップアップ --- */
#score-popup-container {
  position: relative;
  height: 50px;
}
.score-popup {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.5em;
  font-weight: bold;
  color: #ffeb3b;
  text-shadow: 1px 1px 2px black;
  animation: fade-out-up 1.5s ease-out forwards;
  pointer-events: none;
}
@keyframes fade-out-up {
  from {
    opacity: 1;
    top: 10px;
  }
  to {
    opacity: 0;
    top: -30px;
  }
}


/* --- ゲーム中の画像リストのスタイル --- */
.image-list-item {
  display: flex;
  align-items: center;
  gap: 10px; /* 画像と名前の間隔 */
  margin-bottom: 5px;
}

.image-list-item img {
  width: 40px;
  height: 40px;
}
/* --- ゲームオーバー画面の結果表示スタイル --- */
.game-over-title {
  font-size: 1.6rem;
  color: #d9534f;
  margin-bottom: 25px;
  text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff; 
  white-space: nowrap;
}

#game-over-popup .popup-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1);
    transform-origin: center center;
    transition: transform 0.2s ease;
}
#game-over-popup .popup-content button {
    padding: 0.6em 1em;
    font-size: 1rem;
}
#final-score-text {
  font-size: 1.3rem;
  color: #333;
  font-weight: bold;
  margin-bottom: 10px;
  white-space: nowrap;
}
.score-highlight {
  color: #d9534f;
  text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff;
}
/* --- ゲームオーバー画面のリンク --- */
.popup-link-area {
  margin: 20px 0 30px 0;
  color: #333;
  border-bottom: 1px solid #5353ff;
  display: inline-block;
}

.popup-link-area p {
  margin: 0 0 8px 0;
  font-size: 1.2rem;
  white-space: nowrap;
}

.popup-link-area a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: #5353ff; 
  font-weight: bold;
  font-size: 1.2rem;
  transition: transform 0.2s;
  white-space: nowrap;
}
/* デフォルト（スマホ表示）では名前を非表示にする */
.image-list-name {
  display: none;
  color: black;
 
  font-size: 14px;
  font-weight: bold;
  text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff; 
  background: rgba(255, 255, 255, 0.7);
  padding: 3px 8px;
  border-radius: 5px;
  white-space: nowrap;
   border: 1px solid white;
}

/* --- PC向けスタイル (769px以上) --- */
@media screen and (min-width: 769px) {
  /* PC表示の時だけ名前を表示する */
  .image-list-name {
    display: inline;
  }
}