@layer zs-project-base {
  :root {
    --paper: #f4eddf;
    --paper-light: #fbf7ee;
    --ink: #302d28;
    --muted: #756f65;
    --line: #bcae9a;
    --line-soft: #d7ccbc;
    --accent: #7b2432;
    --accent-dark: #5d1723;
    --accent-soft: #ead8da;
    --shadow: 0 18px 40px rgba(42, 34, 24, 0.14);
  }

  * {
    box-sizing: border-box;
  }

  body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: radial-gradient(circle at 45% 18%, rgba(255, 255, 255, 0.62), transparent 42%),
        linear-gradient(90deg, rgba(123, 36, 50, 0.035), transparent 22%, transparent 78%, rgba(123, 36, 50, 0.035)),
        var(--paper);
    font-family: Georgia, "Times New Roman", serif;
  }

  button {
    font: inherit;
  }

  .tree-area, .tree-title, .panel-body, .story-modal {
    scrollbar-width: thin;
    scrollbar-color: rgba(123, 36, 50, 0.45) rgba(188, 174, 154, 0.18);
  }

  .tree-area::-webkit-scrollbar, .tree-title::-webkit-scrollbar, .panel-body::-webkit-scrollbar, .story-modal::-webkit-scrollbar {
    width: 5px;
    height: 5px;
  }

  .tree-area::-webkit-scrollbar-track, .tree-title::-webkit-scrollbar-track, .panel-body::-webkit-scrollbar-track, .story-modal::-webkit-scrollbar-track {
    background: rgba(188, 174, 154, 0.16);
    border-radius: 999px;
  }

  .tree-area::-webkit-scrollbar-thumb, .tree-title::-webkit-scrollbar-thumb, .panel-body::-webkit-scrollbar-thumb, .story-modal::-webkit-scrollbar-thumb {
    background: rgba(123, 36, 50, 0.48);
    border-radius: 999px;
  }

  .tree-area::-webkit-scrollbar-thumb:hover, .tree-title::-webkit-scrollbar-thumb:hover, .panel-body::-webkit-scrollbar-thumb:hover, .story-modal::-webkit-scrollbar-thumb:hover {
    background: rgba(123, 36, 50, 0.68);
  }

  .tree-area::-webkit-scrollbar-corner, .tree-title::-webkit-scrollbar-corner, .panel-body::-webkit-scrollbar-corner, .story-modal::-webkit-scrollbar-corner {
    background: transparent;
  }

  .app {
    min-height: 100vh;
    height: 100vh;
    padding: 18px 0 0;
    overflow: hidden;
  }

  .header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 18px;
    margin: 0 28px 14px;
  }

  .header::before, .header::after {
    content: "";
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent));
  }

  .header::after {
    background: linear-gradient(90deg, var(--accent), transparent);
  }

  .brand {
    display: grid;
    justify-items: center;
    min-width: 560px;
  }

  .brand-title {
    margin: 0;
    color: #544c43;
    font-size: 25px;
    letter-spacing: 0.04em;
    line-height: 1.12;
    text-align: center;
  }

  .screen {
    --branch-panel-height: 360px;
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    grid-template-rows: minmax(260px, 1fr) 8px minmax(210px, var(--branch-panel-height));
    column-gap: 20px;
    row-gap: 0;
    height: calc(100vh - 82px);
    padding: 0 28px 0;
    margin: 0;
    min-width: 0;
  }

  .tree-area {
    grid-column: 2;
    grid-row: 1 / span 3;
    position: relative;
    height: 100%;
    min-height: 0;
    overflow: auto;
    border: 1px solid rgba(188, 174, 154, 0.45);
    border-radius: 7px;
    cursor: grab;
    overscroll-behavior: contain;
    scrollbar-gutter: stable both-edges;
    background: rgba(251, 247, 238, 0.16);
  }

  .tree-area.is-panning {
    cursor: grabbing;
    user-select: none;
  }

  .tree-title {
    grid-column: 1;
    grid-row: 3;
    position: relative;
    align-self: stretch;
    width: 100%;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    padding: 16px 18px 17px;
    border: 1px solid rgba(188, 174, 154, 0.72);
    border-top-color: rgba(123, 36, 50, 0.45);
    border-radius: 0 0 7px 7px;
    background: rgba(251, 247, 238, 0.94);
    box-shadow: 0 16px 34px rgba(42, 34, 24, 0.12);
  }

  .left-panel-resizer {
    grid-column: 1;
    grid-row: 2;
    position: relative;
    cursor: row-resize;
    touch-action: none;
    background: transparent;
    border-left: 1px solid rgba(188, 174, 154, 0.42);
    border-right: 1px solid rgba(188, 174, 154, 0.42);
  }

  .left-panel-resizer::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 3px;
    transform: translateY(-50%);
    background: rgba(123, 36, 50, 0.56);
    box-shadow: 0 1px 0 rgba(251, 247, 238, 0.55);
  }

  .left-panel-resizer:hover::before, .left-panel-resizer:active::before {
    height: 4px;
    background: rgba(123, 36, 50, 0.64);
  }

  body.is-resizing-layout {
    cursor: row-resize;
    user-select: none;
  }

  .tree-title p {
    margin: 0 0 4px;
    color: var(--accent);
    font-size: 12px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
  }

  .tree-title h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 500;
    line-height: 1.14;
  }

  .tree-search {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line-soft);
  }

  .tree-search label {
    display: block;
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }

  .person-search-input {
    width: 100%;
    border: 1px solid var(--line-soft);
    border-radius: 6px;
    background: rgba(251, 247, 238, 0.92);
    color: var(--ink);
    padding: 9px 10px;
    font-family: inherit;
    font-size: 13px;
    outline: none;
  }

  .person-search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
  }

  .search-results {
    display: grid;
    gap: 6px;
    margin-top: 8px;
    max-height: 210px;
    overflow: auto;
  }

  .search-empty {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
    padding: 7px 2px 0;
  }

  .search-result {
    display: grid;
    gap: 2px;
    width: 100%;
    border: 1px solid var(--line-soft);
    border-radius: 6px;
    background: rgba(251, 247, 238, 0.9);
    color: var(--ink);
    padding: 8px 10px;
    cursor: pointer;
    text-align: left;
    font-size: 13px;
  }

  .search-result b {
    color: var(--accent);
    font-weight: 600;
  }

  .search-result span {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.25;
  }

  .branch-switch {
    display: grid;
    gap: 8px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line-soft);
  }

  .branch-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px;
    align-items: stretch;
  }

  .branch-button, .branch-album-button {
    border: 1px solid var(--line-soft);
    border-radius: 6px;
    background: rgba(251, 247, 238, 0.88);
    color: var(--muted);
    cursor: pointer;
    font-size: 13px;
    text-align: left;
  }

  .branch-button {
    display: grid;
    gap: 2px;
    padding: 8px 10px;
  }

  .branch-button span {
    color: inherit;
    font-size: 13px;
    line-height: 1.15;
  }

  .branch-button small {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.15;
    letter-spacing: 0.02em;
  }

  .branch-album-button {
    padding: 0 10px;
    color: var(--accent);
    white-space: nowrap;
    text-align: center;
  }

  .branch-album-button.is-disabled {
    color: var(--line);
    cursor: default;
    opacity: 0.62;
  }

  .branch-card.is-active .branch-button {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
  }

  .branch-card.is-active .branch-button small {
    color: var(--accent-dark);
  }

  .tree-canvas {
    position: relative;
    width: 15000px;
    height: 4200px;
    min-height: 4200px;
  }

  .tree-lines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
  }

  .tree-lines path {
    fill: none;
    stroke: var(--line);
    stroke-width: 1.35;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .tree-lines circle {
    fill: var(--paper);
    stroke: var(--line);
    stroke-width: 1.15;
  }

  .branch-context-layer {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
  }

  .branch-context {
    position: absolute;
    display: grid;
    grid-template-columns: 420px minmax(0, 1fr) 260px;
    gap: 18px;
    width: 1500px;
    min-height: 315px;
    border: 1px solid rgba(188, 174, 154, 0.78);
    border-radius: 8px;
    background: rgba(251, 247, 238, 0.96);
    box-shadow: 0 18px 36px rgba(42, 34, 24, 0.09);
    padding: 22px 24px;
    pointer-events: auto;
  }

  .branch-context {
    cursor: pointer;
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
  }

  .branch-context:hover, .branch-context:focus-visible {
    border-color: rgba(123, 36, 50, 0.72);
    box-shadow: 0 20px 44px rgba(123, 36, 50, 0.14);
    transform: translateY(-1px);
    outline: none;
  }

  .story-modal {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: block;
    padding: 20px;
    overflow: auto;
    background: rgba(34, 29, 23, 0.78);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 240ms ease, visibility 0s linear 240ms;
  }

  .story-modal.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 240ms ease;
  }

  .story-shell {
    width: min(1540px, calc(100vw - 40px));
    min-height: calc(100vh - 40px);
    margin: 0 auto;
    border: 1px solid rgba(188, 174, 154, 0.86);
    border-radius: 9px;
    background: radial-gradient(circle at 48% 10%, rgba(255, 255, 255, 0.72), transparent 46%),
        var(--paper-light);
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.34);
    overflow: hidden;
    opacity: 0;
    transform: translateY(18px) scale(0.985);
    transition: opacity 260ms ease, transform 260ms ease;
  }

  .story-modal.is-open .story-shell {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  .story-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    padding: 22px 30px 18px;
    border-bottom: 1px solid var(--line-soft);
  }

  .story-kicker {
    margin: 0 0 4px;
    color: var(--accent);
    font-size: 12px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
  }

  .story-title {
    margin: 0;
    color: var(--ink);
    font-size: 31px;
    font-weight: 500;
    line-height: 1.12;
  }

  .story-subtitle {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.35;
  }

  .story-close {
    border: 1px solid var(--line);
    border-radius: 5px;
    background: rgba(251, 247, 238, 0.82);
    color: var(--accent);
    padding: 9px 13px;
    cursor: pointer;
    white-space: nowrap;
  }

  .story-body {
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(360px, 0.92fr);
    gap: 22px;
    padding: 24px 30px 30px;
  }

  .story-figure {
    margin: 0;
    display: grid;
    gap: 8px;
    border: 1px solid rgba(188, 174, 154, 0.58);
    border-radius: 7px;
    background: rgba(244, 237, 223, 0.42);
    padding: 10px;
  }

  .story-image-button {
    position: relative;
    display: block;
    width: 100%;
    border: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    cursor: zoom-in;
  }

  .story-image-button:focus-visible {
    outline: 2px solid rgba(123, 36, 50, 0.72);
    outline-offset: 3px;
    border-radius: 5px;
  }

  .story-figure img {
    display: block;
    width: 100%;
    height: 235px;
    object-fit: contain;
    border-radius: 4px;
    background: #e1d2b6;
  }

  .story-zoom-hint {
    position: absolute;
    right: 8px;
    bottom: 8px;
    border: 1px solid rgba(251, 247, 238, 0.78);
    border-radius: 999px;
    background: rgba(42, 34, 24, 0.66);
    color: var(--paper-light);
    padding: 4px 8px;
    font-size: 11px;
    line-height: 1;
    letter-spacing: 0.04em;
    opacity: 0;
    transform: translateY(3px);
    transition: opacity 0.16s ease, transform 0.16s ease;
    pointer-events: none;
  }

  .story-image-button:hover .story-zoom-hint, .story-image-button:focus-visible .story-zoom-hint {
    opacity: 1;
    transform: translateY(0);
  }

  .story-figure figcaption {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.3;
    text-align: center;
  }

  .story-main-text {
    display: grid;
    gap: 15px;
    align-content: start;
  }

  .story-section {
    border: 1px solid rgba(188, 174, 154, 0.55);
    border-radius: 7px;
    background: rgba(251, 247, 238, 0.78);
    padding: 15px 16px;
  }

  .story-section h3, .story-boundary-large h3, .story-timeline h3 {
    margin: 0 0 7px;
    color: var(--accent);
    font-size: 18px;
    font-weight: 500;
    line-height: 1.2;
  }

  .story-section p, .story-boundary-large p {
    margin: 0;
    color: var(--ink);
    font-size: 15px;
    line-height: 1.45;
  }

  .story-main-text-wide {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .story-section-wide {
    grid-column: 1 / -1;
  }

  .story-section p + p {
    margin-top: 9px;
  }

  .story-section-with-media {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(255px, 0.38fr);
    gap: 15px;
    align-items: start;
  }

  .story-section-content {
    min-width: 0;
  }

  .story-section-media {
    display: grid;
    gap: 10px;
    align-content: start;
  }

  .story-section-media .story-figure {
    padding: 8px;
    gap: 7px;
    background: rgba(244, 237, 223, 0.48);
  }

  .story-section-media .story-figure img {
    height: 170px;
  }

  .story-section-media .story-figure figcaption {
    font-size: 12px;
    line-height: 1.25;
  }

  .story-boundary-large {
    border: 1px solid rgba(123, 36, 50, 0.72);
    border-radius: 7px;
    background: rgba(255, 252, 246, 0.84);
    padding: 16px 17px;
  }

  .story-boundary-large.story-section-with-media {
    grid-template-columns: 1fr;
  }

  .story-boundary-large .story-section-media {
    grid-template-columns: 1fr;
    margin-top: 12px;
  }

  .story-figure a, .story-figure button {
    display: block;
    color: inherit;
    font: inherit;
  }

  .story-timeline {
    grid-column: 1 / -1;
    border: 1px solid rgba(188, 174, 154, 0.62);
    border-radius: 7px;
    background: rgba(244, 237, 223, 0.38);
    padding: 15px 18px 17px;
  }

  .story-timeline-items {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
    margin-top: 11px;
  }

  .story-timeline-item {
    border-top: 2px solid var(--line);
    padding-top: 8px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.28;
  }

  .story-timeline-item b {
    display: block;
    margin-bottom: 3px;
    color: var(--accent);
    font-size: 15px;
    font-weight: 700;
  }

  .story-scheme {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr;
    gap: 22px;
    border: 1px solid rgba(188, 174, 154, 0.68);
    border-radius: 8px;
    background: rgba(251, 247, 238, 0.82);
    padding: 22px 24px 24px;
    box-shadow: 0 12px 26px rgba(42, 34, 24, 0.08);
  }

  .story-scheme-panel {
    min-width: 0;
  }

  .story-scheme-title {
    margin: 0 0 15px;
    color: var(--accent);
    font-size: 21px;
    font-weight: 500;
    line-height: 1.18;
  }

  .story-scheme-columns {
    display: grid;
    grid-template-columns: repeat(var(--scheme-cols, 2), minmax(0, 1fr));
    gap: 28px;
    align-items: start;
  }

  .story-scheme-column-title {
    margin: 0 0 12px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    text-align: center;
  }

  .story-scheme-line {
    position: relative;
    display: grid;
    gap: 13px;
    min-height: 0;
  }

  .story-scheme-line::before {
    content: "";
    position: absolute;
    top: 30px;
    bottom: 30px;
    left: 50%;
    width: 1px;
    background: var(--line);
    transform: translateX(-50%);
  }

  .story-scheme-node {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    width: min(250px, 100%);
    min-height: 52px;
    margin: 0 auto;
    border: 1px solid var(--line-soft);
    border-radius: 6px;
    background: rgba(251, 247, 238, 0.96);
    padding: 8px 11px;
    box-shadow: 0 8px 18px rgba(42, 34, 24, 0.07);
  }

  .story-scheme-node::before {
    content: "";
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(123, 36, 50, 0.14);
    box-shadow: inset 0 0 0 7px rgba(123, 36, 50, 0.72);
  }

  .story-scheme-node b {
    display: block;
    color: var(--ink);
    font-size: 15px;
    line-height: 1.12;
  }

  .story-scheme-node span {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.18;
  }

  .story-scheme-node.is-accent {
    border-color: rgba(123, 36, 50, 0.62);
  }

  .story-marriage-note {
    width: min(520px, 100%);
    margin: 16px auto 0;
    border-top: 1px solid var(--line-soft);
    padding-top: 12px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.35;
    text-align: center;
    font-style: italic;
  }

  .story-marriage-symbol {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    margin: 0 9px -8px;
    border: 1px solid var(--accent);
    border-radius: 50%;
    color: var(--accent);
    font-style: normal;
    font-size: 18px;
    line-height: 1;
  }

  .story-passport {
    grid-column: 1 / -1;
    border: 0;
    border-radius: 0;
    background: transparent;
    overflow-x: auto;
    overflow-y: visible;
    align-self: stretch;
    min-width: 0;
  }

  .story-passport h3 {
    margin: 0 0 12px;
    padding: 0;
    color: var(--ink);
    background: transparent;
    font-size: 22px;
    font-weight: 600;
    line-height: 1.2;
  }

  .story-passport-table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
    table-layout: auto;
    background: rgba(251, 247, 238, 0.9);
    border: 1px solid rgba(188, 174, 154, 0.76);
    font-size: 15px;
    line-height: 1.38;
  }

  .story-passport-table th {
    padding: 10px 12px;
    background: var(--accent-dark);
    color: var(--paper-light);
    border: 1px solid rgba(188, 174, 154, 0.76);
    font-weight: 700;
    text-align: left;
  }

  .story-passport-table td {
    padding: 12px;
    border: 1px solid rgba(188, 174, 154, 0.68);
    color: var(--ink);
    vertical-align: top;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: none;
  }

  .story-passport-table th:first-child, .story-passport-table td:first-child {
    width: 28%;
    min-width: 230px;
    color: var(--ink);
    font-weight: 600;
    background: rgba(244, 237, 223, 0.46);
  }

  .story-passport-table th:last-child, .story-passport-table td:last-child {
    width: 72%;
  }

  .person {
    position: absolute;
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    width: 198px;
    min-height: 88px;
    border: 1px solid var(--line-soft);
    border-radius: 6px;
    background: rgba(251, 247, 238, 0.94);
    color: var(--ink);
    padding: 12px 13px;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 10px 22px rgba(42, 34, 24, 0.075);
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease, opacity 160ms ease;
    z-index: 3;
  }

  .person:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
  }

  .person.is-selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft), 0 14px 30px rgba(123, 36, 50, 0.16);
  }

  .person.is-muted {
    opacity: 0.52;
  }

  .avatar {
    position: relative;
    display: block;
    width: 34px;
    height: 48px;
    color: rgba(117, 111, 101, 0.44);
  }

  .avatar::before, .avatar::after {
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    background: currentColor;
  }

  .avatar::before {
    top: 3px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
  }

  .avatar::after {
    bottom: 4px;
    width: 30px;
    height: 24px;
    border-radius: 13px 13px 8px 8px;
  }

  .person.is-selected .avatar {
    color: rgba(123, 36, 50, 0.88);
  }

  .person-name {
    display: block;
    margin-bottom: 4px;
    color: var(--ink);
    font-size: 16px;
    line-height: 1.12;
    font-weight: 700;
    overflow-wrap: anywhere;
  }

  .person-years {
    display: block;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }

  .side-panel {
    grid-column: 1;
    grid-row: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 1px solid var(--line);
    border-bottom-color: rgba(123, 36, 50, 0.45);
    border-radius: 7px 7px 0 0;
    background: rgba(251, 247, 238, 0.96);
    box-shadow: 0 18px 40px rgba(42, 34, 24, 0.12);
    overflow: hidden;
  }

  .panel-head {
    padding: 18px 18px 14px;
    text-align: center;
  }

  .panel-avatar {
    position: relative;
    margin: 0 auto 8px;
    width: 48px;
    height: 62px;
    color: rgba(123, 36, 50, 0.86);
  }

  .panel-avatar::before, .panel-avatar::after {
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    background: currentColor;
  }

  .panel-avatar::before {
    top: 5px;
    width: 21px;
    height: 21px;
    border-radius: 50%;
  }

  .panel-avatar::after {
    bottom: 6px;
    width: 39px;
    height: 31px;
    border-radius: 24px 24px 12px 12px;
  }

  .panel-head h2 {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 24px;
    font-weight: 500;
    line-height: 1.12;
  }

  .panel-years {
    margin: 0;
    color: var(--muted);
    font-size: 16px;
  }

  .panel-rule {
    display: flex;
    align-items: center;
    gap: 11px;
    margin: 13px auto 0;
    color: var(--line);
    width: 78%;
  }

  .panel-rule::before, .panel-rule::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line-soft);
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-top: 1px solid var(--line-soft);
    border-bottom: 1px solid var(--line-soft);
  }

  .tab {
    border: 0;
    border-right: 1px solid var(--line-soft);
    background: transparent;
    color: var(--ink);
    padding: 12px 6px 10px;
    cursor: pointer;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 11px;
  }

  .tab:last-child {
    border-right: 0;
  }

  .tab.is-active {
    color: var(--accent);
    box-shadow: inset 0 -2px 0 var(--accent);
  }

  .panel-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px 18px 22px;
  }

  .doc-view {
    display: grid;
    gap: 14px;
  }

  .doc-title {
    margin: 0;
    color: var(--accent);
    font-size: 21px;
    font-weight: 500;
  }

  .person-note {
    border-left: 2px solid var(--accent);
    padding: 10px 0 10px 13px;
  }

  .person-note-title {
    margin: 0 0 5px;
    color: var(--accent);
    font-size: 14px;
    line-height: 1.25;
    font-weight: 500;
    letter-spacing: 0.025em;
  }

  .person-note-text {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
  }

  .scan {
    position: relative;
    height: 220px;
    border: 1px solid var(--line);
    border-radius: 5px;
    overflow: hidden;
    background: linear-gradient(90deg, rgba(123, 36, 50, 0.07) 1px, transparent 1px) 0 0 / 42px 100%,
        linear-gradient(rgba(48, 45, 40, 0.13) 1px, transparent 1px) 0 16px / 100% 27px,
        linear-gradient(110deg, rgba(255,255,255,0.45), transparent 42%),
        #d8c39f;
  }

  .scan.has-image {
    display: grid;
    place-items: center;
    background: #ded0b4;
  }

  .scan.has-image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .scan-button {
    width: 100%;
    padding: 0;
    cursor: zoom-in;
  }

  .document-fallback {
    display: grid;
    align-content: center;
    gap: 10px;
    min-height: 190px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: rgba(244, 237, 223, 0.58);
    color: var(--ink);
    padding: 24px 22px;
  }

  .document-fallback b {
    color: var(--accent);
    font-size: 19px;
    font-weight: 500;
    line-height: 1.18;
  }

  .document-fallback span {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.35;
  }

  .family-note {
    color: var(--muted);
    font-size: 15px;
    line-height: 1.48;
  }

  .family-note p {
    margin: 0;
  }

  .scan.has-image::before, .scan.has-image::after {
    display: none;
  }

  .scan::before, .scan::after {
    content: "";
    position: absolute;
    left: 22px;
    right: 22px;
    height: 1px;
    background: rgba(48, 45, 40, 0.18);
  }

  .scan::before {
    top: 44px;
  }

  .scan::after {
    top: 76px;
  }

  .doc-switcher {
    display: grid;
    gap: 8px;
  }

  .doc-option {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    min-height: 58px;
    width: 100%;
    border: 1px solid var(--line-soft);
    border-radius: 5px;
    background: rgba(244, 237, 223, 0.56);
    color: var(--ink);
    padding: 9px 10px;
    text-align: left;
    cursor: pointer;
  }

  .doc-option.is-active {
    border-color: var(--accent);
    box-shadow: inset 3px 0 0 var(--accent);
    background: rgba(251, 247, 238, 0.92);
  }

  .doc-option-year {
    color: var(--accent);
    font-size: 15px;
    line-height: 1.1;
  }

  .doc-option-title {
    display: block;
    color: var(--ink);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.15;
  }

  .doc-option-type {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.2;
  }

  .info-grid {
    display: grid;
    gap: 12px;
    margin-top: 18px;
    border-top: 1px solid var(--line-soft);
    padding-top: 16px;
  }

  .transcript {
    margin-top: 18px;
    border-top: 1px solid var(--line-soft);
    padding-top: 16px;
  }

  .transcript-title {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 16px;
    font-weight: 500;
  }

  .transcript-text {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.5;
    white-space: pre-line;
  }

  .info-row {
    display: grid;
    grid-template-columns: 94px 1fr;
    gap: 12px;
    align-items: start;
    line-height: 1.35;
  }

  .info-row b {
    color: var(--accent);
    font-weight: 500;
  }

  .info-row span {
    color: var(--muted);
  }

  .source-list {
    display: grid;
    gap: 13px;
  }

  .source-meta {
    display: grid;
    gap: 8px;
    margin-top: 8px;
  }

  .source-item {
    border-top: 1px solid var(--line-soft);
    padding-top: 13px;
    line-height: 1.45;
  }

  .source-item:first-child {
    border-top: 0;
    padding-top: 0;
  }

  .source-item b {
    display: block;
    margin-bottom: 4px;
    color: var(--ink);
    font-weight: 700;
  }

  .source-item span {
    color: var(--muted);
  }

  .source-item.family-source {
    border-top: 0;
    padding-top: 0;
    color: var(--muted);
  }

  .source-item.family-source b {
    color: var(--accent);
    font-weight: 500;
  }

  .lightbox {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 14px;
    padding: 22px;
    background: rgba(34, 29, 23, 0.82);
  }

  .lightbox.is-story-scoped {
    inset: auto;
    left: var(--lightbox-left, 20px);
    top: var(--lightbox-top, 20px);
    width: var(--lightbox-width, calc(100vw - 40px));
    height: var(--lightbox-height, calc(100vh - 40px));
    border: 1px solid rgba(188, 174, 154, 0.72);
    border-radius: 9px;
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.42);
    background: rgba(34, 29, 23, 0.88);
  }

  .lightbox.is-open {
    display: grid;
  }

  .lightbox-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    color: var(--paper-light);
  }

  .lightbox-title {
    margin: 0;
    font-size: 18px;
    line-height: 1.3;
  }

  .lightbox-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }

  .lightbox-zoom-control, .lightbox-close {
    border: 1px solid rgba(251, 247, 238, 0.65);
    background: rgba(251, 247, 238, 0.1);
    color: var(--paper-light);
    padding: 9px 13px;
    cursor: pointer;
  }

  .lightbox-zoom-control {
    min-width: 38px;
    padding: 9px 11px;
  }

  .lightbox-zoom-level {
    min-width: 54px;
    color: rgba(251, 247, 238, 0.88);
    font-size: 13px;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }

  .lightbox-image-wrap {
    min-height: 0;
    display: grid;
    place-items: center;
    overflow: auto;
    border: 1px solid rgba(251, 247, 238, 0.28);
    background: rgba(251, 247, 238, 0.08);
    cursor: default;
  }

  .lightbox-image-wrap.is-zoomed {
    cursor: grab;
    place-items: start center;
  }

  .lightbox-image-wrap.is-dragging {
    cursor: grabbing;
    user-select: none;
  }

  .lightbox-image {
    display: block;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    transition: width 0.12s ease;
    user-select: none;
  }

  .lightbox-transcript {
    max-height: 25vh;
    overflow: auto;
    border: 1px solid rgba(251, 247, 238, 0.26);
    background: rgba(251, 247, 238, 0.94);
    color: var(--ink);
    padding: 14px 16px;
    font-size: 17px;
    line-height: 1.5;
    white-space: pre-line;
  }

  .lightbox-transcript:empty {
    display: none;
  }

  @media (max-width:1280px) {
    .story-body {
      grid-template-columns: 1fr;
    }

    .story-main-text-wide {
      grid-template-columns: 1fr;
    }

    .story-scheme {
      grid-template-columns: 1fr;
    }

    .story-timeline-items {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  @media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
    .story-modal {
      padding: 10px;
    }

    .story-shell {
      width: calc(100vw - 20px);
    }

    .story-header, .story-body {
      padding-left: 16px;
      padding-right: 16px;
    }

    .story-main-text-wide, .story-scheme-columns {
      grid-template-columns: 1fr;
    }

    .story-timeline-items {
      grid-template-columns: 1fr 1fr;
    }
  }

  @media (max-width:1180px) {
    .app {
      height: auto;
      min-height: 100vh;
      overflow: auto;
      padding: 18px 16px 22px;
    }

    .header {
      margin: 0 auto 14px;
    }

    .screen {
      display: grid;
      grid-template-columns: 1fr;
      grid-template-rows: auto auto auto;
      height: auto;
      padding: 0;
    }

    .tree-title, .side-panel {
      grid-column: auto;
      grid-row: auto;
      width: 100%;
      margin-bottom: 12px;
    }

    .tree-area {
      grid-column: auto;
      grid-row: auto;
      position: relative;
      height: 800px;
      min-height: 800px;
    }

    .tree-canvas {
      min-height: 4200px;
    }

    .side-panel {
      height: 800px;
    }
  }

  @media (max-width:960px) {
    .story-section-with-media {
      grid-template-columns: 1fr;
    }

    .story-section-media .story-figure img {
      height: 190px;
    }
  }

  body.modal-open {
    overflow: hidden;
  }

  @media (hover:none) and (pointer:coarse) {
    .person:hover {
      transform: none;
    }

    .tree-area {
      cursor: default;
    }
  }

  @media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
    html, body {
      min-width: 0;
      overflow-x: hidden;
      -webkit-text-size-adjust: 100%;
    }

    .app {
      min-height: 100dvh;
    }

    .header {
      grid-template-columns: 1fr;
      gap: 0;
    }

    .header::before, .header::after {
      display: none;
    }

    .brand {
      width: 100%;
      min-width: 0;
    }

    .brand-title {
      line-height: 1.12;
    }

    .tree-title {
      width: 100%;
      max-height: none;
    }

    .tree-title p {
      margin-bottom: 4px;
      font-size: 10px;
      letter-spacing: 0.14em;
    }

    .tree-title h2 {
      display: none;
    }

    .tree-search {
      margin-top: 8px;
      padding-top: 8px;
    }

    .tree-search label {
      display: none;
    }

    .person-search-input {
      border-radius: 6px;
    }

    .branch-switch {
      padding-top: 8px;
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .branch-button, .branch-album-button {
      font-size: 12px;
    }

    .tree-area::before {
      content: "Двигайте дерево пальцем. Нажмите карточку — сведения ниже.";
      position: sticky;
      top: 6px;
      left: 6px;
      display: inline-block;
      max-width: calc(100vw - 32px);
      z-index: 20;
      pointer-events: none;
      padding: 5px 8px;
      border: 1px solid rgba(188, 174, 154, 0.74);
      border-radius: 999px;
      background: rgba(251, 247, 238, 0.92);
      color: var(--muted);
      font-size: 11px;
      line-height: 1.2;
      box-shadow: 0 8px 18px rgba(42, 34, 24, 0.10);
    }

    .side-panel {
      max-height: none;
    }

    .panel-avatar {
      display: none;
    }

    .panel-head h2 {
      line-height: 1.12;
    }

    .panel-years {
      font-size: 15px;
    }

    .panel-rule {
      margin-top: 9px;
      width: 86%;
    }

    .tabs {
      background: rgba(251, 247, 238, 0.98);
    }

    .panel-body {
      overflow: visible;
      padding: 13px;
    }

    .doc-title {
      line-height: 1.2;
    }

    .doc-option {
      grid-template-columns: 44px minmax(0, 1fr);
    }

    .transcript-text, .info-row span, .source-item span, .family-note {
      font-size: 14px;
    }

    .info-row {
      grid-template-columns: 1fr;
      gap: 4px;
    }

    .story-modal {
      overflow: auto;
    }

    .story-shell {
      margin: 0;
      border: 0;
      border-radius: 0;
    }

    .story-header {
      flex-direction: column;
      align-items: stretch;
      gap: 10px;
    }

    .story-kicker {
      font-size: 10px;
    }

    .story-close {
      width: 100%;
    }

    .story-body {
      display: grid;
      gap: 14px;
    }

    .story-section h3, .story-timeline h3, .story-scheme-title, .story-passport h3 {
      font-size: 19px;
    }

    .story-figure img, .story-section-media .story-figure img {
      max-height: 280px;
    }

    .story-passport-table {
      min-width: 640px;
    }

    .story-passport-table th, .story-passport-table td {
      font-size: 13px;
    }

    .lightbox.is-story-scoped {
      position: fixed;
    }

    .lightbox-bar {
      flex-direction: column;
      align-items: stretch;
      gap: 8px;
    }

    .lightbox-title {
      max-height: 3.8em;
      overflow: auto;
    }

    .lightbox-actions {
      flex-wrap: wrap;
    }

    .lightbox-transcript {
      padding: 12px;
    }
  }

  @media (max-width:390px) {
    .brand-title {
      font-size: 17px;
    }

    .branch-switch {
      grid-template-columns: 1fr;
    }

    .branch-card {
      grid-template-columns: minmax(0, 1fr) 62px;
    }

    .scan {
      height: 230px;
    }
  }

  .demo-note {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.35;
    padding: 7px 3px 0;
  }

  .tree-view-controls {
    position: sticky;
    top: 12px;
    left: 12px;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 6px;
    width: max-content;
    margin: 12px;
    padding: 6px;
    border: 1px solid rgba(188,174,154,.75);
    border-radius: 8px;
    background: rgba(251,247,238,.94);
    box-shadow: 0 8px 22px rgba(42,34,24,.12);
    backdrop-filter: blur(5px);
  }

  .tree-view-button {
    border: 1px solid var(--line-soft);
    border-radius: 5px;
    background: rgba(255,252,246,.9);
    color: var(--muted);
    padding: 7px 10px;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
  }

  .tree-view-button:hover, .tree-view-button.is-active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(234,216,218,.44);
  }

  .tree-view-icon {
    width: 31px;
    padding-left: 0;
    padding-right: 0;
    text-align: center;
    font-size: 16px;
  }

  .tree-view-separator {
    width: 1px;
    height: 25px;
    background: var(--line-soft);
    margin: 0 2px;
  }

  .tree-zoom-level {
    min-width: 44px;
    text-align: center;
    color: var(--muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
  }

  .person.is-private {
    opacity: .25;
    filter: grayscale(1);
    cursor: default;
    box-shadow: none;
  }

  .person.is-private:hover {
    border-color: var(--line-soft);
    transform: none;
  }

  .person.is-private .person-name {
    color: #948b7f;
    font-size: 13px;
    font-weight: 500;
  }

  .person.is-private .avatar {
    opacity: .6;
  }

  .overview-labels {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    display: none;
  }

  .overview-label {
    position: absolute;
    transform: translate(-50%,-100%);
    color: rgba(80,72,64,.68);
    font-size: 112px;
    line-height: 1;
    white-space: nowrap;
    letter-spacing: .04em;
  }

  .overview-label.is-open {
    color: var(--accent);
    font-weight: 700;
  }

  .tree-area.is-overview .overview-labels {
    display: block;
  }

  .tree-area.is-overview .branch-context-layer {
    display: none;
  }

  .tree-area.is-overview .person {
    width: 72px;
    min-height: 38px;
    height: 38px;
    padding: 0;
    display: block;
    border-width: 3px;
    border-radius: 20px;
    box-shadow: none;
  }

  .tree-area.is-overview .person .avatar, .tree-area.is-overview .person .person-name, .tree-area.is-overview .person .person-years {
    display: none;
  }

  .tree-area.is-overview .person:not(.is-private) {
    width: 96px;
    height: 44px;
    border-color: var(--accent);
    background: rgba(123,36,50,.18);
    opacity: 1;
  }

  .tree-area.is-overview .person.is-private {
    opacity: .46;
    background: rgba(188,174,154,.48);
  }

  .tree-area.is-medium-zoom .person .avatar, .tree-area.is-medium-zoom .person-years {
    display: none;
  }

  .tree-area.is-medium-zoom .person {
    grid-template-columns: 1fr;
    width: 170px;
    min-height: 64px;
    padding: 10px 12px;
  }

  .tree-area.is-medium-zoom .person-name {
    font-size: 14px;
  }

  /*Demo-only redaction plaques: hidden material is physically absent from this build.*/

  .demo-redaction {
    display: grid;
    gap: 5px;
    place-items: center;
    min-height: 112px;
    margin: 2px 0;
    padding: 22px 26px;
    border: 1px dashed rgba(123, 36, 50, 0.48);
    border-radius: 7px;
    background: rgba(123, 36, 50, 0.045);
    text-align: center;
    color: var(--muted);
  }

  .demo-redaction strong {
    color: var(--accent);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.025em;
  }

  .demo-redaction span {
    max-width: 720px;
    font-size: 13px;
    line-height: 1.42;
  }

  .story-scheme-hidden {
    display: grid;
    gap: 6px;
    place-items: center;
    min-height: 178px;
    padding: 18px 14px;
    border: 1px dashed rgba(123, 36, 50, 0.42);
    border-radius: 6px;
    background: rgba(123, 36, 50, 0.04);
    color: var(--muted);
    text-align: center;
  }

  .story-scheme-hidden strong {
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
  }

  .story-scheme-hidden span {
    font-size: 12px;
    line-height: 1.35;
  }

  /*Phone layout: independent tree viewport, finger-sized actions and a document sheet.*/

  .mobile-panel-close, .mobile-person-quick, .mobile-panel-backdrop, .mobile-demo-help {
    display: none;
  }

  @media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
    html, body {
      height: 100%;
      width: 100%;
      overflow: hidden;
      overscroll-behavior: none;
    }

    body {
      min-height: 100dvh;
    }

    .app {
      display: flex;
      flex-direction: column;
      width: 100%;
    }

    .header {
      flex: none;
    }

    .brand-title {
      font-size: clamp(16px, 4.7vw, 20px);
      letter-spacing: 0;
    }

    .screen {
      flex: 1;
      flex-direction: column;
      min-height: 0;
      min-width: 0;
    }

    .tree-title {
      order: 1;
      flex: none;
      position: relative;
      padding: 8px 9px 7px;
      overflow: visible;
      box-shadow: 0 3px 12px rgba(42,34,24,.05);
    }

    .tree-title > p {
      margin: 0 0 5px;
      font-size: 10px;
      letter-spacing: .12em;
    }

    .tree-search {
      position: relative;
      margin: 0;
      padding: 0;
      border: 0;
    }

    .person-search-input {
      display: block;
      padding: 10px 13px;
      line-height: 1.2;
      width: 100%;
    }

    .search-results {
      z-index: 70;
      overflow-y: auto;
      margin: 0;
      padding: 5px;
      border: 1px solid var(--line);
      border-radius: 7px;
      background: var(--paper-light);
    }

    .search-results:empty {
      display: none;
    }

    .search-result {
      min-height: 48px;
      padding: 8px 10px;
    }

    .branch-switch {
      flex-wrap: nowrap;
      gap: 7px;
      overflow-x: auto;
      scrollbar-width: thin;
      scroll-snap-type: x proximity;
      overscroll-behavior-x: contain;
      -webkit-overflow-scrolling: touch;
      margin-top: 7px;
      padding: 0 0 3px;
      border: 0;
      width: 100%;
    }

    .branch-card {
      gap: 4px;
      scroll-snap-align: start;
    }

    .branch-button, .branch-album-button {
      min-height: 43px;
      height: 43px;
      border-radius: 6px;
      touch-action: manipulation;
    }

    .mobile-demo-help {
      display: block;
      margin-top: 2px;
      font-size: 11px;
      color: var(--muted);
    }

    .mobile-demo-help summary {
      width: max-content;
      cursor: pointer;
      padding: 3px 0;
    }

    .mobile-demo-help p {
      margin: 3px 0 5px;
      font-size: 12px;
      line-height: 1.4;
      letter-spacing: 0;
      text-transform: none;
      color: var(--ink);
    }

    .tree-area {
      position: relative;
      flex: 1 1 0;
      width: 100%;
      max-height: none;
      margin: 0;
      overflow: auto;
      touch-action: none;
      overscroll-behavior: contain;
      -webkit-overflow-scrolling: auto;
      scrollbar-gutter: auto;
      background: rgba(251,247,238,.38);
    }

    .tree-canvas {
      width: 15000px;
      height: 4200px;
      min-height: 4200px;
    }

    .person {
      width: 198px;
      min-height: 88px;
      touch-action: none;
    }

    .person:active:not(:disabled) {
      border-color: var(--accent);
    }

    .tree-view-controls {
      position: sticky;
      display: grid;
      align-items: center;
      background: rgba(251,247,238,.97);
    }

    .tree-view-button {
      min-width: 0;
    }

    .tree-view-icon {
      width: auto;
    }

    .tree-view-separator, #treeZoomReset {
      display: none;
    }

    .tree-view-controls::after {
      content: "Одним пальцем — двигать · двумя — масштабировать";
      grid-column: 1 / -1;
      color: var(--muted);
      text-align: center;
      font-size: 10px;
      line-height: 1.2;
    }

    .tree-area.is-overview .overview-label {
      font-size: 175px;
      font-weight: 600;
    }

    .tree-area.is-overview .overview-label.is-open {
      font-weight: 700;
    }

    .mobile-person-quick {
      flex: none;
      display: flex;
      justify-content: space-between;
      width: 100%;
      margin: 0;
      color: var(--ink);
      background: var(--paper-light);
      cursor: pointer;
      text-align: left;
    }

    .mobile-quick-caption {
      display: grid;
      color: var(--muted);
    }

    .mobile-quick-caption strong {
      text-overflow: ellipsis;
      color: var(--accent);
      font-weight: 500;
    }

    .mobile-quick-action {
      flex: none;
      color: var(--accent);
      white-space: nowrap;
    }

    .mobile-panel-backdrop {
      position: fixed;
      inset: 0;
      z-index: 48;
      display: block;
      width: 100%;
      border: 0;
      padding: 0;
      background: rgba(30,25,22,.48);
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
      transition: opacity .22s ease, visibility .22s;
    }

    body.mobile-details-open .mobile-panel-backdrop {
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
    }

    .side-panel {
      order: 4;
      z-index: 49;
      inset: auto 0 0 0;
      display: flex;
      flex-direction: column;
      width: 100%;
      min-height: 0;
      border: 1px solid var(--line);
      border-radius: 17px 17px 0 0;
      overflow: hidden;
      background: var(--paper-light);
      box-shadow: 0 -20px 55px rgba(28,24,20,.28);
      transform: translateY(105%);
      visibility: hidden;
      pointer-events: none;
      transition: transform .24s ease, visibility .24s;
    }

    .side-panel.mobile-is-open {
      transform: translateY(0);
      visibility: visible;
      pointer-events: auto;
    }

    .panel-head {
      position: relative;
      flex: none;
      text-align: left;
    }

    .panel-head::before {
      content: "";
      position: absolute;
      width: 42px;
      height: 4px;
      top: 8px;
      left: calc(50% - 21px);
      border-radius: 9px;
      background: var(--line);
    }

    .panel-head h2 {
      margin: 0 0 4px;
    }

    .panel-head .panel-years {
      font-size: 14px;
    }

    .panel-head .panel-rule {
      display: none;
    }

    .mobile-panel-close {
      position: absolute;
      display: block;
      right: 12px;
      border: 1px solid var(--line-soft);
      border-radius: 7px;
      min-height: 44px;
      padding: 0 11px;
      color: var(--accent);
      background: var(--paper-light);
      font-size: 13px;
      cursor: pointer;
    }

    .tabs {
      position: relative;
      z-index: 1;
      flex: none;
      top: auto;
    }

    .tab {
      min-height: 47px;
      padding: 11px 5px;
      font-size: 12px;
    }

    .panel-body {
      flex: 1 1 auto;
      min-height: 0;
      padding: 15px 16px calc(26px + env(safe-area-inset-bottom));
      -webkit-overflow-scrolling: touch;
    }

    .doc-title {
      font-size: 21px;
    }

    .person-note-text, .transcript-text, .info-row span, .source-item span {
      font-size: 15px;
    }

    .scan {
      height: clamp(180px, 30dvh, 270px);
    }

    .doc-option {
      min-height: 58px;
    }

    .story-modal {
      z-index: 75;
    }

    .story-shell {
      min-height: 100dvh;
    }

    .story-header {
      position: sticky;
      top: 0;
      z-index: 30;
      background: var(--paper-light);
    }

    .story-close {
      min-height: 46px;
    }

    .story-modal.is-scrolled .story-header {
      gap: 0;
      box-shadow: 0 5px 16px rgba(42,34,24,.13);
    }

    .story-modal.is-scrolled .story-header > div {
      display: none;
    }

    .story-modal.is-scrolled .story-close {
      min-height: 44px;
      height: 44px;
    }

    .story-scheme-panel, .story-passport, .story-main-text, .story-section {
      min-width: 0;
    }

    .story-passport {
      overflow-x: auto;
    }

    .lightbox {
      z-index: 90;
      padding: 9px;
      gap: 7px;
      grid-template-rows: auto minmax(0,1fr) auto;
      background: #241f1b;
    }

    .lightbox.is-story-scoped {
      border: 0;
      border-radius: 0;
      background: #241f1b;
    }

    .lightbox-image-wrap {
      min-height: 0;
      touch-action: none;
    }

    .lightbox-actions {
      display: grid;
      grid-template-columns: 44px 44px 44px minmax(58px,1fr) auto;
      gap: 5px;
    }

    .lightbox-zoom-control, .lightbox-close {
      min-height: 44px;
      padding: 8px 4px;
      font-size: 12px;
    }

    .lightbox-zoom-level {
      min-width: 0;
      font-size: 12px;
    }

    .lightbox-transcript {
      max-height: 28dvh;
      font-size: 14px;
      line-height: 1.42;
    }
  }

  @media (max-width:760px) and (max-height:570px), (max-width:1000px) and (max-height:570px) and (pointer:coarse) {
    .brand-title {
      font-size: 15px;
    }

    .screen {
      gap: 4px;
    }

    .tree-title {
      padding: 5px 7px 4px;
    }

    .tree-title > p, .mobile-demo-help {
      display: none;
    }

    .person-search-input {
      height: 38px;
      min-height: 38px;
    }

    .branch-switch {
      margin-top: 4px;
    }

    .branch-button, .branch-album-button {
      min-height: 38px;
      height: 38px;
    }

    .mobile-person-quick {
      min-height: 46px;
      padding-top: 4px;
      padding-bottom: calc(4px + env(safe-area-inset-bottom));
    }
  }

  @media (max-width:760px) and (prefers-reduced-motion:reduce), (max-width:1000px) and (max-height:600px) and (pointer:coarse) and (prefers-reduced-motion:reduce) {
    .side-panel, .mobile-panel-backdrop {
      transition: none;
    }
  }

  /*Mobile redesign: the tree owns the viewport; navigation and text remain readable.*/

  .brand-mobile-title, .mobile-nav, .mobile-overview-picker, .mobile-view-label {
    display: none;
  }

  @media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
    .brand-mobile-title {
      display: block;
      font-size: clamp(17px,4.6vw,21px);
      line-height: 1.2;
    }

    .brand-mobile-title span {
      font-size: .72em;
      color: var(--muted);
    }

    .screen {
      gap: 5px;
    }

    .tree-title {
      z-index: 35;
      background: rgba(251,247,238,.98);
      border-radius: 9px;
    }

    .mobile-nav {
      display: grid;
      gap: 4px;
    }

    .mobile-nav-button {
      display: flex;
      justify-content: center;
      align-items: center;
      min-width: 0;
      padding: 4px 6px;
      border: 1px solid var(--line-soft);
      border-radius: 6px;
      background: #fffaf3;
      color: var(--accent);
      white-space: nowrap;
      cursor: pointer;
    }

    .mobile-nav-button[aria-expanded="true"] {
      background: var(--accent-soft);
      border-color: var(--accent);
    }

    .mobile-search-button {
      gap: 5px;
      font-size: 21px;
    }

    .mobile-search-button span {
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .tree-search, .branch-switch {
      position: absolute;
      top: calc(100% + 3px);
      left: 0;
      right: 0;
      width: 100%;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: var(--paper-light);
      box-shadow: 0 12px 28px rgba(35,25,20,.23);
      z-index: 60;
    }

    body.mobile-branches-open .branch-switch {
      flex-direction: column;
      flex-wrap: nowrap;
      max-height: min(67dvh,480px);
      overflow: auto;
      scroll-snap-type: none;
    }

    .person-search-input {
      min-height: 46px;
      height: 46px;
      font-size: 16px;
    }

    .search-results {
      position: relative;
      top: auto;
      left: auto;
      right: auto;
      max-height: min(43dvh,300px);
      margin-top: 4px;
      box-shadow: none;
    }

    .branch-card {
      display: grid;
      flex: none;
      width: 100%;
      min-width: 0;
      grid-template-columns: minmax(0,1fr) 85px;
    }

    .branch-button {
      text-align: left;
      padding: 8px 10px;
    }

    .branch-button span {
      font-size: 14px;
      line-height: 1.3;
    }

    .branch-switch .branch-button small {
      font-size: 11px;
      line-height: 1.15;
      color: var(--muted);
    }

    .branch-album-button {
      font-size: 12px;
      padding: 5px 6px;
    }

    .mobile-person-quick {
      border-radius: 8px;
      border: 1px solid rgba(123,36,50,.5);
      box-shadow: 0 2px 8px rgba(42,34,24,.06);
    }

    .mobile-quick-caption {
      font-size: 11px;
    }

    .tree-area {
      border-radius: 9px;
    }

    .tree-view-controls {
      width: calc(100% - 12px);
      max-width: 470px;
      gap: 3px;
      margin: 6px 6px -59px;
      padding: 4px;
      top: 6px;
      left: 6px;
      z-index: 22;
    }

    .tree-view-controls::after {
      display: none;
    }

    .tree-view-button {
      padding: 7px 3px;
    }

    .tree-view-icon {
      font-size: 22px;
    }

    .mobile-view-label {
      display: inline;
    }

    .tree-area.is-overview .overview-labels {
      display: none;
    }

    .tree-area.is-overview {
      touch-action: pan-y;
    }

    .tree-area.is-overview .mobile-overview-picker:not([hidden]) {
      display: block;
      position: absolute;
      z-index: 24;
      width: auto;
      max-width: none;
      max-height: none;
      min-height: 0;
      overflow-y: auto;
      margin: 0;
      padding: 12px;
      touch-action: pan-y;
      overscroll-behavior: contain;
      border: 1px solid rgba(123,36,50,.42);
      border-radius: 10px;
      background: rgba(251,247,238,.98);
      box-shadow: 0 10px 30px rgba(30,25,22,.16);
    }

    .mobile-overview-picker h2 {
      margin: 0 0 3px;
      font-size: 17px;
      font-weight: 500;
      color: var(--accent);
    }

    .mobile-overview-picker p {
      margin: 0 0 9px;
      font-size: 12px;
      line-height: 1.35;
      color: var(--muted);
    }

    .mobile-overview-grid {
      display: grid;
      grid-template-columns: repeat(2,minmax(0,1fr));
      gap: 6px;
    }

    .mobile-overview-grid button {
      display: grid;
      gap: 3px;
      min-width: 0;
      min-height: 48px;
      padding: 6px 8px;
      text-align: left;
      border: 1px solid var(--line-soft);
      border-radius: 6px;
      background: #fffaf3;
      color: var(--ink);
      font: inherit;
      font-size: 14px;
      cursor: pointer;
    }

    .mobile-overview-grid button:first-child {
      border-color: var(--accent);
      color: var(--accent);
      background: rgba(234,216,218,.37);
    }

    .mobile-overview-grid button small {
      color: var(--muted);
      font-size: 11px;
    }

    .tree-area.is-overview .person {
      pointer-events: none;
    }

    .tree-area.is-overview .tree-canvas {
      opacity: .10;
      pointer-events: none;
    }

    .mobile-lineage-preview {
      margin-top: 14px;
      padding-top: 11px;
      border-top: 1px solid var(--line-soft);
    }

    .mobile-lineage-preview > h3 {
      margin: 0 0 9px;
      font-size: 16px;
      font-weight: 500;
      color: var(--accent);
    }

    .mobile-lineage-columns {
      display: grid;
      grid-template-columns: repeat(2,minmax(0,1fr));
      gap: 8px;
      align-items: start;
    }

    .mobile-lineage {
      min-width: 0;
      padding: 8px;
      border: 1px solid var(--line-soft);
      border-radius: 7px;
      background: #fffbf5;
    }

    .mobile-lineage h4 {
      margin: 0 0 8px;
      font-size: 13px;
      color: var(--accent);
      font-weight: 600;
      line-height: 1.25;
    }

    .mobile-ancestor {
      position: relative;
      display: grid;
      gap: 3px;
      width: 100%;
      min-width: 0;
      min-height: 46px;
      margin: 0 0 12px;
      padding: 7px 7px;
      border: 1px solid #d7ccbc;
      border-radius: 5px;
      background: #fffdf9;
      text-align: left;
      font: inherit;
      cursor: pointer;
    }

    .mobile-ancestor:not(:last-child)::after {
      content: "↓";
      position: absolute;
      bottom: -13px;
      left: calc(50% - 5px);
      font-size: 13px;
      color: var(--accent);
      pointer-events: none;
    }

    .mobile-ancestor:last-child {
      margin-bottom: 0;
    }

    .mobile-ancestor strong {
      font-size: 14px;
      font-weight: 500;
      line-height: 1.18;
      color: var(--ink);
      overflow-wrap: anywhere;
    }

    .mobile-ancestor small {
      font-size: 12px;
      color: var(--muted);
    }

    .mobile-ancestor:active {
      border-color: var(--accent);
    }

    .mobile-lineage-note {
      padding: 8px;
      border-left: 2px solid var(--accent);
    }

    @media (max-width:320px) {
      .mobile-lineage-columns {
        grid-template-columns: 1fr;
      }
    }

    .panel-head {
      padding: 20px 102px 7px 14px;
    }

    .panel-head h2 {
      font-size: 21px;
    }

    .mobile-panel-close {
      top: 19px;
    }

    .panel-body {
      padding-bottom: calc(30px + env(safe-area-inset-bottom));
    }
  }

  @media (max-width:360px) {

    .tree-zoom-level {
      display: none;
    }

    .mobile-nav-button {
      padding: 4px 3px;
    }

    .mobile-overview-grid button {
      font-size: 12px;
    }
  }

  @media (max-width:1000px) and (max-height:450px) and (pointer:coarse) {
    .header {
      display: none;
    }

    .screen {
      gap: 3px;
    }

    .mobile-person-quick {
      min-height: 44px;
      max-height: 44px;
      padding: 4px 10px;
    }

    .mobile-quick-caption {
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .mobile-quick-caption strong {
      font-size: 15px;
    }

    .tree-view-controls {
      margin-bottom: -54px;
    }

    .tree-area.is-overview .mobile-overview-picker:not([hidden]) {
      inset: 61px 5px 5px;
    }
  }

  .story-scheme-mobile,.story-scheme-explain,.story-toc,.mobile-kin {
    display: none;
  }

  @media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
    /*Compact, not a desktop toolbar shrunk until labels are unreadable.*/

    .mobile-nav {
      grid-template-columns: minmax(0,1fr) 86px 88px;
    }

    .mobile-nav-button {
      min-height: 44px;
      font-size: 14px;
    }

    .mobile-search-button span {
      font-size: 14px;
    }

    .mobile-person-quick {
      max-height: 55px;
      padding: 6px 10px;
    }

    .tree-view-controls {
      grid-template-columns: minmax(0,1fr) minmax(0,.70fr) 44px 43px 44px;
    }

    .tree-view-button {
      min-height: 46px;
      font-size: 13px;
    }

    .tree-zoom-level {
      font-size: 13px;
    }

    .mobile-kin {
      align-items: center;
      position: sticky;
      top: 62px;
      left: 7px;
      z-index: 20;
      width: calc(100% - 14px);
      margin: 67px 7px -103px;
      padding: 5px 8px;
      border: 1px solid rgba(188,174,154,.85);
      font-size: 12px;
      line-height: 1.2;
    }

    .mobile-kin-group {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 4px;
      min-width: 0;
    }

    .mobile-kin-group b {
      font-size: 11px;
      color: var(--muted);
      font-weight: 500;
      margin-right: 3px;
    }

    .mobile-kin-link {
      font: inherit;
      white-space: normal;
      color: var(--accent);
      background: #fff8f0;
      border: 1px solid var(--line-soft);
      border-radius: 5px;
      cursor: pointer;
    }

    /*The overview is an explicit choice, not an unintended consequence of pinching.*/

    .tree-area.is-overview .mobile-overview-picker:not([hidden]) {
      inset: 61px 5px 5px;
    }

    /*Album: a small persistent close affordance, no enormous full-width button.*/

    .story-modal {
      scroll-padding-top: 80px;
    }

    .story-header {
      min-height: 65px;
    }

    .story-header > div {
      min-width: 0;
      flex: 1;
    }

    .story-kicker {
      display: none;
    }

    .story-title {
      font-size: clamp(16px,4.7vw,20px);
      line-height: 1.15;
    }

    .story-subtitle {
      font-size: 12px;
      line-height: 1.25;
      margin-top: 2px;
    }

    .story-close {
      min-width: 44px;
      max-width: 44px;
      height: 44px;
      overflow: hidden;
      flex: none;
    }

    .story-close::before {
      content: "×";
      font-size: 30px;
      line-height: 40px;
      display: block;
      text-align: center;
    }

    .story-modal.is-scrolled .story-subtitle {
      display: none;
    }

    .story-modal.is-scrolled .story-title {
      font-size: 16px;
    }

    .story-toc {
      display: block;
      border: 1px solid var(--line-soft);
      border-radius: 7px;
      background: var(--paper-light);
    }

    .story-toc summary {
      display: flex;
      justify-content: space-between;
      align-items: center;
      min-height: 43px;
      cursor: pointer;
      padding: 9px 12px;
      font-size: 15px;
      color: var(--accent);
      font-weight: 600;
      list-style: none;
    }

    .story-toc summary::-webkit-details-marker {
      display: none;
    }

    .story-toc > div {
      display: grid;
      grid-template-columns: 1fr;
      gap: 2px;
      padding: 0 7px 7px;
    }

    .story-toc button {
      text-align: left;
      font: inherit;
      font-size: 14px;
      border: 0;
      border-top: 1px solid var(--line-soft);
      background: transparent;
      color: var(--ink);
      padding: 9px 6px;
      min-height: 43px;
    }

    .story-scheme {
      gap: 10px;
      box-shadow: none;
    }

    .story-scheme-title {
      font-size: 19px;
      margin-bottom: 7px;
    }

    .story-scheme-explain {
      display: block;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.4;
      margin: 0 0 10px;
    }

    .story-scheme-mobile {
      display: grid;
      grid-template-columns: 1fr;
      gap: 8px;
    }

    .story-line-details {
      border: 1px solid var(--line-soft);
      border-radius: 7px;
      background: rgba(255,253,248,.95);
      overflow: hidden;
    }

    .story-line-details summary {
      min-height: 57px;
      display: grid;
      grid-template-columns: 26px minmax(0,1fr) auto;
      align-items: center;
      gap: 8px;
      padding: 8px;
      cursor: pointer;
      list-style: none;
    }

    .story-line-details summary::-webkit-details-marker {
      display: none;
    }

    .story-line-number {
      color: var(--accent);
      font-size: 13px;
      font-weight: 700;
    }

    .story-line-summary {
      display: grid;
      gap: 3px;
      min-width: 0;
    }

    .story-line-summary b {
      font-size: 14px;
      line-height: 1.2;
      color: var(--ink);
    }

    .story-line-summary small {
      font-size: 12px;
      line-height: 1.25;
      color: var(--muted);
      overflow-wrap: anywhere;
    }

    .story-line-expand {
      font-size: 11px;
      color: var(--accent);
      white-space: nowrap;
    }

    .story-line-details[open] .story-line-expand {
      font-size: 0;
    }

    .story-line-details[open] .story-line-expand::before {
      content: "Свернуть ▴";
      font-size: 11px;
    }

    .story-line-list {
      counter-reset: lineage;
      list-style: none;
      margin: 0;
      padding: 2px 8px 9px 42px;
      border-top: 1px solid var(--line-soft);
    }

    .story-line-list li {
      display: grid;
      grid-template-columns: minmax(0,1fr) auto;
      gap: 8px;
      align-items: baseline;
      position: relative;
      padding: 7px 0 7px 11px;
      border-left: 1px solid var(--line);
      font-size: 14px;
      line-height: 1.25;
    }

    .story-line-list li::before {
      content: "";
      position: absolute;
      left: -4px;
      top: 14px;
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: var(--accent);
    }

    .story-line-list li strong {
      font-weight: 500;
      overflow-wrap: anywhere;
    }

    .story-line-list li span {
      font-size: 12px;
      color: var(--muted);
      text-align: right;
      max-width: 98px;
    }

    .story-marriage-note {
      font-size: 13px;
      line-height: 1.45;
      text-align: left;
      margin: 9px 0 0;
      padding-top: 11px;
    }

    .story-marriage-symbol {
      width: 22px;
      height: 22px;
      font-size: 14px;
      margin: 0 8px 0 0;
      vertical-align: middle;
    }

    /*Passport becomes vertical label/value rows, so there is never a 640px sideways scroll.*/

    .story-passport {
      max-width: 100%;
    }

    .story-passport h3 {
      font-size: 19px;
    }

    .story-passport-table {
      border: 0;
      background: transparent;
    }

    .story-passport-table thead {
      display: none;
    }

    .story-passport-table tbody {
      display: grid;
      gap: 7px;
    }

    .story-passport-table tr {
      display: grid;
      grid-template-columns: minmax(0,1fr);
      gap: 2px;
      border: 1px solid var(--line-soft);
      border-radius: 6px;
      padding: 9px 10px;
      background: #fffaf3;
    }

    .story-passport-table td,.story-passport-table td:first-child,.story-passport-table td:last-child {
      display: block;
      width: auto;
      min-width: 0;
      border: 0;
      padding: 0;
      background: transparent;
      color: var(--ink);
      font-size: 14px;
      line-height: 1.36;
      overflow-wrap: anywhere;
    }

    .story-passport-table td:first-child {
      font-size: 12px;
      color: var(--accent);
      font-weight: 700;
      margin-bottom: 2px;
    }

    .story-section,.story-section-content {
      min-width: 0;
    }

    .story-section h3 {
      font-size: 19px;
      line-height: 1.2;
    }

    .story-section p, .story-section li, .story-timeline-item {
      font-size: 16px;
      line-height: 1.52;
      overflow-wrap: break-word;
    }

    .story-figure img,.story-section-media .story-figure img {
      width: 100%;
      object-fit: contain;
      max-height: 280px;
    }

    .story-zoom-hint {
      pointer-events: none;
      text-align: center;
    }

    .story-image-button {
      display: block;
      width: 100%;
    }

    .story-scheme,#storyPassport,.story-section,.story-timeline {
      scroll-margin-top: 86px;
    }

    .lightbox-title {
      font-size: 14px;
      line-height: 1.3;
    }
  }

  @media (max-width:360px) {
    .tree-view-controls {
      grid-template-columns: minmax(0,1fr) 64px 44px 44px;
    }

    .tree-view-controls #viewAll {
      font-size: 12px;
    }

    .mobile-nav {
      grid-template-columns: minmax(0,1fr) 68px 70px;
    }

    .mobile-nav-button,.mobile-search-button span {
      font-size: 12px;
    }

    .story-line-details summary {
      grid-template-columns: 22px minmax(0,1fr);
    }

    .story-line-expand {
      grid-column: 2;
      justify-self: start;
    }
  }

  @media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
    .tree-area:not(.is-overview) .person {
      align-items: center;
      gap: 0;
      width: 198px;
      padding: 7px 9px;
      border-radius: 7px;
      overflow: visible;
      opacity: 1;
    }

    .tree-area:not(.is-overview) .person > span:last-child {
      min-width: 0;
      display: block;
    }

    .tree-area:not(.is-overview) .person .person-name {
      line-height: 1.12;
      font-weight: 650;
      margin-bottom: 3px;
      overflow-wrap: normal;
      word-break: normal;
      hyphens: auto;
    }

    .tree-area:not(.is-overview) .person .person-years {
      line-height: 1.16;
      overflow-wrap: normal;
    }

    .tree-area:not(.is-overview) .person.is-selected {
      z-index: 7;
      background: #fffaf4;
      border: 2px solid var(--accent);
      box-shadow: 0 0 0 3px rgba(123,36,50,.13), 0 6px 20px rgba(50,29,25,.16);
    }

    .tree-area:not(.is-overview) .person.is-muted:not(.is-private) {
      opacity: .78;
    }

    .tree-area:not(.is-overview) .person.is-private {
      opacity: .30;
    }

    .mobile-kin {
      display: flex;
      flex-wrap: wrap;
      gap: 5px 8px;
      max-width: none;
      min-height: 0;
      box-shadow: none;
      background: rgba(244,237,223,.35);
      border-radius: 7px;
    }

    .mobile-kin-link {
      font-size: 13px;
      min-height: 36px;
      padding: 6px 9px;
    }

    .mobile-person-quick {
      gap: 8px;
      min-height: 64px;
      align-items: center;
    }

    .mobile-quick-caption {
      min-width: 0;
      gap: 1px;
    }

    .mobile-quick-caption strong {
      font-size: 17px;
      white-space: normal;
      line-height: 1.12;
      overflow: visible;
    }

    .mobile-quick-caption small {
      font-size: 12px;
      line-height: 1.15;
      color: var(--muted);
    }

    .mobile-quick-action {
      font: inherit;
      font-size: 14px;
      font-weight: 600;
      padding: 10px 8px;
      min-height: 44px;
      border: 1px solid var(--accent);
      border-radius: 6px;
      background: #fffaf3;
      color: var(--accent);
      cursor: pointer;
    }

    .mobile-quick-action:focus-visible {
      outline: 3px solid var(--accent);
      outline-offset: 2px;
    }

    .tree-zoom-level {
      min-width: 38px;
    }
  }

  .mobile-mode-tabs,.full-tree-overview {
    display: none;
  }

  @media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
    .mobile-mode-tabs {
      display: grid;
      order: 2;
      flex: none;
      grid-template-columns: 1fr 1fr;
      gap: 5px;
      padding: 4px;
      border: 1px solid var(--line-soft);
      border-radius: 9px;
      background: #faf4eb;
    }

    .mobile-mode-tabs button {
      min-width: 0;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      gap: 2px;
      min-height: 50px;
      border: 1px solid transparent;
      border-radius: 6px;
      color: #756b64;
      background: transparent;
      font: inherit;
      font-size: 17px;
      line-height: 1.14;
      cursor: pointer;
    }

    .mobile-mode-tabs button small {
      font-size: 10px;
      white-space: nowrap;
      color: #756b64;
    }

    .mobile-mode-tabs button[aria-selected="true"] {
      color: var(--accent);
      background: #fffaf3;
      border-color: var(--accent);
      box-shadow: 0 2px 7px rgba(45,30,22,.06);
    }

    .mobile-person-quick {
      order: 3;
    }

    .tree-area {
      order: 4;
    }

    .tree-area .tree-view-controls {
      grid-template-columns: minmax(0,1fr) 44px minmax(34px,50px) 44px;
    }

    .tree-area.is-full-tree {
      overscroll-behavior: none;
    }

    .full-tree-overview:not([hidden]) {
      display: flex;
      flex-direction: column;
      gap: clamp(5px,1dvh,10px);
      height: 100%;
      width: 100%;
      min-height: 0;
      box-sizing: border-box;
      padding: clamp(8px,2vw,14px);
      overflow: hidden;
      background: #fffaf3;
      touch-action: none;
      user-select: none;
      pointer-events: none;
    }

    .overview-heading {
      display: flex;
      align-items: baseline;
      justify-content: space-between;
      gap: 4px;
      flex: none;
      color: var(--accent);
    }

    .overview-heading strong {
      font-size: clamp(17px,4.5vw,22px);
      line-height: 1.1;
    }

    .overview-heading span {
      font-size: clamp(11px,3vw,13px);
      white-space: nowrap;
    }

    .overview-explain,.overview-footnote {
      flex: none;
      color: #6f655b;
      font-size: clamp(10px,2.6vw,12px);
      line-height: 1.27;
    }

    .overview-poster {
      display: block;
      height: clamp(65px,18%,125px);
      flex: none;
      border: 1px solid #dacdbc;
      border-radius: 6px;
      background: #f8efdf;
      overflow: hidden;
    }

    .overview-graph {
      width: 100%;
      height: 100%;
      display: block;
    }

    .overview-edges {
      fill: none;
      stroke: #baab95;
      stroke-width: 15;
      stroke-linecap: round;
      stroke-linejoin: round;
    }

    .overview-nodes rect {
      fill: #cdbfa9;
      stroke: #a99a85;
      stroke-width: 9;
    }

    .overview-nodes rect.public {
      fill: #924f5c;
      stroke: #713744;
    }

    .overview-footnote {
      padding: 0 2px;
    }

    .side-panel.mobile-is-open {
      display: flex;
      flex-direction: column;
    }

    .side-panel .panel-head {
      flex: 0 0 auto;
      min-height: 0;
      padding: 22px 107px 8px 15px;
    }

    .side-panel .panel-head h2 {
      font-size: clamp(19px,5.3vw,25px);
      overflow-wrap: anywhere;
    }

    .side-panel #mobileKin:not([hidden]) {
      flex-direction: column;
      align-items: stretch;
      flex: 0 0 auto;
      max-width: none;
      max-height: min(24dvh,162px);
      overflow: auto;
      box-sizing: border-box;
    }

    .side-panel .mobile-kin-group {
      width: 100%;
      grid-template-columns: 65px minmax(0,1fr);
      align-items: start;
      gap: 6px;
      min-width: 0;
    }

    .side-panel .mobile-kin-group b {
      padding-top: 7px;
      font-size: 12px;
    }

    .side-panel .mobile-kin-names {
      display: flex;
      flex-wrap: wrap;
      gap: 5px;
      min-width: 0;
    }

    .side-panel .mobile-kin-link {
      max-width: 100%;
      white-space: normal;
      overflow-wrap: anywhere;
      line-height: 1.22;
    }

    .side-panel .tabs {
      flex: 0 0 auto;
      display: grid;
      margin: 0;
      clear: both;
    }

    .side-panel .panel-body {
      flex: 1 1 auto;
      min-height: 0;
      overflow: auto;
    }
  }

  @media (max-width:360px) {
    .mobile-mode-tabs button {
      font-size: 14px;
    }

    .overview-heading {
      flex-wrap: wrap;
    }

    .overview-poster {
      height: clamp(52px,15%,95px);
    }

    .overview-explain {
      font-size: 10px;
    }
  }

  @media (max-width:1000px) and (max-height:450px) and (pointer:coarse) {
    .mobile-mode-tabs button {
      min-height: 37px;
      flex-direction: row;
      gap: 6px;
      font-size: 14px;
    }

    .overview-explain,.overview-footnote {
      display: none;
    }

    .overview-poster {
      height: 20%;
    }
  }

  @media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
    .screen > .tree-view-controls {
      order: 4;
      flex: none;
      position: relative;
      top: auto;
      left: auto;
      width: 100%;
      max-width: none;
      margin: 0;
      padding: 5px;
      box-sizing: border-box;
      display: grid;
      grid-template-columns: minmax(0,1fr) 44px 46px 44px;
      gap: 4px;
      background: rgba(251,247,238,.99);
      border: 1px solid var(--line-soft);
      border-radius: 8px;
      box-shadow: 0 2px 9px rgba(42,34,24,.05);
    }

    .screen > .tree-area {
      order: 5;
    }
  }

  @media (min-width:1001px), (min-width:761px) and (pointer:fine), (min-width:761px) and (min-height:601px) {
    .screen > .mobile-mode-tabs {
      display: grid;
      grid-column: 2;
      grid-row: 1;
      z-index: 42;
      align-self: start;
      justify-self: center;
      width: min(470px,calc(100% - 28px));
      height: auto;
      margin-top: 10px;
      padding: 4px;
      grid-template-columns: 1fr 1fr;
      gap: 5px;
      border: 1px solid var(--line-soft);
      border-radius: 9px;
      background: rgba(251,247,238,.98);
      box-shadow: 0 7px 20px rgba(42,34,24,.09);
    }

    .mobile-mode-tabs button {
      min-height: 48px;
      padding: 5px 12px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 2px;
      border: 1px solid transparent;
      border-radius: 6px;
      background: transparent;
      color: var(--muted);
      font: inherit;
      font-size: 17px;
      cursor: pointer;
    }

    .mobile-mode-tabs button small {
      color: var(--muted);
      font-size: 11px;
    }

    .mobile-mode-tabs button[aria-selected="true"] {
      background: var(--paper-light);
      border-color: var(--accent);
      color: var(--accent);
      box-shadow: 0 2px 5px rgba(42,34,24,.06);
    }

    .tree-area .tree-view-controls {
      top: 72px;
      margin-top: 74px;
    }

    .full-tree-overview:not([hidden]) {
      display: flex;
      flex-direction: column;
      height: 100%;
      width: 100%;
      min-width: 0;
      min-height: 0;
      padding: 83px 22px 16px;
      gap: 10px;
      overflow: hidden;
      background: var(--paper-light);
      box-sizing: border-box;
      user-select: none;
      touch-action: none;
    }

    .overview-heading {
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      gap: 15px;
      flex: none;
      color: var(--accent);
    }

    .overview-heading strong {
      font-size: 26px;
      font-weight: 500;
    }

    .overview-heading span {
      font-size: 14px;
      white-space: nowrap;
    }

    .overview-explain,.overview-footnote {
      flex: none;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.4;
    }

    .overview-poster {
      display: block;
      flex: 1 1 65%;
      min-height: 140px;
      border: 1px solid var(--line-soft);
      border-radius: 6px;
      background: #f8efdf;
      overflow: hidden;
    }

    .overview-graph {
      display: block;
      width: 100%;
      height: 100%;
    }

    .overview-edges {
      fill: none;
      stroke: #baab95;
      stroke-width: 15;
      stroke-linecap: round;
      stroke-linejoin: round;
    }

    .overview-nodes rect {
      fill: #cdbfa9;
      stroke: #a99a85;
      stroke-width: 9;
    }

    .overview-nodes rect.public {
      fill: #924f5c;
      stroke: #713744;
    }

    .screen.is-full-tree .tree-area {
      grid-column: 1/-1;
      grid-row: 1/-1;
    }

    .screen.is-full-tree > .mobile-mode-tabs {
      grid-column: 1/-1;
      grid-row: 1;
    }
  }

  @media (min-width:761px) and (max-height:680px) and (pointer:fine) {
    .full-tree-overview:not([hidden]) {
      padding-top: 74px;
      gap: 5px;
      padding-bottom: 7px;
    }

    .overview-heading strong {
      font-size: 19px;
    }

    .overview-poster {
      min-height: 70px;
    }

    .overview-explain,.overview-footnote {
      font-size: 11px;
    }
  }

  /*Narrow desktop uses the SAME two-column composition, not the legacy
   <=1180px single-column fallback which created a phantom grid column.*/

  @media (min-width:761px) and (max-width:1180px) and (min-height:700px) and (pointer:fine), (min-width:1001px) and (max-width:1180px) and (min-height:700px) {
    .screen .side-panel {
      display: flex;
      grid-column: 1;
      grid-row: 1;
      min-height: 0;
      max-height: 100%;
    }

    .screen .left-panel-resizer {
      grid-column: 1;
      grid-row: 2;
    }

    .screen .tree-title {
      grid-column: 1;
      grid-row: 3;
      min-height: 0;
      max-height: 100%;
      overflow: auto;
    }

    .screen .tree-area {
      grid-column: 2;
      grid-row: 1 / span 3;
      max-height: 100%;
    }

    .screen > .mobile-mode-tabs {
      grid-column: 2;
      grid-row: 1;
    }

    .screen.is-full-tree .tree-area {
      grid-column: 1/-1;
      grid-row: 1/-1;
    }

    .screen.is-full-tree > .mobile-mode-tabs {
      grid-column: 1/-1;
      grid-row: 1;
    }
  }

  /*Desktop browser windows with little vertical space: don't create an
   implicit second grid column or a 14px-wide tree. Stack the sections.*/

  @media (min-width:761px) and (max-width:1180px) and (max-height:699px) and (pointer:fine), (min-width:1001px) and (max-width:1180px) and (max-height:699px) {
    .screen {
      flex-direction: column;
    }

    .screen > .mobile-mode-tabs {
      display: grid;
      order: 0;
      flex: none;
      position: relative;
      align-self: center;
      justify-self: auto;
      width: min(470px,100%);
      margin: 0 auto;
    }

    .screen .tree-area {
      order: 1;
      flex: none;
      grid-column: auto;
      grid-row: auto;
      width: 100%;
      max-height: none;
    }

    .screen .side-panel {
      order: 2;
      grid-column: auto;
      grid-row: auto;
      min-height: 0;
      width: 100%;
    }

    .screen .tree-title {
      order: 3;
      grid-column: auto;
      grid-row: auto;
      width: 100%;
      min-height: 0;
      max-height: none;
      overflow: visible;
    }

    .screen.is-full-tree .tree-area {
      order: 1;
      width: 100%;
    }

    .screen.is-full-tree > .mobile-mode-tabs {
      order: 0;
    }

    .overview-heading strong {
      font-size: 18px;
    }

    .overview-explain,.overview-footnote {
      font-size: 10px;
      line-height: 1.15;
    }
  }

  .branch-button:disabled, .branch-album-button:disabled, .mobile-overview-grid button:disabled {
    opacity: .72;
  }

  .branch-card:has(.branch-main:disabled) .branch-button {
    background: #f6f0e7;
    color: #777068;
  }

  .branch-card:has(.branch-main:disabled) .branch-album-button {
    color: #756f65;
    background: #f6f0e7;
  }

  .full-tree-overview:not([hidden]) {
    justify-content: stretch;
  }

  .full-tree-overview:not([hidden]) .overview-poster {
    overflow: hidden;
  }

  .full-tree-overview:not([hidden]) .overview-graph {
    display: block;
    width: 100%;
    height: 100%;
  }

  .full-tree-overview:not([hidden]) .overview-footnote {
    flex: none;
    color: var(--accent);
    font-weight: 600;
    padding: 0 1px;
  }

  @media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
    .full-tree-overview:not([hidden]) .overview-heading strong {
      font-size: clamp(18px,5vw,23px);
    }
  }

  @media (min-width:1001px), (min-width:761px) and (min-height:601px) {
    .screen > .tree-view-controls {
      grid-column: 2;
      grid-row: 1;
      align-self: start;
      justify-self: start;
      z-index: 44;
      width: max-content;
      max-width: calc(100% - 24px);
      height: 47px;
      flex: none;
      box-sizing: border-box;
      background: rgba(251,247,238,.98);
      border: 1px solid var(--line-soft);
      box-shadow: 0 3px 9px rgba(42,34,24,.06);
      backdrop-filter: none;
    }

    .screen:not(.is-full-tree) .person {
      height: 108px;
      min-height: 108px;
    }
  }

  @media (min-width:761px) and (max-width:1180px) and (max-height:699px) and (pointer:fine), (min-width:1001px) and (max-width:1180px) and (max-height:699px) {
    .screen > .tree-view-controls {
      order: 1;
      align-self: flex-start;
      width: max-content;
      max-width: 100%;
      height: auto;
    }

    .screen:not(.is-full-tree) > .tree-area {
      order: 2;
    }
  }

  /*The full-tree overview is an integrated illustration on the same paper,
   not an inset white PNG inside a second white panel.*/

  .screen.is-full-tree > .tree-area {
    scrollbar-width: none;
  }

  .full-tree-overview:not([hidden]) {
    align-items: stretch;
  }

  .full-tree-overview:not([hidden]) .overview-poster {
    aspect-ratio: 12410 / 2330;
    width: 100%;
  }

  @media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
    .full-tree-overview:not([hidden]) .overview-poster {
      aspect-ratio: 12410 / 2330;
    }
  }

  .full-tree-overview:not([hidden]) {
    user-select: none;
    touch-action: none;
  }

  .full-tree-overview:not([hidden]) .overview-heading {
    min-width: 0;
  }

  .overview-edges {
    fill: none;
    stroke: #b4a58f;
    stroke-width: 11;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .overview-nodes rect {
    fill: #cdbfa9;
    stroke: #a99a85;
    stroke-width: 7;
  }

  .overview-nodes rect.public {
    fill: #92515e;
    stroke: #713744;
  }

  .overview-branch-name {
    font-family: Georgia,'Times New Roman',serif;
    font-size: 128px;
    fill: #746859;
    font-weight: 500;
  }

  .overview-branch-name.public-label {
    fill: #7b2432;
    font-weight: 700;
  }

  .overview-branch-count {
    font-family: Georgia,'Times New Roman',serif;
    font-size: 76px;
    fill: #786e63;
  }

  .overview-volume {
    display: grid;
    grid-template-columns: repeat(5,minmax(0,1fr));
    gap: 12px;
    flex: 0 0 auto;
    min-width: 0;
  }

  .overview-volume-item {
    padding: 9px 12px;
    border: 1px solid #d6cabb;
    border-radius: 6px;
    background: rgba(251,247,238,.30);
    min-width: 0;
  }

  .overview-volume-item.is-public {
    border-color: rgba(123,36,50,.45);
    background: rgba(123,36,50,.04);
  }

  .overview-volume-line {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 2px 9px;
  }

  .overview-volume-line strong {
    font-weight: 600;
    color: var(--ink);
    font-size: 15px;
  }

  .overview-volume-item.is-public .overview-volume-line strong {
    color: var(--accent);
  }

  .overview-volume-line span {
    font-size: 11px;
    color: var(--muted);
  }

  @media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
    .overview-volume {
      flex-direction: column;
      gap: 7px;
      overflow: auto;
      min-height: 0;
    }

    .overview-volume-item {
      flex: 0 0 auto;
    }

    .overview-volume-line strong {
      font-size: clamp(13px,4vw,16px);
    }

    .overview-volume-line span {
      font-size: clamp(11px,3.2vw,13px);
    }
  }

  @media (min-width:761px) and (max-height:700px) {
    .overview-volume-item {
      padding: 5px 8px;
    }
  }

  @media (max-width:1000px) and (max-height:450px) and (pointer:coarse) {
    .overview-volume {
      grid-template-columns: repeat(5,minmax(0,1fr));
      gap: 4px;
    }
  }
}

