/* ==========================================================================
 *  《四季》 · 世纪工作室四周年纪念
 *  style.css —— 舞台、提示、加载、首页
 *
 *  设计基调：东方 / 空灵 / 留白 / 克制
 *  颜色：墨（#0a0b0d 底）、纸（#e8e2d4 字）、金（#c9ad78）、朱（#a62a20）
 *  动效：一律只动 transform 与 opacity，避免重排
 * ========================================================================== */

/* ------------------------------------------------------------------ */
/* 字体                                                                */
/* ------------------------------------------------------------------ */

@font-face {
  font-family: 'SanJiXingKai';
  src: url('../assets/font/SanJiXingKaiJianTi-Cu-2.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'SanJiXingKai';
  src: url('../assets/font/SanJiXingKaiJianTi-Cu-2.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #0a0b0d;
  --ink-2: #14171b;
  --paper: #e8e2d4;
  --paper-dim: rgba(232, 226, 212, 0.62);
  --paper-faint: rgba(232, 226, 212, 0.34);
  --gold: #c9ad78;
  --cinnabar: #a62a20;
  --font-display: 'SanJiXingKai', 'STKaiti', 'KaiTi', 'Kaiti SC', 'Songti SC', 'SimSun', serif;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* 四季拼页底色：四角各据一季（左上冬 / 右上秋 / 左下春 / 右下夏）
     四道由各角向内衰减的径向渐变叠在暗底之上——
     颜色在画面中央自然隐没，既"拼"成四块，又不留任何硬边。 */
  --season-quads:
    radial-gradient(78% 78% at 0% 0%, rgba(60, 112, 160, 0.56), rgba(60, 112, 160, 0) 74%),
    radial-gradient(78% 78% at 100% 0%, rgba(170, 118, 40, 0.52), rgba(170, 118, 40, 0) 74%),
    radial-gradient(78% 78% at 0% 100%, rgba(50, 140, 82, 0.46), rgba(50, 140, 82, 0) 74%),
    radial-gradient(78% 78% at 100% 100%, rgba(176, 84, 42, 0.44), rgba(176, 84, 42, 0) 74%);
}

/* ------------------------------------------------------------------ */
/* 复位                                                                */
/* ------------------------------------------------------------------ */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

canvas { display: block; }

.noscript {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 8vw; text-align: center; line-height: 2; color: var(--paper-dim); font-size: 16px;
  background: var(--ink); z-index: 999;
}

/* ------------------------------------------------------------------ */
/* 舞台                                                                */
/* ------------------------------------------------------------------ */

/**
 * 全屏静态效果全部走 CSS 合成层，而不是画进 Canvas：
 * 暗场 / 光池 / 暗角 / 颗粒原先每帧要占 4~5 次全屏渐变构造与混合，
 * 是低端设备（软件渲染、远程桌面、老手机）卡顿的最大来源。
 * 改为静态 DOM 层后由合成器承担，Canvas 每帧只画书与粒子。
 */

/* 暗场背景 + 书后光池 */
.bg-backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(46% 42% at 50% 47%, rgba(126, 134, 146, 0.16), rgba(96, 102, 112, 0.07) 46%, rgba(80, 86, 96, 0) 72%),
    radial-gradient(120% 84% at 50% 42%, #14171b 0%, #0c0e11 55%, #050608 100%);
}

/*
 * 合书之后的四季拼页底色
 * 叠在 .bg-backdrop 之上（同为 z-index:0，靠 DOM 顺序压住它），
 * 默认完全透明，由 final.js 在书页合拢时加 .show 淡入。
 */
.fx-seasons {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  background: var(--season-quads);
  transition: opacity 1.8s var(--ease-out);
}
.fx-seasons.show { opacity: 1; }

/*
 * 跳转官网的过渡幕：只做一次朴素的**渐暗**
 *
 * 试过"四色拉幕"，但满屏色块无论怎么柔化都会抢戏，也把前面攒下的克制感一次性放掉。
 * 渐暗最安静，且与全片暗调一致；终点取近黑的深色，正好接住官网的深色底，
 * 切过去时两边都是暗的，不会有亮度跳变。
 */
.leave-veil {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  opacity: 0;
  background: #101216;
}

/* 暗角：压四角，聚视线 */
.fx-vignette {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: radial-gradient(78% 78% at 50% 46%,
    rgba(0, 0, 0, 0) 0%,
    rgba(8, 7, 6, 0.18) 62%,
    rgba(6, 5, 4, 0.62) 100%);
  transition: opacity 1.8s var(--ease-out);
}
/* 四季拼页亮起时把暗角收敛——它正好压住四角，不收敛就看不清四季色 */
.fx-vignette.soften { opacity: 0.42; }

/* 胶片颗粒：平铺噪点 + 位移跳变，GPU 合成 */
.fx-grain {
  position: fixed;
  inset: -128px;
  z-index: 5;
  pointer-events: none;
  background: url('../assets/texture/noise.png') repeat;
  background-size: 256px 256px;
  opacity: 0.05;
  mix-blend-mode: overlay;
  animation: grainShift 0.6s steps(1, end) infinite;
  will-change: transform;
}
@keyframes grainShift {
  0%, 100% { transform: translate3d(0, 0, 0); }
  20% { transform: translate3d(-64px, 32px, 0); }
  40% { transform: translate3d(32px, -48px, 0); }
  60% { transform: translate3d(-48px, -16px, 0); }
  80% { transform: translate3d(24px, 40px, 0); }
}

#app {
  position: fixed;
  inset: 0;
  z-index: 1;
  opacity: 0;
  transition: opacity 1.2s var(--ease-out);
}
#app.ready { opacity: 1; }

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: default;
}

