/* スーパー画像編集画蔵君 — 編集画面 */

:root {
  --bg: #eef0f4;
  --panel: #ffffff;
  --fg: #1f2328;
  --sub: #5f6368;
  --line: #dfe4ea;
  --accent: #7048e8;
  --accent-weak: #efeafc;
  --danger: #c92a2a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141518;
    --panel: #1f2125;
    --fg: #e8eaed;
    --sub: #9aa0a6;
    --line: #33363c;
    --accent: #b197fc;
    --accent-weak: #2a2440;
    --danger: #ff8787;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.6 system-ui, "Yu Gothic UI", "Meiryo", sans-serif;
}

/* ---------- 上部バー ---------- */

.bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;              /* 幅が足りなければ次の行へ回す */
  gap: 8px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}

/* 折り返したとき、右端の組が次の行の右に付くようにする */
@media (max-width: 1100px) {
  .bar .spacer { flex-basis: 100%; height: 0; }
}

.logo { width: 20px; height: 20px; border-radius: 4px; }
.brand { font-weight: 600; white-space: nowrap; margin-right: 8px; }
.spacer { flex: 1; }
.group { display: flex; align-items: center; gap: 6px; }

.btn {
  padding: 6px 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { background: var(--accent-weak); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { padding: 5px 10px; }
.btn.small { padding: 4px 6px; font-size: 12px; flex: 1; }
.btn.block { display: block; width: 100%; margin-top: 8px; }
.btn.danger:hover { background: #fff0f0; color: var(--danger); }

.zoom { min-width: 46px; text-align: center; color: var(--sub); font-variant-numeric: tabular-nums; }

/* ---------- 本体 ---------- */

.wrap { flex: 1; display: flex; min-height: 0; min-width: 0; }

.stage {
  flex: 1;
  min-width: 0;
  overflow: auto;
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* 透明部分がわかる市松模様。キャンバス自体は透明のまま */
.board {
  flex: none;
  position: relative;
  background-color: #ffffff;
  background-image:
    linear-gradient(45deg, #d9dde3 25%, transparent 25%, transparent 75%, #d9dde3 75%),
    linear-gradient(45deg, #d9dde3 25%, transparent 25%, transparent 75%, #d9dde3 75%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
  box-shadow: 0 2px 18px rgba(15, 25, 40, .2);
}

#view { display: block; cursor: move; }
.stage.panning, .stage.panning #view { cursor: grabbing; }
.stage.can-pan #view { cursor: grab; }

.crop-box {
  position: absolute;
  border: 2px dashed #fff;
  outline: 2px dashed var(--accent);
  background: rgba(112, 72, 232, .16);
  pointer-events: none;
}

.stage.cropping #view { cursor: crosshair; }

/* レイヤーの大きさを変える枠とつまみ（移動の道具のとき） */
.ly-frame {
  position: absolute;
  box-sizing: border-box;
  border: 1px dashed var(--accent);
  pointer-events: none;
}
.ly-frame i {
  position: absolute;
  box-sizing: border-box;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border: 2px solid var(--accent);
  border-radius: 2px;
  background: #fff;
  pointer-events: auto;
}
.ly-frame i[data-k="nw"] { left: 0;    top: 0;    cursor: nwse-resize; }
.ly-frame i[data-k="n"]  { left: 50%;  top: 0;    cursor: ns-resize; }
.ly-frame i[data-k="ne"] { left: 100%; top: 0;    cursor: nesw-resize; }
.ly-frame i[data-k="e"]  { left: 100%; top: 50%;  cursor: ew-resize; }
.ly-frame i[data-k="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.ly-frame i[data-k="s"]  { left: 50%;  top: 100%; cursor: ns-resize; }
.ly-frame i[data-k="sw"] { left: 0;    top: 100%; cursor: nesw-resize; }
.ly-frame i[data-k="w"]  { left: 0;    top: 50%;  cursor: ew-resize; }

.chk {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
  font-size: 12px;
  color: var(--sub);
  cursor: pointer;
}

.chk input { accent-color: var(--accent); }

/* ---------- ドロップ領域 ---------- */

.drop { margin: auto; width: 100%; max-width: 640px; }

.drop-inner {
  padding: 56px 32px;
  border: 2px dashed var(--line);
  border-radius: 14px;
  text-align: center;
  color: var(--sub);
  background: var(--panel);
}

.drop.over .drop-inner { border-color: var(--accent); background: var(--accent-weak); }
.drop-icon { font-size: 40px; color: var(--accent); line-height: 1; }
.drop-title { margin: 14px 0 8px; font-size: 19px; font-weight: 700; color: var(--fg); }
.drop-sub { margin: 0 0 16px; font-size: 13px; }
.drop-note { margin: 0; font-size: 11.5px; }

.limits {
  margin: 0 auto 16px;
  max-width: 520px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  text-align: left;
}

.limits-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 6px;
}

.limits ul { margin: 0; padding-left: 1.2em; }
.limits li { font-size: 11.5px; line-height: 1.65; margin-bottom: 4px; color: var(--sub); }
.limits b { color: var(--fg); }

/* ---------- 右パネル ---------- */

.side {
  width: 268px;
  flex: none;
  padding: 14px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow: auto;
}

.sec { margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.sec h3 { margin: 0 0 8px; font-size: 12px; color: var(--sub); font-weight: 600; }

.row { display: flex; align-items: center; gap: 6px; margin-bottom: 7px; }
.row.sub { font-size: 12px; color: var(--sub); }
.row .lab { flex: none; color: var(--sub); font-size: 12px; white-space: nowrap; }
.row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.row .num { min-width: 28px; text-align: right; font-variant-numeric: tabular-nums; }

select, .numin, .txtin {
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  color: var(--fg);
  font: inherit;
}

select { flex: 1; min-width: 0; }
.numin { width: 74px; font-variant-numeric: tabular-nums; }
.small-num { width: 62px; }
.txtin { flex: 1; min-width: 0; }

.note { margin: 4px 0 0; font-size: 11px; color: var(--sub); }

/* ---------- レイヤー一覧 ---------- */

.layers {
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  margin-bottom: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.ly {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.ly:last-child { border-bottom: none; }
.ly:hover { background: var(--accent-weak); }

/* 選択中のレイヤーをはっきり示す */
.ly.on {
  background: var(--accent-weak);
  box-shadow: inset 4px 0 0 var(--accent);
}
.ly.on .ly-name { font-weight: 700; color: var(--accent); }

/* 非表示のレイヤーは薄くする */
.ly.hidden .ly-thumb,
.ly.hidden .ly-body { opacity: .38; }

.ly-mark {
  flex: none;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.ly-eye {
  flex: none;
  width: 26px; height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  padding: 0;
}

.ly-eye:hover { border-color: var(--line); background: var(--panel); }
.ly-eye.off { color: var(--sub); opacity: .55; }
.ly-eye svg { display: block; }

.ly-thumb {
  flex: none;
  width: 34px; height: 34px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e4e8ee 25%, transparent 25%, transparent 75%, #e4e8ee 75%),
    linear-gradient(45deg, #e4e8ee 25%, transparent 25%, transparent 75%, #e4e8ee 75%);
  background-size: 10px 10px;
  background-position: 0 0, 5px 5px;
  object-fit: contain;
}

.ly-body { flex: 1; min-width: 0; }
.ly-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ly-meta { display: block; font-size: 10.5px; color: var(--sub); }

.empty { padding: 14px; text-align: center; color: var(--sub); font-size: 12px; }

.side-foot {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--sub);
  line-height: 1.7;
}

/* ---------- 下部 ---------- */

.foot {
  display: flex;
  gap: 12px;
  padding: 6px 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  color: var(--sub);
  font-size: 11.5px;
  flex: none;
}

/* 下の帯のリンク（プライバシーポリシー。2026-09-23。Apple の指針 5.1.1(i)） */
.foot-link { color: inherit; text-decoration: underline; margin-left: 12px; opacity: .85; }
.foot-link:hover { opacity: 1; }

/* ---------- PDFのページ選択 ---------- */

.warn { color: var(--danger); }

.pg-btns { display: flex; gap: 6px; flex: 1; }

.pg-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 168px;
  overflow-y: auto;
  padding: 8px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.pg {
  position: relative;
  min-width: 38px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  text-align: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
}

.pg input { position: absolute; opacity: 0; pointer-events: none; }
.pg:hover { background: var(--accent-weak); }
.pg.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }

/* ---------- ダイアログ ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15, 20, 28, .48);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-box {
  width: 380px;
  max-width: 92vw;
  padding: 20px 22px;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}

.modal-box h2 { margin: 0 0 6px; font-size: 17px; }
.modal-sub { margin: 0 0 14px; font-size: 12px; color: var(--sub); }
.modal-box code {
  background: var(--accent-weak);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, Consolas, monospace;
}
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-btns .btn { flex: none; }

.prog { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.prog-fill { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

/* ---------- 下部ツールバー（Figma風） ---------- */

.toolbar {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  padding: 3px;
  border-radius: 9px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.tl {
  min-width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 9px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}

.tlab { font-size: 11.5px; white-space: nowrap; }

/* 画面が狭いときは名前を隠してアイコンだけにする */
@media (max-width: 900px) {
  .tlab { display: none; }
  .tl { padding: 0; justify-content: center; width: 32px; }
}

.tl:hover { background: var(--accent-weak); }
.tl.on { background: var(--accent); color: #fff; }
.tl svg { width: 18px; height: 18px; fill: currentColor; display: block; }
.tl-sep { width: 1px; height: 20px; background: var(--line); margin: 0 3px; }

.swatches { display: flex; gap: 5px; flex-wrap: wrap; }

.sw {
  width: 20px; height: 20px;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.2);
}

.sw.on { border-color: var(--fg); }

.text-input { position: fixed; z-index: 40; }

.text-input input {
  min-width: 200px;
  padding: 5px 9px;
  border: 2px solid var(--accent);
  border-radius: 7px;
  background: rgba(255,255,255,.97);
  color: #111;
  font-weight: 700;
  outline: none;
}

.stage.drawing #view { cursor: crosshair; }

.sel-box {
  position: absolute;
  border: 1px solid var(--accent);
  background: rgba(112, 72, 232, .12);
  pointer-events: none;
}

.align-row .btn { font-size: 15px; line-height: 1; padding: 3px 0; }

/* ---------- 通知 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  padding: 9px 20px;
  border-radius: 8px;
  background: rgba(20, 26, 32, .92);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .28);
  z-index: 10;
}

/* ---- レシピ ---- */
.rc-items {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 12px 0 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
.rc-items .chk { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.rc-v { margin-left: auto; font-size: 11.5px; color: var(--sub); }
.rc-count { font-size: 12px; color: var(--sub); }
#rcSizeRow { padding-left: 22px; }
#rcBatch2 { margin: 18px 0 4px; }

/* ---------- 来歴（Content Credentials）と撮影情報 ---------- */

.prov-dot {
  display: inline-block;
  width: 8px; height: 8px;
  margin-left: 5px;
  border-radius: 50%;
  vertical-align: middle;
  background: var(--sub);
}
.prov-dot.ok { background: #2f9e44; }
.prov-dot.ng { background: var(--danger); }
.prov-dot.mid { background: #f59f00; }

.prov-mini { font-size: 12px; margin-bottom: 8px; }
.prov-mini p { margin: 0 0 4px; }

.prov-box { width: 640px; max-height: 88vh; overflow: auto; }
.prov-src { margin: 0 0 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.prov-src h4 { margin: 0 0 6px; font-size: 13px; word-break: break-all; }
.prov-head { margin: 0 0 8px; font-weight: 700; font-size: 14px; }
.prov-tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.prov-tbl th { width: 9.5em; text-align: left; vertical-align: top; color: var(--sub); font-weight: 600; padding: 3px 8px 3px 0; }
.prov-tbl td { padding: 3px 0; word-break: break-word; }
.prov-tbl .sub { color: var(--sub); font-size: 11px; }
.prov-alert {
  margin: 8px 0 0;
  padding: 7px 10px;
  border-radius: 6px;
  background: rgba(201, 42, 42, .08);
  color: var(--danger);
  font-size: 12px;
}
.prov-sub-h { margin: 10px 0 4px; font-size: 12px; color: var(--sub); }
.prov-list { margin: 0; padding-left: 1.4em; font-size: 12px; }
.pill {
  display: inline-block;
  padding: 0 7px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid currentColor;
}
.pill.ok { color: #2f9e44; }
.pill.ng { color: var(--danger); }
.pill.mid { color: #e67700; }
.pill.none { color: var(--sub); }

/* ---------- 段階 B（範囲選択・トーンカーブ） ---------- */

.sel-view {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  image-rendering: auto;
}

.tone-cv {
  display: block;
  width: 100%;
  max-width: 256px;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line, #d7dde3);
  border-radius: 4px;
  cursor: crosshair;
  margin: 4px 0;
}

.tone-chs .btn.on { background: var(--accent); color: #fff; }

#pickSw {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, .2);
}

/* ---------- 段階 D（履歴・ショートカット・画質の比較） ---------- */

.hist-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--line, #d7dde3);
  border-radius: 6px;
}
.hist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 4px 8px;
  border: 0;
  border-bottom: 1px solid #eef0f3;
  background: transparent;
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.hist-item:hover { background: #f4f1ff; }
.hist-item.on { background: #ece6ff; font-weight: 700; }
.hist-item.undone { color: #9aa1ab; }
.hist-n { width: 22px; color: #9aa1ab; font-variant-numeric: tabular-nums; }
.hist-l { flex: 1; }
.hist-t { color: #9aa1ab; font-size: 11px; font-variant-numeric: tabular-nums; }

.linkbtn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 0 10px;
}
.linkbtn:hover { text-decoration: underline; }

.keys-box { max-width: 560px; }
.keys-box h3 { margin: 12px 0 4px; font-size: 13px; }
.keys-tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.keys-tbl th { text-align: left; font-weight: 400; white-space: nowrap; padding: 3px 12px 3px 0; width: 45%; }
.keys-tbl td { padding: 3px 0; }
kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid #c9ced6;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #fff;
  font: 11px/1.4 ui-monospace, Consolas, monospace;
  text-align: center;
}

.cmp-box { max-width: 900px; }
.cmp-row { display: flex; gap: 8px; flex-wrap: wrap; }
.cmp-row canvas {
  max-width: 100%;
  border: 1px solid var(--line, #d7dde3);
  image-rendering: pixelated;
}
#cmpA { cursor: crosshair; }
.cmp-fig { margin: 0; }
.cmp-fig figcaption { font-size: 12px; font-weight: 700; margin: 0 0 3px; }
