:root {
  color-scheme: light;
  --ink: #0b2a5b;
  --muted: #60728e;
  --blue: #1769e0;
  --blue-dark: #1055bb;
  --line: #d8e2ef;
  --soft: #f5f8fc;
  --danger: #d91f3d;
  --shadow: 0 16px 44px rgba(20, 54, 94, 0.09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: #fff;
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }

.shell {
  width: min(100% - 40px, 980px);
  margin: 28px auto 64px;
}

.shell--form {
  max-width: 760px;
  padding: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.page-header h1, .result-header h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 48px);
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.page-header p {
  margin: 12px 0 36px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.6;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: -14px 0 30px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--soft);
}

.mode-switch a {
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}

.mode-switch a:hover { color: var(--blue); }
.mode-switch a.is-active { background: #fff; color: var(--blue); box-shadow: 0 2px 8px rgba(20, 54, 94, 0.08); }

.config-grid { display: grid; gap: 16px; }
.config-card { padding: 20px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.config-card h2 { margin: 0 0 14px; font-size: 19px; }
.config-list { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 10px 18px; margin: 0; }
.config-list dt { color: var(--muted); font-size: 13px; font-weight: 700; }
.config-list dd { min-width: 0; margin: 0; overflow-wrap: anywhere; color: #18355f; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.key-ready { color: #117a52; }
.key-missing { color: var(--danger); }
.config-note { margin: 0 0 24px; color: var(--muted); line-height: 1.65; }

.field-section + .field-section { margin-top: 30px; }

.field-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.field-heading label, .standalone-label {
  display: block;
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
}

.field-heading span { color: var(--muted); font-size: 14px; }

.drop-zone {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 190px;
  padding: 28px;
  border: 1.5px dashed #77a9ec;
  border-radius: 10px;
  background: #fbfdff;
  text-align: center;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.drop-zone:hover, .drop-zone.is-dragging {
  border-color: var(--blue);
  background: #f2f7ff;
  transform: translateY(-1px);
}

.drop-zone input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.drop-zone svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  fill: none;
  stroke: var(--blue);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.drop-zone strong { font-size: 17px; }
.drop-zone small { margin-top: 5px; color: var(--muted); font-size: 13px; }
.drop-zone--compact { min-height: 138px; }
.drop-zone--compact svg { width: 38px; height: 38px; margin-bottom: 8px; }

.file-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.file-row {
  display: grid;
  grid-template-columns: 36px 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.file-number { font-weight: 800; font-variant-numeric: tabular-nums; }
.file-thumb { width: 52px; height: 42px; border-radius: 4px; object-fit: cover; background: var(--soft); }
.file-meta { min-width: 0; }
.file-name { overflow: hidden; color: #18355f; font-size: 14px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.file-size { margin-top: 2px; color: var(--muted); font-size: 12px; }
.file-actions { display: flex; gap: 3px; }

.icon-button {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover { background: var(--soft); color: var(--ink); }
.icon-button:disabled { cursor: default; opacity: 0.28; }

.standalone-label { margin-bottom: 10px; }

textarea {
  width: 100%;
  resize: vertical;
  min-height: 148px;
  padding: 15px 16px;
  border: 1px solid #c9d7e8;
  border-radius: 8px;
  outline: none;
  color: #18355f;
  line-height: 1.65;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.12); }

.answer-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #18355f;
  font-size: 14px;
  font-weight: 650;
}

.answer-file input { max-width: 245px; color: var(--muted); font-size: 13px; }

.primary-button, .secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
}

.primary-button {
  width: 100%;
  margin-top: 28px;
  border: 0;
  background: var(--blue);
  color: #fff;
  transition: background 150ms ease, transform 150ms ease;
}

.primary-button:hover { background: var(--blue-dark); transform: translateY(-1px); }
.primary-button:disabled { cursor: wait; opacity: 0.72; transform: none; }

.processing {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  color: var(--muted);
  font-size: 14px;
}

.processing[hidden] { display: none; }

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

.shell--progress {
  display: grid;
  min-height: min(720px, calc(100vh - 56px));
  place-items: center;
}

.progress-card {
  width: min(100%, 560px);
  padding: 52px 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  text-align: center;
}

.spinner--large { display: inline-block; width: 42px; height: 42px; border-width: 4px; }
.spinner--large[hidden] { display: none; }
.progress-kicker { margin: 20px 0 8px; color: var(--blue); font-weight: 750; }
.progress-card h1 { margin: 0; font-size: clamp(32px, 6vw, 44px); letter-spacing: -0.035em; }
.progress-card > p:not(.progress-kicker) { min-height: 48px; margin: 14px 0 24px; color: var(--muted); line-height: 1.6; }

.danger-button {
  min-width: 150px;
  min-height: 46px;
  padding: 0 20px;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: #fff;
  color: var(--danger);
  font-weight: 750;
  cursor: pointer;
}

.danger-button:hover { background: #fff3f5; }
.danger-button:disabled { cursor: wait; opacity: 0.55; }
.progress-card .secondary-button { margin: 0 auto; }
.progress-card .secondary-button[hidden] { display: none; }

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

.error {
  margin: 0 0 24px;
  padding: 13px 15px;
  border-left: 4px solid var(--danger);
  background: #fff3f5;
  color: #8f1630;
  line-height: 1.5;
}

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

.secondary-button {
  min-width: 126px;
  padding: 0 18px;
  border: 1px solid var(--blue);
  color: var(--blue);
}

.secondary-button:hover { background: #f2f7ff; }

.result-gallery { display: grid; gap: 18px; }

.result-page {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdff;
}

.result-page figcaption {
  padding-top: 5px;
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.result-page a { display: block; line-height: 0; }
.result-page img { width: 100%; height: auto; border-radius: 5px; box-shadow: 0 5px 18px rgba(18, 45, 80, 0.1); }

@media (max-width: 640px) {
  .shell { width: min(100% - 24px, 980px); margin-top: 12px; }
  .shell--form { padding: 24px 18px; border-radius: 10px; }
  .page-header p { margin-bottom: 26px; font-size: 16px; }
  .mode-switch { grid-template-columns: repeat(2, 1fr); }
  .config-list { grid-template-columns: 1fr; gap: 4px; }
  .config-list dd { margin-bottom: 8px; }
  .field-heading { display: block; }
  .field-heading span { display: block; margin-top: 4px; }
  .drop-zone { min-height: 156px; }
  .file-row { grid-template-columns: 28px 44px minmax(0, 1fr); gap: 8px; }
  .file-thumb { width: 44px; height: 38px; }
  .file-actions { grid-column: 3; justify-content: flex-end; }
  .answer-file { align-items: flex-start; flex-direction: column; }
  .answer-file input { max-width: 100%; }
  .result-header { align-items: flex-start; }
  .result-header h1 { font-size: 34px; }
  .secondary-button { min-width: 112px; min-height: 42px; padding: 0 14px; font-size: 14px; }
  .result-page { grid-template-columns: 1fr; padding: 8px; }
  .result-page figcaption { padding: 2px 3px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
