:root {
  color-scheme: light;
  --paper: #f5f2ec;
  --surface: #fffdf9;
  --surface-2: #ebe7df;
  --ink: #201f1d;
  --muted: #706d66;
  --line: #d9d4ca;
  --coral: #ed684f;
  --coral-dark: #d9533d;
  --mint: #37a77f;
  --yellow: #f3c84b;
  --blue: #4e80c4;
  --shadow: 0 16px 45px rgba(51, 45, 35, 0.1);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); scroll-behavior: smooth; }

body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--paper); }

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, label:focus-within { outline: 3px solid rgba(78, 128, 196, 0.28); outline-offset: 2px; }

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

.topbar {
  height: 72px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 249, 0.92);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 11px; width: fit-content; }
.brand > span:last-child { display: flex; align-items: baseline; gap: 8px; }
.brand strong { font-size: 20px; letter-spacing: 0; }
.brand small { font-size: 12px; color: var(--muted); }

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--ink);
  background: var(--surface);
}
.brand-mark i { display: block; background: var(--coral); }
.brand-mark i:nth-child(2) { background: var(--yellow); }
.brand-mark i:nth-child(3) { background: var(--mint); }
.brand-mark i:nth-child(4) { background: var(--blue); }

.topbar-status { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 7px; }
.privacy-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 4px rgba(55, 167, 127, 0.12); }
.topbar-actions { display: flex; justify-content: flex-end; gap: 8px; }

.workspace {
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: 310px minmax(420px, 1fr) 320px;
  max-width: 1800px;
  margin: 0 auto;
}

.control-panel, .inventory-panel { background: var(--surface); padding: 24px; min-width: 0; }
.control-panel { border-right: 1px solid var(--line); overflow-y: auto; }
.inventory-panel { border-left: 1px solid var(--line); display: flex; flex-direction: column; max-height: calc(100vh - 72px); position: sticky; top: 72px; }

.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.panel-heading h1, .panel-heading h2 { margin: 2px 0 0; font-size: 21px; line-height: 1.2; letter-spacing: 0; }
.step-label { margin: 0; font: 700 10px/1.2 ui-monospace, monospace; color: var(--coral); }
.status-badge { padding: 5px 8px; border: 1px solid var(--line); color: var(--muted); font-size: 11px; background: var(--paper); }

