/* ===== CSS 变量 ===== */
:root {
  --color-bg: #000;
  --color-primary: #FF2B4E;
  --color-text: #fff;
  --color-muted: rgba(255,255,255,0.5);
  --color-blur-bg: rgba(0,0,0,0.65);
  --blur: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 44px;
  --narrative-h: 80px;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', sans-serif;
  overflow: hidden;
  overscroll-behavior-y: contain; /* 禁用下拉刷新 */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
button { background: none; border: none; cursor: pointer; color: inherit; font: inherit; }

/* ===== App 容器 ===== */
#app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh; /* 动态视口高度，适配 iOS Safari 地址栏 */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== 顶部导航 ===== */
#topNav {
  position: relative;
  z-index: 100;
  display: flex;
  justify-content: center;
  gap: 32px;
  padding: calc(var(--safe-top) + 8px) 0 8px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.7) 0%, transparent 100%);
  pointer-events: auto;
}
.nav-tab {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-muted);
  padding: 4px 8px;
  transition: color 0.2s;
  position: relative;
}
.nav-tab.active {
  color: var(--color-text);
  font-weight: 700;
}
.nav-tab.active::after {
  content: '';
  position: absolute;
  bottom: -2px; left: 50%; transform: translateX(-50%);
  width: 20px; height: 2px;
  background: var(--color-primary);
  border-radius: 1px;
}

/* ===== Tab 视图 ===== */
.tab-view {
  position: absolute;
  inset: 0;
  display: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.tab-view.active { display: block; }

/* ===== 发现 Tab ===== */
#viewDiscover {
  overflow: hidden;
}

/* ===== 视频 Stack ===== */
#videoStack {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
}

.slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
}
.slide.active {
  opacity: 1;
  pointer-events: auto;
  z-index: 2;
}

.slide-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  filter: blur(20px) brightness(0.4);
  transform: scale(1.1);
}

.iframe-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.iframe-wrap iframe {
  position: absolute;
  /* 放大并居中，裁掉B站顶部工具栏和底部控制条 */
  top: -60px;
  left: -10px;
  width: calc(100% + 20px);
  height: calc(100% + 120px);
  border: none;
  pointer-events: none; /* 手势层接管所有触摸 */
}

/* 滑动动画 */
.slide-in-left  { transform: translateX(100%); }
.slide-in-right { transform: translateX(-100%); }
.slide-in-up    { transform: translateY(100%); }
.slide-in-down  { transform: translateY(-100%); }

/* 手势层：覆盖整个视频区，拦截所有触摸 */
#gestureLayer {
  position: absolute;
  inset: 0;
  z-index: 10;
}

/* 加载占位 */
#loadingPlaceholder {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
  transition: opacity 0.4s;
}
#loadingPlaceholder.hidden {
  opacity: 0;
  pointer-events: none;
}
.loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 首次播放蒙层 ===== */
#playOverlay {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
  transition: opacity 0.3s;
}
#playOverlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.play-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.play-icon {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.4);
  display: flex; align-items: center; justify-content: center;
}
.play-overlay-inner p {
  font-size: 16px;
  color: rgba(255,255,255,0.8);
}

/* ===== 手势引导 ===== */
#gestureGuide {
  position: absolute;
  inset: 0;
  z-index: 85;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  pointer-events: none;
  animation: guideFade 3s ease forwards;
  animation-delay: 0.5s;
  opacity: 0;
}
@keyframes guideFade {
  0%   { opacity: 0; }
  20%  { opacity: 1; }
  70%  { opacity: 1; }
  100% { opacity: 0; }
}
.guide-hint {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 10px 20px;
}
.guide-arrow { font-size: 20px; }
.guide-label { font-size: 14px; color: rgba(255,255,255,0.9); }

