.dynasty-connection-explorer {
  --ink: #262c29;
  --muted: #515c52;
  --forest: #1e4138;
  --forest-dark: #17332d;
  --surface: #fffdf7;
  --paper: #f5f1e9;
  --line: #d6cdbd;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --shadow: 0 14px 38px #263e3310;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.55 Inter, system-ui, sans-serif;
}

.dynasty-connection-explorer :is(h1, h2, h3, p) { margin: 0; }
.dynasty-connection-explorer :is(button, select, input) { font: inherit; color: inherit; }
.dynasty-connection-explorer button { cursor: pointer; }
.dynasty-connection-explorer a { color: var(--forest); text-underline-offset: .18em; }
.dynasty-connection-explorer [hidden] { display: none !important; }
.dynasty-connection-explorer :focus-visible { outline: 3px solid #8b4d33; outline-offset: 3px; }
.dynasty-connection-explorer .wrap { width: min(1312px, calc(100% - clamp(28px, 7vw, 112px))); }

.dynasty-connection-explorer .hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: 0;
  color: #fff9ed;
  background: var(--forest-dark);
  border-bottom: 4px solid #af8750;
}
.hero-image { position: absolute; inset: 0 0 0 52%; margin: 0; z-index: -1; }
.hero-image img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center 38%; }
.hero-image::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #17332d, #17332db2 28%, #18322e28 71%), linear-gradient(0deg, #192e2ab8, transparent 45%);
}
.hero-image figcaption {
  position: absolute;
  bottom: .6rem;
  right: .9rem;
  z-index: 1;
  background: #1a302a;
  border-radius: 4px;
  padding: .15rem .45rem;
  font-size: .74rem;
}
.dynasty-connection-explorer .hero-image a { color: #fff7e8; }
.dynasty-connection-explorer .hero a:focus-visible { outline-color: #ffd99f; }
.hero-copy { position: relative; padding-block: 2rem 2.75rem; pointer-events: none; }
.dynasty-connection-explorer .hero h1 {
  max-width: 22ch;
  margin: .55rem 0 .38rem;
  font: 700 clamp(2.55rem, 5.7vw, 5.6rem)/.97 var(--serif);
  letter-spacing: -.033em;
}
.dynasty-connection-explorer .hero-copy > p:last-child { color: #f9efda; max-width: 35rem; font-size: 1.05rem; }
.explorer-breadcrumb { display: flex; align-items: baseline; gap: .65rem; }
.dynasty-connection-explorer .explorer-breadcrumb a { color: #fae2bc; font-size: .94rem; font-weight: 650; pointer-events: auto; }

.explorer-workspace { padding-block: 1.65rem 2.75rem; }
.modes { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: .85rem; }
.dynasty-connection-explorer :is(.modes button, .example-buttons button, .outline-button, .primary-button) {
  min-height: 42px;
  padding: .35rem .7rem;
  border: 1px solid #ccbda7;
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  font-size: .875rem;
  font-weight: 650;
}
.dynasty-connection-explorer :is(.modes button, .example-buttons button, .outline-button):hover { background: #f4ead8; }
.dynasty-connection-explorer :is(.modes button, .example-buttons button)[aria-pressed="true"],
.dynasty-connection-explorer button.primary-button { background: var(--forest); border-color: var(--forest); color: #fff9ee; }
.dynasty-connection-explorer button.primary-button:hover { background: var(--forest-dark); }

.control-panel, .panel {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.control-panel { margin-bottom: 1.1rem; }
.control-row {
  display: grid;
  grid-template-columns: minmax(0, .85fr) minmax(0, 1fr) minmax(0, 1.4fr);
  align-items: end;
  gap: .85rem;
  padding: .95rem 1.1rem;
}
.select-field { position: relative; }
.select-field::after {
  content: '';
  position: absolute;
  right: .7rem;
  bottom: 1.12rem;
  width: .45rem;
  height: .45rem;
  border: solid var(--forest);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  pointer-events: none;
}
.control-panel label, .control-panel legend, .examples p { display: block; font-size: .9rem; font-weight: 650; }
.select-field label, .control-panel legend { margin-bottom: .25rem; }
.dynasty-connection-explorer .select-field select {
  width: 100%;
  min-height: 43px;
  padding: .4rem 1.65rem .4rem .57rem;
  border: 1px solid #aebeb1;
  border-radius: 5px;
  background: #fffefb;
  appearance: none;
}
.control-panel fieldset { margin: 0; padding: 0; min-width: 0; border: 0; }
.control-panel legend { padding: 0; }
.type-controls, .example-buttons { display: flex; flex-wrap: wrap; gap: .35rem; }
.type-controls .filter {
  display: inline-flex;
  align-items: center;
  gap: .36rem;
  min-height: 43px;
  padding: .36rem .52rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fffefb;
  cursor: pointer;
}
.type-controls .filter:has(:checked) { color: var(--tie); background: var(--wash); }
.filter input { accent-color: var(--tie); width: 16px; height: 16px; margin: 0; }
.family { --tie: #28483b; --wash: #e6efe5; }
.marriage { --tie: #653049; --wash: #f2e3ec; }
.political { --tie: #634321; --wash: #f0e5cf; }

.compare-controls .control-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.examples {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .4rem .65rem;
  border-top: 1px solid var(--line);
  padding: .68rem 1.1rem;
  color: var(--muted);
}
.dynasty-connection-explorer .example-buttons button { min-height: 36px; padding: .25rem .55rem; }

.explore-layout, .compare-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(18rem, 1fr);
  gap: 1.1rem;
  align-items: start;
}
.panel { padding: .95rem 1.1rem; }
.panel h2 { color: var(--forest); font: 700 clamp(1.65rem, 2.8vw, 2.25rem)/1.05 var(--serif); }
.panel-heading { margin-bottom: .68rem; }
.dynasty-connection-explorer :is(.panel-heading p, .small) { margin-top: .22rem; color: var(--muted); font-size: .9rem; }
.graph {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr) minmax(0, 1fr);
  gap: clamp(.7rem, 3.6vw, 2.75rem);
  align-items: center;
  min-height: 220px;
  padding: .85rem;
  border: 1px solid #cdd8ca;
  border-radius: 5px;
  background: #e9eee4;
}
.graph canvas { position: absolute; z-index: -1; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.graph-column { display: grid; align-content: center; gap: .5rem; }
.graph-center { min-width: 0; }
.dynasty-connection-explorer :is(.edge-node, .focus-node) {
  display: block;
  width: 100%;
  min-width: 0;
  padding: .52rem .6rem;
  border-radius: 5px;
  text-align: left;
  overflow-wrap: anywhere;
}
.dynasty-connection-explorer .edge-node {
  border: 1px solid #b1c1b4;
  border-inline-start: 3px solid var(--tie);
  background: var(--surface);
}
.dynasty-connection-explorer .edge-node:hover { background: var(--wash); border-color: var(--tie); }
.dynasty-connection-explorer .edge-node[aria-pressed="true"] { background: var(--wash); border-color: var(--tie); box-shadow: inset 0 0 0 1px var(--tie); }
.edge-node strong, .focus-node strong { display: block; font: 700 1.28rem/1.05 var(--serif); }
.edge-node strong { color: var(--forest); }
.edge-node small, .focus-node small { display: block; margin-top: .2rem; font-size: .8rem; line-height: 1.35; }
.edge-node small { color: var(--tie); }
.dynasty-connection-explorer .focus-node { background: var(--forest); color: #fff9ed; }
.focus-node small { color: #f0e8d8; }
.dynasty-connection-explorer .graph-note { margin-top: .48rem; }
.graph-empty { grid-column: 1 / -1; color: var(--muted); font-size: .9rem; text-align: center; }

.evidence-panel { border-top: 3px solid #af8750; }
#evidence { padding-top: .68rem; }
.dynasty-connection-explorer .evidence-person { margin: .35rem 0 .12rem; color: var(--forest); font: 700 1.8rem/1.05 var(--serif); }
.type-label { display: inline-block; padding: .1rem .4rem; border-radius: 4px; color: var(--tie); background: var(--wash); font-size: .875rem; font-weight: 650; }
.dynasty-connection-explorer .evidence-text { margin-block: .55rem .5rem; font-size: .96rem; }
.source-link { display: inline-block; font-size: .875rem; overflow-wrap: anywhere; }
.detail-actions { display: flex; flex-wrap: wrap; gap: .42rem; margin-top: .8rem; }
.detail-actions a { align-self: center; font-size: .875rem; font-weight: 650; margin-right: .2rem; }

.result-head { margin: .75rem 0; padding: .68rem .82rem; border: 1px solid #cdd8ca; border-radius: 5px; background: #edf1e9; }
.result-head h3 { color: var(--forest); font: 700 clamp(1.75rem, 3.4vw, 2.4rem)/1.08 var(--serif); }
.dynasty-connection-explorer .result-head p { margin-top: .25rem; font-size: .9rem; }
.shared-ancestor { color: var(--forest); font-weight: 650; font-size: .94rem; }
.shared-ancestor-list { margin: .25rem 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: .35rem; }
.shared-ancestor-list li { padding: .16rem .43rem; background: #f2eadb; border-radius: 4px; font-size: .875rem; }
.branches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; margin-top: .55rem; }
.branch { min-width: 0; border: 1px solid var(--line); border-radius: 5px; padding: .55rem .62rem; background: #fffefa; }
.branch h4 { margin: 0; font: 700 1.28rem/1.08 var(--serif); color: var(--forest); }
.branch small { color: var(--muted); font-size: .8rem; }
.branch ol { margin: .4rem 0 0; list-style: none; padding: 0; font-size: .86rem; }
.branch li + li { margin-top: .2rem; padding-left: .6rem; border-left: 2px solid #c9d8cb; }
.branch li span, .branch li a.source-link { font-size: .82rem; }
.alternate-branches { margin-top: .55rem; }
.alternate-branches summary { width: fit-content; padding-block: .25rem; color: var(--forest); font-size: .875rem; font-weight: 650; cursor: pointer; }
.dynasty-connection-explorer .relations { display: grid; gap: .45rem; margin: .65rem 0 0; padding: 0; list-style: none; }
.relations li { min-width: 0; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 5px; }
.dynasty-connection-explorer .relations li p { margin: .22rem 0 .12rem; font-size: .9rem; }
.dynasty-connection-explorer .relations a { background: none; padding: 0; text-decoration: underline; font-size: .875rem; }
.trail { list-style: none; margin: .6rem 0 0; padding: 0; }
.trail li { margin-top: .25rem; font-size: .9rem; }
.trail li + li { margin-left: .25rem; padding-left: .55rem; border-left: 2px solid var(--tie); }
.trail .type-label { margin-bottom: .15rem; }
.trail a.source-link { display: block; }
.dynasty-connection-explorer .method {
  border-top: 1px solid var(--line);
  color: var(--muted);
  margin-top: 1.45rem;
  padding-top: .65rem;
  font-size: .9rem;
}

@media (max-width: 860px) {
  .explore-layout, .compare-layout { grid-template-columns: minmax(0, 1fr); }
  .explore-controls .control-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .explore-controls fieldset { grid-column: 1 / -1; }
}
@media (max-width: 680px) {
  .hero-image { inset-inline-start: 27%; }
  .hero-image::after { background: linear-gradient(90deg, #17332d, #17332dcf 57%, #17332d99); }
  .hero-image figcaption { max-width: calc(100% - 1.8rem); }
  .hero-copy { padding-block: 1.35rem 3.65rem; }
  .control-row, .panel, .examples { padding: .7rem; }
}
@media (max-width: 540px) {
  .explorer-workspace { padding-block: 1.1rem 2rem; }
  .modes { margin-bottom: .65rem; }
  .modes button { flex: 1 1 145px; }
  .control-row { gap: .55rem; }
  .graph { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .52rem; padding: .5rem; min-height: 0; align-items: start; }
  .graph canvas { display: none; }
  .graph-center { grid-column: 1 / -1; grid-row: 1; }
  .branches { grid-template-columns: minmax(0, 1fr); }
}
