/* ══════════════════════════════════════════════════════════════════════════════
   MTG CARDS — Grid, Card, List View, Modal
   ══════════════════════════════════════════════════════════════════════════════ */

/* ── Grid ─────────────────────────────────────────────────────────────────── */
.mtg-grid {
  display: grid;
  grid-template-columns: repeat(
    auto-fill,
    minmax(max(calc((100% - 80px) / 6), 170px), 1fr)
  );
  gap: 16px;
}
.mtg-empty {
  text-align: center;
  color: #aaa;
  padding: 2rem 0;
  font-size: 14px;
}

/* ── Grid size variants ─────────────────────────────────────────────────────
   max(percentage, min-px): percentage = 100%/N enforces the column cap;
   when the container shrinks below N*min-px, the px floor kicks in
   and auto-fill naturally produces fewer columns.
   ─────────────────────────────────────────────────────────────────────────── */
.mtg-grid--grid-sm {
  grid-template-columns: repeat(
    auto-fill,
    minmax(max(calc((100% - 84px) / 8), 170px), 1fr)
  );
  gap: 12px;
}
.mtg-grid--grid-md {
  grid-template-columns: repeat(
    auto-fill,
    minmax(max(calc((100% - 80px) / 6), 170px), 1fr)
  );
  gap: 16px;
}
.mtg-grid--grid-lg {
  grid-template-columns: repeat(
    auto-fill,
    minmax(max(calc((100% - 60px) / 4), 170px), 1fr)
  );
  gap: 20px;
}
.mtg-grid--list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Card ─────────────────────────────────────────────────────────────────── */
.mtg-card {
  border: 1px solid #e0e0e0;
  border-radius: 19px;
  overflow: hidden;
  background: #fff;
  transition:
    box-shadow 0.15s,
    transform 0.15s;
  display: flex;
  flex-direction: column;
  cursor: pointer;
}
.mtg-card:hover {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  transform: translateY(-2px);
}
.mtg-card--sharp-top {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.mtg-rarity--uncommon {
  border-top: 3px solid #7ab8d4;
}
.mtg-rarity--rare {
  border-top: 3px solid #c9a84c;
}
.mtg-rarity--mythic {
  border-top: 3px solid #e07840;
}
.mtg-rarity--bonus {
  border-top: 3px solid #1a7a3a;
}
.mtg-card > img {
  width: 100%;
  display: block;
}

/* ── Card image wrapper with rarity icon ──────────────────────────────────── */
.mtg-card-img-wrap {
  position: relative;
  display: block;
}
.mtg-card-img-wrap img {
  width: 100%;
  display: block;
}

.mtg-card-rarity-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  text-align: center;
  align-content: center;
  font-size: 10px;
}
.mtg-card-rarity--common {
  background: #f0f0f0;
  color: #555;
  border-color: #ccc;
}
.mtg-card-rarity--uncommon {
  background: #dff0f8;
  color: #1a6a8a;
  border-color: #7ab8d4;
}
.mtg-card-rarity--rare {
  background: #fef9e7;
  color: #8a6010;
  border-color: #c9a84c;
}
.mtg-card-rarity--mythic {
  background: #fff1eb;
  color: #9a3d10;
  border-color: #e07840;
}
.mtg-card-rarity--bonus {
  background: #f3fcee;
  color: #0f8a0f;
  border-color: #16c615;
}

/* ── Card body ────────────────────────────────────────────────────────────── */
.mtg-card-body {
  padding: 10px 12px 5px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  justify-content: flex-start;
  position: relative;
}
.mtg-card-name-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}
.mtg-card-name {
  font-size: 13px;
  font-weight: 700;
  color: #2d2418;
  line-height: 1.3;
  flex: 1;
  font-family: var(--font-serif);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  min-height: calc(2 * 1.3em);
}

.mtg-card-meta-row {
  font-size: 11px;
  color: #888;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  min-height: calc(2 * 1.35em);
}
.mtg-meta-sep {
  margin: 0 3px;
}
.mtg-meta-set {
  color: #6b5f4f;
  font-family: var(--font-sans);
  font-size: 11px;
  text-transform: uppercase;
}
.mtg-meta-type {
  font-style: italic;
}
.mtg-card-divider {
  border: none;
  border-top: 1px solid #f0f0f0;
  margin: 2px 0;
}

