:root{
  --bg:#f7f4fb; --surface:#ffffff; --surface-alt:#f0ecf8; --border:#e1d9ee;
  --text:#221f2e; --text-muted:#6f6884;
  --accent:#b8305f; --accent-strong:#96234c; --accent-soft:#f6dbe4;
  --shadow: 0 1px 2px rgba(40,20,50,.06), 0 6px 20px rgba(40,20,50,.06);
  --danger:#c23b3b;
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#15121f; --surface:#1e1a2c; --surface-alt:#262038; --border:#372f4a;
    --text:#eee9f8; --text-muted:#9a91b3;
    --accent:#e8608e; --accent-strong:#f183a6; --accent-soft:#3a2333;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    --danger:#e06767;
  }
}
:root[data-theme="dark"]{
  --bg:#15121f; --surface:#1e1a2c; --surface-alt:#262038; --border:#372f4a;
  --text:#eee9f8; --text-muted:#9a91b3;
  --accent:#e8608e; --accent-strong:#f183a6; --accent-soft:#3a2333;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  --danger:#e06767;
}

*{ box-sizing:border-box; }
html,body{ margin:0; padding:0; }
body{
  background:var(--bg); color:var(--text);
  font-family:"Noto Sans JP","Hiragino Kaku Gothic ProN",sans-serif;
  min-height:100vh; -webkit-font-smoothing:antialiased;
}
.brand, h2, h3, h4{ font-family:"Zen Maru Gothic","Hiragino Maru Gothic ProN",sans-serif; }
::selection{ background:var(--accent-soft); }

.wrap{ max-width:1080px; margin:0 auto; padding:0 20px 80px; }

