/* effects.css — 动效 / 过渡 / 仪式
   追加在 portrait.css 末尾
*/

/* ============ 打字机 ============ */
.narrative.typing p { opacity: 0; }
.narrative.typing p.in {
  opacity: 1;
  transition: opacity 0.3s ease;
}
.narrative .caret {
  display: inline-block;
  width: 0.6ch;
  height: 1em;
  background: var(--accent);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: caretBlink 0.7s steps(1) infinite;
}
@keyframes caretBlink {
  50% { opacity: 0; }
}

/* 跳过按钮 (打字进行中右下浮出) */
.skip-typing {
  position: absolute;
  bottom: -36px;
  right: 0;
  background: rgba(0,0,0,0.6);
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 4px 10px;
  font-size: 11px;
  border-radius: 4px;
  cursor: pointer;
  animation: skipHint 2s ease-in-out infinite;
}
@keyframes skipHint {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ============ 选项点击反馈 ============ */
.choice {
  position: relative;
  overflow: hidden;
}
.choice::after {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(212,175,55,0.3), transparent);
  transition: left 0.4s ease;
}
.choice:hover:not(:disabled)::after { left: 100%; }

.choice.selected {
  border-color: var(--accent) !important;
  background: linear-gradient(90deg, rgba(212,175,55,0.15), rgba(212,175,55,0.05)) !important;
  animation: choiceSelected 0.5s ease;
  transform: translateX(4px) scale(1.02);
}
@keyframes choiceSelected {
  0% { transform: scale(1); }
  30% { transform: scale(1.05); box-shadow: 0 0 16px var(--accent); }
  100% { transform: scale(1.02); }
}

.choice.fading {
  animation: choiceFade 0.3s ease forwards;
}
@keyframes choiceFade {
  to { opacity: 0.25; transform: scale(0.95); pointer-events: none; }
}

/* ============ 9/8 加: 顶部工具栏 (top-bar) ============
   玻璃 + sticky top, 桌面 + 移动 都显示
   左侧 4 个 stats (迷你) + 右侧 4 个工具按钮
   整合了 OOB #2 (重置) + #3 (喇叭按钮) → 顶部
*/
.top-bar {
  position: sticky;
  top: 0;
  z-index: 1100;  /* 9/23 修真: 修真 intro-overlay (999), 让 about 按钮 (⚡) 修真 */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: rgba(10, 10, 15, 0.85);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  z-index: 80;
  font-size: 12px;
  color: var(--fg-2);
}
.top-bar-stats {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.top-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  color: var(--fg-2);
  font-size: 11px;
  letter-spacing: 0.02em;
}
.top-stat-icon { font-size: 14px; line-height: 1; }
.top-bar-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.top-tool {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  color: var(--fg-2);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}
.top-tool:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(212, 175, 55, 0.08);
}
.top-tool:active {
  transform: scale(0.94);
}
.top-tool.active {  /* BGM/TTS 开启时 */
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(212, 175, 55, 0.3);
}
.top-tool-danger:hover {  /* 重置按钮 - 红色 hover */
  border-color: #e74c3c;
  color: #e74c3c;
  background: rgba(231, 76, 60, 0.08);
}

/* mobile: top-bar 紧凑, 4 stats 只显 2 + 隐藏一些 */
@media (max-width: 768px) {
  .top-bar {
    padding: 6px 8px;
    gap: 6px;
  }
  .top-bar-stats { gap: 6px; }
  .top-stat { font-size: 10px; }
  .top-stat:nth-child(n+3) { display: none; }  /* 隐藏成就 + 时长 */
  .top-tool { width: 32px; height: 32px; font-size: 14px; }
}

/* desktop: 顶 bar + 侧 sidebar 同时存在, sidebar 不用改 */
@media (min-width: 769px) {
  /* 桌面端 top-bar sticky 在 sidebar 上方 (sidebar 高度 = 100vh) */
  .layout-with-sidebar {
    padding-top: 0;  /* top-bar 在 main padding 外, sticky 在 main 顶部 */
  }
}

