/* 全局变量与重置 */
:root {
  --primary: #5385aa;
  --primary-dark: #3e6a8a;
  --bg: #e3e3e3;
  --surface: #f2f2f2;
  --text: #333;
  --text-light: #666;
  --white: #fff;
  --shadow: rgba(0, 0, 0, 0.15);
  --radius: 8px;
  --transition: 0.3s ease;
  --reveal-duration: 0.8s;
  --reveal-offset: 60px;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: '仿宋', 'FangSong', 'STFangsong', 'Noto Serif SC', serif;
  line-height: 1.8;
  overflow-x: hidden;
}

/* 单页章节容器 */
.section {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 80px 20px 40px;
}

.section-title {
  width: 90%;
  max-width: 1200px;
  margin-bottom: 40px;
}

.section-title img {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px var(--shadow);
}

/* 图片容器 */
.image-container {
  width: 90%;
  max-width: 1100px;
  margin: 20px 0;
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 12px var(--shadow);
  background-color: var(--white);
}

.image-container img {
  width: 100%;
  height: auto;
  display: block;
  transition: transform var(--transition);
}

.image-container:hover img {
  transform: scale(1.02);
}

/* 文字容器 */
.text-container {
  background-color: var(--surface);
  width: 90%;
  max-width: 900px;
  padding: 28px 32px;
  border-radius: var(--radius);
  margin: 20px 0;
  font-size: 20px;
  line-height: 2;
  color: var(--text);
  box-shadow: 0 2px 8px var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}

.text-container:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px var(--shadow);
}

.text-container p {
  margin-bottom: 16px;
}

.text-container p:last-child {
  margin-bottom: 0;
}

/* 高亮文本 */
.highlight {
  background-color: var(--primary);
  color: var(--white);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}

/* Hover文字浮层 */
.hover-text {
  position: absolute;
  bottom: -500%;
  left: 50%;
  transform: translateX(-50%);
  width: 85%;
  max-width: 700px;
  background-color: rgba(0, 0, 0, 0.75);
  color: var(--white);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px 24px;
  border-radius: var(--radius);
  font-size: 18px;
  line-height: 1.8;
  transition: bottom 0.5s, opacity 0.5s;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
}

.image-container:hover .hover-text {
  bottom: 50%;
  opacity: 1;
  transition: bottom 0.5s, opacity 0.5s 0.3s;
}

/* 左侧固定导航 */
.sidebar {
  position: fixed;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  background-color: rgba(51, 51, 51, 0.9);
  padding: 12px 8px;
  border-radius: 0 16px 16px 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  backdrop-filter: blur(4px);
  transition: transform var(--transition);
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background-color: var(--primary);
  color: var(--white);
  border-radius: 50%;
  text-decoration: none;
  position: relative;
  transition: background-color var(--transition), transform var(--transition);
  font-size: 14px;
}

.nav-icon:hover {
  background-color: var(--primary-dark);
  transform: scale(1.1);
}

.nav-icon .icon-name {
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: var(--white);
  white-space: nowrap;
  background-color: rgba(0,0,0,0.7);
  padding: 2px 8px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}

.nav-icon:hover .icon-name {
  opacity: 1;
}

.nav-icon.active {
  background-color: var(--primary-dark);
  box-shadow: 0 0 0 3px rgba(83, 133, 170, 0.4);
}

/* 移动端汉堡菜单 */
.mobile-nav-toggle {
  display: none;
  position: fixed;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  background-color: rgba(51, 51, 51, 0.9);
  border-radius: 50%;
  z-index: 1001;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  border: none;
  backdrop-filter: blur(4px);
}

.mobile-nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background-color: var(--white);
  transition: all 0.3s;
}

.mobile-nav-toggle.open span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.mobile-nav-toggle.open span:nth-child(2) {
  opacity: 0;
}

.mobile-nav-toggle.open span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* 底部页脚 */
.footer {
  width: 100%;
  padding: 40px 20px;
  background-color: var(--primary);
  color: var(--white);
  text-align: center;
  font-size: 22px;
  line-height: 2;
}

.footer p {
  max-width: 900px;
  margin: 0 auto;
}

/* 回到顶部按钮 */
.back-to-top {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 48px;
  height: 48px;
  background-color: var(--primary);
  color: var(--white);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
  box-shadow: 0 4px 12px var(--shadow);
  transition: background-color var(--transition), transform var(--transition);
}

.back-to-top:hover {
  background-color: var(--primary-dark);
  transform: translateY(-3px);
}

.back-to-top.visible {
  display: flex;
}

/* 进度指示器 */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 4px;
  background-color: var(--primary);
  z-index: 1002;
  transition: width 0.1s;
}

/* ============================================================
   滚动动画：从下方滑入出现，向上滚出消失
   ============================================================ */

.scroll-reveal {
  opacity: 0;
  transform: translateY(var(--reveal-offset));
  transition: opacity var(--reveal-duration) cubic-bezier(0.25, 0.46, 0.45, 0.94),
              transform var(--reveal-duration) cubic-bezier(0.25, 0.46, 0.45, 0.94);
  will-change: opacity, transform;
}

/* 进入视口：从下方滑入 */
.scroll-reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* 离开视口（向上滚出）：向上滑出消失 */
.scroll-reveal.is-hidden {
  opacity: 0;
  transform: translateY(calc(var(--reveal-offset) * -1));
}

/* 延迟动画：为连续元素创造依次出现的效果 */
.scroll-reveal:nth-child(1) { transition-delay: 0s; }
.scroll-reveal:nth-child(2) { transition-delay: 0.08s; }
.scroll-reveal:nth-child(3) { transition-delay: 0.16s; }
.scroll-reveal:nth-child(4) { transition-delay: 0.24s; }
.scroll-reveal:nth-child(5) { transition-delay: 0.32s; }
.scroll-reveal:nth-child(6) { transition-delay: 0.40s; }
.scroll-reveal:nth-child(7) { transition-delay: 0.48s; }
.scroll-reveal:nth-child(8) { transition-delay: 0.56s; }

/* 响应式布局 */
@media (max-width: 768px) {
  .sidebar {
    transform: translateY(-50%) translateX(-120%);
    left: 0;
    top: 50%;
    padding: 16px;
    border-radius: 0 16px 16px 0;
  }

  .sidebar.open {
    transform: translateY(-50%) translateX(0);
  }

  .mobile-nav-toggle {
    display: flex;
  }

  .text-container {
    width: 95%;
    padding: 20px 18px;
    font-size: 17px;
    line-height: 1.8;
  }

  .image-container {
    width: 95%;
  }

  .hover-text {
    width: 90%;
    font-size: 15px;
    padding: 14px 16px;
  }

  .section {
    padding: 60px 12px 30px;
  }

  .footer {
    font-size: 18px;
    padding: 30px 16px;
  }

  .back-to-top {
    width: 40px;
    height: 40px;
    font-size: 16px;
    bottom: 20px;
    right: 20px;
  }

  .nav-icon {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 480px) {
  .text-container {
    font-size: 16px;
    padding: 16px 14px;
  }

  .hover-text {
    font-size: 14px;
  }

  .footer {
    font-size: 16px;
  }

  .scroll-reveal {
    --reveal-offset: 40px;
  }
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .scroll-reveal {
    transition: none;
    opacity: 1;
    transform: none;
  }

  .scroll-reveal.is-visible,
  .scroll-reveal.is-hidden {
    opacity: 1;
    transform: none;
  }

  .image-container img,
  .text-container,
  .nav-icon,
  .back-to-top {
    transition: none;
  }
}
