/* 全画面トランジションのタイトル文字用ディスプレイ書体（自己ホスト・OFL。CDN は依存ゼロ方針に反するため不可）。 */
@font-face {
  font-family: "Cinzel";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("/fonts/cinzel.woff2") format("woff2");
}

:root {
  color-scheme: dark;
  --ink: #fff7dd;
  --muted: #b9cec2;
  --gold: #ffd15c;
  --field: #7dd873;
  --danger: #ff5c57;
  --panel: rgba(8, 13, 13, 0.74);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: #050807;
}

button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 6px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.5);
  font: inherit;
  font-weight: 900;
}

button.is-on {
  color: #07100b;
  background: var(--field);
}

.overlay {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: #101512;
  isolation: isolate;
}

.bg,
.shade {
  position: absolute;
  inset: 0;
}

.bg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  transform: scale(1.06);
}

.shade {
  background:
    linear-gradient(180deg, rgba(5, 8, 7, 0.12), rgba(5, 8, 7, 0.68)),
    radial-gradient(circle at 66% 48%, rgba(255, 92, 87, 0), rgba(255, 92, 87, 0));
  z-index: 1;
}

body[data-phase="idle"] .shade,
body[data-phase="complete"] .shade {
  background: linear-gradient(180deg, rgba(5, 8, 7, 0.04), rgba(5, 8, 7, 0.36));
}

.bar,
.stage {
  position: relative;
  z-index: 2;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  padding: 0 20px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.5), transparent);
}

/* タイトル + フェーズを 1 行に並べる */
.titlebar {
  display: flex;
  align-items: center;
  min-width: 0;
}

/* ゲームタイトル: フェーズと同じ大きさ・金のグラデ + 発光でオシャレに */
.brand {
  font-size: 1.95rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.03em;
  background: linear-gradient(177deg, #fff6d2 6%, #ffd763 44%, #f0a52e 78%, #c97e16 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--gold);
  filter:
    drop-shadow(0 1px 0 rgba(60, 30, 0, 0.55))
    drop-shadow(0 0 9px rgba(255, 198, 74, 0.5));
}

#phaseLabel {
  font-size: 1.95rem;
  line-height: 1;
  font-weight: 800;
  color: var(--ink);
}

/* タイトルとフェーズの間の小さな菱形セパレータ（クエスト一覧のアイコンと調和） */
#phaseLabel::before {
  content: "◆";
  margin: 0 0.5em;
  font-size: 0.6em;
  font-weight: 900;
  color: rgba(255, 209, 92, 0.72);
  vertical-align: 0.2em;
  filter: drop-shadow(0 0 5px rgba(255, 209, 92, 0.5));
}

.buttons {
  display: flex;
  gap: 6px;
}

#audioButton {
  position: fixed;
  right: 10px;
  bottom: 10px;
  z-index: 20;
  width: 42px;
  height: 38px;
  font-size: 1.15rem;
}

/* 「街に戻る」ボタン：音 ON/OFF ボタン(bottom:10px,高さ38px)の真上に積む。 */
#townButton {
  position: fixed;
  right: 10px;
  bottom: 56px;
  z-index: 20;
  width: 42px;
  height: 38px;
  font-size: 1.15rem;
}

.stage {
  height: calc(100vh - 60px);
  min-height: 116px;
  overflow: hidden;
  perspective: 480px;
}

body[data-phase="battle"] .stage {
  overflow: visible;
}

.stage[data-shake="light"] {
  animation: stageShakeLight 0.18s steps(2);
}

.stage[data-shake="hit"] {
  animation: stageShakeHit 0.22s steps(2);
}

.stage[data-shake="skill"] {
  animation: stageShakeSkill 0.28s steps(2);
}

.hero,
.monster,
#fxCanvas {
  position: absolute;
}

.hero {
  left: 50%;
  bottom: max(-178px, -45vh);
  width: min(82vw, 540px);
  height: min(95vh, 600px);
  z-index: 5; /* モンスター(z-index:4)より必ず手前。同値だと DOM 後勝ちで勇者が裏に回るため */
  transform: translateX(-50%) translateY(0) rotate(0deg);
  transform-origin: center bottom;
  animation: heroWalkInPlace 0.72s ease-in-out infinite;
  filter: drop-shadow(0 15px 10px rgba(0, 0, 0, 0.34));
}

.hero img,
.monster img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.monster img {
  position: relative;
  z-index: 1;
  transform: scale(var(--monster-sprite-scale, 1));
  transform-origin: center center;
}

.monster[data-sprite="goblin"] {
  --monster-sprite-scale: 0.8;
}

.monster[data-sprite="slime"] {
  --monster-sprite-scale: 0.5;
}

.monster[data-sprite="witch"],
.monster[data-sprite="succubus"],
.monster[data-sprite="dullahan"],
.monster[data-sprite="dark-mage"],
.monster[data-sprite="wolf-beastwoman"],
.monster[data-sprite="dark-knight"] {
  --monster-sprite-scale: 1.2;
}

.monster[data-sprite="grim-reaper"],
.monster[data-sprite="demon-lord"] {
  --monster-sprite-scale: 1.3;
}

.monster[data-sprite="dragon"] {
  --monster-sprite-scale: 1.4;
}

body[data-phase="idle"] .hero,
body[data-phase="complete"] .hero {
  left: 34%;
  bottom: max(-38px, -12vh);
  width: min(72vw, 440px);
  height: min(82vh, 440px);
  animation: heroRest 2.4s ease-in-out infinite;
  filter: drop-shadow(0 12px 9px rgba(0, 0, 0, 0.28));
}

.monster {
  --monster-rest-filter: drop-shadow(0 13px 9px rgba(0, 0, 0, 0.42));
  left: 50%;
  top: 47%;
  width: min(82vw, 520px);
  height: min(62vh, 383px);
  z-index: 3; /* 勇者(5)・全精霊より背面。水精霊(Aqua z-index:4)を「敵より前・勇者より後ろ」に置くため 4→3 に下げた */
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.76);
  transform-origin: center center;
  transition: opacity 180ms ease, transform 180ms ease, filter 180ms ease;
  filter: var(--monster-rest-filter);
}

.monster::before,
.monster::after {
  position: absolute;
  inset: -16% -18%;
  z-index: 0;
  pointer-events: none;
  content: "";
  opacity: 0;
}

.monster::before {
  border-radius: 50%;
  background:
    radial-gradient(ellipse at center, rgba(226, 255, 205, 0.58) 0 11%, rgba(117, 220, 179, 0.32) 12% 18%, transparent 20%),
    conic-gradient(from 18deg, transparent 0 13%, rgba(135, 255, 215, 0.64) 15% 19%, transparent 21% 36%, rgba(255, 221, 128, 0.72) 38% 43%, transparent 45% 61%, rgba(160, 128, 255, 0.62) 64% 69%, transparent 71% 100%);
  filter: blur(0.5px) drop-shadow(0 0 17px rgba(128, 255, 215, 0.54));
  transform: scale(0.42) rotate(-26deg);
}

