/* 丙洲陳氏族譜網 · 姻親族譜圖 (meChart.aspx) */
html, body.chart-page { height: 100%; overflow: hidden; }
body.chart-page {
  display: flex;
  flex-direction: column;
  margin: 0;
  background-attachment: scroll;
  --male: #23408e;
  --female: #b8261b;
  --added: #f6dd6a;
}
body.chart-page form { margin: 0; }
.msg { display: block; padding: 6px 16px 0; color: var(--cinnabar); }

/* ---------- 工具列 ---------- */
.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 6px;
}
.search { position: relative; flex: 1 1 240px; max-width: 360px; }
.search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); font-size: 19px; color: var(--ink-soft); pointer-events: none; }
.search input {
  width: 100%;
  height: 40px;
  padding: 0 12px 0 38px;
  font-family: var(--font-serif);
  font-size: 15px;
  background: #fffaf0;
  border: 1px solid var(--paper-edge);
  border-radius: 20px;
  outline: none;
}
.search input:focus { border-color: var(--cinnabar); box-shadow: 0 0 0 3px rgba(158, 42, 30, .12); }
.results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 30;
  max-height: 50vh;
  overflow-y: auto;
  background: #fffaf0;
  border: 1px solid var(--paper-edge);
  border-top: 3px solid var(--cinnabar);
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.results[hidden] { display: none; }
.r { padding: 7px 14px; border-bottom: 1px dotted var(--paper-edge); cursor: pointer; }
.r:hover { background: rgba(195, 154, 78, .14); }
.r.empty { color: var(--ink-soft); cursor: default; }
.r .sub { font-size: 13px; color: #8a7663; }
.male { color: var(--male); }
.female { color: var(--female); }

.seg {
  display: inline-flex;
  padding: 3px;
  background: #fffaf0;
  border: 1px solid var(--paper-edge);
  border-radius: 22px;
}
.seg button {
  height: 34px;
  min-width: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 17px;
  background: none;
  font-family: var(--font-kai);
  font-size: 16px;
  color: var(--ink);
  cursor: pointer;
}
.seg button:hover { background: rgba(195, 154, 78, .18); }
.seg button.on { background: var(--wood-2); color: #fff3cf; }

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 0 16px 8px;
  font-size: 13px;
  color: var(--ink-soft);
}
.legend b { font-family: var(--font-kai); font-size: 20px; font-weight: 400; color: var(--wood-2); margin-right: 6px; }
.lg { display: inline-flex; align-items: center; gap: 4px; }
.lg.male { color: var(--male); }
.lg.female { color: var(--female); }
.lg.added::before { content: ""; width: 14px; height: 14px; background: var(--added); border: 1px solid #c9a93a; border-radius: 3px; }
.lg.dead i, .nd .tag {
  font-style: normal;
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  font-size: 11px;
  color: #fff;
  background: #6d6158;
  border-radius: 50%;
}
.lg-count { margin-left: auto; }

/* ---------- 畫布 ---------- */
.viewport {
  position: relative;
  flex: 1;
  margin: 0 16px 16px;
  overflow: hidden;
  background: #fffdf7;
  border: 1px solid var(--paper-edge);
  border-radius: 4px;
  box-shadow: inset 0 0 30px rgba(195, 154, 78, .12);
  cursor: grab;
  touch-action: none;
}
.viewport.dragging { cursor: grabbing; }
.canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.canvas.anim { transition: transform .35s ease; }
.edges { position: absolute; left: 0; top: 0; overflow: visible; }
.edges path { fill: none; stroke: #8f7a63; stroke-width: 1.3; }
.mode-h .edges path { stroke: #c9ad85; stroke-width: 1.6; }
.nodes { position: absolute; left: 0; top: 0; }

/* 節點 */
.nd {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eef2fa;
  border: 1px solid #6c7a99;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .15);
  cursor: pointer;
  user-select: none;
}
.nd .nm {
  font-family: var(--font-kai);
  font-size: 18px;
  font-weight: 600;
  color: var(--male);
  line-height: 1.15;
}
.nd.female .nm { color: var(--female); }
.nd.added { background: var(--added); border-color: #b8952a; }
.nd.dead { border-style: double; border-width: 3px; }
.nd .tag { position: absolute; top: -7px; right: -7px; }
.nd:hover { box-shadow: 0 0 0 3px rgba(158, 42, 30, .25); }
.nd.hit { box-shadow: 0 0 0 3px var(--cinnabar), 0 0 14px rgba(158, 42, 30, .5); }
.nd.root { background: var(--wood-2); border-color: var(--wood); }
.nd.root .nm { color: #fff3cf; }

.mode-v .nd .nm { writing-mode: vertical-rl; text-orientation: upright; letter-spacing: 2px; }

.mode-h .nd {
  flex-direction: column;
  padding: 0;
  background: #fdf6e3;
  border: 1px solid #c9ad85;
  border-radius: 3px;
  box-shadow: inset 0 0 0 3px #fdf6e3, inset 0 0 0 4px #e3d1ad;
  overflow: hidden;
}
.mode-h .nd .meta {
  align-self: stretch;
  padding: 2px 4px;
  font-size: 12px;
  text-align: center;
  color: #5b4d2c;
  background: #dccd8c;
  margin: 4px 4px 0;
}
.mode-h .nd .nm { flex: 1; display: grid; place-items: center; font-size: 19px; font-weight: 400; }
.mode-h .nd.added { background: var(--added); box-shadow: inset 0 0 0 3px var(--added), inset 0 0 0 4px #c9a93a; }
.mode-h .nd.root { background: var(--wood-2); box-shadow: none; }
.mode-h .nd.root .meta { background: rgba(255, 243, 207, .2); color: #fff3cf; }

.gen {
  position: absolute;
  transform: translateX(-50%);
  font-size: 12px;
  color: #6d6158;
  white-space: nowrap;
  pointer-events: none;
}
.tgl {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  font-size: 12px;
  line-height: 18px;
  color: #4a3a12;
  background: #dccd8c;
  border: 1px solid #a8964c;
  border-radius: 10px;
  cursor: pointer;
  z-index: 2;
}
.tgl:hover { background: var(--cinnabar); border-color: var(--cinnabar); color: #fff; }

/* ---------- 資料卡 ---------- */
.card {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 40;
  width: 280px;
  padding: 14px 16px;
  background: #fffaf0;
  border: 1px solid var(--paper-edge);
  border-top: 3px solid var(--cinnabar);
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.card[hidden] { display: none; }
.card .x { position: absolute; top: 6px; right: 8px; border: 0; background: none; font-size: 16px; color: var(--ink-soft); cursor: pointer; }
.c-top { display: flex; gap: 12px; align-items: center; }
.c-top img { width: 56px; height: 68px; object-fit: cover; border: 1px solid var(--paper-edge); border-radius: 3px; }
.c-seal { display: grid; place-items: center; width: 48px; height: 48px; font-family: var(--font-kai); font-size: 22px; color: rgba(158, 42, 30, .5); background: var(--paper-2); border-radius: 4px; }
.c-name { font-family: var(--font-kai); font-size: 24px; }
.c-sub { font-size: 13px; color: var(--ink-soft); }
.card dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 12px 0 10px; font-size: 14px; }
.card dt { color: var(--ink-soft); }
.card dd { margin: 0; }
.c-act { display: flex; flex-wrap: wrap; gap: 6px; }
.c-act a {
  padding: 4px 12px;
  font-size: 13px;
  border: 1px solid var(--paper-edge);
  border-radius: 14px;
  color: var(--wood-2);
  background: #fff;
}
.c-act a:hover { color: #fff; background: var(--cinnabar); border-color: var(--cinnabar); text-decoration: none; }

@media (max-width: 640px) {
  .bar { padding: 8px 10px 4px; }
  .search { max-width: none; flex-basis: 100%; }
  .legend { padding: 0 10px 6px; }
  .lg-count { margin-left: 0; }
  .viewport { margin: 0 10px 10px; }
  .card { left: 10px; right: 10px; bottom: 10px; width: auto; }
}

@media print {
  .bar, .card, .tgl { display: none !important; }
  html, body.chart-page { height: auto; overflow: visible; }
  .viewport { border: 0; box-shadow: none; overflow: visible; }
}

/* 滑鼠移入時的浮動卡；點一下固定 (顯示 ✕) */
.card { pointer-events: auto; animation: cardIn .15s ease-out; }
.card:not(.pinned) .x { display: none; }
.card:not(.pinned)::after {
  content: "點一下可固定此卡";
  display: block;
  margin-top: 8px;
  font-size: 11px;
  color: #a8957d;
  text-align: right;
}
.card.pinned { border-top-color: var(--wood-2); }
@keyframes cardIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* 有相片者：名字下方小圖示 */
.nd .pic {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 16px;
  color: #8a6a2c;
  border-radius: 3px;
  line-height: 0;
}
.nd .pic:hover { color: #fff; background: var(--cinnabar); text-decoration: none; }
.mode-v .nd { flex-direction: column; gap: 1px; }
.mode-v .nd .pic { margin-top: 1px; }
.nd.root .pic { color: #f3d58e; }
.mode-h .nd .nm { display: flex; align-items: center; justify-content: center; gap: 4px; }
.mode-h .nd .pic { position: absolute; right: 4px; bottom: 4px; }

/* 資料待補：姓名空白 / 性別依名稱推定 */
.nd.noname { background: #f4f1ea; border-style: dashed; border-color: #a99a85; }
.nd.noname .nm { color: #a99a85; font-weight: 400; font-size: 14px; }
.nd.guess { outline: 1px dashed var(--female); outline-offset: 2px; }
.c-warn {
  margin-top: 10px;
  padding: 5px 8px;
  font-size: 12.5px;
  color: #8a4b12;
  background: #fbefd5;
  border-left: 3px solid #d08a2a;
  border-radius: 3px;
}
