/* ============================================================
   界书 · 世界观与角色档案
   纯手写样式，无外部依赖
   ============================================================ */

/* ---------- 主题变量 ---------- */
:root {
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", SimSun, serif;
  --sans: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;

  --bg: #131110;
  --surface: #1a1715;
  --surface-2: #211d1a;
  --surface-3: #2a2521;
  --line: #332c26;
  --line-soft: #282220;
  --text: #ece4d8;
  --text-dim: #a99d8e;
  --text-faint: #70645a;
  --accent: #d0a75f;
  --accent-soft: rgba(208, 167, 95, .13);
  --accent-line: rgba(208, 167, 95, .35);
  --accent-ink: #16130f;
  --ok: #84b494;
  --danger: #cf6b5c;
  --danger-soft: rgba(207, 107, 92, .12);
  --shadow: 0 18px 48px rgba(0, 0, 0, .45);
  --radius: 12px;
  --radius-sm: 8px;
}

html[data-theme="light"] {
  --bg: #f2ece0;
  --surface: #fbf8f1;
  --surface-2: #f7f1e5;
  --surface-3: #ece3d1;
  --line: #dcd0b9;
  --line-soft: #e7ddca;
  --text: #2b241b;
  --text-dim: #6f6353;
  --text-faint: #9c8f7c;
  --accent: #a2701f;
  --accent-soft: rgba(162, 112, 31, .11);
  --accent-line: rgba(162, 112, 31, .32);
  --accent-ink: #fffaf0;
  --ok: #4d7f5f;
  --danger: #b34f40;
  --danger-soft: rgba(179, 79, 64, .09);
  --shadow: 0 18px 48px rgba(90, 70, 40, .16);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button { cursor: pointer; }

::selection { background: var(--accent-soft); color: var(--text); }

/* 细滚动条 */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: padding-box; border: 2px solid transparent; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- 骨架 ---------- */
.app {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ---------- 侧栏 ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 16px 16px;
  background: var(--surface);
  border-right: 1px solid var(--line-soft);
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 4px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(150deg, var(--accent-soft), transparent 70%), var(--surface-2);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0;
  box-shadow: inset 0 0 22px rgba(208, 167, 95, .08);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: .14em;
}
.brand-text span { font-size: 11px; color: var(--text-faint); letter-spacing: .12em; white-space: nowrap; }

.side-label {
  font-size: 11px;
  letter-spacing: .16em;
  color: var(--text-faint);
  text-transform: uppercase;
}

.side-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}

.world-switch { display: flex; flex-direction: column; }
.world-row { display: flex; gap: 6px; }

.world-select {
  flex: 1;
  min-width: 0;
  appearance: none;
  background-color: var(--surface-2);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%), linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 26px 8px 11px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.world-select:hover { border-color: var(--text-faint); }

.icon-btn {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  transition: .16s;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }

.mini-btn {
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 11px;
  padding: 0;
  letter-spacing: .05em;
  border-bottom: 1px dashed transparent;
}
.mini-btn:hover { color: var(--accent); border-bottom-color: var(--accent-line); }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-dim);
  font-size: 13.5px;
  letter-spacing: .04em;
  text-align: left;
  transition: .16s;
  position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}
