/* 显影 · 暗房画廊
   暗墙 #171412 / 相纸 #ECE6DA / 灰阶 #8F887B / 暗银 #3A352E / 安全灯 #C0532F
   动效 token 与通用入场基类见 css/motion.css */

:root {
  --wall: #171412;
  --wall-lift: #221e19;
  --paper: #ece6da;
  --ash: #8f887b;
  --safelight: #c0532f;
  --line: rgba(236, 230, 218, 0.10);      /* 暗底上的统一分隔线，不用实色 */
  --serif: "Noto Serif SC", "Songti SC", "SimSun", serif;
  --sans: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --gutter: 28px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { color-scheme: dark; }

body {
  background: var(--wall);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.85;
  padding-top: 52px;              /* 固定顶栏的高度补偿 */
  -webkit-font-smoothing: antialiased;
}

img { display: block; max-width: 100%; }

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--safelight);
  outline-offset: 3px;
}

/* ---------- 外壳 ---------- */

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

/* ---------- 顶栏：磨砂固定，滚动后出现分隔 ---------- */

.masthead {
  position: fixed;
  inset: 0 0 auto 0;
  height: 52px;
  z-index: 10;
  display: flex;
  align-items: center;
  background: rgba(23, 20, 18, 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur-1) var(--ease-ui);
}

body.is-scrolled .masthead {
  border-bottom-color: rgba(236, 230, 218, 0.08);
}

.masthead-in {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.wordmark {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-decoration: none;
}

.masthead nav { display: flex; gap: 28px; }

.masthead nav a {
  font-size: 12.5px;
  letter-spacing: 0.02em;
  color: var(--ash);
  text-decoration: none;
  padding-bottom: 2px;
  border-bottom: 1px solid transparent;
}

.masthead nav a:hover {
  color: var(--paper);
  border-bottom-color: var(--safelight);
}

/* ---------- 首屏：钉住 + 滚动驱动显影 ---------- */
/* 滚动进度 p（0→1）由 js/main.js 写入 .hero 的 --p；
   支持 animation-timeline: view() 的浏览器走文末的原生时间线块，JS 自动跳过。 */

.hero {
  position: relative;
  height: 144svh;                 /* 100svh 钉住画面 + 44svh 钉住行程 */
}

.hero-media {
  position: sticky;
  top: 0;
  height: 100svh;
  overflow: hidden;
  background: var(--wall-lift);
}

.hero-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* 静态基准 = 显影完成态；.u-hero 时由滚动进度接管 */
}

.hero-tail {
  height: 44svh;
}

.hero-copy {
  position: absolute;
  top: 66svh;
  left: var(--gutter);
  right: var(--gutter);
  z-index: 2;
  max-width: 980px;
}

.hero-line {
  font-family: var(--serif);
  font-size: clamp(30px, 5.2vw, 64px);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.hero-line span { display: inline-block; }

/* --- JS 滚动驱动路径（.u-hero 由 JS 添加）--- */

.hero.u-hero .hero-media img {
  --dd: min(1, var(--p, 0) / 0.18);
  opacity: calc(0.08 + var(--dd) * 0.92);
  filter:
    brightness(calc(0.35 + var(--dd) * 0.65))
    contrast(calc(0.6 + var(--dd) * 0.4));
  transform:
    scale(calc(1.06 - var(--p, 0) * 0.06))
    translateY(calc(-24px * var(--p, 0)));
}

.hero.u-hero .hero-line span {
  --ll: min(1, max(0, (var(--p, 0) - var(--ls, 0.1)) / 0.3));
  opacity: var(--ll);
  transform: translateY(calc(var(--rise) * (1 - var(--ll))));
}

.hero.u-hero .hero-copy {
  --ce: min(1, max(0, (var(--p, 0) - 0.55) / 0.45));
  opacity: calc(1 - var(--ce));
  transform: translateY(calc(-12px * var(--ce)));
}

/* --- 原生滚动时间线路径：与上面的 JS 路径等价，二选一 --- */

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* 具名时间线必须挂在非 sticky 的 .hero 上：sticky 的 .hero-media
       自身 rect 几乎不动，不能直接当 view() 时间线载体 */
    .hero { view-timeline: --hero block; }

    .hero.u-hero .hero-media img {
      opacity: 1;
      filter: none;
      transform: none;
      animation: u-hero-develop linear both, u-hero-para linear both;
      animation-timeline: --hero, --hero;
      animation-range: cover 41% cover 44.2%, cover 41% cover 59.03%;
    }

    .hero.u-hero .hero-line span {
      opacity: 1;
      transform: none;
      animation: u-hero-line linear both;
      animation-timeline: --hero;
    }
    .hero.u-hero .hero-line span:nth-child(1) { animation-range: cover 42.8% cover 48.2%; }
    .hero.u-hero .hero-line span:nth-child(2) { animation-range: cover 43.6% cover 49.02%; }
    .hero.u-hero .hero-line span:nth-child(3) { animation-range: cover 44.4% cover 49.83%; }

    .hero.u-hero .hero-copy {
      opacity: 1;
      transform: none;
      animation: u-hero-copy linear both;
      animation-timeline: --hero;
      animation-range: cover 50.9% cover 59.03%;
    }
  }
}