/* ============ 9/8 加: 历程 modal (History) ============ */
.history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: tutorialIn 0.3s ease;
  padding: 20px;
}
.history-modal {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-top: 3px solid var(--accent);
  border-radius: 18px;
  padding: 24px;
  max-width: 720px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.55), 0 0 32px rgba(212, 175, 55, 0.15);
}
.history-modal h2 { margin: 0 0 4px; color: var(--accent); }
.history-modal .history-tagline { font-size: 12px; color: var(--fg-3); margin-bottom: 16px; }
.history-modal .close-btn {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px; border-radius: 50%;
  background: transparent; border: 1px solid var(--border); color: var(--fg-2);
  cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center;
}
.history-modal .close-btn:hover { color: var(--accent); border-color: var(--accent); }
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-row {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  font-size: 13px;
}
.history-row .ts { color: var(--fg-3); font-size: 11px; font-family: monospace; }
.history-row .name { color: var(--fg); }
.history-row .badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  background: var(--bg-2);
  color: var(--fg-2);
}
.history-row.unlock { border-left: 3px solid var(--accent); }
.history-row.unlock .badge { background: var(--accent); color: #000; font-weight: 700; }
.history-empty { text-align: center; color: var(--fg-3); padding: 40px 0; }

@media (prefers-reduced-motion: reduce) {
  .ss-progress-bar { transition: none; }
}

/* ============ 9/7 加: Narrative skeleton (进剧本瞬间显示) ============
   narrative-active class 时隐藏 (narrative.js render 时添加)
   prefers-reduced-motion: 关掉 shimmer 动画
*/
.narrative-skeleton {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 0;
}
.narrative-active .narrative-skeleton { display: none; }
.skeleton-line {
  height: 16px;
  border-radius: 4px;
  background: linear-gradient(90deg,
    rgba(255,255,255,0.05) 0%,
    rgba(255,255,255,0.12) 50%,
    rgba(255,255,255,0.05) 100%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s ease-in-out infinite;
}
.skeleton-line:nth-child(2) { animation-delay: 0.15s; }
.skeleton-line:nth-child(3) { animation-delay: 0.30s; }
.skeleton-line:nth-child(4) { animation-delay: 0.45s; }
.skeleton-line:nth-child(5) { animation-delay: 0.60s; }
@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton-line { animation: none; background: rgba(255,255,255,0.08); }
}

/* ============ 翻页过渡 ============ */
.stage-transition {
  animation: stageSlideIn 0.25s ease;  /* 9/7 优化: 0.5 → 0.25s */
}
@keyframes stageSlideIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.stage-transition-out {
  animation: stageSlideOut 0.15s ease forwards;  /* 9/7 优化: 0.3 → 0.15s */
}
@keyframes stageSlideOut {
  to { opacity: 0; transform: translateY(-20px); }
}

/* ============ 金手指仪式 ============ */
.finger-ceremony {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  pointer-events: none;
  background: rgba(0,0,0,0.85);
  animation: fingerBgIn 0.5s ease;
}
@keyframes fingerBgIn {
  from { background: rgba(0,0,0,0); }
  to { background: rgba(0,0,0,0.85); }
}

.finger-pulse {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent), transparent 70%);
  animation: fingerPulse 1s ease-in-out infinite;
}
@keyframes fingerPulse {
  0%, 100% { transform: scale(0.8); opacity: 0.6; }
  50% { transform: scale(1.4); opacity: 1; }
}

.finger-text {
  position: absolute;
  font-size: 28px;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.2em;
  text-shadow: 0 0 12px var(--accent);
  animation: fingerTextIn 0.6s ease;
}
@keyframes fingerTextIn {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

.finger-countdown {
  font-size: 72px;
  color: var(--accent);
  font-weight: 800;
  text-shadow: 0 0 20px var(--accent);
  animation: countdownTick 1s ease;
}
@keyframes countdownTick {
  0% { transform: scale(2); opacity: 0; }
  50% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.8); opacity: 0.6; }
}

.screen-shake {
  animation: screenShake 0.5s ease;
}
@keyframes screenShake {
  0%, 100% { transform: translateX(0); }
  10% { transform: translateX(-6px); }
  20% { transform: translateX(6px); }
  30% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  50% { transform: translateX(-2px); }
  60% { transform: translateX(2px); }
}

/* 金手指"撕开"效果 */
.tear-open {
  animation: tearOpen 0.8s ease;
  clip-path: polygon(50% 0, 50% 0, 50% 100%, 50% 100%);
}
@keyframes tearOpen {
  0% { clip-path: polygon(50% 0, 50% 0, 50% 100%, 50% 100%); }
  100% { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); }
}

/* ============ 结局高光 ============ */
.ending-card.tier-1 .ending-card-inner {
  animation: endingTier1 1.5s ease;
}
@keyframes endingTier1 {
  0% { filter: brightness(1); }
  50% { filter: brightness(1) grayscale(1); }
  100% { filter: brightness(0.6) grayscale(0.7); }
}

.ending-card.tier-3::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100vmax;
  height: 100vmax;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
  opacity: 0;
  animation: endingTier3Burst 1.5s ease forwards;
  pointer-events: none;
}
@keyframes endingTier3Burst {
  0% { opacity: 0.8; transform: translate(-50%, -50%) scale(0); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

.ending-card.tier-3 { position: relative; }
.ending-card.tier-3 h2 {
  animation: tier3TitlePulse 2s ease-in-out infinite;
}
@keyframes tier3TitlePulse {
  0%, 100% { text-shadow: 0 0 0 var(--accent); }
  50% { text-shadow: 0 0 24px var(--accent), 0 0 8px var(--accent); }
}

.ending-card.crashed {
  animation: endingCrashed 0.8s ease;
}
@keyframes endingCrashed {
  0% { transform: scale(1); filter: brightness(1); }
  20% { transform: scale(1.1) rotate(-2deg); filter: brightness(1.3); }
  40% { transform: scale(0.95) rotate(1deg); filter: brightness(0.8); }
  60% { transform: scale(1.02) rotate(-1deg); }
  100% { transform: scale(1) rotate(0); filter: brightness(0.7); }
}

/* ============ 立绘动态 ============ */
.pportrait {
  opacity: 0;
  transform: translateX(-30px);
  animation: portraitSlideIn 0.5s ease forwards;
}
@keyframes portraitSlideIn {
  to { opacity: 1; transform: translateX(0); }
}
.pportrait.leaving {
  animation: portraitSlideOut 0.3s ease forwards;
}
@keyframes portraitSlideOut {
  to { opacity: 0; transform: translateX(30px); }
}
.pportrait.bobbing {
  animation: portraitBob 3s ease-in-out infinite;
}
@keyframes portraitBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

/* ============ LOBBY 沉浸 ============ */
.lobby-open {
  animation: lobbyFadeIn 0.8s ease;
}
@keyframes lobbyFadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.script-card.cascade-in {
  opacity: 0;
  transform: translateY(30px);
  animation: cardCascade 0.6s ease forwards;
}
@keyframes cardCascade {
  to { opacity: 1; transform: translateY(0); }
}

.hero-card {
  position: relative;
  overflow: hidden;
}
.hero-card::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(212,175,55,0.2), transparent);
  transition: left 0.8s ease;
}
.hero-card:hover::before { left: 100%; }
.hero-card:hover {
  transform: translateY(-4px) scale(1.02) !important;
  box-shadow: 0 8px 24px rgba(212,175,55,0.25) !important;
}

