:root {
  --bg: #1e1e2e;
  --bg-panel: #232336;
  --bg-elevated: #2b2b40;
  --fg: #e6e6f0;
  --fg-dim: #9ea0b3;
  --accent: #7aa2f7;
  --accent-hover: #9bbbff;
  --border: #3a3a52;
  /* 通常の枠より一段はっきり見せたいとき用（実行トグルなど） */
  --border-strong: #6e6e90;
  --danger: #f7768e;
}

* {
  box-sizing: border-box;
}

/* 表示／非表示の共通フェード（0.3秒） fade.js と対で使用する */
.fade-dialog {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.fade-dialog.fade-visible {
  opacity: 1;
}

.fade-dialog::backdrop {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.fade-dialog.fade-visible::backdrop {
  opacity: 1;
}

.fade-element {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.fade-element.fade-visible {
  opacity: 1;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans",
    "Noto Sans CJK JP", "Yu Gothic UI", sans-serif;
  font-size: 14px;
}

body {
  display: grid;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  /* フッターは通常1行ぶん。開くと10行ぶんの履歴が加わる（4.6節） */
  --footer-bar-h: 32px;
  --footer-line-h: 18px;
  /* 10行ぶん ＋ 上下の余白8px ＋ 履歴の枠線1px ＋ フッターの枠線1px。
     枠線と余白を足し忘れると、10行目が数px切れて見える。 */
  --footer-log-h: calc(var(--footer-line-h) * 10 + 10px);
  grid-template-rows: 48px 1fr var(--footer-bar-h);
  grid-template-columns: 440px 1fr;
}

body.footer-expanded {
  grid-template-rows: 48px 1fr calc(var(--footer-bar-h) + var(--footer-log-h));
}

/* ゲーム表示エリアにフォーカスがある間、キー操作はゲームへ送られる。
   どこへ入力が向かっているかが分かるよう、枠の色で示す。 */
.game-canvas:focus {
  outline: none;
  border-color: var(--accent);
}

/* 読み込み中の中央インジケーター（B案） */
.app-loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(30, 30, 46, 0.62);
  backdrop-filter: blur(2px);
}

.app-loading.is-visible {
  display: flex;
}

.app-loading-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: arcadeer-spin 0.9s linear infinite;
}

.app-loading-text {
  margin: 0;
  font-size: 13px;
  color: var(--fg-dim);
}

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

/* 左ペインのスケルトン表示（A案） */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, #383850 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: arcadeer-shimmer 1.3s ease-in-out infinite;
  border-radius: 6px;
}

@keyframes arcadeer-shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

.skeleton-project {
  height: 22px;
  width: 60%;
  margin-bottom: 8px;
}

.skeleton-tabbar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.skeleton-tab {
  width: 34px;
  height: 34px;
}

.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 2px;
}

.skeleton-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  min-height: 0;
  overflow: hidden;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.skeleton-thumb {
  flex: 1 1 auto;
  min-height: 0;
  width: auto;
  height: auto;
  max-width: 100%;
  aspect-ratio: 1;
}

.skeleton-name {
  height: 6px;
  width: 70%;
  align-self: center;
}

/* 動きを減らす設定では点滅させない */
@media (prefers-reduced-motion: reduce) {
  .app-loading-spinner,
  .skeleton {
    animation: none;
  }
}

.ide-header {
  grid-area: header;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
  cursor: pointer;
}

/* 起動バナー（banner.png、1176×196）を縮めて出す。幅は縦横比から決まる（約 192px） */
.header-logo-banner {
  height: 32px;
  width: auto;
  display: block;
}

/* ヘッダー右側のアイコンボタン群 */
.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 20px;
  padding-left: 20px;
  border-left: 1px solid var(--border);
}

.header-icon-btn {
  position: relative;
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--fg-dim);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.header-icon-btn:hover:not(:disabled) {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--accent);
}

.header-icon-btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  color: var(--accent);
}

