:root {
  --ink: #17181a;
  --ink-2: #4a4c51;
  --ink-3: #8a8c92;
  --line: #e3e3e1;
  --line-2: #d2d2cf;
  --surface: #ffffff;
  --surface-2: #f6f6f5;
  --stage: #dcdcd9;
  --accent: #17181a;
  --danger: #b4412f;
  --r: 10px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  --num: "SF Mono", ui-monospace, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font: 13px/1.6 var(--font);
  color: var(--ink);
  background: var(--stage);
  display: grid;
  grid-template: "bar bar bar" 56px "tools stage panel" minmax(0, 1fr) / 64px minmax(0, 1fr) 320px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---- top bar ---- */
.bar {
  grid-area: bar; display: flex; align-items: center; gap: 14px;
  padding: 0 14px 0 18px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, var(--ink) 0 38%, transparent 39%),
    radial-gradient(var(--ink) .9px, transparent 1.2px) 0 0/4px 4px;
  -webkit-mask: radial-gradient(circle, #000 66%, transparent 67%);
          mask: radial-gradient(circle, #000 66%, transparent 67%);
}
.doc-name {
  border: 1px solid transparent; background: transparent; border-radius: 8px;
  padding: 6px 10px; width: 220px; color: var(--ink-2);
}
.doc-name:hover { border-color: var(--line); }
.doc-name:focus { outline: none; border-color: var(--line-2); background: var(--surface-2); color: var(--ink); }
.bar-group { display: flex; align-items: center; gap: 6px; }
.spacer { flex: 1; }
.count { display: flex; align-items: baseline; gap: 4px; font-family: var(--num); font-size: 13px; color: var(--ink-2); padding: 0 6px; }
.count small { font-family: var(--font); font-size: 11px; color: var(--ink-3); }
.count.warn { color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface);
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #2c2d31; }
.btn.primary:disabled { opacity: .45; cursor: default; }
.btn.sm { height: 30px; padding: 0 12px; font-size: 12px; }
.btn.danger { color: var(--danger); }
.btn.file { position: relative; overflow: hidden; }
.btn.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%;
  border: 0; background: transparent; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.split { display: flex; align-items: center; }
.split .btn.primary { border-radius: 999px 0 0 999px; }
.split-select {
  height: 34px; border-radius: 0 999px 999px 0; border: 1px solid var(--accent); border-left-color: #3a3b40;
  background: var(--accent); color: #fff; padding: 0 26px 0 10px; font-size: 12px; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #fff 50%), linear-gradient(135deg, #fff 50%, transparent 50%);
  background-position: right 13px center, right 9px center; background-size: 4px 4px; background-repeat: no-repeat;
}
.split-select option { color: var(--ink); }

/* ---- tools ---- */
.tools {
  grid-area: tools; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 0;
}
.tool {
  width: 52px; min-height: 52px; border: 0; border-radius: 12px; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--ink-2);
}
.tool span { font-size: 10.5px; letter-spacing: .04em; }
.tool svg { width: 22px; height: 22px; }
.tool:hover { background: var(--surface-2); color: var(--ink); }
.tool.active { background: var(--ink); color: #fff; }
.tool.small { min-height: 36px; width: 40px; }
.tool.small svg { width: 18px; height: 18px; }
.tools-sep { width: 28px; height: 1px; background: var(--line); margin: 8px 0; flex: none; }
.tools .tool.small:first-of-type { margin-top: auto; }

/* ---- stage ---- */
.stage { grid-area: stage; position: relative; overflow: hidden; touch-action: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { cursor: crosshair; }
.stage[data-tool="select"] #overlay { cursor: default; }
.stage.panning #overlay { cursor: grab; }
.empty {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(360px, 70%); text-align: center; color: var(--ink-2); pointer-events: none;
}
.empty-title { font-size: 15px; font-weight: 600; color: var(--ink); margin: 0 0 6px; }
.empty p { margin: 0; line-height: 1.8; }
.hint {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  background: rgba(23,24,26,.86); color: #fff; font-size: 12px; padding: 7px 14px; border-radius: 999px;
  pointer-events: none; opacity: 0; transition: opacity .2s; white-space: nowrap;
}
.hint.show { opacity: 1; }
.toast {
  position: absolute; right: 16px; top: 16px; max-width: 380px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.12); font-size: 12px; line-height: 1.7;
  opacity: 0; transform: translateY(-6px); transition: opacity .2s, transform .2s; pointer-events: none; white-space: pre-line;
}
.toast.show { opacity: 1; transform: none; pointer-events: auto; }
.toast.err { border-color: #e6b8ae; }

/* ---- panel ---- */
.panel { grid-area: panel; background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--line); flex: none; }
.tabs button {
  border: 0; background: transparent; padding: 8px 10px 10px; cursor: pointer; color: var(--ink-3);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
.tab-body { padding: 16px 16px 40px; overflow-y: auto; flex: 1; min-height: 0; }
.tab-body[hidden] { display: none; }
.sub { font-size: 12px; font-weight: 600; margin: 26px 0 12px; padding-top: 18px; border-top: 1px solid var(--line); }
.note { color: var(--ink-3); font-size: 12px; line-height: 1.7; margin: 0 0 8px; }
.note.sm { font-size: 11px; margin: 6px 0 0; }
.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 7px; }
.field small, .switch small { color: var(--ink-3); font-size: 11px; margin-left: 4px; }
.field.two { display: flex; align-items: end; gap: 10px; }
.field.two label { flex: 1; display: flex; flex-direction: column; gap: 4px; position: relative; margin: 0; }
.field.two small { position: absolute; right: 8px; bottom: 7px; }
input[type=number], input[type=text], select {
  width: 100%; height: 32px; border: 1px solid var(--line-2); border-radius: 8px; padding: 0 9px; background: var(--surface);
}
input:focus, select:focus { outline: 2px solid rgba(23,24,26,.15); outline-offset: 0; border-color: var(--ink-3); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid rgba(0,0,0,.12); cursor: pointer; position: relative; padding: 0;
}
.chip.on::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 1.6px solid var(--ink); }
.chip.none { background: var(--surface) !important; }
.chip.none::before { content: ""; position: absolute; left: 50%; top: 3px; bottom: 3px; width: 1.4px; background: var(--danger); transform: rotate(45deg); }
.chip.paper::before { content: "穴"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 10px; color: var(--ink-3); }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 14px; border-radius: 999px; cursor: pointer; color: var(--ink-2); font-size: 12px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.range { margin-bottom: 14px; }
.range-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }
.range-head output { font-family: var(--num); font-size: 11.5px; color: var(--ink); }
input[type=range] { width: 100%; margin: 0; height: 18px; background: transparent; -webkit-appearance: none; appearance: none; }
input[type=range]::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: linear-gradient(var(--ink), var(--ink)) 0/var(--p, 50%) 100% no-repeat, var(--line-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%; background: var(--surface); border: 1.5px solid var(--ink); margin-top: -6px; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
input[type=range]::-moz-range-track { height: 3px; border-radius: 3px; background: var(--line-2); }
input[type=range]::-moz-range-progress { height: 3px; border-radius: 3px; background: var(--ink); }
input[type=range]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: var(--surface); border: 1.5px solid var(--ink); }