/* ============ 通用过渡 ============ */
.stage-chapter {
  animation: chapterEnter 0.6s ease;
}
@keyframes chapterEnter {
  from { opacity: 0; transform: translateX(-15px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ============ 角色对话气泡 (替代纯文字speaker card) ============ */
.speaker-card {
  animation: speakerEnter 0.5s ease;
}
@keyframes speakerEnter {
  from { opacity: 0; transform: translateY(8px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============ 移动端适配 ============ */
@media (max-width: 768px) {
  /* 9/3 P0-B 修: 移动端 sidebar (bottom 64px) 与声音按钮重合
     移动端把按钮移到 sidebar 上方 (bottom 88px) */
  .bgm-toggle { bottom: 84px; right: 16px; }
  .tts-btn { bottom: 84px; right: 70px; }
  .continue-prompt { top: 80px; }
}
@media (max-width: 480px) {
  .finger-text { font-size: 22px; }
  .finger-countdown { font-size: 56px; }
  .skip-typing { font-size: 10px; padding: 3px 8px; }
  /* P0-B: 小屏幕 sidebar 64px, 按钮更靠上 */
  .bgm-toggle { bottom: 76px; right: 12px; }
  .tts-btn { bottom: 76px; right: 60px; }
}

/* ============ 结局缩略图 ============ */
.ending-thumb {
  width: 100%;
  height: 120px;
  border-radius: var(--radius);
  margin: 16px 0;
  overflow: hidden;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.3);
  animation: endingThumbIn 0.8s ease;
}
.ending-thumb svg {
  width: 100%;
  height: 100%;
  display: block;
}
@keyframes endingThumbIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* ============ 短剧逐句 narrative 动画 ============ */
.narrative.narrative-active {
  position: relative;
  min-height: 100px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 16px 12px;
  scroll-behavior: smooth;
}
.narrative .line {
  display: inline;
  font-size: 17px;
  line-height: 2;
  margin-right: 4px;
  opacity: 0;
  transform: translateY(8px);
  filter: blur(2px);
  transition: opacity 0.4s ease, transform 0.4s ease, filter 0.4s ease;
}
.narrative .line.line-in {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}
.narrative .line.line-important {
  display: inline-block;
  font-size: 19px;
  font-weight: 600;
}
.narrative .line.line-important.line-in {
  animation: linePop 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes linePop {
  0% { transform: scale(0.8) translateY(10px); opacity: 0; }
  60% { transform: scale(1.1) translateY(-2px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
/* narrative 顶部的 ⏭ 跳过按钮 */
.narrative .skip-typing {
  position: sticky;
  top: 0;
  right: 0;
  float: right;
  z-index: 10;
  margin-bottom: 8px;
}

/* ============ 隐藏式金手指入口 ============ */
.hidden-finger {
  position: relative;
  display: inline;
  cursor: pointer;
  color: transparent;
  background: linear-gradient(90deg, var(--accent), transparent);
  background-clip: text;
  -webkit-background-clip: text;
  font-style: italic;
  filter: blur(0.5px);
  animation: hiddenFingerPulse 3s ease-in-out infinite;
  border-bottom: 1px dashed rgba(212, 175, 55, 0.3);
}
.hidden-finger:hover {
  color: var(--accent);
  filter: blur(0);
  text-shadow: 0 0 8px var(--accent);
}
.hidden-finger::before {
  content: '✦';
  position: absolute;
  font-size: 12px;
  color: var(--accent);
  opacity: 0;
  animation: hiddenFingerHint 2.5s ease-in-out infinite;
  top: -10px;
  left: -16px;
}
@keyframes hiddenFingerPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.85; }
}
@keyframes hiddenFingerHint {
  0%, 100% { opacity: 0; transform: translateY(0); }
  50% { opacity: 0.7; transform: translateY(-3px); }
}
.hidden-finger.used {
  color: var(--fg-3) !important;
  filter: none !important;
  border-bottom-style: solid;
  cursor: not-allowed;
}

/* ============ Mini-Game ============ */
.minigame-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 450;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  animation: tutorialIn 0.4s ease;
}
.minigame-card {
  /* 9/7 升级: 液态玻璃 */
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-top: 3px solid var(--accent);
  border-radius: 18px;
  padding: 28px 32px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 24px 72px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.12);
  animation: modalIn 0.4s ease;
}
.minigame-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--glass-highlight);
  pointer-events: none;
  border-radius: inherit;
}
.minigame-card > * { position: relative; z-index: 1; }
.minigame-card h3 {
  color: var(--accent);
  font-size: 18px;
  margin-bottom: 8px;
  letter-spacing: 0.1em;
}
.minigame-card p {
  color: var(--fg-2);
  font-size: 13px;
  margin-bottom: 16px;
}
.minigame-input {
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 16px;
  font-size: 16px;
  font-family: inherit;
  border-radius: var(--radius);
  text-align: center;
  width: 100%;
  margin: 8px 0;
}
.minigame-input:focus { outline: none; border-color: var(--accent); }

/* 拖动能量球 */
.energy-ball-area {
  position: relative;
  width: 280px;
  height: 280px;
  margin: 0 auto;
  background: radial-gradient(circle, rgba(212,175,55,0.08), transparent 70%);
  border: 2px dashed var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
}
.energy-ball {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff7d4, var(--accent) 60%, #8b6914);
  box-shadow: 0 0 40px var(--accent);
  position: absolute;
  cursor: grab;
  transition: transform 0.1s;
  user-select: none;
}
.energy-ball:active { cursor: grabbing; transform: scale(1.1); }
.energy-target {
  position: absolute;
  width: 120px;
  height: 120px;
  border: 3px solid rgba(212,175,55,0.4);
  border-radius: 50%;
  pointer-events: none;
  animation: targetPulse 1.5s ease-in-out infinite;
}
@keyframes targetPulse {
  0%, 100% { transform: scale(1); border-color: rgba(212,175,55,0.4); }
  50% { transform: scale(1.1); border-color: rgba(212,175,55,0.8); }
}

/* 滑动解锁 */
.swipe-area {
  position: relative;
  width: 280px;
  height: 60px;
  margin: 0 auto;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  border-radius: 30px;
  overflow: hidden;
}
.swipe-track {
  position: absolute;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(212,175,55,0.15), transparent);
  animation: swipeTrack 2s linear infinite;
}
@keyframes swipeTrack {
  from { left: -100%; }
  to { left: 100%; }
}
.swipe-thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  user-select: none;
  transition: left 0.05s linear;
}
.swipe-thumb:active { cursor: grabbing; }
.swipe-label {
  position: absolute;
  width: 100%;
  text-align: center;
  line-height: 60px;
  color: var(--fg-3);
  font-size: 13px;
  letter-spacing: 0.2em;
  pointer-events: none;
}

/* ============ TTS 控制 ============ */
.tts-btn {
  /* 9/8 加: 顶部 header 已有 TTS 按钮, 浮动按钮 hide (避免重复 + 重叠) */
  display: none !important;
}
.tts-btn:hover { border-color: var(--accent); color: var(--accent); }
.tts-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* 角色名显示时加 TTS 朗读按钮 (在 speaker-card) */
.speaker-tts {
  margin-left: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-3);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.speaker-tts:hover { color: var(--accent); border-color: var(--accent); }

/* ============ 结局选择分布 ============ */
.choice-distribution {
  margin: 16px 0;
  padding: 12px 14px;
  background: rgba(0,0,0,0.3);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}
.choice-distribution h4 {
  font-size: 11px;
  color: var(--fg-2);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.choice-dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  font-size: 13px;
}
.choice-dist-row .dist-label {
  flex: 1;
  color: var(--fg-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.choice-dist-row .dist-bar {
  flex: 0 0 120px;
  height: 8px;
  background: var(--bg-3);
  border-radius: 4px;
  overflow: hidden;
}
.choice-dist-row .dist-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #f5d76e);
  border-radius: 4px;
  transition: width 1s ease;
}
.choice-dist-row .dist-pct {
  flex: 0 0 36px;
  text-align: right;
  color: var(--accent);
  font-weight: 700;
  font-family: ui-monospace, monospace;
}
.choice-dist-row.user-pick {
  background: rgba(212,175,55,0.1);
  border-radius: 4px;
  padding: 4px 6px;
  margin: 4px -6px;
}
.choice-dist-row.user-pick .dist-label::before {
  content: '✦ ';
  color: var(--accent);
}

/* ============ 跨剧本心理记忆 ============ */
.psych-echo {
  margin: 12px 0;
  padding: 10px 14px;
  background: linear-gradient(135deg, rgba(176,102,255,0.1), rgba(88,166,255,0.05));
  border-left: 3px solid #b066ff;
  border-radius: 4px;
  font-size: 13px;
  color: var(--fg-2);
  font-style: italic;
  animation: echoIn 1s ease;
}
.psych-echo::before {
  content: '🌀 ';
  color: #b066ff;
}
@keyframes echoIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

kbd {
  display: inline-block;
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 7px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  margin: 0 2px;
}
#shortcutPanel kbd { min-width: 22px; text-align: center; }
#shortcutPanel > div:not(:first-child) { color: var(--fg-2); }

/* ============ 章节进度条 ============ */
.chapter-progress {
  position: relative;
  width: 100%;
  height: 6px;               /* 9/7 加高: 3 → 6px 更明显 */
  background: var(--glass-bg);  /* 9/7 加: 玻璃底 */
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  border-radius: 4px;
  margin-top: 8px;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.10);
}
.chapter-progress .bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #f5d76e);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 8px var(--accent);
}
.chapter-progress .marker {
  position: absolute;
  top: -2px;
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent);
  transition: left 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.chapter-progress .label {
  position: absolute;
  top: -18px;
  right: 0;
  font-size: 10px;
  color: var(--fg-3);
  letter-spacing: 0.1em;
}


