/* 全站动画过渡（动效方案 B「流畅有层次」）：页面切换、载入进度条、骨架屏、列表错峰进场、时间流新帖插入、标签滑动、弹层、菜单、提示、悬停和按压。
   只动透明度和小位移，时长 150–300ms，减速曲线不回弹；系统开启「减少动态效果」时全部变为瞬时。
   共用的 JS 在 motion.js。各页面在其他样式表之前引入本文件，同优先级的页面规则可以覆盖这里。 */
:root {
  --motion-fast: 150ms;
  --motion-base: 260ms;
  --motion-stagger: 40ms;
  --motion-rise: 10px;
  --motion-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --motion-ease-in: cubic-bezier(0.4, 0, 1, 1);
  interpolate-size: allow-keywords;
}
@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-fast: 0s;
    --motion-base: 0s;
    --motion-stagger: 0s;
  }
}

@keyframes fv-fade-in {
  from {
    opacity: 0;
  }
}
@keyframes fv-rise-in {
  from {
    opacity: 0;
    transform: translateY(var(--motion-rise));
  }
}
@keyframes fv-drop-in {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
  }
}
@keyframes fv-toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
}

/* 整页跳转（例如单独打开的工坊页回到社区）在支持的浏览器里淡入淡出。 */
@view-transition {
  navigation: auto;
}
@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }
}
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: var(--motion-base);
}

/* 社区单页切换：新内容逐块上浮淡入。载入提示延迟出现，快速加载时不会闪一下。 */
#app > * {
  animation: fv-rise-in var(--motion-base) var(--motion-ease) backwards;
}
#app > :nth-child(2) {
  animation-delay: var(--motion-stagger);
}
#app > :nth-child(3) {
  animation-delay: calc(var(--motion-stagger) * 2);
}
#app > :nth-child(4) {
  animation-delay: calc(var(--motion-stagger) * 3);
}
#app > :nth-child(n + 5) {
  animation-delay: calc(var(--motion-stagger) * 4);
}
#app > .loading {
  animation: fv-fade-in var(--motion-base) ease 300ms backwards;
}
/* 同一页面内重新渲染（如投票页切换一览／1点ずつ）时不再整页上浮，只让变化的面板淡入。 */
#app[data-motion='quiet'] > :not(.loading) {
  animation: none;
}
#vote-panel > * {
  animation: fv-rise-in var(--motion-base) var(--motion-ease) backwards;
}
/* 手机端投票页底部有 position: fixed 的按钮条，位移会让它跟着跳，这里只淡入。 */
#app > :is(.vote-stage, :has(.vote-stage)),
#vote-panel > :is(.vote-stage, :has(.vote-stage)) {
  animation-name: fv-fade-in;
}
#workshop-container:not([hidden]) {
  animation: fv-fade-in var(--motion-base) var(--motion-ease);
}

/* 工坊：切换产品类型、实景摄影棚和左右面板标签时淡入。 */
#badge-workspace:not([hidden]),
#acrylic-frame:not([hidden]),
#liquid-frame:not([hidden]),
#plush-frame:not([hidden]),
#studio-frame:not([hidden]),
[role='tabpanel']:not([hidden]) {
  animation: fv-fade-in var(--motion-base) var(--motion-ease);
}

/* 弹窗：打开时轻微上浮放大，关闭时淡出；不支持 @starting-style 的浏览器直接显示。 */
dialog {
  --fv-dialog-from: translateY(10px) scale(0.985);
  opacity: 0;
  transform: var(--fv-dialog-from);
  transition:
    opacity var(--motion-fast) var(--motion-ease-in),
    transform var(--motion-fast) var(--motion-ease-in),
    overlay var(--motion-fast) allow-discrete,
    display var(--motion-fast) allow-discrete;
}
dialog[open] {
  opacity: 1;
  transform: none;
  transition-duration: var(--motion-base);
  transition-timing-function: var(--motion-ease);
}
@starting-style {
  dialog[open] {
    opacity: 0;
    transform: var(--fv-dialog-from);
  }
}
dialog::backdrop {
  opacity: 0;
  transition:
    opacity var(--motion-fast) var(--motion-ease-in),
    overlay var(--motion-fast) allow-discrete,
    display var(--motion-fast) allow-discrete;
}
dialog[open]::backdrop {
  opacity: 1;
  transition-duration: var(--motion-base);
}
@starting-style {
  dialog[open]::backdrop {
    opacity: 0;
  }
}
/* 全屏登录页只淡入淡出。 */
dialog.login-screen {
  --fv-dialog-from: none;
}

