:root {
  --navy: #111827;
  --ink: #1a1f2a;
  --muted: #6b7380;
  --line: #e2e5eb;
  --soft: #f0f1f4;
  --bg: #f3f4f7;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.05), 0 8px 24px rgba(17, 24, 39, 0.06);
  --checker-a: #efeef2;
  --checker-b: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--navy);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex: 0 0 auto;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; letter-spacing: 0.01em; }
.brand-text span { font-size: 12px; color: #cbd5e1; font-weight: 500; }
.tag { margin: 0; color: #cbd5e1; font-size: 13px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  padding: 20px;
  max-width: 1280px;
  margin: 0 auto;
  align-items: start;
}

.stage-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: calc(100vh - 120px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.stage {
  position: relative;
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.stage canvas {
  width: 100%;
  height: auto;
  max-height: calc(100vh - 168px);
  object-fit: contain;
  display: block;
  background:
    linear-gradient(var(--preview-bg, #fff), var(--preview-bg, #fff)),
    repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%)
      0 0 / 20px 20px;
  border-radius: 10px;
}
.stage.transparent canvas { --preview-bg: transparent; }
.stage-empty {
  display: none;
  text-align: center;
  color: var(--muted);
  margin-top: 12px;
}
.stage-empty.show { display: block; }
.stage-empty p { margin: 0 0 8px; font-size: 14px; }
.stage.dragover {
  outline: 2px dashed var(--accent);
  outline-offset: 8px;
  border-radius: 12px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 16px 18px;
  position: sticky;
  top: 16px;
}
.block { padding: 14px 0; border-bottom: 1px solid var(--line); }
.block:last-child { border-bottom: 0; }
.label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.upload { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filename {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.thumbs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.thumb {
  appearance: none;
  border: 2px solid var(--line);
  background: var(--soft);
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
}
.thumb img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  object-position: center 40%;
  display: block;
  background: #f7f8fa;
}
.thumb span {
  display: block;
  padding: 6px 8px 8px;
  font-size: 12.5px;
  font-weight: 600;
}
.thumb.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { margin: 0 0 12px; }
.field-row, .field-name {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 4px;
}
.field-row output { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 500; }
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 28px;
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  margin: 6px 0 14px;
  cursor: pointer;
}
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.seg {
  display: flex;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  overflow: hidden;
}
.seg button {
  flex: 1;
  border: 0;
  background: #fff;
  padding: 8px 6px;
  min-height: 38px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.seg button + button { border-left: 1px solid #cbd5e1; }
.seg button.on { background: var(--navy); color: #fff; }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.actions { display: flex; gap: 8px; margin-top: 4px; }
.btn {
  border: 0;
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  min-height: 44px;
  padding: 0 14px;
  cursor: pointer;
  font-size: 14.5px;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; flex: 1; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost {
  background: #fff;
  color: var(--accent);
  border: 1.5px solid var(--accent);
  flex: 1;
}
.btn-ghost:hover:not(:disabled) { background: #f5f8ff; }
.hint { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); min-height: 1.3em; }
.hint.ok { color: #047857; }
.hint.err { color: #b91c1c; }

@media (max-width: 860px) {
  .top { flex-direction: column; align-items: flex-start; padding: 12px 16px; gap: 4px; }
  .tag { font-size: 12.5px; }
  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }
  .stage-wrap {
    min-height: 0;
    padding: 12px;
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .stage { max-width: 280px; margin: 0 auto; }
  .stage canvas { max-height: 46vh; }
  .panel { position: static; }
  .thumbs { grid-template-columns: repeat(4, 1fr); }
  .thumb span { font-size: 11px; padding: 4px 4px 6px; }
}