.nav-ico { font-size: 13px; width: 16px; text-align: center; opacity: .9; }
.nav-count {
  margin-left: auto;
  font-style: normal;
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.nav-item.active .nav-count { color: var(--accent); opacity: .8; }

.side-spacer { flex: 1; }

.side-stats {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 11px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 11.5px;
  color: var(--text-faint);
}
.side-stats .stat-row { display: flex; justify-content: space-between; gap: 8px; }
.side-stats b { color: var(--text-dim); font-weight: 500; font-variant-numeric: tabular-nums; }

.side-foot { display: flex; gap: 6px; }

.ghost-btn {
  flex: 1;
  padding: 7px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
  background: none;
  color: var(--text-faint);
  font-size: 11.5px;
  letter-spacing: .06em;
  transition: .16s;
  white-space: nowrap;
}
.ghost-btn:hover { color: var(--text); border-color: var(--line); background: var(--surface-2); }

/* ---------- 主区 ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 26px;
  border-bottom: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(6px);
}

.topbar-title { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.topbar-title h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: .1em;
  white-space: nowrap;
}
.topbar-title .sub {
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(340px, 34vw);
  padding: 0 10px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  transition: .18s;
}
.search:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 15px; height: 15px; flex: 0 0 15px; fill: none; stroke: var(--text-faint); stroke-width: 1.7; stroke-linecap: round; }
.search input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: none;
  font-size: 13px;
}
.search input::placeholder { color: var(--text-faint); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search kbd {
  font-family: var(--sans);
  font-size: 10px;
  color: var(--text-faint);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 5px;
  line-height: 16px;
}

.primary-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 15px;
  border-radius: 999px;
  border: 1px solid var(--accent-line);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  white-space: nowrap;
  transition: .16s;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .22);
}
.primary-btn:hover { filter: brightness(1.07); transform: translateY(-1px); }
.primary-btn:active { transform: translateY(0); }
.primary-btn .plus { font-size: 15px; margin-top: -1px; }

/* ---------- 内容 ---------- */
.content {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(276px, 330px) minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.list-pane {
  border-right: 1px solid var(--line-soft);
  overflow-y: auto;
  padding: 14px 12px 30px;
  min-height: 0;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}

.detail-pane {
  overflow-y: auto;
  min-height: 0;
  padding: 26px 34px 90px;
  scroll-behavior: smooth;
}

/* ---------- 列表 ---------- */
.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px 10px;
  font-size: 11px;
  letter-spacing: .16em;
  color: var(--text-faint);
  text-transform: uppercase;
}
.list-head .mini-btn { font-size: 11px; letter-spacing: .08em; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 4px 12px; }
.chip {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-faint);
  font-size: 11px;
  transition: .15s;
  white-space: nowrap;
}
.chip:hover { color: var(--text-dim); border-color: var(--text-faint); }
.chip.active { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

.list-item {
  display: flex;
  gap: 11px;
  padding: 11px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: .15s;
  position: relative;
}
.list-item:hover { background: var(--surface-2); }
.list-item.active { background: var(--accent-soft); border-color: var(--accent-line); }
.list-item.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 14px;
  bottom: 14px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 19px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  overflow: hidden;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.square { border-radius: 10px; }

.list-body { min-width: 0; flex: 1; }
.list-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}
.list-meta {
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.list-tags { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.tag {
  font-size: 10.5px;
  line-height: 1.6;
  padding: 0 7px;
  border-radius: 4px;
  background: var(--surface-3);
  color: var(--text-faint);
  letter-spacing: .02em;
}

.empty {
  padding: 46px 22px;
  text-align: center;
  color: var(--text-faint);
}
.empty .empty-mark {
  font-family: var(--serif);
  font-size: 34px;
  color: var(--line);
  margin-bottom: 10px;
}
.empty p { margin: 6px 0; font-size: 13px; line-height: 1.8; }
.empty .link { color: var(--accent); border-bottom: 1px solid var(--accent-line); cursor: pointer; }

/* ---------- 详情 ---------- */
.detail-head {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 24px;
}
.detail-avatar {
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 34px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.detail-avatar img { width: 100%; height: 100%; object-fit: cover; }

.detail-title { flex: 1; min-width: 0; padding-top: 2px; }
.detail-title h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 600;
  letter-spacing: .04em;
  line-height: 1.3;
  word-break: break-word;
}
.detail-title .alias {
  font-size: 13px;
  color: var(--text-faint);
  margin-top: 3px;
  letter-spacing: .06em;
}
.detail-actions { display: flex; gap: 8px; flex: 0 0 auto; padding-top: 4px; }

.soft-btn {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 12px;
  transition: .15s;
  white-space: nowrap;
}
.soft-btn:hover { color: var(--text); border-color: var(--text-faint); background: var(--surface-2); }
.soft-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

/* 表单 */
.form { display: flex; flex-direction: column; gap: 26px; max-width: 820px; }

.field-group { display: flex; flex-direction: column; gap: 12px; }
.group-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  letter-spacing: .2em;
  color: var(--text-faint);
  text-transform: uppercase;
}
.group-title .g-name {
  white-space: nowrap;
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  padding-bottom: 1px;
  transition: .15s;
}
.group-title .g-name:hover { color: var(--accent); border-bottom-color: var(--accent-line); }
.group-title .g-line { flex: 1; height: 1px; background: var(--line-soft); }
.group-title .g-tools { display: flex; gap: 1px; opacity: .55; transition: opacity .15s; }
.group-title:hover .g-tools { opacity: 1; }
.g-tools button {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: none;
  color: var(--text-faint);
  font-size: 14px;
  line-height: 1;
  transition: .15s;
}
.g-tools button:hover { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }
.g-tools button[data-hide-group]:hover { color: var(--danger); background: var(--danger-soft); border-color: var(--danger); }

.form-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: span 3; }
.form-grid .span-6 { grid-column: span 6; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label,
.field > .field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-faint);
  letter-spacing: .08em;
}
.field-del {
  opacity: .22;
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 13px;
  line-height: 1;
  padding: 0 3px;
  border-radius: 4px;
  transition: .15s;
}
.field:hover .field-del { opacity: .75; }
.field-del:hover { opacity: 1; color: var(--danger); background: var(--danger-soft); }

