/* ── Layout ── */
#box_marketplace {
  margin-top: 32px;
  margin-bottom: 32px;
  height: 800px;
  overflow-y: auto;
}

/* ── Header ── */
#mp_header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

#mp_title {
  color: var(--color-black);
  margin: 0 0 4px;
}

#mp_subtitle {
  font-size: 13px;
  color: var(--color-greyMedium);
  margin: 0;
}

#mp_submit_btn {
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
  background: transparent;
  border: 1.5px solid var(--color-primary);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  cursor: pointer;
  transition: background var(--motion-fast);
  flex-shrink: 0;
}

#mp_submit_btn:hover {
  background: var(--color-primaryLight);
}

/* ── How to use ── */
#mp_howto {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--color-primaryWash);
  border: 1px solid var(--color-primaryLight);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--color-greyDark);
  margin-bottom: 24px;
  line-height: 1.6;
  word-break: break-word;
}

#mp_howto svg {
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--color-primaryDark);
}

#mp_howto strong {
  color: var(--color-black);
}

/* ── SSR ?s= deep-link content (crawler-visible, no-JS fallback) ── */
#mp_ssr_detail {
  margin-bottom: 24px;
}

#mp_ssr_detail h4 {
  color: var(--color-black);
  margin: 0 0 8px;
}

#mp_ssr_detail .mp-card-desc {
  -webkit-line-clamp: unset;
  overflow: visible;
}

/* ── Submit modal balance + withdraw ── */
.mp-modal-divider {
  border: none;
  border-top: 1px solid var(--color-greyLight);
  margin: 4px 0;
}

.mp-balance-withdraw-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mp-withdraw-balance-label {
  font-size: 12px;
  color: var(--color-greyMedium);
  margin-bottom: 2px;
}

.mp-withdraw-balance-amount {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-black);
}

.mp-btn-withdraw {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
  text-decoration: none;
  border: 1.5px solid var(--color-primary);
  border-radius: var(--radius-sm);
  padding: 7px 16px;
  transition: background var(--motion-fast);
  white-space: nowrap;
}

.mp-btn-withdraw:hover {
  background: var(--color-primaryLight);
  color: var(--color-primaryDark);
}

/* ── Submit modal steps ── */
.mp-howto-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--color-greyDark);
  line-height: 1.6;
}

.mp-step-num {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-primaryLight);
  color: var(--color-primaryDark);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

/* ── Loader ── */
#mp_loader {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 360px;
}

.mp-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-greyLight);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: mp-spin 0.7s linear infinite;
}

@keyframes mp-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Empty ── */
#mp_empty {
  text-align: center;
  padding: 120px 0;
  color: var(--color-greyMedium);
  font-size: 14px;
}

/* ── Grid ── */
#mp_grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  align-items: start;
}

/* ── Card ── */
.mp-card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow var(--motion-fast);
}

.mp-card:hover {
  box-shadow: var(--shadow-brand);
}

/* SSR grid cards are real <a> elements (crawlable href), styled identical
   to the JS-built <div> cards — reset the browser anchor defaults only. */
.mp-card-ssr {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.mp-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mp-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-primaryDark);
  background: var(--color-primaryLight);
  border-radius: var(--radius-xs);
  padding: 2px 8px;
  text-transform: capitalize;
}

.mp-purchased-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-greenBlack);
  background: var(--color-greenLight);
  border-radius: var(--radius-xs);
  padding: 2px 8px;
}

.mp-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-black);
  margin: 0;
  line-height: 1.4;
}

.mp-card-desc {
  font-size: 13px;
  color: var(--color-greyDark);
  margin: 0;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Card P&L chart (Version A: chart above the short description, low-key) ──
   Inner well recipe — transparent + 1px greyLight border, never body-color
   filled. object-fit:contain shows the full report.pnl_image_url (axis
   labels included, sized for the modal's full-width chart) without cropping;
   height raised from the initial 64px so the ~1.75:1 image still reads at a
   legible size instead of shrinking to a postage stamp.
   TODO(designer, non-blocking): a dedicated axis-free `pnl_thumb_url` would
   read cleaner and allow a shorter card; v1 reuses the one PNG the API
   already has. */
.mp-card-chart-wrap {
  overflow: hidden;
  background: transparent;
  height: 162px;
}

.mp-card-chart-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity var(--motion-fast) var(--ease-standard);
}

.mp-card-chart-img.loaded {
  opacity: 1;
}

.mp-card-chart-skeleton {
  width: 100%;
  height: 100%;
  background: var(--color-greyLight);
}

[data-state="loaded"] .mp-card-chart-skeleton {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .mp-card-chart-img {
    transition: none;
  }
}

.mp-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}

