.card-container { margin-bottom: 70px; }
.fav-qty-bar { margin-right: 50px; align-content: left; }
.mg-fav-star { display: none; }

.primary-button {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  background: #eee;
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  transition: background .2s ease, transform .15s ease;
  width: 100%;
  box-sizing: border-box;
}
.primary-button:hover { background: #aaa; }
.primary-button:active { transform: scale(.97); }
.primary-button:disabled { opacity: .5; cursor: not-allowed; }
.primary-button .icon { width: 18px; height: 18px; flex: 0 0 auto; pointer-events: none; }
.primary-button.danger:hover { background: #fa8e8e; }

@media (hover: none), (pointer: coarse) {
  .primary-button:hover,
  .primary-button:active { background: #eee !important; transform: none !important; }
  .primary-button:focus { outline: none; }
}

/* toast */
.copy-toast {
  position: fixed; bottom: 30px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.85); color: #fff;
  padding: 10px 16px; border-radius: 6px;
  font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
  z-index: 9999;
}
.copy-toast.show { opacity: 1; transform: translateX(-50%) translateY(-5px); }

.favorites-empty-msg { text-align: center; color: #ccc; padding: 1rem; font-size: 1rem; }

:root {
  --card-w: 280px !important;
  --card-h: 390px !important;
  --card-extra-h: 0px !important;
}

/* ===============================
   Grid view (card preview/flip)
   =============================== */
body[data-page="favorites"] .favorites-grid .card-inner-wrapper { perspective: 1000px; }
body[data-page="favorites"] .favorites-grid .card-flip-inner.flipped { transform: rotateY(180deg); }
body[data-page="favorites"] .favorites-grid .flip-btn { z-index: 15; }
.flip-btn { top: 16px !important; left: 16px !important; width: 28px !important; height: 28px !important; }

@media (max-width: 768px) {
  body[data-page="favorites"] .favorites-grid { justify-items: center; justify-content: center; }
  body[data-page="favorites"] .favorites-grid > * { justify-self: center; }
}

.favorites-grid {
  --tile-gap: 14px;
  /* keep a sane default; phones can still collapse to one column */
  --tile-min: 220px;
   display: grid;
   grid-template-columns: repeat(auto-fill, minmax(var(--tile-min), 1fr));
   gap: var(--tile-gap);
   align-items: start;
}

body[data-page="favorites"] .card-container,
body[data-page="favorites"] .card-inner-wrapper {
  width: var(--card-w);
  max-width: 100%;
}
body[data-page="favorites"] .card-front img,
body[data-page="favorites"] .card-back img {
  width: 100%;
  height: auto;
  display: block;
}

/* ===============================
   Page layout + featured preview
   =============================== */
.favorites-container {
  display: flex; max-width: 1400px; margin: 0 auto; padding: 1rem; gap: 2rem; justify-content: center;
}
.favorites-list-section { flex: 0 0 40%; }
.favorites-detail-section { flex: 0 0 25%; display: flex; flex-direction: column; align-items: center; }

/* Expand grid width when in grid view */
body.grid-view .favorites-list-section   { flex: 0 0 75%; }
body.grid-view .favorites-detail-section { flex: 0 0 25%; }

.featured-card img {
  width: 260px; height: auto; max-width: 100%; max-height: 100%;
  background: #111; border: 1px solid var(--mg-border); border-radius: var(--mg-radius);
  /* MTG rounded corners */
  border-top-left-radius: 4.75% 3.5%;
  border-top-right-radius: 4.75% 3.5%;
  border-bottom-left-radius: 4.75% 3.5%;
  border-bottom-right-radius: 4.75% 3.5%;
  display: block; margin-bottom: 20px;
}

/* ===============================
   LIST VIEW
   =============================== */
.favorites-list {
  display: grid;
  /* qty | name | icon | set-code | price */
  grid-template-columns: max-content minmax(0,1fr) 28px max-content auto;
  grid-auto-rows: 40px;  /* fixed row height = stable vertical centering */
  row-gap: 0;
  background: var(--mg-bg);
  border-radius: var(--mg-radius);
  padding: 0;
  margin: 0;
  list-style: none;
}

/* Each row uses the parent’s rails */
.favorites-list > li.favorite-item {
  display: grid;
  grid-template-columns: subgrid;   /* <-- never override this in media queries */
  grid-column: 1 / -1;
  align-items: center;              /* vertical center for all cells */
  gap: 8px;
  padding: 4px 8px;
  font-size: 13px;
  min-height: 36px;
}

.favorites-list > li.favorite-item:hover { background: var(--mg-bg-hover); }
.favorites-list > li.favorite-item * { box-sizing: border-box; }

/* columns */
.favorite-item .quantity { display: flex; align-items: center; min-width: 0; }
.favorite-item .card-name {
  min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: left; padding-left: 8px; position: relative; z-index: 1;
}
.favorite-item .set-icon{
  width: 20px;
  height: 20px;
  display: flex;              /* center inside its 28px rail */
  align-items: center;
  justify-content: center;
  line-height: 0;             /* kill baseline effects */
  margin: 0;                  /* spacing comes from grid gap */
  background: currentColor;
  -webkit-mask: var(--icon-url) center / contain no-repeat;
          mask: var(--icon-url) center / contain no-repeat;
}
.favorite-item .card-name,
.favorite-item .set-code,
.favorite-item .price {
  line-height: 1.2;
}

.favorite-item .set-code {
  white-space: nowrap; opacity: .85;
  margin-right: 6px;                /* space before price */
  justify-self: end;
}

.favorite-item .price {
  justify-self: end; font-weight: 700; color: var(--mg-text-dim);
}

/* quantity control (trash | select) */
.qty-controls {
  display: grid; grid-template-columns: 22px 52px; gap: 6px; align-items: center;
}
.qty-controls .remove-btn { width: 22px; height: 22px; border: none; background: none; color: var(--mg-text-dimmer); cursor: pointer; }
.qty-controls .remove-btn svg { width: 16px; height: 16px; display: block; }
.remove-btn:hover { color: var(--mg-accent-danger); }
.remove-btn:active { transform: scale(.96); }

/* compact select */
body[data-page="favorites"] .qty-select {
  width: 52px; height: 22px; padding: 0 18px 0 6px;
  border: 1px solid var(--mg-border); background: var(--mg-bg-soft); color: var(--mg-text);
  border-radius: 6px; line-height: 1; font-size: 12px;
  appearance: none; -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #aaa 50%),
    linear-gradient(135deg, #aaa 50%, transparent 50%);
  background-position: calc(100% - 13px) 8px, calc(100% - 8px) 8px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}

/* grid view qty row on tiles */
body[data-page="favorites"] .fav-qty-bar {
  display: grid; grid-template-columns: 28px 1fr; gap: 6px;
}

.favorites-actions > button {
  margin-bottom: 10px;
}

/* ===============================
   RESPONSIVE
   =============================== */
@media (max-width: 1100px) {
  .favorites-container { flex-direction: column; gap: 1rem; }
  .favorites-list-section, .favorites-detail-section { width: 100%; flex: 0 0 auto; }
  .favorites-detail-section { align-items: center; }
}

@media (max-width: 600px) {
  .favorite-item .set-code { display: none; }
  .favorites-list {
    /* qty | name | icon | price */
    grid-template-columns: max-content minmax(0,1fr) 28px auto;
    grid-auto-rows: 42px;
  }
}

/* Tablet only rule to fix cards overlapping */
@media (min-width: 820px) and (max-width: 1280px) {
  .favorites-grid {
    grid-template-columns: repeat(auto-fill, minmax(var(--card-w), 1fr));
    justify-items: center;
  }

  .card-container { margin-bottom: 40px; }
}

.favorites-actions {
  max-width: 300px;
}
.primary-button { font-size: 14px; line-height: 1.2; max-width: 260px; }