.chart-page {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    padding: var(--gutter);
    max-width: var(--content-max);
    margin: 0 auto;
}

.chart-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-surface);
    border: var(--border-strong-width) solid var(--border-strong);
    border-radius: var(--radius-card);
}

.chart-toolbar .field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin: 0;
}

.chart-toolbar__group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin: 0;
    padding: var(--space-2) var(--space-3);
    border: var(--border-hairline-width) solid var(--border-strong);
    border-radius: var(--radius-input);
}

.chart-toolbar__radio {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    min-height: var(--touch-target);
    font-size: var(--type-ui);
}

.chart-toolbar__pan {
    display: inline-flex;
    flex-wrap: wrap;
    gap: var(--space-1);
}

.chart-toolbar__tier {
    margin-left: auto;
}

.chart-note {
    margin: 0;
    font-size: var(--type-ui);
}

.chart-note--warning {
    padding: var(--space-2) var(--space-3);
    border-left: var(--border-strong-width) solid var(--warning);
    color: var(--text-primary);
    background: var(--bg-surface);
}

.chart-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
}

.chart-after {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.chart-equivalent {
    border: var(--border-hairline-width) solid var(--border-strong);
    border-radius: var(--radius-card);
    padding: var(--space-3);
}

.chart-equivalent > summary {
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    font-weight: 600;
    cursor: pointer;
}

.chart-table {
    margin-top: var(--space-3);
}

.chart-table caption {
    text-align: left;
    padding-bottom: var(--space-2);
    font-size: var(--type-small);
    color: var(--text-muted);
}

.chart-scroller {
    overflow-x: auto;
}

.skip-canvas {
    position: absolute;
    left: -9999px;
}

.skip-canvas:focus {
    position: static;
    left: auto;
    align-self: flex-start;
    padding: var(--space-2) var(--space-4);
    border: var(--border-strong-width) solid var(--border-strong);
    border-radius: var(--radius-input);
}

/* Tree canvas */

.tree-canvas {
    position: relative;
    overflow: auto;
    max-height: 80vh;
    background: var(--bg-page);
    border: var(--border-strong-width) solid var(--border-strong);
    border-radius: var(--radius-card);
}

.tree-canvas:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring);
    outline-offset: var(--focus-ring-offset);
}

.chart-svg {
    display: block;
    max-width: none;
}

.tree-link {
    fill: none;
    stroke: var(--border-strong);
    stroke-width: 1.5;
}

.tree-node__box {
    fill: var(--bg-surface);
    stroke: var(--border-strong);
    stroke-width: 2;
}

.tree-node--root .tree-node__box {
    stroke: var(--link);
    stroke-width: 3;
}

.tree-node--empty .tree-node__box {
    fill: none;
    stroke-dasharray: 4 4;
}

.tree-node__band--male {
    fill: var(--band-male);
}

.tree-node__band--female {
    fill: var(--band-female);
}

.tree-node__band--unknown {
    fill: var(--band-unknown);
}

.tree-node__name {
    fill: var(--text-primary);
    font-family: var(--font-ui);
    font-size: var(--type-dense);
    font-weight: 600;
}

.tree-node__surname {
    font-variant-caps: small-caps;
    letter-spacing: 0.02em;
}

.tree-node__years {
    fill: var(--text-muted);
    font-family: var(--font-ui);
    font-size: var(--type-small);
    font-variant-numeric: tabular-nums;
}

.tree-node__mark {
    fill: var(--text-muted);
    font-family: var(--font-ui);
    font-size: var(--type-micro);
}

.tree-node__mark--quiet {
    fill: var(--text-muted);
}

.tree-node {
    text-decoration: none;
}

.tree-node:focus-visible .tree-node__box,
.tree-chevron:focus-visible .tree-chevron__box {
    stroke: var(--focus-ring);
    stroke-width: 3;
}

.tree-chevron__box {
    fill: var(--bg-surface);
    stroke: var(--link);
    stroke-width: 2;
}

.tree-chevron__count {
    fill: var(--link);
    font-family: var(--font-ui);
    font-size: var(--type-micro);
    font-weight: 600;
}

.tree-scene[data-tier="names"] .tree-node__years,
.tree-scene[data-tier="names"] .tree-node__marks {
    display: none;
}

