:root {
  --ink: #251f2d;
  --muted: #746e7b;
  --faint: #a7a0aa;
  --paper: #f7f4f0;
  --panel: #fffdfb;
  --line: #e8e2e5;
  --line-strong: #d7ced4;
  --purple: #7357d7;
  --purple-dark: #5940bb;
  --purple-soft: #eee9ff;
  --peach: #ff8e6e;
  --green: #2f9b73;
  --shadow: 0 12px 38px rgba(63, 46, 70, 0.075);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 8%, rgba(255, 191, 174, 0.17), transparent 26rem),
    radial-gradient(circle at 88% 4%, rgba(115, 87, 215, 0.09), transparent 30rem),
    var(--paper);
}

button,
input,
select {
  font: inherit;
}

button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(115, 87, 215, 0.22);
  outline-offset: 2px;
}

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

.topbar {
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid rgba(218, 210, 215, 0.9);
  background: rgba(255, 253, 251, 0.86);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 17px;
  letter-spacing: 0.02em;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.2em;
  font-weight: 700;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  grid-template-columns: repeat(3, 8px);
  grid-auto-rows: 8px;
  gap: 2px;
  align-content: center;
  justify-content: center;
  border-radius: 11px;
  background: var(--ink);
  transform: rotate(-2deg);
  box-shadow: 0 6px 14px rgba(37, 31, 45, 0.2);
}

.brand-mark i {
  border-radius: 50%;
  background: #f9f4ee;
}

.brand-mark i:nth-child(2),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(6),
.brand-mark i:nth-child(8) {
  background: #ff9c7f;
}

.brand-mark i:nth-child(5) {
  background: #9277eb;
}

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

.mobile-dock,
.install-section {
  display: none;
}

.button.mobile-upload-button,
.button.mobile-edit-button,
.mobile-merge-bar,
.mobile-gesture-hint {
  display: none;
}

.main-nav {
  height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 11px;
  background: #f1edee;
}

.main-nav button {
  height: 30px;
  padding: 0 14px;
  cursor: pointer;
  color: var(--muted);
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 10px;
  font-weight: 750;
}

.main-nav button:hover,
.main-nav button.is-active {
  color: var(--purple-dark);
  background: #fff;
  box-shadow: 0 2px 8px rgba(44, 34, 49, 0.08);
}

.privacy-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  color: #446b5b;
  border: 1px solid #d9e9e2;
  background: #f0f8f4;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #36a878;
  box-shadow: 0 0 0 4px rgba(54, 168, 120, 0.11);
}

.workspace {
  display: grid;
  grid-template-columns: 318px minmax(430px, 1fr) 310px;
  gap: 14px;
  min-height: calc(100vh - 74px);
  padding: 14px;
  max-width: 1820px;
  margin: 0 auto;
}

