:root {
  color: #18211f;
  background: #f7f4ed;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  padding: 28px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(24, 33, 31, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(24, 33, 31, 0.05) 1px, transparent 1px), #f7f4ed;
  background-size: 36px 36px;
}

.data-state {
  display: grid;
  min-height: calc(100vh - 56px);
  place-content: center;
  text-align: center;
}

.data-state h1 {
  font-size: clamp(1.7rem, 3vw, 3.1rem);
}

.data-state p {
  max-width: 560px;
  color: #6e5d44;
}

.login-screen {
  display: grid;
  min-height: calc(100vh - 56px);
  place-items: center;
}

.login-card {
  width: min(100%, 440px);
  padding: 36px 32px 32px;
  border: 1px solid #d5cab8;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 20px 50px rgba(48, 38, 22, 0.08);
}

.login-card h1 {
  font-size: clamp(2.2rem, 4vw, 3.4rem);
}

.login-card p {
  max-width: none;
  margin-bottom: 0;
  color: #6e5d44;
}

.login-field {
  display: grid;
  gap: 8px;
  margin: 24px 0 12px;
  color: #243a35;
  font-size: 0.92rem;
  font-weight: 700;
}

.login-field input {
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid #d5cab8;
  border-radius: 8px;
  background: #fffdf8;
  color: #18211f;
  font-weight: 400;
}

.login-field input:focus {
  outline: 2px solid #243a35;
  outline-offset: 2px;
}

.login-error {
  margin: 0 0 16px;
  color: #8a3d2f;
}

.login-submit,
.logout-button {
  min-height: 46px;
  border: 1px solid #243a35;
  border-radius: 8px;
  font-weight: 700;
}

.login-submit {
  width: 100%;
  background: #243a35;
  color: #fffdf8;
}

.login-submit:disabled {
  cursor: default;
  opacity: 0.65;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logout-button {
  padding: 0 14px;
  background: #fffdf8;
  color: #243a35;
  white-space: nowrap;
}

.topbar {
  display: flex;
  flex: 0 0 auto;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin: 0 auto 18px;
  max-width: 1400px;
}

.topbar h1 {
  font-size: clamp(1.55rem, 2vw, 2.15rem);
  line-height: 1.1;
}

.eyebrow {
  margin: 0 0 6px;
  color: #6e5d44;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: #243a35;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(2rem, 4vw, 4.5rem);
  font-weight: 600;
  letter-spacing: 0;
}

.search-box {
  display: flex;
  align-items: center;
  width: min(100%, 420px);
  min-height: 46px;
  gap: 10px;
  padding: 0 14px;
  border: 1px solid #d5cab8;
  border-radius: 8px;
  background: #fffdf8;
  color: #6e5d44;
  box-shadow: 0 14px 34px rgba(48, 38, 22, 0.08);
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: #18211f;
}

.search-results {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 1400px;
  margin: 0 auto 18px;
}

.search-results button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid #d5cab8;
  border-radius: 999px;
  background: #fffdf8;
  color: #243a35;
}

.workspace {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: stretch;
  min-height: 0;
  margin: 0 auto;
}

.tree-view {
  min-height: 0;
  overflow: auto;
  padding: 24px;
  border: 1px solid #d5cab8;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.78);
  box-shadow: 0 20px 50px rgba(48, 38, 22, 0.08);
}

.tree-forest {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 56px;
  min-width: max-content;
}

.tree-branch {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: max-content;
}

.tree-node {
  position: relative;
  display: flex;
  justify-content: center;
}

.tree-branch:has(> .children-branches) > .tree-node::after {
  position: absolute;
  bottom: -32px;
  left: 50%;
  width: 2px;
  height: 32px;
  background: #98b7aa;
  content: '';
  transform: translateX(-50%);
}

