/* ============================================================
   base.css — card-atelier デザイントークンと全体レイアウト
   ai-holdings のトークン設計を下敷きに、シアン・ブルー基調。
   カードは暗色フレーム（TCG風）なので、地は明るく静かに保つ。
   ============================================================ */

:root {
  /* 地の色（ワークスペース側） */
  --bg: #f4f7f9;
  --bg-2: #eef2f5;
  --surface: #ffffff;
  --line: #dde5ea;
  --line-2: #e8eef2;
  --text: #1a2b33;
  --text-2: #5b7078;
  --text-3: #8fa2aa;
  --brand: #0891b2;
  --brand-grad: linear-gradient(135deg, #0891b2, #2563eb);

  /* カード側（暗色フレーム）。card.css がこの上に種別accentを重ねる */
  --card-frame: #16222e;
  --card-frame-2: #1d2d3c;
  --card-text: #eaf3f7;
  --card-text-2: #9fb4c0;

  /* 状態トーン */
  --tone-ok: #10b981;
  --tone-warn: #f59e0b;
  --tone-muted: #7d8f97;

  /* 形・影 */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-full: 999px;
  --shadow-1: 0 1px 2px rgba(23, 42, 51, 0.06), 0 2px 8px rgba(23, 42, 51, 0.06);
  --shadow-2: 0 2px 6px rgba(23, 42, 51, 0.08), 0 10px 24px rgba(23, 42, 51, 0.12);
  --shadow-3: 0 6px 14px rgba(23, 42, 51, 0.12), 0 26px 48px rgba(23, 42, 51, 0.18);

  /* モーション */
  --dur-fast: 160ms;
  --dur-base: 280ms;
  --dur-slow: 500ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --font: "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", "Segoe UI", sans-serif;
  --font-mono: "Consolas", "SF Mono", "Menlo", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  /* ドラッグ中にテキスト選択が始まると手触りが壊れるので全体で無効化。
     入力欄だけ selectable に戻す */
  user-select: none;
  /* P2-1: ヘッダー高さの固定値（旧: 100vh - 61px）をやめ、
     body縦flexで「ヘッダーを引いた残り」を #view-host に自動配分する。
     ページ全体はスクロールさせず、スクロールは #view-host 内で起こす */
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.read-only-banner {
  position: relative;
  z-index: 50;
  padding: 7px 16px;
  border-bottom: 1px solid color-mix(in srgb, var(--brand) 35%, transparent);
  background: color-mix(in srgb, var(--brand) 10%, var(--surface));
  color: var(--text-2);
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
}

.catl-read-only #add-card-btn,
.catl-read-only #mobile-quick-btn,
.catl-read-only #seed-btn,
.catl-read-only .card-action[data-act="link"],
.catl-read-only .card-action[data-act="stow"],
.catl-read-only .card-action[data-act="delete"],
.catl-read-only .table-selectbar,
.catl-read-only .table-historybar,
.catl-read-only .table-stampbar,
.catl-read-only .table-matbar,
.catl-read-only .table-snapbar,
.catl-read-only .tray-menu-btn,
.catl-read-only .stamp-delete,
.catl-read-only .stamp-handle {
  display: none !important;
}

.catl-read-only .tray-item,
.catl-read-only .link-label,
.catl-read-only .stack-badge {
  pointer-events: none;
}
input, textarea { user-select: text; }

/* キーボード操作時だけ、操作対象を全UIで一貫して見えるようにする。 */
:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 3px;
}

#view-host {
  flex: 1;
  min-height: 0; /* flex子のデフォルトmin-height:autoだと縮めなくなる */
  overflow: auto;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   ヘッダー: ブランド + ビュー切替タブ
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  /* P2-1: 幅が足りないときはボタン群を2段目へ折り返す（縦書き状の崩れ防止）。
     高さが変わっても body 縦flex が #view-host の残高を自動計算する */
  flex-wrap: wrap;
  gap: 8px 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 100; /* テーブル上のカードより常に手前 */
}

