:root {
  color-scheme: light;
  --bg: #f1efe8;
  --panel: rgba(255, 252, 245, 0.9);
  --line: rgba(57, 48, 34, 0.12);
  --text: #231d13;
  --muted: #6a6154;
  --accent: #a65f2b;
  --accent-strong: #88461a;
  --shadow: 0 20px 50px rgba(71, 49, 18, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.9), transparent 38%),
    linear-gradient(135deg, #ece7da 0%, #f4efe4 52%, #ede4d4 100%);
  color: var(--text);
}

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel-side {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  min-height: 0;
  overflow-y: auto;
}

.panel-stage {
  padding: 20px;
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 22px;
}

.summary {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.slot-list {
  display: grid;
  gap: 14px;
  padding-right: 6px;
}

.slot-list-stage {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding-right: 0;
  margin-bottom: 14px;
}

.active-slot-panel {
  display: grid;
  gap: 14px;
}

.config-panel,
.product-panel {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
}

.product-panel[hidden] {
  display: none;
}

.config-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 8px;
  align-items: center;
}

.config-actions #load-config-btn {
  grid-column: 1;
  justify-self: start;
}

.config-actions #delete-config-btn {
  grid-column: 2;
  justify-self: end;
}

.config-actions select {
  min-width: 0;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font: inherit;
}

.config-actions .layer-btn {
  padding-inline: 10px;
  white-space: nowrap;
}

.config-status {
  font-size: 12px;
  color: var(--muted);
}

.config-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.config-panel-body {
  display: grid;
  gap: 10px;
}

.config-panel.collapsed .config-panel-body {
  display: none;
}

.collapse-btn {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.product-list {
  display: grid;
  gap: 8px;
}

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

.layer-btn {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.layer-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.product-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "select delete"
    "controls controls";
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.62);
}

.product-item.active {
  border-color: rgba(255, 140, 66, 0.55);
  background: rgba(255, 140, 66, 0.12);
}

