:root {
    --bg: #f3efe7;
    --panel: rgba(255, 251, 244, 0.92);
    --ink: #2e2a27;
    --muted: #6f655e;
    --accent: #1c6e6b;
    --line-parent: #2d5f8b;
    --line-parent-0: #2d5f8b;
    --line-parent-1: #1f8a70;
    --line-parent-2: #c06a3d;
    --line-parent-3: #7663b8;
    --line-parent-4: #b5486a;
    --line-parent-5: #4d7c2f;
    --line-parent-6: #8b6f22;
    --line-parent-7: #27849a;
    --line-spouse: #8a4d5d;
    --border: #d7cfc5;
    --shadow: 0 20px 45px rgba(36, 29, 21, 0.08);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, #fffdf8 0, #fffdf8 15%, transparent 45%),
        linear-gradient(180deg, #f8f4ec 0%, #efe7d9 100%);
    color: var(--ink);
    min-height: 100dvh;
    display: grid;
    grid-template-rows: auto 1fr;
    overflow: hidden;
}

.topbar {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) auto;
    gap: 8px 16px;
    align-items: end;
    padding: 8px 20px 6px;
}

.eyebrow {
    display: none;
    margin: 0 0 6px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 12px;
    font-weight: 700;
}

.auth-status {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.2;
}

.family-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 0;
}

.family-name {
    margin: 0;
    color: var(--accent);
    font-size: 17px;
    font-weight: 600;
}

h1 {
    display: none;
    margin: 0;
    font-size: 32px;
}

.topbar-actions,
.modal-actions,
.detail-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.topbar-actions {
    justify-content: flex-end;
    align-items: end;
}

.topbar .ghost-button,
.topbar .primary-button {
    padding: 7px 12px;
    font-size: 14px;
    line-height: 1.1;
}

.topbar .ghost-button:disabled {
    display: none;
}

.family-switcher,
.language-switcher {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
}

.language-switcher {
    flex: 0 0 220px;
    width: 220px;
    align-items: stretch;
    gap: 4px;
}

.language-switcher > span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 18px;
    width: 100%;
    height: 18px;
    line-height: 18px;
    overflow: hidden;
    white-space: nowrap;
}

.family-switcher select,
.language-switcher select {
    min-width: 150px;
    min-height: 32px;
}

.language-switcher select {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
}

.app-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 12px;
    padding: 0 12px 12px;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.canvas-panel,
.side-panel {
    background: var(--panel);
    border: 1px solid rgba(215, 207, 197, 0.9);
    border-radius: 24px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    min-height: 0;
}

.canvas-panel {
    display: flex;
    flex-direction: column;
    padding: 6px;
    overflow: hidden;
    position: relative;
}

.legend {
    display: none;
    gap: 18px;
    padding: 4px 6px 16px;
    color: var(--muted);
    font-size: 14px;
}

.line {
    display: inline-block;
    width: 28px;
    height: 0;
    margin-right: 6px;
    border-top: 3px solid currentColor;
    vertical-align: middle;
}

.spouse-line {
    color: var(--line-spouse);
}

.parent-line {
    color: var(--line-parent);
}

.tree-scroll {
    overflow-y: auto;
    overflow-x: scroll;
    flex: 1;
    min-height: 0;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.45), rgba(248, 241, 229, 0.65));
    cursor: grab;
    user-select: none;
}

.tree-scroll.panning,
.tree-scroll.panning-ready:active {
    cursor: grabbing;
}

.tree-canvas {
    position: relative;
    min-width: 900px;
    min-height: 700px;
}