.header-icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 実行トグルは常に枠を出して、押せる場所だと分かるようにする */
.game-toggle-btn {
  border-color: var(--border-strong);
  border-radius: 6px;
}

.game-toggle-btn:hover:not(:disabled) {
  border-color: var(--accent);
}

/* 押せないときは控えめに戻す */
.game-toggle-btn:disabled {
  border-color: var(--border);
}

/* ゲーム実行中のトグルボタン（停止アイコン表示中） */
.header-icon-btn.game-running {
  color: var(--danger);
}

.header-icon-btn.game-running,
.header-icon-btn.game-running:hover:not(:disabled) {
  color: var(--danger);
  border-color: var(--danger);
}

/* ヘッダー右端に寄せるボタン（リファレンス以降） */
.header-icon-btn-end {
  margin-left: auto;
}

/* 開いている間は、押されていることが分かるようにする */
.reference-btn[aria-expanded="true"] {
  color: var(--accent);
  border-color: var(--accent);
}

/* 歯車は文字グリフのため、線画アイコンより大きめに描く
   ヘッダー高48pxに収まる範囲でボタン枠ごと広げる */
.settings-btn {
  width: 42px;
  height: 42px;
  font-size: 30px;
  line-height: 1;
}

/* ツールチップ: data-tooltip の文字列をボタン下に 0.3秒フェードで表示する */
.header-icon-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: var(--bg-elevated);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 10;
}

/* 右端に並ぶボタンは、ツールチップを中央揃えにすると画面からはみ出す。
   ボタンの右端に合わせて内側へ収める。
   余白（margin-left: auto）とは別の指定にしてあるのは、
   右端のまとまりが複数のボタンになっても効くようにするため。 */
.tooltip-right::after {
  left: auto;
  right: 0;
  transform: none;
}

.header-icon-btn:hover:not(:disabled)::after,
.header-icon-btn:focus-visible::after {
  opacity: 1;
}

.ide-sidebar {
  grid-area: sidebar;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* タブバーと最下段ボタンを固定し、一覧だけをスクロールさせる */
  overflow: hidden;
}

.sidebar-btn {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-elevated);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  transition: background 0.15s;
}

.sidebar-btn:hover:not(:disabled) {
  background: var(--accent);
  color: #fff;
}

.sidebar-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 左ペイン（プロジェクトを開いた後） */
/* 左に「タブ群」、右端に「＋」を置く。両端へ確実に寄せる */
.pane-tabbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.pane-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.pane-tab {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: transparent;
  color: var(--fg-dim);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

/* タブ名はツールチップで示す（0.3秒フェード。左端から出してペイン内へ収める） */
.pane-tab::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  padding: 4px 8px;
  background: var(--bg-elevated);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 10;
}

.pane-tab:hover::after,
.pane-tab:focus-visible::after {
  opacity: 1;
}

.pane-tab:hover {
  color: var(--fg);
  background: var(--bg-elevated);
}

.pane-tab-active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.pane-tab-active:hover {
  color: #fff;
  background: var(--accent-hover);
}

.pane-tab:focus-visible {
  outline: none;
  border-color: var(--accent-hover);
}

/* 選択中タブの一覧。ここだけがスクロールする */
.pane-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.pane-empty {
  margin: 0;
  padding: 4px;
  font-size: 12px;
  color: var(--fg-dim);
}

.pane-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pane-item {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: default;
  transition: background 0.15s;
}

.pane-item:hover {
  background: var(--bg-elevated);
}

/* オブジェクト一覧: 正方形アイコンを横3列で並べる */
.pane-object-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 2px;
  /* 行の高さに合わせてカードが縦へ引き伸ばされないようにする */
  align-items: start;
  align-content: start;
}

.object-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* ファイル名まで含めてカード全体を正方形に保つ。
     グリッド項目の自動最小サイズ（min-height: auto）が内容に合わせて
     カードを縦へ広げてしまうため、min-height と overflow で抑え込む。 */
  aspect-ratio: 1;
  min-height: 0;
  overflow: hidden;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.object-card:hover {
  border-color: var(--accent);
}

