:root {
  color: #17201d;
  background: #edf1f2;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  font-synthesis: none;
  --ink: #17201d;
  --muted: #66716d;
  --line: #d5dcda;
  --line-strong: #b8c4c0;
  --panel: #ffffff;
  --canvas: #dfe5e4;
  --green: #176b4c;
  --green-dark: #10543b;
  --green-soft: #e3f1eb;
  --amber: #9b6a16;
  --danger: #a23d3d;
  accent-color: var(--green);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: #edf1f2;
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
label[for],
input[type="range"],
input[type="color"],
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(23, 107, 76, 0.2);
  outline-offset: 2px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.brand,
.header-actions,
.brand-copy {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid #174e3c;
  border-radius: 5px;
  background: var(--green);
  color: #fff;
  font-family: serif;
  font-size: 18px;
  font-weight: 700;
}

.brand-copy {
  align-items: flex-start;
  flex-direction: column;
  line-height: 1.15;
}

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

.brand-copy span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.header-actions {
  gap: 14px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-chip i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aa6a2;
}

.status-chip.is-ready i {
  background: #2f8b65;
}

.status-chip.is-busy i {
  background: var(--amber);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(310px, 360px) minmax(0, 1fr);
  width: min(1480px, 100%);
  min-height: calc(100vh - 58px);
  margin: 0 auto;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: var(--panel);
}

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

.panel-section {
  display: grid;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.section-heading,
.preview-toolbar,
.export-bar,
.file-meta,
.range-field > span,
.toggle-row,
.color-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-heading h2 {
  margin: 0;
  font-size: 14px;
}

.text-action {
  border: 0;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.text-action:hover {
  color: var(--green-dark);
  text-decoration: underline;
}

.muted-count,
.file-meta span,
.preview-toolbar span {
  color: var(--muted);
  font-size: 12px;
}

.file-meta {
  gap: 12px;
  align-items: flex-start;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f7f9f8;
}

.file-meta strong {
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta.is-empty strong {
  color: var(--muted);
  font-weight: 500;
}

.field,
.range-field,
.format-field,
.quality-field {
  display: grid;
  gap: 7px;
  margin: 0;
  border: 0;
  padding: 0;
}

.field > span,
.field legend,
.format-field legend,
.quality-field > span,
.range-field b {
  color: #3b4743;
  font-size: 12px;
  font-weight: 700;
}

.field-full {
  width: 100%;
}

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

textarea,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
}

textarea {
  min-height: 68px;
  resize: vertical;
  padding: 10px 11px;
  line-height: 1.5;
}

select {
  height: 38px;
  padding: 0 9px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #eef2f1;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented span {
  display: grid;
  min-height: 32px;
  place-items: center;
  border-radius: 3px;
  color: #53605b;
  font-size: 13px;
  font-weight: 700;
}

.segmented input:checked + span {
  border: 1px solid #cbd5d1;
  background: #fff;
  color: var(--green-dark);
  box-shadow: 0 1px 2px rgba(23, 32, 29, 0.08);
}

.segmented input:focus-visible + span {
  outline: 3px solid rgba(23, 107, 76, 0.2);
}

.position-grid {
  display: grid;
  grid-template-columns: repeat(3, 34px);
  gap: 5px;
  width: max-content;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f5f7f6;
}

.position-grid button {
  display: grid;
  width: 34px;
  height: 30px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
}

.position-grid button:hover,
.position-grid button.is-active {
  border-color: #b9ccc4;
  background: var(--green-soft);
}

.position-grid i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6c7974;
}

.position-grid button.is-active i {
  background: var(--green);
}

.color-control {
  justify-content: flex-start;
  height: 38px;
  gap: 8px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
}

.color-control input {
  width: 24px;
  height: 24px;
  border: 0;
  padding: 0;
  background: transparent;
}

.color-control output {
  color: #4d5a55;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.range-field output {
  color: var(--green-dark);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.range-field input,
.quality-field input {
  width: 100%;
  height: 20px;
  margin: 0;
}

.toggle-row {
  justify-content: flex-start;
  gap: 24px;
  padding-top: 2px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.toggle input {
  position: absolute;
  opacity: 0;
}

.toggle span {
  position: relative;
  width: 34px;
  height: 19px;
  border-radius: 10px;
  background: #b8c1be;
  transition: background 120ms ease;
}

.toggle span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  content: "";
  transition: transform 120ms ease;
}

.toggle input:checked + span {
  background: var(--green);
}

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

.toggle input:focus-visible + span {
  outline: 3px solid rgba(23, 107, 76, 0.2);
  outline-offset: 2px;
}

.toggle b {
  font-size: 12px;
}

.preview-panel {
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr) auto;
  min-width: 0;
  background: #f4f6f6;
}

.preview-toolbar {
  min-height: 54px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.preview-toolbar > div {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.preview-toolbar strong {
  font-size: 14px;
}

.canvas-stage {
  position: relative;
  display: grid;
  min-height: 420px;
  overflow: hidden;
  place-items: center;
  padding: 28px;
  background-color: var(--canvas);
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.34) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.34) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.34) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.34) 75%);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.canvas-stage.is-dragging {
  box-shadow: inset 0 0 0 3px var(--green);
}

