* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; background: #14181f; color: #eef2f6;
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: none;
}
#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
}

#version-tag {
  position: absolute; left: 6px; bottom: 4px; z-index: 30;
  font-size: 10px; color: rgba(238,242,246,0.35); pointer-events: none;
  user-select: none;
}

/* ヘッダー: ゴールド・ライフ・ウェーブ・スコア */
/* 375px幅のスマホでも右端のボタンが画面外にはみ出ないよう、隙間や余白を詰めてある */
#hud {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; background: #1c2330; border-bottom: 1px solid #2c3648;
  font-size: 13px; flex-shrink: 0; flex-wrap: nowrap; overflow: hidden;
}
#hud .stat { display: flex; align-items: center; gap: 3px; white-space: nowrap; flex-shrink: 0; }
#hud .stat .icon { font-size: 14px; }
#hud .spacer { flex: 1; min-width: 0; }
#hud button {
  background: #2c3648; color: #eef2f6; border: 1px solid #3c4a63;
  border-radius: 6px; padding: 4px 8px; font-size: 12px; cursor: pointer;
  flex-shrink: 0; line-height: 1.4;
}
#hud button:active { background: #3c4a63; }
#hud button.active { background: #4fc3f7; color: #06202b; border-color: #4fc3f7; }

/* ゲーム画面本体 */
#stage {
  position: relative; flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  background: #0e1218;
}
#game-canvas { display: block; touch-action: none; }

/* 敵がゴールに到達した瞬間、画面の縁を一瞬赤く光らせるダメージ演出 */
#damage-flash {
  position: absolute; inset: 0; pointer-events: none; z-index: 13;
  box-shadow: inset 0 0 0 0 rgba(255,0,0,0);
}
#damage-flash.hit {
  animation: damageFlashPulse 0.45s ease-out;
}
@keyframes damageFlashPulse {
  0%   { box-shadow: inset 0 0 60px 20px rgba(255,23,23,0.85); background: rgba(255,0,0,0.12); }
  100% { box-shadow: inset 0 0 60px 20px rgba(255,23,23,0); background: rgba(255,0,0,0); }
}

/* タワー選択バー(下部) */
#tower-bar {
  display: flex; gap: 6px; padding: 8px; background: #1c2330;
  border-top: 1px solid #2c3648; overflow-x: auto; flex-shrink: 0;
}
.tower-btn {
  flex: 0 0 auto; width: 68px; padding: 6px 4px; border-radius: 8px;
  border: 2px solid #3c4a63; background: #232b3a; color: #eef2f6;
  text-align: center; cursor: pointer; font-size: 11px; line-height: 1.3;
}
.tower-btn .sw { width: 20px; height: 20px; border-radius: 50%; margin: 0 auto 4px; }
.tower-btn .cost { color: #ffd54f; }
.tower-btn.selected { border-color: #4fc3f7; background: #26364a; }
.tower-btn:disabled { opacity: 0.4; }

/* タワー情報パネル(選択中タワー) */
#tower-panel {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  background: rgba(20, 26, 36, 0.95); border: 1px solid #3c4a63; border-radius: 10px;
  padding: 10px 14px; display: none; gap: 10px; align-items: center; font-size: 13px;
  max-width: 92%;
}
#tower-panel.show { display: flex; }
#tower-panel .tower-panel-actions { display: flex; gap: 8px; flex-shrink: 0; }
#tower-panel button {
  background: #2c3648; color: #eef2f6; border: 1px solid #4a5a78; border-radius: 6px;
  padding: 6px 10px; font-size: 12px; cursor: pointer;
}
#tower-panel button.danger { border-color: #e57373; color: #ffb4b4; }

/* スマホ等、幅に余裕が無い画面向け:
   タワー情報(#tower-panel-body、名前・威力・射程等で複数行になりやすい)とボタン列を横に並べると
   ボタンが多段に押し出されてパネル全体が縦に間延びしてしまうため、
   「情報行」「ボタン行」の2行構成に切り替えて見やすくする。
   PC等の幅に余裕がある画面は従来通り横一列のまま。 */
