/* 模型市场 / 个人仓库 共用组件层
 *
 * market.css 与 assets.css 原本是同一份样式复制两遍再改前缀（.market-* / .assets-*），
 * 约 7KB 逐字重复，改一边忘另一边就会出现「同一个卡片两个页面长得不一样」。
 * 这里把两边共有的顶栏、工具条、卡片、按钮、浮层、空状态、toast、分页收敛成
 * 一套 .bf-* 组件，页面自己的样式表只留各自独有的部分。
 *
 * 取值一律走 tokens.css 的语义令牌，深浅色由 html[data-theme] 自动切换，
 * 本文件不出现任何写死的十六进制颜色。
 *
 * 加载顺序：tokens.css → market-common.css → 页面样式表。
 */

* { box-sizing: border-box; }

/* 浏览器默认样式里 [hidden] 只是 display:none，作者样式表里任何一条
   display:flex / grid 都会盖过它——原来的 .market-denied{display:flex} 就是这样，
   哪怕带着 hidden 属性，「请先登录」面板照样挂在页面底部。这里显式兜死，
   否则每加一个 display 非 block 的浮层都要单独再写一遍 [hidden]。 */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.grow { flex: 1; }
.bf-hidden { display: none !important; }

/* ---------- 顶栏 ---------- */

.bf-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.bf-navlink {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
.bf-navlink:hover { color: var(--accent); }

.bf-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bf-brand img { width: 32px; height: 32px; border-radius: var(--radius-sm); }
.bf-brand b { font-size: 16px; display: block; line-height: 1.2; }
.bf-brand small { color: var(--text-muted); font-size: 12px; }

.bf-theme {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  flex: none;
  cursor: pointer;
  font-size: 15px;
}
.bf-theme:hover { border-color: var(--border-hover); color: var(--text); }

/* ---------- 主体与标题行 ---------- */

.bf-main {
  flex: 1;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.bf-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.bf-head b { font-size: 18px; display: block; }
.bf-head small { color: var(--text-muted); font-size: 12px; }
.bf-head-count { color: var(--text-muted); font-size: 13px; white-space: nowrap; }

/* ---------- 工具条：搜索 / 下拉 / 药丸页签 ---------- */

.bf-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.bf-search {
  flex: 1 1 220px;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0 10px;
}
.bf-search:focus-within {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.bf-search i { font-style: normal; color: var(--text-muted); font-size: 13px; }
.bf-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 8px 0;
}
.bf-search input::placeholder { color: var(--text-muted); }

.bf-select {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.bf-select:hover { border-color: var(--border-hover); color: var(--text); }
.bf-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.bf-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.bf-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 6px 16px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, color .15s, background .15s;
}
.bf-chip:hover { border-color: var(--accent-border); color: var(--text); }
.bf-chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

/* ---------- 按钮 ---------- */

.bf-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: filter .15s, border-color .15s, color .15s, background .15s;
}
.bf-btn:hover { border-color: var(--accent-border); color: var(--accent); }
.bf-btn:disabled, .bf-btn[aria-disabled="true"] {
  opacity: .55;
  cursor: default;
  filter: none;
  pointer-events: none;
}
.bf-btn--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}
.bf-btn--primary:hover { filter: brightness(1.08); color: var(--on-accent); border-color: var(--accent); }
.bf-btn--ghost {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-weight: 500;
}
.bf-btn--ghost:hover { border-color: var(--accent-border); color: var(--accent); }
.bf-btn--danger { border-color: var(--border); background: var(--surface); color: var(--text-secondary); font-weight: 500; }
.bf-btn--danger:hover { border-color: var(--danger-border); color: var(--danger); }
.bf-btn--sm { padding: 7px 12px; font-size: 13px; }
.bf-btn--block { width: 100%; }

/* ---------- 角标 ---------- */

.bf-badge {
  display: inline-block;
  font-size: 11px;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--surface-sunken);
  color: var(--text-muted);
  line-height: 1.5;
}
.bf-badge--accent { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-border); }
.bf-badge--ok { color: var(--success); background: var(--success-soft); border-color: var(--success-border); }
.bf-badge--warn { color: var(--warn); background: var(--warn-soft); border-color: var(--warn-border); }
.bf-badge--bad { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-border); }
.bf-badge--info { color: var(--info); background: var(--info-soft); border-color: var(--info-border); }

.bf-free { color: var(--success); font-weight: 600; }

/* ---------- 卡片网格 ---------- */

.bf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.bf-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: 0;
  font: inherit;
  color: inherit;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.bf-card--clickable { cursor: pointer; }
.bf-card:hover {
  border-color: var(--accent-border);
  box-shadow: var(--shadow-pop);
  transform: translateY(-2px);
}

