:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page-plane:     #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border-hairline: rgba(11,11,11,0.10);
  --success-text:   #006300;

  /* sequential blue ramp, used ordinally by generation depth */
  --seq-250: #86b6ef;
  --seq-350: #5598e7;
  --seq-450: #2a78d6;
  --seq-550: #1c5cab;
  --seq-650: #104281;

  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page-plane:     #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border-hairline: rgba(255,255,255,0.10);
    --success-text:   #0ca30c;

    --seq-250: #86b6ef;
    --seq-350: #5598e7;
    --seq-450: #2a78d6;
    --seq-550: #1c5cab;
    --seq-650: #104281;

    --series-1: #3987e5;
    --series-2: #d95926;
  }
}

/* Explicit theme choice (data-theme on <html>) overrides the OS preference above. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page-plane:     #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border-hairline: rgba(255,255,255,0.10);
  --success-text:   #0ca30c;

  --seq-250: #86b6ef;
  --seq-350: #5598e7;
  --seq-450: #2a78d6;
  --seq-550: #1c5cab;
  --seq-650: #104281;

  --series-1: #3987e5;
  --series-2: #d95926;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.viz-root { padding: 24px; max-width: 1200px; margin: 0 auto; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.app-header h1 { font-size: 22px; margin: 0; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.status-line { color: var(--text-secondary); font-size: 13px; }

.btn {
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-hairline);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
}
.btn:hover { border-color: var(--series-1); }
.btn-toggle.active { background: var(--series-1); color: #fff; border-color: var(--series-1); }

.theme-controls { display: flex; gap: 6px; }
.theme-controls .btn { padding: 6px 10px; }

.filter-row { display: flex; gap: 8px; margin-bottom: 12px; }

.table-filter {
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-hairline);
  background: var(--page-plane);
  color: var(--text-primary);
  width: 100%;
  flex: 1;
}
.table-filter:focus { outline: none; border-color: var(--series-1); }
.table-filter::-webkit-search-cancel-button { display: none; }

.filter-clear { padding: 6px 12px; font-size: 15px; line-height: 1; }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 20px;
}
.panel h2 { font-size: 15px; margin: 0 0 12px; color: var(--text-secondary); font-weight: 600; }

.panel-row { display: flex; gap: 20px; margin-bottom: 20px; }
.panel-row .panel { flex: 1; margin-bottom: 0; min-width: 0; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: 10px;
  padding: 16px 18px;
}
.stat-tile .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.stat-tile .stat-value {
  font-size: 32px;
  font-weight: 600;
  font-variant-numeric: proportional-nums;
}

.birthdays-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
}
.bday-card {
  border: 1px solid var(--border-hairline);
  border-radius: 10px;
  background: var(--page-plane);
  text-align: center;
  overflow: hidden;
}
.bday-card-month {
  background: var(--series-1);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 4px 0;
}
.bday-card-day {
  font-size: 28px;
  font-weight: 700;
  padding: 8px 0 2px;
  font-variant-numeric: tabular-nums;
}
.bday-card-name {
  font-size: 13px;
  padding: 0 8px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bday-card-when {
  font-size: 11px;
  color: var(--text-secondary);
  padding: 2px 8px 10px;
}
.bday-card.is-today { border-color: var(--series-2); }
.bday-card.is-today .bday-card-month { background: var(--series-2); }

.gender-chart-row { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.gender-donut { flex-shrink: 0; }
.gender-donut circle.gender-arc { transition: stroke-dasharray 0.2s; }
.gender-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.gender-legend-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.gender-swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.gender-legend-label { color: var(--text-primary); min-width: 60px; }
.gender-legend-count { color: var(--text-secondary); font-variant-numeric: tabular-nums; }

.dow-chart { display: flex; gap: 10px; align-items: flex-end; }
.dow-bar-item { flex: 1; display: flex; flex-direction: column; align-items: center; }
.dow-bar-track {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 110px;
  width: 100%;
}
.dow-bar-value { font-size: 11px; color: var(--text-secondary); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.dow-bar { width: 100%; max-width: 28px; border-radius: 4px 4px 0 0; background: var(--baseline); }
.dow-bar.is-top { background: var(--series-1); }
.dow-bar-label { font-size: 11px; color: var(--text-secondary); margin-top: 6px; }
.dow-bar-item.is-top .dow-bar-label { color: var(--text-primary); font-weight: 600; }

.tree-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.tree-panel-header h2 { margin: 0; }
.tree-controls { display: flex; gap: 6px; }

.tree-scroll {
  overflow: auto;
  border: 1px solid var(--gridline);
  border-radius: 8px;
  background: var(--page-plane);
  height: 560px;
  position: relative;
  cursor: grab;
}
.tree-scroll.dragging { cursor: grabbing; }
.tree-canvas { position: relative; transform-origin: top left; }

.tree-node {
  position: absolute;
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-top: 4px solid var(--series-1);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.tree-node .member-name { color: var(--text-primary); font-weight: 600; }
.tree-node .member-name.spouse { font-weight: 400; color: var(--text-secondary); }
.tree-node .member-meta { color: var(--text-muted); font-size: 11px; }

.tree-svg { position: absolute; top: 0; left: 0; pointer-events: none; }
.tree-edge { stroke: var(--baseline); stroke-width: 1.5px; fill: none; }

.table-wrap { overflow: auto; max-height: 560px; }
#generation-body { overflow-x: auto; }
.tree-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tree-table th, .tree-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}
.tree-table th { color: var(--text-secondary); font-weight: 600; position: sticky; top: 0; background: var(--surface-1); }

.app-footer { margin-top: 12px; color: var(--text-muted); font-size: 12px; text-align: center; }

.empty-note { color: var(--text-muted); font-size: 13px; }

@media (max-width: 640px) {
  .viz-root { padding: 16px; }

  .app-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .header-actions { flex-wrap: wrap; width: 100%; gap: 8px; }

  .panel { padding: 14px 16px; }
  .panel-row { flex-direction: column; gap: 16px; }

  .tree-panel-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .tree-controls { flex-wrap: wrap; }

  .stat-row { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
  .stat-tile { padding: 12px 14px; }
  .stat-tile .stat-value { font-size: 26px; }

  .tree-scroll { height: 380px; }

  .birthdays-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; }
}
