/* ================================================================ tokens */
:root {
  color-scheme: light;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #1c2130;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --accent: #4c5fd5;
  --accent-hover: #3f51c4;
  --accent-soft: #eef0fd;
  --accent-text: #3646b8;
  --on-accent: #ffffff;
  --good: #137a3a;
  --good-soft: #e5f5eb;
  --warn: #93610a;
  --warn-soft: #fdf3dc;
  --bad: #c0362c;
  --bad-soft: #fdecea;
  --toast: #1c2130;
  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / .05);
  --shadow: 0 1px 3px rgb(16 24 40 / .06), 0 10px 28px rgb(16 24 40 / .07);
  --ring: 0 0 0 3px rgb(76 95 213 / .3);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1116;
    --surface: #171a21;
    --surface-2: #1d212a;
    --text: #e8eaef;
    --muted: #9aa3b5;
    --faint: #6c7486;
    --line: #262b35;
    --line-strong: #343b48;
    --accent: #7b8cff;
    --accent-hover: #95a3ff;
    --accent-soft: #222949;
    --accent-text: #aab5ff;
    --on-accent: #0c1020;
    --good: #4ade80;
    --good-soft: #13281b;
    --warn: #fbbf24;
    --warn-soft: #2b2410;
    --bad: #f87171;
    --bad-soft: #301818;
    --toast: #2a2f3b;
    --shadow-sm: none;
    --shadow: 0 0 0 1px var(--line);
    --ring: 0 0 0 3px rgb(123 140 255 / .4);
  }
}

/* ================================================================ base */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; line-height: 1.25; }
p { margin: 0; }
.muted { color: var(--muted); }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: none; box-shadow: var(--ring); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition: none !important; } }

/* ================================================================ header */
.topbar, .tools, .layout, .footer { max-width: 1180px; margin-inline: auto; padding-inline: 24px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 22px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-sm); }
.logo .icon { width: 24px; height: 24px; }
h1 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.brand p { color: var(--muted); font-size: 14px; }
.privacy { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 99px;
  background: var(--good-soft); color: var(--good); font-size: 13px; font-weight: 600; cursor: default; }
.privacy .icon { width: 16px; height: 16px; }

/* ================================================================ tool picker */
.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 20px; }
.tool-card { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1.5px solid var(--line); color: var(--text); text-decoration: none;
  box-shadow: var(--shadow-sm); transition: border-color .15s, background .15s, transform .15s; }
.tool-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.tool-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex: none;
  background: var(--surface-2); color: var(--muted); transition: background .15s, color .15s; }
.tool-text { display: flex; flex-direction: column; min-width: 0; }
.tool-text strong { font-size: 15px; }
.tool-text span { font-size: 13px; color: var(--muted); }
.tool-card[aria-current="page"] { border-color: var(--accent); background: var(--accent-soft); }
.tool-card[aria-current="page"] .tool-icon { background: var(--accent); color: var(--on-accent); }

/* ================================================================ layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start;
  padding-top: 20px; padding-bottom: 32px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.workspace { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* ================================================================ buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s; }
.btn:hover { background: var(--surface-2); }
.btn .icon { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; flex: none;
  border: none; background: transparent; color: var(--muted); cursor: pointer; text-decoration: none;
  transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--bad-soft); color: var(--bad); }
.link-btn { display: inline-flex; align-items: center; gap: 5px; border: none; background: none; padding: 4px 6px;
  border-radius: 6px; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.link-btn:hover { color: var(--accent-text); }
.link-btn .icon { width: 15px; height: 15px; }
.mobile-only { display: none !important; }
.howto .link-btn { padding: 4px 0; margin-top: 4px; color: var(--accent-text); }

/* ================================================================ drop zone */
.drop { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px;
  padding: 40px 24px; border: 2px dashed var(--line-strong); border-radius: var(--radius-lg);
  background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s, padding .2s; }
.drop:hover { border-color: var(--accent); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); }
.drop-icon .icon { width: 28px; height: 28px; }
.drop.over .drop-icon { background: var(--accent); color: var(--on-accent); }
.drop-text strong { display: block; font-size: 18px; font-weight: 650; }
.drop-text p { color: var(--muted); font-size: 14px; margin-top: 2px; }
.drop-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
/* after files are added the drop zone becomes a slim "add more" bar */
.drop.compact { flex-direction: row; text-align: left; padding: 12px 14px; gap: 12px; border-width: 1.5px; }
.drop.compact .drop-icon { width: 40px; height: 40px; }
.drop.compact .drop-icon .icon { width: 20px; height: 20px; }
.drop.compact .drop-text { flex: 1; min-width: 0; }
.drop.compact .drop-text strong { font-size: 15px; }
.drop.compact .drop-text p { font-size: 13px; }
.drop.compact .btn { height: 36px; padding: 0 12px; }

