/* ============================================================
   经典古籍阅读 · 全屏/阅读增强样式（外置）
   功能：纯色护眼主题、左文右讲解两栏布局、全屏工具栏、非全屏内联导航
   布局采用【静态选择器 + body[data-page] 标记】，不依赖动态 class，
   切换章节时 React 重渲染不丢布局（无"讲解先下后右"闪烁）。
   ============================================================ */

/* 隐藏平台水印（豆包 AI 生成 / 由飞书妙搭提供支持） */
doubao-watermark,
[data-custom-element="doubao-watermark"],
[data-custom-element="doubao-watermark-mobile"] {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* ============================================================
   全屏主题：纯色背景（深色墨绿 / 浅色羊皮纸）+ 隐藏模拟黑板光照/噪点
   ============================================================ */
/* 全屏容器禁用所有过渡/动画：进入与退出均立即生效，
   避免退出动画期间深色背景淡出覆盖页面（黑屏 + 卡顿不流畅） */
[data-fs-theme] {
  transition: none !important;
  animation: none !important;
}
[data-fs-theme="dark"] { background: #1c2b26 !important; }
[data-fs-theme="light"] { background: #f7f1e3 !important; }
[data-fs-theme] > div.fixed.inset-0 { display: none !important; }

/* ---------- 浅色主题：白字反转深色（后定义优先） ---------- */
[data-fs-theme="light"] [class*="text-white"] { color: #3b3226 !important; }
[data-fs-theme="light"] [class*="text-white/"] { color: rgba(59, 50, 38, .74) !important; }
[data-fs-theme="light"] [class*="text-white/30"] { color: rgba(59, 50, 38, .38) !important; }
[data-fs-theme="light"] [class*="text-white/40"] { color: rgba(59, 50, 38, .46) !important; }
[data-fs-theme="light"] [class*="text-white/60"] { color: rgba(59, 50, 38, .64) !important; }
[data-fs-theme="light"] [class*="text-white/70"] { color: rgba(59, 50, 38, .72) !important; }
[data-fs-theme="light"] [class*="text-yellow-"] { color: #8a6a1f !important; }
[data-fs-theme="light"] [class*="border-white"] { border-color: rgba(120, 100, 70, .28) !important; }
[data-fs-theme="light"] [class*="border-dashed"] { border-color: rgba(120, 100, 70, .3) !important; }
[data-fs-theme="light"] [class*="bg-white/"] { background: rgba(255, 255, 255, .5) !important; }
[data-fs-theme="light"] [class*="bg-white/5"] { background: rgba(255, 255, 255, .55) !important; }
[data-fs-theme="light"] [class*="bg-white/10"] { background: rgba(255, 255, 255, .6) !important; }
[data-fs-theme="light"] [class*="bg-white/20"] { background: rgba(255, 255, 255, .68) !important; }

/* 全屏讲解卡：浅色下给浅底 + 细边框，弱化 tab 分隔 */
[data-fs-theme="light"] .space-y-12 > div[class*="border-t-2"] {
  border-left: 1px solid rgba(120, 100, 70, .22) !important;
}
/* 浅色：选中 tab 高亮（加强边框/投影，与未选中区分） */
[data-fs-theme="light"] [class*="border-white/40"] {
  border-color: rgba(120, 100, 70, .5) !important;
  box-shadow: 0 1px 6px rgba(90, 70, 40, .12);
}

/* ---------- 全屏内容容器加宽 ---------- */
[data-fs-theme] > .relative.max-w-4xl {
  max-width: 1640px !important;
  width: 100% !important;
  padding-left: 32px !important;
  padding-right: 32px !important;
}

/* ============================================================
   全屏两栏：左文右讲解（静态选择器，无需动态 class）
   ============================================================ */
[data-fs-theme] .space-y-12 {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 40%) !important;
  gap: 44px !important;
  align-items: start !important;
}
[data-fs-theme] .space-y-12 > * { margin-top: 0 !important; }
[data-fs-theme] .space-y-12 > :first-child { grid-column: 1; }
[data-fs-theme] .space-y-12 > article { grid-column: 1; }
[data-fs-theme] .space-y-12 > div[class*="border-t-2"] {
  grid-column: 2;
  grid-row: 1 / span 30;
  border-top: none !important;
  border-left: 1px solid rgba(255, 255, 255, .16);
  padding-left: 36px;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

/* 全屏标题区：一行显示（书名 + 章标题同行），降低高度 */
[data-fs-theme] .space-y-12 > :first-child {
  display: flex !important;
  align-items: baseline !important;
  justify-content: center !important;
  gap: 12px !important;
  padding-top: 0 !important;
  margin-bottom: 0 !important;
}
[data-fs-theme] .space-y-12 > :first-child > div {
  font-size: 1rem !important;
  margin-bottom: 0 !important;
}
[data-fs-theme] .space-y-12 > :first-child h1 {
  font-size: 1.7rem !important;
  line-height: 1.25 !important;
  margin: 0 !important;
}

/* ---------- 全屏悬浮工具栏（挂 body 顶层，规避容器 transform 导致的 fixed 失效） ---------- */
.fs-enh-toolbar {
  position: fixed !important;
  top: 16px !important;
  right: 16px !important;
  z-index: 2147483000 !important;
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(28, 43, 38, .82);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 999px;
  padding: 6px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .3);
}
.fs-enh-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 11px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  transition: all .2s;
  white-space: nowrap;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
.fs-enh-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .28); }
.fs-enh-btn:disabled { opacity: .35; cursor: not-allowed; }
.fs-enh-btn.primary { background: rgba(255, 255, 255, .22); }
.fs-enh-btn.marked { background: #16a34a !important; color: #fff !important; }
.fs-enh-btn.ghost { background: rgba(0, 0, 0, .05); color: #444; border: 1px solid rgba(0, 0, 0, .1); }
.fs-enh-btn.ghost:hover:not(:disabled) { background: rgba(0, 0, 0, .1); }

/* 浅色主题下的工具栏配色 */
[data-fs-theme="light"] .fs-enh-toolbar {
  background: rgba(255, 251, 240, .92);
  border-color: rgba(120, 100, 70, .25);
  box-shadow: 0 8px 32px rgba(90, 70, 40, .18);
}
[data-fs-theme="light"] .fs-enh-btn { color: #4a3f30; background: rgba(120, 100, 70, .1); }
[data-fs-theme="light"] .fs-enh-btn:hover:not(:disabled) { background: rgba(120, 100, 70, .2); }
[data-fs-theme="light"] .fs-enh-btn.primary { background: rgba(120, 100, 70, .18); }
[data-fs-theme="light"] .fs-enh-btn.marked { background: #16a34a !important; color: #fff !important; }

/* 全屏：隐藏容器自带的"退出全屏"按钮（与工具栏重叠，功能由工具栏"✕ 退出"承担） */
[data-fs-theme] > button[class*="top-6 right-6"] { display: none !important; }

/* ============================================================
   非全屏章节页：内容容器加宽 + 两栏布局（静态选择器，切章不丢）
   ============================================================ */
body[data-page="chapter"] main > div[class*="max-w-3xl"] {
  max-width: 1440px !important;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 38%) !important;
  gap: 36px !important;
  align-items: start !important;
}
body[data-page="chapter"] main > div[class*="max-w-3xl"] > * { margin-top: 0 !important; }
/* 顶部工具条跨两栏 */
body[data-page="chapter"] main > div[class*="max-w-3xl"] > div:first-child { grid-column: 1 / -1; }
/* 正文左列 */
body[data-page="chapter"] main > div[class*="max-w-3xl"] > div[class*="glass-soft"] { grid-column: 1; }
/* 讲解右栏：与标题卡同排顶部对齐（grid-row 2），sticky */
body[data-page="chapter"] main > div[class*="max-w-3xl"] > div[class*="border-primary"] {
  grid-column: 2;
  grid-row: 2 / span 40;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
/* 文章标题卡：一行显示（书名 + 章标题同行），降低高度 */
body[data-page="chapter"] main > div[class*="max-w-3xl"] > div[class*="glass-card"][class*="text-center"] {
  display: flex !important;
  align-items: baseline !important;
  justify-content: center !important;
  gap: 12px !important;
  padding: 8px 16px !important;
  margin-bottom: 0 !important;
}
body[data-page="chapter"] main > div[class*="max-w-3xl"] > div[class*="glass-card"][class*="text-center"] > div {
  margin-bottom: 0 !important;
}
body[data-page="chapter"] main > div[class*="max-w-3xl"] > div[class*="glass-card"][class*="text-center"] h1,
body[data-page="chapter"] main > div[class*="max-w-3xl"] > div[class*="glass-card"][class*="text-center"] h2,
body[data-page="chapter"] main > div[class*="max-w-3xl"] > div[class*="glass-card"][class*="text-center"] h3 {
  font-size: 1.4rem !important;
  margin: 0 !important;
}

/* ============================================================
   字体大小 + 加粗（全局：非全屏正文/讲解 + 全屏正文/讲解）
   档位：标准 1.26rem / 大 1.52rem / 超大 1.78rem
   ============================================================ */
html[data-guji-font="normal"] article,
html[data-guji-font="normal"] body[data-page="chapter"] main div[class*="glass-soft"],
html[data-guji-font="normal"] body[data-page="chapter"] main div[class*="border-primary"],
html[data-guji-font="normal"] [data-fs-theme] .space-y-12 div[class*="border-t-2"] { font-size: 1.26rem !important; }
html[data-guji-font="large"] article,
html[data-guji-font="large"] body[data-page="chapter"] main div[class*="glass-soft"],
html[data-guji-font="large"] body[data-page="chapter"] main div[class*="border-primary"],
html[data-guji-font="large"] [data-fs-theme] .space-y-12 div[class*="border-t-2"] { font-size: 1.52rem !important; }
html[data-guji-font="xl"] article,
html[data-guji-font="xl"] body[data-page="chapter"] main div[class*="glass-soft"],
html[data-guji-font="xl"] body[data-page="chapter"] main div[class*="border-primary"],
html[data-guji-font="xl"] [data-fs-theme] .space-y-12 div[class*="border-t-2"] { font-size: 1.78rem !important; }
html[data-guji-bold="1"] article,
html[data-guji-bold="1"] body[data-page="chapter"] main div[class*="glass-soft"],
html[data-guji-bold="1"] body[data-page="chapter"] main div[class*="border-primary"],
html[data-guji-bold="1"] [data-fs-theme] .space-y-12 div[class*="border-t-2"] { font-weight: 650 !important; }

/* ============================================================
   非全屏：顶部工具条内联导航（返回按钮 与 全屏讲解 之间，非悬浮）
   ============================================================ */
.fs-inline-nav {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 2px;
  flex-wrap: wrap;
  justify-content: center;
}
.fs-inline-nav .fs-enh-btn.ghost {
  background: rgba(0, 0, 0, .05);
  color: #444;
  border: 1px solid rgba(0, 0, 0, .1);
}
.fs-inline-nav .fs-enh-btn.ghost:hover:not(:disabled) { background: rgba(0, 0, 0, .1); }
.fs-inline-nav .fs-enh-btn:disabled { opacity: .35; cursor: not-allowed; }
