/* ============================================================
   style.css - メインスタイルシート
   KeyMonster Quest - キーモンスター クエスト
   ============================================================ */

:root {
  --primary: #1a1a2e;
  --secondary: #16213e;
  --accent: #0f3460;
  --highlight: #e94560;
  --gold: #f5c518;
  --blue: #4fc3f7;
  --green: #66bb6a;
  --purple: #ab47bc;
  --orange: #ffa726;
  --text: #e8e8f0;
  --text-dim: #9090a8;
  --border: #2a2a4a;
  --panel-bg: rgba(22, 33, 62, 0.95);
  --hp-color: #4caf50;
  --mp-color: #2196f3;
  --danger: #f44336;
}

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

body {
  background: var(--primary);
  color: var(--text);
  font-family: 'Segoe UI', 'Meiryo', 'Yu Gothic', sans-serif;
  min-height: 100vh;
  overflow-y: auto;
  user-select: none;
}

/* ============================================================
   共通コンポーネント
   ============================================================ */
.hidden { display: none !important; }

.btn {
  padding: 10px 22px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: bold;
  letter-spacing: 1px;
}
.btn:hover { background: var(--highlight); border-color: var(--highlight); transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn.btn-gold { background: var(--gold); border-color: var(--gold); color: #111; }
.btn.btn-gold:hover { background: #ffdc44; }
.btn.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn.btn-green { background: var(--green); border-color: var(--green); color: #111; }
.btn.btn-disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* HPバー */
.stat-bar {
  width: 100%;
  height: 11px;
  background: #333355;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #444466;
}
.stat-bar-fill {
  height: 100%;
  border-radius: 7px;
  transition: width 0.4s ease;
}
.stat-bar-fill.hp { background: linear-gradient(90deg, #388e3c, #66bb6a); }
.stat-bar-fill.hp.low { background: linear-gradient(90deg, #b71c1c, #f44336); }
.stat-bar-fill.hp.mid { background: linear-gradient(90deg, #e65100, #ffa726); }
.stat-bar-fill.mp { background: linear-gradient(90deg, #1565c0, #42a5f5); }
.stat-bar-fill.timer { background: linear-gradient(90deg, #7b1fa2, #ce93d8); }
.stat-bar-fill.timer.warning { background: linear-gradient(90deg, #b71c1c, #f44336); animation: pulse 0.5s infinite; }

/* ============================================================
   タイトル画面
   ============================================================ */
#screen-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 40px;
  padding-bottom: 32px;
  min-height: 100vh;
  background: radial-gradient(ellipse at center, #1a1a4a 0%, #0a0a1e 100%);
  position: relative;
  overflow: hidden;
}

.title-bg-stars {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image:
    radial-gradient(circle, white 1px, transparent 1px),
    radial-gradient(circle, white 1px, transparent 1px);
  background-size: 200px 200px, 150px 150px;
  background-position: 0 0, 100px 100px;
  opacity: 0.15;
  animation: twinkle 4s infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.15; }
  50% { opacity: 0.25; }
}

.title-logo {
  text-align: center;
  margin-bottom: 20px;
  z-index: 1;
}

.title-logo-sub {
  font-size: 13px;
  letter-spacing: 6px;
  color: var(--gold);
  opacity: 0.8;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.title-logo h1 {
  font-size: 48px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--gold), var(--highlight), var(--blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  letter-spacing: 4px;
  animation: titleGlow 3s infinite;
}

@keyframes titleGlow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.3); }
}

.title-logo .subtitle {
  font-size: 16px;
  color: var(--text-dim);
  margin-top: 6px;
  letter-spacing: 3px;
}

.title-logo .tagline {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 4px;
  opacity: 0.7;
}

/* ---- ストーリースクロール ---- */
.title-story-wrap {
  position: relative;
  width: 380px;
  max-width: 90vw;
  height: 210px;
  overflow: hidden;
  margin-bottom: 24px;
  z-index: 1;
  border-top: 1px solid rgba(245,197,24,0.15);
  border-bottom: 1px solid rgba(245,197,24,0.15);
}

.title-story-fade-top,
.title-story-fade-bottom {
  position: absolute;
  left: 0; right: 0;
  height: 48px;
  z-index: 2;
  pointer-events: none;
}
.title-story-fade-top {
  top: 0;
  background: linear-gradient(to bottom, #0a0a1e 0%, transparent 100%);
}
.title-story-fade-bottom {
  bottom: 0;
  background: linear-gradient(to top, #0a0a1e 0%, transparent 100%);
}

.title-story-scroll {
  position: absolute;
  width: 100%;
  animation: storyScroll 36s linear infinite;
}

@keyframes storyScroll {
  0%   { transform: translateY(100%); }
  100% { transform: translateY(-100%); }
}

.title-story-text {
  padding: 12px 20px;
  text-align: center;
  line-height: 1.85;
}

.title-story-text p {
  font-size: 13.5px;
  color: #b8b8d0;
  margin: 0;
}

.title-story-text .story-chapter {
  font-size: 13px;
  color: var(--gold);
  letter-spacing: 3px;
  opacity: 0.9;
  margin: 8px 0 4px;
}

.title-story-text .story-highlight {
  font-size: 15px;
  font-weight: bold;
  color: var(--gold);
  letter-spacing: 1px;
}

.title-story-text .story-dark {
  color: var(--highlight);
  opacity: 0.85;
}

.title-story-text .story-end {
  font-size: 13px;
  color: var(--blue);
  letter-spacing: 2px;
  opacity: 0.9;
  margin-top: 8px;
}

/* ---- タイトルボタン ---- */
.title-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 1;
  align-items: center;
}

.title-buttons .btn {
  width: 220px;
  font-size: 18px;
  padding: 14px 30px;
  letter-spacing: 2px;
}

/* ============================================================
   キャラクター作成画面
   ============================================================ */
#screen-setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at center, #1a2a4a 0%, #0a0a1e 100%);
  padding: 20px;
}

.setup-panel {
  background: var(--panel-bg);
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 36px;
  max-width: 600px;
  width: 100%;
  box-shadow: 0 0 40px rgba(15, 52, 96, 0.5);
}

.setup-panel h2 {
  text-align: center;
  font-size: 28px;
  margin-bottom: 24px;
  color: var(--gold);
  letter-spacing: 2px;
}

.setup-field {
  margin-bottom: 24px;
}

.setup-field label {
  display: block;
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.setup-field input[type="text"] {
  width: 100%;
  background: var(--accent);
  border: 2px solid #1a4080;
  border-radius: 8px;
  color: var(--text);
  font-size: 20px;
  padding: 10px 16px;
  outline: none;
  transition: border-color 0.2s;
}
.setup-field input[type="text"]:focus { border-color: var(--blue); }

.type-selector {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.type-card {
  background: var(--accent);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.type-card:hover { border-color: var(--blue); transform: translateY(-3px); }
.type-card.selected { border-color: var(--gold); background: #1a3060; }
.type-card .type-emoji { font-size: 28px; margin-bottom: 6px; }
.type-card .type-name { font-size: 12px; font-weight: bold; color: var(--text); }
.type-card .type-desc { font-size: 10px; color: var(--text-dim); margin-top: 2px; }

.type-stats-preview {
  margin-top: 16px;
  padding: 14px;
  background: var(--accent);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-dim);
  min-height: 60px;
}
.type-stats-preview .stat-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.type-stats-preview .stat-item {
  color: var(--text);
}
.type-stats-preview .stat-item span {
  color: var(--gold);
  font-weight: bold;
}

/* ============================================================
   メインゲーム画面（バトル）
   ============================================================ */
#screen-battle {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  background: linear-gradient(180deg, #0a0a1e 0%, #1a1a3e 100%);
}

/* ヘッダー */
.battle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 16px;
  background: rgba(10, 10, 30, 0.9);
  border-bottom: 2px solid var(--accent);
  position: relative;
}

/* ============================================================
   右上メニューバー
   ============================================================ */
.battle-menu-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: 16px;
  flex-shrink: 0;
}

.menu-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 13px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  border: 2px solid;
  transition: all 0.18s;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.menu-btn:hover { transform: translateY(-2px); filter: brightness(1.2); }
.menu-btn:active { transform: translateY(0); }

.menu-btn-bench {
  background: #1a2a40;
  border-color: var(--blue);
  color: var(--blue);
}
.menu-btn-bench:hover { background: #1e3a58; }
.menu-btn-bench.has-monsters {
  border-color: var(--gold);
  color: var(--gold);
  background: #2a2200;
}
.menu-btn-bench.has-monsters:hover { background: #332a00; }

.menu-btn-top {
  background: #2a1a1a;
  border-color: #aa4444;
  color: #ff8888;
}
.menu-btn-top:hover { background: #3a1a1a; border-color: var(--danger); }

/* ============================================================
   ベンチモンスター小窓
   ============================================================ */
.bench-popup {
  position: fixed;
  top: 60px;
  right: 16px;
  width: 300px;
  background: #0e1428;
  border: 2px solid var(--blue);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7), 0 0 20px rgba(79, 195, 247, 0.15);
  z-index: 500;
  animation: popupSlideIn 0.18s ease-out;
  overflow: hidden;
}

@keyframes popupSlideIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

.bench-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: linear-gradient(90deg, #0f2040, #0a1830);
  border-bottom: 1px solid #1e3a5a;
  font-size: 14px;
  font-weight: bold;
  color: var(--blue);
  letter-spacing: 1px;
}

.bench-popup-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 4px;
  transition: all 0.15s;
}
.bench-popup-close:hover { color: var(--danger); background: rgba(244,67,54,0.15); }

.bench-popup-body {
  max-height: 340px;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bench-popup-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 20px 0;
}

.bench-popup-card {
  background: #141e34;
  border: 1px solid #2a3a5a;
  border-radius: 8px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  transition: border-color 0.15s;
}
.bench-popup-card:hover { border-color: var(--blue); }
.bench-popup-card.is-blue-slime { border-color: #4499ff; background: #0d1830; }
.bench-popup-card-emoji {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.bench-popup-card-emoji svg { width: 100%; height: 100%; }
.bench-popup-card-info { min-width: 0; }
.bench-popup-card-name {
  font-size: 14px;
  font-weight: bold;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bench-popup-card-level {
  font-size: 11px;
  color: var(--gold);
  margin-bottom: 4px;
}
.bench-popup-card-stats {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
  flex-wrap: wrap;
}
.bench-popup-card-stats span { white-space: nowrap; }
.bench-popup-card-stats span b { color: var(--text); }

.bench-popup-hpbar {
  margin-top: 5px;
}
.bench-popup-hpbar .stat-bar { height: 6px; }

.bench-popup-count {
  font-size: 11px;
  color: var(--text-dim);
  text-align: right;
  padding: 4px 10px 8px;
  border-top: 1px solid #1e3a5a;
}

.stage-info {
  font-size: 16px;
  color: var(--gold);
  font-weight: bold;
  letter-spacing: 1px;
}

.player-exp-bar {
  flex: 1;
  max-width: 300px;
  margin: 0 20px;
}
.player-exp-bar .exp-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 2px;
  display: flex;
  justify-content: space-between;
}
.stat-bar-fill.exp { background: linear-gradient(90deg, #5e35b1, #9c27b0); }

/* メインバトルエリア */
.battle-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 10px 14px;
  align-items: start;
}

/* キャラクターパネル */
.char-panel {
  background: var(--panel-bg);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  position: relative;
  transition: border-color 0.3s;
}
.char-panel.active-turn { border-color: var(--gold); box-shadow: 0 0 15px rgba(245, 197, 24, 0.3); }
.char-panel.enemy { border-color: var(--highlight); }
.char-panel.enemy.active-turn { box-shadow: 0 0 15px rgba(233, 69, 96, 0.3); }

.char-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.char-emoji {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.char-emoji svg {
  width: 100%;
  height: 100%;
}

.char-name-info h3 {
  font-size: 16px;
  font-weight: bold;
  color: var(--text);
}
.char-name-info .char-level {
  font-size: 12px;
  color: var(--text-dim);
}
.char-name-info .char-type-badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: bold;
  margin-top: 2px;
}

.type-badge-attack { background: #b71c1c; color: white; }
.type-badge-magic { background: #4a148c; color: white; }
.type-badge-defense { background: #1a237e; color: white; }
.type-badge-magicDef { background: #1b5e20; color: white; }
.type-badge-speed { background: #e65100; color: white; }

.char-stats { display: grid; gap: 4px; }

.hp-mp-row {
  display: grid;
  gap: 3px;
}

.stat-row-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  margin-bottom: 2px;
}
.stat-row-label .label { color: var(--text-dim); font-weight: bold; font-size: 11px; }
.stat-row-label .value { color: var(--text); font-size: 13px; }

/* 詳細ステータス（ホバー表示） */
.stat-detail-btn {
  font-size: 11px;
  color: var(--blue);
  cursor: pointer;
  text-decoration: underline;
  background: none;
  border: none;
  padding: 0;
  margin-top: 4px;
}

.stat-detail-popup {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #0a0a2a;
  border: 2px solid var(--blue);
  border-radius: 10px;
  padding: 16px;
  z-index: 100;
  min-width: 200px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.8);
}
.stat-detail-popup.show { display: block; }
.stat-detail-popup h4 { color: var(--gold); margin-bottom: 10px; font-size: 14px; }
.stat-detail-popup table { width: 100%; font-size: 13px; border-collapse: collapse; }
.stat-detail-popup td { padding: 3px 8px; }
.stat-detail-popup td:first-child { color: var(--text-dim); }
.stat-detail-popup td:last-child { color: var(--text); font-weight: bold; text-align: right; }

/* 左パネル（プレイヤー＋仲間） */
.battle-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 仲間パネル + コマンドパネルを横並び */
.battle-left-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: start;
}

.companion-empty {
  background: var(--panel-bg);
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* ============================================================
   バトルログ
   ============================================================ */
.battle-bottom {
  padding: 0 14px 8px;
}

.battle-log {
  background: rgba(10, 10, 30, 0.9);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  height: 110px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.5;
}

.battle-log .log-normal { color: var(--text); }
.battle-log .log-damage { color: var(--highlight); }
.battle-log .log-heal { color: var(--green); }
.battle-log .log-system { color: var(--gold); font-weight: bold; }
.battle-log .log-tame { color: var(--purple); }
.battle-log .log-level { color: var(--blue); font-weight: bold; }

/* ============================================================
   コマンドパネル
   ============================================================ */
.command-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.command-title {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: bold;
  letter-spacing: 1px;
}

.command-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.cmd-btn {
  padding: 7px 6px;
  border: 2px solid;
  border-radius: 8px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  letter-spacing: 0.5px;
}
.cmd-btn:hover:not(.disabled) { transform: translateY(-2px); filter: brightness(1.2); }
.cmd-btn.disabled { opacity: 0.35; cursor: not-allowed; }

.cmd-btn.cmd-weak-attack { background: #1a2a1a; border-color: #4caf50; color: #a5d6a7; }
.cmd-btn.cmd-strong-attack { background: #2a1a1a; border-color: #f44336; color: #ef9a9a; }
.cmd-btn.cmd-magic { background: #1a1a3a; border-color: #9c27b0; color: #ce93d8; }
.cmd-btn.cmd-tame { background: #2a1a2a; border-color: #ff9800; color: #ffcc80; }
.cmd-btn.cmd-tame.gold { background: #2a2000; border-color: var(--gold); color: var(--gold); box-shadow: 0 0 12px rgba(245, 197, 24, 0.5); }

.cmd-btn .cmd-label { font-size: 15px; }
.cmd-btn .cmd-sub { font-size: 10px; opacity: 0.7; }

/* ============================================================
   タイピングオーバーレイ
   ============================================================ */
#typing-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}

.typing-panel {
  background: var(--panel-bg);
  border: 3px solid var(--accent);
  border-radius: 16px;
  padding: 36px 40px;
  max-width: 680px;
  width: 90%;
  box-shadow: 0 0 60px rgba(15, 52, 96, 0.6);
}

.typing-title {
  text-align: center;
  font-size: 22px;
  font-weight: bold;
  margin-bottom: 8px;
  color: var(--gold);
  letter-spacing: 2px;
}

.typing-subtitle {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 24px;
}

/* タイマーバー */
.typing-timer-bar {
  margin-bottom: 20px;
}
.typing-timer-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
#timer-seconds { font-size: 16px; font-weight: bold; color: var(--text); }

/* ひらがな表示 */
.typing-target {
  text-align: center;
  margin-bottom: 16px;
}

.typing-kana {
  font-size: 36px;
  font-weight: bold;
  letter-spacing: 3px;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 6px;
}

.typing-romaji-guide {
  font-size: 18px;
  color: var(--text-dim);
  letter-spacing: 2px;
  font-family: 'Courier New', monospace;
}

/* タイピング進捗表示 */
.typing-progress-text {
  font-family: 'Courier New', monospace;
  font-size: 22px;
  letter-spacing: 3px;
  text-align: center;
  min-height: 36px;
  margin-bottom: 16px;
}
.typing-progress-text .char-correct { color: var(--green); }
.typing-progress-text .char-current { color: var(--gold); border-bottom: 2px solid var(--gold); }
.typing-progress-text .char-pending { color: var(--text-dim); }
.typing-progress-text .char-wrong { color: var(--danger); text-decoration: underline; }

/* 入力フィールド */
.typing-input-wrap {
  position: relative;
  margin-bottom: 16px;
}

#typing-input {
  width: 100%;
  background: var(--accent);
  border: 3px solid #1a4080;
  border-radius: 10px;
  color: var(--text);
  font-size: 22px;
  padding: 12px 18px;
  outline: none;
  text-align: center;
  font-family: 'Courier New', monospace;
  letter-spacing: 3px;
  transition: border-color 0.2s;
  caret-color: transparent;
}
#typing-input:focus { border-color: var(--blue); }
#typing-input.correct { border-color: var(--green); }
#typing-input.wrong { border-color: var(--danger); animation: shake 0.3s; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.typing-result-msg {
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  min-height: 28px;
  color: var(--text-dim);
}
.typing-result-msg.success { color: var(--green); }
.typing-result-msg.failure { color: var(--danger); }

/* ============================================================
   ルーレットオーバーレイ（仲間にするコマンド）
   ============================================================ */
#roulette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 300;
  backdrop-filter: blur(4px);
}

.roulette-panel {
  background: var(--panel-bg);
  border: 3px solid var(--purple);
  border-radius: 20px;
  padding: 36px 40px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 60px rgba(156, 39, 176, 0.4);
}

.roulette-title {
  font-size: 22px;
  font-weight: bold;
  color: var(--purple);
  margin-bottom: 8px;
  letter-spacing: 2px;
}

.roulette-rate {
  font-size: 16px;
  color: var(--text-dim);
  margin-bottom: 24px;
}

.roulette-canvas-wrap {
  position: relative;
  width: 280px;
  height: 280px;
  margin: 0 auto 20px;
}

#roulette-canvas {
  border-radius: 50%;
  box-shadow: 0 0 20px rgba(156, 39, 176, 0.5);
}

.roulette-pointer {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 28px;
  color: var(--gold);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
}

.roulette-result {
  font-size: 28px;
  font-weight: bold;
  min-height: 42px;
  color: var(--text-dim);
}
.roulette-result.success { color: var(--green); animation: resultPop 0.5s; }
.roulette-result.failure { color: var(--danger); animation: resultPop 0.5s; }

@keyframes resultPop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* ============================================================
   モンスター入れ替え画面
   ============================================================ */
#screen-monster-swap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at center, #1a1a3a 0%, #0a0a1e 100%);
  padding: 20px;
}

.swap-panel {
  background: var(--panel-bg);
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 28px;
  max-width: 700px;
  width: 100%;
}

.swap-panel h2 {
  text-align: center;
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--gold);
}
.swap-panel .swap-subtitle {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 24px;
}

.swap-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.swap-section h3 {
  font-size: 15px;
  color: var(--text-dim);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.monster-slot {
  background: var(--accent);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.monster-slot:hover { border-color: var(--blue); }
.monster-slot.selected { border-color: var(--gold); background: #1a3060; }
.monster-slot.active-companion { border-color: var(--green); }
.monster-slot-emoji {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.monster-slot-emoji svg { width: 100%; height: 100%; }
.monster-slot-info .slot-name { font-size: 14px; font-weight: bold; }
.monster-slot-info .slot-stats { font-size: 11px; color: var(--text-dim); }

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

/* ============================================================
   ステージ移行・結果画面
   ============================================================ */
#screen-stage-clear {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at center, #1a3a1a 0%, #0a0a1e 100%);
  text-align: center;
  padding: 20px;
}

.stage-clear-panel {
  background: var(--panel-bg);
  border: 3px solid var(--green);
  border-radius: 20px;
  padding: 40px;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 0 50px rgba(102, 187, 106, 0.3);
}

.stage-clear-panel h2 {
  font-size: 36px;
  color: var(--green);
  margin-bottom: 12px;
  letter-spacing: 3px;
}

.stage-clear-panel .exp-gained {
  font-size: 20px;
  color: var(--gold);
  margin: 16px 0;
}

.level-up-list {
  list-style: none;
  margin: 12px 0;
}
.level-up-list li {
  font-size: 16px;
  color: var(--blue);
  padding: 4px 0;
}

/* ============================================================
   ゲームオーバー・クリア画面
   ============================================================ */
#screen-game-over {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at center, #3a0a0a 0%, #0a0a0a 100%);
  text-align: center;
}
#screen-game-over h1 {
  font-size: 72px;
  color: var(--danger);
  font-weight: 900;
  letter-spacing: 6px;
  text-shadow: 0 0 30px rgba(244, 67, 54, 0.5);
  animation: flicker 2s infinite;
}
@keyframes flicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

#screen-game-clear {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at center, #2a2a0a 0%, #0a0a1e 100%);
  text-align: center;
  padding: 20px;
}
#screen-game-clear h1 {
  font-size: 56px;
  background: linear-gradient(135deg, var(--gold), #fff, var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 900;
  letter-spacing: 4px;
  margin-bottom: 20px;
  animation: clearShine 2s infinite;
}
@keyframes clearShine {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.4); }
}

/* ============================================================
   ターン開始バナー
   ============================================================ */
#turn-start-banner {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  pointer-events: none; /* クリックを透過 */
}

#turn-start-banner.show {
  display: flex;
}

.turn-start-inner {
  background: linear-gradient(135deg, rgba(15, 52, 96, 0.96), rgba(26, 26, 46, 0.96));
  border: 2px solid var(--gold);
  border-radius: 16px;
  padding: 18px 40px;
  text-align: center;
  box-shadow: 0 0 40px rgba(245, 197, 24, 0.4), 0 0 80px rgba(245, 197, 24, 0.15);
  animation: turnBannerAnim 1.8s ease-in-out forwards;
}

.turn-start-num {
  font-size: 28px;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 4px;
  margin-bottom: 6px;
}

.turn-start-order {
  font-size: 15px;
  color: var(--text-dim);
  letter-spacing: 2px;
}

@keyframes turnBannerAnim {
  0%   { opacity: 0; transform: scale(0.8) translateY(-20px); }
  20%  { opacity: 1; transform: scale(1.05) translateY(0); }
  60%  { opacity: 1; transform: scale(1) translateY(0); }
  100% { opacity: 0; transform: scale(0.95) translateY(10px); }
}

/* ============================================================
   アニメーション
   ============================================================ */
.damage-flash {
  animation: damageFlash 0.3s;
}
@keyframes damageFlash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; background: rgba(244, 67, 54, 0.3); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.float-damage {
  position: absolute;
  font-size: 22px;
  font-weight: bold;
  color: var(--danger);
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
  animation: floatUp 1.2s ease-out forwards;
  pointer-events: none;
  z-index: 999;
}
.float-damage.magic { color: var(--purple); }
.float-damage.heal { color: var(--green); }

@keyframes floatUp {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  60% { transform: translateY(-50px) scale(1.2); }
  100% { transform: translateY(-80px) scale(0.8); opacity: 0; }
}

/* ============================================================
   レスポンシブ
   ============================================================ */
@media (max-width: 768px) {
  .title-logo h1 { font-size: 40px; }
  .battle-main { grid-template-columns: 1fr; }
  .battle-left-bottom { grid-template-columns: 1fr; }
  .type-selector { grid-template-columns: repeat(3, 1fr); }
  .command-buttons { grid-template-columns: 1fr 1fr; }
}

/* スクロールバー */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #1a1a2e; }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 3px; }

/* ============================================================
   仲間コマンド選択オーバーレイ
   ============================================================ */
.companion-cmd-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 250;
  backdrop-filter: blur(4px);
}

.companion-cmd-panel {
  background: var(--panel-bg);
  border: 3px solid #4caf50;
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 0 40px rgba(76, 175, 80, 0.4);
}

.companion-cmd-title {
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  color: #a5d6a7;
  margin-bottom: 20px;
}

.companion-cmd-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cmd-btn.cmd-defense {
  background: #1a2a3a;
  border: 2px solid #2196f3;
  color: #90caf9;
  border-radius: 10px;
  padding: 12px 16px;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform 0.1s, filter 0.1s;
}
.cmd-btn.cmd-defense:hover { transform: translateY(-2px); filter: brightness(1.2); }

/* ============================================================
   バトル中仲間交代オーバーレイ
   ============================================================ */
.mid-battle-swap-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 250;
  backdrop-filter: blur(4px);
}

.mid-battle-swap-panel {
  background: var(--panel-bg);
  border: 3px solid #ff9800;
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 40px rgba(255, 152, 0, 0.4);
}

.mid-battle-swap-title {
  font-size: 20px;
  font-weight: bold;
  color: #ffcc80;
  margin-bottom: 8px;
}

.mid-battle-swap-subtitle {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.mid-battle-swap-slots {
  text-align: left;
  max-height: 280px;
  overflow-y: auto;
}
