/* Image tools (compress, resize, crop, remove background). Shared tokens only. */
.img-layout { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr); }
.img-layout > * { min-width: 0; }
@media (min-width: 900px) { .img-layout.split { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); align-items: start; } }
.img-sum { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; font-variant-numeric: tabular-nums; }
.img-sum .big { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; color: var(--accent-strong); }
.img-sum .old { color: var(--muted); }
.img-note { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); font-size: 0.9rem; color: var(--fg); }
.img-note svg { width: 18px; height: 18px; flex: none; color: var(--accent-strong); margin-top: 2px; }
.img-range { display: flex; align-items: center; gap: 10px; }
.img-range input[type="range"] { width: 150px; accent-color: var(--accent); }
.img-range output { min-width: 2.5ch; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--fg); }
.file-row.is-sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.file-row.pick { cursor: pointer; }
.file-row .st .tag { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: 0.78rem; }
.file-row .st .gain { font-weight: 700; }
.img-sub { font-size: 0.86rem; color: var(--muted); }

/* Before / after comparison */
.cmp-wrap { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.cmp-wrap > * { min-width: 0; }
.cmp-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-size: 0.9rem; color: var(--muted); }
.cmp-head strong { color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; max-width: 100%; }
.cmp {
  position: relative; display: grid; place-items: center; overflow: hidden; border-radius: 14px; min-height: 220px;
  background: var(--surface-2); touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: ew-resize;
}
.cmp img { display: block; max-width: 100%; max-height: min(64vh, 620px); width: auto; height: auto; pointer-events: none; -webkit-user-drag: none; }
.cmp-in { position: relative; line-height: 0; }
.cmp .cmp-a { position: absolute; inset: 0; }
.cmp .cmp-a img { width: 100%; height: 100%; max-height: none; object-fit: contain; }
.cmp .cmp-line { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--paper); box-shadow: 0 0 0 1px rgba(0,0,0,.25); pointer-events: none; }
.cmp .cmp-knob {
  position: absolute; top: 50%; width: 38px; height: 38px; margin: -19px 0 0 -19px; border-radius: 50%; display: grid; place-items: center;
  background: var(--paper); color: #27261f; box-shadow: 0 2px 8px rgba(0,0,0,.3); pointer-events: none;
}
.cmp .cmp-knob svg { width: 20px; height: 20px; }
.cmp .cmp-lab { position: absolute; top: 10px; padding: 2px 10px; border-radius: 99px; background: rgba(20,19,14,.66); color: #fff; font-size: 0.78rem; font-weight: 700; pointer-events: none; }
.cmp .cmp-lab.l { left: 10px; } .cmp .cmp-lab.r { right: 10px; }
.cmp.zoom { display: block; overflow: auto; max-width: 100%; max-height: min(64vh, 620px); cursor: default; touch-action: auto; }
.cmp.zoom .cmp-in { width: max-content; }
.cmp.zoom img { max-width: none; max-height: none; }
.cmp-range { width: 100%; accent-color: var(--accent); }

/* Transparency preview */
.checker {
  background-color: var(--paper);
  background-image: conic-gradient(#d9d6cf 25%, transparent 0 50%, #d9d6cf 0 75%, transparent 0);
  background-size: 22px 22px;
}

/* Crop */
.crop-stage { position: relative; display: grid; place-items: center; padding: 14px; background: var(--surface-2); min-height: 260px; }
.crop-box-wrap { position: relative; line-height: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
.crop-box-wrap canvas { display: block; max-width: 100%; }
.crop-sel { position: absolute; outline: 1.5px solid #fff; cursor: move; touch-action: none; z-index: 1; }
.crop-clip { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.crop-shade { position: absolute; box-shadow: 0 0 0 9999px rgba(18, 17, 12, 0.58); }
.crop-sel:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 0; border-radius: 0; }
.crop-sel .grid { position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(to right, transparent calc(33.33% - .5px), rgba(255,255,255,.55) calc(33.33% - .5px) calc(33.33% + .5px), transparent calc(33.33% + .5px) calc(66.66% - .5px), rgba(255,255,255,.55) calc(66.66% - .5px) calc(66.66% + .5px), transparent calc(66.66% + .5px)),
    linear-gradient(to bottom, transparent calc(33.33% - .5px), rgba(255,255,255,.55) calc(33.33% - .5px) calc(33.33% + .5px), transparent calc(33.33% + .5px) calc(66.66% - .5px), rgba(255,255,255,.55) calc(66.66% - .5px) calc(66.66% + .5px), transparent calc(66.66% + .5px));
}
.crop-h { position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px; display: grid; place-items: center; touch-action: none; z-index: 2; }
.crop-h::after { content: ""; width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.crop-h.nw { left: 0; top: 0; } .crop-h.n { left: 50%; top: 0; } .crop-h.ne { left: 100%; top: 0; }
.crop-h.e { left: 100%; top: 50%; } .crop-h.se { left: 100%; top: 100%; } .crop-h.s { left: 50%; top: 100%; }
.crop-h.sw { left: 0; top: 100%; } .crop-h.w { left: 0; top: 50%; }
.crop-h.e, .crop-h.w { cursor: ew-resize; } .crop-h.n, .crop-h.s { cursor: ns-resize; }
.crop-h.nw, .crop-h.se { cursor: nwse-resize; } .crop-h.ne, .crop-h.sw { cursor: nesw-resize; }
.crop-h.e::after, .crop-h.w::after { width: 8px; height: 22px; border-radius: 4px; }
.crop-h.n::after, .crop-h.s::after { width: 22px; height: 8px; border-radius: 4px; }
.crop-size { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); padding: 2px 10px; border-radius: 99px; background: rgba(20,19,14,.72); color: #fff; font-size: 0.8rem; font-weight: 700; white-space: nowrap; pointer-events: none; font-variant-numeric: tabular-nums; line-height: 1.6; }
.crop-tools { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; padding: 12px 14px; border-top: 1px solid var(--line); }
.crop-tools .grp { display: flex; gap: 6px; align-items: center; }
.seg.wrap { flex-wrap: wrap; border-radius: 14px; }
.num-in { width: 92px; }
.dim-x { color: var(--muted); padding-bottom: 10px; }

/* Remove background */
.bg-view { position: relative; display: grid; place-items: center; border-radius: 14px; overflow: hidden; min-height: 240px; }
.bg-view img, .bg-view canvas { display: block; max-width: 100%; max-height: min(64vh, 620px); width: auto; height: auto; }
.bg-wait { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 12px; padding: 20px; text-align: center; background: color-mix(in srgb, var(--surface) 82%, transparent); color: var(--fg); }
.bg-wait .progress { width: min(320px, 80%); }
.bg-wait p { max-width: 36ch; font-size: 0.95rem; }
.bg-wait .sub { color: var(--muted); font-size: 0.85rem; }
.swatches { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.sw-btn { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1.5px var(--line); cursor: pointer; padding: 0; display: grid; place-items: center; color: var(--muted); }
.sw-btn[aria-pressed="true"] { box-shadow: 0 0 0 2.5px var(--accent); }
.sw-btn.checker { background-size: 10px 10px; }
.sw-btn input[type="color"] { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.sw-btn.custom { position: relative; background: conic-gradient(#e44, #ec4, #4c4, #4ce, #44e, #e4e, #e44); }

@media (max-width: 720px) {
  .img-range input[type="range"] { width: 120px; }
  .crop-stage { padding: 8px; }
  .panel-bar .field { min-width: 0; }
}

/* Image editor: picture large on the left, grouped controls on the right (below on phones) */
.ed-bar { gap: 8px 10px; }
.ed-file { display: grid; min-width: 0; flex: 1 1 200px; line-height: 1.3; }
.ed-file strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-hist { display: flex; align-items: center; gap: 2px; }
.ed-hist .icon-btn:disabled, .ed-hist .btn:disabled { opacity: .4; cursor: default; background: transparent; }
.ed-grid { display: grid; grid-template-columns: minmax(0, 1fr); }
.ed-grid > * { min-width: 0; }
.ed-stage { position: relative; display: grid; place-items: center; padding: 14px; background: var(--surface-2); min-height: 260px; }
.ed-img { display: block; box-shadow: 0 1px 6px rgba(0,0,0,.18); }
.ed-side { display: flex; flex-direction: column; border-top: 1px solid var(--line); min-width: 0; }
.ed-foot { position: sticky; bottom: 0; z-index: 3; display: grid; gap: 10px; padding: 12px 16px 14px; margin-top: auto; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -6px 16px -12px rgba(0,0,0,.35); }
.ed-sec { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 16px; border-bottom: 1px solid var(--line); }
.ed-sec:last-of-type { border-bottom: 0; }
.ed-sec h2 { font-family: var(--font-display); font-size: 1rem; font-weight: 700; margin: 0; }
.ed-turns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.ed-turns .btn { min-width: 0; padding: 0 10px; }
.ed-turns .btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-sec > * { min-width: 0; }
.ed-turns .btn, .ed-row .btn { justify-content: flex-start; gap: 8px; }
.ed-turns .btn svg, .ed-row .btn svg { width: 17px; height: 17px; flex: none; }
.ed-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.ed-crop { display: grid; gap: 12px; padding: 12px; border-radius: 14px; background: var(--accent-soft); }
.ed-crop .seg { background: var(--surface); }
.ed-crop .seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.ed-crop .seg button { min-height: 34px; padding: 0 11px; }
.ed-dims { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; gap: 8px; }
.ed-dims .input { width: 100%; min-width: 0; }
.ed-dims .dim-x { padding-bottom: 10px; text-align: center; }
.ed-lock { margin-bottom: 3px; }
.ed-lock[aria-pressed="true"] { color: var(--accent-strong); background: var(--accent-soft); }
.ed-pct .ed-unit { display: flex; align-items: center; gap: 6px; }
.ed-pct .input { width: 66px; padding: 0 8px; }
.ed-scale { flex-wrap: nowrap; align-items: end; }
.ed-scale .seg button { padding: 0 8px; }
.ed-pct .ed-unit span { color: var(--muted); }
.ed-fmt { justify-self: start; }
.ed-est { display: grid; gap: 2px; min-height: 50px; font-variant-numeric: tabular-nums; }
.ed-est-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
.ed-est .big { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; color: var(--accent-strong); min-height: 1.7rem; display: inline-flex; align-items: center; }
.ed-est .spinner { width: 18px; height: 18px; }
.ed-note { margin: 0; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); font-size: 0.88rem; line-height: 1.45; }
.ed-dl { width: 100%; justify-content: center; }
.ed-link { display: flex; align-items: center; gap: 10px; padding: 14px 16px; color: var(--muted); font-size: 0.9rem; text-decoration: none; }
.ed-link svg { width: 18px; height: 18px; flex: none; color: var(--accent-strong); }
.ed-link:hover span, .ed-link:focus-visible span { color: var(--fg); text-decoration: underline; }
.ed-stage .crop-box-wrap canvas { max-width: none; }
@media (min-width: 900px) {
  .ed-grid { grid-template-columns: minmax(0, 1fr) 340px; }
  .ed-stage { height: min(76vh, 700px); min-height: 440px; padding: 20px; }
  .ed-side { border-top: 0; border-left: 1px solid var(--line); max-height: min(76vh, 700px); min-height: 440px; overflow: auto; }
}
@media (max-width: 720px) {
  .ed-stage { padding: 10px; min-height: 220px; }
  .ed-sec { padding: 14px 12px; }
  .ed-foot { padding: 10px 12px 12px; }
  .ed-crop .seg button { padding: 0 9px; }
}

/* Convert images */
.cv .result .big { font-size: clamp(1.25rem, 4vw, 1.6rem); line-height: 1.2; }
.cv-bg { display: flex; align-items: center; gap: 8px; }
.cv-bg input[type="color"] { width: 42px; height: 42px; padding: 3px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.file-row .st .arrow { color: var(--muted); margin: 0 4px; }