.object-card:focus-visible {
  outline: none;
  border-color: var(--accent-hover);
}

/* アセットのカード（画像タブ）。クリック操作はまだ無いため既定カーソル */
.asset-card {
  cursor: default;
}

.asset-card:hover {
  border-color: var(--border);
}

/* ホバー中に回転表示するモデル。静止画サムネイルの上に重ねる */
.model-card[data-url] {
  cursor: pointer;
}

.model-hover-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* 回転表示中は、下に残る静止画サムネイルを隠す */
.object-card-thumb.model-hover-active img {
  visibility: hidden;
}

/* サムネイル枠。将来ここへ画像・3Dモデルのプレビューを描画する */
.object-card-thumb {
  position: relative;
  /* 名前の実際の高さ（ブラウザの最小フォントサイズ設定で変わる）に関わらず
     カードが正方形を保つよう、サムネイルが残りの高さを受け持つ。 */
  flex: 1 1 auto;
  min-height: 0;
  width: auto;
  height: auto;
  max-width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 6px;
  overflow: hidden;
  color: var(--fg-dim);
}

.object-card-thumb img,
.object-card-thumb canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* 音声プレビューの再生ボタン */
.audio-play-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  padding: 0;
  background: var(--bg-elevated);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.audio-play-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-hover);
}

.audio-play-btn:focus-visible {
  outline: none;
  border-color: var(--accent-hover);
}

