:root {
  color-scheme: light;
  --bg: #f6f2ea;
  --panel: #fffaf2;
  --ink: #27231f;
  --muted: #766e63;
  --line: #d7c9b8;
  --line-strong: #b99d74;
  --accent: #226b5d;
  --accent-dark: #174f45;
  --male-bg: #e4f3ef;
  --male-border: #257263;
  --female-bg: #fde8ec;
  --female-border: #be5b6a;
  --empty-bg: #f0ece6;
  --empty-border: #bbb0a3;
  --mark: #fff1a8;
  --shadow: 0 18px 44px rgba(43, 31, 18, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  /* 原为 min-width:1120px，导致手机端布局视口被撑到 1120px，
     浏览器只显示最左侧一块，登录卡片落在视野外 → 整屏空白 */
  min-width: 320px;
  /* 某些隐藏面板会撑出横向滚动，背景图只铺满视口，溢出区会露白边 */
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

button:hover {
  border-color: var(--line-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 86px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 242, 0.92);
  backdrop-filter: blur(10px);
}

/* 族谱页锁定为一屏高：顶栏自适应，剩余空间全部给画布，
   页面本身不产生滚动条，图例等悬浮元素始终可见 */
.tree-app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* height:0 + flex:1 1 0 让布局高度只由剩余空间决定，
   不会被画布内容（可能上万像素）反向撑高——否则 fitToScreen 会读到错误的视口高度 */
.tree-app .layout {
  height: 0;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

.intro-page {
  min-height: 100vh;
  padding: 38px 28px;
  background: #f6f2ea;
}

.intro-shell {
  width: min(980px, calc(100vw - 56px));
  margin: 0 auto;
}

.intro-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 0 28px;
  border-bottom: 1px solid var(--line);
}

.intro-header h1 {
  font-size: 42px;
}

.intro-enter {
  min-width: 132px;
}

.intro-actions,
.footer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.intro-lead {
  margin: 34px 0 24px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.intro-lead p {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  line-height: 1.9;
}

.intro-lead p + p {
  margin-top: 12px;
}

.intro-sections {
  display: grid;
  gap: 16px;
}

.intro-section {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 18px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf2;
}

.section-kicker {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--accent);
  background: #eef5ef;
  font-weight: 800;
}

.intro-section p {
  margin: 0;
  color: #3a342c;
  font-size: 16px;
  line-height: 1.9;
}

.intro-section p + p {
  margin-top: 10px;
}

.generation-order-large {
  color: var(--accent) !important;
  font-size: 24px !important;
  font-weight: 800;
  letter-spacing: 0;
}

.timeline p {
  padding: 10px 0;
  border-bottom: 1px solid #eadfce;
}

.timeline p:last-child {
  border-bottom: 0;
}

.intro-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 18px;
  padding: 18px 0;
  color: var(--muted);
}

/* 备案信息：工信部要求在首页底部展示并链接到备案系统，这里各页都放一份 */
.site-beian {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 16px;
  margin-top: 6px;
  /* 底部留白：别贴着浏览器底边，也躲开右下角的悬浮球 */
  padding: 10px 0 28px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
  text-align: center;
}

.site-beian .beian-link {
  color: var(--muted);
  text-decoration: none;
}

.site-beian .beian-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* 公安备案和 ICP 之间用竖线隔开；整段隐藏时竖线跟着一起消失 */
.site-beian .beian-police {
  display: inline-flex;
  align-items: center;
  gap: 16px;
}

.site-beian .beian-sep {
  color: #c9bba7;
  user-select: none;
}

/* 族谱页没有页脚，放侧栏最底下：内容少时靠底，内容多时跟着滚 */
.sidebar .site-beian {
  flex: none;
  margin-top: auto;
  padding: 2px 0 6px;
  font-size: 11.5px;
}

/* 登录页：紧贴卡片下方，不需要给底部留白 */
.site-beian.is-plain {
  margin-top: 0;
  padding: 0;
  font-size: 12px;
}

.text-button {
  border: 0;
  color: var(--accent);
  background: transparent;
  font-weight: 800;
}

.honor-page {
  min-height: 100vh;
  padding: 34px 28px;
  background: #f6f2ea;
}

.honor-shell {
  width: min(1120px, calc(100vw - 56px));
  margin: 0 auto;
}

.honor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 0 26px;
  border-bottom: 1px solid var(--line);
}

