/* SPDX-License-Identifier: MIT  Copyright (c) 2026 Mozilla Foundation */

:root {
  /* Firefox Photon-derived palette: warm off-white surface, ink
     foreground, Mozilla purple as the single accent. */
  --bg: #faf8f5;
  --bg-grad-1: #fbf3ec;
  --bg-grad-2: #f3edff;
  --surface: #ffffff;
  --surface-sunken: #f5f2ee;
  --ink: #15141a;
  --ink-2: #3a3944;
  --muted: #6e6e78;
  --border: #e7e3dd;
  --border-strong: #d2cec7;
  --accent: #9059ff;
  --accent-strong: #7c3aed;
  --accent-tint: rgba(144, 89, 255, 0.1);
  --accent-ring: rgba(144, 89, 255, 0.25);
  --warn: #ff9400;
  --error: #c8102e;
  --error-tint: rgba(200, 16, 46, 0.1);
  --ok: #058b00;
  --ok-tint: rgba(5, 139, 0, 0.1);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 30, 0.04);
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.04), 0 4px 12px rgba(20, 20, 30, 0.05);

  --mono:
    "JetBrains Mono", ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

html {
  background: var(--bg);
}
body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  margin: 0;
  padding: 4.5rem 1.5rem 3rem;
  /* Soft brand-gradient blob behind the hero. */
  background:
    radial-gradient(
      ellipse 60rem 32rem at 50% -10rem,
      var(--bg-grad-2) 0%,
      transparent 60%
    ),
    radial-gradient(
      ellipse 50rem 24rem at 90% -6rem,
      var(--bg-grad-1) 0%,
      transparent 55%
    ),
    var(--bg);
  background-repeat: no-repeat;

  &.drag-over::before {
    content: "";
    position: fixed;
    inset: 1rem;
    border: 2px dashed var(--accent);
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.6);
    pointer-events: none;
    z-index: 1000;
  }
}

/* Mozilla "moz://a" wordmark in the top-left corner. Renders with
   Zilla Slab Highlight, the slab serif Mozilla's wordmark uses. */
.moz-corner {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 100;
  font-family: "Zilla Slab Highlight", "Zilla Slab", serif;
  font-weight: 700;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--ink);
  text-decoration: none;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  transition:
    background 0.15s ease,
    transform 0.15s ease;
}
.moz-corner:hover,
.moz-corner:focus-visible {
  background: rgba(0, 0, 0, 0.06);
  outline: none;
  transform: translateY(-1px);
}

.github-corner {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  color: var(--ink-2);
  display: inline-flex;
  padding: 0.45rem;
  border-radius: 999px;
  text-decoration: none;
  transition:
    background 0.15s ease,
    color 0.15s ease,
    transform 0.15s ease;
}
.github-corner:hover,
.github-corner:focus-visible {
  background: rgba(0, 0, 0, 0.06);
  color: var(--accent);
  outline: none;
  transform: translateY(-1px);
}

/* ── hero ───────────────────────────────────────────────────────── */
.hero {
  max-width: 80rem;
  margin: 0 auto 2rem;
  padding: 0 0.25rem;
}
.hero h1 {
  font-size: clamp(1.75rem, 3.5vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 0.5rem;
}
.hero h1 .accent {
  background: linear-gradient(
    135deg,
    var(--accent) 0%,
    #ff7139 70%,
    #ffa436 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero .lede {
  margin: 0;
  max-width: 56rem;
  font-size: 1rem;
  color: var(--muted);
}
/* Privacy reassurance pill — the harness never uploads the PDF, and
   that's worth saying explicitly up-front for first-time visitors. */
.privacy-note {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.85rem 0 0;
  padding: 0.3rem 0.7rem 0.3rem 0.55rem;
  font-size: 0.82rem;
  color: var(--ok);
  background: var(--ok-tint, rgba(5, 139, 0, 0.1));
  border: 1px solid rgba(5, 139, 0, 0.25);
  border-radius: 999px;
}
.privacy-note svg {
  flex-shrink: 0;
}

/* ── controls ───────────────────────────────────────────────────── */
.controls {
  max-width: 80rem;
  margin: 0 auto;
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.controls .card-drop,
.controls .card-wide {
  grid-column: 1 / -1;
}
@media (max-width: 56rem) {
  .controls {
    grid-template-columns: minmax(0, 1fr);
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem 1.25rem;
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.85rem;
}

/* file drop zone — visually obvious target since drag-and-drop is
   the harness's primary entry point */
.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 1.5rem 1rem;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-sunken);
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  transition:
    border-color 0.15s ease,
    background 0.15s ease,
    color 0.15s ease;
}
.dropzone:hover,
.dropzone:focus-within {
  border-color: var(--accent);
  background: var(--accent-tint);
  color: var(--ink);
}
.dropzone-icon {
  font-size: 1.5rem;
  line-height: 1;
  color: var(--accent);
}
.dropzone-text {
  font-size: 0.95rem;
}
.dropzone-text strong {
  color: var(--accent-strong);
  font-weight: 600;
}
.dropzone-hint {
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--mono);
}
/* hide the native file input but keep it interactive over the zone */
.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: inherit;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.85rem 1rem;
  align-items: end;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}
