/* トークン（画面仕様書 §4）。文字は 20 / 15 / 13 / 11 の4段のみ */
:root {
  --bg: #F7F7F5;
  --panel: #FFFFFF;
  --around: #E9E9E6;
  --main: #2F4B6E;
  --main-tint: #E6ECF4;
  --accent: #E8590C;
  --text: #222222;
  --sub: #6B6B6B;
  --line: #D8D8D4;
  --err: #B42318;
  --radius: 6px;
  --font: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.6; font-weight: 400;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; height: 100vh; min-width: 1100px; }

/* 状態ごとの出し分け */
#app[data-state="empty"] .only-edit { display: none !important; }
#app[data-state="edit"] .only-empty { display: none !important; }

/* 上部バー */
.topbar {
  height: 56px; flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.tb-left { display: flex; align-items: center; gap: 16px; min-width: 0; }
.tb-right { display: flex; justify-content: flex-end; }
.filename { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ボタン */
.btn {
  height: 40px; min-width: 40px; padding: 0 16px; border: 1px solid var(--main); border-radius: var(--radius);
  background: var(--panel); color: var(--main); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--main-tint); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--main); outline-offset: 2px; }
.btn-main { background: var(--main); color: #fff; }
.btn-main:hover { background: #3A5A82; }
.btn-save { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-save:hover { background: #CF4E08; }
.btn-icon { padding: 0; width: 40px; }
.btn:disabled { color: #9A9A96; border-color: var(--line); background: var(--bg); cursor: default; }

/* 作業エリア */
.workspace { flex: 1; min-height: 0; display: flex; }
.panel { flex: none; background: var(--panel); overflow-y: auto; padding: 16px; }
.panel-left { width: 240px; border-right: 1px solid var(--line); }
.panel-right { width: 320px; border-left: 1px solid var(--line); }
.h { margin: 0 0 8px; font-size: 15px; font-weight: 600; color: var(--main); }
.muted { margin: 8px 0 0; font-size: 13px; color: var(--sub); }
.error { margin: 8px 0 0; font-size: 13px; color: var(--err); min-height: 0; }
.error:empty { display: none; }
.title { margin: 0; font-size: 20px; font-weight: 600; }

/* 読み込み前 */
.empty {
  flex: 1; margin: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  border: 2px dashed var(--main); border-radius: var(--radius); background: var(--panel); text-align: center;
}
.empty .muted, .empty .error { margin: 0; }
.empty.drag { background: var(--main-tint); }

/* レイヤー */
.layers { list-style: none; margin: 0; padding: 0; }
.layer { display: flex; align-items: center; height: 44px; border-radius: var(--radius); cursor: pointer; }
.layer.sel { background: var(--main-tint); }
.layer .eye {
  width: 44px; height: 44px; flex: none; border: 0; background: none; cursor: pointer; color: var(--main);
  display: flex; align-items: center; justify-content: center; border-radius: var(--radius);
}
.layer .lname { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer.off .lname { color: var(--sub); opacity: .6; }
.layer.off .eye { color: var(--sub); }

/* 中央 */
.center { flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; background: var(--around); }
.stage { flex: 1; min-height: 0; overflow: auto; padding: 72px 24px 24px; cursor: grab; }
.stage.range { cursor: crosshair; }
.paper { position: relative; margin: 0 auto; background: #fff; border: 1px solid var(--line); width: max-content; }
.paper canvas { display: block; }
.selbox { position: absolute; border: 2px solid var(--main); pointer-events: none; }
.zoombar {
  position: absolute; left: 24px; bottom: 16px; display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px;
}
.zoomval { min-width: 56px; text-align: center; font-size: 13px; }

.busy { position: absolute; inset: 0; background: rgba(247, 247, 245, .8); display: flex; align-items: center; justify-content: center; z-index: 5; }
.busy-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; width: 320px; }
.busy-title { margin: 0 0 16px; font-weight: 600; }
.bar { height: 8px; background: var(--around); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.toast {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 6;
  background: var(--main); color: #fff; padding: 8px 16px; border-radius: var(--radius);
}
body.busy-on .topbar, body.busy-on .panel { pointer-events: none; opacity: .5; }

/* 色一覧 */
.colors { list-style: none; margin: 0 0 8px; padding: 0; max-height: 216px; overflow-y: auto; }
.color {
  display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 8px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.color.sel { border: 2px solid var(--main); padding: 3px 7px; }
.color .sw { width: 32px; height: 32px; flex: none; border-radius: 4px; border: 1px solid var(--line); }
.color .ct { flex: 1; min-width: 0; font-size: 15px; white-space: nowrap; }
.color .cn { font-size: 11px; color: var(--sub); }
.color.spot { cursor: default; }
.editor { padding: 0 0 8px; }
.cmyk-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0; }
.cmyk-row label { display: flex; flex-direction: column; gap: 0; }
.lab { font-size: 11px; color: var(--sub); }
input[type="number"], select, textarea {
  width: 100%; height: 40px; padding: 0 8px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
}
textarea { height: auto; padding: 8px; resize: vertical; }

/* 右下：テキスト差し替え */
.block + .block { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); }
.steps { list-style: none; margin: 0; padding: 0; }
.steps > li { display: flex; gap: 8px; margin-bottom: 16px; }
.num { flex: none; width: 24px; font-weight: 600; color: var(--main); }
.step-body { flex: 1; min-width: 0; }
.step-body .muted { margin-top: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 96px; gap: 8px; margin-top: 8px; }
.size { position: relative; display: block; }
.size input { padding-right: 32px; }
.unit { position: absolute; right: 8px; top: 8px; font-size: 13px; color: var(--sub); }
.check { display: flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; }
.btn[aria-pressed="true"] { background: var(--main); color: #fff; }

/* 右パネル：「色」の見出しと「配置する」は常に見える */
.panel-right .block:first-child .h { position: sticky; top: -16px; z-index: 2; margin: -16px -16px 8px; padding: 16px 16px 8px; background: var(--panel); }
.steps > li:last-child { position: sticky; bottom: -16px; z-index: 2; margin: 0 -16px -16px; padding: 8px 16px 16px; background: var(--panel); border-top: 1px solid var(--line); }
