/* ============================================================ tokens */
:root {
  --bg: #f7f6f3;
  --bg-soft: #efede8;
  --surface: #ffffff;
  --text: #17171a;
  --text-2: #5e5e66;
  --text-3: #8c8c94;
  --border: #e4e2dc;
  --accent: #4353ff;
  --accent-hover: #3343ee;
  --accent-soft: #e8eaff;
  --accent-text: #ffffff;
  --ok: #16a34a;
  --danger: #d93636;
  --warn-bg: #fff6e0;
  --warn-text: #7a5300;
  --shadow-sm: 0 1px 2px rgb(20 20 30 / .06);
  --shadow: 0 1px 2px rgb(20 20 30 / .05), 0 8px 28px rgb(20 20 30 / .08);
  --shadow-lg: 0 2px 6px rgb(20 20 30 / .06), 0 24px 60px rgb(20 20 30 / .16);
  --r-sm: 10px;
  --r: 16px;
  --r-lg: 28px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e11;
    --bg-soft: #17171c;
    --surface: #18181d;
    --text: #f3f3f5;
    --text-2: #a6a6b0;
    --text-3: #75757f;
    --border: #2a2a31;
    --accent: #6b78ff;
    --accent-hover: #808bff;
    --accent-soft: #23264a;
    --warn-bg: #2d2412;
    --warn-text: #f1cf86;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 28px rgb(0 0 0 / .35);
    --shadow-lg: 0 24px 60px rgb(0 0 0 / .55);
    color-scheme: dark;
  }
}

