/* ==========================================================================
   Image Converter: desktop-app styling (glass panes + macOS-style dock)
   ========================================================================== */

:root {
  --bg: #e9edf4;
  --surface: #ffffff;
  --surface-2: #f6f7fa;
  --field-bg: rgba(255, 255, 255, 0.78);
  --border: rgba(15, 23, 42, 0.09);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text: #14171c;
  --text-muted: #555d6b;
  --text-faint: #858d9b;
  --accent: #3b5bdb;
  --accent-hover: #3049b8;
  --accent-soft: rgba(59, 91, 219, 0.12);
  --accent-ring: rgba(59, 91, 219, 0.35);
  --btn-bg: #3b5bdb;          /* white text on these stays above 4.5:1 in both themes */
  --btn-bg-hover: #3049b8;
  --ok-bg: #237032;
  --success: #2b8a3e;
  --success-soft: rgba(43, 138, 62, 0.12);
  --danger: #c92a2a;
  --danger-soft: rgba(201, 42, 42, 0.1);
  --warn: #9a5700;
  --warn-soft: rgba(230, 140, 0, 0.14);
  --track: rgba(15, 23, 42, 0.1);
  --checker: rgba(15, 23, 42, 0.06);

  /* Glass */
  --glass-bg: rgba(255, 255, 255, 0.58);
  --glass-strong: rgba(250, 251, 253, 0.8);
  --glass-border: rgba(255, 255, 255, 0.7);
  --glass-sep: rgba(15, 23, 42, 0.08);
  --glass-shadow: 0 1px 1px rgba(15, 23, 42, 0.04), 0 12px 40px -14px rgba(15, 23, 42, 0.28);
  --tip-bg: rgba(28, 30, 36, 0.88);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --spring: cubic-bezier(0.2, 0.9, 0.3, 1.15);
  --dock-size: 52px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f14;
    --surface: #1b1e25;
    --surface-2: #20242c;
    --field-bg: rgba(0, 0, 0, 0.28);
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --text: #eceef2;
    --text-muted: #a6adba;
    --text-faint: #7a8291;
    --accent: #7b96ff;
    --accent-hover: #93a9ff;
    --accent-soft: rgba(123, 150, 255, 0.16);
    --accent-ring: rgba(123, 150, 255, 0.45);
    --btn-bg: #3b5bdb;
    --btn-bg-hover: #4263eb;
    --success: #69db7c;
    --success-soft: rgba(105, 219, 124, 0.14);
    --danger: #ff8787;
    --danger-soft: rgba(255, 135, 135, 0.12);
    --warn: #ffc078;
    --warn-soft: rgba(255, 192, 120, 0.14);
    --track: rgba(255, 255, 255, 0.12);
    --checker: rgba(255, 255, 255, 0.05);

    --glass-bg: rgba(30, 33, 40, 0.55);
    --glass-strong: rgba(32, 35, 43, 0.82);
    --glass-border: rgba(255, 255, 255, 0.09);
    --glass-sep: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 1px 1px rgba(0, 0, 0, 0.3), 0 16px 48px -16px rgba(0, 0, 0, 0.7);
    --tip-bg: rgba(40, 43, 51, 0.92);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

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

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Soft "desktop wallpaper" so the glass has something to blur */
.wallpaper {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(60% 50% at 12% 18%, rgba(129, 140, 248, 0.38), transparent 70%),
    radial-gradient(50% 45% at 88% 12%, rgba(244, 114, 182, 0.26), transparent 70%),
    radial-gradient(55% 50% at 72% 92%, rgba(56, 189, 248, 0.3), transparent 70%),
    radial-gradient(45% 40% at 20% 95%, rgba(52, 211, 153, 0.2), transparent 70%),
    var(--bg);
}
@media (prefers-color-scheme: dark) {
  .wallpaper {
    background:
      radial-gradient(60% 50% at 12% 18%, rgba(79, 70, 229, 0.32), transparent 70%),
      radial-gradient(50% 45% at 88% 12%, rgba(190, 24, 93, 0.18), transparent 70%),
      radial-gradient(55% 50% at 72% 92%, rgba(14, 116, 144, 0.28), transparent 70%),
      radial-gradient(45% 40% at 20% 95%, rgba(5, 150, 105, 0.14), transparent 70%),
      var(--bg);
  }
}

/* ---------- Glass material ---------- */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(24px) saturate(170%);
  backdrop-filter: blur(24px) saturate(170%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: var(--glass-strong); }
}