.monster::after {
  background:
    radial-gradient(circle at 24% 66%, rgba(226, 232, 211, 0.44) 0 7%, transparent 15%),
    radial-gradient(circle at 37% 29%, rgba(189, 171, 255, 0.38) 0 6%, transparent 14%),
    radial-gradient(circle at 63% 72%, rgba(165, 240, 211, 0.36) 0 8%, transparent 16%),
    radial-gradient(circle at 78% 34%, rgba(255, 217, 126, 0.34) 0 5%, transparent 13%);
  filter: blur(5px);
  transform: translateY(14px) scale(0.72);
}

.enemy-status {
  position: absolute;
  left: 50%;
  top: -18px;
  z-index: 2;
  display: none;
  justify-content: center;
  transform: translateX(-50%);
  filter: drop-shadow(0 4px 5px rgba(0, 0, 0, 0.48));
}

/* モンスター名のみ。背景は文字幅に合わせた最小限、中央寄せ。 */
#monsterName {
  display: inline-block;
  max-width: min(60vw, 260px);
  padding: 2px 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 5px;
  background: rgba(8, 13, 13, 0.72);
  font-size: 1.16rem;
  font-weight: 900;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body[data-phase="battle"] .monster {
  opacity: 1;
  transform: translate(-50%, -50%) scale(0.8); /* モンスターを 2 割縮小 */
  filter: var(--monster-rest-filter);
  animation: monsterBattleIdle 0.9s steps(2) infinite;
}

#monsterStage.monster[data-action="appear"] {
  opacity: 1;
  transform: translate(-50%, -50%) scale(0.8);
  animation: monsterAppear 0.64s cubic-bezier(0.18, 0.86, 0.26, 1), monsterBattleIdle 0.9s steps(2) 0.64s infinite;
}

#monsterStage.monster[data-action="appear"]::before {
  animation: monsterPortalOpen 0.64s ease-out;
}

#monsterStage.monster[data-action="appear"]::after {
  animation: monsterArrivalSmoke 0.68s ease-out;
}

#monsterStage.monster[data-action="defeat"] {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(0.8);
  animation: monsterDefeat 0.58s cubic-bezier(0.3, 0, 0.22, 1) forwards;
}

#monsterStage.monster[data-action="defeat"]::before {
  animation: monsterDefeatFlash 0.58s ease-out forwards;
}

#monsterStage.monster[data-action="defeat"]::after {
  animation: monsterDefeatShards 0.58s steps(4, end) forwards;
}

.monster-impact {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 6;
  width: 66%;
  height: 59%;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.54);
  transform-origin: center center;
  will-change: opacity, transform, filter;
}

.monster-impact::before,
.monster-impact::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
}

.impact-fire {
  border-radius: 48% 48% 42% 42%;
  background:
    radial-gradient(ellipse at 50% 72%, rgba(255, 245, 196, 0.95) 0 12%, transparent 26%),
    conic-gradient(from -28deg at 50% 60%, transparent 0 7%, rgba(255, 236, 128, 0.96) 8% 14%, rgba(255, 92, 32, 0.88) 17% 23%, transparent 26% 35%, rgba(255, 190, 50, 0.94) 38% 47%, rgba(255, 55, 32, 0.86) 50% 57%, transparent 60% 69%, rgba(255, 222, 78, 0.92) 72% 79%, rgba(255, 67, 30, 0.84) 82% 88%, transparent 92% 100%);
  filter:
    blur(0.2px)
    drop-shadow(0 0 16px rgba(255, 56, 24, 0.95))
    drop-shadow(0 0 34px rgba(255, 156, 36, 0.82));
  animation: monsterImpactFire 0.74s cubic-bezier(0.16, 0.82, 0.22, 1) forwards;
}

.impact-fire::before {
  inset: 5% 13% 2%;
  border-radius: 46% 46% 38% 38%;
  background:
    radial-gradient(ellipse at 24% 78%, rgba(255, 248, 198, 0.92) 0 8%, transparent 21%),
    radial-gradient(ellipse at 48% 52%, rgba(255, 218, 78, 0.9) 0 9%, transparent 24%),
    radial-gradient(ellipse at 73% 70%, rgba(255, 113, 42, 0.86) 0 11%, transparent 26%),
    linear-gradient(0deg, rgba(255, 46, 24, 0.72), transparent 68%);
  transform-origin: center bottom;
  animation: monsterImpactFireTongues 0.74s ease-out forwards;
}

.impact-fire::after {
  inset: 18% 8% 6%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 18% 76%, rgba(255, 206, 74, 0.86) 0 4%, transparent 9%),
    radial-gradient(circle at 34% 35%, rgba(255, 88, 28, 0.9) 0 5%, transparent 11%),
    radial-gradient(circle at 64% 27%, rgba(255, 238, 128, 0.86) 0 4%, transparent 10%),
    radial-gradient(circle at 82% 68%, rgba(255, 70, 24, 0.78) 0 6%, transparent 13%);
  animation: monsterImpactSparks 0.74s ease-out forwards;
}

.impact-earth {
  background:
    radial-gradient(ellipse at 50% 72%, rgba(91, 52, 24, 0.84) 0 12%, rgba(153, 114, 58, 0.62) 13% 24%, transparent 42%),
    radial-gradient(ellipse at 50% 56%, rgba(255, 229, 146, 0.7) 0 7%, transparent 18%);
  filter:
    drop-shadow(0 0 14px rgba(255, 204, 105, 0.68))
    drop-shadow(0 12px 10px rgba(0, 0, 0, 0.36));
  animation: monsterImpactEarth 0.78s cubic-bezier(0.12, 0.78, 0.18, 1) forwards;
}

