:root {
  --bg: #0d0d0f;
  --bg-soft: #17171b;
  --card: #1c1c21;
  --line: #2c2c33;
  --txt: #f4f4f5;
  --muted: #a0a0aa;
  --accent: #ff5a3c;
  --accent-2: #ffd23c;
  --ok: #34d399;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: rgba(13,13,15,.82);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark { font-weight: 800; font-size: 22px; letter-spacing: -.5px; }
.brand-sub { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 2px; }
.tabs { display: flex; gap: 4px; background: var(--bg-soft); padding: 4px; border-radius: 999px; }
.tabs a {
  font-size: 13px; font-weight: 600; color: var(--muted);
  padding: 7px 14px; border-radius: 999px; transition: .2s;
}
.tabs a.active { background: var(--txt); color: #000; }

/* ---------- Views ---------- */
.view { min-height: calc(100dvh - 56px); }
.hidden { display: none !important; }

/* ---------- Scan ---------- */
.scan-stage {
  position: relative; width: 100%;
  height: calc(100dvh - 56px - 96px);
  background: #000; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
#cam { width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute; inset: 12% 8%;
  border: 2px solid rgba(255,255,255,.55);
  border-radius: 14px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.35);
  pointer-events: none;
}
.scan-overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 28px; text-align: center;
  background: radial-gradient(120% 80% at 50% 20%, rgba(13,13,15,.55), rgba(13,13,15,.92));
}
.scan-hint h1 { font-size: 24px; margin: 0 0 8px; }
.scan-hint p { color: var(--muted); margin: 0; max-width: 320px; line-height: 1.5; }

.scan-controls {
  height: 96px; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 0 24px calc(var(--safe-bottom)); 
  background: var(--bg);
}
.scan-caption { color: var(--muted); font-size: 13px; text-align: center; flex: 1; }

/* Coins animés du cadre de visée */
.scan-frame .corner { position: absolute; width: 26px; height: 26px; border: 3px solid var(--accent-2); }
.scan-frame .corner.tl { top: -2px; left: -2px; border-right: 0; border-bottom: 0; border-top-left-radius: 12px; }
.scan-frame .corner.tr { top: -2px; right: -2px; border-left: 0; border-bottom: 0; border-top-right-radius: 12px; }
.scan-frame .corner.bl { bottom: -2px; left: -2px; border-right: 0; border-top: 0; border-bottom-left-radius: 12px; }
.scan-frame .corner.br { bottom: -2px; right: -2px; border-left: 0; border-top: 0; border-bottom-right-radius: 12px; }

/* Pastille de statut live */
.live-status {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 8px;
  background: rgba(13,13,15,.72); backdrop-filter: blur(8px);
  border: 1px solid var(--line); color: var(--txt);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
}
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent-2); animation: pulse 1.1s infinite; }
.live-status.found .live-dot { background: var(--ok); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.7); } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; border-radius: 12px; padding: 13px 20px;
  transition: .15s; color: var(--txt); background: var(--card);
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-lg { padding: 15px 28px; font-size: 16px; }
.btn-ghost { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.18); }
.btn-file { position: relative; }
.btn-round { width: 52px; height: 52px; padding: 0; border-radius: 50%; }
.btn-round svg { width: 24px; height: 24px; }

/* ---------- Loading ---------- */
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.18); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress { width: 220px; height: 6px; background: rgba(255,255,255,.14); border-radius: 999px; overflow: hidden; }
#loadingBar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

