.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  isolation: isolate;
}

.card {
  position: relative;
  background: linear-gradient(180deg, rgba(13, 18, 28, 0.98), rgba(8, 12, 20, 0.98));
  border: 1px solid rgba(165, 177, 198, 0.3);
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(41, 54, 74, 0.6), var(--shadow);
  padding: 6px;
  display: grid;
  gap: 6px;
  transform: translateY(0);
  opacity: 1;
  z-index: 1;
  /* Perf: skip layout/paint for offscreen cards (keeps scroll size stable). */
  content-visibility: auto;
  contain-intrinsic-size: 280px 260px;
}

.card.popover-active {
  z-index: 9000;
  /* Ensure popover card is fully rendered even if previously offscreen. */
  content-visibility: visible;
}

.card.next-in-line {
  border-color: rgba(38, 185, 109, 0.9);
  box-shadow:
    inset 0 0 0 1px rgba(41, 54, 74, 0.6),
    inset 0 0 0 1px rgba(38, 185, 109, 0.35),
    var(--shadow);
}

@keyframes card-jump-pulse {
  0% {
    box-shadow:
      inset 0 0 0 1px rgba(41, 54, 74, 0.6),
      inset 0 0 0 1px rgba(38, 185, 109, 0.35),
      0 0 0 0 rgba(38, 185, 109, 0.0),
      var(--shadow);
    transform: translateY(0);
  }
  30% {
    box-shadow:
      inset 0 0 0 1px rgba(41, 54, 74, 0.6),
      inset 0 0 0 1px rgba(38, 185, 109, 0.55),
      0 0 0 10px rgba(38, 185, 109, 0.16),
      var(--shadow);
    transform: translateY(-1px);
  }
  100% {
    box-shadow:
      inset 0 0 0 1px rgba(41, 54, 74, 0.6),
      inset 0 0 0 1px rgba(38, 185, 109, 0.35),
      0 0 0 22px rgba(38, 185, 109, 0.0),
      var(--shadow);
    transform: translateY(0);
  }
}

.card.card-jump-highlight {
  animation: card-jump-pulse 900ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.card.card-jump-highlight {
  /* ensure it's rendered even if it was just offscreen */
  content-visibility: visible;
}

.card.favorited {
  border-color: rgba(255, 203, 72, 0.92);
  box-shadow:
    inset 0 0 0 1px rgba(41, 54, 74, 0.6),
    inset 0 0 0 1px rgba(255, 203, 72, 0.28),
    var(--shadow);
}

.favorite-toggle {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border: 1px solid rgba(171, 186, 211, 0.4);
  border-radius: 4px;
  background: rgba(9, 13, 20, 0.9);
  color: rgba(214, 225, 241, 0.84);
  display: grid;
  place-items: center;
  font-size: 0.88rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  z-index: 2;
}

.favorite-toggle:hover,
.favorite-toggle:focus-visible {
  border-color: rgba(255, 203, 72, 0.78);
  color: rgba(255, 203, 72, 0.94);
  outline: none;
}

.favorite-toggle.checked {
  border-color: rgba(255, 203, 72, 0.9);
  color: rgba(255, 203, 72, 0.98);
}

.card.card-enter {
  transform: translateY(12px);
  opacity: 0;
  animation: rise-in 420ms ease forwards;
}

.card h2 {
  margin: 0;
  min-height: 42px;
  font-size: 0.9rem;
  line-height: 1.15;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #f2d5a5;
  text-shadow: 0 0 8px rgba(243, 157, 54, 0.22);
  display: grid;
  place-items: center;
  border: 1px solid rgba(188, 128, 56, 0.2);
  background: linear-gradient(180deg, rgba(42, 17, 10, 0.35), rgba(15, 11, 15, 0));
}

.art-frame {
  position: relative;
  height: 158px;
  background: radial-gradient(circle at 50% 42%, rgba(25, 39, 59, 0.52), rgba(7, 13, 22, 0.92));
  border: 1px solid rgba(126, 143, 165, 0.33);
  display: grid;
  place-items: center;
  padding: 8px;
}

.item-art {
  max-width: 100%;
  max-height: 144px;
  object-fit: contain;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5));
  opacity: 1;
  transition: opacity 160ms ease;
}

.item-art.is-loading {
  opacity: 0;
}

.item-art.is-loaded {
  opacity: 1;
}

.price-box {
  border: 1px solid rgba(222, 160, 58, 0.88);
  background: rgba(8, 10, 14, 0.88);
  color: #ffcb48;
  text-align: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem;
  font-weight: 500;
  line-height: 1.2;
  /* Keep card layout stable: reserve space for 2 lines even when showing "Price: n/a". */
  min-height: calc(2 * 1.2em + 8px);
  padding: 4px 6px;
  border-radius: 4px;
  white-space: pre-line;
}

