:root {
  --ink: #2b2620;
  --ink2: #6b6152;
  --paper: #f3ede1;
  --card: #ffffff;
  --line: #b9ad99;
  --accent: #7a5c3e;
  --male: #3b6ea5;
  --female: #a5476a;
  --unknown: #8a8072;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", Verdana, sans-serif;
  color: var(--ink);
  overflow: hidden;
}

#toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  z-index: 20;
  overflow-x: auto;
  overflow-y: hidden;
}
#toolbar h1 { font-size: 1rem; margin: 0; color: var(--accent); white-space: nowrap; flex-shrink: 0; }
#toolbar .spacer { flex: 1; min-width: 8px; }
#toolbar button, #toolbar a {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 7px 12px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.status { flex-shrink: 0; white-space: nowrap; }

@media (max-width: 480px) {
  #toolbar { gap: 6px; padding: 0 8px; }
  #toolbar h1 { font-size: 0; }
  #toolbar h1::before { content: "🌳"; font-size: 1.2rem; }
  #toolbar button, #toolbar a { font-size: 0.78rem; padding: 6px 9px; }
  .status { font-size: 0.68rem; }
}
#toolbar button:hover, #toolbar a:hover { background: #f1ece3; }
.status { font-size: 0.75rem; color: var(--ink2); }
.status.live::before { content: "●"; color: #2e7d4f; margin-right: 4px; }
.status.down::before { content: "●"; color: #b23a2e; margin-right: 4px; }

#stage {
  position: absolute;
  top: 52px; left: 0; right: 0; bottom: 0;
  background: var(--paper);
  overflow: hidden;
  touch-action: none;
}

#canvas { width: 100%; height: 100%; display: block; cursor: grab; }
#canvas.grabbing { cursor: grabbing; }

.edge-line { stroke: var(--line); stroke-width: 1.6; fill: none; }
.edge-spouse { stroke: var(--accent); stroke-width: 2; }

.node-wrap { cursor: pointer; user-select: none; }
.node-wrap .card-bg {
  fill: var(--card);
  stroke: var(--line);
  stroke-width: 1;
  filter: drop-shadow(0 1px 2px rgba(60, 50, 30, 0.18));
}
.node-wrap:hover .card-bg { filter: drop-shadow(0 2px 5px rgba(60, 50, 30, 0.3)); }
.node-wrap .card-accent { stroke: var(--unknown); stroke-width: 5; stroke-linecap: round; }
.node-wrap.sex-M .card-accent { stroke: var(--male); }
.node-wrap.sex-F .card-accent { stroke: var(--female); }
.node-wrap .name-text { font-size: 12px; font-weight: 600; fill: var(--ink); }
.node-wrap .dates-text { font-size: 10.5px; fill: var(--ink2); }

.node-actions { opacity: 0.55; transition: opacity 0.12s; }
.node-wrap:hover .node-actions, .node-wrap:focus .node-actions { opacity: 1; }
.node-actions circle {
  fill: #fff;
  stroke: var(--line);
  stroke-width: 1;
}
.node-actions text {
  font-size: 11px;
  text-anchor: middle;
  dominant-baseline: central;
  fill: var(--ink);
  pointer-events: none;
}
.node-actions g:hover circle { fill: var(--accent); }
.node-actions g:hover text { fill: #fff; }

#panel {
  position: fixed;
  top: 52px; right: 0; bottom: 0;
  width: 300px;
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -3px 0 10px rgba(0,0,0,0.08);
  z-index: 30;
  padding: 16px;
  overflow-y: auto;
  transition: transform 0.18s ease;
}
#panel.hidden { transform: translateX(320px); pointer-events: none; }
#panel .close {
  position: absolute; top: 8px; right: 10px;
  border: none; background: none; font-size: 20px; cursor: pointer; color: var(--ink2);
}
#panel label { display: block; font-size: 0.72rem; color: var(--ink2); margin: 10px 0 3px; }
#panel input, #panel select {
  width: 100%; padding: 6px 8px; font-size: 0.85rem;
  border: 1px solid var(--line); border-radius: 6px; font-family: inherit;
}
#panel .row { display: flex; gap: 8px; }
#panel .row > div { flex: 1; }
#panel .actions { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
#panel .actions button {
  padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: #fff;
  cursor: pointer; font-size: 0.85rem; font-family: inherit;
}
#panel .actions button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
#panel .actions button.danger { color: #b23a2e; border-color: #e2b6ae; }
#panel .actions button:hover { filter: brightness(0.95); }
#panel h3 { margin: 4px 0 0; font-size: 1rem; }
#panel .rel-list { font-size: 0.78rem; color: var(--ink2); margin: 4px 0 0; }
#panel .rel-list a { color: var(--accent); cursor: pointer; text-decoration: underline; }

#toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #2b2620; color: #fff; padding: 8px 16px; border-radius: 20px;
  font-size: 0.8rem; opacity: 0; pointer-events: none; transition: opacity 0.2s;
  z-index: 40;
}
#toast.show { opacity: 0.92; }