.panel {
  border: 1px solid rgba(226, 218, 223, 0.95);
  background: rgba(255, 253, 251, 0.96);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.control-panel,
.export-panel {
  align-self: start;
  max-height: calc(100vh - 102px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #d9d0d6 transparent;
}

.panel-section {
  padding: 19px;
  border-bottom: 1px solid var(--line);
}

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

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

.section-heading h2 {
  margin: 3px 0 0;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.eyebrow {
  display: block;
  color: var(--purple);
  font-size: 9px;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.format-tag,
.board-count {
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.drop-zone {
  min-height: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  border: 1.5px dashed #cfc3d9;
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(243, 237, 255, 0.7), rgba(255, 247, 242, 0.8));
  transition: border-color 160ms ease, transform 160ms ease, background 160ms ease;
}

.drop-zone:hover,
.drop-zone.is-dragging {
  border-color: var(--purple);
  background: linear-gradient(135deg, #eee7ff, #fff1eb);
  transform: translateY(-1px);
}

.drop-zone strong {
  font-size: 13px;
}

.drop-zone > span:last-child {
  color: var(--muted);
  font-size: 10px;
}

.upload-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  margin-bottom: 2px;
  border-radius: 11px;
  color: var(--purple);
  background: #fff;
  box-shadow: 0 5px 14px rgba(85, 61, 116, 0.1);
}

.upload-icon svg,
.button svg,
.icon-button svg,
.ratio-lock svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.source-card {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 10px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #faf8f6;
}

.source-card img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 9px;
  background: #eee;
}

.source-info {
  min-width: 0;
}

.source-info strong,
.source-info span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-info strong {
  font-size: 12px;
}

.source-info span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.icon-button {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
}

.icon-button:hover {
  color: var(--purple);
  border-color: #cbbdf6;
  background: var(--purple-soft);
}

.size-grid {
  display: grid;
  grid-template-columns: 1fr 28px 1fr;
  align-items: end;
  gap: 7px;
}

.field > span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
}

.number-control {
  height: 38px;
  display: grid;
  grid-template-columns: 29px 1fr 29px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
}

.number-control button {
  padding: 0;
  cursor: pointer;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}

.number-control button:hover {
  color: var(--purple);
  background: var(--purple-soft);
}

.number-control input {
  width: 100%;
  min-width: 0;
  padding: 0;
  text-align: center;
  border: 0;
  border-inline: 1px solid var(--line);
  color: var(--ink);
  background: transparent;
  font-size: 12px;
  font-weight: 750;
  appearance: textfield;
}

.number-control input::-webkit-inner-spin-button,
.number-control input::-webkit-outer-spin-button {
  appearance: none;
}

.ratio-lock {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  margin-bottom: 5px;
  padding: 0;
  cursor: pointer;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ratio-lock svg {
  width: 13px;
  height: 13px;
}

.ratio-lock.is-active {
  color: var(--purple);
  border-color: #cabdf2;
  background: var(--purple-soft);
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  margin-top: 10px;
}

.preset-row button,
.view-switcher button {
  height: 29px;
  padding: 0 6px;
  cursor: pointer;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf8f7;
  font-size: 10px;
  font-weight: 700;
}

.preset-row button:hover,
.preset-row button.is-active,
.view-switcher button.is-active {
  color: var(--purple-dark);
  border-color: #c9bbf2;
  background: var(--purple-soft);
}

.full-field {
  display: block;
  margin-top: 13px;
}

select {
  width: 100%;
  height: 38px;
  padding: 0 34px 0 11px;
  cursor: pointer;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background-color: #fff;
  background-image: linear-gradient(45deg, transparent 50%, #7e7582 50%), linear-gradient(135deg, #7e7582 50%, transparent 50%);
  background-position: calc(100% - 15px) 16px, calc(100% - 10px) 16px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  appearance: none;
  font-size: 11px;
  font-weight: 650;
}

.text-button {
  padding: 3px 0;
  cursor: pointer;
  color: var(--purple);
  border: 0;
  background: transparent;
  font-size: 10px;
  font-weight: 750;
}

.text-button:hover {
  color: var(--purple-dark);
  text-decoration: underline;
}

.palette-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 9px;
}

.palette-meta strong {
  color: var(--ink);
}

.toggle-list {
  display: grid;
  gap: 2px;
}

.toggle-row {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.toggle-row span strong,
.toggle-row span small {
  display: block;
}

.toggle-row span strong {
  font-size: 11px;
}

.toggle-row span small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
}

.toggle-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-row i {
  width: 34px;
  height: 19px;
  flex: 0 0 auto;
  position: relative;
  border-radius: 99px;
  background: #d8d2d6;
  transition: background 150ms ease;
}

.toggle-row i::after {
  content: "";
  width: 15px;
  height: 15px;
  position: absolute;
  top: 2px;
  left: 2px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(32, 24, 36, 0.25);
  transition: transform 150ms ease;
}

.toggle-row input:checked + i {
  background: var(--purple);
}

.toggle-row input:checked + i::after {
  transform: translateX(15px);
}

.preview-column {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr) auto;
  gap: 12px;
}

.preview-toolbar {
  min-height: 66px;
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto minmax(160px, 1fr);
  align-items: center;
  gap: 16px;
  padding: 11px 15px;
}

.project-title-wrap {
  min-width: 0;
}

.project-title {
  width: min(100%, 360px);
  display: block;
  margin-top: 3px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  font-weight: 750;
  text-overflow: ellipsis;
}

.view-switcher {
  display: grid;
  grid-template-columns: repeat(2, 58px);
  gap: 4px;
  padding: 4px;
  border-radius: 11px;
  background: #f1edee;
}

.view-switcher button {
  border: 0;
  background: transparent;
}

.view-switcher button.is-active {
  background: #fff;
  box-shadow: 0 2px 8px rgba(44, 34, 49, 0.08);
}

.zoom-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.zoom-tools > span {
  min-width: 42px;
  text-align: center;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.canvas-stage {
  min-height: 440px;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(45deg, #f0ebed 25%, transparent 25%),
    linear-gradient(-45deg, #f0ebed 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f0ebed 75%),
    linear-gradient(-45deg, transparent 75%, #f0ebed 75%),
    #f7f3f4;
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}

.canvas-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 70px rgba(58, 42, 66, 0.05);
}

.empty-state {
  width: min(360px, 80%);
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  text-align: center;
  transform: translate(-50%, -50%);
}

.empty-state strong {
  display: block;
  margin-top: 18px;
  font-size: 18px;
}

.empty-state p {
  margin: 8px auto 18px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}

.empty-beads {
  width: 108px;
  height: 88px;
  display: grid;
  grid-template-columns: repeat(5, 18px);
  grid-template-rows: repeat(2, 18px);
  gap: 4px;
  align-content: center;
  justify-content: center;
  margin: 0 auto;
  transform: rotate(-7deg);
}

.empty-beads span {
  border-radius: 50%;
  background: #d9d1ec;
  box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.75), 0 4px 7px rgba(68, 50, 81, 0.12);
}

.empty-beads span:nth-child(2),
.empty-beads span:nth-child(5),
.empty-beads span:nth-child(7) {
  background: #ffad95;
}

.empty-beads span:nth-child(4),
.empty-beads span:nth-child(8) {
  background: #8ccbb3;
}

.canvas-scroll {
  width: 100%;
  height: 100%;
  min-height: 440px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  overflow: auto;
  padding: 34px;
  scrollbar-width: thin;
}

#patternCanvas {
  display: block;
  flex: 0 0 auto;
  margin: auto;
  max-width: none;
  max-height: none;
  background: transparent;
  filter: drop-shadow(0 16px 24px rgba(44, 31, 50, 0.13));
  transform-origin: center;
}

#patternCanvas.is-selecting {
  cursor: crosshair;
  touch-action: none;
}

.processing {
  width: 210px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 6;
  padding: 18px;
  border: 1px solid rgba(220, 210, 218, 0.95);
  border-radius: 15px;
  background: rgba(255, 253, 251, 0.94);
  box-shadow: 0 14px 42px rgba(42, 29, 49, 0.17);
  backdrop-filter: blur(12px);
  transform: translate(-50%, -50%);
}

.processing strong {
  margin-top: 4px;
  font-size: 11px;
}

.processing small {
  color: var(--muted);
  font-size: 9px;
}

.spinner {
  width: 25px;
  height: 25px;
  border: 3px solid #e5dff2;
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

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

.summary-strip {
  min-height: 67px;
  display: grid;
  grid-template-columns: repeat(4, minmax(76px, 1fr)) auto;
  align-items: center;
  overflow: hidden;
}

.summary-strip > div {
  min-width: 0;
  padding: 10px 16px;
  border-right: 1px solid var(--line);
}

.summary-strip span,
.summary-strip strong {
  display: block;
}

.summary-strip span {
  color: var(--muted);
  font-size: 9px;
}

.summary-strip strong {
  margin-top: 4px;
  font-size: 13px;
}

.summary-strip .engine-badge {
  min-width: 138px;
  border-right: 0;
  background: #faf7ff;
}

.engine-badge span {
  color: var(--purple);
  letter-spacing: 0.12em;
  font-weight: 800;
}

.engine-badge strong {
  font-size: 10px;
}

.export-panel {
  display: flex;
  flex-direction: column;
}

.material-section {
  min-height: 0;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.material-empty {
  min-height: 180px;
  display: grid;
  place-items: center;
  color: var(--faint);
  text-align: center;
  font-size: 10px;
}

.material-list {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 5px;
  max-height: none;
  flex: 1;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  scrollbar-width: thin;
}

.material-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.merge-tools {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
  padding: 10px;
  border: 1px solid #d9cff4;
  border-radius: 11px;
  background: #f8f5ff;
}

.merge-tools p {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.merge-scope-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.merge-scope-row select {
  min-width: 0;
  height: 34px;
}

.merge-tools #clearRegionButton {
  justify-self: start;
}

.selection-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 3px;
  border-radius: 8px;
  background: #ebe5f8;
}

.selection-tools button {
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.selection-tools button.is-active {
  background: #fff;
  color: var(--purple);
  box-shadow: 0 1px 5px rgba(44, 34, 49, 0.1);
}

.target-preview {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 10px;
  font-weight: 700;
}

.target-preview i {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 1px solid rgba(28, 22, 31, 0.14);
  border-radius: 50%;
}

.quick-targets {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.quick-targets button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 25px;
  padding: 2px 6px;
  border: 1px solid #ded7e7;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.quick-targets button.is-active {
  border-color: var(--purple);
  box-shadow: inset 0 0 0 1px var(--purple);
}

.quick-targets i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(28, 22, 31, 0.14);
}

.selected-color-info {
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 5px 7px;
  border-radius: 8px;
  background: #f5f1fa;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

.selected-color-info i,
.used-color-targets i {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  border: 1px solid rgba(28, 22, 31, 0.2);
  border-radius: 50%;
}

.selected-color-info strong {
  min-width: 0;
  color: var(--ink);
  font-weight: 700;
}

.used-color-picker {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.used-color-picker > strong {
  color: var(--muted);
  font-size: 10px;
}

.used-color-targets {
  display: flex;
  gap: 5px;
  min-width: 0;
  overflow-x: auto;
  padding: 1px 1px 5px;
  scrollbar-width: thin;
}

.used-color-targets button {
  min-height: 30px;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border: 1px solid #ded7e7;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.used-color-targets button.is-active {
  border-color: var(--purple);
  background: var(--purple-soft);
  box-shadow: inset 0 0 0 1px var(--purple);
}

.merge-history-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.merge-history-actions .button {
  min-height: 32px;
  padding: 0 9px;
  font-size: 10px;
}

.merge-history-actions span {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.merge-history-list {
  display: grid;
  gap: 4px;
  max-height: 104px;
  margin: 0;
  padding: 0 0 0 19px;
  overflow: auto;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

.merge-history-list li:first-child {
  color: var(--ink);
  font-weight: 700;
}

.merge-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.merge-action-row select {
  min-width: 0;
  height: 34px;
}

.merge-action-row .button {
  min-height: 34px;
  padding: 0 12px;
}

.merge-tools > .text-button {
  justify-self: start;
}

.material-item {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: 10px;
  transition: background 120ms ease;
}

.material-select {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  position: relative;
  cursor: pointer;
}

.material-select input {
  position: absolute;
  top: -3px;
  right: -3px;
  z-index: 1;
  width: 16px;
  height: 16px;
  margin: 0;
  opacity: 0;
  accent-color: var(--purple);
  cursor: pointer;
}

.material-list.is-merging .material-select input {
  opacity: 1;
}

.material-list.is-point-selecting .material-select input {
  display: none;
}

.material-select input:checked + .material-swatch {
  outline: 3px solid var(--purple);
  outline-offset: 2px;
}

.material-item:hover {
  background: #f7f3f5;
}

.material-swatch {
  width: 27px;
  height: 27px;
  position: relative;
  border: 1px solid rgba(28, 22, 31, 0.14);
  border-radius: 50%;
  box-shadow: inset 0 0 0 6px rgba(255, 255, 255, 0.2);
}

.material-swatch::after {
  content: "";
  width: 6px;
  height: 6px;
  position: absolute;
  top: 50%;
  left: 50%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.68);
  transform: translate(-50%, -50%);
}

.material-name {
  min-width: 0;
}

.material-name strong,
.material-name span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.material-name strong {
  font-size: 10px;
}

.material-name span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 8px;
}

.material-count {
  text-align: right;
}

.material-count strong,
.material-count span {
  display: block;
}

.material-count strong {
  font-size: 11px;
}

.material-count span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 8px;
}

.export-section {
  background: linear-gradient(180deg, #fffdfb, #fbf8ff);
}

.export-size {
  margin: 8px 0 10px;
  color: var(--muted);
  font-size: 9px;
  text-align: right;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 7px 0 13px;
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
}

.check-row input {
  width: 15px;
  height: 15px;
  accent-color: var(--purple);
}

.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 750;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease, border-color 140ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.button-primary {
  color: #fff;
  background: linear-gradient(135deg, #8065df, #6549c8);
  box-shadow: 0 7px 15px rgba(104, 76, 199, 0.23);
}

.button-primary:hover:not(:disabled) {
  box-shadow: 0 9px 20px rgba(104, 76, 199, 0.3);
}

.button-secondary {
  color: var(--purple-dark);
  border-color: #cfc3f0;
  background: #f5f1ff;
}

.button-ghost {
  color: var(--muted);
  border-color: var(--line);
  background: #fff;
}

.button.compact {
  min-height: 34px;
  padding: 0 11px;
  font-size: 10px;
}

.full-button {
  width: 100%;
  margin-top: 8px;
}

.export-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.5;
  text-align: center;
}

.toast {
  min-width: 180px;
  max-width: min(420px, calc(100vw - 32px));
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  padding: 11px 16px;
  pointer-events: none;
  color: #fff;
  border-radius: 11px;
  background: rgba(37, 31, 45, 0.94);
  box-shadow: 0 12px 28px rgba(35, 27, 40, 0.24);
  opacity: 0;
  font-size: 11px;
  text-align: center;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.catalog-page {
  width: min(1420px, calc(100% - 28px));
  display: grid;
  gap: 14px;
  margin: 14px auto 34px;
}

.catalog-hero {
  min-height: 210px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 50px;
  padding: 34px 40px;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(circle at 96% 0%, rgba(115, 87, 215, 0.14), transparent 23rem),
    radial-gradient(circle at 3% 100%, rgba(255, 142, 110, 0.14), transparent 24rem),
    rgba(255, 253, 251, 0.98);
}

.catalog-hero::after {
  content: "";
  width: 240px;
  height: 240px;
  position: absolute;
  right: -90px;
  top: -110px;
  border: 22px dotted rgba(115, 87, 215, 0.075);
  border-radius: 50%;
  pointer-events: none;
}

.catalog-intro {
  position: relative;
  z-index: 1;
}

.catalog-intro h1 {
  margin: 8px 0 9px;
  font-size: clamp(25px, 3vw, 40px);
  line-height: 1.15;
  letter-spacing: -0.025em;
}

.catalog-intro p {
  max-width: 580px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.screen-note {
  display: inline-flex;
  align-items: center;
  margin-top: 16px;
  padding: 7px 10px;
  color: #806047;
  border: 1px solid #efdecb;
  border-radius: 8px;
  background: #fff8ef;
  font-size: 9px;
  font-weight: 650;
}

.catalog-stats {
  display: grid;
  grid-template-columns: repeat(2, 126px);
  gap: 8px;
  position: relative;
  z-index: 1;
}

.catalog-stats div {
  min-height: 73px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 12px 15px;
  border: 1px solid rgba(220, 211, 218, 0.88);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(7px);
}

.catalog-stats strong,
.catalog-stats span {
  display: block;
}

.catalog-stats strong {
  font-size: 22px;
  line-height: 1;
}

.catalog-stats span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 650;
}

.catalog-browser {
  padding: 24px;
}

.catalog-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.catalog-search-wrap {
  width: min(570px, 100%);
  height: 44px;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 0 11px 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fff;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.catalog-search-wrap:focus-within {
  border-color: #aa98e3;
  box-shadow: 0 0 0 4px rgba(115, 87, 215, 0.1);
}

.catalog-search-wrap svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
}

.catalog-search-wrap input {
  width: 100%;
  min-width: 0;
  padding: 0;
  color: var(--ink);
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 11px;
}

.catalog-search-wrap input::-webkit-search-cancel-button {
  cursor: pointer;
}

.catalog-search-wrap kbd {
  min-width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  border: 1px solid var(--line);
  border-bottom-color: #ccc3c9;
  border-radius: 6px;
  background: #f8f5f5;
  font: 10px inherit;
}

.catalog-palette-filter {
  width: 196px;
  flex: 0 0 auto;
}

.catalog-palette-filter span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.catalog-palette-filter select {
  height: 44px;
  border-color: var(--line-strong);
  border-radius: 12px;
  background-position: calc(100% - 15px) 19px, calc(100% - 10px) 19px;
}

.catalog-result-count {
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  white-space: nowrap;
}

.series-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 17px 0 21px;
}

.series-filter button {
  min-width: 35px;
  height: 31px;
  padding: 0 10px;
  cursor: pointer;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf8f7;
  font-size: 10px;
  font-weight: 750;
}

.series-filter button:hover,
.series-filter button.is-active {
  color: #fff;
  border-color: var(--purple);
  background: var(--purple);
  box-shadow: 0 5px 12px rgba(115, 87, 215, 0.2);
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(126px, 1fr));
  gap: 9px;
}

.color-card {
  min-width: 0;
  padding: 8px;
  cursor: pointer;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.color-card:hover {
  z-index: 1;
  border-color: #b8a9df;
  box-shadow: 0 9px 20px rgba(55, 42, 62, 0.1);
  transform: translateY(-2px);
}

.color-card-swatch {
  height: 72px;
  position: relative;
  border: 1px solid rgba(30, 24, 33, 0.13);
  border-radius: 8px;
  overflow: hidden;
}

.color-card-swatch::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(145deg, rgba(255,255,255,.28), transparent 45%, rgba(0,0,0,.05));
}

.color-card-copy {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  position: absolute;
  right: 6px;
  top: 6px;
  z-index: 1;
  color: rgba(30, 24, 33, 0.7);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.76);
  opacity: 0;
  transition: opacity 120ms ease;
}

.color-card:hover .color-card-copy {
  opacity: 1;
}

.color-card-meta {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 7px;
  padding: 8px 2px 2px;
}

.color-card-meta strong,
.color-card-meta span {
  display: block;
}

.color-card-meta strong {
  font-size: 12px;
}

.color-card-meta span {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 8px;
}

.color-series-tag {
  min-width: 23px;
  padding: 3px 5px;
  color: var(--purple-dark);
  border-radius: 5px;
  background: var(--purple-soft);
  font-size: 8px;
  font-weight: 800;
  text-align: center;
}

.catalog-no-results {
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
}

.catalog-no-results strong {
  color: var(--ink);
  font-size: 14px;
}

.catalog-no-results span {
  margin-top: 6px;
  font-size: 10px;
}

.catalog-source {
  margin-top: 24px;
  padding-top: 16px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 9px;
  text-align: right;
}

.catalog-source a {
  color: var(--purple);
  font-weight: 700;
  text-decoration: none;
}

.catalog-source a:hover {
  text-decoration: underline;
}

.is-hidden {
  display: none !important;
}

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

@media (min-width: 1221px) {
  html[data-page="studio"],
  body[data-page="studio"] {
    overflow: hidden;
  }

  .workspace {
    height: calc(100vh - 74px);
    height: calc(100dvh - 74px);
    min-height: 0;
    overflow: hidden;
  }

  .control-panel,
  .export-panel,
  .preview-column {
    height: 100%;
    min-height: 0;
  }

  .control-panel,
  .export-panel {
    max-height: none;
  }

  .preview-column {
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .canvas-stage,
  .canvas-scroll {
    min-height: 0;
  }

}

@media (min-width: 1221px) and (max-height: 780px) {
  .topbar {
    height: 64px;
  }

  .workspace {
    height: calc(100vh - 64px);
    height: calc(100dvh - 64px);
    gap: 10px;
    padding: 10px;
  }

  .panel-section {
    padding: 10px 14px;
  }

  .section-heading {
    margin-bottom: 8px;
  }

  .full-field {
    margin-top: 9px;
  }

  .toggle-row {
    min-height: 40px;
  }

  .preview-column {
    gap: 10px;
  }

  .canvas-scroll {
    padding: 24px;
  }

  .summary-strip {
    min-height: 58px;
  }
}

@media (max-width: 1220px) {
  .workspace {
    grid-template-columns: 292px minmax(420px, 1fr);
  }

  .export-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    max-height: none;
  }

  .export-panel .panel-section {
    border-bottom: 0;
  }

  .material-section {
    border-right: 1px solid var(--line);
  }

  .material-list {
    max-height: 210px;
  }
}

@media (max-width: 820px) {
  .topbar {
    height: 64px;
    padding: 0 14px;
  }

  .privacy-pill,
  .topbar .button-ghost {
    display: none;
  }

  .main-nav button {
    padding: 0 9px;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    padding: 10px;
  }

  .control-panel,
  .export-panel {
    width: 100%;
    max-height: none;
  }

  .control-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-panel .panel-section {
    border-right: 1px solid var(--line);
  }

  .preview-column {
    grid-template-rows: auto minmax(400px, 64vh) auto;
    order: -1;
  }

  .preview-toolbar {
    grid-template-columns: 1fr auto;
  }

  .view-switcher {
    display: none;
  }

  .summary-strip {
    grid-template-columns: repeat(4, 1fr);
  }

  .summary-strip .engine-badge {
    display: none;
  }

  .catalog-hero {
    grid-template-columns: 1fr;
    gap: 26px;
    padding: 28px;
  }

  .catalog-stats {
    grid-template-columns: repeat(4, minmax(90px, 1fr));
  }

  .catalog-toolbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .catalog-search-wrap,
  .catalog-palette-filter {
    width: 100%;
  }
}

@media (max-width: 560px) {
  html,
  body {
    min-width: 320px;
  }

  .topbar {
    height: 58px;
    padding: 0 16px;
  }

  .brand {
    gap: 10px;
  }

  .brand strong {
    font-size: 16px;
  }

  .brand small {
    display: none;
  }

  .main-nav,
  .topbar-meta {
    display: none;
  }

  .workspace {
    gap: 8px;
    min-height: calc(100dvh - 58px);
    padding: 8px 8px calc(82px + env(safe-area-inset-bottom));
  }

  html[data-mobile-tab="preview"] .workspace {
    height: calc(100dvh - 58px - 70px - env(safe-area-inset-bottom));
    min-height: 0;
    overflow: hidden;
    padding-bottom: 8px;
  }

  html[data-mobile-tab="preview"],
  body[data-mobile-tab="preview"] {
    overflow: hidden;
  }

  html[data-mobile-tab="preview"] .control-panel,
  html[data-mobile-tab="preview"] .export-panel,
  html[data-mobile-tab="settings"] .preview-column,
  html[data-mobile-tab="settings"] .export-panel,
  html[data-mobile-tab="materials"] .preview-column,
  html[data-mobile-tab="materials"] .control-panel {
    display: none;
  }

  .mobile-dock {
    height: calc(70px + env(safe-area-inset-bottom));
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: start;
    padding: 5px 8px env(safe-area-inset-bottom);
    border-top: 1px solid var(--line);
    background: rgba(255, 253, 251, 0.96);
    box-shadow: 0 -8px 24px rgba(63, 46, 70, 0.08);
    backdrop-filter: blur(16px);
  }

  .mobile-dock button {
    min-height: 58px;
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 2px;
    padding: 2px;
    border: 0;
    border-radius: 11px;
    color: var(--muted);
    background: transparent;
    font-size: 11px;
    font-weight: 700;
  }

  .mobile-dock button.is-active {
    color: var(--purple-dark);
    background: var(--purple-soft);
  }

  .dock-icon {
    font-size: 21px;
    line-height: 1.15;
  }

  .preview-column {
    flex: 1;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 8px;
  }

  body[data-mobile-merging="true"] .preview-column {
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  body[data-mobile-merging="true"] .summary-strip {
    display: none;
  }

  .preview-toolbar {
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    gap: 6px;
    min-height: 56px;
    padding: 8px 10px;
  }

  .project-title {
    font-size: 16px;
  }

  .button.mobile-upload-button,
  .button.mobile-edit-button {
    min-height: 38px;
    display: inline-flex;
    padding: 0 9px;
    white-space: nowrap;
  }

  .button.mobile-edit-button.is-active {
    color: var(--purple-dark);
    border-color: #c8baf3;
    background: var(--purple-soft);
  }

  .mobile-merge-bar:not(.is-hidden) {
    display: grid;
    gap: 7px;
    padding: 9px 10px;
  }

  .mobile-merge-heading,
  .mobile-merge-tools,
  .mobile-merge-actions {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .mobile-merge-heading {
    justify-content: space-between;
  }

  .mobile-merge-heading strong {
    min-width: 0;
    overflow: hidden;
    color: var(--purple-dark);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-merge-heading .text-button {
    flex: 0 0 auto;
  }

  .mobile-merge-bar .selected-color-info {
    min-height: 30px;
    font-size: 11px;
  }

  .mobile-merge-bar .used-color-targets button {
    min-height: 34px;
    font-size: 11px;
  }

  .mobile-merge-tools button {
    flex: 1;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .mobile-merge-tools button.is-active {
    border-color: #c8baf3;
    background: var(--purple-soft);
    color: var(--purple-dark);
  }

  .mobile-merge-actions select {
    flex: 1;
    min-width: 0;
    height: 42px;
    font-size: 16px;
  }

  .mobile-merge-actions .button {
    flex: 0 0 auto;
    min-height: 42px;
    padding: 0 10px;
    font-size: 12px;
  }

  .mobile-merge-actions #mobileUndoMergeButton {
    padding: 0 8px;
  }

  .zoom-tools {
    gap: 3px;
  }

  .zoom-tools .icon-button {
    width: 36px;
    height: 36px;
    font-size: 17px;
  }

  .zoom-tools > span,
  .zoom-tools .text-button {
    display: none;
  }

  .canvas-stage,
  .canvas-scroll {
    min-height: 0;
  }

  .canvas-scroll {
    padding: 12px;
    overscroll-behavior: contain;
    touch-action: none;
  }

  body[data-pattern-ready="true"]:not([data-mobile-merging="true"]) .mobile-gesture-hint {
    display: block;
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 3;
    padding: 6px 9px;
    border-radius: 999px;
    background: rgba(39, 31, 47, 0.73);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    pointer-events: none;
  }

  .summary-strip {
    min-height: 62px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .summary-strip > div {
    padding: 8px 5px;
    text-align: center;
  }

  .summary-strip span {
    font-size: 9px;
  }

  .summary-strip strong {
    font-size: 12px;
  }

  .control-panel,
  .export-panel {
    margin: 0;
    overflow: visible;
  }

  .install-section {
    display: block;
  }

  .install-section p {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
  }

  .number-control,
  select {
    height: 44px;
    font-size: 16px;
  }

  .number-control input,
  .project-title,
  #colorSearchInput {
    font-size: 16px;
  }

  .number-control {
    grid-template-columns: 40px 1fr 40px;
  }

  .preset-row button,
  .ratio-lock {
    min-height: 40px;
  }

  .toggle-row {
    min-height: 52px;
  }

  .material-section {
    display: block;
  }

  .material-list {
    max-height: none;
    overflow: visible;
  }

  .material-item {
    min-height: 48px;
  }

  .export-section .button {
    min-height: 48px;
  }

  .control-panel,
  .export-panel {
    display: block;
  }

  .control-panel .panel-section,
  .material-section {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .catalog-page {
    width: calc(100% - 20px);
    margin-top: 10px;
    margin-bottom: calc(82px + env(safe-area-inset-bottom));
  }

  .catalog-hero,
  .catalog-browser {
    padding: 20px;
  }

  .catalog-stats {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .toast {
    bottom: calc(82px + env(safe-area-inset-bottom));
  }
}

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