.switch { position: relative; display: flex; align-items: center; gap: 9px; cursor: pointer; font-size: 12px; color: var(--ink-2); margin-bottom: 10px; }
.switch input { position: absolute; left: 0; top: 0; width: 30px; height: 18px; margin: 0; opacity: 0; pointer-events: none; }
.switch span { width: 30px; height: 18px; border-radius: 999px; background: var(--line-2); position: relative; transition: background .15s; flex: none; }
.switch span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--ink); }
.switch input:checked + span::after { transform: translateX(12px); }
.switch input:focus-visible + span { outline: 2px solid rgba(23,24,26,.3); outline-offset: 2px; }
.top-gap { margin-top: 14px; }
.light-ctl { padding-left: 39px; }

.row-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }
.row-btns.tight { margin-top: 0; }

.layers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.layers li {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; font-size: 12px; color: var(--ink-2);
}
.layers li:hover { background: var(--surface-2); }
.layers li.on { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.layers .sw { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,.12); flex: none; }
.layers .nm { flex: 1; }
.layers .eye { border: 0; background: transparent; padding: 2px; cursor: pointer; color: var(--ink-3); display: grid; }
.layers .eye svg { width: 16px; height: 16px; }
.layers li.off .nm, .layers li.off .sw { opacity: .4; }

