/* ============================================================
   7/8 —— 夏日夜空 × 数学摇滚（单页滚动版）
   配色克制：深夜蓝 #0d1426 / 墨蓝 #22314a / 白 / 金 #f2c230
   ============================================================ */

:root {
  --night: #0d1426;
  --ink: #22314a;
  --blue: #2e6fd8;
  --blue-pale: #bfe0f5;
  --gold: #f2c230;
  --white: #fdfdfd;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--night);
  color: var(--ink);
  font-family: "Hiragino Sans", "Noto Sans SC", "PingFang SC", sans-serif;
  line-height: 1.9;
  overflow-x: hidden;
}

::selection { background: var(--gold); color: var(--ink); }

/* ---------- 底噪颗粒 ---------- */
.grain {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 50;
  opacity: .05;
  background-image: repeating-conic-gradient(#000 0 .0001%, transparent 0 .0002%);
  background-size: 180px 180px;
}

/* ---------- 导航：difference 混合，深浅背景上都可读 ---------- */
.site-nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 2rem;
  mix-blend-mode: difference;
  color: #fff;
}
.nav-mark { font-weight: 700; letter-spacing: .15em; }
.nav-links a {
  color: #fff; text-decoration: none;
  margin-left: 1.4rem; font-size: .95rem; letter-spacing: .2em;
  border-bottom: 2px solid transparent;
  transition: border-color .25s;
}
.nav-links a:hover { border-color: var(--gold); }

/* ---------- 滚动显现 ---------- */
.reveal {
  opacity: 0;
  transform: translateY(36px);
  transition: opacity .9s ease, transform .9s cubic-bezier(.22, .8, .3, 1);
}
.reveal.in-view { opacity: 1; transform: none; }

/* ============ 第一幕：夜空（sticky，被白幕盖住） ============ */
.scene-night {
  position: sticky; top: 0;
  height: 100vh;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  background: radial-gradient(ellipse 90% 60% at 50% 110%, #1a2a4a 0%, var(--night) 60%);
  overflow: hidden;
  z-index: 1;
}
#fireworks { position: absolute; inset: 0; width: 100%; height: 100%; }

.sky-inner {
  position: relative; z-index: 2;
  padding: 2rem;
  animation: rise 1.2s ease-out both;
}
@keyframes rise { from { opacity: 0; transform: translateY(24px); } }

.kicker {
  letter-spacing: .5em; font-size: .8rem;
  color: var(--gold);
  margin-bottom: 1.2rem;
}
.title {
  font-size: clamp(2.6rem, 8vw, 5rem);
  font-weight: 700; color: var(--white);
  letter-spacing: .08em;
  text-shadow: 0 0 40px rgba(242, 194, 48, .25);
}
.tilde { color: var(--gold); }
.subtitle { margin-top: 1.4rem; color: rgba(253, 253, 253, .75); }
.time-signatures {
  margin-top: 2rem;
  display: flex; justify-content: center; gap: 1.6rem;
  color: rgba(191, 224, 245, .5);
  font-weight: 700; letter-spacing: .1em; font-size: .85rem;
}
.scroll-hint {
  position: absolute; left: 50%; bottom: 1.8%; z-index: 2;
  transform: translateX(-50%);
  color: var(--gold); text-decoration: none; letter-spacing: .3em;
  animation: bob 2s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateX(-50%) translateY(6px); } }

/* ============ 第二幕：乡间白昼，群山从夜空里升上来 ============ */
.scene-field {
  position: relative; z-index: 2;
  background: none; /* 上沿透明，透出后面的 sticky 夜空 */
}
/* 山脊边缘：波浪上沿用夜空做背景，不再是白板一条 */
.field-edge { position: relative; }
.field-edge svg { display: block; width: 100%; height: clamp(170px, 26vw, 360px); }

.field-inner {
  background: var(--white);
  margin-top: -1px; /* 和山脚白边接合，不留缝 */
  padding: 3rem 2rem 5rem;
}
.field-inner .kicker { color: var(--blue); text-align: center; }
.section-title {
  text-align: center; color: var(--ink);
  letter-spacing: .15em; margin-bottom: 3rem;
}

/* 乡间场景：立绘站在风景里，无框 */
.countryside {
  position: relative;
  max-width: 900px; margin: 0 auto;
}
.hills { display: block; width: 100%; height: auto; }
.hero-img {
  position: absolute;
  bottom: 8%; left: 50%;
  transform: translateX(-50%);
  max-height: 95%;
  max-width: 60%;
  filter: drop-shadow(0 12px 24px rgba(34, 49, 74, .25));
  animation: hero-float 5s ease-in-out infinite;
}
@keyframes hero-float { 50% { transform: translateX(-50%) translateY(-10px); } }

