:root {
  color-scheme: light;
  --paper: #f6f2ea;
  --panel: #fffaf1;
  --ink: #272521;
  --muted: #6d675f;
  --line: #d7cdbd;
  --accent: #2f6652;
  --accent-2: #385a78;
  --danger: #9c3d34;
  --shadow: 0 18px 40px rgba(39, 37, 33, 0.12);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.shell { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 241, 0.92);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-family: Georgia, "Times New Roman", serif; font-size: 1.45rem; color: var(--ink); }
.nav { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.nav a, .nav button, .button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 9px 12px;
  border-radius: var(--radius);
  cursor: pointer;
}
.nav a.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(47, 102, 82, 0.18);
}
.button.primary { background: var(--accent); border-color: var(--accent); color: white; }
.content { padding: 28px; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 20px;
  margin-bottom: 24px;
}
.page-title { font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 4vw, 3.5rem); margin: 0 0 20px; }
.grid { display: grid; gap: 18px; }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.metric { font-size: 2rem; font-weight: 700; }
.muted { color: var(--muted); }
.flash { padding: 12px 14px; border-radius: var(--radius); margin-bottom: 18px; border: 1px solid var(--line); background: #fff; }
.flash.error { border-color: var(--danger); color: var(--danger); }
label { display: grid; gap: 6px; font-weight: 650; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  color: var(--ink);
  padding: 10px 12px;
  font: inherit;
}
textarea { min-height: 120px; resize: vertical; }
.form-grid { display: grid; gap: 14px; max-width: 780px; }
.tree-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 360px;
  min-height: calc(100vh - 74px);
}
.tree-sidebar, .person-panel {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 18px;
}
.person-panel { border-right: 0; border-left: 1px solid var(--line); }
#treeCanvas {
  width: 100%;
  height: 100%;
  min-height: 720px;
  background:
    linear-gradient(rgba(215, 205, 189, 0.25) 1px, transparent 1px),
    linear-gradient(90deg, rgba(215, 205, 189, 0.25) 1px, transparent 1px),
    #fbf8f0;
  background-size: 42px 42px;
  position: relative;
  overflow: hidden;
  touch-action: none;
}
#treeViewport {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}
#treeEdges,
#treeNodes {
  position: absolute;
  inset: 0;
}
#treeEdges {
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}
#treeNodes {
  z-index: 2;
}
.tree-edge {
  fill: none;
  stroke: rgba(47, 102, 82, 0.6);
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tree-edge.partner {
  stroke: rgba(56, 90, 120, 0.78);
  stroke-width: 2.75;
}
.tree-edge.union {
  stroke: rgba(47, 102, 82, 0.72);
}
.tree-edge.child-bus {
  stroke: rgba(47, 102, 82, 0.55);
}
.node-card {
  position: absolute;
  width: 220px;
  min-height: 118px;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 12px 26px rgba(39, 37, 33, 0.13);
  cursor: pointer;
  text-align: left;
  display: grid;
  gap: 7px;
  color: var(--ink);
  z-index: 3;
}
.node-card:focus-visible {
  outline: 3px solid rgba(56, 90, 120, 0.45);
  outline-offset: 3px;
}
.node-card strong { font-size: 1rem; line-height: 1.25; }
.node-card small { color: var(--muted); line-height: 1.35; }
.node-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 102, 82, 0.16), 0 18px 36px rgba(39, 37, 33, 0.18);
}
.node-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.node-role {
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}
.node-branch-controls {
  display: inline-flex;
  gap: 4px;
}
.node-branch-controls button {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbf8f0;
  color: var(--accent-2);
  cursor: pointer;
  font-weight: 800;
  line-height: 1;
}
.node-branch-controls button:hover {
  border-color: var(--accent-2);
}
.union-node {
  position: absolute;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 2px solid rgba(47, 102, 82, 0.55);
  background: #fbf8f0;
  box-shadow: 0 0 0 5px rgba(251, 248, 240, 0.92);
  z-index: 2;
}
.union-node::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: inherit;
  background: var(--accent);
}
.tree-tools {
  display: grid;
  gap: 8px;
}
.tree-legend {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.92rem;
}
.tree-legend span {
  display: flex;
  align-items: center;
  gap: 9px;
}
.legend-line {
  display: inline-block;
  width: 34px;
  height: 2px;
  background: rgba(47, 102, 82, 0.65);
}
.legend-line.partner {
  background: rgba(56, 90, 120, 0.78);
}
.legend-dot {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(47, 102, 82, 0.55);
  border-radius: 999px;
  background: var(--accent);
  box-shadow: inset 0 0 0 4px #fbf8f0;
}
.person-facts {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 8px 12px;
}
.person-facts dt { color: var(--muted); }
.person-facts dd { margin: 0; }
.relation-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.panel-actions {
  margin-top: 14px;
}
.person-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 16px;
}
.person-tabs button {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 0.88rem;
}
.person-tabs button.active {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(47, 102, 82, 0.16);
}
.person-tab {
  display: none;
}
.person-tab.active {
  display: block;
}
.inline-form {
  display: grid;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.inline-form h3 {
  margin: 0;
}
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.media-grid article,
.stack-list article {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  padding: 10px;
  display: grid;
  gap: 6px;
}
.media-grid img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
}
.stack-list {
  display: grid;
  gap: 8px;
}
.stack-list small {
  color: var(--muted);
}
.link-button {
  border: 1px solid var(--line);
  background: white;
  color: var(--accent-2);
  border-radius: 999px;
  padding: 7px 10px;
  cursor: pointer;
}
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; }
.tab { border: 1px solid var(--line); border-radius: 999px; padding: 7px 10px; background: white; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 10px; vertical-align: top; }
th { color: var(--muted); font-size: 0.9rem; }
.footer { padding: 20px 28px; color: var(--muted); border-top: 1px solid var(--line); }
.admin-layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}
.admin-card h2 { margin-top: 0; }
.status-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  gap: 4px;
}
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.status-grid p,
.type-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  padding: 12px;
}
.status-grid p {
  margin: 0;
  display: grid;
  gap: 4px;
}
.status-grid span {
  color: var(--muted);
  overflow-wrap: anywhere;
}
.type-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}
.type-card {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.type-card input {
  width: auto;
}
.admin-table { margin-top: 22px; }
.research-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
  margin-bottom: 22px;
}
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  background: white;
}
.status-completed { color: var(--accent); border-color: rgba(47, 102, 82, 0.35); }
.status-running, .status-queued, .status-researching, .status-todo { color: var(--accent-2); border-color: rgba(56, 90, 120, 0.35); }
.status-failed, .status-blocked { color: var(--danger); border-color: rgba(156, 61, 52, 0.35); }
.family-admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 22px;
  align-items: start;
}
.family-list {
  display: grid;
  gap: 12px;
}
.family-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.family-row h2 { margin: 0 0 6px; }
.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: end;
}
.admin-side {
  display: grid;
  gap: 16px;
}
.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 10px;
}
.check-row input { width: auto; }
.landing {
  max-width: 1180px;
  margin: 0 auto;
}
.landing-hero {
  min-height: min(720px, calc(100vh - 150px));
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  align-items: center;
  gap: 48px;
  padding: 54px 0 42px;
}
.hero-copy {
  display: grid;
  justify-items: start;
  gap: 22px;
}
.hero-copy h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3rem, 7vw, 6.4rem);
  line-height: 0.96;
  text-wrap: balance;
  margin: 0;
  max-width: 760px;
}
.hero-copy p {
  font-size: 1.18rem;
  line-height: 1.75;
  color: var(--muted);
  max-width: 720px;
  margin: 0;
  text-wrap: pretty;
}
.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.archive-visual {
  min-height: 430px;
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(145deg, rgba(47, 102, 82, 0.12), transparent 42%),
    #efe6d6;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.archive-sheet {
  position: absolute;
  background: #fffaf1;
  border: 1px solid #cabda9;
  border-radius: 4px;
  box-shadow: 0 18px 35px rgba(39, 37, 33, 0.16);
}
.sheet-main {
  left: 16%;
  top: 16%;
  width: 58%;
  min-height: 240px;
  padding: 28px;
  transform: rotate(-3deg);
  display: grid;
  align-content: start;
  gap: 18px;
}
.sheet-main span,
.sheet-main small {
  color: var(--muted);
}
.sheet-main strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.6rem;
}
.sheet-photo {
  right: 12%;
  bottom: 12%;
  width: 34%;
  aspect-ratio: 4 / 5;
  transform: rotate(5deg);
  background:
    linear-gradient(180deg, rgba(56, 90, 120, 0.18), rgba(47, 102, 82, 0.2)),
    #d6c8b6;
}
.archive-thread {
  position: absolute;
  left: -8%;
  right: -8%;
  top: 56%;
  height: 2px;
  background: rgba(47, 102, 82, 0.35);
  transform: rotate(-8deg);
}
.public-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin: 6px 0 52px;
}
.public-stats.compact {
  margin: 22px 0;
}
.import-complete {
  max-width: 820px;
  margin: 40px auto;
}
.public-stats article,
.process-grid article,
.quiet-panel,
.contact-form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.public-stats article {
  padding: 22px;
  display: grid;
  gap: 6px;
}
.public-stats strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.5rem;
}
.public-stats span {
  color: var(--muted);
}
.landing-section {
  padding: 54px 0;
}
.landing-section h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 4vw, 3.6rem);
  margin: 0 0 18px;
  text-wrap: balance;
}
.landing-section p {
  color: var(--muted);
  line-height: 1.75;
  max-width: 760px;
}
.split-section,
.contact-section {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(340px, 1.1fr);
  gap: 34px;
  align-items: start;
}
.quiet-panel {
  padding: 26px;
}
.process-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.process-grid article {
  padding: 24px;
}
.process-grid h3 {
  margin: 0 0 10px;
  font-size: 1.25rem;
}
.contact-form {
  padding: 24px;
  display: grid;
  gap: 16px;
}
.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-errors {
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  background: #fff;
  padding: 12px 14px;
}
.form-errors p {
  margin: 0;
  color: inherit;
}
.honeypot {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.auth-page {
  min-height: calc(100vh - 180px);
  display: grid;
  place-items: center;
}
.auth-card {
  width: min(100%, 460px);
  padding: 28px;
}
.auth-card h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.4rem;
  margin: 0 0 8px;
}

@media (max-width: 980px) {
  .grid.cols-3, .grid.cols-4, .tree-layout, .landing-hero, .split-section, .contact-section, .public-stats, .process-grid, .form-row, .family-admin-grid, .research-grid { grid-template-columns: 1fr; }
  .tree-sidebar, .person-panel { border: 0; border-bottom: 1px solid var(--line); }
  .content { padding: 18px; }
  .landing-hero { min-height: auto; padding-top: 30px; }
  .archive-visual { min-height: 320px; }
  .family-row { align-items: start; flex-direction: column; }
  .page-head { display: block; }
}