/* 狭い画面では間隔を詰め、さらに狭ければ飾りを削って折返しを最小にする */
@media (max-width: 1366px) {
  .topbar { gap: 8px 12px; padding: 10px 16px; }
}
@media (max-width: 900px) {
  .brand-sub { display: none; }
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--brand-grad);
  flex-shrink: 0;
}
.brand-name {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.brand-sub {
  font-size: 0.66rem;
  color: var(--text-3);
  line-height: 1.3;
}

.view-tabs { display: flex; gap: 4px; }
.view-tab {
  padding: 8px 18px;
  white-space: nowrap; /* 幅不足でもタブ文字を縦に折り返さない（P2-1） */
  border: none;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.view-tab:hover { background: var(--bg-2); color: var(--text); }
.view-tab:active { transform: scale(0.96); }
.view-tab.is-active {
  background: color-mix(in srgb, var(--brand) 12%, white);
  color: color-mix(in srgb, var(--brand) 85%, black);
}
.view-tab:disabled {
  opacity: 0.4;
  cursor: default;
}
.view-tab-icon { display: none; }

.topbar-spacer { flex: 1; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.topbar-more { display: contents; }
.mobile-only,
.menu-label,
.mobile-menu-only,
.mobile-fab,
.mobile-fab-menu,
.mobile-fab-backdrop { display: none; }

/* 右端のユーティリティボタン（ミュート等） */
.icon-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--surface);
  font-size: 1rem;
  cursor: pointer;
  transition: background var(--dur-fast), transform var(--dur-fast) var(--ease-spring);
}
.icon-btn:hover { background: var(--bg-2); }
.icon-btn:active { transform: scale(0.9); }

/* 接続状態ラベルとボタン */
.conn-label {
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font-family: inherit;
  font-size: 0.72rem;
  color: var(--text-3);
  white-space: nowrap;
  cursor: default;
}
.conn-label.is-ok { color: var(--tone-ok); font-weight: 700; }
.conn-btn {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text-2);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.conn-btn:hover { background: var(--bg-2); border-color: var(--brand); color: var(--text); }

/* toast（画面下の小さな通知） */
#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  translate: -50% 16px;
  z-index: 1000;
  padding: 10px 22px;
  border-radius: var(--r-full);
  background: var(--text);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: var(--shadow-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out), translate var(--dur-base) var(--ease-spring);
}
#toast.show { opacity: 1; translate: -50% 0; }
#toast.error { background: #b4232f; }

/* 保存失敗バナー（js/save-status.js。P1-1/P1-2）。
   toastと違い、解決するまで出しっぱなしにして「未保存」を隠さない */
#save-banner {
  position: fixed;
  top: 0;
  left: 50%;
  translate: -50%;
  z-index: 9000; /* モーダル(2000)やクイックキャプチャ(8001)より上。保存状態は常に見えるべき */
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(92vw, 720px);
  padding: 8px 16px;
  border-radius: 0 0 10px 10px;
  font-size: 13px;
  color: #fff;
  box-shadow: 0 4px 16px rgb(0 0 0 / 35%);
}
#save-banner.warn { background: #9a6b00; }
#save-banner.error { background: #b4232f; }
#save-banner button {
  flex-shrink: 0;
  padding: 4px 10px;
  border: 1px solid rgb(255 255 255 / 55%);
  border-radius: 6px;
  background: rgb(255 255 255 / 12%);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
}
#save-banner button:hover { background: rgb(255 255 255 / 24%); }

/* ============================================================
   コマンドパレット（js/palette.js。spec-37）
   .modal-overlay を継承しつつ、中央でなく上部に出す
   ============================================================ */
.palette-overlay {
  align-items: flex-start;
  padding-top: 10vh;
}
.palette {
  width: 560px;
  max-width: 100%;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 18px 60px rgb(23 42 51 / 30%);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.palette-input {
  padding: 14px 16px;
  border: none;
  border-bottom: 1px solid var(--line);
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}
.palette-list {
  max-height: 52vh;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.palette-section {
  padding: 8px 8px 3px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-3);
}
.palette-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.palette-row:hover { background: var(--bg-2); }
.palette-row.is-selected {
  background: color-mix(in srgb, var(--brand) 10%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 35%, transparent);
}
/* compact行のクリックは行が受ける（カード側のハンドラは無い前提だが保険） */
.palette-row .catl-card { pointer-events: none; }
.palette-action-label { font-size: 0.85rem; font-weight: 600; }
.palette-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 0.85rem;
}

/* 小さめの補助ボタン（登録フォームの「画像を外す」等） */
.btn-small {
  font-size: 0.74rem;
  padding: 5px 10px;
  margin-top: 6px;
  align-self: flex-start;
}

/* ============================================================
   モーダル（登録フォーム）
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 42, 51, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 24px;
}
.modal {
  width: 420px;
  max-width: 100%;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  padding: 24px;
  animation: modal-in 220ms var(--ease-spring);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-title {
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 800;
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-2);
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 15%, transparent);
}
.field textarea { resize: vertical; }
.field-group { border-top: 1px solid var(--line-2); padding-top: 4px; margin-top: 4px; }
.image-preview {
  margin-top: 8px;
  max-width: 120px;
  max-height: 120px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  display: block;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
.btn {
  padding: 9px 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text-2);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}
.btn:hover { background: var(--bg-2); }
.btn.primary {
  background: var(--brand-grad);
  color: #fff;
  border-color: transparent;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger {
  background: #b4232f;
  color: #fff;
  border-color: transparent;
}
.btn.danger:hover { background: #b4232f; filter: brightness(1.12); }
.btn:disabled { opacity: 0.6; cursor: default; }

/* ============================================================
   確認ダイアログ（削除など。dialogs.js が生成）
   ============================================================ */
