/* ── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: 'Inter', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input { font-family: inherit; }

/* ── CSS Custom Properties ─────────────────────────────── */
:root {
  --bg:          #0d0d14;
  --bg-side:     #13131e;
  --bg-card:     #17172a;
  --bg-card-h:   #1e1e32;
  --bg-panel:    #1a1a2e;
  --bg-input:    #1e1e2e;
  --border:      #2a2a40;
  --border-h:    #3a3a58;
  --text:        #d8d8f0;
  --text-dim:    #7878a0;
  --text-muted:  #454566;

  --c-p0:        #ff4d4d;
  --c-p1:        #ffb640;
  --c-p2:        #5b8df5;
  --c-micro:     #22d3ee;
  --c-low:       #4ade80;
  --c-mid:       #fbbf24;
  --c-high:      #f87171;
  --c-dynamic:   #a78bfa;
  --c-static:    #64748b;
  --c-single:    #34d399;
  --c-double:    #fb923c;
  --c-grade-a:   #22c55e;
  --c-grade-b:   #3b82f6;
  --c-grade-c:   #f59e0b;
  --c-grade-d:   #ef4444;
  --c-accent:    #5b8df5;

  --radius:      8px;
  --radius-sm:   5px;
  --shadow:      0 4px 20px rgba(0,0,0,.5);
  --transition:  .18s ease;
}

/* ── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-h); border-radius: 3px; }

/* ══════════════════════════════════════════════════════════
   GALLERY PAGE
══════════════════════════════════════════════════════════ */
.gallery-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h1 {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 500;
}
.sidebar-header p {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}
.sidebar-filters {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 16px;
}
.filter-section { border-bottom: 1px solid var(--border); }
.filter-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: color var(--transition);
}
.filter-title:hover { color: var(--text); }
.filter-title .arrow {
  font-size: 9px;
  transition: transform var(--transition);
}
.filter-title.open .arrow { transform: rotate(180deg); }
.filter-body { padding: 4px 12px 10px; display: none; }
.filter-body.open { display: block; }
.filter-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  transition: all var(--transition);
}
.filter-opt:hover { color: var(--text); background: rgba(255,255,255,.04); }
.filter-opt input[type=checkbox],
.filter-opt input[type=radio] {
  width: 13px; height: 13px;
  accent-color: var(--c-accent);
  cursor: pointer;
  flex-shrink: 0;
}
.filter-opt.active { color: var(--text); }
.filter-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.filter-count {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-muted);
  background: rgba(255,255,255,.06);
  padding: 1px 6px;
  border-radius: 10px;
}
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}
.btn-reset {
  font-size: 11px;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 4px;
  transition: all var(--transition);
}
.btn-reset:hover { border-color: var(--border-h); color: var(--text); }

/* ── Gallery Main ──────────────────────────────────────── */
.gallery-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.gallery-topbar {
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-side);
  flex-shrink: 0;
}
.gallery-title { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.gallery-subtitle { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.search-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.search-wrap {
  flex: 1;
  position: relative;
}
.search-wrap svg {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
#search {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px 8px 34px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}
#search::placeholder { color: var(--text-muted); }
#search:focus { border-color: var(--c-accent); }
.sort-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-dim);
  outline: none;
  cursor: pointer;
}
.result-bar {
  padding: 10px 24px;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-side);
}
#result-count { color: var(--text-dim); font-weight: 600; }

