/* ==========================================================================
   答案之书 — 星界古籍 / 现代神秘美学 + 3D 翻书动效
   设计理念：深空背景、玻璃态卡片、真实 3D 翻页、粒子光效
   ========================================================================== */

:root {
  /* === 色彩系统 === */
  /* 深空背景层 */
  --space-900: #050508;
  --space-800: #0a0a12;
  --space-700: #11111a;

  /* 古籍材质色 */
  --leather-900: #1a0d06;
  --leather-800: #2a160c;
  --leather-700: #3d2214;
  --leather-600: #4a2c1a;
  --leather-highlight: #5d3a1e;

  /* 纸张色 */
  --paper-100: #fdfaf5;
  --paper-200: #f5efe3;
  --paper-300: #ede4d0;
  --paper-shadow: rgba(26,13,6,0.4);

  /* 烫金色 */
  --gold-500: #c8a040;
  --gold-400: #d4b05a;
  --gold-300: #e8c885;
  --gold-200: #f0dab8;
  --gold-100: #faf3e8;
  --gold-glow: rgba(212, 176, 90, 0.5);
  --gold-glow-strong: rgba(212, 176, 90, 0.85);

  /* 星界强调色 */
  --star-500: #6366f1;
  --star-400: #818cf8;
  --star-glow: rgba(99, 102, 241, 0.3);
  --void-500: #a855f7;
  --void-glow: rgba(168, 85, 247, 0.25);

  /* 文本 */
  --text-primary: #f5f0e8;
  --text-secondary: #d4c8b8;
  --text-muted: #9a8d7a;
  --text-on-gold: #1a1005;
  --text-ink: #1f1812;

  /* 玻璃态 */
  --glass-bg: rgba(17, 17, 26, 0.75);
  --glass-border: rgba(212, 176, 90, 0.12);
  --glass-border-hover: rgba(212, 176, 90, 0.3);
  --glass-shadow: 0 8px 32px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.02);

  /* 间距 */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* 圆角 */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;

  /* 过渡 */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 150ms;
  --duration-base: 300ms;
  --duration-slow: 500ms;
  --duration-slower: 800ms;

  /* 字体 */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Z-index */
  --z-bg: 0;
  --z-content: 10;
  --z-book: 20;
  --z-overlay: 100;
  --z-modal: 200;
  --z-toast: 300;

  /* 书本尺寸 */
  --book-width: 360px;
  --book-height: 480px;
  --book-thickness: 24px;
}

/* === 浅色模式（备用）=== */
@media (prefers-color-scheme: light) {
  :root {
    --space-900: #faf8f5;
    --space-800: #f0ebe3;
    --space-700: #e4ddd2;
    --text-primary: #1a1610;
    --text-secondary: #4a4235;
    --text-muted: #8b8272;
    --glass-bg: rgba(250, 248, 245, 0.85);
    --glass-border: rgba(200, 160, 64, 0.25);
    --glass-shadow: 0 8px 32px rgba(26,20,16,0.12), inset 0 1px 0 rgba(255,255,255,0.5);
    --leather-900: #3d2514;
    --leather-800: #4a2f1a;
    --paper-100: #fffef8;
    --paper-200: #faf7ed;
  }
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--space-900);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* === 背景氛围系统 === */
.bg-atmosphere {
  position: fixed;
  inset: 0;
  z-index: var(--z-bg);
  pointer-events: none;
  overflow: hidden;
}