.couple-group {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.partner-link {
  width: 30px;
  height: 2px;
  background: #98b7aa;
}

.tree-zoom {
  position: relative;
}

.tree-zoom-bar {
  position: sticky;
  top: 12px;
  left: 12px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  margin-bottom: -46px;
}

.tree-zoom-button,
.tree-zoom-level {
  min-height: 38px;
  border: 1px solid #d5cab8;
  border-radius: 8px;
  background: #fffdf8;
  color: #243a35;
  box-shadow: 0 10px 24px rgba(48, 38, 22, 0.08);
}

.tree-zoom-button {
  display: grid;
  width: 38px;
  place-items: center;
  padding: 0;
}

.tree-zoom-button:disabled {
  cursor: default;
  opacity: 0.45;
}

.tree-zoom-level {
  min-width: 64px;
  padding: 0 10px;
  font-size: 0.86rem;
  font-weight: 700;
}

.lineage-tree {
  position: absolute;
  top: 0;
  left: 0;
  width: 3160px;
  height: 2210px;
}

.tree-connector-svg {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 3160px;
  height: 2210px;
  overflow: visible;
  pointer-events: none;
}

.tree-connector-path {
  fill: none;
  stroke: #98b7aa;
  stroke-linecap: square;
  stroke-linejoin: round;
  stroke-width: 2;
}

.tree-connector-path--hypothesis {
  stroke: #96794c;
  stroke-dasharray: 7 5;
}

.tree-card-node {
  position: absolute;
  z-index: 1;
}

.ancestor-parent-row,
.ancestor-child-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(390px, 1fr));
  justify-items: center;
  column-gap: 70px;
  width: 100%;
}

.ancestor-parent-row {
  align-items: end;
}

.parent-unit,
.ancestor-child-slot {
  position: relative;
  display: flex;
  justify-content: center;
}

.parent-unit::after {
  position: absolute;
  bottom: -42px;
  left: 50%;
  width: 2px;
  height: 42px;
  background: #98b7aa;
  content: '';
  transform: translateX(-50%);
}

.ancestor-child-row {
  position: relative;
  align-items: center;
  margin-top: 42px;
}

.ancestor-child-slot::before {
  position: absolute;
  top: -42px;
  left: 50%;
  width: 2px;
  height: 42px;
  background: #98b7aa;
  content: '';
  transform: translateX(-50%);
}

.ancestor-spouse-link {
  position: absolute;
  top: 50%;
  left: calc(50% - 15px);
  width: 30px;
  transform: translateY(-50%);
}

.direct-descendants {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 66px;
}

.direct-descendants::before {
  position: absolute;
  top: -66px;
  left: 50%;
  width: 2px;
  height: 66px;
  background: #98b7aa;
  content: '';
  transform: translateX(-50%);
}

.descendant-row {
  position: relative;
  display: flex;
  justify-content: center;
}

.descendant-row + .descendant-row,
.descendant-row + .maternal-branch,
.maternal-branch + .descendant-row {
  margin-top: 66px;
}

.descendant-row + .descendant-row::before {
  position: absolute;
  top: -66px;
  left: 50%;
  width: 2px;
  height: 66px;
  background: #98b7aa;
  content: '';
  transform: translateX(-50%);
}

.maternal-branch {
  position: relative;
  align-self: stretch;
  height: 210px;
}

.maternal-parent {
  position: absolute;
  top: 0;
  left: calc(50% + 135px);
  transform: translateX(-50%);
}

.maternal-branch::before {
  position: absolute;
  top: -66px;
  left: calc(50% - 105px);
  width: 2px;
  height: 342px;
  background: #98b7aa;
  content: '';
  transform: translateX(-50%);
}

.maternal-parent::after {
  position: absolute;
  bottom: -66px;
  left: 50%;
  width: 2px;
  height: 66px;
  background: #98b7aa;
  content: '';
  transform: translateX(-50%);
}

.maternal-branch + .descendant-row::before {
  left: calc(50% - 105px);
  top: -66px;
  height: 66px;
  display: none;
}

.maternal-branch + .descendant-row.parent-target-first::after {
  display: none;
}

.descendant-row.parent-target-first::before {
  left: calc(50% - 105px);
  top: -33px;
  height: 33px;
}

