* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f7f8fa;
  color: #1f2937;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.app-header {
  background: #ffffff;
  border-bottom: 1px solid #eef0f3;
}
.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.header-text h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: #111827;
}
.subtitle { color: #6b7280; margin: 4px 0 0; font-size: 13px; }

.lang-switch { display: flex; border: 1px solid #e5e7eb; border-radius: 8px; overflow: hidden; }
.lang-btn {
  background: #fff;
  border: none;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  color: #4b5563;
}
.lang-btn + .lang-btn { border-left: 1px solid #e5e7eb; }
.lang-btn:hover { background: #f3f4f6; }
.lang-btn.active { background: #111827; color: #fff; }

.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px 48px;
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
}
@media (max-width: 900px) {
  .app-main {
    grid-template-columns: 1fr;
    padding: 12px 12px 32px;
    gap: 12px;
  }
  /* Stage appears first on mobile */
  .stage-wrap { order: 1; }
  .controls   { order: 2; }
}

/* Grid/flex items must be allowed to shrink below their content's intrinsic
   min-size, otherwise a long filename in the upload card pushes the whole
   column (and therefore the stage) wider than the viewport on mobile. */
.app-main > * { min-width: 0; }

.controls {
  background: #ffffff;
  border: 1px solid #eef0f3;
  border-radius: 12px;
  padding: 16px;
  height: fit-content;
  box-shadow: 0 1px 2px rgba(16,24,40,0.04);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.uploader { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.upload-card {
  display: block;
  border: 1.5px dashed #d1d5db;
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  background: #fafbfc;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
.upload-card:hover, .upload-card.drag-over {
  border-color: #2563eb;
  background: #eff6ff;
}
.upload-inner { min-width: 0; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  background: #eff6ff;
  color: #1d4ed8;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 6px;
}
.badge-top { background: #f5f3ff; color: #6d28d9; }
.hint {
  color: #6b7280;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: block;
}
.upload-card.filled .hint { color: #047857; }

.sliders { margin-top: 16px; display: flex; flex-direction: column; gap: 14px; }
.slider-group label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #374151;
  margin-bottom: 6px;
  font-weight: 500;
}
.slider-group input[type=range] { width: 100%; accent-color: #111827; }
.scale-row { display: flex; align-items: center; gap: 6px; }
.scale-row input[type=range] { flex: 1; }
.icon-btn {
  width: 26px;
  height: 26px;
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  color: #374151;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: #f3f4f6; }
.slider-group select {
  width: 100%;
  padding: 7px 8px;
  background: #fff;
  color: #111827;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 13px;
}

.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }
.btn {
  padding: 7px 10px;
  background: #fff;
  color: #374151;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn:hover { background: #f3f4f6; }
.btn.active { background: #111827; color: #fff; border-color: #111827; }
.btn-danger { color: #b91c1c; border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }

.stage-wrap { display: flex; flex-direction: column; gap: 8px; min-width: 0; max-width: 100%; }
.stage {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-height: 520px;
  height: calc(100vh - 220px);
  touch-action: none;
  background-color: #ffffff;
  background-image:
    linear-gradient(45deg, #f0f1f3 25%, transparent 25%),
    linear-gradient(-45deg, #f0f1f3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f0f1f3 75%),
    linear-gradient(-45deg, transparent 75%, #f0f1f3 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, 10px 0;
  border: 1px solid #eef0f3;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(16,24,40,0.04);
}

/* Image 1: centered, fit to stage (set via JS) */
.layer1 {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: none;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  z-index: 1;
}

/* Frame for image 2: absolute positioning with resize handles */
.frame {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  display: none;
  z-index: 2;
  outline: 1px dashed rgba(37, 99, 235, 0.6);
  outline-offset: 0;
}
.frame.hidden { display: none !important; }
.stage.drag-enabled .layer2 { cursor: grab; }
.stage.dragging .layer2 { cursor: grabbing; }

.layer2 {
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  opacity: 0.5;
}

.handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #2563eb;
  border: 1.5px solid #fff;
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  z-index: 3;
}
.handle.nw { left: -6px; top: -6px; cursor: nwse-resize; }
.handle.ne { right: -6px; top: -6px; cursor: nesw-resize; }
.handle.sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.handle.se { right: -6px; bottom: -6px; cursor: nwse-resize; }
.handle.n  { left: 50%; top: -6px; transform: translateX(-50%); cursor: ns-resize; }
.handle.s  { left: 50%; bottom: -6px; transform: translateX(-50%); cursor: ns-resize; }
.handle.w  { left: -6px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.handle.e  { right: -6px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

.frame.no-handles .handle { display: none; }
.frame.no-handles { outline: none; }

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  font-size: 14px;
  pointer-events: none;
}
.tip { color: #9ca3af; font-size: 12px; margin: 0; }

/* ===== SEO content ===== */
.seo-section {
  background: #ffffff;
  border-top: 1px solid #eef0f3;
  padding: 48px 24px;
}
.seo-inner {
  max-width: 1080px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
}
@media (max-width: 820px) {
  .seo-inner { grid-template-columns: 1fr; gap: 28px; }
}
.seo-section h2 {
  font-size: 18px;
  font-weight: 600;
  color: #111827;
  margin: 0 0 12px;
}
.seo-section p { color: #4b5563; font-size: 14px; line-height: 1.7; margin: 0 0 12px; }
.seo-section ul { padding-left: 18px; color: #4b5563; font-size: 14px; line-height: 1.8; margin: 0; }
.seo-section strong { color: #111827; font-weight: 600; }
.seo-section details {
  border: 1px solid #eef0f3;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  background: #fafbfc;
}
.seo-section details[open] { background: #fff; }
.seo-section summary {
  cursor: pointer;
  font-weight: 500;
  color: #111827;
  font-size: 14px;
  list-style: none;
}
.seo-section summary::-webkit-details-marker { display: none; }
.seo-section summary::before {
  content: '+';
  display: inline-block;
  width: 16px;
  color: #6b7280;
}
.seo-section details[open] summary::before { content: '−'; }
.seo-section details p { margin-top: 8px; font-size: 13px; }

.site-footer {
  text-align: center;
  padding: 20px 16px 32px;
  color: #9ca3af;
  font-size: 12px;
  background: #ffffff;
  border-top: 1px solid #eef0f3;
}
.site-footer p { margin: 0; }

/* ===== Mobile tweaks ===== */
@media (max-width: 900px) {
  .header-inner { padding: 14px 16px; }
  .header-text h1 { font-size: 18px; }
  .subtitle { font-size: 12px; }
  .stage {
    min-height: 320px;
    height: 60vh;
    max-height: 520px;
  }
  .stage-wrap .tip { padding: 0 4px; }
  .controls { padding: 12px; }
  .toggles { grid-template-columns: 1fr 1fr; }
  /* Larger, easier-to-tap handles on touch devices */
  .handle { width: 16px; height: 16px; }
  .handle.nw { left: -9px; top: -9px; }
  .handle.ne { right: -9px; top: -9px; }
  .handle.sw { left: -9px; bottom: -9px; }
  .handle.se { right: -9px; bottom: -9px; }
  .handle.n  { top: -9px; }
  .handle.s  { bottom: -9px; }
  .handle.w  { left: -9px; }
  .handle.e  { right: -9px; }
  .seo-section { padding: 32px 16px; }
}
@media (pointer: coarse) {
  /* Bigger targets on any touch device */
  .handle { width: 18px; height: 18px; }
}
