/* ─── Reset & Base ─────────────────────────────────────────────────────── */

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

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1e1e1e;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --text-muted: #888;
  --text-dim: #555;
  --accent: #c4ff4d;
  --accent-dim: #8fb836;
  --danger: #ff4d4d;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

/* ─── Header ──────────────────────────────────────────────────────────── */

header {
  text-align: center;
  padding: 24px 0 20px;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--accent);
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 4px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ─── Drop Zone ───────────────────────────────────────────────────────── */

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--surface);
  position: relative;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(196, 255, 77, 0.03);
}

.drop-zone:active {
  transform: scale(0.98);
}

.camera-icon {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.drop-zone p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.drop-zone .hint {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 6px;
}

/* ─── Preview Row ─────────────────────────────────────────────────────── */

.preview-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  padding: 4px 0;
  scrollbar-width: none;
}

.preview-row::-webkit-scrollbar { display: none; }

.preview-thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--border);
  position: relative;
}

.preview-item {
  position: relative;
  flex-shrink: 0;
}

.preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  padding: 0;
}

/* ─── Buttons ─────────────────────────────────────────────────────────── */

.action-bar {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font);
}

.btn-primary {
  background: var(--accent);
  color: #0a0a0a;
  flex: 1;
}

.btn-primary:hover { background: #d4ff77; }
.btn-primary:active { transform: scale(0.97); }

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

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover { color: var(--danger); }

.btn-full {
  width: 100%;
  margin-top: 24px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Loading ─────────────────────────────────────────────────────────── */

.loader {
  text-align: center;
  padding: 64px 0;
}

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

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

.loader p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ─── Results ─────────────────────────────────────────────────────────── */

.results-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.results-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.badge {
  background: var(--accent);
  color: #0a0a0a;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
}

.timing {
  color: var(--text-dim);
  font-size: 0.75rem;
  font-family: var(--mono);
  margin-left: auto;
}

.results-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ─── Result Card ─────────────────────────────────────────────────────── */

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
}

.result-card:hover {
  border-color: var(--accent-dim);
}

.card-top {
  display: flex;
  gap: 12px;
  padding: 12px;
}

.card-image {
  width: 100px;
  height: 100px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background: var(--surface-2);
}

.card-info {
  flex: 1;
  min-width: 0;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-brand {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
}

.card-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.01);
}

.card-price {
  font-weight: 700;
  font-size: 0.95rem;
}

.card-score {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
}

.score-bar {
  width: 40px;
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-left: 6px;
}

.score-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

/* ─── Modal ───────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  overflow-y: auto;
  padding: 20px;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-close {
  position: sticky;
  top: 0;
  float: right;
  background: var(--surface-2);
  border: none;
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  z-index: 1;
}

/* Modal gallery */
.modal-gallery {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 16px;
  padding: 4px 0;
  scrollbar-width: none;
}

.modal-gallery::-webkit-scrollbar { display: none; }

.modal-gallery img {
  height: 200px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
}

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

.modal-brand {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 16px;
}

/* Modal detail grid */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 16px;
}

.detail-cell {
  background: var(--surface);
  padding: 10px 12px;
}

.detail-cell.full {
  grid-column: 1 / -1;
}

.detail-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.detail-value {
  font-size: 0.85rem;
  font-weight: 500;
}

/* ─── Toast ───────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  left: 16px;
  right: 16px;
  max-width: 480px;
  margin: 0 auto;
  background: var(--danger);
  color: white;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  text-align: center;
  z-index: 200;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Utilities ───────────────────────────────────────────────────────── */

.hidden { display: none !important; }

/* ─── Desktop ─────────────────────────────────────────────────────────── */

@media (min-width: 600px) {
  #app {
    max-width: 560px;
    padding: 24px;
  }

  .drop-zone {
    padding: 64px 32px;
  }

  .card-image {
    width: 120px;
    height: 120px;
  }

  .modal-content {
    border-radius: var(--radius);
    max-height: 80dvh;
    margin-bottom: 24px;
  }

  .modal {
    align-items: center;
  }
}
