/* ============================================================
   chroma-grid.css — ChromaGrid 画廊网格（RareUI 移植，vanilla 版）
   聚光灯跟随鼠标：灰度照片在光圈内恢复彩色 + accent 辉光
   亮/暗两套主题，跟随 html[data-theme]
   ============================================================ */

.chroma-grid {
  --chroma-x: -9999px;
  --chroma-y: -9999px;
  --chroma-power: 0;
  --chroma-ox: 0px;
  --chroma-oy: 0px;
  /* ChromaGrid light 主题 */
  --chroma-frame: rgba(240, 240, 243, 0.8);
  --chroma-frame-edge: rgba(24, 24, 27, 0.07);
  --chroma-frame-highlight: rgba(255, 255, 255, 0.95);
  --chroma-frame-shadow: 0 22px 44px -22px rgba(24, 24, 27, 0.3), 0 6px 16px -10px rgba(24, 24, 27, 0.16);
  --chroma-tile: linear-gradient(180deg, #ffffff 0%, #f6f6f8 100%);
  --chroma-tile-edge: rgba(24, 24, 27, 0.08);
  --chroma-tile-highlight: rgba(255, 255, 255, 1);
  --chroma-tile-shadow: 0 4px 10px -5px rgba(24, 24, 27, 0.25);
  --chroma-media-edge: rgba(24, 24, 27, 0.06);
  --chroma-well: rgba(24, 24, 27, 0.05);
  --chroma-ink: #27272a;
  --chroma-muted: rgba(39, 39, 42, 0.55);
  --chroma-hover: brightness(0.97);
  --chroma-press: brightness(0.92);
  /* 网格参数：3 列 / 最小 180px / 间距 12 / 卡片圆角 22 / 比例 3:2 */
  --chroma-cols: 3;
  --chroma-min: 180px;
  --chroma-gap: 12px;
  --chroma-r: 260px;
  --chroma-radius: 22px;
  --chroma-ratio: 3 / 2;
  --chroma-gray: 1;
  --chroma-dim: 0.12;
  --chroma-glow: 0.5;
  --chroma-border: 1;
  --chroma-fade: 0.6s;
  --chroma-stops: rgba(0,0,0,1) 0%, rgba(0,0,0,1) 33.3%, rgba(0,0,0,0.9998) 41.7%, rgba(0,0,0,0.9645) 50%, rgba(0,0,0,0.8294) 58.3%, rgba(0,0,0,0.6033) 66.7%, rgba(0,0,0,0.3466) 75%, rgba(0,0,0,0.135) 83.3%, rgba(0,0,0,0.0217) 91.7%, rgba(0,0,0,0) 100%;
  position: relative;
  width: 100%;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html[data-theme="dark"] .chroma-grid {
  --chroma-frame: rgba(38, 35, 46, 0.66);
  --chroma-frame-edge: rgba(255, 255, 255, 0.08);
  --chroma-frame-highlight: rgba(255, 255, 255, 0.07);
  --chroma-frame-shadow: 0 22px 44px -20px rgba(0, 0, 0, 0.8), 0 6px 16px -8px rgba(0, 0, 0, 0.5);
  --chroma-tile: linear-gradient(180deg, #3a3644 0%, #27242f 100%);
  --chroma-tile-edge: rgba(255, 255, 255, 0.07);
  --chroma-tile-highlight: rgba(255, 255, 255, 0.12);
  --chroma-tile-shadow: 0 4px 10px -4px rgba(0, 0, 0, 0.7);
  --chroma-media-edge: rgba(255, 255, 255, 0.06);
  --chroma-well: rgba(255, 255, 255, 0.08);
  --chroma-ink: #f4f4f5;
  --chroma-muted: rgba(244, 244, 245, 0.55);
  --chroma-hover: brightness(1.12);
  --chroma-press: brightness(0.85);
}

.chroma-grid-inner {
  display: grid;
  gap: var(--chroma-gap);
  grid-template-columns: repeat(
    auto-fill,
    minmax(
      min(
        100%,
        max(var(--chroma-min), calc((100% - (var(--chroma-cols) - 1) * var(--chroma-gap)) / var(--chroma-cols)))
      ),
      1fr
    )
  );
}

.chroma-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 8px;
  box-sizing: border-box;
  border-radius: var(--chroma-radius);
  background: var(--chroma-tile);
  box-shadow: var(--chroma-tile-shadow);
  color: var(--chroma-ink);
  text-decoration: none;
  overflow: hidden;
  isolation: isolate;
  transition: filter 0.25s ease;
  cursor: pointer;
}

.chroma-card:hover { filter: var(--chroma-hover); }
.chroma-card:active { filter: var(--chroma-press); }
.chroma-card:focus-visible { outline: 2px solid var(--chroma-ink); outline-offset: 2px; }

/* 聚光灯遮罩：光圈内才显示彩色层 / 辉光 */
.chroma-wash,
.chroma-color,
.chroma-card-glow {
  -webkit-mask-image: radial-gradient(
    circle var(--chroma-r) at calc(var(--chroma-x) - var(--chroma-ox, 0px))
      calc(var(--chroma-y) - var(--chroma-oy, 0px)),
    var(--chroma-stops)
  );
  mask-image: radial-gradient(
    circle var(--chroma-r) at calc(var(--chroma-x) - var(--chroma-ox, 0px))
      calc(var(--chroma-y) - var(--chroma-oy, 0px)),
    var(--chroma-stops)
  );
}

.chroma-wash {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(130% 70% at 50% 100%, var(--chroma-accent, #ffffff), transparent 72%);
  opacity: calc(var(--chroma-glow) * var(--chroma-power) * 0.45);
}

.chroma-media {
  position: relative;
  z-index: 1;
  aspect-ratio: var(--chroma-ratio);
  border-radius: max(0px, calc(var(--chroma-radius) - 8px));
  overflow: hidden;
  background: var(--chroma-well);
}

.chroma-media img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.chroma-mono {
  filter: grayscale(var(--chroma-gray)) brightness(calc(1 - var(--chroma-dim)));
  transition: filter 0.5s ease;
}

.chroma-color { opacity: var(--chroma-power); }

.chroma-media-rim {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px var(--chroma-media-edge);
  pointer-events: none;
}

.chroma-info {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 2px 6px 4px;
}

.chroma-title {
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chroma-subtitle {
  overflow: hidden;
  font-size: 13px;
  line-height: 1.35;
  color: var(--chroma-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chroma-card-rim,
.chroma-card-glow {
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  pointer-events: none;
}

.chroma-card-rim {
  box-shadow:
    inset 0 0 0 1px var(--chroma-tile-edge),
    inset 0 1px 0 var(--chroma-tile-highlight);
}

.chroma-card-glow {
  box-shadow:
    inset 0 0 0 1px var(--chroma-accent, #ffffff),
    inset 0 0 16px -8px var(--chroma-accent, #ffffff);
  opacity: calc(var(--chroma-border) * var(--chroma-power));
}

/* 无图占位 */
.chroma-media .chroma-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  color: var(--chroma-muted);
  background: linear-gradient(160deg, rgba(24, 24, 27, 0.05), rgba(24, 24, 27, 0.1));
}

/* 移动端 / 触屏：没有悬停聚光灯，直接显示彩色 */
@media (hover: none), (max-width: 860px) {
  .chroma-color { opacity: 1; }
  .chroma-mono { filter: grayscale(calc(var(--chroma-gray) * 0.4)) brightness(calc(1 - var(--chroma-dim) * 0.5)); }
}

/* ============================================================
   卡片逐个进场
   由渲染时写入的 --chroma-i 决定延迟，DOM 顺序即从左到右、从上到下。
   fill-mode 用 backwards：延迟期间保持首帧，动画结束后不锁定 transform，
   因此不影响 :hover 的 filter 过渡，也不影响聚光灯遮罩。
   ============================================================ */
@keyframes chromaCardIn {
  from {
    opacity: 0;
    transform: translate3d(0, 14px, 0) scale(0.982);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

.chroma-grid-inner .chroma-card {
  animation: chromaCardIn 0.46s cubic-bezier(0.22, 0.68, 0.32, 1) backwards;
  animation-delay: calc(var(--chroma-i, 0) * 40ms);
}

@media (prefers-reduced-motion: reduce) {
  .chroma-grid-inner .chroma-card {
    animation: none;
  }
}

/* ============================================================
   切标签过渡：旧内容轻微压暗（不整体消失，避免闪白/空窗），
   新数据到达后由 JS 移除 is-switching 淡回，卡片同时逐个进场
   ============================================================ */
.chroma-grid-inner {
  transition: opacity 0.2s ease;
}

.chroma-grid-inner.is-switching {
  opacity: 0.42;
  transition-duration: 0.14s;
  pointer-events: none;
}
