:root {
  --bg: #0f1222;
  --bg2: #171b33;
  --card: #1d2240;
  --line: #2a3059;
  --text: #f1f3ff;
  --muted: #9aa1c9;
  --accent: #ffcb05;
  --accent2: #3b5cff;
  --ok: #3ddc84;
  --sar: #ff6bd6;
  --ar: #6bd3ff;
  --top-h: 0px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
html, body { overflow-x: hidden; margin: 0; background: var(--bg); color: var(--text); font: 16px/1.35 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
h1, h2 { margin: 0; }
.muted { color: var(--muted); font-size: .85rem; }

.top { position: sticky; top: 0; z-index: 10; background: linear-gradient(var(--bg) 85%, transparent);
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px; }
.top-row { display: flex; align-items: center; justify-content: space-between; }
.top h1 { font-size: 1.35rem; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; background: var(--card); font-size: 1.2rem; }
.tools { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
#search { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); font-size: 1rem; }
.chips { display: flex; gap: 8px; overflow-x: auto; }
.chip { padding: 6px 12px; border-radius: 99px; background: var(--card); color: var(--muted); font-size: .85rem; white-space: nowrap; }
.chip.on { background: var(--accent); color: #1b1b1b; font-weight: 600; }
.summary { margin-top: 8px; display: flex; gap: 14px; font-size: .9rem; color: var(--muted); }
.summary b { color: var(--text); }
.summary .total b { color: var(--accent); }

main { padding: 6px 12px 16px; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }

/* Pokédex */
.dex-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 520px) { .dex-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 760px) { .dex-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.tile { min-width: 0; position: relative; background: var(--card); border-radius: 16px; padding: 8px 6px 10px; text-align: center;
  content-visibility: auto; contain-intrinsic-size: 150px 170px; border: 1px solid transparent; }
.tile:active { transform: scale(.97); }
.tile img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; }
.tile .num { position: absolute; top: 6px; left: 8px; font-size: .7rem; color: var(--muted); }
.tile .nm { font-size: .8rem; font-weight: 600; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .cnt { margin-top: 3px; font-size: .78rem; color: var(--muted); }
.tile.has .cnt { color: var(--text); }
.tile.zero img { filter: grayscale(1) brightness(.55); }
.tile .own { position: absolute; top: 6px; right: 6px; background: var(--ok); color: #06210f; font-size: .68rem; font-weight: 700; padding: 1px 6px; border-radius: 99px; }
.tile.done { border-color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

/* Cartes */
.sheet, .viewer { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet-bg { position: absolute; inset: 0; background: rgba(5, 7, 18, .7); backdrop-filter: blur(3px); }
.sheet-body { position: relative; width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto; background: var(--bg2);
  border-radius: 22px 22px 0 0; padding: 14px 14px calc(18px + env(safe-area-inset-bottom)); animation: up .22s ease-out; overscroll-behavior: contain; }
.sheet-body.small { display: flex; flex-direction: column; gap: 10px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; gap: 12px; position: sticky; top: -14px; background: var(--bg2); padding: 4px 0 10px; z-index: 2; }
.sheet-head img { width: 76px; height: 76px; object-fit: contain; }
.sheet-title { flex: 1; min-width: 0; }
.sheet-title h2 { font-size: 1.3rem; }
.sheet-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; }
.pcard { display: flex; flex-direction: column; gap: 6px; }
.pcard .img { position: relative; border-radius: 10px; overflow: hidden; background: var(--card); aspect-ratio: 245 / 342; }
.pcard .img img { width: 100%; height: 100%; display: block; object-fit: cover; }
.pcard.off .img img { opacity: .55; filter: saturate(.5); }
.pcard .zoom { position: absolute; right: 6px; bottom: 6px; width: 32px; height: 32px; border-radius: 99px; background: rgba(0,0,0,.6); font-size: .95rem; }
.badge { position: absolute; left: 6px; top: 6px; padding: 1px 7px; border-radius: 99px; font-size: .68rem; font-weight: 700; color: #111; }
.badge.AR { background: var(--ar); } .badge.SAR { background: var(--sar); } .badge.ALT { background: #ffa94d; } .badge.GAL { background: #8ce99a; }
.pcard .meta { display: flex; flex-direction: column; gap: 2px; padding: 0 2px; }
.pcard .set { font-size: .8rem; color: var(--muted); line-height: 1.2; }
.price { font-weight: 700; color: var(--accent); font-size: .95rem; font-variant-numeric: tabular-nums; }
.price.na { color: var(--muted); font-weight: 400; }
.check { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--card); font-size: .88rem; }
.check .box { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--muted); display: grid; place-items: center; color: transparent; font-weight: 800; font-size: .85rem; flex: none; }
.pcard.on .check { background: rgba(61, 220, 132, .15); }
.pcard.on .check .box { background: var(--ok); border-color: var(--ok); color: #06210f; }

/* Collection */
.col-group { margin-bottom: 18px; }
.col-group h3 { margin: 6px 4px 8px; font-size: .95rem; display: flex; gap: 8px; align-items: baseline; }
.col-group h3 span { color: var(--muted); font-weight: 400; font-size: .8rem; }
.col-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 8px; }
@media (min-width: 640px) { .col-cards { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.ccard { text-align: center; }
.ccard .img { border-radius: 8px; overflow: hidden; aspect-ratio: 245 / 342; background: var(--card); }
.ccard img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ccard .price { font-size: .85rem; margin-top: 3px; display: block; }

/* Visionneuse */
.viewer { align-items: center; }
.viewer-body { position: relative; width: min(92vw, 420px); max-height: 96dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; align-items: center; padding: 8px 0; }
.viewer-body img { width: 100%; border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.viewer-info { text-align: center; }
.viewer-info h2 { font-size: 1.15rem; }
.viewer-info .big { font-size: 1.4rem; font-weight: 800; color: var(--accent); }
.viewer-actions { display: flex; gap: 10px; width: 100%; }
.btn { flex: 1; padding: 12px 14px; border-radius: 12px; background: var(--accent2); font-weight: 600; text-align: center; }
.btn.ghost { background: var(--card); }
.btn.danger { background: #c2374d; }
.btn.block { width: 100%; flex: none; text-align: left; background: var(--card); }
.btn.block.ghost { text-align: center; }
.small-print { font-size: .75rem; margin: 4px 0; }

/* Barre du bas */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--bg2); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1; padding: 9px 4px 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: .78rem; }
.tab .ti { font-size: 1.25rem; }
.tab.on { color: var(--accent); }
.tab b { background: var(--accent); color: #1b1b1b; border-radius: 99px; padding: 0 6px; font-size: .7rem; margin-left: 4px; }

.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; max-width: 90vw;
  background: #fff; color: #111; padding: 10px 16px; border-radius: 12px; font-size: .9rem; box-shadow: 0 6px 20px rgba(0,0,0,.4); text-align: center; }
.badge-inline { font-size: .7rem; padding: 1px 7px; border-radius: 99px; background: var(--ar); color: #111; vertical-align: middle; }
.badge-inline.SAR { background: var(--sar); } .badge-inline.ALT { background: #ffa94d; } .badge-inline.GAL { background: #8ce99a; }

.badge.PRM { background: #b197fc; } .badge.PERSO { background: #dee2e6; }
.badge-inline.PRM { background: #b197fc; } .badge-inline.PERSO { background: #dee2e6; }
.mini { font-size: .75rem; color: var(--muted); text-decoration: underline; text-align: left; padding: 2px; }
#addCardBtn { margin-top: 18px; text-align: center; font-size: .9rem; }
#pkSearch { width: 100%; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 1rem; margin-bottom: 10px; }
.pk-list { display: flex; flex-direction: column; gap: 8px; }
.pk-item { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px; padding: 8px; }
.pk-item img { width: 56px; aspect-ratio: 245 / 342; object-fit: cover; border-radius: 6px; background: var(--bg2); }
.pk-meta { flex: 1; display: flex; flex-direction: column; min-width: 0; font-size: .9rem; }
.pk-item .btn { flex: none; padding: 8px 14px; }
.badge.SCN { background: #ffd43b; } .badge-inline.SCN { background: #ffd43b; }
button, .tile, .tab { touch-action: manipulation; }
body { -webkit-user-select: none; user-select: none; }
input { -webkit-user-select: text; user-select: text; }
.tab { position: relative; }
.tab b { position: absolute; top: 5px; left: calc(50% + 6px); margin: 0; }

/* Wish list */
.tile .wsh { position: absolute; top: 6px; right: 6px; background: #ff6b8b; color: #2b0610; font-size: .68rem; font-weight: 700; padding: 1px 6px; border-radius: 99px; }
.tile .own + .wsh { top: 26px; }
.acts { display: flex; gap: 6px; }
.acts .check { flex: 1; min-width: 0; }
.wbtn { flex: none; width: 40px; border-radius: 10px; background: var(--card); color: var(--muted); font-size: 1.15rem; }
.pcard.wished .wbtn { background: rgba(255, 107, 139, .2); color: #ff6b8b; }
.pcard.wished .img img { opacity: .8; }
.viewer-actions.col { flex-direction: column; }
.btn.wish { background: var(--card); }
.btn.wish.on { background: rgba(255, 107, 139, .2); color: #ff6b8b; }
.tab { font-size: .72rem; }

/* ---- Langues, tendances, extensions, stats, sauvegarde ---- */
.chip.sm { font-size: .75rem; padding: 4px 10px; }
.summary { align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.sum-info { display: flex; gap: 14px; flex-wrap: wrap; flex: 1; min-width: 0; }
.mini-btn { padding: 6px 12px; border-radius: 10px; background: var(--accent2); color: #fff; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.mini-btn.ghost { background: var(--card); color: var(--muted); }
.backup { margin-top: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; background: rgba(255, 203, 5, .12); border: 1px solid rgba(255, 203, 5, .4); border-radius: 12px; font-size: .85rem; }
.backup span { flex: 1; min-width: 140px; }
.tiny { font-size: .72rem; }

.lg { font-style: normal; font-size: .62rem; font-weight: 800; letter-spacing: .03em; padding: 1px 5px; border-radius: 6px; background: rgba(0, 0, 0, .65); color: #cfd3f5; border: 1px solid rgba(255, 255, 255, .2); }
.lg.own { background: var(--ok); color: #06210f; border-color: var(--ok); }
.lg.wi:not(.own) { background: #ff6b8b; color: #2b0610; border-color: #ff6b8b; }
.langs { position: absolute; right: 6px; top: 6px; display: flex; gap: 3px; }
.ccard .img { position: relative; }
.badge-lg { position: absolute; left: 4px; top: 4px; }
.pl { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; justify-content: inherit; }
.ccard .pl { justify-content: center; margin-top: 3px; }
.ccard .price { margin-top: 0; }
.dlt { font-size: .72rem; font-weight: 700; }
.dlt.up, .up { color: var(--ok); }
.dlt.dn, .dn { color: #ff6b6b; }
.pcard .img .badge { left: 6px; top: 6px; }

.set-list { display: flex; flex-direction: column; gap: 8px; }
.setrow, .st-set { text-align: left; background: var(--card); border-radius: 14px; padding: 10px 12px; display: block; width: 100%; }
.sr-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sr-top b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 4px 0; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }

.sortbar { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.sortbar select { flex: 1; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 1rem; }

.viewer-body { width: min(94vw, 440px); }
.vimg { position: relative; width: 100%; }
.vimg .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 38px; height: 56px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 1.8rem; border-radius: 12px; z-index: 2; }
.vimg .prev { left: -2px; } .vimg .next { right: -2px; }
.vlangs { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.lrow { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 12px; padding: 6px 8px; border: 2px solid transparent; }
.lrow.sel { border-color: var(--accent2); }
.lrow.on { background: rgba(61, 220, 132, .13); }
.lname { flex: 1; min-width: 0; text-align: left; font-size: .85rem; display: flex; gap: 6px; align-items: center; }
.lp { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.lbtn { padding: 7px 9px; border-radius: 9px; background: var(--bg2); font-size: .75rem; font-weight: 600; white-space: nowrap; }
.lbtn.on { background: var(--ok); color: #06210f; }
.lbtn.w.on { background: #ff6b8b; color: #2b0610; }
.viewer-info .big small { font-size: .7rem; color: var(--muted); font-weight: 400; }

.st-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.st-cards div { background: var(--card); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; }
.st-cards b { font-size: 1.15rem; } .st-cards span { color: var(--muted); font-size: .75rem; }
#stBody h3 { margin: 16px 0 6px; font-size: .95rem; }
.st-row { display: flex; justify-content: space-between; gap: 8px; font-size: .88rem; }
.st-top { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--card); border-radius: 12px; padding: 6px 8px; margin-bottom: 6px; }
.st-top img { width: 38px; aspect-ratio: 245 / 342; object-fit: cover; border-radius: 4px; }
.st-top span { flex: 1; min-width: 0; font-size: .85rem; } .st-top b { color: var(--accent); }
.st-set { margin-bottom: 6px; }
#sharedAll { margin-top: 14px; text-align: center; }
.vimg img { display: block; width: auto; max-width: 100%; max-height: 54dvh; margin: 0 auto; }
.top { position: relative; background: transparent; }

.lpx { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.lpx > span { display: flex; align-items: center; justify-content: center; gap: 5px; font-size: .78rem; border-radius: 6px; padding: 1px 3px; }
.lpx .lg { background: var(--card); }
.lpx .price { font-size: .8rem; color: var(--muted); margin: 0; }
.lpx .cur { background: rgba(255, 107, 139, .18); }
.lpx .cur .price { color: var(--accent); font-weight: 800; }
.noimg { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 14px 8px 8px; font-weight: 700; font-size: .85rem; color: #fff; text-shadow: 0 1px 4px #000; }
.noimg small { font-weight: 400; font-size: .68rem; color: #cfd3f5; }

/* Fenêtres : le fond ne défile pas, et le défilement dans une fenêtre ne « déborde » pas sur la page */
.sheet-bg { touch-action: none; }
.sheet-body, .viewer-body { overscroll-behavior: contain; }