.impact-earth::before {
  inset: 10% 8% 0;
  background:
    radial-gradient(circle at 17% 60%, #6c4327 0 5%, transparent 5.5%),
    radial-gradient(circle at 31% 30%, #c18a45 0 7%, transparent 7.5%),
    radial-gradient(circle at 48% 70%, #8e5b2f 0 9%, transparent 9.5%),
    radial-gradient(circle at 64% 38%, #d7aa65 0 6%, transparent 6.5%),
    radial-gradient(circle at 81% 62%, #76502f 0 8%, transparent 8.5%);
  filter:
    drop-shadow(-16px -22px 0 rgba(151, 98, 50, 0.92))
    drop-shadow(19px -18px 0 rgba(214, 164, 84, 0.86))
    drop-shadow(-24px 18px 0 rgba(91, 61, 35, 0.88))
    drop-shadow(25px 16px 0 rgba(120, 84, 45, 0.88));
  animation: monsterImpactRocks 0.78s steps(4, end) forwards;
}

.impact-earth::after {
  inset: 26% 7% 10%;
  border: 10px solid rgba(238, 197, 110, 0.78);
  border-right-color: rgba(111, 82, 47, 0.48);
  border-bottom-color: rgba(111, 82, 47, 0.38);
  border-radius: 50%;
  box-shadow:
    inset 0 0 18px rgba(255, 231, 158, 0.44),
    0 0 22px rgba(255, 206, 102, 0.52);
  animation: monsterImpactShockRing 0.78s ease-out forwards;
}

.impact-wind {
  background:
    linear-gradient(128deg, transparent 10%, rgba(232, 255, 249, 0.96) 13% 17%, rgba(110, 255, 224, 0.72) 18% 23%, transparent 26%),
    linear-gradient(148deg, transparent 24%, rgba(255, 255, 255, 0.92) 28% 31%, rgba(148, 241, 255, 0.68) 32% 36%, transparent 40%),
    linear-gradient(116deg, transparent 47%, rgba(223, 255, 209, 0.96) 51% 54%, rgba(77, 222, 255, 0.62) 55% 60%, transparent 64%);
  filter:
    drop-shadow(0 0 12px rgba(196, 255, 226, 0.92))
    drop-shadow(0 0 28px rgba(93, 223, 255, 0.66));
  animation: monsterImpactWind 0.66s ease-out forwards;
}

.impact-wind::before {
  inset: 11% 0;
  border: 5px solid rgba(210, 255, 236, 0.72);
  border-left-color: transparent;
  border-bottom-color: transparent;
  border-radius: 50%;
  transform: rotate(-24deg);
  animation: monsterImpactWindRing 0.66s ease-out forwards;
}

.impact-wind::after {
  inset: 3% 8%;
  background:
    linear-gradient(35deg, transparent 37%, rgba(255, 255, 255, 0.95) 39% 42%, transparent 45%),
    linear-gradient(-36deg, transparent 42%, rgba(178, 255, 222, 0.88) 45% 48%, transparent 51%),
    linear-gradient(18deg, transparent 57%, rgba(120, 236, 255, 0.76) 60% 63%, transparent 66%);
  animation: monsterImpactWindCross 0.66s ease-out forwards;
}

.impact-water {
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 50% 58%, rgba(235, 255, 255, 0.94) 0 9%, rgba(99, 227, 255, 0.78) 10% 20%, transparent 42%),
    radial-gradient(ellipse at 50% 73%, rgba(49, 136, 255, 0.48) 0 12%, transparent 36%);
  filter:
    drop-shadow(0 0 15px rgba(103, 221, 255, 0.98))
    drop-shadow(0 0 32px rgba(83, 131, 255, 0.66));
  animation: monsterImpactWater 0.76s cubic-bezier(0.12, 0.82, 0.2, 1) forwards;
}

.impact-water::before {
  inset: 22% 6% 13%;
  border: 8px solid rgba(208, 252, 255, 0.82);
  border-top-color: rgba(68, 220, 255, 0.46);
  border-left-color: rgba(72, 142, 255, 0.4);
  border-radius: 50%;
  animation: monsterImpactWaterRing 0.76s ease-out forwards;
}

.impact-water::after {
  inset: 0 4%;
  background:
    radial-gradient(circle at 16% 73%, rgba(228, 255, 255, 0.98) 0 4%, transparent 8%),
    radial-gradient(circle at 29% 29%, rgba(88, 225, 255, 0.94) 0 5%, transparent 10%),
    radial-gradient(circle at 47% 16%, rgba(228, 255, 255, 0.9) 0 4%, transparent 9%),
    radial-gradient(circle at 67% 31%, rgba(96, 149, 255, 0.84) 0 6%, transparent 12%),
    radial-gradient(circle at 84% 69%, rgba(211, 252, 255, 0.98) 0 5%, transparent 11%),
    radial-gradient(circle at 53% 86%, rgba(67, 213, 255, 0.82) 0 5%, transparent 10%);
  animation: monsterImpactDroplets 0.76s ease-out forwards;
}

body[data-phase="battle"] .hero {
  left: 20%;
  bottom: max(-120px, -20vh);
  width: min(79.2vw, 451px);
  height: min(93.5vh, 539px);
  opacity: 1;
  animation: heroBattleReady 1.05s ease-in-out infinite;
  filter: drop-shadow(0 15px 10px rgba(0, 0, 0, 0.42));
}

#fxCanvas {
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

@keyframes idle {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -4px;
  }
}

@keyframes heroWalkInPlace {
  0% {
    transform: translateX(-50%) translateY(0) rotate(-1.7deg) scaleX(1);
  }
  25% {
    transform: translateX(calc(-50% - 3px)) translateY(-7px) rotate(1.2deg) scaleX(0.985);
  }
  50% {
    transform: translateX(-50%) translateY(0) rotate(1.7deg) scaleX(1);
  }
  75% {
    transform: translateX(calc(-50% + 3px)) translateY(-7px) rotate(-1.2deg) scaleX(0.985);
  }
  100% {
    transform: translateX(-50%) translateY(0) rotate(-1.7deg) scaleX(1);
  }
}

@keyframes heroRest {
  0%,
  100% {
    transform: translateX(-50%) translateY(0) rotate(-0.4deg);
  }
  50% {
    transform: translateX(-50%) translateY(-2px) rotate(0.5deg);
  }
}

@keyframes monsterBattleIdle {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -5px;
  }
}

@keyframes monsterAppear {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.34) rotate(-5deg);
    filter:
      brightness(2.4)
      saturate(0.7)
      blur(3px)
      drop-shadow(0 0 26px rgba(147, 255, 215, 0.92));
  }
  38% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.88) rotate(2deg);
    filter:
      brightness(1.8)
      saturate(1.35)
      blur(0)
      drop-shadow(0 0 21px rgba(255, 226, 134, 0.82));
  }
  62% {
    transform: translate(-50%, -50%) scale(0.76) rotate(-1deg);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.8) rotate(0deg);
    filter: drop-shadow(0 13px 9px rgba(0, 0, 0, 0.42));
  }
}

@keyframes monsterPortalOpen {
  0% {
    opacity: 0;
    transform: scale(0.22) rotate(-46deg);
  }
  28% {
    opacity: 0.98;
    transform: scale(0.96) rotate(14deg);
  }
  66% {
    opacity: 0.74;
    transform: scale(1.12) rotate(42deg);
  }
  100% {
    opacity: 0;
    transform: scale(1.34) rotate(72deg);
  }
}

@keyframes monsterArrivalSmoke {
  0% {
    opacity: 0;
    transform: translateY(22px) scale(0.52);
  }
  34% {
    opacity: 0.84;
    transform: translateY(6px) scale(0.92);
  }
  100% {
    opacity: 0;
    transform: translateY(-18px) scale(1.32);
  }
}

@keyframes monsterDefeat {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.8) rotate(0deg);
    filter:
      brightness(1.12)
      saturate(1.18)
      drop-shadow(0 13px 9px rgba(0, 0, 0, 0.42));
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.86) rotate(-2deg);
    filter:
      brightness(2.55)
      saturate(0.65)
      drop-shadow(0 0 28px rgba(255, 255, 255, 0.92));
  }
  42% {
    opacity: 0.78;
    transform: translate(-50%, -53%) scale(0.74, 0.86) rotate(5deg);
    filter:
      brightness(1.72)
      saturate(1.45)
      contrast(1.3)
      drop-shadow(0 0 18px rgba(183, 236, 255, 0.84));
  }
  70% {
    opacity: 0.38;
    transform: translate(-50%, -58%) scale(0.9, 0.56) rotate(-7deg);
    filter:
      brightness(1.28)
      saturate(0.72)
      blur(1px)
      drop-shadow(0 0 16px rgba(255, 217, 132, 0.58));
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -64%) scale(1.1, 0.28) rotate(10deg);
    filter:
      brightness(1.8)
      saturate(0)
      blur(5px)
      drop-shadow(0 0 0 rgba(0, 0, 0, 0));
  }
}