.chart-wrap {
  height: 46px;
  border: 1px solid rgba(221, 160, 60, 0.72);
  background: rgba(9, 12, 18, 0.92);
  border-radius: 3px;
  padding: 3px;
}

/* Inferred sales: scatter, mirrors vs time; expanded panel on hover / tap. */
.sales-chart-outer {
  position: relative;
  z-index: 1;
  margin-top: 4px;
}

.sales-chart-outer.is-open {
  z-index: 200;
}

.sales-chart-outer[hidden] {
  display: none;
}

.sales-chart-mini {
  height: 38px;
  border: 1px solid rgba(241, 190, 75, 0.55);
  background: rgba(7, 11, 18, 0.94);
  border-radius: 3px;
  padding: 2px 3px;
  cursor: pointer;
}

.sales-chart-canvas {
  display: block;
  width: 100% !important;
  height: 32px !important;
}

/* Panel lives in the card until opened; then it is portaled to body. */
.sales-chart-pop {
  display: none;
  box-sizing: border-box;
  flex-direction: column;
  border: 1px solid rgba(241, 190, 75, 0.68);
  background: rgba(6, 10, 16, 0.98);
  border-radius: 6px;
  padding: 0;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.45);
}

.sales-chart-pop.sales-chart-pop--floating {
  display: flex;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  /* Above portaled listings popover (12000) and other overlays */
  z-index: 20000;
  width: min(92vw, 720px);
  height: min(70vh, 480px);
  max-height: 90vh;
  margin: 0;
}

.sales-chart-backdrop {
  position: fixed;
  inset: 0;
  z-index: 19990;
  background: rgba(0, 0, 0, 0.45);
  pointer-events: auto;
  border: 0;
  padding: 0;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
}

.sales-chart-pop-header {
  position: relative;
  z-index: 2;
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 4px 10px;
  border-bottom: 1px solid rgba(241, 190, 75, 0.18);
}

.sales-chart-sub {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  font-weight: 500;
  color: rgba(241, 190, 75, 0.92);
  text-align: left;
  flex: 1;
}

.sales-chart-close {
  position: relative;
  z-index: 3;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(241, 190, 75, 0.45);
  border-radius: 4px;
  background: rgba(10, 16, 24, 0.95);
  color: rgba(241, 190, 75, 0.94);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.sales-chart-close:hover,
.sales-chart-close:focus-visible {
  border-color: rgba(255, 203, 72, 0.9);
  outline: none;
}

.sales-chart-plot {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 4px 8px 8px;
}

.sales-chart-canvas-expanded {
  display: block;
  width: 100% !important;
  height: 100% !important;
  min-height: 0;
  flex: 1;
}

.sales-chart-empty {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 6px;
  top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.68rem;
  line-height: 1.4;
  color: rgba(200, 214, 235, 0.72);
  pointer-events: none;
}

.card-sales-summary {
  margin-top: 4px;
  padding: 3px 4px 2px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.62rem;
  font-weight: 500;
  line-height: 1.35;
  color: rgba(200, 220, 245, 0.88);
  text-align: center;
  border-radius: 3px;
  background: rgba(12, 16, 24, 0.55);
  border: 1px solid rgba(100, 140, 190, 0.22);
}

.trend {
  border-top: 1px solid rgba(142, 163, 188, 0.2);
  padding-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: #f1be4b;
}

.trend.up {
  color: #2ad36c;
}

.trend.down {
  color: #ff5a4f;
}

.trend.flat {
  color: #f1be4b;
}

.trend-listings {
  color: #f1be4b;
}

.listings-hover-area {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px dashed rgba(241, 190, 75, 0.58);
  border-radius: 5px;
  padding: 4px 12px;
  background: rgba(10, 14, 22, 0.82);
  cursor: default;
  transition: border-color 0.16s ease, transform 0.16s ease, background 0.16s ease;
  min-width: 140px;
  justify-content: center;
  z-index: 100;
}

.listings-hover-area:not(.disabled) {
  cursor: default;
}

.listings-hover-area:not(.disabled):hover,
.listings-hover-area:not(.disabled):focus-within {
  border-color: rgba(255, 203, 72, 0.95);
  background: rgba(14, 20, 31, 0.95);
  transform: translateY(-1px);
}

.listings-hover-area:focus-visible {
  outline: 1px solid rgba(255, 203, 72, 0.95);
  outline-offset: 1px;
}

.listings-hover-area.disabled {
  opacity: 0.65;
  border-style: solid;
  border-color: rgba(142, 163, 188, 0.34);
}

.listings-count {
  color: #f1be4b !important;
}

.listings-popover {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 2px);
  /* Avoid transform scaling which can blur text on some browsers. */
  transform: translateX(calc(-50% + var(--listings-popover-shift-x, 0px)));
  width: min(320px, 88vw);
  max-width: 98vw;
  max-height: 240px;
  overflow: auto;
  border: 1px solid rgba(255, 203, 72, 0.82);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(13, 18, 28, 0.98), rgba(8, 12, 20, 0.98));
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.5);
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 10000;
  transition: opacity 0.16s ease, visibility 0.16s ease;
  box-sizing: border-box;
  text-shadow: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