.cf-label { cursor: pointer; border-bottom: 1px dashed var(--line); padding-bottom: 1px; }
.cf-label:hover { color: var(--accent); border-bottom-color: var(--accent-line); }

.renamable {
  cursor: pointer;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 1px;
  transition: .15s;
}
.renamable:hover { color: var(--accent); border-bottom-color: var(--accent-line); }

.form-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 16px;
  border-top: 1px dashed var(--line-soft);
}
.form-foot .add-inline { align-self: auto; }
.foot-note { font-size: 11.5px; color: var(--text-faint); margin-left: auto; text-align: right; }

.restore-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 12px;
  color: var(--text-faint);
}
.restore-btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 11.5px;
  transition: .15s;
}
.restore-btn:hover { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }

.input, .textarea, .select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 9px 11px;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); opacity: .8; }
.input:hover, .textarea:hover, .select:hover { border-color: var(--text-faint); }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface-2);
}
.textarea { resize: vertical; min-height: 84px; }
.textarea.tall { min-height: 150px; }
.textarea.prose {
  font-family: var(--serif);
  font-size: 14.5px;
  line-height: 1.95;
  letter-spacing: .01em;
}
.select { appearance: none; cursor: pointer; background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%), linear-gradient(135deg, var(--text-faint) 50%, transparent 50%); background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 28px; }

.field-hint { font-size: 11px; color: var(--text-faint); }

/* 标签编辑器 */
.tag-editor { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 7px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); min-height: 40px; }
.tag-editor:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag-editor input { flex: 1; min-width: 90px; border: none; outline: none; background: none; font-size: 12.5px; padding: 2px 4px; }
.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 4px 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  font-size: 11.5px;
}
.tag-pill button { border: none; background: none; color: inherit; opacity: .6; font-size: 13px; line-height: 1; padding: 0 3px; }
.tag-pill button:hover { opacity: 1; }

