/* ── overlay: full-screen dimmer that centres the modal ── */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, .75);
  -webkit-backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#modal-overlay.open {
  display: flex;
}

/* ── modal: the single scrollable card container ── */
#modal {
  position: relative;
  width: min(424px, 100%);
  max-height: 100%;
  background: #1e1e23;
  border-radius: 20px;
  /* one natural vertical scroll — image on top, details below */
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  animation: modal-in .18s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── mobile: fill the screen, flush edges ── */
@media (max-width: 480px) {
  #modal-overlay {
    padding: 0;
    background: #0e1116;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  #modal {
    width: 100%;
    /* dvh tracks the *visible* viewport as the mobile URL bar shows/hides,
       so the modal never ends up a few px taller than the screen (which
       would trigger a phantom scrollbar). vh is the fallback. */
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    animation: none;
  }
  /* content fills the screen when short (no scrollbar), scrolls when tall */
  #modal .m-body {
    min-height: 100vh;
    min-height: 100dvh;
    box-sizing: border-box;
    max-height: 100vh;
    max-height: 100dvh;
  }
}

/* ── zoom lightbox: full-screen card art on top of everything ── */
#zoom-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, .92);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  /* scroll container: image sits at native size, drag to pan when it overflows */
  overflow: auto;
  overscroll-behavior: contain;
  cursor: grab;
  touch-action: none; /* JS owns panning so a tap can still dismiss */
}
#zoom-overlay:active { cursor: grabbing; }
#zoom-overlay.open {
  display: grid;
  place-items: center;
  animation: zoom-in .18s ease;
}
#zoom-overlay .zoom-img {
  /* native resolution — never scaled down to fit */
  display: block;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  /* padding around the card via margin so it can be centred/panned with breathing room */
  margin: 24px;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.7);
  user-select: none;
  -webkit-user-drag: none;
}
@keyframes zoom-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── close button ── */
.m-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: rgba(255,255,255,.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 2;
  transition: color .15s;
}
.m-close svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  fill: none;
}
.m-close:hover {
  color: #fff;
}

/* ── prev / next navigation arrows ── */
.m-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 50%;
  background: rgba(30,30,35,.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: rgba(255,255,255,.8);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 210;
  transition: background .15s, color .15s, opacity .15s, transform .15s;
}
.m-nav svg {
  width: 26px;
  height: 26px;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.m-nav:hover:not(:disabled) {
  background: rgba(45,45,52,.8);
  color: #fff;
}
.m-nav:disabled {
  opacity: .28;
  cursor: default;
}
.m-nav[hidden] {
  display: none;
}
/* flank the modal: modal is max 424px wide + 24px overlay padding */
.m-nav--prev { left: max(16px, calc(50% - 212px - 68px)); }
.m-nav--next { right: max(16px, calc(50% - 212px - 68px)); }

/* ── position counter (e.g. "01 / 30") ── */
/* desktop: centred horizontally, below and outside the modal near the bottom
   of the overlay. Mobile overrides this to the bottom bar. */
.m-count {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 210;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  letter-spacing: .12em;
  color: rgba(255,255,255,.55);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  user-select: none;
}
.m-count[hidden] { display: none; }


/* ── body layout: single column ── */
.m-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 28px 32px 32px;
  align-items: stretch;
}

