body {
  font-family: sans-serif;
}

.hidden {
  display: none;
}

.error-message {
  color: #c0392b;
  min-height: 1.2em;
}

/* =========================================================
   Kana-rush 共通テーマ (battle.html / index.html)
   body.battle-page 配下にすべてスコープする
   ========================================================= */

body.battle-page {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #2a1a4a 0%, #150c28 45%, #08050f 100%);
  color: #f2edff;
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
  display: flex;
  flex-direction: column;
}

/* 背景の上に「枠」を置くのではなく、app-shell自体が画面いっぱいの高さを占め、
   中の画面(.screen)が縦方向にも余白を使い切るようにする */
body.battle-page .app-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: min(96vw, 1400px);
  margin: 0 auto;
  padding: clamp(12px, 3vw, 40px) clamp(12px, 5vw, 56px) clamp(32px, 6vw, 72px);
  box-sizing: border-box;
}

/* 各ページ本体の画面はカード化せず、背景の上にそのまま配置して
   縦方向の余白いっぱいに広がる(ポップアップの.modal-cardは別扱い) */
body.battle-page .screen:not(.hidden) {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

/* プレイ中の画面(対戦・練習)はキャラクター/HPが余った縦の空間いっぱいに広がって
   中央に来るようにし(#battleStageのflex:1)、操作系はその下に自然な高さで並ぶ */
body.battle-page .gameplay-screen:not(.hidden) {
  gap: 16px;
}

body.battle-page .battle-controls {
  display: flex;
  flex-direction: column;
}

body.battle-page * {
  box-sizing: border-box;
}

/* --- ヘッダー --- */

body.battle-page .app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

body.battle-page .app-title {
  font-size: clamp(1.3rem, 1rem + 1.5vw, 2.2rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  margin: 0;
  color: #ffd54a;
  text-shadow: 2px 2px 0 #c0392b;
}

/* トップへ戻るボタン: ホームの記号だけのシンプルな正方形ボタン。
   .hiddenより詳細度が高くなり上書きしてしまわないよう :not(.hidden) にする */
body.battle-page .icon-button:not(.hidden) {
  font-family: inherit;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #cbb8ff;
  text-decoration: none;
  background: transparent;
  border: 1px solid rgba(203, 184, 255, 0.4);
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
}

body.battle-page .icon-button:hover {
  background: rgba(203, 184, 255, 0.12);
}

/* --- ポップアップ(準備・結果・決着): battleScreenの上に重ねて表示する --- */

body.battle-page .modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 2, 15, 0.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 50;
}

body.battle-page .modal-overlay .modal-card {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 560px);
  max-height: 85vh;
  overflow-y: auto;
}

/* --- 画面共通のカード --- */

body.battle-page .screen-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: clamp(18px, 3vw, 32px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  text-align: center;
}

body.battle-page .eyebrow {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: #ffd54a;
  margin: 0 0 6px;
}

body.battle-page .section-title {
  font-size: clamp(1.2rem, 1rem + 1vw, 1.7rem);
  margin: 0 0 8px;
  color: #fff;
}

body.battle-page .caption {
  font-size: 0.85rem;
  color: #b8aed1;
  margin: 4px 0 12px;
}

body.battle-page .lead-text {
  font-size: 0.9rem;
  color: #cfc4ea;
  line-height: 1.6;
  max-width: 520px;
  margin: 4px auto 18px;
}

/* --- ボタン --- */
/* ボタン・本文は画面幅いっぱいに伸びると押しにくく読みにくいので、
   読みやすい幅に留めて中央寄せにする(盤面まわりの要素は幅いっぱいに広げる) */

body.battle-page .cta-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 420px;
  margin: 0 auto;
}

/* トップ画面のモード選択ボタンは主役なので、他のポップアップのボタンより横長にする。
   flexのstretchだけに頼らず、ボタン自体にもwidth:100%を明示して確実に広げる */
body.battle-page .cta-stack-wide {
  width: 100%;
  max-width: 720px;
}

body.battle-page .cta-stack-wide .btn {
  width: 100%;
}

body.battle-page .btn {
  font-size: 0.95rem;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

body.battle-page .btn:active {
  transform: scale(0.97);
}

body.battle-page .btn-primary {
  background: linear-gradient(180deg, #ffd54a, #ff9f43);
  color: #2a1a4a;
  box-shadow: 0 6px 14px rgba(255, 159, 67, 0.35);
}

body.battle-page .btn-secondary {
  background: transparent;
  color: #f2edff;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

body.battle-page .btn-compact {
  padding: 10px 16px;
  font-size: 0.9rem;
}

/* --- モード選択 --- */

#modeSelectTeaser {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
}

#modeSelectTeaser img {
  width: clamp(80px, 14vw, 160px);
  height: clamp(80px, 14vw, 160px);
  object-fit: contain;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
}

/* --- 準備インターバル(交代・BOT開始前) --- */

body.battle-page .get-ready-count {
  font-size: clamp(3.2rem, 2.6rem + 2vw, 5rem);
  font-weight: 900;
  color: #ffd54a;
  text-shadow: 0 0 18px rgba(255, 213, 74, 0.6);
  animation: count-pulse 1s ease-in-out infinite;
}

/* --- バトルステージ --- */

#battleStage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: clamp(12px, 2vw, 24px) clamp(12px, 3vw, 28px);
}

