:root {
  --bg: #f7f6f2;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #c9ccd1;
  --card: #ffffff;
  --accent: #b5542d;
  --accent-soft: #f3e3da;
  --union: #2f6f9f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --ink: #e8e6e1;
    --muted: #9aa0a6;
    --line: #3a3f46;
    --card: #1f2227;
    --accent: #e0825a;
    --accent-soft: #3b2a22;
    --union: #6fa8d6;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
}

header, footer {
  padding: 24px 16px;
  max-width: 1100px;
  margin: 0 auto;
}

h1 { margin: 0 0 4px; font-size: 1.6rem; letter-spacing: 0.01em; }
.sub { margin: 0; color: var(--muted); }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

.status {
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  margin-bottom: 16px;
}
.status.error { border-color: var(--accent); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.toolbar button {
  font: inherit;
  font-size: 0.9rem;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}
.toolbar button:hover { border-color: var(--accent); }
.toolbar .hint { color: var(--muted); font-size: 0.85rem; }

.toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  padding: 8px 0;
}

.tree {
  overflow-x: auto;
  padding-bottom: 24px;
}

svg { display: block; }

.node { cursor: pointer; }
.node.leaf { cursor: default; }
.node.collapsed rect { stroke-dasharray: 4 3; }
.node.deceased .name { fill: var(--muted); }
.node.root rect { stroke-width: 2px; }

.node .name { font-size: 13px; font-weight: 600; fill: var(--ink); }
.node .years { font-size: 10.5px; fill: var(--muted); }

.order circle { fill: var(--bg); stroke: var(--line); stroke-width: 1.5px; }
.order text { font-size: 10px; fill: var(--muted); font-weight: 600; }

.badge rect { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1px; }
.badge text { font-size: 11px; fill: var(--accent); font-weight: 600; }

.link {
  fill: none;
  stroke: var(--line);
  stroke-width: 2px;
}

.node rect {
  fill: var(--card);
  stroke: var(--line);
  stroke-width: 1.5px;
  rx: 6px;
}
.node.root rect { stroke: var(--accent); }

.node text { font-size: 13px; fill: var(--ink); }
.node .years { font-size: 11px; fill: var(--muted); }

.union-dot {
  fill: var(--union);
}
.union-label {
  font-size: 11px;
  fill: var(--union);
}

footer p { color: var(--muted); font-size: 0.9rem; }

/* navigation between pages */
.nav { display: flex; gap: 14px; margin-top: 6px; font-size: 0.95rem; }
.nav a { color: var(--muted); text-decoration: none; padding-bottom: 2px; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--ink); }
.nav a.current { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------------------------------------------------------------------- */
/* Timeline page                                                           */
/* ---------------------------------------------------------------------- */
.timeline-page {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tl-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: 16px 16px 10px;
  max-width: none;
  margin: 0;
}
.tl-header h1 { font-size: 1.3rem; }
.tl-counter { text-align: right; line-height: 1.1; }
.tl-year { display: block; font-size: 1.8rem; font-weight: 700; min-height: 1.2em; font-variant-numeric: tabular-nums; }
.tl-count { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

.stage {
  flex: 1;
  min-height: 0;
  margin: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  overflow: hidden;
  cursor: grab;
}
.stage:active { cursor: grabbing; }
.stage svg { width: 100%; height: 100%; }

.tl-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 10px 16px 14px;
}
.tl-controls button {
  font: inherit; font-size: 0.9rem; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--card); color: var(--ink); cursor: pointer;
}
.tl-controls button.primary { background: var(--accent); border-color: var(--accent); color: #fff; min-width: 84px; }
.tl-controls label { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); }
.tl-speed input { width: 110px; }
.tl-scrub { flex: 1 1 220px; min-width: 160px; accent-color: var(--accent); }
.tl-follow input[type="text"], .tl-follow input:not([type]) {
  font: inherit; font-size: 0.9rem; padding: 6px 10px; width: 200px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink);
}
.tl-follow button { padding: 4px 9px; }

/* nodes during playback */
.tl-node { transition: opacity 0.3s; }
.tl-node.hidden { opacity: 0 !important; pointer-events: none; }
.tl-node rect { transform-box: fill-box; transform-origin: center; }
.tl-node.married rect { stroke: var(--union); }
.tl-link.hidden { opacity: 0; }
.tl-spouse { font-size: 13px; font-weight: 600; fill: var(--union); }

@media (max-width: 700px) {
  .tl-header { align-items: flex-start; }
  .tl-year { font-size: 1.3rem; }
  .tl-follow input:not([type]) { width: 150px; }
}