/* 読み込みが終わるまでは押せない */
.audio-play-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* 再生中 */
.audio-play-btn.audio-playing {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* 透過画像が背景と同化しないよう、市松模様を敷く */
.asset-card .object-card-thumb {
  background-color: #2a2a3c;
  background-image:
    linear-gradient(45deg, #22222f 25%, transparent 25%),
    linear-gradient(-45deg, #22222f 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #22222f 75%),
    linear-gradient(-45deg, transparent 75%, #22222f 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}

.object-card-name {
  font-size: 6px;
  line-height: 1.25;
  /* 高さは内容なりに確保し、縮ませない（残りをサムネイルが受け持つ） */
  flex: 0 0 auto;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* サムネイル一覧の先頭に置く「新規追加」カード */
.add-card {
  cursor: pointer;
  background: transparent;
  border-style: dashed;
  color: var(--fg-dim);
}

.add-card:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.add-card:focus-visible {
  outline: none;
  border-color: var(--accent-hover);
  color: var(--accent);
}

/* 追加カードのサムネイル枠は、市松模様などを敷かず「＋」だけを見せる。
   「＋」は他のカードのサムネイルと同じく、枠の中央に置く
   （下に「新規追加」の文字が入るため、カード全体の中央にはしない） */
.add-card .object-card-thumb {
  background: transparent;
  color: inherit;
}

/* 「新規追加」の文字。ファイル名より少し大きくして押せることを分かりやすくする */
.add-card-name {
  font-size: 8px;
  font-weight: 600;
}

/* 並べ替え中のカード（掴んでいる本体。周りは実際に動いて結果を見せる） */
.object-card.dragging {
  opacity: 0.4;
  border-style: dashed;
  /* 掴んでいるカード自身がドラッグ先の判定を奪わないようにする
     （奪うと、その先のカードへ重ねても並べ替えが進まなくなる） */
  pointer-events: none;
}

/* ゲームの起点となるオブジェクト（削除不可）の目印。
   枠は「編集中」「ホバー」に使うため、ここでは色を変えず名前だけを強調する。
   常時アクセント枠が付いていると、選択されているように見えてしまうため。 */
.object-card-entry .object-card-name {
  color: var(--accent);
  font-weight: 700;
}

.object-card-entry.object-card-active .object-card-name {
  color: #fff;
}

/* 編集中のオブジェクト */
.object-card-active,
.object-card-active:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.object-card-active .object-card-thumb {
  color: #fff;
}

/* 設定ダイアログのセレクトボックス */
.dialog-select {
  padding: 8px 10px;
  background: var(--bg-elevated);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
}

.dialog-select:focus {
  outline: none;
  border-color: var(--accent);
}

/* 設定ダイアログのスライダー（文字サイズ） */
.dialog-range-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dialog-range {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

.dialog-range:focus {
  outline: none;
}

/* 数字が変わっても幅が動かないよう、桁数ぶんの場所を空けておく */
.dialog-range-value {
  min-width: 5ch;
  text-align: right;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--fg-muted, var(--fg));
}

/* 設定ダイアログのラジオボタン（ゲーム画面の配置） */
.dialog-label {
  font-size: 12px;
  color: var(--fg-dim);
}

.dialog-radio-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dialog-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--fg);
  cursor: pointer;
}

/* .dialog-form input の余白や枠をラジオには当てない */
.dialog-form .dialog-radio input {
  margin: 0;
  padding: 0;
  border: none;
  accent-color: var(--accent);
  cursor: pointer;
}

.ide-main {
  grid-area: main;
  background: var(--bg);
  display: grid;
  grid-template-columns: 1fr;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  /* 狭いウィンドウで、ゲーム画面を中央へ重ねる際の基準 */
  position: relative;
}

/* 従来の表示領域（エディタなど） */
.ide-content {
  padding: 16px;
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

/* ゲーム実行画面（配置は body.game-layout-* で切り替える。4.13節） */
.ide-game {
  display: none;
  grid-template-rows: 1fr;
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--border);
}

/* canvas は長い方を領域に合わせ、短い方は中央に置く（表示サイズはRust側が算出する） */
.ide-game-body {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

/* 起動時のバナー（4.14節）。canvas の上に重ね、タップ待ちの間だけ操作を受ける */
.game-splash {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.game-splash.splash-waiting {
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
}

.game-splash-banner,
.game-splash-tap {
  opacity: 0;
  transition: opacity 0.5s ease;
}

.game-splash-banner.splash-visible,
.game-splash-tap.splash-visible {
  opacity: 1;
}

.game-splash-banner {
  width: min(70%, 560px);
  height: auto;
  filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.6));
}

.game-splash-tap {
  margin: 0;
  color: #e6e6f0;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

/* 停止中はグレー地にして、動いていないことが分かるようにする */
.ide-main:not(.game-active) .ide-game-body {
  background: #43434f;
}

.ide-main:not(.game-active) .game-canvas {
  display: none;
}

.game-canvas {
  display: block;
  background: #000;
  border: 2px solid var(--border);
  border-radius: 4px;
}

/* 画面いっぱいの表示（ゲーム画面のダブルクリック）。余白も黒にして枠を消す */
.ide-game-body:fullscreen {
  background: #000;
}

.ide-game-body:fullscreen .game-canvas {
  border: none;
  border-radius: 0;
}

/*
 * 「エディタの右に並べる」: メイン部を左右half&halfに分割し、右をゲーム実行画面にする。
 * プロジェクトを開いている時だけ分割する（起動画面で黒い領域を出さないため）。
 */
body.game-layout-side .ide-main.has-project {
  grid-template-columns: 1fr 1fr;
}

body.game-layout-side .ide-main.has-project .ide-game {
  display: grid;
}

/*
 * 「エディタの上に重ねる」（既定）: 分割せず、ゲーム実行中だけ
 * メイン部の中央へゲーム画面を重ねて表示する。
 */
body.game-layout-overlay .ide-main.game-active .ide-game {
  display: grid;
  place-items: center;
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.75);
  border-left: none;
}

/* 重ねる配置でも canvas を置く領域はペイン全体にする。
   領域が canvas の大きさに縮むと、大きさ合わせのたびに余白ぶん小さくなっていく */
body.game-layout-overlay .ide-main.game-active .ide-game-body {
  width: 100%;
  height: 100%;
  background: transparent;
}

/* コードエディタ（Ace） */
.editor-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  /* .ide-content の padding を打ち消して領域いっぱいに広げる */
  margin: -16px;
}

.editor-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.editor-filename {
  font-weight: 600;
  color: var(--fg);
}

.editor-dirty:not(:empty) {
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
}

.editor-hint {
  margin-left: auto;
  color: var(--fg-dim);
  font-size: 12px;
}

.editor-body {
  flex: 1;
  min-height: 0;
  width: 100%;
}

.ide-footer {
  grid-area: footer;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  font-size: 12px;
  color: var(--fg-dim);
}

/* 常に見えている1行。クリックで履歴を開閉する */
.footer-bar {
  flex: 0 0 var(--footer-bar-h);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.footer-bar:hover {
  background: var(--bg-elevated);
}

.footer-bar:focus-visible {
  outline: none;
  background: var(--bg-elevated);
}

.footer-fps {
  min-width: 80px;
}

.footer-console {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 履歴を消すボタン（開いている間だけ出す） */
.footer-clear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--fg-dim);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.footer-clear-btn[hidden] {
  display: none;
}

.footer-clear-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.footer-clear-btn:focus-visible {
  outline: none;
  color: var(--danger);
  border-color: var(--danger);
}

/* 開閉の向きを示す目印 */
.footer-caret {
  flex-shrink: 0;
  font-size: 10px;
  line-height: 1;
  opacity: 0.7;
}

/* 過去ログの一覧。閉じている間は高さ0にして隠す */
.footer-log {
  flex: 1 1 auto;
  min-height: 0;
  height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  overflow-x: hidden;
  border-top: 1px solid var(--border);
  background: var(--bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  visibility: hidden;
}

body.footer-expanded .footer-log {
  height: auto;
  visibility: visible;
  padding: 4px 12px;
}

.footer-log-line {
  line-height: var(--footer-line-h);
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--fg);
}

/* 左ペインのプロジェクト名の右端に置く実行トグル（6.2.1節） */
.pane-toggle-btn {
  display: flex;
  margin-left: auto;
  flex-shrink: 0;
}

/* 左ペイン最上部: 開いているプロジェクト名 */
.pane-project {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
  min-width: 0;
}

/* 名前が長い場合はここだけを省略表示にする（右端のボタンを押し出さない） */
.pane-project-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.pane-project::before {
  content: "📁";
  font-size: 18px;
  font-weight: 400;
  flex-shrink: 0;
}

.dialog-new-project {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--fg);
  padding: 0;
  min-width: 360px;
}

.dialog-new-project::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

/* プロジェクト選択ダイアログ（横幅はブラウザの80%、高さは90%） */
.dialog-project-select {
  width: 80vw;
  height: 90vh;
  /* <dialog> の既定の上限を外す */
  max-width: none;
  max-height: none;
  /* 上端を基準にして、そこからロールダウンさせる */
  margin-top: 0;
  margin-bottom: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: var(--bg-panel);
  color: var(--fg);
  overflow: hidden;

  /* 開く: 上から降りてくる ／ 閉じる: 上へ巻き上がる */
  transform: translateY(-100%);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.dialog-project-select.fade-visible {
  transform: translateY(0);
}

.dialog-project-select::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.project-select {
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100%;
  padding: 20px;
  box-sizing: border-box;
}

.project-select-header {
  display: flex;
  align-items: center;
  gap: 16px;
}

.project-select-title {
  margin: 0;
  font-size: 18px;
}

/* 見出しとボタンの間を空け、閉じるボタンを右端へ寄せる */
.project-select-spacer {
  flex: 1;
}

.project-select-empty {
  margin: 0;
  color: var(--fg-dim);
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  align-content: start;
  overflow-y: auto;
  padding: 4px;
}

.project-card {
  /* ゴミ箱ボタンを右上へ重ねるため、基準にする */
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 8px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--fg);
  font-size: 12px;
  transition: border-color 0.15s, background 0.15s;
}

/* カード右上のゴミ箱。ふだんは控えめにし、カードに触れた時だけはっきり出す */
.project-card-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  /* --fg-muted は未定義のため、本文色へ倒す（781行目と同じ書き方）*/
  color: var(--fg-muted, var(--fg));
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.project-card:hover .project-card-delete,
.project-card-delete:focus-visible {
  opacity: 1;
}

.project-card-delete:hover {
  background: var(--bg);
  /* 消す操作だと分かるよう、触れた時だけ赤くする */
  color: #e63b30;
}

.project-card:hover {
  border-color: var(--accent);
  background: var(--bg);
}

.project-card-icon {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
}

.project-card-icon img {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  object-fit: cover;
}

.project-card-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-form {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog-form h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.dialog-form label {
  font-size: 12px;
  color: var(--fg-dim);
}

.dialog-form input {
  padding: 8px 10px;
  background: var(--bg-elevated);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
}

.dialog-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.dialog-btn {
  padding: 8px 16px;
  background: var(--bg-elevated);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

.dialog-btn:hover {
  background: var(--border);
}

.dialog-btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.dialog-btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ============================================================
   仕様・リファレンス（4.9節）
   ゲーム画面を右に並べる配置ではゲーム表示エリアと同じ場所へ、
   上に重ねる配置では右ペイン全体へ出す。
   ============================================================ */

.ide-reference {
  display: none;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--bg);
}

.reference-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.reference-title {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--fg);
}

.reference-nav {
  display: flex;
  gap: 4px;
}

.reference-nav-item {
  flex-shrink: 0;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--fg-dim);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.reference-nav-item:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.reference-body {
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px 32px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--fg);
}

.reference-section-title {
  margin: 24px 0 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--accent);
  font-size: 16px;
}

.reference-section-title:first-child {
  margin-top: 0;
}

.reference-heading {
  margin: 20px 0 6px;
  font-size: 14px;
  color: var(--accent);
}

.reference-text {
  margin: 0 0 10px;
}

.reference-code {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  /* 長い行は表と同じく、この枠の中だけで横スクロールさせる */
  overflow-x: auto;
}

/* 幅が足りない場合に、表だけを横スクロールさせる（本文は折り返す） */
.reference-table-wrap {
  margin: 0 0 14px;
  overflow-x: auto;
}

.reference-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
}

