:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --border: #e1e5ef;
  --text: #171a26;
  --muted: #5d6478;
  --accent: #4f46e5;
  --accent-2: #7c3aed;
  --accent-soft: #eceafe;
  --good: #0f9d58;
  --good-soft: #e3f6ec;
  --bad: #d93025;
  --bad-soft: #fde8e7;
  --warn: #b26a00;
  --warn-soft: #fff3dc;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 8px 24px rgba(20, 24, 40, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117;
    --surface: #171a23;
    --surface-2: #1f2330;
    --border: #2b3040;
    --text: #e9ebf3;
    --muted: #9aa1b5;
    --accent: #8b85ff;
    --accent-2: #b58bff;
    --accent-soft: #25234a;
    --good: #3ccf86;
    --good-soft: #13301f;
    --bad: #ff6b60;
    --bad-soft: #3a1714;
    --warn: #ffb547;
    --warn-soft: #3a2a0d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #171a23;
  --surface-2: #1f2330;
  --border: #2b3040;
  --text: #e9ebf3;
  --muted: #9aa1b5;
  --accent: #8b85ff;
  --accent-2: #b58bff;
  --accent-soft: #25234a;
  --good: #3ccf86;
  --good-soft: #13301f;
  --bad: #ff6b60;
  --bad-soft: #3a1714;
  --warn: #ffb547;
  --warn-soft: #3a2a0d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
img { max-width: 100%; }
button, input, select { font: inherit; color: inherit; }

.container { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.site-header .container { display: flex; align-items: center; gap: 16px; height: 60px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; text-decoration: none; color: var(--text); letter-spacing: -.01em; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff; font-size: 15px;
}
.nav { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text);
  font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-lg { padding: 13px 22px; font-size: 16px; border-radius: 12px; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; border: none; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: var(--muted); font-size: 18px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Landing ---------- */
.hero { padding: 72px 0 48px; text-align: center; }
.hero h1 { font-size: clamp(32px, 5vw, 54px); line-height: 1.08; letter-spacing: -.03em; margin: 0 0 18px; }
.hero h1 .grad { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p.lead { font-size: 19px; color: var(--muted); max-width: 680px; margin: 0 auto 30px; }
.hero .cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.hero .badges { margin-top: 26px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 13px; color: var(--muted); }

.demo-bar { max-width: 640px; margin: 44px auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; text-align: left; }
.demo-row { display: grid; grid-template-columns: 110px 1fr 70px; gap: 12px; align-items: center; margin: 8px 0; font-size: 14px; }
.demo-track { height: 12px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.demo-fill { height: 100%; border-radius: 6px; background: var(--muted); opacity: .5; }
.demo-fill.good { background: linear-gradient(90deg, var(--accent), var(--accent-2)); opacity: 1; }
.demo-row .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

section.block { padding: 56px 0; }
section.block h2 { font-size: clamp(24px, 3.4vw, 34px); letter-spacing: -.02em; margin: 0 0 10px; text-align: center; }
section.block .sub { text-align: center; color: var(--muted); max-width: 640px; margin: 0 auto 36px; }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.card h3 { margin: 10px 0 6px; font-size: 17px; }
.card p { margin: 0; color: var(--muted); font-size: 14.5px; }
.card .ico { width: 40px; height: 40px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 20px; }
.step-num { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; }

.pipeline { display: flex; align-items: stretch; gap: 10px; flex-wrap: wrap; justify-content: center; }
.pipeline .stage { flex: 1 1 160px; max-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; text-align: center; }
.pipeline .stage strong { display: block; margin: 8px 0 4px; }
.pipeline .stage span { color: var(--muted); font-size: 13.5px; }
.pipeline .arrow { align-self: center; color: var(--muted); font-size: 22px; }

.formats-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); font-size: 14.5px; }
.formats-table th, .formats-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.formats-table th { background: var(--surface-2); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.formats-table tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.faq { max-width: 760px; margin: 0 auto; }
.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 18px; margin-bottom: 10px; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq details p { color: var(--muted); margin: 10px 0 0; }

.final-cta { text-align: center; padding: 64px 0 80px; }
.site-footer { border-top: 1px solid var(--border); padding: 24px 0; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- App ---------- */
.app-main { padding: 22px 0 120px; }

.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); background: var(--surface);
  padding: 34px 20px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone { display: block; }
.dropzone > span { display: block; }
.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big { font-size: 18px; font-weight: 700; margin: 8px 0 4px; }
.dropzone .small { color: var(--muted); font-size: 13.5px; }
.dropzone .dz-icon { font-size: 34px; }
.dropzone.compact { padding: 14px 16px; display: flex; gap: 12px; align-items: center; justify-content: center; }
.dropzone.compact .big { font-size: 15px; margin: 0; }
.dropzone.compact .dz-icon { font-size: 20px; }
.dropzone.compact .small { display: none; }

.toolbar {
  margin: 16px 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; box-shadow: var(--shadow);
}
.toolbar .title { font-weight: 700; font-size: 14px; margin-right: 4px; }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--border); }
.toolbar .spacer { flex: 1; }
.field-inline { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); }

