:root {
  --red: #e31e24;
  --dark: #1a1a1a;
  --bg: #f5f5f7;
  --card: #ffffff;
  --muted: #6b7280;
  --border: #e5e7eb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--dark);
  padding-bottom: 40px;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  background: var(--red);
  color: white;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 { font-size: 18px; margin: 0; }

main { max-width: 560px; margin: 0 auto; padding: 16px; }

.hidden { display: none !important; }

.capture-card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.preview-wrap { margin-bottom: 12px; }
.preview-wrap img { width: 100%; border-radius: 12px; display: block; max-height: 360px; object-fit: cover; }

.capture-buttons { display: flex; gap: 10px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  padding: 14px 10px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.btn.primary { background: var(--red); color: white; }
.btn.secondary { background: #eee; color: var(--dark); }
.btn.ghost { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn.wide { width: 100%; margin-top: 10px; }

.ghost-btn {
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn.small { padding: 6px 10px; font-size: 12px; background: #eee; color: var(--dark); border: none; }

.status-box {
  margin-top: 16px;
  padding: 14px;
  border-radius: 12px;
  background: #fff7e6;
  border: 1px solid #fde3a7;
  font-size: 14px;
}
.status-box.error { background: #fdecea; border-color: #f5b5b0; color: #9a1c1c; }

.result-card {
  margin-top: 16px;
  background: var(--card);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.result-card h2 { margin: 0 0 4px; font-size: 20px; }
.result-card .meta { color: var(--muted); font-size: 14px; margin-bottom: 12px; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  margin-right: 6px;
}
.badge.common { background: #e5e7eb; color: #374151; }
.badge.rare { background: #fde68a; color: #92400e; }
.badge.epic { background: #ddd6fe; color: #5b21b6; }

.field-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.field-row:last-child { border-bottom: none; }
.field-row span:first-child { color: var(--muted); }

.price-box {
  margin-top: 14px;
  padding: 14px;
  border-radius: 12px;
  background: #eefdf3;
  border: 1px solid #b7ebc6;
}
.price-box h3 { margin: 0 0 6px; font-size: 15px; color: #166534; }
.price-box .amount { font-size: 22px; font-weight: 700; color: #166534; }
.price-box .sources { margin-top: 8px; font-size: 12px; }
.price-box .sources a { color: #166534; display: block; margin-bottom: 2px; }
.price-box.note-only { background: #f3f4f6; border-color: var(--border); }
.price-box.note-only h3 { color: var(--muted); }

.save-row { margin-top: 16px; display: flex; gap: 10px; }

.collection-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}
.collection-actions { display: flex; gap: 8px; align-items: center; }
#searchInput {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 13px;
}

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

.collection-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.car-tile {
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  position: relative;
}
.car-tile img { width: 100%; height: 120px; object-fit: cover; display: block; }
.car-tile .tile-body { padding: 8px 10px; }
.car-tile .tile-name { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.car-tile .tile-meta { font-size: 11px; color: var(--muted); }
.car-tile .delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.55);
  color: white;
  border: none;
  border-radius: 999px;
  width: 24px;
  height: 24px;
  font-size: 13px;
  cursor: pointer;
}