/* ===== 情感钩子文案 ===== */
#hookText {
  position: absolute;
  top: 80px;
  left: 0; right: 0;
  z-index: 20;
  text-align: center;
  padding: 0 24px;
  pointer-events: none;
}
#hookContent {
  display: inline-block;
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0,0,0,0.8);
  line-height: 1.5;
  background: rgba(0,0,0,0.25);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: 12px;
  padding: 8px 16px;
  transition: opacity 0.2s;
}
#hookText.animating #hookContent { opacity: 0; }

/* ===== 右侧操作按钮 ===== */
#sideActions {
  position: absolute;
  right: 16px;
  bottom: calc(var(--narrative-h) + 60px + var(--safe-bottom));
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.side-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.15s;
}
.side-btn:active { transform: scale(0.9); }

/* ===== 剧名标签 ===== */
#dramaLabel {
  position: absolute;
  left: 16px;
  bottom: calc(var(--narrative-h) + 56px + var(--safe-bottom));
  z-index: 20;
  opacity: 0;
  transition: opacity 0.8s ease;
  pointer-events: none;
}
#dramaLabel.visible { opacity: 1; }
#dramaLabelText {
  font-size: 13px;
  color: rgba(255,255,255,0.75);
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

/* ===== 节点圆点 ===== */
#progressDots {
  position: absolute;
  right: 16px;
  bottom: calc(var(--narrative-h) + 56px + var(--safe-bottom));
  z-index: 20;
  display: flex;
  gap: 5px;
  align-items: center;
}
.progress-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
  transition: all 0.2s;
}
.progress-dot.active {
  background: var(--color-primary);
  width: 18px;
  border-radius: 3px;
}
.progress-dot.visited {
  background: rgba(255,255,255,0.6);
}

/* ===== 叙事进度条 ===== */
#narrativeBar {
  position: absolute;
  bottom: var(--safe-bottom);
  left: 0; right: 0;
  height: var(--narrative-h);
  z-index: 20;
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, transparent 100%);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  padding: 0 12px 8px;
  gap: 2px 8px;
  pointer-events: none;
}
.node-label {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.4);
  justify-self: center;
}
.node-label.node-current {
  width: 8px; height: 8px;
  background: var(--color-primary);
}
.node-label-text {
  font-size: 12px;
  line-height: 1.3;
  text-align: center;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.prev-text, .next-text {
  color: rgba(255,255,255,0.45);
  font-size: 11px;
}
.current-text {
  color: #fff;
  font-weight: 600;
  font-size: 13px;
}

/* ===== 视频进度条 ===== */
#videoProgress {
  position: absolute;
  bottom: calc(var(--narrative-h) + var(--safe-bottom));
  left: 0; right: 0;
  height: 2px;
  background: rgba(255,255,255,0.15);
  z-index: 21;
}
#videoProgressBar {
  height: 100%;
  background: var(--color-primary);
  width: 0%;
  transition: width 0.5s linear;
}