.confirm-modal { width: 380px; }
.confirm-message {
  margin: 0 0 18px;
  font-size: 0.88rem;
  color: var(--text-2);
  line-height: 1.7;
}

/* ============================================================
   カード詳細ビュー（カード裏面の情報を読める文字サイズで）
   --accent は dialogs.js が種別色を注入する
   ============================================================ */
.detail-modal { width: 520px; }
.detail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.detail-type {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: color-mix(in srgb, var(--accent, var(--brand)) 70%, var(--text));
}
.detail-badge {
  padding: 2px 10px;
  border-radius: var(--r-full);
  font-size: 0.7rem;
  font-weight: 800;
  color: #fff;
}
.detail-badge.tone-ok { background: var(--tone-ok); }
.detail-badge.tone-warn { background: var(--tone-warn); }
.detail-badge.tone-muted { background: var(--tone-muted); }
.detail-title {
  margin: 0 0 6px;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.detail-desc {
  margin: 0 0 14px;
  font-size: 0.92rem;
  color: var(--text-2);
  line-height: 1.75;
}
.detail-image {
  display: block;
  max-width: 100%;
  max-height: 260px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  margin: 0 0 14px;
}
.detail-fields {
  display: grid;
  grid-template-columns: 7em 1fr;
  gap: 8px 14px;
  margin: 0 0 14px;
  padding: 14px 16px;
  background: var(--bg-2);
  border-radius: var(--r-md);
  font-size: 0.9rem;
}
.detail-fields dt {
  font-weight: 700;
  color: var(--text-2);
  font-size: 0.82rem;
  padding-top: 2px;
}
.detail-fields dd {
  margin: 0;
  line-height: 1.7;
  overflow-wrap: anywhere;
}
/* fmtBack が返すゲージ（◆◆◇）とパス表示を、明るい地の上でも読めるように */
.detail-fields .lv-on { color: var(--accent, var(--brand)); }
.detail-fields .lv-off { color: var(--line); }
.detail-fields .path { font-family: var(--font-mono); font-size: 0.82em; }
.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.detail-tag {
  padding: 2px 10px;
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--brand) 10%, white);
  color: color-mix(in srgb, var(--brand) 80%, black);
  font-size: 0.74rem;
  font-weight: 700;
}
.detail-meta {
  font-size: 0.72rem;
  color: var(--text-3);
  margin-bottom: 4px;
}
.detail-actions .actions-spacer { flex: 1; }

/* --- S3: 使用記録（愛用度）とレアリティ切替 --- */
.detail-usage {
  font-size: 0.85rem;
  color: var(--text-2);
  margin-bottom: 10px;
}
.detail-usage strong {
  color: var(--accent, var(--brand));
  font-size: 1rem;
}
.detail-usage .usage-sub { font-size: 0.76rem; color: var(--text-3); }
.detail-usage .usage-wear {
  margin: 0 2px;
  padding: 2px 10px;
  border-radius: var(--r-full);
  font-size: 0.72rem;
  font-weight: 800;
  color: #8a6d1d;
  background: color-mix(in srgb, #d4af37 18%, white);
}
.detail-rarity {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.detail-rarity .rarity-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-2);
  margin-right: 4px;
}
.rarity-btn {
  padding: 5px 13px;
  border-radius: var(--r-full);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-2);
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color var(--dur-base) var(--ease-out),
              background var(--dur-base) var(--ease-out),
              color var(--dur-base) var(--ease-out);
}
.rarity-btn:hover {
  border-color: var(--accent, var(--brand));
  color: var(--text);
}
.rarity-btn.is-active {
  border-color: var(--accent, var(--brand));
  background: color-mix(in srgb, var(--accent, var(--brand)) 14%, transparent);
  color: var(--text);
}

/* ============================================================
   ビュー切替（display で出し分け。SPA的なルーティングはしない）
   ============================================================ */
.view { display: none; }
/* P2-1: テーブルは「残り高さぴったり」、バインダー等は「最低限埋めて超えたら
   #view-host がスクロール」の両立のため、ビューを縦flexで残高いっぱいに広げる */
.view.is-active { display: flex; flex-direction: column; flex: 1; }

