/* PixelShift – theme tokens use light-dark() so system and manual theme both work */
:root {
  color-scheme: light dark;
  --bg: light-dark(#f4f5fb, #0b0e1a);
  --glow: light-dark(#e2e5ff, #1b2050);
  --card: light-dark(#ffffff, #141831);
  --field: light-dark(#f6f7fc, #1a1f3d);
  --text: light-dark(#161a2e, #eceefb);
  --muted: light-dark(#646b8a, #98a0c6);
  --line: light-dark(#e3e6f1, #262c4f);
  --accent: light-dark(#4f46e5, #8b93ff);
  --accent-soft: light-dark(#eceaff, #252a5c);
  --ok: light-dark(#047857, #34d399);
  --ok-soft: light-dark(#d9f5e8, #123a2e);
  --bad: light-dark(#dc2626, #f87171);
  --bad-soft: light-dark(#fde4e4, #411a1f);
  --warn-soft: light-dark(#fff1d6, #403315);
  --shadow: 0 1px 2px rgb(20 20 60 / 0.06), 0 12px 32px -16px rgb(30 30 90 / 0.3);
  --radius: 16px;
}
:root[data-theme='light'] { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.55 Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(1100px 460px at 50% -140px, var(--glow), transparent 70%), var(--bg);
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
a { color: inherit; text-decoration: none; }
kbd { font: 11px ui-monospace, Menlo, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: var(--field); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.bar { display: flex; align-items: center; gap: 14px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: -0.3px; margin-right: auto; }
.logo { width: 30px; height: 30px; }
.badge-private {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--ok);
  background: var(--ok-soft); padding: 5px 11px; border-radius: 999px;
}
.badge-private svg { width: 15px; height: 15px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; flex: none;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text);
  cursor: pointer; font: inherit;
}
.icon-btn:hover:not(:disabled) { border-color: var(--accent); }
.icon-btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- hero ---------- */
.hero { text-align: center; padding: 38px 0 24px; }
.hero h1 { margin: 0 0 8px; font-size: clamp(26px, 4.2vw, 40px); line-height: 1.15; letter-spacing: -0.8px; font-weight: 800; }
.hero p { margin: 0 auto; max-width: 560px; color: var(--muted); font-size: 16px; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-areas: 'drop settings' 'results settings';
  gap: 20px; align-items: start; padding-bottom: 20px;
}
.drop { grid-area: drop; }
.settings { grid-area: settings; position: sticky; top: 76px; }
.results { grid-area: results; }
@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: 'drop' 'settings' 'results'; }
  .settings { position: static; }
  .badge-private { display: none; }
}

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

/* ---------- drop zone ---------- */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  min-height: 230px; padding: 28px 20px; cursor: pointer;
  background: var(--card); border: 2px dashed color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 20px; box-shadow: var(--shadow);
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop:focus-visible { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, var(--card)); outline: none; }
.drop-icon { width: 54px; height: 54px; color: var(--accent); margin-bottom: 6px; }
.drop-title { margin: 0; font-size: 20px; font-weight: 700; }
.drop-sub { margin: 4px 0 14px; color: var(--muted); }
.link { color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.fmt-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.fmt-chips span { font-size: 11.5px; font-weight: 700; letter-spacing: .3px; color: var(--muted); background: var(--field); border: 1px solid var(--line); padding: 2px 9px; border-radius: 999px; }

/* ---------- settings ---------- */
.settings { padding: 6px 18px 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 0 10px; }
.card-head h2 { margin: 0; font-size: 16px; }
.link-btn { border: 0; background: none; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; padding: 4px; }
.link-btn:hover { color: var(--accent); }
.group { border-top: 1px solid var(--line); padding: 14px 0 0; margin-top: 4px; }
.group + .group { margin-top: 14px; }

.field { margin-top: 16px; }
.lbl { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.lbl .opt { font-weight: 400; color: var(--muted); }
.lbl-row { display: flex; justify-content: space-between; align-items: baseline; }
.val { font-size: 13px; font-weight: 700; color: var(--accent); }
.hint { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }
.hint:empty { display: none; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-between .lbl { margin: 0; }

select, input[type='number'] {
  width: 100%; padding: 9px 11px; font: inherit; font-size: 14px;
  color: var(--text); background: var(--field);
  border: 1px solid var(--line); border-radius: 10px;
}
select { cursor: pointer; }
select:focus-visible, input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 40px; }
.input-suffix span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 12.5px; color: var(--muted); pointer-events: none; }
input[type='range'] { width: 100%; accent-color: var(--accent); margin: 2px 0 0; }
input[type='color'] { width: 44px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; cursor: pointer; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  padding: 4px 10px; border-radius: 999px; color: var(--text);
  background: var(--field); border: 1px solid var(--line);
}
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- results ---------- */
.results-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.stats { display: flex; flex-wrap: wrap; gap: 8px; }
.stat { display: flex; flex-direction: column; padding: 6px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); min-width: 84px; }
.stat small { font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); }
.stat b { font-size: 15px; }
.stat.good b { color: var(--ok); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  padding: 9px 16px; border-radius: 11px; color: var(--text);
  background: var(--card); border: 1px solid var(--line);
  transition: border-color .15s, transform .05s, opacity .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { color: #fff; border-color: transparent; background: linear-gradient(135deg, #6366f1, #8b5cf6); box-shadow: 0 6px 16px -6px rgb(99 102 241 / .6); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 9px; }

.progress { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; margin-bottom: 12px; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, #6366f1, #8b5cf6); transition: width .2s; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.item { padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.item[data-status='done'] { border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); }
.item[data-status='error'] { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.item-top { display: flex; align-items: center; gap: 12px; }
.item[data-status='done'] .thumb { display: none; }
.thumb {
  flex: none; width: 56px; height: 56px; object-fit: cover; border-radius: 10px; display: block;
  background: repeating-conic-gradient(var(--field) 0% 25%, var(--line) 0% 50%) 50% / 14px 14px;
}
.meta { min-width: 0; flex: 1; }
.name-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { flex: none; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--field); color: var(--muted); }
.pill.working { background: var(--accent-soft); color: var(--accent); animation: pulse 1s ease-in-out infinite; }
.pill.done { background: var(--ok-soft); color: var(--ok); }
.pill.error { background: var(--bad-soft); color: var(--bad); }
@keyframes pulse { 50% { opacity: .5; } }
.sub { margin-top: 2px; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 8px; }
.sub .bad { color: var(--bad); }
.sub .note { background: var(--warn-soft); color: var(--text); padding: 0 8px; border-radius: 99px; }
.btns { display: flex; gap: 6px; align-items: center; flex: none; }

/* before / after preview inside each finished card */
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.fig { display: block; padding: 0; text-align: left; font: inherit; color: inherit; background: none; border: 0; cursor: zoom-in; min-width: 0; }
.fig-img {
  height: 190px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line);
  background: repeating-conic-gradient(var(--field) 0% 25%, var(--line) 0% 50%) 50% / 16px 16px;
}
.fig:hover .fig-img { border-color: var(--accent); }
.fig-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.fig-cap { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.fig-cap b { color: var(--text); }
.fig-cap .save { font-weight: 700; padding: 0 8px; border-radius: 99px; }
.fig-cap .save.ok { background: var(--ok-soft); color: var(--ok); }
.fig-cap .save.bad { background: var(--bad-soft); color: var(--bad); }

@media (max-width: 560px) {
  .item-top { flex-wrap: wrap; }
  .btns { width: 100%; justify-content: flex-end; }
  .fig-img { height: 130px; }
  .actions .btn { flex: 1 1 auto; }
}

.foot { padding: 26px 20px 40px; text-align: center; color: var(--muted); font-size: 13px; }
.foot p { margin: 0; }

/* ---------- compare dialog ---------- */
.cmp { width: min(96vw, 980px); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px 16px; background: var(--card); color: var(--text); box-shadow: 0 30px 80px -20px rgb(0 0 0 / .6); }
.cmp::backdrop { background: rgb(5 7 20 / .7); backdrop-filter: blur(3px); }
.cmp-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.cmp-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-stage {
  position: relative; margin: 0 auto; overflow: hidden; border-radius: 12px; user-select: none; touch-action: none; cursor: ew-resize;
  width: 100%; max-height: 68vh;
  background: repeating-conic-gradient(var(--field) 0% 25%, var(--line) 0% 50%) 50% / 18px 18px;
}
.cmp-stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.cmp-handle { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; background: #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / .35); transform: translateX(-1px); pointer-events: none; }
.cmp-handle span { position: absolute; top: 50%; left: 50%; width: 34px; height: 34px; transform: translate(-50%, -50%); border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgb(0 0 0 / .4); }
.cmp-handle span::before { content: '◀ ▶'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 9px; color: #444; letter-spacing: 1px; }
.cmp-tag { position: absolute; top: 10px; font-size: 12px; font-weight: 700; color: #fff; background: rgb(0 0 0 / .55); padding: 3px 9px; border-radius: 99px; pointer-events: none; }
.cmp-tag.l { left: 10px; }
.cmp-tag.r { right: 10px; }
#cmpRange { margin-top: 12px; width: 100%; accent-color: var(--accent); }
.cmp-foot { margin: 8px 0 0; text-align: center; color: var(--muted); font-size: 13.5px; }

/* ---------- toasts & drag overlay ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 8px; max-width: min(92vw, 380px); }
.toast {
  padding: 11px 14px; border-radius: 12px; font-size: 14px; font-weight: 600;
  background: var(--text); color: var(--bg); box-shadow: 0 10px 30px -8px rgb(0 0 0 / .45);
  animation: in .2s ease-out;
}
.toast.ok { background: var(--ok); color: #fff; }
.toast.warn { background: #b45309; color: #fff; }
.toast.error { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); transition: all .25s; }
@keyframes in { from { opacity: 0; transform: translateY(8px); } }

.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; pointer-events: none;
  background: color-mix(in srgb, var(--accent) 22%, rgb(8 10 28 / .75)); backdrop-filter: blur(3px);
}
.overlay div { font-size: 24px; font-weight: 800; color: #fff; padding: 28px 44px; border: 3px dashed #fff; border-radius: 24px; }

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