:root {
  color-scheme: light;
  --bg: #eef3f6;
  --panel: #ffffff;
  --topbar: #f9fbfd;
  --field: #ffffff;
  --field-soft: #f8fbff;
  --item: #ffffff;
  --preview: #eef3f6;
  --accent-soft: #edf4ff;
  --drag-bg: #e9fbf8;
  --disabled: #aab5c2;
  --ink: #162033;
  --muted: #657186;
  --line: #d6dee8;
  --blue: #2764d8;
  --teal: #159895;
  --green: #2d9b6f;
  --yellow: #f5b82e;
  --red: #cc3d3d;
  --shadow: 0 12px 32px rgba(31, 49, 79, 0.12);
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15191f;
  --panel: #202630;
  --topbar: #1b2028;
  --field: #151a21;
  --field-soft: #1b222b;
  --item: #202630;
  --preview: #161c24;
  --accent-soft: #223553;
  --drag-bg: #17342f;
  --disabled: #596273;
  --ink: #eef3f6;
  --muted: #a3afbf;
  --line: #3a4655;
  --blue: #6f9cff;
  --teal: #32c8bf;
  --green: #55d392;
  --yellow: #e4b64a;
  --red: #ff7474;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 12px 22px;
  background: var(--topbar);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.15;
  letter-spacing: 0;
}

.brand span,
.summary-item span,
.control-field span,
.field-label,
.check-field,
.top-control span,
.theme-control,
.header-action,
.file-item small,
.message {
  color: var(--muted);
}

.top-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.top-control {
  display: grid;
  gap: 4px;
}

.top-control select,
.header-action {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--ink);
}

.top-control select {
  min-width: 150px;
  padding: 6px 9px;
}

.theme-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
}

.theme-control input {
  accent-color: var(--blue);
}

.header-action,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
}

.header-action {
  padding: 7px 10px;
}

.header-action img,
.secondary-action img {
  width: 18px;
  height: 18px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

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

.controls-panel {
  padding: 18px;
  align-self: start;
}

.field-group {
  margin-bottom: 18px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

.upload-zone,
.secondary-upload {
  width: 100%;
  border: 1px dashed #9fb0c4;
  border-radius: 8px;
  background: var(--field-soft);
  color: var(--ink);
  cursor: pointer;
}

.upload-zone {
  display: grid;
  place-items: center;
  min-height: 136px;
  padding: 18px;
  text-align: center;
}

.upload-zone.dragging {
  border-color: var(--teal);
  background: var(--drag-bg);
}

.upload-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-size: 30px;
  line-height: 1;
}

.upload-zone small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.file-list {
  display: grid;
  gap: 8px;
  max-height: 132px;
  margin-top: 10px;
  overflow: auto;
}

.file-item,
.result-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--item);
}

.file-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
}

.file-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.secondary-action {
  width: 100%;
  min-height: 40px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--ink);
  font-weight: 700;
}

.operation-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.operation-option {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--item);
  cursor: pointer;
}

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

.operation-option img,
.primary-action img,
.secondary-upload img {
  width: 20px;
  height: 20px;
}

.operation-option:has(input:checked) {
  border-color: var(--blue);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.control-field {
  display: grid;
  gap: 6px;
}

.control-field input,
.control-field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--field);
  color: var(--ink);
}

.watermark-area {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.secondary-upload {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  margin-bottom: 10px;
  border-style: solid;
}

.watermark-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.message {
  min-height: 22px;
  margin: 14px 0 10px;
}

.message.error {
  color: var(--red);
}

.primary-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.primary-action:disabled {
  cursor: wait;
  opacity: 0.72;
}

.app-shell button:disabled,
.app-shell input:disabled,
.app-shell select:disabled {
  cursor: wait;
  opacity: 0.68;
}

.workspace {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.summary-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
}

.summary-item {
  min-height: 86px;
  padding: 16px;
  background: var(--item);
}

.summary-item strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
  letter-spacing: 0;
}

.summary-item.changed strong {
  color: var(--green);
}

.summary-item.failed strong {
  color: var(--red);
}

.results-panel {
  min-height: 520px;
  padding: 18px;
}

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

.results-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.download-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: var(--teal);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  font-weight: 700;
}

.download-link.individual {
  background: var(--blue);
}

.download-link.disabled {
  pointer-events: none;
  background: var(--disabled);
  cursor: default;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 390px;
  color: var(--muted);
}

.empty-state img {
  width: 94px;
  height: 94px;
  margin-bottom: 12px;
  opacity: 0.72;
}

.empty-spinner {
  display: none;
  width: 34px;
  height: 34px;
  border: 4px solid var(--line);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.empty-state.is-processing .empty-spinner {
  display: block;
}

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

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

.result-card {
  overflow: hidden;
}

.result-preview {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  background: var(--preview);
}

.result-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.result-preview span {
  color: var(--muted);
}

.result-body {
  display: grid;
  gap: 6px;
  padding: 10px;
}

.result-body strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-body small {
  color: var(--muted);
}

.result-body .error-text {
  color: var(--red);
}

[hidden] {
  display: none !important;
}

@media (max-width: 920px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-controls {
    justify-content: flex-start;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .summary-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .results-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .download-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 540px) {
  .topbar {
    padding: 10px 14px;
  }

  .top-controls,
  .top-control,
  .top-control select,
  .theme-control,
  .header-action {
    width: 100%;
  }

  .app-shell {
    padding: 12px;
  }

  .operation-grid,
  .settings-grid,
  .watermark-grid {
    grid-template-columns: 1fr;
  }

  .summary-panel {
    grid-template-columns: 1fr;
  }

  .download-actions,
  .download-link {
    width: 100%;
  }
}
