:root {
  --bg0: #f4f7fb;
  --bg1: #ffffff;
  --bg2: #e8eef6;
  --line: #d0dae8;
  --text: #1a2433;
  --muted: #5a6b82;
  --accent: #0d9f6e;
  --accent-dim: #0b8a5f;
  --accent-soft: #e6f7f0;
  --warn: #c47d12;
  --danger: #d14343;
  --focus: #2b7de9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(26, 36, 51, 0.04), 0 8px 24px rgba(26, 36, 51, 0.06);
  --font: "IBM Plex Sans", "Source Han Sans SC", "Noto Sans SC", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background:
    radial-gradient(900px 480px at 8% -8%, #d9f3e8 0%, transparent 55%),
    radial-gradient(800px 420px at 100% 0%, #d6e6fa 0%, transparent 50%),
    linear-gradient(180deg, #eef3f9 0%, var(--bg0) 40%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--focus); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 8px;
}
.brand h1 {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  color: #122033;
}
.brand .tag {
  color: var(--muted);
  font-size: 0.92rem;
}

.statusbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin: 16px 0 28px;
  padding: 12px 16px;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  color: var(--muted);
}
.statusbar .ok { color: var(--accent-dim); font-weight: 600; }
.statusbar .bad { color: var(--danger); font-weight: 600; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.panel h2 {
  margin: 0 0 14px;
  font-size: 1.08rem;
  font-weight: 600;
  color: #122033;
}
.panel.full { grid-column: 1 / -1; }

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
  line-height: 1.35;
}
.label-hint {
  display: block;
  font-size: 0.72rem;
  font-weight: 400;
  color: #8a9bb0;
  margin-top: 1px;
}
.field { margin-bottom: 12px; min-width: 0; }
.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
/* 编码区：四列同一行，标签与输入框对齐 */
.row-encode {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: start;
  gap: 12px;
  margin-bottom: 0;
}
.row-encode .field {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
}
.row-encode .field > label {
  height: 1.35em;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-encode .field > input,
.row-encode .field > select,
.row-encode .saved-row {
  height: 42px;
}
.row-encode .field-saved .saved-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.row-encode .field-saved select {
  flex: 1;
  min-width: 0;
  height: 42px;
}
.row-encode .field-saved .btn-sm {
  flex-shrink: 0;
  height: 42px;
  min-height: 42px;
  padding: 0 12px;
}
.encode-tip {
  margin: 8px 0 12px;
}
@media (max-width: 900px) {
  .row-encode {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 520px) {
  .row-encode {
    grid-template-columns: 1fr;
  }
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background: #f8fafc;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  min-height: 42px;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 36px;
  background-image:
    linear-gradient(45deg, transparent 50%, #5a6b82 50%),
    linear-gradient(135deg, #5a6b82 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  background-color: #f8fafc;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
}
select option {
  line-height: 1.5;
  padding: 8px;
}
input:hover, select:hover, textarea:hover {
  border-color: #b4c3d8;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--focus);
  background-color: #fff;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent);
}
select:focus {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, transparent 50%, #5a6b82 50%),
    linear-gradient(135deg, #5a6b82 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
textarea {
  min-height: 72px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow: auto;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg1);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 14px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover {
  background: var(--bg2);
  border-color: #b4c3d8;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(13, 159, 110, 0.25);
}
.btn-primary:hover {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: #fff;
}
.btn-ghost { background: transparent; }
.btn-danger {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--line));
  color: var(--danger);
  background: #fff5f5;
}
.btn-danger:hover { background: #ffe8e8; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.drop {
  border: 1.5px dashed #b8c8dc;
  border-radius: var(--radius);
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  background: #f7fafc;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.drop:hover, .drop.drag {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 20%, transparent);
}
.drop strong { color: var(--text); display: block; margin-bottom: 4px; font-size: 0.98rem; }

.meta {
  margin-top: 12px;
  font-size: 0.82rem;
  color: var(--muted);
  font-family: var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.profile-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  background: #f9fbfd;
}
.profile-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.profile-card header input[type="text"] {
  font-weight: 600;
  font-size: 0.95rem;
  background: #fff;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.chip:hover {
  color: var(--accent-dim);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 6px 0;
}
.details[open] summary { color: var(--text); margin-bottom: 10px; font-weight: 500; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text);
  margin-top: 14px;
}
.check input { width: auto; }

.log {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: #f0f4f8;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  color: #334155;
  margin-top: 12px;
}

.result-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.result-item:last-child { border-bottom: 0; }
.result-main {
  flex: 1;
  min-width: 0;
}
.result-thumb {
  flex-shrink: 0;
  width: 72px;
  height: 96px;
  border-radius: 8px;
  overflow: hidden;
  background: #e8eef5;
  border: 1px solid var(--line);
  display: block;
}
.result-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 6px;
}
.badge.ok {
  background: var(--accent-soft);
  color: var(--accent-dim);
}
.badge.fail {
  background: #ffe8e8;
  color: var(--danger);
}

.hint { font-size: 0.82rem; color: var(--muted); margin: 0 0 12px; }
.hint code,
.hint strong {
  color: #122033;
}
.hint code {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: #334155;
}

.effect-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.effect {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f9fbfd;
  overflow: hidden;
}

.effect-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 6px;
  margin: 0;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}
.effect-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.effect-desc {
  display: none;
  margin: 0 14px 10px 40px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}
.effect.on .effect-desc,
.effect:has([data-enable]:checked) .effect-desc {
  display: block;
}

.effect-body {
  display: none;
  padding: 0 14px 14px;
  border-top: 1px solid transparent;
}
.effect.on {
  background: #fff;
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 12%, transparent);
}
.effect.on .effect-body {
  display: block;
  border-top-color: var(--line);
  padding-top: 12px;
}

.field-help {
  margin: 6px 0 0;
  font-size: 0.72rem;
  line-height: 1.4;
  color: #7a8ca3;
}
.check-help {
  display: block;
  margin: 2px 0 0 24px;
  font-size: 0.72rem;
  font-weight: 400;
  color: #7a8ca3;
  line-height: 1.4;
}
.check {
  flex-wrap: wrap;
  align-items: flex-start;
}

.summary {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  color: var(--accent-dim);
  font-size: 0.88rem;
  font-weight: 500;
}

.topbar {
  margin-bottom: 8px;
}
.topbar .statusbar {
  margin-top: 12px;
}

.h2-sub {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 6px;
}

.panel-upload .drop span {
  display: block;
  margin-top: 4px;
  font-size: 0.85rem;
}

.file-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.file-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  max-height: 260px;
  overflow: auto;
}

.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  margin-bottom: 8px;
}
.file-item:last-child { margin-bottom: 0; }
.file-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.file-main strong {
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-main span {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--mono);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.actions-main {
  margin-top: 4px;
}
.actions-main .btn-primary {
  min-width: 160px;
}

.progress-wrap {
  margin-bottom: 14px;
}
.progress-bar {
  height: 10px;
  background: var(--bg2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.progress-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 999px;
  transition: width .35s ease;
}
.progress-text {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
  word-break: break-word;
}

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: #f0f6ff;
  border: 1px solid #d6e4ff;
  border-radius: 10px;
}
.results-toolbar[hidden] {
  display: none !important;
}
.results-toolbar-hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.src-tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--bg2);
  border-radius: 4px;
  padding: 1px 6px;
}

.diff-metrics {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 4px;
  line-height: 1.4;
}

.err-log {
  margin: 8px 0 0;
  padding: 8px 10px;
  max-height: 180px;
  overflow: auto;
  font-size: 0.72rem;
  line-height: 1.35;
  color: #8a1f1f;
  background: #fff5f5;
  border: 1px solid #f0c2c2;
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-all;
}

#run-hint {
  margin-top: 12px;
}