/* View Transitions（#5）: カードのモーフと全体クロスフェードの速度。
   非対応ブラウザではこのブロックごと無視される */
::view-transition-group(*) {
  animation-duration: 300ms;
  animation-timing-function: var(--ease-out);
}

/* ============================================================
   クイックキャプチャ（#40）: Nキーで出る1行入力ピル
   ============================================================ */
.quick-capture {
  position: fixed;
  top: 76px;
  left: 50%;
  translate: -50% -8px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  box-shadow: var(--shadow-2);
  z-index: 1500; /* ヘッダー(100)より手前・モーダル(2000)より奥 */
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-out),
              translate var(--dur-fast) var(--ease-spring);
}
.quick-capture.is-open {
  opacity: 1;
  pointer-events: auto;
  translate: -50% 0;
}
.qc-icon { font-size: 1rem; }
.qc-input {
  width: 320px;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
}
.qc-hint {
  font-size: 0.68rem;
  color: var(--text-3);
  white-space: nowrap;
}
/* 空のままEnterしたときの「追加されなかった」合図 */
.quick-capture.is-shake { animation: qc-shake 240ms var(--ease-out); }
@keyframes qc-shake {
  20% { translate: calc(-50% - 6px) 0; }
  50% { translate: calc(-50% + 5px) 0; }
  80% { translate: calc(-50% - 3px) 0; }
}


/* ============================================================
   操作マニュアル（js/manual.js）
   ============================================================ */
.manual-modal { width: 660px; }
.manual-intro {
  margin: 0 0 16px;
  font-size: 0.84rem;
  color: var(--text-2);
}
.manual-section { margin-bottom: 18px; }
.manual-section h3 {
  margin: 0 0 6px;
  padding-bottom: 4px;
  font-size: 0.92rem;
  border-bottom: 1px solid var(--line-2);
}
.manual-section ul {
  margin: 0;
  padding-left: 1.2em;
  font-size: 0.84rem;
  line-height: 1.75;
}
.manual-section li { margin: 2px 0; }
.manual-keys {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}
.manual-keys td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--line-2);
}
.manual-keys td:first-child { white-space: nowrap; }
.manual-modal kbd {
  display: inline-block;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-2);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
}

/* ============================================================
   スマホ共通UI（Phase 1改: 2026-07-17 ミニマルシェル）
   ヘッダー・常設タブを出さず、画面いっぱいをビューに使う。
   入口は右下の＋ボタン1個。360px縦画面に加え、
   844×390前後のスマホ横画面も同じ操作系にする。
   ============================================================ */
