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

:root {
  --blue: #4295ec;
  --blue-light: #5da5ed;
  --blue-dim: #e8f1fd;
  --orange: #ffc04c;
  --orange-dim: #fff7ea;

  --text: #1a1a1a;
  /* グレー文字は読みやすいよう濃く・統一（ラベル/補助テキスト共通） */
  --label: #767c87;
  --muted: #767c87;
  --placeholder: #9aa0ab;

  --border: #d3d5da;
  --border-light: #f0f0f0;
  --dashed: #d8dade;

  --bg: #f5f6f8;
  --panel: #ffffff;
  --on-blue: #ededed;

  --radius: 5px;
  --radius-lg: 8px;
  --font: "Inter", "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* ===== Top bar ===== */
.topbar {
  height: 80px;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
}
.topbar__left { display: flex; align-items: center; gap: 18px; min-width: 0; }
.topbar__title { font-size: 18px; font-weight: 700; color: #000; display: flex; align-items: center; margin: 0; }
.topbar__logo { display: block; height: 46px; width: auto; margin-left: 20px; } /* 左パネルのモデル・画質枠のラインに合わせる */
.topbar__right { display: flex; align-items: center; gap: 16px; }

/* ===== プロジェクト切替（ヘッダー左のドロップダウン） ===== */
.project-switcher { position: relative; }
.project-switcher__btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.project-switcher__btn:hover { background: var(--border-light); border-color: var(--blue); }
.project-switcher__btn svg { flex-shrink: 0; color: var(--label); }
.project-switcher__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-switcher__chev { transition: transform 0.15s; }
.project-switcher.open .project-switcher__chev { transform: rotate(180deg); }

.project-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 300px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
  padding: 8px;
  z-index: 50;
}
.project-menu__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 8px;
}
.project-menu__title { font-size: 11px; font-weight: 700; color: var(--label); letter-spacing: 0.02em; }

.project-menu__list { display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; }

