:root {
  --bg: #000;
  --surface: #121216;
  --surface2: #1b1b21;
  --line: rgba(255, 255, 255, .09);
  --text: #f4f4f6;
  --muted: #8d8d99;
  --accent: #7c6cff;
  --accent2: #a99bff;
  --danger: #ff5d6c;
  --ok: #3ddc97;
  --warn: #ffb547;
  --r: 18px;
  --sat: env(safe-area-inset-top);
  --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left);
  --sar: env(safe-area-inset-right);
  font-family: system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; overscroll-behavior-y: none; -webkit-font-smoothing: antialiased; touch-action: manipulation; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }
[hidden] { display: none !important; }

#app { max-width: 760px; margin: 0 auto; padding: calc(var(--sat) + 8px) calc(var(--sar) + 16px) calc(var(--sab) + 110px) calc(var(--sal) + 16px); }

/* ---------- En-tête ---------- */
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 12px; }
.top h1 { margin: 0; font-size: 32px; font-weight: 800; letter-spacing: -.03em; }
.actions { display: flex; gap: 8px; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); transition: transform .15s, background .2s; position: relative; }
.icon-btn:active { transform: scale(.92); background: var(--surface2); }
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn .dot { position: absolute; top: 9px; right: 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); border: 2px solid var(--surface); }
.icon-btn[data-s="ok"] .dot { background: var(--ok); }
.icon-btn[data-s="error"] .dot { background: var(--danger); }
.icon-btn[data-s="offline"] .dot { background: var(--warn); }
.icon-btn[data-s="syncing"] svg { animation: spin 1s linear infinite; }
.icon-btn[data-s="off"] svg { opacity: .55; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Recherche + bannière ---------- */
.search { padding-bottom: 14px; }
.search input { width: 100%; height: 46px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); padding: 0 16px 0 44px; font-size: 16px; outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%238d8d99' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 14px center; }
.search input:focus { border-color: var(--accent); }
.banner { display: flex; gap: 12px; align-items: center; padding: 12px 14px; margin-bottom: 14px; border-radius: 16px; background: linear-gradient(135deg, rgba(124,108,255,.18), rgba(124,108,255,.06)); border: 1px solid rgba(124,108,255,.35); font-size: 14px; line-height: 1.35; }
.banner b { display: block; }
.banner button.go { margin-left: auto; padding: 8px 14px; border-radius: 999px; background: var(--accent); font-weight: 650; white-space: nowrap; }
.banner button.x { color: var(--muted); font-size: 22px; padding: 0 2px; line-height: 1; }

/* ---------- Grille de cartes ---------- */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.tile { container-type: inline-size; position: relative; aspect-ratio: 1.586; border-radius: var(--r); overflow: hidden; color: var(--fg); text-align: left;
  background: var(--bg-c); background: linear-gradient(135deg, color-mix(in srgb, var(--bg-c) 86%, #fff) 0%, var(--bg-c) 42%, color-mix(in srgb, var(--bg-c) 78%, #000) 100%);
  box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 10px 24px -12px rgba(0,0,0,.9); transition: transform .18s cubic-bezier(.3,.7,.4,1.2); animation: pop .35s both; animation-delay: calc(var(--i, 0) * 25ms); }
.tile::after { content: ""; position: absolute; inset: 0; background: radial-gradient(120% 90% at 0% 0%, rgba(255,255,255,.22), transparent 55%); pointer-events: none; }
.tile:active { transform: scale(.95); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.97); } }
.mark { position: absolute; inset: 0; display: grid; place-items: center; padding: 0 12%; }
.mark svg { width: 34cqw; height: 34cqw; max-height: 56%; fill: var(--fg); }
.mark .wm { font-weight: 800; font-size: 14px; font-size: max(12px, calc(var(--k, 12) * 1cqw)); line-height: 1.05; letter-spacing: -.02em; text-align: center; text-wrap: balance; text-transform: uppercase; }
.tname { position: absolute; left: 12px; bottom: 9px; right: 30px; font-size: 12.5px; font-weight: 650; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 6px rgba(0,0,0,.25); }
.tile .star { position: absolute; top: 8px; right: 8px; width: 17px; height: 17px; fill: var(--fg); opacity: .9; }

.empty { grid-column: 1 / -1; text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .art { width: 150px; margin: 0 auto 20px; aspect-ratio: 1.586; border-radius: 16px; background: linear-gradient(135deg, #3a2fa8, #7c6cff 60%, #b3a8ff); position: relative; transform: rotate(-6deg); box-shadow: 0 20px 40px -16px rgba(124,108,255,.55); }
.empty .art::before { content: ""; position: absolute; left: 14%; right: 14%; bottom: 16%; height: 28%; background: repeating-linear-gradient(90deg, #fff 0 3px, transparent 3px 5px, #fff 5px 6px, transparent 6px 10px); opacity: .9; border-radius: 3px; }
.empty h2 { color: var(--text); margin: 0 0 6px; font-size: 22px; }
.empty p { margin: 0 0 22px; font-size: 15px; line-height: 1.4; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 50px; padding: 0 22px; border-radius: 15px; background: var(--accent); font-weight: 700; font-size: 16px; transition: transform .15s, opacity .2s; }
.btn { white-space: nowrap; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--surface2); border: 1px solid var(--line); }
.btn.danger { background: rgba(255,93,108,.12); color: var(--danger); }
.btn.sm { height: 40px; padding: 0 16px; font-size: 14px; border-radius: 12px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.fab { position: fixed; right: calc(var(--sar) + 20px); bottom: calc(var(--sab) + 22px); width: 62px; height: 62px; border-radius: 22px; display: grid; place-items: center; background: linear-gradient(135deg, #8f81ff, #5b49e8); box-shadow: 0 14px 30px -8px rgba(124,108,255,.7), 0 1px 0 rgba(255,255,255,.35) inset; transition: transform .18s cubic-bezier(.3,.7,.4,1.4); z-index: 5; }
.fab:active { transform: scale(.9) rotate(90deg); }
.fab svg { width: 28px; height: 28px; stroke: #fff; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; opacity: 0; transform: translateY(24px); transition: opacity .22s, transform .28s cubic-bezier(.2,.8,.2,1); overflow-y: auto; overscroll-behavior: contain; }
.overlay.show { opacity: 1; transform: none; }

/* Fiche carte */
.viewer { background: linear-gradient(180deg, var(--bg-c) 0%, color-mix(in srgb, var(--bg-c) 30%, #000) 38%, #000 78%); color: var(--text); padding: calc(var(--sat) + 10px) calc(var(--sar) + 18px) calc(var(--sab) + 24px) calc(var(--sal) + 18px); }
.vbar { display: flex; justify-content: space-between; align-items: center; color: var(--fg); }
.vbar .group { display: flex; gap: 8px; }
.vbar .icon-btn { background: rgba(0,0,0,.28); border-color: rgba(255,255,255,.14); backdrop-filter: blur(10px); color: #fff; }
.vhead { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 18px 0 22px; color: var(--fg); text-align: center; }
.vhead .logo { width: 84px; height: 84px; border-radius: 24px; display: grid; place-items: center; background: rgba(0,0,0,.16); box-shadow: 0 0 0 1px rgba(255,255,255,.12) inset; }
.vhead .logo svg { width: 48px; height: 48px; fill: var(--fg); }
.vhead h2 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
.code-wrap { width: min(100%, 520px); margin: 0 auto; }
.code-panel { background: #fff; border-radius: 26px; padding: 26px; box-shadow: 0 30px 60px -20px rgba(0,0,0,.8); display: grid; place-items: center; min-height: 140px; }
.code-panel svg { width: 100%; height: auto; }
.code-panel svg[data-kind="1d"] { aspect-ratio: 2.3 / 1; max-height: 56vh; }
.code-panel svg[data-kind="2d"] { width: min(100%, 72vw, 340px); aspect-ratio: auto; }
.code-panel .err { color: #333; font-size: 14px; text-align: center; }
.number { display: block; margin: 20px auto 0; font: 600 26px/1.2 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .06em; text-align: center; word-break: break-all; padding: 6px 12px; border-radius: 12px; }
.number:active { background: rgba(255,255,255,.08); }
.number small { display: block; font: 500 12px system-ui; letter-spacing: .02em; color: var(--muted); margin-top: 4px; }
.vnotes { margin: 20px auto 0; width: min(100%, 520px); padding: 14px 16px; border-radius: 16px; background: rgba(255,255,255,.07); color: #d6d6de; font-size: 15px; line-height: 1.4; white-space: pre-wrap; }

/* Feuilles (bottom sheets) */
.sheet-bd { background: rgba(0,0,0,.6); backdrop-filter: blur(6px); justify-content: flex-end; transform: none; }
.sheet { background: var(--surface); border-radius: 28px 28px 0 0; max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain; padding: 8px calc(var(--sar) + 20px) calc(var(--sab) + 24px) calc(var(--sal) + 20px); transform: translateY(40px); transition: transform .3s cubic-bezier(.2,.8,.2,1); width: 100%; max-width: 640px; margin: 0 auto; border: 1px solid var(--line); border-bottom: 0; }
.sheet-bd.show .sheet { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.2); margin: 6px auto 12px; }
.sheet h3 { margin: 4px 0 16px; font-size: 22px; letter-spacing: -.02em; display: flex; align-items: center; justify-content: space-between; }
.sheet h3 .icon-btn { width: 36px; height: 36px; background: var(--surface2); }
.preview { width: min(62%, 240px); margin: 0 auto 20px; }
.field { display: block; margin-bottom: 16px; }
.field > span, .label { display: block; font-size: 12.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 7px; }
.field input, .field select, .field textarea { width: 100%; min-height: 50px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface2); padding: 12px 14px; font-size: 16px; outline: none; transition: border-color .15s; }
.field textarea { resize: none; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.row { display: flex; gap: 10px; }
.row > .field { flex: 1; min-width: 0; }
.row .scan { align-self: flex-end; margin-bottom: 16px; width: 54px; min-height: 50px; border-radius: 14px; background: var(--accent); display: grid; place-items: center; flex: none; }
.row .scan svg { width: 24px; height: 24px; stroke: #fff; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 14px; margin: -4px -20px 0; padding-left: 20px; padding-right: 20px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px 0 6px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--line); font-size: 14px; font-weight: 600; white-space: nowrap; }
.chip:active { transform: scale(.95); }
.chip i { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--bg-c); color: var(--fg); font-style: normal; font-size: 11px; font-weight: 800; overflow: hidden; }
.chip i svg { width: 16px; height: 16px; fill: var(--fg); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.sw { width: 34px; height: 34px; border-radius: 50%; background: var(--c); border: 2px solid transparent; box-shadow: 0 0 0 1px rgba(255,255,255,.18) inset; }
.sw.on { border-color: #fff; box-shadow: 0 0 0 2px var(--surface) inset; }
.sw.custom { background: conic-gradient(#f44, #fa4, #ee4, #4e6, #4be, #84f, #f4b, #f44); position: relative; overflow: hidden; }
.sw.custom input { position: absolute; inset: -6px; opacity: 0; width: 60px; height: 60px; cursor: pointer; }
.actions-row { display: flex; gap: 10px; margin-top: 8px; }
.actions-row .btn { flex: 1; }
.hint { color: var(--muted); font-size: 13.5px; line-height: 1.45; margin: 0 0 14px; }
.hint a, .sheet a { color: var(--accent2); }
.sec { margin: 0 0 26px; }
.sec h4 { margin: 0 0 6px; font-size: 17px; }
.status { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 0 0 14px; padding: 10px 12px; border-radius: 12px; background: var(--surface2); }
.status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.status.ok::before { background: var(--ok); } .status.error::before { background: var(--danger); } .status.warn::before { background: var(--warn); }
details { background: var(--surface2); border-radius: 12px; padding: 12px 14px; margin: 0 0 14px; font-size: 14px; line-height: 1.5; color: #c9c9d3; }
details summary { cursor: pointer; font-weight: 650; color: var(--text); }
details ol { margin: 10px 0 0; padding-left: 20px; }
code { background: rgba(255,255,255,.08); border-radius: 6px; padding: 1px 6px; font-size: 13px; }

/* Scanner */
.scanner { background: #000; z-index: 40; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner .shade { position: absolute; inset: 0; background: radial-gradient(70% 28% at 50% 46%, transparent 98%, rgba(0,0,0,.62) 100%); box-shadow: 0 0 0 100vmax rgba(0,0,0,.0); pointer-events: none; }
.frame { position: absolute; left: 50%; top: 46%; width: min(82vw, 380px); aspect-ratio: 1.7; transform: translate(-50%, -50%); border-radius: 22px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.55); }
.frame i { position: absolute; width: 34px; height: 34px; border: 4px solid #fff; }
.frame i:nth-child(1) { left: -2px; top: -2px; border-right: 0; border-bottom: 0; border-top-left-radius: 22px; }
.frame i:nth-child(2) { right: -2px; top: -2px; border-left: 0; border-bottom: 0; border-top-right-radius: 22px; }
.frame i:nth-child(3) { left: -2px; bottom: -2px; border-right: 0; border-top: 0; border-bottom-left-radius: 22px; }
.frame i:nth-child(4) { right: -2px; bottom: -2px; border-left: 0; border-top: 0; border-bottom-right-radius: 22px; }
.frame b { position: absolute; left: 8%; right: 8%; height: 2px; background: var(--accent2); box-shadow: 0 0 14px 2px var(--accent); border-radius: 2px; animation: scan 1.8s ease-in-out infinite alternate; }
@keyframes scan { from { top: 12%; } to { top: 88%; } }
.sbar { position: absolute; left: 0; right: 0; top: 0; padding: calc(var(--sat) + 12px) 16px 0; display: flex; justify-content: space-between; z-index: 2; }
.sbar .icon-btn { background: rgba(0,0,0,.45); backdrop-filter: blur(10px); border-color: rgba(255,255,255,.2); }
.sbottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 24px calc(var(--sab) + 28px); text-align: center; z-index: 2; }
.sbottom p { margin: 0 0 14px; font-size: 15px; text-shadow: 0 1px 8px #000; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: calc(var(--sab) + 104px); transform: translate(-50%, 20px); background: #f4f4f6; color: #111; padding: 12px 18px; border-radius: 999px; font-size: 14.5px; font-weight: 600; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: 88vw; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
