:root {
  color-scheme: light;
  --bg: #f5f1e8;
  --paper: #fffaf0;
  --ink: #23211d;
  --muted: #6e695f;
  --line: #d8ccb9;
  --accent: #2f6f6d;
  --accent-soft: #d8e7e4;
  --coral: #c96f56;
  --gold: #d7a441;
  --violet: #7a6faf;
  --leaf: #71965d;
  --sky: #5f8fb9;
  --warn: #9b5c22;
  --shadow: 0 14px 32px rgba(50, 43, 32, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(201, 111, 86, 0.22), transparent 28%),
    radial-gradient(circle at 80% 6%, rgba(95, 143, 185, 0.18), transparent 30%),
    radial-gradient(circle at 96% 82%, rgba(215, 164, 65, 0.18), transparent 28%),
    linear-gradient(120deg, #fbf3e3 0%, var(--bg) 42%, #e8f3ef 100%);
  font-family: "Segoe UI", system-ui, sans-serif;
}

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  border: 1px solid rgba(47, 111, 109, 0.18);
  border-radius: 8px;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(255, 250, 240, 0.92), rgba(216, 231, 228, 0.7)),
    var(--paper);
  box-shadow: var(--shadow);
}

.header-tools {
  display: flex;
  gap: 16px;
  align-items: center;
}

.family-crest {
  width: 96px;
  height: 118px;
  object-fit: contain;
  border: 1px solid rgba(35, 33, 29, 0.14);
  border-radius: 8px;
  padding: 6px;
  background: rgba(255, 250, 240, 0.86);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(32px, 5vw, 62px);
  letter-spacing: 0;
  color: #2d3c36;
}

.topbar-subtitle {
  max-width: 640px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.search-box {
  display: grid;
  gap: 6px;
  width: min(420px, 100%);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--ink);
  background: var(--paper);
  font: inherit;
  box-shadow: var(--shadow);
}

.view-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
  border: 1px solid rgba(35, 33, 29, 0.1);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 250, 240, 0.72);
  box-shadow: 0 8px 22px rgba(50, 43, 32, 0.08);
}

.view-tabs button,
.edit-form button,
.file-button,
.auth-panel button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--ink);
  background: var(--paper);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.view-tabs button:hover,
.edit-form button:hover,
.file-button:hover,
.auth-panel button:hover {
  background: var(--accent-soft);
}

.view-tabs button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.view-tab.is-active {
  border-color: rgba(47, 111, 109, 0.45);
  color: #163c3a;
  background: var(--accent-soft);
  box-shadow: inset 0 -3px 0 rgba(47, 111, 109, 0.55);
}

.primary-action {
  border-color: rgba(47, 111, 109, 0.45) !important;
  color: #fff !important;
  background: var(--accent) !important;
}

.primary-action:hover {
  background: #245654 !important;
}

.ghost-action {
  background: rgba(255, 250, 240, 0.68) !important;
}

.nav-spacer {
  flex: 1 1 auto;
}

.save-status {
  color: var(--muted);
  font-size: 13px;
}

.view-shell {
  display: grid;
  gap: 16px;
}

.family-toolbar {
  display: flex;
  gap: 16px;
  align-items: end;
  justify-content: space-between;
}

.family-toolbar h2 {
  margin: 0 0 4px;
  font-size: 24px;
  color: #2d3c36;
}

.family-toolbar p {
  margin: 0;
  color: var(--muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.setup-panel,
.auth-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 16px;
  padding: 14px;
  background: rgba(255, 250, 240, 0.9);
  box-shadow: var(--shadow);
}

.setup-panel p,
.auth-panel p {
  margin: 6px 0 0;
  color: var(--muted);
}

.auth-panel form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.auth-panel label {
  display: grid;
  gap: 5px;
  min-width: min(260px, 100%);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.auth-panel input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--ink);
  background: var(--paper);
  font: inherit;
  font-weight: 400;
  text-transform: none;
}

.summary-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 250, 240, 0.82);
  border-top: 4px solid var(--accent);
}

.summary-grid article:nth-child(2) {
  border-top-color: var(--coral);
}

.summary-grid article:nth-child(3) {
  border-top-color: var(--gold);
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.summary-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 26px;
}