/* ============================================================ base */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
svg { width: 1em; height: 1em; flex: none; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -.025em; line-height: 1.1; }
.sub { color: var(--text-2); margin: 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
body.no-scroll { overflow: hidden; }

/* ============================================================ topbar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 60px; padding: 0 max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 700; letter-spacing: -.01em; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 18px; box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 35%, transparent);
}
.status-pill {
  display: inline-flex; align-items: center; gap: 8px; max-width: 60vw;
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; animation: pulse 1.4s ease-in-out infinite; }
.status-pill.error .dot { background: var(--danger); animation: none; }
@keyframes pulse { 50% { opacity: .3; } }

main {
  max-width: 1180px; margin: 0 auto;
  padding: 24px max(16px, env(safe-area-inset-left)) calc(120px + env(safe-area-inset-bottom));
}
.view { animation: viewIn .45s var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } }

/* ============================================================ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px; border-radius: 999px; border: 0;
  font-weight: 600; font-size: 16px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .15s var(--ease), background .15s, box-shadow .15s, opacity .15s;
}
.btn svg { font-size: 20px; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.primary { background: var(--accent); color: var(--accent-text); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 32%, transparent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.btn.secondary:hover { background: var(--bg-soft); }
.btn.light { background: #fff; color: #111; }
.btn.small { min-height: 40px; padding: 0 16px; font-size: 14px; }
.btn.small svg { font-size: 17px; }
.btn.grow { flex: 1; }
.link-btn {
  background: none; border: 0; padding: 6px 2px; cursor: pointer;
  color: var(--accent); font-weight: 600; font-size: 15px;
}
.link-btn:hover { text-decoration: underline; }

/* ============================================================ capture */
.capture-view {
  display: grid; gap: 28px; align-items: center;
  grid-template-columns: 1fr;
}
@media (min-width: 900px) {
  .capture-view { grid-template-columns: 1fr minmax(380px, 460px); gap: 64px; min-height: calc(100dvh - 60px - 140px); }
}

.intro { display: flex; flex-direction: column; gap: 18px; }
.intro h1 { font-size: clamp(30px, 7vw, 56px); font-weight: 800; text-wrap: balance; }
.intro .sub { font-size: clamp(16px, 2vw, 19px); max-width: 34em; }
.br-desktop { display: none; }
@media (min-width: 900px) { .br-desktop { display: inline; } }

.steps { display: flex; gap: 6px; padding: 0; margin: 0; list-style: none; font-size: 13px; font-weight: 600; color: var(--text-3); }
.steps li { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px 5px 5px; border-radius: 999px; background: var(--bg-soft); }
.steps li span { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--border); color: var(--text-2); font-size: 11px; }
.steps li.active { background: var(--accent-soft); color: var(--accent); }
.steps li.active span { background: var(--accent); color: #fff; }

.tips { display: grid; gap: 10px; padding: 0; margin: 4px 0 0; list-style: none; }
.tips li { display: flex; align-items: center; gap: 12px; color: var(--text-2); font-size: 15px; }
.tips li b { color: var(--text); font-weight: 600; }
.tips svg { font-size: 22px; padding: 8px; width: 38px; height: 38px; border-radius: 12px; background: var(--surface); color: var(--accent); border: 1px solid var(--border); }
.privacy { display: flex; align-items: center; gap: 8px; margin: 4px 0 0; font-size: 13px; color: var(--text-3); }
.privacy svg { font-size: 15px; }

/* Mobile: compact intro so the camera is visible without scrolling */
@media (max-width: 899px) {
  main { padding-top: 16px; }
  .capture-view { gap: 16px; }
  .intro { gap: 10px; text-align: center; align-items: center; }
  .intro h1 { font-size: clamp(26px, 7.4vw, 40px); text-wrap: balance; }
  .intro .sub, .intro .tips, .intro .privacy { display: none; }
  .camera-card { --stage-w: max(min(100%, 240px), min(100%, 460px, calc((100dvh - 290px) * 3 / 4))); }
}

.camera-card {
  --stage-w: max(min(100%, 260px), min(100%, 460px, calc((100dvh - 330px) * 3 / 4)));
  display: flex; flex-direction: column; align-items: center; gap: 16px; justify-self: center; width: 100%;
}
@media (min-width: 900px) { .camera-card { --stage-w: min(100%, 460px, calc((100dvh - 260px) * 3 / 4)); } }
.stage {
  position: relative; overflow: hidden; isolation: isolate;
  width: var(--stage-w);
  aspect-ratio: 3 / 4;
  border-radius: var(--r-lg);
  background: radial-gradient(120% 80% at 50% 20%, #2a2a33, #0b0b0e);
  box-shadow: var(--shadow-lg);
}
.stage video, .stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.stage video { transform: scaleX(-1); }
.stage img { animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; } }

.oval { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.oval::after {
  content: ""; position: absolute; left: 50%; top: 44%; width: 64%; height: 60%;
  transform: translate(-50%, -50%); border-radius: 50%;
  border: 2.5px solid rgb(255 255 255 / .85);
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / .45);
}
.stage-tip {
  position: absolute; left: 50%; bottom: 14px; z-index: 2; transform: translateX(-50%);
  padding: 6px 14px; border-radius: 999px; white-space: nowrap;
  background: rgb(0 0 0 / .5); color: #fff; font-size: 13px; font-weight: 500;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
@media (min-width: 900px) { .stage-tip { display: none; } }
.stage.ready .oval::after { animation: breathe 2.8s ease-in-out infinite; }
@keyframes breathe { 50% { border-color: rgb(255 255 255 / .45); } }

.countdown {
  position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; pointer-events: none;
  color: #fff; font-size: 120px; font-weight: 800; text-shadow: 0 6px 30px rgb(0 0 0 / .45);
}
.countdown.tick { animation: tick .9s var(--ease); }
@keyframes tick { from { transform: scale(1.5); opacity: 0; } 30% { opacity: 1; } to { transform: scale(.9); opacity: 0; } }

.flash { position: absolute; inset: 0; z-index: 4; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .5s ease-out; }
@keyframes flash { from { opacity: .95; } to { opacity: 0; } }

.drop-hint {
  position: absolute; inset: 12px; z-index: 5; display: none; place-items: center; align-content: center; gap: 10px;
  border: 2.5px dashed #fff; border-radius: calc(var(--r-lg) - 8px);
  background: rgb(67 83 255 / .55); color: #fff; font-weight: 700; font-size: 18px;
}
.drop-hint svg { font-size: 40px; }
.stage.dragging .drop-hint { display: grid; }

.camera-msg {
  position: absolute; inset: 0; z-index: 6; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 28px; text-align: center; color: #fff;
  background: radial-gradient(120% 80% at 50% 20%, #2a2a33, #0b0b0e);
}
.camera-msg > svg { font-size: 44px; opacity: .6; }
.camera-msg p { margin: 0; font-size: 15px; line-height: 1.5; color: rgb(255 255 255 / .82); max-width: 28ch; }

.controls { display: flex; align-items: center; justify-content: center; gap: 28px; width: var(--stage-w); min-height: 84px; }
.controls.preview { gap: 12px; }
.icon-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: 64px; padding: 8px 0; border: 0; background: none; cursor: pointer;
  color: var(--text-2); font-size: 12px; font-weight: 600; border-radius: 14px;
}
.icon-btn svg {
  font-size: 22px; width: 48px; height: 48px; padding: 13px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  transition: background .15s, color .15s;
}
.icon-btn:hover svg { background: var(--bg-soft); }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.icon-btn[aria-pressed="true"] svg { background: var(--accent); color: #fff; border-color: var(--accent); }

.shutter {
  position: relative; width: 80px; height: 80px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 4px solid var(--text); background: transparent; transition: transform .15s var(--ease), opacity .2s;
}
.shutter span {
  position: absolute; inset: 5px; border-radius: 50%; background: var(--accent);
  transition: transform .15s var(--ease), background .15s;
}
.shutter:hover span { background: var(--accent-hover); }
.shutter:active span { transform: scale(.88); }
.shutter:disabled { opacity: .35; cursor: default; }
.shutter.counting span { transform: scale(.5); border-radius: 30%; }

/* ============================================================ searching */
.searching-view { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding-top: 8vh; }
.scan {
  position: relative; width: 200px; height: 200px; border-radius: 50%; overflow: hidden; margin-bottom: 18px;
  box-shadow: 0 0 0 6px var(--surface), 0 0 0 8px var(--accent-soft), var(--shadow-lg);
}
.scan img { width: 100%; height: 100%; object-fit: cover; filter: saturate(.85); }
.scan::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(circle, rgb(255 255 255 / .35) 1px, transparent 1.5px);
  background-size: 14px 14px; mix-blend-mode: overlay;
}
.scan-line {
  position: absolute; left: 0; right: 0; height: 40%; top: -40%;
  background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--accent) 55%, transparent) 85%, #fff 100%);
  animation: scan 1.6s cubic-bezier(.45, 0, .55, 1) infinite;
}
@keyframes scan { to { top: 100%; } }
.searching-view h2 { font-size: 26px; }