@media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
  .app {
    padding: 8px 8px 14px;
  }

  .screen {
    padding: 0;
  }

  .left-panel-resizer {
    display: none;
  }

  .story-shell {
    width: 100vw;
  }

  .story-body {
    padding: 14px;
  }

  .story-section, .story-scheme, .story-main-text, .story-main-text-wide, .story-scheme-columns, .story-section-with-media {
    grid-template-columns: 1fr;
  }

  .story-figure img, .story-section-media .story-figure img {
    height: auto;
  }

  .story-timeline-items {
    grid-template-columns: 1fr;
  }

  .lightbox.is-story-scoped {
    inset: 0;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100dvh;
  }
}

@media (max-width:390px) {
  .tree-area {
    height: 66dvh;
    min-height: 455px;
  }
}

@media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
  .app {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding: max(6px, env(safe-area-inset-top)) 8px 0;
  }

  .screen {
    display: flex;
    height: auto;
  }

  .tree-title {
    margin: 0;
  }

  .branch-switch {
    display: flex;
    grid-template-columns: none;
  }

  .branch-button small, .branch-switch .demo-note {
    display: none;
  }

  .tree-area {
    height: auto;
    min-height: 0;
  }

  .tree-area::before {
    display: none;
  }

  .side-panel {
    position: fixed;
    margin: 0;
  }

  .panel-body {
    overflow-y: auto;
  }

  .story-modal {
    padding: 0;
  }

  .story-shell {
    overflow: visible;
  }
}

