.directory:has(.profile-hero) {
  grid-template-columns: minmax(10rem, .3fr) minmax(0, 1fr);
  align-items: start;
}

.person:has(.profile-hero) {
  --profile-inset: clamp(1rem, 3vw, 2.2rem);
  min-width: 0;
  padding: 0;
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.profile-hero {
  display: flex;
  align-items: center;
  gap: clamp(.8rem, 2.6vw, 1.6rem);
  padding: clamp(1.35rem, 3.9vw, 2.55rem) var(--profile-inset);
  border-bottom: 1px solid var(--border);
  border-radius: calc(1rem - 1px) calc(1rem - 1px) 0 0;
  background: linear-gradient(125deg, var(--panel), color-mix(in srgb, var(--panel) 55%, var(--surface)));
}

.profile-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: clamp(3.1rem, 7vw, 4.65rem);
  aspect-ratio: 1;
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  font: 400 clamp(1.15rem, 2.8vw, 1.65rem)/1 var(--serif);
  box-shadow: 0 4px 15px color-mix(in srgb, var(--accent) 9%, transparent);
}

:is(.profile-avatar, .compact-portrait) {
  position: relative;
  overflow: hidden;
}

:is(.profile-avatar, .compact-portrait) > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.compact-portrait {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  font: 400 .83rem/1 var(--serif);
}

.person-link-portrait { gap: .55rem; }

.pedigree-chart .pedigree-node {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: .45rem;
}

.pedigree-node-copy { display: grid; min-width: 0; }

#anulka-fan-roster .fan-roster-person { gap: .5rem; }
#anulka-fan-roster .fan-roster-copy { flex: 1; min-width: 0; }

.profile-identity { min-width: 0; }

.profile-identity .kicker {
  margin-bottom: .35rem;
  color: var(--accent);
}

.profile-identity h3 {
  margin: 0;
  color: var(--text);
  font: 400 clamp(1.75rem, 4.1vw, 3rem)/1.08 var(--serif);
  letter-spacing: -.035em;
}

.profile-identity p:not(.kicker) {
  margin: .5rem 0 0;
  color: var(--muted);
  font-size: .88rem;
}

.profile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem;
  padding: 1.05rem var(--profile-inset) 0;
}

.profile-actions :is(.button-link, .person-link) {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: .48rem .75rem;
  border-radius: .55rem;
  font-size: .83rem;
  font-weight: 650;
  line-height: 1.35;
}

.profile-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .15rem .65rem;
  margin: 1rem var(--profile-inset) 0;
  border-bottom: 1px solid var(--border);
}

.profile-tabs button {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: .55rem .6rem;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: .45rem .45rem 0 0;
  background: none;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 650;
}

.profile-tabs button:hover { background: var(--paper); }

.profile-tabs button[aria-selected="true"] {
  margin-bottom: -1px;
  border-bottom-color: var(--accent);
  color: var(--text);
}

.profile-panel {
  min-width: 0;
  padding: 1.5rem var(--profile-inset) 1.75rem;
}

.profile-panel > :first-child { margin-top: 0; }
.profile-panel > :last-child { margin-bottom: 0; }

.profile-panel h4 {
  margin: 0 0 .75rem;
  font: 400 1.32rem/1.2 var(--serif);
}

.person .profile-panel dl {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr));
  gap: .55rem 1rem;
  margin: .75rem 0 1.2rem;
}

.profile-panel dl > div {
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: .5rem;
  background: var(--paper);
}

.profile-panel dt { font-weight: 650; }
.profile-panel dd { margin-top: .15rem; }

.profile-relatives {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
  gap: .55rem;
}

.person .profile-relatives > li { margin: 0; }

.profile-relative {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  justify-items: start;
  align-items: center;
  gap: .5rem;
  width: 100%;
  min-height: 3.65rem;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: .55rem;
  background: var(--paper);
  color: var(--text);
  font-size: .86rem;
  font-weight: 650;
  text-decoration: none;
}

.profile-relative:hover {
  border-color: var(--panel-border);
  background: var(--panel);
}

.profile-relation {
  color: var(--muted);
  font-size: .7rem;
  font-weight: 550;
}

.profile-tree-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: .55rem;
  margin-bottom: .85rem;
}

.profile-tree-controls label { width: auto; }
.profile-tree-controls button { min-height: 2.75rem; }

.profile-pedigree {
  min-width: 0;
  max-width: 100%;
}

.profile-empty {
  margin: .5rem 0;
  color: var(--muted);
  font-size: .9rem;
}

.person .profile-timeline {
  display: grid;
  gap: 0;
  margin: .65rem 0 1rem;
  padding: 0;
  list-style: none;
}

.person .profile-timeline > li {
  position: relative;
  margin: 0 0 0 .25rem;
  padding: .3rem 0 .85rem 1rem;
  border-left: 1px solid var(--panel-border);
}

.profile-timeline > li::before {
  position: absolute;
  top: .65rem;
  left: -.26rem;
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  background: var(--accent);
  content: "";
}

.profile-timeline time {
  margin-right: .45rem;
  color: var(--accent);
  font-weight: 650;
}

@media (max-width: 700px) {
  .directory:has(.profile-hero) { grid-template-columns: minmax(0, 1fr); }
  .profile-tabs { column-gap: .25rem; }
  .profile-tabs button { font-size: .8rem; }
}

#tree-mode-picker {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin: 0 0 1rem;
}

#tree-mode-picker button {
  min-height: 2.75rem;
  padding: .45rem .8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: .85rem;
  font-weight: 650;
}

