@import url("./ui-arena.css");
:root {
  --bg: #0b0b12;
  --panel: #15151f;
  --panel-2: #1d1d2b;
  --ink: #e7e3d4;
  --ink-dim: #9b97a8;
  --accent: #c9a227;
  --accent-2: #6b8cff;
  --danger: #d4504e;
  --good: #4caf50;
  --border: #2c2c3d;
  --font: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", "Noto Serif CJK JP", "Source Han Serif JP", serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --game-width: 520px;
}

/* マウスで遊ぶ広い画面だけ横幅を広げ、タブレットは従来の幅を保つ。 */
@media (min-width: 1000px) and (hover: hover) and (pointer: fine) {
  html.pc-input { --game-width: 640px; }
  html.pc-input #app, html.pc-input #town-screen, html.pc-input #town-shell,
  html.pc-input .ui-sheet:not(.k-celebrate) {
    width: min(100%, 640px); max-width: 640px;
  }
}

/* 内側のスクロール領域でもダブルタップ拡大を許さず、通常の操作は保つ。 */
* { box-sizing: border-box; touch-action: manipulation; }

/* 全画面でスクロール操作を保ち、縦横のスクロールバーだけを隠す */
* { scrollbar-width: none !important; -ms-overflow-style: none !important; }
*::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }

html, body {
  margin: 0;
  padding: 0;
  background: #050509;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: none;
  image-rendering: pixelated;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* 文節で折り返す (全画面共通): 字と字の間では折らず、src/ui/phrase.js が入れる折り目
   (句読点・括弧・助詞の後) でだけ改行する。一つの文節が1行に収まらないときだけ途中で折る */
html, body { word-break: keep-all; overflow-wrap: break-word; line-break: strict; }

/* ページ自体はスクロールさせず、画面内に収める */
html, body { height: 100%; overflow: hidden; }

/* 起動中は、HTMLに置いてある素のゲームUIを見せない。
   タイトル画面や復元後の画面が用意できてから src/game.js が解除する。 */
body.booting #app {
  visibility: hidden;
}

/* タイトルから本編の準備完了までは、画像の準備・レイアウトを続けながら背面を隠す。 */
body.game-starting #app { opacity: 0; pointer-events: none; }

#app {
  position: relative;
  width: min(100%, 520px);
  max-width: 520px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ===== トップバー ===== */
#topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: linear-gradient(180deg, #232333, #12121c 70%, #0d0d15);
  border-bottom: 2px solid var(--accent);
  box-shadow: 0 2px 10px rgba(201, 162, 39, 0.18), inset 0 1px 0 rgba(255,255,255,0.06);
}
/* 街のヘッダ (.tw-head) と同じ構図: 左=操作ボタン / 中央=タイトル / 右=通貨 */
.topbar-left { display: flex; align-items: center; gap: 6px; }
#floor-info { flex: 1; text-align: center; font-size: 15px; font-weight: bold; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: 0.5px; }
#topbar-cur { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; font-size: 11px; font-weight: bold; white-space: nowrap; }
#settings-btn, #descend-btn, #return-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--ink);
  font-size: 16px;
  padding: 4px 8px;
  cursor: pointer;
  line-height: 1;
  min-width: 40px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#settings-btn:active { background: #2a2a3a; }
#descend-btn:not(:disabled):active { background: #2a2a3a; }
#descend-btn { border-color: #7fd0ff; box-shadow: 0 0 10px rgba(127,208,255,0.35); }
#descend-btn.hidden { display: none; }
#return-btn:active { background: #2a2a3a; }
#return-btn { border-color: #7fd0ff; box-shadow: 0 0 10px rgba(127,208,255,0.35); }
#return-btn.hidden { display: none; }

/* ===== 盤面 (主役。横幅いっぱい、上部に固定) ===== */
#screen {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  padding: 8px 8px 4px;
  background: #060609;
}
#view {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  background: #000;
  border: 2px solid #3a3a50;
  border-radius: 6px;
  display: block;
  image-rendering: pixelated;
  touch-action: none; /* スワイプ移動をブラウザのスクロール/ズームに奪われないように */
  box-shadow: 0 0 0 1px #15151f, 0 6px 22px rgba(0, 0, 0, 0.65), inset 0 0 18px rgba(0,0,0,0.5);
}

/* ===== ログ (中間の余白を埋めて履歴を広く表示) ===== */
#hud { flex: 1 1 auto; min-height: 56px; display: flex; padding: 4px 10px; }
#log {
  flex: 1;
  overflow-y: auto;
  touch-action: pan-y;
  background: linear-gradient(180deg, #0a0a12, #07070d);
  border: 1px solid #34344a;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.5;
  -webkit-overflow-scrolling: touch;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.5);
}
#log .l-sys { color: var(--ink-dim); }
#log .l-hit { color: var(--accent-2); }
#log .l-dmg { color: var(--danger); }
#log .l-heal { color: var(--good); }
#log .l-win { color: var(--accent); font-weight: bold; }

/* ===== パーティ: 隊の札の見た目と配置は dungeon.css ===== */

/* ===== 操作系 ===== */
#controls { flex: 0 0 auto; padding: 6px 10px 8px; }