@media (max-width:760px) and (max-height:570px), (max-width:1000px) and (max-height:570px) and (pointer:coarse) {
  .app {
    padding-top: 3px;
  }

  .header {
    margin-bottom: 3px;
  }

  .side-panel {
    height: min(92dvh, 760px);
  }
}

@media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
  .app {
    padding: max(5px,env(safe-area-inset-top)) 7px 4px;
  }

  .header {
    margin: 0 0 4px;
  }

  .brand-desktop-title, .tree-title > p, .mobile-demo-help, .desktop-view-label {
    display: none;
  }

  .tree-title {
    padding: 4px;
  }

  .tree-search, .branch-switch {
    display: none;
    margin: 0;
    padding: 8px;
  }

  body.mobile-search-open .tree-search {
    display: block;
  }

  body.mobile-branches-open .branch-switch {
    display: flex;
  }

  .branch-button,.branch-album-button {
    min-height: 48px;
    height: auto;
  }

  .branch-switch .branch-button small {
    display: block;
  }

  .mobile-overview-picker[hidden] {
    display: none;
  }

  .mobile-lineage-note {
    margin: 10px 0 0;
    font-size: 12px;
    line-height: 1.4;
  }

  .side-panel {
    height: min(90dvh,820px);
    max-height: calc(100dvh - 20px);
  }
}

