:root {
  color-scheme: light;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #e5e1f1;
  --panel: #ffffff;
  --page: #f3f1fc;
  --soft: #f3f1fc;
  --lavender: #cec1ed;
  --lavender-strong: #9f8ad1;
  --lavender-dark: #7257b7;
  --accent: #8d6bd0;
  --warm: #b9788c;
  --gold: #a47d28;
  --focus: #a991db;
  --shadow: 0 18px 48px rgba(54, 42, 82, 0.1);
  --hairline: rgba(107, 88, 160, 0.16);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", Inter, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #ffffff 0, rgba(243, 241, 252, 0.72) 260px, rgba(255, 255, 255, 0.95) 620px),
    #f3f1fc;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="range"],
input[type="checkbox"],
.dropzone {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.dropzone:focus-within {
  outline: 3px solid rgba(159, 138, 209, 0.32);
  outline-offset: 2px;
}

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

.topbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(54, 42, 82, 0.06);
  backdrop-filter: blur(18px);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin: 0 auto 16px;
  max-width: 1680px;
  padding: 14px 16px;
}

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

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

h1 {
  font-size: clamp(1.35rem, 1.9vw, 2.1rem);
  letter-spacing: 0;
  line-height: 1.12;
  margin-bottom: 0;
}

h2 {
  font-size: 0.98rem;
  line-height: 1.25;
  margin-bottom: 0;
}

h3 {
  font-size: 0.92rem;
  margin-bottom: 10px;
}

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

.ghost-link,
.seg-button,
.mini-button,
.tool-button,
.primary-button,
.secondary-button {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  font-weight: 750;
  justify-content: center;
  line-height: 1;
  min-height: 40px;
  padding: 0 13px;
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
  white-space: nowrap;
}

.seg-button,
.mini-button,
.tool-button,
.secondary-button,
.ghost-link {
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
}

.ghost-link:hover,
.seg-button:hover,
.mini-button:hover,
.tool-button:hover,
.secondary-button:hover {
  border-color: var(--lavender-strong);
  transform: translateY(-1px);
}

.primary-button {
  background: #1d1d1f;
  border-color: #1d1d1f;
  color: #fff;
  width: 100%;
}

.primary-button:hover {
  background: #33284d;
  border-color: #33284d;
}

.secondary-button {
  width: 100%;
}

.workspace {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(292px, 352px) minmax(0, 1fr);
  margin: 0 auto;
  max-width: 1680px;
}

.control-panel,
.canvas-panel,
.materials-panel,
.export-panel,
.reference-pane,
.pattern-pane {
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(18px);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  align-self: start;
  display: grid;
  gap: 10px;
  padding: 14px;
  position: sticky;
  top: 12px;
}

.panel-section {
  border-bottom: 1px solid rgba(107, 88, 160, 0.13);
  display: grid;
  gap: 12px;
  padding: 4px 0 14px;
}

.panel-section:last-child {
  border-bottom: 0;
  padding-bottom: 4px;
}

.section-title,
.pane-header {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.section-title {
  justify-content: flex-start;
}

.step {
  align-items: center;
  background: #f3f1fc;
  border: 1px solid var(--lavender);
  border-radius: 50%;
  color: var(--lavender-dark);
  display: inline-flex;
  font-size: 0.8rem;
  font-weight: 800;
  height: 24px;
  justify-content: center;
  width: 24px;
}

.dropzone {
  align-items: center;
  background:
    linear-gradient(135deg, rgba(206, 193, 237, 0.32), rgba(243, 241, 252, 0.92)),
    #fff;
  border: 1px dashed var(--lavender-strong);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  min-height: 104px;
  padding: 20px;
  text-align: center;
}

.dropzone input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.dropzone span {
  font-weight: 800;
}

.dropzone small {
  color: var(--muted);
}

.dropzone.is-dragging {
  border-color: var(--lavender-dark);
  box-shadow: 0 0 0 3px rgba(206, 193, 237, 0.42);
}

.source-canvas-wrap,
.pattern-scroll {
  background: #fbfaff;
  border: 1px solid rgba(107, 88, 160, 0.14);
  border-radius: 8px;
  min-height: 168px;
  overflow: hidden;
  position: relative;
}

#sourceCanvas {
  display: block;
  height: auto;
  width: 100%;
}

.empty-note {
  color: var(--muted);
  font-size: 0.92rem;
  inset: 0;
  margin: auto;
  pointer-events: none;
  position: absolute;
  text-align: center;
  top: 46%;
}

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

.preset-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.field > span,
.compact-field > span,
.check-row span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.field input[type="number"],
.field select,
.compact-field select,
.compact-field input[type="number"] {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(107, 88, 160, 0.18);
  border-radius: 8px;
  color: var(--ink);
  min-height: 39px;
  padding: 0 10px;
  width: 100%;
}

.field input[type="range"],
.compact-field input[type="range"] {
  accent-color: var(--lavender-dark);
  width: 100%;
}

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

.check-row {
  align-items: center;
  display: flex;
  gap: 9px;
}

.check-row input {
  accent-color: var(--lavender-dark);
  height: 18px;
  width: 18px;
}

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

.stats-grid div {
  background: rgba(243, 241, 252, 0.66);
  border: 1px solid rgba(107, 88, 160, 0.13);
  border-radius: 8px;
  padding: 10px;
}

.stats-grid dt {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.stats-grid dd {
  font-size: 1rem;
  font-weight: 850;
  margin: 0;
}

.quality-note {
  background: #fff9f7;
  border: 1px solid #ead2ca;
  border-radius: 8px;
  color: #70483f;
  font-size: 0.86rem;
  line-height: 1.45;
  margin: 0;
  padding: 10px;
}

.canvas-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.tool-strip {
  align-items: center;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(18px);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
}

.tool-button {
  height: 44px;
  min-width: 44px;
  padding: 0;
  position: relative;
  width: 44px;
}

.tool-button.is-active {
  background: #1d1d1f;
  border-color: #1d1d1f;
  color: #fff;
  box-shadow: 0 8px 18px rgba(29, 29, 31, 0.18);
}

.tool-button svg {
  fill: none;
  height: 22px;
  pointer-events: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 22px;
}

.icon-fill {
  fill: rgba(206, 193, 237, 0.38);
  stroke: none;
}

.tool-button.is-active .icon-fill {
  fill: rgba(255, 255, 255, 0.24);
}

.tool-button::after {
  background: var(--ink);
  border-radius: 6px;
  bottom: calc(100% + 8px);
  color: #fff;
  content: attr(data-label);
  font-size: 0.73rem;
  font-weight: 800;
  left: 50%;
  opacity: 0;
  padding: 6px 8px;
  pointer-events: none;
  position: absolute;
  transform: translateX(-50%) translateY(3px);
  transition: opacity 120ms ease, transform 120ms ease;
  white-space: nowrap;
  z-index: 5;
}

.tool-button:hover::after,
.tool-button:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.sr-only {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.compact-field {
  align-items: center;
  grid-template-columns: auto minmax(72px, 130px);
}

.preview-switch {
  align-items: center;
  display: grid;
  gap: 7px;
  min-width: 232px;
}

.preview-switch > span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.preview-switch select {
  display: none;
}

.preview-options {
  background: rgba(243, 241, 252, 0.82);
  border: 1px solid rgba(107, 88, 160, 0.15);
  border-radius: 8px;
  display: grid;
  gap: 3px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 3px;
}

.preview-option {
  background: transparent;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  min-height: 32px;
  padding: 0 10px;
}

.preview-option.is-active {
  background: #ffffff;
  box-shadow: 0 4px 14px rgba(54, 42, 82, 0.12);
  color: var(--ink);
}

.compare-layout {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(250px, 0.46fr) minmax(360px, 1fr);
}

.reference-pane,
.pattern-pane,
.materials-panel,
.export-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.pane-header span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

#referenceCanvas {
  background: #fbfaff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
  max-height: 440px;
  width: 100%;
}

.pattern-scroll {
  align-items: start;
  display: grid;
  justify-items: start;
  min-height: 620px;
  overflow: auto;
  padding: 14px;
}

#patternCanvas {
  display: block;
  flex: none;
  max-width: none;
  transform-origin: top left;
}

.bottom-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(280px, 1fr) minmax(260px, 0.42fr);
}

