:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #d9dce1;
  --text: #24292f;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --warn-bg: #fff7e6;
  --warn-border: #f5c26b;
  --ok: #16a34a;
  --warn: #d97706;
  --over: #dc2626;
  --selected: #e8f0fe;
  --off: #9ca3af;
  --tag-color: #888;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 8px; }
h2 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code, pre { font-family: Consolas, "Courier New", monospace; }
input[type=text], input[type=number], textarea, select {
  font: inherit; padding: 5px 7px; border: 1px solid var(--border); border-radius: 4px; background: #fff; color: var(--text);
}
textarea { width: 100%; resize: vertical; }
input.wide { width: 100%; }
label.field { display: block; margin-top: 10px; }
label.field input { margin-left: 8px; width: 120px; }

/* ---------- iPentec 共通ヘッダ・フッタ (PngInfoWeb / WD-Tagger と同じ構成) ---------- */
.TopBar { display: flow-root; text-align: left; width: 100%; margin: 0 auto; background: #fff; border-bottom: 1px solid #E0E0E0; } /* flow-root でロゴの margin が body 側に抜ける (相殺) のを防ぐ */
.TopBarLogo { margin: 0.6rem 2rem 0.4rem 2rem; width: 9.8rem; }
.TopBarLogo img {display: block; width: 100%; height: auto; }
.BottomBar { width: 100%; margin: 24px auto 0; background-color: #F1F1F1; padding-top: 36px; padding-bottom: 16px; }
.BottomBarContentFrame { padding: 8px 5%; font-size: 12px; text-align: right; }
.FooterLinkFrame { color: #616161; display: block; }
.FooterLinkFrameColumn { flex: 1; text-align: left; }
.FooterLinkFrameColumnTitle { font-weight: 600; font-size: 1.0rem; }
.FooterLinkFrameColumnLink { font-size: 0.8rem; margin: 1.25rem 0; }
.FooterLinkFrameColumnLink a:link, .FooterLinkFrameColumnLink a:visited, .FooterLinkFrameColumnLink a:active { color: #616161; }
.FooterLinkFrameColumnLink a:hover { color: #616161; text-decoration: underline; }
.CopyRightFrame { margin: 0 1rem 0 0; font-size: 0.6rem; text-align: right; }
.CopyRightLogo { display: inline-block; width: 7.8rem; }
.CopyRightLogo img { display: block; width: 100%; height: auto; }
@media (min-width: 480px) { .FooterLinkFrame { display: flex; } }

.app-header {
  display: flex; align-items: center; gap: 24px; padding: 8px 16px;
  background: #1f2937; color: #fff;
}
.app-header .brand { color: #fff; font-weight: 600; font-size: 16px; }
.app-header nav a { color: #d1d5db; margin-right: 16px; }
.app-header nav a:hover { color: #fff; }
.app-main { padding: 16px; }
body.editor-page .app-main { padding: 8px 12px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 12px; flex-wrap: wrap; }
.page-head .meta span { margin-right: 12px; color: var(--muted); }
.page-head .actions { display: flex; gap: 8px; align-items: center; }
.crumbs { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.inline-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
form.inline { display: inline; }

.btn {
  display: inline-block; padding: 5px 12px; border: 1px solid var(--border); border-radius: 4px;
  background: #fff; color: var(--text); cursor: pointer; font: inherit; line-height: 1.4; white-space: nowrap;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--danger); border-color: #fca5a5; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.tiny { padding: 0 5px; font-size: 11px; line-height: 1.5; }

.alert { padding: 8px 12px; border-radius: 4px; margin-bottom: 12px; }
.alert.error { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }
.alert.info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e3a8a; }
.alert.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: #7c2d12; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px; margin-bottom: 14px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: top; }
.table th { background: #f9fafb; font-weight: 600; }
.table.kv th { width: 220px; }
.table.roles input[type=text] { width: 100%; }
.table.roles td:nth-child(1) { width: 120px; }
.table.roles td:nth-child(2) { width: 140px; }
.table.roles td:nth-child(3) { width: 60px; }
.table.roles td:nth-child(5) { width: 50px; text-align: center; }
.table.blocks tr.disabled { color: var(--off); }
.table.blocks td.en { width: 40%; }
.table.blocks td.ja { width: 30%; }
.table .thumbs img { height: 48px; margin-right: 4px; border-radius: 3px; }
.table .actions { white-space: nowrap; }
.table .actions .btn { margin-right: 4px; }

.tag {
  display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 10px; margin-right: 3px; line-height: 1.6;
  color: #fff; background: var(--tag-color);
}
.badge { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 3px; margin-right: 3px; background: #e5e7eb; color: #374151; }
.badge.changed { background: #fef3c7; color: #92400e; }
.badge.added { background: #dcfce7; color: #166534; }
.badge.removed { background: #fee2e2; color: #991b1b; }
.badge.toggled { background: #e0e7ff; color: #3730a3; }
.badge.moved { background: #f3e8ff; color: #6b21a8; }
.badge.off { background: #e5e7eb; color: #6b7280; }

.output-text { white-space: pre-wrap; word-break: break-word; background: #f9fafb; border: 1px solid var(--border); border-radius: 4px; padding: 8px; font-family: inherit; margin: 0 0 8px; max-height: 40vh; overflow: auto; }

/* ---------- landing / workspace ---------- */
.app-header .grow { flex: 1; }
.app-header .header-btn { background: transparent; color: #d1d5db; border-color: #4b5563; }
.app-header .header-btn:hover { color: #fff; background: #374151; }
.landing { max-width: 760px; margin: 24px auto; }
.landing h1 { font-size: 28px; }
.landing .lead { font-size: 15px; margin-bottom: 12px; }
.landing .features { margin: 0 0 20px; padding-left: 20px; }
.landing .features li { margin-bottom: 4px; }
.landing-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 20px; }
.btn.large { padding: 10px 20px; font-size: 15px; }
.create-form { display: flex; flex-direction: column; gap: 8px; }
.create-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.turnstile-status:empty { display: none; }
.landing-note h2 { margin-bottom: 6px; }
.entry-box { margin-top: 16px; }
.entry-box.small { font-size: 12px; }
.entry-url { display: flex; gap: 6px; align-items: center; margin: 6px 0; }
.entry-url input { flex: 1; font-family: Consolas, monospace; font-size: 12px; background: #fff; }

/* ---------- prompt list ---------- */
.prompt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.prompt-card { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; display: flex; flex-direction: column; }
.prompt-card .thumb { display: block; height: 150px; background: #e5e7eb; display: flex; align-items: center; justify-content: center; }
.prompt-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.prompt-card .no-image { color: var(--muted); }
.prompt-card .body { padding: 8px 10px; }
.prompt-card .title { font-weight: 600; display: block; margin-bottom: 4px; }
.prompt-card .meta { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.prompt-card .meta span { margin-right: 8px; }
.prompt-card .actions { display: flex; gap: 4px; align-items: center; }

/* ---------- image list ---------- */
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.image-card { display: block; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; color: var(--text); }
.image-card:hover { text-decoration: none; border-color: var(--primary); }
.image-card.highlight { outline: 3px solid var(--primary); }
.image-card img { width: 100%; height: 150px; object-fit: cover; display: block; background: #e5e7eb; }
.image-card .caption { padding: 6px 8px; font-size: 12px; }
.image-card .title { font-weight: 600; }
.image-card .meta { color: var(--muted); }
.image-card .note { margin-top: 2px; }

/* ---------- compare ---------- */
.compare-select { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.compare-select label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.compare-select select { min-width: 300px; }
.compare-heads { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.compare-heads .thumbs img { height: 64px; margin-right: 4px; border-radius: 3px; }
.table.diff td.status { width: 100px; white-space: nowrap; }
.table.diff td.cell { width: 45%; }
.table.diff .block .tags { margin-bottom: 2px; }
.table.diff .block .ord { color: var(--muted); font-size: 11px; margin-right: 4px; }
.table.diff .block .ja { color: var(--muted); font-size: 12px; }
.table.diff .block.off { color: var(--off); }
.table.diff tr.diff-changed td.cell { background: #fffbeb; }
.table.diff tr.diff-added td.cell:last-child { background: #f0fdf4; }
.table.diff tr.diff-removed td.cell:nth-child(2) { background: #fef2f2; }
.table.diff tr.diff-toggled td.cell { background: #eef2ff; }
.table.diff tr.diff-moved td.cell { background: #faf5ff; }

/* ---------- editor ---------- */
.editor { display: flex; flex-direction: column; gap: 8px; }
.editor-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.editor-top .title-input { font-size: 16px; font-weight: 600; min-width: 260px; }
.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; flex: 1; }
.toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.toolbar .grow, .row .grow, .col-head .grow { flex: 1; }
.view-mode label { margin-right: 6px; }
.save-status { color: var(--muted); font-size: 12px; }
.save-status.dirty { color: var(--warn); }
.save-status.error { color: var(--danger); }

.editor-body { display: grid; grid-template-columns: minmax(520px, 1.4fr) minmax(380px, 1fr); gap: 8px; min-height: 0; }
.col-left, .col-center { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; overflow: auto; min-height: 40vh; max-height: 72vh; }

/* 出力プレビュー (段組みの下に全幅で配置) */
.editor-output { display: grid; grid-template-columns: 1fr 340px; gap: 8px; }
.output-main, .output-side { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; }
.output-main .output-text { max-height: 30vh; }
.output-main .actions { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.gauge-row .sep { width: 1px; height: 16px; background: var(--border); margin: 0 4px; }
.gauge-row .gauge { max-width: 320px; }
.col-head { font-weight: 600; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.hint { font-size: 12px; margin-top: 6px; }

.block-list { list-style: none; margin: 0; padding: 0; }
.block-list li.block {
  display: flex; gap: 6px; align-items: flex-start; padding: 6px 6px; border: 1px solid transparent; border-radius: 4px; margin-bottom: 4px;
  background: #fafafa; cursor: pointer;
}
.block-list li.block:hover { border-color: var(--border); }
.block-list li.block.selected { background: var(--selected); border-color: #93c5fd; }
.block-list li.block.off .content { color: var(--off); text-decoration: line-through; }
.block-list li.block.drag-over-top { box-shadow: 0 -3px 0 var(--primary); }
.block-list li.block.drag-over-bottom { box-shadow: 0 3px 0 var(--primary); }
.block-list li.block.dragging { opacity: .4; }
/* 並べ替えハンドル: ここだけがドラッグ対象。
   点模様は当初どおり左上の小さい表示にし、押せる範囲だけを行の高さいっぱい・幅 24px に広げる
   (負の margin で行の余白まで広げ、同じ分の padding で点の位置を元に戻す) */
.block-list .handle {
  cursor: grab; color: var(--muted); user-select: none; -webkit-user-select: none;
  align-self: stretch; flex: 0 0 24px;
  margin: -6px 0 -6px -6px; padding: 7px 0 0 6px;
  border-radius: 4px 0 0 4px;
}
.block-list .handle:hover { color: var(--text); background: rgba(0, 0, 0, .06); }
.block-list .handle:active { cursor: grabbing; }
/* 本文はドラッグで文字選択できる */
.block-list li.block .content { user-select: text; -webkit-user-select: text; cursor: text; }
.block-list li.block .content .tag, .block-list li.block .content .fwd { cursor: default; }
.block-list .ord { color: var(--muted); font-size: 11px; width: 18px; text-align: right; padding-top: 2px; }
.block-list .content { flex: 1; min-width: 0; }
.block-list .label { font-weight: 600; word-break: break-word; }
.block-list .sub { font-size: 12px; color: var(--muted); word-break: break-word; margin-top: 2px; }
.block-list .sub-row { display: flex; gap: 10px; align-items: flex-start; }
.block-list .sub-row .sub { flex: 1 1 0; min-width: 0; }
.block-list .sub-row .sub.en { color: var(--text); }
.block-list .sub-row .sub.ja { border-left: 1px solid var(--border); padding-left: 10px; }
.block-list .sub.stale { color: var(--warn); }
.block-list .tags { margin-top: 3px; }
.fwd { color: var(--warn); font-size: 11px; border: 1px solid var(--warn); border-radius: 3px; padding: 0 3px; margin-right: 4px; cursor: help; }

.detail-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.detail-head .ord { font-weight: 600; }
.detail label.lbl { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 3px; }
.detail textarea.en { font-size: 15px; line-height: 1.5; }
.detail .ja-box { background: #f9fafb; border: 1px solid var(--border); border-radius: 4px; padding: 8px; min-height: 40px; }
.detail .ja-box.stale { border-color: var(--warn-border); background: var(--warn-bg); }
.detail .stale-mark { display: none; color: var(--warn); font-size: 12px; margin-left: 6px; }
.detail .ja-box.stale .stale-mark { display: inline; }
.detail .roles { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.detail .roles label { display: inline-flex; align-items: center; gap: 3px; }
.detail .row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.detail fieldset { border: 1px solid var(--border); border-radius: 4px; margin: 12px 0 0; padding: 8px 10px; }
.detail fieldset legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.candidate { border: 1px solid var(--border); border-radius: 4px; padding: 6px 8px; margin-top: 6px; background: #fafafa; }
.candidate .nuance { font-size: 12px; color: var(--muted); margin-top: 3px; }
.candidate textarea { margin-top: 4px; }
.candidate .row { margin-top: 4px; }

.gauge-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 12px; }
.gauge { flex: 1; height: 10px; background: #e5e7eb; border-radius: 5px; overflow: hidden; }
.gauge-bar { height: 100%; width: 0; background: var(--ok); transition: width .2s; }
.gauge-bar.warn { background: var(--warn); }
.gauge-bar.over { background: var(--over); }
.warnings { margin-bottom: 10px; }
.warning { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 4px; padding: 4px 8px; font-size: 12px; margin-bottom: 4px; cursor: pointer; }
.warning:hover { filter: brightness(.97); }

.glossary-list { font-size: 12px; margin-bottom: 6px; max-height: 150px; overflow: auto; }
.glossary-list .gl { display: flex; gap: 6px; align-items: center; padding: 2px 0; border-bottom: 1px dashed var(--border); }
.glossary-list .gl .ja { flex: 1; }
.glossary-list .gl .en { flex: 1; color: var(--muted); }
.glossary-add { display: flex; gap: 4px; }
.glossary-add input { flex: 1; min-width: 0; }

.editor-history { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; min-height: 150px; max-height: 260px; display: flex; flex-direction: column; }
.history { display: flex; gap: 8px; overflow-x: auto; flex: 1; padding-bottom: 4px; }
.vcard { flex: 0 0 240px; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; background: #fafafa; display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.vcard.base { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.vcard.highlight { background: #fef9c3; }
.vcard.drag-over { background: #e0f2fe; border-color: var(--primary); }
.vcard .vhead { display: flex; gap: 6px; align-items: center; font-weight: 600; }
.vcard .vhead .reason { font-weight: normal; color: var(--muted); }
.vcard .memo { min-height: 16px; cursor: text; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.vcard .memo:empty::before { content: "メモを追加..."; color: var(--muted); }
.vcard .thumbs { display: flex; gap: 4px; flex-wrap: wrap; }
.vcard .thumbs .img { position: relative; }
.vcard .thumbs img { height: 56px; border-radius: 3px; display: block; cursor: pointer; }
.vcard .thumbs .img .ops { position: absolute; right: 0; top: 0; display: none; gap: 2px; }
.vcard .thumbs .img:hover .ops { display: flex; }
.vcard .drop { border: 1px dashed var(--border); border-radius: 4px; padding: 3px; text-align: center; color: var(--muted); cursor: pointer; }
.vcard .vactions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: auto; }
.compare-bar { font-size: 12px; display: flex; gap: 6px; align-items: center; }

.dialog { border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; width: min(760px, 95vw); }
.dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog .row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.import-preview { margin-top: 8px; max-height: 40vh; overflow: auto; }
.import-preview ol { padding-left: 24px; margin: 4px 0; }
.import-preview li { margin-bottom: 3px; }
.import-preview .cand { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 4px; padding: 6px 8px; margin-top: 6px; }
.import-preview .cand label { display: block; margin: 2px 0; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 6px; z-index: 1000; }
.toast { background: #1f2937; color: #fff; padding: 8px 12px; border-radius: 6px; font-size: 13px; max-width: 360px; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.toast.warn { background: #b45309; }
.toast.error { background: #b91c1c; }

@media (max-width: 1100px) {
  .editor-body { grid-template-columns: 1fr; }
  .editor-output { grid-template-columns: 1fr; }
  .col-left, .col-center { max-height: 60vh; }
}

.AdTopFrame {
  text-align: center;
  margin: 1.2rem auto 1.2rem auto;
}
.AdBottomFrame {
  text-align: center;
  margin: 1.2rem auto 1.2rem auto;
}