:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #2b2f36;
  --muted: #7a828c;
  --line: #e3e7ec;
  --brand: #2f7fd6;
  --brand-2: #5aa0e6;
  --accent: #e0557f;
  --shadow: 0 6px 24px rgba(30, 20, 10, .10);
  --radius: 14px;
  --topbar: linear-gradient(135deg, #ffffff, #eef2f6);
  --topbar-text: #2b2f36;
  --topbar-accent: #2f7fd6;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.6;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; justify-content: flex-start;
  height: 52px; flex: 0 0 52px; padding: 0 20px;
  background: var(--topbar);
  color: var(--topbar-text); box-shadow: 0 2px 10px rgba(0,0,0,.18);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 17px; font-weight: 700; letter-spacing: .4px; }
.topbar-title span { color: var(--topbar-accent); }
.topbar-nav { display: flex; gap: 18px; align-items: center; margin-left: 22px; }
.topbar-nav a {
  color: var(--topbar-text); text-decoration: none; font-size: 13px; opacity: .82;
  padding: 4px 2px; transition: .15s; border-bottom: 2px solid transparent;
}
.topbar-nav a:hover { opacity: 1; color: var(--topbar-accent); }
.topbar-nav a.active { opacity: 1; color: var(--topbar-accent); border-bottom-color: var(--topbar-accent); }
.topbar-actions { display: flex; gap: 10px; align-items: center; margin-left: auto; }
.topbar-actions a, .topbar-actions button {
  background: color-mix(in srgb, var(--topbar-text) 12%, transparent); color: var(--topbar-text);
  border: 1px solid color-mix(in srgb, var(--topbar-text) 20%, transparent); padding: 7px 14px;
  border-radius: 8px; cursor: pointer; font-size: 13px; transition: .15s;
  text-decoration: none; display: inline-block;
}
.topbar-actions a:hover, .topbar-actions button:hover { background: color-mix(in srgb, var(--topbar-text) 22%, transparent); }
.topbar-actions .wb-user { font-size: 13px; opacity: .9; cursor: pointer; user-select: none; }
/* 保存到云端 / 从云端导入 / 登出 已统一收进头像弹出菜单，隐藏顶栏独立按钮 */
.topbar-actions #wbSave, .topbar-actions #wbRestore, .topbar-actions #wbLogout { display: none !important; }
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 14px;
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-primary { background: linear-gradient(90deg, var(--brand), var(--brand-2)); color: #fff; border: none; }
.btn-ghost { background: transparent; }
.container { max-width: 1320px; margin: 28px auto; padding: 0 18px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
}
input, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit;
}
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.msg { margin-top: 12px; font-size: 14px; min-height: 20px; }
.msg.err { color: #e5484d; }
.msg.ok { color: #2e9e5b; }
.searchbox { display: flex; gap: 10px; }
.searchbox input { flex: 1; }
.world-item {
  display: flex; align-items: center; gap: 14px; cursor: pointer;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); margin-bottom: 12px; transition: transform .12s ease, box-shadow .12s ease;
}
.world-item:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.world-item .meta { flex: 1; min-width: 0; }
.world-item .title { font-weight: 600; font-size: 16px; }
.world-item .snippet { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.world-item .likes { color: var(--accent); font-weight: 600; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* 阅读页 */
.read-layout { display: grid; grid-template-columns: 240px 1fr 300px; gap: 18px; align-items: start; }
.sidebar { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
.rightbar { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; padding: 16px; }
.side-section { font-size: 13px; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .04em; }
.side-item {
  padding: 9px 12px; border-radius: 9px; cursor: pointer; font-size: 14px;
  border: 1px solid transparent;
}
.side-item:hover { background: var(--bg); }
.side-item.active { background: var(--bg); border-color: var(--line); font-weight: 600; }
.side-item.sub { padding-left: 24px; font-size: 13px; color: var(--muted); }
.read-content { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; scroll-margin-top: 76px; }
.read-content h1 { margin-top: 0; }
.prose p { margin: 0 0 14px; white-space: pre-wrap; }
.like-btn { display: inline-flex; align-items: center; gap: 8px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: 12px; color: var(--muted); }

/* 阅读页：右侧栏「改编续写」派生列表 */
.rightbar-head { font-size: 15px; font-weight: 700; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.rightbar-hint { font-size: 13px; color: var(--muted); padding: 8px 2px; }
.fork-item { display: block; text-decoration: none; color: var(--text); padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); margin-bottom: 10px; background: var(--bg); transition: transform .15s ease, border-color .15s ease; }
.fork-item:hover { border-color: var(--accent); transform: translateY(-1px); }
.fork-item.fork-orig { background: color-mix(in srgb, var(--accent) 10%, var(--panel)); border-color: var(--accent); }
.fork-item.fork-orig:hover { border-color: var(--accent); transform: translateY(-1px); }
.fork-item.fork-orig.fork-locked { background: var(--bg); border-color: var(--line); cursor: not-allowed; opacity: .62; }
.fork-item.fork-orig.fork-locked .fork-meta { color: var(--muted); }
.fork-item.fork-orig.fork-locked:hover { transform: none; border-color: var(--line); }
.fork-meta { font-size: 11px; color: var(--accent); margin-bottom: 3px; font-weight: 600; }
.fork-name { font-size: 14px; font-weight: 600; line-height: 1.35; margin-bottom: 3px; }
.fork-sub { font-size: 12px; color: var(--muted); }

@media (max-width: 1080px) {
  .read-layout { grid-template-columns: 220px 1fr; }
  .rightbar { grid-column: 1 / -1; position: static; max-height: none; }
}
@media (max-width: 720px) {
  .read-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .rightbar { position: static; max-height: none; }
}

/* 发现页：世界设定标签 */
.set-label { font-size: 12px; color: var(--brand); font-weight: 600; margin: 4px 0 2px; }

/* 发现页：三栏榜单（收藏/点赞/热度） */
.rank-cols { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.rank-col { min-width: 0; }   /* 防止长文本把网格撑爆导致两栏宽度不均 */
.rank-col h3 { margin: 0 0 12px; font-size: 15px; }
.rank-col .empty { padding: 20px 0; }
.world-item { align-items: flex-start; }
.rank-no { font-size: 20px; font-weight: 700; color: var(--brand); min-width: 28px; padding-top: 2px; }
.world-item .likes.hot { color: #e0863a; }
.world-item .likes.fav { color: #e0a800; }
@media (max-width: 720px) {
  .rank-cols { grid-template-columns: 1fr; }
}

/* 阅读页：侧栏树形（设定集 / 章节） */
.side-group { margin-top: 4px; }
.side-grp-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; color: var(--muted); margin: 14px 0 6px;
  text-transform: uppercase; letter-spacing: .04em; cursor: pointer; user-select: none;
}
.side-grp-head:hover { color: var(--text); }
.caret { font-size: 11px; display: inline-block; transition: transform .15s ease; }
.chap-head { font-weight: 600; }

/* 阅读页：正文与对话条目（隐藏角色/用户小标签，用左侧色条区分） */
.prose { margin: 0 0 14px; white-space: pre-wrap; line-height: 1.75; }
.dlg-text { border-left: 3px solid var(--line); padding-left: 12px; margin: 0 0 16px; }
.dlg-text.dlg-ai { border-left-color: var(--brand); }
.dlg-text.dlg-user { border-left-color: var(--muted); }

/* 阅读页：控件 / 进度 / 翻页 */
.read-controls { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.story-nav { display: flex; gap: 6px; margin-left: auto; }
.progress-wrap { height: 6px; background: var(--bg); border-radius: 4px; margin-top: 10px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .2s ease; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 12px; font-size: 13px; color: var(--muted); }

/* 阅读页：底部导航条（上一篇/下一篇 + 上一页/下一页） */
.read-bottom {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap; justify-content: space-between;
  margin: 16px auto 40px; padding: 14px 18px; max-width: 960px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.read-bottom .pager { margin-top: 0; justify-content: flex-start; }
.read-bottom .bottom-story { display: flex; gap: 8px; margin-left: auto; }

/* 目录 / 进度 弹窗目录项 */
.toc-group { margin: 10px 0 16px; }
.toc-head { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.toc-item { padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.toc-item:hover { background: var(--bg); }

/* 阅读底色主题（绿 / 棕 / 黑 / 白）：整站背景 + 阅读区 + 侧栏 + 底部栏 同步变化 */
/* ---------- 全局底色（绿/棕/黑/白）：用变量覆盖，对所有页面通用 ---------- */
body.rt-brown {
  --bg:#efe2cb; --panel:#fbf4e6; --text:#4a3826; --muted:#8a7355; --line:#e3d3b6;
  --brand:#b9893f; --brand-2:#d8a85a; --accent:#e08aa0;
  --topbar:linear-gradient(135deg,#6b4f3a,#8a6a4a); --topbar-text:#f5ecdd; --topbar-accent:#f0c08a;
}
body.rt-green {
  --bg:#e3eddf; --panel:#f1f7ed; --text:#2e4a2c; --muted:#5a7a55; --line:#cfe3c8;
  --brand:#4f9e5b; --brand-2:#7ec46f; --accent:#e08aa0;
  --topbar:linear-gradient(135deg,#3f7a4a,#5a9e6a); --topbar-text:#eef5ea; --topbar-accent:#d6f0c8;
}
body.rt-dark {
  --bg:#16181d; --panel:#22252c; --text:#d8d4cc; --muted:#9aa0ac; --line:#33384a;
  --brand:#7e6efc; --brand-2:#6aa6f8; --accent:#ff6b9a;
  --topbar:linear-gradient(135deg,#2a2d36,#3a3f4d); --topbar-text:#d8d4cc; --topbar-accent:#9aa0ff;
}
/* 白：干净通透，强调色用蓝 */
body.rt-white {
  --bg:#f4f6f8; --panel:#ffffff; --text:#2b2f36; --muted:#7a828c; --line:#e3e7ec;
  --brand:#2f7fd6; --brand-2:#5aa0e6; --accent:#e0557f;
  --topbar:linear-gradient(135deg,#ffffff,#eef2f6); --topbar-text:#2b2f36; --topbar-accent:#2f7fd6;
}

/* 阅读页特定细节：跟随主题变量，任意底色均生效 */
.dlg-text.dlg-ai { border-left-color: var(--brand); }
.dlg-text.dlg-user { border-left-color: var(--line); }
.progress-bar { background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.set-label { color: var(--brand); }
.side-item.active { background: color-mix(in srgb, var(--brand) 16%, var(--panel)); }
.side-item:hover { background: color-mix(in srgb, var(--brand) 9%, var(--panel)); }
.toc-item:hover { background: color-mix(in srgb, var(--brand) 9%, var(--panel)); }
.read-controls .mini, .read-bottom .mini {
  background: color-mix(in srgb, var(--brand) 12%, var(--panel));
  border-color: var(--line); color: var(--text);
}
.read-content .prose { color: var(--text); }

/* 通用弹窗（目录/进度等）：跟随主题、响应式 */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(20, 16, 10, .45); backdrop-filter: blur(3px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%; max-width: 560px; max-height: 86vh; overflow: auto;
  animation: modalPop .2s cubic-bezier(.2, .8, .3, 1);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 20px; }
@keyframes modalPop { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }

/* 顶栏窄屏响应式：不溢出、可换行 */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; min-height: 52px; padding: 8px 12px; gap: 6px; }
  .topbar-title { font-size: 15px; }
  .topbar-nav { margin-left: 0; gap: 12px; }
  .topbar-nav a { font-size: 12px; }
  .topbar-actions { margin-left: auto; gap: 6px; }
  .topbar-actions button, .topbar-actions a { padding: 6px 10px; font-size: 12px; }
  .modal-overlay { padding: 12px; }
  .modal { max-width: 100%; max-height: 90vh; }
}

/* 阅读页：头部操作区（点赞 / 收藏 / 克隆 / 续写 / 目录） */
.read-head-top { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.read-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.fav-btn.faved { background: color-mix(in srgb, var(--accent) 16%, var(--panel)); border-color: var(--accent); color: var(--accent); }
.era-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.era-head h2 { margin: 0; }
.era-head-actions { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
.era-like-btn { display: inline-flex; align-items: center; gap: 8px; }
.era-adapt-btn { display: inline-flex; align-items: center; gap: 8px; }
.mini:disabled, .btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

/* 阅读页：底部导航（顺序：上一篇 / 上一页 / 下一页 / 下一篇） */
.read-bottom { justify-content: center; }
.bottom-nav { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
.bottom-nav .page-info { font-size: 13px; color: var(--muted); padding: 0 2px; white-space: nowrap; }

/* 发现页：收藏栏（默认折叠，位于排行榜上方） */
.fav-card .fav-head { display: flex; align-items: center; justify-content: space-between; cursor: pointer; user-select: none; }
.fav-card .fav-head h2 { margin: 0; cursor: pointer; }
.fav-card .caret { font-size: 14px; color: var(--muted); transition: transform .15s ease; }
.fav-body { margin-top: 12px; }