.mp-card-price {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-black);
}

.mp-buy-btn {
  background: var(--color-primary);
  color: var(--color-pureWhite);
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--motion-fast);
}

.mp-buy-btn:hover {
  background: var(--color-primaryDark);
}

.mp-owned-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-greenBlack);
}

.mp-note-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: #7a5a1e;
  background: #fef3cd;
  border-radius: var(--radius-xs);
  padding: 2px 8px;
  text-decoration: none;
  transition: background var(--motion-fast);
}

.mp-note-badge:hover {
  background: #fde89a;
  color: #5a3e0e;
}

.mp-owner-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: #5a6a9a;
  background: #eef0fa;
  border-radius: var(--radius-xs);
  padding: 2px 8px;
}

.mp-card-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mp-download-count {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--color-greyMedium);
}

/* ── Modal ── */
.mp-modal {
  border-radius: var(--radius-xl);
  border: none;
  overflow: hidden;
}

.mp-modal-header {
  display: flex;
  justify-content: space-between;
  padding: 20px 0px;
  border-bottom: 1px solid var(--color-greyLight);
}

.mp-modal-header h6 {
  margin: 0;
  font-weight: 700;
  font-size: 16px;
  color: var(--color-black);
  white-space: normal;
}

.mp-modal-body {
  /* bottom 20 → 12: modal-content's own bottom inset already covers the
     tail; 20px here doubled up into a hollow below the footnote */
  padding: 20px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mp-modal-body p {
  margin: 0;
  font-size: 13px;
  color: var(--color-greyDark);
  line-height: 1.6;
}

.mp-price-row,
.mp-balance-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-greyLight);
}

.mp-balance-row {
  border-bottom: none;
}

.mp-price-label {
  font-size: 13px;
  color: var(--color-greyDark);
}

.mp-price-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-black);
}

.mp-topup-box {
  background: var(--color-primaryWash);
  border: 1px solid var(--color-primaryLight);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

.mp-topup-box p {
  color: var(--color-primaryDark);
  font-size: 13px;
  margin: 0;
}

.mp-nocard-box {
  border: 1px solid var(--color-greyLight);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

.mp-nocard-box p {
  color: var(--color-greyDark);
  font-size: 13px;
  margin: 0;
}

.mp-nocard-box a {
  color: var(--color-primary);
  font-weight: 600;
  text-decoration: none;
}

.mp-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  /* top 20 → 8, bottom 20 → 0: modal-content's own 25px bottom inset is
     the inset below the button — 20+25 was a double bottom margin */
  padding: 8px 0 0;
}

.mp-btn-primary {
  background: var(--color-primary);
  color: var(--color-pureWhite);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--motion-fast);
}

.mp-btn-primary:hover:not(:disabled) {
  background: var(--color-primaryDark);
}

.mp-btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.mp-btn-secondary {
  background: transparent;
  color: var(--color-greyDark);
  border: 1.5px solid var(--color-greyLight);
  border-radius: var(--radius-sm);
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--motion-fast);
}

.mp-btn-secondary:hover {
  border-color: var(--color-greyMedium);
}

/* ── Tabs + sort toolbar row ── */
#mp_toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

#mp_tabs {
  display: flex;
  gap: 6px;
}

/* Sort control — canon Dropdown menu recipe (trigger+caret / panel / plain
   items / selected = pure bold, no fill/icon) */
.mp-sort {
  position: relative;
}

.mp-sort-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  border: 1.5px solid var(--color-greyLight);
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 13px;
  color: var(--color-greyDark);
  cursor: pointer;
  position: relative;
  transition: all var(--motion-fast);
}

.mp-sort-trigger:hover {
  border-color: var(--color-greyMedium);
  color: var(--color-black);
}