.field-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.field-hint {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
}
/* Keep the page-count hint inline with its input so the Page and DPI
   fields have the same height and their inputs stay aligned. */
.field-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}
.field-input-row > input {
  flex: 1;
  min-width: 0;
}

input[type="number"],
select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.65rem;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}
input[type="number"]:hover,
select:hover {
  border-color: var(--ink-2);
}
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 0.95rem) 50%,
    calc(100% - 0.55rem) 50%;
  background-size:
    5px 5px,
    5px 5px;
  background-repeat: no-repeat;
  padding-right: 1.6rem;
}

/* toggle (custom checkbox) — used for antialias / transparent */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  user-select: none;
}
.toggle input[type="checkbox"] {
  appearance: none;
  width: 1.05rem;
  height: 1.05rem;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
}
.toggle input[type="checkbox"]:hover {
  border-color: var(--ink-2);
}
.toggle input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 0;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.toggle input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* renderer chips — pill checkboxes with per-engine accent dot */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem 0.35rem 0.6rem;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 999px;
  font-size: 0.85rem;
  font-family: var(--mono);
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
  transition:
    border-color 0.15s ease,
    background 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease;
}
.chip:hover {
  border-color: var(--ink-2);
}
.chip input[type="checkbox"] {
  appearance: none;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--border-strong);
  margin: 0;
  cursor: pointer;
  transition: background 0.15s ease;
}
.chip:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-tint);
  color: var(--ink);
}
.chip:has(input:checked) input[type="checkbox"] {
  background: var(--engine, var(--accent));
  box-shadow: 0 0 0 2px var(--accent-tint);
}
.chip:has(input:focus-visible) {
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.chip[data-engine="cairo"] {
  --engine: #ff7139;
}
.chip[data-engine="splash"] {
  --engine: #ffa436;
}
.chip[data-engine="pdfium"] {
  --engine: #4285f4;
}
.chip[data-engine="mupdf"] {
  --engine: #d9434c;
}
.chip[data-engine="pdfjs"] {
  --engine: #9059ff;
}
.chip[data-engine="pdfbox"] {
  --engine: #00b287;
}
.chip[data-engine="gs"] {
  --engine: #6a737d;
}
.chip[data-engine="xpdf"] {
  --engine: #b16cea;
}

/* ── status pill ────────────────────────────────────────────────── */
.status-wrap {
  max-width: 80rem;
  margin: 1.25rem auto 0;
}
#status {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.9rem 0.35rem 0.7rem;
  min-height: 1.6rem;
  box-shadow: var(--shadow-sm);

  &::before {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-tint);
    flex-shrink: 0;
    animation: status-pulse 1.6s ease-in-out infinite;
  }
  &.err {
    color: var(--error);
    background: var(--error-tint);
    border-color: rgba(200, 16, 46, 0.3);
  }
  &.err::before {
    background: var(--error);
    box-shadow: 0 0 0 3px var(--error-tint);
    animation: none;
  }
}
@keyframes status-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

/* ── renders grid ───────────────────────────────────────────────── */
#renders {
  max-width: 80rem;
  margin: 1.5rem auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: flex-start;

  & > .render {
    flex: 0 1 auto;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease;

    &:hover {
      box-shadow: var(--shadow);
    }

    & > h3 {
      margin: 0;
      font-size: 0.78rem;
      font-family: var(--mono);
      font-weight: 500;
      color: var(--ink-2);
      letter-spacing: 0.01em;
    }
  }
}

.canvas-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: repeating-conic-gradient(#eeeae5 0% 25%, #fff 0% 50%) 50% / 16px
    16px;
  width: fit-content;
  max-width: 100%;
  overflow: auto;

  & > canvas {
    display: block;
  }
}

/* skeleton/failed render slots ─ shown per renderer during render */
.render-row {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
#renders > .render.skeleton .canvas-wrap,
#renders > .render.failed .canvas-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-sunken);
  border-style: dashed;
  border-color: var(--border-strong);
  min-width: 11rem;
  min-height: 7.5rem;
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  overflow: hidden;
}
#renders > .render.skeleton {
  animation: skeleton-pulse 1.6s ease-in-out infinite;
}
/* A card being re-rendered keeps its previous canvas visible but dimmed and
   pulsing, so the layout height — and the scroll position — stays put while
   the new render is in flight. */