.reference-table th,
.reference-table td {
  padding: 5px 8px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.reference-table th {
  background: var(--bg-panel);
  color: var(--fg-dim);
  font-weight: 600;
  white-space: nowrap;
}

.reference-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
}

.reference-first {
  color: var(--accent);
}

/* エディタの右に並べる配置: ゲーム表示エリアと同じ場所を使い、辞書アイコンで入れ替える */
body.game-layout-side.reference-open .ide-main {
  grid-template-columns: 1fr 1fr;
}

body.game-layout-side.reference-open .ide-reference {
  display: grid;
}

/* 同じ場所なので、リファレンスを開いている間はゲーム側を隠す */
body.game-layout-side.reference-open .ide-main .ide-game {
  display: none;
}

/* エディタの上に重ねる配置: 右ペイン全体を覆う */
body.game-layout-overlay.reference-open .ide-reference {
  display: grid;
  position: absolute;
  inset: 0;
  z-index: 5;
  border-left: none;
}

/* ============================================================
   プロジェクトを開いていない間の案内（4.10節）
   Chrome のファイル操作に慣れていなくても、
   「何を選ぶ操作なのか」が分かるようにする。
   ============================================================ */

.ide-welcome {
  /* メイン部と重ねて置く。プロジェクトを開くと隠れる */
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

/* プロジェクトを開いたら用済み */
.ide-main.has-project .ide-welcome {
  display: none;
}

.welcome-inner {
  max-width: 560px;
}

.welcome-title {
  margin: 0 0 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--fg);
}