/* invisible hit-area bump to 44px (canon touch target) without growing the
   visual 32px control — same technique as .mp-note-link's negative margin,
   adapted for a centered box since this trigger isn't a padded inline link */
.mp-sort-trigger::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 44px;
  min-width: 44px;
  transform: translate(-50%, -50%);
}

.mp-sort-trigger .sort-label {
  color: var(--color-greyMedium);
}

.mp-sort-trigger .sort-value {
  font-weight: 600;
  color: var(--color-black);
}

.mp-sort-caret {
  width: 7px;
  height: 7px;
  border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: rotate(45deg);
  transition: transform var(--motion-fast) var(--ease-standard);
  color: var(--color-greyMedium);
}

.mp-sort.open .mp-sort-caret {
  transform: rotate(-135deg);
}

.mp-sort-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--color-surface);
  border: 1px solid var(--color-greyLight);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 6px;
  display: none;
  z-index: 20;
}

.mp-sort.open .mp-sort-panel {
  display: block;
}

.mp-sort-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--color-greyDark);
}

.mp-sort-item:hover {
  background: var(--color-greyLight);
  color: var(--color-black);
}

.mp-sort-item.selected {
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .mp-sort-caret {
    transition: none;
  }
}

.mp-tab {
  background: transparent;
  border: 1.5px solid var(--color-greyLight);
  border-radius: var(--radius-sm);
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-greyDark);
  cursor: pointer;
  transition: all var(--motion-fast);
}

.mp-tab:hover {
  border-color: var(--color-greyMedium);
  color: var(--color-black);
}

.mp-tab.active {
  background: var(--color-black);
  border-color: var(--color-black);
  color: var(--color-pureWhite);
}

/* ── Official badge ── */
.mp-official-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-primaryDark);
  background: var(--color-primary);
  color: var(--color-pureWhite);
  border-radius: var(--radius-xs);
  padding: 2px 8px;
}

/* ── Free label ── */
.mp-free-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primaryDark);
}

/* ── Card badges group ── */
.mp-card-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
}

/* ── Card metrics ── */
.mp-card-metrics {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 0;
  border-top: 1px solid var(--color-greyLight);
}

.mp-card-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ── Stat label/value (canon "Beginner strategy card + metric gloss") ── */
.mp-card-metrics .sl {
  font-size: 11px;
  color: var(--color-greyMedium);
}

/* has-tip already sets the dotted underline (main.css); as a flex-column
   child it would otherwise stretch to the container width — clip it to
   the label text itself */
.mp-card-metrics .sl.has-tip {
  width: fit-content;
}

.mp-card-metrics .sv {
  font-family: "Roboto Mono", monospace;
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  font-weight: 600;
  color: var(--color-black);
}

.mp-card-metrics .sv.pos {
  color: var(--color-greenText);
}

.mp-card-metrics .sv.neg {
  color: var(--color-redText);
}

/* ── Card cursor ── */
.mp-card {
  cursor: pointer;
}

/* ── Detail modal title row ── */
.mp-modal-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}

#detail_badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ── Detail desc ── */
.mp-detail-desc {
  font-size: 13px;
  color: var(--color-greyDark);
  line-height: 1.6;
  margin: 0;
}

/* ── Metrics grid in modal ──
   background: transparent (not --color-white) — Inner well fix, kept from
   the marketplace redesign round even though the stat-strip layout itself
   was reverted. */
.mp-metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 16px;
  background: transparent;
  border: 1px solid var(--color-greyLight);
  border-radius: var(--radius-lg);
}

.mp-metric {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mp-metric-label {
  font-size: 11px;
  color: var(--color-greyMedium);
}

.mp-metric-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-black);
}

.mp-metric-red {
  color: var(--color-red);
}

.mp-metric-value.pos {
  color: var(--color-greenText);
}

.mp-metric-value.neg {
  color: var(--color-redText);
}

/* ── P&L chart — background: transparent (not --color-white), Inner well
   fix, kept from the marketplace redesign round ── */
.mp-pnl-chart-wrap {
  margin-top: 16px;
  border: 1px solid var(--color-greyLight);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: transparent;
}

.mp-pnl-img {
  width: 100%;
  display: block;
}

