:root {
  --bg: #f2f5f8;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
  --radius: 12px;
  /* 灯箱配色（跟随亮/暗主题，不再写死深色） */
  --lb-bg: rgba(255, 255, 255, .97);
  --lb-text: #1e293b;
  --lb-border: #e2e8f0;
  --lb-track: #e2e8f0;
  --lb-accent: #2563eb;
  --lb-nav-bg: rgba(15, 23, 42, .08);
}
html.dark {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #16213a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --accent: #60a5fa;
  --accent-soft: #1e3a5f;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  --lb-bg: rgba(2, 6, 23, .96);
  --lb-text: #e2e8f0;
  --lb-border: #475569;
  --lb-track: #1e293b;
  --lb-accent: #60a5fa;
  --lb-nav-bg: rgba(255, 255, 255, .12);
}
* { box-sizing: border-box; }
/* 修复：.lightbox/.drawer 自带 display:flex，会覆盖浏览器默认的 [hidden]{display:none}，
   导致 hidden 属性失效、灯箱和抽屉在首页加载时就直接显示。!important 确保 hidden 始终生效；
   JS 移除 hidden 属性后 display:flex 恢复，开关逻辑不变。 */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
button { font: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--text); }

/* 顶栏 */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow); }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { font-size: 20px; font-weight: 700; white-space: nowrap; }
.brand span { color: var(--accent); font-size: 14px; font-weight: 600; }
.search-box { flex: 1; display: flex; min-width: 200px; max-width: 480px; }
.search-box input { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px 0 0 8px; background: var(--surface-2); outline: none; }
.search-box input:focus { border-color: var(--accent); }
.search-box button { padding: 8px 16px; border: none; border-radius: 0 8px 8px 0; background: var(--accent); color: #fff; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.source-switch { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.source-switch button { padding: 6px 10px; border: none; background: var(--surface); color: var(--muted); }
.source-switch button.active { background: var(--accent); color: #fff; }
.icon-btn { width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 16px; }

/* 统计条 */
.statsbar { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 20px; flex-wrap: wrap; align-items: center; color: var(--muted); }
.statsbar b { color: var(--text); }
.filter-toggle { display: none; margin-left: auto; padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }

/* 布局 */
.layout { max-width: 1280px; margin: 0 auto; padding: 0 16px 32px; display: flex; gap: 20px; align-items: flex-start; }
.filters { width: 240px; flex-shrink: 0; position: sticky; top: 70px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.filters h3 { margin: 0 0 8px; font-size: 14px; }
.filters section + section { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 16px; }
.filters select, .filters input[type="search"] { width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); outline: none; }
.company-list, .tag-list { max-height: 260px; overflow-y: auto; margin-top: 8px; }
.company-item, .tag-item { display: flex; justify-content: space-between; width: 100%; padding: 6px 8px; border: none; border-radius: 6px; background: transparent; color: var(--text); text-align: left; }
.company-item:hover, .tag-item:hover { background: var(--surface-2); }
.company-item.active, .tag-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.company-item .n, .tag-item .n { color: var(--muted); font-size: 12px; }
/* 筛选面板头部、遮罩与悬浮筛选按钮（仅移动端使用，桌面端隐藏） */
.filters-head { display: none; }
.filters-backdrop { display: none; }
.filter-fab { display: none; }
.count { color: var(--muted); font-weight: 400; font-size: 12px; }

.content { flex: 1; min-width: 0; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.shuffle-btn { padding: 7px 14px; border: none; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; }
.chip button { border: none; background: none; color: inherit; font-size: 14px; padding: 0; line-height: 1; }
.result-count { margin-left: auto; color: var(--muted); font-size: 12px; }

/* 网格 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); cursor: pointer; transition: transform .15s ease, box-shadow .15s ease; }
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(15, 23, 42, .12); }
.card-cover { aspect-ratio: 3 / 4; background: var(--surface-2); overflow: hidden; }
.card-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-fallback { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; background: var(--surface-2); }
.card-body { padding: 10px 12px 12px; }
.card-title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.9em; }
.card-meta { margin-top: 6px; color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 8px; }
.card-tags { margin-top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.card-tags span { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.empty { text-align: center; padding: 48px 0; color: var(--muted); }
.empty button { margin-top: 8px; padding: 8px 16px; border: none; border-radius: 8px; background: var(--accent); color: #fff; }
.more-wrap { text-align: center; margin-top: 20px; }
.more-btn { padding: 10px 32px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; border-top: 1px solid var(--border); }

/* 详情抽屉 */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 30; }
.drawer { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(720px, calc(100vw - 32px)); height: min(92vh, 920px); background: var(--surface); z-index: 31; display: flex; flex-direction: column; box-shadow: 0 12px 48px rgba(0, 0, 0, .25); border-radius: 16px; overflow: hidden; }
.drawer-head { padding: 12px 16px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.drawer-title-row { display: flex; gap: 8px; align-items: flex-start; }
.drawer-title-row h2 { margin: 0; font-size: 16px; line-height: 1.4; flex: 1; }
.drawer-meta { margin-top: 4px; color: var(--muted); font-size: 12px; }
.drawer-meta button { border: none; background: none; color: var(--accent); padding: 0; font-size: 12px; }
.drawer-tags { margin-top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.drawer-tags button { font-size: 12px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.drawer-progress { height: 4px; background: var(--surface-2); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.drawer-progress-bar { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.drawer-progress-text { font-size: 12px; color: var(--muted); margin-top: 4px; }
.drawer-photos { flex: 1; overflow-y: auto; padding: 12px 16px; }
.drawer-photos figure { margin: 0 0 12px; }
.drawer-photos img { width: 100%; display: block; border-radius: 8px; cursor: zoom-in; background: var(--surface-2); }
.drawer-photos figcaption { font-size: 12px; color: var(--muted); text-align: center; margin-top: 4px; }
.back-top { position: absolute; right: 16px; bottom: 16px; padding: 8px 14px; border: none; border-radius: 999px; background: var(--accent); color: #fff; box-shadow: var(--shadow); }

/* 灯箱（配色全部走 --lb-* 变量，跟随亮/暗主题） */
.lightbox { position: fixed; inset: 0; background: var(--lb-bg); z-index: 40; display: flex; flex-direction: column; color: var(--lb-text); }
.lightbox-top { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; }
.lightbox-top .icon-btn { background: transparent; border-color: var(--lb-border); color: var(--lb-text); }
.lightbox-progress { height: 3px; background: var(--lb-track); }
.lightbox-progress div { height: 100%; background: var(--lb-accent); width: 0; transition: width .2s; }
.lightbox-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; width: 44px; height: 44px; border: none; border-radius: 50%; background: var(--lb-nav-bg); color: var(--lb-text); font-size: 28px; line-height: 1; }
.lightbox-nav.prev { left: 12px; }
.lightbox-nav.next { right: 12px; }
.lightbox-stage { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 8px 60px; position: relative; }
.lightbox-stage img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.lightbox-strip { display: flex; gap: 6px; padding: 10px 16px 14px; overflow-x: auto; justify-content: center; }
.lightbox-strip img { height: 56px; border-radius: 4px; cursor: pointer; opacity: .55; border: 2px solid transparent; }
.lightbox-strip img.active { opacity: 1; border-color: var(--lb-accent); }

/* 加载动画：转圈 + 各处 loading 占位 */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.grid-loading, .detail-loading { text-align: center; padding: 48px 0; color: var(--muted); }
.grid-loading .spinner, .detail-loading .spinner { margin: 0 auto 12px; }
.grid-loading p, .detail-loading p { margin: 0; }
/* 图片容器：图未加载完时中央显示转圈，加载完（JS 加 .loaded）或失败后隐藏 */
.card-cover { position: relative; }
.card-cover::after, .drawer-photos figure::after, .lightbox-stage::after {
  content: ''; position: absolute; width: 28px; height: 28px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
.card-cover::after { top: 50%; left: 50%; margin: -14px 0 0 -14px; }
.drawer-photos figure { position: relative; }
.drawer-photos figure::after { top: 60px; left: 50%; margin-left: -14px; }
.drawer-photos img { min-height: 120px; }
.lightbox-stage::after { top: 50%; left: 50%; margin: -14px 0 0 -14px; border-color: var(--lb-border); border-top-color: var(--lb-accent); }
.card-cover.loaded::after, .drawer-photos figure.loaded::after, .lightbox-stage.loaded::after { display: none; }

/* 首页回到顶部 */
.home-top { position: fixed; right: 20px; bottom: 20px; z-index: 15; padding: 10px 16px; border: none; border-radius: 999px; background: var(--accent); color: #fff; box-shadow: var(--shadow); }

/* 移动端 */
@media (max-width: 760px) {
  .drawer { top: 0; left: 0; transform: none; width: 100%; height: 100%; border-radius: 0; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .layout { padding-bottom: 80px; }
  /* 筛选改为底部抽屉：固定头（标题+清除+关闭）+ 可滚动正文 */
  .filters { display: none; position: fixed; left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-height: 82vh; z-index: 25; border-radius: 16px 16px 0 0; padding: 0; overflow: hidden; }
  .filters.open { display: flex; flex-direction: column; animation: sheetUp .25s ease; }
  .filters-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
  .filters-head h3 { margin: 0; font-size: 16px; }
  .filters-head-actions { display: flex; gap: 8px; align-items: center; }
  .filters-clear { border: none; background: none; color: var(--accent); padding: 6px 8px; }
  .filters-body { overflow-y: auto; padding: 16px; flex: 1; min-height: 0; }
  .filters-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 24; }
  .filter-toggle { display: inline-block; }
  .filter-toggle.open { background: var(--accent-soft); color: var(--accent); }
  /* 悬浮筛选按钮：下滑浏览时不用回顶也能打开筛选 */
  .filter-fab { display: block; position: fixed; left: 16px; bottom: 20px; z-index: 15; padding: 10px 16px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
  .filter-fab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
  .topbar-inner { gap: 8px; }
  .search-box { order: 3; flex-basis: 100%; max-width: none; }
  .lightbox-stage { padding: 8px 48px; }
  .lightbox-nav { width: 36px; height: 36px; font-size: 22px; }
}