/* 档案卡片列表（角色详情内） */
.related-list { display: flex; flex-direction: column; gap: 7px; }
.related-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: .15s;
}
.related-item:hover { border-color: var(--accent-line); background: var(--surface-2); }
.related-item .ri-cat {
  font-size: 10.5px;
  color: var(--accent);
  border: 1px solid var(--accent-line);
  border-radius: 4px;
  padding: 0 6px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.related-item .ri-title { flex: 1; min-width: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.related-item .ri-time { font-size: 11px; color: var(--text-faint); flex: 0 0 auto; }
.related-item .ri-del { opacity: 0; border: none; background: none; color: var(--text-faint); font-size: 14px; padding: 0 4px; }
.related-item:hover .ri-del { opacity: 1; }
.related-item .ri-del:hover { color: var(--danger); }

.add-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  padding: 6px 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-faint);
  font-size: 12px;
  transition: .15s;
}
.add-inline:hover { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }

/* ---------- 总览 ---------- */
.overview { max-width: 900px; display: flex; flex-direction: column; gap: 26px; }

.world-hero {
  position: relative;
  padding: 21px 26px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background:
    radial-gradient(120% 160% at 90% -20%, var(--accent-soft), transparent 60%),
    var(--surface);
  overflow: hidden;
}
.world-hero::after {
  content: "界";
  position: absolute;
  right: 18px;
  bottom: -34px;
  font-family: var(--serif);
  font-size: 150px;
  color: var(--text);
  opacity: .035;
  pointer-events: none;
  line-height: 1;
}
.world-hero h2 {
  margin: 0 0 4px;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: .08em;
}
.world-hero .tagline { color: var(--accent); font-size: 13px; letter-spacing: .14em; margin-bottom: 11px; }
.world-hero p { margin: 0; color: var(--text-dim); font-size: 13.5px; line-height: 1.88; white-space: pre-wrap; max-width: 66ch; }

