:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #141824;
  --muted: #5d6576;
  --line: #e2e5ec;
  --accent: #4a3aff;
  --accent-ink: #ffffff;
  --accent-soft: #eceaff;
  --ok: #0f8f6a;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --err: #b42318;
  --err-soft: #fdecea;
  --check-a: #ffffff;
  --check-b: #e6e8ee;
  --shadow: 0 1px 2px rgba(20, 24, 36, .06), 0 8px 24px rgba(20, 24, 36, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1016;
    --surface: #161922;
    --surface-2: #1c202b;
    --ink: #eceef4;
    --muted: #9aa2b4;
    --line: #2a2f3c;
    --accent: #7d70ff;
    --accent-ink: #0e1016;
    --accent-soft: #24214a;
    --ok: #37c99a;
    --warn: #f0b44c;
    --warn-soft: #2e2512;
    --err: #ff8a80;
    --err-soft: #331816;
    --check-a: #2a2e39;
    --check-b: #1f222b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- barre du haut */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 24px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 17px; letter-spacing: -.01em; }
.brand-text small { color: var(--muted); font-size: 12px; }
.badge {
  font-size: 12px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); padding: 3px 9px; border-radius: 99px;
}
.topnav { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.topnav a { text-decoration: none; font-weight: 600; font-size: 14px; }
.lang {
  border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 8px; padding: 4px 10px; font-size: 13px; font-weight: 600; cursor: pointer;
}

/* --- mise en page */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px;
  max-width: 1400px; margin: 0 auto; padding: 20px 24px;
  align-items: start;
}
.stage { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; position: sticky; top: 76px;
  max-height: calc(100vh - 92px); overflow: auto;
}

/* --- zone de dépôt */
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--surface);
  min-height: 420px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 32px 20px; cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { width: 56px; height: 56px; color: var(--accent); margin-bottom: 8px; }
.drop-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.drop-hint { color: var(--muted); margin: 0 0 12px; }
.drop-formats { font-size: 12px; color: var(--muted); margin: 0; letter-spacing: .04em; }

