:root {
  --bg: #e8e9e7;
  --surface: #f7f7f5;
  --surface-strong: #ffffff;
  --ink: #171817;
  --muted: #6d716d;
  --line: #d4d7d2;
  --line-strong: #b9bdb7;
  --accent: #171817;
  --danger: #b23a32;
  --panel-width: 360px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--bg);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Segoe UI", sans-serif;
}

button,
input,
select { font: inherit; }

button,
label[for] { cursor: pointer; }

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

.converter-app {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
}

.app-header {
  position: relative;
  z-index: 5;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: 0 16px 0 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand-block {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.brand-block strong { font-size: 15px; }
.brand-block span,
.file-summary { color: var(--muted); font-size: 12px; }
.file-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.header-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.button,
.icon-button,
.add-color-button,
.text-button,
.segment {
  border: 0;
  color: inherit;
  background: transparent;
}

.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font-size: 13px;
  font-weight: 650;
}

.button.primary { border-color: var(--accent); color: #fff; background: var(--accent); }
.button.secondary { background: var(--surface-strong); }
.button.compact { min-height: 36px; padding-inline: 11px; white-space: nowrap; }
.button.full-width { width: 100%; min-height: 44px; }
.button:not(:disabled):hover { filter: brightness(0.94); }

.icon-button {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-strong);
}

.icon-button:not(:disabled):hover { border-color: var(--line-strong); background: #eff0ed; }
.icon-button.danger:not(:disabled):hover { color: var(--danger); border-color: #d5aaa6; background: #fff4f3; }
.icon { font-size: 17px; }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: var(--panel-width) minmax(0, 1fr);
}

.settings-panel {
  min-height: 0;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.settings-section { padding: 24px 22px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.section-heading h1,
.section-heading h2 { margin: 0; letter-spacing: 0; }
.section-heading h1 { font-size: 21px; }
.section-heading h2 { font-size: 15px; }
.compact-heading { margin-bottom: 18px; }
.eyebrow { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; font-weight: 700; }

.field-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
.select-row,
.palette-name-row { display: flex; gap: 8px; }
.palette-name-row { margin-top: 10px; }

.select-input,
.text-input,
.hex-input {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  outline: none;
  color: var(--ink);
  background: var(--surface-strong);
}

.select-input:focus,
.text-input:focus,
.hex-input:focus { border-color: #676c66; box-shadow: 0 0 0 2px rgba(23, 24, 23, 0.08); }
.select-input { flex: 1; }

.color-list { margin-top: 18px; display: grid; gap: 7px; }
.color-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) 32px; align-items: center; gap: 8px; }
.color-picker { width: 34px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
.hex-input { height: 34px; text-transform: uppercase; font-family: Consolas, monospace; font-size: 12px; }
.remove-color { width: 32px; height: 32px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; }
.remove-color:not(:disabled):hover { color: var(--danger); background: #fff0ef; }

.add-color-button {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 9px;
  border: 1px dashed var(--line-strong);
  border-radius: 4px;
  color: var(--muted);
  font-size: 12px;
}
.add-color-button:hover { color: var(--ink); border-color: #747974; background: #f0f1ef; }

.field-group { display: grid; gap: 7px; }
.color-input-row { display: grid; grid-template-columns: 34px minmax(0, 1fr); align-items: center; gap: 8px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-actions { display: flex; align-items: center; gap: 8px; }
.icon-button.tiny { width: 26px; height: 26px; flex-basis: 26px; }
.icon-button.tiny .icon { font-size: 13px; }
.compact-list { margin-top: 0; }
.field-hint { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.6; }

.parameters-section { display: grid; gap: 18px; }
.text-button { padding: 4px 0; color: var(--muted); font-size: 11px; }
.text-button:hover { color: var(--ink); }
.range-field { display: grid; gap: 9px; }
.range-field > span { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 12px; }
.range-field output { color: var(--muted); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.toggle-row { min-height: 48px; display: grid; grid-template-columns: minmax(0, 1fr) 0 38px; align-items: center; gap: 10px; }
.toggle-row > span:first-child { display: grid; gap: 3px; font-size: 12px; }
.toggle-row small { color: var(--muted); font-size: 10px; }
.toggle-row input { width: 0; height: 0; opacity: 0; }
.toggle { position: relative; width: 38px; height: 22px; border-radius: 11px; background: #bfc3bd; transition: background 140ms ease; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 140ms ease; }
.toggle-row input:checked + .toggle { background: var(--accent); }
.toggle-row input:checked + .toggle::after { transform: translateX(16px); }

.red-section .toggle-row { margin-bottom: 16px; }
.red-body { display: grid; gap: 16px; }
.red-body.disabled { opacity: 0.45; pointer-events: none; }

.process-footer { padding: 20px 22px 26px; }
.progress-track { height: 3px; margin-top: 12px; overflow: hidden; border-radius: 2px; background: #dfe1dd; opacity: 0; }
.progress-track.active { opacity: 1; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); transition: width 120ms ease; }
.process-status { min-height: 17px; margin: 8px 0 0; color: var(--muted); font-size: 11px; text-align: center; }

.preview-panel { min-width: 0; min-height: 0; display: grid; grid-template-rows: 52px minmax(0, 1fr); }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.segmented-control { display: flex; padding: 3px; border: 1px solid var(--line); border-radius: 5px; background: #eceeeb; }
.segment { min-width: 78px; height: 29px; padding: 0 11px; border-radius: 3px; color: var(--muted); font-size: 12px; }
.segment.active { color: var(--ink); background: var(--surface-strong); box-shadow: 0 1px 3px rgba(20, 24, 20, 0.12); }
.zoom-controls { display: flex; align-items: center; gap: 6px; }
.zoom-controls .icon-button { width: 32px; height: 32px; flex-basis: 32px; }
.zoom-controls output { width: 48px; color: var(--muted); font-size: 11px; text-align: center; }

.canvas-stage { position: relative; min-height: 0; overflow: hidden; background: #dfe1dd; }
.canvas-stage.dragging { background: #d4d8d2; }
.drop-zone { position: absolute; inset: 20px; display: grid; place-content: center; justify-items: center; gap: 8px; border: 1px dashed #aeb3ac; color: var(--muted); text-align: center; }
.drop-zone:hover,
.canvas-stage.dragging .drop-zone { border-color: #60655f; color: var(--ink); background: rgba(255,255,255,0.3); }
.drop-zone strong { margin-top: 5px; color: var(--ink); font-size: 15px; }
.drop-zone span { font-size: 12px; }
.drop-zone small { font-size: 10px; }
.drop-icon { width: 54px; height: 54px; display: grid; place-items: center; border: 1px solid #c5c9c3; border-radius: 50%; background: var(--surface); }
.drop-icon .icon { font-size: 23px; }

.canvas-scroller { width: 100%; height: 100%; overflow: auto; }
.canvas-holder { position: relative; min-width: 100%; min-height: 100%; display: grid; place-items: center; padding: 28px; }
.canvas-holder canvas { display: block; max-width: none; max-height: none; box-shadow: 0 3px 18px rgba(22, 26, 22, 0.16); background: #fff; image-rendering: auto; }
.canvas-holder.pixelated canvas { image-rendering: pixelated; }

@media (max-width: 820px) {
  body { overflow: auto; }
  .converter-app { min-height: 100%; height: auto; grid-template-rows: auto auto; }
  .app-header { min-height: 58px; grid-template-columns: 1fr auto; padding: 10px 12px; }
  .brand-block span,
  .file-summary { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .settings-panel { max-height: none; overflow: visible; border-right: 0; }
  .preview-panel { min-height: 70vh; order: -1; }
  .header-actions .button span { display: none; }
  .header-actions .button { width: 38px; padding: 0; }
  .preview-toolbar { padding-inline: 10px; }
  .canvas-holder { padding: 14px; }
}
