/* ==========================================================================
 * ui-enhance.css —— 非画布页 UI 增强层 v2（明显可见的科技感 + 交互）
 * --------------------------------------------------------------------------
 * 边界：只服务非画布页面。画布（workspace/canvas/projects 及 iframe 子页）
 * 不引入本文件，零影响。首页 index 用 --h-* 独立变量，配色分支单独处理。
 *
 * 原则：
 *   1. 颜色优先用现有 var(--*)，天然跟随黑白主题；叠加分支用 [data-theme]。
 *   2. 只加不删：不改 site.css/home.css 原文，同特异性后加载胜出。
 *   3. 尊重 prefers-reduced-motion。
 * ========================================================================== */

/* ---------- 0. 浅色主题终局覆盖（修复 site.css:2022 深色 :root 误压浅色） ---------- */
html[data-theme="light"] body:not([data-page="home"]):not([data-page="canvas"]) {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef1f7;
  --ink: #16203a;
  --muted: #5c6785;
  --subtle: #98a2b3;
  --line: #e2e7f0;
  --primary: #5451d8;
  --primary-dark: #413eb4;
  --primary-soft: #ecebff;
  --cyan: #189fb5;
  --cyan-soft: #e2f7fb;
  --orange: #ec7f45;
  --orange-soft: #fff0e7;
  --success: #1f9e64;
  --success-soft: #e6f8ef;
  --danger: #d34b58;
  --danger-soft: #ffeff1;
  --shadow: 0 14px 34px rgba(36, 52, 92, .09);
  color-scheme: light;
}

/* ---------- 1. SVG 图标基础 ---------- */
.ui-ico {
  display: inline-block;
  width: 18px;
  height: 18px;
  vertical-align: -0.15em;
  flex: 0 0 auto;
  transition: transform .18s ease, filter .18s ease;
}
.ui-ico-host {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.rail-icon .ui-ico, .mobile-menu .ui-ico, .header-icon .ui-ico { width: 20px; height: 20px; }
.bp-glyph .ui-ico { width: 15px; height: 15px; vertical-align: -0.2em; }
[data-theme-icon] .ui-ico { width: 18px; height: 18px; }

/* v2 新覆盖图标的尺寸 */
.content-stat i.ui-ico-host .ui-ico,
.mc-icon.ui-ico-host .ui-ico { width: 15px; height: 15px; }
.market-icon.ui-ico-host .ui-ico { width: 26px; height: 26px; }
.model-logo.ui-ico-host .ui-ico { width: 22px; height: 22px; }
.search-box > span.ui-ico-host .ui-ico,
.market-search > span.ui-ico-host .ui-ico,
.docs-search > span.ui-ico-host .ui-ico { width: 17px; height: 17px; }
button > span.ui-ico-host .ui-ico { width: 16px; height: 16px; }
.btn-tail-ico { margin-left: 2px; }
.btn-tail-ico .ui-ico { width: 16px; height: 16px; }

/* 点赞/收藏点亮态：SVG 描边变主色 + 微光 */
html[data-theme="dark"] .content-stat.is-active i.ui-ico-host .ui-ico {
  color: var(--primary);
  filter: drop-shadow(0 0 5px color-mix(in srgb, var(--primary) 70%, transparent));
}
html[data-theme="light"] .content-stat.is-active i.ui-ico-host .ui-ico {
  color: var(--danger);
  filter: drop-shadow(0 0 4px color-mix(in srgb, var(--danger) 45%, transparent));
}
.content-stat.is-clickable { cursor: pointer; }
.content-stat.is-clickable i.ui-ico-host { transition: transform .16s ease; }
.content-stat.is-clickable:hover i.ui-ico-host { transform: scale(1.25); }
.content-stat.is-clickable:active i.ui-ico-host { transform: scale(.92); }

/* 交互：图标随宿主 hover 轻微放大 */
a:hover > .ui-ico-host .ui-ico,
button:hover > .ui-ico-host .ui-ico,
.rail-link:hover .rail-icon .ui-ico { transform: scale(1.1); }

/* 主题切换按钮 */
.ui-theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  transition: background-color .18s ease, transform .25s cubic-bezier(.2,.8,.2,1);
}
.ui-theme-toggle:hover { transform: rotate(20deg) scale(1.08); }

/* ---------- 2. 统一焦点环 ---------- */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 7px;
}

/* ---------- 3. 按钮交互：按压 + 光泽扫过 ---------- */
.button, .btn { position: relative; overflow: hidden; }
.button, .btn, .top-nav a, .rail-link, .account-link {
  transition: background-color .2s ease, border-color .2s ease,
              color .2s ease, transform .16s ease, box-shadow .22s ease;
}
.button:not([disabled]):hover, .btn:not([disabled]):hover { transform: translateY(-2px); }
.button:active, .btn:active { transform: translateY(0) scale(.98); }
.button[disabled], .btn[disabled], button[disabled] { opacity: .5; cursor: not-allowed; }