/* ---------- Scan result (bottom sheet live) ---------- */
.result-sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 8;
  padding: 14px 14px calc(18px + var(--safe-bottom));
  background: linear-gradient(to top, rgba(13,13,15,.98) 70%, rgba(13,13,15,0));
  transform: translateY(100%); transition: transform .32s cubic-bezier(.2,.8,.2,1);
}
.result-sheet.show { transform: translateY(0); }
.result-sheet .res-card {
  width: 100%; max-width: 460px; margin: 0 auto; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.res-row { display: flex; gap: 14px; padding: 14px; align-items: center; }
.res-row img.rthumb { width: 76px; height: 76px; border-radius: 12px; object-fit: cover; flex: 0 0 auto; background: #000; }
.res-row .rinfo { flex: 1; min-width: 0; }
.res-row .rinfo h2 { margin: 0 0 3px; font-size: 19px; }
.result { background: rgba(13,13,15,.94); }
.result .res-card {
  width: 100%; max-width: 360px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.res-badge { font-size: 12px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; padding: 10px; }
.res-badge.ok { background: var(--ok); color: #04231a; }
.res-badge.maybe { background: var(--accent-2); color: #2a2200; }
.res-badge.no { background: #3a3a42; color: var(--txt); }
.res-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: #000; }
.res-body { padding: 16px; text-align: left; }
.res-body h2 { margin: 0 0 4px; font-size: 20px; }
.res-body .meta { color: var(--muted); font-size: 14px; }
.res-actions { display: flex; gap: 10px; margin-top: 16px; }
.res-actions .btn { flex: 1; }
.maybe-list { display: flex; gap: 10px; margin-top: 12px; }
.maybe-list a { flex: 1; background: var(--bg-soft); border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.maybe-list img { width: 100%; aspect-ratio: 1; object-fit: cover; }
.maybe-list span { display: block; font-size: 11px; padding: 6px; color: var(--muted); }

/* ---------- Galerie ---------- */
.search { padding: 16px 16px 8px; position: sticky; top: 56px; background: var(--bg); z-index: 10; }
.search input {
  width: 100%; padding: 13px 16px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--line); color: var(--txt); font-size: 15px;
}
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 12px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; font-size: 13px; font-weight: 600; color: var(--muted);
  padding: 8px 14px; border-radius: 999px; background: var(--card);
  border: 1px solid var(--line); cursor: pointer;
}
.chip.active { background: var(--txt); color: #000; border-color: var(--txt); }
.grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 8px 16px 40px;
}
@media (min-width: 620px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; cursor: pointer; transition: transform .15s, border-color .15s;
}
.card:active { transform: scale(.97); }
.card .thumb { width: 100%; aspect-ratio: 3/4; object-fit: cover; background: var(--bg-soft); }
.card .info { padding: 10px 12px 12px; }
.card .info .name { font-weight: 600; font-size: 14px; line-height: 1.25; }
.card .info .sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.count { text-align: center; color: var(--muted); font-size: 13px; padding-bottom: 30px; }

/* ---------- Fiche ---------- */
.fiche-wrap { padding-bottom: 60px; }
.fiche-back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); padding: 16px; font-size: 14px; }
.match-banner { margin: 0 16px 14px; background: var(--ok); color: #04231a; font-weight: 700; font-size: 13px; padding: 10px 14px; border-radius: 10px; }
.panels { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 10px; padding: 0 16px 12px; scrollbar-width: none; }
.panels::-webkit-scrollbar { display: none; }
.panels figure { flex: 0 0 86%; scroll-snap-align: center; margin: 0; }
.panels img { width: 100%; border-radius: 14px; background: var(--bg-soft); cursor: zoom-in; }
.panels figcaption { color: var(--muted); font-size: 12px; text-align: center; margin-top: 6px; }
.dots { display: flex; justify-content: center; gap: 6px; margin: 4px 0 18px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line); transition: .2s; }
.dots i.on { background: var(--txt); width: 18px; border-radius: 3px; }
.fiche-head { padding: 0 20px; }
.fiche-head .num { color: var(--accent); font-weight: 700; font-size: 13px; letter-spacing: 1px; }
.fiche-head h1 { margin: 6px 0 2px; font-size: 28px; line-height: 1.1; }
.fiche-head .promo { color: var(--muted); font-size: 15px; }
.fiche-specs { display: flex; flex-wrap: wrap; gap: 8px; padding: 18px 20px 0; }
.spec { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.spec b { color: var(--muted); font-weight: 500; }
.fiche-desc { padding: 20px; color: #d8d8dd; line-height: 1.65; font-size: 15px; }
.fiche-desc h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin: 0 0 8px; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.95);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