/* ── Card Grid ─────────────────────────────────────────── */
.grid-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.no-result {
  grid-column: 1/-1;
  text-align: center;
  padding: 80px 0;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Card ──────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
  display: flex;
  flex-direction: column;
}
.card:hover {
  transform: translateY(-3px);
  border-color: var(--border-h);
  box-shadow: 0 10px 28px rgba(0,0,0,.5);
}
.card-img-wrap {
  position: relative;
  aspect-ratio: 4/5;
  background: var(--bg-panel);
  overflow: hidden;
  flex-shrink: 0;
}
.card-img-wrap img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity .3s, transform .3s;
}
.card:hover .card-img-wrap img { transform: scale(1.03); }
.card-img-wrap img.loading { opacity: 0; }
.card-id-badge {
  position: absolute;
  top: 7px; left: 7px;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(6px);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 700;
  color: rgba(255,255,255,.8);
  letter-spacing: .4px;
}
.card-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a30 0%, #12121e 100%);
}
.card-placeholder .ph-id {
  font-size: 28px;
  font-weight: 700;
  color: rgba(255,255,255,.07);
  letter-spacing: -1px;
}
.card-info {
  padding: 9px 10px 8px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.card-name {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-cluster {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 2px;
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: .3px;
  white-space: nowrap;
}
.tag-priority { background: rgba(var(--tc),0.15); color: rgb(var(--tc)); }
.tag-p0  { background: rgba(255,77,77,.18); color: var(--c-p0); }
.tag-p1  { background: rgba(255,182,64,.18); color: var(--c-p1); }
.tag-p2  { background: rgba(91,141,245,.18); color: var(--c-p2); }
.tag-motion-dynamic { background: rgba(167,139,250,.15); color: var(--c-dynamic); }
.tag-motion-static  { background: rgba(100,116,139,.15); color: var(--c-static); }
.tag-hands-single   { background: rgba(52,211,153,.15); color: var(--c-single); }
.tag-hands-double   { background: rgba(251,146,60,.15); color: var(--c-double); }
.tag-energy-micro { background: rgba(34,211,238,.15); color: var(--c-micro); }
.tag-energy-low   { background: rgba(74,222,128,.15); color: var(--c-low); }
.tag-energy-mid   { background: rgba(251,191,36,.15); color: var(--c-mid); }
.tag-energy-high  { background: rgba(248,113,113,.15); color: var(--c-high); }
.tag-grade-A { background: rgba(34,197,94,.18); color: var(--c-grade-a); }
.tag-grade-B { background: rgba(59,130,246,.18); color: var(--c-grade-b); }
.tag-grade-C { background: rgba(245,158,11,.18); color: var(--c-grade-c); }
.tag-grade-D { background: rgba(239,68,68,.18); color: var(--c-grade-d); }

.card-score-bar {
  margin-top: 7px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.score-bar-track {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.score-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--c-accent);
  transition: width .4s ease;
}
.score-val {
  font-size: 10px;
  color: var(--text-dim);
  min-width: 28px;
  text-align: right;
}

/* ══════════════════════════════════════════════════════════
   DETAIL PAGE
══════════════════════════════════════════════════════════ */
.detail-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Left Similar Panel ────────────────────────────────── */
.similar-panel {
  width: 200px;
  min-width: 200px;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.similar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.btn-back {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  background: none;
  border: none;
  padding: 0;
  margin-bottom: 12px;
  transition: color var(--transition);
}
.btn-back:hover { color: var(--text); }
.similar-header h3 { font-size: 12px; color: var(--text-dim); font-weight: 500; }
.similar-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.similar-card {
  display: flex;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 4px;
}
.similar-card:hover { background: var(--bg-card-h); }
.similar-thumb {
  width: 44px; height: 56px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-panel);
  flex-shrink: 0;
}
.similar-thumb img { width: 100%; height: 100%; object-fit: cover; }
.similar-thumb .ph { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 10px; color: var(--text-muted); }
.similar-info { flex: 1; min-width: 0; }
.similar-id { font-size: 12px; font-weight: 600; color: var(--text); }
.similar-desc { font-size: 10px; color: var(--text-muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.4; }

/* ── Detail Main ───────────────────────────────────────── */
.detail-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}
.detail-id-name { flex: 1; }
.detail-id {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1;
}
.detail-desc {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
  max-width: 480px;
  line-height: 1.6;
}
.detail-header-tags {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  margin-left: 16px;
}

/* ── Viewer + Props Row ────────────────────────────────── */
.viewer-props-row {
  display: flex;
  gap: 18px;
  align-items: stretch;   /* 两列同高 */
  margin-top: 16px;
}
.viewer-col {
  width: 300px;
  min-width: 300px;
  flex-shrink: 0;
  position: relative;     /* 作为 viewer-wrap 绝对定位的锚点 */
  min-height: 300px;      /* 保底高度，防止 props-col 过矮时太小 */
}
.props-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.props-col .prop-tags,
.props-col .metaphor-box,
.props-col .info-section,
.props-col .meta-row { margin-top: 0; }

/* ── Viewer Box ────────────────────────────────────────── */
.viewer-wrap {
  position: absolute;     /* 脱离正常流，不参与父元素高度计算 */
  inset: 0;               /* 精确填满 viewer-col */
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.viewer-wrap canvas { display: block; width: 100% !important; height: 100% !important; }
.viewer-hint {
  position: absolute;
  bottom: 10px; right: 10px;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px);
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 10px;
  color: rgba(255,255,255,.5);
  line-height: 1.8;
  pointer-events: none;
}
.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-panel);
  font-size: 12px;
  color: var(--text-muted);
  gap: 8px;
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Property Tags ─────────────────────────────────────── */
.prop-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.prop-tag {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  color: var(--text-dim);
  background: var(--bg-card);
}
.prop-tag.active {
  border-color: var(--c-accent);
  color: var(--c-accent);
  background: rgba(91,141,245,.1);
}

/* ── Metaphor text ─────────────────────────────────────── */
.metaphor-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--c-accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
}