.color-list {
  display: grid;
  gap: 7px;
  max-height: 360px;
  overflow: auto;
  padding-right: 3px;
}

.color-row {
  align-items: center;
  background: #fbfcfb;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: 30px minmax(0, 1fr) auto auto auto;
  min-height: 48px;
  padding: 7px;
}

.color-row.is-active {
  border-color: var(--lavender-dark);
  box-shadow: 0 0 0 2px rgba(206, 193, 237, 0.45);
}

.swatch {
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 50%;
  height: 28px;
  width: 28px;
}

.color-meta {
  min-width: 0;
}

.color-name {
  display: block;
  font-size: 0.87rem;
  font-weight: 850;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-code {
  color: var(--muted);
  display: block;
  font-size: 0.75rem;
}

.count-pill {
  background: var(--soft);
  border: 1px solid #e2daf3;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 850;
  padding: 6px 9px;
}

.row-action {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--lavender-dark);
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 850;
  justify-content: center;
  min-width: 32px;
  min-height: 34px;
  padding: 0;
  width: 34px;
}

.row-action:hover {
  background: #f8f5ff;
  border-color: var(--lavender-strong);
}

.row-action svg {
  fill: none;
  height: 18px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.85;
  width: 18px;
}

.row-action .icon-fill {
  fill: rgba(206, 193, 237, 0.36);
  stroke: none;
}

.shop-reco {
  background: var(--soft);
  border: 1px solid #e2daf3;
  border-radius: 8px;
  padding: 12px;
}

.shop-reco ul {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.shop-reco a {
  color: var(--lavender-dark);
  font-weight: 800;
}

.toast {
  background: var(--ink);
  border-radius: 8px;
  bottom: 18px;
  color: #fff;
  left: 50%;
  padding: 11px 14px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 20;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }

  .compare-layout,
  .bottom-grid {
    grid-template-columns: 1fr;
  }
}

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

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions,
  .tool-strip {
    width: 100%;
  }

  .topbar-actions > *,
  .export-actions {
    flex: 1;
  }

  .dimension-grid,
  .button-row,
  .preset-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .compact-field {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .preview-switch {
    min-width: 0;
    width: 100%;
  }

  .pattern-scroll {
    min-height: 460px;
    padding: 10px;
  }

  .color-row {
    grid-template-columns: 28px minmax(0, 1fr) auto auto;
  }

  .color-row .count-pill {
    grid-column: 3 / -1;
  }

  .color-row .row-action {
    grid-column: auto;
  }
}