/* Popover is portaled to <body> on mobile; animate from its trigger */
.listings-popover.listings-popover--global {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: none;
  transform-origin: 50% 100%;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s ease;
  z-index: 12000;
  text-shadow: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

.listings-popover.listings-popover--global.listings-popover--global-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
}

.listings-popover-overlay {
  display: none;
}

.listings-popover::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -8px;
  height: 8px;
  pointer-events: auto;
}

.listings-hover-area:not(.disabled):hover .listings-popover,
.listings-hover-area.popover-open .listings-popover {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(calc(-50% + var(--listings-popover-shift-x, 0px)));
}

.listings-popover-header {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 203, 72, 0.94);
  margin-bottom: 2px;
}

.listings-popover-subline {
  font-size: 0.64rem;
  color: rgba(201, 214, 230, 0.82);
  margin-bottom: 6px;
}

.listings-popover-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.listings-popover-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.listings-popover-row {
  border: 1px solid rgba(139, 163, 194, 0.26);
  border-radius: 6px;
  background: rgba(20, 28, 42, 0.62);
  padding: 4px 6px;
}

.listings-row-top,
.listings-row-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.listings-row-top {
  min-height: 20px;
}

.listings-row-price-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 18px;
}

.listings-row-badges-group {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-height: 18px;
  flex: 0 0 auto;
}

.listings-row-price {
  color: #ffcb48;
  font-weight: 400;
  font-size: 0.72rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-shadow: none;
  font-family: "IBM Plex Mono", monospace;
  min-width: 0;
}

.listings-row-currency {
  width: 18px;
  height: 18px;
  object-fit: contain;
  flex: 0 0 auto;
}

.listings-row-currency-text {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.listings-row-meta {
  margin-top: 2px;
  color: rgba(194, 210, 227, 0.88);
  font-size: 0.66rem;
}

.buyout-badge {
  font-size: 0.62rem;
  padding: 1px 5px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
  flex: 0 0 auto;
}

.buyout-badge.yes {
  color: #6be29a;
  border-color: rgba(54, 209, 121, 0.42);
  background: rgba(27, 100, 58, 0.24);
}

.buyout-badge.no {
  color: #f7ba63;
  border-color: rgba(247, 186, 99, 0.36);
  background: rgba(100, 74, 31, 0.2);
}

.listings-row-corrupt-badge {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-weight: 700;
  font-size: 0.60rem;
  color: #dc2626;
  border: 1px solid rgba(220, 38, 38, 0.35);
  background: rgba(220, 38, 38, 0.10);
  padding: 0 5px;
  border-radius: 999px;
  white-space: nowrap;
  flex: 0 0 auto;
  line-height: 1.4;
}

.listings-row-count-badge {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-weight: 600;
  font-size: 0.60rem;
  color: rgba(194, 210, 227, 0.45);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  line-height: 1.4;
}

.listings-popover-message {
  color: rgba(194, 210, 227, 0.88);
  font-size: 0.67rem;
}

.listings-popover-muted {
  color: rgba(194, 210, 227, 0.7);
}

.listings-popover-error {
  color: #ff7f7f;
}

/* Light theme overrides */
:root.light-theme .card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(250, 252, 255, 0.9));
  border: 1px solid rgba(100, 130, 170, 0.25);
  box-shadow: inset 0 0 0 1px rgba(200, 220, 240, 0.5), 0 2px 8px rgba(0, 0, 0, 0.08);
}

:root.light-theme .card.next-in-line {
  border-color: rgba(38, 185, 109, 0.7);
  box-shadow:
    inset 0 0 0 1px rgba(200, 220, 240, 0.5),
    inset 0 0 0 1px rgba(38, 185, 109, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.08);
}

:root.light-theme .card.favorited {
  border-color: rgba(255, 140, 0, 0.6);
  box-shadow:
    inset 0 0 0 1px rgba(200, 220, 240, 0.5),
    inset 0 0 0 1px rgba(255, 140, 0, 0.3),
    0 2px 8px rgba(0, 0, 0, 0.08);
}