/* ============================================================ results */
.results-head { display: flex; align-items: center; gap: 16px; }
.avatar {
  width: 64px; height: 64px; border-radius: 50%; flex: none; background: var(--bg-soft);
  box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--accent);
}
.results-title { flex: 1; min-width: 0; }
.results-title h2 { font-size: clamp(22px, 4vw, 32px); }
.results-title .sub { margin-top: 4px; font-size: 15px; }
@media (max-width: 560px) {
  .avatar { width: 52px; height: 52px; }
  .results-head .btn span { display: none; }
  .results-head .btn { width: 44px; padding: 0; }
}

.notice { margin-top: 16px; padding: 12px 16px; border-radius: var(--r-sm); background: var(--warn-bg); color: var(--warn-text); font-size: 14px; }

.toolbar {
  position: sticky; top: 60px; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 16px -4px 8px; padding: 10px 4px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.sel-count { color: var(--text-2); font-size: 14px; }
.sel-count.has { color: var(--text); font-weight: 700; font-size: 15px; }

.grid { display: grid; gap: 4px; grid-template-columns: repeat(3, 1fr); }
@media (min-width: 600px) { .grid { gap: 10px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }
@media (min-width: 1000px) { .grid { gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); } }

.card {
  position: relative; aspect-ratio: 1; overflow: hidden; cursor: pointer;
  border-radius: 6px; background: var(--bg-soft);
  animation: cardIn .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 25ms);
}
@media (min-width: 600px) { .card { border-radius: var(--r); } }
@keyframes cardIn { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.card::before { /* shimmer while loading */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, color-mix(in srgb, var(--surface) 70%, transparent) 50%, transparent 70%) var(--bg-soft);
  background-size: 200% 100%; animation: shimmer 1.3s linear infinite;
}
.card.loaded::before { display: none; }
@keyframes shimmer { to { background-position: -200% 0; } }
.card img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .35s ease, transform .25s var(--ease), border-radius .25s var(--ease);
}
.card.loaded img { opacity: 1; }
@media (hover: hover) { .card:hover img { transform: scale(1.04); } }
.card.selected img { transform: scale(.86); border-radius: 12px; }
.card.selected { background: var(--accent-soft); }

