/* scene-ui — 画布、颗粒、章节轨、降级状态 */

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  background: var(--night);
}

.scene-fallback {
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0;
  pointer-events: none;
  background:
    radial-gradient(70% 60% at 50% 42%, rgba(43, 26, 18, .35), rgba(10, 8, 6, .9) 72%),
    var(--night) url("../assets/stills/cafe.webp") center / cover no-repeat;
  transition: opacity .6s ease;
}

body.no-webgl .scene-fallback { opacity: 1; }
body.no-webgl #scene { display: none; }

/* 胶片颗粒 */
.grain {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: .05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='160' height='160' filter='url(%23n)' opacity='.55'/></svg>");
  background-size: 160px 160px;
}

/* 顶部栏 */
.site-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: clamp(1.2rem, 2.6vw, 2.2rem) var(--gutter);
  pointer-events: none;
}

.site-header::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 190%;
  /* 正文会从标题栏底下滚过去，压暗要撑得住卡片那种浅色图 */
  background: linear-gradient(to bottom,
    rgba(10, 8, 6, .86) 0%,
    rgba(10, 8, 6, .58) 46%,
    rgba(10, 8, 6, 0) 100%);
  pointer-events: none;
}

.site-header a,
.chapter-track a { pointer-events: auto; }

.wordmark {
  display: grid;
  gap: .2rem;
  position: relative;
}

.wordmark__name {
  font-family: var(--latin);
  font-weight: 600;
  font-size: clamp(1.25rem, 1.8vw, 1.6rem);
  letter-spacing: .04em;
  line-height: 1;
}

.wordmark__meta {
  font-family: var(--latin);
  font-size: .56rem;
  letter-spacing: .3em;
  color: var(--ink-32);
}

/* 章节轨 */
.chapter-track {
  position: fixed;
  z-index: 21;
  right: var(--gutter);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  transition: opacity .45s ease, visibility .45s;
}

body.is-ending .chapter-track {
  opacity: 0;
  visibility: hidden;
}

.chapter-track a {
  display: flex;
  align-items: center;
  gap: .7rem;
  font-size: var(--fs-micro);
  letter-spacing: .14em;
  color: var(--ink-32);
  transition: color .35s ease;
}

.chapter-track .num {
  font-family: var(--latin);
  font-weight: 600;
  font-size: .74rem;
  letter-spacing: .1em;
  font-variant-numeric: tabular-nums;
}

.chapter-track .label {
  position: relative;
  padding-bottom: 2px;
}

.chapter-track .label::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .45s ease;
}

.chapter-track a:hover,
.chapter-track a:focus-visible { color: var(--ink-70); }

.chapter-track a.is-active { color: var(--amber); }
.chapter-track a.is-active .label::after { transform: scaleX(1); }

/* 滚动提示 */
.scroll-hint {
  position: absolute;
  left: var(--gutter);
  bottom: clamp(1.6rem, 4vh, 2.6rem);
  display: flex;
  flex-direction: column;
  gap: .7rem;
  font-size: var(--fs-micro);
  letter-spacing: .3em;
  color: var(--ink-32);
  z-index: 2;
}

.scroll-hint__line {
  width: 1px;
  height: 46px;
  background: linear-gradient(to bottom, var(--ink-32), transparent);
  animation: hint-drift 2.6s ease-in-out infinite;
}

@keyframes hint-drift {
  0%, 100% { transform: scaleY(.55); opacity: .4; transform-origin: top; }
  50%      { transform: scaleY(1);   opacity: 1;  transform-origin: top; }
}

/* 揭示动画 */
.reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity .9s cubic-bezier(.2, .7, .2, 1), transform .9s cubic-bezier(.2, .7, .2, 1);
}

.reveal.is-in {
  opacity: 1;
  transform: none;
}

/* 焦点 */
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 4px;
}

/* 移动端：章节轨折叠为顶部一条 */
@media (max-width: 900px) {
  .chapter-track {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    flex-direction: row;
    justify-content: space-between;
    gap: 0;
    padding: .8rem var(--gutter) calc(.8rem + env(safe-area-inset-bottom));
    background: linear-gradient(to top, rgba(10, 8, 6, .92), rgba(10, 8, 6, 0));
  }

  .chapter-track .label { display: none; }
  .chapter-track .num { font-size: .8rem; }
  .chapter-track a { padding: .3rem .2rem; }
  .chapter-track a.is-active .num { color: var(--amber); }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-hint__line { animation: none; }
  .reveal { opacity: 1; transform: none; transition: none; }
  .scene-fallback { transition: none; }
}

/* 画质开关（由 JS 注入） */
.quality-toggle {
  position: fixed;
  z-index: 22;
  right: var(--gutter);
  bottom: 1.4rem;
  font-family: var(--latin);
  font-size: .6rem;
  letter-spacing: .22em;
  color: var(--ink-32);
  text-transform: uppercase;
  border-bottom: 1px solid transparent;
}

.quality-toggle:hover { color: var(--ink-70); }

@media (max-width: 900px) {
  .quality-toggle { display: none; }
}