.bg-atmosphere::before {
  content: '';
  position: absolute;
  inset: -50%;
  background:
    radial-gradient(ellipse 80% 60% at 50% 20%, rgba(99,102,241,0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 80% at 80% 80%, rgba(168,85,247,0.04) 0%, transparent 50%),
    radial-gradient(ellipse 100% 100% at 20% 50%, rgba(212,176,90,0.03) 0%, transparent 40%),
    var(--space-900);
  animation: bg-breathe 25s ease-in-out infinite alternate;
}

@keyframes bg-breathe {
  0% { transform: scale(1) rotate(0deg); opacity: 1; }
  100% { transform: scale(1.015) rotate(0.3deg); opacity: 0.95; }
}

/* 极光流体 */
.aurora {
  position: absolute;
  border-radius: 50%;
  filter: blur(140px);
  opacity: 0.35;
  animation: aurora-drift 18s ease-in-out infinite alternate;
}
.aurora-1 { width: 450px; height: 450px; top: -120px; left: -120px; background: radial-gradient(circle, var(--gold-400) 0%, transparent 70%); animation-delay: 0s; }
.aurora-2 { width: 350px; height: 350px; bottom: -80px; right: -80px; background: radial-gradient(circle, var(--star-500) 0%, transparent 70%); animation-delay: -6s; }
.aurora-3 { width: 280px; height: 280px; top: 35%; left: 55%; background: radial-gradient(circle, var(--void-500) 0%, transparent 70%); animation-delay: -12s; }

@keyframes aurora-drift {
  0% { transform: translate(0, 0) scale(1) rotate(0deg); }
  33% { transform: translate(40px, -30px) scale(1.03) rotate(1deg); }
  66% { transform: translate(-30px, 40px) scale(0.97) rotate(-1deg); }
  100% { transform: translate(0, 0) scale(1) rotate(0deg); }
}

/* 星尘 */
.starfield {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 20% 30%, var(--gold-300), transparent),
    radial-gradient(1.5px 1.5px at 80% 70%, var(--star-400), transparent),
    radial-gradient(1px 1px at 40% 80%, var(--gold-200), transparent),
    radial-gradient(1px 1px at 90% 20%, var(--star-400), transparent),
    radial-gradient(1.5px 1.5px at 60% 40%, var(--void-500), transparent),
    radial-gradient(2px 2px at 10% 90%, var(--gold-300), transparent),
    radial-gradient(1px 1px at 70% 10%, var(--star-400), transparent);
  background-repeat: repeat;
  background-size: 700px 700px;
  animation: starfield-drift 80s linear infinite;
  opacity: 0.25;
}

@keyframes starfield-drift {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(-700px, -700px) rotate(360deg); }
}

/* 细微网格纹理 */
.bg-atmosphere::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(212,176,90,0.012) 1px, transparent 1px),
    linear-gradient(90deg, rgba(212,176,90,0.012) 1px, transparent 1px);
  background-size: 70px 70px;
  mask-image: radial-gradient(ellipse at center, black 35%, transparent 85%);
}

/* === 布局容器 === */
.book-page {
  position: relative;
  z-index: var(--z-content);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl) var(--space-lg);
}

.book-page--share {
  min-height: auto;
  padding-bottom: var(--space-3xl);
}

/* === 通用玻璃卡片 === */
.glass-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  transition: border-color var(--duration-base) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out),
              transform var(--duration-base) var(--ease-out);
}
.glass-card:hover {
  border-color: var(--glass-border-hover);
  box-shadow: var(--glass-shadow), 0 0 40px rgba(212,176,90,0.06);
}

/* === 标题系统 === */
.book-header { text-align: center; margin-bottom: var(--space-2xl); opacity: 0; transform: translateY(20px); animation: fade-in-up var(--duration-slower) var(--ease-out) forwards; animation-delay: 100ms; }

.book-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.2;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--gold-300) 50%, var(--text-primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-fill-color: transparent;
  margin-bottom: var(--space-sm);
}

