:root {
  color-scheme: light;
  --ink: #24302d;
  --muted: #63756f;
  --soft: #81958d;
  --mist-lilac: #e5e9f2;
  --mist-green: #d7e8d5;
  --mist-blue: #c8d5dd;
  --sage: #afc7b4;
  --deep-sage: #96b3a2;
  --line: rgba(255, 255, 255, 0.72);
  --line-strong: rgba(150, 179, 162, 0.58);
  --paper: #d7e8d5;
  --panel: rgba(255, 255, 255, 0.7);
  --panel-soft: rgba(255, 255, 255, 0.42);
  --accent: #6f9586;
  --accent-dark: #4f7568;
  --accent-soft: rgba(215, 232, 213, 0.74);
  --focus: #7fa595;
  --shadow: 0 26px 80px rgba(65, 91, 82, 0.16);
  --shadow-soft: 0 16px 42px rgba(65, 91, 82, 0.12);
  --glow: 0 0 0 1px rgba(255, 255, 255, 0.66), 0 0 44px rgba(255, 255, 255, 0.42);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(229, 233, 242, 0.86) 0%, rgba(215, 232, 213, 0.86) 46%, rgba(150, 179, 162, 0.82) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.58), rgba(200, 213, 221, 0.38)),
    var(--paper);
  color: var(--ink);
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1560px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.workspace {
  display: grid;
  grid-template-columns: 430px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.control-panel,
.preview-area,
.info-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(1.15);
}

.control-panel {
  position: sticky;
  top: 24px;
  display: grid;
  gap: 18px;
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 24px;
}

.control-panel::-webkit-scrollbar,
.legend-list::-webkit-scrollbar,
.canvas-stage::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.control-panel::-webkit-scrollbar-thumb,
.legend-list::-webkit-scrollbar-thumb,
.canvas-stage::-webkit-scrollbar-thumb {
  background: rgba(111, 149, 134, 0.5);
  border-radius: 8px;
}

.brand-block {
  display: grid;
  gap: 8px;
}

.brand-block h1,
.preview-header h2,
.panel-block h2,
.info-panel h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand-block h1 {
  color: #3f5e53;
  font-size: 31px;
  line-height: 1.18;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.86), 0 12px 30px rgba(111, 149, 134, 0.16);
}

.brand-copy {
  margin: 0;
  color: rgba(36, 48, 45, 0.72);
  font-size: 14px;
  line-height: 1.6;
}

.eyebrow {
  margin: 0 0 2px;
  color: #6f9586;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel-block {
  display: grid;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.block-title,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.panel-block h2,
.info-panel h3 {
  font-size: 15px;
  font-weight: 760;
}

.step-dot {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: linear-gradient(145deg, #ffffff, var(--mist-green));
  border: 1px solid rgba(255, 255, 255, 0.84);
  box-shadow: 0 8px 20px rgba(111, 149, 134, 0.18);
  color: #fff;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.file-drop,
.load-project {
  display: grid;
  gap: 8px;
  min-height: 104px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.54), rgba(215, 232, 213, 0.4)),
    var(--panel-soft);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
  cursor: pointer;
  align-content: center;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.load-project {
  min-height: 42px;
  place-items: center;
  color: var(--ink);
  font-weight: 760;
}

.file-drop:hover,
.file-drop:focus-within,
.load-project:hover,
.load-project:focus-within {
  border-color: rgba(255, 255, 255, 0.96);
  background: rgba(255, 255, 255, 0.66);
  transform: translateY(-1px);
}

.file-drop input,
.load-project input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-title {
  font-size: 18px;
  font-weight: 780;
}

.file-meta,
.muted,
.status-text,
.pattern-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

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

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  color: #3c514b;
  font-size: 13px;
  font-weight: 760;
}

.checkbox-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-dark);
}

.field-group.compact {
  gap: 6px;
}

.field-group label {
  color: #3c514b;
  font-size: 13px;
  font-weight: 760;
}

.range-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.range-label span {
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 780;
  white-space: nowrap;
}

select,
input[type="number"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

select:focus,
input[type="number"]:focus,
input[type="range"]:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(150, 179, 162, 0.24), 0 0 24px rgba(255, 255, 255, 0.42);
}

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

.size-grid,
.button-row {
  display: grid;
  gap: 10px;
}

