/* ============================================================
   base.css — 全局基础样式 · Preloader · 日夜模式变量
   trees.center · 种亿棵树
   ============================================================ */

/* === Google Fonts 引入 === */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@300;400;500;700&family=Playfair+Display:ital,wght@0,400;0,700;1,400&display=swap');

/* ===========================
   CSS Reset
   =========================== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

img, video, canvas, svg {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

ul, ol { list-style: none; }

/* ===========================
   设计令牌 — 核心变量
   =========================== */
:root {
  /* 品牌色彩 */
  --c-deep-green:   #0a1f0a;
  --c-forest:       #1a4a1a;
  --c-emerald:      #2d8a4e;
  --c-gold:         #c9a84c;
  --c-night:        #0a0e2a;
  --c-neon-green:   #4ade80;

  /* 字体 */
  --font-cn: 'Noto Serif SC', 'Songti SC', serif;
  --font-en: 'Playfair Display', 'Georgia', serif;

  /* 默认（夜间）氛围变量 */
  --sky-color:        #0a0e2a;
  --sky-gradient:     linear-gradient(180deg, #060818 0%, #0a0e2a 40%, #0a1f0a 100%);
  --fog-color:        #0a1f0a;
  --ambient-light:    0.3;
  --text-primary:     rgba(255, 255, 255, 0.92);
  --text-secondary:   rgba(255, 255, 255, 0.65);
  --text-accent:      #4ade80;
  --bg-primary:       #0a1f0a;
  --bg-overlay:       rgba(10, 31, 10, 0.85);
  --particle-color:   #4ade80;
  --particle-glow:    rgba(74, 222, 128, 0.6);
  --glow-color:       rgba(74, 222, 128, 0.15);
  --surface-glass:    rgba(255, 255, 255, 0.04);
  --border-subtle:    rgba(255, 255, 255, 0.08);

  /* 动画时长 */
  --ease-smooth:  cubic-bezier(0.25, 0.1, 0.25, 1);
  --ease-bounce:  cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast:   0.2s;
  --duration-normal: 0.4s;
  --duration-slow:   0.8s;
}

/* ===========================
   夜间模式（默认）
   =========================== */
body.night-mode {
  --sky-color:        #0a0e2a;
  --sky-gradient:     linear-gradient(180deg, #060818 0%, #0a0e2a 40%, #0a1f0a 100%);
  --fog-color:        #0a1f0a;
  --ambient-light:    0.3;
  --bg-primary:       #0a1f0a;
  --bg-overlay:       rgba(10, 31, 10, 0.85);
  --text-primary:     rgba(255, 255, 255, 0.92);
  --text-secondary:   rgba(255, 255, 255, 0.65);
  --text-accent:      #4ade80;
  --particle-color:   #4ade80;
  --particle-glow:    rgba(74, 222, 128, 0.6);
  --glow-color:       rgba(74, 222, 128, 0.15);
  --surface-glass:    rgba(255, 255, 255, 0.04);
  --border-subtle:    rgba(255, 255, 255, 0.08);
}

/* ===========================
   白天模式
   =========================== */
body.day-mode {
  --sky-color:        #87CEEB;
  --sky-gradient:     linear-gradient(180deg, #5BA3D9 0%, #87CEEB 30%, #b8e6c8 70%, #2d8a4e 100%);
  --fog-color:        #c8e6c0;
  --ambient-light:    0.85;
  --bg-primary:       #f0f7ec;
  --bg-overlay:       rgba(240, 247, 236, 0.88);
  --text-primary:     rgba(10, 31, 10, 0.9);
  --text-secondary:   rgba(10, 31, 10, 0.6);
  --text-accent:      #1a6a30;
  --particle-color:   #f5e6a3;       /* 蒲公英/花粉色 */
  --particle-glow:    rgba(245, 230, 163, 0.5);
  --glow-color:       rgba(201, 168, 76, 0.2);
  --surface-glass:    rgba(255, 255, 255, 0.5);
  --border-subtle:    rgba(10, 31, 10, 0.1);
}

/* ===========================
   Body 基础样式
   =========================== */
body {
  font-family: var(--font-cn);
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 1.2s var(--ease-smooth),
              color 1.2s var(--ease-smooth);
}

/* ===========================
   滚动条美化
   =========================== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--c-emerald);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--c-neon-green);
}

/* Firefox */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--c-emerald) var(--bg-primary);
}

/* ===========================
   选中文字样式
   =========================== */
::selection {
  background: rgba(74, 222, 128, 0.25);
  color: #fff;
}

/* ===========================
   Preloader 容器
   =========================== */
#preloader {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #050a05;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: opacity 0.8s var(--ease-smooth);
}

