:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --line: #d8ddd6;
  --line-strong: #b9c1b5;
  --text: #222623;
  --muted: #687069;
  --sage: #6f8f79;
  --sage-strong: #42664e;
  --coral: #dc806d;
  --ink: #1e2024;
  --shadow: 0 16px 40px rgba(31, 38, 34, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans TC",
    "PingFang TC", "Microsoft JhengHei", sans-serif;
}

button,
input {
  font: inherit;
}

body.modal-open {
  overflow: hidden;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 0 0 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--sage-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
  letter-spacing: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-pill.ready {
  border-color: rgba(66, 102, 78, 0.28);
  color: var(--sage-strong);
}

.status-pill.warn {
  border-color: rgba(220, 128, 109, 0.38);
  color: #a34e3e;
}

.file-warning {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid rgba(220, 128, 109, 0.38);
  border-radius: 8px;
  background: #fff7f4;
  color: #8f4638;
  font-size: 14px;
  line-height: 1.5;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.control-panel {
  position: sticky;
  top: 20px;
  display: grid;
  gap: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dropzone {
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 22px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 8px;
  background: #fbfcfb;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    transform 160ms ease;
}

.dropzone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.dropzone.dragover {
  border-color: var(--sage);
  background: #eef4ef;
  transform: translateY(-1px);
}

.drop-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--sage-strong);
  font-size: 28px;
  line-height: 1;
}

.drop-title {
  font-size: 18px;
  font-weight: 700;
}

.drop-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.control-group {
  display: grid;
  gap: 10px;
}

.group-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--sage-strong);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf0ec;
}

.segmented button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(31, 38, 34, 0.1);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 8px;
}

.primary,
.secondary,
.download,
.inspect {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
}

.primary {
  border: 1px solid var(--sage-strong);
  background: var(--sage-strong);
  color: #fff;
  font-weight: 700;
}

.secondary {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

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

.batch-download {
  grid-column: 1 / -1;
}

.run-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  color: var(--muted);
  font-size: 13px;
}

.results-panel {
  min-width: 0;
  min-height: calc(100vh - 134px);
  padding: 0 0 40px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 430px), 1fr));
  gap: 16px;
  min-width: 0;
}

.result-card {
  display: grid;
  gap: 12px;
  min-width: 0;
  overflow: hidden;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(31, 38, 34, 0.05);
}

.card-head,
.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.filename {
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  background: #edf0ec;
  color: var(--muted);
  font-size: 12px;
}

.badge.done {
  background: #e4f0e6;
  color: var(--sage-strong);
}

.badge.error {
  background: #f8e3df;
  color: #a34e3e;
}

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

figure {
  display: grid;
  gap: 8px;
  min-width: 0;
  margin: 0;
}

figcaption {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.preview {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  max-width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

.checker-bg {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #dfe3df 25%, transparent 25%),
    linear-gradient(-45deg, #dfe3df 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dfe3df 75%),
    linear-gradient(-45deg, transparent 75%, #dfe3df 75%);
  background-position:
    0 0,
    0 12px,
    12px -12px,
    -12px 0;
  background-size: 24px 24px;
}

.dark-bg {
  background: var(--ink);
}

.light-bg {
  background: #fff;
}

.stats {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.download,
.inspect {
  flex: 0 0 auto;
  min-width: 86px;
  min-height: 36px;
  border: 1px solid var(--sage-strong);
  background: var(--surface);
  color: var(--sage-strong);
  font-size: 13px;
  font-weight: 700;
}

.inspect {
  min-width: 104px;
}

.download.disabled,
.inspect.disabled {
  border-color: var(--line);
  color: var(--muted);
  pointer-events: none;
}

.inspect:disabled {
  cursor: not-allowed;
}

.inspect-modal[hidden] {
  display: none;
}

.inspect-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(18, 20, 22, 0.62);
}

.inspect-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1120px, 100%);
  height: min(840px, 100%);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.25);
}

.inspect-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.inspect-heading {
  min-width: 0;
}

.inspect-title {
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inspect-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.inspect-mode {
  width: 210px;
}

.zoom-control {
  display: grid;
  grid-template-columns: auto minmax(100px, 160px) 48px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.zoom-control input {
  width: 100%;
  accent-color: var(--sage-strong);
}

.inspect-close {
  min-width: 70px;
  min-height: 36px;
}

.inspect-viewport {
  min-height: 0;
  overflow: auto;
  background: #eef0ed;
  overscroll-behavior: contain;
}

.inspect-stage {
  display: grid;
  place-items: center;
  min-width: 100%;
  min-height: 100%;
  padding: 48px;
}

.inspect-stage img {
  display: block;
  max-width: none;
  max-height: none;
  image-rendering: auto;
}

@media (max-width: 900px) {
  .app-shell {
    padding: 18px;
  }

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

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

  .control-panel {
    position: static;
  }

  .results-panel {
    min-height: auto;
  }
}

@media (max-width: 520px) {
  .preview-pair,
  .actions {
    grid-template-columns: 1fr;
  }

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

  .meta-row {
    align-items: stretch;
    flex-direction: column;
  }

  .card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .inspect-modal {
    padding: 0;
  }

  .inspect-panel {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
  }

  .inspect-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .inspect-controls {
    display: grid;
    grid-template-columns: 1fr;
  }

  .inspect-mode {
    width: 100%;
  }

  .zoom-control {
    grid-template-columns: auto minmax(0, 1fr) 48px;
  }

  .inspect-close {
    width: 100%;
  }

  .inspect-stage {
    padding: 28px;
  }
}
