:root {
  --bg: #f5f2ea;
  --bg-2: #faf8f3;
  --panel: #ffffff;
  --line: #e6e1d6;
  --line-strong: #d9d2c5;
  --text: #1f1e1a;
  --muted: #6f6a60;
  --accent: #c96442;
  --accent-hover: #b55435;
  --accent-soft: #f4e5de;
  --accent-2: #8a3d24;
  --danger: #b42318;
  --warn: #9a6700;
  --shadow: 0 1px 2px rgba(40, 35, 25, 0.04), 0 12px 32px rgba(40, 35, 25, 0.06);
  --radius: 16px;
  --font: "Noto Sans SC", "Segoe UI", system-ui, sans-serif;
  --display: "Noto Sans SC", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  font-family: var(--font);
  background:
    radial-gradient(1000px 480px at 12% -8%, rgba(201, 100, 66, 0.08), transparent 55%),
    radial-gradient(900px 420px at 100% 0%, rgba(111, 106, 96, 0.06), transparent 50%),
    var(--bg);
  min-height: 100%;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(31, 30, 26, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 30, 26, 0.03) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(circle at 50% 20%, black, transparent 75%);
  opacity: 0.55;
}

.app {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
  position: relative;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: linear-gradient(145deg, #d97854, var(--accent));
  box-shadow: 0 0 0 1px rgba(201, 100, 66, 0.18), 0 10px 24px rgba(201, 100, 66, 0.16);
}

h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: var(--text);
}

.sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.top-actions {
  display: flex;
  gap: 4px;
  background: #f1ece3;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tab.is-active {
  background: #fff;
  color: var(--text);
  font-weight: 650;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.badge {
  min-width: 1.4em;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(31, 30, 26, 0.08);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.panel { display: none; }
.panel.is-active { display: block; }

.layout {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 16px;
  align-items: start;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.label {
  font-size: 0.86rem;
  color: var(--muted);
  font-weight: 550;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}

input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 12px;
  font: inherit;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

textarea { resize: vertical; min-height: 132px; line-height: 1.55; }

input:focus, textarea:focus {
  border-color: rgba(201, 100, 66, 0.55);
  box-shadow: 0 0 0 3px rgba(201, 100, 66, 0.12);
}

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

.seg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.seg[aria-label="清晰度"] {
  grid-template-columns: repeat(3, 1fr);
}

.seg-btn, .icon-btn, .primary, .ghost, .chip-btn {
  font: inherit;
  cursor: pointer;
}

.seg-btn {
  border: 1px solid var(--line-strong);
  background: #f1ece3;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 0;
  transition: .15s ease;
}

.seg-btn.is-active {
  border-color: #e7b9a5;
  background: var(--accent-soft);
  color: var(--accent-2);
  font-weight: 700;
}

.stepper {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 8px;
  align-items: center;
}

.icon-btn {
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  font-size: 1.2rem;
}

.stepper input {
  text-align: center;
  font-family: var(--mono);
  background: var(--bg-2);
}

.upload {
  position: relative;
  min-height: 110px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  background: var(--bg-2);
  overflow: hidden;
}

.upload input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.upload-ui {
  min-height: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px;
  color: var(--muted);
  text-align: center;
}

.upload-preview {
  min-height: 110px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
}

.upload-preview img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.hidden { display: none !important; }

.chip-btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 6px 10px;
  position: relative;
  z-index: 3;
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.primary {
  border: 0;
  border-radius: 12px;
  padding: 13px 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 20px rgba(201, 100, 66, 0.2);
}

.primary:hover {
  background: var(--accent-hover);
}

.primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.primary.is-loading .btn-label::after {
  content: "…";
}

.status {
  min-height: 1.2em;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.status.error { color: var(--danger); }
.status.ok { color: var(--accent-2); }

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.result-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-family: var(--display);
  font-weight: 650;
}

.result-actions { display: flex; gap: 8px; }

.ghost {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
}

.ghost:hover {
  background: var(--bg-2);
}

.ghost:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ghost.danger {
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.28);
}

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  background: linear-gradient(180deg, #fff, #fbf8f1);
}

.empty p { margin: 0 0 6px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.img-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
}

.img-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
  background: #ebe4d6;
}

.img-card .meta {
  display: flex;
  gap: 6px;
  padding: 8px;
}

.img-card button {
  flex: 1;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 0;
  font: inherit;
  cursor: pointer;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-2);
  padding: 12px;
}

.history-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-family: var(--mono);
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  background: #fff;
}

.history-prompt {
  margin: 0 0 10px;
  white-space: pre-wrap;
  line-height: 1.55;
  word-break: break-word;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.history-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.history-thumbs img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: zoom-in;
  background: #ebe4d6;
}

.foot {
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.lightbox {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  background: #fff;
  color: var(--text);
  width: min(920px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
}

.lightbox::backdrop {
  background: rgba(31, 30, 26, 0.45);
}

.lightbox-inner {
  margin: 0;
  display: flex;
  flex-direction: column;
}

.lightbox-inner img {
  max-width: 100%;
  max-height: calc(100vh - 100px);
  object-fit: contain;
  display: block;
  margin: 0 auto;
  background: #f5f2ea;
}

.lightbox-actions {
  display: flex;
  justify-content: flex-end;
  padding: 10px;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .row-2 { grid-template-columns: 1fr; }
  .top { flex-direction: column; align-items: stretch; }
  .top-actions { width: fit-content; }
}