@media (max-width: 768px), (max-height: 480px) and (max-width: 900px) {
  body {
    min-height: 100dvh;
  }

  /* ヘッダーは丸ごと出さない（操作ボタンはapp.jsがFABメニューへ移動済み） */
  .topbar { display: none; }
  .desktop-only { display: none; }
  .mobile-only { display: inline; }

  #view-host {
    /* セーフエリアぶんだけ確保し、残りは全部ビューが使う */
    padding-top: env(safe-area-inset-top);
    overscroll-behavior: contain;
  }

  /* ---------- 右下の＋ボタン（唯一の常設UI） ---------- */
  .mobile-fab {
    position: fixed;
    right: calc(14px + env(safe-area-inset-right));
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 950;
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    padding: 0;
    border: none;
    border-radius: var(--r-full);
    background: var(--brand-grad);
    color: #fff;
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 4px 14px rgba(8, 145, 178, 0.45);
    cursor: pointer;
    transition: transform var(--dur-fast) var(--ease-spring);
  }
  body.fab-menu-open .mobile-fab { transform: rotate(45deg); }

  .mobile-fab-backdrop {
    position: fixed;
    inset: 0;
    z-index: 930;
    display: none;
    background: rgba(10, 22, 32, 0.35);
  }
  body.fab-menu-open .mobile-fab-backdrop { display: block; }

  /* ---------- ＋ボタンから開くメニュー ---------- */
  .mobile-fab-menu {
    position: fixed;
    right: calc(10px + env(safe-area-inset-right));
    bottom: calc(80px + env(safe-area-inset-bottom));
    z-index: 940;
    display: none;
    flex-direction: column;
    gap: 10px;
    width: min(300px, calc(100vw - 20px));
    max-height: calc(100dvh - 100px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding: 10px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-3);
  }
  body.fab-menu-open .mobile-fab-menu {
    display: flex;
    animation: fab-menu-in 180ms var(--ease-out);
  }
  @keyframes fab-menu-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* ビュー切替: メニュー先頭にアイコン+ラベルのタイルを4つ並べる */
  .mobile-view-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
  }
  .mobile-view-tabs .view-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 56px;
    padding: 6px 2px;
    border-radius: 10px;
    font-size: 0.64rem;
    line-height: 1.25;
  }
  .mobile-view-tabs .view-tab-icon {
    display: block;
    font-size: 1.15rem;
    line-height: 1;
  }
  .mobile-view-tabs .view-tab.is-active {
    background: color-mix(in srgb, var(--brand) 14%, var(--surface));
    box-shadow: inset 0 -3px 0 var(--brand);
  }

  /* 操作ボタン（ヘッダーから移動してきた実DOM）を縦に並べる */
  .fab-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-top: 1px solid var(--line-2);
    padding-top: 8px;
  }
  .fab-actions .conn-btn,
  .fab-actions .icon-btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    padding: 9px 12px;
    border-radius: var(--r-sm);
    font-size: 0.85rem;
  }
  .fab-actions .add-card-btn {
    color: #fff;
    background: var(--brand-grad);
    border-color: transparent;
  }
  .fab-actions .mobile-menu-only { display: flex; }
  .fab-actions .menu-label { display: inline; }
  .fab-actions .conn-label {
    min-height: 32px;
    padding: 4px 12px;
    text-align: left;
    font-size: 0.72rem;
    cursor: pointer;
  }

  #toast {
    bottom: calc(82px + env(safe-area-inset-bottom));
    width: max-content;
    max-width: calc(100vw - 24px);
    padding: 9px 16px;
    text-align: center;
  }
  #save-banner {
    top: env(safe-area-inset-top);
    width: calc(100vw - 20px);
    max-width: 720px;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: calc(8px + env(safe-area-inset-top)) 0 0;
    overscroll-behavior: contain;
  }
  .modal {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 8px - env(safe-area-inset-top));
    padding: 20px max(16px, env(safe-area-inset-right))
             calc(16px + env(safe-area-inset-bottom))
             max(16px, env(safe-area-inset-left));
    border-radius: 20px 20px 0 0;
    overscroll-behavior: contain;
    animation-name: mobile-sheet-in;
  }
  @keyframes mobile-sheet-in {
    from { opacity: 0; transform: translateY(24px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .modal > .modal-title:first-child {
    position: sticky;
    top: -20px;
    z-index: 2;
    margin: -20px -16px 16px;
    padding: 18px max(16px, env(safe-area-inset-right)) 12px
             max(16px, env(safe-area-inset-left));
    background: var(--surface);
    border-bottom: 1px solid var(--line-2);
  }
  .field input,
  .field select,
  .field textarea,
  .palette-input,
  .qc-input {
    font-size: 16px;
  }
  .field input,
  .field select {
    min-height: 44px;
  }
  .btn,
  .rarity-btn {
    min-height: 44px;
  }
  .modal-actions {
    position: sticky;
    bottom: calc(-16px - env(safe-area-inset-bottom));
    z-index: 2;
    flex-wrap: wrap;
    margin: 16px -16px calc(-16px - env(safe-area-inset-bottom));
    padding: 12px max(16px, env(safe-area-inset-right))
             calc(12px + env(safe-area-inset-bottom))
             max(16px, env(safe-area-inset-left));
    background: var(--surface);
    border-top: 1px solid var(--line-2);
  }
  .modal-actions .btn { flex: 1 1 auto; }

  .palette-overlay {
    align-items: flex-end;
    padding: calc(8px + env(safe-area-inset-top)) 0 0;
  }
  .palette {
    width: 100%;
    max-height: calc(100dvh - 8px - env(safe-area-inset-top));
    border-radius: 20px 20px 0 0;
  }
  .palette-input { min-height: 56px; }
  .palette-list { max-height: 68dvh; }

  .quick-capture {
    top: calc(10px + env(safe-area-inset-top));
    width: calc(100vw - 20px);
    padding: 10px 12px;
    border-radius: var(--r-md);
  }
  .qc-input { min-width: 0; width: 100%; }
  .qc-hint { display: none; }
}

/* スマホ横画面: メニューが縦に収まりきらないことがあるので少し詰める */
@media (max-height: 480px) and (max-width: 900px) {
  .mobile-fab {
    width: 48px;
    height: 48px;
    bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .mobile-fab-menu { bottom: calc(66px + env(safe-area-inset-bottom)); }
  .mobile-view-tabs .view-tab { min-height: 46px; }
  .fab-actions .conn-btn,
  .fab-actions .icon-btn { min-height: 40px; padding-block: 6px; }
  #toast { bottom: calc(66px + env(safe-area-inset-bottom)); }
}