.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat-card {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line-soft);
  background: var(--surface);
  cursor: pointer;
  transition: .18s;
}
.stat-card:hover { border-color: var(--accent-line); transform: translateY(-2px); background: var(--surface-2); }
.stat-card .num { font-family: var(--serif); font-size: 26px; line-height: 1.15; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-card .lbl { font-size: 11.5px; color: var(--text-faint); letter-spacing: .12em; margin-top: 4px; }

.panel {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px 18px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h3 { margin: 0; font-family: var(--serif); font-size: 15px; font-weight: 600; letter-spacing: .12em; }
.panel-head .mini-btn { font-size: 11.5px; }

.graph-wrap { width: 100%; overflow: hidden; display: flex; justify-content: center; }
.graph-svg { width: 100%; max-width: 520px; height: auto; display: block; }
.graph-svg .edge { stroke: var(--text-faint); stroke-width: 1.2; opacity: .6; }
.graph-svg .edge-label { fill: var(--text-faint); font-size: 9.5px; }
.graph-svg .node-circle { fill: var(--surface-3); stroke: var(--line); }
.graph-svg .node-circle.active { stroke: var(--accent); }
.graph-svg .node-emoji { font-size: 15px; }
.graph-svg .node-name { fill: var(--text-dim); font-size: 10.5px; }

.recent-list { display: flex; flex-direction: column; }
.recent-item { display: flex; align-items: center; gap: 12px; padding: 9px 2px; border-bottom: 1px dashed var(--line-soft); cursor: pointer; }
.recent-item:last-child { border-bottom: none; }
.recent-item:hover .recent-title { color: var(--accent); }
.recent-kind { font-size: 10.5px; color: var(--text-faint); border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; flex: 0 0 auto; }
.recent-title { flex: 1; font-size: 13px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-time { font-size: 11px; color: var(--text-faint); flex: 0 0 auto; }

/* ---------- 关系 ---------- */
.rel-form {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: end;
  padding: 18px 20px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 20px;
}
.rel-arrow { padding-bottom: 11px; color: var(--accent); font-size: 15px; }

.rel-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: 7px;
  transition: .15s;
}
.rel-row:hover { border-color: var(--line); background: var(--surface-2); }
.rel-person { display: flex; align-items: center; gap: 7px; font-size: 13px; min-width: 0; }
.rel-person .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: 0 0 7px; }
.rel-arrow-line { color: var(--text-faint); font-size: 13px; flex: 0 0 auto; }
.rel-type {
  font-size: 10.5px;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--accent-line);
  color: var(--accent);
  background: var(--accent-soft);
  flex: 0 0 auto;
}
.rel-note { font-size: 12px; color: var(--text-faint); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rel-del { border: none; background: none; color: var(--text-faint); font-size: 14px; padding: 0 4px; opacity: 0; }
.rel-row:hover .rel-del { opacity: 1; }
.rel-del:hover { color: var(--danger); }

/* ---------- 状态栏 ---------- */
.statusbar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 26px;
  border-top: 1px solid var(--line-soft);
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: .06em;
  background: var(--surface);
  flex: 0 0 auto;
}
.save-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); transition: .2s; }
.save-dot.dirty { background: var(--accent); }
.save-dot.saved { background: var(--ok); }
.status-sep { opacity: .5; }
.status-right { margin-left: auto; font-variant-numeric: tabular-nums; }
.status-icp { font-size: 11px; color: var(--text-faint); white-space: nowrap; }
.status-icp a { color: inherit; text-decoration: none; }
.status-icp a:hover { text-decoration: underline; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 46px;
  transform: translate(-50%, 14px);
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12.5px;
  letter-spacing: .05em;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: .24s ease;
  z-index: 90;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(460px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px;
  animation: pop .18s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.modal h3 { margin: 0 0 6px; font-family: var(--serif); font-size: 18px; letter-spacing: .08em; font-weight: 600; }
.modal .modal-desc { font-size: 12.5px; color: var(--text-faint); margin: 0 0 18px; line-height: 1.7; }
.modal .modal-fields { display: flex; flex-direction: column; gap: 14px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.btn {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 13px;
  transition: .15s;
}
.btn:hover { color: var(--text); border-color: var(--text-faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); }

/* ---------- 补充 ---------- */
.content.single { grid-template-columns: minmax(0, 1fr); }
.list-pane[hidden] { display: none; }

.avatar .glyph {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}
.avatar.square .glyph { font-size: 17px; }
.detail-avatar .glyph {
  font-family: var(--serif);
  font-size: 31px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}
.graph-svg .node-emoji {
  font-family: var(--serif);
  fill: var(--accent);
  font-weight: 600;
}
.graph-svg .graph-node:hover .node-circle { stroke: var(--accent); }
.graph-svg .graph-node:hover .node-name { fill: var(--text); }

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
  body { overflow: auto; }
  .app { grid-template-columns: 1fr; height: auto; min-height: 100dvh; }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-right: none;
    border-bottom: 1px solid var(--line-soft);
    position: sticky;
    top: 0;
    z-index: 40;
  }
  .brand-text { display: none; }
  .world-switch { flex: 1; min-width: 150px; }
  .side-label-row, .side-stats, .side-spacer { display: none; }
  .nav { flex-direction: row; width: 100%; min-width: 0; overflow-x: auto; flex-wrap: nowrap; gap: 2px; }
  .nav-item { width: auto; flex: 0 0 auto; padding: 6px 8px; white-space: nowrap; }
  .nav-item > span { white-space: nowrap; }
  .nav-count { margin-left: 3px; }
  .side-foot { flex: 0 0 100%; width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .side-foot .ghost-btn { flex: 0 0 auto; padding: 5px 14px; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  .search { order: 3; width: 100%; margin-left: 0; }
  .content { grid-template-columns: 1fr; }
  .list-pane { max-height: 38vh; border-right: none; border-bottom: 1px solid var(--line-soft); }
  .detail-pane { padding: 20px 18px 70px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2, .form-grid .span-3, .form-grid .span-6 { grid-column: span 1; }
  .group-title .g-tools { opacity: 1; }
  .field-del { opacity: .6; }
  .rel-form { grid-template-columns: 1fr; }
  .rel-arrow { display: none; }
  .detail-head { gap: 12px; flex-wrap: wrap; }
  .detail-actions { flex: 1 1 100%; width: auto; justify-content: flex-end; }
  .detail-actions .soft-btn { padding: 5px 10px; font-size: 11.5px; }
  .detail-avatar { width: 56px; height: 56px; flex-basis: 56px; font-size: 26px; }
  .detail-title h2 { font-size: 21px; }
}

/* ---------- 登录 / 注册 ---------- */
.app[hidden], .auth-view[hidden] { display: none !important; }

.auth-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(90% 70% at 50% 0%, var(--accent-soft), transparent 60%),
    var(--bg);
}

.auth-card {
  width: min(380px, 100%);
  padding: 34px 30px 26px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--accent-line);
  background: linear-gradient(150deg, var(--accent-soft), transparent 70%), var(--surface-2);
  color: var(--accent);
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 600;
}

.auth-card h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 26px;
  letter-spacing: .16em;
  font-weight: 600;
}

.auth-sub {
  margin: 4px 0 22px;
  font-size: 12px;
  letter-spacing: .18em;
  color: var(--text-faint);
}

.auth-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 20px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
}

