:root {
  color-scheme: light;
  --page: #eef0f7;
  --surface: #ffffff;
  --surface-subtle: #f7f7fb;
  --text: #17162a;
  --text-secondary: #686779;
  --border: #dedee8;
  --border-strong: #c9c8d7;
  --accent: #2d13ea;
  --accent-hover: #2410c4;
  --accent-soft: #ece9ff;
  --danger: #b4233a;
  --focus: #765fff;
  --radius-card: 18px;
  --radius-control: 12px;
  --shadow-panel: 0 18px 60px rgb(40 35 94 / 0.1);
  font-family: "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--page); }

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 82% 15%, rgb(45 19 234 / 0.09), transparent 30rem),
    var(--page);
}

button,
input,
select { font: inherit; }

button,
summary,
select,
input[type="color"],
.upload-button { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
summary:focus-visible,
select:focus-visible,
input:focus-visible,
.upload-button:has(input:focus-visible) {
  outline: 3px solid rgb(118 95 255 / 0.42);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
  min-height: 100dvh;
}

.editor {
  height: 100dvh;
  overflow-y: auto;
  padding: 30px 24px 56px;
  border-right: 1px solid var(--border);
  background: rgb(255 255 255 / 0.93);
  backdrop-filter: blur(22px);
}

.editor-header {
  padding-bottom: 26px;
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
p { margin-top: 0; }

h1 {
  margin-bottom: 9px;
  font-size: clamp(30px, 3vw, 40px);
  line-height: 1.05;
  letter-spacing: -0.045em;
}

.intro {
  max-width: 34ch;
  margin-bottom: 22px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.65;
}

.header-actions {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 10px;
}

.button {
  min-height: 44px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-size: 14px;
  font-weight: 750;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease;
}

.button:active { transform: translateY(1px); }

.button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.button-primary {
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 8px 22px rgb(45 19 234 / 0.22);
}

.button-primary:hover { background: var(--accent-hover); }

.button-secondary {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface);
}

.button-secondary:hover { background: var(--surface-subtle); }

.settings-section { padding-top: 28px; }

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: 18px;
  letter-spacing: -0.025em;
}

.section-heading span {
  color: var(--text-secondary);
  font-size: 12px;
}

.type-controls {
  display: grid;
  grid-template-columns: 1fr 1.18fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-subtle);
}

.font-size-field {
  display: grid;
  gap: 9px;
}

.font-size-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 20px;
}

.font-size-heading > label:first-child {
  font-size: 12px;
  font-weight: 750;
}

.font-size-number {
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--text-secondary);
  font-size: 11px;
}

.font-size-number input {
  width: 48px;
  height: 28px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  text-align: center;
}

#fontSizeRange {
  width: 100%;
  min-height: 28px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

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

.color-field {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-subtle);
}

.color-field input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: none;
  cursor: pointer;
}

.color-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-field input[type="color"]::-webkit-color-swatch { border: 0; }

.color-field label {
  min-width: 0;
  cursor: pointer;
}

.color-field strong,
.color-field .color-hex {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-field strong {
  margin-bottom: 3px;
  font-size: 12px;
}

.color-field .color-hex {
  width: 100%;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--text-secondary);
  background: transparent;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  text-transform: uppercase;
}

.color-field .color-hex:focus-visible {
  outline: 2px solid rgb(118 95 255 / 0.42);
  outline-offset: 2px;
}

.segment-list {
  display: grid;
  gap: 10px;
}

.segment-card {
  overflow: clip;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.segment-card[open] {
  border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
  box-shadow: 0 9px 28px rgb(35 31 74 / 0.07);
}

.segment-card summary {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 18px;
  gap: 11px;
  align-items: center;
  min-height: 62px;
  padding: 10px 14px;
  list-style: none;
  cursor: pointer;
}

.segment-card summary::-webkit-details-marker { display: none; }

.segment-index {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 850;
}

.segment-summary {
  display: block;
  min-width: 0;
}

.segment-summary strong,
.segment-summary small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segment-summary strong {
  margin-bottom: 3px;
  font-size: 13px;
}

.segment-summary small {
  color: var(--text-secondary);
  font-size: 11px;
}

.chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-secondary);
  border-bottom: 2px solid var(--text-secondary);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 160ms ease;
}

.segment-card[open] .chevron { transform: rotate(225deg) translate(-1px, -1px); }

.segment-body {
  display: grid;
  gap: 15px;
  padding: 15px 14px 17px;
  border-top: 1px solid var(--border);
  background: var(--surface-subtle);
}

.field,
.image-field {
  display: grid;
  gap: 7px;
}

.field > span,
.image-field > span {
  font-size: 12px;
  font-weight: 750;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  color: var(--text);
  background: var(--surface);
}

.field input:hover,
.field select:hover { border-color: #aaa9bb; }

.product-fields {
  display: grid;
  gap: 15px;
}

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

.image-upload-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.image-thumb {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 13px;
  background-color: #ffffff;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
}

.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.upload-button:hover { background: var(--accent-soft); }
.upload-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.image-field > small {
  color: var(--text-secondary);
  font-size: 10px;
  line-height: 1.5;
}

.preview-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 100dvh;
  padding: 34px clamp(24px, 5vw, 72px) 26px;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.preview-header h2 {
  margin-bottom: 0;
  font-size: 22px;
  letter-spacing: -0.03em;
}

.preview-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #1e9b62;
  box-shadow: 0 0 0 4px rgb(30 155 98 / 0.12);
}

.canvas-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 24px 0;
}

#wheelCanvas {
  display: block;
  width: min(100%, 720px, calc(100dvh - 165px));
  height: auto;
  max-height: calc(100dvh - 165px);
  border-radius: 50%;
  filter: drop-shadow(0 22px 36px rgb(32 23 104 / 0.15));
}

.preview-note {
  margin: 0;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.toast {
  position: fixed;
  z-index: 10;
  right: 24px;
  bottom: 24px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 16px;
  border: 1px solid rgb(255 255 255 / 0.18);
  border-radius: 12px;
  color: #ffffff;
  background: #242235;
  box-shadow: 0 14px 36px rgb(24 22 45 / 0.28);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 16px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.toast.is-error { background: var(--danger); }

.toast-close {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid rgb(255 255 255 / 0.28);
  border-radius: 9px;
  color: #ffffff;
  background: rgb(255 255 255 / 0.1);
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

@media (max-width: 920px) {
  body { overflow: auto; }

  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .editor {
    height: auto;
    overflow: visible;
    padding: 26px 18px 48px;
    border-right: 0;
  }

  .preview-pane {
    min-height: auto;
    padding: 24px 18px 20px;
  }

  #wheelCanvas {
    width: min(82vw, 560px);
    max-height: none;
  }
}

@media (max-width: 520px) {
  .preview-header { align-items: flex-end; }
  .preview-meta { max-width: 96px; text-align: right; }
  .canvas-stage { padding: 18px 0 12px; }
  #wheelCanvas { width: min(92vw, 500px); }
  .color-grid { grid-template-columns: 1fr; }
  .type-controls { grid-template-columns: 1fr; }
  .color-field .color-hex,
  .field input,
  .field select,
  .font-size-number input { font-size: 16px; }
  .editor-header { padding-bottom: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