/* 右下提示：轻触翻开故事 */
.hint {
  position: absolute;
  right: max(5.5vw, 26px);
  bottom: max(6vh, 34px);
  z-index: 7;
  font-size: clamp(13px, 1.5vw, 17px);
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  color: rgba(232, 226, 212, 0.66);
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 1px 14px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
}
.hint::after {
  content: '';
  position: absolute;
  right: 0;
  bottom: -10px;
  width: 44px;
  height: 1px;
  background: linear-gradient(90deg, rgba(201, 173, 120, 0), rgba(201, 173, 120, 0.75));
}

/* 声音开关 */
.sound {
  position: absolute;
  left: max(4.5vw, 22px);
  bottom: max(5.5vh, 30px);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid rgba(232, 226, 212, 0.16);
  border-radius: 999px;
  background: rgba(232, 226, 212, 0.04);
  color: rgba(232, 226, 212, 0.55);
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: color .45s ease, border-color .45s ease, background .45s ease, transform .3s var(--ease-out);
}
.sound:hover { color: rgba(232, 226, 212, 0.9); border-color: rgba(232, 226, 212, 0.3); }
.sound:active { transform: scale(0.96); }
.sound-bar { display: flex; align-items: flex-end; gap: 2px; height: 12px; }
.sound-bar i {
  display: block; width: 2px; height: 4px;
  background: currentColor; border-radius: 1px;
  animation: soundWave 1.5s ease-in-out infinite;
}
.sound-bar i:nth-child(2) { animation-delay: .22s; }
.sound-bar i:nth-child(3) { animation-delay: .44s; }
.sound.muted .sound-bar i { animation-play-state: paused; height: 3px; opacity: .5; }
.sound.muted .sound-txt { opacity: .55; }

@keyframes soundWave {
  0%, 100% { height: 3px; }
  50% { height: 12px; }
}

/* ------------------------------------------------------------------ */
/* 加载：研墨                                                          */
/* ------------------------------------------------------------------ */

.loader {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
}
.loader-inner { text-align: center; }

.loader-seal {
  width: 34px; height: 34px; margin: 0 auto 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--cinnabar);
  border: 1.5px solid var(--cinnabar);
  border-radius: 3px;
  opacity: .82;
  animation: sealPulse 3.4s ease-in-out infinite;
}
@keyframes sealPulse {
  0%, 100% { opacity: .62; transform: scale(1); }
  50% { opacity: .95; transform: scale(1.045); }
}

