/* ══════════════════════════════════════════════════════════════════
   CODEX CARD TILE (redesign step 6)
   See design_handoff_codex_redesign/README.md §Component Vocabulary 4.

   Wraps the existing .card markup emitted by src/cardRenderer.js's
   createCardElement(). The original IDs, click handlers, action
   buttons, owned/wishlist/ordered/upcoming class toggling all stay —
   we only restyle. Status pip + corner badges layer via CSS pseudo-
   elements + position absolute so no markup changes are needed.

   Future: a true price row (€low — €high + 5-star rarity) would need
   new data wiring in renderCard. Deferred — see DEFERRED.md.
   ══════════════════════════════════════════════════════════════════ */

/* ── Tile container ───────────────────────────────────────────────── */
#cardsContainer .card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease;
  /* Wipe legacy gradient/inner padding */
  background-image: none;
  box-shadow: none;
}

#cardsContainer .card:hover {
  transform: translateY(-2px);
  border-color: var(--border-hi);
  box-shadow: var(--shadow-tile-hover);
}

/* Status indicators on the card image (corner pip ::before + corner
   badge ::after) were removed — the tinted .card-info background
   below the image is now the sole at-a-glance signal for ownership
   state, paired with the per-status action button accents in the
   meta row. */

/* Card body status tint — coloured background on the .card-info
   strip below the image is now the primary status signal at a
   glance (the left-stripe variant was scrapped — it ate into the
   card art and the colour was too narrow to read). The corner pip +
   top-right badge handle the secondary signal. */
#cardsContainer .card.owned .card-info {
  background: color-mix(in srgb, var(--pos) 22%, var(--surface));
  border-top-color: color-mix(in srgb, var(--pos) 40%, var(--border));
}
#cardsContainer .card.wishlist .card-info {
  background: color-mix(in srgb, var(--warm) 22%, var(--surface));
  border-top-color: color-mix(in srgb, var(--warm) 40%, var(--border));
}
#cardsContainer .card.ordered .card-info {
  background: color-mix(in srgb, var(--cool) 22%, var(--surface));
  border-top-color: color-mix(in srgb, var(--cool) 40%, var(--border));
}
/* owned wins the tint when stacked with wishlist/ordered */
#cardsContainer .card.owned.wishlist .card-info,
#cardsContainer .card.owned.ordered .card-info {
  background: color-mix(in srgb, var(--pos) 22%, var(--surface));
  border-top-color: color-mix(in srgb, var(--pos) 40%, var(--border));
}
/* Upcoming (unreleased) cards — a soft tint using the same --upcoming hue as
   the release date. Only when the card isn't held, so a collection status
   (owned/wishlist/ordered) always wins the tint. */
#cardsContainer .card.upcoming:not(.owned):not(.wishlist):not(.ordered) .card-info {
  background: color-mix(in srgb, var(--upcoming) 15%, var(--surface));
  border-top-color: color-mix(in srgb, var(--upcoming) 38%, var(--border));
}

/* ── Scan area ────────────────────────────────────────────────────── */
#cardsContainer .card .card-image-container {
  position: relative;
  width: 100%;
  display: block;
  overflow: hidden;
  background: var(--surface2);
  /* Maintain card aspect ratio ~ 1:1.39 (jumbo). */
  aspect-ratio: 1 / 1.39;
}

#cardsContainer .card .card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s ease;
}
#cardsContainer .card:hover .card-image {
  transform: scale(1.02);
}

#cardsContainer .card .card-image.loading {
  background: var(--surface2);
}

/* ── Quick-actions row (wishlist / order / edit) ──────────────────── */
/* Lives in the centre column of .card-meta — always visible (no hover
   gating) and no longer absolutely positioned over the scan. */
#cardsContainer .card .card-actions {
  display: inline-flex;
  flex-direction: row;
  gap: 4px;
  align-items: center;
  justify-content: center;
}

#cardsContainer .card .card-actions > a,
#cardsContainer .card .card-actions > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-mute);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  /* Inactive emoji icons (⭐ / 📦) look just as colourful as active ones
     since emoji glyphs ignore CSS color. Desaturate + lower opacity so
     the active/inactive contrast reads at a glance. */
  opacity: 0.45;
  filter: grayscale(1);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease,
    opacity 0.15s ease, filter 0.15s ease;
}
#cardsContainer .card .card-actions > a:hover,
#cardsContainer .card .card-actions > button:hover {
  background: var(--surface3);
  border-color: var(--accent);
  color: var(--accent);
  opacity: 1;
  filter: none;
}

/* Active states — full saturation + tinted background ring per status. */
#cardsContainer .card .card-actions .owned-edit-btn.has-data,
#cardsContainer .card .card-actions .wishlist-btn.active,
#cardsContainer .card .card-actions .ordered-btn.active {
  opacity: 1;
  filter: none;
}
#cardsContainer .card .card-actions .owned-edit-btn.has-data {
  background: color-mix(in srgb, var(--pos) 22%, transparent);
  border-color: color-mix(in srgb, var(--pos) 55%, var(--border));
  color: var(--pos);
}
#cardsContainer .card .card-actions .wishlist-btn.active {
  background: color-mix(in srgb, var(--warm) 22%, transparent);
  border-color: color-mix(in srgb, var(--warm) 55%, var(--border));
  color: var(--warm);
}
#cardsContainer .card .card-actions .ordered-btn.active {
  background: color-mix(in srgb, var(--cool) 22%, transparent);
  border-color: color-mix(in srgb, var(--cool) 55%, var(--border));
  color: var(--cool);
}

#cardsContainer .card .card-actions svg {
  width: 11px;
  height: 11px;
  display: block;
}