@media (max-width:1000px) and (max-height:450px) and (pointer:coarse) {
  .app {
    padding-top: 2px;
  }
}

.mobile-kin[hidden] {
  display: none;
}

@media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {

  .tree-area.is-overview .mobile-kin {
    display: none;
  }

  .story-header {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
  }

  .story-close {
    width: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 0;
  }

  .story-modal.is-scrolled .story-header {
    padding: 7px 10px;
  }

  .story-modal.is-scrolled .story-header > div {
    display: block;
  }

  .story-body {
    padding: 10px 10px calc(34px + env(safe-area-inset-bottom));
    gap: 12px;
  }

  .story-scheme {
    padding: 13px;
  }

  .story-scheme-columns {
    display: none;
  }

  .story-passport {
    overflow: visible;
  }

  .story-passport-table {
    display: block;
    min-width: 0;
    width: 100%;
  }

  .story-zoom-hint {
    display: block;
    position: static;
    opacity: 1;
    visibility: visible;
    transform: none;
    padding: 8px 5px;
    color: var(--accent);
    background: #fffaf3;
    font-size: 14px;
  }
  .tree-area:not(.is-overview) .person {
    display: grid;
    grid-template-columns: minmax(0,1fr);
    min-height: 88px;
    height: auto;
  }

  .tree-area:not(.is-overview) .person .avatar {
    display: none;
  }

  .tree-area:not(.is-overview) .person .person-name {
    display: block;
    font-size: var(--mobile-person-name-size,16px);
  }

  .tree-area:not(.is-overview) .person .person-years {
    display: block;
    font-size: var(--mobile-person-year-size,13px);
  }

  .tree-area:not(.is-overview) .person::after {
    content: none;
    display: none;
  }

  .mobile-kin {
    position: static;
    width: auto;
    margin: 0 12px 8px;
    padding: 7px 9px;
  }

  .mobile-person-quick {
    max-height: none;
  }
  .tree-area #viewAll {
    display: none;
  }

  .tree-area.is-full-tree {
    overflow: hidden;
    touch-action: none;
  }

  .tree-area.is-full-tree .tree-view-controls, .tree-area.is-full-tree .tree-canvas {
    display: none;
  }

  .screen.is-full-tree .mobile-person-quick {
    display: none;
  }

  .overview-explain,.overview-footnote {
    margin: 0;
  }

  .side-panel #mobileKin:not([hidden]) {
    position: static;
    display: flex;
    width: auto;
    margin: 0 12px 8px;
    padding: 8px;
  }

  .side-panel .mobile-kin-group {
    display: grid;
  }

  .side-panel .tabs {
    position: relative;
    transform: none;
  }
}