/* --- visionneuse */
.viewer {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px;
}
.viewer-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.viewer-actions { display: flex; gap: 8px; }
.canvas-wrap { position: relative; display: flex; justify-content: center; }
.compare {
  --ratio: 1.5;
  position: relative; aspect-ratio: var(--ratio);
  width: min(100%, calc(66vh * var(--ratio)));
  border-radius: 10px; overflow: hidden; background: var(--surface-2);
  user-select: none; touch-action: pan-y;
}
.layer { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.after-wrap { position: absolute; inset: 0; }
.checker {
  background-color: var(--check-a);
  background-image: conic-gradient(var(--check-b) 25%, transparent 0 50%, var(--check-b) 0 75%, transparent 0);
  background-size: 20px 20px;
}
.after-wrap.dark-bg { background: #15171c; }
.after-wrap.light-bg { background: #ffffff; }
.handle {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px;
  background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); pointer-events: none;
}
.handle span {
  position: absolute; top: 50%; left: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.handle span::before, .handle span::after {
  content: ""; position: absolute; top: 50%; width: 0; height: 0; margin-top: -5px;
  border: 5px solid transparent;
}
.handle span::before { left: 5px; border-right-color: #4a4f5c; }
.handle span::after { right: 5px; border-left-color: #4a4f5c; }
#split {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize;
  -webkit-appearance: none; appearance: none;
}
.tag {
  position: absolute; top: 10px; font-size: 12px; font-weight: 600; color: #fff;
  background: rgba(15, 17, 23, .62); padding: 3px 8px; border-radius: 6px; pointer-events: none;
}
.tag-before { left: 10px; }
.tag-after { right: 10px; }
.compare.mode-after .layer.before, .compare.mode-after .handle, .compare.mode-after #split,
.compare.mode-after .tag, .compare.mode-before .after-wrap, .compare.mode-before .handle,
.compare.mode-before #split, .compare.mode-before .tag, .compare.single .handle,
.compare.single #split, .compare.single .tag, .compare.single .after-wrap { display: none; }
.compare.mode-after .after-wrap { clip-path: none !important; }
.file-line { font-size: 13px; color: var(--muted); margin-top: 8px; text-align: center; }

.busy {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; background: rgba(14, 16, 22, .62); color: #fff; border-radius: 10px; text-align: center; padding: 16px;
}
.busy p { margin: 0; font-weight: 600; }
.busy .busy-hint { font-weight: 400; font-size: 13px; opacity: .85; max-width: 420px; }
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.25); border-top-color: #fff; animation: spin .9s linear infinite;
  margin-bottom: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* --- résultat */
.result {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px;
}
.result-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.result h2 { font-size: 17px; margin: 0; }
.meta { color: var(--muted); margin: 2px 0 0; font-size: 14px; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.steps { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.steps li {
  font-size: 13px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 10px;
}
.steps li b { font-variant-numeric: tabular-nums; }
.notes { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.note { font-size: 13px; background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 6px 10px; }
.analysis { margin-top: 12px; }
.analysis summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font-size: 12.5px; border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; background: var(--surface-2); }
.chip b { font-variant-numeric: tabular-nums; }

.alert {
  background: var(--err-soft); color: var(--err); border-radius: 10px; padding: 10px 14px; font-weight: 500;
}

/* --- panneau de réglages */
fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend { font-weight: 700; margin-bottom: 10px; padding: 0; }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preset {
  display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 10px;
  transition: border-color .15s, background .15s;
}
.preset strong { display: block; font-size: 14px; line-height: 1.2; }
.preset small { display: block; color: var(--muted); font-size: 12px; line-height: 1.25; margin-top: 2px; }
.preset:hover { border-color: var(--accent); }
.preset.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.p-ico { flex: none; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); position: relative; }
.p-ico::after { content: ""; position: absolute; inset: 7px; border-radius: 3px; background: var(--accent-ink); }
.p-cut::after { border-radius: 50% 50% 4px 4px; }
.p-fix::after { border-radius: 50%; inset: 8px; box-shadow: 0 0 0 3px rgba(255,255,255,.35); }
.p-up::after { inset: 6px 12px 12px 6px; box-shadow: 6px 6px 0 0 rgba(255,255,255,.55); }
.p-all::after { clip-path: polygon(50% 0, 100% 100%, 0 100%); border-radius: 0; }

.block { border-top: 1px solid var(--line); padding: 14px 0 4px; }
.block.flat { padding-bottom: 14px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch-row strong { display: block; font-size: 15px; }
.switch-row small { display: block; color: var(--muted); font-size: 12.5px; line-height: 1.3; }
.block-body { padding-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.block.off .block-body { display: none; }

.switch {
  -webkit-appearance: none; appearance: none; flex: none; width: 42px; height: 24px; border-radius: 99px;
  background: var(--line); position: relative; cursor: pointer; transition: background .15s; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
select {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 9px; padding: 8px 10px; width: 100%;
}
.hint { color: var(--muted); font-size: 12.5px; margin: 0; line-height: 1.4; }
.hint.center { text-align: center; margin-top: 8px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer;
  font-size: 13.5px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg.small { display: flex; }
.seg.small button { flex: 1; padding: 6px 8px; }
.seg.wrap { flex-wrap: wrap; }

.sub { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
input[type="color"] { width: 44px; height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--surface-2); cursor: pointer; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line); cursor: pointer; padding: 0; }

.sliders { display: flex; flex-direction: column; gap: 10px; }
.slider { display: grid; grid-template-columns: 1fr 34px; grid-template-rows: auto auto; column-gap: 8px; font-size: 13px; width: 100%; }
.slider span { grid-column: 1 / -1; color: var(--muted); font-weight: 600; }
.slider input { width: 100%; accent-color: var(--accent); }
.slider output { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.file-pick {
  display: flex; align-items: center; gap: 8px; width: 100%; border: 1px dashed var(--line); border-radius: 9px;
  padding: 9px 12px; cursor: pointer; color: var(--muted); font-size: 13.5px;
}
.file-pick input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-pick:hover { border-color: var(--accent); color: var(--ink); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 10px;
  padding: 9px 16px; font-weight: 700; text-decoration: none; cursor: pointer; border: 1px solid transparent;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { width: 100%; padding: 13px; font-size: 16px; margin-top: 4px; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.ghost {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 9px; padding: 7px 12px;
  font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.ghost:hover { border-color: var(--accent); }
.ghost.light { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.35); color: #fff; margin-top: 6px; }

.foot { max-width: 1400px; margin: 8px auto 32px; padding: 0 24px; font-size: 13px; color: var(--ink); }
.foot p { margin: 4px 0; }
.muted { color: var(--muted); }

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .panel { position: static; max-height: none; }
  .topbar { padding: 10px 16px; }
  .badge { display: none; }
  .drop { min-height: 260px; }
  .foot { padding: 0 16px; }
  .compare { width: min(100%, calc(56vh * var(--ratio))); }
}
@media (max-width: 420px) {
  .preset-grid { grid-template-columns: 1fr; }
  .brand-text small { display: none; }
}
.hint.warn { color: var(--warn); }