/* ── art panel ── */
.m-art {
  flex: none;
  width: 100%;
  display: flex;
  justify-content: center;
}
/* skeleton frame: reserves the card's exact footprint so nothing jumps */
.m-art-frame {
  width: 82%;
  max-width: 300px;
  /* Fixed ratio for EVERY card — loading or loaded. This guarantees an
     identical footprint so nothing below ever shifts by a pixel or two when a
     slightly different-ratio image loads in. The image fills it via
     object-fit: cover (see .m-art-img). */
  aspect-ratio: 2.5 / 3.5;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.6);
  overflow: hidden;
  background: #27272d;
  background-image: linear-gradient(100deg,
    rgba(255,255,255,0) 30%,
    rgba(255,255,255,.06) 50%,
    rgba(255,255,255,0) 70%);
  background-size: 220% 100%;
  animation: m-shimmer 1.3s ease-in-out infinite;
}
.m-art-img {
  width: 100%;
  height: 100%;
  /* cover, not contain: fill the fixed frame edge-to-edge so no card ever
     letterboxes (which read as "smaller"). Card ratios are near-identical, so
     the crop is a sub-pixel sliver at most. */
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .28s ease;
  cursor: zoom-in;
}
.m-art-img.is-loaded {
  opacity: 1;
}
/* once loaded, stop the shimmer so it doesn't bleed through transparent PNGs.
   The frame keeps its fixed aspect-ratio so the footprint never changes. */
.m-art-frame:has(.m-art-img.is-loaded) {
  background-image: none;
  animation: none;
}

@keyframes m-shimmer {
  from { background-position: 180% 0; }
  to   { background-position: -80% 0; }
}
.m-no-art {
  width: 82%;
  max-width: 300px;
  aspect-ratio: 2.5 / 3.5;
  border-radius: 14px;
  background: #27272d;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: rgba(255,255,255,.3);
  text-align: center;
  padding: 16px;
}

/* ── details panel ── */
.m-details {
  flex: 1;
  min-width: 0;
  padding-top: 4px;
}

.m-name {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  margin: 0 0 16px;
  line-height: 1.15;
}

/* ── single-table details ── */
.m-rows {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-radius: 0px;
  overflow: hidden;
  font-family: 'Manrope', sans-serif;
  font-size: 13px;
  font-weight: 600;
}

.m-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 10px;
  background: rgba(255,255,255,.02);
}
/* zebra striping for a compact, readable table */
/* .m-row:nth-child(even) {
  background: rgba(255,255,255,.05);
} */

.m-label, .m-value {
  padding-top: 0;
}

.m-label {
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.38);
  flex: none;
}

.m-value {
  text-align: right;
  color: #fff;
}

.m-text {
  padding-right: 0;
}