#renders > .render.refreshing .canvas-wrap {
  opacity: 0.5;
  animation: skeleton-pulse 1.6s ease-in-out infinite;
}
#renders > .render.failed .canvas-wrap {
  color: var(--error);
  background: var(--error-tint);
  border-color: rgba(200, 16, 46, 0.35);
}
.spinner {
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes skeleton-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.65;
  }
}

/* ── diffs ──────────────────────────────────────────────────────── */
#diffs {
  max-width: 80rem;
  margin: 1.5rem auto 0;

  & .pair {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);

    & > h2 {
      margin: 0 0 0.85rem;
      font-size: 0.9rem;
      font-family: var(--mono);
      font-weight: 600;
      color: var(--ink);
    }

    & .pair-row {
      display: flex;
      flex-wrap: wrap;
      gap: 1rem;
      align-items: flex-start;

      & > .diff {
        flex: 0 1 auto;
        max-width: 100%;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.35rem;
        font-family: var(--mono);
        font-size: 0.78rem;
        color: var(--muted);
        padding: 0.75rem;
        background: var(--surface-sunken);
        border-radius: var(--radius-sm);

        & > h3 {
          margin: 0;
          font-size: 0.78rem;
          font-weight: 600;
          color: var(--ink);
          /* Stretch across the card so the help icon sits at the far edge,
             opposite the metric name. */
          align-self: stretch;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 0.5rem;
        }
      }
    }
  }
}

.diff-info,
.diff-note {
  font-family: var(--mono);
  font-size: 0.78rem;
}

.diff-info {
  color: var(--muted);
}

.diff-note {
  color: var(--error);
}

.diff-image {
  display: block;
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* Diff card title + "?" help icon (built by diffCardHeading). */
.diff-title {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}
.diff-help {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  user-select: none;
  transition:
    color 0.15s ease,
    border-color 0.15s ease,
    background 0.15s ease;
}
.diff-help:hover,
.diff-help:focus-visible {
  color: var(--accent-strong);
  border-color: var(--accent);
  background: var(--accent-tint);
  outline: none;
}
/* Hover/focus tooltip. Anchored to the icon's right edge so it grows leftward
   and never spills past the page edge; sits below the icon to avoid clipping. */
.diff-tip {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  width: max-content;
  max-width: 17rem;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #fff;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.4;
  text-align: left;
  white-space: normal;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.15s ease,
    visibility 0.15s ease;
}
.diff-help:hover .diff-tip,
.diff-help:focus .diff-tip {
  opacity: 1;
  visibility: visible;
}

/* Pair card header — title on the left, live "computing diffs…" badge on
   the right while in progress, replaced by a "N diffs in 234 ms" summary
   when done. Sized so a small change is still obvious to a casual viewer. */
#diffs .pair > .pair-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 0.85rem;
}
#diffs .pair > .pair-head > h2 {
  margin: 0;
}
.pair-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent-strong);
  background: var(--accent-tint);
  border: 1px solid rgba(144, 89, 255, 0.25);
  border-radius: 999px;
  padding: 0.3rem 0.75rem 0.3rem 0.55rem;
}
.pair-badge.done {
  color: var(--ok);
  background: var(--ok-tint);
  border-color: rgba(5, 139, 0, 0.25);
  transition:
    color 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease;
}

.diff-progress {
  position: relative;
  height: 6px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin: 0 0 1rem;
}
.diff-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(
    90deg,
    var(--accent) 0%,
    #ff7139 70%,
    #ffa436 100%
  );
  border-radius: inherit;
  transition: width 0.2s ease;
}
.diff-progress.done {
  opacity: 0;
  transition: opacity 0.4s ease 0.25s;
}

#diffs .pair-row > .diff.loading,
#diffs .pair-row > .diff.failed {
  min-width: 9rem;
}
#diffs .pair-row > .diff.loading {
  animation: skeleton-pulse 1.6s ease-in-out infinite;
}
/* Diffs being recomputed (whole pair while waiting for renderers, or an
   individual card while its comparator reruns) keep their stale result
   visible but dimmed/pulsing, so the area's height — and the scroll
   position — stays stable. */
#diffs .pair.refreshing .pair-row,
#diffs .pair-row > .diff.refreshing {
  opacity: 0.5;
  animation: skeleton-pulse 1.6s ease-in-out infinite;
}
.diff-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 9rem;
  min-height: 4.5rem;
  padding: 0.75rem;
  border: 1px dashed var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-family: var(--mono);
  text-align: center;
}
#diffs .pair-row > .diff.failed .diff-placeholder {
  color: var(--error);
  background: var(--error-tint);
  border-color: rgba(200, 16, 46, 0.35);
}

.ssim-readout {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 600;
  font-family: var(--mono);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  min-width: 9rem;
}