/* 棋盘底纹让透明背景的模型缩略图有参照，深浅色各有一套令牌。 */
.bf-cover {
  aspect-ratio: 1 / 1;
  background:
    linear-gradient(var(--stage-grid) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, var(--stage-grid) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--stage);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.bf-cover img {
  width: 82%;
  height: 82%;
  object-fit: contain;
  image-rendering: pixelated;
}
.bf-cover-fallback { font-size: 52px; color: var(--stage-text); font-style: normal; }

/* 封面是懒加载的：进视口才渲染。等待期间给一道扫光，别让人以为卡住了。 */
.bf-cover.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, var(--surface-hover) 50%, transparent 80%);
  opacity: .7;
  animation: bf-shimmer 1.4s ease-in-out infinite;
}
@keyframes bf-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
@media (prefers-reduced-motion: reduce) {
  .bf-cover.is-loading::after { animation: none; }
  .bf-card:hover { transform: none; }
}

.bf-card-body { padding: 12px 14px 12px; flex: 1; min-width: 0; }
.bf-card-body b {
  font-size: 15px;
  display: block;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bf-card-desc {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.6em;
}
.bf-card-tags { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.bf-card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.bf-card-ops {
  display: flex;
  gap: 8px;
  padding: 0 14px 14px;
  margin-top: auto;
}
.bf-card-ops > * { flex: 1; }

/* ---------- 3D 舞台 ---------- */

.bf-stage {
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background:
    linear-gradient(var(--stage-grid) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(90deg, var(--stage-grid) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--stage);
  overflow: hidden;
  position: relative;
  touch-action: none;
}
.bf-stage canvas { display: block; width: 100% !important; height: 100% !important; }
.bf-stage img.bf-stage-flat {
  position: absolute;
  inset: 8%;
  width: 84%;
  height: 84%;
  object-fit: contain;
  image-rendering: pixelated;
}
.bf-stage-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 24px;
  text-align: center;
  color: var(--stage-text);
}
.bf-stage-empty i { font-style: normal; font-size: 42px; }
.bf-stage-empty b { font-size: 14px; font-weight: 500; }
.bf-stage-hint { text-align: center; color: var(--text-muted); font-size: 12px; margin: 10px 0 0; }

/* 代码与纯文本素材摊在舞台上直接看。仓库里已经有真人存进来的 build.gradle、
   mods.toml、LICENSE 这类文件，它们既没有 3D 形状也没有图，原来落到「这个类型
   暂时不支持预览」的空板子上，点进去等于白点一次。 */
.bf-stage-text {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  background: var(--surface);
  color: var(--text-secondary);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-size: 12px;
  line-height: 1.65;
  tab-size: 2;
  text-align: left;
  white-space: pre;
}

/* ---------- 信息面板与键值表 ---------- */

.bf-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.bf-panel-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bf-panel-head h1 { font-size: 22px; margin: 0; }
.bf-panel-desc { color: var(--text-secondary); font-size: 14px; line-height: 1.7; }

.bf-meta { margin: 16px 0; border-top: 1px solid var(--border-subtle); }
.bf-meta > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
}
.bf-meta dt { color: var(--text-muted); }
.bf-meta dd { margin: 0; text-align: right; word-break: break-word; }

.bf-stats { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 0; }
.bf-stat {
  flex: 1 1 90px;
  border: 1px solid var(--border-subtle);
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  text-align: center;
}
.bf-stat b { display: block; font-size: 17px; line-height: 1.3; }
.bf-stat small { color: var(--text-muted); font-size: 11px; }

.bf-actions { display: flex; gap: 12px; margin-top: 20px; flex-wrap: wrap; }
.bf-actions > .bf-btn { flex: 1 1 140px; padding: 12px 0; font-size: 15px; }
.bf-note { color: var(--text-muted); font-size: 12px; margin: 12px 0 0; line-height: 1.6; }
.bf-note a { color: var(--accent); text-decoration: none; }
.bf-note a:hover { text-decoration: underline; }

/* ---------- 空状态 / 无权限 ---------- */

.bf-empty {
  text-align: center;
  padding: 56px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.bf-empty i { font-size: 44px; font-style: normal; line-height: 1; }
.bf-empty b { font-size: 16px; }
.bf-empty small { color: var(--text-muted); font-size: 13px; max-width: 34em; line-height: 1.7; }
.bf-empty-ops { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }

.bf-denied {
  max-width: 420px;
  margin: 72px auto;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.bf-denied i { font-style: normal; font-size: 40px; line-height: 1; }
.bf-denied b { font-size: 17px; }
.bf-denied small { color: var(--text-muted); font-size: 13px; line-height: 1.7; }
.bf-denied .bf-btn { margin-top: 8px; }

/* ---------- 分页 ---------- */

.bf-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
  font-size: 13px;
  color: var(--text-muted);
}
.bf-pager[hidden] { display: none; }

/* ---------- 浮层 ---------- */

.bf-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
}
.bf-modal[hidden] { display: none; }
.bf-modal-card {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-modal);
  padding: 22px 24px 20px;
}
.bf-modal-card h2 { margin: 0 0 4px; font-size: 18px; }
.bf-modal-card > p { color: var(--text-muted); font-size: 13px; margin: 0 0 14px; line-height: 1.6; }
.bf-modal-ops { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

.bf-field { display: block; margin-bottom: 12px; font-size: 13px; color: var(--text-secondary); }
.bf-field > span { display: block; margin-bottom: 5px; }
.bf-field input,
.bf-field select,
.bf-field textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
}
.bf-field textarea { resize: vertical; min-height: 72px; line-height: 1.6; }
.bf-field input:focus,
.bf-field select:focus,
.bf-field textarea:focus {
  outline: 0;
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.bf-field-hint { color: var(--text-muted); font-size: 12px; margin: 4px 0 0; line-height: 1.6; }
/* 不可逆的操作（比如删掉贴图工坊里的原图）要看得出来是警告，不能和普通说明一个样 */
.bf-field-hint--warn {
  margin-top: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
}
.bf-field-hint--warn b { color: var(--danger); }

/* 确认按钮跟着警告框一起变红。openModal() 把确认键写死成 .bf-btn--primary（绿），
   于是「我知道，仍然删除」和「确认移出」长得一模一样——手已经按熟了绿键位置的人
   不会因为多了一段红字就停手。这里不改 JS，只认「这张卡里有 .bf-field-hint--warn」
   这一个信号：警告框只在取不回来的操作上才挂，普通确认弹窗没有它，照旧是绿的。
   #modalError 用的是不带 --warn 的 .bf-field-hint，所以表单校验报错不会误染。 */
.bf-modal-card:has(.bf-field-hint--warn) #modalOk {
  border-color: var(--danger);
  background: var(--danger);
  color: var(--on-accent);
}
.bf-modal-card:has(.bf-field-hint--warn) #modalOk:hover {
  filter: brightness(1.08);
  border-color: var(--danger);
  color: var(--on-accent);
}