.loader-title {
  font-size: clamp(38px, 7vw, 62px);
  letter-spacing: 0.30em;
  text-indent: 0.30em;
  color: rgba(232, 226, 212, 0.9);
  margin-bottom: 26px;
}

.loader-bar-wrap {
  width: min(220px, 54vw);
  height: 1px;
  margin: 0 auto 16px;
  background: rgba(232, 226, 212, 0.12);
  overflow: hidden;
}
.loader-bar {
  width: 100%; height: 100%;
  background: linear-gradient(90deg, rgba(201, 173, 120, .3), var(--gold));
  transform: scaleX(0);
  transform-origin: left center;
}
.loader-text {
  font-size: 13px;
  letter-spacing: 0.36em;
  text-indent: 0.36em;
  color: rgba(232, 226, 212, 0.42);
}

/* ------------------------------------------------------------------ */
/* 首页                                                                */
/* ------------------------------------------------------------------ */

.home {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  overflow: hidden;
  /* 与合书后的暗场同源：四角四季色 + 中央暗底，过渡过去时不会突兀换调 */
  background:
    var(--season-quads),
    radial-gradient(120% 80% at 50% 0%, #171a1f 0%, #0d0f12 45%, #08090b 100%);
}
.home.show { display: block; }

/* 首页上的两抹淡墨，增加空气感 */
.home::before,
.home::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
.home::before {
  width: 78vw; height: 78vw; left: -26vw; top: -30vw;
  background: radial-gradient(circle, rgba(120, 138, 158, 0.10), rgba(120, 138, 158, 0) 68%);
}
.home::after {
  width: 66vw; height: 66vw; right: -22vw; bottom: -26vw;
  background: radial-gradient(circle, rgba(201, 173, 120, 0.075), rgba(201, 173, 120, 0) 68%);
}

.home-inner {
  position: relative;
  z-index: 2;
  height: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: max(4.2vh, 26px) max(5vw, 26px) max(3.6vh, 24px);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* 顶栏 */
.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: none;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-seal {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--cinnabar);
  border: 1.4px solid rgba(166, 42, 32, 0.85);
  border-radius: 2px;
}
.brand-name {
  font-size: 16px;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  color: rgba(232, 226, 212, 0.86);
}
.brand-year {
  font-size: 12px;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  color: var(--paper-faint);
}

/* 主视觉 */
.hero {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: max(5vh, 30px) 0 max(4vh, 26px);
}
.hero-title {
  font-size: clamp(64px, 15vw, 168px);
  font-weight: 400;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  line-height: 1.05;
  color: #efe9dc;
  text-shadow: 0 2px 40px rgba(0, 0, 0, 0.55);
}
.hero-rule {
  width: min(200px, 44vw);
  height: 1px;
  margin: clamp(20px, 3.4vh, 34px) 0 clamp(16px, 2.6vh, 26px);
  background: linear-gradient(90deg, rgba(201, 173, 120, 0), rgba(201, 173, 120, 0.85), rgba(201, 173, 120, 0));
}
.hero-sub {
  font-size: clamp(15px, 2.1vw, 20px);
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  color: var(--gold);
  opacity: .9;
}
.hero-lead {
  margin-top: clamp(20px, 3.2vh, 34px);
  font-size: clamp(13px, 1.6vw, 16px);
  line-height: 2.15;
  letter-spacing: 0.16em;
  color: var(--paper-dim);
  max-width: 40em;
}

/* 四季 */
.chapters {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(10px, 2vw, 26px);
  padding: max(3vh, 20px) 0;
  border-top: 1px solid rgba(232, 226, 212, 0.10);
  border-bottom: 1px solid rgba(232, 226, 212, 0.10);
}
.chapter {
  text-align: center;
  padding: clamp(12px, 2.2vh, 22px) 6px;
  position: relative;
}
.chapter + .chapter::before {
  content: '';
  position: absolute;
  left: 0; top: 22%; bottom: 22%;
  width: 1px;
  background: rgba(232, 226, 212, 0.10);
}
.chapter-mark {
  font-size: 11px;
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  color: var(--paper-faint);
  margin-bottom: 8px;
}
.chapter h2 {
  font-size: clamp(28px, 4.4vw, 44px);
  font-weight: 400;
  letter-spacing: 0.14em;
  text-indent: 0.14em;
  color: rgba(240, 234, 222, 0.94);
  margin-bottom: 10px;
}
.chapter p {
  font-size: clamp(12px, 1.35vw, 14px);
  letter-spacing: 0.14em;
  text-indent: 0.14em;
  line-height: 1.9;
  color: var(--paper-faint);
}

/* 按钮 */
.home-actions {
  flex: none;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: clamp(12px, 1.6vw, 20px);
  padding: max(3.4vh, 24px) 0 max(2vh, 14px);
}

/* 主行动：开启新篇章 → 官网 */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 13px 38px;
  font-size: 14px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: #1b1a16;
  text-decoration: none;
  border: 1px solid rgba(201, 173, 120, 0.9);
  border-radius: 999px;
  background: linear-gradient(180deg, #dcc48c, #c9ad78);
  box-shadow: 0 6px 22px rgba(201, 173, 120, 0.14);
  transition: filter .45s var(--ease-out), transform .4s var(--ease-out),
              box-shadow .45s var(--ease-out);
}
.btn-primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 10px 30px rgba(201, 173, 120, 0.22);
}
.btn-primary:active { transform: translateY(0) scale(0.985); }
/* 一枚素净的箭头，不依赖字体 */
.btn-primary::after {
  content: '';
  width: 6px; height: 6px;
  margin-left: 2px;
  border-top: 1.4px solid currentColor;
  border-right: 1.4px solid currentColor;
  transform: rotate(45deg);
  opacity: .7;
}