/* 主按钮流光扫过 */
.button-primary::before, .btn-primary::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 25%, rgba(255,255,255,.28) 50%, transparent 75%);
  transform: translateX(-120%);
  transition: transform .55s ease;
  pointer-events: none;
}
.button-primary:hover::before, .btn-primary:hover::before { transform: translateX(120%); }
html[data-theme="dark"] .button-primary,
html[data-theme="dark"] .btn-primary {
  box-shadow: 0 6px 20px color-mix(in srgb, var(--primary) 32%, transparent);
}
html[data-theme="dark"] .button-primary:hover {
  box-shadow: 0 10px 28px color-mix(in srgb, var(--primary) 50%, transparent);
}

/* ---------- 4. 顶栏：玻璃质感 + 渐变描边 ---------- */
html[data-theme="dark"] body:not([data-page="home"]) .site-header {
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  border-bottom-color: transparent;
}
html[data-theme="dark"] body:not([data-page="home"]) .site-header::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), var(--primary), var(--orange), transparent);
  background-size: 200% 100%;
  animation: ui-hue-flow 8s linear infinite;
  pointer-events: none;
}
html[data-theme="light"] body:not([data-page="home"]) .site-header {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(130%);
  backdrop-filter: blur(14px) saturate(130%);
}
/* §494 浅色主题也用流动彩线（原先只有静态淡线，用户反馈「项目页的线不会动」） */
html[data-theme="light"] body:not([data-page="home"]) .site-header::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), var(--primary), var(--orange), transparent);
  background-size: 200% 100%;
  animation: ui-hue-flow 8s linear infinite;
  opacity: .6; pointer-events: none;
}
@keyframes ui-hue-flow { 0% { background-position: 0 0; } 100% { background-position: 200% 0; } }

/* 首页顶栏：仅加玻璃，不动影院色调 */
html[data-theme="dark"] body[data-page="home"] .site-header {
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  backdrop-filter: blur(16px) saturate(150%);
}

/* ---------- 5. 卡片：渐变描边 + hover 抬升光晕（明显） ---------- */
.model-card, .template-card, .resource-card, .project-card,
.stat-card, .metric-card, .creator-card,
.market-card, .content-card, [class$="-card"] {
  position: relative;
  transition: transform .24s cubic-bezier(.2,.8,.2,1), box-shadow .24s ease, border-color .24s ease;
}
/* 渐变描边（伪元素，不影响布局） */
.model-card::after, .template-card::after, .resource-card::after,
.market-card::after, .content-card::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--cyan) 55%, transparent),
              transparent 45%, color-mix(in srgb, var(--primary) 55%, transparent));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  opacity: 0; transition: opacity .26s ease; pointer-events: none;
}
html[data-theme="dark"] .model-card:hover,
html[data-theme="dark"] .template-card:hover,
html[data-theme="dark"] .resource-card:hover,
html[data-theme="dark"] .project-card:hover,
html[data-theme="dark"] .market-card:hover,
html[data-theme="dark"] .content-card:hover,
html[data-theme="dark"] .stat-card:hover,
html[data-theme="dark"] .metric-card:hover {
  transform: translateY(-6px);
  border-color: color-mix(in srgb, var(--primary) 60%, var(--line));
  box-shadow: 0 20px 46px rgba(0, 0, 0, .5),
              0 0 26px color-mix(in srgb, var(--primary) 22%, transparent);
}
html[data-theme="dark"] .model-card:hover::after,
html[data-theme="dark"] .template-card:hover::after,
html[data-theme="dark"] .resource-card:hover::after,
html[data-theme="dark"] .market-card:hover::after,
html[data-theme="dark"] .content-card:hover::after { opacity: 1; }
html[data-theme="light"] .model-card:hover,
html[data-theme="light"] .template-card:hover,
html[data-theme="light"] .resource-card:hover,
html[data-theme="light"] .project-card:hover,
html[data-theme="light"] .market-card:hover,
html[data-theme="light"] .content-card:hover,
html[data-theme="light"] .stat-card:hover,
html[data-theme="light"] .metric-card:hover {
  transform: translateY(-5px);
  border-color: color-mix(in srgb, var(--primary) 45%, var(--line));
  box-shadow: 0 18px 40px rgba(36, 52, 92, .14),
              0 0 0 1px color-mix(in srgb, var(--primary) 12%, transparent);
}
html[data-theme="light"] .model-card:hover::after,
html[data-theme="light"] .template-card:hover::after,
html[data-theme="light"] .resource-card:hover::after,
html[data-theme="light"] .market-card:hover::after,
html[data-theme="light"] .content-card:hover::after { opacity: .9; }

/* 卡片内主图 hover 轻微放大 */
.model-card:hover .model-logo, .market-card:hover .market-cover,
.content-card:hover .thumb, .home-card:hover .thumb {
  transform: scale(1.04);
  transition: transform .35s ease;
}

/* 数字等宽对齐 */
.stat-card strong, .metric-card strong, .bp-glyph + b,
[data-header-diamonds], [data-header-points],
table td, .data-number { font-variant-numeric: tabular-nums; }

/* 顶栏 active 科技下划线 */
.top-nav a.is-active { position: relative; }
.top-nav a.is-active::after {
  content: ""; position: absolute; left: 12%; right: 12%; bottom: -6px; height: 2px;
  border-radius: 2px; background: var(--primary);
  box-shadow: 0 0 10px color-mix(in srgb, var(--cyan) 70%, transparent);
}

