/* ==========================================================================
   TaleVant C 端主题 —— 「深夜藏书馆」
   --------------------------------------------------------------------------
   定调：暗色沉浸 + 轻奢叙事。受众是移动端海外华人玩家；产品是故事世界，
   视觉应当像一间点着蜡烛的藏书馆，而不是一个 SaaS 工具面板。
   记忆点：琥珀烛光（单一强调色）× 衬线展示字 × 暖暗底上的氛围光晕。
   所有规则限定在 #app 作用域（运营后台 admin.html 无 #app，不受影响）。
   ========================================================================== */

/* ---- 令牌：在 #app 上重定义基础变量，全部现有组件自动换肤 ---- */
#app {
  --bg: #131009;
  --panel: #1c1812;
  --panel-2: #241f17;
  --text: #f2ecdf;
  --muted: #a3988a;
  --line: rgba(242, 236, 223, .12);
  --line-2: rgba(242, 236, 223, .07);
  --accent: #d9a441;
  --accent-soft: rgba(217, 164, 65, .14);
  --danger: #e06c5a;
  --danger-soft: rgba(224, 108, 90, .13);
  --ok: #7fb98a;
  --ok-soft: rgba(127, 185, 138, .13);
  --warn: #d9a441;
  --warn-soft: rgba(217, 164, 65, .12);

  --serif: "Fraunces", "Noto Serif SC", "Songti SC", serif;
  --ease: cubic-bezier(.16, 1, .3, 1);

  color-scheme: dark;   /* 原生控件（select 弹出层、日期选择器等）跟随暗色 */
  background: var(--bg);
  color: var(--text);
  position: relative;
  font-variant-numeric: tabular-nums;
}

/* select 弹出列表：部分浏览器不吃 color-scheme，显式给底色和字色 */
#app select option,
#app select optgroup {
  background: #241f17;
  color: #f2ecdf;
}

/* ---- 氛围层：烛光光晕 + 颗粒，替代纯色平铺 ---- */
#app::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(46rem 32rem at 85% -8%, rgba(217, 164, 65, .13), transparent 62%),
    radial-gradient(40rem 30rem at -18% 12%, rgba(122, 90, 248, .10), transparent 58%),
    radial-gradient(30rem 26rem at 50% 118%, rgba(217, 164, 65, .07), transparent 60%);
}
#app::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  opacity: .05; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
#app > * { position: relative; z-index: 1; }   /* 内容压在氛围层之上 */

/* ---- 字体：标题衬线化，正文保持无衬线内敛字体 ---- */
#app h1, #app h2, #app h3, #app .section-title, #app .brand,
#app .plot-title, #app .msg .who {
  font-family: var(--serif);
  letter-spacing: .01em;
}
#app .brand { font-size: 17px; font-weight: 650; }
#app .brand::first-letter { color: var(--accent); }
#app .section-title { font-size: 19px; font-weight: 620; }

/* ---- 顶栏：暗色玻璃 ---- */
#app .topbar {
  background: rgba(19, 16, 9, .78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-2);
}
#app .topnav a { border-radius: 8px; transition: color .16s ease, background .16s ease; }
#app .topnav a.active { background: transparent; color: var(--accent); position: relative; }
#app .topnav a.active::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 2px; height: 2px;
  border-radius: 2px; background: var(--accent);
}

/* ---- 卡片：书册质感（渐变描边 + 悬停烛光） ---- */
#app .card {
  background: linear-gradient(168deg, var(--panel) 0%, #191510 100%);
  border: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(242, 236, 223, .04);
}
#app .plot-card {
  position: relative; overflow: hidden;
  transition: transform .2s var(--ease), border-color .2s ease;
}
#app .plot-card::before {                 /* 书脊装饰条 */
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: linear-gradient(180deg, var(--accent), transparent 85%);
  opacity: .55; z-index: 2;
}
#app .plot-card:hover { transform: translateY(-3px); border-color: rgba(217, 164, 65, .45); }
#app .plot-cover {
  aspect-ratio: 3 / 4; width: calc(100% + 28px);         /* 出血到卡片边缘 */
  margin: -14px -14px 0;                                  /* 抵消卡片内边距 */
  overflow: hidden; position: relative;
}
#app .plot-cover img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform .35s var(--ease), filter .35s ease;
  filter: saturate(.92) brightness(.96);
}
#app .plot-card:hover .plot-cover img { transform: scale(1.04); filter: saturate(1) brightness(1); }
/* 程序化封面（用户自建剧情无图时的兜底） */
#app .plot-cover.proc {
  display: flex; align-items: center; justify-content: center;
  background-image: radial-gradient(ellipse at 70% 20%, rgba(242,236,223,.06), transparent 55%);
}
#app .plot-cover .proc-glyph {
  font-family: var(--font-display); font-size: 64px; font-weight: 620;
  opacity: .85; text-shadow: 0 2px 18px rgba(0,0,0,.45);
}
#app .plot-cover::after {                 /* 底部渐隐压到正文 */
  content: ""; position: absolute; inset: auto 0 0 0; height: 44%;
  background: linear-gradient(180deg, transparent, rgba(16,13,10,.72)); pointer-events: none;
}
#app .plot-body { position: relative; z-index: 1; }
#app .plot-title { font-size: 15.5px; font-weight: 620; }
#app .plot-sum {
  margin-top: 4px; font-size: 12.5px; line-height: 1.55; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---- 按钮：主按钮琥珀实底，悬停微抬 ---- */