.descendant-row.parent-target-first::after {
  position: absolute;
  top: -33px;
  left: calc(50% - 105px);
  width: 105px;
  height: 2px;
  background: #98b7aa;
  content: '';
}

.descendant-row.parent-source-couple::after {
  position: absolute;
  z-index: 0;
  top: 50%;
  left: 50%;
  width: 2px;
  height: calc(50% + 33px);
  background: #98b7aa;
  content: '';
  transform: translateX(-50%);
}

.children-branches {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 28px;
  padding-top: 64px;
}

.children-branches::before {
  position: absolute;
  top: 32px;
  right: 90px;
  left: 90px;
  height: 2px;
  background: #98b7aa;
  content: '';
}

.child-branch {
  position: relative;
}

.child-branch::before {
  position: absolute;
  top: -32px;
  left: 50%;
  width: 2px;
  height: 32px;
  background: #98b7aa;
  content: '';
  transform: translateX(-50%);
}

.children-branches .child-branch:only-child::after {
  position: absolute;
  top: -32px;
  left: 50%;
  width: 2px;
  height: 2px;
  background: #98b7aa;
  content: '';
}

.child-branch--hypothesis::before {
  background: repeating-linear-gradient(to bottom, #96794c 0 6px, transparent 6px 11px);
}

.person-card {
  display: grid;
  justify-items: center;
  width: 180px;
  min-height: 210px;
  padding: 18px 14px;
  border: 1px solid #d5cab8;
  border-radius: 8px;
  background: #fffdf8;
  color: #18211f;
  text-align: center;
  box-shadow: 0 14px 28px rgba(48, 38, 22, 0.08);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.person-card:hover,
.person-card.active {
  border-color: #2f6f5e;
  box-shadow: 0 16px 34px rgba(47, 111, 94, 0.18);
  transform: translateY(-2px);
}

.person-card--hypothesis {
  padding-top: 12px;
  padding-bottom: 12px;
  border: 2px dashed #96794c;
}

.person-card--hypothesis .portrait-medium {
  margin-bottom: 8px;
}

.person-hypothesis {
  margin-top: 6px;
  color: #765b32;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.25;
}

.hypothesis-note {
  padding-left: 12px;
  border-left: 2px dashed #96794c;
  color: #765b32;
  font-size: 0.85rem;
  line-height: 1.5;
}

.relation-hypothesis {
  color: #765b32;
  font-size: 0.82rem;
}

.portrait {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border: 2px solid #e8dfcf;
  border-radius: 50%;
  background: #d8eadf;
  color: #243a35;
  font-weight: 800;
  object-fit: cover;
}

.portrait-medium {
  width: 78px;
  height: 78px;
  margin-bottom: 14px;
  font-size: 1.15rem;
}

.portrait-large {
  width: 92px;
  height: 92px;
  font-size: 1.35rem;
}

.person-name {
  display: block;
  min-height: 44px;
  color: #243a35;
  font-weight: 800;
  line-height: 1.22;
}

.person-meta,
.person-years,
.subtle,
.empty-state {
  color: #756a5a;
  font-size: 0.88rem;
  line-height: 1.45;
}

.person-years {
  margin-top: 8px;
}

.details-panel {
  min-height: 0;
  padding: 20px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid #c7d7cf;
  border-radius: 8px;
  background: #f3fbf7;
  box-shadow: 0 20px 50px rgba(36, 58, 53, 0.12);
}

.details-heading {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
}

.details-heading h2 {
  margin-bottom: 4px;
  color: #243a35;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.75rem;
  line-height: 1.05;
  letter-spacing: 0;
}

.details-grid {
  display: grid;
  gap: 10px;
}

.field {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 2px 10px;
  padding: 12px;
  border: 1px solid #c7d7cf;
  border-radius: 8px;
  background: #fffdf8;
}

.field svg {
  grid-row: span 2;
  margin-top: 2px;
  color: #2f6f5e;
}

.field span {
  color: #6e5d44;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.field strong {
  color: #18211f;
  font-size: 0.95rem;
  line-height: 1.4;
}

.notes {
  margin: 16px 0 0;
  padding: 14px 0;
  border-top: 1px solid #c7d7cf;
  border-bottom: 1px solid #c7d7cf;
  color: #3d4a45;
  line-height: 1.55;
  word-break: break-word;
}

.markdown-text {
  display: grid;
  gap: 10px;
}

.markdown-text p,
.markdown-text ul,
.markdown-text ol {
  margin: 0;
}

.markdown-text ul,
.markdown-text ol {
  padding-left: 20px;
}

.markdown-text li + li {
  margin-top: 4px;
}

.photo-gallery {
  margin-top: 18px;
}

.photo-gallery h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: #243a35;
  font-size: 0.95rem;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.photo-thumb {
  overflow: hidden;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid #c7d7cf;
  border-radius: 8px;
  background: #fffdf8;
}

.photo-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 160ms ease;
}

.photo-thumb:hover img {
  transform: scale(1.04);
}

.photo-lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(18, 24, 22, 0.86);
}

