:root {
  --bg: #f3f3f1;
  --card: #fff;
  --ink: #1c1d20;
  --mute: #6b6e76;
  --line: #dcdcd8;
  --accent: #1f5eff;
  --warn: #fff4d6;
  --err: #c62828;
  --ok: #1b7f45;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font:
    15px/1.5 "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
}
.top {
  padding: 24px 28px 8px;
}
.top h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.02em;
}
.top p {
  margin: 2px 0 0;
  color: var(--mute);
}
.app {
  display: grid;
  grid-template-columns: minmax(300px, 400px) 1fr;
  gap: 20px;
  padding: 16px 28px 40px;
  align-items: start;
}
.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
h2 {
  margin: 0;
  font-size: 15px;
}
.count {
  color: var(--mute);
  font-size: 13px;
}
.drop {
  border: 1.5px dashed var(--line);
  border-radius: 6px;
  padding: 18px 12px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--mute);
  font-size: 13px;
}
.drop strong {
  color: var(--ink);
  font-size: 14px;
}
.drop:hover,
.drop:focus-visible,
.drop.over {
  border-color: var(--accent);
  background: #f3f6ff;
  outline: none;
}
.thumbs {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.thumbs li {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
}
.thumbs img {
  width: 56px;
  height: 42px;
  object-fit: cover;
  border-radius: 3px;
  background: #eee;
}
.thumbs .nm {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thumbs .nm small {
  display: block;
  color: var(--mute);
}
.tb {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  grid-column: 1/-1;
  justify-content: flex-end;
}
.tb button {
  padding: 2px 8px;
  font-size: 13px;
}
.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.fields label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--mute);
  gap: 3px;
}
.fields label:nth-child(2) {
  grid-column: span 1;
}
input[type="text"],
input[type="number"] {
  font: inherit;
  color: var(--ink);
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}
input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 5px;
  padding: 8px 14px;
}
button:hover:not(:disabled) {
  border-color: var(--ink);
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.primary:hover:not(:disabled) {
  background: #1749cc;
  border-color: #1749cc;
}
button.ghost {
  border-color: transparent;
  color: var(--mute);
}
.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.actions .primary {
  flex: 1 1 140px;
}
.preview {
  min-width: 0;
}
.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.zoom {
  display: flex;
  align-items: center;
  gap: 6px;
}
.zoom button {
  padding: 3px 10px;
}
#zVal {
  min-width: 44px;
  text-align: center;
  font-size: 13px;
  color: var(--mute);
}
.warn {
  background: var(--warn);
  border: 1px solid #e8cf86;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 13px;
}
.stage {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e4e4e0;
  padding: 20px;
  max-height: calc(100vh - 140px);
}
.page {
  position: relative;
  background: #fff;
  margin: 0 auto;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  aspect-ratio: 210/297;
  overflow: hidden;
  color: #000;
  font-family: Helvetica, Arial, sans-serif;
}
.page img {
  position: absolute;
  display: block;
}
.page .hd {
  position: absolute;
  white-space: nowrap;
  font-weight: bold;
}
.page .empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #aaa;
  font:
    14px "Segoe UI",
    sans-serif;
  text-align: center;
  padding: 20px;
}
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9;
  max-width: calc(100vw - 32px);
}
.toast {
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
  border-left: 4px solid var(--accent);
}
.toast.error {
  border-color: var(--err);
}
.toast.success {
  border-color: var(--ok);
}
.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 28px 24px;
  border-top: 1px solid var(--line);
  color: var(--mute);
  font-size: 13px;
}
.foot .brand {
  color: var(--ink);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 21, 24, 0.55);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 20;
}
.modal[hidden] {
  display: none;
}
.sheet {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: min(1100px, 100%);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
}
.sheet-head {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.nm2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.sheet-head .ghost {
  margin-left: auto;
  padding: 4px 10px;
}
.sheet-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  padding: 16px;
  overflow: auto;
  min-height: 0;
}
.ed-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.ed-stage {
  background: #e4e4e0;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: auto;
  max-height: 55vh;
  padding: 12px;
}
.ed-wrap {
  position: relative;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
}
.ed-wrap > img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.crop {
  position: absolute;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(15, 16, 20, 0.5);
  cursor: move;
  touch-action: none;
  box-sizing: border-box;
}
.crop i {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 2px;
  touch-action: none;
  box-sizing: border-box;
}
.crop i[data-h="nw"] {
  left: 0;
  top: 0;
  cursor: nwse-resize;
}
.crop i[data-h="n"] {
  left: 50%;
  top: 0;
  cursor: ns-resize;
}
.crop i[data-h="ne"] {
  left: 100%;
  top: 0;
  cursor: nesw-resize;
}
.crop i[data-h="e"] {
  left: 100%;
  top: 50%;
  cursor: ew-resize;
}
.crop i[data-h="se"] {
  left: 100%;
  top: 100%;
  cursor: nwse-resize;
}
.crop i[data-h="s"] {
  left: 50%;
  top: 100%;
  cursor: ns-resize;
}
.crop i[data-h="sw"] {
  left: 0;
  top: 100%;
  cursor: nesw-resize;
}
.crop i[data-h="w"] {
  left: 0;
  top: 50%;
  cursor: ew-resize;
}
.side h3 {
  margin: 0 0 8px;
  font-size: 14px;
}
.side p {
  margin: 6px 0;
}
.prev {
  border: 1px solid var(--line);
  background: repeating-conic-gradient(#f1f1ef 0 25%, #fff 0 50%) 0 0/14px 14px;
  border-radius: 6px;
  padding: 8px;
  display: grid;
  place-items: center;
  min-height: 100px;
}
.prev canvas {
  max-width: 100%;
  height: auto;
  background: #fff;
  box-shadow: 0 0 0 1px var(--line);
}
.mrg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  color: var(--mute);
  margin-top: 12px;
}
.note {
  font-size: 13px;
  color: var(--ink);
  min-height: 40px;
}
.sheet-foot {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.sheet-foot .primary {
  margin-left: auto;
}
button.on {
  border-color: var(--accent);
  color: var(--accent);
  background: #f3f6ff;
}
@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    padding: 12px 14px 32px;
  }
  .top {
    padding: 18px 14px 4px;
  }
  .sheet-body {
    grid-template-columns: 1fr;
  }
  .sheet-foot .primary {
    margin-left: 0;
  }
  .foot {
    padding: 14px 14px 20px;
  }
  .stage {
    max-height: none;
    padding: 10px;
  }
}
@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }
  body {
    background: #fff;
  }
  .top,
  .panel,
  .bar,
  .warn,
  .toasts,
  .foot,
  .modal {
    display: none !important;
  }
  .app {
    display: block;
    padding: 0;
  }
  .stage {
    border: 0;
    padding: 0;
    background: #fff;
    overflow: visible;
    max-height: none;
  }
  .page {
    width: 210mm !important;
    height: 297mm;
    box-shadow: none;
    margin: 0;
  }
}
