/* ========== 全局重置 ========== */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-light: #F5F2EB;
  --card-bg: #FFFFFF;
  --text-dark: #2C2C2C;
  --accent-gold: #A68A56;
  --border-light: #E5D9C5;

  --node-width: 70px;
  --node-height: 60px;
  --level-gap: 80px;
  --vertical-gap: 30px;
  --font-size: 13px;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Noto Serif SC', serif;
  background-color: var(--bg-light);
  color: var(--text-dark);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ========== 头部：关键修复！ ========== */
.app-header {
  background: var(--card-bg);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  flex-wrap: nowrap;
  /* 强制不换行 */
  gap: 10px;
}

.header-left h1 {
  margin: 0;
  font-size: 1.4rem;
  /* 手机默认小一点，长标题能放下 */
  font-weight: 400;
  letter-spacing: 2px;
  color: var(--text-dark);
  white-space: nowrap;
  /* 标题不换行 */
}

.header-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  /* 防止被压缩 */
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-light);
  border-radius: 30px;
  padding: 3px 10px;
  border: 1px solid var(--border-light);
}

.search-box input {
  border: none;
  background: transparent;
  padding: 6px 4px;
  font-size: 14px;
  outline: none;
  width: 130px;
  /* 手机宽度减小，给标题让位 */
  font-family: inherit;
}

.search-box button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--accent-gold);
  font-size: 16px;
  padding: 0 4px;
}

.nav-controls {
  display: flex;
  gap: 5px;
}

.nav-controls button {
  background: var(--bg-light);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 5px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-dark);
  transition: all 0.2s;
  white-space: nowrap;
}

/* ========== 树图容器 ========== */
.tree-container {
  flex: 1;
  overflow: auto;
  position: relative;
  cursor: grab;
  background: var(--bg-light);
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  user-select: none;
}

.tree-container:active {
  cursor: grabbing;
}

.canvas-viewport {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  display: inline-block;
  padding: 40px 20px;
  transform-origin: 0 0;
  transition: transform 0.05s ease-out;
}

.family-tree {
  position: relative;
  display: inline-block;
}

/* ========== 节点卡片 ========== */
.person-card {
  position: absolute;
  width: var(--node-width);
  min-width: 44px;
  min-height: 44px;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 1px solid var(--border-light);
  transition: all 0.2s;
  cursor: pointer;
  color: var(--text-dark);
}

.person-card.selected {
  border: 2px solid var(--accent-gold);
  box-shadow: 0 6px 14px rgba(166, 138, 86, 0.2);
}

.person-card:active {
  opacity: 0.7;
}

.person-name {
  font-weight: 600;
  font-size: var(--font-size);
  line-height: 1.3;
}

.person-dates {
  font-size: calc(var(--font-size) - 3px);
  color: #777;
  white-space: nowrap;
}

.person-id {
  font-size: 9px;
  color: #aaa;
}

/* ========== 连线 ========== */
.branch-line {
  position: absolute;
  background-color: var(--accent-gold);
  opacity: 0.4;
  z-index: 1;
  pointer-events: none;
}

/* ========== 底部 ========== */
.app-footer {
  background: var(--card-bg);
  border-top: 1px solid var(--border-light);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: #666;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.detail-path {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: break-all;
  flex: 1;
}

.legend {
  display: flex;
  gap: 12px;
}

/* ========== 移动端精细调整（仅缩小尺寸，不破坏结构） ========== */
@media (max-width: 600px) {
  :root {
    --node-width: 55px;
    --level-gap: 50px;
    --font-size: 12px;
  }

  .app-header {
    padding: 8px 12px;
  }

  .header-left h1 {
    font-size: 1.1rem;
    /* 标题再小一点，保证“延津吴氏世系谱”完整显示 */
    letter-spacing: 1px;
  }

  .search-box input {
    width: 110px;
    font-size: 14px;
  }

  .nav-controls button {
    padding: 4px 8px;
    font-size: 12px;
  }

  .canvas-viewport {
    padding: 30px 10px;
  }

  .person-card {
    padding: 5px 2px;
  }

  .app-footer {
    padding: 8px 12px;
  }

  .detail-path {
    white-space: normal;
    /* 底部路径允许换行 */
    font-size: 11px;
  }
}

/* 超小屏（如 iPhone SE） */
@media (max-width: 380px) {
  .header-left h1 {
    font-size: 1rem;
  }

  .search-box input {
    width: 90px;
  }
}