/* 头像、通知菜单 */
.pop:not([hidden]) {
  transform-origin: top right;
  animation: fv-drop-in var(--motion-fast) var(--motion-ease);
}
/* 社区底部提示（显示时由 display: none 切换为 block，ui.js 隐藏前先加 .leaving 滑出） */
@keyframes fv-toast-out {
  to {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
}
#notice {
  animation: fv-toast-in var(--motion-base) var(--motion-ease);
}
#notice.leaving {
  animation: fv-toast-out var(--motion-fast) var(--motion-ease-in) forwards;
}

/* 折叠面板展开收起（Chrome 131+ 等支持 ::details-content 的浏览器）。 */
@supports selector(::details-content) {
  details::details-content {
    block-size: 0;
    overflow-y: clip;
    transition:
      block-size var(--motion-base) var(--motion-ease),
      content-visibility var(--motion-base) allow-discrete;
  }
  details[open]::details-content {
    block-size: auto;
  }
}

/* 链接和控件的悬停、选中状态渐变。:where() 不加优先级，页面里已有的 transition 照常生效。 */
:where(a, button, summary, select, input, textarea, [role='tab']) {
  transition:
    color var(--motion-fast) ease,
    background-color var(--motion-fast) ease,
    border-color var(--motion-fast) ease,
    box-shadow var(--motion-fast) ease;
}

/* ===== 页面载入 ===== */