.card .pick {
  position: absolute; top: 0; left: 0; z-index: 2; width: 48px; height: 48px; padding: 0; border: 0;
  background: none; cursor: pointer; display: grid; place-items: center;
}
.card .pick span {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid #fff; background: rgb(0 0 0 / .18); color: transparent;
  box-shadow: 0 1px 4px rgb(0 0 0 / .3); transition: background .15s, border-color .15s, transform .15s var(--ease);
}
.card .pick svg { font-size: 16px; }
.card.selected .pick span { background: var(--accent); border-color: var(--accent); color: #fff; transform: scale(1.08); }
.card .badge {
  position: absolute; right: 8px; bottom: 8px; z-index: 2; padding: 3px 8px; border-radius: 999px;
  background: rgb(0 0 0 / .55); color: #fff; font-size: 11px; font-weight: 600; letter-spacing: .02em;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
@media (max-width: 599px) { .card .badge { display: none; } }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 56px 0 24px; }
.empty .sub { max-width: 40ch; }
.empty .btn { margin-top: 12px; }
.empty-art {
  display: grid; place-items: center; width: 88px; height: 88px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 38px; margin-bottom: 6px;
}
.empty h3 { font-size: 22px; }

/* ============================================================ download bar */
.download-bar {
  position: fixed; z-index: 20; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom));
  width: min(calc(100% - 24px), 560px); transform: translateX(-50%);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 8px 8px 22px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: barIn .4s var(--ease);
}
@keyframes barIn { from { transform: translate(-50%, 140%); } }
.db-info { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.db-info strong { font-size: 15px; white-space: nowrap; }
.download-bar .btn { min-height: 46px; }

/* ============================================================ lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column;
  background: #0a0a0c; color: #fff;
  animation: fadeIn .2s ease;
}
.lb-top, .lb-bottom {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
}
.lb-bottom { justify-content: center; padding: 12px 12px max(16px, env(safe-area-inset-bottom)); }
.lb-counter { font-size: 14px; font-weight: 600; color: rgb(255 255 255 / .7); font-variant-numeric: tabular-nums; }
.lb-btn {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgb(255 255 255 / .1); color: #fff; font-size: 22px;
}
.lb-btn:hover { background: rgb(255 255 255 / .18); }
.lb-select {
  display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 16px 0 10px; border-radius: 999px;
  border: 0; cursor: pointer; background: rgb(255 255 255 / .1); color: #fff; font-weight: 600; font-size: 15px;
}
.lb-select .tick {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid #fff; color: transparent; font-size: 14px; transition: background .15s;
}
.lb-select[aria-pressed="true"] { background: var(--accent); }
.lb-select[aria-pressed="true"] .tick { background: #fff; color: var(--accent); }

.lb-stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; touch-action: pan-y; }
.lb-stage img {
  max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none;
  transition: opacity .2s ease, transform .25s var(--ease);
}
.lb-stage img.loading { opacity: 0; }
.lb-spinner {
  position: absolute; width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid rgb(255 255 255 / .2); border-top-color: #fff; animation: spin .8s linear infinite;
}
.lb-stage:not(.busy) .lb-spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgb(255 255 255 / .12); color: #fff; font-size: 26px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.lb-nav:hover { background: rgb(255 255 255 / .22); }
.lb-nav.prev { left: 16px; }
.lb-nav.next { right: 16px; }
@media (hover: none) and (max-width: 700px) { .lb-nav { display: none; } }

/* ============================================================ toasts */
.toasts {
  position: fixed; z-index: 60; left: 50%; top: calc(72px + env(safe-area-inset-top)); transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; width: min(calc(100% - 32px), 440px); pointer-events: none;
}
.toast {
  padding: 12px 18px; border-radius: 14px; font-size: 15px; font-weight: 500; text-align: center;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg);
  animation: toastIn .35s var(--ease);
}
.toast.error { background: var(--danger); color: #fff; }
.toast.out { animation: toastOut .3s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px) scale(.96); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

/* ============================================================ motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .scan-line { display: none; }
}
