:root{
  --font-sans:"Noto Sans SC",system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Apple Color Emoji","Segoe UI Emoji";
  --font-size-base:16px;
  --font-line-height:1.6;
  --font-weight-base:400;
  --font-letter-spacing:0px;
  --radius:16px;
  --radius-sm:12px;
  --shadow:0 12px 28px rgba(15, 23, 42, .08);
  --shadow-sm:0 8px 20px rgba(15, 23, 42, .06);

  --bg:#fbfaf7;
  --panel:#ffffff;
  --panel2:#f7f6f2;
  --text:#171717;
  --muted:#667085;
  --line:rgba(17, 24, 39, .10);
  --focus:rgba(245, 158, 11, .35);

  --brand:#f4bf4f; /* 柔和暖黄 */
  --brand-2:#ffe4a8;
  --brand-rgb:244,191,79;
  --accent:#8b5cf6;
  --danger:#ef4444;
  --ok:#16a34a;

  --sidebar-w:320px;
  --drawer-w:720px;
  --topbar-h:56px;
}

[data-theme="dark"]{
  --bg:#0f1012;
  --panel:#14161a;
  --panel2:#101216;
  --text:#f3f4f6;
  --muted:#9ca3af;
  --line:rgba(255,255,255,.10);
  --shadow:0 18px 40px rgba(0,0,0,.35);
  --shadow-sm:0 12px 28px rgba(0,0,0,.28);
  --focus:rgba(245, 158, 11, .35);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family:var(--font-sans);
  font-size:var(--font-size-base);
  line-height:var(--font-line-height);
  font-weight:var(--font-weight-base);
  letter-spacing:var(--font-letter-spacing);
  background:var(--bg);
  color:var(--text);
}

a{color:inherit;text-decoration:none}
button,input,textarea,select{font:inherit;color:inherit}
::selection{background:rgba(var(--brand-rgb),.35)}

.app{
  height:100%;
  display:grid;
  grid-template-columns:var(--sidebar-w) 1fr;
  grid-template-rows:var(--topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
}
.app.sidebar-collapsed{
  grid-template-columns:1fr;
  grid-template-areas:
    "topbar"
    "main";
}
.app.sidebar-collapsed .sidebar{
  display:none;
}

.topbar{
  grid-area:topbar;
  position:sticky;
  top:0;
  z-index:30;
  display:flex;
  gap:10px;
  align-items:center;
  padding:10px 12px;
  background:linear-gradient(180deg, rgba(255,255,255,.75), rgba(255,255,255,.55));
  backdrop-filter:blur(10px);
  border-bottom:1px solid var(--line);
}
[data-theme="dark"] .topbar{
  background:linear-gradient(180deg, rgba(20,22,26,.78), rgba(20,22,26,.62));
}

.sidebar{
  grid-area:sidebar;
  border-right:1px solid var(--line);
  background:linear-gradient(180deg, var(--panel), var(--panel2));
  display:flex;
  flex-direction:column;
  min-width:0;
}

.main{
  grid-area:main;
  min-width:0;
  position:relative;
  padding:16px;
  overflow:auto;
}

.card{
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow-sm);
}

.btn{
  border:1px solid var(--line);
  background:var(--panel);
  border-radius:12px;
  padding:8px 10px;
  display:inline-flex;
  align-items:center;
  gap:8px;
  cursor:pointer;
  user-select:none;
  transition:transform .04s ease, background .15s ease, border-color .15s ease;
}
.btn:hover{background:rgba(var(--brand-rgb),.10)}
.btn:active{transform:translateY(1px)}
.btn.primary{
  background:linear-gradient(180deg, var(--brand), var(--brand-2));
  border-color:rgba(0,0,0,.06);
}
.btn.danger{border-color:rgba(239,68,68,.35);background:rgba(239,68,68,.10)}
.btn.ghost{background:transparent}
.btn.small{padding:6px 8px;border-radius:10px}
.btn:focus-visible,.input:focus-visible,.textarea:focus-visible,.select:focus-visible{
  outline:3px solid var(--focus);
  outline-offset:2px;
}

.input,.textarea,.select{
  width:100%;
  border:1px solid var(--line);
  background:var(--panel);
  border-radius:12px;
  padding:10px 12px;
}
.textarea{min-height:96px;resize:vertical}

.pill{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:4px 10px;
  border-radius:999px;
  border:1px solid var(--line);
  background:rgba(var(--brand-rgb),.10);
  color:var(--text);
  font-size:12px;
}

.muted{color:var(--muted)}
.row{display:flex;gap:12px;align-items:center}
.col{display:flex;flex-direction:column;gap:12px}
.grow{flex:1;min-width:0}
.divider{height:1px;background:var(--line)}

