/* =========================================================
   What's That Part? — design system
   Clean & modern, high-contrast, auto dark mode.
   ========================================================= */

:root {
  /* Brand */
  --brand: #2563eb;
  --brand-strong: #1d4ed8;
  --brand-tint: #eff4ff;

  /* Surfaces & text (light) */
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --text: #0f172a;
  --text-muted: #5b6677;
  --border: #e6eaf0;
  --border-strong: #d4dae3;

  /* Confidence */
  --high: #15803d;   --high-bg: #e7f7ec;
  --medium: #b45309; --medium-bg: #fdf2de;
  --low: #c2321f;    --low-bg: #fce7e3;

  /* Radii */
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 20px;
  --r-pill: 999px;

  /* Shadows */
  --sh-1: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --sh-2: 0 4px 12px rgba(15, 23, 42, .08), 0 2px 4px rgba(15, 23, 42, .04);
  --sh-3: 0 12px 28px rgba(15, 23, 42, .14);
  --sh-brand: 0 8px 20px rgba(37, 99, 235, .28);

  --ease: cubic-bezier(.4, 0, .2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #3b82f6;
    --brand-strong: #2563eb;
    --brand-tint: #16233f;

    --bg: #0b0f19;
    --surface: #141a28;
    --surface-2: #1b2334;
    --text: #f3f6fb;
    --text-muted: #9aa6b8;
    --border: #232c3e;
    --border-strong: #2d384e;

    --high: #4ade80;   --high-bg: #10271a;
    --medium: #fbbf24; --medium-bg: #2a2110;
    --low: #f87171;    --low-bg: #2a1513;

    --sh-1: 0 1px 2px rgba(0, 0, 0, .4);
    --sh-2: 0 6px 16px rgba(0, 0, 0, .45);
    --sh-3: 0 16px 36px rgba(0, 0, 0, .55);
    --sh-brand: 0 8px 22px rgba(59, 130, 246, .4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-feature-settings: "cv05" 1, "ss01" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(18px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* ---------- Screen switching + transitions ---------- */
.screen { display: none; flex: 1; flex-direction: column; }
.screen.active {
  display: flex;
  animation: screenIn .32s var(--ease) both;
}
@keyframes screenIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Brand mark (centered) ---------- */
.capture-body {
  margin-top: clamp(28px, 8vh, 88px);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 26px;
}
.brandmark { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.brandmark__icon {
  display: grid; place-items: center;
  width: clamp(84px, 26vw, 104px);
  aspect-ratio: 1;
  border-radius: 28px;
  color: #fff;
  background: linear-gradient(145deg, var(--brand), var(--brand-strong));
  box-shadow: var(--sh-brand);
}
.brandmark__icon svg { width: 58%; height: 58%; }
.brandmark__name {
  margin: 0;
  font-size: clamp(1.9rem, 8vw, 2.4rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.1;
}
.tagline {
  margin: 0;
  max-width: 30ch;
  font-size: 1.05rem;
  line-height: 1.5;
  color: var(--text-muted);
}

/* ---------- Buttons ---------- */
.actions { width: 100%; display: flex; flex-direction: column; gap: 12px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%;
  padding: 17px 20px;
  border: none;
  border-radius: var(--r);
  font: inherit;
  font-size: 1.08rem;
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s var(--ease), background .18s var(--ease), box-shadow .18s var(--ease);
}
.btn:active { transform: scale(.975); }
.btn__icon { width: 22px; height: 22px; flex: none; }

.btn--primary {
  color: #fff;
  background: linear-gradient(145deg, var(--brand), var(--brand-strong));
  box-shadow: var(--sh-brand);
}
.btn--primary:active { background: var(--brand-strong); }

.btn--ghost {
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  box-shadow: var(--sh-1);
}
.btn--ghost:active { background: var(--surface-2); }

.btn--secondary {
  color: var(--brand);
  background: var(--brand-tint);
}
.btn--secondary:active { filter: brightness(.97); }

/* ---------- Photo preview ---------- */
.preview-wrap {
  position: relative;
  width: 100%;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #0a0d14;
  box-shadow: var(--sh-2);
  border: 1px solid var(--border);
}
.preview {
  display: block; width: 100%;
  max-height: 44vh; object-fit: contain;
  background: #0a0d14;
}

/* Scanning animation over the loading preview */
.preview-wrap--scanning::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(37,99,235,.06) 50%, transparent 60%);
  pointer-events: none;
}
.scanline {
  position: absolute; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--brand), transparent);
  box-shadow: 0 0 12px 2px rgba(37, 99, 235, .55);
  animation: scan 1.9s var(--ease) infinite;
}
@keyframes scan {
  0% { top: 4%; opacity: 0; }
  15% { opacity: 1; }
  85% { opacity: 1; }
  100% { top: 96%; opacity: 0; }
}

/* ---------- Loading ---------- */
#screen-loading { align-items: stretch; justify-content: center; }
.loading-meta { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 28px; }
.loading-status { font-size: 1.1rem; font-weight: 600; color: var(--text); margin: 0; }
.loading-dots { display: inline-flex; gap: 5px; }
.loading-dots i {
  width: 8px; height: 8px; border-radius: 50%; background: var(--brand);
  animation: bounce 1s var(--ease) infinite;
}
.loading-dots i:nth-child(2) { animation-delay: .15s; }
.loading-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 100% { transform: translateY(0); opacity: .45; }
  50% { transform: translateY(-7px); opacity: 1; }
}

/* ---------- Result card ---------- */
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
  padding: 22px;
  margin-top: 16px;
}
.result-card > * { animation: rise .4s var(--ease) both; }
.result-card > *:nth-child(1) { animation-delay: .04s; }
.result-card > *:nth-child(2) { animation-delay: .09s; }
.result-card > *:nth-child(3) { animation-delay: .14s; }
.result-card > *:nth-child(4) { animation-delay: .19s; }
.result-card > *:nth-child(5) { animation-delay: .24s; }
.result-card > *:nth-child(6) { animation-delay: .29s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.result-name {
  font-size: 1.65rem; font-weight: 800; letter-spacing: -0.02em;
  line-height: 1.18; margin: 14px 0 18px;
}

/* Confidence badge */
.badge {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 13px 6px 11px;
  border-radius: var(--r-pill);
  font-size: .8rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge--high { background: var(--high-bg); color: var(--high); }
.badge--medium { background: var(--medium-bg); color: var(--medium); }
.badge--low { background: var(--low-bg); color: var(--low); }

/* Specs */
.specs { margin: 0; display: flex; flex-direction: column; }
.specs .spec-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 13px 0;
  border-top: 1px solid var(--border);
}
.specs .spec-row:first-child { border-top: none; padding-top: 4px; }
.specs dt { color: var(--text-muted); font-weight: 500; font-size: .95rem; }
.specs dd {
  margin: 0; font-weight: 650; font-size: 1rem; text-align: right;
  word-break: break-word;
}
.specs dd.spec--mono { font-variant-numeric: tabular-nums; letter-spacing: .01em; }

/* Notes / best-guess flag */
.notes { margin: 6px 0 0; }
.notes:empty { display: none; }
.notes .note-line {
  margin: 14px 0 0; padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: .92rem; line-height: 1.5;
}
.best-guess {
  display: flex; gap: 10px; align-items: flex-start;
  margin-top: 16px; padding: 13px 14px;
  background: var(--low-bg); color: var(--low);
  border-radius: var(--r-sm);
  font-weight: 600; font-size: .92rem; line-height: 1.45;
}
.best-guess svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }

