/* style.css - ゲームスタイル */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center; /* 上下中央揃えを追加 */
  padding: 20px;
  overflow-y: auto;
}

body.compact-layout {
  padding: 5px;
}

header {
  text-align: center;
  color: white;
  margin-bottom: 4px;
  flex-shrink: 0;
  /* 難易度選択時に中央配置を邪魔しないよう、絶対配置にする */
  position: absolute;
  top: 20px;
}

header h1 {
  font-size: 1.4em;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  margin-bottom: 2px;
}

header p {
  font-size: 0.8em;
  margin: 0;
}

/* 難易度選択画面 */
#difficultySelect {
  background: white;
  border-radius: 15px;
  padding: 40px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

#difficultySelect h2 {
  color: #333;
  font-size: 1.8em;
  margin-bottom: 10px;
}

.difficulty-buttons {
  display: flex;
  gap: 15px;
}

.difficulty-btn {
  padding: 15px 30px;
  font-size: 1.2em;
  font-weight: bold;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.difficulty-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

.difficulty-btn[data-level="1"] {
  background: #4caf50;
  color: white;
}

.difficulty-btn[data-level="2"] {
  background: #ff9800;
  color: white;
}

.difficulty-btn[data-level="3"] {
  background: #f44336;
  color: white;
}

/* ギャラリーセクション */
.gallery-section {
  margin-top: 30px;
  width: 100%;
  border-top: 2px dashed #eee;
  padding-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.gallery-section h3 {
  color: #666;
  font-size: 1.1em;
  font-weight: bold;
}

.gallery-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.gallery-btn {
  text-decoration: none;
  background: white;
  color: #1976d2;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.9em;
  font-weight: bold;
  transition: all 0.3s ease;
  border: 2px solid #e3f2fd;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.gallery-btn:hover {
  background: #e3f2fd;
  color: #1565c0;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  border-color: #bbdefb;
}

/* ゲームエリア */
#gameArea {
  display: none;
  flex-direction: column;
  background: white;
  border-radius: 15px;
  padding: 8px 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  /* スマホ対応: 画面幅に合わせて縮小 */
  width: 100%;
  max-width: 424px;
  box-sizing: border-box;
}

#gameArea.compact {
  padding: 10px;
}

#gameArea.compact .score-area {
  margin-bottom: 5px;
  padding: 10px;
}

#gameArea.compact .turn-display {
  padding: 5px;
  margin-bottom: 5px;
}

#gameArea.compact #gameCanvas {
  margin-bottom: 10px;
}

#gameArea.compact .controls-area {
  padding: 10px;
  margin-bottom: 5px;
}

#gameArea.compact .button-row {
  margin-top: 5px;
}

/* スコアエリア */
.score-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
  padding: 6px 12px;
  background: #f5f5f5;
  border-radius: 8px;
  flex-shrink: 0;
}

.round-info {
  font-size: 1.2em;
  font-weight: bold;
  color: #333;
}

.wins-display {
  display: flex;
  gap: 20px;
  font-size: 1.1em;
}

.player-wins {
  color: #2196F3;
  font-weight: bold;
}

.ai-wins {
  color: #F44336;
  font-weight: bold;
}

/* ターン表示 */
.turn-display {
  text-align: center;
  padding: 4px;
  background: #e3f2fd;
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 0.95em;
  font-weight: bold;
  color: #1976d2;
  flex-shrink: 0;
  /* 2行分の高さに固定（テキスト増減で画面がずれないよう） */
  line-height: 1.4;
  height: calc(0.95em * 1.4 * 2 + 8px);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Canvas */
#gameCanvas {
  border: 3px solid #333;
  border-radius: 8px;
  display: block;
  margin: 0 auto 4px;
  background: #f5f5f5;
  cursor: pointer;
  /* スマホ対応: 画面幅に合わせて縮小 */
  width: 100%;
  max-width: 400px;
  height: auto;
  aspect-ratio: 400 / 570;
  flex-shrink: 0;
}

