* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #222;
  background: #f4f5f7;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background: #fff;
  border-bottom: 1px solid #e1e4e8;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.upload-row, .selection-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.upload-btn {
  background: #0969da;
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.upload-btn:hover { background: #0858bd; }

.filename {
  font-size: 13px;
  color: #555;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selection-row span {
  font-size: 13px;
  color: #555;
}

button {
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid #d0d7de;
  background: #fff;
  cursor: pointer;
  font-weight: 500;
}
button:hover:not(:disabled) { background: #f6f8fa; }
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#compare-btn {
  background: #1f883d;
  color: #fff;
  border-color: #1f883d;
}
#compare-btn:hover:not(:disabled) { background: #1a7533; }

main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.thumbs {
  width: 220px;
  background: #fff;
  border-right: 1px solid #e1e4e8;
  overflow-y: auto;
  padding: 12px;
}

.thumb {
  position: relative;
  margin-bottom: 12px;
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  background: #fff;
  padding: 4px;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.thumb canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid #d0d7de;
  border-radius: 3px;
}
.thumb .page-num {
  font-size: 11px;
  color: #666;
  text-align: center;
  margin-top: 4px;
}
.thumb:hover { border-color: #b4c7e7; }
.thumb.previewing { border-color: #57606a; background: #f6f8fa; }
.thumb.selected-a { border-color: #0969da; box-shadow: 0 0 0 2px rgba(9,105,218,0.2); }
.thumb.selected-b { border-color: #bf3989; box-shadow: 0 0 0 2px rgba(191,57,137,0.2); }
.thumb .badge {
  position: absolute;
  top: 2px;
  left: 2px;
  background: #0969da;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  z-index: 2;
}
.thumb.selected-b .badge { background: #bf3989; }

.thumb-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 2;
}
.thumb:hover .thumb-actions,
.thumb:focus-within .thumb-actions {
  opacity: 1;
}
.thumb-btn {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 4px;
  border: 1px solid #d0d7de;
  background: rgba(255,255,255,0.95);
  color: #333;
  cursor: pointer;
  line-height: 1.2;
}
.thumb-btn:hover { background: #fff; }
.thumb-btn.set-a.active {
  background: #0969da;
  border-color: #0969da;
  color: #fff;
}
.thumb-btn.set-b.active {
  background: #bf3989;
  border-color: #bf3989;
  color: #fff;
}
.thumb-btn.set-a.active,
.thumb-btn.set-b.active {
  opacity: 1;
}
.thumb .thumb-btn.active ~ .thumb-btn,
.thumb.selected-a .thumb-actions,
.thumb.selected-b .thumb-actions {
  opacity: 1;
}

.preview-wrap {
  background: #fff;
  border: 1px solid #e1e4e8;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.preview-title {
  font-size: 13px;
  color: #555;
  font-weight: 500;
}
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}
.zoom-btn {
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 4px;
  border: 1px solid #d0d7de;
  background: #fff;
  color: #333;
  cursor: pointer;
  line-height: 1.2;
  min-width: 28px;
}
.zoom-btn:hover { background: #f6f8fa; }
.zoom-level {
  font-size: 12px;
  color: #555;
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: center;
}
.preview-scroll {
  overflow: auto;
  border: 1px solid #d0d7de;
  border-radius: 4px;
  background: #fafbfc;
  max-height: calc(100vh - 200px);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 8px;
}
.preview-canvas {
  display: block;
  background: #fff;
  box-shadow: 0 0 0 1px #e1e4e8;
}

.viewer {
  flex: 1;
  overflow: auto;
  padding: 20px;
}

.placeholder {
  color: #888;
  font-size: 14px;
  padding: 20px;
  text-align: center;
}

.verdict {
  background: #fff;
  border: 1px solid #e1e4e8;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.verdict .status {
  font-size: 15px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
}
.verdict .status.similar { background: #dafbe1; color: #1a7f37; }
.verdict .status.different { background: #ffebe9; color: #cf222e; }
.verdict .metric {
  font-size: 13px;
  color: #555;
}
.verdict .metric strong { color: #111; font-variant-numeric: tabular-nums; }

.legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: #555;
  margin-left: auto;
}
.legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
  border: 1px solid rgba(0,0,0,0.1);
}
.legend .dot.both { background: #000; }
.legend .dot.only-a { background: #ff0000; }
.legend .dot.only-b { background: #0000ff; }

.overlay-wrap {
  background: #fff;
  border: 1px solid #e1e4e8;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.overlay-scroll {
  overflow: auto;
  border: 1px solid #d0d7de;
  border-radius: 4px;
  background: #fafbfc;
  max-height: calc(100vh - 260px);
  padding: 8px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.overlay-img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  box-shadow: 0 0 0 1px #e1e4e8;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  flex-shrink: 0;
}

.loading {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 100;
}
.loading.hidden { display: none; }
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #d0d7de;
  border-top-color: #0969da;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
