:root {
  --bg: #12101c;
  --panel: #1d1a2e;
  --line: #3b3458;
  --text: #ece9f7;
  --muted: #9a94b8;
  --accent: #ff4d8d;
  --common: #a3a3a3;
  --uncommon: #55555f;
  --rare: #1f6fe0;
  --superrare: #8a2be2;
  --legendary: #ff7a00;
  --header-h: 52px;
  --nav-h: 60px;
  /* Taille de carte / booster : limitée par la largeur ET la hauteur de l'écran */
  --card-w: min(70vw, 300px, calc((100dvh - var(--header-h) - var(--nav-h) - 140px) / 1.4));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: radial-gradient(circle at 50% 30%, #2a1f45 0%, var(--bg) 70%) fixed var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

a { color: var(--accent); }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  background: var(--panel);
  color: var(--text);
}
button.primary { background: var(--accent); color: white; font-weight: 700; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.hidden { display: none !important; }

/* ---------- Header / navigation ---------- */

.topbar {
  flex: none;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px);
}
.topbar h1 { margin: 0; font-size: 1.2rem; letter-spacing: 0.05em; }
.topbar h1 span { color: var(--accent); }

.stock-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.stock-icon { width: 12px; height: 16px; border-radius: 2px; background: linear-gradient(135deg, var(--accent), #7c3aed); }

main { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view { display: none; }
.view.active { display: block; }

.bottom-nav {
  flex: none;
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(10, 8, 18, 0.9);
  border-top: 1px solid var(--line);
}
.bottom-nav .tab {
  flex: 1;
  border-radius: 0;
  background: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.75rem;
  padding: 6px;
}
.bottom-nav .tab.active { color: var(--accent); }
.tab-icon { font-size: 1.3rem; line-height: 1; }
.bottom-nav small { opacity: 0.7; }

/* ---------- Compte / connexion ---------- */

.header-right { display: flex; align-items: center; gap: 8px; }
.account {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 3px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.85rem;
  max-width: 40vw;
}
.account img { width: 26px; height: 26px; border-radius: 50%; flex: none; }
.account span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.login-screen { display: none; }
body.logged-out .login-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}
body.logged-out :is(main, .bottom-nav, .header-right) { display: none; }
body.loading main { visibility: hidden; }
.login-pack {
  width: 120px;
  aspect-ratio: 63 / 88;
  border-radius: 10px;
  background: linear-gradient(135deg, #ff4d8d, #7c3aed 55%, #1e3a8a);
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 1.5rem;
  line-height: 1;
  box-shadow: 0 14px 40px rgba(124, 58, 237, 0.5);
  transform: rotate(-6deg);
  margin-bottom: 10px;
}
.login-screen h2 { margin: 0; font-size: 1.3rem; max-width: 320px; }
.login-screen p { margin: 0; color: var(--muted); max-width: 320px; font-size: 0.95rem; }
.discord-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  background: #5865f2;
  color: white;
  text-decoration: none;
  font-weight: 700;
  padding: 14px 22px;
  border-radius: 12px;
}
.discord-btn svg { width: 24px; height: 24px; }
.login-error { color: #ff8080 !important; }

/* ---------- Vue booster ---------- */

#view-booster.active {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
}
.stage.scrollable { overflow-y: auto; place-items: start center; }

.hint {
  flex: none;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 8px 24px 16px;
  min-height: 52px;
}
.swipe-anim { display: inline-block; animation: swipe-hint 1.6s ease-in-out infinite; }

/* Booster blister */
.pack-wrap {
  grid-area: 1 / 1;
  filter: drop-shadow(0 14px 30px rgba(124, 58, 237, 0.45));
  z-index: 3;
}
.pack-wrap.enter { animation: pack-enter 0.5s cubic-bezier(.2,1.3,.5,1); }
.pack { width: var(--card-w); position: relative; }
.pack.empty { filter: grayscale(1) brightness(0.6); }

.pack-top {
  height: calc(var(--card-w) * 0.2);
  background: linear-gradient(180deg, #d4d4e0, #9898b0 70%, #c9c9d9);
  position: relative;
  touch-action: none;
  cursor: grab;
  transition: transform 0.15s;
}
.pack-top::before {
  /* reflets de l'aluminium */
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.25) 0 2px, transparent 2px 9px);
}
.pack-top::after {
  content: "✂";
  position: absolute;
  left: 8px;
  bottom: 6px;
  font-size: 0.9rem;
  color: #4b4b63;
}
.pack.empty .pack-top { cursor: default; }
.tear-line {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: repeating-linear-gradient(90deg, #5b5b78 0 6px, transparent 6px 10px);
}
.tear-progress {
  height: 100%;
  width: 0;
  background: var(--bg);
  box-shadow: 0 0 8px 2px rgba(255, 255, 255, 0.9), 0 0 16px var(--accent);
}
.tear-progress.from-right { margin-left: auto; }
.pack-top.torn { animation: tear-off 0.6s ease-in forwards; }

.pack-body {
  height: calc(var(--card-w) * 1.45);
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #ff4d8d, #7c3aed 55%, #1e3a8a);
}
.pack-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  opacity: 0.55;
  mix-blend-mode: luminosity;
}
.pack-body::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(124, 58, 237, 0.2) 0%, rgba(255, 77, 141, 0.55) 55%, rgba(18, 16, 28, 0.95) 100%);
}
.pack-body::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, 0.35) 50%, transparent 70%);
  animation: shine 3.5s infinite;
}
.pack-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12%;
  text-align: center;
  z-index: 1;
}
.pack-title {
  display: block;
  font-weight: 900;
  font-size: calc(var(--card-w) * 0.17);
  line-height: 0.95;
  letter-spacing: 0.04em;
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.6);
}
.pack-sub { font-size: 0.8rem; opacity: 0.85; letter-spacing: 0.1em; text-transform: uppercase; }
.pack-body.dropping { animation: pack-drop 0.45s ease-in forwards; }

