/* =====================================================================
   Carte à collectionner. Toutes les dimensions internes sont en cqw
   (pourcentage de la largeur de la carte) : la carte s'adapte à toute taille.
   ===================================================================== */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(200px * var(--fs)), 1fr)); gap: 18px; }
@media (max-width: 520px) { .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }

.cd {
  --rc: var(--r-common);
  --frame: var(--rc);
  container-type: inline-size;
  position: relative; width: 100%; aspect-ratio: 5 / 7.2;
  border-radius: 5% / 3.5%; user-select: none; cursor: pointer;
  transition: transform .18s ease;
}
.cd.static { cursor: default; }
.cd:not(.static):hover { transform: translateY(-4px); }
.cd .frame {
  position: absolute; inset: 0; border-radius: inherit; padding: 2.2cqw; background: var(--frame);
  box-shadow: 0 2px 4px rgba(0,0,0,.25), 0 14px 30px -12px color-mix(in srgb, var(--rc) 70%, transparent);
}
.cd .face { position: relative; height: 100%; border-radius: 3.6cqw; overflow: hidden; background: var(--card-face); color: var(--card-ink); display: flex; flex-direction: column; }
.cd.r-uncommon { --rc: var(--r-uncommon); }
.cd.r-rare { --rc: var(--r-rare); }
.cd.r-epic { --rc: var(--r-epic); --frame: linear-gradient(150deg, #c9a2ff, var(--r-epic) 45%, #5c1fb0); }
.cd.r-legendary { --rc: var(--r-legendary); --frame: linear-gradient(150deg, #ffe7a0, #f0b01a 35%, #a86800 65%, #ffd76a); }

.cd-top { display: flex; align-items: center; justify-content: space-between; padding: 3.6cqw 4.4cqw 2.4cqw; gap: 2cqw; }
.cd-rarity { display: inline-flex; align-items: center; gap: 1.6cqw; font-size: 4.4cqw; font-weight: 820; letter-spacing: .09em; text-transform: uppercase; color: var(--rc); }
.cd-rarity .ri { width: 4.6cqw; height: 4.6cqw; flex: none; }
.cd-badges { display: flex; gap: 1.6cqw; }
.cd-badge { font-size: 3.8cqw; font-weight: 760; padding: .6cqw 2.2cqw; border-radius: 1.8cqw; background: var(--card-face-2); color: var(--card-ink-2); }
.cd-badge.capital { background: var(--card-ink); color: var(--card-face); }
.cd .cd-badge.level { background: linear-gradient(180deg, #fff, #dfe6f5); color: #1b2436; font-weight: 820; }

.cd-art { position: relative; margin: 0 4.4cqw; height: 45%; border-radius: 2.8cqw; overflow: hidden; background: var(--card-face-2); }
.cd-art img.photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .35s; }
.cd-art img.photo.loaded { opacity: 1; }
.cd-art .globe-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cd-no { position: absolute; left: 2.6cqw; bottom: 2.2cqw; font-size: 3.6cqw; font-weight: 720; color: #fff; background: rgba(8,12,20,.62); padding: .4cqw 2cqw; border-radius: 1.6cqw; }

.cd-title { padding: 3.4cqw 4.4cqw 0; }
.cd-title h3 { font-size: 8.4cqw; font-weight: 800; letter-spacing: -0.025em; line-height: 1.08; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cd-country { display: flex; align-items: center; gap: 2.2cqw; margin-top: 1.4cqw; font-size: 4.4cqw; color: var(--card-ink-2); white-space: nowrap; overflow: hidden; }
.cd-country .flag { width: 6.4cqw; height: 4.8cqw; border-radius: .8cqw; flex: none; vertical-align: 0; }
.cd-country span { overflow: hidden; text-overflow: ellipsis; }

.cd-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1.8cqw 3cqw; padding: 3.2cqw 4.4cqw 0; margin: 0; }
.cd-stats div { min-width: 0; }
.cd-stats dt { font-size: 3.4cqw; color: var(--card-ink-2); font-weight: 680; text-transform: uppercase; letter-spacing: .06em; opacity: .85; }
.cd-stats dd { margin: .2cqw 0 0; font-size: 5.1cqw; font-weight: 720; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cd-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 2cqw; padding: 2.6cqw 4.4cqw; border-top: 1px solid var(--card-line); background: var(--card-face-2); }
.cd-income { display: flex; align-items: center; gap: 1.6cqw; font-size: 5.6cqw; font-weight: 820; color: var(--coin-ink); font-variant-numeric: tabular-nums; }
.cd-income .coin { width: 5.6cqw; height: 5.6cqw; }
.cd-income small { font-size: 3.8cqw; font-weight: 650; color: var(--card-ink-2); }

.cd-ribbon { position: absolute; top: -3.2cqw; left: 50%; transform: translateX(-50%); white-space: nowrap; z-index: 3; font-size: 4.2cqw; font-weight: 820; padding: 1cqw 3.4cqw; border-radius: 99px; background: var(--accent); color: #fff; box-shadow: var(--shadow); letter-spacing: .03em; }
.cd-ribbon.duplicate { background: var(--surface-3); color: var(--text-2); }
.cd-count { position: absolute; top: -2.4cqw; right: -2.4cqw; z-index: 3; min-width: 10cqw; height: 10cqw; border-radius: 99px; padding: 0 2.4cqw; display: grid; place-items: center; background: var(--text); color: var(--bg); font-size: 4.6cqw; font-weight: 780; }

/* =====================================================================
   Couche d'effets (.cd-foil) : aucune animation permanente (une collection affiche des dizaines de
   cartes). Chaque rareté a sa texture fixe (::before) ; le reflet et les étoiles (::after)
   n'apparaissent que sur la carte qui bouge sous le pointeur ou le doigt (classe .lit, posée par
   card.js, avec la position --mx / --my).
     Rare : fines stries bleutées, léger reflet ;
     Épique : stries violettes et dorées, paillettes, reflet moyen et petites étoiles ;
     Légendaire : film doré, paillettes denses, reflet intense et grandes étoiles ;
     Irisée : arc-en-ciel texturé et reflet prismatique.
   ===================================================================== */
.cd-foil { position: absolute; inset: 0; z-index: 2; pointer-events: none; border-radius: inherit; display: none; }
.cd-foil::before, .cd-foil::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.cd.r-rare .cd-foil, .cd.r-epic .cd-foil, .cd.r-legendary .cd-foil, .cd.shiny .cd-foil { display: block; }

/* textures fixes */
.cd.r-rare .cd-foil::before {
  background: repeating-linear-gradient(115deg, rgba(190,225,255,.08) 0 .35cqw, transparent .35cqw 1.6cqw);
}
.cd.r-epic .cd-foil::before {
  background:
    linear-gradient(118deg, transparent 10%, rgba(200,140,255,.16) 24%, rgba(255,210,120,.12) 32%, transparent 44%,
      transparent 56%, rgba(170,130,255,.14) 68%, transparent 80%),
    repeating-linear-gradient(115deg, rgba(220,180,255,.09) 0 .35cqw, transparent .35cqw 1.5cqw),
    radial-gradient(circle, rgba(255,225,160,.45) 0 .14cqw, transparent .28cqw);
  background-size: 100% 100%, auto, 5.2cqw 4.8cqw;
}
.cd.r-legendary .cd-foil::before {
  background:
    linear-gradient(118deg, transparent 6%, rgba(255,230,150,.22) 20%, rgba(255,250,220,.18) 27%, transparent 38%,
      transparent 52%, rgba(255,200,80,.2) 64%, rgba(255,245,200,.14) 70%, transparent 82%),
    repeating-linear-gradient(115deg, rgba(255,225,140,.12) 0 .35cqw, transparent .35cqw 1.4cqw),
    radial-gradient(circle, rgba(255,248,210,.7) 0 .16cqw, transparent .3cqw),
    radial-gradient(circle, rgba(255,248,210,.5) 0 .12cqw, transparent .24cqw);
  background-size: 100% 100%, auto, 4.6cqw 4.2cqw, 3.1cqw 3.5cqw;
  background-position: 0 0, 0 0, 0 0, 1cqw 1.6cqw;
}

/* reflet : invisible au repos, suit le pointeur sur la carte qui bouge */
:root { --star: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 0C12.8 8 16 11.2 24 12C16 12.8 12.8 16 12 24C11.2 16 8 12.8 0 12C8 11.2 11.2 8 12 0Z' fill='white'/%3E%3C/svg%3E"); }
.cd-foil::after {
  opacity: 0;
  background:
    radial-gradient(circle at var(--mx, 50%) var(--my, 30%), rgba(255,255,255,var(--shine, .3)) 0, transparent 40%),
    linear-gradient(115deg, transparent calc(var(--mx, 50%) - 28%), var(--glare, rgba(255,255,255,.2)) var(--mx, 50%), transparent calc(var(--mx, 50%) + 28%));
}
.cd.lit .cd-foil::after { opacity: 1; mix-blend-mode: screen; transition: opacity .3s ease; }
.cd.r-rare { --shine: .22; --glare: rgba(150,205,255,.22); }
.cd.r-epic { --shine: .34; --glare: rgba(215,165,255,.32); }
.cd.r-legendary { --shine: .5; --glare: rgba(255,215,120,.42); }
/* étoiles : petites pour les Épiques, grandes pour les Légendaires et les Irisées */
.cd.r-epic .cd-foil::after, .cd.r-legendary .cd-foil::after, .cd.shiny .cd-foil::after {
  background:
    var(--star) 22% 16% / var(--s1) var(--s1) no-repeat, var(--star) 78% 38% / var(--s2) var(--s2) no-repeat,
    var(--star) 32% 72% / var(--s2) var(--s2) no-repeat, var(--star) 86% 84% / var(--s1) var(--s1) no-repeat,
    radial-gradient(circle at var(--mx, 50%) var(--my, 30%), rgba(255,255,255,var(--shine, .3)) 0, transparent 40%),
    linear-gradient(115deg, transparent calc(var(--mx, 50%) - 28%), var(--glare) var(--mx, 50%), transparent calc(var(--mx, 50%) + 28%));
}
.cd.r-epic { --s1: 3.4cqw; --s2: 2.4cqw; }
.cd.r-legendary { --s1: 7cqw; --s2: 5cqw; }

/* =====================================================================
   Irisée : cadre arc-en-ciel fixe, texture prismatique croisée, nom irisé ; reflet prismatique
   ===================================================================== */
.cd.shiny { --shine: .45; --glare: rgba(255,170,240,.4); --s1: 6cqw; --s2: 4.4cqw; }
.cd.shiny .frame {
  background: linear-gradient(115deg, #ff4d6d, #ff9f1c, #ffe14d, #3ddc84, #2ec4f5, #6a5cff, #d24dff, #ff4d6d);
  box-shadow: 0 0 0 1px rgba(255,255,255,.6) inset, 0 14px 38px -8px rgba(120,120,255,.55), 0 0 26px rgba(255,120,200,.35);
}
.cd.shiny .cd-foil::before {
  opacity: .5;
  background:
    repeating-linear-gradient(115deg,
      hsla(0, 100%, 65%, .4) 0%, hsla(40, 100%, 60%, .4) 3.5%, hsla(70, 100%, 60%, .4) 7%, hsla(140, 90%, 55%, .4) 10.5%,
      hsla(190, 100%, 60%, .4) 14%, hsla(240, 100%, 68%, .4) 17.5%, hsla(290, 100%, 66%, .4) 21%, hsla(340, 100%, 65%, .4) 24.5%, hsla(360, 100%, 65%, .4) 28%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.16) 0 1px, transparent 1px 2.6cqw),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.12) 0 1px, transparent 1px 2.6cqw),
    radial-gradient(circle, rgba(255,255,255,.6) 0 .2cqw, transparent .34cqw);
  background-size: 220% 220%, auto, auto, 4.6cqw 4.2cqw;
}
.cd.shiny .face { box-shadow: inset 0 0 0 1px rgba(255,255,255,.3); }
.cd.shiny .cd-title h3 {
  background: linear-gradient(90deg, #ffd1dc, #ffe8b0, #fffbb8, #c4ffd9, #bfefff, #d4ccff, #f6c9ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.45));
}
.cd-badge.shiny, .badge.shiny, .cd-ribbon.newShiny {
  background: linear-gradient(90deg, #ff4d6d, #ff9f1c, #ffe14d, #3ddc84, #2ec4f5, #6a5cff, #d24dff);
  color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.45);
}
@keyframes iris-frame { to { background-position: 400% 0; } }
:root[data-animations="off"] .cd.lit .cd-foil::after { opacity: 0; }

/* =====================================================================
   Couleur de rareté : toute la carte prend la teinte de sa rareté.
   ===================================================================== */
.cd:not(.catastrophe) .face {
  --card-ink: #fff; --card-ink-2: rgba(255,255,255,.78); --card-face-2: rgba(0,0,0,.2); --card-line: rgba(255,255,255,.16); --coin-ink: #ffe38a;
  background:
    radial-gradient(120% 70% at 15% 0%, color-mix(in srgb, var(--rc) 55%, #fff) 0%, transparent 55%),
    linear-gradient(165deg, color-mix(in srgb, var(--rc) 82%, #10131c), color-mix(in srgb, var(--rc) 38%, #07090f));
}
.cd:not(.catastrophe) .cd-rarity { color: #fff; }
.cd:not(.catastrophe):not(.shiny) .frame { background: linear-gradient(150deg, color-mix(in srgb, var(--rc) 45%, #fff), var(--rc)); }
.cd .cd-badge { background: rgba(255,255,255,.18); color: #fff; }

.cd.tilt { transition: transform .08s linear; }

/* Carte catastrophe : teinte par famille (--c1 clair, --c2 vif, --c3 sombre), ondes de choc
   animées autour de l'icône, bande d'alerte et effets en pastilles. */
.cd.catastrophe { --c1: #ffb3a8; --c2: #ef4f46; --c3: #6e1410; --rc: var(--c2); --frame: linear-gradient(150deg, var(--c1), var(--c2) 45%, var(--c3)); }
.cd.catastrophe.k-temporary { --c1: #ffd59a; --c2: #f58a1f; --c3: #6b3108; }
.cd.catastrophe.k-traffic { --c1: #c8c0ff; --c2: #7a68ff; --c3: #261a73; }
.cd.catastrophe.t-blizzard { --c1: #d6efff; --c2: #4aa8e8; --c3: #12385a; }
.cd.catastrophe.t-flood, .cd.catastrophe.t-tsunami, .cd.catastrophe.t-storm { --c1: #b6e6ff; --c2: #2d8fd6; --c3: #0c2c4f; }
.cd.catastrophe .face {
  color: #fff;
  background:
    radial-gradient(120% 60% at 50% 0%, color-mix(in srgb, var(--c2) 38%, transparent), transparent 70%),
    linear-gradient(180deg, color-mix(in srgb, var(--c3) 70%, #0b0d14), #0d0f16);
}
.cd.catastrophe .cd-rarity { color: var(--c1); }
.cd.catastrophe .cd-rarity svg { width: 4.6cqw; height: 4.6cqw; stroke-width: 2.4; }
.cd.catastrophe .cd-badge { background: color-mix(in srgb, var(--c2) 30%, rgba(0,0,0,.4)); color: #fff; }
.cd.catastrophe .cd-art {
  background:
    radial-gradient(circle at 50% 52%, color-mix(in srgb, var(--c2) 70%, transparent) 0%, transparent 58%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.04) 0 1px, transparent 1px 4cqw),
    repeating-linear-gradient(90deg, rgba(255,255,255,.04) 0 1px, transparent 1px 4cqw),
    color-mix(in srgb, var(--c3) 75%, #08090e);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c1) 25%, transparent);
}
.cd-cat-icon { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; }
.cd-cat-icon svg { width: 30cqw; height: 30cqw; stroke-width: 1.4; filter: drop-shadow(0 0 3cqw var(--c2)) drop-shadow(0 0 1cqw var(--c1)); }
.cat-waves { position: absolute; inset: 0; display: grid; place-items: center; }
.cat-waves i {
  grid-area: 1 / 1; width: 30cqw; aspect-ratio: 1; border-radius: 50%;
  border: .5cqw solid color-mix(in srgb, var(--c1) 70%, transparent);
  animation: cat-wave 3s ease-out infinite; opacity: 0;
}
.cat-waves i:nth-child(2) { animation-delay: 1s; }
.cat-waves i:nth-child(3) { animation-delay: 2s; }
@keyframes cat-wave { 0% { transform: scale(.6); opacity: .9; } 100% { transform: scale(2.6); opacity: 0; } }
.cat-stripes {
  position: absolute; left: 0; right: 0; bottom: 0; height: 3.4cqw; opacity: .85;
  background: repeating-linear-gradient(-45deg, var(--c2) 0 2.6cqw, #111 2.6cqw 5.2cqw);
}
.cd.catastrophe .cd-country { color: color-mix(in srgb, var(--c1) 80%, #fff); }
.cat-effects { list-style: none; margin: 0; padding: 2.8cqw 4.4cqw 0; display: flex; flex-wrap: wrap; gap: 1.6cqw; }
.cat-effects li {
  display: inline-flex; align-items: center; gap: 1.2cqw; padding: .9cqw 2.2cqw; border-radius: 99px;
  font-size: 3.6cqw; font-weight: 720; line-height: 1.2; white-space: nowrap;
  background: color-mix(in srgb, var(--c2) 22%, rgba(255,255,255,.06)); border: 1px solid color-mix(in srgb, var(--c1) 30%, transparent);
}
.cat-effects svg { width: 3.8cqw; height: 3.8cqw; flex: none; color: var(--c1); }
.cd.catastrophe .cd-foot {
  background: rgba(0,0,0,.28); border-top-color: color-mix(in srgb, var(--c1) 18%, transparent);
  font-size: 4cqw; color: color-mix(in srgb, var(--c1) 80%, #fff);
}
.cd.catastrophe .cd-foot b { color: #fff; font-size: 4.8cqw; font-variant-numeric: tabular-nums; }
:root[data-animations="off"] .cat-waves i { animation: none; opacity: .35; }
:root[data-animations="off"] .cat-waves i:nth-child(2) { transform: scale(1.6); opacity: .2; }
:root[data-animations="off"] .cat-waves i:nth-child(3) { display: none; }

/* Dos de carte */
.cd-back {
  container-type: inline-size; position: relative; width: 100%; aspect-ratio: 5 / 7.2; border-radius: 5% / 3.5%;
  background: radial-gradient(circle at 50% 35%, #26304a, #0b0f1a 70%); display: grid; place-items: center; overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255,255,255,.1) inset, 0 16px 34px -10px rgba(0,0,0,.7);
}
.cd-back::before {
  content: ""; position: absolute; inset: 5cqw; border-radius: 3cqw; border: 1px solid rgba(255,255,255,.14);
  background: repeating-radial-gradient(circle at 50% 50%, rgba(255,255,255,.05) 0 1px, transparent 1px 6cqw);
}
.cd-back .mark { position: relative; width: 36cqw; height: 36cqw; color: #fff; opacity: .92; }
.cd-back .word { position: absolute; bottom: 10cqw; left: 0; right: 0; text-align: center; font-weight: 800; color: rgba(255,255,255,.75); letter-spacing: .32em; font-size: 4.4cqw; }

/* Favori : étoile pleine dans le coin de la carte */
.cd-fav { position: absolute; top: -2.4cqw; left: -2.4cqw; z-index: 3; width: 10cqw; height: 10cqw; border-radius: 50%; display: grid; place-items: center;
  background: var(--coin); color: #3b2600; box-shadow: var(--shadow); }
.cd-fav .i { width: 6cqw; height: 6cqw; fill: currentColor; stroke: currentColor; }
.cd-fav .sr-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Dos de cartes (cosmétiques de la boutique) : appliqués à toute l'interface quand ils sont équipés,
   et aux aperçus de la boutique (.card-back-…). */
:root[data-card-back="night"] .cd-back:not(.plain), .card-back-night .cd-back {
  background: radial-gradient(1.2px 1.2px at 20% 30%, #fff, transparent), radial-gradient(1px 1px at 70% 20%, #fff, transparent),
    radial-gradient(1.4px 1.4px at 80% 70%, #fff, transparent), radial-gradient(1px 1px at 35% 80%, #fff, transparent),
    radial-gradient(circle at 50% 30%, #1d2a5c, #070a1a 75%); }
:root[data-card-back="gold"] .cd-back:not(.plain), .card-back-gold .cd-back {
  background: radial-gradient(circle at 50% 30%, #ffe7a0, #c88a12 55%, #6e4500); }
:root[data-card-back="gold"] .cd-back:not(.plain) .mark, .card-back-gold .cd-back .mark { color: #fff7dd; }
:root[data-card-back="holo"] .cd-back:not(.plain), .card-back-holo .cd-back {
  background: linear-gradient(135deg, #ff4d6d, #ffb347, #3ddc84, #2ec4f5, #a66bff, #ff4d6d); background-size: 300% 300%; animation: frame-flow 16s ease-in-out infinite; }
:root[data-animations="off"] .cd-back { animation: none; }