/* Condition + Foil  */
.mtg-foil-cond-row {
  display: flex;
  margin-top: auto;
  gap: 3px;
  align-items: center;
}

/* ── Condition selector ───────────────────────────────────────────────────── */
.mtg-cond-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
}
.mtg-cond-select {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid #ddd;
  font-size: 12px;
  background: #f8f5ef;
  color: #222;
  cursor: pointer;
}
.mtg-cond-select:focus {
  outline: none;
  border-color: #1a1a2e;
}

/* Price block + Add button */
.mtg-price-add-row {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  align-items: center;
}

/* ── Price block ──────────────────────────────────────────────────────────── */
.mtg-price-block {
  margin-top: 0;
  min-height: 82px;
  display: flex;
  justify-content: space-between;
  flex: 1;
  min-width: 0;
}
.mtg-buylabel {
  font-size: 10px;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.mtg-price-val {
  font-size: 17px;
  font-weight: 600;
  color: var(--foreground);
  line-height: 1.1;
  font-family: var(--font-sans);
  height: 32px;
  align-content: center;
}
.mtg-price-base {
  font-size: 12px;
  color: #aaa;
  margin-top: 1px;
}
.mtg-price-none {
  font-size: 12px;
  color: #c0392b;
  font-weight: 600;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mtg-price-none-grid {
  position: absolute;
  bottom: 0px;
  left: 13px;
  right: 13px;
  min-height: 60px;
}

.mtg-price-contact {
  font-size: 11px;
}
.mtg-contact-link {
  color: #1a1a2e;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.mtg-contact-link:hover {
  color: #444;
}

/* ── Add to buylist button ────────────────────────────────────────────────── */
.mtg-cart-row:empty {
  display: none;
  margin-top: 0;
}
.mtg-add-to-cart {
  width: 80px;
  height: 32px;
  border-radius: 6px;
  border: none;
  background: var(--yellow);
  color: #333;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition:
    background 0.15s,
    color 0.15s;
}
.mtg-add-to-cart:hover {
  background: #1a1a2e;
  color: #fff;
}
.mtg-cart-plus {
  font-size: 15px;
  line-height: 1;
}
.mtg-add-to-cart--added {
  background: #1a7a3a !important;
  border-color: #1a7a3a !important;
  color: #fff !important;
}
.mtg-add-to-cart--unavailable {
  background: #e0e0e0 !important;
  border-color: #ccc !important;
  color: #999 !important;
  cursor: default;
}

/* ── List row ─────────────────────────────────────────────────────────────── */
.mtg-list-row {
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  padding: 10px 14px;
  transition: box-shadow 0.15s;
  height: 140px;

  position: relative;
  overflow: hidden;
}
.mtg-list-row:hover {
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}
.mtg-list-thumb {
  align-self: stretch;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  cursor: pointer;
  margin-right: 14px;
}
.mtg-list-info {
  flex: 1;
  min-width: 40px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-self: stretch;
  padding: 10px 5px 10px 0px;
}
.mtg-list-name {
  font-size: 14px;
  font-weight: 700;
  color: #111;
  margin-bottom: 2px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.mtg-list-set {
  font-size: 11px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 5px;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mtg-list-ctrl-price {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  justify-content: space-between;
  padding-top: 40px;
}
.mtg-list-price-add {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  flex-shrink: 0;
  min-width: 200px;
}
.mtg-list-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.mtg-list-cond {
  width: auto;
  min-width: 90px;
  height: 30px;
  padding: 0 6px;
  font-size: 12px;
}
.mtg-list-foil-btn {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  height: 30px;
  min-width: 70px;
  padding: 0 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #f8f5ef;
  font-size: 12px;
  color: #555;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 0.15s,
    border-color 0.15s;
  user-select: none;
}
.mtg-list-foil-btn input {
  display: none;
}
.mtg-list-foil-btn:has(input:checked) {
  background: #fef9e7;
  border-color: #c9a84c;
  color: #8a6010;
  font-weight: 600;
}
.mtg-list-foil-btn--disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}
.mtg-list-price {
  text-align: center;
  flex-shrink: 0;
  min-width: 90px;
}
.mtg-list-price .mtg-price-val {
  font-size: 20px;
}
.mtg-list-price .mtg-price-base {
  font-size: 10px;
}
.mtg-list-price .mtg-price-none {
  font-size: 11px;
  position: absolute;
  bottom: 5px;
  right: 14px;
  text-align: right;
}
.mtg-list-add-btn {
  height: 34px;
  padding: 0 16px;
  border-radius: 8px;
  border: none;
  min-width: 100px;
  background: var(--yellow);
  color: #333;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
  white-space: nowrap;
}
.mtg-list-add-btn:hover {
  background: #b8973b;
}
.mtg-list-add-btn--added {
  background: #1a7a3a !important;
}
.mtg-list-add-btn--unavail {
  background: #ccc !important;
  cursor: default;
}

/* ══════════════════════════════════════════════════════════════════════════════
   Card detail modal
   ══════════════════════════════════════════════════════════════════════════════ */

.mtg-modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.mtg-modal-bg.mtg-modal--open {
  display: flex;
}

.mtg-modal {
  background: #fff;
  border-radius: 16px;
  max-width: 1000px;
  width: calc(100vw - 4rem);
  position: relative;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  padding: 0;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
}

.mtg-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f0f0f0;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: #555;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.mtg-modal-close:hover {
  background: #e0e0e0;
  color: #111;
}

/* ── Two column layout ────────────────────────────────────────────────────── */
.mtg-modal-layout {
  display: flex;
  min-height: 480px;
}

/* ── Left: image column ───────────────────────────────────────────────────── */
.mtg-modal-img-col {
  width: 45%;
  flex-shrink: 0;
  border-radius: 16px 0 0 16px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  padding: 2rem;
  position: relative;
}
.mtg-modal-card-img {
  width: 100%;
  border: none;
  border-radius: 25px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  display: block;
}
.mtg-modal-img-wrap {
  position: relative;
  display: inline-block;
}
.mtg-modal-img-wrap img {
  display: block;
  width: 100%;
  border-radius: 25px;
}
.mtg-modal-rarity-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
}

/* ── Right: info column ───────────────────────────────────────────────────── */
.mtg-modal-info-col {
  flex: 1;
  padding: 2rem 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
}

.mtg-modal-name {
  font-size: 26px;
  font-weight: 700;
  color: #111;
  line-height: 1.2;
  font-family: var(--font-serif, inherit);
}
.mtg-modal-set {
  font-size: 13px;
  color: #888;
  margin-top: 2px;
}
.mtg-modal-divider {
  border: none;
  height: 1px;
  margin: 40px 0;
  background: linear-gradient(
    to right,
    transparent,
    rgba(22, 22, 22, 0.219),
    transparent
  );
}

.mtg-modal-emptySpace {
  border: none;
  margin-top: 30px;
}

/* ── Price section ────────────────────────────────────────────────────────── */
.mtg-modal-price-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.mtg-modal-price-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #aaa;
  text-transform: uppercase;
}
.mtg-modal-price-val {
  font-size: 40px;
  font-weight: 600;
  color: var(--darkBrown);
  line-height: 1.1;
  font-family: var(--font-sans);
}
.mtg-modal-price-market {
  font-size: 12px;
  color: #aaa;
}