/* Pile de cartes */
.stack {
  grid-area: 1 / 1;
  position: relative;
  width: var(--card-w);
  aspect-ratio: 63 / 88;
  z-index: 2;
  touch-action: none;
}
.stack.rising { animation: stack-rise 0.55s cubic-bezier(.2,.9,.3,1.1); }
.stack-card {
  position: absolute;
  inset: 0;
  transform: translateY(calc(var(--depth) * 5px)) rotate(var(--tilt));
  transition: transform 0.3s;
  cursor: grab;
  will-change: transform;
}
.stack-card.top { transform: rotate(0deg); }
.stack-card .card { width: 100%; height: 100%; }
.stack-card:not(.top) .new-tag { display: none; }
.stack-card.reveal-burst::before {
  content: "";
  position: absolute;
  inset: -40%;
  z-index: -1;
  background: radial-gradient(circle, var(--burst) 0%, transparent 60%);
  animation: burst 1.4s ease-out infinite;
  pointer-events: none;
}
.stack-card:has(.rarity-superrare) { --burst: rgba(192, 132, 252, 0.6); }
.stack-card:has(.rarity-legendary) { --burst: rgba(251, 191, 36, 0.75); }
.stack-counter {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  z-index: 5;
}

/* Récapitulatif */
.summary {
  grid-area: 1 / 1;
  width: 100%;
  max-width: 640px;
  padding: 16px;
  text-align: center;
  animation: fade-up 0.4s;
}
.summary h2 { margin: 4px 0 14px; font-size: 1.1rem; }
.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.summary-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }

/* ---------- Cartes ---------- */
/* Format TCG réel (63 × 88 mm). Tout l'intérieur est dimensionné en cqw (largeur de la carte)
   pour que la même carte rende pareil en miniature, en pile ou en zoom. */

