:root {
  color-scheme: light;
  --bg: #ece9df;
  --surface: #fbfaf6;
  --surface-2: #f2efe7;
  --ink: #1d2528;
  --muted: #687176;
  --line: #cfc8ba;
  --accent: #2b7a78;
  --accent-strong: #1f5c5a;
  --accent-soft: #d8ece8;
  --warn: #b0642d;
  --shadow: 0 12px 30px rgba(35, 39, 41, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="number"] {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdfa;
  color: var(--ink);
}

button {
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #f7f4ec;
}

.brand {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 2px solid var(--accent);
  background: var(--surface);
  color: var(--accent-strong);
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 15px;
}

p,
.hint,
.preview-panel header span,
.palette-panel header span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.drop-zone {
  position: relative;
  display: grid;
  min-height: 142px;
  place-items: center;
  gap: 8px;
  padding: 18px;
  border: 1px dashed #9b927f;
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
  cursor: pointer;
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.drop-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-size: 28px;
  line-height: 1;
}

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

.panel,
.preview-panel,
.palette-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.panel-title {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  color: var(--ink);
  font-size: 14px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.control-row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 36px;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.control-row label,
.color-row span:first-child {
  color: var(--muted);
  font-size: 13px;
}

.control-row select,
.control-row input[type="number"] {
  min-width: 0;
  height: 36px;
  padding: 0 10px;
}

.control-row select,
.control-row input[type="number"] {
  grid-column: 2 / -1;
}

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

output {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.color-row {
  display: grid;
  grid-template-columns: 76px 40px 1fr;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.color-chip {
  width: 36px;
  height: 30px;
  padding: 0;
  border-radius: 4px;
  background:
    linear-gradient(45deg, #bbb 25%, transparent 25%),
    linear-gradient(-45deg, #bbb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #bbb 75%),
    linear-gradient(-45deg, transparent 75%, #bbb 75%);
  background-color: #eee;
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}

.primary-action {
  width: 100%;
  height: 42px;
  margin-top: 14px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.candidates {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
  margin-top: 12px;
}

.candidate-button {
  min-width: 52px;
  height: 30px;
  padding: 0 8px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
}

.candidate-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 800;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stats strong {
  display: block;
  overflow: hidden;
  margin-top: 4px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.button-grid button {
  min-height: 38px;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
  min-width: 0;
  min-height: 100vh;
  padding: 18px;
  gap: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.asset-name {
  overflow: hidden;
  max-width: 64vw;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.view-options {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}

.swatch {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 6px;
}

.swatch.active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.swatch[data-bg="checker"],
.checker {
  background:
    linear-gradient(45deg, rgba(95, 97, 101, 0.18) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(95, 97, 101, 0.18) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(95, 97, 101, 0.18) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(95, 97, 101, 0.18) 75%);
  background-color: #dad6ca;
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

.swatch-dark {
  background: #161a20;
}

.swatch-light {
  background: #f6f2e7;
}

.swatch-green {
  background: #13d46b;
}

.preview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
}

.preview-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.preview-panel header,
.palette-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.preview-panel header span,
.palette-panel header span {
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.canvas-stage {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  overflow: auto;
  padding: 18px;
}

canvas {
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
}

#sourceCanvas.pickable {
  cursor: crosshair;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
}

.empty-state.hidden {
  display: none;
}

.palette-panel {
  overflow: hidden;
}

.palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  max-height: 190px;
  overflow: auto;
  padding: 12px;
}

.palette-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdfa;
  font-size: 12px;
}

.palette-swatch {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(0, 0, 0, 0.24);
  border-radius: 4px;
}

.palette-item code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette-item span {
  color: var(--muted);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    min-height: 72vh;
  }
}

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

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

  .asset-name {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .sidebar,
  .workspace {
    padding: 12px;
  }

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