/* =========================================================
   GEXI — public/market/market.css   (Marketplace UI U1)

   The market surface on the SHARED brand tokens (styles.css: --ink, --card, --line, --muted,
   --brand-500, --shadow-*) + gx-ui's feel — no parallel token system. Namespaced .mkt-* so it is
   purely additive. Mobile-correct per the contract: every flex child that must shrink carries
   min-width: 0; the grid is preview-first (cards are ~90% image).
   ========================================================= */

.mkt-page { max-width: 1120px; margin: 0 auto; padding: 0 16px 96px; box-sizing: border-box; }

/* ---- filter chips ---- */
.mkt-chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 18px; }
.mkt-chip {
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 7px 16px; font-size: 14px; font-weight: 650; cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s var(--gx-ease, ease);
}
.mkt-chip:hover { border-color: var(--brand-500); transform: translateY(-1px); }
.mkt-chip[aria-pressed="true"] { background: var(--brand-500); border-color: var(--brand-500); color: #fff; }

/* ---- the grid ---- */
.mkt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }
@media (min-width: 720px) { .mkt-grid { grid-template-columns: repeat(auto-fill, minmax(216px, 1fr)); gap: 18px; } }

/* ---- ListingCard — preview-first, price chip overlaid ---- */
.mkt-card {
  position: relative; display: flex; flex-direction: column; min-width: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden;
  cursor: pointer; text-decoration: none; color: inherit;
  transition: transform .18s var(--gx-ease, ease), box-shadow .18s, border-color .18s;
}
.mkt-card:hover, .mkt-card:focus-visible { transform: translateY(-3px); box-shadow: var(--shadow-md, 0 8px 24px rgba(0,0,0,.12)); border-color: var(--brand-500); outline: none; }
.mkt-thumb { position: relative; aspect-ratio: 1 / 1; background: linear-gradient(135deg, rgba(16,185,129,.10), rgba(132,204,22,.10)); overflow: hidden; }
.mkt-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mkt-thumb img[data-broken="1"] { display: none; }   /* broken preview → the gradient shows */
.mkt-badge-modality {
  position: absolute; top: 8px; left: 8px; font-size: 11px; font-weight: 700; letter-spacing: .02em;
  color: #fff; background: rgba(0,0,0,.55); border-radius: 999px; padding: 3px 9px; backdrop-filter: blur(4px);
}
.mkt-badge-price {
  position: absolute; bottom: 8px; right: 8px; font-size: 13px; font-weight: 800;
  color: #fff; background: rgba(0,0,0,.62); border-radius: 999px; padding: 4px 11px; backdrop-filter: blur(4px);
}
.mkt-card-meta { display: flex; align-items: center; gap: 8px; padding: 9px 11px; min-width: 0; }
.mkt-card-license { font-size: 12px; font-weight: 650; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.mkt-card-prov { font-size: 11px; color: var(--muted); padding: 0 11px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- skeletons (loading state that feels instant) ---- */
.mkt-skel { border-radius: 16px; border: 1px solid var(--line); overflow: hidden; }
.mkt-skel .s-thumb { aspect-ratio: 1 / 1; }
.mkt-skel .s-line { height: 12px; margin: 10px 11px; border-radius: 6px; }
.mkt-skel .s-thumb, .mkt-skel .s-line {
  background: linear-gradient(100deg, var(--line) 35%, var(--card) 50%, var(--line) 65%);
  background-size: 220% 100%; animation: mktShimmer 1.3s linear infinite;
}
@keyframes mktShimmer { to { background-position: -120% 0; } }
@media (prefers-reduced-motion: reduce) { .mkt-skel .s-thumb, .mkt-skel .s-line { animation: none; } }

/* ---- empty / unavailable states ---- */
.mkt-state { text-align: center; padding: 64px 16px; color: var(--muted); }
.mkt-state .mkt-state-icon { font-size: 44px; margin-bottom: 10px; }
.mkt-state h2 { color: var(--ink); font-size: 20px; margin: 0 0 6px; }
.mkt-state p { margin: 0 auto; max-width: 44ch; font-size: 15px; line-height: 1.5; }

/* ---- the lightbox viewer (full-screen preview) ---- */
.mkt-viewer { position: fixed; inset: 0; z-index: 1300; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; background: rgba(8, 12, 16, .92); padding: 20px; cursor: zoom-out; }
.mkt-viewer img { max-width: min(94vw, 980px); max-height: 78vh; border-radius: 12px; box-shadow: 0 18px 60px rgba(0,0,0,.5); }
.mkt-viewer-caption { display: flex; align-items: center; gap: 12px; color: #e8eef3; font-size: 14px; }
.mkt-viewer-caption .mkt-badge-price { position: static; }
.mkt-viewer-close { position: absolute; top: 14px; right: 16px; font-size: 26px; color: #fff; background: none; border: none; cursor: pointer; line-height: 1; padding: 8px; }

/* ---- the load-more sentinel ---- */
.mkt-sentinel { height: 1px; }
.mkt-loadnote { text-align: center; color: var(--muted); font-size: 13px; padding: 18px 0; }

/* ---- U2: the BuySheet — bottom sheet on mobile, centered card on desktop ----
   z-index 1200: ABOVE the fixed mobile bottom-nav (z-index 1000) — a sheet that slides under the
   nav leaves its Buy/license controls untappable (caught by the mobile e2e). The zoom viewer sits
   above the sheet at 1300. */
.mkt-sheet-backdrop { position: fixed; inset: 0; z-index: 1200; background: rgba(8, 12, 16, .55); display: flex; align-items: flex-end; justify-content: center; }
.mkt-sheet {
  position: relative; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; min-width: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 48px rgba(0,0,0,.35); transform: translateY(24px); opacity: 0;
  transition: transform .22s var(--gx-ease, ease), opacity .22s;
}
.mkt-sheet.open { transform: translateY(0); opacity: 1; }
@media (min-width: 720px) {
  .mkt-sheet-backdrop { align-items: center; padding: 24px; }
  .mkt-sheet { border-radius: 20px; }
}
@media (prefers-reduced-motion: reduce) { .mkt-sheet { transition: none; transform: none; opacity: 1; } }
.mkt-sheet-close { position: absolute; top: 10px; right: 12px; z-index: 2; font-size: 24px; line-height: 1; padding: 8px; background: rgba(0,0,0,.45); color: #fff; border: none; border-radius: 999px; cursor: pointer; width: 40px; height: 40px; }
.mkt-sheet-media { aspect-ratio: 1 / 1; max-height: 44vh; background: linear-gradient(135deg, rgba(16,185,129,.10), rgba(132,204,22,.10)); cursor: zoom-in; }
.mkt-sheet-media img { width: 100%; height: 100%; object-fit: contain; display: block; }
.mkt-sheet-body { padding: 16px 18px calc(22px + env(safe-area-inset-bottom, 0)); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.mkt-sheet-row { display: flex; align-items: center; gap: 10px; }
.mkt-sheet-row .mkt-badge-price { position: static; font-size: 16px; padding: 6px 14px; }
.mkt-sheet-mod { color: var(--muted); font-size: 14px; font-weight: 650; }
.mkt-sheet-license { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; color: var(--ink); }
.mkt-sheet-licensetext { font-size: 13px; line-height: 1.55; color: var(--muted); background: rgba(127,127,127,.07); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; white-space: pre-wrap; }
.mkt-sheet-prov { font-size: 12px; color: var(--muted); }
.mkt-sheet-actions { display: flex; align-items: center; gap: 14px; margin-top: 6px; }
.mkt-buy {
  flex: 1; min-width: 0; padding: 13px 18px; font-size: 16px; font-weight: 750; color: #fff;
  background: var(--gx-grad, linear-gradient(120deg, #10b981, #22c55e)); border: none; border-radius: 999px;
  cursor: pointer; transition: transform .15s var(--gx-ease, ease), filter .15s;
}
.mkt-buy:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.06); }
.mkt-buy:disabled { opacity: .65; cursor: wait; }
.mkt-buy.mkt-owned { background: var(--card); color: var(--brand-500); border: 1.5px solid var(--brand-500); }
.mkt-link { background: none; border: none; padding: 0; font-size: 13px; font-weight: 650; color: var(--brand-500); cursor: pointer; text-decoration: underline; }
.mkt-sheet-note { min-height: 18px; font-size: 13px; color: var(--muted); }

/* ---- U3: the Browse | Sell view tabs ---- */
.mkt-viewtabs { display: flex; gap: 6px; margin: 0 0 16px; border-bottom: 1.5px solid var(--line); }
.mkt-viewtab { background: none; border: none; padding: 10px 16px; font-size: 15px; font-weight: 750; color: var(--muted); cursor: pointer; border-bottom: 2.5px solid transparent; margin-bottom: -1.5px; }
.mkt-viewtab[aria-selected="true"] { color: var(--brand-500); border-bottom-color: var(--brand-500); }

/* ---- U3: the SellSheet checklist ---- */
.mkt-sell-checklist { display: flex; flex-direction: column; gap: 8px; }
.mkt-gate { display: flex; align-items: flex-start; gap: 10px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.mkt-gate.ok { border-color: rgba(34, 197, 94, .45); }
.mkt-gate-mark { flex: none; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 999px; font-size: 13px; font-weight: 800; background: rgba(127,127,127,.12); color: var(--muted); }
.mkt-gate.ok .mkt-gate-mark { background: rgba(34, 197, 94, .16); color: #16a34a; }
.mkt-gate-text { flex: 1; min-width: 0; font-size: 13px; color: var(--ink); line-height: 1.4; }
.mkt-gate-text > span { color: var(--muted); }
.mkt-gate-hint { display: block; margin-top: 3px; font-size: 12px; color: var(--muted); font-style: italic; }
.mkt-badge-sell { background: var(--gx-grad, linear-gradient(120deg, #10b981, #22c55e)); }

/* ---- U3: pricing ---- */
.mkt-sell-price-label { font-size: 13px; font-weight: 700; color: var(--ink); }
.mkt-sell-bounds { color: var(--muted); font-weight: 600; }
.mkt-sell-price-row { display: flex; align-items: center; gap: 14px; margin: 6px 0 2px; }
.mkt-sell-price { font-size: 22px; font-weight: 800; color: var(--ink); min-width: 64px; text-align: center; }
.mkt-step { width: 38px; height: 38px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); font-size: 19px; font-weight: 800; cursor: pointer; }
.mkt-step:hover { border-color: var(--brand-500); }
.mkt-sell-take { font-size: 12px; color: var(--muted); }
.mkt-sell-live { font-size: 14px; color: var(--ink); }

/* ---- U5: search ---- */
.mkt-search-wrap { margin: 2px 0 16px; }
.mkt-search {
  width: 100%; box-sizing: border-box; padding: 12px 18px; font-size: 15px;
  background: var(--card); color: var(--ink); border: 1.5px solid var(--line); border-radius: 999px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.mkt-search:focus { border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(34,197,94,.15); }

/* ---- U5: rails (safe-center horizontal scroll — the ribbon lesson) ---- */
.mkt-rail { margin: 0 0 18px; }
.mkt-rail-title { font-size: 16px; font-weight: 750; color: var(--ink); margin: 0 0 10px; }
.mkt-rail-row {
  display: flex; gap: 12px; overflow-x: auto; padding: 2px 2px 8px; scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.mkt-rail-row > .mkt-card { flex: 0 0 156px; scroll-snap-align: start; }
.mkt-rail-row::-webkit-scrollbar { height: 6px; }
.mkt-rail-row::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }

/* ---- U5: ratings ---- */
.mkt-card-rating { font-size: 12px; font-weight: 750; color: #f59e0b; white-space: nowrap; margin-left: auto; }
.mkt-card-meta { gap: 8px; }
.mkt-rate { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.mkt-rate-label { font-size: 13px; color: var(--muted); margin-right: 6px; }
.mkt-rate-star { background: none; border: none; font-size: 20px; color: var(--line); cursor: pointer; padding: 2px; transition: color .12s, transform .12s; }
.mkt-rate-star:hover { transform: scale(1.15); }
.mkt-rate-star.on, .mkt-rate-star:hover, .mkt-rate-star:hover ~ .mkt-rate-star.on { color: #f59e0b; }

/* ---- U6: pack cards + sheet ---- */
.mkt-pack-thumbs { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 2px; }
.mkt-pack-thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mkt-pack-thumbs img[data-broken="1"] { visibility: hidden; }
.mkt-pack-items { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow-y: auto; }
.mkt-pack-item { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink); min-width: 0; }
.mkt-pack-item img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; flex: none; }

/* ---- U6: the site-search federation section ---- */
.mkt-fed { margin: 14px 0 6px; }
.mkt-fed .mkt-rail-title { display: flex; align-items: baseline; gap: 12px; }

/* ---- U5: template cards ---- */
.mkt-card-template .mkt-thumb { background: linear-gradient(135deg, rgba(99,102,241,.14), rgba(16,185,129,.14)); }
.mkt-tpl-teaser { display: flex; align-items: center; justify-content: center; height: 100%; padding: 14px; font-size: 13px; line-height: 1.45; color: var(--ink); font-style: italic; text-align: center; }
.mkt-tpl-teaser-big { font-size: 16px; }

/* ---- U4: the creator's P&L ---- */
.mkt-earn-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 6px 0 16px; }
.mkt-earn-tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mkt-earn-n { font-size: 20px; font-weight: 800; color: var(--ink); }
.mkt-earn-l { font-size: 12px; color: var(--muted); }
.mkt-earn-row { display: flex; align-items: center; gap: 12px; min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.mkt-earn-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.mkt-earn-line1 { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; min-width: 0; }
.mkt-earn-stat { font-size: 12px; color: var(--muted); white-space: nowrap; }
.mkt-earn-bar { height: 8px; border-radius: 999px; background: rgba(127,127,127,.14); overflow: hidden; }
.mkt-earn-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #f59e0b, #facc15); transition: width .4s var(--gx-ease, ease); }
.mkt-earn-fill.profit { background: var(--gx-grad, linear-gradient(90deg, #10b981, #22c55e)); }
.mkt-earn-sub { font-size: 12px; color: var(--muted); }

/* the first-sale moment — one gentle celebration, never a popup */
.mkt-first-sale { display: flex; align-items: center; gap: 14px; background: linear-gradient(135deg, rgba(16,185,129,.12), rgba(132,204,22,.12)); border: 1.5px solid var(--brand-500); border-radius: 16px; padding: 14px 16px; margin: 0 0 14px; font-size: 14px; color: var(--ink); }
.mkt-first-sale span { color: var(--muted); font-size: 13px; }
.mkt-first-sale-burst { font-size: 28px; animation: mktPop .6s var(--gx-ease, ease); }
@keyframes mktPop { 0% { transform: scale(.4) rotate(-15deg); } 70% { transform: scale(1.25) rotate(6deg); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .mkt-first-sale-burst { animation: none; } }

/* ---- U4: the public storefront ---- */
.mkt-store { margin: 10px 0 22px; }
.mkt-store-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 8px 0 14px; }
.mkt-store-stats { display: flex; flex-wrap: wrap; gap: 14px; font-size: 14px; color: var(--muted); }
.mkt-store-stat strong { color: var(--ink); }
.mkt-store-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.mkt-store-badge { font-size: 11px; font-weight: 700; color: var(--brand-500); border: 1px solid var(--brand-500); border-radius: 999px; padding: 3px 10px; }

/* ---- U2: the Purchases list (profile tab) ---- */
.mkt-purchases { display: flex; flex-direction: column; gap: 10px; }
.mkt-purchase-row {
  display: flex; align-items: center; gap: 12px; min-width: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px;
}
.mkt-purchase-thumb { width: 56px; height: 56px; border-radius: 10px; overflow: hidden; flex: none; background: linear-gradient(135deg, rgba(16,185,129,.12), rgba(132,204,22,.12)); }
.mkt-purchase-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mkt-purchase-thumb img[data-broken="1"] { display: none; }
.mkt-purchase-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mkt-purchase-title { font-size: 14px; font-weight: 650; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mkt-purchase-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mkt-purchase-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.mkt-purchase-refunded { font-size: 11px; font-weight: 700; color: #b45309; background: rgba(245,158,11,.14); border-radius: 999px; padding: 3px 9px; }
.mkt-btn-small { padding: 8px 14px; font-size: 13px; font-weight: 700; color: #fff; background: var(--brand-500); border: none; border-radius: 999px; cursor: pointer; }
.mkt-btn-small:hover { filter: brightness(1.06); }

/* ---- CI4: the cash-in storefront (pricing.html #credits) + resume toast ---- */
.packs-balance {
  text-align: center; font-size: 13.5px; font-weight: 700; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  width: fit-content; margin: 0 auto 16px; padding: 7px 16px;
}
.pack-card { position: relative; }
.pack-card.pack-best { border-color: var(--brand-500); box-shadow: 0 0 0 1px var(--brand-500) inset; }
.pack-tag {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  font-size: 11px; font-weight: 800; letter-spacing: .02em; white-space: nowrap;
  color: #fff; background: var(--brand-500); border-radius: 999px; padding: 3px 10px;
}
.pack-meta { font-size: 12.5px; color: var(--muted); }
.pack-meta strong { color: var(--brand-600, var(--brand-500)); }
.mkt-toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 1400; max-width: min(92vw, 360px);
  font-size: 13.5px; font-weight: 700; color: #fff; background: rgba(17, 24, 39, .92);
  border-radius: 999px; padding: 10px 18px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  animation: mktToastIn .25s ease;
}
.mkt-toast-out { opacity: 0; transition: opacity .35s ease; }
@keyframes mktToastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