.rarity-common { --rc: #8f8f8f; --frame: #b8b8b8; }
.rarity-uncommon { --rc: #45454e; --frame: #5c5c66; }
.rarity-rare { --rc: #1f6fe0; --frame: #2f7df0; }
.rarity-superrare { --rc: #8a2be2; --frame: #9440f0; }
.rarity-legendary { --rc: #f06e00; --frame: #ff8a14; }

.card {
  --paper: #f3eee2;
  --ink: #1b1915;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .1  0 0 0 0 .08  0 0 0 0 .05  0 0 0 .35 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --tone: radial-gradient(circle, rgba(27, 25, 21, 0.16) 30%, transparent 32%);
  --edge: 3px;
  container-type: inline-size;
  position: relative;
  aspect-ratio: 63 / 88;
  border-radius: 4.5% / 3.2%;
  background: var(--grain), linear-gradient(160deg, color-mix(in srgb, var(--frame) 75%, white), var(--frame) 40%, color-mix(in srgb, var(--frame) 70%, black));
  /* Épaisseur : tranche de carton visible en bas à droite, puis ombre portée */
  box-shadow:
    calc(var(--edge) * 0.33) calc(var(--edge) * 0.33) 0 #e9e3d4,
    calc(var(--edge) * 0.66) calc(var(--edge) * 0.66) 0 #d6ceba,
    var(--edge) var(--edge) 0 #b3a98f,
    calc(var(--edge) + 1px) calc(var(--edge) + 1px) 0 rgba(0, 0, 0, 0.55),
    calc(var(--edge) + 4px) calc(var(--edge) + 8px) 16px rgba(0, 0, 0, 0.45);
  color: var(--ink);
  text-align: left;
  font-family: "Zen Kaku Gothic New", system-ui, sans-serif;
}

.card-frame {
  position: absolute;
  inset: 3.6cqw;
  border-radius: 2.2cqw;
  background: var(--grain), var(--paper);
  border: 0.5cqw solid var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 1.6cqw;
  gap: 1.4cqw;
}

.card-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2cqw;
  padding: 0 0.6cqw 1cqw;
  border-bottom: 0.4cqw solid var(--ink);
}
.card-names { min-width: 0; }
.card-name {
  font-family: "Dela Gothic One", "Zen Kaku Gothic New", sans-serif;
  font-size: var(--name-size, 6.4cqw);
  line-height: 1.05;
  white-space: nowrap;
}
.card-native {
  font-family: "Shippori Mincho", serif;
  font-size: 3.6cqw;
  font-weight: 700;
  color: var(--rc);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-score {
  flex: none;
  font-family: "Dela Gothic One", sans-serif;
  font-size: 4.6cqw;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.card-score small { font-size: 0.7em; color: var(--rc); margin-right: 0.8cqw; }

.card-art {
  position: relative;
  flex: 1;
  min-height: 0;
  border: 0.5cqw solid var(--ink);
  background: var(--tone) 0 0 / 2cqw 2cqw, #e4ddcc;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.card-art img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 15%; display: block; pointer-events: none; }
.card-art span { font-family: "Dela Gothic One", sans-serif; font-size: 22cqw; color: rgba(27, 25, 21, 0.18); }
.card-series {
  position: absolute;
  left: -0.5cqw;
  bottom: 2.4cqw;
  max-width: 80%;
  background: var(--ink);
  color: var(--paper);
  font-size: 2.8cqw;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.8cqw 2.4cqw 0.8cqw 2cqw;
  clip-path: polygon(0 0, 100% 0, calc(100% - 1.6cqw) 100%, 0 100%);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-text {
  flex: none;
  height: 21cqw;
  font-size: 3.15cqw;
  line-height: 1.32;
  padding: 1.6cqw 2cqw;
  border: 0.3cqw solid rgba(27, 25, 21, 0.5);
  background: linear-gradient(90deg, var(--paper) 70%, transparent), var(--tone) 0 0 / 1.6cqw 1.6cqw;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
}

.card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 2.7cqw;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0 0.6cqw;
  color: rgba(27, 25, 21, 0.7);
}
.card-rarity { color: var(--rc); display: inline-flex; align-items: center; gap: 1.2cqw; }
.rarity-icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  flex: none;
  background: var(--rc);
}
.rarity-icon.common { border-radius: 50%; }
.rarity-icon.uncommon { clip-path: polygon(50% 4%, 100% 94%, 0 94%); }
.rarity-icon.rare { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.rarity-icon.superrare { clip-path: polygon(50% 0, 100% 38%, 81% 100%, 19% 100%, 0 38%); }
.rarity-icon.legendary { clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%); }
.card-foot .rarity-icon { width: 3.4cqw; height: 3.4cqw; }

.card-count,
.new-tag {
  position: absolute;
  z-index: 3;
  font-family: system-ui, sans-serif;
  font-weight: 800;
  color: white;
}
.card-count {
  top: -1.5cqw;
  right: -1.5cqw;
  background: var(--ink);
  border: 0.6cqw solid var(--paper);
  font-size: 4cqw;
  padding: 0.6cqw 2cqw;
  border-radius: 999px;
}
.new-tag {
  top: 34%;
  right: -2cqw;
  background: var(--accent);
  font-size: 3.6cqw;
  padding: 1cqw 2.6cqw;
  transform: rotate(4deg);
  box-shadow: 0 1cqw 2cqw rgba(0, 0, 0, 0.35);
}

/* Carte non possédée : emplacement vide en pointillés */
.card.unknown { box-shadow: none; background: rgba(255, 255, 255, 0.03); outline: 2px dashed color-mix(in srgb, var(--frame) 60%, transparent); outline-offset: -2px; }
.card.unknown .card-frame { background: var(--tone) 0 0 / 3cqw 3cqw, #24212f; border-color: #3b3458; opacity: 0.7; }
.card.unknown .card-art { background: transparent; border-color: #3b3458; }
.card.unknown .card-art span { color: #4b4370; }
.card.unknown .card-foot { color: #7d76a0; }
.card-series-mini { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 2cqw; }

/* --- Lumière : un point lumineux (--mx, --my) partagé par tous les reflets de la carte.
   Il se promène tout seul, et suit le doigt quand on manipule la carte (.tilting). --- */
@property --mx { syntax: "<percentage>"; inherits: true; initial-value: 30%; }
@property --my { syntax: "<percentage>"; inherits: true; initial-value: 20%; }

.fx { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; overflow: hidden; }
.fx-foil, .fx-shine, .fx-glitter, .fx-gloss { animation: light-move 7s ease-in-out infinite; }
.card.tilting :is(.fx-foil, .fx-shine, .fx-glitter, .fx-gloss) { animation: none; }

/* --- Foil holographique (Rare et +) : cadre (sous le papier) et illustration.
   Irisation en soft-light (préserve les couleurs), concentrée autour du point lumineux.
   Intensité par palier : --foil (irisation), --glitter (paillettes), --foil-dodge (éclat coloré). --- */
.rarity-rare { --foil: 0.45; --glitter: 0.45; --foil-dodge: 0; --foil-reach: 45%; }
.rarity-superrare { --foil: 0.7; --glitter: 0.75; --foil-dodge: 0.12; --foil-reach: 60%; }
.rarity-legendary { --foil: 0.95; --glitter: 1; --foil-dodge: 0.25; --foil-reach: 80%; }

.fx-foil {
  --px: calc(var(--mx) * 0.8 + 10%);
  --py: calc(var(--my) * 0.8 + 10%);
  background-image:
    repeating-linear-gradient(115deg, #ff6b8b 0%, #ffd86b 5%, #a3ff6b 10%, #6bfff0 15%, #6b8dff 20%, #d36bff 25%, #ff6b8b 30%),
    repeating-linear-gradient(45deg, transparent 0 1.1cqw, rgba(255, 255, 255, 0.45) 1.1cqw 1.5cqw);
  background-size: 400% 400%, 100% 100%;
  background-position: var(--px) var(--py), 0 0;
  -webkit-mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, rgba(0, 0, 0, 0.6) 30%, rgba(0, 0, 0, 0.15) var(--foil-reach), rgba(0, 0, 0, 0.08) 100%);
  mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, rgba(0, 0, 0, 0.6) 30%, rgba(0, 0, 0, 0.15) var(--foil-reach), rgba(0, 0, 0, 0.08) 100%);
  mix-blend-mode: soft-light;
  opacity: var(--foil);
}
/* Éclat coloré (Super rare / Légende) : un peu de color-dodge, juste sous la lumière */
.fx-shine {
  background: repeating-linear-gradient(115deg, #ff6b8b 0%, #ffd86b 5%, #a3ff6b 10%, #6bfff0 15%, #6b8dff 20%, #d36bff 25%, #ff6b8b 30%);
  background-size: 400% 400%;
  background-position: calc(var(--mx) * 0.8 + 10%) calc(var(--my) * 0.8 + 10%);
  -webkit-mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, transparent 35%);
  mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, transparent 35%);
  mix-blend-mode: color-dodge;
  opacity: var(--foil-dodge);
}
/* Paillettes : grain métallique qui s'allume autour du point lumineux */
.fx-glitter {
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='2' seed='7'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeComponentTransfer%3E%3CfeFuncR type='discrete' tableValues='0 0 0 0 0 0 .6 1'/%3E%3CfeFuncG type='discrete' tableValues='0 0 0 0 0 0 .6 1'/%3E%3CfeFuncB type='discrete' tableValues='0 0 0 0 0 0 .6 1'/%3E%3CfeFuncA type='discrete' tableValues='0 0 0 0 0 0 1 1'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E") 0 0 / 22cqw 22cqw;
  -webkit-mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, rgba(0, 0, 0, 0.4) 25%, transparent 55%);
  mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, rgba(0, 0, 0, 0.4) 25%, transparent 55%);
  mix-blend-mode: screen;
  opacity: var(--glitter);
}

/* Rare : la lumière passe plus souvent */
.rarity-rare :is(.fx-foil, .fx-shine, .fx-glitter, .fx-gloss) { animation-duration: 3s; }
.rarity-rare { --foil-dodge: 0.08; }

/* --- Légende : foil doré très fort, sur toute la carte --- */
.rarity-legendary {
  --gold: repeating-linear-gradient(115deg, #fff4c2 0%, #ffd34d 5%, #b8860b 10%, #ffe68f 15%, #8a5a00 20%, #ffcf40 25%, #fff4c2 30%);
}
.card.rarity-legendary:not(.unknown) {
  background: var(--grain), linear-gradient(135deg, #7a4f00 0%, #ffe58a 22%, #c8901a 40%, #fff3c0 55%, #a86e00 75%, #ffd34d 100%);
}
.rarity-legendary .fx-foil {
  background-image: var(--gold), repeating-linear-gradient(45deg, transparent 0 1.1cqw, rgba(255, 240, 180, 0.55) 1.1cqw 1.5cqw);
  background-size: 300% 300%, 100% 100%;
  -webkit-mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, rgba(0, 0, 0, 0.75) 45%, rgba(0, 0, 0, 0.45) 100%);
  mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, rgba(0, 0, 0, 0.75) 45%, rgba(0, 0, 0, 0.45) 100%);
  mix-blend-mode: overlay;
  opacity: 1;
}
.rarity-legendary .card-art .fx-foil { opacity: 0.6; }
.rarity-legendary .fx-shine {
  background-image: var(--gold);
  background-size: 300% 300%;
  -webkit-mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, transparent 50%);
  mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, transparent 50%);
  opacity: 0.6;
}
.rarity-legendary .card-art .fx-shine { opacity: 0.35; }
.rarity-legendary .fx-glitter {
  filter: sepia(1) saturate(5) hue-rotate(-12deg) brightness(1.2);
  -webkit-mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, rgba(0, 0, 0, 0.6) 35%, rgba(0, 0, 0, 0.15) 75%);
  mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, rgba(0, 0, 0, 0.6) 35%, rgba(0, 0, 0, 0.15) 75%);
}

/* --- Vernis « papier glacé » sur toutes les cartes : point chaud + traînée de reflet --- */
.fx-gloss {
  z-index: 2;
  background: radial-gradient(farthest-corner circle at var(--mx) var(--my), rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0.55) 16%, rgba(255, 255, 255, 0) 42%, rgba(0, 0, 0, 0.12) 100%);
  mix-blend-mode: overlay;
  opacity: var(--gloss, 0.45);
}
/* Point chaud : éclat blanc franc là où tombe la lumière */
.fx-gloss::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--mx) var(--my), rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0.35) 9%, rgba(255, 255, 255, 0) 26%);
  mix-blend-mode: screen;
  opacity: var(--hotspot, 0.25);
}
/* Traînée de reflet diagonale, comme sur un papier glacé */
.fx-gloss::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(115deg, transparent 40%, rgba(255, 255, 255, 0.3) 46%, rgba(255, 255, 255, 1) 50%, rgba(255, 255, 255, 0.3) 54%, transparent 60%),
    linear-gradient(115deg, transparent 56%, rgba(255, 255, 255, 0.5) 58%, transparent 61%);
  background-size: 300% 300%;
  background-position: calc(100% - var(--mx)) calc(100% - var(--my));
  mix-blend-mode: screen;
  opacity: var(--streak, 0.2);
}
.rarity-uncommon { --gloss: 0.6; --hotspot: 0.35; --streak: 0.3; }
.rarity-rare { --gloss: 0.6; --hotspot: 0.45; --streak: 0.45; }
.rarity-superrare { --gloss: 0.75; --hotspot: 0.6; --streak: 0.6; }
.rarity-legendary { --gloss: 0.9; --hotspot: 0.75; --streak: 0.8; }
/* Dans la grille, seules les Rare et + gardent la lumière animée (perf mobile) */
.grid .rarity-common .fx-gloss, .grid .rarity-uncommon .fx-gloss { animation: none; }