.tree-scene[data-tier="blocks"] .tree-node__name,
.tree-scene[data-tier="blocks"] .tree-node__years,
.tree-scene[data-tier="blocks"] .tree-node__marks,
.tree-scene[data-tier="blocks"] .tree-chevron__count {
    display: none;
}

.tree-focus {
    margin: 0;
    min-height: 1.5em;
    font-size: var(--type-ui);
}

/* Fan chart */

.fan-layout {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-5);
    align-items: flex-start;
}

.fan-figure {
    flex: 1 1 320px;
    overflow: auto;
    max-height: 85vh;
}

.fan-svg {
    width: 100%;
    height: auto;
    max-width: 100%;
}

.fan-legend {
    flex: 0 1 260px;
}

.fan-segment {
    stroke: var(--bg-page);
    stroke-width: 1;
}

.fan-link:focus-visible .fan-segment {
    stroke: var(--focus-ring);
    stroke-width: 3;
}

.fan-segment--root {
    fill: var(--bg-surface);
    stroke: var(--border-strong);
    stroke-width: 2;
}

.fan-segment--near {
    fill: var(--bg-surface);
    stroke: var(--border-strong);
}

.fan-label {
    font-family: var(--font-ui);
    font-weight: 500;
    fill: var(--text-primary);
}

.fan-segment--lineage-1 {
    fill: var(--lin-1);
}

.fan-segment--lineage-2 {
    fill: var(--lin-2);
}

.fan-segment--lineage-3 {
    fill: var(--lin-3);
}

.fan-segment--lineage-4 {
    fill: var(--lin-4);
}

.fan-segment--lineage-5 {
    fill: var(--lin-5);
}

.fan-segment--lineage-6 {
    fill: var(--lin-6);
}

.fan-segment--lineage-7 {
    fill: var(--lin-7);
}

.fan-segment--lineage-8 {
    fill: var(--lin-8);
}

.fan-segment--lineage-1 ~ .fan-label,
.fan-segment--lineage-2 ~ .fan-label,
.fan-segment--lineage-3 ~ .fan-label,
.fan-segment--lineage-4 ~ .fan-label,
.fan-segment--ord-1 ~ .fan-label,
.fan-segment--ord-2 ~ .fan-label,
.fan-segment--ord-3 ~ .fan-label {
    fill: var(--lin-1-label);
}

.fan-segment--lineage-5 ~ .fan-label,
.fan-segment--lineage-6 ~ .fan-label,
.fan-segment--lineage-7 ~ .fan-label,
.fan-segment--lineage-8 ~ .fan-label,
.fan-segment--ord-4 ~ .fan-label,
.fan-segment--ord-5 ~ .fan-label {
    fill: var(--lin-5-label);
}

.fan-segment--ord-1 {
    fill: var(--ord-1);
}

.fan-segment--ord-2 {
    fill: var(--ord-2);
}

.fan-segment--ord-3 {
    fill: var(--ord-3);
}

.fan-segment--ord-4 {
    fill: var(--ord-4);
}

.fan-segment--ord-5 {
    fill: var(--ord-5);
}

.legend-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--type-ui);
}

.legend-list--ramp {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
}

.legend-swatch {
    display: inline-block;
    width: 20px;
    height: 20px;
    vertical-align: -4px;
    margin-right: var(--space-2);
    border: var(--border-hairline-width) solid var(--border-strong);
    border-radius: var(--radius-input);
}

.legend-swatch--lineage-1 {
    background: var(--lin-1);
}

.legend-swatch--lineage-2 {
    background: var(--lin-2);
}

.legend-swatch--lineage-3 {
    background: var(--lin-3);
}

.legend-swatch--lineage-4 {
    background: var(--lin-4);
}

.legend-swatch--lineage-5 {
    background: var(--lin-5);
}

.legend-swatch--lineage-6 {
    background: var(--lin-6);
}

.legend-swatch--lineage-7 {
    background: var(--lin-7);
}

.legend-swatch--lineage-8 {
    background: var(--lin-8);
}

.legend-swatch--ord-1 {
    background: var(--ord-1);
}

.legend-swatch--ord-2 {
    background: var(--ord-2);
}

