:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev-2: #1e222b;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --text-dim: #9aa1b1;
  --accent: #ffcb05;      /* giallo Pokémon */
  --accent-ink: #1d1d1d;
  --blue: #3b6cf0;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: min(1400px, 100% - 2rem); margin-inline: auto; }

/* ---------- header ---------- */
.site-header {
  padding: 2.4rem 0 1.6rem;
  background:
    radial-gradient(900px 320px at 15% -40%, rgba(255,203,5,.16), transparent 60%),
    radial-gradient(700px 300px at 85% -30%, rgba(59,108,240,.18), transparent 60%),
    var(--bg);
  border-bottom: 1px solid var(--line);
}

.site-header h1 {
  margin: 0 0 .5rem;
  font-size: clamp(1.6rem, 4vw, 2.5rem);
  letter-spacing: -.02em;
}

.tagline { margin: 0; color: var(--text-dim); font-size: .97rem; }
.tagline strong { color: var(--accent); font-variant-numeric: tabular-nums; }
.tagline .hint { display: block; margin-top: .45rem; font-size: .87rem; opacity: .75; }

/* ---------- toolbar ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15,17,21,.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.toolbar-inner {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem;
  align-items: center;
  padding: .7rem 0;
}

.search-box { position: relative; flex: 1 1 260px; min-width: 200px; display: flex; align-items: center; }
.search-box svg {
  position: absolute; left: .7rem; width: 17px; height: 17px;
  fill: none; stroke: var(--text-dim); stroke-width: 2; stroke-linecap: round; pointer-events: none;
}
.search-box input {
  width: 100%;
  padding: .58rem .58rem .58rem 2.2rem;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  font-size: .93rem;
}
.search-box input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute; right: .35rem;
  border: 0; background: none; color: var(--text-dim);
  font-size: 1.3rem; line-height: 1; cursor: pointer; padding: .1rem .35rem;
}
.search-clear:hover { color: var(--text); }

select {
  padding: .58rem 1.9rem .58rem .7rem;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg-elev) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%239aa1b1' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right .65rem center/11px;
  color: var(--text);
  font-size: .9rem;
  appearance: none;
  cursor: pointer;
  max-width: 220px;
}

input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.toggle {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem .75rem;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg-elev);
  font-size: .88rem; cursor: pointer; user-select: none;
  white-space: nowrap;
}
.toggle input { accent-color: var(--accent); margin: 0; cursor: pointer; }
.toggle:has(input:checked) { border-color: var(--accent); color: var(--accent); }

.btn-reset {
  padding: .5rem .8rem;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-dim);
  font-size: .86rem;
  cursor: pointer;
}
.btn-reset:hover { color: var(--text); border-color: var(--text-dim); }

.result-count {
  margin: 1.1rem 0 .8rem;
  color: var(--text-dim);
  font-size: .88rem;
}

/* ---------- griglia ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  padding-bottom: 3rem;
}

.card {
  position: relative;
  border: 0;
  padding: 0;
  background: var(--bg-elev);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: zoom-in;
  text-align: left;
  color: inherit;
  font: inherit;
  transition: transform .16s ease, box-shadow .16s ease;
}
.card:hover, .card:focus-visible {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.card-img {
  position: relative;
  aspect-ratio: 245 / 342;
  background: var(--bg-elev-2);
  overflow: hidden;
}
.card-img img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .28s ease;
}
.card-img img.loaded { opacity: 1; }

.badge-qty {
  position: absolute; top: .4rem; right: .4rem;
  background: var(--accent); color: var(--accent-ink);
  font-size: .7rem; font-weight: 700;
  padding: .12rem .38rem; border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.card-body { padding: .5rem .6rem .6rem; }
.card-name {
  font-size: .87rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Il set distingue carte con lo stesso nome (i tre Arbok, ecc.): deve leggersi
   a colpo d'occhio, non essere una scritta grigia di servizio. */