.tree-generations {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.tree-generation-labels {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 4;
}

.tree-generation-band {
    position: absolute;
    left: 8px;
    border-radius: 18px;
    background: var(--band-fill, rgba(255, 255, 255, 0.52));
    border: 1px solid var(--band-border, rgba(106, 125, 140, 0.16));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.tree-generation-label {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    padding: 8px 6px;
    border-radius: 14px;
    background: rgba(255, 253, 249, 0.88);
    border: 1px solid rgba(115, 107, 96, 0.12);
    box-shadow: 0 6px 12px rgba(71, 57, 41, 0.08);
    text-align: center;
    z-index: 3;
    pointer-events: auto;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.tree-generation-label:hover,
.tree-generation-label:focus-visible {
    background: rgba(255, 255, 255, 0.96);
    border-color: rgba(40, 118, 125, 0.36);
    box-shadow: 0 8px 16px rgba(50, 86, 90, 0.14);
    outline: none;
}

.tree-generation-label.active {
    background: rgba(35, 110, 118, 0.94);
    border-color: rgba(22, 80, 86, 0.4);
    box-shadow: 0 9px 18px rgba(24, 80, 86, 0.22);
}

.tree-generation-number {
    display: block;
    font-size: 18px;
    line-height: 1;
    font-weight: 700;
    color: var(--accent);
}

.tree-generation-label.active .tree-generation-number {
    color: #ffffff;
}

.tree-generation-text {
    display: block;
    margin-top: 3px;
    font-size: 9px;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.tree-generation-label.active .tree-generation-text {
    color: rgba(255, 255, 255, 0.82);
}

.tree-lines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    z-index: 1;
}

.tree-drop-area {
    position: absolute;
    pointer-events: none;
    z-index: 2;
    border: 2px dashed rgba(49, 142, 96, 0.76);
    border-radius: 12px;
    background: rgba(49, 142, 96, 0.08);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.72);
}

#tree-nodes {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
}

.person-card {
    position: absolute;
    width: 64px;
    min-height: 82px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #ffffff;
    box-shadow:
        0 8px 16px rgba(51, 38, 20, 0.08),
        0 0 0 0 var(--gender-shadow, transparent);
    padding: 2px 2px 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: grab;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
}

.person-card.gender-male {
    --gender-shadow: rgba(71, 145, 209, 0.24);
    border-color: rgba(95, 153, 205, 0.34);
    box-shadow:
        0 8px 16px rgba(51, 38, 20, 0.08),
        0 0 0 3px var(--gender-shadow);
}

.person-card.gender-female {
    --gender-shadow: rgba(215, 102, 145, 0.24);
    border-color: rgba(213, 121, 156, 0.34);
    box-shadow:
        0 8px 16px rgba(51, 38, 20, 0.08),
        0 0 0 3px var(--gender-shadow);
}

.person-card.gender-unknown {
    background: #ffffff;
    --gender-shadow: transparent;
}

.birth-order-badge {
    position: absolute;
    top: -8px;
    left: -8px;
    min-width: 25px;
    height: 25px;
    padding: 0 7px;
    border: 1px solid color-mix(in srgb, var(--birth-order-border, rgba(106, 125, 140, 0.18)) 58%, rgba(255, 255, 255, 0.78));
    border-radius: 999px;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.2) 42%, rgba(255, 255, 255, 0.58)),
        var(--birth-order-fill, rgba(227, 239, 233, 0.78));
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.88),
        inset 0 -1px 4px rgba(87, 135, 142, 0.14),
        0 3px 8px rgba(55, 78, 86, 0.14);
    color: rgba(39, 69, 73, 0.88);
    font-size: 15px;
    font-weight: 800;
    line-height: 23px;
    text-align: center;
    letter-spacing: 0;
    backdrop-filter: blur(5px) saturate(1.15);
    z-index: 1;
}

.person-card:hover,
.person-card.active {
    transform: translateY(-2px);
    box-shadow:
        0 10px 20px rgba(34, 49, 77, 0.16),
        0 0 0 3px var(--gender-shadow, transparent);
}

.person-card.connection-relative {
    animation: connection-card-pulse 3s ease-in-out infinite;
}

.person-card.connection-self {
    border-color: rgba(0, 139, 111, 0.95);
    box-shadow: 0 10px 20px rgba(34, 49, 77, 0.16), 0 0 0 4px rgba(0, 139, 111, 0.28);
}

