/* ============================================
   StoryEngine v1.0 — 数据驱动故事引擎基础样式
   每个故事通过 theme.css 覆盖颜色变量
   ============================================ */

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

/* 每个故事在 theme.css 中定义这些变量 */
:root {
  --story-bg: #0f0f2e;
  --story-primary: #ffd700;
  --story-accent: #7b68ee;
  --story-gradient: linear-gradient(180deg, #0a0a2e, #1a1a3e);
  --story-card-bg: rgba(123, 104, 238, 0.12);
  --story-text: #f0e6ff;
  --story-text-secondary: rgba(240, 230, 255, 0.65);
  --story-glow: 0 0 30px rgba(255, 215, 0, 0.3);
  --white: #ffffff;
  --white-95: rgba(255,255,255,0.95);
  --white-90: rgba(255,255,255,0.9);
  --white-70: rgba(255,255,255,0.7);
  --white-30: rgba(255,255,255,0.3);
  --white-10: rgba(255,255,255,0.1);
  --radius-xl: 28px;
  --radius-lg: 18px;
  --radius-md: 12px;
}

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--story-bg);
  color: var(--story-text);
  overflow: hidden;
  height: 100vh; height: 100dvh;
  width: 100vw; width: 100dvw;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ===== 场景容器 ===== */
.scene {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
}
.scene.active { display: flex; }

/* ===== 动画区（上 65%）===== */
.anim-zone {
  position: relative;
  flex: 0 0 65%;
  overflow: hidden;
  background: var(--story-gradient);
}
.anim-zone canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

/* 场景插画（黄金标准故事可选） */
.scene-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  z-index: 1;
  opacity: 0.92;
}
.anim-zone.has-scene-image canvas {
  opacity: 0.35;
}
.anim-zone.has-scene-image .role-badge {
  z-index: 12;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 50%;
  padding: 4px 8px;
}

/* 角色 Emoji */
.role-badge {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(36px, 9vw, 52px);
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5));
  z-index: 10;
  animation: gentleFloat 3s ease-in-out infinite;
}
@keyframes gentleFloat {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%      { transform: translateX(-50%) translateY(-8px); }
}

/* ===== 家长讲解层 ===== */
.parent-hint {
  margin: 6px 0 4px;
  text-align: left;
}
.parent-hint-toggle {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 9999px;
  color: var(--story-text-secondary);
  font-size: 12px;
  padding: 4px 12px;
  cursor: pointer;
  font-family: inherit;
}
.parent-hint-text {
  display: none;
  margin-top: 8px;
  padding: 10px 12px;
  background: rgba(255, 179, 71, 0.1);
  border-left: 3px solid rgba(255, 179, 71, 0.4);
  border-radius: 0 8px 8px 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--story-text-secondary);
}
.parent-hint.open .parent-hint-text {
  display: block;
}

/* ===== 文字区（下 35%）===== */
.text-zone {
  flex: 0 0 35%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 20px calc(10px + env(safe-area-inset-bottom, 0));
  background: linear-gradient(180deg, rgba(15,15,46,0) 0%, rgba(15,15,46,0.95) 18%);
  gap: 8px;
  text-align: center;
  z-index: 5;
}

.text-zone.enter {
  animation: textSlideIn 0.4s ease-out;
}
@keyframes textSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== 标题 ===== */
.main-title {
  font-size: clamp(28px, 7vw, 38px);
  font-weight: 900;
  text-shadow: 0 3px 15px rgba(0,0,0,0.5);
  line-height: 1.3;
  letter-spacing: 2px;
}
.subtitle {
  font-size: clamp(13px, 3.5vw, 16px);
  color: var(--story-text-secondary);
  opacity: 0.9;
}

/* ===== 核心台词 ===== */
.caption {
  font-size: clamp(14px, 3.8vw, 18px);
  line-height: 1.75;
  color: var(--white-95);
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  max-width: 420px;
}
.caption strong { color: var(--story-primary); }

/* ===== 分支标题 ===== */
.branch-label {
  font-size: clamp(13px, 3.2vw, 15px);
  font-weight: 600;
  color: var(--story-primary);
  letter-spacing: 1px;
  opacity: 0.85;
}

/* ===== 步骤圆点 ===== */
.step-dots {
  display: flex;
  gap: 7px;
}
.step-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--white-30);
  transition: all 0.3s ease;
}
.step-dot.active { background: var(--story-primary); transform: scale(1.4); }
.step-dot.done   { background: var(--story-accent); }

/* ===== 按钮系统 ===== */
.btn-primary {
  background: linear-gradient(135deg, var(--story-primary), var(--story-accent));
  color: var(--white);
  border: none;
  border-radius: var(--radius-xl);
  padding: 14px 32px;
  font-size: clamp(15px, 4vw, 18px);
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--story-glow);
  transition: all 300ms ease;
  min-height: 48px;
  letter-spacing: 1px;
}
.btn-primary:hover, .btn-primary:active {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(255, 215, 0, 0.45);
}
.btn-primary:active { transform: translateY(0); }