/* ── Section labels ───────────────────────────────────────────────────────── */
.mtg-modal-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #aaa;
  text-transform: uppercase;
  margin-bottom: -4px;
}

/* ── Condition chips ──────────────────────────────────────────────────────── */
.mtg-modal-cond-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.mtg-modal-cond-chip {
  height: 50px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1.5px solid #e0e0e0;
  background: #fff;
  font-size: 13px;
  color: var(--darkBrown);
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 20px;
  width: fit-content;
  justify-content: space-between;
}
.mtg-modal-cond-chip:hover {
  border-color: var(--darkBrown);
}
.mtg-modal-cond-chip--active {
  background: var(--darkBrown);
  border-color: var(--darkBrown);
  color: #fff;
}
.mtg-modal-cond-chip:disabled {
  opacity: 0.4;
  cursor: default;
}
.mtg-modal-cond-chip:disabled:hover {
  background: #fff;
  border-color: #e0e0e0;
  color: #333;
  cursor: default;
}
.mtg-modal-cond-chip--no-price {
  opacity: 0.45;
  cursor: default;
}
.mtg-modal-chip-price {
  font-size: 11px;
  opacity: 0.5;
}
.mtg-modal-cond-chip--active .mtg-modal-chip-price {
  display: none;
}

/* ── Foil toggle ──────────────────────────────────────────────────────────── */
.mtg-modal-foil-row {
  display: flex;
  align-items: center;
  margin-top: 20px;
}
.mtg-modal-foil-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  color: #333;
}
.mtg-modal-foil-toggle input {
  display: none;
}
.mtg-modal-toggle-track {
  width: 38px;
  height: 20px;
  background: #ccc;
  border-radius: 99px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
}
.mtg-modal-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.mtg-modal-foil-toggle input:checked + .mtg-modal-toggle-track {
  background: var(--darkBrown);
}
.mtg-modal-foil-toggle
  input:checked
  + .mtg-modal-toggle-track
  .mtg-modal-toggle-thumb {
  transform: translateX(18px);
}
.mtg-modal-foil-toggle--disabled {
  opacity: 0.4;
  cursor: default;
}
.mtg-modal-foil-text {
  font-size: 13px;
  color: #555;
}