/* Buy links */
.buy-heading {
  margin: 22px 0 12px; font-size: .8rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted);
}
.buy-links { display: flex; flex-direction: column; gap: 10px; }
.buy-link {
  display: flex; align-items: center; gap: 14px;
  padding: 15px 16px;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r);
  text-decoration: none; color: var(--text);
  font-size: 1.02rem; font-weight: 600;
  box-shadow: var(--sh-1);
  transition: transform .12s var(--ease), border-color .18s var(--ease), background .18s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.buy-link:active { transform: scale(.985); background: var(--surface-2); }
.buy-link:hover { border-color: var(--brand); }
.buy-link__logo {
  display: grid; place-items: center; flex: none;
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--brand-tint); color: var(--brand);
  font-weight: 800; font-size: 1rem;
}
.buy-link__text { flex: 1; min-width: 0; }
.buy-link__text small {
  display: block; font-weight: 500; font-size: .8rem; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.buy-link__chev { width: 20px; height: 20px; flex: none; color: var(--text-muted); }
.buy-link__badge {
  flex: none; font-size: .65rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
  padding: 4px 8px; border-radius: var(--r-pill);
}
.buy-link__badge--exact { color: var(--high); background: var(--high-bg); }
.buy-link__badge--close { color: var(--brand); background: var(--brand-tint); }
.buy-link--matched { border-color: var(--border-strong); }

/* ---------- State card (error) ---------- */
#screen-error { align-items: center; justify-content: center; }
.state-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
  padding: 34px 24px;
  text-align: center;
}
.state-icon { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 50%; }
.state-icon svg { width: 30px; height: 30px; }
.state-icon--error { background: var(--low-bg); color: var(--low); }
.state-text { font-size: 1.08rem; line-height: 1.5; margin: 0 0 22px; }
.state-card .btn { max-width: 280px; margin: 0 auto; }

/* ---------- Sticky action bar ---------- */
.action-bar {
  position: sticky; bottom: 0;
  margin: 14px -20px 0; padding: 14px 20px max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, var(--bg) 22%);
}

/* ---------- iOS install hint ---------- */
.ios-hint {
  display: flex; align-items: center; gap: 11px;
  margin-top: auto; padding: 13px 14px;
  background: var(--brand-tint);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: .92rem; line-height: 1.4; color: var(--text);
}
.ios-hint__icon { width: 20px; height: 20px; flex: none; color: var(--brand); }
.ios-hint button { flex: none; background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 2px; display: grid; place-items: center; }
.ios-hint button svg { width: 18px; height: 18px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