.person-card.connection-target {
    border-color: rgba(86, 121, 210, 0.95);
    box-shadow: 0 10px 20px rgba(34, 49, 77, 0.16), 0 0 0 4px rgba(86, 121, 210, 0.26);
}

.connection-label {
    display: block;
    margin-top: 2px;
    padding: 1px 5px;
    border-radius: 999px;
    background: rgba(189, 94, 40, 0.13);
    color: #8a3f1d;
    font-size: 10px;
    font-weight: 800;
    line-height: 1.25;
    max-width: 58px;
    overflow: hidden;
    overflow-wrap: anywhere;
    white-space: normal;
    animation: connection-label-pulse 2.8s ease-in-out infinite;
}

.person-card.dragging {
    cursor: grabbing;
    box-shadow: 0 16px 28px rgba(34, 49, 77, 0.22);
    transition: none;
    z-index: 20;
}

.person-card.dragging.drop-ok {
    outline: 3px solid rgba(49, 142, 96, 0.58);
    box-shadow: 0 16px 28px rgba(34, 49, 77, 0.2), 0 0 0 7px rgba(49, 142, 96, 0.12);
}

.person-card.dragging.drop-stop {
    cursor: no-drop;
    outline: 3px solid rgba(188, 69, 69, 0.58);
    box-shadow: 0 16px 28px rgba(34, 49, 77, 0.2), 0 0 0 7px rgba(188, 69, 69, 0.12);
}

.person-card.dragging.drop-ok::after,
.person-card.dragging.drop-stop::after {
    position: absolute;
    right: -10px;
    bottom: -10px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 10px;
    font-weight: 900;
    line-height: 1;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 5px 12px rgba(34, 49, 77, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.88);
}

.person-card.dragging.drop-ok::after {
    content: attr(data-drop-status);
    border: 2px solid rgba(49, 142, 96, 0.7);
    color: #256c49;
}

.person-card.dragging.drop-stop::after {
    content: "";
    border: 2px solid rgba(188, 69, 69, 0.78);
}

.person-card.dragging.drop-stop::before {
    content: "";
    position: absolute;
    right: -4px;
    bottom: 1px;
    width: 19px;
    height: 3px;
    border-radius: 999px;
    background: rgba(188, 69, 69, 0.82);
    transform: rotate(-42deg);
    z-index: 21;
}

.person-hover-tooltip {
    position: fixed;
    left: 0;
    top: 0;
    width: min(220px, calc(100vw - 16px));
    max-height: min(360px, calc(100vh - 16px));
    overflow: auto;
    padding: 12px;
    border: 1px solid rgba(38, 62, 68, 0.18);
    border-radius: 8px;
    background: rgba(255, 253, 249, 0.98);
    box-shadow: 0 14px 30px rgba(34, 49, 77, 0.22);
    color: var(--text);
    font-size: 12px;
    line-height: 1.35;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 100ms ease, transform 100ms ease;
    z-index: 1200;
}

.person-hover-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.person-tooltip-name {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 8px;
}

.person-tooltip-counts,
.person-tooltip-descendants {
    display: grid;
    gap: 6px;
    margin: 10px 0 0;
}

.person-tooltip-counts div,
.person-tooltip-descendants div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 8px;
    border: 1px solid rgba(115, 107, 96, 0.14);
    border-radius: 8px;
    background: rgba(246, 242, 234, 0.84);
}

.person-tooltip-counts dt,
.person-tooltip-descendants dt {
    margin: 0;
    color: var(--muted);
    font-size: 10px;
}

.person-tooltip-counts dd,
.person-tooltip-descendants dd {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--accent);
}