.workspace {
  display: grid;
  grid-template-columns: 280px minmax(360px, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.person-list,
.tree-panel,
.detail-panel {
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.9);
  box-shadow: var(--shadow);
}

.person-list,
.detail-panel {
  max-height: calc(100vh - 190px);
  overflow: auto;
}

.person-button {
  display: grid;
  width: 100%;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: center;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 10px;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.person-button:hover,
.person-button.is-selected {
  background: linear-gradient(90deg, rgba(216, 231, 228, 0.9), rgba(247, 221, 202, 0.68));
}

.avatar {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: #2f6f6d;
  background: linear-gradient(135deg, #eef7f0, #f8e9d7);
  font-weight: 700;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.person-name {
  display: block;
  font-weight: 700;
}

.person-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.tree-panel {
  position: relative;
  overflow: auto;
  padding: 16px;
}

.tree-view {
  display: grid;
  gap: 12px;
  min-width: 660px;
}

.compact-generation {
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: 12px;
  align-items: start;
  border: 1px solid rgba(35, 33, 29, 0.08);
  border-radius: 8px;
  padding: 10px;
}

.generation-tone-1 {
  background: rgba(216, 231, 228, 0.55);
}

.generation-tone-2 {
  background: rgba(247, 221, 202, 0.58);
}

.generation-tone-3 {
  background: rgba(241, 229, 190, 0.62);
}

.generation-tone-4 {
  background: rgba(225, 218, 241, 0.56);
}

.generation-tone-5 {
  background: rgba(221, 236, 211, 0.58);
}

.generation-tone-6 {
  background: rgba(214, 232, 244, 0.58);
}

.generation-title {
  color: #37443f;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  padding-top: 4px;
}

.sibling-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.compact-node {
  display: inline-flex;
  max-width: 170px;
  align-items: center;
  gap: 5px;
  border: 1px solid rgba(35, 33, 29, 0.14);
  border-radius: 999px;
  padding: 4px 8px 4px 5px;
  color: var(--ink);
  background: var(--paper);
  font: inherit;
  font-size: 12px;
  line-height: 1.2;
  cursor: pointer;
}

.single-node {
  background: linear-gradient(135deg, rgba(255, 250, 240, 0.98), rgba(236, 244, 239, 0.96));
}

.compact-node span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-node.is-muted {
  opacity: 0.38;
}

.compact-node.is-selected {
  border-color: var(--accent);
  background: #d8e7e4;
  box-shadow: 0 0 0 3px rgba(47, 111, 109, 0.16);
}

.compact-node.is-lineage {
  border-color: rgba(215, 164, 65, 0.9);
  box-shadow: inset 0 -3px 0 rgba(215, 164, 65, 0.55);
}

.compact-node.is-lineage .gender-icon {
  outline: 2px solid rgba(215, 164, 65, 0.75);
  outline-offset: 1px;
}

.couple-node {
  display: inline-flex;
  max-width: 360px;
  overflow: hidden;
  border: 1px solid rgba(35, 33, 29, 0.14);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 0 8px 18px rgba(50, 43, 32, 0.08);
}

.couple-node .compact-node {
  max-width: 168px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.couple-node .compact-node + .compact-node {
  border-left: 1px solid rgba(35, 33, 29, 0.12);
}

.couple-node .person-half:first-child {
  background: linear-gradient(135deg, rgba(214, 232, 244, 0.96), rgba(255, 250, 240, 0.96));
}

.couple-node .person-half:last-child {
  background: linear-gradient(135deg, rgba(247, 221, 202, 0.96), rgba(255, 250, 240, 0.96));
}

.couple-node.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 109, 0.18), 0 8px 18px rgba(50, 43, 32, 0.08);
}

.couple-node.is-lineage {
  border-color: rgba(215, 164, 65, 0.95);
  box-shadow: 0 0 0 3px rgba(215, 164, 65, 0.18), 0 8px 18px rgba(50, 43, 32, 0.08);
}

.couple-node.is-muted {
  opacity: 0.38;
}

.couple-node.has-external-partner {
  outline: 1px dashed rgba(47, 111, 109, 0.28);
  outline-offset: 2px;
}

.gender-icon {
  display: inline-grid;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--sky);
  font-size: 10px;
  font-weight: 800;
}

.gender-icon.is-female {
  background: var(--coral);
}

.hover-card {
  position: absolute;
  z-index: 5;
  width: min(320px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: linear-gradient(145deg, #fffaf0, #eef7f3);
  box-shadow: var(--shadow);
  pointer-events: none;
}

.hover-head {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 10px;
  align-items: center;
}

.hover-head span,
.hover-card dt,
.field-hint {
  color: var(--muted);
  font-size: 12px;
}

.hover-photo {
  width: 58px;
  height: 58px;
}

.hover-card dl {
  display: grid;
  gap: 5px;
  margin: 10px 0;
}

.hover-card dl div {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 8px;
}

.hover-card dd {
  margin: 0;
}

.hover-card p {
  margin: 8px 0 0;
}

.hover-links {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}

.detail-panel {
  padding: 18px;
}

.edit-form {
  display: grid;
  gap: 10px;
}

.form-heading {
  display: flex;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

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

.form-heading span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.edit-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.edit-form input,
.edit-form select,
.edit-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--ink);
  background: var(--paper);
  font: inherit;
  font-weight: 400;
  text-transform: none;
}

.edit-form textarea {
  resize: vertical;
}

.photo-editor {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 10px;
  align-items: center;
}

.file-button {
  display: inline-grid;
  place-items: center;
  text-align: center;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.detail-photo {
  width: 112px;
  height: 112px;
}

.detail-panel h2 {
  margin: 0 0 8px;
  font-size: 24px;
  letter-spacing: 0;
}

.fact-list {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

.fact-list div {
  display: grid;
  gap: 2px;
}

.fact-list span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.review-flag {
  display: inline-block;
  margin: 4px 4px 0 0;
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--warn);
  background: #f3dfc9;
  font-size: 12px;
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: end;
}

.relative-list {
  display: grid;
  gap: 4px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.relative-list strong {
  color: var(--ink);
}

.admin-workspace {
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.admin-panel {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.admin-panel h2,
.admin-panel h3 {
  margin: 0;
}

.admin-panel h2 {
  font-size: clamp(28px, 4vw, 44px);
  color: #2d3c36;
}

.admin-hero {
  display: flex;
  gap: 18px;
  align-items: start;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(216, 231, 228, 0.95), rgba(255, 244, 218, 0.84)),
    var(--paper);
  box-shadow: var(--shadow);
}

.admin-hero p:not(.eyebrow) {
  max-width: 680px;
  margin: 8px 0 0;
  color: var(--muted);
}

.admin-badge {
  flex: 0 0 auto;
  border: 1px solid rgba(47, 111, 109, 0.35);
  border-radius: 999px;
  padding: 7px 12px;
  color: #163c3a;
  background: rgba(255, 250, 240, 0.82);
  font-size: 13px;
  font-weight: 800;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.admin-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: rgba(255, 250, 240, 0.9);
  box-shadow: var(--shadow);
}

.admin-card-wide {
  grid-column: 2;
}

.invite-card {
  position: sticky;
  top: 16px;
}

.admin-list {
  display: grid;
  gap: 10px;
  align-content: start;
}

.admin-list-heading {
  display: flex;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(35, 33, 29, 0.08);
}

.admin-list-heading span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(240px, 320px);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 250, 240, 0.82);
  min-width: 0;
}

.admin-row-main,
.admin-controls {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.admin-controls {
  grid-template-columns: minmax(100px, 1fr) minmax(100px, 1fr);
  gap: 8px;
}

.admin-row strong,
.admin-row span {
  overflow-wrap: anywhere;
}

.admin-row span {
  color: var(--muted);
  font-size: 12px;
}

.admin-row code {
  overflow-wrap: anywhere;
  font-size: 12px;
  color: #36514e;
}

.admin-row select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--paper);
  font: inherit;
}

.empty-detail {
  color: var(--muted);
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 260px 1fr;
  }

  .detail-panel {
    grid-column: 1 / -1;
    min-height: 0;
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }

  .admin-card-wide {
    grid-column: auto;
  }

  .invite-card {
    position: static;
  }
}

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

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

  .header-tools {
    align-items: start;
  }

  .topbar,
  .family-toolbar,
  .admin-hero {
    align-items: stretch;
  }

  .family-toolbar,
  .admin-hero {
    display: grid;
  }

  .nav-spacer {
    display: none;
  }

  .view-tabs button {
    flex: 1 1 auto;
  }

  .family-crest {
    width: 72px;
    height: 88px;
  }

  .compact-generation {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .admin-row {
    grid-template-columns: 1fr;
  }

  .admin-controls {
    grid-template-columns: 1fr;
  }

  .person-list,
  .tree-panel,
  .detail-panel {
    min-height: 0;
    max-height: none;
  }
}
