:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f0f1f5;
  --border: #e1e3ea;
  --text: #171a21;
  --muted: #5d6475;
  --faint: #8a90a0;
  --accent: #5b4cf0;
  --accent-soft: #ece9ff;
  --accent-text: #ffffff;
  --teal: #12a594;
  --good: #11875d;
  --bad: #c43d3d;
  --view-bg: #e6e8ee;
  --check-a: #d9dce4;
  --check-b: #eceef3;
  --shadow: 0 1px 2px rgb(16 18 27 / 6%), 0 4px 16px rgb(16 18 27 / 5%);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015;
    --surface: #161921;
    --surface-2: #1d2029;
    --border: #2a2e3a;
    --text: #e8eaf0;
    --muted: #a2a8b8;
    --faint: #727889;
    --accent: #8b7dff;
    --accent-soft: #262245;
    --accent-text: #0e1015;
    --teal: #2ccbb6;
    --good: #3ccf8e;
    --bad: #ff7a7a;
    --view-bg: #0a0b0f;
    --check-a: #1b1e26;
    --check-b: #232731;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 24px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  overflow-x: hidden;
}

a {
  color: var(--accent);
}

code,
kbd {
  font-family: var(--mono);
  font-size: 0.86em;
}

kbd {
  padding: 0 0.35em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
}

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

/* Header */
.top {
  max-width: 1360px;
  margin: 0 auto;
  padding: 22px 24px 6px;
}

.top-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}

.logo {
  width: 26px;
  height: 26px;
}

.logo .l1 { fill: var(--accent); }
.logo .l2 { fill: var(--teal); }
.logo .l3 { fill: var(--accent); opacity: 0.5; }