.book-subtitle {
  font-size: clamp(0.95rem, 2vw, 1.15rem);
  color: var(--text-muted);
  font-weight: 300;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* === 状态容器 === */
.book-state {
  width: 100%;
  max-width: 600px;
  opacity: 0;
  visibility: hidden;
  position: absolute;
  transition: opacity var(--duration-base) var(--ease-out), visibility var(--duration-base) var(--ease-out);
}
.book-state.active {
  opacity: 1;
  visibility: visible;
  position: relative;
}

/* ==========================================================================
   状态 1：提问界面
   ========================================================================== */
.state-input { animation: fade-in-up var(--duration-slower) var(--ease-out) forwards; animation-delay: 200ms; }

.input-card {
  padding: var(--space-2xl);
  max-width: 480px;
  margin: 0 auto;
}

.input-field { position: relative; margin-bottom: var(--space-xl); }

.input-field label {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.question-textarea {
  width: 100%; min-height: 140px; padding: var(--space-lg);
  border: 1px solid var(--glass-border); border-radius: var(--radius-md);
  background: rgba(10,10,18,0.6); color: var(--text-primary);
  font-family: var(--font-ui); font-size: 1.05rem; line-height: 1.7;
  resize: vertical; outline: none;
  transition: border-color var(--duration-base) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out),
              background-color var(--duration-base) var(--ease-out);
}
.question-textarea::placeholder { color: var(--text-muted); opacity: 0.6; }
.question-textarea:focus {
  border-color: var(--gold-400);
  box-shadow: 0 0 0 3px rgba(212,176,90,0.15), inset 0 0 0 1px var(--gold-400);
  background: rgba(10,10,18,0.9);
}
.question-textarea:focus::placeholder { opacity: 0.3; }

.input-hint {
  display: flex; align-items: center; justify-content: center; gap: var(--space-sm);
  margin-top: var(--space-md); font-size: 0.85rem; color: var(--text-muted);
}
.hint-icon { width: 18px; height: 18px; opacity: 0.4; animation: hint-pulse 2.5s ease-in-out infinite; }
@keyframes hint-pulse { 0%,100% { opacity: 0.3; transform: scale(1); } 50% { opacity: 0.6; transform: scale(1.1); } }

/* 提交按钮 */
.btn-ask {
  width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-md);
  padding: var(--space-md) var(--space-xl);
  border: none; border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--gold-400) 0%, var(--gold-500) 100%);
  color: var(--text-on-gold);
  font-family: var(--font-ui); font-size: 1.05rem; font-weight: 600; letter-spacing: 0.02em;
  cursor: pointer; position: relative; overflow: hidden;
  box-shadow: 0 4px 20px rgba(212,176,90,0.35), inset 0 1px 0 rgba(255,255,255,0.2);
  transition: transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out);
}
.btn-ask::before { content: ''; position: absolute; inset: 0; background: linear-gradient(135deg, var(--gold-300) 0%, var(--gold-400) 100%); opacity: 0; transition: opacity var(--duration-base) var(--ease-out); }
.btn-ask:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(212,176,90,0.5), inset 0 1px 0 rgba(255,255,255,0.25); }
.btn-ask:hover::before { opacity: 1; }
.btn-ask:active { transform: translateY(0) scale(0.99); }
.btn-ask:focus-visible { outline: 2px solid var(--gold-300); outline-offset: 3px; }
.btn-ask:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: 0 4px 20px rgba(212,176,90,0.2); }
.btn-ask span:first-child { position: relative; z-index: 1; }
.btn-ask .btn-icon { position: relative; z-index: 1; transition: transform var(--duration-base) var(--ease-spring); }
.btn-ask:hover .btn-icon { transform: translateX(4px); }

.disclaimer { text-align: center; margin-top: var(--space-xl); font-size: 0.8rem; color: var(--text-muted); opacity: 0.7; }

/* ==========================================================================
   状态 2：3D 翻书动效
   ========================================================================== */
.state-flipping {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-xl);
  padding: var(--space-lg);
  min-height: 560px;
}

.flipping-stage {
  perspective: 1600px;
  perspective-origin: center center;
  width: var(--book-width);
  height: var(--book-height);
  position: relative;
  z-index: var(--z-book);
  filter: drop-shadow(0 40px 80px rgba(0,0,0,0.6)) drop-shadow(0 0 120px rgba(212,176,90,0.15));
}

/* === 3D 书本结构 === */
.book-3d {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform-origin: center center;
}

/* 书脊厚度侧面 */
.book-spine {
  position: absolute;
  left: 50%; top: 0;
  width: var(--book-thickness);
  height: 100%;
  margin-left: calc(var(--book-thickness) / -2);
  transform-origin: left center;
  transform: rotateY(-90deg) translateZ(calc(var(--book-thickness) / -2));
  background: linear-gradient(180deg, var(--leather-900) 0%, var(--leather-800) 50%, var(--leather-900) 100%);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  box-shadow:
    inset 0 0 30px rgba(0,0,0,0.5),
    inset 2px 0 0 rgba(212,176,90,0.1),
    -10px 0 30px rgba(0,0,0,0.4);
  z-index: 1;
}