.size-grid {
  grid-template-columns: 1fr 1fr;
}

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

button {
  min-height: 44px;
  border: 0;
  border-radius: 7px;
  padding: 0 16px;
  font-weight: 780;
  cursor: pointer;
  transition:
    background 160ms ease,
    color 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.primary-button {
  background: linear-gradient(135deg, #afc7b4, #6f9586);
  color: #fff;
  box-shadow: 0 12px 26px rgba(111, 149, 134, 0.24);
}

.primary-button:not(:disabled):hover {
  background: linear-gradient(135deg, #bcd2c1, #5f8677);
  transform: translateY(-1px);
}

.secondary-button,
.mini-button {
  border: 1px solid rgba(255, 255, 255, 0.76);
  background: rgba(255, 255, 255, 0.48);
  color: var(--ink);
}

.mini-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.secondary-button:not(:disabled):hover,
.mini-button:not(:disabled):hover {
  border-color: rgba(255, 255, 255, 0.94);
  background: rgba(215, 232, 213, 0.62);
}

.status-text {
  min-height: 20px;
  margin: 0;
}

.crop-preview {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 300px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(229, 233, 242, 0.42) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(229, 233, 242, 0.42) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(229, 233, 242, 0.42) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(229, 233, 242, 0.42) 75%);
  background-color: rgba(255, 255, 255, 0.42);
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
  overflow: hidden;
}

#cropCanvas {
  display: none;
  width: 100%;
  height: auto;
  cursor: crosshair;
  touch-action: none;
}

.crop-empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.crop-help {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.size-help {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.preview-area {
  min-width: 0;
  padding: 24px;
}

.preview-header {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: end;
  margin-bottom: 16px;
}

.preview-header h2 {
  font-size: 24px;
  color: #3f5e53;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.82), 0 12px 30px rgba(111, 149, 134, 0.14);
}

.canvas-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 620px;
  border: 1px solid rgba(255, 255, 255, 0.76);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(229, 233, 242, 0.38), rgba(215, 232, 213, 0.34)),
    rgba(255, 255, 255, 0.28);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.34);
  overflow: auto;
}

#patternCanvas {
  display: none;
  max-width: 100%;
  height: auto;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--glow), var(--shadow-soft);
  cursor: crosshair;
}

.empty-state {
  width: min(430px, calc(100% - 40px));
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.76);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
  text-align: center;
}

.result-grid {
  display: grid;
  grid-template-columns: minmax(210px, 1fr) minmax(220px, 1fr) minmax(210px, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.info-panel {
  box-shadow: none;
  padding: 16px;
}

.info-panel h3 {
  margin-bottom: 12px;
}

.panel-heading h3 {
  margin-bottom: 0;
}

.source-preview {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.36);
  overflow: hidden;
}

.source-preview img {
  display: none;
  max-width: 100%;
  max-height: 240px;
  object-fit: contain;
}

.paint-color-list {
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
  padding-right: 4px;
}

.paint-color-list.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.paint-color-option {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.38);
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}

.paint-color-option:hover,
.paint-color-option.active {
  border-color: var(--line-strong);
  background: rgba(215, 232, 213, 0.62);
}

.paint-color-text {
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-list {
  display: grid;
  gap: 6px;
  max-height: 240px;
  overflow: auto;
  padding-right: 4px;
}

.legend-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) minmax(56px, auto);
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
}

.legend-row:hover {
  background: rgba(255, 255, 255, 0.38);
}

.legend-row.active {
  border-color: var(--line-strong);
  background: rgba(215, 232, 213, 0.62);
}

.swatch {
  width: 26px;
  height: 26px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 6px;
}

.legend-name {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 760;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-code {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 520;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-count {
  justify-self: end;
  color: var(--ink);
  font-size: 13px;
  font-weight: 780;
  white-space: nowrap;
}

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

  .control-panel {
    position: static;
    max-height: none;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }
}

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

  .control-panel,
  .preview-area {
    padding: 18px;
  }

  .preview-header {
    display: grid;
    align-items: start;
  }

  .brand-block h1 {
    font-size: 24px;
  }

  .size-grid,
  .button-row {
    grid-template-columns: 1fr;
  }

  .crop-preview,
  .source-preview {
    min-height: 240px;
  }
}