.legend-swatch--ord-3 {
    background: var(--ord-3);
}

.legend-swatch--ord-4 {
    background: var(--ord-4);
}

.legend-swatch--ord-5 {
    background: var(--ord-5);
}

.legend-swatch--bar {
    background: var(--ord-2);
}

.legend-swatch--hatched {
    background: repeating-linear-gradient(
        45deg,
        var(--ord-2),
        var(--ord-2) 3px,
        var(--bg-page) 3px,
        var(--bg-page) 6px
    );
}

.legend-swatch--living {
    background: var(--ord-4);
    border-style: dashed;
    border-width: var(--border-strong-width);
}

/* Pedigree ladder */

.ladder {
    display: flex;
    gap: var(--space-4);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: var(--space-3);
}

.ladder-column {
    flex: 0 0 100%;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.ladder-nav__list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.ladder-nav__list a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    border: var(--border-hairline-width) solid var(--border-strong);
    border-radius: var(--radius-input);
    text-decoration: none;
}

.ladder-nav__list a[aria-current="true"] {
    border-width: var(--border-strong-width);
    font-weight: 600;
}

.ladder-cards {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    margin: 0;
    padding: 0;
    list-style: none;
}

.ladder-card {
    padding: var(--space-3);
    background: var(--bg-surface);
    border: var(--border-strong-width) solid var(--border-strong);
    border-radius: var(--radius-card);
}

.ladder-card > p {
    margin: 0 0 var(--space-1) 0;
}

.ladder-card__name {
    font-size: var(--type-h3);
    font-weight: 600;
}

@media (min-width: 56.25rem) {
    .ladder-column {
        flex: 0 0 320px;
    }
}

/* Descendant outline */

.outline-list {
    margin: 0;
    padding-left: var(--space-5);
    list-style: none;
}

.outline-list--root {
    padding-left: 0;
}

.outline-node {
    border-left: var(--border-hairline-width) solid var(--border-hairline);
    padding-left: var(--space-3);
}

.outline-list--root > .outline-node {
    border-left: 0;
    padding-left: 0;
}

.outline-node__person {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    min-height: var(--row-height);
    font-size: var(--type-ui);
}

summary.outline-node__person {
    cursor: pointer;
}

/* Lifespans */

.lifespan-axis__rule {
    stroke: var(--border-hairline);
    stroke-width: 1;
}

.lifespan-axis__label,
.lifespan-name {
    font-family: var(--font-ui);
    fill: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.lifespan-bar {
    fill: var(--ord-2);
    stroke: var(--border-strong);
    stroke-width: 1;
}

.lifespan-bar--open-start,
.lifespan-bar--open-end {
    fill: url(#lifespan-hatch);
}

.lifespan-bar--living {
    stroke-dasharray: 4 3;
    stroke-width: 2;
}

.lifespan-hatch__line {
    stroke: var(--ord-2);
    stroke-width: 3;
}

.lifespan-link:focus-visible .lifespan-bar {
    stroke: var(--focus-ring);
    stroke-width: 3;
}

/* Statistics */

.statistics-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.statistics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-3);
    margin: 0;
    padding: 0;
    list-style: none;
}

.statistics-tile {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.statistics-tile__value {
    margin: 0;
    font-size: var(--type-h1);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.statistics-tile__label {
    margin: 0;
    font-size: var(--type-ui);
}

.statistics-list {
    margin: 0;
    padding-left: var(--space-5);
    font-size: var(--type-ui);
}

.bar-label,
.bar-value {
    font-family: var(--font-ui);
    fill: var(--text-primary);
}

.bar-value {
    font-variant-numeric: tabular-nums;
}

.bar {
    stroke: var(--border-strong);
    stroke-width: 1;
}

.bar--ord-1 {
    fill: var(--ord-1);
}

.bar--ord-2 {
    fill: var(--ord-2);
}

.bar--ord-3 {
    fill: var(--ord-3);
}

.bar--ord-4 {
    fill: var(--ord-4);
}

.bar--ord-5 {
    fill: var(--ord-5);
}

/* Relationship path */

.relationship-chain {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.relationship-step {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    border-left: var(--border-strong-width) solid var(--border-strong);
}

.relationship-step--up {
    border-left-color: var(--ord-2);
}

.relationship-step--down {
    border-left-color: var(--ord-4);
}

.relationship-step__person {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    font-size: var(--type-ui);
}

.relationship-step__role {
    margin: 0;
}

.relationship-connector {
    display: block;
}

.relationship-connector__line,
.relationship-connector__head {
    fill: none;
    stroke: var(--border-strong);
    stroke-width: 2;
}

.relationship-summary {
    margin: 0;
    font-size: var(--type-h3);
}

/* Maps */

.map-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-4);
}

.map-canvas {
    min-height: 360px;
    background: var(--bg-surface);
    border: var(--border-strong-width) solid var(--border-strong);
    border-radius: var(--radius-card);
}

.map-places,
.map-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-height: 60vh;
    overflow-y: auto;
}

