:root {
  --bg: #f6f4f1;
  --card: #ffffff;
  --ink: #1d1b19;
  --muted: #6f6a64;
  --line: #e4dfd8;
  --accent: #b5532f;
  --accent-ink: #fff;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151413; --card: #1f1d1b; --ink: #f1ede8; --muted: #a39d96; --line: #34302c; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.45;
}
header { padding: 24px 20px 8px; max-width: 1200px; margin: 0 auto; }
h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.02em; }
.sub { margin: 4px 0 0; color: var(--muted); }
main { max-width: 1200px; margin: 0 auto; padding: 12px 16px 32px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card h2 { margin: 0 0 6px; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.step { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: .8rem; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: .9rem; }
.drop {
  position: relative; display: grid; place-items: center; aspect-ratio: 3/4;
  border: 2px dashed var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; background: var(--bg);
}
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop img { width: 100%; height: 100%; object-fit: contain; }
.drop .placeholder { color: var(--muted); padding: 16px; text-align: center; }
.drop.has-img .placeholder { display: none; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: .9rem; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.chips button {
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  padding: 6px 12px; border-radius: 999px; font-size: .85rem; cursor: pointer;
}
.chips button.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 4px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; }
.segmented button { border: 0; background: transparent; color: var(--ink); border-radius: 9px;
  padding: 8px; cursor: pointer; text-align: left; font: inherit; }
.segmented button small { display: block; color: var(--muted); font-size: .75rem; }
.segmented button.active { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.engine-opts label, details label { display: block; margin-top: 10px; font-size: .9rem; color: var(--muted); }
.engine-opts input[type=text], .engine-opts input[type=password], .engine-opts select {
  width: 100%; margin-top: 4px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit;
}
.engine-opts .hint { margin: 6px 0 0; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--muted); font-size: .9rem; }

.primary {
  width: 100%; padding: 14px; font: inherit; font-weight: 600; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
}
.primary:disabled { opacity: .45; cursor: not-allowed; }
.secondary { margin-top: 12px; background: none; border: 1px solid var(--accent); color: var(--accent);
  padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: .85rem; }
.status { min-height: 1.4em; color: var(--muted); font-size: .9rem; }
.status.error { color: #c0392b; }

.compare { position: relative; aspect-ratio: 3/4; border-radius: 12px; overflow: hidden; background: var(--bg); touch-action: pan-y; }
.compare img, .compare canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.after-wrap { position: absolute; inset: 0; clip-path: inset(0 0 0 50%); }
.divider { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; background: #fff; box-shadow: 0 0 4px rgba(0,0,0,.4); pointer-events: none; }
.compare input[type=range] {
  position: absolute; left: 0; right: 0; bottom: 10px; width: calc(100% - 24px); margin: 0 12px;
}

.live-view { position: relative; border-radius: 12px; overflow: hidden; background: #000; min-height: 200px;
  display: grid; place-items: center; }
.live-view canvas { width: 100%; max-height: 70vh; object-fit: contain; display: block; }
.fps { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.55); color: #fff;
  font-size: .75rem; padding: 2px 8px; border-radius: 999px; }
.live-controls { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 6px; margin-top: 10px; }
.live-controls .secondary { margin-top: 0; padding: 8px 6px; }
.live-controls .primary { padding: 10px; }
.live-after { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: start; margin-top: 12px;
  padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.live-after img { width: 96px; border-radius: 8px; }
.live-after .hint { margin: 0 0 8px; }
.live-after .secondary { margin-top: 0; }
.secondary:disabled { opacity: .45; cursor: not-allowed; }

.adjust { margin-top: 12px; display: grid; gap: 4px; }
.adjust-head { display: flex; justify-content: space-between; align-items: center; }
.adjust label:not(.check) { display: grid; grid-template-columns: 9.5em 1fr; align-items: center; gap: 8px;
  font-size: .85rem; color: var(--muted); }
.adjust .check { margin-top: 4px; }
.adjust input[type=range] { width: 100%; }

.history { margin-top: 16px; }
.thumbs { display: flex; gap: 8px; overflow-x: auto; }
.thumbs img { height: 140px; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; }
footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 16px 24px; }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--muted);
  border-top-color: transparent; border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