.project-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s;
}
.project-item:hover { background: var(--border-light); }
.project-item.active { background: var(--blue-dim); }
.project-item__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; cursor: pointer; overflow: hidden; }
.project-item__name { font-size: 14px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-item.active .project-item__name { color: var(--blue); font-weight: 600; }
.project-item__path { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-item__check { flex-shrink: 0; color: var(--blue); display: inline-flex; }
.project-item__actions { display: flex; gap: 2px; flex-shrink: 0; opacity: 0; transition: opacity 0.12s; }
.project-item:hover .project-item__actions { opacity: 1; }
.project-item__act {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: none; border-radius: 6px;
  color: var(--muted); cursor: pointer;
}
.project-item__act:hover { background: #e6e8ec; color: var(--text); }
.project-item__act.danger:hover { background: #fdecea; color: #c0392b; }

/* 新規プロジェクト（ヘッダー右・残高の左） */
.new-project { position: relative; display: flex; align-items: center; }
.new-project__btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--blue);
  background: var(--blue-dim);
  color: var(--blue);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.new-project__btn:hover { background: #d8e7fb; }

.new-project__pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: flex;
  gap: 6px;
  width: 300px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
  padding: 10px;
  z-index: 50;
}
.new-project__pop input {
  flex: 1; min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
}
.new-project__pop input:focus { outline: none; border-color: var(--blue); }
.new-project__pop button {
  flex-shrink: 0;
  border: none;
  background: var(--blue);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 0 14px;
  border-radius: var(--radius);
  cursor: pointer;
}
.new-project__pop button:hover { background: var(--blue-light); }

.cost-badge {
  border: 1px solid var(--orange);
  color: var(--orange);
  font-size: 16px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: var(--radius);
  white-space: nowrap;
}

/* デモ版バッジ（残り回数表示） */
.demo-badge {
  border: 1px solid var(--orange);
  background: #fff7ef;
  color: var(--orange);
  font-size: 14px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  white-space: nowrap;
}
.demo-badge b { font-weight: 700; }

.credit-badge {
  border: 1px solid var(--blue);
  background: var(--blue-dim);
  color: var(--blue);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  padding: 5px 12px;
  border-radius: var(--radius);
  white-space: nowrap;
  /* 表示専用：クリック不可（変更は右上メニューから） */
}
.credit-badge.low { border-color: #e0736b; background: #fdecea; color: #c0392b; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: #1a1a1a;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--border-light); }
.icon-btn svg { display: block; }

.avatar {
  background: var(--blue-dim);
  color: var(--blue);
  border-radius: 50%;
}
.avatar:hover { background: #d8e7fb; }

/* ===== Layout ===== */
.layout {
  --left-w: 280px;
  --right-w: 400px;
  flex: 1;
  display: grid;
  /* 縮む優先順位: ①生成履歴(右) → ②モデル(左) → ③編集(中央・最後)。
     中央に最小幅を持たせて最後まで保ち、右を最初に縮める。 */
  grid-template-columns: var(--left-w) 12px minmax(480px, 1fr) 12px minmax(0, var(--right-w));
  gap: 0;
  padding: 12px 16px 16px;
  align-items: stretch;
  width: 100%;
}

/* 列幅をドラッグで変更するつまみ */
.col-resizer {
  position: relative;
  align-self: stretch;
  cursor: col-resize;
  touch-action: none;
}
.col-resizer::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  border-radius: 2px;
  background: transparent;
  transition: background 0.15s;
}
.col-resizer:hover::before,
.col-resizer.dragging::before { background: var(--blue); }

.sidebar { display: flex; flex-direction: column; gap: 22px; }

/* 操作パネルは白カード */
.sidebar--left {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 20px;
}

/* ===== おまかせバー / 詳細設定 ===== */
/* モデル・画質を1枚のパネルにまとめ、状態で色を変えて
   「おまかせ中（青）」と「手動選択中（グレー）」をひと目で区別する。
   枠線の二重化を避けるため、囲いは背景色＋内側シャドウで表現し、
   中のカードは白地にして浮かせる。 */
.auto-group {
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: background 0.2s, box-shadow 0.2s;
}
.auto-group.is-auto {
  background: var(--blue-dim);
  box-shadow: inset 0 0 0 1.5px #bcd6f7;
}
.auto-group.is-manual {
  background: #f1f3f6;
  box-shadow: inset 0 0 0 1.5px #d9dde3;
}
.auto-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
}
.auto-bar__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.auto-bar__sub { font-size: 12px; color: var(--muted); }

/* おまかせ／手動 iOS風トグルスイッチ（ラベルは左、スイッチには文字なし） */
.ios-switch {
  position: relative;
  flex-shrink: 0;
  width: 62px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: #c7ccd3;
  cursor: pointer;
  transition: background 0.2s;
}
.ios-switch[aria-checked="true"] { background: var(--blue); }
.ios-switch__knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 30px;
  height: 30px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.ios-switch[aria-checked="true"] .ios-switch__knob { transform: translateX(26px); }
.auto-bar__info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.auto-bar__label { font-size: 16px; font-weight: 700; color: var(--text); }
.auto-bar__value { font-size: 13px; font-weight: 600; }
.auto-group.is-auto .auto-bar__value { color: var(--blue); }
.auto-group.is-manual .auto-bar__value { color: var(--text); }

/* おまかせ中の状態バッジ／手動中の戻すボタンは、同じ位置で同じ大きさに統一し押しやすくする */
.auto-bar__badge,
.auto-bar__toggle {
  flex-shrink: 0;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--blue);
  white-space: nowrap;
}
.auto-bar__badge {
  color: #fff;
  background: var(--blue);
}
.auto-bar__toggle {
  color: var(--blue);
  background: #fff;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.auto-bar__toggle:hover,
.auto-bar__toggle.active { background: var(--blue); color: #fff; }

#advancedSettings { display: flex; flex-direction: column; gap: 20px; padding: 14px; }
/* 内側のカードは白地にして、色付きパネルの上で浮かせる（枠線の二重化を防ぐ）。
   選択中は青ハイライトを残すため :has(input:checked) を除外する。 */
#advancedSettings .option-card { background: #fff; }
#advancedSettings .quality-option:not(:has(input:checked)) { background: #fff; }

/* ===== Fields / labels ===== */
.field { display: flex; flex-direction: column; gap: 10px; }
.field__label {
  font-size: 12px;
  font-weight: 700;
  color: var(--label);
}
/* 見出し横の補足（モデル＝AI種類 / 画質＝細かさ の違いを明示） */
.field__hint {
  font-size: 10px;
  font-weight: 400;
  color: var(--muted);
}

/* ===== Option cards (model / size) ===== */
.option-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.option {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.option input { position: absolute; opacity: 0; pointer-events: none; }
.option__name { font-size: 12px; font-weight: 600; color: var(--text); }
.option__tag { font-size: 10px; font-weight: 400; color: var(--muted); }

.option:hover { background: #f6f7f9; }
.option:has(input:checked) { background: var(--blue); }
.option:has(input:checked) .option__name { color: #fff; }
.option:has(input:checked) .option__tag { color: var(--on-blue); }

/* custom size inputs */
.size-custom {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 4px;
}
.size-input {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}
.size-input input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 12px;
  color: var(--text);
  padding: 4px 28px 4px 8px;
}
.size-input input:focus { outline: none; border-color: var(--blue); }
.size-input .px {
  position: absolute;
  right: 8px;
  font-size: 10px;
  color: var(--placeholder);
  pointer-events: none;
}
.size-custom__x { font-size: 12px; font-weight: 600; color: var(--text); }

/* ===== 画質セレクター ===== */
.quality-group { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.quality-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.quality-option input { position: absolute; opacity: 0; pointer-events: none; }
.quality-option .q-name { font-size: 12px; font-weight: 600; color: var(--text); }
.quality-option .q-cost { font-size: 10px; color: var(--muted); }
/* デモ版：最高画質は選べない（グレーアウト） */
.quality-option.is-disabled { opacity: 0.4; cursor: not-allowed; background: var(--border-light); }
.quality-option.is-disabled:hover { background: var(--border-light); border-color: var(--border); }
.quality-option:hover { background: #f6f7f9; }
.quality-option:has(input:checked) { background: var(--blue); border-color: var(--blue); }
.quality-option:has(input:checked) .q-name,
.quality-option:has(input:checked) .q-cost { color: #fff; }

/* 背景透過チェック */
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.check-row input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--blue); cursor: pointer; }

/* ===== Prompt ===== */
.prompt-wrap { position: relative; }
.prompt-wrap textarea {
  width: 100%;
  height: 150px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  padding: 12px 14px;
  resize: none;
}
.prompt-wrap textarea:focus { outline: none; border-color: var(--blue); }
.prompt-wrap textarea::placeholder { color: var(--placeholder); }
.prompt-count {
  position: absolute;
  right: 10px;
  bottom: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

/* ===== Cost block / pills ===== */
.cost-block { display: flex; flex-direction: column; gap: 8px; }
.cost-per { font-size: 12px; font-weight: 500; color: var(--muted); text-align: right; }

.pill-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pill {
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 4px 8px;
  white-space: nowrap;
}
.pill--clickable { cursor: pointer; }
.pill--clickable:hover { border-color: var(--blue); color: var(--blue); }
.pill--cost { color: var(--orange); border-color: var(--orange); }
.pill--solid { background: var(--border-light); color: #000; border-color: var(--border-light); }
.tokens { font-size: 10px; font-weight: 500; color: var(--muted); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  transition: opacity 0.15s, background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn--primary { background: var(--blue); color: var(--on-blue); }
.btn--primary:hover:not(:disabled) { background: #2f86e6; }

.btn--generate {
  width: 100%;
  height: 55px;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius);
  background: #ff9f1c;
  color: #fff;
}
.btn--generate:hover:not(:disabled) { background: #f08c00; }

.btn--download {
  padding: 12px 16px;
  font-size: 15px;
  border-radius: var(--radius-lg);
}

.btn--outline {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border-light);
  font-weight: 600;
  font-size: 13px;
  padding: 11px 0;
}
.btn--outline:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }

/* ===== Center column ===== */
/* 中央は「編集ツール（上）」と「作業スペース（下）」の2カードに分ける */
.center { display: flex; flex-direction: column; gap: 12px; }

/* 生成結果〜ダウンロードを白カードでまとめる */
.result-card {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

/* edit toolbar */
.edit-toolbar {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.edit-toolbar__head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.edit-title { font-size: 16px; font-weight: 700; color: var(--blue-light); }
.edit-desc { font-size: 12px; color: var(--muted); }

.tool-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tool-group { display: flex; gap: 6px; }
.tool-group + .tool-group { margin-left: auto; }

.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 64px;
  height: 31px;
  padding: 0 8px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--panel);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tool svg { display: block; flex-shrink: 0; }
.tool:hover { border-color: var(--blue); }
.tool.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.tool:disabled { opacity: 0.45; cursor: not-allowed; }
.tool--clear { margin-left: auto; color: var(--text); }

.brush-row { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 220px; }
.brush-label { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; }
.brush-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 4px 10px;
  min-width: 56px;
  text-align: center;
}

/* slider */
.slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--blue);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--blue);
}
.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--blue);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--blue);
}

.center__label { margin-top: 4px; }

/* canvas */
.canvas-frame {
  position: relative;
  border: 4px dashed var(--dashed);
  border-radius: var(--radius-lg);
  /* 白背景の画像でも縁が分かるよう、枠の内側は薄グレーにする */
  background: #eef1f5;
  min-height: 520px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 8px;
}
.canvas-frame.dragover {
  border-color: var(--blue);
  background: var(--blue-dim);
}
/* ×は破線枠の「外・白い余白の右上」に置く（枠内overflow:hiddenで隠れないように）。
   通常フローの要素にして、表示時だけ1行ぶんの高さを取り、点線枠を下げる。 */
.canvas-close {
  align-self: flex-end;   /* 白カード右上に寄せる */
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  transition: background 0.12s, transform 0.12s, border-color 0.12s;
}
.canvas-close:hover { background: #fdecea; color: #c0392b; border-color: #e0736b; transform: scale(1.08); }

/* 画像（編集可能エリア）の範囲を明示：枠線＋影で縁取りし、
   透過画像でも範囲が分かるよう下地に市松模様を敷く */
.canvas-stack {
  position: relative;
  display: inline-flex;
  max-width: 100%;
  max-height: 70vh;
  background:
    repeating-conic-gradient(#e7eaee 0% 25%, #ffffff 0% 50%) 0 0 / 20px 20px;
  box-shadow: 0 0 0 1px var(--border), 0 6px 18px rgba(0, 0, 0, 0.10);
  border-radius: 4px;
}
.canvas-stack img { display: block; max-width: 100%; max-height: 70vh; object-fit: contain; border-radius: 4px; }
.canvas-stack canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  opacity: 0.5; /* マスクはベタ塗り→表示だけ半透明にして下の画像を見せる */
}
.placeholder { color: var(--placeholder); font-size: 13px; text-align: center; padding: 60px 20px; cursor: pointer; }

/* ブラシ/消しゴムのサイズを示す円カーソル */
.brush-cursor {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 4;
  border: 2px solid rgba(255, 40, 40, 0.9);
  background: rgba(255, 40, 40, 0.2);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6) inset;
}
.brush-cursor--eraser {
  border: 2px dashed #555;
  background: rgba(255, 255, 255, 0.35);
}

/* result bar = メタピル（左）＋ 選択範囲DL（右）※Figma準拠 */
.result-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.result-meta { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
/* 選択/生成した画像のプロンプト（画像の上に表示して、選択時すぐ見えるようにする） */
.result-prompt {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--blue-dim);
  border: 1px solid #cfe0fb;
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  padding: 10px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.result-prompt::before {
  content: "プロンプト";
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 3px;
}
.result-dl-group { display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== Right column / history ===== */
.sidebar--right {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  /* 履歴パネルは画面内に固定し、リストだけを内部スクロールさせる */
  position: sticky;
  top: 12px;
  align-self: start;
  max-height: calc(100vh - 24px);
}
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}
/* 履歴の一括ダウンロード操作行 */
.history-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.history-selectall {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.history-bulk { padding: 6px 12px; font-size: 12px; }
.history-bulk:disabled { opacity: 0.4; cursor: not-allowed; }

.history-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.history-card__check {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  cursor: pointer;
  accent-color: var(--blue);
}
.history-card:hover { background: #f6f7f9; }
.history-card.active { border-color: var(--blue); background: var(--blue-dim); }
.history-card__thumb {
  width: 60px;
  height: 46px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border-light);
}
/* サムネの右にメタ情報（時刻・サイズ・DLボタン）を縦に並べる。幅は内容ぶんだけ。 */
.history-card__body { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex-shrink: 0; }
.history-card__time { font-size: 11px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-card__dim { font-size: 10px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-card__cost { color: var(--orange); font-weight: 700; }
/* 「画像をダウンロード」はサイズの下に固定（左揃え・常に同じ位置） */
.history-card__dl {
  align-self: flex-start;
  margin-top: 4px;
  background: var(--blue);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  text-decoration: none;
  white-space: nowrap;
}
.history-card__dl:hover { background: #2f86e6; }
/* 右側の余白：選択されたカードだけプロンプトを表示。長文で隠れる場合は
   上辺を固定したまま下方向にカードを伸ばして全文を表示する（クリップしない）。 */
.history-card__prompt {
  display: none;
  flex: 1;
  min-width: 0;
  align-self: flex-start;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  background: #fff;
  border: 1px solid #cfe0fb;
  border-radius: 6px;
  padding: 6px 8px;
  white-space: pre-wrap;
  word-break: break-word;
}
.history-card.active .history-card__prompt { display: block; }
.history-empty { font-size: 12px; color: var(--muted); text-align: center; padding: 30px 10px; }
.show-all { margin-top: 14px; width: 100%; }

/* ===== 設定モーダル ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

/* ===== ログイン（デモ）オーバーレイ ===== */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #e8f1fd, #f4f7fb);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}
.auth-card {
  width: min(360px, 100%);
  background: var(--panel);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.16);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.auth-logo { height: 44px; width: auto; object-fit: contain; margin: 0 auto 6px; }
.auth-lead { margin: 0; font-size: 16px; font-weight: 700; color: var(--text); }
.auth-note { margin: 0 0 8px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.auth-input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
  font-size: 14px;
  font-family: inherit;
}
.auth-input:focus { outline: none; border-color: var(--blue); }
.auth-btn {
  border: none;
  border-radius: var(--radius);
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}
.auth-btn:hover { background: var(--blue-light); }
.auth-btn--guest { background: #fff; color: var(--blue); border: 1px solid var(--blue); }
.auth-btn--guest:hover { background: var(--blue-dim); }
.auth-error { margin: 2px 0 0; font-size: 12px; color: #c0392b; }
.modal {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: min(540px, 100%);
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.22);
}
.modal__head { display: flex; align-items: center; justify-content: space-between; }
.modal__title { font-size: 16px; font-weight: 700; color: #000; }

/* モーダルのタブ（クレジット / 設定） */
.modal__tabs { display: flex; gap: 4px; }
.modal__tab {
  border: none;
  background: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  padding: 4px 4px 8px;
  margin-right: 10px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.modal__tab:hover { color: var(--text); }
.modal__tab.active { color: var(--blue); border-bottom-color: var(--blue); }
/* タブ切替でモーダルの高さが変わらないよう、高い方（クレジット）に合わせて最低高さを確保 */
.modal__panel { margin-top: 6px; min-height: 430px; }
.text-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
}
.text-input:focus { outline: none; border-color: var(--blue); }
.modal__sep { border: none; border-top: 1px solid var(--border-light); margin: 4px 0; }
.credit-balance { font-size: 28px; font-weight: 700; color: var(--blue); }
.month-usage { margin: 4px 0 0; font-size: 20px; font-weight: 700; color: var(--text); }
.charge-row { display: flex; gap: 10px; }
.charge-row .text-input { flex: 1; }
.charge-row .btn { padding: 10px 20px; font-size: 14px; white-space: nowrap; }
.charge-presets { display: flex; flex-wrap: wrap; gap: 8px; }
.charge-presets button {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.charge-presets button:hover { background: var(--blue-dim); border-color: var(--blue); color: var(--blue); }
.modal__hint { font-size: 12px; color: var(--text); word-break: break-all; }
.modal__note { font-size: 11px; color: var(--muted); line-height: 1.6; }

/* 課金履歴 / 使用履歴（タブ切替） */
.ledger { margin-top: 16px; }
.ledger__tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.ledger__tab {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.ledger__tab:hover { border-color: var(--blue); color: var(--blue); }
.ledger__tab.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.ledger__list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 168px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.ledger__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
}
.ledger__list li:last-child { border-bottom: none; }
.ledger__main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ledger__date { color: var(--muted); }
.ledger__note { font-size: 11px; color: var(--placeholder); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ledger__amt { font-weight: 700; white-space: nowrap; }
.ledger__amt--plus { color: #1f9d57; }
.ledger__amt--minus { color: #c0392b; }
.ledger__empty { padding: 14px; text-align: center; font-size: 13px; color: var(--muted); }

.modal__actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal__actions .btn { padding: 10px 20px; font-size: 14px; }

/* ===== Loading / toast ===== */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.78);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 6;
}
.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--border-light);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 12px; color: var(--muted); }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 11px 16px;
  font-size: 12px;
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s;
  pointer-events: none;
  z-index: 100;
  max-width: 360px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: #e0736b; color: #c0392b; }

/* ===== Responsive ===== */
/* ②段階目: 生成履歴(右)を下段にまわし、モデル(左)が縮む。編集(中央)は維持 */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, var(--left-w)) minmax(380px, 1fr); gap: 12px; }
  .col-resizer { display: none; }
  .sidebar--right { grid-column: 1 / -1; position: static; max-height: none; }
  .history-list { max-height: none; flex-direction: row; flex-wrap: wrap; overflow: visible; }
  .history-card { width: calc(50% - 6px); }
}
/* ③段階目: 最後に編集(中央)も1カラムに */
@media (max-width: 680px) {
  .topbar { padding: 0 20px; }
  .topbar__title { font-size: 15px; }
  .topbar__logo { height: 34px; }
  .layout { grid-template-columns: 1fr; padding: 16px; gap: 12px; }
  .history-card { width: 100%; }
}