.auth-tabs button {
  flex: 1;
  padding: 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: none;
  color: var(--text-faint);
  font-size: 13px;
  transition: .15s;
}

.auth-tabs button.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-line);
}

.auth-form { display: flex; flex-direction: column; gap: 12px; text-align: left; }

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-faint);
  letter-spacing: .08em;
}

.auth-form .input { background: var(--surface-2); }
.auth-submit { width: 100%; justify-content: center; margin-top: 6px; height: 40px; }
.auth-msg { min-height: 18px; margin-top: 12px; font-size: 12px; color: var(--text-faint); }
.auth-msg.error { color: var(--danger); }
.auth-foot { margin: 14px 0 0; font-size: 11px; color: var(--text-faint); }
.auth-icp { margin: 8px 0 0; font-size: 11px; color: var(--text-faint); }
.auth-icp a { color: inherit; text-decoration: none; }
.auth-icp a:hover { text-decoration: underline; }

/* ---------- 当前用户 ---------- */
.side-user {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 4px 8px;
  font-size: 11.5px;
  color: var(--text-faint);
}
.side-user b {
  color: var(--text-dim);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-user .mini-btn { margin-left: auto; }
.user-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); flex: 0 0 6px; }

.auth-form[hidden] { display: none !important; }

/* ---------- 共享 / 成员 ---------- */
.share-block { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.share-head { font-size: 12px; letter-spacing: .08em; color: var(--text-faint); margin-bottom: 10px; }
.share-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.share-row .input { flex: 1 1 160px; min-width: 0; }
.share-members { display: flex; flex-direction: column; gap: 6px; }
.member-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.member-name { flex: 1 1 auto; }
.member-role { font-size: 11.5px; color: var(--text-faint); white-space: nowrap; }
.invite-code {
  margin-top: 10px; padding: 12px 14px; border-radius: 10px;
  background: var(--surface-2); border: 1px dashed var(--line);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 18px; letter-spacing: .18em; text-align: center;
  user-select: all; -webkit-user-select: all;
}
.share-code { margin-top: 10px; }
.share-hint { margin: 8px 0 0; font-size: 11.5px; color: var(--text-faint); line-height: 1.6; }
.danger-text { color: var(--danger); }

/* 只读世界：压暗所有编辑入口 */
body.is-readonly .form-grid input,
body.is-readonly .form-grid textarea,
body.is-readonly .detail-pane .soft-btn,
body.is-readonly #btnNew,
body.is-readonly [data-add-field],
body.is-readonly .renamable,
body.is-readonly .rel-form input,
body.is-readonly .rel-form select {
  pointer-events: none;
  opacity: .45;
}

/* ---------- 空状态：还没有世界 ---------- */
.welcome-view {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 24px;
  min-height: 62vh;
}
/* display:flex 会盖掉 [hidden] 的 display:none，必须显式压掉 */
.welcome-view[hidden] { display: none !important; }
.list-pane[hidden],
.detail-pane[hidden] { display: none !important; }
.welcome-card {
  width: min(520px, 100%);
  text-align: center;
}
.welcome-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 22px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent);
  font-size: 30px;
  box-shadow: var(--shadow);
}
.welcome-card h2 {
  margin: 0 0 12px;
  font-size: 23px;
  font-weight: 600;
  letter-spacing: .02em;
}
.welcome-desc {
  margin: 0 0 26px;
  font-size: 13.5px;
  line-height: 1.95;
  color: var(--text-dim);
}
.welcome-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.welcome-actions .primary-btn,
.welcome-actions .btn { min-width: 168px; justify-content: center; }
.welcome-hint {
  margin: 30px 0 0;
  font-size: 12px;
  color: var(--text-faint);
}
.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-btn:hover { opacity: .8; }