@keyframes u-hero-develop {
  from { opacity: 0.08; filter: brightness(0.35) contrast(0.6); }
  to   { opacity: 1;    filter: brightness(1) contrast(1); }
}

@keyframes u-hero-para {
  from { transform: scale(1.06) translateY(0); }
  to   { transform: scale(1) translateY(-24px); }
}

@keyframes u-hero-line {
  from { opacity: 0; transform: translateY(var(--rise)); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes u-hero-copy {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-12px); }
}

/* ---------- 章节化画廊：三个 sticky 章节 ---------- */

.works { margin-top: 0; }

.chapter {
  display: grid;
  grid-template-columns: 4fr 8fr;
  column-gap: 26px;
}

.chapter + .chapter { margin-top: 128px; }

.chapter-head {
  position: sticky;
  top: 96px;
  align-self: start;
  opacity: 0.35;                  /* 非当前章节时压暗，进入中线附近提亮 */
  transition: opacity var(--dur-3) var(--ease-out-expo);
}

.chapter.is-current .chapter-head { opacity: 1; }

/* 章节进入时序号先、名字后的一次 40ms 错位淡入 */
.chapter-head > * {
  opacity: 0;
  transition: opacity var(--dur-3) var(--ease-out-expo);
  transition-delay: calc(var(--i, 0) * 40ms);
}

.chapter.is-in .chapter-head > * { opacity: 1; }

.chapter-no {
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ash);
  font-variant-numeric: tabular-nums;
}

.chapter-name {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-top: 14px;
}

.chapter-meta {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--ash);
}

.chapter-lede {
  margin-top: 20px;
  font-size: 14.5px;
  line-height: 1.9;
  color: var(--paper);
  max-width: 22em;
}

.chapter-body {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  column-gap: 26px;
  row-gap: 72px;
  align-items: start;
}

/* ---------- 作品卡：入场由 js 挂 .u-rise / .is-in（见 motion.css）---------- */

.work {
  display: block;
  text-decoration: none;
}

.work-figure {
  position: relative;
  overflow: hidden;
  background: var(--wall-lift);
}

.work-figure img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--dur-2) var(--ease-ui);
}

/* 入场后卡片进入可按压状态（.u-done 由 js 在入场结束时添加） */
.work.u-done { transition: transform var(--dur-1) var(--ease-ui); }
.work.u-done:active { transform: scale(0.98); }

/* 悬停只允许两个动作：图片 scale 与下划线展开 */
.work:hover .work-figure img { transform: scale(1.02); }

.work-label {
  margin-top: 14px;
  display: flex;
  align-items: baseline;
  gap: 14px;
}

.work-label h2 {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.02em;
  display: inline-block;
  padding-bottom: 4px;
  background: linear-gradient(var(--safelight), var(--safelight)) no-repeat left 100% / 0% 2px;
  transition: background-size var(--dur-2) var(--ease-ui);
}

.work:hover .work-label h2 { background-size: 100% 2px; }

.work-label .series-year {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ash);
  white-space: nowrap;
}

.work.is-empty .work-figure img { display: none; }

/* ---------- 占位 / 骨架：替换 images/works/<id>.jpg 后自动消失 ---------- */

.stand-in {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.04 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E"),
    linear-gradient(135deg, #221e19, #1b1815);
}

.stand-in small {
  font-size: 11px;
  color: var(--ash);
  letter-spacing: 0.04em;
}

/* ---------- 页脚 ---------- */

.site-foot {
  margin-top: 144px;
  padding-top: 44px;
  padding-bottom: 60px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 7fr 5fr;
  column-gap: 26px;
}

.foot-block h3 {
  font-size: 13px;
  font-weight: 400;
  color: var(--ash);
  margin-bottom: 12px;
}

.foot-block p {
  font-size: 14.5px;
  line-height: 1.9;
  max-width: 34em;
}

.foot-block p a {
  color: var(--paper);
  display: inline-block;
  text-decoration-color: var(--safelight);
  text-underline-offset: 4px;
}

.colophon {
  margin-top: 40px;
  font-size: 12px;
  color: var(--ash);
}

/* ---------- 详情页：看照片时保持安静，全页只有两处动效 ---------- */

.detail { padding-top: 10px; }

.backlink {
  display: inline-block;
  margin-top: 30px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--ash);
  text-decoration: none;
}

.backlink:hover { color: var(--paper); }