.sidebarHeader{
  padding:12px 12px 10px 12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.brandMark{
  display:flex;
  gap:10px;
  align-items:center;
  min-width:0;
}
.logo{
  width:34px;height:34px;border-radius:12px;
  background:conic-gradient(from 200deg, var(--brand), var(--brand-2), var(--brand), var(--brand-2));
  box-shadow:0 8px 20px rgba(var(--brand-rgb),.25);
}
.brandTitle{font-weight:800;letter-spacing:.5px}
.brandSub{font-size:12px;color:var(--muted)}

.sidebarSection{
  padding:0 12px 12px 12px;
  overflow:auto;
}
.sectionTitle{
  display:flex;
  align-items:center;
  justify-content:space-between;
  font-size:12px;
  color:var(--muted);
  margin:10px 0 8px;
}

.worldList{display:flex;flex-direction:column;gap:8px}
.worldItem{
  display:flex;
  gap:10px;
  padding:10px;
  border-radius:14px;
  border:1px solid var(--line);
  background:rgba(255,255,255,.60);
  cursor:pointer;
}
[data-theme="dark"] .worldItem{background:rgba(20,22,26,.75)}
.worldItem.active{border-color:rgba(var(--brand-rgb),.7);box-shadow:0 0 0 4px rgba(var(--brand-rgb),.15)}
.worldCover{
  width:44px;height:44px;border-radius:14px;
  background:linear-gradient(135deg, rgba(var(--brand-rgb),.45), rgba(var(--brand-rgb),.18));
  overflow:hidden;
  border:1px solid rgba(0,0,0,.06);
  flex:0 0 auto;
}
.worldCover img{width:100%;height:100%;object-fit:cover;display:block}
.worldMeta{min-width:0}
.worldName{font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.worldDesc{font-size:12px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

.nav{
  display:flex;
  flex-direction:column;
  gap:6px;
}
.navItem{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px 10px;
  border-radius:14px;
  border:1px solid transparent;
  cursor:pointer;
}
.navItem:hover{background:rgba(var(--brand-rgb),.10)}
.navItem.active{background:rgba(var(--brand-rgb),.16);border-color:rgba(var(--brand-rgb),.25)}
.navLeft{display:flex;gap:10px;align-items:center;min-width:0}
.navIcon{
  width:24px;height:24px;display:inline-flex;align-items:center;justify-content:center;
  border-radius:8px;background:rgba(var(--brand-rgb),.12);font-size:14px;flex:0 0 auto;
}
.navTextCol{gap:2px;min-width:0}
.navLabel{font-weight:600}
.navDesc{
  font-size:12px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:210px;
}
.badge{font-size:12px;color:var(--muted)}

.searchBox{
  flex:1;
  display:flex;
  gap:8px;
  align-items:center;
  border:1px solid var(--line);
  border-radius:14px;
  padding:8px 10px;
  background:var(--panel);
  min-width:0;
}
.searchBox input{
  border:none;
  outline:none;
  background:transparent;
  width:100%;
  min-width:0;
}

.drawer{
  position:fixed;
  top:var(--topbar-h);
  right:0;
  width:var(--drawer-w);
  height:calc(100% - var(--topbar-h));
  background:var(--panel);
  border-left:1px solid var(--line);
  box-shadow:var(--shadow);
  transform:translateX(100%);
  transition:transform .2s ease;
  z-index:40;
  display:flex;
  flex-direction:column;
}
.drawer.open{transform:translateX(0)}
.drawerHeader{
  padding:14px 14px 10px;
  border-bottom:1px solid var(--line);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.drawerBody{padding:14px;overflow:auto}
.drawerTitle{font-weight:800}

.hasWordCount .main{
  padding-bottom:calc(16px + 44px);
}
.hasWordCount .drawerBody{
  padding-bottom:calc(14px + 44px);
}
.hasWordCount .readerBody{
  padding-bottom:calc(12px + 44px);
}

.wordCount{
  position:fixed;
  right:14px;
  bottom:14px;
  z-index:60;
  display:flex;
  gap:10px;
  align-items:center;
  padding:8px 10px;
  border-radius:999px;
  border:1px solid var(--line);
  background:rgba(255,255,255,.72);
  backdrop-filter:blur(10px);
  box-shadow:var(--shadow-sm);
  color:var(--muted);
  font-size:12px;
  line-height:1;
  user-select:none;
  pointer-events:none;
}
[data-theme="dark"] .wordCount{
  background:rgba(20,22,26,.68);
}
.wordCount.hidden{display:none}
.wordCountItem{white-space:nowrap}

.gridCards{
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(240px, 1fr));
  gap:12px;
  /* 避免同一行被最高卡片“拉伸”导致折叠卡片大片空白 */
  align-items:start;
}
.wcCard{
  padding:12px;
  display:flex;
  flex-direction:column;
  gap:10px;
  cursor:pointer;
}
.wcCover{
  height:140px;
  border-radius:14px;
  background:linear-gradient(135deg, rgba(var(--brand-rgb),.45), rgba(var(--brand-rgb),.18));
  overflow:hidden;
  border:1px solid rgba(0,0,0,.06);
}
.wcCover img{width:100%;height:100%;object-fit:cover;display:block}
.wcTitleRow{display:flex;justify-content:space-between;gap:10px;align-items:flex-start}
.wcTitle{font-weight:800}

.empty{
  padding:24px;
  border:1px dashed var(--line);
  border-radius:var(--radius);
  background:rgba(var(--brand-rgb),.06);
}

/* 富文本块 */
.rtToolbar{
  display:flex;flex-wrap:wrap;gap:8px;align-items:center;
  position:sticky;top:0;
  padding:10px;
  background:linear-gradient(180deg, rgba(255,255,255,.82), rgba(255,255,255,.62));
  border-bottom:1px solid var(--line);
  border-radius:var(--radius) var(--radius) 0 0;
  backdrop-filter:blur(10px);
  z-index:2;
}
[data-theme="dark"] .rtToolbar{
  background:linear-gradient(180deg, rgba(20,22,26,.85), rgba(20,22,26,.65));
}
.rtArea{padding:10px}
.blockList{display:flex;flex-direction:column;gap:10px}
.rtBlock{
  border:1px solid var(--line);
  border-radius:14px;
  background:rgba(255,255,255,.70);
  overflow:hidden;
}
[data-theme="dark"] .rtBlock{background:rgba(20,22,26,.75)}
.rtBlockHeader{
  display:flex;justify-content:space-between;align-items:center;gap:10px;
  padding:8px 10px;
  border-bottom:1px solid var(--line);
  background:rgba(var(--brand-rgb),.08);
}
.dragHandle{cursor:grab}
.rtContent{
  padding:10px 12px;
  min-height:70px;
  outline:none;
}
.rtContent:empty:before{content:"在这里开始写…（支持粘贴/格式化/自动保存）";color:var(--muted)}
.rtContent img{max-width:100%;border-radius:12px;border:1px solid var(--line)}

/* 时间线 */
.timelineWrap{display:flex;flex-direction:column;gap:12px}
.tlControls{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
.tl{
  position:relative;
  padding-left:16px;
}
.tl:before{
  content:"";
  position:absolute;left:6px;top:0;bottom:0;width:2px;background:rgba(var(--brand-rgb),.55);
  border-radius:99px;
}
.tlItem{
  position:relative;
  padding:12px;
  margin:10px 0;
}
.tlDot{
  position:absolute;left:-2px;top:18px;
  width:16px;height:16px;border-radius:999px;
  background:var(--brand);
  box-shadow:0 0 0 4px rgba(var(--brand-rgb),.18);
}
.tlHead{display:flex;justify-content:space-between;gap:10px;align-items:flex-start}
.tlTitle{font-weight:800}
.tlTime{font-size:12px;color:var(--muted)}
.tlBody{margin-top:8px}
.tlBody .desc{white-space:pre-wrap;line-height:1.6}
.thumbRow{display:flex;gap:8px;flex-wrap:wrap;margin-top:10px}
.thumb{
  width:90px;height:72px;border-radius:12px;overflow:hidden;border:1px solid var(--line);
  cursor:pointer;background:rgba(0,0,0,.04);
}
.thumb img{width:100%;height:100%;object-fit:cover;display:block}

/* 地图 */
.mapWrap{display:grid;grid-template-columns:1fr 320px;gap:12px;align-items:start}
.mapStage{
  position:relative;
  aspect-ratio:16/10;
  border-radius:var(--radius);
  overflow:hidden;
  border:1px solid var(--line);
  background:linear-gradient(135deg, rgba(var(--brand-rgb),.20), rgba(var(--brand-rgb),.10));
}
.mapStage img{width:100%;height:100%;object-fit:contain;display:block;background:rgba(0,0,0,.02)}
.marker{
  position:absolute;
  width:22px;height:22px;border-radius:999px;
  background:rgba(239,68,68,.95);
  box-shadow:0 0 0 4px rgba(239,68,68,.18);
  transform:translate(-50%,-50%);
  cursor:grab;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:14px;
  line-height:1;
  color:rgba(17,24,39,.92);
  user-select:none;
}
.marker[data-type="mine"]{background:rgba(34,197,94,.95);box-shadow:0 0 0 4px rgba(34,197,94,.16)}
.marker[data-type="realm"]{background:rgba(139,92,246,.95);box-shadow:0 0 0 4px rgba(139,92,246,.18)}
.marker[data-type="other"]{background:rgba(var(--brand-rgb),.95);box-shadow:0 0 0 4px rgba(var(--brand-rgb),.18)}
.marker.active{outline:3px solid rgba(255,255,255,.65)}
.mapPanel{padding:12px}
.list{display:flex;flex-direction:column;gap:8px}
.listItem{
  padding:10px;
  border:1px solid var(--line);
  border-radius:14px;
  cursor:pointer;
  background:rgba(255,255,255,.65);
}
[data-theme="dark"] .listItem{background:rgba(20,22,26,.75)}
.listItem.active{border-color:rgba(var(--brand-rgb),.7)}

/* 主线剧情 */
.plotCard{padding:12px;display:flex;flex-direction:column;gap:10px;min-width:0}
.plotTitle{font-weight:900}
.plotText{
  white-space:normal;
  overflow-wrap:anywhere;
  word-break:break-word;
  line-height:1.6;
}
.plotChapter{min-width:0}

/* 人物卡片 */
.charGrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:12px}
.charCard{padding:12px;display:flex;gap:12px;cursor:pointer}
.avatar{
  width:64px;height:64px;border-radius:18px;overflow:hidden;border:1px solid var(--line);
  background:linear-gradient(135deg, rgba(var(--brand-rgb),.35), rgba(var(--brand-rgb),.12));
  flex:0 0 auto;
}
.avatar img{width:100%;height:100%;object-fit:cover;display:block}
.charName{font-weight:900}
.kv{display:grid;grid-template-columns:90px 1fr;gap:8px;align-items:start}
.k{color:var(--muted);font-size:12px}
.v{white-space:pre-wrap;line-height:1.6}

/* 通用预览区 */
.previewPanel{
  border:1px solid var(--line);
  border-radius:14px;
  padding:10px;
  background:rgba(var(--brand-rgb),.06);
  min-width:0;
}
.previewPanel:empty{display:none}
.previewRich{display:flex;flex-direction:column;gap:8px;min-width:0}
.previewBlock{
  min-width:0;
  white-space:normal;
  overflow-wrap:anywhere;
  word-break:break-word;
  line-height:1.65;
}
.readerBody .previewBlock{
  /* 阅读模式严格保留编辑内容的换行/连续空格（&nbsp; 等） */
  white-space:pre-wrap;
}
.previewThumbs{display:flex;gap:8px;flex-wrap:wrap;margin-top:8px}

.readerView{display:flex;flex-direction:column;gap:12px;min-height:0}
.readerTitle{font-weight:900;font-size:18px}
.readerBody{
  border:1px solid var(--line);
  border-radius:14px;
  padding:12px;
  background:var(--panel2);
  max-height:calc(100vh - 180px);
  overflow:auto;
  display:flex;
  flex-direction:column;
  gap:12px;
}

/* 关系图谱 */
.graphWrap{display:grid;grid-template-columns:1fr 320px;gap:12px}
.graphStage{
  border-radius:var(--radius);
  border:1px solid var(--line);
  background:linear-gradient(135deg, rgba(var(--brand-rgb),.14), rgba(var(--brand-rgb),.08));
  height:min(72vh, 720px);
  overflow:hidden;
  position:relative;
}
.graphStage canvas{width:100%;height:100%;display:block}

/* 模态图片预览 */
.modal{
  position:fixed;inset:0;
  background:rgba(0,0,0,.55);
  display:none;
  align-items:center;
  justify-content:center;
  padding:20px;
  z-index:100;
}
.modal.open{display:flex}
.modalCard{
  max-width:min(1000px, 96vw);
  max-height:92vh;
  width:100%;
  background:var(--panel);
  border-radius:18px;
  border:1px solid var(--line);
  box-shadow:var(--shadow);
  overflow:hidden;
}
.modalHeader{padding:12px;border-bottom:1px solid var(--line);display:flex;justify-content:space-between;align-items:center;gap:10px}
.modalBody{padding:12px;display:flex;justify-content:center;align-items:center;background:rgba(0,0,0,.03)}
.modalBody img{max-width:100%;max-height:78vh;border-radius:14px;border:1px solid var(--line)}

/* 响应式 */
@media (max-width: 980px){
  :root{--sidebar-w:280px;--drawer-w:min(96vw, 720px)}
  .mapWrap,.graphWrap{grid-template-columns:1fr}
}
@media (max-width: 760px){
  :root{--sidebar-w:0px}
  .app{grid-template-columns:1fr;grid-template-areas:"topbar" "main"}
  .sidebar{display:none}
  .main{padding:12px}
}

/* 打印 */
@media print{
  .topbar,.sidebar,.drawer,.btn{display:none !important}
  body{background:#fff}
  .main{padding:0}
  .card{box-shadow:none}
}