/* ---------- 6. 搜索框：聚焦发光 ---------- */
.search-box, .market-search, .docs-search {
  transition: box-shadow .22s ease, border-color .22s ease;
}
.search-box:focus-within, .market-search:focus-within, .docs-search:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent),
              0 0 20px color-mix(in srgb, var(--cyan) 18%, transparent);
}

/* ---------- 7. Toast（沿用现有 DOM + 进场动效） ---------- */
.toast { animation: ui-toast-in .28s cubic-bezier(.2,.8,.2,1); }
@keyframes ui-toast-in {
  from { opacity: 0; transform: translateY(-10px) scale(.96); }
  to { opacity: 1; transform: none; }
}

/* ---------- 8. 骨架屏 / 空态 ---------- */
.ui-skeleton {
  background: linear-gradient(90deg, var(--surface-soft) 25%, var(--line) 37%, var(--surface-soft) 63%);
  background-size: 400% 100%;
  animation: ui-shimmer 1.4s ease infinite;
  border-radius: 8px;
}
@keyframes ui-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.ui-empty {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 44px 20px; color: var(--muted); text-align: center;
}
.ui-empty .ui-ico { width: 42px; height: 42px; color: var(--subtle); }
.ui-empty h3 { margin: 0; font-size: 15px; color: var(--ink); font-weight: 600; }
.ui-empty p { margin: 0; font-size: 13px; }

/* ---------- 9. 进场动画：卡片逐个淡入（错峰） ---------- */
.content-wrap > *:first-child { animation: ui-page-in .3s ease both; }
@keyframes ui-page-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.model-grid > *, .market-grid > *, [class$="-grid"] > *:not([hidden]) {
  animation: ui-card-in .38s ease both;
}
.model-grid > *:nth-child(2), .market-grid > *:nth-child(2) { animation-delay: .04s; }
.model-grid > *:nth-child(3), .market-grid > *:nth-child(3) { animation-delay: .08s; }
.model-grid > *:nth-child(4), .market-grid > *:nth-child(4) { animation-delay: .12s; }
.model-grid > *:nth-child(n+5), .market-grid > *:nth-child(n+5) { animation-delay: .16s; }
@keyframes ui-card-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- 10. 表格：斑马纹 hover 高亮 ---------- */
table tbody tr { transition: background-color .18s ease; }
table tbody tr:hover { background: color-mix(in srgb, var(--primary) 7%, transparent); }

/* ---------- 11. 响应式 ---------- */
@media (max-width: 900px) {
  .header-actions { gap: 6px; }
  .header-icon, .mobile-menu { width: 40px; height: 40px; }
  .content-wrap table { display: block; overflow-x: auto; max-width: 100%; }
}
@media (max-width: 560px) {
  .ui-ico { width: 17px; height: 17px; }
  .market-icon.ui-ico-host .ui-ico { width: 22px; height: 22px; }
  .model-grid > *, .market-grid > * { animation: none; }
  .toast-stack { left: 12px; right: 12px; }
}

/* ---------- 12. 减弱动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  .ui-skeleton { animation: none !important; }
}

/* ---------- 13. Bootstrap Icons 字体图标适配（v3） ----------
 * 渲染层已由自绘 SVG 换成 Bootstrap Icons 字体图标（i.bi.ui-ico）。
 * 字体图标靠 font-size 定尺寸，这里把原 SVG 的 width/height 等价映射，
 * 保留 UI 结构（宿主 .ui-ico-host 仍 inline-flex 居中）与 hover/点亮态规则。 */
i.bi.ui-ico {
  display: inline-block;
  width: auto; height: auto;
  line-height: 1;
  font-size: 18px;          /* 对应原 .ui-ico 18px */
  vertical-align: middle;
}
.rail-icon i.bi.ui-ico, .mobile-menu i.bi.ui-ico, .header-icon i.bi.ui-ico { font-size: 20px; }
.bp-glyph i.bi.ui-ico { font-size: 15px; }
[data-theme-icon] i.bi.ui-ico { font-size: 18px; }
.content-stat i.ui-ico-host i.bi.ui-ico,
.mc-icon.ui-ico-host i.bi.ui-ico { font-size: 15px; }
.market-icon.ui-ico-host i.bi.ui-ico { font-size: 26px; }
.model-logo.ui-ico-host i.bi.ui-ico { font-size: 22px; }
.search-box > span.ui-ico-host i.bi.ui-ico,
.market-search > span.ui-ico-host i.bi.ui-ico,
.docs-search > span.ui-ico-host i.bi.ui-ico { font-size: 17px; }
button > span.ui-ico-host i.bi.ui-ico { font-size: 16px; }
.btn-tail-ico i.bi.ui-ico { font-size: 16px; }
.ui-empty i.bi.ui-ico { font-size: 42px; }
@media (max-width: 560px) {
  i.bi.ui-ico { font-size: 17px; }
  .market-icon.ui-ico-host i.bi.ui-ico { font-size: 22px; }
}