.card-set {
  margin-top: .18rem;
  font-size: .77rem; font-weight: 600; color: var(--accent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-num {
  font-size: .72rem; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.empty { text-align: center; color: var(--text-dim); padding: 3rem 0 5rem; line-height: 2.2; }

.site-footer {
  border-top: 1px solid var(--line);
  padding: 1.6rem 0 2.4rem;
  color: var(--text-dim);
  font-size: .84rem;
}
.site-footer p { margin: 0; }

/* ---------- lightbox ---------- */
.lb {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8,9,12,.96);
  display: grid;
  grid-template-columns: 1fr 320px;
}
.lb[hidden] { display: none; }

.lb-stage {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: grab;
}
.lb-stage.panning { cursor: grabbing; }

#lbImg {
  max-width: 92%;
  max-height: 92%;
  border-radius: 10px;
  box-shadow: 0 12px 48px rgba(0,0,0,.7);
  transform-origin: 0 0;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}
#lbImg.loading { opacity: .25; }

.lb-spinner {
  position: absolute;
  width: 34px; height: 34px;
  border: 3px solid rgba(255,255,255,.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.lb-panel {
  border-left: 1px solid var(--line);
  background: var(--bg-elev);
  padding: 2.6rem 1.3rem 1.3rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  overflow-y: auto;
}

.lb-info h2 { margin: 0 0 .35rem; font-size: 1.3rem; letter-spacing: -.01em; }
.lb-meta { margin: 0; color: var(--text-dim); font-size: .88rem; line-height: 1.7; }
.lb-meta b { color: var(--text); font-weight: 600; }
.lb-notes {
  margin: .6rem 0 0; padding: .55rem .7rem;
  background: var(--bg-elev-2); border-left: 2px solid var(--accent);
  border-radius: 0 6px 6px 0;
  font-size: .84rem; color: var(--text-dim);
}

.lb-controls { display: flex; flex-direction: column; gap: .6rem; }

.seg {
  display: flex;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 3px;
  gap: 3px;
  flex-wrap: wrap;
}
.seg button {
  flex: 1 1 auto;
  min-width: 62px;
  padding: .45rem .5rem;
  border: 0; border-radius: 6px;
  background: transparent; color: var(--text-dim);
  font-size: .85rem; font-weight: 600; cursor: pointer;
  transition: background .12s, color .12s;
}
.seg button:hover { color: var(--text); }
.seg button.is-active { background: var(--accent); color: var(--accent-ink); }

.zoom-controls {
  display: flex; align-items: center; gap: .5rem;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: .3rem .5rem;
}
.zoom-controls button {
  width: 30px; height: 30px;
  border: 0; border-radius: 6px;
  background: var(--line); color: var(--text);
  font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.zoom-controls button:hover { background: #39404f; }
.zoom-controls span {
  flex: 1; text-align: center;
  font-size: .82rem; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.lb-hint { margin: auto 0 0; font-size: .74rem; color: var(--text-dim); line-height: 1.9; }
kbd {
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: 4px; padding: .05rem .3rem; font-size: .72rem; font-family: inherit;
}

.lb-close, .lb-nav {
  position: absolute; z-index: 2;
  border: 0; border-radius: 50%;
  background: rgba(255,255,255,.08);
  color: #fff; cursor: pointer;
  display: grid; place-items: center;
  transition: background .14s;
}
.lb-close:hover, .lb-nav:hover { background: rgba(255,255,255,.2); }

.lb-close { top: .8rem; right: 336px; width: 38px; height: 38px; font-size: 1.5rem; }
.lb-nav { top: 50%; transform: translateY(-50%); width: 46px; height: 46px; font-size: 2rem; padding-bottom: .2rem; }
.lb-prev { left: 1rem; }
.lb-next { left: auto; right: calc(320px + 1rem); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .lb { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .lb-panel {
    border-left: 0; border-top: 1px solid var(--line);
    padding: .9rem 1rem 1.1rem;
    max-height: 46vh;
  }
  .lb-hint { display: none; }
  .lb-close { right: .8rem; top: .8rem; }
  .lb-next { right: 1rem; }
  .lb-nav { width: 40px; height: 40px; font-size: 1.7rem; }
  .lb-info h2 { font-size: 1.1rem; }
}

@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .7rem; }
  .toolbar-inner { gap: .45rem; }
  select { flex: 1 1 45%; max-width: none; font-size: .84rem; }
  .site-header { padding: 1.6rem 0 1.2rem; }
}

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