@media (max-width:1000px) and (max-height:450px) and (pointer:coarse) {
  .mobile-mode-tabs small {
    font-size: 9px;
  }
}

@media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
  .screen > .tree-view-controls #viewAll {
    display: none;
  }

  .screen > .tree-view-controls::after {
    display: none;
  }

  .screen.is-full-tree > .tree-view-controls {
    display: none;
  }
}

@media (min-width:1001px), (min-width:761px) and (pointer:fine), (min-width:761px) and (min-height:601px) {
  .tree-area .tree-view-controls #viewAll, .tree-area .tree-view-controls .tree-view-separator {
    display: none;
  }

  .tree-area.is-full-tree {
    overflow: hidden;
    cursor: default;
  }

  .tree-area.is-full-tree .tree-canvas, .tree-area.is-full-tree .tree-view-controls {
    display: none;
  }

  .overview-explain,.overview-footnote {
    margin: 0;
  }

  .screen.is-full-tree .side-panel,.screen.is-full-tree .tree-title, .screen.is-full-tree .left-panel-resizer {
    display: none;
  }
}

@media (min-width:761px) and (max-width:1180px) and (min-height:700px) and (pointer:fine), (min-width:1001px) and (max-width:1180px) and (min-height:700px) {
  .app {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding: 18px 16px 14px;
  }

  .screen {
    display: grid;
    height: calc(100dvh - 76px);
    min-height: 0;
    padding: 0;
    gap: 0 12px;
    grid-template-columns: minmax(250px,29%) minmax(0,1fr);
    grid-template-rows: minmax(260px,1fr) 8px minmax(195px,330px);
  }

  .screen .side-panel {
    height: 100%;
    margin: 0;
  }

  .screen .left-panel-resizer {
    display: block;
  }

  .screen .tree-title {
    margin: 0;
  }

  .screen .tree-area {
    height: 100%;
    min-height: 0;
  }

  .screen.is-full-tree .side-panel,.screen.is-full-tree .tree-title, .screen.is-full-tree .left-panel-resizer {
    display: none;
  }
}

