:root {
  --bg: #12151c;
  --bg2: #1a1f2b;
  --bg3: #232a39;
  --line: #2e3647;
  --fg: #e6e9ef;
  --muted: #97a0b3;
  --accent: #5b9dff;
  --accent2: #3d7de0;
  --danger: #ff6b6b;
  --ok: #4cd08a;
  --chip: #2b3346;
  --shadow: 0 8px 30px rgba(0,0,0,.45);
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
button { font-family: inherit; }
a { color: var(--accent); }

/* ---- ヘッダ ---- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 18px; background: var(--bg2);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .3px; white-space: nowrap; }
.brand .dot { color: var(--accent); }
.brand .trial {
  font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line);
  border-radius: 6px; padding: 1px 6px; margin-left: 4px; vertical-align: 2px;
}
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; border: 0; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; white-space: nowrap;
}
.tab:hover { background: var(--bg3); color: var(--fg); }
.tab.active { background: var(--accent2); color: #fff; }
/* スマホ幅ではタブをブランドの下の段に回す */
@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .tabs { width: 100%; }
  .tab { flex: 1; padding: 8px 6px; }
}

/* ---- 保存場所の説明帯 ---- */
.notice {
  padding: 8px 18px; font-size: 12.5px; color: var(--muted);
  background: var(--bg); border-bottom: 1px solid var(--line); text-align: center;
}
.notice a { margin-left: 6px; }
.notice.warn { color: #ffd28a; background: #2a2416; }

/* ---- 共通 ---- */
.view { padding: 18px; max-width: 1200px; margin: 0 auto; }
.hidden { display: none !important; }
.btn {
  background: var(--accent2); color: #fff; border: 0; border-radius: 8px;
  padding: 9px 16px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.btn:hover { background: var(--accent); }
.btn.ghost { background: var(--bg3); color: var(--fg); border: 1px solid var(--line); font-weight: 500; }
.btn.ghost:hover { border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid #5a2b2b; font-weight: 500; }
.btn.danger:hover { background: #3a1e1e; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
input, select, textarea {
  background: var(--bg); color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 14px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; width: 100%; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }
.field > span .req { color: var(--danger); }
.field > input, .field > select { width: 100%; }

/* ---- ツールバー ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.tb-left { display: flex; flex-direction: column; gap: 6px; }
.tb-checks { display: flex; gap: 12px; align-items: center; }
.tb-main { flex: 1; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tb-main .search { flex: 1; min-width: 200px; }
.toolbar .grow { flex: 1; }
.count { color: var(--muted); font-size: 12.5px; }

/* ---- プロンプトカード ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; transition: border-color .15s;
}
.card:hover { border-color: #3b475f; }
.card .thumb {
  aspect-ratio: 9 / 16; background: var(--bg3);
  display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px;
  cursor: pointer; overflow: hidden;
}
.card .thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.card .body { padding: 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card .title { font-weight: 600; font-size: 14.5px; display: flex; align-items: center; gap: 6px; }
.card .title .star { cursor: pointer; color: #56607a; }
.card .title .star.on { color: #ffcb52; }
.card .meta { color: var(--muted); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.badge { background: var(--chip); color: #c7cfdf; border-radius: 6px; padding: 1px 7px; font-size: 11.5px; }
.badge.video { background: #3a2b46; color: #e0b6ff; }
.badge.image { background: #2b3a46; color: #a6d5ff; }
.card .excerpt { color: #b7bfd0; font-size: 12.5px; max-height: 54px; overflow: hidden; }
.tags { display: flex; gap: 5px; flex-wrap: wrap; }
.tag { background: var(--chip); color: #aeb8cc; border-radius: 20px; padding: 1px 9px; font-size: 11px; }
.card .actions { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); }
.card .actions .grow { flex: 1; }

.empty { color: var(--muted); text-align: center; padding: 60px 0; grid-column: 1 / -1; }
.empty p { margin: 0 auto 16px; max-width: 30em; }

/* 参考画像OFF時はサムネイル領域ごと消してカードをコンパクトに */
.no-thumb .card .thumb { display: none; }

/* 詳細設定アコーディオン */
.accordion { border: 1px solid var(--line); border-radius: 8px; margin-top: 6px; background: var(--bg); }
.accordion > summary { cursor: pointer; padding: 9px 12px; color: var(--muted); font-size: 12.5px; list-style: none; user-select: none; }
.accordion > summary::-webkit-details-marker { display: none; }
.accordion > summary::before { content: '▸ '; }
.accordion[open] > summary::before { content: '▾ '; }
.accordion > summary:hover { color: var(--fg); }
.acc-body { padding: 6px 12px 10px; }

/* ---- モーダル ---- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex;
  align-items: flex-start; justify-content: center; padding: 30px 16px; z-index: 50; overflow: auto;
}
.modal {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  width: 100%; max-width: 560px; box-shadow: var(--shadow);
}
.modal .head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal .head h3 { margin: 0; font-size: 16px; }
.modal .body { padding: 18px; }
.modal .foot { display: flex; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); }
.row5 { display: grid; grid-template-columns: minmax(0,1fr) max-content minmax(0,1fr) max-content max-content; gap: 10px; align-items: end; }
.favbox { display: flex; align-items: center; gap: 4px; padding: 8px 0; white-space: nowrap; }
@media (max-width: 640px) { .row5 { grid-template-columns: 1fr 1fr; } }
.copybar { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }

/* ---- 画像 ---- */
.dropzone {
  border: 1px dashed var(--line); border-radius: 10px; padding: 14px; text-align: center;
  color: var(--muted); cursor: pointer; font-size: 12.5px;
}
.dropzone.drag { border-color: var(--accent); color: var(--fg); background: var(--bg3); }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.thumbs .t { position: relative; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.thumbs .t img { width: 100%; height: 100%; object-fit: cover; cursor: pointer; display: block; }
.thumbs .t .x {
  position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.65); color: #fff;
  border: 0; border-radius: 6px; width: 22px; height: 22px; cursor: pointer; line-height: 1;
}
.hint { color: var(--muted); font-size: 12px; margin: 6px 0; }

/* ---- データ ---- */
.bk-card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; max-width: 720px;
}
.bk-card h3 { margin: 0 0 6px; font-size: 15px; }
.bk-card p { color: var(--muted); margin: 4px 0 12px; font-size: 13px; }
.bk-card ul.plain { color: var(--muted); margin: 0 0 12px; padding-left: 20px; font-size: 13px; }
.bk-card .stats { color: var(--fg); margin-bottom: 0; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- フッター ---- */
.footer { text-align: center; padding: 24px 16px 40px; font-size: 12.5px; }
.footer a { color: var(--muted); }
.footer a:hover { color: var(--fg); }

/* ---- ギャラリー ---- */
.tb-right { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--bg3); color: var(--muted); border: 0; padding: 7px 12px; cursor: pointer; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent2); color: #fff; }
.gallery-grid { display: grid; gap: 8px; }
.gallery-grid.size-s { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
.gallery-grid.size-m { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.gallery-grid.size-l { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.gallery-cell { position: relative; aspect-ratio: 9 / 16; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); cursor: pointer; background: var(--bg3); }
.gallery-cell img { width: 100%; height: 100%; object-fit: contain; display: block; }
.gallery-cell .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 8px 5px; font-size: 11.5px;
  background: linear-gradient(transparent, rgba(0,0,0,.75)); color: #fff;
  opacity: 0; transition: opacity .15s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gallery-cell:hover .cap { opacity: 1; }
.gallery-cell:hover { border-color: var(--accent); }

/* ---- スライドショー ---- */
.slideshow { position: fixed; inset: 0; background: rgba(0,0,0,.93); z-index: 120; display: flex; align-items: center; justify-content: center; }
.slideshow img { max-width: 92vw; max-height: 82vh; border-radius: 8px; object-fit: contain; cursor: pointer; }
.slideshow .ss-cap { position: absolute; top: 20px; left: 0; right: 0; text-align: center; color: #e6e9ef; font-size: 15px; padding: 0 20px; }
.slideshow .ss-bar { position: absolute; bottom: 24px; display: flex; gap: 10px; align-items: center; }

/* ---- ライトボックス ---- */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex;
  align-items: center; justify-content: center; z-index: 100; cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }

/* ---- トースト ---- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); color: var(--fg); border: 1px solid var(--line);
  padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow);
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 200;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
#toast.err { border-color: var(--danger); color: #ffc3c3; }