.lightbox-close {
  position: fixed;
  top: 18px;
  right: 18px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 253, 248, 0.35);
  border-radius: 50%;
  background: rgba(255, 253, 248, 0.12);
  color: #fffdf8;
}

.lightbox-nav {
  position: fixed;
  top: 50%;
  z-index: 21;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 253, 248, 0.35);
  border-radius: 50%;
  background: rgba(255, 253, 248, 0.12);
  color: #fffdf8;
  transform: translateY(-50%);
}

.lightbox-nav:hover,
.lightbox-close:hover {
  background: rgba(255, 253, 248, 0.2);
}

.lightbox-nav-previous {
  left: 18px;
}

.lightbox-nav-next {
  right: 18px;
}

.lightbox-content {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  width: min(100%, 1100px);
  height: 100%;
  min-height: 0;
  max-width: min(100%, 1100px);
  max-height: 100%;
  margin: 0;
}

.lightbox-content img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

.lightbox-content figcaption {
  display: grid;
  max-height: 35vh;
  overflow: auto;
  gap: 2px;
  color: #fffdf8;
  text-align: center;
}

.lightbox-content figcaption span {
  color: rgba(255, 253, 248, 0.78);
  font-size: 0.92rem;
}

.lightbox-related-photos {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  margin-top: 6px;
}

.lightbox-related-photos a {
  color: #fffdf8;
  text-underline-offset: 3px;
}

.lightbox-related-photos a:focus-visible {
  outline: 2px solid #fffdf8;
  outline-offset: 3px;
}

@media (max-width: 680px) {
  .photo-lightbox {
    padding: 72px 20px 80px;
  }

  .lightbox-nav {
    top: auto;
    bottom: 18px;
    width: 44px;
    height: 44px;
    transform: none;
  }

  .lightbox-nav-previous {
    left: calc(50% - 58px);
  }

  .lightbox-nav-next {
    right: calc(50% - 58px);
  }

  .lightbox-content img {
    max-height: 100%;
  }
}

.relation-section {
  margin-top: 18px;
}

.relation-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  color: #243a35;
  font-size: 0.95rem;
}

.relation-section ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

.relation-section li {
  color: #3d4a45;
}

@media (max-width: 940px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    padding: 18px;
    overflow: visible;
  }

  .workspace {
    flex: none;
  }

  .tree-view {
    min-height: auto;
    overflow-x: auto;
    overflow-y: visible;
  }

  .details-panel {
    overflow: visible;
  }

  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    align-items: stretch;
  }

  .topbar-tools,
  .search-box {
    width: 100%;
  }

  .topbar-tools {
    display: grid;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 12px;
  }

  .tree-view,
  .details-panel {
    padding: 14px;
  }

  .children-branches {
    gap: 18px;
  }

  .tree-forest {
    gap: 28px;
  }

  .ancestor-parent-row,
  .ancestor-child-row {
    grid-template-columns: repeat(2, minmax(320px, 1fr));
    column-gap: 32px;
  }

  .person-card {
    width: 154px;
  }
}