/* 风车慢慢转 */
.windmill-blades {
  transform-origin: 322px 196px;
  animation: spin 14s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 山丘波浪缓慢小幅起伏（只往下压，顶部白底不露缝） */
.hills > path:nth-of-type(1) { animation: hillBob 8s ease-in-out infinite; }
.hills > path:nth-of-type(2) { animation: hillBob 10s ease-in-out -3s infinite; }
.hills > path:nth-of-type(3) { animation: hillBob 9s ease-in-out -5.5s infinite; }
@keyframes hillBob { 50% { transform: translateY(3px); } }

/* 两只飞鸟轻轻浮动，相位错开 */
.hills .birds path { animation: birdBob 3.6s ease-in-out infinite; }
.hills .birds path + path { animation-delay: -1.8s; }
@keyframes birdBob { 50% { transform: translateY(-3px); } }

/* ---------- 好友纪念：文字 + 左右方形头像 ---------- */
.friends {
  display: flex; align-items: center; justify-content: center;
  gap: 2.6rem;
  margin: 0 auto 3.5rem;
}
.friend-line { text-align: center; font-size: .95rem; opacity: .85; }
.friend-line strong {
  color: var(--gold); font-size: 1.2em; padding: 0 .15em;
}
.avatar {
  position: relative; flex: none;
  width: 104px; height: 104px;
  border: 1.5px solid var(--blue-pale);
  background: linear-gradient(160deg, rgba(191,224,245,.4), rgba(242,194,48,.1));
  box-shadow: 4px 4px 0 rgba(191, 224, 245, .5);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar .deco {
  position: absolute; top: -20px;
  width: 36px; height: 36px;
  pointer-events: none;
}
.avatar-me .deco { left: -12px; }   /* 左边：红色小花 */
.avatar-her .deco { right: -12px; } /* 右边：小鸟剪影 */

.field-text { max-width: 640px; margin: 4rem auto 0; }
.field-text h3 { color: var(--ink); margin-bottom: 1.4rem; letter-spacing: .1em; }
.field-text p { margin-bottom: 1rem; }
.note { font-size: .8rem; color: var(--blue); opacity: .6; margin-top: 1rem; }

/* ============ 第三幕：信 ============ */
.scene-letter {
  position: relative; z-index: 2;
  background:
    radial-gradient(ellipse 60% 40% at 50% 0%, var(--blue-pale), transparent 70%),
    var(--white);
}
.letter-wrap { max-width: 720px; margin: 0 auto; padding: 7rem 1.5rem 6rem; }
.letter-wrap > .kicker { text-align: center; color: var(--blue); }
.letter {
  background: #fff;
  border: 1px solid var(--blue-pale);
  box-shadow: 6px 6px 0 rgba(191, 224, 245, .6);
  padding: 3.5rem 3rem; margin-top: 2rem;
  position: relative;
}
.letter h1 { color: var(--ink); font-size: 1.4rem; margin-bottom: 1.5rem; }
.letter p { margin-bottom: 1.2rem; }
.postmark {
  position: absolute; top: 1.5rem; right: 1.5rem;
  width: 64px; height: 64px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  background: none;
  display: flex; align-items: center; justify-content: center;
  color: var(--gold); font-size: 1.3rem;
  transform: rotate(12deg);
  cursor: pointer;
  transition: border-color .3s, color .3s, opacity .3s;
}
.postmark:hover { transform: rotate(12deg) scale(1.08); }
/* 播放中：变成旋转的浅蓝色按钮 */
.postmark.playing {
  border-color: #8fb3d9;
  color: #8fb3d9;
  animation: spin 4s linear infinite;
}
.postmark.missing { opacity: .3; cursor: not-allowed; }
.sign { text-align: right; margin-top: 2.5rem; }
.sign-date { font-size: .85rem; color: var(--blue); }

.outro { text-align: center; padding: 4rem 2rem 5rem; }
.prev-link {
  color: var(--blue); text-decoration: none; letter-spacing: .2em;
  border-bottom: 1px solid var(--blue-pale);
}

/* ---------- 波浪播放器（第一屏下半部分） ---------- */
.wave-player {
  position: absolute; left: 50%; bottom: 7%;
  transform: translateX(-50%);
  width: min(82vw, 880px);
  text-align: center;
  cursor: pointer; z-index: 2;
}
.wave-hint {
  color: rgba(191, 224, 245, .75);
  font-size: .82rem; letter-spacing: .3em;
  margin-bottom: .4rem;
  animation: hintPulse 2.4s ease-in-out infinite;
  transition: opacity .5s;
}
.wave-hint.gone { opacity: 0; animation: none; }
@keyframes hintPulse { 50% { opacity: .35; } }
.wave-lines { display: block; width: 100%; height: 96px; }
#waveBlue { filter: drop-shadow(0 0 5px rgba(191, 224, 245, .4)); }
#waveGold {
  transition: opacity .4s;
  filter: drop-shadow(0 0 7px rgba(242, 194, 48, .55));
}

/* ---------- 音乐开关（滚过第一幕后出现） ---------- */
#music-toggle {
  position: fixed; right: 1.6rem; bottom: 1.6rem; z-index: 60;
  width: 52px; height: 52px; border-radius: 50%;
  border: 2px solid var(--gold);
  background: rgba(253, 253, 253, .72);
  backdrop-filter: blur(4px);
  color: var(--gold); font-size: 1.4rem; line-height: 1;
  cursor: pointer;
  opacity: 0; pointer-events: none;
  transition: opacity .3s, transform .2s;
}
#music-toggle.show { opacity: 1; pointer-events: auto; }
#music-toggle.show:hover { transform: scale(1.08); }
#music-toggle.playing { animation: spin 4s linear infinite; }
#music-toggle.missing { opacity: .3; cursor: not-allowed; }