.product-select-btn {
  grid-area: select;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 0;
  padding: 4px 6px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.product-title {
  font-weight: 700;
  white-space: nowrap;
}

.product-name {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-delete-btn {
  grid-area: delete;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: rgba(180, 50, 32, 0.1);
  color: #9f2f20;
  font: inherit;
  cursor: pointer;
}

.product-delete-btn:hover {
  background: rgba(180, 50, 32, 0.18);
}

.product-list-controls {
  grid-area: controls;
  display: grid;
  gap: 8px;
  padding-top: 2px;
}

.product-control-row {
  display: grid;
  gap: 6px;
}

.product-control-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.product-control-track {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 30px;
  gap: 8px;
  align-items: center;
}

.product-control-label,
.product-control-value {
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.product-control-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.product-control-btn {
  min-width: 30px;
  height: 28px;
  border: 1px solid rgba(166, 95, 43, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.product-control-btn:hover {
  border-color: rgba(255, 140, 66, 0.42);
  background: rgba(255, 140, 66, 0.1);
}

.product-control-range {
  width: 100%;
  min-width: 0;
  accent-color: #ff8c42;
}

.slot-tab {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.62);
  text-align: center;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.slot-tab:hover {
  transform: translateY(-1px);
}

.slot-tab.active {
  border-color: rgba(166, 95, 43, 0.48);
  background: rgba(166, 95, 43, 0.12);
}

.slot-tab-title {
  font-weight: 700;
  white-space: nowrap;
}

.slot-tab-status {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
}

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

.slot-meta,
.slot-status,
.text-hint {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.text-editor {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.text-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.field-group {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.54);
}

.field-group-title {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.text-preset-grid {
  margin-top: 10px;
}

.image-editor {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.logo-editor {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.logo-preset-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.logo-preset-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  cursor: pointer;
}

.logo-preset-btn:hover {
  border-color: rgba(44, 181, 109, 0.55);
  background: rgba(44, 181, 109, 0.1);
}

.logo-preset-btn img {
  max-width: 100%;
  max-height: 42px;
  object-fit: contain;
}

.image-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.image-editor-value {
  font-size: 13px;
  color: var(--muted);
}

.image-crop-stage {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 1.3 / 1;
  border-radius: 14px;
  border: 1px solid var(--line);
  background:
    linear-gradient(45deg, rgba(35, 29, 19, 0.06) 25%, transparent 25%, transparent 75%, rgba(35, 29, 19, 0.06) 75%),
    linear-gradient(45deg, rgba(35, 29, 19, 0.06) 25%, transparent 25%, transparent 75%, rgba(35, 29, 19, 0.06) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 9px 9px;
  cursor: grab;
  touch-action: none;
}

.image-crop-stage.dragging {
  cursor: grabbing;
}

.image-crop-preview {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  max-width: none;
}

.image-angle-presets {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.image-angle-presets button {
  min-width: 0;
  padding: 7px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.image-angle-presets button.active {
  border-color: rgba(255, 140, 66, 0.9);
  background: rgba(255, 140, 66, 0.16);
  color: #9b4a14;
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.field span {
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.field textarea,
.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font: inherit;
}

.field textarea {
  resize: vertical;
  min-height: 86px;
}

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

.upload-btn,
.clear-btn,
.preview-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 0;
  cursor: pointer;
  text-decoration: none;
}

.upload-btn {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--accent);
  color: white;
  font-weight: 600;
}

.upload-btn-secondary {
  background: rgba(166, 95, 43, 0.14);
  color: var(--accent-strong);
}

.upload-btn input {
  display: none;
}

.clear-btn,
.preview-link {
  padding: 10px 12px;
  background: rgba(35, 29, 19, 0.08);
  color: var(--text);
}

.stage-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: none;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#preview-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.live-preview-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.live-preview-layer img {
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.live-top-edges {
  position: absolute;
  object-fit: fill;
  z-index: 3;
}

.frontend-composite-canvas {
  position: absolute;
  pointer-events: none;
  z-index: 2;
}

.live-product,
.live-logo,
.live-slot-layer,
.live-perspective-plane,
.live-text-rotated,
.live-text {
  position: absolute;
  pointer-events: none;
  transform-origin: top left;
}

.live-product {
  z-index: 1;
}

.live-text-rotated {
  transform-origin: center center;
}

.live-slot-layer {
  overflow: hidden;
}

.live-perspective-plane {
  left: 0;
  top: 0;
}

.live-slot-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.live-text {
  color: #fff4c8;
  box-sizing: border-box;
  font-family: "Noto Sans CJK SC", "Noto Sans SC", "Hiragino Sans GB", "Arial Unicode MS", Arial, sans-serif;
  font-weight: 700;
  line-height: 1.05;
  white-space: pre;
  overflow: visible;
  text-align: center;
  -webkit-text-stroke: 1px rgba(62, 36, 96, 0.85);
  text-shadow: 0 6px 12px rgba(20, 13, 33, 0.28);
}

.slot-overlay,
.guide-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.slot-overlay {
  z-index: 2;
}

.guide-overlay {
  z-index: 4;
  overflow: visible;
}

.image-drag-layer,
.text-drag-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.image-drag-layer {
  z-index: 5;
}

.text-drag-layer {
  z-index: 3;
}

.image-drag-layer.active-layer,
.text-drag-layer.active-layer {
  z-index: 6;
}

.image-drag-box {
  position: absolute;
  border: 2px dashed rgba(77, 141, 255, 0.9);
  border-radius: 14px;
  background: rgba(77, 141, 255, 0.1);
  box-shadow: 0 8px 24px rgba(23, 62, 105, 0.18);
  pointer-events: auto;
  touch-action: none;
  cursor: move;
}

.image-drag-box.logo {
  border-color: rgba(44, 181, 109, 0.92);
  background: rgba(44, 181, 109, 0.12);
}

.image-drag-box.product {
  border-color: rgba(255, 140, 66, 0.94);
  background: rgba(255, 140, 66, 0.12);
}

.image-drag-box.product.available {
  border-color: rgba(255, 140, 66, 0.5);
  background: rgba(255, 140, 66, 0.06);
  box-shadow: 0 6px 18px rgba(120, 58, 18, 0.12);
  z-index: 2;
}

.image-drag-box.product.available .image-drag-label {
  opacity: 0.78;
}

.image-drag-box.product.available .image-drag-handle {
  opacity: 0.82;
}

.image-drag-box.product.active {
  background: rgba(255, 140, 66, 0.16);
  box-shadow: 0 12px 28px rgba(120, 58, 18, 0.22);
}

.image-drag-box.hit-target {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  z-index: 1;
}

.image-drag-box.active,
.text-drag-box.active {
  z-index: 5;
}

.image-drag-label {
  position: absolute;
  left: 10px;
  top: 10px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(17, 28, 46, 0.84);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  pointer-events: none;
}

.text-drag-box {
  position: absolute;
  border: 2px dashed rgba(166, 95, 43, 0.95);
  border-radius: 14px;
  background: rgba(166, 95, 43, 0.12);
  box-shadow: 0 8px 24px rgba(71, 49, 18, 0.18);
  pointer-events: auto;
  cursor: move;
  touch-action: none;
}

.text-drag-box.dragging {
  background: rgba(166, 95, 43, 0.2);
  box-shadow: 0 14px 32px rgba(71, 49, 18, 0.24);
}

.text-drag-box.hit-target {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  z-index: 1;
}

.text-drag-label {
  position: absolute;
  left: 10px;
  top: 10px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(35, 29, 19, 0.78);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0.04em;
  white-space: nowrap;
  user-select: none;
  pointer-events: none;
}

.text-drag-handle {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
  pointer-events: auto;
}

.text-drag-handle.rotate {
  left: 50%;
  top: -14px;
  transform: translate(-50%, -100%);
  background: #ff8c42;
  cursor: grab;
}

.text-drag-handle.skew {
  right: -14px;
  top: 50%;
  transform: translate(100%, -50%);
  background: #4d8dff;
  cursor: ew-resize;
}

.image-drag-handle {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
  pointer-events: auto;
}

.image-drag-handle.rotate {
  left: 50%;
  top: -14px;
  transform: translate(-50%, -100%);
  background: #ff8c42;
  cursor: grab;
}

.image-drag-handle.scale {
  right: -14px;
  bottom: -14px;
  transform: translate(100%, 100%);
  background: #ffffff;
  cursor: nwse-resize;
}

.slot-overlay polygon {
  fill: rgba(166, 95, 43, 0.12);
  stroke: rgba(166, 95, 43, 0.9);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.slot-overlay polygon.active {
  fill: rgba(166, 95, 43, 0.24);
}

.cropped-export-guide rect {
  fill: none;
  stroke: rgba(255, 35, 35, 0.98);
  stroke-width: 2.5;
  stroke-dasharray: 14 10;
  vector-effect: non-scaling-stroke;
}

.cropped-export-guide line {
  stroke: rgba(255, 35, 35, 0.9);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.cropped-export-guide line.third {
  stroke: rgba(255, 255, 255, 0.86);
  stroke-dasharray: 8 10;
}


@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .panel-side,
  .panel-stage {
    position: static;
    max-height: none;
  }

  .slot-list {
    overflow: visible;
    flex: initial;
  }

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