.btn-back {
  background: rgba(255,255,255,0.08);
  border: 1.5px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-md);
  padding: 10px 22px;
  color: var(--white-70);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 150ms ease;
  min-height: 40px;
}
.btn-back:hover { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.35); }

.btn-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===== 决策选项 ===== */
.decision-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 340px;
  align-items: center;
}
.decision-question {
  font-size: clamp(15px, 4vw, 18px);
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
  line-height: 1.5;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.choice-btn {
  width: 100%;
  max-width: 340px;
  padding: 14px 18px;
  background: var(--story-card-bg);
  border: 2px solid rgba(255, 215, 0, 0.3);
  border-radius: var(--radius-lg);
  color: var(--white);
  cursor: pointer;
  transition: all 300ms ease;
  text-align: left;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.choice-btn:hover, .choice-btn:active {
  border-color: var(--story-primary);
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
  transform: translateY(-1px);
}
.choice-icon { font-size: 28px; flex-shrink: 0; }
.choice-text { flex: 1; }
.choice-title { font-size: 15px; font-weight: 700; }
.choice-desc { font-size: 12px; color: var(--white-70); margin-top: 2px; }

/* ===== 确认弹窗 ===== */
.confirm-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 10, 46, 0.95);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  flex-direction: column;
}
.confirm-overlay.active { display: flex; }
.confirm-card {
  text-align: center;
  padding: 28px 24px;
  border: 2px solid rgba(255, 215, 0, 0.3);
  border-radius: var(--radius-xl);
  background: rgba(123, 104, 238, 0.08);
  box-shadow: 0 0 40px rgba(255, 215, 0, 0.2);
  max-width: 360px;
  width: 90%;
}
.confirm-choice-text {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--story-primary);
}
.confirm-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===== 结局 ===== */
.ending-title {
  font-size: clamp(20px, 5vw, 26px);
  font-weight: 900;
  margin-bottom: 8px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
.ending-text {
  font-size: clamp(13px, 3.5vw, 16px);
  line-height: 1.7;
  margin-bottom: 10px;
  color: var(--white-90);
  max-width: 400px;
}

/* ===== 成就徽章 ===== */
.achievement-badge {
  background: rgba(255, 215, 0, 0.08);
  border: 1.5px solid rgba(255, 215, 0, 0.25);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  max-width: 380px;
  width: 100%;
}
.achievement-icon { font-size: 32px; flex-shrink: 0; }
.achievement-info { flex: 1; }
.achievement-name { font-size: 14px; font-weight: 800; color: var(--story-primary); }
.achievement-desc { font-size: 12px; color: var(--white-70); margin-top: 2px; }

/* ===== 知识卡 ===== */
.knowledge-card {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--white-70);
  text-align: left;
  max-width: 380px;
  width: 100%;
  max-height: 70px;
  overflow-y: auto;
}
.knowledge-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--story-primary);
  margin-bottom: 4px;
  letter-spacing: 1px;
}

/* ===== 进度条 ===== */
.progress-bar-wrap {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 4px;
  background: var(--white-10);
  z-index: 1000;
}
.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--story-primary), var(--story-accent));
  transition: width 0.5s ease;
  border-radius: 0 2px 2px 0;
}

/* ===== 音频按钮 ===== */
.audio-btn {
  position: absolute;
  top: 12px; right: 12px;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--story-accent), var(--story-primary));
  border: 2px solid rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(0,0,0,0.3);
  z-index: 20;
  transition: all 150ms ease;
  font-size: 20px;
  color: var(--white);
}
.audio-btn:hover { transform: scale(1.08); }
.audio-btn:active { transform: scale(0.95); }
.audio-btn.playing {
  box-shadow: 0 5px 22px rgba(255, 215, 0, 0.5);
  animation: audioPulse 1.5s ease-in-out infinite;
}
@keyframes audioPulse {
  0%, 100% { box-shadow: 0 3px 12px rgba(0,0,0,0.3); }
  50%      { box-shadow: 0 5px 25px rgba(255, 215, 0, 0.55); }
}

/* ===== 家长讲解（可选功能入口）===== */
.parent-toggle {
  font-size: 12px;
  color: var(--story-accent);
  opacity: 0.6;
  cursor: pointer;
  border: none;
  background: none;
  padding: 4px 8px;
  transition: opacity 0.2s;
}
.parent-toggle:hover { opacity: 1; }

/* ===== 响应式 ===== */
@media (max-width: 380px) {
  .text-zone { padding: 8px 16px 12px; gap: 6px; }
  .choice-btn { padding: 12px 14px; min-height: 48px; }
  .choice-icon { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