.btn-replay {
  display: inline-block;
  padding: 13px 34px;
  font-size: 14px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: rgba(232, 226, 212, 0.86);
  text-decoration: none;
  border: 1px solid rgba(201, 173, 120, 0.34);
  border-radius: 999px;
  background: rgba(201, 173, 120, 0.05);
  transition: color .5s var(--ease-out), border-color .5s var(--ease-out),
              background .5s var(--ease-out), transform .4s var(--ease-out);
}
.btn-replay:hover {
  color: #fff8ea;
  border-color: rgba(201, 173, 120, 0.72);
  background: rgba(201, 173, 120, 0.12);
  transform: translateY(-1px);
}
.btn-replay:active { transform: translateY(0) scale(0.985); }

/* 页脚 */
.home-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 11px;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  color: rgba(232, 226, 212, 0.26);
}
.home-foot .dot { opacity: .5; }

/* ------------------------------------------------------------------ */
/* 响应式                                                              */
/* ------------------------------------------------------------------ */

@media (max-width: 860px) {
  .chapters { grid-template-columns: repeat(2, 1fr); gap: 4px 10px; }
  .chapter:nth-child(3)::before,
  .chapter:nth-child(4)::before { display: none; }
  .chapter:nth-child(3)::before { display: block; }
  .chapter:nth-child(odd)::before { display: none; }
  .hero-lead { letter-spacing: 0.12em; }
}

@media (max-width: 520px) {
  .home-inner { padding-left: 22px; padding-right: 22px; }
  .brand-name { font-size: 14px; letter-spacing: 0.18em; }
  .brand-year { font-size: 11px; }
  .hero-sub { letter-spacing: 0.24em; text-indent: 0.24em; }
  .home-foot { flex-wrap: wrap; text-align: center; }
}

/* 横屏矮窗口：压缩纵向节奏 */
@media (max-height: 560px) {
  .hero { padding: 18px 0; }
  .hero-lead { display: none; }
  .chapters { padding: 14px 0; }
  .home-actions { padding: 16px 0 10px; }
}

/* 深色偏好与降级 */
@media (prefers-reduced-motion: reduce) {
  .sound-bar i, .loader-seal { animation: none; }
  .fx-grain { animation: none; }
}