/* ---------- 信件区浅水：滚动时从底部漫上来 ---------- */
.scene-letter { overflow: hidden; }
.water {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 0; /* JS 按滚动进度驱动 */
  background: rgba(143, 179, 217, .32);
  z-index: 3;
  pointer-events: none;
}
.water-wave {
  position: absolute; left: 0; bottom: 100%;
  width: 200%; height: 34px; display: block;
  animation: waterDrift 7s linear infinite;
}
@keyframes waterDrift { to { transform: translateX(-50%); } }

/* ---------- 星幕分层入场：滚到这一幕时依次浮现 ---------- */
.scene-star .sky-bg, .scene-star .sun, .scene-star .sea,
.scene-star .sand, .scene-star .foam, .scene-star .palm-tree,
.scene-star .suitcase {
  opacity: 0;
  transition: opacity 1.2s ease, transform 1.2s cubic-bezier(.22, .8, .3, 1);
}
.scene-star .sun       { transform: translateY(120px); }
.scene-star .sea       { transform: translateY(60px); }
.scene-star .sand, .scene-star .foam { transform: translateY(90px); }
.scene-star .palm-tree { transform: translateY(40px); }
.scene-star .suitcase  { transform: translateX(-50%) translateY(30px); }

.scene-star.in-view .sky-bg   { opacity: 1; }
.scene-star.in-view .sun      { opacity: 1; transform: none; transition-delay: .3s; }
.scene-star.in-view .sea      { opacity: 1; transform: none; transition-delay: .5s; }
.scene-star.in-view .sand, .scene-star.in-view .foam {
  opacity: 1; transform: none; transition-delay: .7s;
}
.scene-star.in-view .palm-tree { opacity: 1; transform: none; transition-delay: .95s; }
.scene-star.in-view .suitcase  { opacity: 1; transform: translateX(-50%); transition-delay: 1.1s; }

/* ============ 第四幕：星 —— 天空 / 大海 / 沙滩 ============ */
.scene-star {
  position: relative; z-index: 2;
  min-height: 100vh;
  overflow: hidden;
  background: #dff0fb; /* SVG 加载前的兜底色 */
}
/* 整张海滩场景背景：天空上端接近白色，和信件区柔和衔接 */
.star-bg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  z-index: 0;
}
.star-inner { padding-top: 6rem; text-align: center; position: relative; z-index: 2; }
.star-inner .kicker { color: var(--blue); }
.suitcase-hint {
  color: var(--blue); font-size: .85rem; letter-spacing: .3em;
  animation: hintPulse 2.4s ease-in-out infinite;
  transition: opacity .5s;
}
.suitcase-hint.gone { opacity: 0; animation: none; }
.star-outro {
  position: absolute; left: 0; right: 0; bottom: 1rem;
  text-align: center; z-index: 1; /* 压在飞出的纸张下面 */
}
/* 椰子树：行李箱左边，窄屏也不会被裁掉 */
.palm-tree {
  position: absolute;
  left: max(3%, calc(50% - 370px));
  bottom: 18%;
  width: 210px; height: auto; z-index: 1;
}