:root.light-theme .card h2 {
  color: #c1680f;
  background: linear-gradient(180deg, rgba(255, 240, 220, 0.6), rgba(255, 248, 240, 0));
  border-color: rgba(255, 180, 100, 0.3);
  text-shadow: none;
}

:root.light-theme .favorite-toggle {
  background: rgba(240, 250, 255, 0.9);
  border-color: rgba(100, 130, 170, 0.3);
  color: rgba(60, 100, 150, 0.8);
}

:root.light-theme .favorite-toggle:hover,
:root.light-theme .favorite-toggle:focus-visible {
  border-color: rgba(255, 140, 0, 0.6);
  color: rgba(255, 140, 0, 0.8);
}

:root.light-theme .favorite-toggle.checked {
  border-color: rgba(255, 140, 0, 0.7);
  color: rgba(255, 140, 0, 0.9);
}

:root.light-theme .art-frame {
  background: radial-gradient(circle at 50% 42%, rgba(220, 235, 250, 0.6), rgba(240, 245, 255, 0.8));
  border-color: rgba(100, 130, 170, 0.2);
}

:root.light-theme .price-box {
  background: rgba(245, 250, 255, 0.95);
  border-color: rgba(255, 140, 0, 0.5);
  color: #c1680f;
}

:root.light-theme .chart-wrap {
  background: rgba(250, 252, 255, 0.95);
  border-color: rgba(255, 140, 0, 0.4);
}

:root.light-theme .sales-chart-mini {
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(193, 104, 15, 0.55);
}

:root.light-theme .sales-chart-pop {
  background: rgba(252, 254, 255, 0.99);
  border-color: rgba(193, 104, 15, 0.52);
  box-shadow: 0 10px 20px rgba(20, 40, 50, 0.18);
}

:root.light-theme .sales-chart-backdrop {
  background: rgba(40, 55, 70, 0.35);
}

:root.light-theme .sales-chart-sub,
:root.light-theme .sales-chart-empty {
  color: rgba(60, 80, 100, 0.88);
}

:root.light-theme .sales-chart-pop-header {
  border-bottom-color: rgba(193, 104, 15, 0.22);
}

:root.light-theme .sales-chart-close {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(193, 104, 15, 0.42);
  color: rgba(193, 104, 15, 0.95);
}

:root.light-theme .card-sales-summary {
  color: rgba(70, 95, 130, 0.95);
  background: rgba(248, 250, 255, 0.9);
  border-color: rgba(100, 130, 170, 0.2);
}

:root.light-theme .trend {
  border-top-color: rgba(100, 130, 170, 0.15);
  color: #c1680f;
}

:root.light-theme .trend.up {
  color: #1e8449;
}

:root.light-theme .trend.down {
  color: #d32f2f;
}

:root.light-theme .trend.flat {
  color: #c1680f;
}

:root.light-theme .trend-listings {
  color: #c1680f;
}

:root.light-theme .listings-hover-area {
  border-color: rgba(193, 104, 15, 0.6);
  background: rgba(255, 255, 255, 0.92);
}

:root.light-theme .listings-hover-area:not(.disabled):hover,
:root.light-theme .listings-hover-area:not(.disabled):focus-within {
  border-color: rgba(193, 104, 15, 0.92);
  background: rgba(255, 248, 240, 0.96);
}

:root.light-theme .listings-count {
  color: #c1680f !important;
}

:root.light-theme .listings-popover {
  border-color: rgba(193, 104, 15, 0.62);
  background: linear-gradient(180deg, rgba(255, 252, 248, 0.98), rgba(250, 247, 241, 0.98));
  box-shadow: 0 12px 24px rgba(15, 26, 38, 0.22);
}

:root.light-theme .listings-popover-header {
  color: #a55a11;
}

:root.light-theme .listings-popover-subline {
  color: #5f6f82;
}

:root.light-theme .listings-popover-row {
  border-color: rgba(100, 130, 170, 0.22);
  background: rgba(240, 247, 255, 0.86);
}

:root.light-theme .listings-row-price {
  color: #c1680f;
}

:root.light-theme .listings-row-meta,
:root.light-theme .listings-popover-message,
:root.light-theme .listings-popover-muted {
  color: #4f6074;
}

:root.light-theme .buyout-badge.yes {
  color: #1e8449;
  border-color: rgba(30, 132, 73, 0.35);
  background: rgba(30, 132, 73, 0.12);
}

:root.light-theme .buyout-badge.no {
  color: #a55a11;
  border-color: rgba(165, 90, 17, 0.35);
  background: rgba(165, 90, 17, 0.1);
}

:root.light-theme .listings-popover-error {
  color: #d32f2f;
}

:root.light-theme .empty {
  border-color: rgba(100, 130, 170, 0.2);
  background: rgba(235, 245, 255, 0.6);
}