.palette { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.pal-row { display: grid; grid-template-columns: 34px 1fr 26px; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: var(--r); }
.pal-row.paper-row { background: var(--surface-2); }
.pal-swatch { width: 34px; height: 34px; border-radius: 50%; border: 1px solid rgba(0,0,0,.12); position: relative; overflow: hidden; }
.pal-swatch input { position: absolute; inset: -8px; width: 52px; height: 52px; opacity: 0; cursor: pointer; }
.pal-mid { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.pal-mid .nm { height: 26px; font-size: 12px; padding: 0 7px; }
.cmyk { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.cmyk label { position: relative; }
.cmyk label b { position: absolute; left: 6px; top: 5px; font-size: 9.5px; color: var(--ink-3); font-weight: 600; pointer-events: none; }
.cmyk input { height: 26px; font-size: 11.5px; padding: 0 3px 0 15px; font-family: var(--num); -moz-appearance: textfield; }
.cmyk input::-webkit-inner-spin-button { display: none; }
.pal-del { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; padding: 0; display: grid; place-items: center; }
.pal-del:hover { color: var(--danger); }
.pal-del svg { width: 15px; height: 15px; }

.save-row { display: flex; gap: 6px; margin-bottom: 10px; }
.presets { list-style: none; margin: 18px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.presets li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 9px 10px; border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; }
.presets li:hover { border-color: var(--line-2); background: var(--surface-2); }
.presets .pv { display: flex; }
.presets .pv i { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,.1); margin-right: -4px; }
.presets .meta { min-width: 0; }
.presets .meta b { display: block; font-weight: 600; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.presets .meta small { color: var(--ink-3); font-size: 11px; }
.presets .del { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; display: grid; padding: 4px; border-radius: 6px; }
.presets .del:hover { color: var(--danger); background: var(--surface); }
.presets .del svg { width: 15px; height: 15px; }
.presets .empty-row { border-style: dashed; color: var(--ink-3); cursor: default; display: block; text-align: center; font-size: 12px; }
.presets .empty-row:hover { background: transparent; border-color: var(--line); }

@media (max-width: 900px) {
  body { grid-template: "bar bar" 56px "tools stage" minmax(0, 1fr) "panel panel" 44vh / 56px minmax(0, 1fr); }
  .brand { display: none; }
  .doc-name { width: 120px; }
  .tool { width: 46px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
}

.spot-chk { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ink-3); cursor: pointer; }
.spot-chk input { width: 13px; height: 13px; margin: 0; accent-color: var(--ink); }
.print-warn { color: #8a4a1c; background: #fbf1e6; border-radius: 8px; padding: 8px 10px; margin-top: 4px; }

textarea { width: 100%; border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 9px; background: var(--surface); font: inherit; resize: vertical; }
textarea:focus { outline: 2px solid rgba(23,24,26,.15); border-color: var(--ink-3); }
.linkish { border: 0; background: none; padding: 0; margin-left: 6px; font-size: 11px; color: var(--ink-3); text-decoration: underline; cursor: pointer; }
.linkish:hover { color: var(--ink); }
