/* ============================================================
   Interactive Story Platform — 全局样式（移动端优先，暗色主题）
   ============================================================ */

:root {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --border: #e3e9f3;
  --text: #1b2434;
  --text-dim: #6b7688;
  --accent: #4f6bff;
  --accent-2: #8a5bff;
  --accent-grad: linear-gradient(135deg, #4f6bff 0%, #8a5bff 100%);
  --gold: #e6a23c;
  --danger: #f56c6c;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 30px rgba(60, 80, 140, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }

/* ---------- 布局容器 ---------- */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 80px;
}

/* ---------- 顶部栏 ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.78);
  border-bottom: 1px solid var(--border);
}
.appbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.3px;
}
.brand .logo {
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand .dot { color: var(--gold); }

/* ---------- 徽标版本 ---------- */
.badge {
  font-size: 11px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--bg-elev);
}

/* ---------- 首页 hero ---------- */
.hero {
  padding: 28px 0 8px;
}
.hero h1 {
  font-size: 26px;
  margin: 0 0 6px;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
}

/* ---------- 搜索 / 分类 ---------- */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 18px 0;
}
.search-box {
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 12px 14px 12px 40px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-box .icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
}
.tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.tag-btn {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: 0.15s;
}
.tag-btn.active {
  background: var(--accent-grad);
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}

/* ---------- 故事列表 ---------- */
.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}
.story-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
}
.story-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.story-cover {
  height: 110px;
  position: relative;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
}
.story-cover .emoji { font-size: 42px; filter: drop-shadow(0 2px 8px rgba(0,0,0,0.4)); }
.story-cover .endings {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 11px;
  background: rgba(0,0,0,0.55);
  padding: 2px 8px;
  border-radius: 999px;
}
.story-body { padding: 10px 12px 12px; }
.story-body h3 { margin: 0 0 4px; font-size: 15px; }
.story-body .desc {
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 0 0 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.story-body .meta { font-size: 11px; color: var(--text-dim); display: flex; gap: 8px; }

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 48px 0;
  font-size: 14px;
}

/* ---------- 故事阅读页 ---------- */
.story-page { min-height: 100vh; display: flex; flex-direction: column; }
.reader {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-top: 16px;
}
.story-header {
  position: relative;
  overflow: hidden;
  padding: 34px 26px;
  border-radius: var(--radius);
  color: #fff;
}
/* 深色蒙版：保证标题在任何封面渐变上都可读 */
.story-header::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(10, 16, 28, 0.62), rgba(10, 16, 28, 0.12));
  pointer-events: none;
}
.story-header > * { position: relative; z-index: 1; }
.story-header h1 {
  font-size: 24px;
  margin: 0 0 4px;
  color: #fff;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
}
.story-header .sub {
  color: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.progress {
  margin: 4px 0 14px;
}
.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-elev);
  overflow: hidden;
}
.progress-bar > span {
  display: block;
  height: 100%;
  background: var(--accent-grad);
  border-radius: 999px;
  transition: width 0.35s;
}
.progress-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
}

/* 故事内容节点 */
.node-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px;
  box-shadow: var(--shadow);
  transition: opacity 0.3s ease;
}
/* 已读（走过/选过）节点：降低透明度，聚焦未读内容 */
.node-card.node-passed {
  opacity: 0.45;
}
.node-text {
  font-size: 17px;
  line-height: 1.8;
  white-space: pre-wrap;
}
.node-media {
  margin: 0 0 18px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.node-media img,
.node-media video {
  width: 100%;
  display: block;
  border-radius: var(--radius-sm);
}

/* 结局样式 */
.ending-banner {
  margin-top: 24px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(108,139,255,0.16), rgba(176,108,255,0.16));
  border: 1px solid rgba(108,139,255,0.4);
  text-align: center;
}
.ending-banner .label {
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.ending-banner .title {
  font-size: 26px;
  font-weight: 800;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 4px 0 8px;
}
.ended-earned { color: var(--gold); font-size: 13px; }

/* 选项按钮 */
.choices {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 22px;
}
.choice-btn {
  padding: 16px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  transition: 0.15s;
  display: flex;
  align-items: center;
  gap: 12px;
}
.choice-btn:hover {
  border-color: var(--accent);
  background: rgba(108,139,255,0.12);
  transform: translateX(4px);
}
.choice-btn .num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* 底部操作栏 */
.reader-actions {
  display: flex;
  gap: 10px;
  margin: 20px 0 8px;
  flex-wrap: wrap;
}
.btn {
  padding: 12px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent-grad); border-color: transparent; color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }

/* 结局收集（成就） */
.collect {
  margin-top: 26px;
  padding: 18px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.collect h4 { margin: 0 0 12px; font-size: 14px; color: var(--text-dim); }
.ending-chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  border: 1px dashed var(--border);
  color: var(--text-dim);
}
.chip.earned {
  background: var(--accent-grad);
  color: #fff;
  border: none;
  font-weight: 600;
}
.chip.locked {
  width: 48px;
  height: 48px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  font-size: 20px;
  color: var(--text-dim);
  background: var(--bg-elev);
}
.collect-count { color: var(--text-dim); font-size: 13px; font-weight: 400; margin-left: 6px; }

/* 评论区（MVP 本地） */
.comments { margin-top: 26px; }
.comments h4 { font-size: 15px; margin: 0 0 12px; }
.comment-form { display: flex; gap: 10px; margin: 18px 0 14px; }
.comment-form input {
  flex: 1;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.comment-form input:focus { border-color: var(--accent); }
.comment-list { display: flex; flex-direction: column; gap: 10px; }
.comment {
  padding: 12px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.comment .who { font-weight: 600; font-size: 13px; }
.comment .when { color: var(--text-dim); font-size: 11px; margin-left: 8px; }
.comment .body { margin-top: 6px; font-size: 14px; }

/* 返回顶部/加载 */
.loading { text-align: center; color: var(--text-dim); padding: 48px 0; }
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 内联展开：段落块 / 非剧情反馈 / 已选状态 */
.node-block { margin-top: 18px; }
.node-block:first-child { margin-top: 0; }

/* 非剧情文字（淡蓝，角色心理反馈） */
.fb-inline {
  margin: 10px 0 0 4px;
  padding-left: 12px;
  border-left: 3px solid rgba(108, 139, 255, 0.5);
  color: #6f8fff;
  font-size: 15px;
  line-height: 1.7;
}

/* 已走过的选项 */
.choice-btn.done { opacity: 0.55; }
.choice-btn.selected {
  border-color: var(--accent);
  background: rgba(108, 139, 255, 0.12);
  opacity: 1;
}
.choice-btn.selected span:last-child {
  color: #2ea043;
  font-weight: 600;
}
.choice-btn:disabled { cursor: not-allowed; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 14px;
  opacity: 0;
  transition: 0.25s;
  z-index: 50;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 背景音乐开关（悬浮） */
.sound-fab {
  position: fixed;
  right: 18px;
  bottom: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  transition: 0.15s;
}
.sound-fab:hover { border-color: var(--accent); transform: scale(1.05); }
.sound-fab.on { background: var(--accent-grad); border-color: transparent; color: #fff; }
@media (prefers-reduced-motion: reduce) { .sound-fab { transition: none; } }

/* ---------- 内容驱动氛围（CSS 特效）---------- */
.atmo {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}
.atmo .snow { position: absolute; inset: 0; display: none; }
body.atmo-snow .atmo .snow { display: block; }
.atmo .snow i {
  position: absolute;
  top: -20px;
  background: #fff;
  border-radius: 50%;
  opacity: 0.9;
  animation: snowFall linear infinite;
}
@keyframes snowFall {
  from { transform: translateY(-20px); }
  to { transform: translateY(110vh); }
}

.atmo .rain { position: absolute; inset: 0; display: none; }
body.atmo-rain .atmo .rain { display: block; }
.atmo .rain i {
  position: absolute;
  top: -40px;
  width: 1.5px;
  height: 34px;
  background: linear-gradient(rgba(120, 160, 220, 0), rgba(120, 160, 220, 0.55));
  animation: rainFall linear infinite;
}
@keyframes rainFall {
  from { transform: translateY(-40px); }
  to { transform: translateY(110vh); }
}

@media (prefers-reduced-motion: reduce) {
  .atmo .snow i,
  .atmo .rain i { animation: none; }
}

@media (max-width: 420px) {
  .story-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