/* コントロールエリア */
.controls-area {
  padding: 6px 12px;
  background: #f9f9f9;
  border-radius: 8px;
  margin-bottom: 4px;
  /* 必ず表示されるように縮小を禁止 */
  flex-shrink: 0;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.score-display {
  font-size: 1.1em;
  color: #333;
  line-height: 1.3;
}

#roundScoreTitle {
  font-weight: bold;
  font-size: 0.9em;
  color: #555;
  margin-bottom: 4px;
}

.score-detail {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.score-row {
  display: flex;
  align-items: baseline;
}

.score-row .label {
  display: inline-block;
  width: 6em; /* 幅を微調整して1行に収める */
  white-space: nowrap; /* 改行を禁止 */
  font-size: 0.85em;
  color: #666;
}

.value-container {
  display: inline-block;
  min-width: 3.5em;
  text-align: right;
  font-weight: bold;
}

#playerCurrentScore {
  color: #2196F3;
}

#aiCurrentScore {
  color: #F44336;
}

.balls-display {
  font-size: 1.1em;
  color: #666;
}



/* ボタン */
.button-row {
  display: flex;
  justify-content: center;
  gap: 15px;
}

button {
  padding: 12px 24px;
  font-size: 1.1em;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

#resetBtn {
  background: #607d8b;
  color: white;
}

/* === ゲーム結果エフェクト: 勝利時バウンド === */
@keyframes dropAndBounce {
  0% {
    opacity: 0;
    transform: translateY(-500px);
  }
  15% {
    opacity: 1;
    transform: translateY(0);
  }
  35% {
    transform: translateY(-60px);
  }
  55% {
    transform: translateY(0);
  }
  75% {
    transform: translateY(-25px);
  }
  85% {
    transform: translateY(0);
  }
  93% {
    transform: translateY(-10px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-content.anim-win {
  animation: dropAndBounce 2.4s ease-out forwards;
}

/* === ゲーム結果エフェクト: 敗北時蜃気楼 === */
@keyframes mirageFadeIn {
  0% {
    opacity: 0;
    filter: blur(10px);
    transform: scale(0.95) skewX(5deg) translateY(10px);
  }
  30% {
    opacity: 0.4;
    filter: blur(5px);
    transform: scale(1.02) skewX(-4deg) translateY(-2px);
  }
  60% {
    opacity: 0.7;
    filter: blur(2px);
    transform: scale(0.98) skewX(2deg) translateY(2px);
  }
  100% {
    opacity: 1;
    filter: blur(0);
    transform: scale(1) skewX(0) translateY(0);
  }
}

.result-content.anim-lose {
  animation: mirageFadeIn 1.5s ease-in-out forwards;
}

/* ゲーム結果 */
#gameResult {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.result-content {
  background: white;
  padding: 40px;
  border-radius: 15px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

#resultText {
  font-size: 3em;
  font-weight: bold;
  margin-bottom: 20px;
}

.result-win {
  color: #4caf50;
}

.result-lose {
  color: #f44336;
}

.result-draw {
  color: #ff9800;
}

#resultDetails {
  font-size: 1.3em;
  color: #333;
  margin-bottom: 30px;
}

#resultDetails p {
  margin: 10px 0;
}

#playAgainBtn {
  background: #2196F3;
  color: white;
  padding: 15px 40px;
  font-size: 1.2em;
}

/* レスポンシブ */
@media (max-width: 900px) {
  #gameCanvas {
    width: 100%;
    height: auto;
  }

  .difficulty-buttons {
    flex-direction: column;
  }

  .score-area {
    flex-direction: column;
    gap: 10px;
  }
}

/* カットイン演出 */
#cutInOverlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  z-index: 2000;
  display: none;
  flex-direction: column;
  -webkit-flex-direction: column;
  justify-content: center;
  -webkit-justify-content: center;
  align-items: center;
  -webkit-align-items: center;
  overflow: hidden;
  pointer-events: none;
  gap: 50px;
  background: transparent;
}