.person-tooltip-section {
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.person-tooltip-stories {
    margin: 0;
    padding-left: 16px;
}

.person-tooltip-stories li + li {
    margin-top: 6px;
}

.person-tooltip-stories strong,
.person-tooltip-stories span {
    display: block;
}

.person-tooltip-stories span {
    margin-top: 2px;
    color: var(--muted);
}

.photo-wrap {
    width: 60px;
    height: 60px;
    position: relative;
}

.person-photo,
.photo-placeholder {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
}

.photo-placeholder {
    background: linear-gradient(135deg, #bed8d5, #e6d2ad);
}

.hidden {
    display: none;
}

.person-text {
    text-align: center;
    width: 100%;
}

.person-name {
    display: block;
    font-size: 10px;
    line-height: 1.1;
    font-weight: 600;
}

.side-panel {
    padding: 20px;
    overflow: auto;
}

.details-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.details-card.empty {
    color: var(--muted);
}

.common-documents h2 {
    margin: 0 0 8px;
}

.common-document-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 14px;
}

.common-document-card {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px;
    border: 1px solid rgba(215, 207, 197, 0.9);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.78);
    color: var(--ink);
    font: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.common-document-card img {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    object-fit: cover;
    border: 1px solid var(--border);
}

.common-document-card span:last-child {
    overflow-wrap: anywhere;
}

.editable-shared-item {
    position: relative;
    min-width: 0;
}

.editable-shared-item .gallery-item,
.editable-shared-item .story-card,
.editable-shared-item .common-document-card {
    width: 100%;
}

.shared-delete-button {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 2;
    border: 1px solid rgba(160, 68, 68, 0.28);
    border-radius: 999px;
    background: rgba(255, 250, 247, 0.96);
    color: #9a3d3d;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    padding: 5px 9px;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(71, 43, 34, 0.12);
}

.shared-delete-button:hover {
    background: #fff0eb;
}

.file-icon {
    display: inline-grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: 12px;
    background: rgba(28, 110, 107, 0.11);
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
}

.detail-photo {
    width: 100%;
    max-width: 180px;
    border-radius: 22px;
    object-fit: cover;
    border: 1px solid var(--border);
}

.detail-meta {
    color: var(--muted);
    margin: 0;
}

.ghost-button,
.primary-button {
    border-radius: 999px;
    padding: 11px 16px;
    border: 1px solid var(--border);
    background: white;
    cursor: pointer;
    font: inherit;
}

.auth-link {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.ghost-button:disabled,
.primary-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.primary-button {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.danger-button {
    color: #9b2f2f;
    border-color: rgba(155, 47, 47, 0.35);
}

.modal {
    border: none;
    border-radius: 24px;
    padding: 0;
    box-shadow: 0 22px 44px rgba(0, 0, 0, 0.18);
}

.modal::backdrop {
    background: rgba(25, 16, 7, 0.4);
}

.modal-form {
    min-width: min(460px, calc(100vw - 32px));
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 24px;
    background: #fffdf8;
}

.modal-form[data-busy="true"] {
    cursor: progress;
}

.modal-form h2 {
    margin: 0 0 8px;
}

.admin-directory-form {
    width: min(760px, calc(100vw - 32px));
    max-height: min(760px, calc(100vh - 32px));
}

.admin-directory-content {
    display: grid;
    gap: 10px;
    overflow: auto;
    padding-right: 4px;
}

.admin-family-row {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    background: white;
}

.admin-family-row h3 {
    margin: 0 0 8px;
    font-size: 16px;
}

.admin-family-row p {
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr);
    gap: 10px;
    margin: 6px 0;
    color: var(--muted);
    font-size: 14px;
}

.admin-family-row strong {
    color: var(--ink);
}

.viewer-modal {
    width: min(96vw, 1320px);
    max-width: calc(100vw - 48px);
    height: min(92vh, 990px);
    max-height: calc(100vh - 48px);
    resize: none;
    overflow: hidden;
    background: transparent;
}

body.viewer-popup-mode {
    display: block;
    min-height: 100vh;
    background: #aaa59d;
}

.viewer-popup-mode .topbar,
.viewer-popup-mode .app-shell {
    display: none;
}

.viewer-popup-mode .viewer-modal {
    width: min(98vw, 1680px);
    max-width: calc(100vw - 16px);
    height: min(96vh, 1180px);
    max-height: calc(100vh - 16px);
    border-radius: 26px;
    box-shadow: none;
}

.viewer-popup-mode .viewer-image {
    border-radius: 24px;
}

.viewer-popup-mode .viewer-stage {
    border-radius: 24px;
    background: transparent;
}

.viewer-shell {
    height: 100%;
    min-height: 100%;
}

.viewer-main {
    display: grid;
    grid-template-columns: 1fr;
    height: 100%;
}

.viewer-overlay-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 4;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    color: #f6efe4;
    background: rgba(12, 9, 7, 0.48);
    backdrop-filter: blur(8px);
}

.viewer-overlay-controls .ghost-button {
    padding: 5px 8px;
    font-size: 12px;
    border-radius: 8px;
}

.viewer-overlay-controls .ghost-button.active {
    border-color: rgba(255, 227, 179, 0.65);
    background: rgba(255, 227, 179, 0.16);
    color: #fff2d0;
}

.viewer-stage {
    position: relative;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    cursor: crosshair;
    background: #15110d;
    border-radius: 8px;
}

.viewer-stage.labeling {
    cursor: crosshair;
}

.viewer-stage.dragging {
    cursor: grabbing;
}

.viewer-image {
    position: absolute;
    top: 50%;
    left: 50%;
    max-width: none;
    max-height: none;
    transform-origin: center center;
    user-select: none;
    -webkit-user-drag: none;
    box-shadow: none;
    border-radius: 8px;
}

.viewer-label-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.viewer-face-label {
    position: absolute;
    z-index: 3;
    transform: translate(-50%, -100%);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 999px;
    background: rgba(24, 18, 12, 0.82);
    color: #fffaf0;
    padding: 6px 10px;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.32);
}