.name {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.badge {
  padding: 2px 9px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.gh {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}

.gh:hover {
  border-color: var(--faint);
}

.gh svg {
  width: 17px;
  height: 17px;
}

.lede {
  max-width: 82ch;
  margin: 12px 0 0;
  color: var(--muted);
}

.lede strong {
  color: var(--text);
  font-weight: 600;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  max-width: 1360px;
  margin: 0 auto;
  padding: 16px 24px 8px;
  align-items: start;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Gallery */
.gallery {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
}

.tile {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
  outline-offset: 2px;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.tile:hover {
  transform: translateY(-1px);
}

.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile .tile-name {
  position: absolute;
  inset: auto 0 0 0;
  padding: 14px 6px 5px;
  background: linear-gradient(transparent, rgb(0 0 0 / 65%));
  color: #fff;
  font-size: 11px;
  font-weight: 550;
  line-height: 1.2;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile[aria-checked="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.tile.upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 2px dashed var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.tile.upload:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tile.upload svg {
  width: 24px;
  height: 24px;
}

.tile.upload.has-image {
  border-style: solid;
  padding: 0;
}

.tile.upload.has-image img {
  position: absolute;
  inset: 0;
}

/* Viewer */
.viewer {
  padding: 10px;
}

.viewer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.spacer {
  flex: 1;
}

.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-2);
  gap: 2px;
}

.seg button {
  padding: 5px 11px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}

.seg button:hover {
  color: var(--text);
}

.seg button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgb(0 0 0 / 12%), 0 0 0 1px var(--border);
}

.seg-fill {
  display: flex;
}

.seg-fill button {
  flex: 1;
}

/* Ten formats: two rows of five. */
#format {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

#format button {
  padding-inline: 2px;
}

.seg button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.icon-btn,
.zoom-level {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  min-width: 32px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.zoom {
  display: inline-flex;
  gap: 4px;
}

.zoom-level {
  min-width: 62px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.diff-gain {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.view {
  position: relative;
  height: min(68vh, 720px);
  min-height: 300px;
  overflow: hidden;
  border-radius: 10px;
  background: var(--view-bg);
  /* One finger scrolls the page; the viewer handles pinch, two-finger pan and the split handle. */
  touch-action: pan-y;
  user-select: none;
}

.view canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

.view canvas.panning {
  cursor: grabbing;
}

.view canvas.on-handle {
  cursor: ew-resize;
}

.tag {
  position: absolute;
  top: 10px;
  padding: 3px 9px;
  border-radius: 7px;
  background: rgb(10 11 15 / 72%);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

.tag-left { left: 10px; }
.tag-right { right: 10px; }

.busy {
  position: absolute;
  left: 50%;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 14px 7px 11px;
  border-radius: 99px;
  background: rgb(10 11 15 / 78%);
  color: #fff;
  font-size: 13px;
  font-weight: 550;
  transform: translateX(-50%);
  pointer-events: none;
  backdrop-filter: blur(4px);
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgb(255 255 255 / 30%);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.placeholder.error {
  color: var(--bad);
}

.hint {
  margin: 8px 2px 0;
  color: var(--faint);
  font-size: 12.5px;
}

/* Controls */
.controls,
.stats {
  padding: 16px 18px 18px;
}

.field {
  margin-bottom: 16px;
}

.field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
}

.field-label output {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.note {
  margin: 5px 0 0;
  color: var(--faint);
  font-size: 12.5px;
  line-height: 1.45;
}

.note code {
  color: var(--muted);
}

.field.disabled {
  opacity: 0.5;
}

input[type="range"] {
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  accent-color: var(--accent);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(to right, var(--accent) var(--fill, 0%), var(--surface-2) var(--fill, 0%));
  box-shadow: inset 0 0 0 1px var(--border);
}

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 99px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
}

input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: 99px;
  background: var(--accent);
}

input[type="range"]::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgb(0 0 0 / 25%);
  -webkit-appearance: none;
  appearance: none;
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgb(0 0 0 / 25%);
}

input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

select {
  padding: 6px 28px 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238a90a0' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center / 10px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.field.two {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.field.two .field-label {
  margin: 0;
}

.checks {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin: -2px 0 14px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.advanced {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.advanced summary {
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.advanced[open] summary {
  margin-bottom: 12px;
}

.link-btn {
  padding: 2px 4px;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* Results */
.pill {
  padding: 2px 9px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.pill.busy-pill {
  background: var(--accent-soft);
  color: var(--accent);
}

.pill.error {
  color: var(--bad);
}

.hero {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.hero-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.hero-num {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.hero-unit {
  color: var(--muted);
  font-size: 14px;
}

.hero-sub {
  margin: 2px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.stats.stale .hero-num,
.stats.stale dd {
  opacity: 0.55;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  margin: 0;
  padding: 12px 0 2px;
  border-top: 1px solid var(--border);
}

.grid dt {
  color: var(--faint);
  font-size: 12px;
  font-weight: 550;
}

.grid dd {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 6px;
  margin: 0;
  font-family: var(--mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.delta {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }
.delta.same { color: var(--faint); }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}

.btn svg {
  width: 18px;
  height: 18px;
}

.btn[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

.cmd {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
}

.cmd code {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* Footer */
.foot {
  max-width: 1360px;
  margin: 0 auto;
  padding: 8px 24px 32px;
  color: var(--faint);
  font-size: 13px;
}

.foot a {
  color: var(--muted);
}

/* Drag and drop */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgb(14 16 21 / 55%);
  backdrop-filter: blur(3px);
  pointer-events: none;
}

.drop-overlay div {
  padding: 28px 40px;
  border: 2px dashed #fff;
  border-radius: 18px;
  color: #fff;
  font-size: 20px;
  font-weight: 650;
  text-align: center;
}

[hidden] {
  display: none !important;
}

/* Narrow screens */
@media (max-width: 1080px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 320px;
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14.5px;
  }

  .top,
  .layout,
  .foot {
    padding-left: 16px;
    padding-right: 16px;
  }

  .gallery {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .panel {
    grid-template-columns: minmax(0, 1fr);
  }

  .view {
    /* Samples are square: no taller than the width needs, or the letterbox outgrows the image. */
    height: min(62vh, 100vw);
    min-height: 260px;
  }

  .viewer {
    padding: 8px;
  }

  .seg button {
    padding: 5px 9px;
  }

  .hint {
    display: none;
  }

  .hero-num {
    font-size: 32px;
  }
}

.cmd .arg {
  white-space: nowrap;
}
