:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #eef0f4;
  --text-dim: #9aa1af;
  --accent: #6d5bff;
  --accent-hover: #8171ff;
  --danger: #ff6b6b;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Heebo", Arial, sans-serif;
}

.wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 48px 20px 32px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  text-align: center;
  margin-bottom: 36px;
}

h1 {
  font-size: 2rem;
  margin: 0 0 10px;
  background: linear-gradient(90deg, #a78bfa, #6d5bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  color: var(--text-dim);
  margin: 0;
  font-size: 0.98rem;
}

main {
  flex: 1;
}

.method-select {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.method-btn {
  flex: 1;
  appearance: none;
  cursor: pointer;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.method-btn:hover {
  border-color: var(--accent);
}

.method-btn.active {
  border-color: var(--accent);
  background: var(--surface-2);
  color: var(--text);
}

.method-hint {
  font-size: 0.76rem;
  font-weight: 400;
  color: var(--text-dim);
}

.tolerance-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  margin-bottom: 18px;
  font-size: 0.88rem;
  color: var(--text-dim);
}

.tolerance-row label {
  white-space: nowrap;
}

.tolerance-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

#toleranceValue {
  min-width: 2ch;
  text-align: center;
  color: var(--text);
  font-weight: 600;
}

.tolerance-row.hidden {
  display: none !important;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 56px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--surface-2);
}

.upload-icon {
  width: 40px;
  height: 40px;
  color: var(--accent);
  margin-bottom: 12px;
}

.dz-title {
  font-size: 1.1rem;
  margin: 0 0 4px;
  font-weight: 600;
}

.dz-sub {
  color: var(--text-dim);
  margin: 0;
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}

.status {
  text-align: center;
  padding: 48px 24px;
}

.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 18px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

#statusText {
  color: var(--text-dim);
  margin: 0 0 16px;
}

.progress-bar {
  width: 100%;
  max-width: 320px;
  height: 6px;
  margin: 0 auto;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

.images {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.image-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  position: relative;
}

.image-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-align: center;
}

.image-card img {
  width: 100%;
  height: auto;
  border-radius: 10px;
  display: block;
}

.checkerboard img {
  background-image:
    linear-gradient(45deg, #2a2f3a 25%, transparent 25%),
    linear-gradient(-45deg, #2a2f3a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2f3a 75%),
    linear-gradient(-45deg, transparent 75%, #2a2f3a 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  background-color: var(--surface-2);
}

.actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
}

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

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.error {
  text-align: center;
  padding: 32px 24px;
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.3);
  border-radius: var(--radius);
}

#errorText {
  color: var(--danger);
  margin: 0 0 16px;
}

footer {
  text-align: center;
  margin-top: 40px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

@media (max-width: 560px) {
  .images {
    grid-template-columns: 1fr;
  }
  h1 {
    font-size: 1.6rem;
  }
  .dropzone {
    padding: 40px 16px;
  }
}