/* --- Étincelles (Super rare) --- */
.fx-sparkles { z-index: 3; }
.fx-sparkles i {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--s);
  height: var(--s);
  margin: calc(var(--s) / -2) 0 0 calc(var(--s) / -2);
  background: radial-gradient(circle, #fff 0 25%, #f1e4ff 45%, rgba(190, 150, 255, 0) 75%);
  clip-path: polygon(50% 0, 56% 44%, 100% 50%, 56% 56%, 50% 100%, 44% 56%, 0 50%, 44% 44%);
  transform: scale(0);
  animation: twinkle var(--t) ease-in-out var(--d) infinite;
}
.rarity-superrare { animation: sr-glow 2.6s ease-in-out infinite; }

/* --- Flammes (Légende) : derrière la carte, elles débordent du pourtour --- */
.rarity-legendary { animation: legend-glow 1.8s ease-in-out infinite; }
.fx-flames { position: absolute; inset: 0; z-index: -1; pointer-events: none; }
.fx-flames::before {
  /* braise continue autour de la carte */
  content: "";
  position: absolute;
  inset: -1.5%;
  border-radius: 6% / 4.5%;
  box-shadow: 0 0 5cqw 2.5cqw rgba(255, 110, 20, 0.7), 0 -3cqw 9cqw 3cqw rgba(255, 190, 60, 0.35);
  animation: ember 0.9s ease-in-out infinite alternate;
}
.fx-flames i {
  position: absolute;
  width: var(--w);
  aspect-ratio: 2 / 3;
  margin: calc(var(--w) * -0.9) 0 0 calc(var(--w) / -2);
  background: radial-gradient(ellipse 48% 58% at 50% 68%, #fff6d0 0%, #ffd34d 22%, #ff7a1a 46%, rgba(220, 45, 10, 0.55) 62%, transparent 72%);
  border-radius: 50% 50% 45% 45% / 70% 70% 30% 30%;
  mix-blend-mode: screen;
  opacity: 0;
  animation: flame-up var(--t) ease-in var(--d) infinite;
}

/* Tailles de contexte */
.grid .fx-flames i:nth-child(2n) { display: none; } /* moins de particules dans la grille (perf mobile) */
.grid .card, .summary-cards .card { --edge: 2px; }
.grid .card[data-id] { cursor: zoom-in; }
/* ~2000 cartes : on ne rend que celles proches de l’écran */
.grid > .card:not(.rarity-legendary, .rarity-superrare) { content-visibility: auto; contain-intrinsic-size: auto 160px auto 224px; }

/* ---------- Collection ---------- */

#view-collection { padding: 12px 12px 24px; }

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  position: sticky;
  top: -12px;
  padding: 12px 0 8px;
  margin-top: -12px;
  background: var(--bg);
  z-index: 4;
}
.filters select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font: inherit;
  font-size: 0.9rem;
  min-width: 0;
}
.toggle { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--muted); }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.collection-stats { font-size: 0.8rem; color: var(--muted); margin: 4px 0 12px; }
.bar { height: 6px; background: var(--panel); border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
.bar div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--legendary)); border-radius: 999px; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.odds { margin-top: 24px; background: var(--panel); border-radius: 12px; padding: 12px 16px; }
.odds summary { cursor: pointer; font-weight: 600; }
.odd { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; padding: 3px 0; }
.odd:first-child { margin-top: 10px; }
.odd small { grid-column: 2 / 4; color: var(--muted); margin-top: -4px; }
.odd .rarity-icon { width: 12px; height: 12px; }
.note { color: var(--muted); font-size: 0.85rem; margin: 10px 0 0; }