.empty-state {
  display: grid;
  justify-items: center;
  width: min(360px, 90%);
  padding: 40px 24px;
  border: 1px dashed #91a19b;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.72);
  color: #44514c;
  text-align: center;
}

.upload-symbol {
  display: grid;
  width: 42px;
  height: 42px;
  margin-bottom: 13px;
  place-items: center;
  border: 1px solid #9fb0aa;
  border-radius: 50%;
  color: var(--green);
  font-size: 28px;
  font-weight: 300;
  line-height: 1;
}

.empty-state strong {
  color: var(--green-dark);
  font-size: 16px;
}

.empty-state span:not(.upload-symbol) {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.empty-state small {
  margin-top: 15px;
  color: #78837f;
  font-size: 11px;
}

#previewCanvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 210px);
  border: 1px solid rgba(58, 70, 66, 0.28);
  background: transparent;
  box-shadow: 0 10px 28px rgba(25, 37, 33, 0.16);
}

.export-bar {
  min-height: 82px;
  gap: 20px;
  padding: 13px 20px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.format-field {
  min-width: 168px;
}

.segmented.compact span {
  min-height: 30px;
  font-size: 12px;
}

.quality-field {
  width: min(240px, 30vw);
}

.quality-field > span {
  display: flex;
  justify-content: space-between;
}

.button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 0 16px;
  font-weight: 700;
}

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

.button-primary {
  min-width: 120px;
  background: var(--green);
  color: #fff;
}

.button-primary:hover:not(:disabled) {
  background: var(--green-dark);
}

.button-quiet {
  border-color: var(--line);
  background: #fff;
  color: #45524d;
}

.button-quiet:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: #f3f6f5;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  max-width: min(380px, calc(100vw - 40px));
  border: 1px solid #b6c8c0;
  border-radius: 5px;
  padding: 12px 15px;
  background: #fff;
  color: #31413b;
  box-shadow: 0 8px 24px rgba(23, 32, 29, 0.16);
  font-size: 13px;
}

.toast.is-error {
  border-color: #d8b2b2;
  color: var(--danger);
}

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

@media (max-width: 900px) {
  .app-header {
    padding: 8px 14px;
  }

  .workspace {
    grid-template-columns: 1fr;
    border: 0;
  }

  .preview-panel {
    order: -1;
    grid-template-rows: auto minmax(320px, 58vh) auto;
    border-bottom: 1px solid var(--line);
  }

  .control-panel {
    border-right: 0;
  }

  .canvas-stage {
    min-height: 320px;
    padding: 16px;
  }

  #previewCanvas {
    max-height: 52vh;
  }
}

@media (max-width: 620px) {
  .brand-copy span,
  .status-chip {
    display: none;
  }

  .panel-section {
    padding: 18px 16px;
  }

  .field-pair {
    grid-template-columns: 1fr;
  }

  .export-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 14px 16px;
  }

  .quality-field {
    width: auto;
  }

  .export-bar .button-primary {
    grid-column: 1 / -1;
    width: 100%;
  }
}