.upload-zone {
  min-height: 138px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  border: 1px dashed #aaa49a;
  background: #faf8f3;
  cursor: pointer;
  transition: border-color 160ms, background 160ms, transform 160ms;
}
.upload-zone:hover, .upload-zone.is-dragging { border-color: var(--coral); background: #fff4ef; transform: translateY(-1px); }
.upload-zone strong { font-size: 14px; }
.upload-zone small { color: var(--muted); font-size: 11px; }
.upload-symbol { width: 34px; height: 34px; border: 1px solid var(--line); display: grid; place-items: center; margin-bottom: 4px; background: white; font-size: 20px; }

.source-preview { position: relative; height: 138px; overflow: hidden; border: 1px solid var(--line); background: #ddd; }
.source-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-remove { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border: 0; background: rgba(32, 31, 29, 0.82); color: white; cursor: pointer; font-size: 18px; }

.preset-row { display: flex; gap: 6px; margin-top: 10px; }
.chip { flex: 1; min-width: 0; padding: 7px 4px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; }
.chip:hover { color: var(--ink); border-color: #9e988d; background: var(--paper); }
.section-divider { height: 1px; background: var(--line); margin: 22px 0; }

.setting-group { margin: 0 0 22px; }
.setting-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; font-size: 12px; }
.setting-title > span:last-child, .setting-title strong { color: var(--muted); font-size: 11px; font-weight: 600; }
.segmented { display: grid; border: 1px solid var(--line); background: var(--paper); padding: 3px; gap: 3px; }
.segmented button { min-height: 30px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; }
.segmented button.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(20, 18, 15, 0.1); font-weight: 700; }
.size-segment { grid-template-columns: repeat(5, 1fr); }

.range { width: 100%; accent-color: var(--coral); height: 4px; }
.range-marks { display: flex; justify-content: space-between; color: #99948a; font-size: 10px; margin-top: 4px; }

.adjustments { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 0 16px; }
.adjustments summary { list-style: none; display: flex; justify-content: space-between; padding: 13px 0; font-size: 12px; cursor: pointer; }
.adjustments summary::-webkit-details-marker { display: none; }
.adjustments[open] summary span { transform: rotate(180deg); }
.slider-row { display: grid; grid-template-columns: 44px 1fr 36px; align-items: center; gap: 8px; padding: 7px 0; }
.slider-row:last-child { padding-bottom: 14px; }
.slider-row label, .slider-row output { font-size: 10px; color: var(--muted); }
.slider-row output { text-align: right; font-variant-numeric: tabular-nums; }
.transform-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.button, .tool-button, .icon-button {
  border: 1px solid var(--line);
  background: var(--surface);
  min-height: 36px;
  padding: 0 13px;
  cursor: pointer;
  font-size: 12px;
  transition: transform 140ms, background 140ms, border-color 140ms;
}
.button:hover, .tool-button:hover, .icon-button:hover:not(:disabled) { transform: translateY(-1px); border-color: #9e988d; }
.button:disabled, .tool-button:disabled, .icon-button:disabled { cursor: not-allowed; opacity: 0.38; }
.button.primary { background: var(--coral); color: white; border-color: var(--coral); font-weight: 700; }
.button.primary:hover { background: var(--coral-dark); border-color: var(--coral-dark); }
.button.dark { background: var(--ink); border-color: var(--ink); color: white; }
.button.secondary { background: var(--surface); }
.tool-button { background: transparent; color: var(--muted); }
.tool-button.compact, .button.compact { min-height: 32px; padding: 0 10px; font-size: 11px; }
.icon-button { width: 36px; padding: 0; display: inline-grid; place-items: center; font-size: 18px; }
.icon-button.small { width: 28px; min-height: 28px; font-size: 15px; }
.generate-button { width: 100%; margin-top: 14px; min-height: 44px; display: flex; align-items: center; justify-content: center; gap: 8px; }

.canvas-stage { min-width: 0; background: var(--paper); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-height: calc(100vh - 72px); }
.stage-toolbar { min-height: 58px; padding: 10px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.view-tabs { display: flex; align-items: center; gap: 2px; }
.view-tabs button { min-height: 32px; border: 0; background: transparent; padding: 0 14px; color: var(--muted); font-size: 12px; cursor: pointer; border-bottom: 2px solid transparent; }
.view-tabs button.is-active { color: var(--ink); border-color: var(--coral); font-weight: 700; }
.stage-actions { display: flex; gap: 6px; align-items: center; }

.canvas-wrap { min-height: 520px; overflow: auto; display: grid; place-items: center; padding: 32px; background-color: #ebe7df; background-image: linear-gradient(#e1dcd2 1px, transparent 1px), linear-gradient(90deg, #e1dcd2 1px, transparent 1px); background-size: 24px 24px; }
.canvas-wrap canvas { display: block; width: min(100%, 820px); height: auto; background: white; box-shadow: var(--shadow); image-rendering: pixelated; transform-origin: center; transition: width 180ms; cursor: crosshair; touch-action: manipulation; }

.empty-state { text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--ink); margin: 18px 0 6px; font-size: 18px; letter-spacing: 0; }
.empty-state p { margin: 0; font-size: 12px; }
.empty-grid { width: 112px; aspect-ratio: 1; margin: 0 auto; border: 1px solid #bcb6aa; background: repeating-linear-gradient(0deg, transparent 0 13px, #c9c3b8 13px 14px), repeating-linear-gradient(90deg, transparent 0 13px, #c9c3b8 13px 14px), linear-gradient(135deg, rgba(237,104,79,.25) 0 35%, rgba(243,200,75,.35) 35% 52%, rgba(55,167,127,.3) 52% 70%, rgba(78,128,196,.28) 70%); box-shadow: 7px 7px 0 rgba(32,31,29,.08); }

.stage-footer { min-height: 58px; padding: 10px 18px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--surface); }
.mode-control, .zoom-control { display: flex; align-items: center; gap: 10px; }
.mode-control > span { color: var(--muted); font-size: 11px; }
.compact-segment { grid-template-columns: repeat(2, auto); }
.zoom-control > span { min-width: 38px; text-align: center; font-size: 11px; font-variant-numeric: tabular-nums; }

.inventory-heading { align-items: center; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); }
.summary-grid div { min-width: 0; padding: 13px 10px; display: flex; flex-direction: column; gap: 3px; border-right: 1px solid var(--line); }
.summary-grid div:last-child { border-right: 0; }
.summary-grid strong { font-size: 18px; line-height: 1; font-variant-numeric: tabular-nums; }
.summary-grid span { color: var(--muted); font-size: 10px; }

.progress-block { margin: 20px 0; }
.progress-copy { display: flex; align-items: center; justify-content: space-between; font-size: 11px; margin-bottom: 7px; }
.progress-copy span { color: var(--muted); }
.progress-track { height: 7px; background: var(--surface-2); overflow: hidden; }
.progress-track i { display: block; width: 0; height: 100%; background: var(--mint); transition: width 180ms; }

.active-color { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; padding: 11px; border: 1px solid var(--line); background: #faf8f3; margin-bottom: 14px; }
.large-swatch { width: 44px; height: 44px; border: 1px solid rgba(0,0,0,.12); }
.active-color div { min-width: 0; display: grid; gap: 1px; }
.active-color small, .active-color span { color: var(--muted); font-size: 10px; }
.active-color strong { font: 700 13px/1.3 ui-monospace, monospace; }

.inventory-tools { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-bottom: 10px; }
.search-box { min-height: 32px; display: flex; align-items: center; gap: 5px; padding: 0 8px; border: 1px solid var(--line); }
.search-box span { color: var(--muted); }
.search-box input { border: 0; outline: 0; min-width: 0; width: 100%; background: transparent; font-size: 11px; }
.tool-button[aria-pressed="true"] { color: var(--coral-dark); border-color: var(--coral); background: #fff3ef; }

.color-list { overflow-y: auto; min-height: 150px; flex: 1; border-top: 1px solid var(--line); }
.color-item { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px; padding: 10px 5px; border-bottom: 1px solid var(--line); cursor: pointer; }
.color-item:hover, .color-item.is-active { background: var(--paper); }
.color-item.is-active { box-shadow: inset 3px 0 var(--coral); }
.color-swatch { width: 30px; height: 30px; border: 1px solid rgba(0,0,0,.13); }
.color-meta { min-width: 0; }
.color-meta strong { display: block; font: 700 12px/1.25 ui-monospace, monospace; }
.color-meta span { color: var(--muted); font-size: 9px; }
.color-count { text-align: right; font-variant-numeric: tabular-nums; }
.color-count strong { display: block; font-size: 12px; }
.color-count span { color: var(--muted); font-size: 9px; }
.list-placeholder { color: var(--muted); text-align: center; font-size: 11px; padding: 38px 8px; }
.inventory-footer { padding-top: 13px; margin-top: 12px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; color: #9a958c; font-size: 9px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 50; padding: 10px 15px; background: var(--ink); color: white; box-shadow: var(--shadow); font-size: 12px; opacity: 0; pointer-events: none; transition: opacity 160ms, transform 160ms; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 280px minmax(420px, 1fr); }
  .inventory-panel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); max-height: none; position: static; display: grid; grid-template-columns: 220px minmax(300px, 1fr); gap: 0 24px; }
  .inventory-heading, .summary-grid, .progress-block, .active-color, .inventory-footer { grid-column: 1; }
  .inventory-tools, .color-list { grid-column: 2; }
  .inventory-tools { grid-row: 1; align-self: end; margin-bottom: 20px; }
  .color-list { grid-row: 2 / span 5; max-height: 340px; }
}

@media (max-width: 760px) {
  .topbar { height: auto; min-height: 64px; grid-template-columns: 1fr auto; padding: 10px 14px; }
  .topbar-status { display: none; }
  .topbar-actions .secondary { display: none; }
  .workspace { display: block; }
  .control-panel, .inventory-panel { border: 0; padding: 18px 14px; }
  .control-panel { border-bottom: 1px solid var(--line); }
  .canvas-stage { min-height: auto; }
  .stage-toolbar { align-items: flex-start; flex-direction: column; padding: 10px 12px; }
  .stage-actions { width: 100%; }
  .stage-actions .compact { flex: 1; }
  .canvas-wrap { min-height: 390px; padding: 20px 12px; place-items: center start; }
  .canvas-wrap canvas { width: 100%; }
  .stage-footer { flex-wrap: wrap; padding: 10px 12px; }
  .inventory-panel { display: block; max-height: none; }
  .inventory-tools { margin-top: 14px; }
  .color-list { max-height: 420px; }
  .brand > span:last-child { display: grid; gap: 0; }
}

@media (max-width: 420px) {
  .topbar-actions .icon-button { display: none; }
  .stage-actions .icon-button { width: 32px; flex: 0 0 auto; }
  .view-tabs button { padding: 0 10px; }
  .mode-control { width: 100%; justify-content: space-between; }
  .compact-segment { flex: 1; }
  .preset-row { display: grid; grid-template-columns: repeat(3, 1fr); }
}

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