/* ===== 剧集卡片 ===== */
#endCardOverlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
#endCardOverlay.visible {
  opacity: 1;
  pointer-events: auto;
}
#endCard {
  width: 100%;
  background: #1a1a1a;
  border-radius: 20px 20px 0 0;
  padding: 24px 20px calc(20px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.25,0.46,0.45,0.94);
  position: relative;
}
#endCardOverlay.visible #endCard { transform: translateY(0); }
#endCardClose {
  position: absolute;
  top: 16px; right: 16px;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.end-genre {
  font-size: 12px;
  color: var(--color-primary);
  font-weight: 600;
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.end-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
}
.end-meta {
  font-size: 13px;
  color: var(--color-muted);
  margin-bottom: 12px;
}
.end-desc {
  font-size: 14px;
  color: rgba(255,255,255,0.7);
  line-height: 1.6;
  margin-bottom: 24px;
}
.end-actions {
  display: flex;
  gap: 12px;
}
.btn-secondary {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255,255,255,0.1);
  font-size: 14px;
  font-weight: 600;
}
.btn-primary {
  flex: 2;
  padding: 12px;
  border-radius: 12px;
  background: var(--color-primary);
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

/* ===== 长按菜单 ===== */
#menuOverlay, #charSubmenuOverlay, #moodSubmenuOverlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
#menuOverlay.visible, #charSubmenuOverlay.visible, #moodSubmenuOverlay.visible {
  opacity: 1;
  pointer-events: auto;
}
#menuSheet, #charSheet, #moodSheet {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: #1c1c1e;
  border-radius: 20px 20px 0 0;
  padding: 12px 0 calc(16px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.25,0.46,0.45,0.94);
}
#menuOverlay.visible #menuSheet,
#charSubmenuOverlay.visible #charSheet,
#moodSubmenuOverlay.visible #moodSheet {
  transform: translateY(0);
}
.menu-handle {
  width: 36px; height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  text-align: left;
  transition: background 0.15s;
}
.menu-item:active { background: rgba(255,255,255,0.05); }
.menu-item.danger .menu-text { color: #ff453a; }
.menu-icon { font-size: 22px; width: 32px; text-align: center; }
.menu-text { font-size: 16px; font-weight: 500; flex: 1; }
.menu-sub { font-size: 12px; color: var(--color-muted); }
.menu-cancel {
  width: calc(100% - 32px);
  margin: 8px 16px 0;
  padding: 14px;
  background: rgba(255,255,255,0.08);
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}
.submenu-title {
  font-size: 14px;
  color: var(--color-muted);
  text-align: center;
  padding: 0 20px 12px;
}
#charList {
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  gap: 4px;
}
.char-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(255,255,255,0.05);
  font-size: 16px;
  transition: background 0.15s;
}
.char-btn:active { background: rgba(255,255,255,0.1); }
.char-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700;
}
#moodGrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 16px 16px;
}
.mood-btn {
  padding: 14px;
  background: rgba(255,255,255,0.07);
  border-radius: 12px;
  font-size: 15px;
  text-align: center;
  transition: background 0.15s;
}
.mood-btn:active { background: rgba(255,255,255,0.15); }

/* ===== Toast ===== */
#toast {
  position: fixed;
  bottom: calc(120px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(30,30,30,0.92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  white-space: nowrap;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== 剧库 Tab ===== */
.library-header {
  padding: calc(var(--safe-top) + 60px) 20px 16px;
}
.library-header h2 { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.library-sub { font-size: 14px; color: var(--color-muted); }
#dramaCards {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 0 16px calc(40px + var(--safe-bottom));
}
.drama-card {
  background: #1a1a1a;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.drama-card-thumb {
  height: 180px;
  background-size: cover;
  background-position: center;
  position: relative;
}
.drama-card-play {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.3);
}
.drama-card-info {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drama-card-title { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.drama-card-meta { font-size: 12px; color: var(--color-muted); }
.drama-card-tag {
  font-size: 11px;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  border-radius: 6px;
  padding: 3px 8px;
  white-space: nowrap;
}

/* ===== 我的 Tab ===== */
.mine-header {
  padding: calc(var(--safe-top) + 60px) 20px 16px;
}
.mine-header h2 { font-size: 28px; font-weight: 700; }
.mine-section { padding: 0 16px 24px; }
.mine-section-title {
  font-size: 13px;
  color: var(--color-muted);
  margin-bottom: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
#historyList { display: flex; flex-direction: column; gap: 12px; }
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #1a1a1a;
  border-radius: 12px;
  padding: 12px;
}
.history-thumb {
  width: 64px; height: 64px;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}
.history-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.history-sub { font-size: 12px; color: var(--color-muted); }
.history-empty { color: var(--color-muted); font-size: 14px; text-align: center; padding: 32px 0; }
.btn-reset {
  width: 100%;
  padding: 14px;
  background: rgba(255,255,255,0.06);
  border-radius: 14px;
  font-size: 15px;
  color: rgba(255,255,255,0.5);
}

/* ===== 竖屏锁定提示 ===== */
#rotatePrompt {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  background: #000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  font-size: 16px;
  color: var(--color-muted);
}
@media (orientation: landscape) {
  #rotatePrompt { display: flex; }
}