/* ============ 剧本预览模态 ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);  /* 9/7 调浅 (0.85 → 0.75) 让背后内容透出 */
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);  /* 9/7 加深 blur (6 → 8) 让 modal 更突出 */
  animation: tutorialIn 0.3s ease;
}
.modal {
  /* 9/7 升级: 液态玻璃 modal — 保留 accent 边框作为品牌色 */
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-top: 3px solid var(--accent);   /* 保留 accent 顶部品牌线 */
  border-radius: 18px;
  padding: 28px;
  max-width: 560px;
  width: 92%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 24px 72px rgba(0,0,0,0.55),
              inset 0 1px 0 rgba(255,255,255,0.12),
              0 0 32px rgba(212, 175, 55, 0.10);  /* accent 微光 */
  animation: modalIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--glass-highlight);
  pointer-events: none;
  border-radius: inherit;
  z-index: 0;
}
.modal > * { position: relative; z-index: 1; }
@keyframes modalIn {
  from { transform: scale(0.9) translateY(20px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-2);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
}
.modal-close:hover { border-color: var(--accent); color: var(--accent); }
.modal h2 {
  color: var(--accent);
  font-size: 22px;
  margin-bottom: 4px;
}
.modal .modal-tagline {
  color: var(--fg-2);
  font-size: 13px;
  margin-bottom: 16px;
}
.preview-section {
  margin: 16px 0;
  padding: 12px 14px;
  background: rgba(0,0,0,0.3);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}
.preview-section h4 {
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.preview-section p {
  color: var(--fg-2);
  font-size: 13px;
  line-height: 1.6;
}
.preview-chapter-list {
  list-style: none;
  padding: 0;
}
.preview-chapter-list li {
  padding: 6px 10px;
  margin: 4px 0;
  background: var(--bg-3);
  border-radius: 4px;
  font-size: 13px;
  color: var(--fg-2);
}
.preview-chapter-list li::before {
  content: '▸ ';
  color: var(--accent);
}
.preview-endings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.preview-endings .ending-pill {
  background: var(--bg-3);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 11px;
  color: var(--fg-2);
  border-left: 2px solid var(--accent);
}
.preview-endings .ending-pill .etier { color: var(--accent); font-weight: 700; }
.preview-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}
.btn-modal-primary {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-weight: 700;
  cursor: pointer;
}
.btn-modal-secondary {
  background: transparent;
  color: var(--fg-2);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: var(--radius);
  cursor: pointer;
}

/* ============ 剧本卡片 i 按钮 ============ */
.script-card-info {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);   /* 9/7 改: 垂直居中 (跟 script-id 在 12-40px 撞, 居中避开) */
  left: auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--fg-2);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  transition: all 0.2s;
}
.script-card-info:hover {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}
/* 9/7 加: i 按钮 hover 显示 tooltip (左侧浮动) */
.script-card-info::before {
  content: attr(data-tooltip);
  position: absolute;
  right: calc(100% + 8px);   /* 按钮左侧 */
  top: 50%;
  transform: translateY(-50%);
  background: var(--accent);
  color: #000;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.script-card-info:hover::before { opacity: 1; }
/* tooltip 三角箭头 */
.script-card-info::after {
  content: '';
  position: absolute;
  right: calc(100% + 4px);
  top: 50%;
  transform: translateY(-50%);
  border: 4px solid transparent;
  border-left-color: var(--accent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.script-card-info:hover::after { opacity: 1; }

/* ============ 剧本头信息卡 ============ */
.script-meta-card {
  background: linear-gradient(135deg, rgba(255,255,255,0.04), rgba(0,0,0,0.2));
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 12px 0 20px;
  font-size: 12px;
  color: var(--fg-3);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
}
.script-meta-card .meta-label { color: var(--fg-2); font-weight: 600; }
.script-meta-card .meta-value { color: var(--fg); }
.script-meta-card .meta-row { display: flex; gap: 6px; align-items: center; }
.script-meta-card .meta-row .meta-icon { color: var(--accent); }

/* ============ 动漫人物 SVG 灵动动画 ============ */
.anime-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

/* 1) 呼吸 (整体微缩 1.0 ↔ 1.02, 3.5s) */
.anime-svg .body-breath {
  transform-origin: 100px 200px;
  animation: bodyBreath 3.5s ease-in-out infinite;
}
@keyframes bodyBreath {
  0%, 100% { transform: scale(1) translateY(0); }
  50% { transform: scale(1.025) translateY(-2px); }
}

/* 2) 头部微摆 (idle/tense 时左右 1.5°) */
.anime-svg .head-sway {
  transform-origin: 100px 130px;
  animation: headSway 5s ease-in-out infinite;
}
.anime-svg .head-sway-reverse {
  animation: headSway 5s ease-in-out infinite reverse;
}
@keyframes headSway {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(1.2deg); }
  75% { transform: rotate(-1.2deg); }
}

/* 3) 眨眼 (随机化: eye ellipse height 1 → 0.05, 0.15s) */
.anime-svg .eye ellipse {
  transform-origin: center;
  animation: blink 6s ease-in-out infinite;
  animation-delay: var(--blink-delay, 0s);
}
.anime-svg .eye:nth-child(2) ellipse {
  animation-delay: calc(var(--blink-delay, 0s) + 0.05s);  /* 双目同步 */
}
@keyframes blink {
  0%, 92%, 96%, 100% { transform: scaleY(1); }
  94% { transform: scaleY(0.05); }
}

/* 4) 说话时张嘴 (speaker-on 类触发) */
.anime-svg.speaking .mouth {
  animation: talkMouth 0.6s ease-in-out infinite;
}
@keyframes talkMouth {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(2.5); }
}

/* 说话挥臂 (arm-only 类触发, 对 <g class="arm">) */
.anime-svg.speaking .arm-left {
  transform-origin: 60px 175px;
  animation: waveArmLeft 1.4s ease-in-out infinite;
}
.anime-svg.speaking .arm-right {
  transform-origin: 140px 175px;
  animation: waveArmRight 1.4s ease-in-out infinite reverse;
}
@keyframes waveArmLeft {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(8deg); }
}
@keyframes waveArmRight {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-8deg); }
}