@keyframes monsterDefeatFlash {
  0% {
    opacity: 0;
    transform: scale(0.64) rotate(0deg);
  }
  15% {
    opacity: 1;
    transform: scale(1.08) rotate(20deg);
  }
  48% {
    opacity: 0.42;
    transform: scale(1.28) rotate(74deg);
  }
  100% {
    opacity: 0;
    transform: scale(1.55) rotate(128deg);
  }
}

@keyframes monsterDefeatShards {
  0% {
    opacity: 0;
    transform: translateY(0) scale(0.72);
    filter: blur(1px);
  }
  20% {
    opacity: 0.9;
    transform: translateY(-6px) scale(0.98);
  }
  58% {
    opacity: 0.62;
    transform: translateY(-24px) scale(1.16);
    filter: blur(2px);
  }
  100% {
    opacity: 0;
    transform: translateY(-46px) scale(1.34);
    filter: blur(5px);
  }
}

@keyframes monsterImpactFire {
  0% {
    opacity: 0;
    transform: translate(-50%, -45%) scale(0.28) rotate(-8deg);
  }
  16% {
    opacity: 1;
  }
  48% {
    opacity: 1;
    transform: translate(-50%, -53%) scale(1.08) rotate(3deg);
    filter:
      brightness(1.18)
      blur(0.1px)
      drop-shadow(0 0 20px rgba(255, 56, 24, 1))
      drop-shadow(0 0 42px rgba(255, 156, 36, 0.9));
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -64%) scale(1.32) rotate(9deg);
    filter:
      brightness(1.35)
      blur(2px)
      drop-shadow(0 0 20px rgba(255, 92, 24, 0.36));
  }
}

@keyframes monsterImpactFireTongues {
  0% {
    opacity: 0;
    transform: scale(0.52, 0.2) translateY(24px);
  }
  28% {
    opacity: 1;
    transform: scale(0.94, 1.08) translateY(0);
  }
  100% {
    opacity: 0;
    transform: scale(1.12, 1.44) translateY(-28px);
  }
}

@keyframes monsterImpactSparks {
  0% {
    opacity: 0;
    transform: scale(0.54);
  }
  22% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(1.52) rotate(28deg);
  }
}

@keyframes monsterImpactEarth {
  0% {
    opacity: 0;
    transform: translate(-50%, -45%) scale(0.28);
  }
  14% {
    opacity: 1;
  }
  44% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -54%) scale(1.32);
    filter:
      blur(2px)
      drop-shadow(0 0 10px rgba(255, 204, 105, 0.32));
  }
}

@keyframes monsterImpactRocks {
  0% {
    opacity: 0;
    transform: translateY(28px) scale(0.42);
  }
  18% {
    opacity: 1;
  }
  58% {
    opacity: 1;
    transform: translateY(-16px) scale(1.14) rotate(-8deg);
  }
  100% {
    opacity: 0;
    transform: translateY(-38px) scale(1.36) rotate(14deg);
  }
}

@keyframes monsterImpactShockRing {
  0% {
    opacity: 0;
    transform: scale(0.2);
  }
  22% {
    opacity: 0.95;
  }
  100% {
    opacity: 0;
    transform: scale(1.55);
  }
}

@keyframes monsterImpactWind {
  0% {
    opacity: 0;
    transform: translate(-64%, -46%) scale(0.3) rotate(-15deg);
  }
  12% {
    opacity: 1;
  }
  58% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1) rotate(-7deg);
  }
  100% {
    opacity: 0;
    transform: translate(-36%, -56%) scale(1.34) rotate(8deg);
    filter:
      blur(1.4px)
      drop-shadow(0 0 14px rgba(196, 255, 226, 0.42));
  }
}

@keyframes monsterImpactWindRing {
  0% {
    opacity: 0;
    transform: scale(0.28) rotate(-48deg);
  }
  22% {
    opacity: 0.96;
  }
  100% {
    opacity: 0;
    transform: scale(1.42) rotate(86deg);
  }
}

@keyframes monsterImpactWindCross {
  0% {
    opacity: 0;
    transform: translate(-30px, 20px) scale(0.42);
  }
  24% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(34px, -24px) scale(1.28);
  }
}

@keyframes monsterImpactWater {
  0% {
    opacity: 0;
    transform: translate(-50%, -44%) scale(0.22);
  }
  15% {
    opacity: 1;
  }
  48% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -56%) scale(1.34);
    filter:
      blur(1.5px)
      drop-shadow(0 0 16px rgba(103, 221, 255, 0.46));
  }
}

@keyframes monsterImpactWaterRing {
  0% {
    opacity: 0;
    transform: scale(0.24);
  }
  24% {
    opacity: 0.95;
  }
  100% {
    opacity: 0;
    transform: scale(1.48);
  }
}

@keyframes monsterImpactDroplets {
  0% {
    opacity: 0;
    transform: scale(0.42);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(1.62) translateY(-18px);
  }
}

@keyframes heroBattleReady {
  0%,
  100% {
    transform: translateX(-50%) translateY(0) rotate(-1.2deg);
  }
  50% {
    transform: translateX(-50%) translateY(-4px) rotate(1.2deg);
  }
}

@keyframes stageShakeLight {
  0%,
  100% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(-2px, 1px);
  }
}

@keyframes stageShakeHit {
  0%,
  100% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(4px, -2px);
  }
  50% {
    transform: translate(-4px, 2px);
  }
  75% {
    transform: translate(3px, 1px);
  }
}

@keyframes stageShakeSkill {
  0%,
  100% {
    transform: translate(0, 0) scale(1);
  }
  20% {
    transform: translate(5px, -3px) scale(1.01);
  }
  45% {
    transform: translate(-5px, 2px) scale(1.01);
  }
  70% {
    transform: translate(4px, 3px) scale(1.005);
  }
}

/* --- TODO=モンスター モデル --- */

/* クエスト（ミッション）トラッカー: TodoWrite スナップショットを MMO 風のパネルで表示。
   探検（フェーズラベル）の下、ステージ左上に固定。 */
.roster {
  /* クエスト窓は最下層に近い：背景画像(#sceneBg)/暗幕(.shade)のすぐ前、かつ .stage(z-index:2)が
     内包するモンスター・勇者・精霊・パーティクル(#fxCanvas)・各種エフェクトより必ず後ろに置く。
     ＝クエスト欄の後ろにあるのは背景だけ。z-index:1 で stage 群(z>=2)の背面に回す。 */
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  width: min(40%, 340px);
  max-height: calc(100% - 24px);
  padding: 9px 13px 11px;
  border: 1px solid rgba(255, 209, 92, 0.30);
  border-left: 3px solid var(--gold);
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(12, 18, 18, 0.86), rgba(8, 12, 12, 0.74));
  box-shadow:
    0 8px 22px rgba(0, 0, 0, 0.5),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  color: var(--ink);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  overflow: hidden;
  pointer-events: none;
}
.roster[data-active="false"] {
  display: none;
}

/* パネル見出し: 紋章 + タイトル + 達成数バッジ */
.roster-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
  padding-bottom: 7px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
}
.roster-crest {
  font-size: 14px;
  color: var(--gold);
  filter: drop-shadow(0 0 5px rgba(255, 209, 92, 0.7));
}
.roster-title {
  font-size: 11.7px;
  font-weight: 900;
  letter-spacing: 0.22em;
  color: var(--gold);
}
.roster-count {
  margin-left: auto;
  padding: 1px 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.32);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