.cut-in-band {
  width: 150%;
  height: 150px;
  display: flex;
  display: -webkit-flex;
  align-items: center;
  -webkit-align-items: center;
  justify-content: center;
  -webkit-justify-content: center;
  position: relative;
  visibility: hidden;
  /* 最初は隠しておく */
}

/* プレイヤー帯の出現アニメーション */
.player-band.active {
  visibility: visible;
  animation: slideInLeft 0.6s cubic-bezier(0.23, 1, 0.32, 1) forwards;
  -webkit-animation: slideInLeft 0.6s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

/* AI帯の出現アニメーション */
.ai-band.active {
  visibility: visible;
  animation: slideInRight 0.6s cubic-bezier(0.23, 1, 0.32, 1) forwards;
  -webkit-animation: slideInRight 0.6s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

@keyframes slideInLeft {
  from {
    transform: translate3d(-100%, 0, 0) skewX(-15deg);
  }

  to {
    transform: translate3d(0, 0, 0) skewX(-15deg);
  }
}

@-webkit-keyframes slideInLeft {
  from {
    -webkit-transform: translate3d(-100%, 0, 0) skewX(-15deg);
  }

  to {
    -webkit-transform: translate3d(0, 0, 0) skewX(-15deg);
  }
}

@keyframes slideInRight {
  from {
    transform: translate3d(100%, 0, 0) skewX(-15deg);
  }

  to {
    transform: translate3d(0, 0, 0) skewX(-15deg);
  }
}

@-webkit-keyframes slideInRight {
  from {
    -webkit-transform: translate3d(100%, 0, 0) skewX(-15deg);
  }

  to {
    -webkit-transform: translate3d(0, 0, 0) skewX(-15deg);
  }
}

.player-band {
  background: linear-gradient(to right, #2196F3 0%, #1976D2 100%);
  background: -webkit-linear-gradient(left, #2196F3 0%, #1976D2 100%);
  border-bottom: 5px solid #fff;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.ai-band {
  background: linear-gradient(to right, #F44336 0%, #D32F2F 100%);
  background: -webkit-linear-gradient(left, #F44336 0%, #D32F2F 100%);
  border-top: 5px solid #fff;
  box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.3);
}

.cut-in-content {
  transform: skewX(15deg);
  -webkit-transform: skewX(15deg);
  display: flex;
  display: -webkit-flex;
  align-items: center;
  -webkit-align-items: center;
  justify-content: space-between;
  -webkit-justify-content: space-between;
  width: 90%;
  max-width: 400px;
  /* キャリア幅に合わせる、ただし画面幅を超えない */
  padding: 0 10px;
  color: white;
  font-style: italic;
  font-weight: 900;
  text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.5);
}

.cut-in-name {
  font-size: min(4rem, 12vw);
  /* 小さい画面ではフォントサイズも縮小 */
  letter-spacing: 0.1em;
  white-space: nowrap;
}

.cut-in-image-container {
  width: min(130px, 30vw);
  height: min(130px, 30vw);
  background: rgba(255, 255, 255, 0.1);
  border: 3px solid rgba(255, 255, 255, 0.5);
  display: flex;
  display: -webkit-flex;
  align-items: center;
  -webkit-align-items: center;
  justify-content: center;
  -webkit-justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.cut-in-image-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* 一時停止関連スタイル */
.pause-control {
  width: 100%;
  margin-bottom: 5px;
}
.pause-btn {
  width: 100%;
  display: block;
  background: #9e9e9e;
  color: white;
  padding: 8px 16px;
  font-size: 0.9em;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  transition: all 0.3s;
}
.pause-btn:hover {
  transform: translateY(-2px);
  background: #757575;
}

#pauseOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5); /* グレーアウト */
  display: none; /* 初期は非表示 */
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.pause-content {
  background: white;
  padding: 30px;
  border-radius: 15px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  max-width: 90%;
}

.pause-content h2 {
  margin-bottom: 20px;
  color: #333;
}

.pause-buttons {
  display: flex;
  gap: 15px;
  justify-content: center;
}

.resume-btn {
  background: #4caf50;
  color: white;
}

.giveup-btn {
  background: #f44336;
  color: white;
}