/* =========================================================
   AnimatedList — 玻璃框列表
   · 外层毛玻璃框 + 内层卡片 tile
   · 弹簧指示环（跟随选中项，带阻尼回弹）
   · 滚动进入时 pop 位移缩放动画（错峰 stagger）
   · 上下渐隐遮罩 + 细滚动条
   主题跟随 css/style.css 的 CSS 变量（--haitang-*）
   ========================================================= */

.animated-list {
  /* 可被 JS / 页面覆盖 */
  --al-radius: 14px;
  --al-gap: 8px;
  --al-fade-size: 56px;
  --al-lead: 38px;

  /* 亮色主题 */
  --al-frame: rgba(255, 252, 244, 0.72);
  --al-frame-edge: rgba(74, 56, 32, 0.08);
  --al-frame-highlight: rgba(255, 255, 255, 0.95);
  --al-frame-shadow: 0 24px 48px -26px rgba(74, 56, 32, 0.3), 0 6px 18px -12px rgba(74, 56, 32, 0.16);
  --al-tile: linear-gradient(180deg, #FFFDF7 0%, #F8F1E2 100%);
  --al-tile-edge: rgba(74, 56, 32, 0.07);
  --al-tile-highlight: rgba(255, 255, 255, 1);
  --al-tile-shadow: 0 4px 10px -6px rgba(74, 56, 32, 0.22);
  --al-well: rgba(74, 56, 32, 0.055);
  --al-ink: var(--haitang-text, #2A2620);
  --al-muted: var(--haitang-text-muted, #8E8472);
  --al-thumb: rgba(74, 56, 32, 0.18);
  --al-ring: var(--haitang-accent, #C18A4A);
  --al-ring-fill: rgba(193, 138, 74, 0.06);
  --al-hover: brightness(0.985);
  --al-press: brightness(0.955);
  --al-active: none;

  position: relative;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border-radius: calc(var(--al-radius) + 12px);
  color: var(--al-ink);
  -webkit-tap-highlight-color: transparent;
}

html[data-theme="dark"] .animated-list {
  --al-frame: rgba(31, 28, 22, 0.66);
  --al-frame-edge: rgba(255, 255, 255, 0.07);
  --al-frame-highlight: rgba(255, 255, 255, 0.06);
  --al-frame-shadow: 0 24px 48px -26px rgba(0, 0, 0, 0.85), 0 6px 18px -12px rgba(0, 0, 0, 0.55);
  --al-tile: linear-gradient(180deg, #272219 0%, #1D1913 100%);
  --al-tile-edge: rgba(255, 255, 255, 0.06);
  --al-tile-highlight: rgba(255, 255, 255, 0.09);
  --al-tile-shadow: 0 4px 10px -6px rgba(0, 0, 0, 0.7);
  --al-well: rgba(255, 255, 255, 0.07);
  --al-muted: rgba(240, 232, 214, 0.5);
  --al-thumb: rgba(255, 255, 255, 0.16);
  --al-ring: var(--haitang-accent-warm, #D9A368);
  --al-ring-fill: rgba(217, 163, 104, 0.09);
  --al-hover: brightness(1.12);
  --al-press: brightness(0.85);
  --al-active: brightness(1.06);
}

/* ---------- 外框 ---------- */
.animated-list--framed {
  padding: 6px;
  background: var(--al-frame);
  box-shadow: var(--al-frame-shadow);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  backdrop-filter: blur(20px) saturate(1.6);
}

.animated-list__frame-rim {
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: inherit;
  box-shadow:
    inset 0 0 0 1px var(--al-frame-edge),
    inset 0 1px 0 var(--al-frame-highlight);
  pointer-events: none;
}

.animated-list:has(> .animated-list__viewport:focus-visible) {
  outline: 2px solid var(--al-ring);
  outline-offset: 3px;
}

/* ---------- 视口（滚动 + 渐隐） ---------- */
.animated-list__viewport {
  --al-fade-top: 0px;
  --al-fade-bottom: 0px;
  position: relative;
  box-sizing: border-box;
  padding: 6px;
  overflow-x: hidden;
  overflow-y: auto;
  /* 不要用 contain：滚到列表末尾时会把滚动卡住，页面无法继续滚动 */
  overscroll-behavior: auto;
  border-radius: calc(var(--al-radius) + 6px);
  outline: none;
  scrollbar-width: thin;
  scrollbar-color: var(--al-thumb) transparent;
  -webkit-mask-image: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0,
    rgba(0, 0, 0, 0.35) calc(var(--al-fade-top) * 0.35),
    rgba(0, 0, 0, 0.78) calc(var(--al-fade-top) * 0.72),
    rgba(0, 0, 0, 1) var(--al-fade-top),
    rgba(0, 0, 0, 1) calc(100% - var(--al-fade-bottom)),
    rgba(0, 0, 0, 0.78) calc(100% - var(--al-fade-bottom) * 0.72),
    rgba(0, 0, 0, 0.35) calc(100% - var(--al-fade-bottom) * 0.35),
    rgba(0, 0, 0, 0) 100%
  );
  mask-image: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0,
    rgba(0, 0, 0, 0.35) calc(var(--al-fade-top) * 0.35),
    rgba(0, 0, 0, 0.78) calc(var(--al-fade-top) * 0.72),
    rgba(0, 0, 0, 1) var(--al-fade-top),
    rgba(0, 0, 0, 1) calc(100% - var(--al-fade-bottom)),
    rgba(0, 0, 0, 0.78) calc(100% - var(--al-fade-bottom) * 0.72),
    rgba(0, 0, 0, 0.35) calc(100% - var(--al-fade-bottom) * 0.35),
    rgba(0, 0, 0, 0) 100%
  );
}

.animated-list__viewport::-webkit-scrollbar { width: 6px; }
.animated-list__viewport::-webkit-scrollbar-track { background: transparent; }
.animated-list__viewport::-webkit-scrollbar-thumb {
  border-radius: 3px;
  background: var(--al-thumb);
}
.animated-list__viewport--bare { scrollbar-width: none; }
.animated-list__viewport--bare::-webkit-scrollbar { display: none; }

/* 内容不超出（列表随页面滚动）时：去掉遮罩，也不再是滚动容器，滚轮直接交给页面 */
.animated-list__viewport.is-static {
  -webkit-mask-image: none;
  mask-image: none;
  overflow: visible;
}

/* ---------- 轨道 ---------- */
.animated-list__track {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--al-gap);
}

/* ---------- 单项 ---------- */
.animated-list__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 9px 14px 9px 9px;
  box-sizing: border-box;
  border-radius: var(--al-radius);
  background: var(--al-tile);
  box-shadow: var(--al-tile-shadow);
  color: var(--al-ink);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition:
    transform 620ms cubic-bezier(0.34, 1.4, 0.64, 1),
    opacity 300ms cubic-bezier(0.22, 1, 0.36, 1),
    filter 200ms ease;
}

.animated-list[data-animated] .animated-list__item:not([data-state]) {
  opacity: 0;
}

@media (hover: hover) {
  .animated-list__item:hover { filter: var(--al-hover); }
}
.animated-list__item[data-selected]:not(:active) { filter: var(--al-active); }
.animated-list__item:active { filter: var(--al-press); }

/* 前置图标块 */
.animated-list__lead {
  display: grid;
  place-items: center;
  flex: none;
  width: var(--al-lead);
  height: var(--al-lead);
  overflow: hidden;
  border-radius: max(9px, calc(var(--al-radius) - 5px));
  background: var(--al-well);
  color: var(--al-ink);
  font-size: calc(var(--al-lead) * 0.5);
  line-height: 1;
}

.animated-list__lead img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 文件类型配色 */
.animated-list__lead[data-kind="folder"] { background: rgba(193, 138, 74, 0.16); }
.animated-list__lead[data-kind="img"]    { background: rgba(74, 144, 164, 0.16); }
.animated-list__lead[data-kind="doc"]    { background: rgba(74, 156, 122, 0.16); }
.animated-list__lead[data-kind="video"]  { background: rgba(204, 107, 62, 0.16); }
.animated-list__lead[data-kind="audio"]  { background: rgba(143, 111, 62, 0.16); }
.animated-list__lead[data-kind="other"]  { background: var(--al-well); }

/* 文本区 */
.animated-list__text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.animated-list__title {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.005em;
  color: var(--al-ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.animated-list__description {
  overflow: hidden;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--al-muted);
  font-family: var(--haitang-font-mono, ui-monospace, monospace);
  letter-spacing: 0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.animated-list__meta {
  flex: none;
  font-size: 11.5px;
  font-family: var(--haitang-font-mono, ui-monospace, monospace);
  font-variant-numeric: tabular-nums;
  color: var(--al-muted);
  letter-spacing: 0.02em;
}

/* 尾部操作按钮 */
.animated-list__tail {
  flex: none;
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  transform: translateX(4px);
  transition: opacity 0.22s ease, transform 0.28s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.animated-list__tail .al-icon-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--al-muted);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.animated-list__tail .al-icon-btn:hover {
  background: var(--haitang-accent-light, rgba(193, 138, 74, 0.12));
  color: var(--al-ring);
}

.animated-list__tail .al-icon-btn:active { transform: scale(0.92); }
.animated-list__tail .al-icon-btn svg { width: 15px; height: 15px; }

@media (hover: hover) {
  .animated-list__item:hover .animated-list__tail,
  .animated-list__item[data-selected] .animated-list__tail {
    opacity: 1;
    transform: none;
  }
}

@media (hover: none) {
  .animated-list__tail { opacity: 1; transform: none; }
}

/* 卡片描边高光 */
.animated-list__rim {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow:
    inset 0 0 0 1px var(--al-tile-edge),
    inset 0 1px 0 var(--al-tile-highlight);
  pointer-events: none;
}

/* ---------- 弹簧指示环 ---------- */
.animated-list__indicator {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  height: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.animated-list__ring {
  position: absolute;
  inset: 0;
  border-radius: var(--al-radius);
  background: var(--al-ring-fill);
  box-shadow:
    inset 0 0 0 1px var(--al-ring),
    inset 0 0 18px -6px var(--al-ring);
  transition:
    transform 620ms cubic-bezier(0.34, 1.4, 0.64, 1),
    opacity 300ms cubic-bezier(0.22, 1, 0.36, 1),
    filter 200ms ease;
}

/* ---------- 小屏适配 ---------- */
@media (max-width: 768px) {
  .animated-list { --al-lead: 40px; }
  .animated-list__item { gap: 11px; padding: 10px 12px 10px 10px; }
  .animated-list__title { font-size: 14px; }
  .animated-list__description,
  .animated-list__meta { font-size: 11px; }
  .animated-list--framed {
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
    backdrop-filter: blur(14px) saturate(1.4);
  }
}

@media (prefers-reduced-motion: reduce) {
  .animated-list__item,
  .animated-list__ring,
  .animated-list__tail { transition-duration: 1ms !important; }
}