/* 項目行: アイコン + 本文（旧 10px の 1.5 倍 = 15px） */
.roster-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.roster-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13.5px;
  line-height: 1.3;
}
.roster-mark {
  flex: 0 0 auto;
  width: 1.15em;
  text-align: center;
  font-weight: 900;
}
.roster-text {
  flex: 1 1 auto;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* 未着手 ◇ */
.roster-item.is-todo .roster-mark {
  color: rgba(255, 235, 200, 0.5);
}
.roster-item.is-todo .roster-text {
  color: rgba(255, 247, 221, 0.88);
}

/* 進行中 ◆（現在の討伐対象）= 強調 + 脈動 */
.roster-item.is-active .roster-mark {
  color: var(--gold);
  text-shadow: 0 0 7px rgba(255, 209, 92, 0.95);
  animation: questPulse 1.1s ease-in-out infinite;
}
.roster-item.is-active .roster-text {
  color: #fff;
  font-weight: 800;
  text-shadow:
    0 0 8px rgba(255, 209, 92, 0.45),
    0 1px 2px rgba(0, 0, 0, 0.85);
}

/* 達成 ✓（チェックマーク + 取り消し線） */
.roster-item.is-done .roster-mark {
  color: var(--field);
  text-shadow: 0 0 6px rgba(125, 216, 115, 0.6);
}
.roster-item.is-done .roster-text {
  color: rgba(170, 192, 180, 0.62);
  text-decoration: line-through;
  text-decoration-color: rgba(170, 192, 180, 0.42);
}
.roster-item.is-folded .roster-text {
  font-style: italic;
  text-decoration: none;
  color: rgba(170, 192, 180, 0.5);
}

@keyframes questPulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(1.22);
  }
}

/* 現在の戦闘相手 = in_progress。target が無ければ隠す */
#monsterStage[data-active="false"] {
  visibility: hidden;
}

#monsterStage[data-active="false"][data-action="defeat"] {
  visibility: visible;
}

/* TODO 本文ラベル */
.enemy-label {
  margin-top: 2px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* フローティングのトースト（技名 / 反撃 / 撃破 など） */
.toast {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  pointer-events: none;
}
.toast-item {
  font-size: 13px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  opacity: 0;
  translate: 0 6px;
  transition: opacity 0.12s ease, translate 0.5s ease;
}
.toast-item.in {
  opacity: 1;
  translate: 0 -8px;
}
.toast-item.out {
  opacity: 0;
  translate: 0 -22px;
}
.toast-skill {
  color: #ffe08a;
}
.toast-hit {
  color: #fff4b8;
}
.toast-ally {
  color: #8feaff;
}
.toast-counter {
  color: #ff7a7a;
}
.toast-win {
  color: #9af08a;
}
.toast-dying {
  color: #d0b0ff;
}

/* 技名カットイン */
.skill-cutin {
  position: absolute;
  left: 50%;
  top: 18%;
  z-index: 12;
  max-width: min(88vw, 360px);
  padding: 2px 14px 5px;
  border: 2px solid rgba(255, 255, 255, 0.62);
  border-radius: 6px;
  color: #fff8c9;
  background:
    linear-gradient(90deg, rgba(255, 209, 92, 0.08), rgba(255, 92, 87, 0.52), rgba(113, 215, 255, 0.14)),
    rgba(8, 9, 14, 0.82);
  box-shadow:
    0 0 20px rgba(255, 209, 92, 0.55),
    0 4px 0 rgba(0, 0, 0, 0.35);
  font-size: clamp(26px, 9vw, 46px);
  font-weight: 1000;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
  text-shadow:
    3px 3px 0 #3d1717,
    0 0 12px rgba(255, 209, 92, 0.95);
  transform: translateX(-50%) rotate(-4deg) scale(0.72);
  animation: skillCutIn 0.78s cubic-bezier(0.17, 0.89, 0.29, 1.38) forwards;
  pointer-events: none;
}

.skill-cutin.out {
  opacity: 0;
  transform: translateX(-50%) translateY(-18px) rotate(3deg) scale(0.92);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

@keyframes skillCutIn {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(18px) rotate(-12deg) scale(0.5);
  }
  22% {
    opacity: 1;
    transform: translateX(-50%) translateY(-2px) rotate(-4deg) scale(1.08);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) rotate(-4deg) scale(1);
  }
}

/* 斬撃の太い軌跡 */
.slash-mark {
  position: absolute;
  left: 50%;
  top: 48%;
  z-index: 11;
  width: min(58vw, 230px);
  height: 80px;
  transform: translate(-50%, -50%) rotate(-28deg) scale(0.72);
  transform-origin: center;
  opacity: 0;
  pointer-events: none;
  animation: slashSweep 0.38s ease-out forwards;
}

.slash-mark::before,
.slash-mark::after {
  position: absolute;
  content: "";
  left: 3%;
  right: 3%;
  top: 34px;
  height: 13px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #fffdf0 18%, #ffe98a 48%, #f0b73a 76%, transparent);
  box-shadow:
    0 0 18px rgba(255, 241, 168, 0.95),
    0 0 32px rgba(255, 188, 54, 0.58);
}

.slash-mark::after {
  left: 18%;
  right: 18%;
  top: 22px;
  height: 5px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.96), transparent);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.95);
}

.slash-skill {
  width: min(72vw, 300px);
  height: 108px;
}

.slash-skill::before {
  height: 18px;
  background: linear-gradient(90deg, transparent, #fff 14%, #ffe98a 34%, #ffd15c 56%, #d98d24 82%, transparent);
  box-shadow:
    0 0 24px rgba(255, 209, 92, 1),
    0 0 46px rgba(255, 177, 64, 0.82),
    0 0 64px rgba(214, 130, 28, 0.5);
}

@keyframes slashSweep {
  0% {
    opacity: 0;
    transform: translate(-62%, -58%) rotate(-34deg) scale(0.28);
    filter: blur(1px);
  }
  18% {
    opacity: 1;
  }
  70% {
    opacity: 1;
    transform: translate(-46%, -48%) rotate(-28deg) scale(1.05);
    filter: blur(0);
  }
  100% {
    opacity: 0;
    transform: translate(-42%, -46%) rotate(-22deg) scale(1.14);
  }
}

/* モンスター反撃の被弾エフェクト（slash / blunt / magic）。勇者・精霊どちらにも使う。 */
.damage-impact {
  --damage-scale: 1;
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 13;
  width: 112px;
  height: 112px;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(calc(0.7 * var(--damage-scale)));
  transform-origin: center;
  will-change: opacity, transform, filter;
}

.damage-impact::before,
.damage-impact::after {
  position: absolute;
  content: "";
  pointer-events: none;
}

.damage-slash {
  animation: damageSlash 0.52s ease-out forwards;
  filter:
    drop-shadow(0 0 14px rgba(255, 255, 255, 0.92))
    drop-shadow(0 0 24px rgba(255, 68, 58, 0.7));
}

.damage-slash::before,
.damage-slash::after {
  left: 6%;
  right: 6%;
  top: 50%;
  height: 11px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #fffdf0 18%, #ffecad 42%, #ff5a4d 74%, transparent);
  transform: rotate(-30deg);
}

.damage-slash::after {
  left: 24%;
  right: 18%;
  top: 39%;
  height: 5px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.98), transparent);
  transform: rotate(-14deg);
}