/* 5) mood 切换的平滑过渡 */
.anime-svg {
  transition: filter 0.6s ease;
}

/* mood 滤镜 (柔和版 - 不让 sad 看起来像葬礼) */
.anime-svg.mood-tense {
  filter: hue-rotate(160deg) saturate(1.15) brightness(0.96);
}
.anime-svg.mood-sad {
  filter: saturate(0.85) brightness(0.92);     /* 不全灰, 留点温度 */
}
.anime-svg.mood-triumph {
  filter: drop-shadow(0 0 14px var(--accent)) saturate(1.2) brightness(1.05);
}
.anime-svg.mood-reveal {
  filter: hue-rotate(240deg) saturate(1.3) drop-shadow(0 0 16px #b066ff);
}

/* 汗滴下落 */
.anime-svg .mood-sweat {
  animation: sweatDrop 1.8s ease-in infinite;
  transform-origin: center top;
}
@keyframes sweatDrop {
  0% { transform: translateY(0); opacity: 0.7; }
  100% { transform: translateY(15px); opacity: 0; }
}

/* 泪滴下落 */
.anime-svg .mood-tear {
  animation: tearFall 2.2s ease-in infinite;
  transform-origin: center top;
}
@keyframes tearFall {
  0% { transform: translateY(0); opacity: 0.8; }
  100% { transform: translateY(20px); opacity: 0; }
}

/* 头顶光环旋转 */
.anime-svg .mood-halo {
  transform-origin: 100px 20px;
  animation: haloSpin 4s linear infinite;
}
@keyframes haloSpin {
  to { transform: rotate(360deg); }
}

/* reveal aura 脉冲 */
.anime-svg .mood-aura {
  transform-origin: 100px 100px;
  animation: auraPulse 2s ease-in-out infinite;
}
@keyframes auraPulse {
  0%, 100% { transform: scale(1); opacity: 0.3; }
  50% { transform: scale(1.15); opacity: 0.6; }
}

/* 系统能量体 (system-body) 浮动 + 旋转 */
.anime-svg .system-body {
  transform-origin: 100px 120px;
  animation: systemFloat 4s ease-in-out infinite, systemPulse 2s ease-in-out infinite;
}
.anime-svg .system-aura {
  transform-origin: 100px 120px;
  animation: systemAura 3s linear infinite;
}
@keyframes systemFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
@keyframes systemPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.3); }
}
@keyframes systemAura {
  to { transform: rotate(360deg) scale(1.2); }
}