.welcome-lead {
  margin: 0 0 20px;
  font-size: 13px;
  line-height: 1.8;
  color: var(--fg-dim);
}

.welcome-steps {
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.welcome-step {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
}

.welcome-step-no {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.welcome-step-icon {
  display: flex;
  color: var(--accent);
}

.welcome-step-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--fg-dim);
}

.welcome-step-text b {
  color: var(--fg);
  font-size: 13px;
}

.welcome-note {
  margin: 0;
  font-size: 11px;
  line-height: 1.7;
  color: var(--fg-dim);
}

/* ============================================================
   キーコンフィグ（6.2.10節）
   コントローラーの絵の上で、押してほしい箇所を光らせる。
   ============================================================ */

.padconf-dialog {
  /* 指示している箇所を示す色。図の中で最も目立たせる */
  --padconf-mark: #ff3b30;
  margin: auto;
  width: min(92vw, 560px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-panel);
  color: var(--fg);
}

.padconf-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.padconf-body {
  padding: 20px;
  text-align: center;
}

.padconf-title {
  margin: 0 0 4px;
  font-size: 16px;
}

.padconf-device {
  margin: 0 0 12px;
  font-size: 11px;
  color: var(--fg-dim);
}

.padconf-figure svg {
  width: 100%;
  height: auto;
  max-height: 40vh;
}