/* ---------- Toast ---------- */

.bf-toast {
  position: fixed;
  left: 50%;
  bottom: 36px;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  padding: 10px 20px;
  font-size: 14px;
  z-index: 300;
  max-width: min(90vw, 480px);
  text-align: center;
}
.bf-toast.is-error { color: var(--danger); border-color: var(--danger-border); }

/* ---------- 窄屏 ---------- */

@media (max-width: 860px) {
  .bf-main { padding: 18px 14px 40px; }
  .bf-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .bf-cover-fallback { font-size: 40px; }
  .bf-panel { padding: 16px; }
  .bf-panel-head h1 { font-size: 19px; }

  /* 触摸屏上每个可点的东西至少 40px 高。这里只抬高度、不动宽度和字号，所以版式
     密度只在纵向变松，横向排布和换行位置跟原来一样（筛选 chips 从 28px 抬到 40，
     卡片上的下载/移出从 31.6 抬到 40，顶栏 .bf-navlink 从 17 抬到 40）。
     chip 和 navlink 本来是按 padding 撑高的，min-height 撑起来之后文字会顶在上边，
     所以一并改成 inline-flex 居中。 */
  .bf-navlink {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0 2px;
  }
  .bf-theme { width: 40px; height: 40px; }
  .bf-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
  }
  .bf-btn { min-height: 40px; }
  .bf-select { min-height: 40px; }
  .bf-search { min-height: 40px; }
  .bf-field input,
  .bf-field select { min-height: 40px; }
}

@media (max-width: 640px) {
  /* 顶栏在窄屏折成两行：品牌独占一行，导航项换行排在下面，
     否则「返回 / 品牌 / 两个入口 / 主题」五组元素会把 320px 的屏挤爆。 */
  .bf-topbar {
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 8px 12px;
  }
  .bf-topbar .grow { flex-basis: 100%; height: 0; }
  .bf-brand { order: -1; flex: 1 1 100%; }
  .bf-brand small { display: none; }
  .bf-navlink { font-size: 13px; }

  .bf-head { flex-direction: column; align-items: flex-start; gap: 4px; }
  .bf-toolbar { gap: 6px; }
  .bf-search { flex-basis: 100%; }
  .bf-select { flex: 1 1 46%; }
  .bf-chip { padding: 5px 12px; font-size: 12px; }
  .bf-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .bf-card-body { padding: 10px 12px; }
  .bf-card-body b { font-size: 14px; }
  .bf-card-ops { padding: 0 12px 12px; }
  .bf-modal { padding: 12px; align-items: flex-start; }
  .bf-modal-card { padding: 18px 16px 16px; }
  .bf-toast { bottom: 20px; }
}

@media (max-width: 380px) {
  .bf-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
}