.honor-header h1 {
  font-size: 38px;
}

.honor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  margin-top: 24px;
  align-items: start;
}

.honor-list-panel,
.honor-form-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.honor-list-panel {
  min-height: 520px;
  padding: 20px;
}

.honor-form-panel {
  position: sticky;
  top: 22px;
  padding: 20px;
}

.honor-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid #eadfce;
}

.honor-title-row h2,
.honor-form-panel h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

.honor-meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.honor-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.honor-empty {
  display: grid;
  min-height: 360px;
  place-items: center;
  border: 1px dashed #d7c9b8;
  border-radius: 8px;
  color: var(--muted);
  background: #fbf5eb;
}

.honor-card {
  padding: 16px;
  border: 1px solid #eadfce;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #fffdfa;
}

.honor-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.honor-person {
  display: block;
  font-size: 20px;
  font-weight: 800;
}

.honor-time {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.honor-card h3 {
  margin: 14px 0 0;
  color: #342e27;
  font-size: 17px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.honor-note {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid #dbc792;
  border-radius: 6px;
  color: #6a5424;
  background: #fff5cf;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.honor-edit-button {
  min-width: 56px;
  height: 32px;
  padding: 0 10px;
}

.site-page {
  min-height: 100vh;
  padding: 34px 28px;
  background: #f6f2ea;
}

.site-shell {
  width: min(1120px, calc(100vw - 56px));
  margin: 0 auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 0 26px;
  border-bottom: 1px solid var(--line);
}

.site-header h1 {
  font-size: 38px;
}

.site-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  margin-top: 24px;
  align-items: start;
}

/* 访客（非管理员）看不到编辑面板时，收起右栏空位，内容单栏居中 */
body:not(.is-admin) .honor-layout,
body:not(.is-admin) .site-layout {
  grid-template-columns: minmax(0, 1fr);
}

.site-map-panel,
.site-form-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.site-map-panel {
  padding: 20px;
}

.site-form-panel {
  position: sticky;
  top: 22px;
  padding: 20px;
}

.site-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid #eadfce;
}

.site-title-row h2,
.site-form-panel h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

.site-meta,
.site-coords {
  color: var(--muted);
  font-size: 13px;
}

.site-coords {
  flex: 0 0 auto;
  max-width: 240px;
  padding: 7px 10px;
  border: 1px solid #eadfce;
  border-radius: 6px;
  background: #f5ecde;
  text-align: right;
}