.damage-blunt {
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 246, 205, 0.96) 0 10%, rgba(255, 112, 68, 0.7) 11% 24%, transparent 42%),
    radial-gradient(circle at 50% 50%, rgba(255, 90, 77, 0.34) 0 28%, transparent 62%);
  animation: damageBlunt 0.58s cubic-bezier(0.12, 0.82, 0.2, 1) forwards;
  filter:
    drop-shadow(0 0 18px rgba(255, 103, 62, 0.86))
    drop-shadow(0 0 30px rgba(255, 209, 92, 0.5));
}

.damage-blunt::before {
  inset: 18%;
  border: 7px solid rgba(255, 237, 188, 0.82);
  border-right-color: rgba(255, 90, 77, 0.38);
  border-bottom-color: rgba(255, 90, 77, 0.32);
  border-radius: 50%;
  animation: damageShockRing 0.58s ease-out forwards;
}

.damage-blunt::after {
  inset: 22%;
  background:
    linear-gradient(100deg, transparent 43%, rgba(70, 25, 20, 0.78) 44% 48%, transparent 50%),
    linear-gradient(18deg, transparent 39%, rgba(255, 235, 162, 0.8) 40% 44%, transparent 48%),
    linear-gradient(-38deg, transparent 50%, rgba(120, 54, 34, 0.75) 51% 56%, transparent 60%);
  animation: damageCrack 0.58s steps(3, end) forwards;
}

.damage-magic {
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.95) 0 8%, rgba(197, 140, 255, 0.52) 9% 22%, transparent 38%),
    conic-gradient(from 20deg, transparent 0 9%, rgba(196, 142, 255, 0.94) 10% 14%, transparent 15% 28%, rgba(114, 232, 255, 0.92) 30% 35%, transparent 36% 55%, rgba(255, 255, 255, 0.86) 57% 61%, transparent 63% 100%);
  animation: damageMagic 0.7s ease-out forwards;
  filter:
    drop-shadow(0 0 16px rgba(197, 140, 255, 0.92))
    drop-shadow(0 0 32px rgba(114, 232, 255, 0.56));
}

.damage-magic::before {
  inset: 12%;
  border: 5px solid rgba(230, 205, 255, 0.78);
  border-left-color: rgba(114, 232, 255, 0.45);
  border-bottom-color: rgba(197, 140, 255, 0.34);
  border-radius: 50%;
  animation: damageMagicRing 0.7s ease-out forwards;
}

.damage-magic::after {
  inset: 4%;
  background:
    radial-gradient(circle at 20% 74%, rgba(255, 255, 255, 0.98) 0 4%, transparent 8%),
    radial-gradient(circle at 32% 28%, rgba(197, 140, 255, 0.94) 0 5%, transparent 10%),
    radial-gradient(circle at 63% 18%, rgba(114, 232, 255, 0.9) 0 4%, transparent 9%),
    radial-gradient(circle at 82% 62%, rgba(255, 255, 255, 0.86) 0 5%, transparent 11%);
  animation: damageMagicSparks 0.7s ease-out forwards;
}

@keyframes damageSlash {
  0% {
    opacity: 0;
    transform: translate(-62%, -58%) scale(calc(0.25 * var(--damage-scale))) rotate(-10deg);
    filter: blur(1px);
  }
  18% {
    opacity: 1;
  }
  74% {
    opacity: 1;
    transform: translate(-48%, -50%) scale(calc(1.08 * var(--damage-scale))) rotate(4deg);
    filter: blur(0);
  }
  100% {
    opacity: 0;
    transform: translate(-42%, -46%) scale(calc(1.18 * var(--damage-scale))) rotate(12deg);
  }
}

@keyframes damageBlunt {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(calc(0.16 * var(--damage-scale)));
  }
  16% {
    opacity: 1;
  }
  48% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(calc(1.08 * var(--damage-scale)));
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(calc(1.5 * var(--damage-scale)));
    filter: blur(2px);
  }
}

@keyframes damageShockRing {
  0% {
    opacity: 0;
    transform: scale(0.24);
  }
  24% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(1.72);
  }
}

@keyframes damageCrack {
  0% {
    opacity: 0;
    transform: scale(0.42);
  }
  24% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(1.24) rotate(8deg);
  }
}

@keyframes damageMagic {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(calc(0.22 * var(--damage-scale))) rotate(-28deg);
  }
  18% {
    opacity: 1;
  }
  58% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(calc(1.06 * var(--damage-scale))) rotate(44deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(calc(1.36 * var(--damage-scale))) rotate(96deg);
    filter: blur(1.5px);
  }
}

@keyframes damageMagicRing {
  0% {
    opacity: 0;
    transform: scale(0.28) rotate(-30deg);
  }
  24% {
    opacity: 0.95;
  }
  100% {
    opacity: 0;
    transform: scale(1.5) rotate(92deg);
  }
}

@keyframes damageMagicSparks {
  0% {
    opacity: 0;
    transform: scale(0.42);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(1.58) translateY(-12px);
  }
}

/* 在席中の仲間（SubagentStart/Stop） */
.allies {
  position: absolute;
  bottom: 1px;
  left: 8px;
  z-index: 6;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  max-width: 48vw;
  overflow: visible;
  pointer-events: none;
}
.allies[data-active="false"] {
  display: none;
}

/* 戦闘以外（街・探索・クリア）の画面では精霊を出さない */
body[data-phase="idle"] .allies,
body[data-phase="complete"] .allies,
body[data-phase="field"] .allies {
  display: none;
}

.ally {
  position: relative;
  display: grid;
  justify-items: center;
  width: clamp(38px, 12vw, 54px);
  min-width: 38px;
  filter:
    drop-shadow(0 6px 4px rgba(0, 0, 0, 0.45))
    drop-shadow(0 0 8px rgba(127, 224, 255, 0.52));
  transform-origin: center bottom;
  animation: allyFloat 1.6s ease-in-out infinite;
  animation-delay: calc(var(--slot, 0) * -0.22s);
}

.ally img {
  display: block;
  width: 100%;
  height: clamp(54px, 17vw, 76px);
  object-fit: contain;
}

