:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --raised: #ffffff;
  --inset: #e8edf3;
  --border: #dbe2ea;
  --text: #0f172a;
  --muted: #475569;
  --accent: #4338ca;
  --accent-contrast: #ffffff;
  --flag: #be123c;
  --flag-soft: #fff1f2;
  --code: #f8fafc;
  --radius: 12px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #020617;
    --card: #0f172a;
    --raised: #334155;
    --inset: #0b1222;
    --border: #1e293b;
    --text: #f8fafc;
    --muted: #cbd5e1;
    --accent: #a5b4fc;
    --accent-contrast: #0f172a;
    --flag: #fda4af;
    --flag-soft: #2a0f1a;
    --code: #0b1222;
  }
}

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

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

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

h1,
h2,
p,
ul,
dl,
dd,
pre,
fieldset {
  margin: 0;
  padding: 0;
}

fieldset {
  border: 0;
  min-width: 0;
}

ul {
  list-style: none;
}

a {
  color: var(--accent);
  text-underline-offset: 3px;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.wrap {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* Masthead */

.masthead {
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.masthead-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.masthead nav {
  display: flex;
  gap: 18px;
  font-size: 14px;
  font-weight: 500;
}

.masthead nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 0;
}

/* Intro */

.intro {
  padding: 28px 0 20px;
  max-width: 760px;
}

h1 {
  font-size: clamp(24px, 3.2vw, 32px);
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-weight: 750;
  text-wrap: balance;
}

.intro p {
  margin-top: 10px;
  color: var(--muted);
  font-size: 16px;
}

h2 {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.005em;
}

.hint {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

/* Controls */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px 22px;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control > label,
.control > legend {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.control > legend {
  margin-bottom: 6px;
}

.control output {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}

.stepper {
  display: inline-flex;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  overflow: hidden;
}

.stepper:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.stepper button {
  width: 34px;
  border: 0;
  background: var(--inset);
  color: var(--text);
  font: inherit;
  font-size: 17px;
  cursor: pointer;
  transition: background-color 160ms ease;
}

.stepper input {
  width: 84px;
  border: 0;
  border-inline: 1px solid var(--border);
  background: transparent;
  color: inherit;
  font-family: var(--mono);
  font-size: 14px;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}

.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

.stepper button:focus-visible,
.stepper input:focus-visible {
  outline: none;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.segmented {
  display: inline-flex;
  height: 36px;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--inset);
}

.segmented label {
  position: relative;
  display: flex;
}

.segmented input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  display: flex;
  align-items: center;
  padding: 0 12px;
  min-width: 34px;
  justify-content: center;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  transition:
    background-color 160ms ease,
    color 160ms ease;
}

.segmented input:checked + span {
  background: var(--raised);
  color: var(--text);
  box-shadow:
    0 0 0 1px var(--border),
    0 1px 2px rgb(15 23 42 / 0.08);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.control-range {
  min-width: 150px;
}

.control-range input {
  height: 36px;
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
}

.control-range input:disabled {
  opacity: 0.45;
}

.button {
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition:
    transform 140ms var(--ease-out),
    background-color 160ms ease;
}

.button:active {
  transform: scale(0.97);
}

.button-quiet {
  height: 30px;
  padding: 0 10px;
  border-color: var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 13px;
}

.controls .button {
  margin-left: auto;
}

/* Status */

.status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  min-height: 24px;
  margin: 14px 2px 12px;
  font-size: 14px;
  color: var(--muted);
}

.engine {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  white-space: nowrap;
}

.engine::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
}

.engine[data-state="loading"]::before {
  background: #f59e0b;
  animation: pulse 1s ease-in-out infinite;
}

.engine[data-state="ready"]::before {
  background: #10b981;
}

.engine[data-state="failed"]::before {
  background: #e11d48;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

/* Workspace */

.workspace {
  display: grid;
  gap: 16px;
  align-items: start;
}

@media (min-width: 980px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 340px;
  }
}

.viewer {
  min-width: 0;
}

.viewer-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tabs button {
  flex: none;
  margin-bottom: -1px;
  padding: 9px 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  transition: color 160ms ease;
}

.tabs button[aria-selected="true"] {
  border-bottom-color: var(--accent);
  color: var(--text);
}

.tabs button:focus-visible {
  outline-offset: -2px;
}

.tabs .count {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--flag);
  color: var(--card);
  font-size: 11px;
  font-weight: 700;
}

.tabs .absent {
  margin-left: 6px;
  color: var(--flag);
  font-size: 12px;
  font-weight: 600;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding-bottom: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

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

.sheet {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--inset);
}

.page {
  position: relative;
  max-width: 920px;
  margin: 0 auto;
  border-radius: 3px;
  background: #ffffff;
  box-shadow:
    0 1px 2px rgb(15 23 42 / 0.1),
    0 10px 30px rgb(15 23 42 / 0.1);
  transition: opacity 150ms ease;
}

.is-stale .page {
  opacity: 0.5;
}

.page img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 3px;
}

.overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Drawn over a white page in either theme, so these colours are fixed. */
.field {
  fill: transparent;
  stroke: #4f46e5;
  stroke-opacity: 0.55;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition:
    fill 120ms ease,
    opacity 120ms ease;
}

.field.flagged {
  fill: rgb(225 29 72 / 0.12);
  stroke: #e11d48;
  stroke-opacity: 1;
  stroke-width: 2;
}

.field.pinned {
  fill: rgb(79 70 229 / 0.22);
  stroke-opacity: 1;
  stroke-width: 2.5;
}

.field.flagged.pinned {
  fill: rgb(225 29 72 / 0.26);
}

.boxes-off .field:not(.flagged, .pinned) {
  opacity: 0;
  pointer-events: none;
}

.tip {
  position: absolute;
  z-index: 2;
  width: max-content;
  max-width: min(320px, 92%);
  padding: 8px 10px;
  border-radius: 8px;
  background: #0f172a;
  color: #f8fafc;
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 6px 20px rgb(15 23 42 / 0.28);
  pointer-events: none;
}

.tip .name {
  display: block;
  font-family: var(--mono);
  font-size: 11.5px;
  color: #a5b4fc;
}

.tip .value {
  display: block;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.tip .truth {
  display: block;
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid rgb(248 250 252 / 0.18);
  color: #fda4af;
}

.missing {
  max-width: 460px;
  margin: 0 auto;
  padding: 56px 16px;
  text-align: center;
  color: var(--muted);
}

.missing strong {
  display: block;
  margin-bottom: 4px;
  color: var(--flag);
  font-size: 16px;
}

/* Fields table */

.fields {
  margin-top: 12px;
  padding: 0;
}

summary {
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.table-scroll {
  max-height: 340px;
  overflow: auto;
  border-top: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--card);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

tbody th {
  width: 42%;
  font-weight: 400;
}

tbody tr:last-child > * {
  border-bottom: 0;
}

td {
  overflow-wrap: anywhere;
}

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  text-underline-offset: 3px;
  cursor: pointer;
}

.fields .link {
  font-family: var(--mono);
  font-size: 12px;
}

.planted {
  margin-left: 8px;
  color: var(--flag);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Side panel */

.panel {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.discrepancies {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.discrepancy {
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--flag) 30%, var(--border));
  border-radius: 10px;
  background: var(--flag-soft);
  font-size: 14px;
}

.kind {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
}

.badge {
  color: var(--flag);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.scope {
  color: var(--muted);
  font-size: 12px;
}

.note {
  margin-top: 4px;
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.pair dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.pair dd {
  font-family: var(--mono);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.discrepancy .link {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
}

.empty {
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chips:empty {
  display: none;
}

.chips li {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--inset);
  font-family: var(--mono);
  font-size: 12px;
}

pre {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
}

.command {
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--code);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.truth {
  padding: 0;
}

.truth .hint {
  padding: 0 16px 10px;
}

.truth pre {
  max-height: 360px;
  margin: 0;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  overflow: auto;
}

/* Footer */

.footer {
  padding-block: 28px 36px;
  color: var(--muted);
  font-size: 13px;
}

.footer code {
  font-family: var(--mono);
}

/* Pointer-only affordances */

@media (hover: hover) and (pointer: fine) {
  .masthead nav a:hover,
  .tabs button:hover {
    color: var(--text);
  }

  .stepper button:hover {
    background: color-mix(in srgb, var(--accent) 14%, var(--inset));
  }

  .button:hover {
    background: color-mix(in srgb, var(--accent) 86%, var(--text));
  }

  .button-quiet:hover {
    background: var(--inset);
  }

  .field:hover {
    fill: rgb(79 70 229 / 0.16);
    stroke-opacity: 1;
  }

  .field.flagged:hover {
    fill: rgb(225 29 72 / 0.22);
  }
}

@media (prefers-reduced-motion: reduce) {
  .button:active {
    transform: none;
  }

  .engine[data-state="loading"]::before {
    animation: none;
  }
}

@media (max-width: 560px) {
  .sheet {
    padding: 8px;
  }

  .viewer-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    border-bottom: 0;
  }

  .tabs {
    border-bottom: 1px solid var(--border);
  }

  .toggle {
    align-self: flex-end;
    padding: 10px 2px 0;
  }

  .controls .button {
    margin-left: 0;
  }

  .masthead nav {
    gap: 14px;
  }
}