/* ================================================================ banners, how-to */
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius); font-size: 14px; }
.banner .icon { width: 18px; height: 18px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.error { background: var(--bad-soft); color: var(--bad); }
.banner.info { background: var(--accent-soft); color: var(--accent-text); }
.banner.info span { flex: 1; }

.howto { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.howto li { display: flex; gap: 12px; padding: 14px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); }
.step { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent-text); font-size: 13px; font-weight: 700; }
.howto strong { font-size: 14px; }
.howto p { color: var(--muted); font-size: 13px; }

/* ================================================================ summary */
.summary { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.summary-main { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.summary-text { flex: 1; min-width: 200px; }
.summary .big { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.summary .big.good { color: var(--good); }
.summary-text .muted { font-size: 14px; }
.summary-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; width: 0; border-radius: 99px; background: var(--accent); transition: width .3s ease; }

/* ================================================================ result rows */
.list { display: flex; flex-direction: column; gap: 8px; }
.row { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto auto; align-items: center; gap: 14px;
  padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  transition: border-color .15s; animation: row-in .2s ease-out; }
.row:hover { border-color: var(--line-strong); }
.row[data-status="error"] { border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
@keyframes row-in { from { opacity: 0; transform: translateY(4px); } }
.thumb, .filetile { width: 56px; height: 56px; border-radius: 10px; }
.thumb { display: block; object-fit: cover; background-color: var(--surface-2);
  outline: 1px solid var(--line); outline-offset: -1px;   /* keeps white images visible */
  background-image: linear-gradient(45deg, var(--line) 25%, transparent 25%, transparent 75%, var(--line) 75%),
    linear-gradient(45deg, var(--line) 25%, transparent 25%, transparent 75%, var(--line) 75%);
  background-size: 12px 12px; background-position: 0 0, 6px 6px; }
.filetile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: var(--good-soft); color: var(--good); font-size: 10px; font-weight: 800; letter-spacing: .04em; }
.filetile .icon { width: 20px; height: 20px; }
.row-info { min-width: 0; }
.row-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 13px; color: var(--muted); margin-top: 2px; }
.row-meta .fmt { font-size: 11px; font-weight: 700; letter-spacing: .03em; padding: 1px 6px; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--line); }
.row-meta .note.error { color: var(--bad); }
.row-actions { display: flex; gap: 2px; }

.badge { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 99px;
  font-size: 13px; font-weight: 700; white-space: nowrap; }
.badge .icon { width: 15px; height: 15px; }
.badge.ok { background: var(--good-soft); color: var(--good); }
.badge.neutral, .badge.kept { background: var(--surface-2); color: var(--muted); }
.badge.queued { background: var(--surface-2); color: var(--faint); font-weight: 600; }
.badge.working { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.badge.error { background: var(--bad-soft); color: var(--bad); }
.spinner { width: 13px; height: 13px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================ settings */
.settings { padding: 18px; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; overscroll-behavior: contain; }
.tool-form { display: flex; flex-direction: column; gap: 18px; }
.form-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.form-head h2 { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; }
.form-head h2 .icon { color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > label, .field > legend, .label, .label-row label { font-size: 14px; font-weight: 600; padding: 0; }
.field > legend { margin-bottom: 8px; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.label-row output { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent-text);
  background: var(--accent-soft); padding: 1px 8px; border-radius: 6px; font-size: 13px; }
.optional { font-weight: 500; color: var(--faint); font-size: 12px; margin-left: 4px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.45; }
.hint:empty { display: none; }
.dim { opacity: .45; }

input[type=text], input[type=number], select {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px; transition: border-color .15s; }
input[type=text]:hover, input[type=number]:hover, select:hover { border-color: var(--faint); }
input[type=text]:focus, input[type=number]:focus, select:focus { border-color: var(--accent); box-shadow: var(--ring); outline: none; }
input::placeholder { color: var(--faint); }
input[type=range] { width: 100%; margin: 4px 0; accent-color: var(--accent); cursor: pointer; }
input[type=color] { width: 40px; height: 32px; padding: 2px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--surface); cursor: pointer; flex: none; }
.input-unit { position: relative; display: flex; align-items: center; }
.input-unit input { padding-right: 48px; }
.input-unit span { position: absolute; right: 12px; color: var(--faint); font-size: 13px; font-weight: 600; pointer-events: none; }
.size-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 6px; }
.size-row .input-unit input { padding-right: 32px; }

/* chips (quick presets) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 30px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s; }
.chip:hover { border-color: var(--accent); color: var(--accent-text); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }

/* segmented control (radio buttons) */
.seg { display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 4px; padding: 4px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; }
.seg label { position: relative; cursor: pointer; }
.seg input, .toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.seg span { display: flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 6px;
  border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); transition: all .15s; text-align: center; }