.site-map-frame {
  position: relative;
  overflow: hidden;
  height: 520px;
  margin-top: 16px;
  border: 1px solid #d7c9b8;
  border-radius: 8px;
  background:
    linear-gradient(#efe5d8 1px, transparent 1px),
    linear-gradient(90deg, #efe5d8 1px, transparent 1px);
  background-color: #fffaf2;
  background-size: 28px 28px;
}

.site-map-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.site-map-empty {
  display: grid;
  height: 100%;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.site-note {
  margin: 14px 0 0;
  padding: 10px 12px;
  border: 1px solid #dbc792;
  border-radius: 6px;
  color: #6a5424;
  background: #fff5cf;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.site-map-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.site-map-actions button,
.map-link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 112px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  text-decoration: none;
  font-size: 14px;
}

.map-link-button:hover {
  border-color: var(--line-strong);
}

.map-link-button.is-disabled {
  pointer-events: none;
  opacity: 0.46;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  margin: 0 0 14px;
  font-size: 16px;
}

h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-box {
  display: flex;
  align-items: center;
  width: 280px;
  height: 40px;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
}

.search-box span {
  flex-shrink: 0;
  white-space: nowrap;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  /* 必须显式声明行高：只写列定义时隐式行是 auto，
     会被画布内容（上万像素）撑高，viewport 就永远量不到真实高度 */
  grid-template-rows: minmax(0, 1fr);
  height: calc(100vh - 87px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  padding: 16px;
  border-right: 1px solid var(--line);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stats-panel div {
  min-height: 72px;
  padding: 10px 8px;
  border-radius: 6px;
  background: #f0e5d6;
  text-align: center;
}

.stats-panel strong {
  display: block;
  font-size: 24px;
  line-height: 1.2;
}

.stats-panel span {
  color: var(--muted);
  font-size: 13px;
}

/* 统计格子下面那行说明：横跨三列，不占格子背景 */
.stats-panel .stats-note {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.55;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
}

.plain-button {
  width: 100%;
  margin-top: 16px;
}

.generation-list {
  /* 可以撑满剩余空间，但不能被压缩：flex-shrink 设 0，
     否则 12 代列表会把面板压到只剩前几代，后面几代溢出到边框外面 */
  flex: 1 0 auto;
  min-height: 220px;
}

.generation-order {
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid #eadfce;
  border-radius: 6px;
  background: #f5ecde;
}

.generation-order span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.generation-order strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}

.generation-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #eadfce;
  color: var(--muted);
  font-size: 14px;
}

.generation-item:last-child {
  border-bottom: 0;
}

.viewer {
  position: relative;
  display: grid;
  grid-template-rows: 54px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbf5eb;
}

.toolbar button {
  width: 38px;
}

.toolbar input {
  width: 220px;
}

#zoomLabel {
  width: 52px;
  color: var(--muted);
  font-size: 14px;
}

.viewport {
  position: relative;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
  background:
    linear-gradient(#efe5d8 1px, transparent 1px),
    linear-gradient(90deg, #efe5d8 1px, transparent 1px);
  background-color: #fffaf2;
  background-size: 28px 28px;
}

.viewport.is-dragging {
  cursor: grabbing;
}

.tree-space {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}

.tree-canvas {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}

.link-layer,
.node-layer {
  position: absolute;
  inset: 0;
}

.link-layer path {
  fill: none;
  stroke: #baa78c;
  stroke-width: 2;
}

.person-node {
  position: absolute;
  width: 168px;
  min-height: 132px;
  padding: 10px;
  border: 1px solid #d7c9b8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 8px 20px rgba(62, 43, 20, 0.1);
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.person-node:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.person-node.is-match {
  background: var(--mark);
  border-color: #c8952b;
}

.person-node.is-hidden-match {
  opacity: 0.2;
}

.person-node.compact {
  min-height: 68px;
}

.gender-box {
  display: -webkit-box;
  overflow: hidden;
  min-height: 38px;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink);
  font-size: calc(var(--node-font-size, 16px) * var(--node-font-boost, 1));
  font-weight: 700;
  line-height: 1.2;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.female-box,
.empty-box {
  margin-top: 10px;
}

.male-box {
  border-color: var(--male-border);
  background: var(--male-bg);
}

.female-box {
  border-color: var(--female-border);
  background: var(--female-bg);
}

.empty-box {
  border-color: var(--empty-border);
  color: #8d8276;
  background: var(--empty-bg);
  font-weight: 600;
}

.person-node.compact .female-box,
.person-node.compact .empty-box,
.person-node.compact .member-note {
  display: none;
}

.member-note {
  overflow: hidden;
  margin-top: 8px;
  padding: 5px 8px;
  border: 1px solid #dbc792;
  border-radius: 6px;
  color: #6a5424;
  background: #fff5cf;
  font-size: calc(12px * var(--node-font-boost, 1));
  font-weight: 600;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 折叠徽标：节点被折叠时提示「还有后代可以展开」
   --badge-boost 由 JS 按当前缩放反向设置，缩小时把徽标放大，保证屏幕上始终看得清 */
.collapse-badge {
  position: absolute;
  left: 50%;
  top: calc(100% + 5px);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: #fff;
  background: var(--accent);
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transform-origin: 50% 0;
  transform: translateX(-50%) scale(var(--badge-boost, 1));
  box-shadow: 0 3px 10px rgba(34, 107, 93, 0.38);
  transition: background 120ms ease, transform 120ms ease;
}

.collapse-badge:hover {
  background: var(--accent-dark);
  transform: translateX(-50%) scale(calc(var(--badge-boost, 1) * 1.06));
}

/* 折叠节点底部加一道虚线，暗示「下面还有」 */
.person-node.is-collapsed {
  border-bottom-style: dashed;
  border-bottom-color: var(--accent);
}

/* 上方还有更早的祖先 */
.collapse-badge.is-top {
  top: auto;
  bottom: calc(100% + 5px);
  transform-origin: 50% 100%;
  border-color: var(--line-strong);
  background: #8a7660;
  box-shadow: 0 3px 10px rgba(93, 74, 53, 0.3);
}

.collapse-badge.is-top:hover {
  background: #6f5d4a;
}

/* 旁边还有没画出来的旁支：做成安静的标签，别抢了人名的注意力 */
.collapse-badge.is-side {
  border-color: #c9a86a;
  color: #8a6b2f;
  background: #fffdf7;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(140, 106, 42, 0.16);
}

.collapse-badge.is-side:hover {
  color: #fff;
  background: #a8843f;
  border-color: #a8843f;
}

/* 同一节点上挂了两个提示时，第二个往下让开，别叠在一起 */
.collapse-badge + .collapse-badge:not(.is-top) {
  top: calc(100% + 37px);
}

/* 「看哪里」小面板 */
.focus-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 8px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.focus-row span {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink);
}

.focus-row button {
  flex: none;
  height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
  white-space: nowrap;
}

.focus-tip {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--muted);
}

.panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.panel-actions button {
  height: 32px;
  min-width: 0;
  padding: 0 6px;
  font-size: 13px;
}

.legend {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 8;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.92);
  box-shadow: 0 10px 24px rgba(43, 31, 18, 0.1);
  color: var(--muted);
  font-size: 13px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 18px;
  height: 14px;
  border: 1px solid transparent;
  border-radius: 4px;
}

.male-swatch {
  border-color: var(--male-border);
  background: var(--male-bg);
}

.female-swatch {
  border-color: var(--female-border);
  background: var(--female-bg);
}

.empty-swatch {
  border-color: var(--empty-border);
  background: var(--empty-bg);
}

.icon-button {
  min-width: 64px;
  padding: 0 12px;
}

.primary-button {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.primary-button:hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 20;
  width: 360px;
  height: 100vh;
  overflow: auto;
  /* 底部多留一段：右下角的「问助手」悬浮球会挡住抽屉最下面的按钮 */
  padding: 22px 22px 84px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  transform: translateX(104%);
  transition: transform 180ms ease;
}

.drawer.is-open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  /* 悬浮固定：下拉到任何位置都可见，不用滚回顶部找「关闭」 */
  position: sticky;
  top: 0;
  z-index: 5;
  margin: -22px -22px 14px;
  padding: 16px 22px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.drawer-note {
  margin: 4px 0 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

#assistantTestResult {
  color: var(--accent);
  word-break: break-all;
}

.field {
  display: block;
  margin-top: 14px;
}

.field span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 14px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: 0;
  background: #fff;
}

.field input,
.field select {
  height: 40px;
}

.field textarea {
  min-height: 96px;
  padding-top: 10px;
  padding-bottom: 10px;
  line-height: 1.6;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent);
}

.drawer-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.drawer-actions button {
  flex: 1;
}

.drawer-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #eadfce;
}