.select, .input {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 6px 8px; font-size: 14px; min-width: 0;
}
.select:focus, .input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.input.num { width: 80px; font-variant-numeric: tabular-nums; }
input[type="range"] { accent-color: var(--accent); }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 13.5px; color: var(--muted); cursor: pointer; user-select: none; }
.check input { accent-color: var(--accent); }

.summary { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; color: var(--muted); font-size: 13.5px; margin: 6px 2px 12px; }
.summary strong { color: var(--text); }

.items { display: flex; flex-direction: column; gap: 14px; }
.item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.item-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--border); }
.item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.item-head .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.item-body { display: grid; grid-template-columns: 200px 1fr 260px; gap: 18px; padding: 16px; }

.thumb {
  position: relative; width: 100%; aspect-ratio: 1; border-radius: 10px; overflow: hidden; cursor: pointer;
  background-color: var(--surface-2);
  background-image: linear-gradient(45deg, rgba(128,128,128,.15) 25%, transparent 25%), linear-gradient(-45deg, rgba(128,128,128,.15) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, rgba(128,128,128,.15) 75%), linear-gradient(-45deg, transparent 75%, rgba(128,128,128,.15) 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.thumb .crop-indicator { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.5), 0 0 0 1px rgba(0,0,0,.4); pointer-events: none; }
.thumb .thumb-hint { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; padding: 3px 8px; border-radius: 6px; opacity: 0; transition: opacity .15s; }
.thumb:hover .thumb-hint { opacity: 1; }

.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; align-content: start; }
.setting label.lbl { display: block; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 5px; }
.setting.full { grid-column: 1 / -1; }
.setting .select { width: 100%; }
.quality-row { display: flex; align-items: center; gap: 10px; }
.quality-row input[type="range"] { flex: 1; min-width: 0; }
.quality-row .qv { width: 36px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.dims-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.dims-row .input.num { width: 84px; }
.lock-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; display: grid; place-items: center; font-size: 15px; }
.lock-btn.on { background: var(--accent-soft); border-color: var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.crop-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.crop-desc { font-size: 13px; color: var(--muted); }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

.result { border-left: 1px solid var(--border); padding-left: 18px; display: flex; flex-direction: column; gap: 10px; }
.result-preview { width: 100%; aspect-ratio: 16/10; }
.sizes { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.sizes .from { color: var(--muted); text-decoration: line-through; font-size: 13.5px; }
.sizes .to { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.gain { display: inline-block; padding: 2px 9px; border-radius: 999px; font-weight: 700; font-size: 13px; }
.gain.good { background: var(--good-soft); color: var(--good); }
.gain.bad { background: var(--bad-soft); color: var(--bad); }
.res-meta { font-size: 12.5px; color: var(--muted); }
.result-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.status.stale { color: var(--warn); }
.status.error { color: var(--bad); }
.warn-box { font-size: 12.5px; background: var(--warn-soft); color: var(--warn); padding: 6px 9px; border-radius: 8px; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; color: var(--muted); padding: 30px 0 0; font-size: 14px; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -6px 20px rgba(0,0,0,.06);
}
.bottom-bar .container { display: flex; align-items: center; gap: 12px; padding-top: 12px; padding-bottom: 12px; flex-wrap: wrap; }
.bottom-bar .totals { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bottom-bar .totals strong { color: var(--text); }
.bottom-bar .spacer { flex: 1; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: none; }
.modal.open { display: flex; flex-direction: column; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 10, 18, .72); }
.modal-panel {
  position: relative; margin: auto; width: min(1200px, calc(100vw - 24px)); height: min(860px, calc(100vh - 24px));
  background: var(--surface); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.modal-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-tools { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 12px 14px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; color: var(--muted); font-size: 13.5px; }

.stage {
  position: relative; flex: 1; min-height: 0; overflow: hidden; user-select: none; touch-action: none;
  background-color: #1b1e27;
  background-image: linear-gradient(45deg, #232733 25%, transparent 25%), linear-gradient(-45deg, #232733 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #232733 75%), linear-gradient(-45deg, transparent 75%, #232733 75%);
  background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

/* Cropper */
.crop-wrap { position: absolute; }
.crop-wrap img { display: block; width: 100%; height: 100%; pointer-events: none; }
.crop-box { position: absolute; border: 1px solid rgba(255,255,255,.95); box-shadow: 0 0 0 9999px rgba(0,0,0,.58); cursor: move; }
.crop-box .grid-line { position: absolute; background: rgba(255,255,255,.35); pointer-events: none; }
.crop-box .h { position: absolute; width: 14px; height: 14px; background: #fff; border: 2px solid var(--accent); border-radius: 3px; }
.crop-box .h[data-dir="nw"] { left: -7px; top: -7px; cursor: nwse-resize; }
.crop-box .h[data-dir="ne"] { right: -7px; top: -7px; cursor: nesw-resize; }
.crop-box .h[data-dir="sw"] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.crop-box .h[data-dir="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.crop-box .h[data-dir="n"] { left: calc(50% - 7px); top: -7px; cursor: ns-resize; }
.crop-box .h[data-dir="s"] { left: calc(50% - 7px); bottom: -7px; cursor: ns-resize; }
.crop-box .h[data-dir="w"] { top: calc(50% - 7px); left: -7px; cursor: ew-resize; }
.crop-box .h[data-dir="e"] { top: calc(50% - 7px); right: -7px; cursor: ew-resize; }
.crop-size-tag { position: absolute; left: 0; top: -26px; background: var(--accent); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 6px; white-space: nowrap; font-variant-numeric: tabular-nums; pointer-events: none; }

/* Compare */
.cmp-layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.cmp-layer canvas, .cmp-layer img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cmp-layer.pixelated canvas, .cmp-layer.pixelated img { image-rendering: pixelated; }
.cmp-divider { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; margin-left: -1px; box-shadow: 0 0 6px rgba(0,0,0,.6); cursor: ew-resize; }
.cmp-divider::after {
  content: "⇆"; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 34px; height: 34px; border-radius: 50%; background: #fff; color: #222; display: grid; place-items: center; font-size: 16px; box-shadow: 0 2px 10px rgba(0,0,0,.4);
}
.cmp-divider .hit { position: absolute; top: 0; bottom: 0; left: -14px; right: -14px; }
.cmp-label { position: absolute; top: 12px; padding: 3px 10px; border-radius: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 12.5px; pointer-events: none; }
.cmp-label.l { left: 12px; }
.cmp-label.r { right: 12px; }
.cmp-busy { position: absolute; right: 12px; bottom: 12px; background: rgba(0,0,0,.65); color: #fff; font-size: 12.5px; padding: 4px 10px; border-radius: 6px; display: none; align-items: center; gap: 6px; }
.cmp-busy.on { display: flex; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button { border: none; background: var(--surface); padding: 5px 10px; font-size: 13px; cursor: pointer; color: var(--muted); border-right: 1px solid var(--border); }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .item-body { grid-template-columns: 160px 1fr; }
  .result { grid-column: 1 / -1; border-left: none; border-top: 1px solid var(--border); padding-left: 0; padding-top: 14px; display: grid; grid-template-columns: 160px 1fr; gap: 10px 18px; }
  .result .result-preview { grid-row: span 4; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .grid-3 { grid-template-columns: 1fr; }
  .item-body { grid-template-columns: 1fr; }
  .thumb { aspect-ratio: 16/10; }
  .settings { grid-template-columns: 1fr; }
  .result { grid-template-columns: 1fr; }
  .result .result-preview { grid-row: auto; }
  .pipeline .arrow { display: none; }
  .toolbar .sep { display: none; }
  .hero { padding: 48px 0 32px; }
  .modal-panel { width: 100vw; height: 100vh; border-radius: 0; margin: 0; }
  .nav .hide-sm { display: none; }
}
@media (max-width: 480px) {
  .grid-4 { grid-template-columns: 1fr; }
  .demo-row { grid-template-columns: 80px 1fr 56px; }
}