/* 練習モード: 1人だけなので中央寄せにする */
#battleStage.single-stage {
  justify-content: center;
}

#battleStage.single-stage .fighter {
  max-width: 220px;
}

.fighter {
  flex: 1;
  max-width: 45%;
  text-align: center;
  transition: opacity 0.3s ease;
}

.fighter-portrait img {
  width: 100%;
  max-width: min(32vw, 260px);
  transition: transform 0.3s ease, filter 0.3s ease, opacity 0.3s ease;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.5));
  opacity: 0.55;
  transform: scale(0.92);
}

.fighter.active-turn .fighter-portrait img {
  opacity: 1;
  transform: scale(1);
  filter: drop-shadow(0 0 16px #ffd54a);
  animation: mic-bounce 0.6s ease-in-out infinite;
}

.fighter.ko .fighter-portrait img {
  opacity: 0.25;
  filter: grayscale(100%);
  animation: none;
  transform: scale(0.85);
}

.fighter.hit .fighter-portrait img {
  animation: hit-flash 0.4s ease-out;
}

.fighter.hit .hp-bar-inner {
  filter: brightness(1.8);
}

.fighter-name {
  margin-top: 6px;
  display: inline-block;
  background: linear-gradient(180deg, #ff5b5b, #c0392b);
  color: #fff;
  font-weight: bold;
  font-size: 0.85rem;
  padding: 2px 12px;
  border-radius: 999px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.vs-badge {
  flex: 0 0 auto;
  font-size: clamp(1.8rem, 1.4rem + 1.5vw, 3rem);
  font-weight: 900;
  font-style: italic;
  color: #ffd54a;
  text-shadow: 0 0 6px rgba(255, 213, 74, 0.6), 2px 2px 0 #c0392b;
  transform: rotate(-6deg);
}

.hp-bar-outer {
  background: #222;
  border: 1px solid #555;
  border-radius: 6px;
  height: 14px;
  overflow: hidden;
  margin: 6px auto 2px;
  max-width: min(80%, 320px);
}

.hp-bar-inner {
  background: linear-gradient(90deg, #ff5f6d, #ffc371);
  height: 100%;
  transition: width 0.3s ease;
}

.hp-value {
  font-size: 0.85em;
  color: #eee;
}

/* --- ラウンド・ターン情報バー --- */

body.battle-page .turn-info-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
}

body.battle-page .pill {
  font-size: clamp(0.95rem, 0.85rem + 0.4vw, 1.2rem);
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  color: #f2edff;
  border-radius: 999px;
  padding: 8px 18px;
}

body.battle-page .pill-accent {
  background: rgba(255, 213, 74, 0.16);
  color: #ffd54a;
}

/* --- タイマー & お題カード --- */

body.battle-page .timer-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

/* タイマー・合計文字数・次の頭文字は同じ大きさの正方形バッジで揃える */
body.battle-page .square-badge {
  flex: 0 0 auto;
  width: clamp(64px, 7vw, 88px);
  height: clamp(64px, 7vw, 88px);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

body.battle-page .timer-badge {
  background: rgba(46, 204, 113, 0.15);
  border: 3px solid #2ecc71;
  color: #2ecc71;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

body.battle-page .badge-value {
  font-weight: 900;
  line-height: 1;
}

body.battle-page .timer-badge .badge-value {
  font-size: clamp(1.5rem, 1.2rem + 1vw, 2.2rem);
}

body.battle-page .timer-badge .timer-unit {
  font-size: 0.6rem;
  font-weight: 700;
  opacity: 0.75;
}

body.battle-page .timer-badge.timer-warning {
  background: rgba(255, 159, 67, 0.18);
  border-color: #ff9f43;
  color: #ff9f43;
}

body.battle-page .timer-badge.timer-critical {
  background: rgba(255, 91, 91, 0.2);
  border-color: #ff5b5b;
  color: #ff5b5b;
  animation: count-pulse 0.6s ease-in-out infinite;
}

/* お題〜現在までの単語チェーンを直近3語の矢印つなぎで見せる、旧prompt-cardの後継 */
body.battle-page .word-chain {
  flex: 1;
  height: clamp(64px, 7vw, 88px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  padding: 6px 14px;
  font-size: clamp(0.9rem, 0.75rem + 0.6vw, 1.3rem);
  font-weight: 700;
  color: #ffd54a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.battle-page .word-chain.slide-in {
  animation: chain-slide-in 0.35s ease-out;
}

/* --- 合計文字数・次に入力すべき頭文字のバッジ --- */

body.battle-page .total-char-badge {
  background: rgba(255, 255, 255, 0.07);
  border: 3px solid #cfc4ea;
  color: #f2edff;
}

body.battle-page .total-char-label {
  font-size: 0.6rem;
  font-weight: 700;
  opacity: 0.75;
}

body.battle-page .total-char-badge .badge-value {
  font-size: clamp(1.3rem, 1rem + 1vw, 2rem);
}

body.battle-page .next-char-badge {
  background: linear-gradient(180deg, #ffd54a, #ff9f43);
  color: #2a1a4a;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(255, 213, 74, 0.5);
}

body.battle-page .next-char-label {
  font-size: 0.6rem;
  font-weight: 700;
  opacity: 0.75;
}

body.battle-page .next-char-badge .badge-value {
  font-size: clamp(1.3rem, 1rem + 1vw, 2rem);
}

/* --- 入力エリア --- */

body.battle-page .input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

body.battle-page .input-row input {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 10px 16px;
  color: #fff;
  font-size: 0.95rem;
}

body.battle-page .input-row input::placeholder {
  color: #9184b5;
}

body.battle-page .input-row input:focus {
  outline: none;
  border-color: #ffd54a;
}

/* 表示の有無やメッセージの長さで高さが変わると入力欄などが上下にずれてしまうため、
   高さを完全に固定し、折り返しも起きないよう1行省略にする。背景色だけを出し分ける */
body.battle-page .error-message {
  color: #ffb3b3;
  background: transparent;
  border-radius: 8px;
  padding: 6px 10px;
  height: 32px;
  line-height: 1.2;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.battle-page .error-message:not(:empty) {
  background: rgba(255, 91, 91, 0.12);
}

body.battle-page .bot-thinking-card {
  font-style: italic;
  color: #cfc4ea;
  text-align: center;
  padding: 6px 0;
}

/* --- ラウンド結果: スコアの比較だけを簡潔に見せる --- */

body.battle-page .result-compare {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 8px 0 12px;
}

body.battle-page .result-side {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.result-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #ffd54a;
  flex: 0 0 auto;
}

body.battle-page .result-name {
  font-weight: 700;
  font-size: 0.85rem;
  color: #cfc4ea;
}

body.battle-page .result-score {
  font-size: clamp(1.6rem, 1.3rem + 1vw, 2.2rem);
  font-weight: 900;
  color: #ffd54a;
  line-height: 1;
}

body.battle-page .result-vs {
  flex: 0 0 auto;
  font-size: 0.9rem;
  font-weight: 900;
  color: #6f6690;
}

body.battle-page .progress-bar {
  width: 100%;
  max-width: 420px;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
  margin: 4px auto 2px;
}

body.battle-page .progress-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ffd54a, #ff5f6d);
}

/* --- 決着画面 --- */

body.battle-page .game-over-title {
  font-size: 1.4rem;
  color: #ffd54a;
  text-shadow: 2px 2px 0 #c0392b;
}

#gameOverPortrait img.winner-portrait {
  max-width: min(50vw, 300px);
  filter: drop-shadow(0 0 20px #ffd54a);
  animation: pop-in 0.4s ease-out;
}

/* --- 失敗演出(画面中央に大きく表示) --- */

body.battle-page .failure-flash {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}

body.battle-page .failure-flash span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5) rotate(-4deg);
  opacity: 0;
  font-size: clamp(2rem, 1.4rem + 3.5vw, 4.5rem);
  font-weight: 900;
  color: #fff;
  background: linear-gradient(180deg, #ff5b5b, #c0392b);
  padding: 0.35em 0.8em;
  border-radius: 18px;
  box-shadow: 0 0 50px rgba(255, 91, 91, 0.7);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}

body.battle-page .failure-flash.flash-anim span {
  animation: flash-pop 1.1s cubic-bezier(0.17, 0.89, 0.32, 1.49) forwards;
}

/* --- キーフレーム --- */

@keyframes mic-bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.04); }
}

@keyframes hit-flash {
  0% { transform: translateX(0); filter: brightness(1) drop-shadow(0 8px 10px rgba(0, 0, 0, 0.5)); }
  20% { transform: translateX(-6px); filter: brightness(2.2) drop-shadow(0 0 14px #ff5b5b); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-3px); }
  100% { transform: translateX(0); filter: brightness(1) drop-shadow(0 8px 10px rgba(0, 0, 0, 0.5)); }
}

@keyframes chain-slide-in {
  from { transform: translateX(28px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes pop-in {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes count-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.12); opacity: 0.8; }
}

@keyframes shrink-bar {
  from { width: 100%; }
  to { width: 0%; }
}

@keyframes flash-pop {
  0% { transform: translate(-50%, -50%) scale(0.4) rotate(-8deg); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1.15) rotate(2deg); opacity: 1; }
  30% { transform: translate(-50%, -50%) scale(1) rotate(-1deg); opacity: 1; }
  80% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(0.9) rotate(0deg); opacity: 0; }
}