.viewer-face-label.remove-mode {
    border-color: rgba(255, 205, 205, 0.9);
    background: rgba(120, 28, 28, 0.86);
}

.viewer-corner-label {
    position: absolute;
    z-index: 3;
    max-width: min(42%, 360px);
    transform: translateY(-100%);
    border: 1px solid rgba(255, 255, 255, 0.68);
    border-radius: 8px;
    background: rgba(18, 14, 10, 0.78);
    color: #fffaf0;
    padding: 7px 10px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.25;
    overflow-wrap: anywhere;
    pointer-events: none;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.32);
}

.viewer-place-label {
    transform: translate(-100%, -100%);
}

.viewer-date-label {
    transform: translateY(-100%);
}

.viewer-person-search,
.viewer-label-toggle {
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #f6efe4;
    font: inherit;
    padding: 5px 8px;
}

.viewer-person-search {
    width: min(280px, 72vw);
    background: #fffdf8;
    color: var(--ink);
    border-color: rgba(30, 26, 21, 0.16);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

.viewer-person-search::placeholder {
    color: rgba(71, 66, 59, 0.68);
}

.viewer-label-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    white-space: nowrap;
    border-radius: 8px;
}

.viewer-label-editor {
    position: absolute;
    z-index: 5;
    transform: translate(-50%, -50%);
}

.viewer-label-editor::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 12px;
    height: 12px;
    transform: translate(-50%, -50%);
    border: 2px solid rgba(255, 255, 255, 0.88);
    border-radius: 50%;
    pointer-events: none;
}

.viewer-label-editor .viewer-person-search {
    transform: translateY(-34px);
}

.viewer-label-editor.ready .viewer-person-search {
    outline: 2px solid rgba(75, 151, 129, 0.72);
}

.viewer-person-results {
    position: absolute;
    left: 50%;
    top: 8px;
    width: min(280px, 72vw);
    max-height: 220px;
    overflow: auto;
    transform: translateX(-50%);
    border: 1px solid rgba(30, 26, 21, 0.14);
    border-radius: 8px;
    background: #fffdf8;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.32);
}