footer { text-align: center; color: var(--muted); font-size: 0.75rem; padding: 24px 8px 0; }

.zoom {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 20;
  padding: 16px;
  animation: fade-up 0.2s;
}
.zoom .card { width: min(80vw, 340px, 62dvh); --edge: 4px; transition: transform 0.15s; }

/* ---------- Écrans plus larges ---------- */

@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .filters { grid-template-columns: 1fr 1fr auto; }
  .toggle { grid-column: auto; }
  .summary-cards { grid-template-columns: repeat(5, 1fr); }
  .summary-actions { flex-direction: row; justify-content: center; }
  #view-collection { max-width: 1100px; margin: 0 auto; }
}

/* ---------- Animations ---------- */

@keyframes shine { 0% { transform: translateX(-100%); } 60%, 100% { transform: translateX(100%); } }
@keyframes swipe-hint { 0%, 100% { transform: translateX(-10px); } 50% { transform: translateX(14px); } }
@keyframes tear-off {
  to { transform: translate(60%, -180%) rotate(28deg); opacity: 0; }
}
@keyframes pack-drop {
  to { transform: translateY(120%) rotate(-4deg); opacity: 0; }
}
@keyframes stack-rise {
  from { transform: translateY(18%) scale(0.92); }
  60% { transform: translateY(-12%) scale(1); }
  to { transform: translateY(0); }
}
@keyframes pack-enter {
  from { transform: translateY(60%) scale(0.85); opacity: 0; }
}
@keyframes burst {
  0% { transform: scale(0.6); opacity: 1; }
  100% { transform: scale(1.2); opacity: 0.4; }
}
@keyframes light-move {
  0%, 100% { --mx: 18%; --my: 12%; }
  25% { --mx: 85%; --my: 28%; }
  50% { --mx: 72%; --my: 88%; }
  75% { --mx: 22%; --my: 70%; }
}
@keyframes twinkle {
  0%, 100% { transform: scale(0) rotate(0deg); opacity: 0; }
  35% { transform: scale(1) rotate(45deg); opacity: 1; }
  42% { transform: scale(0.45) rotate(60deg); opacity: 0.6; }
  50% { transform: scale(1.25) rotate(90deg); opacity: 1; }
  70% { transform: scale(0) rotate(135deg); opacity: 0; }
}
@keyframes flame-up {
  0% { transform: translate(0, 0) scale(0.5); opacity: 0; }
  15% { opacity: 1; }
  50% { transform: translate(calc(var(--dx) * 0.5), -12cqw) scale(0.75, 0.9); }
  100% { transform: translate(var(--dx), -24cqw) scale(0.15) rotate(10deg); opacity: 0; }
}
@keyframes ember {
  from { opacity: 0.75; }
  to { opacity: 1; transform: scale(1.01); }
}
@keyframes legend-glow {
  50% { filter: drop-shadow(0 0 12px rgba(255, 120, 20, 0.75)); }
}
@keyframes sr-glow {
  50% { filter: drop-shadow(0 0 10px rgba(192, 132, 252, 0.6)); }
}
@keyframes fade-up { from { opacity: 0; transform: translateY(16px); } }
