/*
 * Akari 首页优化 (2026-11-06)
 * 只做覆盖，不改动主题自带样式表；删除本文件并移除 <link> 即可还原。
 */

/* ------------------------------------------------------------------ 1. 最新文章卡片 */
/* 现象：手机上卡片右侧文字被裁。
   原因：≤767px 时 .post-card 为 grid-template-columns: 42% 1fr（≤420px 为 38% 1fr），
   1fr 轨道下限是 auto，而标题被 white-space: nowrap 锁成单行，把第二列撑破。
   修复：列宽 minmax(0, 1fr) 允许收缩，标题在手机上两行截断。 */
@media (width <= 767px) {
  .latest-section .post-card,
  .post-grid .post-card {
    grid-template-columns: 42% minmax(0, 1fr);
  }

  .latest-section .post-copy,
  .post-grid .post-copy {
    min-width: 0;
  }

  .latest-section .post-copy h3 {
    display: -webkit-box;
    overflow: hidden;
    white-space: normal;
    overflow-wrap: anywhere;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
}

@media (width <= 420px) {
  .latest-section .post-card,
  .post-grid .post-card {
    grid-template-columns: 38% minmax(0, 1fr);
  }
}

/* ------------------------------------------------------------------ 2. 相册与瞬间：手机两列平铺 */
/* 现象：两张卡片一大一小、右侧贴边；改成横滑轨道后又要划一下才能看全。
   要求：一眼看到全部内容，不出现横向滚动。
   修复：≤767px 关掉横滑轨道，改成等宽两列网格（三张及以上按 2 列折行）。 */
@media (width <= 767px) {
  .media-links,
  .media-links:has(> :nth-child(2):last-child),
  .media-links:has(> :nth-child(3):last-child) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row;
    grid-auto-columns: auto;
    gap: 12px;
    margin-right: 0;
    padding-right: 0;
    overflow-x: visible;
    scroll-snap-type: none;
  }

  .media-links:has(> :only-child) {
    grid-template-columns: minmax(0, 1fr);
  }

  .media-link {
    min-height: 0;
    aspect-ratio: 3 / 4;
    scroll-snap-align: none;
  }
}

/* ------------------------------------------------------------------ 3. 首屏不要闪一下再渐入 */
/* 现象：内容先完整显示，等 JS 加载完再被隐藏并重新渐入（闪一下）。
   原因：隐藏规则只挂在 .motion-stage 上，而 .motion-stage 2.5 秒后就被移除；
   之后进入视口的区块先以 opacity:1 绘制，reveal 模块启动时才把它压回 0 再动画。
   修复：只要还没被 reveal 模块接管（没有 data-motion-reveal），就保持隐藏。
   兜底：模板里的内联脚本 6 秒后若仍无 data-motion-reveal，会加 .reveal-fallback 让内容直接显示，
        避免 JS 失败时整页空白。 */
html.motion-ready:not(.motion-reduce) [data-reveal]:not([data-motion-reveal]) {
  opacity: 0;
}

html.reveal-fallback [data-reveal] {
  opacity: 1 !important;
}

/* ------------------------------------------------------------------ 4. 页面切换不要白屏一下 */
/* 现象：点文章后先卡一下，随后整页从 opacity:0 淡入 0.28s，观感是「卡一下再慢慢浮出来」。
   这里把入场压到 0.16s 且从 0.35 起淡，切换瞬间不会出现整页透明的空白帧。 */
.page-view.is-visible {
  animation: 0.16s both akari-page-in-fast;
}

@keyframes akari-page-in-fast {
  from {
    opacity: 0.35;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

/* ------------------------------------------------------------------ 5. 页面切换的 View Transitions 时长 */
/* 现象：点击文章后网络只要 ~80ms，但换页要 ~390ms 才完成——剩下的大头是浏览器
   View Transitions API 的默认交叉淡出（约 250-300ms）。这里把它压到 0.12s。 */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.12s;
}

/* ------------------------------------------------------------------ 6. 换页时的进度条 */
/* 点开文章到新页面出来约有 200-400ms 的空档，给一条 2px 的顶部进度条做即时反馈。 */
html.nav-pending::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 999;
  height: 2px;
  background: linear-gradient(90deg, var(--akari-accent-source, #b94363), #d98ca3);
  transform-origin: 0 50%;
  animation: akari-nav-progress 0.9s ease-out forwards;
}

@keyframes akari-nav-progress {
  from { transform: scaleX(0.05); opacity: 1; }
  to { transform: scaleX(0.85); opacity: 0.9; }
}