.ally span {
  max-width: 62px;
  margin-top: -10px;
  padding: 1px 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  color: #e8fbff;
  background: rgba(0, 0, 0, 0.46);
  font-size: 9px;
  font-weight: 900;
  line-height: 1.1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body[data-phase="battle"] .allies {
  right: clamp(-44px, -9vw, -34px);
  bottom: clamp(-78px, -18vh, -54px);
  left: auto;
  /* 精霊コンテナを stacking context にしない＝各精霊の z-index を .stage 文脈で評価し、
     水精霊(Aqua)だけを勇者(.hero z-index:5)の背面へ回せるようにする。 */
  z-index: auto;
  display: block;
  width: min(88vw, 620px);
  height: clamp(250px, 37.8vw, 303px); /* 精霊 1.5 倍に合わせて拡張 */
  max-width: none;
}

body[data-phase="battle"] .ally {
  position: absolute;
  right: calc(var(--slot, 0) * clamp(44px, 8vw, 66px));
  bottom: 0;
  width: clamp(250px, 37.8vw, 303px);
  min-width: clamp(250px, 37.8vw, 303px);
  filter:
    drop-shadow(0 13px 10px rgba(0, 0, 0, 0.48))
    drop-shadow(0 0 14px rgba(140, 226, 255, 0.42));
}

body[data-phase="battle"] .ally + .ally {
  margin-left: 0;
}

body[data-phase="battle"] .ally img {
  height: clamp(250px, 37.8vw, 303px);
  image-rendering: pixelated;
}

body[data-phase="battle"] .ally-fire {
  /* 画面の一番右に固定（slot 依存の calc だと中央寄りになるため明示的に右端へ） */
  position: fixed;
  z-index: 6; /* 勇者(5)より手前。.allies の stacking context を外したので個別指定が必要 */
  right: clamp(-40px, -3vw, -12px);
  left: auto;
  bottom: clamp(-70px, -4vh, -36px);
  width: clamp(386px, 58.38vw, 469px);
  min-width: clamp(386px, 58.38vw, 469px);
}

body[data-phase="battle"] .ally-fire img {
  height: clamp(386px, 58.38vw, 469px);
  transform: scaleX(-1); /* 火の精霊の画像を左右反転 */
}

body[data-phase="battle"] .ally-earth {
  /* 画面の水平中央に固定。margin:auto は `.ally + .ally` の margin-left:0 に負けるため、
     幅の半分だけ左にずらして中央寄せする（transform はフロート演出が使うので不可）。 */
  position: fixed;
  z-index: 6; /* 勇者(5)より手前。中央下で勇者と重なるが前面に保つ */
  left: calc(50% - clamp(154px, 23.25vw, 186px));
  right: auto;
  bottom: clamp(-44px, -5vh, -30px);
  width: clamp(308px, 46.5vw, 372px);
  min-width: clamp(308px, 46.5vw, 372px);
}

body[data-phase="battle"] .ally-earth img {
  height: clamp(308px, 46.5vw, 372px);
}

body[data-phase="battle"] .ally-wind {
  position: fixed;
  right: clamp(-40px, 1.5vw, -20px);
  top: -34px;
  bottom: auto;
  z-index: 8;
  width: clamp(297px, 45.62vw, 435px);
  min-width: clamp(297px, 45.62vw, 435px);
  aspect-ratio: 3 / 2;
  transform-origin: center center;
}

body[data-phase="battle"] .ally-wind img {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: contain;
  transform: rotate(-15deg);
  transform-origin: center center;
}

body[data-phase="battle"] .ally-water {
  position: fixed;
  top: clamp(60px, 10vh, 84px);
  left: clamp(-12px, 1vw, 6px);
  right: auto;
  bottom: auto;
  z-index: 4; /* 勇者(.hero z-index:5)の背面、かつモンスター(z-index:3)より前面（要望：水の精霊より勇者を前・モンスターより水を前） */
  width: clamp(295px, 49.82vw, 418px);
  min-width: clamp(295px, 49.82vw, 418px);
  transform-origin: 58% 42%;
  animation: allyWaterFloat 2.2s ease-in-out infinite;
  filter:
    drop-shadow(0 13px 10px rgba(0, 0, 0, 0.44))
    drop-shadow(0 0 18px rgba(103, 221, 255, 0.62));
}

body[data-phase="battle"] .ally-water::after {
  position: absolute;
  right: 17%;
  bottom: 8%;
  width: 48%;
  height: 10%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(114, 232, 255, 0.3), rgba(114, 232, 255, 0));
  content: "";
  filter: blur(3px);
  transform: rotate(-10deg);
}

body[data-phase="battle"] .ally-water img {
  height: clamp(295px, 49.82vw, 418px);
  image-rendering: pixelated;
  transform: rotate(-7deg);
  transform-origin: 55% 44%;
}

body[data-phase="battle"] .ally-water[data-action="summon"] {
  animation: allyWaterSummon 0.54s ease-out, allyWaterFloat 2.2s ease-in-out 0.54s infinite;
}

body[data-phase="battle"] .ally-water[data-action="assist"] {
  animation: allyWaterAssist 0.42s ease-out, allyWaterFloat 2.2s ease-in-out 0.42s infinite;
}

body[data-phase="battle"] .ally-fire[data-action="assist"] img {
  animation: allyFireAssistGlow 0.42s ease-out;
}

body[data-phase="battle"] .ally-earth[data-action="assist"] img {
  animation: allyEarthAssistGlow 0.42s ease-out;
}

body[data-phase="battle"] .ally-wind[data-action="assist"] img {
  animation: allyWindAssistGlow 0.42s ease-out;
}

body[data-phase="battle"] .ally-water[data-action="assist"] img {
  animation: allyWaterAssistGlow 0.42s ease-out;
}

body[data-phase="battle"] .ally-water[data-action="stagger"] {
  animation: allyWaterStagger 0.38s ease-out, allyWaterFloat 2.2s ease-in-out 0.38s infinite;
}

body[data-phase="battle"] .ally span {
  display: none;
}

.ally[data-action="summon"] {
  animation: allySummon 0.54s ease-out, allyFloat 1.6s ease-in-out 0.54s infinite;
}

.ally[data-action="assist"] {
  animation: allyAssist 0.42s ease-out, allyFloat 1.6s ease-in-out 0.42s infinite;
}

.ally[data-action="stagger"] {
  animation: allyStagger 0.38s ease-out, allyFloat 1.6s ease-in-out 0.38s infinite;
}

/* 撃破後の帰還：光を放ちながら上へ縮んで消える（allyFloat は止める＝forwards で終端を保持） */
.ally[data-action="return"] {
  animation: allyReturn 0.52s ease-in forwards;
  pointer-events: none;
}

@keyframes allyReturn {
  0% {
    transform: translateY(0) scale(1);
    opacity: 1;
    filter: drop-shadow(0 6px 4px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 8px rgba(127, 224, 255, 0.55));
  }
  35% {
    transform: translateY(-7px) scale(1.08);
    opacity: 1;
    filter: drop-shadow(0 0 18px rgba(255, 255, 255, 0.95));
  }
  100% {
    transform: translateY(-36px) scale(0.36);
    opacity: 0;
    filter: drop-shadow(0 0 24px rgba(255, 255, 255, 0));
  }
}

@keyframes allyFloat {
  0%,
  100% {
    transform: translateY(0) rotate(-1deg);
  }
  50% {
    transform: translateY(-5px) rotate(1deg);
  }
}


@keyframes allyWaterFloat {
  0%,
  100% {
    transform: translateY(0) translateX(0) rotate(5deg);
  }
  50% {
    transform: translateY(-10px) translateX(3px) rotate(9deg);
  }
}

@keyframes allyWaterSummon {
  0% {
    opacity: 0;
    transform: translateY(28px) translateX(-18px) scale(0.28) rotate(-18deg);
    filter: brightness(2.5) drop-shadow(0 0 22px rgba(103, 221, 255, 1));
  }
  72% {
    opacity: 1;
    transform: translateY(-14px) translateX(6px) scale(1.12) rotate(12deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) translateX(0) scale(1) rotate(5deg);
  }
}

@keyframes allyWaterAssist {
  0%,
  100% {
    transform: translateY(0) translateX(0) scale(1) rotate(5deg);
  }
  45% {
    transform: translateY(-22px) translateX(34px) scale(1.1) rotate(13deg);
    filter: brightness(1.75) drop-shadow(0 0 18px rgba(103, 221, 255, 1));
  }
}