/* ── clickable links ── */
.m-link {
  background: rgba(255,255,255,.06);
  border: none;
  padding: 4px 10px;
  border-radius: 6px;
  font: inherit;
      font-size: 13px;
  color: inherit;
  cursor: pointer;
  transition: background .15s;
  text-align: right;
  text-decoration: none;
}
.m-link:hover {
  background: rgba(255,255,255,.12);
}
.m-link--type {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.m-icon {
  flex: none;
  object-fit: contain;
}
.m-icon--type {
  width: 18px;
  height: 18px;
}
.m-icon-wrap {
  display: inline-flex;
  align-items: center;
  flex: none;
}
.m-icon-wrap .m-icon--type {
  fill: currentColor;
}

/* ── rarity badge ── */
.m-link--rarity {
  border-radius: 6px;
  padding: 3px 10px;
  letter-spacing: .03em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.rarity-common                { background: rgba(180,180,180,.12); color: #b0b0b0; }
.rarity-uncommon              { background: rgba(120,190,120,.12); color: #7ec87e; }
.rarity-rare                  { background: rgba(100,160,240,.12); color: #6ea8f0; }
.rarity-double                { background: rgba(100,160,240,.14); color: #6ea8f0; }
.rarity-ultra                 { background: rgba(240,180, 60,.12); color: #f0c040; }
.rarity-hyper                 { background: rgba(220,100,220,.13); color: #e070e0; }
.rarity-illustration          { background: rgba(100,220,200,.12); color: #50d8c0; }
.rarity-special-illustration  { background: rgba(100,220,200,.16); color: #50d8c0; }
.rarity-promo                 { background: rgba(240,120, 80,.12); color: #f07850; }

/* ── rarity SVG icons ── */
.m-rarity-icon {
  width: 14px;
  height: 14px;
  flex: none;
  fill: currentColor;
}
.m-rarity-multi {
  display: inline-flex;
  align-items: center;
  gap: 1px;
}
.m-rarity-multi .m-rarity-icon {
  width: 12px;
  height: 12px;
}
.ri-common   { fill: currentColor; }
.ri-uncommon { fill: currentColor; }
.ri-black    { fill: currentColor; }
.ri-ultra    { fill: none; stroke: currentColor; stroke-width: 2.5; }
.ri-gold     { fill: #f0c040; }
.ri-promo    { fill: #f07850; }
.rarity-unknown      { background: rgba(255,255,255,.06); color: rgba(255,255,255,.5); }

/* ── prices (fits inside .m-row like other fields) ── */
.m-price-vals {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 4px 14px;
  align-items: baseline;
  justify-content: flex-end;
}

.m-price-printing {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
}

.m-price-printing-label {
  font-size: 11px;
  color: rgba(255,255,255,.35);
}

.m-price-market {
  color: #a3d9a5;
  font-size: 13px;
  font-weight: bold;
}

.m-price-sub {
  font-size: 11px;
  color: rgba(255,255,255,.3);
}

/* ── responsive: same image-top / details-below layout, tuned for phones ── */
@media (max-width: 480px) {
  .m-body {
    padding: 20px 20px 96px; /* leave room for the floating nav arrows */
    gap: 4px;
  }

  /* Drive the card off a FIXED height in vh, and let width follow from the
     aspect-ratio. The vertical footprint (which is what pushes the stats down)
     is then locked regardless of the .m-body width fluctuating with the mobile
     URL bar / scrollbar state. Override every width-based rule so nothing else
     can resize it. */
  .m-art-frame, .m-no-art {
    height: 48vh;
    width: auto;
    max-width: none;
    aspect-ratio: 2.5 / 3.5;
    flex: none;
  }

  /* arrows float over the card, pinned to the bottom corners (thumb reach) */
  .m-nav {
    top: auto;
    transform: none;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    width: 48px;
    height: 48px;
  }
  .m-nav--prev { left: 20px; }
  .m-nav--next { right: 20px; }

  /* counter drops to the bottom bar, vertically centred on the 48px arrows */
  .m-count {
    top: auto;
    bottom: calc(16px + 14px + env(safe-area-inset-bottom, 0px));
  }

  .m-name {
    font-size: 20px;
    margin: 0 0 16px;
  }

  .m-rows {
    font-size: 12px;
  }

  .m-row {
    padding: 5px 8px;
    gap: 8px;
  }

  .m-label {
    font-size: 10px;
    letter-spacing: .08em;
  }

  .m-value {
    font-size: 12px;
  }

  .m-link {
    font-size: 12px;
    padding: 3px 8px;
  }

  .m-price-market {
    font-size: 12px;
  }

  .m-price-printing-label {
    font-size: 10px;
  }

  /* ── card-to-card slide (mobile only) ──
     On navigate, the incoming card slides + fades in from the side you're
     heading toward, so it reads as one card leaving and the next arriving.
     Only the .m-body animates — the modal shell, backdrop and nav arrows stay
     put. Kept short so browsing many cards still feels fast. */
  .m-body--in-next { animation: m-card-in-next .26s cubic-bezier(.22,.61,.36,1); }
  .m-body--in-prev { animation: m-card-in-prev .26s cubic-bezier(.22,.61,.36,1); }
}

@keyframes m-card-in-next {
  from { opacity: 0; transform: translateX(28px); }
  to   { opacity: 1; transform: none; }
}
@keyframes m-card-in-prev {
  from { opacity: 0; transform: translateX(-28px); }
  to   { opacity: 1; transform: none; }
}

/* respect users who ask for less motion */
@media (prefers-reduced-motion: reduce) {
  .m-body--in-next,
  .m-body--in-prev { animation: none; }
}