#app .btn { border-radius: 10px; transition: transform .16s var(--ease), filter .16s ease; }
#app .btn.primary { background: var(--accent); border-color: var(--accent); color: #221a0c; font-weight: 620; }
#app .btn.primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
#app .btn:hover { background: var(--panel-2); }

/* ---- 表单 ---- */
#app input, #app textarea, #app select {
  background: rgba(242, 236, 223, .05);
  border-color: var(--line);
  color: var(--text);
}
#app input:focus, #app textarea:focus, #app select:focus {
  outline: 2px solid rgba(217, 164, 65, .55); outline-offset: 1px; border-color: transparent;
}
#app input::placeholder, #app textarea::placeholder { color: var(--muted); }

/* ---- AI 配图工具条 ---- */
#app .cover-tools {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px;
}
#app .cover-tools .btn[disabled] { opacity: .45; }
#app .cover-tools a { color: var(--accent); text-decoration: none; white-space: nowrap; }
#app .cover-tools a:hover { text-decoration: underline; }

/* ---- 对话 ---- */
#app .msg.user { background: rgba(217, 164, 65, .16); border: 1px solid rgba(217, 164, 65, .22); }
#app .msg.assistant { background: var(--panel-2); border: 1px solid var(--line-2); }
#app .composer textarea { background: rgba(242, 236, 223, .05); }

/* ---- 标签 / 提示 / 分隔 ---- */
#app .tag.gray { background: rgba(242, 236, 223, .08); color: var(--muted); }
#app .divider { background: var(--line-2); }
#app .loading, #app .empty { color: var(--muted); }

/* ---- 键盘焦点全局可见 ---- */
#app :focus-visible { outline: 2px solid rgba(217, 164, 65, .7); outline-offset: 2px; }

/* ---- 入场序列：错峰上浮（3 组节奏，60/120/180ms） ---- */
@media (prefers-reduced-motion: no-preference) {
  #app .wrap > * {
    animation: tv-rise .5s var(--ease) both;
  }
  #app .wrap > *:nth-child(2) { animation-delay: 60ms; }
  #app .wrap > *:nth-child(3) { animation-delay: 120ms; }
  #app .wrap > *:nth-child(4) { animation-delay: 180ms; }
  #app .grid > * { animation: tv-rise .45s var(--ease) both; }
  #app .grid > *:nth-child(2) { animation-delay: 60ms; }
  #app .grid > *:nth-child(3) { animation-delay: 120ms; }
  #app .grid > *:nth-child(4) { animation-delay: 180ms; }
  #app .grid > *:nth-child(5) { animation-delay: 240ms; }
  #app .grid > *:nth-child(n+6) { animation-delay: 300ms; }
}
@keyframes tv-rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  #app .wrap > *, #app .grid > * { animation: none !important; }
  #app * { transition-duration: .01ms !important; }
}

/* ---- 桌面居中栏：底色同步暗色 ---- */
@media (min-width: 640px) {
  body { background: #0a0908; }
  #app { box-shadow: 0 0 64px rgba(217, 164, 65, .06), 0 0 24px rgba(0, 0, 0, .55); }
}

/* ---- 窄屏顶栏：再压一档防重叠（衬线 brand 变宽后 390px 很紧） ---- */
@media (max-width: 420px) {
  #app .topbar { gap: 5px; padding: 0 10px; }
  #app .brand { font-size: 14.5px; letter-spacing: 0; }
  #app .topnav { gap: 0; }
  #app .topnav a { padding: 6px 5px; font-size: 12px; }
  #app .topbar select { font-size: 11px; padding: 5px 3px; max-width: 78px; }
  #app .topbar .btn.sm, #app .topbar a.btn { padding: 5px 8px; font-size: 12px; }
}