.map-place-list,
.map-panel__events,
.map-panel__people,
.map-unlocatable ul,
.life-legend {
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--type-ui);
}

.map-place-list li,
.map-panel__events li,
.map-panel__people li {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: baseline;
    min-height: var(--row-height);
}

.map-attribution {
    margin: 0;
    font-size: var(--type-small);
    color: var(--text-muted);
}

.life-legend__item {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
    min-height: var(--touch-target);
}

.life-legend__pin {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--ord-2);
    color: var(--ord-2-label);
    font-size: var(--type-micro);
    font-weight: 600;
}

.map-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    min-height: 26px;
    padding: 0 var(--space-1);
    border: var(--border-strong-width) solid var(--border-strong);
    border-radius: 50%;
    background: var(--ord-3);
    color: var(--ord-3-label);
    font-family: var(--font-ui);
    font-size: var(--type-micro);
    font-weight: 600;
    cursor: pointer;
}

.map-marker--cluster {
    border-radius: var(--radius-card);
}

.map-marker--first {
    border-radius: var(--radius-input);
}

@media (min-width: 80rem) {
    .map-layout {
        grid-template-columns: 280px minmax(0, 1fr) 320px;
    }

    .map-layout--life {
        grid-template-columns: minmax(0, 1fr) 360px;
    }

    .map-canvas {
        min-height: 560px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tree-scene,
    .fan-scene {
        transition: none !important;
    }
}

@media print {
    .chart-toolbar,
    .chart-links,
    .skip-canvas,
    .tree-focus,
    .map-canvas,
    .tree-minimap,
    .tree-trail,
    .ladder-nav {
        display: none;
    }

    .tree-canvas {
        overflow: visible;
        max-height: none;
        border: 0;
    }

    .chart-equivalent > summary {
        display: none;
    }

    .chart-equivalent[open] .chart-table,
    .chart-equivalent .chart-table {
        display: table;
    }

    .tree-node,
    .ladder-card,
    .outline-node,
    .relationship-step,
    .data-table tr {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

.map-filters input[type="range"] {
    min-width: 160px;
    min-height: var(--touch-target);
}

.map-filters output {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.tree-stage {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--space-4);
}

.tree-stage > .tree-canvas {
    flex: 1 1 320px;
    min-width: 0;
}

.tree-minimap {
    flex: 0 0 240px;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-2);
    background: var(--bg-surface);
    border: var(--border-strong-width) solid var(--border-strong);
    border-radius: var(--radius-card);
}

.tree-minimap__title {
    margin: 0;
}

.tree-minimap__figure {
    max-height: 40vh;
    cursor: pointer;
}

.tree-minimap__nodes {
    fill: var(--border-strong);
    stroke: none;
}

.tree-minimap__viewport {
    fill: none;
    stroke: var(--link);
    stroke-width: 2;
}

.tree-trail__list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--type-ui);
}

.tree-trail__list li + li::before {
    content: "\203A";
    margin-right: var(--space-2);
    color: var(--text-muted);
}

.tree-trail__list a,
.tree-trail__list span {
    display: inline-flex;
    align-items: center;
    min-height: var(--touch-target);
}

.tree-trail__list [aria-current="true"] {
    font-weight: 600;
}

.chart-toolbar[hidden],
.tree-minimap[hidden] {
    display: none;
}

.map-marker--cluster {
    pointer-events: none;
}