/* ── Info Grid (replacing 6-element description) ───────── */
.info-section {
  margin-top: 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.info-section-title {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.info-cell {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.info-cell:nth-child(2n) { border-right: none; }
.info-cell:nth-last-child(-n+2) { border-bottom: none; }
.info-cell.full { grid-column: 1 / -1; border-right: none; }
.info-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-bottom: 5px;
}
.info-value {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}
.info-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.info-tag {
  font-size: 10px;
  padding: 2px 7px;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
}

/* ── Bottom Meta Row ───────────────────────────────────── */
.meta-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 14px;
}
.meta-cell {
  background: var(--bg-card);
  padding: 12px 14px;
}
.meta-label { font-size: 10px; color: var(--text-muted); margin-bottom: 4px; }
.meta-value { font-size: 13px; color: var(--text); font-weight: 500; }

/* ── Right TPI Panel ───────────────────────────────────── */
.tpi-panel {
  width: 300px;
  min-width: 300px;
  background: var(--bg-side);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px;
}
.tpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.tpi-title { font-size: 14px; font-weight: 700; }
.tpi-radar-wrap {
  width: 100%;
  height: 200px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
}
.tpi-scores {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.tpi-score-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.tpi-score-label { font-size: 10px; color: var(--text-muted); margin-bottom: 4px; }
.tpi-score-val { font-size: 18px; font-weight: 700; }
.tpi-score-max { font-size: 10px; color: var(--text-muted); }
.tpi-formula-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
}
.tpi-formula-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tpi-formula-text {
  font-size: 10px;
  color: var(--c-accent);
  background: rgba(91,141,245,.08);
  border-radius: 4px;
  padding: 8px;
  line-height: 1.8;
  font-family: monospace;
  margin-bottom: 10px;
}
.tpi-formula-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}
.tpi-formula-row:last-child { border-bottom: none; }
.tpi-formula-row .label { color: var(--text-dim); }
.tpi-formula-row .val { font-weight: 600; }
.tpi-formula-row .val.pos { color: var(--c-low); }
.tpi-formula-row .val.neg { color: var(--c-high); }
.tpi-final-box {
  background: rgba(91,141,245,.08);
  border: 1px solid rgba(91,141,245,.25);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.tpi-final-label { font-size: 12px; color: var(--text-dim); }
.tpi-final-score { font-size: 32px; font-weight: 800; color: var(--c-accent); }
.tpi-recommend-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
}
.tpi-recommend-title { font-size: 10px; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .8px; }
.tpi-recommend-text { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.tpi-device-section { margin-bottom: 14px; }
.tpi-section-title { font-size: 11px; font-weight: 600; color: var(--text-dim); margin-bottom: 8px; }
.device-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 11px;
}
.device-bar-label { width: 70px; color: var(--text-dim); flex-shrink: 0; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-bar-track { flex: 1; height: 4px; background: var(--border); border-radius: 2px; }
.device-bar-fill { height: 100%; border-radius: 2px; background: var(--c-accent); }
.device-bar-pct { font-size: 10px; color: var(--text-dim); min-width: 28px; text-align: right; }
.algo-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.algo-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 11px;
  border-bottom: 1px solid var(--border);
}
.algo-row:last-child { border-bottom: none; }
.algo-row .label { color: var(--text-muted); }
.algo-row .val { color: var(--text); font-weight: 500; }

/* ── Placeholder state ─────────────────────────────────── */
.placeholder-text {
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
}