@media (min-width:761px) and (max-width:1180px) and (max-height:699px) and (pointer:fine), (min-width:1001px) and (max-width:1180px) and (max-height:699px) {
  .screen {
    display: flex;
    height: auto;
    gap: 8px;
    padding: 0;
  }

  .screen .tree-area {
    height: max(245px,calc(100dvh - 150px));
    min-height: 245px;
  }

  .screen .side-panel {
    height: 480px;
    margin: 0;
  }

  .screen .tree-title {
    margin: 0;
  }

  .screen .left-panel-resizer {
    display: none;
  }

  .screen.is-full-tree .side-panel,.screen.is-full-tree .tree-title {
    display: none;
  }

  .full-tree-overview:not([hidden]) {
    padding: 7px 10px;
    gap: 3px;
  }

  .overview-poster {
    min-height: 70px;
  }
}

.branch-button:disabled, .branch-album-button:disabled, .mobile-overview-grid button:disabled {
  cursor: default;
  pointer-events: none;
  box-shadow: none;
  transform: none;
}

@media (min-width:1001px), (min-width:761px) and (min-height:601px) {
  .screen > .tree-view-controls {
    display: flex;
    position: relative;
    inset: auto;
    top: auto;
    left: auto;
    margin: 74px 0 0 12px;
  }

  .screen:not(.is-full-tree) > .tree-area {
    margin-top: 130px;
    height: calc(100% - 130px);
    max-height: calc(100% - 130px);
    min-height: 0;
  }

  .screen.is-full-tree > .tree-area {
    margin-top: 0;
    height: 100%;
    max-height: none;
  }
}