/* 烫金条 - 书脊 */
.book-spine::before,
.book-spine::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold-400), transparent);
  opacity: 0.6;
}
.book-spine::before { top: 25%; }
.book-spine::after { bottom: 25%; }

/* 封面、书页通用 */
.book-cover,
.book-page-side {
  position: absolute;
  top: 0; left: 0;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  backface-visibility: hidden;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  box-shadow:
    inset 0 0 60px rgba(0,0,0,0.3),
    0 20px 60px rgba(0,0,0,0.5);
}

/* === 前封面 === */
.cover-front {
  z-index: 4;
  transform: rotateY(0deg);
  background:
    linear-gradient(145deg, var(--leather-900) 0%, var(--leather-800) 40%, var(--leather-700) 60%, var(--leather-800) 100%),
    radial-gradient(ellipse at 30% 30%, rgba(212,176,90,0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 70%, rgba(26,13,6,0.3) 0%, transparent 40%);
  border: 1px solid rgba(212,176,90,0.1);
}

/* 封面装饰：烫金边框 */
.cover-front::before {
  content: '';
  position: absolute;
  inset: var(--space-xl);
  border: 1px solid var(--gold-500);
  border-radius: var(--radius-sm);
  opacity: 0.4;
  pointer-events: none;
}

/* 封面标题 */
.cover-title {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: 0.15em;
  color: var(--gold-400);
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  white-space: nowrap;
  pointer-events: none;
}

/* 装饰线 */
.cover-line {
  position: absolute;
  left: 20%; right: 20%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-500), transparent);
  opacity: 0.3;
}
.cover-line:nth-child(1) { top: 30%; }
.cover-line:nth-child(2) { top: 50%; }
.cover-line:nth-child(3) { top: 70%; }

/* === 左页 === */
.page-left {
  z-index: 3;
  transform: rotateY(0deg);
  background:
    linear-gradient(90deg, var(--paper-100) 0%, var(--paper-200) 50%, var(--paper-300) 100%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 28px,
      rgba(212,176,90,0.02) 28px,
      rgba(212,176,90,0.02) 29px
    );
  box-shadow:
    inset 0 0 40px rgba(26,13,6,0.1),
    inset -2px 0 8px rgba(0,0,0,0.1),
    4px 0 20px rgba(0,0,0,0.3);
}

/* 左页页码/纹理 */
.page-left::after {
  content: '';
  position: absolute;
  bottom: var(--space-xl);
  left: var(--space-xl);
  width: 30px; height: 30px;
  border: 1px solid var(--gold-500);
  border-radius: 50%;
  opacity: 0.15;
  pointer-events: none;
}

/* === 右页 === */
.page-right {
  left: 50%;
  width: 50%;
  transform-origin: right center;
  z-index: 2;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background:
    linear-gradient(-90deg, var(--paper-100) 0%, var(--paper-200) 50%, var(--paper-300) 100%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 28px,
      rgba(212,176,90,0.02) 28px,
      rgba(212,176,90,0.02) 29px
    );
  box-shadow:
    inset 0 0 40px rgba(26,13,6,0.1),
    inset 2px 0 8px rgba(0,0,0,0.1),
    -4px 0 20px rgba(0,0,0,0.3);
}

/* 右页装饰 */
.page-right::before {
  content: '';
  position: absolute;
  bottom: var(--space-xl);
  right: var(--space-xl);
  width: 30px; height: 30px;
  border: 1px solid var(--gold-500);
  border-radius: 50%;
  opacity: 0.15;
  pointer-events: none;
}

/* === 后封面 === */
.cover-back {
  left: 50%;
  width: 50%;
  transform-origin: right center;
  z-index: 1;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background:
    linear-gradient(145deg, var(--leather-900) 0%, var(--leather-800) 40%, var(--leather-700) 60%, var(--leather-800) 100%),
    radial-gradient(ellipse at 30% 30%, rgba(26,13,6,0.3) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 70%, rgba(212,176,90,0.08) 0%, transparent 50%);
  border: 1px solid rgba(212,176,90,0.1);
}