/* SVG側から色指定を外してあるので、すべてここで決める。
   インラインの style が残っているとクラス指定が効かないため */
.padconf-figure svg path,
.padconf-figure svg circle,
.padconf-figure svg rect {
  fill: none;
  stroke: var(--fg-dim);
  stroke-width: 0.6;
}

.padconf-figure svg text,
.padconf-figure svg tspan {
  fill: var(--fg-dim);
  stroke: none;
}

/* 十字キーの目印は位置を示すためだけのもの。指している時以外は見せない。
   :not() を使い、指している時の指定と競合しないようにする */
.padconf-figure svg #pad-markers circle:not(.padconf-target) {
  fill: none;
  stroke: none;
}

/* いま押してほしい箇所。赤で示し、ゆっくり明滅させて目を引く。
   図の他の部分は控えめな色なので、赤が最も目立つ */
.padconf-figure svg .padconf-target {
  stroke: var(--padconf-mark);
  stroke-width: 2;
  fill: color-mix(in srgb, var(--padconf-mark) 30%, transparent);
  animation: padconf-blink 1.2s ease-in-out infinite;
}

.padconf-figure svg text.padconf-target,
.padconf-figure svg tspan.padconf-target {
  fill: var(--padconf-mark);
}

/* 倒す向きを示す矢印。押す手順との違いが分かるようにする */
.padconf-figure svg #padconf-arrow path {
  fill: none;
  stroke: var(--padconf-mark);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.padconf-figure svg .padconf-arrow-inner {
  animation: padconf-slide 1s ease-in-out infinite;
}

/* 倒す向きへ、ゆっくり出ていく動き */
@keyframes padconf-slide {
  0% { transform: translateX(0); opacity: 0.2; }
  40% { opacity: 1; }
  100% { transform: translateX(6px); opacity: 0; }
}

@keyframes padconf-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* 動きに敏感な人への配慮。矢印は向きだけ示して止める */
@media (prefers-reduced-motion: reduce) {
  .padconf-figure svg .padconf-target,
  .padconf-figure svg .padconf-arrow-inner {
    animation: none;
  }

  .padconf-figure svg .padconf-arrow-inner {
    opacity: 1;
  }
}

.padconf-ask {
  /* 文の長さで行数が変わっても、画面の高さが動かないようにする */
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3em;
  margin: 12px 0 8px;
  font-size: 15px;
  font-weight: 700;
}

.padconf-hint {
  margin: 0 0 10px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--fg-dim);
}

/* 自動で決まったことの知らせ。
   出し入れで画面の大きさが変わらないよう、場所は常に確保しておく */
.padconf-notice {
  margin: 0 0 10px;
  padding: 6px 10px;
  min-height: 2.6em;
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--accent);
  transition: opacity 0.3s ease;
}