@media (min-width:761px) and (max-width:1180px) and (max-height:699px) and (pointer:fine), (min-width:1001px) and (max-width:1180px) and (max-height:699px) {
  .screen > .tree-view-controls {
    margin: 0;
  }

  .screen:not(.is-full-tree) > .tree-area {
    margin: 0;
    height: max(245px,calc(100dvh - 200px));
    min-height: 245px;
    max-height: none;
  }

  .screen.is-full-tree > .tree-area {
    margin: 0;
    height: max(245px,calc(100dvh - 150px));
  }
}

.screen.is-full-tree > .tree-area::-webkit-scrollbar {
  display: none;
}

@media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
  .full-tree-overview:not([hidden]) {
    justify-content: center;
  }
}

.screen.is-full-tree {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  min-width: 0;
}

.screen.is-full-tree > .side-panel, .screen.is-full-tree > .left-panel-resizer, .screen.is-full-tree > .tree-title, .screen.is-full-tree > .tree-view-controls, .screen.is-full-tree > .mobile-person-quick {
  display: none;
}

.screen.is-full-tree > .mobile-mode-tabs {
  position: relative;
  inset: auto;
  grid-column: auto;
  grid-row: auto;
  order: 0;
  align-self: center;
  justify-self: center;
  margin: 0;
  flex: 0 0 auto;
  z-index: 1;
}

