:root {
  --bg: #e7e2d8;
  --bg-deep: #d9d2c4;
  --surface: #f7f4ee;
  --ink: #1c1914;
  --ink-soft: #5c564c;
  --line: rgba(28, 25, 20, 0.12);
  --accent: #c45c26;
  --accent-hover: #a84a1a;
  --ok: #2f6b4f;
  --shadow: 0 18px 50px rgba(28, 25, 20, 0.12);
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Instrument Serif", Georgia, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(196, 92, 38, 0.14), transparent 50%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(47, 107, 79, 0.1), transparent 45%),
    linear-gradient(165deg, var(--bg) 0%, var(--bg-deep) 100%);
  background-attachment: fixed;
}

body {
  min-height: 100vh;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 20px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, var(--accent), #e8a06a 55%, var(--ok));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.brand-name {
  font-family: var(--display);
  font-size: 1.65rem;
  letter-spacing: 0.02em;
}

.steps {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  background: rgba(247, 244, 238, 0.7);
  padding: 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.step {
  border: 0;
  background: transparent;
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

.step.is-active {
  background: var(--ink);
  color: var(--surface);
}

.step.is-done {
  color: var(--ok);
}

.workspace {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  min-height: 640px;
  overflow: hidden;
}

.panel {
  display: none;
  padding: 28px;
  animation: fadeIn 0.35s ease;
}

.panel.is-active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.panel-intro {
  margin-bottom: 24px;
  max-width: 520px;
}

.panel-intro h1 {
  font-family: var(--display);
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  font-weight: 400;
  margin: 0 0 8px;
  line-height: 1.15;
}

.panel-intro p,
.muted {
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.55;
}

.small {
  font-size: 0.85rem;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.product-card {
  text-align: left;
  border: 1px solid var(--line);
  background: #fffdf9;
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  color: var(--ink);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.product-card:hover {
  transform: translateY(-3px);
  border-color: rgba(196, 92, 38, 0.45);
  box-shadow: 0 12px 28px rgba(28, 25, 20, 0.08);
}

.product-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(196, 92, 38, 0.2);
}

.product-visual {
  height: 120px;
  border-radius: 10px;
  margin-bottom: 14px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(28, 25, 20, 0.08);
}

.product-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.45), transparent 55%);
  pointer-events: none;
}

.product-label {
  position: absolute;
  right: 10px;
  bottom: 8px;
  z-index: 1;
  font-family: var(--display);
  font-size: 1.4rem;
  color: rgba(28, 25, 20, 0.55);
}

.product-shape {
  width: 64px;
  height: 64px;
  border: 2px solid rgba(28, 25, 20, 0.45);
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 6px 16px rgba(28, 25, 20, 0.12);
}

.product-shape.cylinder {
  width: 56px;
  height: 70px;
  border-radius: 10px 10px 14px 14px;
}

.product-shape.plane {
  width: 48px;
  height: 78px;
  border-radius: 8px;
}

.product-shape.glb {
  width: 72px;
  height: 48px;
  border-radius: 8px;
  clip-path: none;
}

.empty-hint {
  grid-column: 1 / -1;
  padding: 28px 18px;
  text-align: center;
  color: var(--ink-soft);
  background: rgba(28, 25, 20, 0.03);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  line-height: 1.6;
}

.empty-hint code {
  font-size: 0.9rem;
  background: rgba(28, 25, 20, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
}

.product-card h3 {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

.product-card p {
  margin: 0 0 12px;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.product-card .price {
  font-weight: 600;
  color: var(--accent);
}

.editor-layout,
.preview-layout,
.order-layout,
.studio-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  min-height: 560px;
}

.preview-layout {
  grid-template-columns: 1fr 300px;
}

.order-layout {
  grid-template-columns: 1fr 340px;
  align-items: start;
}

.studio-layout {
  grid-template-columns: 270px 1fr;
  gap: 16px;
}

.studio-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-height: 560px;
}

.studio-canvas,
.studio-viewer {
  min-height: 520px;
}

.studio-viewer {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #2a2620 0%, #141210 100%);
}

.studio-viewer #viewer3d {
  width: 100%;
  height: 100%;
  min-height: 520px;
}

.viewer-meta {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 2;
  pointer-events: none;
  color: #fff;
}