/* hidden でも場所は残す（消えるのは見た目だけ） */
.padconf-notice[hidden] {
  display: block;
  opacity: 0;
  border-color: transparent;
}

.padconf-progress {
  height: 4px;
  border-radius: 999px;
  background: var(--bg-elevated);
  overflow: hidden;
}

.padconf-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s ease;
}

.padconf-step {
  margin: 6px 0 14px;
  font-size: 11px;
  color: var(--fg-dim);
}

.padconf-buttons {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.padconf-btn {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--fg);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.padconf-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.padconf-cancel:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* アセットの対応表（5.7節） */
.pane-tab-action {
  margin-left: auto;
}

.assetmap-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: auto;
  padding: 16px 20px;
  gap: 12px;
}

.assetmap-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.assetmap-title {
  font-size: 15px;
  font-weight: 600;
}

.assetmap-note {
  font-size: 12px;
  color: var(--fg-muted, #94a3b8);
}

/* 問題がある入力は赤で知らせる */
.assetmap-note.assetmap-error {
  color: #ff6b6b;
}

.assetmap-section {
  margin-bottom: 8px;
}

.assetmap-kind {
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0 6px;
  color: var(--accent);
}

.assetmap-empty {
  font-size: 12px;
  color: var(--fg-muted, #94a3b8);
  margin: 0 0 4px;
}

.assetmap-table {
  border-collapse: collapse;
  width: 100%;
  max-width: 720px;
  font-size: 13px;
}

.assetmap-table th {
  text-align: left;
  font-weight: 500;
  color: var(--fg-muted, #94a3b8);
  border-bottom: 1px solid var(--border);
  padding: 4px 8px;
}

.assetmap-table td {
  padding: 3px 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

/* ファイル名は等幅にして、拡張子の違いを見分けやすくする */
.assetmap-file {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--fg);
}

.assetmap-input {
  width: 100%;
  max-width: 240px;
  padding: 3px 6px;
  background: var(--bg-elevated);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}

.assetmap-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* --- 3Dモデルの詳細表示（4.4節） --- */

.modelview-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.modelview-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.modelview-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
}

.modelview-note {
  font-size: 12px;
  color: var(--fg-muted, var(--fg));
  opacity: 0.75;
}

.modelview-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* 正面から見た大きめのプレビュー */
.modelview-front {
  width: 320px;
  height: 320px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.modelview-heading {
  align-self: stretch;
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}

.modelview-empty {
  align-self: stretch;
  font-size: 12px;
  opacity: 0.75;
}

/* アニメーション1件ぶん */
.modelview-row {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.modelview-row-canvas {
  width: 128px;
  height: 128px;
  flex: none;
}

.modelview-row-side {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

/* 名前はボタン。押せることが分かるようにする */
.modelview-clip-name {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.modelview-clip-name:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.modelview-clip-length {
  font-size: 11px;
  opacity: 0.7;
}

/* 画像の詳細表示（4.4節）。枠組みは modelview と共通 */
.imageview-cell {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--fg);
}

.imageview-cell input {
  width: 64px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

.imageview-body {
  justify-content: center;
}

/* 透けているところが分かるよう、市松模様の上に置く */
.imageview-stage {
  position: relative;
  flex: none;
  background-color: #9a9aa6;
  background-image:
    linear-gradient(45deg, #6e6e7a 25%, transparent 25%, transparent 75%, #6e6e7a 75%),
    linear-gradient(45deg, #6e6e7a 25%, transparent 25%, transparent 75%, #6e6e7a 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
  border: 1px solid var(--border);
}

/* ドット絵をにじませない */
.imageview-picture {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.imageview-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* 選んでいる節（リファレンスの目次はタブとして働く） */
.reference-nav-item-active {
  background: var(--bg-elevated);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* 一覧から説明へ飛ぶための名前（押せることが分かるようにする） */
.reference-link {
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.reference-link:hover {
  text-decoration-thickness: 2px;
}
