/* ============================================================
   瀑布 · Adaptive Masonry
   设计要点：
   - 卡片绝对定位 + translate3d，由 JS 计算"最短列"落位
   - 列数 = round(容器宽 / 目标列宽)，因此列宽恒定，只有列数变化
   - 图片高度由 API 的宽高算出，加载前就占好位置 → 零布局跳动
   ============================================================ */

:root {
  --bg: #0d0e11;
  --bg-elev: #14161b;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-strong: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e9eaf0;
  --muted: #8b91a1;
  --accent: #b28fce;
  --accent-ink: #100a18;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --gap: 12px;
  --radius: 14px;
  --bar-h: 64px;
}

[data-theme='light'] {
  --bg: #f4f4f7;
  --bg-elev: #ffffff;
  --panel: rgba(15, 17, 22, 0.035);
  --panel-strong: rgba(15, 17, 22, 0.07);
  --line: rgba(15, 17, 22, 0.1);
  --text: #14161b;
  --muted: #6b7280;
  --accent: #7c5aa8;
  --accent-ink: #ffffff;
  --shadow: 0 10px 26px rgba(20, 22, 27, 0.14);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(900px 480px at 12% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    radial-gradient(760px 420px at 108% 4%, rgba(80, 140, 210, 0.12), transparent 70%),
    var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }

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

.bar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 clamp(12px, 3vw, 28px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand__mark { display: flex; align-items: flex-end; gap: 3px; height: 22px; }
.brand__mark i { display: block; width: 5px; border-radius: 3px; background: var(--accent); }
.brand__mark i:nth-child(1) { height: 12px; opacity: 0.55; }
.brand__mark i:nth-child(2) { height: 22px; }
.brand__mark i:nth-child(3) { height: 17px; opacity: 0.75; }
.brand__text { font-weight: 650; letter-spacing: 0.02em; }
.brand__text em { font-style: normal; color: var(--muted); font-weight: 400; margin-left: 6px; font-size: 12px; }

.search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 320px;
  min-width: 0;
  height: 40px;
  padding-left: 36px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: border-color 0.18s, background 0.18s;
}
.search:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, transparent); background: var(--panel-strong); }
.search__icon {
  position: absolute; left: 11px; top: 50%; translate: 0 -50%;
  width: 17px; height: 17px; fill: none; stroke: var(--muted); stroke-width: 1.9; stroke-linecap: round;
}
.search input {
  flex: 1; min-width: 0; height: 100%;
  background: none; border: 0; outline: 0; color: var(--text);
  font: inherit; padding: 0 8px 0 0;
}
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { filter: grayscale(1) opacity(0.5); }
.search__go {
  height: 30px; margin-right: 5px; padding: 0 13px;
  border: 0; border-radius: 9px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 600;
  transition: filter 0.15s;
}
.search__go:hover { filter: brightness(1.08); }

.tools { display: flex; align-items: center; gap: 10px; flex: none; }

.field {
  display: flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.field__label { color: var(--muted); font-size: 12px; white-space: nowrap; }
.field select {
  background: none; border: 0; outline: 0; color: var(--text);
  font: inherit; font-size: 13px; cursor: pointer; max-width: 130px;
}
.field select option { color: #111; }

.field--range { padding-right: 8px; }
.field--range input[type='range'] {
  width: 92px; height: 18px; accent-color: var(--accent); cursor: pointer;
}
.field output { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); min-width: 30px; text-align: right; }

.icon-btn {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--panel-strong); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------- 主体 ---------------- */

.wrap {
  padding: 14px clamp(12px, 3vw, 28px) 60px;
  max-width: 2200px;
  margin: 0 auto;
}

.meta {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 26px; margin-bottom: 10px;
  font-size: 12px; color: var(--muted);
}
.hud { font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.hud b { color: var(--text); font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--muted); font-size: 11.5px;
}
.chip button { all: unset; cursor: pointer; color: inherit; opacity: 0.7; }
.chip button:hover { opacity: 1; }

.board { position: relative; width: 100%; }

/* ---------------- 卡片 ---------------- */

.card {
  position: absolute;
  top: 0; left: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  transform: translate3d(0, 0, 0);
  transition:
    transform 0.34s cubic-bezier(0.22, 0.61, 0.36, 1),
    width 0.34s cubic-bezier(0.22, 0.61, 0.36, 1),
    height 0.34s cubic-bezier(0.22, 0.61, 0.36, 1),
    box-shadow 0.2s;
  contain: layout paint style;
}
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card:hover { box-shadow: var(--shadow); z-index: 2; }

.card__media { position: absolute; inset: 0; background: var(--panel-strong); }
.card__media img {
  width: 100%; height: 100%; display: block;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.45s ease, scale 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
  scale: 1;
}
.card.is-loaded .card__media img { opacity: 1; }
.card:hover .card__media img { scale: 1.045; }

.card__media::after {
  content: '';
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(100deg, transparent 18%, rgba(255, 255, 255, 0.07) 42%, transparent 66%);
  background-size: 220% 100%;
  animation: shimmer 1.5s linear infinite;
  opacity: 1;
  transition: opacity 0.3s;
}
.card.is-loaded .card__media::after { opacity: 0; animation: none; }
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }

.card__meta {
  position: absolute; inset: auto 0 0 0;
  display: flex; align-items: center; gap: 6px;
  padding: 22px 10px 9px;
  background: linear-gradient(to top, rgba(6, 7, 10, 0.86), rgba(6, 7, 10, 0));
  color: #f2f3f7;
  font-size: 11px;
  opacity: 0;
  translate: 0 6px;
  transition: opacity 0.2s, translate 0.2s;
  pointer-events: none;
}
.card:hover .card__meta, .card:focus-visible .card__meta { opacity: 1; translate: 0 0; }
.card__meta .taglist {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.92;
}
.card__meta .star {
  margin-left: auto; flex: none;
  font-variant-numeric: tabular-nums;
  padding: 1px 6px; border-radius: 6px;
  background: rgba(255, 255, 255, 0.14);
}
.card__badge {
  position: absolute; top: 8px; left: 8px;
  padding: 2px 7px; border-radius: 7px;
  background: rgba(10, 11, 14, 0.6);
  backdrop-filter: blur(6px);
  color: #fff; font-size: 10.5px; letter-spacing: 0.02em;
  opacity: 0; transition: opacity 0.2s;
}
.card.is-loaded .card__badge { opacity: 1; }
.card__badge[hidden] { display: none; }

/* ---------------- 底部 ---------------- */

.sentinel { height: 1px; }

.footer { display: grid; place-items: center; gap: 10px; padding: 26px 0 10px; }
.ghost-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 18px;
  border-radius: 11px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text);
  font: inherit; font-size: 13px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.ghost-btn:hover { background: var(--panel-strong); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.tip { margin: 0; color: var(--muted); font-size: 12px; min-height: 18px; }

/* ---------------- 灯箱 ---------------- */

.lb {
  position: fixed; inset: 0; z-index: 100;
  display: grid;
  grid-template-columns: 1fr minmax(240px, 320px);
  align-items: stretch;
}
.lb[hidden] { display: none; }
.lb__scrim { position: absolute; inset: 0; background: rgba(4, 5, 8, 0.86); backdrop-filter: blur(10px); }

.lb__stage {
  position: relative; margin: 0;
  display: grid; place-items: center;
  padding: 22px;
  min-width: 0;
  z-index: 1;
}
.lb__stage img, .lb__stage video {
  max-width: 100%; max-height: calc(100vh - 44px);
  border-radius: 10px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  object-fit: contain;
  background: #000;
}
.lb__stage img { opacity: 0; transition: opacity 0.25s; }
.lb__stage img.is-ready { opacity: 1; }

.lb__side {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px 18px 22px;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  border-left: 1px solid var(--line);
  overflow: auto;
}
.lb__head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.lb__head .icon-btn { margin-left: auto; }

.badge {
  padding: 3px 9px; border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--text); font-size: 11.5px;
}
.badge--soft { background: var(--panel); border-color: var(--line); color: var(--muted); }

.lb__tags { display: flex; flex-wrap: wrap; gap: 5px; align-content: flex-start; }
.lb__tags a {
  padding: 3px 8px; border-radius: 7px;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 11.5px; color: var(--muted);
  transition: color 0.15s, border-color 0.15s;
}
.lb__tags a:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }

.lb__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lb__hint { margin: auto 0 0; color: var(--muted); font-size: 11.5px; }

.lb__nav {
  position: absolute; top: 50%; translate: 0 -50%; z-index: 2;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(20, 21, 26, 0.6); backdrop-filter: blur(8px);
  color: #fff; font-size: 22px; line-height: 1; cursor: pointer;
  transition: background 0.15s;
}
.lb__nav:hover { background: rgba(40, 42, 52, 0.85); }
.lb__nav--prev { left: 14px; }
.lb__nav--next { right: 340px; }

/* ---------------- 提示条 ---------------- */

.toast {
  position: fixed; left: 50%; bottom: 26px; translate: -50% 0;
  z-index: 200;
  max-width: min(560px, calc(100vw - 32px));
  padding: 11px 16px; border-radius: 12px;
  background: color-mix(in srgb, var(--bg-elev) 94%, transparent);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 13px;
}
.toast[hidden] { display: none; }

/* ---------------- 响应式 ---------------- */

@media (max-width: 1080px) {
  .field--range { display: none; }
}

@media (max-width: 820px) {
  :root { --bar-h: 56px; }
  .bar { gap: 10px; padding: 0 12px; }
  .brand__text em { display: none; }
  .search { flex: 1 1 auto; }
  .search__go { display: none; }
  .tools .field { display: none; }
  .lb { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .lb__side {
    max-height: 42vh; border-left: 0; border-top: 1px solid var(--line);
    padding: 14px 14px 18px;
  }
  .lb__stage { padding: 10px; }
  .lb__stage img, .lb__stage video { max-height: calc(58vh - 20px); }
  .lb__nav--next { right: 10px; }
  .lb__nav--prev { left: 10px; }
  .lb__nav { width: 38px; height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .card__media img, .card__meta { transition: none !important; }
  .card__media::after { animation: none; }
}