@media (max-width: 520px) {
  #tower-panel.show { flex-direction: column; align-items: stretch; }
  #tower-panel .tower-panel-actions { justify-content: center; }
}

/* オーバーレイ(タイトル/ステージ選択/結果/図鑑) */
.overlay {
  position: absolute; inset: 0; background: rgba(10, 13, 18, 0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  gap: 14px; padding: 20px; padding-top: max(20px, 3vh); text-align: center; z-index: 20;
  overflow-y: auto;
}
.overlay.hidden { display: none; }
.overlay h1 { font-size: 22px; margin: 0 0 4px; }

.home-section { width: min(94vw, 420px); }
.home-heading { font-size: 14px; color: #9fb0c6; margin: 4px 0 8px; text-align: left; }
.score-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.score-table th, .score-table td { padding: 4px 6px; border-bottom: 1px solid #2c3648; text-align: left; }
.score-table th { color: #8ea0b8; font-weight: normal; }
.period-tabs { display: flex; gap: 4px; }
.period-tabs button {
  background: #232b3a; border: 1px solid #3c4a63; color: #9fb0c6; border-radius: 6px;
  padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.period-tabs button.active { color: #eef2f6; border-color: #4fc3f7; background: #26364a; }
.ranking-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ranking-table th, .ranking-table td { padding: 5px 6px; border-bottom: 1px solid #2c3648; text-align: left; }
.ranking-table th { color: #8ea0b8; font-weight: normal; }
.ranking-table td.num { text-align: right; }
.ranking-table td.date { color: #8ea0b8; font-size: 11px; white-space: nowrap; }
.score-table td.num { text-align: right; color: #ffd54f; }
.special-setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #1c2330; border: 1px solid #2c3648; border-radius: 8px; padding: 8px 12px; margin-bottom: 6px;
  text-align: left;
}
.special-setting-row .info { display: flex; align-items: center; gap: 10px; }
.special-setting-row .icon { font-size: 20px; }
.special-setting-row .name { font-size: 13px; }
.special-setting-row .req { font-size: 11px; color: #8ea0b8; }
.special-setting-row.locked { opacity: 0.5; }
.special-setting-row input[type="checkbox"] { width: 18px; height: 18px; }

/* ==== home.html(独立したホームページ)専用スタイル ==== */
/* 基本ルール(html,body { overflow:hidden; touch-action:none; })がゲーム画面(index.html)向けの
   全画面固定レイアウト用のため、ホームページでは html 側も含めて解除する必要がある */
html.home-page, body.home-page {
  overflow-y: auto; height: auto; min-height: 100%;
  touch-action: pan-y;
}
.home-wrap {
  max-width: 480px; margin: 0 auto; padding: 14px 14px 40px; text-align: center;
}
.home-header h1 { font-size: 18px; margin: 2px 0; }
.home-actions { display: flex; gap: 8px; justify-content: center; margin: 10px 0 16px; flex-wrap: wrap; }
.home-actions button {
  background: #232b3a; color: #eef2f6; border: 1px solid #3c4a63; border-radius: 8px;
  padding: 7px 12px; font-size: 12px; cursor: pointer;
}
.home-heading { margin: 12px 0 6px; }
.home-scroll-list { max-height: 220px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.home-modal {
  position: fixed; inset: 0; background: rgba(10,13,18,0.92); z-index: 40;
  display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px;
  overflow-y: auto;
}
.home-modal.hidden { display: none; }
.home-modal-body {
  background: #1c2330; border: 1px solid #2c3648; border-radius: 12px; padding: 20px;
  width: 100%; max-width: 460px; text-align: center;
}
.home-modal-body h2, .home-modal-body h1 { margin-top: 0; font-size: 18px; }
.home-modal-body .big-btn { margin-top: 16px; }
.overlay p { margin: 0; color: #a9b4c4; font-size: 13px; max-width: 420px; }
.stage-list { display: flex; flex-direction: column; gap: 7px; width: min(90vw, 380px); }
.stage-card {
  background: #1c2330; border: 1px solid #2c3648; border-radius: 10px; padding: 9px 12px;
  text-align: left; cursor: pointer; color: #eef2f6;
}
.stage-card:active { background: #232b3a; }
.stage-card .stage-card-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.stage-card b { font-size: 13px; }
.stage-card .badge-sa { font-size: 10px; color: #ffd54f; white-space: nowrap; }
.stage-card .stage-card-desc {
  font-size: 11px; color: #9aa7bb; margin: 2px 0 4px;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}
.stage-card .stage-card-meta { display: flex; justify-content: space-between; font-size: 11px; color: #ffd54f; }
.stage-card span { font-size: 12px; color: #9aa7bb; }
.big-btn {
  background: #4fc3f7; color: #06202b; font-weight: bold; border: none; border-radius: 8px;
  padding: 12px 26px; font-size: 15px; cursor: pointer;
}
#btn-share-x { background: #14171a; color: #ffffff; }

/* Waveスタート/ゲーム開始ボタン(共用) */
#next-wave-btn {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  background: #4fc3f7; color: #06202b; border: none; border-radius: 20px;
  padding: 8px 18px; font-size: 13px; font-weight: bold; cursor: pointer; display: none;
  z-index: 12;
}
#next-wave-btn.show { display: block; }

/* 特殊攻撃バー(★で解放。ボム/フリーズ/パワーアップなど) */
#special-bar {
  position: absolute; bottom: 8px; right: 8px;
  display: flex; gap: 6px; z-index: 12;
}
.special-btn {
  position: relative; width: 44px; height: 44px; border-radius: 50%;
  background: #232b3a; border: 2px solid #ffd54f; font-size: 20px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  color: #eef2f6;
}
.special-btn.targeting { border-color: #ff7043; box-shadow: 0 0 0 4px rgba(255,112,67,0.3); }
.special-btn.cooling { opacity: 0.5; cursor: default; }
.special-btn .cd-label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.55); border-radius: 50%; font-size: 13px; font-weight: bold;
}

/* スコア獲得の演出トースト(画面上部にポップして消える) */
#score-toast-layer {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 14;
}
.score-toast {
  position: absolute; left: 50%;
  /* --toast-slot はJS(UIManager._acquireToastSlot)が縦方向の空きスロット番号を割り当てる。
     複数のトースト(Wave開始・Waveスキップ・特殊攻撃発動など)が短時間に重なっても、
     互いに被らないよう縦にずらして表示する。 */
  top: calc(10% + var(--toast-slot, 0) * 120px);
  font-weight: bold; white-space: nowrap;
  text-shadow: 0 2px 8px rgba(0,0,0,0.7);
  animation: scoreToastPop 1.1s ease-out forwards; /* durationはJS側でelement.style.animationDurationにより上書きされる */
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.score-toast--medium { font-size: 18px; color: #4fc3f7; }
.score-toast--large { font-size: 26px; color: #ffd54f; text-shadow: 0 0 14px rgba(255,213,79,0.7), 0 2px 8px rgba(0,0,0,0.7); }
.score-toast--warning { font-size: 20px; color: #ff8a65; text-shadow: 0 0 14px rgba(255,138,101,0.7), 0 2px 8px rgba(0,0,0,0.7); }
/* 複数行トーストの行ごとの色分け。1行目(見出し)は親のkind色をそのまま使い、
   2行目以降はリワード種別ごとに色を変えて視認性を上げる。 */
.toast-line--title { color: #ffffff; font-size: 1em; }
.toast-line--score { color: #ffd54f; font-size: 0.72em; }
.toast-line--gold { color: #a5d6a7; font-size: 0.72em; }
.toast-line--bonus { color: #ff8a65; font-size: 0.72em; }
@keyframes scoreToastPop {
  0%   { opacity: 0; transform: translate(-50%, 12px) scale(0.6); }
  15%  { opacity: 1; transform: translate(-50%, 0) scale(1.18); }
  30%  { opacity: 1; transform: translate(-50%, 0) scale(1); }
  75%  { opacity: 1; transform: translate(-50%, -6px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -30px) scale(1); }
}

/* タワー/敵 一覧(図鑑) */
#dex-content h2 { font-size: 14px; margin: 14px 0 8px; color: #4fc3f7; }
.dex-card {
  display: flex; gap: 10px; align-items: flex-start;
  background: #1c2330; border: 1px solid #2c3648; border-radius: 8px;
  padding: 10px 12px; margin-bottom: 8px; font-size: 12px;
}
.dex-card .sw { width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0; margin-top: 2px; }
/* 敵の特殊能力の系統ごとに輪郭を変えて識別しやすくする(ゲーム画面の描画と対応させている) */
.dex-card .sw.shape-hexagon { border-radius: 0; clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%); }
.dex-card .sw.shape-pentagon { border-radius: 0; clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%); }
.dex-card .sw.shape-diamond { border-radius: 0; clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }
.dex-card .sw.shape-triangle { border-radius: 0; clip-path: polygon(50% 0%, 100% 100%, 0% 100%); }
.dex-card .sw.shape-star { border-radius: 0; clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.dex-card b { font-size: 13px; }
.dex-card .desc { color: #9aa7bb; margin: 3px 0 6px; }
.dex-card table { width: 100%; border-collapse: collapse; font-size: 11px; }
.dex-card table th, .dex-card table td { text-align: center; padding: 2px 4px; border-bottom: 1px solid #262f40; }
.dex-card table th { color: #8ea0b8; font-weight: normal; }

/* ==== ローグライクモード: ショップパネル ====
   全面オーバーレイにはせず、画面下部に固定パネルとして表示することで、
   ショップを開いたままでも下のtower-barや盤面(タワー配置)を操作できるようにしている */
#shop-panel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 18;
  display: flex; justify-content: center; padding: 10px; pointer-events: none;
}
#shop-panel.hidden { display: none; }
.shop-panel-inner {
  pointer-events: auto;
  background: rgba(20, 26, 36, 0.97); border: 1px solid #3c4a63; border-radius: 12px;
  padding: 14px 16px; width: min(92vw, 420px); text-align: center;
  max-height: 62vh; overflow-y: auto;
}
#shop-status {
  display: flex; justify-content: space-around; font-size: 13px; color: #ffd54f;
  background: #1c2330; border-radius: 8px; padding: 6px 10px; margin-bottom: 10px;
}
.shop-actions { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.shop-actions .big-btn { padding: 10px 16px; font-size: 13px; }
.shop-actions .big-btn:disabled { opacity: 0.4; cursor: default; }

/* ==== ローグライクモード: 強化選択カード ==== */
#overlay-upgrade-choice h1 { margin-bottom: 2px; }
#upgrade-next-wave-info {
  background: #1c2330; border: 1px solid #2c3648; border-radius: 8px; padding: 8px 12px;
  font-size: 12px; color: #9fb0c6; text-align: left;
}
.upgrade-card {
  background: #1c2330; border: 2px solid #3c4a63; border-radius: 12px; padding: 12px 14px;
  text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px;
}
.upgrade-card:active { background: #232b3a; transform: scale(0.98); }
.upgrade-card .rarity-badge {
  align-self: flex-start; font-size: 10px; font-weight: bold; padding: 2px 8px; border-radius: 10px;
}
.upgrade-card.rarity-COMMON { border-color: #78909c; }
.upgrade-card .rarity-badge.rarity-COMMON { background: #455a64; color: #eceff1; }
.upgrade-card.rarity-RARE { border-color: #4fc3f7; box-shadow: 0 0 10px rgba(79,195,247,0.25); }
.upgrade-card .rarity-badge.rarity-RARE { background: #01579b; color: #b3e5fc; }
.upgrade-card.rarity-EPIC { border-color: #ffb300; box-shadow: 0 0 14px rgba(255,179,0,0.35); }
.upgrade-card .rarity-badge.rarity-EPIC { background: #ff8f00; color: #fff3e0; }
.upgrade-card .name { font-size: 15px; font-weight: bold; }
.upgrade-card .desc { font-size: 12px; color: #c3cede; }
.upgrade-card .category-tag { font-size: 10px; color: #78909c; }
#upgrade-build-summary { font-size: 11px; color: #78909c; text-align: left; }
#result-build-summary { font-size: 12px; color: #c3cede; text-align: left; background: #1c2330; border-radius: 8px; padding: 8px 12px; }