/* 立绘卡片容器 (在 narrative 上方) */
.portrait-stage {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin: 12px 0;
  min-height: 200px;
}

/* 单个立绘 wrapper */
.anime-portrait {
  width: 140px;
  height: 168px;
  position: relative;
  transition: transform 0.4s ease;
}
.anime-portrait:hover {
  transform: translateY(-4px) scale(1.05);
}
.anime-portrait .anime-svg {
  width: 100%;
  height: 100%;
}
.anime-portrait .portrait-label {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.65);
  color: var(--fg);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 8px;
  white-space: nowrap;
  letter-spacing: 0.05em;
}

/* 立绘入场动画 (滑入) */
.anime-portrait.entering {
  animation: portraitSlideIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes portraitSlideIn {
  from { opacity: 0; transform: translateX(-30px) scale(0.9); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
.anime-portrait.leaving {
  animation: portraitSlideOut 0.4s ease;
}
@keyframes portraitSlideOut {
  to { opacity: 0; transform: translateX(30px) scale(0.9); }
}

/* 立绘讲话时 (speak 类触发) */
.anime-portrait.speaking .portrait-label {
  background: var(--accent);
  color: #000;
}
.anime-portrait.speaking {
  animation: portraitSpeak 0.6s ease-in-out infinite;
}
@keyframes portraitSpeak {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

/* 移动端 */
@media (max-width: 480px) {
  .anime-portrait { width: 110px; height: 132px; }
}

/* ============ 结局评分 ============ */
.ending-rating {
  margin: 20px 0;
  text-align: center;
}
.ending-rating .rating-label {
  font-size: 13px;
  color: var(--fg-2);
  margin-bottom: 8px;
  letter-spacing: 0.1em;
}
.ending-rating .thumbs {
  display: inline-flex;
  gap: 4px;
  margin: 0 auto 12px;
}
.ending-rating .thumb-btn {
  background: transparent;
  border: 1px solid var(--border);
  font-size: 22px;
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  filter: grayscale(0.8);
}
.ending-rating .thumb-btn:hover { transform: translateY(-2px); filter: grayscale(0); border-color: var(--accent); }
.ending-rating .thumb-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  filter: none;
  transform: scale(1.1);
}
.ending-rating .rating-display {
  font-size: 11px;
  color: var(--accent);
  margin-top: 4px;
  min-height: 16px;
}

.ending-comment-area {
  width: 100%;
  min-height: 60px;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  color: var(--fg);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  margin: 8px 0;
}
.ending-comment-area:focus { outline: none; border-color: var(--accent); }

.ending-rating-saved {
  font-size: 12px;
  color: var(--accent);
  text-align: center;
  margin-top: 4px;
  animation: savedPulse 0.5s ease;
}
@keyframes savedPulse {
  0% { transform: scale(0.95); opacity: 0; }
  50% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.previous-comment {
  margin-top: 8px;
  padding: 8px 12px;
  background: rgba(0,0,0,0.3);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 12px;
  color: var(--fg-2);
  font-style: italic;
}
.previous-comment .prev-label {
  display: block;
  color: var(--fg-3);
  font-size: 10px;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
  font-style: normal;
}

/* ============ 继续按钮 (剧本卡上 ● + 一键继续) ============ */
.script-card-continue {
  position: absolute;
  top: 50%;
  left: 48px;
  transform: translateY(-50%);   /* 9/7 改: 跟 info 按钮同高度, 居中 */
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--accent);
  color: #000;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  z-index: 2;
  border: none;
  transition: all 0.2s;
}
.script-card-continue:hover { transform: scale(1.05); box-shadow: 0 2px 8px var(--accent); }
.script-card-continue::before {
  content: '●';
  font-size: 8px;
  animation: continueBlink 1.5s ease-in-out infinite;
}
@keyframes continueBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.continue-prompt {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  border: 1px solid var(--accent);
  border-radius: 24px;
  padding: 8px 18px;
  font-size: 13px;
  color: var(--fg);
  z-index: 80;
  backdrop-filter: blur(8px);
  animation: continuePromptIn 0.5s ease 3s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.continue-prompt button {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 4px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
}
.continue-prompt button.skip {
  background: transparent;
  color: var(--fg-2);
  border: 1px solid var(--border);
  font-weight: 400;
}
@keyframes continuePromptIn {
  from { transform: translateX(-50%) translateY(-20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ============ 结局页 · AI 专属短片 (P0-D-9 9/7) ============ */
.ending-video {
  margin: 16px 0;
  padding: 14px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
  position: relative;
  overflow: hidden;
}
.ending-video-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.ending-video-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
}
.ending-video-quota {
  font-size: 11px;
  color: var(--fg-3);
  background: rgba(255,255,255,0.05);
  padding: 2px 8px;
  border-radius: 8px;
}
.btn-video {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-cool, #4fc3f7));
  color: #000;
  border: none;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-video:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
.btn-video:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.ending-video-progress {
  margin-top: 10px;
}
.progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(0,0,0,0.3);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-cool, #4fc3f7));
  transition: width 0.3s;
  animation: progressShimmer 2s linear infinite;
}
@keyframes progressShimmer {
  0% { background-position: 0 0; }
  100% { background-position: 30px 0; }
}
.progress-text {
  margin-top: 6px;
  font-size: 12px;
  color: var(--fg-2);
  text-align: center;
}

.ending-video-player {
  margin-top: 12px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}
.ending-video-player video {
  width: 100%;
  max-height: 360px;
  display: block;
}

.ending-video-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--fg-3);
  text-align: center;
}

/* ============ 9/7 加: 液态玻璃 (Liquid Glass / Glassmorphism) ============
   风格参考: Apple Vision Pro / iOS 26 Liquid Glass
   设计目标:
     - 半透明背景 + backdrop-filter 折射模糊
     - 1px 高光边 (inset linear-gradient 模拟光从上方斜照)
     - 柔和阴影 (投影 + 内部高光, 模拟玻璃厚度)
     - hover 时背景变亮 + 边变亮 + 阴影加深
   兼容性:
     - Firefox / Safari 支持 backdrop-filter
     - 老浏览器 fallback 到 --glass-bg 实色
     - 不影响现有各剧本独立主题 (body.theme-XXX) 因为只改半透明叠加
     - prefers-reduced-motion: 关掉所有 transition/animation
*/
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow);
  position: relative;
  overflow: hidden;
}
.glass::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--glass-highlight);
  pointer-events: none;
  border-radius: inherit;
}
.glass:hover {
  background: var(--glass-bg-hover);
  border-color: var(--glass-border-hi);
}