.screen.is-full-tree > .tree-area {
  flex: 1 1 auto;
  order: 1;
  width: 100%;
  height: auto;
  max-height: none;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  cursor: default;
}

.screen.is-full-tree .tree-canvas, .screen.is-full-tree .tree-area .tree-view-controls {
  display: none;
}

.full-tree-overview:not([hidden]) {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 8px 12px 10px;
  gap: 9px;
  overflow: hidden;
  background: transparent;
}

.full-tree-overview:not([hidden]) .overview-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  flex: 0 0 auto;
  margin: 0;
}

.full-tree-overview:not([hidden]) .overview-heading strong {
  font-size: clamp(19px,1.6vw,26px);
  line-height: 1.2;
}

.full-tree-overview:not([hidden]) .overview-heading span {
  font-size: clamp(11px,.9vw,14px);
}

.full-tree-overview:not([hidden]) .overview-explain {
  display: block;
  margin: 0;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: clamp(12px,.95vw,14px);
  font-weight: 400;
  line-height: 1.35;
}

.full-tree-overview:not([hidden]) .overview-poster {
  display: block;
  flex: 0 1 auto;
  width: 100%;
  height: auto;
  min-height: 0;
  max-height: min(52dvh,490px);
  aspect-ratio: 12500 / 2530;
  overflow: hidden;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.full-tree-overview:not([hidden]) .overview-graph {
  display: block;
  width: 100%;
  height: 100%;
}

.full-tree-overview:not([hidden]) .overview-footnote {
  display: block;
  margin: 0;
  padding: 0;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: clamp(12px,.92vw,14px);
  font-weight: 400;
  letter-spacing: normal;
  line-height: 1.35;
}

@media (max-width:760px), (max-width:1000px) and (max-height:600px) and (pointer:coarse) {
  .screen.is-full-tree {
    gap: 5px;
  }

  .screen.is-full-tree > .mobile-mode-tabs {
    width: 100%;
  }

  .full-tree-overview:not([hidden]) {
    padding: 8px 4px 6px;
    gap: 7px;
  }

  .full-tree-overview:not([hidden]) .overview-heading {
    flex-wrap: nowrap;
    align-items: baseline;
  }

  .full-tree-overview:not([hidden]) .overview-heading strong {
    font-size: clamp(17px,5vw,21px);
  }

  .full-tree-overview:not([hidden]) .overview-heading span {
    font-size: clamp(10px,2.7vw,12px);
    white-space: nowrap;
  }

  .full-tree-overview:not([hidden]) .overview-explain {
    font-size: clamp(11px,3.2vw,13px);
    line-height: 1.33;
  }

  .full-tree-overview:not([hidden]) .overview-poster {
    max-height: none;
    min-height: 62px;
    flex: 0 0 auto;
    aspect-ratio: 12500 / 2530;
  }

  .overview-volume {
    display: flex;
    flex: 1 1 auto;
  }

  .overview-volume-item {
    padding: 8px 11px;
  }

  .full-tree-overview:not([hidden]) .overview-footnote {
    font-size: clamp(11px,3.2vw,13px);
  }
}

@media (min-width:761px) and (max-height:700px) {
  .screen.is-full-tree {
    height: calc(100dvh - 72px);
    gap: 5px;
  }

  .screen.is-full-tree > .mobile-mode-tabs {
    min-height: 0;
  }

  .full-tree-overview:not([hidden]) {
    gap: 5px;
    padding: 4px 8px 4px;
  }

  .full-tree-overview:not([hidden]) .overview-poster {
    max-height: 42dvh;
  }
}

@media (max-width:1000px) and (max-height:450px) and (pointer:coarse) {
  .full-tree-overview:not([hidden]) .overview-explain {
    display: none;
  }

  .full-tree-overview:not([hidden]) .overview-poster {
    max-height: 27dvh;
    min-height: 0;
  }

  .overview-volume {
    display: grid;
    flex: 1 1 auto;
  }

  .overview-volume-item {
    padding: 3px 5px;
  }

  .overview-volume-line strong {
    font-size: 11px;
  }

  .overview-volume-line span {
    font-size: 9px;
  }

  .full-tree-overview:not([hidden]) .overview-footnote {
    display: block;
    font-size: 10px;
  }
}

body.album-open .app {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

body.album-open .tree-view-controls, body.album-open .mobile-mode-tabs, body.album-open .mobile-nav, body.album-open .mobile-person-quick, body.album-open #mobilePanelBackdrop {
  display: none;
}

body.album-open #storyModal.is-open {
  position: fixed;
  inset: 0;
  z-index: 1000;
  visibility: visible;
  pointer-events: auto;
}

body.album-open #lightbox.is-open {
  z-index: 1100;
}

/* === LANDSCAPE TEXT-SIZE STABILITY V7 === */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}


/* V26 — restore normal text selection for all readable content.
   Disable selection only on actual UI chrome; never on body, paragraphs,
   legal terms, FAQ answers, research narratives or ordinary copy. */
body { cursor:default; }
body :is(button,[role="button"],[role="tab"],[role="switch"],summary,
  a,input[type="checkbox"],input[type="radio"],input[type="range"],select),
body :is(button,[role="button"],[role="tab"],[role="switch"],summary,
  a,input[type="checkbox"],input[type="radio"],input[type="range"],select) * {
  -webkit-user-select:none !important;
  user-select:none !important;
  -webkit-touch-callout:none;
}
/* Re-enable inline citations and links when embedded inside prose. */
body :is(p,li,blockquote,dd,td) a:not(.button):not([role="button"]) {
  -webkit-user-select:text !important;
  user-select:text !important;
  -webkit-touch-callout:default;
}
body :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="button"]):not([type="submit"]):not([type="reset"]),
  textarea,[contenteditable="true"],[contenteditable="plaintext-only"]) {
  -webkit-user-select:text !important;
  user-select:text !important;
  -webkit-touch-callout:default;
  caret-color:auto !important;
  cursor:text;
}
body :is(input[type="checkbox"],input[type="radio"],input[type="range"],select) {
  -webkit-user-select:none !important;
  user-select:none !important;
  caret-color:transparent !important;
}
/* Non-editable prose is selectable but never pretends to be an input. */
body :is(h1,h2,h3,h4,h5,h6,p,span,small,strong,em,label,legend,blockquote,dt,dd,li) {
  caret-color:transparent !important;
  cursor:inherit;
}
body :is(a,button,[role="button"],label:has(input[type="checkbox"]),
  label:has(input[type="radio"]),label[for],input[type="checkbox"],input[type="radio"]) {cursor:pointer;}
body :is(a,button,[role="button"]) * {cursor:inherit;}
/* Click/touch focus should not show a frame; keyboard focus remains visible. */
body :is(button,a,input[type="checkbox"],input[type="radio"],select,[role="button"]):focus:not(:focus-visible) {
  outline:none !important;
}
@media (pointer:coarse) {body * {-webkit-tap-highlight-color:transparent;}}



/* V27: Copyable editorial content, non-selectable interface controls.
   Older global V24/V25 overrides were overly broad. Reset those rules, then
   reapply nonselection exclusively to active UI and imagery. */
body, body * {
  -webkit-user-select: auto !important;
  user-select: auto !important;
}
body :is(button, [role="button"], [role="tab"], [role="switch"],
  input[type="checkbox"], input[type="radio"], input[type="range"],
  select, summary),
body :is(button, [role="button"], [role="tab"], [role="switch"],
  input[type="checkbox"], input[type="radio"], input[type="range"],
  select, summary) *,
body :is(nav, .site-header, .topbar, .brand, .intake-progress,
  .presentation-tabs, .presentation-rail, .book-toolbar,
  .book-footer, .book-canvas, .line-context-strip,
  .segmented, .pedigree-picker .branch-option),
body :is(nav, .site-header, .topbar, .brand, .intake-progress,
  .presentation-tabs, .presentation-rail, .book-toolbar,
  .book-footer, .book-canvas, .line-context-strip,
  .segmented, .pedigree-picker .branch-option) *,
body a:is(.button, .price-cta, .header-cta, .presentation-page-link, .back-link),
body a:is(.button, .price-cta, .header-cta, .presentation-page-link, .back-link) *,
body :is(img, svg, canvas, video),
body :is(img, svg, canvas, video) * {
  -webkit-user-select: none !important;
  user-select: none !important;
}
/* Text inside paragraphs, headings, labels and historical descriptions stays copyable.
   Link text embedded in copy is selectable, unlike actual CTA buttons. */
body :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="button"]):not([type="submit"]):not([type="reset"]),
  textarea, [contenteditable="true"], [contenteditable="plaintext-only"]) {
  -webkit-user-select: text !important;
  user-select: text !important;
  cursor: text;
}
body :is(button, [role="button"], [role="tab"], [role="switch"],
  input[type="checkbox"], input[type="radio"], input[type="range"], select) { cursor: pointer; }
/* High-specificity legacy rules suppressed first-screen headings despite V26. */
body .screen-heading :is(h1,h2,h3,.eyebrow),
body .form-section .section-heading :is(h2,h3),
body .form-section :is(.field__label, .field-label, legend),
body .legal-section :is(h1,h2,h3,h4) {
  -webkit-user-select: text !important;
  user-select: text !important;
}