/* ---------- 行李箱（伪3D开盖） ---------- */
.suitcase {
  position: absolute; left: 50%; bottom: 18%; /* 上移，避开底部按钮的触发范围 */
  transform: translateX(-50%);
  width: 280px; height: 190px;
  perspective: 1000px;
  cursor: pointer; z-index: 3; /* 飞出的纸张要盖过星幕其他元素 */
}
/* 箱体（打开后看到的内部） */
.case-body {
  position: absolute; inset: 0;
  background: #1a2740;
  border-radius: 14px;
  box-shadow: inset 0 8px 20px rgba(0, 0, 0, .5),
              0 16px 26px rgba(34, 49, 74, .3);
}
/* 盖子：整个正面，绕顶边向上掀开 */
.case-lid {
  position: absolute; inset: 0; z-index: 3;
  background: linear-gradient(160deg, #324a75, #22314a 70%);
  border-radius: 14px;
  transform-origin: center top;
  transform: rotateX(0deg);
  transition: transform .9s cubic-bezier(.34, 1.2, .5, 1);
  backface-visibility: visible;
}
/* 盖子上的金色绑带 */
.case-lid::before, .case-lid::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 14px;
  background: var(--gold); opacity: .85;
}
.case-lid::before { left: 22%; }
.case-lid::after { right: 22%; }
/* 提手 */
.case-handle {
  position: absolute; left: 50%; top: -16px;
  width: 58px; height: 20px;
  transform: translateX(-50%);
  border: 5px solid var(--gold);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
}
.suitcase.open .case-lid { transform: rotateX(-102deg); }

/* 箱子里的纸：开盖后飞到页面前面，带纸纹和揉皱感 */
.case-paper {
  position: absolute; left: 50%; top: 24px; z-index: 2;
  width: 240px; min-height: 150px;
  margin-left: -120px;
  padding: 14px 16px;
  color: var(--ink);
  background:
    linear-gradient(105deg, rgba(0, 0, 0, .06), transparent 32%),
    linear-gradient(75deg, transparent 62%, rgba(0, 0, 0, .05)),
    linear-gradient(160deg, transparent 45%, rgba(0, 0, 0, .04) 55%, transparent 65%),
    repeating-linear-gradient(0deg, transparent 0 24px, rgba(34, 49, 74, .06) 24px 25px),
    radial-gradient(ellipse at 25% 20%, rgba(0, 0, 0, .04), transparent 55%),
    radial-gradient(ellipse at 80% 85%, rgba(0, 0, 0, .05), transparent 50%),
    #fbf7ec;
  box-shadow: 0 10px 24px rgba(34, 49, 74, .35);
  opacity: 0;
  transform: translateY(26px) scale(.55);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif SC", "Songti SC", serif;
  /* 点击穿透纸张：盖住底部按钮时也能点到按钮；点纸会落到幕布空白处从而收纸 */
  pointer-events: none;
  transition: transform 1.1s cubic-bezier(.22, .9, .3, 1.15) .3s,
              opacity .5s ease .3s;
}
.suitcase.open .case-paper {
  opacity: 1; z-index: 5;
  transform: translateY(-290px) scale(1.8) rotate(-2.5deg);
}
.case-paper img { width: 100%; display: block; margin-bottom: 10px; }
.case-paper p { font-size: .9rem; line-height: 1.7; margin: 0; }

/* ---------- 插曲的右下角蓝色音符（与金色按钮互斥，共用角落位置） ---------- */
#music-toggle2 {
  position: fixed; right: 1.6rem; bottom: 1.6rem; z-index: 60;
  width: 52px; height: 52px; border-radius: 50%;
  border: 2px solid var(--blue);
  background: rgba(253, 253, 253, .72);
  backdrop-filter: blur(4px);
  color: var(--blue); font-size: 1.4rem; line-height: 1;
  cursor: pointer;
  opacity: 0; pointer-events: none;
  transition: opacity .3s, transform .2s;
}
#music-toggle2.show { opacity: 1; pointer-events: auto; }
#music-toggle2.show:hover { transform: scale(1.08); }
#music-toggle2.playing { animation: spin 4s linear infinite; }

/* ---------- 窄屏 ---------- */
@media (max-width: 720px) {
  .site-nav { padding: 1rem; }
  .letter { padding: 2.5rem 1.5rem; }
  .hero-img { max-width: 80%; }
  .friends { gap: 1.2rem; }
  .avatar { width: 80px; height: 80px; }
  .avatar .deco { width: 28px; height: 28px; top: -16px; }
  .friend-line { font-size: .85rem; }
  .suitcase { scale: .78; bottom: 14%; }
  .palm-tree { width: 130px; left: max(1%, calc(50% - 230px)); bottom: 22%; }
}