/* 大尺寸卡片 (script-card / ending-card) */
.glass-card {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.10), inset 0 -1px 0 rgba(255,255,255,0.04);
  position: relative;
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease, background 0.3s ease;
}
.glass-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--glass-highlight);
  pointer-events: none;
  border-radius: inherit;
  z-index: 0;
}
.glass-card > * { position: relative; z-index: 1; }  /* 玻璃效果覆盖之下, 内容浮在上面 */
.glass-card:hover {
  background: var(--glass-bg-hover);
  border-color: var(--glass-border-hi);
  box-shadow: 0 16px 48px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.15);
  transform: translateY(-2px);
}

/* 小面板 (toolbar / status panel / stats) */
.glass-panel {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.08);
  padding: 10px 14px;
  position: relative;
  overflow: hidden;
}
.glass-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--glass-highlight);
  pointer-events: none;
  border-radius: inherit;
}
.glass-panel > * { position: relative; z-index: 1; }

/* 浮动按钮 (floating / dialog / modal) */
.glass-floating {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.12);
  position: relative;
  overflow: hidden;
}
.glass-floating::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--glass-highlight);
  pointer-events: none;
  border-radius: inherit;
}
.glass-floating > * { position: relative; z-index: 1; }

/* 备用: 不支持 backdrop-filter 的浏览器用半透实色 */
@supports not (backdrop-filter: blur(1px)) {
  .glass, .glass-card, .glass-panel, .glass-floating {
    background: rgba(20, 20, 28, 0.92);  /* 深色 fallback */
  }
}

