:root {
  color-scheme: light dark;
  --bg: #fbfbfa;
  --fg: #1a1a19;
  --muted: #6b6b66;
  --line: #e2e2dd;
  --card: #ffffff;
  --accent: #2f6f4f;
  --accent-fg: #ffffff;
  --danger: #8a2b20;
  --danger-bg: #fdf0ee;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161714;
    --fg: #ececE6;
    --muted: #9a9a92;
    --line: #2e302b;
    --card: #1e201c;
    --accent: #7fbf9a;
    --accent-fg: #10120f;
    --danger: #f0a79c;
    --danger-bg: #2c1c19;
  }
}

* { box-sizing: border-box; }

/* Must outrank the id selectors below. `#working { display: flex }` beat the
   user agent's `[hidden] { display: none }` on specificity, so the progress
   panel and the access code row were both visible on first paint. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main { max-width: 720px; margin: 0 auto; padding: 48px 20px 96px; }

h1 { font-size: 1.6rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 0.95rem; margin: 0 0 12px; font-weight: 600; }
.sub { margin: 0 0 28px; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

/* file drop */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; min-height: 128px; padding: 24px;
  border: 1.5px dashed var(--line); border-radius: 10px;
  cursor: pointer; text-align: center;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.drop-title { font-weight: 600; }
.drop-hint { color: var(--muted); font-size: 0.9rem; }
.preview-wrap {
  position: relative; display: block; width: fit-content;
  margin: 16px auto 0; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line); line-height: 0;
}
.preview { display: block; max-width: 100%; max-height: 260px; width: auto; height: auto; }

/* The sharp copy, revealed only through the travelling band. */
.preview-sharp { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; }

/* :not(.preview-sharp) matters. The sharp copy also carries .preview, so
   without it the reveal layer was blurred too and the band could never show. */
.preview-wrap.busy .preview:not(.preview-sharp) {
  filter: blur(12px) saturate(0.6); transform: scale(1.04);
}
.preview-wrap.busy .preview-sharp {
  opacity: 1;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 40%, #000 60%, transparent);
          mask-image: linear-gradient(to bottom, transparent, #000 40%, #000 60%, transparent);
  -webkit-mask-size: 100% 55%;  mask-size: 100% 55%;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  animation: sweep 1.9s linear infinite;
}
.preview-wrap .preview:not(.preview-sharp) { transition: filter .35s ease, transform .35s ease; }

@keyframes sweep {
  from { -webkit-mask-position: 0 -55%; mask-position: 0 -55%; }
  to   { -webkit-mask-position: 0 100%; mask-position: 0 100%; }
}

/* Nothing on the options is usable mid request: changing the model or the
   output size in flight would describe the result wrongly when it lands. */
.locked { opacity: 0.45; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  .preview-wrap.busy .preview-sharp { animation-duration: 6s; }
}
.fileinfo { margin: 12px 0 0; color: var(--muted); font-size: 0.875rem; text-align: center; }

/* options */
.ops { display: grid; gap: 2px; margin-bottom: 18px; }
.op { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.op:hover { background: color-mix(in srgb, var(--fg) 4%, transparent); }
.op input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.size { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.875rem; }
select, input[type=password] {
  font: inherit; font-size: 0.875rem; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--fg);
}

button {
  font: inherit; font-size: 0.9rem; font-weight: 500;
  padding: 9px 18px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg);
  cursor: pointer; transition: opacity .15s;
}
button:hover { opacity: 0.82; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; margin-left: auto; }

.custom { display: block; margin: 4px 0 18px; }
.custom span { display: block; color: var(--muted); font-size: 0.82rem; margin-bottom: 6px; }
textarea {
  font: inherit; font-size: 0.875rem; width: 100%; padding: 9px 11px; resize: vertical;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--fg);
}
textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.note { margin: 18px 0 0; padding-top: 16px; border-top: 1px solid var(--line);
        color: var(--muted); font-size: 0.82rem; line-height: 1.5; }

/* working */
#working { display: flex; align-items: center; gap: 14px; }
.spinner {
  width: 18px; height: 18px; flex: none; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.working-text { margin: 0; }
.elapsed { margin: 0 0 0 auto; color: var(--muted); font-variant-numeric: tabular-nums; }

/* access gate */
.gate h2 { margin-bottom: 6px; }
.gate-hint { margin: 0 0 14px; color: var(--muted); font-size: 0.875rem; }
.gate .row input { flex: 1; }
.gate-error { margin: 10px 0 0; color: var(--danger); font-size: 0.85rem; }

/* error */
.error { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); }
.error p { margin: 0; }
#codewrap { display: flex; gap: 8px; margin-top: 12px; }

/* before and after */
.compare {
  position: relative; overflow: hidden; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card);
  user-select: none; touch-action: none; cursor: ew-resize; line-height: 0;
}
.compare img { display: block; width: 100%; height: auto; }
/* Clipped, not resized. Giving this a width made the image inside it narrow as
   the wipe moved, so the original slid horizontally instead of staying put. */
.before-wrap { position: absolute; inset: 0; clip-path: inset(0 50% 0 0); }
/* The original is drawn into the same box as the result. The model does not
   return a pixel aligned copy, so this keeps the wipe readable. */
.before-wrap img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.divider {
  position: absolute; top: 0; bottom: 0; left: 50%;
  width: 2px; margin-left: -1px; background: rgba(255,255,255,0.85);
  pointer-events: none;
}
.handle {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 34px; margin-left: -17px;
  cursor: ew-resize; display: flex; align-items: center; justify-content: center;
}
.handle::after {
  content: ""; width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,0.92); box-shadow: 0 1px 6px rgba(0,0,0,0.35);
}
.handle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tag {
  position: absolute; top: 10px; padding: 3px 8px; border-radius: 6px;
  background: rgba(0,0,0,0.55); color: #fff; font-size: 0.72rem; line-height: 1.5;
  pointer-events: none;
}
.tag-l { left: 10px; } .tag-r { right: 10px; }

.meta { margin: 12px 0 16px; color: var(--muted); font-size: 0.82rem; }
.spend { margin: 24px 0 0; color: var(--muted); font-size: 0.8rem; text-align: center; }