/* ── Card info block (below the scan) ─────────────────────────────── */
#cardsContainer .card .card-info {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* Images-only mode (countbar toggle): drop the info block entirely so
   the grid is pure artwork. The whole card stays clickable to open the
   modal — only the text/actions strip is hidden. */
body.images-only #cardsContainer .card .card-info {
  display: none;
}

/* Card name — sans, single line, ellipsis. */
#cardsContainer .card .card-name {
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

#cardsContainer .card .card-name .dev-id {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-mute);
  margin-right: 4px;
  letter-spacing: 0;
}

/* Card number row (with flag) — small mono. */
#cardsContainer .card .card-number {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 4px;
  line-height: 1.2;
  letter-spacing: 0.02em;
}

#cardsContainer .card .card-number .flag-icon {
  width: 14px;
  height: 10px;
  border-radius: 1.5px;
  display: inline-block;
}

/* Set — set label, sans, dim. */
#cardsContainer .card .card-set {
  font-family: var(--font-sans);
  font-size: 10.5px;
  color: var(--text-dim);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Price + rarity row (Codex step 6 — sits above the type/year meta).
   Dashed top divider, mono €low — €high on the left, 5 stars on the
   right. Hidden when the card has no global price. */
#cardsContainer .card .card-price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-top: 6px;
  margin-top: 2px;
  border-top: 1px dashed var(--border);
  font-family: var(--font-mono);
  /* Bumped from 10.5 → 11.5 for readability (audit P0-4). */
  font-size: 11.5px;
  letter-spacing: -0.01em;
}

#cardsContainer .card .card-price {
  color: var(--text);
  font-weight: 500;
}

#cardsContainer .card .card-rarity {
  color: var(--warm);
  letter-spacing: 0.5px;
  font-size: 11px;
  line-height: 1;
}

/* When the price row is present, the meta row no longer needs its
   own dashed top — drop the duplicate divider. */
#cardsContainer .card .card-price-row + .card-meta {
  border-top: 0;
  padding-top: 4px;
}

/* Meta row — TYPE · actions · YEAR. 3-col grid so the actions stay
   perfectly centred regardless of icon/date widths. */
#cardsContainer .card .card-meta {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  /* Bumped from 10.5 → 11.5 and contrast from --text-mute → --text-dim
     (audit P0-4: meta was clipping into bg / low-contrast). */
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 2px;
  /* Dashed divider above (the price row spot — for now this is the
     "release year" row). */
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

/* The type icon span is the first child of .card-meta. */
#cardsContainer .card .card-meta > span:first-child {
  justify-self: start;
}
#cardsContainer .card .card-meta .type-icon {
  width: 14px;
  height: 14px;
  display: block;
}

/* Card-actions sit in the centre column. */
#cardsContainer .card .card-meta > .card-actions {
  justify-self: center;
}

/* Year (or langs region) is the trailing span. */
#cardsContainer .card .card-meta > span:last-child {
  justify-self: end;
  white-space: nowrap;
  color: var(--text-dim);
  letter-spacing: 0;
}
#cardsContainer .card .card-meta .upcoming-date {
  color: var(--upcoming);
  font-weight: 500;
}

/* ── Selection mode (batch) ───────────────────────────────────────── */
#cardsContainer .card.selection-mode {
  cursor: pointer;
}
#cardsContainer .card.selection-mode.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
#cardsContainer .card .card-selection-checkbox {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  width: 20px;
  height: 20px;
  background: rgba(12, 15, 21, 0.85);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
#cardsContainer .card .card-selection-checkbox.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}
#cardsContainer .card .card-selection-checkbox.selected::after {
  content: '✓';
  font-size: 13px;
  font-weight: 700;
  color: var(--bg);
}

/* ── Grid spacing (cardsContainer is the grid itself) ─────────────── */
#cardsContainer {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
#cardsContainer.cols-1  { grid-template-columns: 1fr; }
#cardsContainer.cols-2  { grid-template-columns: repeat(2, 1fr); }
#cardsContainer.cols-4  { grid-template-columns: repeat(4, 1fr); }
#cardsContainer.cols-6  { grid-template-columns: repeat(6, 1fr); }
#cardsContainer.cols-8  { grid-template-columns: repeat(8, 1fr); }
#cardsContainer.cols-10 { grid-template-columns: repeat(10, 1fr); gap: 8px; }
#cardsContainer.cols-12 { grid-template-columns: repeat(12, 1fr); gap: 6px; }

/* ── Light-mode adjustments ───────────────────────────────────────── */
:root[data-theme='light'] #cardsContainer .card,
.theme-light #cardsContainer .card {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow-tile);
}
:root[data-theme='light'] #cardsContainer .card:hover,
.theme-light #cardsContainer .card:hover {
  box-shadow: var(--shadow-hover);
  border-color: var(--border-hi);
}
:root[data-theme='light'] #cardsContainer .card .card-actions > a,
:root[data-theme='light'] #cardsContainer .card .card-actions > button,
.theme-light #cardsContainer .card .card-actions > a,
.theme-light #cardsContainer .card .card-actions > button {
  background: rgba(255, 255, 255, 0.92);
  border-color: var(--border);
  color: var(--text);
}

/* ── Dark-mode override for any conflicting legacy .card rules ────── */
body.dark-mode #cardsContainer .card {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: none;
}
body.dark-mode #cardsContainer .card .card-name {
  color: var(--text);
}
body.dark-mode #cardsContainer .card .card-set,
body.dark-mode #cardsContainer .card .card-number,
body.dark-mode #cardsContainer .card .card-meta {
  color: var(--text-dim);
}