.viewer-person-results button {
    display: grid;
    gap: 2px;
    width: 100%;
    border: 0;
    border-bottom: 1px solid rgba(30, 26, 21, 0.08);
    background: transparent;
    color: var(--ink);
    padding: 7px 10px;
    text-align: left;
    cursor: pointer;
    font: inherit;
}

.viewer-person-results button:hover {
    background: rgba(28, 110, 107, 0.09);
}

.viewer-person-results small {
    color: var(--muted);
    font-size: 12px;
}

.viewer-metadata-editor {
    position: absolute;
    right: 10px;
    bottom: 10px;
    z-index: 5;
    width: min(360px, calc(100% - 20px));
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    background: rgba(255, 253, 248, 0.97);
    color: var(--ink);
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.32);
}

.viewer-metadata-editor.hidden {
    display: none;
}

.viewer-metadata-editor label {
    display: grid;
    gap: 5px;
    font-size: 13px;
    font-weight: 700;
}

.viewer-metadata-editor input {
    width: 100%;
    border: 1px solid rgba(30, 26, 21, 0.16);
    border-radius: 8px;
    padding: 8px 10px;
    font: inherit;
}

.viewer-metadata-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.viewer-metadata-actions .primary-button,
.viewer-metadata-actions .ghost-button {
    padding: 7px 10px;
    font-size: 12px;
}

.photo-results-modal {
    width: min(92vw, 980px);
    background: #fffdf8;
}

.photo-results-shell {
    min-height: min(78vh, 760px);
}

.photo-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
    padding: 18px;
}

.photo-result-card {
    display: grid;
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    padding: 8px;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
}

.photo-result-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 6px;
}

.photo-result-card span {
    overflow-wrap: anywhere;
    font-size: 13px;
}

.photo-cropper {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.photo-cropper-hint {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.photo-crop-stage {
    position: relative;
    width: min(100%, 320px);
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 24px;
    background:
        linear-gradient(45deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.04) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.04) 75%),
        #f6f0e7;
    background-size: 24px 24px;
    background-position: 0 0, 0 12px, 12px -12px, -12px 0;
    border: 1px solid var(--border);
    cursor: grab;
    touch-action: none;
}

.photo-crop-stage.dragging {
    cursor: grabbing;
}

.photo-crop-image {
    position: absolute;
    top: 50%;
    left: 50%;
    max-width: none;
    max-height: none;
    transform-origin: center center;
    user-select: none;
    -webkit-user-drag: none;
}

.photo-crop-frame {
    position: absolute;
    inset: 0;
    border: 2px solid rgba(255, 255, 255, 0.92);
    border-radius: 24px;
    box-shadow: 0 0 0 999px rgba(17, 14, 11, 0.22) inset;
    pointer-events: none;
}

label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-weight: 600;
}

input,
select,
textarea {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px 12px;
    font: inherit;
    background: white;
}

textarea {
    resize: vertical;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.gallery-grid img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 16px;
    border: 1px solid var(--border);
}

.gallery-item {
    padding: 0;
    border: none;
    background: transparent;
    cursor: zoom-in;
}

.clickable-section-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: var(--accent);
}

.clickable-section-label::after {
    content: "↗";
    font-size: 13px;
    line-height: 1;
}