@media (max-width: 860px) {
  .welcome-view { padding: 40px 18px; min-height: 50vh; }
  .welcome-actions { flex-direction: column; }
  .welcome-actions .primary-btn,
  .welcome-actions .btn { width: 100%; }
}

/* hidden 属性要真的生效（.primary-btn 的 display 会覆盖它） */
#btnNew[hidden] { display: none !important; }
#worldEditBtn[hidden],
#worldShareBtn[hidden] { display: none !important; }

/* ---------- 找回密码 ---------- */
.auth-tabs[hidden] { display: none !important; }
.auth-card p[hidden] { display: none !important; }
.label-opt { font-size: 11px; color: var(--text-faint); margin-left: 6px; font-weight: 400; letter-spacing: 0; }
.auth-tip { margin: 0 0 14px; font-size: 12px; line-height: 1.75; color: var(--text-faint); text-align: left; }
.auth-foot .link-btn { font-size: 11.5px; }

/* 声音字段只有一两句话，不需要默认那么高 */
[data-field-wrap^="voice"] .textarea { min-height: 58px; }

/* ---------- 列表排序 / 势力分组 ---------- */
.sort-select {
  margin-left: auto;
  margin-right: 8px;
  padding: 2px 6px;
  font-size: 11.5px;
  font-family: inherit;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
}
.sort-select:hover { border-color: var(--text-faint); }
.list-head.group-head { margin-top: 16px; }
.list-head.group-head span:first-child {
  color: var(--text-dim);
  letter-spacing: .1em;
}

/* ---------- 导入比对（合并） ---------- */
.modal.modal-wide {
  width: min(880px, 100%);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 22px;
}
.modal-wide .merge-body {
  flex: 1 1 auto;
  min-height: 240px;
  max-height: 58vh;
  overflow-y: auto;
  margin: 6px -6px 0;
  padding: 0 6px;
}

.merge-bar { display: flex; gap: 8px; margin: 10px 0 0; flex-wrap: wrap; }
.btn.mini { padding: 5px 12px; font-size: 12px; }

.merge-group { margin-top: 16px; }
.merge-group-head {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 11.5px; letter-spacing: .16em; color: var(--text-faint);
  padding: 0 2px 7px; border-bottom: 1px solid var(--line-soft);
}
.merge-group-head span { letter-spacing: 0; }

.merge-item { border-bottom: 1px dashed var(--line-soft); padding: 11px 2px 12px; }
.merge-item:last-child { border-bottom: none; }
.merge-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.mi-title { font-size: 13.5px; color: var(--text); font-weight: 500; }
.mi-tag {
  font-size: 10.5px; padding: 1px 7px; border-radius: 4px;
  border: 1px solid var(--line); color: var(--text-faint);
}
.mi-time { font-size: 10.5px; color: var(--text-faint); margin-left: auto; }