.badge-live {
  background: rgba(47, 107, 79, 0.9);
}

.badge-live.is-wait {
  background: rgba(28, 25, 20, 0.65);
}

.studio-side {
  max-height: calc(100vh - 140px);
  overflow: auto;
  padding-right: 4px;
}

.sidebar,
.preview-side,
.order-form,
.order-summary {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar h2,
.preview-side h2,
.order-form h2,
.order-summary h3 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.55rem;
  margin: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field > label {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.field input,
.field textarea {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}

.field input:focus,
.field textarea:focus {
  border-color: rgba(196, 92, 38, 0.55);
  box-shadow: 0 0 0 3px rgba(196, 92, 38, 0.12);
}

.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
  padding: 0;
}

.btn-shopify {
  background: #008060;
  color: #fff;
  margin-top: 8px;
}

.btn-shopify:hover:not(:disabled) {
  background: #006e52;
}

.placement-info {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(28, 25, 20, 0.04);
  border: 1px solid var(--line);
  font-size: 0.88rem;
  color: var(--ink-soft);
  line-height: 1.45;
  word-break: break-all;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--surface);
  cursor: pointer;
  font-weight: 500;
  text-align: center;
}

.upload-btn:hover {
  background: #2a251f;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s ease, transform 0.15s ease;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(28, 25, 20, 0.04);
}

.btn-block {
  width: 100%;
}

.sidebar-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview-side .sidebar-actions {
  flex-direction: row;
  flex-wrap: wrap;
}

.slider-row {
  display: grid;
  grid-template-columns: 40px 1fr;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.tip {
  background: rgba(196, 92, 38, 0.08);
  border-radius: 10px;
  padding: 12px;
}

.tip p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--ink-soft);
  line-height: 1.45;
}

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

.canvas-meta {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 2;
  pointer-events: none;
}

.badge {
  background: rgba(28, 25, 20, 0.8);
  color: #fff;
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 999px;
}

#editorCanvas {
  max-width: 100%;
  max-height: 480px;
  background: transparent;
  box-shadow: none;
  cursor: grab;
  touch-action: none;
}

#editorCanvas:active {
  cursor: grabbing;
}

.canvas-hint {
  position: absolute;
  color: var(--ink-soft);
  font-size: 0.95rem;
  pointer-events: none;
}

.canvas-hint.is-hidden {
  display: none;
}

.viewer-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #2a2620 0%, #141210 100%);
  min-height: 520px;
}

#viewer3d {
  width: 100%;
  height: 520px;
}

.viewer-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.8rem;
  pointer-events: none;
}

.preview-thumbs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.preview-thumbs div {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.preview-thumbs img,
#sumPreview {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.order-summary {
  background: #fffdf9;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.order-summary dl {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.order-summary dl > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.order-summary dt {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.order-summary dd {
  margin: 0;
  font-weight: 600;
}

.order-result {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.order-result a {
  color: var(--accent);
  font-weight: 600;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  z-index: 50;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}

.loading {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 20, 0.45);
  display: grid;
  place-items: center;
  z-index: 60;
  color: #fff;
}

.loading[hidden],
.toast[hidden],
[hidden] {
  display: none !important;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 860px) {
  .editor-layout,
  .preview-layout,
  .order-layout,
  .studio-layout,
  .studio-main {
    grid-template-columns: 1fr;
  }

  .viewer-wrap,
  #viewer3d,
  .studio-viewer,
  .studio-viewer #viewer3d,
  .studio-canvas {
    min-height: 360px;
    height: 360px;
  }

  .sidebar-actions {
    margin-top: 8px;
  }

  .panel {
    padding: 18px;
  }

  .studio-side {
    max-height: none;
  }
}

/* 独立站商品详情 iframe 嵌入 */
html.is-embed,
body.is-embed {
  background: #f7f4ee;
  background-attachment: scroll;
  min-height: 100%;
}

body.is-embed .app {
  max-width: none;
  padding: 12px;
}

body.is-embed .topbar .brand {
  display: none;
}

body.is-embed .steps .step[data-step="1"] {
  display: none;
}

body.is-embed #step-1 {
  display: none !important;
}

body.is-embed .panel-intro {
  display: none;
}