.clickable-section-label:hover,
.clickable-section-label:focus-visible {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.context-menu {
    position: fixed;
    z-index: 1000;
    min-width: 220px;
    padding: 8px;
    border-radius: 18px;
    background: rgba(255, 252, 247, 0.98);
    border: 1px solid rgba(215, 207, 197, 0.95);
    box-shadow: 0 20px 40px rgba(22, 15, 7, 0.18);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.context-menu.hidden {
    display: none;
}

.context-menu button {
    border: none;
    background: transparent;
    border-radius: 12px;
    padding: 10px 12px;
    text-align: left;
    font: inherit;
    cursor: pointer;
    color: var(--ink);
    white-space: nowrap;
}

.context-menu button:hover {
    background: rgba(28, 110, 107, 0.09);
}

.story-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.story-card {
    padding: 12px 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(215, 207, 197, 0.9);
    text-align: left;
    cursor: pointer;
    width: 100%;
    font: inherit;
    transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.story-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(51, 38, 20, 0.08);
}

.story-card h3 {
    margin: 0 0 6px;
    font-size: 16px;
}

.story-card p {
    margin: 0;
    color: var(--muted);
    white-space: pre-wrap;
}

.story-card-meta {
    display: block;
    margin-top: 10px;
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
}

.common-story-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 7px 58px 7px 12px;
    border-radius: 12px;
}

.common-story-row:hover {
    transform: translateX(2px);
}

.common-story-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 700;
}

.common-story-row .story-card-meta {
    margin-top: 0;
    white-space: nowrap;
    font-size: 12px;
}

.story-viewer-modal {
    width: min(92vw, 820px);
    max-width: 820px;
    background: #fffdf8;
}

.story-viewer-shell {
    display: flex;
    flex-direction: column;
    max-height: min(86vh, 880px);
}

.story-viewer-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 18px 22px;
    border-bottom: 1px solid rgba(215, 207, 197, 0.9);
}

.story-viewer-body {
    padding: 22px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.story-viewer-body h2 {
    margin: 0;
}

.story-viewer-text {
    margin: 0;
    color: var(--muted);
    line-height: 1.7;
    white-space: pre-wrap;
}

.story-viewer-images {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.story-image-button {
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: white;
    overflow: hidden;
    cursor: zoom-in;
}

.story-image-button img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
}

.tree-line-spouse {
    stroke: var(--line-spouse);
    stroke-width: 4;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tree-line-parent {
    stroke: var(--line-parent);
    stroke-width: 3;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tree-line-connection-highlight {
    stroke: var(--line-parent-1);
    stroke-width: 9;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 2px 4px rgba(109, 63, 13, 0.34));
    pointer-events: none;
    animation: connection-line-pulse 2.8s ease-in-out infinite;
}

.tree-line-connection-highlight.spouse {
    stroke: #d5406f;
}

@keyframes connection-card-pulse {
    0%,
    100% {
        transform: translateY(0);
        filter: brightness(1);
    }

    50% {
        transform: translateY(-9px) scale(1.06);
        filter: brightness(1.14);
    }
}

@keyframes connection-label-pulse {
    0%,
    100% {
        background: rgba(189, 94, 40, 0.13);
    }

    50% {
        background: rgba(242, 181, 68, 0.3);
    }
}

@keyframes connection-line-pulse {
    0%,
    100% {
        opacity: 0.72;
        stroke-width: 8;
    }

    50% {
        opacity: 1;
        stroke-width: 12;
    }
}

.tree-line-parent.branch-color-0 {
    stroke: var(--line-parent-0);
}

.tree-line-parent.branch-color-1 {
    stroke: var(--line-parent-1);
}

.tree-line-parent.branch-color-2 {
    stroke: var(--line-parent-2);
}

.tree-line-parent.branch-color-3 {
    stroke: var(--line-parent-3);
}

.tree-line-parent.branch-color-4 {
    stroke: var(--line-parent-4);
}

.tree-line-parent.branch-color-5 {
    stroke: var(--line-parent-5);
}

.tree-line-parent.branch-color-6 {
    stroke: var(--line-parent-6);
}

.tree-line-parent.branch-color-7 {
    stroke: var(--line-parent-7);
}

.tree-line-bridge-mask {
    stroke: rgba(248, 244, 236, 0.98);
    stroke-width: 14;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

@media (max-width: 1100px) {
    body {
        overflow: auto;
        grid-template-rows: auto auto;
    }

    .app-shell {
        grid-template-columns: 1fr;
        height: auto;
        overflow: visible;
    }

    .tree-scroll {
        height: 70vh;
        flex: none;
    }
}
