:root {
  --bg: #111315;
  --surface: #1b1e22;
  --border: #2a2f35;
  --text: #eceff1;
  --text-2: #9aa4ad;
  --accent: #f2b544;
  --accent-ink: #1a1204;
  --uploading: #4f8cff;
  --queued: #9aa4ad;
  --processing: #f2b544;
  --success: #3ccb7f;
  --danger: #ff6b6b;
  --danger-bg: #2a1618;
  --radius-card: 12px;
  --radius-button: 10px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

a {
  color: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 56px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-size: 17px;
  font-weight: 600;
  text-decoration: none;
}

.topnav {
  display: flex;
  gap: 8px;
}

.topnav a,
.topnav button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: var(--radius-button);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}

.topnav a:hover,
.topnav button:hover {
  color: var(--text);
  border-color: var(--border);
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px;
}

.page-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.muted {
  color: var(--text-2);
  font-size: 13px;
}

.mono {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 13px;
  word-break: break-all;
}

.button {
  min-height: 48px;
  width: 100%;
  border-radius: var(--radius-button);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0 16px;
}

.button-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.button:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
summary:focus-visible,
[role="slider"]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

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

.field input[type="password"] {
  min-height: 48px;
  padding: 0 12px;
  border-radius: var(--radius-button);
  border: 1px solid var(--border);
  background: #14171a;
  color: var(--text);
  font: inherit;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 160px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-card);
  background: #15181b;
  color: var(--text-2);
  text-align: center;
  cursor: pointer;
  padding: 16px;
}

.dropzone strong {
  color: var(--text);
  font-size: 16px;
}

.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.preview-frame {
  position: relative;
  background: #0b0d0f;
  border-radius: var(--radius-card);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.error-text {
  color: var(--danger);
  font-size: 13px;
  min-height: 20px;
  margin: 0;
}

.progress {
  height: 8px;
  border-radius: 4px;
  background: #262b30;
  overflow: hidden;
}

.progress > div {
  height: 100%;
  width: 0;
  background: var(--uploading);
  transition: width 120ms linear;
}

.status-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.status-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
}

.status-icon {
  font-size: 20px;
  line-height: 1;
}

.status-icon.uploading { color: var(--uploading); }
.status-icon.queued { color: var(--queued); }
.status-icon.processing { color: var(--processing); }
.status-icon.succeeded { color: var(--success); }
.status-icon.failed { color: var(--danger); }

.status-icon.spin {
  animation: spin 1.2s linear infinite;
}

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

.status-meta {
  text-align: right;
  color: var(--text-2);
  font-size: 13px;
}

.stepper {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-top: 16px;
}

.step {
  border-top: 3px solid var(--border);
  padding-top: 8px;
  font-size: 13px;
  color: var(--text-2);
}

.step.done {
  border-color: var(--success);
  color: var(--text);
}

.step.active {
  border-color: var(--processing);
  color: var(--text);
}

.step.failed {
  border-color: var(--danger);
  color: var(--danger);
}

.failure-card {
  background: var(--danger-bg);
  border-color: var(--danger);
}

.failure-card h2 {
  margin: 0 0 8px;
  font-size: 17px;
}

.failure-card p {
  margin: 0 0 8px;
}

.failure-card details {
  margin: 12px 0;
}

.compare {
  position: relative;
  border-radius: var(--radius-card);
  overflow: hidden;
  background: #0b0d0f;
  touch-action: pan-y;
  user-select: none;
}

.compare img {
  display: block;
  width: 100%;
  height: auto;
}

.compare .layer {
  position: absolute;
  inset: 0;
}

.compare .layer img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.compare .clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.compare .handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  transform: translateX(-1.5px);
}

.badge {
  position: absolute;
  top: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 12px;
  color: #fff;
}

.badge.left {
  left: 8px;
}

.badge.right {
  right: 8px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.segmented button {
  min-height: 44px;
  border-radius: var(--radius-button);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--text);
}

.output-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.output-title {
  font-weight: 600;
}

.hash-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.hash-line button {
  min-height: 32px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

details.info {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

details.info summary {
  cursor: pointer;
  color: var(--text-2);
  min-height: 40px;
  display: flex;
  align-items: center;
}

.timeline {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.banner {
  border-radius: var(--radius-button);
  padding: 12px 16px;
  background: #33280f;
  border: 1px solid #5a4715;
  color: #f6d78a;
  font-size: 14px;
}

.ok-banner {
  background: #10291d;
  border-color: #1f5a3c;
  color: #9be8bd;
}

.job-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}

.job-row:last-child {
  border-bottom: 0;
}

.job-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #0b0d0f;
  object-fit: cover;
  flex: 0 0 auto;
}

.job-row-main {
  flex: 1;
  min-width: 0;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
}

.status-chip.succeeded { color: var(--success); }
.status-chip.failed { color: var(--danger); }
.status-chip.processing { color: var(--processing); }
.status-chip.queued { color: var(--text-2); }

.job-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.job-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.compare-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.compare-single {
  border-radius: var(--radius-card);
  overflow: hidden;
  background: #0b0d0f;
}

.compare-single img {
  display: block;
  width: 100%;
  height: auto;
}

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

.preview-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.text-button {
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-button);
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
}

.batch-new-btn {
  width: auto;
  flex: 0 0 auto;
}

.info-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.info-row .mono {
  text-align: right;
}

@media (min-width: 768px) {
  .job-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 16px;
    align-items: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
