:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --paper: #ffffff;
  --ink: #17211d;
  --muted: #66736d;
  --line: #d9e1dc;
  --brand: #06c755;
  --brand-dark: #049842;
  --warn: #b86a00;
  --bad: #c73333;
  --shadow: 0 18px 50px rgba(28, 44, 37, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 22px;
}

.workspace {
  max-width: 1460px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 2px 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.3;
}

.guideline-link {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--paper);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls-panel {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 16px;
  padding: 16px;
}

.dropzone {
  display: grid;
  place-items: center;
  gap: 7px;
  min-height: 164px;
  border: 2px dashed #a9b9b1;
  border-radius: 8px;
  background: #fbfdfc;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.dropzone:hover,
.dropzone.dragging {
  border-color: var(--brand);
  background: #effbf4;
  transform: translateY(-1px);
}

.dropzone input {
  display: none;
}

.drop-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 30px;
  line-height: 1;
}

.dropzone small,
.file-summary,
.group-head span,
.output-panel p,
.hint-text {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.hint-text {
  margin-top: 4px;
}

.file-summary {
  min-height: 32px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #eef3f0;
}

.control-group {
  display: grid;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.custom-split {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfdfc;
}

.number-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr 0.9fr;
  gap: 8px;
}

.number-grid input,
.number-grid select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.preset-button,
.segment,
.ghost-button,
.primary-button,
.download-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.compact {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

.preset-button.active,
.segment.active {
  border-color: var(--brand);
  background: #eafaf1;
  color: #047a36;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.control-help {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.45;
}

label b {
  color: var(--ink);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--brand);
}

.segmented {
  display: grid;
  gap: 6px;
}

.bg-toggle {
  grid-template-columns: repeat(4, 1fr);
}

.product-toggle {
  grid-template-columns: repeat(2, 1fr);
}

.color-line,
.toggle-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.color-line input {
  width: 48px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  background: #fff;
}

.toggle-line {
  justify-content: flex-start;
  color: var(--ink);
  font-weight: 650;
}

.toggle-line input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

.primary-button,
.download-button {
  width: 100%;
  min-height: 48px;
  border: 0;
  background: var(--brand);
  color: #fff;
}

.download-button {
  background: var(--ink);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.preview-area {
  display: grid;
  gap: 18px;
}

.preview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 18px;
}

.image-panel,
.status-panel,
.output-panel {
  padding: 16px;
}

.canvas-wrap {
  position: relative;
  display: grid;
  min-height: 430px;
  margin-top: 14px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: #fdfdfd;
  background-image:
    linear-gradient(45deg, #dfe7e3 25%, transparent 25%),
    linear-gradient(-45deg, #dfe7e3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dfe7e3 75%),
    linear-gradient(-45deg, transparent 75%, #dfe7e3 75%);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

canvas {
  max-width: 100%;
  max-height: 70vh;
}

#overlayCanvas {
  position: absolute;
  inset: auto;
  pointer-events: auto;
  touch-action: none;
  cursor: crosshair;
}

#overlayCanvas.dragging-line {
  cursor: grabbing;
}

.empty-state,
.empty-output {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.check-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.check-list li {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 10px;
  border-radius: 8px;
  background: #f3f7f5;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.check-list strong {
  display: block;
  color: var(--ink);
}

.dot {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--brand);
}

.dot.warn {
  background: var(--warn);
}

.dot.bad {
  background: var(--bad);
}

.output-panel .group-head {
  align-items: flex-start;
}

.output-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(126px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.stamp-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fbfdfc;
  cursor: pointer;
}

.stamp-card.selected {
  outline: 3px solid rgba(6, 199, 85, 0.28);
  border-color: var(--brand);
}

.thumb {
  display: grid;
  min-height: 108px;
  place-items: center;
  border-radius: 6px;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e0e7e3 25%, transparent 25%),
    linear-gradient(-45deg, #e0e7e3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e0e7e3 75%),
    linear-gradient(-45deg, transparent 75%, #e0e7e3 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.thumb img {
  display: block;
  width: 100%;
  max-height: 120px;
  object-fit: contain;
}

.stamp-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

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

.badge {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  border-radius: 999px;
  padding: 0 7px;
  background: #e7f8ee;
  color: #047a36;
  font-size: 11px;
  font-weight: 800;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 18px;
}

.image-modal.open {
  display: grid;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 25, 21, 0.58);
}

.modal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(760px, 96vw);
  max-height: 92vh;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--paper);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-image-wrap {
  display: grid;
  min-height: 360px;
  place-items: center;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #dfe7e3 25%, transparent 25%),
    linear-gradient(-45deg, #dfe7e3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dfe7e3 75%),
    linear-gradient(-45deg, transparent 75%, #dfe7e3 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
}

.modal-image-wrap img {
  display: block;
  width: min(88vw, 560px);
  max-height: 68vh;
  object-fit: contain;
  image-rendering: auto;
}

.modal-download {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

@media (max-width: 980px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .layout,
  .preview-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .controls-panel {
    position: static;
  }

  .preview-grid {
    display: grid;
  }
}

@media (max-width: 560px) {
  .preset-grid,
  .number-grid {
    grid-template-columns: 1fr;
  }

  .canvas-wrap {
    min-height: 300px;
  }

  .output-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .modal-image-wrap {
    min-height: 260px;
  }
}