.mi-fields { display: flex; flex-direction: column; gap: 6px; margin-top: 9px; }
.merge-field {
  display: grid; grid-template-columns: 96px minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px; align-items: stretch;
}
.mf-label { font-size: 11.5px; color: var(--text-faint); padding-top: 8px; }
.mf-opt {
  text-align: left; display: flex; gap: 8px; align-items: flex-start;
  padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line-soft);
  background: var(--surface-2); color: var(--text-dim);
  font-size: 12px; line-height: 1.7; font-family: inherit;
  white-space: pre-wrap; word-break: break-word;
  cursor: pointer; transition: .13s;
}
.mf-opt:hover { border-color: var(--text-faint); }
.mf-opt.on { border-color: var(--accent-line); background: var(--accent-soft); color: var(--text); }
.mf-src { flex: 0 0 auto; font-size: 10px; letter-spacing: .08em; color: var(--text-faint); padding-top: 2px; }
.mf-opt.on .mf-src { color: var(--accent); }
.mf-empty { color: var(--text-faint); opacity: .65; }

@media (max-width: 720px) {
  .merge-field { grid-template-columns: 1fr; }
  .mf-label { padding-top: 2px; }
  .modal-wide .merge-body { max-height: 48vh; }
}

/* ---------- 模板库 ---------- */
.tpl-list { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.tpl-card {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border: 1px solid var(--line-soft);
  border-radius: 10px; background: var(--surface-2);
}
.tpl-main { flex: 1 1 180px; min-width: 0; }
.tpl-name { font-size: 13.5px; color: var(--text); margin-bottom: 3px; }
.tpl-meta { font-size: 11px; color: var(--text-faint); }
.tpl-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tpl-empty {
  font-size: 12.5px; color: var(--text-faint); line-height: 1.9;
  text-align: center; padding: 24px 6px;
}
.tpl-check {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 12.5px; color: var(--text-dim); cursor: pointer; line-height: 1.6;
}
.tpl-check input { margin-top: 3px; flex: 0 0 auto; }
.tpl-check.is-off { opacity: .45; cursor: not-allowed; }

@media (max-width: 640px) {
  .tpl-card { align-items: stretch; }
  .tpl-actions { flex: 1 0 100%; }
  .tpl-actions .btn { flex: 1 1 auto; }
}

/* ---------- 批量操作 ---------- */
.bulk-toolbar {
  display: flex; align-items: center; gap: 8px;
  min-height: 30px; padding: 0 2px 8px;
}
.bulk-hint { flex: 1 1 auto; }
.bulk-count { flex: 1 1 auto; font-size: 12.5px; color: var(--accent); }
.bulk-toolbar .mini-btn { flex: 0 0 auto; }
.bulk-toolbar.on {
  position: sticky; top: -14px; z-index: 6;
  background: var(--surface);
  padding: 10px 2px;
  border-bottom: 1px solid var(--line-soft);
}

.list-pane.bulk-on { padding-bottom: 0; }
.bulk-actions {
  position: sticky; bottom: 0; z-index: 7;
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px 14px;
  margin: 10px -12px 0;
  background: var(--surface);
  border-top: 1px solid var(--line-soft);
  box-shadow: 0 -8px 20px rgba(0, 0, 0, .07);
}
.bulk-actions .btn { flex: 1 1 auto; }

.pick-box {
  flex: 0 0 20px;
  align-self: center;
  width: 20px; height: 20px;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; line-height: 1;
  color: var(--accent-ink);
  background: var(--surface-2);
}
.pick-box.on { background: var(--accent); border-color: var(--accent); }
.list-item.picked { background: var(--accent-soft); border-color: var(--accent-line); }
.list-item.picked::before { display: none; }

.bulk-fac-chips { display: flex; flex-wrap: wrap; gap: 6px; }

@media (max-width: 640px) {
  .bulk-toolbar.on { flex-wrap: wrap; }
  .bulk-actions .btn { flex: 1 1 40%; }
}