.seg label:hover span { color: var(--text); }
.seg input:checked + span { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.seg input:focus-visible + span { box-shadow: var(--ring); }
.seg-tall span { flex-direction: column; height: auto; padding: 8px 4px; gap: 4px; line-height: 1.2; }
.seg-tall .icon { width: 22px; height: 22px; }

/* switches */
.toggles { display: flex; flex-direction: column; gap: 14px; }
.toggle { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; position: relative; }
.switch { width: 38px; height: 22px; border-radius: 99px; background: var(--line-strong); position: relative; flex: none;
  margin-top: 1px; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / .25); transition: transform .15s; }
.toggle input:checked + .switch { background: var(--accent); }
.toggle input:checked + .switch::after { transform: translateX(16px); }
.toggle input:focus-visible + .switch { box-shadow: var(--ring); }
.toggle-text { font-size: 14px; font-weight: 600; display: flex; flex-direction: column; }
.toggle-text small { font-size: 13px; font-weight: 400; color: var(--muted); line-height: 1.45; }

/* "More options" */
.more { border-top: 1px solid var(--line); padding-top: 14px; }
.more summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); list-style: none;
  display: flex; align-items: center; gap: 6px; }
.more summary::-webkit-details-marker { display: none; }
.more summary::before { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s; margin-right: 2px; }
.more[open] summary::before { transform: rotate(45deg); }
.more summary:hover { color: var(--text); }
.more > :not(summary) { margin-top: 18px; }

/* ================================================================ dialogs */
.dialog { border: none; border-radius: var(--radius-lg); padding: 0; background: var(--surface); color: var(--text);
  max-width: min(96vw, 1400px); box-shadow: 0 20px 60px rgb(0 0 0 / .35); }
.dialog::backdrop { background: rgb(12 15 24 / .6); backdrop-filter: blur(2px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 12px 12px 18px;
  border-bottom: 1px solid var(--line); }
.dlg-title { display: flex; flex-direction: column; min-width: 0; }
.dlg-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.dlg-title .muted { font-size: 13px; }
.dlg-actions { display: flex; align-items: center; gap: 6px; }
.cmp-wrap { position: relative; line-height: 0; user-select: none; background: var(--surface-2); }
.cmp-wrap img { display: block; max-width: min(96vw, 1400px); max-height: 72vh; }
#cmpB { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#cmpLine { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; box-shadow: 0 0 6px rgb(0 0 0 / .5); pointer-events: none; }
.cmp-handle { position: absolute; top: 50%; left: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px; border-radius: 50%;
  background: #fff; color: #1c2130; display: grid; place-items: center; box-shadow: 0 2px 8px rgb(0 0 0 / .35); }
.cmp-handle .icon { width: 18px; height: 18px; }
.cmp-tag { position: absolute; top: 12px; padding: 3px 10px; border-radius: 99px; background: rgb(0 0 0 / .55); color: #fff;
  font-size: 12px; font-weight: 600; line-height: 1.6; pointer-events: none; }
.cmp-tag.left { left: 12px; }
.cmp-tag.right { right: 12px; }
#cmpSlider { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: ew-resize; margin: 0; }
.cmp-missing { padding: 48px; text-align: center; color: var(--muted); }
.cmp-labels { display: flex; justify-content: space-between; gap: 12px; padding: 10px 18px; font-size: 13px; font-weight: 600; }
#textPreview { margin: 0; padding: 16px 18px; max-height: 70vh; width: min(90vw, 720px); overflow: auto;
  font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; background: var(--surface-2); }

/* ================================================================ toasts, footer */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column;
  align-items: center; gap: 8px; z-index: 10; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 10px; background: var(--toast);
  color: #fff; font-size: 14px; font-weight: 500; box-shadow: 0 8px 24px rgb(0 0 0 / .25); animation: toast-in .2s ease-out; }
.toast .icon { width: 18px; height: 18px; color: #86efac; }
.toast.error .icon { color: #fca5a5; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.footer { padding-bottom: 28px; color: var(--faint); font-size: 13px; text-align: center; }

/* ================================================================ responsive */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .settings { position: static; max-height: none; overflow: visible; }
  .mobile-only { display: inline-flex !important; }
  .tools { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .topbar, .tools, .layout, .footer { padding-inline: 16px; }
  .topbar { padding-top: 16px; }
  .brand p { display: none; }
  .tools { gap: 8px; margin-top: 14px; }
  .tool-card { padding: 10px; gap: 10px; }
  .tool-icon { width: 34px; height: 34px; }
  .tool-text span { display: none; }
  .howto { grid-template-columns: 1fr; }
  .drop { padding: 28px 16px; }
  .drop.compact { flex-wrap: wrap; }
  .drop.compact .drop-actions { width: 100%; }
  .drop.compact .drop-actions .btn { flex: 1; }
  .paste-hint { display: none; }
  .row { grid-template-columns: 48px minmax(0, 1fr) auto; gap: 10px; }
  .thumb, .filetile { width: 48px; height: 48px; }
  .row-actions { grid-column: 2 / -1; justify-content: flex-end; margin-top: -6px; }
  .summary-actions { width: 100%; }
  .summary-actions .btn.primary { flex: 1; }
}