/* 后封面烫金边框 */
.cover-back::before {
  content: '';
  position: absolute;
  inset: var(--space-xl);
  border: 1px solid var(--gold-500);
  border-radius: var(--radius-sm);
  opacity: 0.3;
  pointer-events: none;
}

/* ==========================================================================
   翻页关键帧动画
   ========================================================================== */

/* === 翻页动画：由父级 .state-flipping.active 触发，不依赖 JS 加类 === */

.state-flipping.active .book-3d {
  animation: flip-cycle 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

/* 整体书本微微呼吸 */
@keyframes flip-cycle {
  0% {
    transform: rotateY(0deg) translateZ(0);
  }
  18% {
    transform: rotateY(-8deg) translateZ(20px);
  }
  35% {
    transform: rotateY(-90deg) translateZ(40px);
  }
  50% {
    transform: rotateY(-180deg) translateZ(30px);
  }
  65% {
    transform: rotateY(-270deg) translateZ(20px);
  }
  82% {
    transform: rotateY(-352deg) translateZ(10px);
  }
  100% {
    transform: rotateY(-360deg) translateZ(0);
  }
}

/* 封面翻页：正常跟随 */
.state-flipping.active .cover-front {
  animation: flip-cover-front 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  transform-origin: left center;
}

@keyframes flip-cover-front {
  0%, 100% { transform: rotateY(0deg); z-index: 4; }
  18% { transform: rotateY(-8deg); z-index: 4; }
  35% { transform: rotateY(-90deg); z-index: 2; }
  50% { transform: rotateY(-180deg); z-index: 1; }
  65% { transform: rotateY(-270deg); z-index: 2; }
  82% { transform: rotateY(-352deg); z-index: 4; }
}

/* 左页：前半程跟随封面，后半程归位 */
.state-flipping.active .page-left {
  animation: flip-page-left 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  transform-origin: left center;
}

@keyframes flip-page-left {
  0%, 100% { transform: rotateY(0deg); z-index: 3; }
  18% { transform: rotateY(-8deg); z-index: 3; }
  35% { transform: rotateY(-90deg); z-index: 2; }
  50% { transform: rotateY(-180deg); z-index: 2; }
  65% { transform: rotateY(-270deg); z-index: 3; }
  82% { transform: rotateY(-352deg); z-index: 3; }
}

/* 右页：前半程隐藏，后半程翻出 */
.state-flipping.active .page-right {
  animation: flip-page-right 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  transform-origin: right center;
}

@keyframes flip-page-right {
  0%, 100% { transform: rotateY(0deg); z-index: 2; }
  18% { transform: rotateY(0deg); z-index: 1; }
  35% { transform: rotateY(0deg); z-index: 1; }
  50% { transform: rotateY(-180deg); z-index: 3; }
  65% { transform: rotateY(-270deg); z-index: 4; }
  82% { transform: rotateY(-352deg); z-index: 2; }
}

/* 后封面：反向 */
.state-flipping.active .cover-back {
  animation: flip-cover-back 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  transform-origin: right center;
}

@keyframes flip-cover-back {
  0%, 100% { transform: rotateY(0deg); z-index: 1; }
  18% { transform: rotateY(8deg); z-index: 1; }
  35% { transform: rotateY(90deg); z-index: 3; }
  50% { transform: rotateY(180deg); z-index: 4; }
  65% { transform: rotateY(270deg); z-index: 3; }
  82% { transform: rotateY(352deg); z-index: 1; }
}

/* 书脊：跟随整体 */
.state-flipping.active .book-spine {
  animation: flip-spine 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes flip-spine {
  0%, 100% { transform: rotateY(-90deg) translateZ(calc(var(--book-thickness) / -2)); }
  50% { transform: rotateY(-270deg) translateZ(calc(var(--book-thickness) / -2)); }
}

/* 兼容：保留 .flipping 类触发方式 */
.book-3d.flipping {
  animation: flip-cycle 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
.book-3d.flipping .cover-front {
  animation: flip-cover-front 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  transform-origin: left center;
}
.book-3d.flipping .page-left {
  animation: flip-page-left 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  transform-origin: left center;
}
.book-3d.flipping .page-right {
  animation: flip-page-right 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  transform-origin: right center;
}
.book-3d.flipping .cover-back {
  animation: flip-cover-back 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  transform-origin: right center;
}
.book-3d.flipping .book-spine {
  animation: flip-spine 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

/* ==========================================================================
   翻页提示与静音
   ========================================================================== */
.flipping-hint {
  display: flex; align-items: center; gap: var(--space-sm);
  font-size: 0.85rem; color: var(--text-muted);
  margin-top: var(--space-lg);
  animation: hint-fade 2s ease-in-out infinite alternate;
}
@keyframes hint-fade { 0% { opacity: 0.4; } 100% { opacity: 0.9; } }

.btn-mute {
  position: fixed; top: var(--space-lg); right: var(--space-lg);
  z-index: var(--z-overlay);
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--glass-border); border-radius: var(--radius-full);
  background: var(--glass-bg); color: var(--text-secondary);
  cursor: pointer; backdrop-filter: blur(10px);
  transition: all var(--duration-base) var(--ease-out);
}
.btn-mute:hover { border-color: var(--gold-400); background: rgba(212,176,90,0.1); color: var(--gold-300); transform: scale(1.05); }
.btn-mute:focus-visible { outline: 2px solid var(--gold-300); outline-offset: 2px; }
.btn-mute svg { width: 22px; height: 22px; }
.btn-mute .icon-sound-off { display: none; }
.btn-mute[aria-pressed="true"] .icon-sound-on { display: none; }
.btn-mute[aria-pressed="true"] .icon-sound-off { display: block; }

/* ==========================================================================
   状态 3：答案揭晓
   ========================================================================== */
.state-reveal {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-xl);
  padding: var(--space-lg);
  max-width: 640px;
  animation: reveal-enter var(--duration-slower) var(--ease-out) forwards;
}

@keyframes reveal-enter {
  0% { opacity: 0; transform: translateY(40px) scale(0.96); }
  55% { opacity: 1; transform: translateY(-10px) scale(1.015); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* 打开的书本展示 */
.reveal-book {
  perspective: 1400px;
  perspective-origin: center center;
  width: var(--book-width);
  height: var(--book-height);
  margin-bottom: var(--space-lg);
  filter: drop-shadow(0 30px 60px rgba(0,0,0,0.5)) drop-shadow(0 0 80px rgba(212,176,90,0.12));
}

.reveal-book .book-3d {
  transform: rotateY(-18deg) translateZ(10px);
  animation: reveal-book-settle 1.2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes reveal-book-settle {
  0% { transform: rotateY(-180deg) translateZ(40px) scale(0.9); opacity: 0; }
  60% { transform: rotateY(-15deg) translateZ(20px) scale(1.03); opacity: 1; }
  100% { transform: rotateY(-18deg) translateZ(10px) scale(1); opacity: 1; }
}

/* 揭晓态的页面内容 */
.reveal-book .cover-front { transform: rotateY(-18deg); z-index: 4; }
.reveal-book .page-left { transform: rotateY(-18deg); z-index: 3; }
.reveal-book .page-right { transform: rotateY(-18deg); z-index: 2; }
.reveal-book .cover-back { transform: rotateY(-18deg); z-index: 1; }
.reveal-book .book-spine { transform: rotateY(-108deg) translateZ(calc(var(--book-thickness) / -2)); z-index: 2; }

/* 答案卡片 */
.answer-card {
  width: 100%; max-width: 640px;
  padding: var(--space-2xl) var(--space-xl);
  position: relative; overflow: hidden;
  animation: card-reveal var(--duration-slower) var(--ease-out) forwards;
  animation-delay: 300ms;
}

@keyframes card-reveal {
  0% { opacity: 0; transform: translateY(30px) scale(0.98); }
  60% { opacity: 1; transform: translateY(-8px) scale(1.01); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.answer-card::before {
  content: ''; position: absolute; inset: -60%;
  background: radial-gradient(ellipse at center, rgba(212,176,90,0.1) 0%, transparent 60%);
  pointer-events: none;
  animation: answer-glow 5s ease-in-out infinite alternate;
}
@keyframes answer-glow {
  0% { opacity: 0.4; transform: scale(1); }
  100% { opacity: 0.9; transform: scale(1.15); }
}

/* 答案文本 */
.answer-quote {
  position: relative; z-index: 1;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  font-weight: 300;
  line-height: 1.55;
  text-align: center;
  color: var(--text-primary);
  letter-spacing: 0.01em;
  margin-bottom: var(--space-xl);
  opacity: 0; transform: translateY(25px) scale(0.95);
  animation: quote-reveal var(--duration-slower) var(--ease-out) forwards;
  animation-delay: 400ms;
}

@keyframes quote-reveal {
  0% { opacity: 0; transform: translateY(25px) scale(0.95); }
  55% { opacity: 1; transform: translateY(-6px) scale(1.02); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* 装饰分隔线 */
.answer-divider {
  position: relative; z-index: 1;
  width: 100%; max-width: 240px; height: 1px;
  margin: 0 auto var(--space-xl);
  background: linear-gradient(90deg, transparent, var(--gold-400), transparent);
  opacity: 0; animation: divider-reveal var(--duration-slow) var(--ease-out) forwards;
  animation-delay: 600ms;
}
@keyframes divider-reveal {
  0% { opacity: 0; transform: scaleX(0); }
  100% { opacity: 1; transform: scaleX(1); }
}

/* 原始问题回显 */
.answer-question {
  position: relative; z-index: 1;
  text-align: center;
  font-size: 0.9rem; color: var(--text-muted);
  font-style: italic;
  padding-top: var(--space-lg);
  border-top: 1px dashed var(--glass-border);
  opacity: 0; animation: fade-in-up var(--duration-slow) var(--ease-out) forwards;
  animation-delay: 800ms;
}

/* 粒子爆发 */
.particle-burst {
  position: absolute; inset: 0; pointer-events: none; z-index: 10;
}
.particle-burst span {
  position: absolute; width: 8px; height: 8px; border-radius: 50%;
  background: var(--gold-300); box-shadow: 0 0 15px var(--gold-glow);
  opacity: 0; transform: translate(-50%, -50%) scale(0);
  animation: particle-explode 1s cubic-bezier(0, 0, 0.2, 1) forwards;
}
@keyframes particle-explode {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) translate(var(--tx), var(--ty)) scale(0.3); }
}

/* 操作按钮组 */
.actions { display: flex; flex-wrap: wrap; gap: var(--space-md); justify-content: center; width: 100%; max-width: 520px; margin-top: var(--space-lg); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-sm);
  padding: var(--space-md) var(--space-xl);
  border-radius: var(--radius-full);
  font-family: var(--font-ui);
  font-size: 0.95rem; font-weight: 600; letter-spacing: 0.01em;
  cursor: pointer; transition: all var(--duration-base) var(--ease-out);
  flex: 1; min-width: 150px;
}
.btn:focus-visible { outline: 2px solid var(--gold-300); outline-offset: 3px; }

.btn-primary {
  border: none;
  background: linear-gradient(135deg, var(--gold-400) 0%, var(--gold-500) 100%);
  color: var(--text-on-gold);
  box-shadow: 0 4px 20px rgba(212,176,90,0.35), inset 0 1px 0 rgba(255,255,255,0.2);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(212,176,90,0.5), inset 0 1px 0 rgba(255,255,255,0.25); }
.btn-primary:active { transform: translateY(0) scale(0.99); }

.btn-secondary {
  border: 1px solid var(--glass-border);
  background: var(--glass-bg); color: var(--text-secondary);
  backdrop-filter: blur(10px);
}
.btn-secondary:hover { border-color: var(--gold-400); color: var(--gold-300); background: rgba(212,176,90,0.08); transform: translateY(-2px); }
.btn-secondary:active { transform: translateY(0) scale(0.99); }
.btn-secondary.copied { border-color: var(--gold-400); background: linear-gradient(135deg, var(--gold-400) 0%, var(--gold-500) 100%); color: var(--text-on-gold); }

/* ==========================================================================
   分享页
   ========================================================================== */
.share-header { animation: fade-in-up var(--duration-slower) var(--ease-out) forwards; animation-delay: 100ms; }

.share-book { perspective: 1200px; perspective-origin: center center; margin-bottom: var(--space-xl); }

.share-book .book-3d {
  width: 320px; height: 420px;
  margin: 0 auto;
  transform: rotateY(-20deg);
  filter: drop-shadow(0 20px 40px rgba(0,0,0,0.4)) drop-shadow(0 0 60px rgba(212,176,90,0.1));
}

.share-book .cover-front { transform: rotateY(-20deg); }
.share-book .page-left { transform: rotateY(-20deg); }
.share-book .page-right { transform: rotateY(-20deg); }
.share-book .cover-back { transform: rotateY(-20deg); }
.share-book .book-spine { transform: rotateY(-110deg) translateZ(calc(var(--book-thickness) / -2)); }

.share-answer { text-align: center; max-width: 640px; margin: 0 auto var(--space-2xl); }
.share-answer .answer-quote { font-size: clamp(1.35rem, 3.5vw, 1.85rem); animation-delay: 100ms; }

.share-meta {
  display: flex; align-items: center; justify-content: center; gap: var(--space-lg);
  font-size: 0.8rem; color: var(--text-muted);
  padding-top: var(--space-lg); border-top: 1px dashed var(--glass-border);
}

.share-actions { animation: fade-in-up var(--duration-slow) var(--ease-out) forwards; animation-delay: 300ms; }

/* === 动画工具 === */
@keyframes fade-in-up {
  0% { opacity: 0; transform: translateY(20px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* === 响应式 === */
@media (max-width: 480px) {
  :root {
    --book-width: 300px;
    --book-height: 400px;
    --book-thickness: 20px;
    --space-xl: 24px;
    --space-2xl: 32px;
  }
  .book-page { padding: var(--space-lg) var(--space-md); }
  .input-card { padding: var(--space-xl) var(--space-md); }
  .actions { flex-direction: column; }
  .btn { width: 100%; }
  .flipping-stage { width: 100%; height: auto; }
}

@media (max-width: 390px) {
  :root { --space-lg: 16px; --space-xl: 20px; }
  .question-textarea { min-height: 120px; font-size: 1rem; }
}

/* === 减弱动画 === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .bg-atmosphere::before { animation: none; }
  .aurora { animation: none; opacity: 0.15; }
  .starfield { animation: none; }
  .book-3d.flipping { animation: none !important; transform: rotateY(0deg) !important; }
  .book-3d.flipping .cover-front,
  .book-3d.flipping .page-left,
  .book-3d.flipping .page-right,
  .book-3d.flipping .cover-back,
  .book-3d.flipping .book-spine { animation: none !important; transform: none !important; }
  .reveal-book .book-3d { animation: none !important; transform: rotateY(-18deg) translateZ(10px) !important; opacity: 1 !important; }
  .particle-burst span { animation: none !important; opacity: 0 !important; }
  .flipping-hint { animation: none !important; opacity: 0.8 !important; }
  .answer-quote { animation: none !important; opacity: 1 !important; transform: none !important; }
  .answer-divider { animation: none !important; opacity: 1 !important; transform: scaleX(1) !important; }
}

/* === 打印样式 === */
@media print {
  .bg-atmosphere, .aurora, .starfield, .btn-mute, .flipping-hint, .actions, .state-flipping { display: none !important; }
  .book-state { opacity: 1 !important; visibility: visible !important; position: relative !important; }
  .answer-quote { animation: none !important; opacity: 1 !important; transform: none !important; color: #000 !important; -webkit-text-fill-color: #000 !important; }
  body { background: #fff !important; color: #000 !important; }
  .glass-card { border: 1px solid #ccc !important; box-shadow: none !important; background: #fff !important; }
}