/* ── Quantity row ─────────────────────────────────────────────────────────── */
.mtg-modal-qty-row {
  display: flex;
  align-items: center;
  gap: 0;
  height: 44px;
  border: 1.5px solid #e0e0e0;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 20px;
}
.mtg-modal-qty-btn {
  width: 44px;
  height: 100%;
  border: none;
  background: #f8f8f8;
  font-size: 18px;
  cursor: pointer;
  color: #333;
  transition: background 0.15s;
  flex-shrink: 0;
}
.mtg-modal-qty-btn:hover {
  background: #eee;
}
.mtg-modal-qty-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.mtg-modal-qty-input {
  --has-width: 100%;
  --has-height: 100%;
  --theme-form-field-border-width: 0px;
  --theme-form-field-border-left: 1.5px solid #e0e0e0;
  --theme-form-field-border-right: 1.5px solid #e0e0e0;
  text-align: center;
  --theme-form-font-size: 16px;
  --theme-form-font-weight: 600;
  --theme-form-font-color: #111;
  outline: none;
  background: #fff;
}
.mtg-modal-qty-input::-webkit-inner-spin-button,
.mtg-modal-qty-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}
.mtg-modal-qty-input:disabled {
  opacity: 0.4;
  cursor: default;
  color: transparent;
}

/* ── Add to sell list button ──────────────────────────────────────────────── */
.mtg-modal-add-btn {
  width: 100%;
  height: 52px;
  background: var(--darkBrown);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: auto;
}
.mtg-modal-add-btn:hover {
  background: var(--lightBrown);
}
.mtg-modal-add-btn--disabled {
  background: #ccc;
  cursor: default;
}
.mtg-modal-add-btn--disabled:hover {
  background: #ccc;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 950px) {
  .mtg-modal-layout {
    flex-direction: column;
  }
  .mtg-modal-img-col {
    width: 100%;
    padding: 1.5rem;
  }
  .mtg-modal-card-img {
    max-width: 300px;
  }
  .mtg-modal-info-col {
    padding: 1.25rem;
  }
  .mtg-modal-name {
    font-size: 20px;
  }
}

@media (max-width: 700px) {
  .mtg-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }
  .mtg-price-val {
    font-size: 18px;
  }

  .mtg-list-set {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mtg-list-row .mtg-rarity-badge {
    display: inline-block;
    font-size: 0;
    padding: 2px 5px;
  }
  .mtg-list-row .mtg-rarity-badge::first-letter {
    font-size: 10px;
  }

  .mtg-list-price-add {
    justify-content: flex-start;
    min-width: 0px;
  }
  .mtg-list-price .mtg-price-none {
    left: 14px;
    font-size: 10px;
  }
  .mtg-list-name {
    overflow: visible;
    text-overflow: clip;
  }
  .mtg-list-price {
    text-align: center;
    min-width: 70px;
  }

  .mtg-list-info {
    padding: 10px 5px 20px 0px;
  }

  .mtg-list-ctrl-price {
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    padding-top: 40px;
    padding-right: 30px;
    padding-bottom: 13px;
    align-self: stretch;
  }

  .mtg-list-add-btn {
    min-width: 70px;
    padding: 0 10px;
  }

  .mtg-list-thumb {
    align-self: anchor-center;
    width: 50px;
  }

  .mtg-list-cond {
    min-width: 70px;
  }

  .mtg-list-foil-btn {
    min-width: 50px;
  }
}