#tree-mode-picker button:hover { background: var(--panel); }

#tree-mode-picker button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.tree-mode-panel {
  --line: var(--border);
  --surface-2: var(--panel);
  --text-soft: var(--muted);
  min-width: 0;
}

.tree-mode-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .75rem;
  margin-bottom: .7rem;
}

.tree-mode-toolbar button { min-height: 2.75rem; }
.tree-mode-toolbar output { font-size: .86rem; font-variant-numeric: tabular-nums; }

#strom:fullscreen, #strom.tree-expanded {
  overflow: auto;
  padding: clamp(1rem, 4vw, 3rem);
  background: var(--surface);
}
#strom.tree-expanded {
  position: fixed;
  z-index: 20;
  inset: 0;
  width: 100%;
  margin: 0;
  border-radius: 0;
  overscroll-behavior: contain;
}
html:has(#strom.tree-expanded) { overflow: hidden; }
.tree-network-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: .65rem 1rem;
  margin-bottom: .9rem;
  padding: .9rem 1rem;
  border: 1px solid var(--border);
  border-radius: .85rem;
  background: var(--surface);
}
.tree-network-heading > div { flex: 1 1 14rem; }
.tree-network-heading h3, .tree-network-heading p { margin: 0; }
.tree-network-heading p { color: var(--muted); }
.tree-network-heading .field { min-width: min(100%, 10rem); }
.tree-side-toggle { display: inline-flex; align-items: center; gap: .4rem; min-height: 2.75rem; color: var(--text); }
.tree-side-toggle input { width: 1.12rem; height: 1.12rem; accent-color: var(--accent); }
.tree-network-detail { padding: 1rem; margin-top: 1rem; border: 1px solid var(--border); border-radius: .85rem; background: var(--surface); }
.tree-network-detail :is(h4, p, h5) { margin: .25rem 0 .5rem; }
.tree-network-identity, .tree-network-relatives { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; }
.tree-network-relatives { margin-bottom: .75rem; }
#pedigree, #tree-descendants-list { height: clamp(17rem, 66svh, 43rem); }
:is(#pedigree, #tree-descendants-list, .profile-pedigree) { overscroll-behavior-x: contain; }
:is(#tree-classic, #tree-descendants) .tree-mode-toolbar button,
.profile-classic-zoom button { min-inline-size: 2.75rem; }
#anulka-fan-stage { touch-action: pan-x pan-y; }
.pedigree-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem 1rem;
  margin: .2rem 0 .65rem;
  color: var(--muted);
  font-size: .84rem;
}
.pedigree-legend strong { color: var(--text); margin-inline-end: auto; }
.pedigree-key { display: inline-flex; align-items: center; gap: .4rem; }
.pedigree-key::before { content: ''; width: 1.4rem; border-block-start: 4px solid #916745; border-radius: 1rem; }
.pedigree-key-partner::before { border-block-start: 2px dashed currentColor; }
.tree-roster { margin-top: 1rem; border: 1px solid var(--border); border-radius: .85rem; }

#strom > .tree-mode-toolbar { align-items: end; }

.tree-find-results {
  display: grid;
  gap: .35rem;
  margin: 0 0 .8rem;
  padding: 0;
  list-style: none;
}

.tree-find-results[hidden] { display: none; }

.tree-mode-help {
  margin: .4rem 0 .8rem;
  color: var(--muted);
  font-size: .85rem;
}

#anulka-fan-stage {
  max-width: 100%;
  max-height: min(75svh, 51rem);
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: .8rem;
  background:
    radial-gradient(ellipse at 50% 45%, var(--surface), transparent 72%),
    radial-gradient(circle, var(--panel-border) .75px, transparent .75px) 0 0 / 19px 19px,
    var(--panel);
}

#anulka-fan-stage:focus-visible { outline-offset: -3px; }

.anulka-fan-canvas {
  width: calc(100% * var(--anulka-fan-scale, 1));
  min-width: 0;
  margin-inline: auto;
  padding: clamp(.55rem, 2vw, 1.35rem);
}

#anulka-fan-roster {
  margin-top: .55rem;
}

#tree-path .field { max-width: 27rem; }

.tree-path-steps {
  display: grid;
  gap: .6rem;
  padding-inline-start: 1.75rem;
}

.tree-path-steps small {
  display: inline-block;
  margin-inline-end: .6rem;
  color: var(--muted);
}

#tree-descendants-list > .profile-empty { margin: 1rem; }
#tree-descendants-list:has(> .profile-empty) { height: auto; }
.profile-tree-controls .profile-classic-zoom { margin: 0; }

@media (max-width: 700px) {
  #tree-mode-picker { gap: .3rem; }
  #tree-mode-picker button { padding-inline: .65rem; font-size: .8rem; }
  #anulka-fan-stage { max-height: 65svh; }
}

.directory-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .8rem;
}
.directory-toolbar .data-status { margin: 0; }
.directory-toolbar button[aria-pressed="true"] { background: var(--panel); border-color: var(--accent); }
.person dl.profile-timeline > div {
  display: grid;
  grid-template-columns: minmax(6rem, 9rem) minmax(0, 1fr);
  gap: .65rem;
  align-items: baseline;
  padding-block: .65rem;
  border-bottom: 1px solid var(--border);
}
.person .profile-timeline dd { font-weight: 600; }
@media (max-width: 700px) {
  .has-open-profile .directory > .person { grid-row: 1; }
}