/* 顶栏下沿的载入进度条（motion.js 的 progress() 插入 .site-header）：载入超过 150ms 才出现，先快后慢走到 80%，完成时补满后淡出。 */
.route-progress {
  position: absolute;
  left: 0;
  bottom: -1px;
  height: 2px;
  width: 0;
  background: var(--blue, #5261ee);
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}
.route-progress.run {
  width: 80%;
  opacity: 1;
  transition:
    width 1.6s cubic-bezier(0.1, 0.6, 0.2, 1),
    opacity var(--motion-fast) ease;
}
.route-progress.done {
  width: 100%;
  opacity: 0;
  transition:
    width var(--motion-fast) ease,
    opacity 300ms ease 150ms;
}

/* 骨架屏：形状接近真实页面（标题 + 列表行或卡片网格），微光从右往左扫过。和原来的载入文字一样延迟 300ms 才淡入。 */
@keyframes fv-shimmer {
  from {
    background-position: 150% 0;
  }
  to {
    background-position: -50% 0;
  }
}
.fv-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.loading.skeleton {
  padding: 0;
  text-align: left;
}
.loading.skeleton > div {
  display: grid;
  gap: 26px;
}
.fv-sk {
  display: block;
  max-width: 100%;
  border-radius: 7px;
  background: linear-gradient(100deg, #e8eaf2 40%, #f5f6fa 50%, #e8eaf2 60%)
    #e8eaf2;
  background-size: 200% 100%;
  animation: fv-shimmer 1.4s linear infinite;
}
.fv-sk-head {
  display: grid;
  gap: 12px;
  padding-top: 6px;
}
.fv-sk-list,
.fv-sk-card {
  background: #fff;
  border: 1px solid var(--line, #e7e9f1);
  border-radius: 22px;
  overflow: hidden;
}
.fv-sk-row {
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line, #e7e9f1);
}
.fv-sk-row:last-child {
  border-bottom: 0;
}
.fv-sk-row > div {
  flex: 1;
  display: grid;
  gap: 9px;
}
.fv-sk-thumb {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  flex: none;
}
.fv-sk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
  gap: 20px;
}
.fv-sk-card {
  display: grid;
  gap: 10px;
  padding-bottom: 18px;
}
.fv-sk-card > .fv-sk:not(.fv-sk-cover) {
  margin-inline: 20px;
}
.fv-sk-cover {
  height: 180px;
  border-radius: 0;
}
@media (prefers-reduced-motion: reduce) {
  .fv-sk {
    animation: none;
  }
  /* 减少动态效果时进度条不走动：载入中直接显示整条，完成后消失。 */
  .route-progress {
    transition: none !important;
  }
  .route-progress.run {
    width: 100%;
  }
}

/* ===== 列表与时间流 ===== */

/* 列表行错峰进场（motion.js 的 enter()：页面画好后的可见行、「さらに読み込む」加进来的行、刚发出的回复）。 */
.fv-enter {
  animation: fv-rise-in var(--motion-base) var(--motion-ease) backwards;
  animation-delay: calc(var(--fv-i, 0) * var(--motion-stagger));
}
/* 时间流新帖（motion.js 的 fresh()）：高度由 JS 从 0 撑开，这里负责淡黄高亮慢慢褪去。颜色变化不算位移，减少动态效果时也保留。 */
@keyframes fv-flash {
  from,
  35% {
    background-color: #fff7dc;
  }
}
.fv-fresh {
  animation: fv-flash 2.6s ease;
}
/* 还在下载的图片到达后淡入。 */
img[data-fv-img] {
  transition: opacity var(--motion-base) ease;
}
img[data-fv-img='wait'] {
  opacity: 0;
}

/* 「新着 N 件」：列表上方的胶囊，贴着顶栏下方随滚动停住，不占列表的位置（motion.js 的 watchFeed()，通知页）。 */
.feed-new {
  position: sticky;
  z-index: 5;
  height: 0;
  display: flex;
  justify-content: center;
}
.feed-new > button {
  translate: 0 -50%;
  height: fit-content;
  min-height: 0;
  padding: 8px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--blue, #5261ee);
  color: #fff;
  font-size: 13px;
  box-shadow: 0 8px 20px #5261ee59;
}
.feed-new > button:hover {
  background: #3f4ee0;
}
.feed-new[hidden] {
  display: none;
}
/* 出现时从上方滑入。 */
.feed-new:not([hidden]) > button {
  animation: fv-drop-in var(--motion-base) var(--motion-ease);
}

/* 标签切换：motion.js 在旧标签的位置放一块同样外观的底色，滑到新标签后移除；滑动期间新标签自己的底色先隐藏。 */
.fv-tabs-moving {
  position: relative;
}
.fv-tabs-moving > a {
  position: relative;
  z-index: 1;
}
.fv-tabs-moving > :is(a[aria-current='page'], a.active) {
  background-color: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
}
.fv-ink {
  position: absolute;
  left: 0;
  top: 0;
  box-sizing: border-box;
  pointer-events: none;
}

/* ===== 悬停与按压 ===== */

/* 帖子行、作品卡片、比赛卡片悬停时轻轻浮起。用 translate 属性，不影响各页面自己的 transform。 */
:where(.topic-row, .search-row, .grid > .card, .work-card, .contest-banner) {
  transition:
    translate var(--motion-base) var(--motion-ease),
    box-shadow var(--motion-base) var(--motion-ease),
    background-color var(--motion-fast) ease;
}
@media (hover: hover) {
  :where(.topic-row, .search-row):hover {
    translate: 0 -1px;
    box-shadow: 0 8px 18px #2024370f;
    position: relative;
  }
  :where(.grid > .card, .work-card, .contest-banner):hover {
    translate: 0 -2px;
    box-shadow: 0 12px 28px #20243714;
  }
}
/* 按钮按下时缩到 97%（只在站点页面和弹窗里，编辑器的控件不变）。 */
:where(#app, dialog) :where(button, a.button, .button):active:not(:disabled) {
  scale: 0.97;
}
:where(#app, dialog) :where(button, a.button, .button) {
  transition:
    scale 120ms ease,
    color var(--motion-fast) ease,
    background-color var(--motion-fast) ease,
    border-color var(--motion-fast) ease,
    box-shadow var(--motion-fast) ease;
}
@media (prefers-reduced-motion: reduce) {
  :where(.topic-row, .search-row, .grid > .card, .work-card, .contest-banner) {
    translate: none !important;
  }
  :where(#app, dialog) :where(button, a.button, .button):active {
    scale: none;
  }
}