header.top{
  position:sticky; top:0; z-index:20;
  background:color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom:1px solid var(--border);
}
.top-inner{ max-width:1080px; margin:0 auto; padding:18px 20px; display:flex; align-items:center; justify-content:flex-start; gap:16px; flex-wrap:wrap; }
.brand{ font-size:22px; font-weight:900; letter-spacing:.02em; display:flex; align-items:center; gap:10px; text-align:left; margin-right:auto; }
.brand-mark{ display:inline-flex; align-items:center; justify-content:center; width:34px; height:34px; border-radius:10px; background:linear-gradient(155deg, var(--accent), var(--accent-strong)); font-size:17px; }
.count-pill{ font-size:12.5px; color:var(--text-muted); font-weight:500; background:var(--surface-alt); border:1px solid var(--border); padding:4px 10px; border-radius:999px; }
.header-actions{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.header-actions[hidden]{ display:none; }
button{ font-family:inherit; }
.btn{ border:1px solid var(--border); background:var(--surface); color:var(--text); padding:9px 16px; border-radius:10px; font-size:14px; font-weight:500; cursor:pointer; transition:transform .12s ease, border-color .12s ease, background .12s ease; }
.btn:hover{ border-color:var(--accent); }
.btn:active{ transform:scale(.97); }
.btn-primary{ background:linear-gradient(155deg, var(--accent), var(--accent-strong)); border:none; color:#fff; font-weight:700; box-shadow:0 4px 14px color-mix(in srgb, var(--accent) 45%, transparent); }
.btn-primary:hover{ filter:brightness(1.05); }
.btn-danger{ border-color:color-mix(in srgb, var(--danger) 55%, var(--border)); color:var(--danger); background:transparent; }
.btn-danger:hover{ border-color:var(--danger); background:color-mix(in srgb, var(--danger) 8%, transparent); }
.btn-ghost{ background:transparent; border-color:transparent; color:var(--text-muted); }
.btn-ghost:hover{ color:var(--text); background:var(--surface-alt); border-color:var(--border); }
.btn-sm{ padding:6px 12px; font-size:13px; border-radius:8px; }
.btn-icon-label{ display:flex; align-items:center; gap:6px; }

.toolbar{ margin-top:22px; display:flex; flex-direction:column; gap:12px; }
.search-row{ display:flex; gap:10px; flex-wrap:wrap; }
.search-box{ position:relative; flex:1 1 240px; min-width:200px; }
.search-box input{ width:100%; padding:11px 14px 11px 38px; border-radius:11px; border:1px solid var(--border); background:var(--surface); color:var(--text); font-size:14.5px; outline:none; }
.search-box input:focus{ border-color:var(--accent); }
.search-box svg{ position:absolute; left:12px; top:50%; transform:translateY(-50%); opacity:.5; }
select{ font-family:inherit; }
select.sort-select{ padding:11px 14px; border-radius:11px; border:1px solid var(--border); background:var(--surface); color:var(--text); font-size:14px; outline:none; cursor:pointer; }
.tag-filter-row{ display:flex; flex-wrap:wrap; gap:8px; }
.tag-chip{ padding:6px 13px; border-radius:999px; border:1px solid var(--border); background:var(--surface); color:var(--text-muted); font-size:13px; cursor:pointer; user-select:none; transition:all .12s ease; }
.tag-chip:hover{ border-color:var(--accent); color:var(--text); }
.tag-chip.active{ background:var(--accent-soft); border-color:var(--accent); color:var(--accent-strong); font-weight:700; }
.clear-filters{ font-size:12.5px; color:var(--text-muted); text-decoration:underline; cursor:pointer; background:none; border:none; padding:6px 4px;}
.clear-filters:hover{ color:var(--accent); }

.grid{ margin-top:22px; display:grid; grid-template-columns:repeat(auto-fill, minmax(168px,1fr)); gap:16px; }
.card{ background:var(--surface); border:1px solid var(--border); border-radius:14px; overflow:hidden; cursor:pointer; text-align:left; padding:0; transition:transform .15s ease, box-shadow .15s ease, border-color .15s ease; display:flex; flex-direction:column; }
.card:hover{ transform:translateY(-3px); box-shadow:var(--shadow); border-color:var(--accent); }
.thumb{ width:100%; aspect-ratio:3/4; background:var(--surface-alt); display:flex; align-items:center; justify-content:center; overflow:hidden; }
.thumb img{ width:100%; height:100%; display:block; }
.thumb .placeholder{ font-size:34px; opacity:.35; }
.card-body{ padding:10px 12px 13px; display:flex; flex-direction:column; gap:6px; flex:1; }
.card-name{ font-weight:700; font-size:14.5px; line-height:1.3; word-break:break-word; }
.card-model{ font-size:11px; color:var(--text-muted); }
.card-tags{ display:flex; flex-wrap:wrap; gap:4px; margin-top:auto; }
.mini-tag{ font-size:11px; padding:2px 8px; border-radius:999px; background:var(--surface-alt); color:var(--text-muted); border:1px solid var(--border); }
.card-tags .mini-tag{ max-width:100%; box-sizing:border-box; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:10.5px; padding:2px 7px; }

.empty{ margin-top:60px; text-align:center; color:var(--text-muted); display:flex; flex-direction:column; align-items:center; gap:14px; }
.empty .icon{ font-size:44px; opacity:.5; }
.empty p{ margin:0; font-size:14.5px; line-height:1.7; }

.overlay{ position:fixed; inset:0; background:rgba(10,8,16,.55); display:flex; align-items:flex-start; justify-content:center; padding:min(6vh,48px) 16px; z-index:100; overflow-y:auto; opacity:0; pointer-events:none; transition:opacity .18s ease; }
.overlay.open{ opacity:1; pointer-events:auto; }
.modal{ background:var(--surface); border-radius:18px; width:100%; max-width:680px; border:1px solid var(--border); box-shadow:var(--shadow); transform:translateY(8px); transition:transform .18s ease; max-height:90vh; display:flex; flex-direction:column; }
.overlay.open .modal{ transform:translateY(0); }
.modal-head{ display:flex; align-items:center; justify-content:space-between; padding:18px 20px; border-bottom:1px solid var(--border); flex-shrink:0; }
.modal-head h2{ margin:0; font-size:18px; font-weight:700; }
.modal-body{ padding:20px; overflow-y:auto; }
.modal-foot{ padding:14px 20px; border-top:1px solid var(--border); display:flex; justify-content:flex-end; gap:10px; flex-shrink:0; }
.icon-btn{ background:none; border:none; color:var(--text-muted); cursor:pointer; font-size:20px; line-height:1; padding:4px; border-radius:8px; }
.icon-btn:hover{ color:var(--text); background:var(--surface-alt); }

.form-section{ margin-bottom:26px; padding-bottom:22px; border-bottom:1px solid var(--border); }
.form-section:last-child{ border-bottom:none; margin-bottom:0; padding-bottom:0; }
.form-section h3{ margin:0 0 14px; font-size:14px; font-weight:700; color:var(--accent-strong); display:flex; align-items:center; gap:7px; }

.field{ margin-bottom:16px; }
.field:last-child{ margin-bottom:0; }
.field label{ display:block; font-size:13px; font-weight:700; margin-bottom:6px; color:var(--text-muted); }
.field input[type=text], .field input[type=number], .field textarea, .field select{
  width:100%; padding:10px 12px; border-radius:10px; border:1px solid var(--border);
  background:var(--surface-alt); color:var(--text); font-size:14px; outline:none;
  font-family:inherit; resize:vertical;
}
.field input:focus, .field textarea:focus, .field select:focus{ border-color:var(--accent); }
.field textarea{ min-height:70px; line-height:1.6; }
.field-hint{ font-size:12px; color:var(--text-muted); margin-top:6px; line-height:1.5; }
.char-counter{ font-size:11.5px; color:var(--text-muted); text-align:right; margin-top:4px; font-variant-numeric:tabular-nums; }
.char-counter.over-limit{ color:var(--danger); font-weight:700; }

.row2{ display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.row3{ display:grid; grid-template-columns:1fr 1fr 1fr; gap:12px; }
@media (max-width:520px){ .row3{ grid-template-columns:1fr 1fr; } }

.thumb-picker{ display:flex; gap:14px; align-items:center; flex-wrap:wrap; }
.thumb-preview{ width:96px; height:128px; border-radius:10px; overflow:hidden; flex-shrink:0; background:var(--surface-alt); border:1px solid var(--border); display:flex; align-items:center; justify-content:center; position:relative; }
.thumb-preview img{ width:100%; height:100%; display:block; }
.thumb-preview .placeholder{ font-size:26px; opacity:.35; }
.thumb-picker-actions{ display:flex; flex-direction:column; gap:8px; }
input[type=file]{ display:none; }

.chip-editor{ display:flex; flex-wrap:wrap; gap:6px; padding:8px; border-radius:10px; border:1px solid var(--border); background:var(--surface-alt); }
.chip-editor-chip{ display:flex; align-items:center; gap:5px; background:var(--accent-soft); color:var(--accent-strong); border-radius:999px; padding:4px 6px 4px 11px; font-size:13px; font-weight:600; }
.chip-editor-chip button{ background:none; border:none; color:var(--accent-strong); cursor:pointer; font-size:14px; line-height:1; padding:2px 4px; opacity:.7; }
.chip-editor-chip button:hover{ opacity:1; }
.chip-editor input{ flex:1 1 100px; min-width:100px; border:none; background:none; outline:none; color:var(--text); font-size:14px; padding:6px 4px; font-family:inherit; }

/* LoRA rows */
.lora-list{ display:flex; flex-direction:column; gap:8px; }
.lora-row{ display:flex; gap:8px; align-items:center; }
.lora-row input[type=text]{ flex:1; }
.lora-row input.strength{ width:76px; flex:none; }
.lora-row .remove-row{ flex:none; background:none; border:none; color:var(--text-muted); cursor:pointer; font-size:16px; padding:6px; border-radius:8px; }
.lora-row .remove-row:hover{ color:var(--danger); background:var(--surface-alt); }
.add-row-btn{ align-self:flex-start; font-size:12.5px; color:var(--accent); background:none; border:none; cursor:pointer; font-weight:700; padding:4px 2px; }
.add-row-btn:hover{ text-decoration:underline; }

.copy-btn{ font-size:11.5px; color:var(--accent); background:none; border:none; cursor:pointer; font-weight:700; padding:2px 4px; }
.copy-btn:hover{ text-decoration:underline; }

/* ---------- プロンプト辞典ピッカー（フォーム内） ---------- */
.dict-picker{ display:flex; flex-direction:column; gap:10px; }
.dict-target-row{ display:flex; gap:16px; flex-wrap:wrap; font-size:13px; color:var(--text-muted); }
.dict-target-row label{ display:flex; align-items:center; gap:6px; cursor:pointer; }
.dict-target-row input[type=radio]{ accent-color:var(--accent); }
.dict-results{ display:flex; flex-direction:column; gap:6px; margin-top:4px; max-height:280px; overflow-y:auto; }
.dict-item{ display:flex; align-items:center; justify-content:space-between; gap:10px; background:var(--surface-alt); border:1px solid var(--border); border-radius:10px; padding:8px 10px; }
.dict-item-text{ display:flex; flex-direction:column; gap:2px; min-width:0; }
.dict-item-ja{ font-size:13.5px; font-weight:600; word-break:break-word; }
.dict-item-code{ font-size:11.5px; color:var(--text-muted); font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; word-break:break-word; }
.dict-empty-hint{ font-size:12.5px; color:var(--text-muted); padding:10px 4px; }

/* ---------- プロンプト辞典ページ（チートシート） ---------- */
.cheatsheet-head{ margin-top:22px; }
.cheatsheet-head h2{ margin:0 0 6px; font-size:20px; }
.cheatsheet-source{ margin:0; font-size:12.5px; color:var(--text-muted); line-height:1.6; }
.cheatsheet-source a{ color:var(--accent); }
.dict-grid{ margin-top:22px; display:grid; grid-template-columns:repeat(auto-fill, minmax(200px,1fr)); gap:12px; }
.dict-card{ background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:12px 14px; display:flex; flex-direction:column; gap:4px; }
.dict-card-ja{ font-weight:700; font-size:14px; }
.dict-card-code{ font-size:12px; color:var(--text-muted); font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; word-break:break-word; }
.dict-card .copy-btn{ align-self:flex-start; margin-top:4px; }

/* detail view */
.detail-top{ display:flex; gap:18px; }
.detail-thumb{ width:150px; height:200px; border-radius:12px; overflow:hidden; flex-shrink:0; background:var(--surface-alt); border:1px solid var(--border); }
.detail-thumb img{ width:100%; height:100%; display:block; }
.detail-meta{ flex:1; min-width:0; }
.detail-meta h3{ margin:0 0 8px; font-size:19px; }
.detail-tags{ display:flex; flex-wrap:wrap; gap:6px; margin-bottom:10px; }
.detail-date{ font-size:12.5px; color:var(--text-muted); }
.detail-section{ margin-top:20px; }
.detail-section h4{ margin:0 0 8px; font-size:12.5px; font-weight:700; color:var(--text-muted); display:flex; align-items:center; justify-content:space-between; }
.detail-pre{ background:var(--surface-alt); border:1px solid var(--border); border-radius:10px; padding:12px 14px; font-size:13.5px; line-height:1.7; white-space:pre-wrap; word-break:break-word; color:var(--text); max-height:160px; overflow-y:auto; }
.detail-pre.empty-note{ color:var(--text-muted); font-style:italic; }

/* アコーディオン（プロンプト・ネガティブプロンプト） */
.detail-accordion summary{ cursor:pointer; list-style:none; display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:8px; }
.detail-accordion summary::-webkit-details-marker{ display:none; }
.accordion-label{ font-size:12.5px; font-weight:700; color:var(--text-muted); display:inline-flex; align-items:center; gap:6px; }
.accordion-label::before{ content:"▸"; display:inline-block; font-size:11px; transition:transform .15s ease; }
.detail-accordion[open] .accordion-label::before{ transform:rotate(90deg); }
.detail-accordion .detail-pre{ margin-top:0; }
.prompt-breakdown{ margin-top:10px; }
.prompt-breakdown summary{ margin-bottom:0; }
.prompt-breakdown[open] summary{ margin-bottom:8px; }

/* プロンプトのカテゴリ別内訳（プロンプト辞典と照合して自動分類） */
.prompt-groups{ display:flex; flex-direction:column; gap:10px; margin-top:10px; }
.prompt-group{ background:var(--surface-alt); border:1px solid var(--border); border-radius:10px; padding:10px 12px; }
.prompt-group-title{ font-size:11.5px; font-weight:700; color:var(--accent-strong); margin-bottom:6px; }
.prompt-group-tags{ display:flex; flex-wrap:wrap; gap:5px; }
.prompt-group-tags .mini-tag{ background:var(--surface); }

/* 関連キャラクター（親子関係） */
.relation-row{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin-bottom:8px; }
.relation-row:last-child{ margin-bottom:0; }
.relation-label{ font-size:12px; color:var(--text-muted); font-weight:700; flex:none; }
.relation-chip-list{ display:flex; flex-wrap:wrap; gap:6px; }
.relation-link{ font-family:inherit; cursor:pointer; }
.relation-link:hover{ border-color:var(--accent); color:var(--accent-strong); }

.settings-grid{ display:grid; grid-template-columns:1fr 1fr; gap:10px 18px; }
.settings-grid .item{ font-size:13px; }
.settings-grid .item .k{ color:var(--text-muted); font-size:11.5px; margin-bottom:2px; }
.settings-grid .item .v{ font-weight:600; word-break:break-word; }
.lora-chip-list{ display:flex; flex-wrap:wrap; gap:6px; }
.lora-chip{ font-size:12px; padding:3px 10px; border-radius:999px; background:var(--surface); border:1px solid var(--border); color:var(--text); }

.confirm-overlay{ position:fixed; inset:0; background:rgba(10,8,16,.55); z-index:200; display:flex; align-items:center; justify-content:center; padding:20px; opacity:0; pointer-events:none; transition:opacity .15s ease; }
.confirm-overlay.open{ opacity:1; pointer-events:auto; }
.confirm-box{ background:var(--surface); border:1px solid var(--border); border-radius:16px; padding:22px; max-width:340px; width:100%; box-shadow:var(--shadow); }
.confirm-box p{ margin:0 0 18px; font-size:14.5px; line-height:1.6; }
.confirm-actions{ display:flex; justify-content:flex-end; gap:10px; }

.toast{ position:fixed; bottom:24px; left:50%; transform:translateX(-50%) translateY(20px); background:var(--text); color:var(--bg); padding:11px 20px; border-radius:999px; font-size:13.5px; font-weight:600; opacity:0; pointer-events:none; transition:opacity .2s ease, transform .2s ease; z-index:300; }
.toast.show{ opacity:1; transform:translateX(-50%) translateY(0); }

/* ---------- 画像クロップ（位置・拡大調整）モーダル ---------- */
/* G:\Claude\image-fit-handoff を参考に移植 */
.crop-backdrop{ position:fixed; inset:0; background:rgba(10,8,16,.65); display:flex; align-items:center; justify-content:center; padding:20px; z-index:400; opacity:0; pointer-events:none; transition:opacity .15s ease; }
.crop-backdrop.open{ opacity:1; pointer-events:auto; }
.crop-modal{ width:100%; max-width:360px; background:var(--surface); border:1px solid var(--border); border-radius:20px; padding:20px; display:flex; flex-direction:column; gap:16px; box-shadow:var(--shadow); }
.crop-modal-head{ display:flex; justify-content:space-between; align-items:center; font-size:14px; font-weight:700; }
.crop-frame{ position:relative; width:100%; aspect-ratio:3/4; margin:0 auto; overflow:hidden; border-radius:12px; background:var(--surface-alt); cursor:grab; touch-action:none; }
.crop-frame:active{ cursor:grabbing; }
.crop-frame img{ width:100%; height:100%; display:block; -webkit-user-drag:none; user-select:none; pointer-events:none; }
.crop-adjust{ display:flex; flex-direction:column; gap:10px; }
.crop-adjust-row{ display:flex; align-items:center; gap:8px; font-size:12px; color:var(--text-muted); }
.crop-adjust-row input[type=range]{ flex:1; min-width:90px; accent-color:var(--accent); }
.crop-adjust-value{ flex:none; width:42px; text-align:right; font-variant-numeric:tabular-nums; }
.crop-reset-btn{ align-self:flex-start; padding:6px 10px; border:1px solid var(--border); border-radius:10px; background:var(--surface); color:var(--text-muted); font-size:11.5px; cursor:pointer; }
.crop-reset-btn:hover{ border-color:var(--accent); color:var(--accent); }
.crop-done-btn{ width:100%; padding:12px; border:none; border-radius:999px; background:linear-gradient(155deg, var(--accent), var(--accent-strong)); color:#fff; font-size:14px; font-weight:700; cursor:pointer; }
.crop-done-btn:hover{ filter:brightness(1.05); }

@media (max-width:480px){
  .detail-top{ flex-direction:column; }
  .detail-thumb{ width:120px; height:160px; }
  .row2, .row3, .settings-grid{ grid-template-columns:1fr; }
  .crop-modal{ padding:16px; max-width:none; }
}

/* ---------- モバイル：書き出し/読み込みボタンはアイコンのみ ---------- */
@media (max-width:600px){
  .io-btn .btn-label{ display:none; }
  .io-btn{ padding:9px 11px; }
}