/* ===== 画面シェイク (被弾・クリティカル) ===== */
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-3px, 2px); }
  40% { transform: translate(3px, -2px); }
  60% { transform: translate(-2px, -1px); }
  80% { transform: translate(2px, 1px); }
}
@keyframes shake-strong {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-6px, 4px); }
  30% { transform: translate(6px, -4px); }
  45% { transform: translate(-5px, -3px); }
  60% { transform: translate(5px, 3px); }
  80% { transform: translate(-3px, 2px); }
}
#view.shake { animation: shake 0.32s ease; }
#view.shake-strong { animation: shake-strong 0.38s ease; }

/* ===== 階移動の暗転演出 (墨の帳: 約1.3秒・400ms 後はタップで飛ばせる) ===== */
.floor-trans {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  animation: ft-in 0.28s ease forwards;
  opacity: 0;
  cursor: default;
}
.floor-trans.skippable { cursor: pointer; }
.floor-trans.out { animation: ft-out 0.3s ease forwards; }
.floor-trans-elite { background: #0a0000; }
.floor-trans-elite .ft-floor { color: #d44040; text-shadow: 0 0 24px rgba(200, 40, 40, 0.7); }
.floor-trans-elite .ft-sub { color: #b05a50; }
@keyframes ft-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ft-out { from { opacity: 1; } to { opacity: 0; } }
.ft-floor {
  font-size: 44px;
  font-weight: bold;
  color: var(--accent);
  letter-spacing: 6px;
  text-shadow: 0 0 24px rgba(201, 162, 39, 0.6);
  animation: ft-rise 0.6s ease 0.12s both;
}
.ft-sub { font-size: 12px; color: var(--ink-dim); letter-spacing: 3px; animation: ft-rise 0.6s ease 0.24s both; }
/* 強敵・特別な階・奈落の変異の知らせ (2〜3行)。後から別の札は出さない */
.ft-lines { max-width: 340px; margin-top: 6px; display: flex; flex-direction: column; gap: 4px; animation: ft-rise 0.6s ease 0.36s both; }
.ft-line { font-size: 13px; line-height: 1.7; color: #d6cbb2; text-align: center; text-shadow: 0 1px 0 #000; }
.floor-trans-special .ft-floor { color: var(--ft-accent, var(--accent)); text-shadow: 0 0 26px color-mix(in srgb, var(--ft-accent, #c9a227) 55%, transparent), 0 2px 0 #000; }
.floor-trans-special .ft-line { color: #e6dbc2; }
.ft-tap { position: absolute; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 28px); text-align: center; font-size: 11px; letter-spacing: 0.3em; color: #6e6457; opacity: 0; transition: opacity 0.2s ease; }
.floor-trans.skippable .ft-tap { opacity: 0.8; }
.floor-trans.rm, .floor-trans.rm .ft-floor, .floor-trans.rm .ft-sub, .floor-trans.rm .ft-lines { animation-duration: 0.08s; animation-delay: 0s; }
@keyframes ft-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== トースト (レベルアップ等の祝福) ===== */
.toast {
  position: fixed;
  top: calc(var(--safe-top) + 52px);
  left: 50%;
  transform: translate(-50%, -16px);
  z-index: 85;
  background: linear-gradient(180deg, #2b2410, #1c1808);
  color: #ffd84a;
  border: 1px solid var(--accent);
  border-radius: 99px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font);
  white-space: nowrap;
  box-shadow: 0 4px 18px rgba(0,0,0,0.6), 0 0 22px rgba(201,162,39,0.35);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.btn {
  font-family: var(--font);
  font-size: 15px;
  color: var(--ink);
  background: linear-gradient(180deg, #262638, #1a1a28);
  border: 1px solid #3c3c54;
  border-radius: 9px;
  padding: 14px 8px;
  cursor: pointer;
  user-select: none;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* タップをダブルタップ判定/パンに奪われず確実にクリックさせる */
  box-shadow: 0 2px 5px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.07);
  transition: box-shadow 0.1s ease, transform 0.05s ease;
}
.btn:active {
  transform: translateY(1px);
  background: linear-gradient(180deg, #1c1c2a, #232336);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4), inset 0 1px 4px rgba(0,0,0,0.4);
}
.btn.primary { border-color: var(--accent); color: var(--accent); }
.btn.danger { border-color: var(--danger); color: #ff9a98; }
@media (hover: hover) {
  .btn:hover { background: #29293c; }
}

/* ===== 戦闘メニュー: コマンド板の見た目は dungeon.css ===== */

.hidden { display: none !important; }

canvas.spr { image-rendering: pixelated; display: block; width: var(--spr-size, auto); height: var(--spr-size, auto); }

/* (旧 #status-screen / .st-* の装備画面は隊 (ui-party.css) へ移った) */
.btn:disabled { opacity: 0.4; }

/* ===== アイテム入手演出 ===== */
#item-get {
  position: fixed;
  inset: 0;
  z-index: 76; /* 街(70)/ステータス(75)の上に出す (はじめからの確認等)。confirm-overlay(80)より下 */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 4, 10, 0.78);
  animation: ig-fade 0.25s ease;
}
@keyframes ig-fade { from { opacity: 0; } to { opacity: 1; } }
.ig-card {
  width: 100%;
  max-width: 340px;
  background: linear-gradient(180deg, #20202e, #14141d);
  border: 2px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 0 40px rgba(201, 162, 39, 0.4);
  padding: 16px 18px 18px;
  text-align: center;
  animation: ig-pop 0.4s cubic-bezier(0.2, 1.4, 0.5, 1);
}
@keyframes ig-pop { 0% { transform: scale(0.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.ig-banner { color: var(--accent); font-size: 14px; letter-spacing: 1px; margin-bottom: 8px; }
.ig-art {
  position: relative;
  display: inline-block;
  padding: 14px;
  margin: 4px auto 10px;
  background: radial-gradient(circle, rgba(201,162,39,0.25), transparent 70%);
}
@keyframes ig-float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.ig-spark {
  position: absolute;
  left: 50%; top: 50%;
  width: 6px; height: 6px;
  margin: -3px;
  background: #fff7cf;
  border-radius: 50%;
  transform: rotate(var(--a)) translateX(46px) scale(0);
  animation: ig-spark 1.4s ease-out infinite;
}
@keyframes ig-spark {
  0% { transform: rotate(var(--a)) translateX(20px) scale(0); opacity: 0; }
  40% { transform: rotate(var(--a)) translateX(52px) scale(1); opacity: 1; }
  100% { transform: rotate(var(--a)) translateX(66px) scale(0); opacity: 0; }
}
.ig-name { font-size: 19px; font-weight: bold; color: #fff; }
.ig-stat { font-size: 12px; color: var(--accent-2); margin-top: 4px; }
.ig-class { font-size: 11px; color: var(--ink-dim); margin-top: 4px; }
.ig-desc { font-size: 12px; color: var(--ink-dim); line-height: 1.6; margin: 10px 4px; }
.ig-who { font-size: 12px; color: var(--accent); margin-bottom: 12px; }
.ig-ok { width: 100%; margin-top: 16px; }

/* ===== ランクアップ専用ポップアップ ===== */

@keyframes ru-pulse { 0%,100% { transform: scale(1); filter: brightness(1); } 50% { transform: scale(1.06); filter: brightness(1.35); } }

@keyframes ru-spin { to { transform: rotate(360deg); } }

@keyframes ru-glow { 0%,100% { filter: drop-shadow(0 0 4px var(--accent)); } 50% { filter: drop-shadow(0 0 16px var(--accent)) brightness(1.15); } }

@keyframes ru-push { 0%,100% { transform: translateX(0); opacity: 0.7; } 50% { transform: translateX(4px); opacity: 1; } }

/* 中央カード内の選択肢ボタン */
.ig-choices { display: grid; gap: 8px; margin-top: 16px; }
.ig-choices .btn { width: 100%; }
.ig-card .ig-name { font-size: 16px; line-height: 1.5; }

/* 確認ダイアログ (ステータス画面より前面) */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 4, 10, 0.78);
  animation: ig-fade 0.2s ease;
}
.confirm-card { max-width: 300px; }

/* 名前入力フィールド */

/* 未生成タブ */
.tw-dolltab.pending { color: #aaa; font-style: italic; }

/* ===== スキル詳細ポップアップ / スキルチップ ===== */
.sk-mp { font-size: 12px; color: var(--accent-2); margin-top: 4px; }
.sk-lines { text-align: left; margin: 4px 4px 10px; }
.sk-line { font-size: 12px; color: var(--ink-dim); line-height: 1.7; }
.sk-chips { margin-top: 3px; }
.sk-chipl { font-size: 11px; color: var(--ink-dim); margin-right: 4px; }
.sk-chip {
  display: inline-block;
  padding: 1px 8px;
  margin: 2px 4px 2px 0;
  border: 1px solid #46466a;
  border-radius: 9px;
  background: #23233a;
  color: #cfd2ff;
  font-size: 11px;
  cursor: pointer;
}
.sk-chip:active { background: #33335a; }

/* タップ専用コントロール: スクロール領域内でもタップがパン/ダブルタップに奪われないようにする */
.sk-chip, .tw-small, .pc { touch-action: manipulation; }

/* ===== ヒント ===== */
#hint {
  flex: 0 0 auto;
  text-align: center;
  font-size: 10px;
  color: var(--ink-dim);
  padding: 4px 8px;
  border-top: 1px solid var(--border);
}

/* 低い画面ではヒントを隠してスペースを確保 */
@media (max-height: 680px) {
  #hint { display: none; }
  #log { height: 52px; }
}

/* 広い画面 (デスクトップ) では中央寄せのまま余白を持たせる */
@media (min-width: 560px) and (min-height: 720px) {
  #app { height: 100dvh; }
}

/* ===== 街 (拠点) 画面 ===== */
#town-screen {
  position: fixed;
  inset: 0;
  z-index: 70;
  background:
    radial-gradient(120% 80% at 50% -10%, #2a1d2e 0%, rgba(0,0,0,0) 55%),
    linear-gradient(170deg, #14101a, #07060b 65%);
  display: flex;
  flex-direction: column;
  width: min(100%, 520px);
  max-width: 520px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 8px) 12px calc(var(--safe-bottom) + 14px);
  overflow-y: auto;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  color: var(--ink);
}

/* 縦スクロール画面 (街/ステータス/設定) は flex 縦積みのため、子の縮小を禁じる。
   overflow を持つ子 (層域アコーディオン .tw-band や図鑑タブ .cdx-tabs) は
   flex の自動最小サイズが 0 になり、あふれた高さを一身に吸収して潰れる —
   リストが途中で切れた上に全体が画面内に収まってスクロール自体が死ぬ。 */
#town-screen > *{ flex-shrink: 0; }

/* 共通ヘッダ */
.tw-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tw-back {
  min-height: 34px; padding: 6px 10px; font-size: 12px;
  background: #1b1426; border: 1px solid #46315a; border-radius: 6px; color: #d9c7ee;
}
.tw-back.ghost { visibility: hidden; }
.tw-title { flex: 1; text-align: center; font-size: 17px; font-weight: bold; color: #efe2ff; letter-spacing: 1px; text-shadow: 0 0 10px rgba(150,110,200,0.4); }

/* 施設の札 (宝物庫の蒐集品などに残る旧来の札。広場の札は town.css の .tw-plate) */
.tw-fac {
  background: linear-gradient(180deg, #1d1628, #140f1d);
  border: 1px solid #3c2c52; border-radius: 10px;
  padding: 12px 10px; text-align: center; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.05);
  transition: transform 0.05s ease, box-shadow 0.1s ease;
}
.tw-fac:active { transform: translateY(1px); }
@media (hover: hover) { .tw-fac:hover { border-color: #6a4d90; box-shadow: 0 0 0 1px #6a4d90, 0 2px 10px rgba(0,0,0,0.55); } }
.tw-faci { font-size: 26px; line-height: 1; }
.tw-facn { font-size: 13px; font-weight: bold; color: #ece0ff; margin-top: 6px; }
.tw-facd { font-size: 10px; color: #8a7ca0; margin-top: 3px; }

/* 潜るボタン: スクロール位置に関わらず画面下部に固定表示 */
.tw-divebar {
  position: sticky;
  bottom: calc(-1 * (var(--safe-bottom) + 14px)); /* 親のpadding-bottom分まで沈めて画面端に密着 */
  z-index: 5;
  margin: 14px -12px calc(-1 * (var(--safe-bottom) + 14px));
  padding: 10px 12px calc(var(--safe-bottom) + 10px);
  background: linear-gradient(180deg, rgba(7,6,11,0), #07060b 35%);
}
.tw-dive { width: 100%; min-height: 54px; font-size: 16px; }

/* 迷宮選択: 10迷宮ごとの層域アコーディオン */
.tw-band { border: 1px solid #34254a; border-radius: 8px; background: #140d1e; margin-bottom: 8px; overflow: hidden; }
.tw-bandh { padding: 10px 11px; font-size: 12px; color: #c8b6e0; letter-spacing: 0.5px; cursor: pointer; list-style: none; user-select: none; -webkit-user-select: none; }
summary.tw-bandh::-webkit-details-marker { display: none; }
summary.tw-bandh::before { content: "▸ "; color: #8a63b8; }
.tw-band[open] > summary.tw-bandh::before { content: "▾ "; }
.tw-band .tw-mlist { padding: 0 8px 8px; }

/* 施設バッジ (王宮の勅命など) */
.tw-facb { font-size: 10px; color: #ffd84a; margin-top: 4px; font-weight: bold; text-shadow: 0 0 6px rgba(255,216,74,0.5); }

/* 宝物庫: 奉納台帳のスロット */
.tw-tslots { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; margin: 6px 0; }
.tw-tslot {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  background: #100b18; border: 1px solid #2c2040; border-radius: 6px; overflow: hidden;
}
.tw-tslot.got { border-color: #6a4d90; background: #1a1230; box-shadow: inset 0 0 6px rgba(150,110,220,0.3); }
.tw-tslot canvas { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.tw-tlock { font-size: 12px; color: #4a3f5e; }
@media (max-width: 380px) { .tw-tslots { grid-template-columns: repeat(5, 1fr); } }

/* ロスター概要 */
.tw-roster { margin-top: 14px; }
.tw-h { font-size: 12px; color: #b49fd2; letter-spacing: 1px; margin: 10px 0 6px; border-left: 3px solid #6a4d90; padding-left: 7px; }
.tw-subh { font-size: 11px; font-weight: bold; color: #e3c98a; margin: 8px 0 4px; padding: 3px 7px; background: #1d1630; border-left: 3px solid #c9a227; border-radius: 0 4px 4px 0; }
.tw-rlist { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.tw-chip, .tw-mrow {
  display: flex; align-items: center; gap: 8px;
  background: #170f22; border: 1px solid #34254a; border-radius: 8px; padding: 6px 8px;
}
.tw-chip.dead, .tw-mrow.dead { opacity: 0.5; filter: grayscale(0.6); }
.tw-chips { flex: 0 0 auto; display: flex; }
.tw-chipi { flex: 1; min-width: 0; }
.tw-chipn { font-size: 12px; font-weight: bold; color: #ede2ff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tw-chipc { font-size: 10px; color: #9685ad; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tw-chiphp { font-size: 10px; color: #c0a0a0; white-space: nowrap; }
.tw-empty { font-size: 11px; color: #7a6c90; padding: 8px; text-align: center; grid-column: 1 / -1; }

/* 各施設共通 */
.tw-lead { font-size: 12px; color: #b6a6cc; line-height: 1.6; margin-bottom: 10px; }
.tw-note { font-size: 10px; color: #80708f; margin-top: 8px; text-align: center; }

/* 人業の館 / 神殿 / 道具屋 のリスト */
.tw-mlist, .tw-shoplist { display: flex; flex-direction: column; gap: 7px; }
.tw-mrow { gap: 8px; }
/* 編成の前衛/後衛の区切りと並び替えボタン */
.tw-rowdiv { font-size: 10px; letter-spacing: 1px; padding: 3px 2px 0; }
.tw-rowdiv.front { color: #e0b06a; }
.tw-rowdiv.back { color: #8fb4dc; }
.tw-move { flex: 0 0 auto; display: flex; gap: 4px; }
.tw-moveb { min-width: 30px; min-height: 30px; font-size: 12px; background: #221833; border: 1px solid #4a3568; border-radius: 6px; color: #e0d2f4; }
.tw-shoprow { display: flex; align-items: center; gap: 9px; background: #170f22; border: 1px solid #34254a; border-radius: 8px; padding: 7px 9px; }
.tw-small { min-height: 34px; padding: 6px 10px; font-size: 11px; background: #221833; border: 1px solid #4a3568; border-radius: 6px; color: #e0d2f4; white-space: nowrap; }
.tw-small.dim { opacity: 0.45; } /* MP不足の野営呪文: 押せるが理由をトーストで知らせる */
.tw-small:disabled { opacity: 0.4; }
.tw-small.danger { border-color: var(--danger); color: #ff9a98; }
.tw-add { margin-top: 10px; min-height: 46px; }

/* 魂封じの祭壇 */
.tw-dolltabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.tw-dolltab { min-height: 34px; padding: 6px 12px; font-size: 12px; background: transparent; border: 1px solid #3c2c52; border-radius: 6px; color: #b49fd2; }
.tw-dolltab.active { background: #221833; border-color: #8a63b8; color: #f0e2ff; box-shadow: 0 0 0 1px #8a63b8; }

.tw-summary { border: 1px solid #34254a; border-left-width: 4px; border-radius: 8px; padding: 9px 11px; margin-bottom: 12px; background: #140d1e; }
.tw-summary:hover { background: #1a1128; }
.tw-sumc { font-size: 15px; font-weight: bold; color: #f0e6ff; }
.tw-sumt { font-size: 11px; color: #b49fd2; margin: 3px 0; }
.tw-sumst { font-size: 11px; color: #c8bcda; letter-spacing: 0.5px; }
.tw-sumsk { font-size: 11px; color: #8fd6bd; margin-top: 3px; }
.tw-sumhint { font-size: 10px; color: #7a6aaa; margin-top: 5px; letter-spacing: 0.5px; }

.tw-parts { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.tw-part {
  background: #15101f; border: 1px solid #34254a; border-radius: 8px;
  padding: 6px 3px; text-align: center; cursor: pointer; min-width: 0;
}
.tw-part.sel { border-color: #b07be0; box-shadow: 0 0 0 1px #b07be0, 0 0 12px rgba(176,123,224,0.4); }
.tw-partl { font-size: 10px; color: #9685ad; }
.tw-partorb { display: flex; align-items: center; justify-content: center; height: 38px; }
.tw-partempty { font-size: 10px; color: #5a4c70; }
.tw-parts2 { font-size: 9px; color: #c0b2d6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tw-soullist { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.tw-soulrow { display: flex; align-items: center; gap: 9px; background: #170f22; border: 1px solid #34254a; border-radius: 8px; padding: 7px 10px; cursor: pointer; }
.tw-soulrow:active { background: #20162e; }
.tw-souln { font-size: 12px; color: #e6dbf6; }
.tw-un { margin: 8px 0; min-height: 40px; }

/* 宿屋 */
.tw-innbox { text-align: center; padding: 14px; background: #140d1e; border: 1px solid #34254a; border-radius: 10px; margin-bottom: 12px; }
.tw-innc { font-size: 18px; color: var(--accent); font-weight: bold; }

/* 魂タブ (ステータス画面) */

/* ===== 酒場: クエスト掲示板 ===== */
.tw-quest {
  display: flex; align-items: center; gap: 9px;
  background: #170f22; border: 1px solid #34254a; border-left: 4px solid #6a4d90;
  border-radius: 8px; padding: 8px 10px;
}
.tw-quest.done { border-left-color: #46c08f; box-shadow: 0 0 10px rgba(70,192,143,0.25); }
.tw-small.primary { border-color: var(--accent); color: #ffd84a; }

/* ===== 王宮: 勅命 (メインクエスト) の大ボタン ===== */
.tw-msq {
  display: block; width: 100%; min-height: 64px;
  font-size: 16px; font-weight: bold; letter-spacing: 1px;
  color: #1a1206;
  background: linear-gradient(180deg, #ffe98a, #c9a227);
  border: 2px solid #ffe98a; border-radius: 12px;
  text-shadow: 0 1px 0 rgba(255,255,255,0.35);
  animation: msq-glow 1.6s ease-in-out infinite alternate;
}
.tw-msq:active { background: linear-gradient(180deg, #e3c455, #ad8a1e); transform: translateY(1px); }
@media (hover: hover) { .tw-msq:hover { background: linear-gradient(180deg, #fff0a6, #d4ad33); } }
@keyframes msq-glow {
  from { box-shadow: 0 0 10px rgba(255, 216, 74, 0.35), 0 3px 10px rgba(0,0,0,0.5); }
  to   { box-shadow: 0 0 26px rgba(255, 216, 74, 0.75), 0 3px 10px rgba(0,0,0,0.5); }
}

/* ===== 王宮: 勲章の間 (実績) ===== */

/* ===== 王宮: ストーリーイベント ===== */
/* ===== 王の語り (勅命・報告) ===== */
.story-overlay { background: radial-gradient(ellipse at 50% 30%, rgba(60,40,10,0.55), rgba(0,0,0,0.88) 70%); }
.story-card {
  max-width: 420px; text-align: left; position: relative;
  border-color: #c9a227 !important;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(201,162,39,0.14), rgba(0,0,0,0) 60%),
    linear-gradient(180deg, #221b14, #15110e 60%, #100d0b);
  box-shadow: 0 0 50px rgba(201,162,39,0.33), inset 0 0 0 1px rgba(255,216,74,0.12), inset 0 0 30px rgba(0,0,0,0.6) !important;
  animation: storyCardIn 0.45s cubic-bezier(.2,.9,.3,1.2) both;
}
@keyframes storyCardIn { from { opacity: 0; transform: translateY(14px) scale(0.96); } to { opacity: 1; transform: none; } }
.story-head { display: flex; align-items: center; gap: 12px; padding-bottom: 10px; margin-bottom: 6px; border-bottom: 1px solid rgba(201,162,39,0.35); }
.story-portrait {
  flex: 0 0 auto; position: relative; width: 90px; height: 90px; border-radius: 8px;
  background: radial-gradient(circle at 50% 35%, #3a2a14, #160f08 75%);
  border: 2px solid #c9a227; box-shadow: 0 0 14px rgba(201,162,39,0.4), inset 0 0 10px rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.story-portrait canvas { width: 84px; height: 84px; image-rendering: pixelated; }
.story-who {
  position: absolute; bottom: -1px; left: 50%; transform: translateX(-50%);
  font-size: 9px; color: #ffd84a; background: rgba(10,8,4,0.85); padding: 0 6px; border-radius: 6px 6px 0 0;
  letter-spacing: 2px; white-space: nowrap;
}
.story-htxt { min-width: 0; }
.story-kicker { font-size: 10px; color: #b8963a; letter-spacing: 3px; }
.story-title { font-size: 16px; font-weight: bold; color: #ffd84a; line-height: 1.4; text-shadow: 0 0 10px rgba(255,216,74,0.35); }
.story-body { padding: 2px 2px 0; }
.story-line { font-size: 13px; color: #e8dfc8; line-height: 1.8; margin: 7px 0; text-align: left; opacity: 0; animation: storyLineIn 0.6s ease forwards; }
.story-line.k-narr { color: #a9a08e; font-style: italic; font-size: 12px; }
.story-line.k-minister { color: #b9c4d8; border-left: 2px solid #5a6a88; padding-left: 8px; }
.story-line.k-decree { color: #ffd84a; font-weight: bold; text-align: center; margin-top: 12px; text-shadow: 0 0 8px rgba(255,216,74,0.3); }
.story-reward { font-size: 12px; color: var(--accent); margin-top: 10px; font-weight: bold; text-align: center; opacity: 0; animation: storyLineIn 0.6s ease forwards; }
.story-ok { opacity: 0; animation: storyLineIn 0.5s ease forwards; }
.story-card:not(.revealed) .story-ok { pointer-events: none; }
.story-card.revealed .story-line, .story-card.revealed .story-reward, .story-card.revealed .story-ok { animation: none; opacity: 1; }
.story-tip { font-size: 10px; color: #7a6e58; text-align: center; margin-top: 6px; transition: opacity 0.3s; }
.story-card.revealed .story-tip { opacity: 0; }
@keyframes storyLineIn { from { opacity: 0; transform: translateY(6px); filter: blur(2px); } to { opacity: 1; transform: none; filter: none; } }
@media (prefers-reduced-motion: reduce) {
  .story-card, .story-line, .story-reward, .story-ok { animation: none !important; opacity: 1 !important; }
}

/* ===== 図鑑 ===== */

/* 図鑑: 詳細オーバーレイ */

/* ===== 魂図鑑/職業図鑑 (王宮書庫) ===== */

/* 画面フラッシュ (ボス撃破/伝説の魂/呪い) */
.screen-flash { position: fixed; inset: 0; z-index: 300; pointer-events: none; opacity: 0.55; transition: opacity 0.6s ease-out; }
.screen-flash.out { opacity: 0; }

/* ===== 記憶を宿した魂 (歴戦) ===== */

/* ===== 酒場の噂話 ===== */
.tw-rumor {
  background: linear-gradient(180deg, #1a1422, #120d18);
  border: 1px solid #4a3568; border-left: 4px solid #8a63b8;
  border-radius: 8px; padding: 10px 12px;
}
.tw-rumors { font-size: 11px; color: #b49fd2; margin-bottom: 5px; }
.tw-rumort { font-size: 13px; color: #ece0ff; line-height: 1.6; }

/* ===== ウィザードリィ風 能力値 ===== */

/* ===== 通貨表示 (街ヘッダ) ===== */
.tw-cur { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; font-size: 11px; font-weight: bold; white-space: nowrap; }

/* 複数行のリード文 */
.tw-lead { white-space: pre-line; }

/* 魂を鍛える */
.tw-trainbox { background: #140d1e; border: 1px solid #34254a; border-radius: 8px; padding: 9px 11px; margin-bottom: 8px; }
.tw-trainn { font-size: 12px; color: #ece0ff; margin-bottom: 4px; }
.tw-souldn { font-size: 10px; color: #7ecfaa; margin: 3px 0 6px; letter-spacing: 0.5px; }

/* 祠の Red Soul 残高 */
.tw-innc.red { color: #ff5b6e; }

/* ===== 魂のランク/個別ステータス表示 ===== */
.tw-soulrow.rare { box-shadow: 0 0 10px rgba(160,140,255,0.25); }
.tw-soulst{ font-size: 10px; color: #9685ad; margin-top: 2px; }

/* ===== 魂の詳細パネル (タップで開閉) ===== */

/* ===== 復活待ち表示 ===== */

/* ===== 迷宮選択 ===== */
.tw-dungeon {
  display: flex; align-items: center; gap: 9px;
  background: #170f22; border: 1px solid #34254a; border-left: 4px solid #4a3568;
  border-radius: 8px; padding: 8px 11px; cursor: pointer;
}
.tw-dungeon.sel { border-left-color: #8a63b8; box-shadow: 0 0 0 1px #8a63b8; background: #20162e; }
.tw-dungeon.locked { opacity: 0.5; cursor: default; }
.tw-dungeon.cleared { border-left-color: #8a7227; }
.tw-dunhelp { font-size: 10px; color: #8a7ca0; margin: -2px 0 8px; line-height: 1.5; }
/* 踏破状態バッジ (★踏破済 / ❗勅命 / 未踏破) */
.tw-dunst {
  flex: 0 0 auto; font-size: 10px; font-weight: bold; white-space: nowrap;
  padding: 3px 8px; border-radius: 99px; border: 1px solid #4a3568; color: #9685ad;
}
.tw-dunst.done { color: #ffd84a; border-color: #8a7227; background: rgba(201, 162, 39, 0.08); }
.tw-dunst.quest { color: #ff9a98; border-color: #7a3a48; background: rgba(228, 85, 79, 0.1); }

/* ===== 図鑑の分類タブと一覧 (旧商店から残る共用のクラス。商会は ui-shop.css) ===== */
.shop-tabs { flex: 0 0 auto; flex-wrap: wrap; }
.shop-stock {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 7px;
  padding: 2px 0 8px;
}

/* モーダルが背の高い内容でも収まるように (スクロールはモーダル内のみ) */
.confirm-overlay .ig-card { max-height: 88vh; overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; }

/* ===== 設定画面 (⚙) ===== */

/* ===== 戦績 ===== */
.tw-records { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tw-recrow { display: flex; justify-content: space-between; background: #140d1e; border: 1px solid #34254a; border-radius: 6px; padding: 6px 10px; }
.tw-recl { font-size: 11px; color: #9685ad; }
.tw-recv { font-size: 13px; color: #ffd84a; font-weight: bold; }

/* 装備可否チップ (キャラアイコン + 名前 + ○/×) */
.eq-pchips { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin-top: 5px; }
.eq-pchip { display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px 2px 3px; border-radius: 7px; border: 1px solid #34344a; font-size: 11px; line-height: 1; }
.eq-pchip.ok { border-color: #3a7a5e; background: rgba(70,192,143,0.12); color: #cfeede; }
.eq-pchip.ng { border-color: #6a3a3a; background: rgba(150,70,70,0.10); color: #b58a8a; opacity: 0.72; }
.eq-pchip-ic { display: flex; }
.eq-pchip-nm { font-weight: bold; }
.eq-pchip-mk { font-weight: bold; }
.eq-pchip.ok .eq-pchip-mk { color: #5fe0a0; }
.eq-pchip.ng .eq-pchip-mk { color: #ff6b6b; }

/* ===== 装備候補チューザー ===== */

.eq-cand { gap: 6px; }

.eq-cur { border-color: #6b8cff; background: rgba(107,140,255,0.08); }
.eq-cur .eq-cn { color: #aec2ff; }
.eq-ci { flex: 0 0 auto; display: flex; }
.eq-ct { display: flex; flex-direction: column; min-width: 0; }
.eq-cn { font-size: 13px; color: #e7e3d4; }
.eq-cs { font-size: 10px; color: #8fd6bd; }
.eq-ccls { font-size: 10px; color: #c9a227; }
.eq-cdesc { font-size: 10px; color: var(--ink-dim); white-space: normal; line-height: 1.4; margin-top: 2px; }
.eq-cd { font-size: 10px; margin-top: 2px; display: flex; flex-wrap: wrap; gap: 3px 8px; align-items: baseline; }
.eq-cd-lab { color: var(--ink-dim); }
.eq-cd-seg.up { color: var(--good); }
.eq-cd-seg.down { color: var(--danger); }
.eq-cd-seg.elem { color: var(--accent); }
.eq-cd-same { color: var(--ink-dim); }

/* 戦績シェア */

/* 街の広場 (夜景・目標・施設の札・編成・迷宮の門) は town.css */

/* ===== 縦画面専用: スマホを横向きにした時の案内 =====
   向きのロック (manifest の orientation / screen.orientation.lock) が効かない環境
   (iOS Safari・ブラウザのタブ等) 向け。端末自体が横向きかつ背の低いタッチ画面だけに出し、
   キーボードで表示領域の高さが縮んでも縦向きでは出さない。
   PC やタブレットの横画面は従来どおり遊べるようにする。 */
#rotate-guard { display: none; }
@media (max-height: 540px) and (hover: none) and (pointer: coarse) {
  html.device-landscape #rotate-guard {
    position: fixed; inset: 0; z-index: 9998;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
    padding: 24px; text-align: center;
    background: radial-gradient(ellipse at 50% 40%, #1a1626 0%, #0b0b12 60%, #050509 100%);
    color: var(--ink);
    font-family: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", serif;
    touch-action: none;
  }
  #rotate-guard .rg-phone {
    position: relative; width: 34px; height: 58px;
    border: 3px solid var(--accent); border-radius: 7px;
    box-shadow: 0 0 18px rgba(201, 162, 39, 0.35);
    animation: rg-turn 2.4s ease-in-out infinite;
  }
  #rotate-guard .rg-phone span {
    position: absolute; left: 50%; bottom: 4px; width: 8px; height: 3px;
    margin-left: -4px; border-radius: 2px; background: var(--accent);
  }
  #rotate-guard .rg-title { font-size: 17px; font-weight: 700; color: #f0dca0; letter-spacing: 0.08em; }
  #rotate-guard .rg-sub { font-size: 12px; color: var(--ink-dim); letter-spacing: 0.06em; }
  /* 案内が出ている間は下のゲーム画面に触れさせない */
  html.device-landscape #app, html.device-landscape #ui-layer { visibility: hidden; }
}
@keyframes rg-turn {
  0%, 20% { transform: rotate(-90deg); }
  55%, 100% { transform: rotate(0deg); }
}
@media (prefers-reduced-motion: reduce) {
  #rotate-guard .rg-phone { animation: none; }
}

/* 規約は本文だけスクロールでき、狭い画面でも操作を隠さない。 */
.legal-dialog { color: #e4e1d5; background: #171d19; border: 1px solid #798574; border-radius: 8px; width: min(640px, 90vw); max-height: 80dvh; padding: 24px; overflow-y: auto; line-height: 1.8; }
.legal-dialog::backdrop { background: #000b; }
.legal-dialog a { color: #c3d6bf; text-decoration: underline; }
.legal-dialog button { position: sticky; bottom: 0; padding: 12px 24px; background: #344b3b; color: #fff; border: 1px solid #8da08e; border-radius: 6px; }
.cloud-controls .cloud-consent { display: flex; align-items: start; gap: 12px; line-height: 1.6; }
.cloud-controls .cloud-consent input { width: 22px; min-width: 22px; height: 22px; margin: 3px 0; }
.cloud-controls form { display: grid; gap: 12px; }
.cloud-panel { max-height: 90dvh; overflow-y: auto; }

/* 装備の世代 (docs/item-generations.md 12-2): 絵に縁取りの層と左上の世代の数字を重ねる (src/sprites.js spriteCanvas) */
.spr-gen { position: relative; display: inline-block; line-height: 0; vertical-align: middle; }
.spr-gen::after { content: ""; position: absolute; inset: 0; border-radius: 3px; box-shadow: inset 0 0 0 1px var(--gen-c), inset 0 0 5px var(--gen-c); pointer-events: none; opacity: 0.9; }
.spr-gen-n { position: absolute; left: 0; top: 0; max-width: 100%; overflow: hidden; padding: 1px 3px; font: 800 9px/1 var(--font, serif); letter-spacing: 0; color: #120d14; background: var(--gen-c); border-radius: 0 0 3px 0; white-space: nowrap; pointer-events: none; }
.it-gen-chip { display: inline-block; padding: 0 6px; font-size: 10.5px; font-weight: 800; letter-spacing: 0.06em; color: #ff9ae2; border: 1px solid currentColor; border-radius: 2px; background: rgba(0,0,0,0.35); white-space: nowrap; }