.detail-figure {
  position: relative;
  overflow: hidden;
  background: var(--wall-lift);
  max-height: 76vh;
}

.detail-figure img {
  width: 100%;
  max-height: 76vh;
  object-fit: contain;
  view-transition-name: photo;
  animation: u-detail-img var(--dur-4) var(--ease-out-expo) backwards;
}

.detail-caption {
  margin-top: 40px;
  display: grid;
  grid-template-columns: 7fr 5fr;
  column-gap: 26px;
  view-transition-name: caption;
  animation: u-detail-cap var(--dur-3) var(--ease-out-expo) 180ms backwards;
}

.detail-caption h1 {
  font-family: var(--serif);
  font-size: clamp(30px, 4vw, 46px);
  font-weight: 600;
  line-height: 1.4;
}

.detail-caption .series-year {
  margin-top: 10px;
  font-size: 13px;
  color: var(--ash);
}

.detail-note {
  font-size: 15px;
  line-height: 2;
  max-width: 34em;
}

.detail-gear {
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--ash);
}

.detail-caption :is(h1, .series-year, .detail-note, .detail-gear) {
  animation: u-detail-el var(--dur-3) var(--ease-out-expo) backwards;
  animation-delay: calc(240ms + var(--i, 0) * 60ms);
}

.detail-figure .stand-in { position: relative; inset: auto; aspect-ratio: 16 / 9; }

/* 加载/占位骨架与真实图的交叉，由 js 的 load/error 事件完成，无空白帧 */

.detail-nav {
  margin-top: 96px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 24px;
}

.detail-nav a {
  display: block;
  max-width: 40%;
  color: var(--ash);
  font-size: 14px;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.detail-nav a:hover {
  color: var(--paper);
  border-bottom-color: var(--safelight);
}

.detail-nav .dir {
  display: block;
  font-size: 12px;
  color: var(--ash);
  margin-bottom: 6px;
}

/* ---------- 跨页转场：上一篇 / 下一篇不闪白 ---------- */

@view-transition { navigation: auto; }

::view-transition-old(photo),
::view-transition-new(photo) {
  animation-duration: var(--dur-2);
  animation-timing-function: var(--ease-ui);
}

::view-transition-old(photo) { animation-name: u-vt-out; }
::view-transition-new(photo) { animation-name: u-vt-in; }

@keyframes u-vt-out {
  to { opacity: 0; transform: scale(1.02); }
}

@keyframes u-vt-in {
  from { opacity: 0; transform: scale(0.99); }
}

/* ---------- 详情页入场 keyframes ---------- */

@keyframes u-detail-img {
  from { opacity: 0; transform: scale(1.02); }
}

@keyframes u-detail-cap {
  from { opacity: 0; transform: translateY(14px); }
}

@keyframes u-detail-el {
  from { opacity: 0; }
}

/* ---------- 可点元素的按压与过渡（逐条列出属性，禁 transition: all）---------- */

:where(.backlink, .foot-block p a) {
  transition:
    color var(--dur-1) var(--ease-ui),
    transform var(--dur-1) var(--ease-ui);
}

:where(.backlink, .foot-block p a):active { transform: scale(0.98); }

/* ---------- 响应式（≤760px 收为纵向流）---------- */

@media (max-width: 760px) {
  :root { --gutter: 20px; }

  .hero { height: calc(100svh + 44svh); }

  .hero-copy { top: 62svh; }

  .works,
  .chapter,
  .chapter-body,
  .site-foot,
  .detail-caption {
    display: block;
  }

  .chapter + .chapter { margin-top: 80px; }

  .chapter-head {
    position: static;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 16px;
    opacity: 1;
  }

  .chapter-head > * { opacity: 1; }

  .chapter-name,
  .chapter-meta,
  .chapter-lede { margin-top: 0; }

  .chapter-meta { margin-left: auto; }

  .chapter-lede { width: 100%; margin-top: 10px; }

  .work { margin-bottom: 56px; }
  .work:last-child { margin-bottom: 0; }

  .site-foot { margin-top: 80px; padding-bottom: 48px; }
  .foot-block + .foot-block { margin-top: 36px; }

  .detail-figure { max-height: none; }
  .detail-figure img { max-height: none; }

  .detail-nav a { max-width: 46%; }
}

/* ---------- 减少动态：首屏完全静态，内容不丢 ---------- */

@media (prefers-reduced-motion: reduce) {
  .hero { height: auto; }
  .hero-media { position: static; height: 60vh; }
  .hero-tail { display: none; }
  .hero-copy { position: static; margin-top: 24px; opacity: 1; transform: none; }
  .hero-line span { opacity: 1; transform: none; }
  .hero-media img { opacity: 1; filter: none; transform: none; }
  .masthead { -webkit-backdrop-filter: none; backdrop-filter: none; background: rgba(23, 20, 18, 0.92); }
}