/* ============ 9/7 加: 成就系统 (achievement grid + toast) ============ */
.ach-item {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 10px 6px;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: all 0.2s;
  cursor: default;
}
.ach-item.unlocked {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(212, 175, 55, 0.25), inset 0 1px 0 rgba(255,255,255,0.12);
}
.ach-item.locked {
  opacity: 0.45;
  filter: grayscale(0.6);
}
.ach-item:hover {
  transform: translateY(-2px);
}
.ach-icon {
  font-size: 28px;
  margin-bottom: 4px;
  line-height: 1;
}
.ach-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--fg);
  margin-bottom: 4px;
  line-height: 1.2;
}
.ach-item.locked .ach-title {
  color: var(--fg-3);
}
.ach-desc {
  font-size: 9px;
  color: var(--fg-3);
  line-height: 1.3;
  margin-top: 4px;
}

/* 成就解锁 toast (右下角浮层) */
.achievement-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur) saturate(140%);
  backdrop-filter: var(--glass-blur) saturate(140%);
  border: 1px solid var(--glass-border);
  border-top: 3px solid var(--accent);
  border-radius: 12px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 600;
  min-width: 280px;
  max-width: 360px;
  opacity: 0;
  transform: translateX(120%) scale(0.9);
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 20px 60px rgba(0,0,0,0.55),
              0 0 24px rgba(212, 175, 55, 0.25),
              inset 0 1px 0 rgba(255,255,255,0.12);
  pointer-events: none;
}
.achievement-toast.show {
  opacity: 1;
  transform: translateX(0) scale(1);
  pointer-events: auto;
}
.achievement-toast .toast-icon {
  font-size: 36px;
  line-height: 1;
  flex-shrink: 0;
}
.achievement-toast .toast-body {
  flex: 1;
  min-width: 0;
}
.achievement-toast .toast-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.achievement-toast .toast-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--fg);
  margin-bottom: 2px;
}
.achievement-toast .toast-desc {
  font-size: 11px;
  color: var(--fg-2);
  line-height: 1.4;
}
@media (prefers-reduced-motion: reduce) {
  .achievement-toast { transition: none; transform: translateX(0); }
}

@media (max-width: 768px) {
  .achievement-toast { right: 12px; bottom: 76px; min-width: 240px; max-width: 320px; padding: 12px 14px; }
  .achievement-toast .toast-icon { font-size: 32px; }
  .achievement-toast .toast-name { font-size: 14px; }
}

/* mobile disable backdrop-filter for achievement cards (GPU 节省) */
@media (max-width: 768px) {
  .ach-item { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .glass-card, .glass-card:hover { transition: none; transform: none; }
}

/* 9/7 加: mobile disable backdrop-filter (GPU 杀手, 38 处磨砂玻璃会让 mobile 渲染慢)
   mobile 用 solid 背景替代, 性能提升 30-50% */
@media (max-width: 768px) {
  * { -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
  /* 但保留部分关键元素的视觉 */
  .script-card, .ending-card, .modal, .tutorial-card, .minigame-card {
    background: var(--bg-2) !important;
  }
}
