:root {
  color: #172126;
  background: #eef1f2;
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  --ink: #172126;
  --muted: #68757b;
  --line: #d9dfe1;
  --paper: #ffffff;
  --soft: #f5f7f7;
  --teal: #087f75;
  --teal-dark: #075f59;
  --amber: #c77515;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
}

button,
input,
select,
textarea {
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 14px clamp(18px, 3vw, 44px);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 23px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 17px;
}

.provider-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #405056;
  font-size: 13px;
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22a65a;
  box-shadow: 0 0 0 3px #dff5e7;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
  min-height: calc(100vh - 76px);
}

.controls {
  padding: 25px clamp(18px, 2.5vw, 34px) 36px;
  border-right: 1px solid var(--line);
  background: var(--paper);
}

.section-block {
  padding: 0 0 24px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.section-heading,
.result-toolbar,
.result-footer,
.size-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-heading {
  margin-bottom: 17px;
}

.section-index {
  color: #9aa5aa;
  font-size: 12px;
}

.field {
  display: grid;
  gap: 7px;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
  color: #536168;
  font-size: 12px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #ccd4d7;
  border-radius: 6px;
  outline: none;
  background: #fff;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input,
select {
  height: 42px;
  padding: 0 11px;
}

textarea {
  min-height: 144px;
  padding: 11px;
  line-height: 1.55;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(8, 127, 117, 0.12);
}

.input-action {
  position: relative;
  display: block;
}

.input-action input {
  padding-right: 62px;
}

.quiet-button {
  position: absolute;
  top: 5px;
  right: 5px;
  height: 32px;
  padding: 0 9px;
  border: 0;
  background: transparent;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
}

.memory-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: -6px;
}

.memory-actions button {
  padding: 3px 0;
  border: 0;
  background: transparent;
  color: #768287;
  font-size: 12px;
}

.memory-actions button:hover {
  color: #b42318;
}

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

.preset-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 14px;
}

.preset-row button,
.secondary-button,
.download-button {
  min-height: 36px;
  border: 1px solid #cbd4d7;
  border-radius: 6px;
  background: var(--paper);
  color: #425157;
  font-size: 12px;
  font-weight: 700;
}

.preset-row button:hover,
.secondary-button:hover,
.download-button:not(:disabled):hover {
  border-color: var(--teal);
  color: var(--teal);
}

.secondary-button {
  width: 100%;
}

.reference-controls {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 38px;
  margin: -3px 0 12px;
}

.upload-button {
  display: inline-grid;
  place-items: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid #cbd4d7;
  border-radius: 6px;
  background: #fff;
  color: #425157;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.upload-button:hover {
  border-color: var(--teal);
  color: var(--teal);
}

#reference-name {
  min-width: 0;
  overflow: hidden;
  color: #7a858a;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-preview {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  min-height: 76px;
  margin: 0 0 12px;
  padding: 6px;
  border: 1px solid #d5dcde;
  border-radius: 6px;
  background: #f7f9f9;
}

.reference-preview[hidden] {
  display: none;
}

.reference-preview img {
  width: 64px;
  height: 64px;
  border-radius: 4px;
  object-fit: cover;
  background: #e1e6e7;
}

.reference-preview div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.reference-preview strong {
  overflow: hidden;
  color: #536168;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-preview button {
  flex: none;
  padding: 5px 7px;
  border: 0;
  background: transparent;
  color: #b42318;
  font-size: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid #d6dcde;
  border-radius: 6px;
  background: #f0f3f4;
}

.segmented label {
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  place-items: center;
  height: 32px;
  border-radius: 4px;
  color: #6b777c;
}

.segmented input:checked + span {
  background: #fff;
  color: var(--teal);
  box-shadow: 0 1px 4px rgba(33, 48, 54, 0.1);
}

.size-summary {
  gap: 12px;
  padding: 11px 12px;
  border-left: 3px solid var(--amber);
  background: #fff8ed;
  color: #667277;
  font-size: 12px;
}

.size-summary strong {
  color: var(--ink);
}

.primary-button {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--teal);
  border-radius: 6px;
  background: var(--teal);
  color: #fff;
  font-weight: 750;
}

.primary-button:hover {
  background: var(--teal-dark);
}

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

.result-panel {
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr) auto;
  min-width: 0;
  padding: 25px clamp(18px, 3vw, 44px) 30px;
  background: var(--soft);
}

.result-toolbar {
  padding-bottom: 20px;
}

.download-button {
  min-width: 82px;
  padding: 0 16px;
}

.preview-shell {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: #e6eaeb;
  background-image:
    linear-gradient(45deg, #dce2e3 25%, transparent 25%),
    linear-gradient(-45deg, #dce2e3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dce2e3 75%),
    linear-gradient(-45deg, transparent 75%, #dce2e3 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

#preview-canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 210px);
  width: auto;
  height: auto;
  background: white;
  box-shadow: 0 12px 34px rgba(27, 39, 43, 0.2);
}

.empty-state,
.loading-state {
  display: grid;
  place-items: center;
  gap: 13px;
  color: #69777c;
  text-align: center;
}

.empty-state p,
.loading-state p {
  margin: 0;
  font-size: 13px;
}

.empty-mark {
  width: 52px;
  height: 42px;
  border: 2px solid #9ba7ab;
  border-radius: 7px;
  background: linear-gradient(145deg, transparent 50%, #aab5b8 51% 56%, transparent 57%);
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #b9cecc;
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.result-footer {
  gap: 16px;
  padding-top: 14px;
  color: #67747a;
  font-size: 12px;
}

.result-footer p {
  margin: 0;
}

#status-text[data-kind="error"] {
  color: #b42318;
}

#status-text[data-kind="success"] {
  color: #087f4f;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

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

  .result-panel {
    min-height: 680px;
  }

  #preview-canvas {
    max-height: 70vh;
  }
}

@media (max-width: 480px) {
  .topbar,
  .result-toolbar {
    align-items: flex-start;
  }

  .provider-state {
    margin-top: 5px;
  }

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

  .preset-row button {
    min-width: 0;
    padding-inline: 4px;
  }

  .result-panel {
    grid-template-rows: auto minmax(340px, 1fr) auto;
  }

  .preview-shell {
    min-height: 340px;
  }
}