.relation-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.relation-actions button {
  min-width: 0;
  padding: 0 8px;
}

.danger-zone {
  padding-bottom: 8px;
}

.danger-button,
.plain-button.danger {
  border-color: #e6b8b2;
  color: #9c2d25;
  background: #f8e5e1;
}

.danger-button:hover,
.plain-button.danger:hover {
  border-color: #ca857b;
}

.empty-state {
  position: absolute;
  left: 50%;
  top: 50%;
  color: var(--muted);
  transform: translate(-50%, -50%);
}

/* ---------------- 登录页 ---------------- */

.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 38px 28px;
}

/* 水墨山水背景：登录 / 首页 / 光荣榜 / 祭祖地共用，族谱页是全屏画布不铺 */
.login-page,
.intro-page,
.honor-page,
.site-page {
  --page-photo: url('assets/login-bg.jpg');
  --page-veil: linear-gradient(180deg, rgba(246, 242, 234, 0.30) 0%, rgba(246, 242, 234, 0.52) 52%, rgba(246, 242, 234, 0.78) 100%);
  background-color: var(--bg);
  background-image: var(--page-veil), var(--page-photo);
  background-size: cover, cover;
  background-position: center, center 72%;
  background-repeat: no-repeat, no-repeat;
}

/* 首页/榜单/祭祖地是文字直接落在底上，纱要更厚，读起来才不费劲 */
.intro-page,
.honor-page,
.site-page {
  --page-veil: linear-gradient(180deg, rgba(246, 242, 234, 0.72) 0%, rgba(246, 242, 234, 0.84) 55%, rgba(246, 242, 234, 0.9) 100%);
}