#preloader.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* --- 种子容器 --- */
.preloader-scene {
  position: relative;
  width: 200px;
  height: 300px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

/* --- 种子 --- */
.seed {
  position: absolute;
  bottom: 140px;
  width: 16px;
  height: 22px;
  background: radial-gradient(ellipse at 40% 30%, #8B6914, #5a4310);
  border-radius: 45% 45% 50% 50%;
  animation: seedDrop 0.6s var(--ease-bounce) forwards;
  opacity: 0;
}

@keyframes seedDrop {
  0%   { transform: translateY(-120px); opacity: 0; }
  60%  { opacity: 1; }
  100% { transform: translateY(0); opacity: 1; }
}

/* --- 种子裂开 --- */
.seed-crack-left,
.seed-crack-right {
  position: absolute;
  bottom: 140px;
  width: 9px;
  height: 22px;
  opacity: 0;
}

.seed-crack-left {
  background: radial-gradient(ellipse at 80% 30%, #8B6914, #5a4310);
  border-radius: 50% 0 0 50%;
  animation: crackLeft 0.4s 0.7s var(--ease-smooth) forwards;
}

.seed-crack-right {
  background: radial-gradient(ellipse at 20% 30%, #8B6914, #5a4310);
  border-radius: 0 50% 50% 0;
  animation: crackRight 0.4s 0.7s var(--ease-smooth) forwards;
}

@keyframes crackLeft {
  0%   { transform: translateX(0) rotate(0); opacity: 1; }
  100% { transform: translateX(-10px) rotate(-15deg); opacity: 0.3; }
}

@keyframes crackRight {
  0%   { transform: translateX(0) rotate(0); opacity: 1; }
  100% { transform: translateX(10px) rotate(15deg); opacity: 0.3; }
}

/* --- 嫩芽 --- */
.sprout-stem {
  position: absolute;
  bottom: 150px;
  width: 3px;
  height: 0;
  background: linear-gradient(to top, #2d6a1e, #4ade80);
  border-radius: 2px;
  animation: stemGrow 0.8s 0.9s var(--ease-smooth) forwards;
  transform-origin: bottom center;
}

@keyframes stemGrow {
  0%   { height: 0; }
  100% { height: 80px; }
}

/* --- 叶片 --- */
.sprout-leaf {
  position: absolute;
  bottom: 220px;
  width: 20px;
  height: 12px;
  border-radius: 0 80% 0 80%;
  opacity: 0;
  transform-origin: 0% 100%;
}

.sprout-leaf--left {
  background: linear-gradient(135deg, #4ade80, #2d8a4e);
  right: calc(50% + 1px);
  animation: leafLeft 0.5s 1.5s var(--ease-bounce) forwards;
  transform: rotate(0deg) scale(0);
}

.sprout-leaf--right {
  background: linear-gradient(225deg, #4ade80, #2d8a4e);
  left: calc(50% + 1px);
  border-radius: 80% 0 80% 0;
  animation: leafRight 0.5s 1.7s var(--ease-bounce) forwards;
  transform: rotate(0deg) scale(0);
}

@keyframes leafLeft {
  0%   { transform: rotate(30deg) scale(0); opacity: 0; }
  100% { transform: rotate(-35deg) scale(1); opacity: 1; }
}

@keyframes leafRight {
  0%   { transform: rotate(-30deg) scale(0); opacity: 0; }
  100% { transform: rotate(35deg) scale(1); opacity: 1; }
}

/* --- 顶叶 --- */
.sprout-leaf--top {
  bottom: 232px;
  left: calc(50% - 7px);
  width: 14px;
  height: 20px;
  background: radial-gradient(ellipse at 50% 80%, #4ade80, #2d8a4e);
  border-radius: 50% 50% 40% 40%;
  opacity: 0;
  animation: leafTop 0.5s 1.6s var(--ease-bounce) forwards;
  transform: scale(0);
}

@keyframes leafTop {
  0%   { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* --- 光粒子散开 --- */
.preloader-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.preloader-particle {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--c-neon-green);
  box-shadow: 0 0 8px var(--c-neon-green), 0 0 16px rgba(74, 222, 128, 0.3);
  opacity: 0;
}

/* 粒子散开动画由 JS 动态设置 —— 这里定义基础关键帧 */
@keyframes particleBurst {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* --- Preloader 文字 --- */
.preloader-text {
  position: absolute;
  bottom: 80px;
  font-family: var(--font-cn);
  font-size: 0.85rem;
  color: rgba(74, 222, 128, 0.5);
  letter-spacing: 0.2em;
  opacity: 0;
  animation: preloaderTextIn 0.6s 0.4s ease forwards;
}

@keyframes preloaderTextIn {
  0%   { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ===========================
   音频切换按钮
   =========================== */
.audio-toggle {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--duration-normal) var(--ease-smooth);
  opacity: 0;
  animation: fadeInBtn 0.6s 3s ease forwards;
}

.audio-toggle:hover {
  background: rgba(74, 222, 128, 0.12);
  color: var(--c-neon-green);
  border-color: rgba(74, 222, 128, 0.3);
  transform: scale(1.08);
}

.audio-toggle.is-active {
  color: var(--c-neon-green);
  border-color: rgba(74, 222, 128, 0.3);
  box-shadow: 0 0 20px rgba(74, 222, 128, 0.15);
}

/* 播放状态呼吸动画 */
.audio-toggle.is-active::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px solid rgba(74, 222, 128, 0.2);
  animation: audioPulse 2s ease-in-out infinite;
}

@keyframes audioPulse {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50%      { transform: scale(1.15); opacity: 0; }
}

/* ===========================
   日夜切换按钮
   =========================== */
.mode-toggle {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all var(--duration-normal) var(--ease-smooth);
  opacity: 0;
  animation: fadeInBtn 0.6s 3.2s ease forwards;
  line-height: 1;
}

.mode-toggle:hover {
  transform: scale(1.1) rotate(15deg);
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--c-gold);
}

@keyframes fadeInBtn {
  0%   { opacity: 0; transform: scale(0.8); }
  100% { opacity: 1; transform: scale(1); }
}

/* ===========================
   通用动画工具类
   =========================== */
.fade-in-up {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity var(--duration-slow) var(--ease-smooth),
              transform var(--duration-slow) var(--ease-smooth);
}

.fade-in-up.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.fade-in {
  opacity: 0;
  transition: opacity var(--duration-slow) var(--ease-smooth);
}

.fade-in.is-visible {
  opacity: 1;
}

.scale-in {
  opacity: 0;
  transform: scale(0.9);
  transition: opacity var(--duration-slow) var(--ease-smooth),
              transform var(--duration-slow) var(--ease-bounce);
}

.scale-in.is-visible {
  opacity: 1;
  transform: scale(1);
}

/* 交错延迟 */
.stagger-1 { transition-delay: 0.1s; }
.stagger-2 { transition-delay: 0.2s; }
.stagger-3 { transition-delay: 0.3s; }
.stagger-4 { transition-delay: 0.4s; }
.stagger-5 { transition-delay: 0.5s; }

/* ===========================
   响应式断点
   =========================== */
@media (max-width: 768px) {
  .audio-toggle {
    top: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
  }

  .mode-toggle {
    bottom: 1rem;
    right: 1rem;
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  .preloader-scene {
    transform: scale(0.85);
  }
}

@media (max-width: 480px) {
  .audio-toggle {
    top: 0.75rem;
    right: 0.75rem;
    width: 38px;
    height: 38px;
  }

  .mode-toggle {
    bottom: 0.75rem;
    right: 0.75rem;
  }
}

/* ===========================
   白天模式下的滚动条
   =========================== */
body.day-mode::-webkit-scrollbar-track {
  background: #f0f7ec;
}

body.day-mode::-webkit-scrollbar-thumb {
  background: #2d8a4e;
}

body.day-mode::selection {
  background: rgba(45, 138, 78, 0.25);
  color: #0a1f0a;
}
