/* ====== モバイル優先・共通フィット ====== */
html,
body {
  height: 100%;
  margin: 0;
  background: #111;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

#fit {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game-root {
  /* JSで data-base を読み取り width/height を与え、transform で拡大縮小 */
  transform-origin: top left;
  image-rendering: pixelated;
  touch-action: none;
}

#game-area {
  position: relative;
  width: 100%;
  /* ← #game-root 基準 */
  height: 100%;
  /* ← #game-root 基準 */
  background: #000;
  overflow: hidden;
}

/* ====== 背景・キャラ ====== */
#bg {
  position: absolute;
  top: 0;
  left: 50%;
  height: 100%;
  width: auto;
  max-width: none;
  transform: translate(-50%, 0) scale(1);
  transform-origin: center top;
  transition: transform 0.5s ease;
  z-index: 0;
}

#boss {
  position: absolute;
  left: 50%;
  top: 30px;
  transform: translateX(-50%);
  width: clamp(160px, 36vw, 300px);
  /* 参考値：内部基準でも可変 */
  transition: transform 0.3s ease, top 0.3s ease;
  z-index: 2;
}

#player {
  position: absolute;
  left: 50%;
  bottom: 8vh;
  width: clamp(140px, 32vw, 300px);
  height: auto;
  transform: translateX(-50%);
  transform-origin: center bottom;
  transition: transform 0.35s ease;
  z-index: 20;
}



@keyframes barrel-spin-cw {
  from {
    transform: rotate(0)
  }

  to {
    transform: rotate(720deg)
  }
}

@keyframes barrel-spin-ccw {
  from {
    transform: rotate(0)
  }

  to {
    transform: rotate(-720deg)
  }
}



.bottle {
  position: absolute;
  left: calc(50% - 15px);
  top: 500px;
  width: 80px;
  height: auto;
  transition: top 1s linear;
  z-index: 25;
}

@keyframes bottle-spin-cw {
  from {
    transform: rotate(0)
  }

  to {
    transform: rotate(720deg)
  }
}

.bottle.spin-cw {
  animation: bottle-spin-cw 1s linear forwards;
}

/* ====== UI ====== */
#btn-throw {
  position: absolute;
  /* #game-area 基準 */
  width: 200px;
  height: auto;
  z-index: 1100;
  touch-action: manipulation;
  user-select: none;
  pointer-events: auto;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .3));
}

#btn-throw.disabled {
  opacity: .45;
  filter: grayscale(1);
  transform: scale(.95);
  pointer-events: none;
}

#ammo-count {
  position: absolute;
  z-index: 1150;
  pointer-events: none;
  font-size: 50px;
  font-weight: 800;
  color: #fff;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .35);
  text-shadow: 0 2px 4px rgba(0, 0, 0, .6);
  transform: translateX(-50%);
  white-space: nowrap;
}

#ammo-count .icon {
  width: 100px;
  height: auto;
  vertical-align: -4px;
  margin-right: 6px;
}

/* 画面左右のタップゾーン（ゲーム内に収める） */
.tapzone {
  position: absolute;
  top: 0;
  height: 100%;
  width: 40%;
  z-index: 1000;
  background: transparent;
}

#tap-left {
  left: 0;
}

#tap-right {
  right: 0;
}

/* ライフ点滅・画面シェイク */
@keyframes hurt-blink {

  0%,
  100% {
    opacity: 1;
    filter: none
  }

  50% {
    opacity: .3;
    filter: brightness(1.4) saturate(1.1)
  }
}

#player.hurt-blink {
  animation: hurt-blink .7s linear;
}

@keyframes shake {
  0% {
    transform: translate(0, 0)
  }

  25% {
    transform: translate(-6px, 2px)
  }

  50% {
    transform: translate(6px, -2px)
  }

  75% {
    transform: translate(-4px, 3px)
  }

  100% {
    transform: translate(0, 0)
  }
}

#game-area.shake {
  animation: shake 180ms ease-in-out;
}

/* ★ モバイル最適配置（内部基準で固定） */
@media (max-width: 820px) {
  #boss {
    top: 6vh;
    width: clamp(160px, 30vw, 320px) !important;
  }

  #player {
    bottom: max(8vh, 60px) !important;
    width: clamp(120px, 24vw, 220px) !important;
  }

  #btn-throw {
    left: 3vw !important;
    bottom: 3vh !important;
    top: auto !important;
    transform: none !important;
  }

  #ammo-count {
    left: auto !important;
    right: 3vw !important;
    bottom: 3vh !important;
    transform: none !important;
  }
}


/* === モバイル簡素化：瓶スプライト＆投げボタンを非表示 === */
#btn-throw {
  display: none !important;
}

/* 左下の瓶ボタン */
.bottle {
  display: none !important;
  pointer-events: none !important;
}

/* 飛んでくる瓶も見せない */

/* 残弾はテキストだけに（アイコン隠す） */
#ammo-count .icon {
  display: none !important;
}

#ammo-count {
  font-size: 36px !important;
  padding: 6px 10px;
}

/* ボタン画像は要らない */
#btn-throw {
  display: none !important;
}

/* 投げた瓶スプライトは表示する（以前の非表示指定を上書き） */
.bottle {
  display: block !important;
  pointer-events: none;
}













/* キーフレーム（未定義ならこれを使う） */
@keyframes barrel-spin-cw {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

@keyframes barrel-spin-ccw {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(-360deg);
  }
}

/* --- モバイル長押し対策（iOS/Android）--- */
#game-area,
.tapzone,
#player,
#boss,
img {
  -webkit-touch-callout: none;
  /* iOS: 長押しメニュー無効 */
  -webkit-user-select: none;
  user-select: none;
  /* テキスト選択無効 */
  -webkit-user-drag: none;
  /* 画像ドラッグ無効（Safari系） */
  touch-action: none;
  /* ブラウザ既定のジェスチャ無効 */
  -webkit-tap-highlight-color: transparent;
  /* タップ時の灰色ハイライト除去 */
}

/* === Barrel（樽）はJSで速度指定。CSSは位置と回転の定義だけ === */
.barrel {
  position: absolute;
  z-index: 20;
  /* transition/animation はここに書かない（JSが都度セット） */
}

/* 回転キーフレームは残す（JSが animation-name で使う） */
@keyframes barrel-spin-cw {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

@keyframes barrel-spin-ccw {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(-360deg);
  }
}

/* ✓ ステ2用の最前面レイヤ（JSが #stage2-root を作る） */
#stage2-root {
  position: absolute;
  inset: 0;
  z-index: 5000;
  /* ← tapzone より上 */
  touch-action: none;
  /* ブラウザジェスチャ無効化 */
  pointer-events: auto;
  /* タップを受ける */
}

/* ✓ ステ1の左右タップゾーン（通常は有効、!important付けない） */
.tapzone {
  z-index: 1000;
  /* ← ステ2より下にする */
  pointer-events: auto;
  /* JSの setTapZonesEnabled で切替可能に */
}

/* オーバーレイはボタン操作できるようにする */
.overlay-go,
.overlay-clear,
#go-overlay {
  pointer-events: auto;
  /* ← ここを有効に */
  user-select: none;
}

/* 残弾カウンタだけはタップを奪わない */
#ammo-count {
  pointer-events: none !important;
  user-select: none;
}

/* 入力遅延を避けるためのヒント（GPUに乗せる） */
#player,
#boss,
.barrel,
.bottle,
#stage2-root img {
  will-change: transform, left, top;
}