/* ---------- App frame ---------- */
.app {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: 14px 16px 0;
}

.titlebar {
  flex: none;
  display: flex; align-items: center; gap: 16px;
  min-width: 0;
  padding: 9px 16px;
  border-radius: 14px;
}

.brand { display: flex; align-items: center; gap: 9px; flex: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border-radius: 7px;
  color: #fff;
  background: linear-gradient(160deg, #5b7cfa, #3b5bdb);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), var(--shadow-sm);
}
h1 { font-size: 0.98rem; font-weight: 650; letter-spacing: -0.01em; }
.tagline {
  min-width: 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.workspace {
  display: grid;
  gap: 14px;
}

.workspace.is-empty .pane { display: none; }
.workspace:not(.is-empty) .empty-state { display: none; }

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 14px 16px 12px;
  border-radius: var(--radius-lg);
}

.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  min-width: 0;
}

.pane-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.74rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.count-pill {
  min-width: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 600 0.72rem/1.6 var(--mono);
  text-align: center;
  letter-spacing: 0;
}

/* ---------- Empty state / drop target ---------- */
.empty-state {
  /* The drop zone below is the surface itself, so this wrapper draws nothing */
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px;
  height: 100%;
  min-height: 300px;
  padding: 32px 20px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 22px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(24px) saturate(170%);
  backdrop-filter: blur(24px) saturate(170%);
  box-shadow: var(--glass-shadow);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), background-color 0.2s var(--ease);
}
.dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }

.dz-art {
  display: grid; place-items: center;
  width: 72px; height: 72px;
  margin-bottom: 8px;
  border-radius: 20px;
  color: #fff;
  background: linear-gradient(160deg, #5ab0ff, #2563eb);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 10px 24px -10px rgba(15, 23, 42, 0.45);
}
.dz-title { font-size: 1.25rem; font-weight: 650; letter-spacing: -0.01em; }
.dz-hint { color: var(--text-muted); font-size: 0.88rem; max-width: 46ch; }
.dz-button { margin-top: 14px; pointer-events: none; }

/* Window-wide drop overlay */
.drop-overlay {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center;
  background: rgba(59, 91, 219, 0.1);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s var(--ease);
}
.drop-overlay.is-active { opacity: 1; }
.drop-overlay-card {
  display: grid; justify-items: center; gap: 10px;
  padding: 30px 48px;
  border-radius: 22px;
  border: 2px dashed var(--accent) !important;
  color: var(--accent);
  font-weight: 650;
  font-size: 1.05rem;
  scale: 0.96;
  transition: scale 0.2s var(--spring);
}
.drop-overlay.is-active .drop-overlay-card { scale: 1; }

/* ---------- Gallery ---------- */
.gallery-totals { font-size: 0.8rem; color: var(--text-muted); font-variant-numeric: tabular-nums; min-height: 1.5em; }
.gallery-totals strong { color: var(--success); font-weight: 650; }

.batch-progress { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; margin-top: 8px; }
.batch-progress .progress { height: 6px; }
.batch-progress .progress > span { transition: width 0.15s linear; }
.batch-text { font-size: 0.76rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.queue {
  list-style: none;
  margin: 10px -10px 0;
  padding: 0 4px;
  overscroll-behavior: contain;
}

.queue-summary { margin-top: 8px; font-size: 0.78rem; color: var(--text-faint); }
.queue-summary:empty { display: none; }

.item {
  position: relative;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 8px 8px;
  border-radius: 12px;
  transition: background-color 0.15s var(--ease);
}
.item + .item { margin-top: 2px; }
.item:hover { background: rgba(127, 127, 127, 0.08); }
.item.is-selected { background: var(--accent-soft); }

.item-hit {
  position: absolute; inset: 0;
  border: 0; padding: 0;
  background: transparent;
  border-radius: inherit;
  cursor: pointer;
}
.item-hit:focus-visible { outline-offset: -2px; }

.item-thumb {
  position: relative;
  width: 52px; height: 52px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--border), var(--shadow-sm);
  pointer-events: none;
}
.item-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; animation: fade-in 0.3s var(--ease); }
.item[data-status="loading"] .item-thumb {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--track) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.item-main { min-width: 0; pointer-events: none; display: grid; gap: 2px; }
.item-name { font-weight: 600; font-size: 0.86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta {
  display: flex; flex-wrap: wrap; align-items: center;
  column-gap: 7px; row-gap: 1px;
  font-size: 0.74rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.meta-out { color: var(--text); }
.item[data-status="error"] .meta-out { color: var(--danger); }

.chip { padding: 0 6px; border-radius: 999px; font-size: 0.7rem; font-weight: 700; line-height: 1.6; }
.chip:empty { display: none; }
.chip.is-smaller { background: var(--success-soft); color: var(--success); }
.chip.is-larger { background: var(--warn-soft); color: var(--warn); }

.progress { height: 4px; border-radius: 999px; background: var(--track); overflow: hidden; }
.progress > span {
  display: block; height: 100%;
  width: calc(var(--p, 0) * 100%);
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.25s var(--ease), background-color 0.2s var(--ease);
}
.item-progress { margin-top: 3px; opacity: 0; transition: opacity 0.2s var(--ease); }
.item[data-status="queued"] .item-progress,
.item[data-status="processing"] .item-progress,
.item[data-status="done"] .item-progress { opacity: 1; }
.item[data-status="done"] .item-progress > span { background: var(--success); }

.item-side { position: relative; z-index: 1; display: flex; align-items: center; gap: 2px; }
.item-status {
  min-width: 40px;
  text-align: right;
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.item[data-status="processing"] .item-status { color: var(--accent); }
.item[data-status="error"] .item-status { color: var(--danger); }
.item[data-status="done"] .item-status::after {
  content: "";
  display: inline-block;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--ok-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 12px no-repeat;
  vertical-align: middle;
  animation: pop 0.35s var(--spring);
}

.icon-btn {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.icon-btn:hover { background: rgba(127, 127, 127, 0.14); color: var(--text); }
.item-download[aria-disabled="true"] { opacity: 0.3; pointer-events: none; }
.item-download[aria-disabled="false"] { color: var(--accent); }
.item-remove:hover { color: var(--danger); }

/* ---------- Stage (preview) ---------- */
.stage-title { min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.preview-name {
  min-width: 0;
  font-weight: 600;
  font-size: 0.86rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.seg {
  display: inline-flex; flex: none;
  padding: 2px;
  border-radius: 8px;
  background: var(--track);
}
.seg-btn {
  height: 26px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.76rem; font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.compare-scroll {
  position: relative;
  display: grid; place-items: center;
  min-height: 220px;
  border-radius: var(--radius);
  overflow: hidden;
  background-color: rgba(127, 127, 127, 0.06);
  background-image:
    linear-gradient(45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  /* The preview sizes itself to this box (see .compare) */
  container-type: size;
}

.compare {
  --split: 50%;
  position: relative;
  aspect-ratio: var(--ar, 4 / 3);
  /* As large as the stage allows, in either direction */
  width: min(100cqw, calc(100cqh * var(--arn, 1.333)));
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.45);
  cursor: ew-resize;                 /* press anywhere on the image to move the divider */
  touch-action: pan-y;               /* horizontal finger moves drag; vertical ones still scroll the page */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: opacity 0.2s var(--ease);
}
.compare.is-updating { opacity: 0.7; }

/* 100% view: one image pixel per device pixel, scroll to pan.
   Here only the handle drags, so the image area stays free for panning. */
.compare-scroll.is-actual { display: block; place-items: start; overflow: auto; }
.compare-scroll.is-actual .compare { width: var(--pw); max-width: none; border-radius: 0; cursor: default; touch-action: auto; }
.compare-scroll.is-actual .compare.is-reposition { cursor: grab; touch-action: none; }

.cmp-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;           /* never start a native image drag */
  user-select: none;
}
/* Composition guides: semi-transparent white lines with a dark halo, so they stay
   visible over both bright and dark areas. The SVG is stretched to the output frame;
   non-scaling strokes keep the lines the same thickness at any size. */
.cmp-guides {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  overflow: visible;
  pointer-events: none;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.75)) drop-shadow(0 0 2.5px rgba(0, 0, 0, 0.35));
}
.cmp-guides path {
  fill: none;
  stroke: rgba(255, 255, 255, 0.85);
  stroke-width: 1.25;
  vector-effect: non-scaling-stroke;
}
.cmp-guides path.faint { stroke: rgba(255, 255, 255, 0.45); stroke-width: 1; }

/* Reposition mode (Crop / Cover): drag the image inside the fixed output frame.
   While dragging, the whole source image is shown with object-fit: cover, and
   object-position follows the pointer, which matches the crop exactly. */
.cmp-live { inset: auto; max-width: none; }      /* left/top/width/height are set by app.js, in % of the frame */
.cmp-live.is-animating { transition: left 0.75s var(--ease), top 0.75s var(--ease), width 0.75s var(--ease), height 0.75s var(--ease); }
.btn-auto { gap: 6px; }
.stage-pane .pane-head { flex-wrap: wrap; }
.compare.is-reposition { cursor: grab; touch-action: none; }
.compare.is-reposition.is-panning { cursor: grabbing; }
.compare.is-live .cmp-line, .compare.is-live .cmp-tag { opacity: 0; }
.cmp-line, .cmp-tag { transition: opacity 0.15s var(--ease); }
.stage-tools { display: flex; align-items: center; gap: 8px; flex: none; }
.btn-ghost[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Output on the right: clip away everything left of the divider */
.cmp-after { clip-path: inset(0 0 0 var(--split)); }

.cmp-line {
  position: absolute; top: 0; bottom: 0;
  left: var(--split);
  width: 2px; margin-left: -1px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}
.cmp-handle {
  position: absolute; top: 50%; left: 50%;
  display: grid; place-items: center;
  width: 36px; height: 36px;
  translate: -50% -50%;
  border-radius: 50%;
  background: #fff;
  color: #3a3f4a;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08), 0 3px 10px rgba(0, 0, 0, 0.3);
  cursor: ew-resize;
  pointer-events: auto;
  touch-action: none;                /* the handle always drags, even on touch screens */
  transition: scale 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.cmp-handle::before {                /* larger invisible hit area for fingers */
  content: "";
  position: absolute; inset: -10px;
  border-radius: 50%;
}
.cmp-handle:hover, .compare.is-dragging .cmp-handle { scale: 1.1; }
.compare.is-dragging .cmp-handle { box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08), 0 6px 18px rgba(0, 0, 0, 0.35); }

.cmp-tag {
  position: absolute; top: 10px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 0.7rem; font-weight: 600;
  pointer-events: none;
}
.cmp-tag.left { left: 10px; }
.cmp-tag.right { right: 10px; }

/* Keyboard-only control: focusable, but the pointer goes to the drag logic */
.cmp-range {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}
.compare:has(.cmp-range:focus-visible) .cmp-handle { box-shadow: 0 0 0 4px var(--accent-ring), 0 3px 10px rgba(0, 0, 0, 0.3); }

/* While dragging: no text selection anywhere, and the resize cursor everywhere */
body.is-comparing { user-select: none; -webkit-user-select: none; cursor: ew-resize; }
body.is-comparing * { cursor: ew-resize !important; }
body.is-panning { user-select: none; -webkit-user-select: none; }
body.is-panning * { cursor: grabbing !important; }

.preview-empty {
  display: grid; place-items: center;
  width: 100%; height: 100%;
  padding: 24px;
  color: var(--text-muted);
  font-size: 0.88rem;
  text-align: center;
}
.preview-empty.is-busy span::before {
  content: "";
  display: inline-block;
  width: 14px; height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.preview-caption {
  min-height: 1.5em;
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ==========================================================================
   Dock
   ========================================================================== */
.dock-wrap {
  position: fixed;
  left: 0; right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 55;                 /* like macOS, the dock stays above windows */
  display: flex; justify-content: center;
  pointer-events: none;
}

.dock {
  pointer-events: auto;
  display: flex; align-items: flex-end;
  gap: 6px;
  padding: 9px 12px;
  border-radius: 24px;
}

.dock-item {
  --s: 1;                                   /* magnification, set by app.js */
  position: relative;
  display: flex; align-items: flex-end; justify-content: center;
  width: calc(var(--dock-size) * var(--s));
  height: var(--dock-size);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transition: width 0.16s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.dock-item:focus-visible { outline: none; }

.dock-icon {
  position: relative;
  flex: none;
  display: grid; place-items: center;
  width: var(--dock-size); height: var(--dock-size);
  border-radius: 14px;
  color: #fff;
  transform: scale(var(--s));
  transform-origin: 50% 100%;
  transition: transform 0.16s var(--ease), filter 0.2s var(--ease), opacity 0.2s var(--ease);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 -1px 0 rgba(0, 0, 0, 0.12), 0 6px 14px -6px rgba(0, 0, 0, 0.45);
}
.dock-icon svg { filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2)); }
.dock-item:active .dock-icon { transform: scale(calc(var(--s) * 0.9)); filter: brightness(0.9); }
.dock-item:focus-visible .dock-icon { box-shadow: 0 0 0 3px var(--accent-ring), inset 0 1px 0 rgba(255, 255, 255, 0.4); }
.dock-item:disabled { cursor: default; }
.dock-item:disabled .dock-icon { filter: grayscale(0.85); opacity: 0.45; }

.di-upload   { background: linear-gradient(165deg, #6cb8ff 0%, #2f6bea 100%); }
.di-settings { background: linear-gradient(165deg, #a7afbd 0%, #5d6676 100%); }
.di-preset   { background: linear-gradient(165deg, #ffd166 0%, #f08c00 100%); }
.di-convert  { background: linear-gradient(165deg, #4fd1b5 0%, #0b8a78 100%); }
.di-download { background: linear-gradient(165deg, #b197fc 0%, #6741d9 100%); }

/* Convert: progress ring around the icon while a batch runs; the glyph becomes a stop square */
.di-stop { display: none; }
.dock-item.is-busy .di-glyph { display: none; }
.dock-item.is-busy .di-stop { display: block; }
.di-ring {
  position: absolute; inset: 0;
  padding: 3px;
  border-radius: inherit;
  background: conic-gradient(#fff calc(var(--p, 0) * 360deg), rgba(255, 255, 255, 0.22) 0);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  opacity: 0;
  transition: opacity 0.2s var(--ease);
}
.dock-item.is-busy .di-ring { opacity: 1; }

/* Count badge (Download all) */
.dock-badge {
  position: absolute; top: -5px; right: -5px;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #e03131;
  color: #fff;
  font: 700 0.72rem/20px var(--font);
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  animation: pop 0.3s var(--spring);
}

/* "Running" indicator dot under an item (settings open / preset active) */
.dock-dot {
  position: absolute; bottom: -7px; left: 50%;
  width: 4px; height: 4px;
  margin-left: -2px;
  border-radius: 50%;
  background: var(--text);
  opacity: 0;
  transition: opacity 0.2s var(--ease);
}
.dock-item[aria-expanded="true"] .dock-dot,
.dock-item[aria-pressed="true"] .dock-dot { opacity: 0.75; }

.dock-sep {
  align-self: center;
  width: 1px; height: 38px;
  margin: 0 5px;
  background: var(--glass-sep);
  box-shadow: 1px 0 0 rgba(255, 255, 255, 0.12);
}

/* Tooltips above the (magnified) icons */
.dock-tip {
  position: absolute;
  left: 50%;
  bottom: calc(var(--dock-size) * var(--s) + 12px);
  translate: -50% 4px;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--tip-bg);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 550;
  line-height: 1.3;
  white-space: nowrap;
  text-align: center;
  box-shadow: 0 6px 18px -6px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s var(--ease), translate 0.14s var(--ease), bottom 0.16s var(--ease);
}
.dock-tip small { display: block; font-size: 0.72rem; font-weight: 500; opacity: 0.75; }
.dock-tip::after {
  content: "";
  position: absolute; top: 100%; left: 50%;
  margin-left: -5px;
  border: 5px solid transparent;
  border-top-color: var(--tip-bg);
}
.dock-item:hover .dock-tip,
.dock-item:focus-visible .dock-tip { opacity: 1; translate: -50% 0; }

/* ==========================================================================
   Floating settings window
   ========================================================================== */
.float-panel {
  position: fixed;
  z-index: 50;
  /* Centred in the space above the dock until dragged (app.js then sets --x/--y) */
  left: var(--x, 50%);
  top: var(--y, calc((100dvh - 100px) / 2));
  translate: var(--tx, -50%) var(--ty, -50%);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 190px);
  display: flex; flex-direction: column;
  border-radius: 16px;
  background: var(--glass-strong);
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.12), 0 30px 80px -20px rgba(0, 0, 0, 0.45), 0 10px 24px -12px rgba(0, 0, 0, 0.25);
  opacity: 0;
  scale: 0.96;
  visibility: hidden;
  transition: opacity 0.18s var(--ease), scale 0.18s var(--ease), visibility 0s linear 0.18s;
}
.float-panel.is-open {
  opacity: 1;
  scale: 1;
  visibility: visible;
  transition: opacity 0.2s var(--ease), scale 0.28s var(--spring), visibility 0s;
}
.float-panel.is-dragging { transition: none; user-select: none; }
.float-panel:focus { outline: none; }

.panel-titlebar {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--glass-sep);
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.float-panel.is-dragging .panel-titlebar { cursor: grabbing; }
.panel-title { font-size: 0.86rem; font-weight: 650; text-align: center; }
.panel-sub { justify-self: end; font-size: 0.72rem; color: var(--text-faint); white-space: nowrap; }

.traffic { display: flex; gap: 8px; }
.tl {
  display: grid; place-items: center;
  width: 12px; height: 12px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.2);
}
.tl-close { background: #ff5f57; color: transparent; cursor: pointer; }
.tl-min { background: #febc2e; }
.tl-max { background: #28c840; }
.traffic:hover .tl-close, .tl-close:focus-visible { color: rgba(0, 0, 0, 0.6); }
.tl-close:focus-visible { outline-offset: 1px; }

.panel-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 18px 18px;
  display: grid; gap: 18px;
}

/* ---------- Form controls (inside the settings window) ---------- */
.fields { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: 18px; }
.fields:disabled { opacity: 0.55; }

.field-group { display: grid; gap: 8px; min-width: 0; }
.field-label { font-weight: 600; font-size: 0.84rem; }
.unit { color: var(--text-faint); font-weight: 500; font-size: 0.76rem; }
.label-row { display: flex; align-items: center; justify-content: space-between; }

.mode-switch { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mode-opt { position: relative; cursor: pointer; }
.mode-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.mode-card {
  display: flex; align-items: center; gap: 10px;
  height: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--field-bg);
  color: var(--text-faint);
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.mode-opt:hover .mode-card { border-color: var(--text-faint); }
.mode-opt input:checked + .mode-card { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.mode-opt input:focus-visible + .mode-card { box-shadow: 0 0 0 3px var(--accent-ring); }
.mode-icon { flex: none; }
.mode-text { display: grid; min-width: 0; }
.mode-title { font-weight: 600; font-size: 0.82rem; color: var(--text); white-space: nowrap; }
.mode-desc { font-size: 0.72rem; color: var(--text-muted); }

.inline-field { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 12px; }
.inline-label { font-size: 0.82rem; font-weight: 600; }
.inline-field select { height: 36px; font-size: 0.84rem; }

.dims { display: flex; align-items: center; gap: 8px; }
.dims-x { color: var(--text-faint); flex: none; }

.input-wrap {
  flex: 1 1 0;
  min-width: 0;
  display: flex; align-items: center;
  height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--field-bg);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.input-wrap.is-invalid { border-color: var(--danger); }
.input-prefix { padding-left: 11px; color: var(--text-faint); font-size: 0.72rem; font-weight: 650; }
.input-wrap input {
  flex: 1; min-width: 0;
  height: 100%;
  border: 0; outline: 0;
  background: transparent;
  padding: 0 10px 0 8px;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.input-wrap input::placeholder { color: var(--text-faint); }
.input-wrap input::-webkit-outer-spin-button,
.input-wrap input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.checkbox { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 0.84rem; user-select: none; }
.checkbox input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.checkbox-box {
  position: relative;
  width: 17px; height: 17px; flex: none;
  border: 1.5px solid var(--border-strong);
  border-radius: 5px;
  background: var(--field-bg);
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.checkbox-box::after {
  content: "";
  position: absolute; left: 4.5px; top: 1px;
  width: 5px; height: 10px;
  border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  transition: transform 0.15s var(--ease);
}
.checkbox input:checked + .checkbox-box { background: var(--btn-bg); border-color: var(--btn-bg); }
.checkbox input:checked + .checkbox-box::after { transform: rotate(45deg) scale(1); }
.checkbox input:focus-visible + .checkbox-box { box-shadow: 0 0 0 3px var(--accent-ring); }

.select-wrap { position: relative; }
.select-wrap::after {
  content: "";
  position: absolute; right: 13px; top: 50%;
  width: 7px; height: 7px;
  border: solid var(--text-muted); border-width: 0 1.8px 1.8px 0;
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
select {
  width: 100%; height: 38px;
  padding: 0 36px 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--field-bg);
  appearance: none; -webkit-appearance: none;
  cursor: pointer;
}
select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

.badge {
  min-width: 44px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 600 0.76rem/1.6 var(--mono);
  text-align: center;
}

input[type="range"] {
  --fill: 50%;
  width: 100%; height: 22px;
  margin: 0;
  background: transparent;
  appearance: none; -webkit-appearance: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--fill), var(--track) var(--fill));
}
input[type="range"]::-moz-range-track { height: 5px; border-radius: 999px; background: var(--track); }
input[type="range"]::-moz-range-progress { height: 5px; border-radius: 999px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  margin-top: -7.5px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.2), 0 2px 6px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s var(--ease);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.2), 0 2px 6px rgba(0, 0, 0, 0.25);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.1); }
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--accent-ring), 0 2px 6px rgba(0, 0, 0, 0.25); }
input[type="range"]:disabled { cursor: not-allowed; filter: grayscale(1); opacity: 0.5; }

.range-scale { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--text-faint); }
.field-note { font-size: 0.76rem; color: var(--text-muted); }
.field-note.warn { color: var(--danger); }
.field-note.caution { color: var(--warn); }

/* Estimate */
.estimate {
  display: grid; gap: 10px;
  padding: 13px 14px;
  border-radius: 12px;
  background: rgba(127, 127, 127, 0.08);
}
.estimate-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.estimate-state { font-size: 0.72rem; color: var(--text-faint); }
.size-bars { display: grid; gap: 7px; }
.size-bar { display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; align-items: center; gap: 10px; font-size: 0.78rem; }
.size-bar-label { color: var(--text-muted); }
.size-bar-track { height: 7px; border-radius: 999px; background: var(--track); overflow: hidden; }
.size-bar-fill { display: block; height: 100%; width: var(--w); border-radius: inherit; transition: width 0.35s var(--ease); }
.size-bar-fill.orig { background: var(--text-faint); }
.size-bar-fill.out { background: var(--success); }
.size-bar-fill.out.is-larger { background: var(--warn); }
.size-bar-value { min-width: 70px; text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.saving { font-size: 0.8rem; color: var(--text-muted); }
.saving strong { color: var(--success); }

/* ---------- Alerts, toast, buttons ---------- */
.alert { padding: 9px 12px; border-radius: 9px; font-size: 0.8rem; }
.alert-warn { background: var(--warn-soft); color: var(--warn); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 90px);
  z-index: 56;
  translate: -50% 0;
  max-width: min(560px, calc(100vw - 32px));
  padding: 9px 16px;
  border-radius: 12px;
  font-size: 0.82rem;
  font-weight: 550;
  text-align: center;
  background: var(--glass-strong);
  animation: toast-in 0.3s var(--spring);
}
.toast.is-warn { color: var(--warn); }
.toast.is-success { color: var(--success); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-weight: 600; font-size: 0.86rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease), opacity 0.15s var(--ease);
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: var(--btn-bg); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--btn-bg-hover); }
.btn-ghost { height: 28px; padding: 0 10px; background: transparent; border-color: var(--border-strong); color: var(--text-muted); font-size: 0.76rem; }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: rgba(127, 127, 127, 0.1); }

/* ---------- Animations ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes pop { 0% { transform: scale(0.4); opacity: 0; } 70% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
@keyframes toast-in { from { opacity: 0; translate: -50% 10px; } to { opacity: 1; translate: -50% 0; } }

/* ==========================================================================
   Desktop: full-height, no page scroll. Gallery | Stage, dock floating below.
   ========================================================================== */
@media (min-width: 961px) {
  html, body {
    height: 100vh;
    height: 100dvh;
    margin: 0;
    overflow: hidden;
  }
  body { min-height: 0; }

  .app { height: 100%; }

  .workspace {
    flex: 1;
    min-height: 0;
    grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    /* Leave room for the floating dock */
    padding-bottom: calc(max(14px, env(safe-area-inset-bottom)) + 88px);
  }
  .workspace.is-empty { grid-template-columns: minmax(0, 1fr); }

  /* Each pane scrolls on its own */
  .gallery-pane .queue { flex: 1; min-height: 0; overflow-y: auto; scrollbar-gutter: stable; }
  .stage-pane .compare-scroll { flex: 1; min-height: 0; }
}

/* ==========================================================================
   Tablet & phone: stacked, page scrolls, dock stays fixed at the bottom
   ========================================================================== */
@media (max-width: 960px) {
  :root { --dock-size: 46px; }
  .app { padding: 10px 10px calc(max(10px, env(safe-area-inset-bottom)) + 96px); }
  .tagline { display: none; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .empty-state { min-height: 60vh; }
  .stage-pane { order: -1; }                 /* preview first, list below */
  .stage-pane .compare-scroll { height: min(56vh, 440px); }
  .gallery-pane .queue { max-height: 60vh; overflow-y: auto; }

  .dock { gap: 4px; padding: 7px 9px; border-radius: 20px; }
  .dock-icon { border-radius: 12px; }
  .dock-icon svg { width: 22px; height: 22px; }
  .dock-sep { height: 32px; margin: 0 3px; }
  .toast { bottom: calc(max(10px, env(safe-area-inset-bottom)) + 80px); }

  /* Settings: a bottom sheet instead of a floating window */
  .float-panel {
    left: 8px; right: 8px; top: auto;
    bottom: max(8px, env(safe-area-inset-bottom));
    translate: none;
    width: auto;
    max-height: calc(100dvh - 24px);
    transform-origin: 50% 100%;
    border-radius: 20px;
    z-index: 60;
  }
  .float-panel:not(.is-open) { translate: 0 24px; }
  .panel-titlebar { cursor: default; }
}

@media (max-width: 520px) {
  .item { grid-template-columns: 46px minmax(0, 1fr) auto; gap: 9px; padding: 8px 4px; }
  .item-thumb { width: 46px; height: 46px; }
  .item-status { min-width: 0; }
  .panel-sub { display: none; }
  .panel-titlebar { grid-template-columns: auto 1fr auto; }
}

/* No hover on touch screens: no tooltips */
@media (hover: none) {
  .dock-tip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