.mp-backtest-period {
  font-size: 11px;
  color: var(--color-greyMedium);
  margin: 0;
}

/* evidence footnote row — LEFT-aligned with the modal's single content
   edge (desc / metrics / PnL chart); never right-aligned: a right-hung
   link stacks visually with the right-aligned deploy button below */
.mp-report-foot {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  gap: 4px 16px;
  flex-wrap: wrap; /* 390: link wraps under the period, still left-aligned */
}

.mp-report-foot:empty {
  display: none;
}

/* evidence link — first-batch CTA language (success_note #box_claw_cta /
   dashboard strat_cta), not the card-badge chip */
.mp-note-link {
  display: inline-block;
  /* touch target ≥44px, decoupled from layout height: 13px padding keeps
     the 44px hit area (12px font × 1.5 line-height ≈ 18 + 2×13 = 44;
     12px padding measured 42 — bumped, not guessed), negative margin
     collapses the occupied row back to text height (~19px). Neighbor
     safety: above is the non-clickable PnL image (12px body gap), below
     the deploy button sits 20px+ away — the invisible hit zone overlaps
     nothing clickable */
  padding: 13px 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-black);
  text-decoration: underline;
  transition: color var(--motion-fast) var(--ease-standard);
}

/* the negative margin needs 0,2,0 specificity — main.css's global
   a:lang(zh/en/cn) rule (0,1,1) re-asserts margin:0 over a bare class */
.mp-report-foot .mp-note-link {
  margin: -13px 0;
}

.mp-note-link:hover {
  color: var(--color-greyDark);
}

/* ── Code section ── */
.mp-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-greyDark);
}

.mp-btn-copy-code {
  background: transparent;
  border: 1px solid var(--color-greyLight);
  border-radius: var(--radius-xs);
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-greyDark);
  cursor: pointer;
  transition: border-color var(--motion-fast);
}

.mp-btn-copy-code:hover {
  border-color: var(--color-greyMedium);
}

.mp-code-block {
  background: var(--color-white);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 12px;
  line-height: 1.6;
  max-height: 220px;
  overflow-y: auto;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── How-to hint ── */
.mp-howto-hint {
  background: var(--color-primaryWash);
  border: 1px solid var(--color-primaryLight);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

.mp-howto-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-greyDark);
  margin: 0 0 8px;
}

.mp-howto-cmd-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* command is mixed CJK + strategy title — Han never goes into mono
   (canon › Type), so the whole field stays on the sans stack */
.mp-howto-cmd {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-black);
  background: transparent;
  word-break: break-all;
}

.mp-btn-copy-hint {
  flex-shrink: 0;
  background: var(--color-primary);
  color: var(--color-pureWhite);
  border: none;
  border-radius: var(--radius-xs);
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--motion-fast);
}

.mp-btn-copy-hint:hover {
  background: var(--color-primaryDark);
}

/* ── RWD ── */
@media (max-width: 1300px) {
  #box_marketplace {
    margin-top: 0;
  }

  #mp_howto {
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
  }

  #mp_howto svg {
    display: none;
  }
}

@media (max-width: 768px) {
  #mp_header {
    flex-direction: column;
    align-items: flex-start;
  }

  #mp_grid {
    grid-template-columns: 1fr;
  }

  #mp_howto {
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px;
    font-size: 12px;
  }

  #mp_howto svg {
    display: none;
  }

  #detailModal .modal-dialog,
  #submitModal .modal-dialog {
    width: 350px;
    margin-left: auto;
    margin-right: auto;
  }

  .mp-modal-title-row h6 {
    font-size: 14px;
    flex-shrink: 1;
    min-width: 0;
  }

  .mp-metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* toolbar wraps to a second row here, so .mp-sort sits near the left
     edge — a right-anchored panel would overhang past the viewport's left
     edge and get clipped. Anchor from the left instead. */
  .mp-sort-panel {
    left: 0;
    right: auto;
  }
}

a.mp-btn-deploy {
  display: inline-block;
  text-decoration: none;
  text-align: center;
}

a.mp-btn-deploy:hover {
  background: var(--color-primaryDark);
  color: var(--color-pureWhite);
}

@media (max-width: 1300px) {
  #mp_title {
    display: none;
  }
}