/* 竖屏换成专门的竖版底图：横版在竖屏只会裁出中间一条，「張」正好被卡片挡住 */
@media (max-aspect-ratio: 3/4) {
  .login-page,
  .intro-page,
  .honor-page,
  .site-page {
    --page-photo: url('assets/login-bg-portrait.jpg');
    background-position: center, center;
  }
}

/* 卡片做成半透明的宣纸感，压在山水上不突兀 */
.login-page .login-shell {
  background: rgba(255, 253, 248, 0.93);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 20px 48px rgba(96, 82, 58, 0.16);
}

.login-shell {
  width: min(460px, calc(100vw - 56px));
  padding: 40px 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-shell .eyebrow {
  margin: 0 0 6px;
}

.login-shell h1 {
  margin: 0 0 10px;
  font-size: 34px;
}

.login-lead {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.login-tabs {
  display: flex;
  gap: 8px;
  /* 去掉登录页那段引导语后，标题和 Tab 挨得太近，补一点间距
     （h1 自带 10px 下边距，相邻外边距会合并，取大值） */
  margin-top: 22px;
  margin-bottom: 20px;
}

.login-tab {
  flex: 1;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.login-tab.is-active {
  border-color: var(--accent);
  color: var(--accent-dark);
  font-weight: 650;
  background: var(--male-bg);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 管理员的「记住我」与说明 */
.admin-remember {
  margin-top: -4px;
  font-size: 13.5px;
}

.login-hint {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
}

.login-submit {
  height: 40px;
}

.login-error {
  margin: 14px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--female-border);
  border-radius: 6px;
  background: var(--female-bg);
  color: #8f3040;
  font-size: 14px;
}

/* ---------------- 身份标识 / 权限 ---------------- */

.user-badge {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--male-bg);
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.logout-button {
  height: 30px;
  color: var(--muted);
}

.logout-button:hover {
  color: var(--ink);
}

.person-node.is-own .gender-box:first-child {
  box-shadow: 0 0 0 3px var(--mark);
}

/* 当前聚焦的这个人：绿色描边 + 外光晕，让「以谁为中心」一眼看得见 */
.person-node.is-focus {
  border-color: var(--accent);
  border-width: 2px;
  box-shadow: 0 0 0 5px rgba(34, 107, 93, 0.13), 0 10px 24px rgba(62, 43, 20, 0.14);
}

.person-node.is-focus .gender-box:first-child {
  font-weight: 800;
}

.honor-actions {
  display: flex;
  gap: 8px;
}

.honor-delete-button {
  color: #8f3040;
}

/* ---------------- 前言内容编辑 ---------------- */

.intro-blocks {
  display: grid;
  gap: 16px;
}

.intro-blocks .intro-lead {
  margin: 0;
}

.intro-head-blocks {
  min-width: 0;
}

.cs-label {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.cs-move {
  flex-shrink: 0;
  width: 26px;
  padding: 0;
}

.cs-common {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.cs-common-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
}

.cs-fontsize {
  width: 60px;
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.cs-common .cs-style,
.cs-common .cs-align,
.cs-common .cs-valign {
  height: 30px;
}

.cs-add-row {
  display: flex;
  gap: 8px;
  margin: 12px 0 4px;
}

.cs-add-row .cs-style {
  flex: 1;
  height: 36px;
}

.drawer textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
  box-sizing: border-box;
}

.drawer textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.content-section-editor {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cs-head {
  display: flex;
  gap: 8px;
  align-items: center;
}

.cs-title {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

.cs-style {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.cs-remove {
  flex-shrink: 0;
  color: #8f3040;
}

/* ---------------- 外观设置面板 ---------------- */

.settings-group-title {
  margin: 22px 0 12px;
  padding-top: 16px;
  border-top: 1px solid #eadfce;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

/* 「管理员密码」单独分区，和上面的外观设置隔开 */
.settings-group-title.account-group {
  margin-top: 32px;
  padding-top: 22px;
  color: var(--ink);
}

.password-message {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.55;
}

.password-message.is-ok {
  color: var(--accent);
}

.password-message.is-error {
  color: #b4322d;
  font-weight: 600;
}

/* 游客点进祭祖地看到的拦截提示 */
.site-blocked {
  max-width: 420px;
  margin: 72px auto;
  padding: 44px 28px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  text-align: center;
}

.site-blocked p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

/* 游客看到的都是打码名字，搜索没有意义，直接收起来免得误会 */
body.is-guest .search-box {
  display: none;
}

.security-log {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid #eadfce;
}

.security-log li {
  padding: 7px 0;
  border-bottom: 1px solid #f1e8db;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
  word-break: break-all;
}

.color-field input[type='color'] {
  width: 100%;
  height: 40px;
  padding: 3px 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

/* ---------------- 智能问答助手 ---------------- */

.assistant-bubble {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: 48px;
  padding: 0 20px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 2px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(34, 107, 93, 0.35);
  transition: transform 0.15s ease, background 0.15s ease;
}

.assistant-bubble:hover {
  background: var(--accent-dark);
  transform: scale(1.06);
}

.assistant-panel {
  position: fixed;
  right: 20px;
  bottom: 84px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  width: min(360px, calc(100vw - 32px));
  height: min(520px, calc(100vh - 140px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 12px 32px rgba(39, 35, 31, 0.18);
}

.assistant-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--male-bg);
}

.assistant-header h2 {
  margin: 0;
  font-size: 16px;
}

.assistant-model-label {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.assistant-header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.assistant-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 14px;
  background: var(--bg);
}

.assistant-msg {
  max-width: 86%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.assistant-msg.is-bot {
  align-self: flex-start;
  border: 1px solid var(--line);
  background: var(--panel);
  border-bottom-left-radius: 4px;
}

.assistant-msg.is-user {
  align-self: flex-end;
  border: 1px solid var(--accent-dark);
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.assistant-msg.is-error {
  align-self: flex-start;
  border: 1px solid var(--female-border);
  background: var(--female-bg);
  color: #8f3040;
}

.assistant-msg.is-typing {
  color: var(--muted);
  font-style: italic;
}

.assistant-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.assistant-form input {
  flex: 1;
  min-width: 0;
}

.assistant-form .primary-button {
  flex-shrink: 0;
}

/* 助手管理抽屉 */

.kb-editor {
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.kb-head {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.kb-head .kb-title {
  flex: 1;
  min-width: 0;
}

.kb-editor textarea {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
}

.assistant-logs {
  max-height: 320px;
  overflow-y: auto;
}

.assistant-log-item {
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.assistant-log-meta {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.assistant-log-question {
  margin: 0 0 4px;
  font-weight: 650;
}

.assistant-log-answer {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 640px) {
  .assistant-panel {
    right: 16px;
    bottom: 78px;
  }

  .site-beian {
    gap: 4px 10px;
    padding: 8px 0 0;
    font-size: 11.5px;
  }

  .site-beian .beian-police {
    gap: 10px;
  }

  /* 手机上这一行会折行，竖线容易跑到行首，干脆去掉靠间距区分 */
  .site-beian .beian-sep {
    display: none;
  }

  .site-beian {
    gap: 2px 14px;
  }

  /* 手机上这一行会折行，竖线容易跑到行首，干脆去掉靠间距区分 */
  .site-beian .beian-sep {
    display: none;
  }

  .site-beian {
    gap: 2px 14px;
  }

  /* 三个 Tab 在窄屏容易把「家族成员登录」挤成两行，缩一号字并把内边距收窄 */
  .login-tabs {
    gap: 6px;
  }

  .login-tab {
    padding: 0 4px;
    font-size: 12.5px;
  }
}

/* ================= 移动端 / 窄屏适配（≤900px） ================= */

/* 只在窄屏出现的控件（侧栏开关） */
.mobile-only {
  display: none !important;
}

@media (max-width: 900px) {
  .mobile-only {
    display: inline-flex !important;
  }

  /* 底部备案行要躲开右下角「智能问答助手」悬浮球，平板和手机统一留够 */
  .site-beian {
    padding-bottom: 84px;
  }

  /* ---- 族谱页顶栏：标题一行，按钮条横向滚动 ---- */
  .app-header {
    flex-wrap: wrap;
    gap: 10px 12px;
    min-height: 0;
    padding: 12px 14px;
  }

  .app-header > div:first-child {
    flex: 1 1 auto;
    min-width: 0;
  }

  .app-header h1 {
    font-size: 22px;
  }

  .header-actions {
    order: 3;
    width: 100%;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .header-actions::-webkit-scrollbar {
    display: none;
  }

  .header-actions > * {
    flex: 0 0 auto;
  }

  .search-box {
    width: 196px;
    height: 36px;
  }

  .icon-button {
    min-width: 52px;
    padding: 0 10px;
    font-size: 13px;
  }

  /* ---- 侧栏改为左侧抽屉，默认收起 ---- */
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 60;
    width: min(300px, 86vw);
    padding: 14px;
    border-right: 1px solid var(--line);
    background: var(--bg);
    box-shadow: 0 0 48px rgba(43, 31, 18, 0.22);
    transform: translateX(-103%);
    transition: transform 200ms ease;
  }

  body.sidebar-open .sidebar {
    transform: none;
  }

  .toolbar {
    gap: 8px;
    padding: 8px 12px;
  }

  .toolbar input {
    flex: 1;
    width: auto;
    min-width: 0;
  }

  .legend {
    left: 10px;
    bottom: 10px;
    padding: 8px 10px;
    font-size: 12px;
  }

  /* ---- 前言 / 光荣榜 / 祭祖地：收窄边距、统一单栏 ---- */
  .intro-page,
  .honor-page,
  .site-page {
    padding: 22px 16px 32px;
  }

  .intro-shell,
  .honor-shell,
  .site-shell {
    width: 100%;
  }

  .intro-header,
  .honor-header,
  .site-header {
    flex-wrap: wrap;
    gap: 14px;
    padding: 14px 0 16px;
  }

  .intro-header h1,
  .honor-header h1,
  .site-header h1 {
    font-size: 28px;
  }

  .intro-actions,
  .footer-actions {
    flex-wrap: wrap;
  }

  .intro-lead {
    margin: 22px 0 16px;
    padding: 18px;
  }

  .intro-lead p {
    font-size: 17px;
    line-height: 1.8;
  }

  .intro-section {
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 12px;
    padding: 16px;
  }

  .section-kicker {
    width: 32px;
    height: 32px;
    font-size: 13px;
  }

  .intro-footer {
    flex-wrap: wrap;
    gap: 10px;
  }

  /* 管理员在手机上同样单栏，360px 右栏会横向溢出 */
  .honor-layout,
  .site-layout,
  body.is-admin .honor-layout,
  body.is-admin .site-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .honor-form-panel,
  .site-form-panel {
    position: static;
  }

  .honor-list-panel {
    min-height: 0;
  }

  .honor-empty {
    min-height: 200px;
  }

  .site-map-frame {
    height: 320px;
  }

  /* 三个地图按钮各带 min-width:112px，在手机上会横向顶出 3px */
  .site-map-actions {
    flex-wrap: wrap;
  }

  .site-map-actions button,
  .map-link-button {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 13px;
  }

  /* ---- 抽屉：手机上按屏宽铺开 ---- */
  .drawer {
    width: min(400px, 100vw);
    /* 底部同样给「问助手」悬浮球让位 */
    padding: 16px 16px 100px;
  }

  .drawer-header {
    margin: -16px -16px 12px;
    padding: 14px 16px 10px;
  }

  .login-page {
    padding: 22px 16px;
  }

  .login-shell {
    width: 100%;
    padding: 28px 22px;
  }

  .login-shell h1 {
    font-size: 28px;
  }

  /* ---- 助手 ---- */
  .assistant-bubble {
    right: 14px;
    bottom: 14px;
    height: 44px;
    padding: 0 16px;
    font-size: 15px;
    letter-spacing: 1px;
  }

  .assistant-panel {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 68px;
    height: min(62vh, 480px);
  }
}