@keyframes allyWaterStagger {
  0%,
  100% {
    transform: translateY(0) translateX(0) rotate(5deg);
  }
  35% {
    transform: translateY(2px) translateX(-5px) rotate(-4deg);
  }
  70% {
    transform: translateY(-3px) translateX(5px) rotate(11deg);
  }
}

@keyframes allyFireAssistGlow {
  0%,
  100% {
    filter: brightness(1) saturate(1) drop-shadow(0 0 0 rgba(255, 94, 35, 0));
  }
  38% {
    filter:
      brightness(1.75)
      saturate(1.65)
      drop-shadow(0 0 16px rgba(255, 45, 28, 0.95))
      drop-shadow(0 0 30px rgba(255, 152, 46, 0.78));
  }
  68% {
    filter:
      brightness(1.35)
      saturate(1.35)
      drop-shadow(0 0 10px rgba(255, 184, 62, 0.78));
  }
}

@keyframes allyEarthAssistGlow {
  0%,
  100% {
    filter: brightness(1) saturate(1) drop-shadow(0 0 0 rgba(160, 188, 70, 0));
  }
  42% {
    filter:
      brightness(1.42)
      saturate(1.32)
      sepia(0.18)
      drop-shadow(0 0 14px rgba(224, 183, 76, 0.88))
      drop-shadow(0 0 24px rgba(111, 184, 82, 0.64));
  }
  72% {
    filter:
      brightness(1.18)
      saturate(1.18)
      drop-shadow(0 0 10px rgba(151, 198, 86, 0.62));
  }
}

@keyframes allyWindAssistGlow {
  0%,
  100% {
    filter: brightness(1) saturate(1) drop-shadow(0 0 0 rgba(144, 255, 228, 0));
  }
  34% {
    filter:
      brightness(1.72)
      saturate(1.38)
      drop-shadow(0 0 15px rgba(191, 255, 194, 0.9))
      drop-shadow(0 0 28px rgba(108, 238, 255, 0.72));
  }
  58% {
    filter:
      brightness(1.32)
      saturate(1.18)
      drop-shadow(0 0 11px rgba(135, 255, 226, 0.72));
  }
}

@keyframes allyWaterAssistGlow {
  0%,
  100% {
    filter: brightness(1) saturate(1) drop-shadow(0 0 0 rgba(88, 207, 255, 0));
  }
  40% {
    filter:
      brightness(1.65)
      saturate(1.42)
      drop-shadow(0 0 16px rgba(66, 218, 255, 0.94))
      drop-shadow(0 0 30px rgba(107, 145, 255, 0.66));
  }
  70% {
    filter:
      brightness(1.24)
      saturate(1.22)
      drop-shadow(0 0 11px rgba(125, 239, 255, 0.74));
  }
}

@keyframes allySummon {
  0% {
    opacity: 0;
    transform: translateY(28px) scale(0.22) rotate(-18deg);
    filter: brightness(2.4) drop-shadow(0 0 18px rgba(127, 224, 255, 1));
  }
  72% {
    opacity: 1;
    transform: translateY(-10px) scale(1.14) rotate(6deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

@keyframes allyAssist {
  0%,
  100% {
    transform: translateX(0) translateY(0) scale(1);
  }
  45% {
    transform: translateX(28px) translateY(-18px) scale(1.12);
    filter: brightness(1.8) drop-shadow(0 0 15px rgba(127, 224, 255, 1));
  }
}

@keyframes allyStagger {
  0%,
  100% {
    transform: translateX(0) rotate(0deg);
  }
  35% {
    transform: translateX(-5px) rotate(-7deg);
  }
  70% {
    transform: translateX(4px) rotate(6deg);
  }
}

/* --- 被弾リアクション（要件3）：勇者・精霊がモンスターの反撃を受けた瞬間 --- */
#heroImage[data-action="hit"] {
  animation: heroHitReact 0.42s ease-out;
}

@keyframes heroHitReact {
  0% {
    transform: translateX(0) translateY(0);
    filter: none;
  }
  28% {
    transform: translateX(-11px) translateY(3px);
    filter: brightness(1.5) drop-shadow(0 0 12px rgba(255, 70, 64, 0.95));
  }
  60% {
    transform: translateX(4px) translateY(-1px);
  }
  100% {
    transform: translateX(0) translateY(0);
    filter: none;
  }
}

.ally[data-action="hit"] img {
  animation: allyHitGlow 0.42s ease-out;
}

@keyframes allyHitGlow {
  0%,
  100% {
    filter: brightness(1);
  }
  40% {
    filter: brightness(1.6) drop-shadow(0 0 14px rgba(255, 80, 70, 0.95));
  }
}

/* --- 戦闘→探検の全画面トランジション（要件5） --- */
/* タイトル一枚絵を全画面に出し、テキストが右上→中央で一瞬静止→左下へ流れる。背景は派手すぎず、
   ヴィネット＋暗幕でフォントが潰れないよう可読性を確保。被覆中に背景/勇者を差し替えて瞬間移動を隠す。 */
.scene-transition {
  position: absolute;
  inset: 0;
  z-index: 16; /* skill-cutin(12) より上、audioButton(20) 未満 */
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
}

.scene-transition[data-active="true"] {
  animation: sceneTransitionFade 1.5s ease-in-out forwards;
}

@keyframes sceneTransitionFade {
  0% {
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.scene-transition-art {
  position: absolute;
  inset: 0;
  background: #07100b url("/assets/title.png") center / cover no-repeat;
  image-rendering: pixelated;
  transform: scale(1.06);
}

.scene-transition-veil {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 48%, rgba(5, 8, 7, 0.12) 0%, rgba(5, 8, 7, 0.5) 68%, rgba(5, 8, 7, 0.84) 100%),
    linear-gradient(180deg, rgba(5, 8, 7, 0.4), rgba(5, 8, 7, 0.26));
}

.scene-transition-text {
  position: absolute;
  left: 50%;
  top: 50%;
  font-family: "Cinzel", Georgia, "Times New Roman", serif;
  font-size: clamp(34px, 7.6vw, 74px);
  font-weight: 800;
  letter-spacing: 0.06em;
  white-space: nowrap;
  background: linear-gradient(177deg, #fff6d2 6%, #ffd763 46%, #f0a52e 82%, #c97e16 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--gold);
  filter:
    drop-shadow(0 2px 1px rgba(40, 20, 0, 0.62))
    drop-shadow(0 0 18px rgba(255, 198, 74, 0.55));
  will-change: transform, opacity;
}

.scene-transition[data-active="true"] .scene-transition-text {
  animation: sceneTransitionText 1.5s cubic-bezier(0.3, 0.7, 0.3, 1) forwards;
}

/* 右上から流れてきて中央で一瞬静止し、左下へ抜ける（vw/vh で要素サイズに依らず画面外へ出す） */
@keyframes sceneTransitionText {
  0% {
    opacity: 0;
    transform: translate(calc(-50% + 72vw), calc(-50% - 62vh)) rotate(-10deg);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg);
  }
  56% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% - 72vw), calc(-50% + 62vh)) rotate(10deg);
  }
}
