:root {
  --bg: #f6f2ea;
  --panel: #fffdf8;
  --panel-strong: #ffffff;
  --text: #201c17;
  --muted: #766f64;
  --line: #d8cab6;
  --line-strong: #b69f82;
  --primary: #7c4d21;
  --primary-dark: #5f3917;
  --danger: #aa3a3a;
  --danger-dark: #842626;
  --alive: #21a657;
  --dead: #161616;
  --shadow: 0 18px 45px rgba(59, 42, 22, 0.12);
  --radius-lg: 24px;
  --radius-md: 16px;
  --card-width: 205px;
  --partner-gap: 34px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(124, 77, 33, 0.13), transparent 32rem),
    linear-gradient(135deg, #f8f0df 0%, var(--bg) 48%, #f3ede2 100%);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 2rem clamp(1rem, 4vw, 3rem) 1rem;
}

.app-header h1 {
  margin: 0.2rem 0 0.5rem;
  font-size: clamp(2rem, 5vw, 4rem);
  letter-spacing: -0.05em;
  line-height: 0.95;
}

.header-copy {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0;
  color: var(--primary);
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 800;
}

main {
  padding: 1rem clamp(1rem, 4vw, 3rem) 3rem;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1.1fr) minmax(280px, 0.9fr);
  gap: 1rem;
  align-items: start;
}

.panel {
  background: rgba(255, 253, 248, 0.88);
  border: 1px solid rgba(124, 77, 33, 0.13);
  box-shadow: var(--shadow);
  border-radius: var(--radius-lg);
  padding: clamp(1rem, 2.2vw, 1.5rem);
  backdrop-filter: blur(12px);
}

.members-panel {
  grid-column: 1 / -1;
}

.section-heading,
.wrap-heading,
.tree-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.section-heading h2,
.tree-toolbar h2 {
  margin: 0.15rem 0 0;
  font-size: clamp(1.35rem, 2.6vw, 2rem);
  letter-spacing: -0.03em;
}

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

.toolbar,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.button {
  border: 0;
  border-radius: 999px;
  padding: 0.72rem 1rem;
  cursor: pointer;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button-primary {
  color: white;
  background: var(--primary);
  box-shadow: 0 10px 22px rgba(124, 77, 33, 0.26);
}

.button-primary:hover {
  background: var(--primary-dark);
}

.button-secondary {
  color: var(--primary-dark);
  background: #efe2cf;
}

.button-secondary:hover {
  background: #e7d5bb;
}

.button-ghost {
  color: var(--primary);
  background: transparent;
  border: 1px solid var(--line);
}

.button-danger {
  color: white;
  background: var(--danger);
}

.button-danger:hover {
  background: var(--danger-dark);
}

.member-form {
  display: grid;
  gap: 1rem;
  margin-top: 1.25rem;
}

.field {
  display: grid;
  gap: 0.45rem;
  color: var(--muted);
  font-weight: 700;
}

.field input,
.field select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
  border-radius: 14px;
  padding: 0.78rem 0.85rem;
  outline: none;
  transition: border 160ms ease, box-shadow 160ms ease;
}

.field input:focus,
.field select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(124, 77, 33, 0.13);
}

.status-field {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.65rem 0.85rem;
  grid-template-columns: repeat(2, max-content);
  align-items: center;
  column-gap: 1rem;
  row-gap: 0.2rem;
}

.status-field legend {
  padding: 0 0.35rem;
}

.status-field label {
  color: var(--text);
  font-weight: 700;
}

.status-field input {
  width: auto;
  margin-right: 0.35rem;
}

.two-column,
.relationship-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

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

.file-field input {
  padding: 0.57rem 0.85rem;
}

.form-message {
  min-height: 1.4rem;
  margin: 0;
  color: var(--primary-dark);
  font-weight: 800;
}

.form-message.error {
  color: var(--danger-dark);
}

.hidden {
  display: none !important;
}

.preview-panel {
  position: sticky;
  top: 1rem;
}

.preview-card-shell {
  min-height: 300px;
  display: grid;
  place-items: center;
  padding: 1.5rem 0 0.5rem;
}

.helper-text {
  color: var(--muted);
  margin: 0.5rem 0 0;
  line-height: 1.55;
}

.member-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.85rem;
  margin-top: 1.2rem;
}

.member-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.8rem;
  align-items: center;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.65);
}

.member-row h3 {
  margin: 0 0 0.2rem;
  font-size: 1rem;
}

.member-row p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.member-row-actions {
  display: flex;
  gap: 0.4rem;
}

.icon-button {
  border: 1px solid var(--line);
  background: white;
  color: var(--primary-dark);
  border-radius: 999px;
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  font-weight: 800;
}

.import-box {
  margin-top: 1.25rem;
  border-top: 1px dashed var(--line-strong);
  padding-top: 1rem;
}

.import-box summary {
  cursor: pointer;
  font-weight: 900;
  color: var(--primary-dark);
}

.import-box textarea {
  margin: 0.75rem 0;
  min-height: 150px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.member-card {
  position: relative;
  z-index: 2;
  width: var(--card-width);
  min-height: 230px;
  border: 1px solid rgba(124, 77, 33, 0.18);
  background: white;
  border-radius: 22px;
  padding: 1rem;
  text-align: center;
  box-shadow: 0 16px 30px rgba(39, 28, 15, 0.12);
}

.member-card:hover {
  box-shadow: 0 20px 40px rgba(39, 28, 15, 0.18);
}

.member-card.compact-card {
  width: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  text-align: left;
  gap: 0.8rem;
  align-items: center;
  padding: 0.65rem;
  box-shadow: none;
  border-radius: 18px;
}

.avatar,
.avatar-fallback {
  width: 82px;
  height: 82px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  object-fit: cover;
  border: 4px solid #f2e6d4;
  background: #eadbc4;
  color: var(--primary-dark);
  font-size: 1.4rem;
  font-weight: 900;
}

.compact-card .avatar,
.compact-card .avatar-fallback,
.member-row .avatar,
.member-row .avatar-fallback {
  width: 50px;
  height: 50px;
  border-width: 3px;
  font-size: 0.95rem;
}

.card-name {
  margin: 0.75rem 0 0.4rem;
  font-size: 1.08rem;
  line-height: 1.2;
}

.compact-card .card-name {
  margin: 0 0 0.2rem;
}

.card-meta {
  display: grid;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.status-line {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 0.42rem;
  font-weight: 800;
  color: var(--text);
}

.status-dot {
  width: 0.68rem;
  height: 0.68rem;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
}

.status-dot.alive {
  background: var(--alive);
  box-shadow: 0 0 0 4px rgba(33, 166, 87, 0.13);
}

.status-dot.dead {
  background: var(--dead);
  box-shadow: 0 0 0 4px rgba(22, 22, 22, 0.1);
}

.empty-state {
  text-align: center;
  max-width: 680px;
  margin: 3rem auto;
  padding: 2rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.58);
}

.empty-state h2 {
  margin: 0 0 0.5rem;
}

.tree-toolbar {
  margin-bottom: 1rem;
}

.tree-stage {
  overflow: auto;
  min-height: 68vh;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(90deg, rgba(124, 77, 33, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(124, 77, 33, 0.05) 1px, transparent 1px),
    rgba(255, 253, 248, 0.72);
  background-size: 44px 44px;
  border: 1px solid rgba(124, 77, 33, 0.16);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78), var(--shadow);
}

.tree-canvas {
  position: relative;
  min-width: max-content;
  min-height: 66vh;
  padding: 3rem clamp(2rem, 5vw, 5rem) 5rem;
}

.connector-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: visible;
}

.connector-path {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.connector-joint {
  fill: var(--line-strong);
}

.tree-rows {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7rem;
}

.generation-row {
  display: grid;
  justify-items: center;
  gap: 1.2rem;
}

.generation-label {
  color: var(--primary-dark);
  background: #efe2cf;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-weight: 900;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.generation-members {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(2.8rem, 6vw, 5.5rem);
  min-width: 100%;
}

.family-unit {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.partner-pair {
  --pair-gap: var(--partner-gap);
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--pair-gap);
}

.partner-pair::before {
  content: "";
  position: absolute;
  left: calc(50% - (var(--pair-gap) / 2));
  top: 50%;
  width: var(--pair-gap);
  height: 4px;
  border-radius: 999px;
  background: var(--primary);
  transform: translateY(-50%);
  z-index: 1;
}

@media (max-width: 980px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .app-header,
  .section-heading,
  .tree-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions,
  .toolbar,
  .form-actions {
    justify-content: flex-start;
  }

  .two-column,
  .relationship-grid {
    grid-template-columns: 1fr;
  }

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

  .member-row-actions {
    grid-column: 1 / -1;
  }
}

/* Updated compact, vibrant interface and tree controls */
:root {
  --bg: #fff7ed;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: #ffffff;
  --text: #172033;
  --muted: #64748b;
  --line: #ffd1a3;
  --line-strong: #ff8a3d;
  --primary: #ff4d2e;
  --primary-dark: #c93017;
  --danger: #e11d48;
  --danger-dark: #9f1239;
  --alive: #00c853;
  --dead: #111827;
  --violet: #6d5dfc;
  --teal: #00b8a9;
  --sun: #ffb703;
  --shadow: 0 18px 42px rgba(255, 77, 46, 0.13), 0 8px 18px rgba(23, 32, 51, 0.08);
  --radius-lg: 22px;
  --radius-md: 15px;
  --card-width: 164px;
  --partner-gap: 22px;
}

body {
  background:
    radial-gradient(circle at top left, rgba(255, 77, 46, 0.22), transparent 28rem),
    radial-gradient(circle at top right, rgba(109, 93, 252, 0.2), transparent 30rem),
    linear-gradient(135deg, #fff7ed 0%, #f7fbff 48%, #fff0f6 100%);
}

.app-header h1 {
  letter-spacing: -0.06em;
}

.eyebrow {
  color: var(--primary-dark);
}

.panel {
  background: var(--panel);
  border-color: rgba(255, 138, 61, 0.34);
}

.button {
  padding: 0.64rem 0.92rem;
}

.button-primary {
  background: linear-gradient(135deg, var(--primary), #ff8a3d);
  box-shadow: 0 10px 22px rgba(255, 77, 46, 0.28);
}

.button-primary:hover {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}

.button-secondary {
  color: #ffffff;
  background: linear-gradient(135deg, var(--violet), #3b82f6);
}

.button-secondary:hover {
  background: linear-gradient(135deg, #5546df, #2563eb);
}

.button-ghost {
  color: var(--primary-dark);
  background: rgba(255, 255, 255, 0.72);
}

.field input,
.field select,
textarea,
.search-box input {
  border-color: rgba(255, 138, 61, 0.55);
}

.field input:focus,
.field select:focus,
textarea:focus,
.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(255, 77, 46, 0.14);
}

.preview-card-shell {
  min-height: 220px;
  padding: 1rem 0 0.25rem;
}

.member-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.admin-generation-group {
  display: grid;
  gap: 0.65rem;
}

.admin-generation-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0.2rem 0;
  color: var(--primary-dark);
  font-weight: 950;
  letter-spacing: -0.01em;
}

.generation-count {
  color: var(--muted);
  background: rgba(255, 183, 3, 0.22);
  border: 1px solid rgba(255, 183, 3, 0.45);
  border-radius: 999px;
  padding: 0.28rem 0.56rem;
  font-size: 0.78rem;
}

.generation-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(275px, 1fr));
  gap: 0.7rem;
}

.member-list-item {
  min-width: 0;
}

.member-row {
  border-color: rgba(255, 138, 61, 0.42);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(255, 247, 237, 0.9));
}

.member-row-editable {
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.member-row-editable:hover,
.member-row-editable:focus-visible {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: 0 12px 26px rgba(255, 77, 46, 0.16);
  outline: none;
}

.member-row-copy {
  min-width: 0;
}

.member-row p .status-dot {
  margin-right: 0.2rem;
  vertical-align: -0.08rem;
}

.icon-button {
  border-color: rgba(255, 138, 61, 0.5);
  color: var(--primary-dark);
  background: rgba(255, 255, 255, 0.92);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(255, 77, 46, 0.16);
  outline: none;
}

.danger-icon {
  color: var(--danger-dark);
  border-color: rgba(225, 29, 72, 0.25);
}

.member-card {
  width: var(--card-width);
  min-height: 148px;
  border: 1px solid rgba(255, 138, 61, 0.45);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 247, 237, 0.97)),
    radial-gradient(circle at top right, rgba(109, 93, 252, 0.12), transparent 9rem);
  border-radius: 18px;
  padding: 0.72rem;
  box-shadow: 0 12px 24px rgba(23, 32, 51, 0.1);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.member-card:hover,
.member-card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: 0 16px 32px rgba(255, 77, 46, 0.18);
  outline: none;
}

.member-card.compact-card {
  border-radius: 16px;
}

.avatar,
.avatar-fallback {
  width: 58px;
  height: 58px;
  border-width: 3px;
  border-color: rgba(255, 183, 3, 0.55);
  background: linear-gradient(135deg, rgba(255, 183, 3, 0.22), rgba(0, 184, 169, 0.22));
  color: var(--primary-dark);
  font-size: 1.02rem;
}

.compact-card .avatar,
.compact-card .avatar-fallback,
.member-row .avatar,
.member-row .avatar-fallback {
  width: 46px;
  height: 46px;
  border-width: 2px;
  font-size: 0.86rem;
}

.card-name {
  margin: 0.55rem 0 0.25rem;
  font-size: 0.98rem;
  line-height: 1.16;
}

.card-meta {
  gap: 0.18rem;
  font-size: 0.78rem;
}

.status-line {
  gap: 0.34rem;
}

.status-dot {
  width: 0.58rem;
  height: 0.58rem;
}

.status-dot.alive {
  background: var(--alive);
  box-shadow: 0 0 0 3px rgba(0, 200, 83, 0.14);
}

.status-dot.dead {
  background: var(--dead);
  box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.12);
}

.tree-toolbar {
  align-items: flex-start;
  margin-bottom: 1rem;
}

.tree-control-stack {
  display: grid;
  gap: 0.55rem;
  justify-items: end;
  min-width: min(580px, 100%);
}

.search-box {
  display: flex;
  gap: 0.5rem;
  width: min(560px, 100%);
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
  border-radius: 999px;
  padding: 0.68rem 0.9rem;
  outline: none;
  transition: border 160ms ease, box-shadow 160ms ease;
}

.search-message {
  min-height: 1.1rem;
  justify-self: stretch;
  text-align: right;
}

.search-message.error {
  color: var(--danger-dark);
}

.control-toolbar {
  justify-content: flex-end;
  align-items: center;
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  padding: 0.32rem;
  border: 1px solid rgba(255, 138, 61, 0.4);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
}

.zoom-value {
  min-width: 3.2rem;
  text-align: center;
  color: var(--text);
  font-weight: 900;
  font-size: 0.86rem;
}

.tree-stage {
  overflow: auto;
  min-height: 70vh;
  background:
    linear-gradient(90deg, rgba(255, 138, 61, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(109, 93, 252, 0.07) 1px, transparent 1px),
    linear-gradient(135deg, rgba(255, 255, 255, 0.82), rgba(255, 247, 237, 0.72));
  background-size: 38px 38px;
  border-color: rgba(255, 138, 61, 0.32);
}

.tree-canvas {
  position: relative;
  min-width: 100%;
  min-height: 70vh;
  padding: 0;
}

.tree-scale-shell {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
  min-width: max-content;
  min-height: 70vh;
  padding: 2rem clamp(1.25rem, 4vw, 3.2rem) 3.4rem;
}

.connector-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: visible;
}

.connector-path {
  stroke: rgba(255, 77, 46, 0.7);
  stroke-width: 2.6;
}

.partner-parent-path {
  stroke: rgba(109, 93, 252, 0.72);
}

.connector-joint {
  fill: var(--violet);
}

.tree-rows {
  gap: 4.6rem;
}

.generation-row {
  gap: 0.9rem;
}

.generation-label {
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  border: 0;
  box-shadow: 0 8px 18px rgba(109, 93, 252, 0.18);
}

.generation-members {
  gap: clamp(1.3rem, 4vw, 3.8rem);
}

.partner-pair {
  --pair-gap: var(--partner-gap);
}

.partner-pair::before {
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--violet));
}

.member-card.search-hit {
  border-color: var(--teal);
  box-shadow: 0 0 0 5px rgba(0, 184, 169, 0.18), 0 18px 36px rgba(0, 184, 169, 0.22);
  animation: searchPulse 900ms ease-in-out 2;
}

@keyframes searchPulse {
  0%, 100% { transform: translateY(-2px) scale(1); }
  50% { transform: translateY(-2px) scale(1.05); }
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 720px) {
  .tree-control-stack {
    justify-items: stretch;
  }

  .search-box {
    flex-direction: column;
  }

  .search-message {
    text-align: left;
  }

  .control-toolbar {
    justify-content: flex-start;
  }

  .zoom-controls {
    flex-wrap: wrap;
    border-radius: 18px;
  }

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

.tree-canvas {
  overflow: hidden;
}

/* Mobile compliance and touch-friendly refinements */
html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
}

button,
input,
select,
textarea,
summary {
  touch-action: manipulation;
}

.button,
.icon-button,
.import-box summary {
  min-height: 44px;
}

.tree-stage {
  width: 100%;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  scrollbar-gutter: stable both-edges;
}

.tree-canvas {
  max-width: none;
}

.card-copy,
.member-row-copy {
  overflow-wrap: anywhere;
}

@media (hover: none) {
  .button:hover,
  .icon-button:hover,
  .member-card:hover,
  .member-row-editable:hover {
    transform: none;
  }
}

@media (max-width: 900px) {
  .app-header {
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .tree-toolbar {
    align-items: stretch;
  }

  .tree-control-stack {
    justify-items: stretch;
    width: 100%;
  }

  .control-toolbar {
    justify-content: stretch;
  }

  .control-toolbar > .button {
    flex: 1 1 150px;
  }

  .zoom-controls {
    justify-content: center;
  }
}

@media (max-width: 600px) {
  :root {
    --card-width: 132px;
    --partner-gap: 14px;
    --radius-lg: 18px;
    --radius-md: 13px;
  }

  .app-header {
    padding: max(0.85rem, env(safe-area-inset-top)) max(0.85rem, env(safe-area-inset-right)) 0.55rem max(0.85rem, env(safe-area-inset-left));
    gap: 0.75rem;
  }

  .app-header h1 {
    font-size: clamp(1.75rem, 12vw, 2.55rem);
    line-height: 0.98;
  }

  .header-copy,
  .helper-text {
    font-size: 0.92rem;
  }

  main {
    padding: 0.65rem max(0.75rem, env(safe-area-inset-right)) max(1.15rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
  }

  .panel {
    padding: 0.85rem;
    border-radius: var(--radius-lg);
  }

  .admin-layout {
    gap: 0.8rem;
  }

  .section-heading,
  .wrap-heading,
  .tree-toolbar {
    gap: 0.75rem;
  }

  .section-heading h2,
  .tree-toolbar h2 {
    font-size: 1.28rem;
  }

  .toolbar,
  .form-actions,
  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
    padding: 0.7rem 0.85rem;
  }

  .member-form {
    gap: 0.8rem;
    margin-top: 0.9rem;
  }

  .field input,
  .field select,
  textarea,
  .search-box input {
    min-height: 46px;
    font-size: 16px;
    border-radius: 13px;
    padding: 0.72rem 0.8rem;
  }

  .status-field {
    grid-template-columns: 1fr 1fr;
    min-height: 46px;
  }

  .preview-card-shell {
    min-height: 170px;
    padding-top: 0.7rem;
  }

  .member-list {
    gap: 0.8rem;
  }

  .generation-list {
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }

  .admin-generation-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.35rem;
  }

  .member-row {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.65rem;
    padding: 0.65rem;
  }

  .member-row h3 {
    font-size: 0.95rem;
  }

  .member-row p {
    font-size: 0.82rem;
    line-height: 1.4;
  }

  .member-row-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
  }

  .member-row-actions .icon-button {
    width: 100%;
  }

  .compact-card .avatar,
  .compact-card .avatar-fallback,
  .member-row .avatar,
  .member-row .avatar-fallback {
    width: 42px;
    height: 42px;
  }

  .tree-toolbar {
    position: sticky;
    top: 0;
    z-index: 10;
    margin-bottom: 0.75rem;
    backdrop-filter: blur(16px);
  }

  .tree-control-stack {
    gap: 0.45rem;
  }

  .search-box {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .search-message {
    font-size: 0.84rem;
    min-height: 1rem;
  }

  .control-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
  }

  .control-toolbar > .button {
    min-width: 0;
    font-size: 0.86rem;
  }

  .zoom-controls {
    grid-column: 1 / -1;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.35rem;
    border-radius: 16px;
    padding: 0.35rem;
  }

  .zoom-controls .icon-button {
    width: 100%;
    padding: 0.45rem 0.25rem;
    font-size: 0.82rem;
  }

  .zoom-value {
    min-width: 0;
    align-self: center;
    font-size: 0.8rem;
  }

  .tree-stage {
    min-height: 62svh;
    height: 62svh;
    border-radius: 16px;
    background-size: 30px 30px;
  }

  .tree-canvas {
    min-height: 62svh;
  }

  .tree-scale-shell {
    min-height: 62svh;
    padding: 1.1rem 0.9rem 2rem;
  }

  .tree-rows {
    gap: 3.2rem;
  }

  .generation-row {
    gap: 0.62rem;
  }

  .generation-label {
    padding: 0.28rem 0.55rem;
    font-size: 0.68rem;
  }

  .generation-members {
    gap: 0.9rem;
    align-items: center;
  }

  .member-card {
    min-height: 112px;
    border-radius: 15px;
    padding: 0.55rem;
  }

  .avatar,
  .avatar-fallback {
    width: 44px;
    height: 44px;
    border-width: 2px;
    font-size: 0.82rem;
  }

  .card-name {
    margin: 0.42rem 0 0.2rem;
    font-size: 0.82rem;
    line-height: 1.12;
  }

  .card-meta {
    font-size: 0.68rem;
  }

  .status-dot {
    width: 0.46rem;
    height: 0.46rem;
  }

  .connector-path {
    stroke-width: 2.1;
  }

  .partner-pair::before {
    height: 2px;
  }

  .empty-state {
    margin: 1rem auto;
    padding: 1rem;
  }
}

@media (max-width: 380px) {
  :root {
    --card-width: 118px;
    --partner-gap: 10px;
  }

  .app-header h1 {
    font-size: clamp(1.55rem, 11vw, 2.2rem);
  }

  .control-toolbar {
    grid-template-columns: 1fr;
  }

  .zoom-controls {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .member-card {
    min-height: 104px;
  }

  .avatar,
  .avatar-fallback {
    width: 38px;
    height: 38px;
  }
}

/* Latest requested refinements: compact presentation page, drag-to-pan tree, thin admin rows, clearer connector colors. */
body[data-page="tree"] {
  min-height: 100vh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 8% 10%, rgba(255, 183, 3, 0.28), transparent 22rem),
    radial-gradient(circle at 92% 4%, rgba(0, 184, 169, 0.24), transparent 26rem),
    radial-gradient(circle at 45% 100%, rgba(109, 93, 252, 0.2), transparent 28rem),
    linear-gradient(135deg, #fff8ed 0%, #f7fbff 42%, #fff2f7 100%);
}

body[data-page="tree"] .tree-app-header {
  flex: 0 0 auto;
  align-items: center;
  padding: max(0.65rem, env(safe-area-inset-top)) clamp(0.8rem, 2vw, 1.35rem) 0.55rem;
  border-bottom: 1px solid rgba(255, 138, 61, 0.26);
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.72), rgba(255, 247, 237, 0.54));
  box-shadow: 0 10px 26px rgba(23, 32, 51, 0.05);
  backdrop-filter: blur(18px);
}

body[data-page="tree"] .tree-title-block {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.8rem;
}

body[data-page="tree"] .tree-app-header .eyebrow {
  font-size: 0.64rem;
  letter-spacing: 0.18em;
}

body[data-page="tree"] .tree-app-header h1 {
  margin: 0;
  font-size: clamp(1.2rem, 3.2vw, 2rem);
  line-height: 1;
  letter-spacing: -0.045em;
}

body[data-page="tree"] .tree-app-header .header-copy {
  max-width: none;
  font-size: 0.86rem;
  line-height: 1.25;
}

body[data-page="tree"] .tree-page-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.55rem clamp(0.7rem, 1.6vw, 1.1rem) max(0.65rem, env(safe-area-inset-bottom));
}

body[data-page="tree"] .compact-tree-toolbar {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.62rem 0.75rem;
  border-radius: 18px;
  display: grid;
  grid-template-columns: minmax(170px, 0.7fr) minmax(320px, 1.3fr);
  align-items: center;
  gap: 0.7rem;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.94), rgba(255, 247, 237, 0.84)),
    radial-gradient(circle at top left, rgba(255, 183, 3, 0.2), transparent 13rem);
}

body[data-page="tree"] .tree-toolbar-title h2 {
  margin: 0;
  font-size: clamp(1rem, 2vw, 1.35rem);
  letter-spacing: -0.035em;
}

body[data-page="tree"] .tree-toolbar-title .helper-text {
  margin-top: 0.18rem;
  font-size: 0.82rem;
  line-height: 1.25;
}

body[data-page="tree"] .tree-control-stack {
  justify-items: stretch;
  gap: 0.34rem;
  min-width: 0;
}

body[data-page="tree"] .search-box {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
}

body[data-page="tree"] .search-box input {
  min-height: 38px;
  padding: 0.52rem 0.78rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

body[data-page="tree"] .compact-tree-toolbar .button,
body[data-page="tree"] .compact-tree-toolbar .icon-button {
  min-height: 38px;
  padding: 0.48rem 0.72rem;
}

body[data-page="tree"] .search-message {
  min-height: 0.9rem;
  font-size: 0.78rem;
  line-height: 1.1;
}

body[data-page="tree"] .control-toolbar {
  justify-content: flex-end;
  align-items: center;
  gap: 0.42rem;
}

body[data-page="tree"] .zoom-controls {
  padding: 0.22rem;
  gap: 0.22rem;
  background: rgba(255, 255, 255, 0.82);
}

body[data-page="tree"] .zoom-value {
  min-width: 2.8rem;
  font-size: 0.78rem;
}

body[data-page="tree"] .tree-stage {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  overflow: hidden;
  position: relative;
  cursor: grab;
  user-select: none;
  touch-action: none;
  scrollbar-width: none;
  border-radius: 22px;
  border: 1px solid rgba(255, 138, 61, 0.35);
  background:
    linear-gradient(90deg, rgba(255, 138, 61, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(109, 93, 252, 0.075) 1px, transparent 1px),
    radial-gradient(circle at 12% 8%, rgba(255, 183, 3, 0.16), transparent 15rem),
    radial-gradient(circle at 90% 82%, rgba(0, 184, 169, 0.14), transparent 18rem),
    linear-gradient(135deg, rgba(255, 255, 255, 0.86), rgba(255, 247, 237, 0.76));
  background-size: 34px 34px, 34px 34px, auto, auto, auto;
}

body[data-page="tree"] .tree-stage::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

body[data-page="tree"] .tree-stage::after {
  content: "Drag canvas to explore";
  position: absolute;
  right: 0.8rem;
  bottom: 0.7rem;
  z-index: 3;
  pointer-events: none;
  color: rgba(23, 32, 51, 0.54);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 138, 61, 0.24);
  border-radius: 999px;
  padding: 0.28rem 0.58rem;
  font-size: 0.72rem;
  font-weight: 900;
  backdrop-filter: blur(10px);
}

body[data-page="tree"] .tree-stage.is-panning {
  cursor: grabbing;
}

body[data-page="tree"] .tree-stage.is-panning .member-card {
  pointer-events: none;
}

body[data-page="tree"] .tree-canvas {
  min-height: 100%;
  overflow: hidden;
}

body[data-page="tree"] .tree-scale-shell {
  min-height: 100%;
  padding: 2.15rem clamp(2rem, 5vw, 4.5rem) 3.25rem;
}

body[data-page="tree"] .tree-rows {
  gap: 4.05rem;
}

body[data-page="tree"] .generation-row {
  gap: 0.65rem;
}

body[data-page="tree"] .generation-label {
  font-size: 0.68rem;
  padding: 0.24rem 0.55rem;
  box-shadow: 0 8px 18px rgba(109, 93, 252, 0.14);
}

body[data-page="tree"] .generation-members {
  gap: clamp(1.15rem, 3.2vw, 3.2rem);
}

body[data-page="tree"] .member-card {
  background:
    linear-gradient(#ffffff, #ffffff) padding-box,
    linear-gradient(145deg, rgba(255, 77, 46, 0.9), rgba(109, 93, 252, 0.8), rgba(0, 184, 169, 0.8)) border-box;
  border: 1px solid transparent;
  box-shadow: 0 14px 28px rgba(23, 32, 51, 0.1), 0 4px 12px rgba(255, 77, 46, 0.08);
}

body[data-page="tree"] .member-card::before {
  content: "";
  position: absolute;
  inset: 0.45rem 0.45rem auto;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--violet), var(--teal));
  opacity: 0.78;
}

body[data-page="tree"] .avatar,
body[data-page="tree"] .avatar-fallback {
  box-shadow: 0 0 0 4px rgba(255, 183, 3, 0.14);
}

body[data-page="tree"] .tree-empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}

.connector-path-gap {
  fill: none;
  stroke: rgba(255, 255, 255, 0.96);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.connector-path {
  stroke-width: 2.45;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.child-path {
  stroke-width: 2.35;
}

.partner-parent-path {
  stroke-width: 2.75;
}

.parent-trunk-path {
  stroke-dasharray: none;
}

.connector-path.connector-color-0 { stroke: #ff4d2e; }
.connector-path.connector-color-1 { stroke: #6d5dfc; }
.connector-path.connector-color-2 { stroke: #00a99d; }
.connector-path.connector-color-3 { stroke: #f59e0b; }
.connector-path.connector-color-4 { stroke: #ec4899; }
.connector-path.connector-color-5 { stroke: #2563eb; }
.connector-joint.connector-color-0 { fill: #ff4d2e; }
.connector-joint.connector-color-1 { fill: #6d5dfc; }
.connector-joint.connector-color-2 { fill: #00a99d; }
.connector-joint.connector-color-3 { fill: #f59e0b; }
.connector-joint.connector-color-4 { fill: #ec4899; }
.connector-joint.connector-color-5 { fill: #2563eb; }

/* Admin saved members: thin, single-column editable lines. */
body[data-page="admin"] .member-list {
  grid-template-columns: 1fr;
  gap: 0.62rem;
}

body[data-page="admin"] .generation-list {
  grid-template-columns: 1fr;
  gap: 0.38rem;
}

body[data-page="admin"] .admin-generation-group {
  gap: 0.42rem;
}

body[data-page="admin"] .admin-generation-title {
  padding: 0.22rem 0.1rem 0;
  font-size: 0.9rem;
}

body[data-page="admin"] .thin-member-row {
  min-height: 46px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.58rem;
  padding: 0.38rem 0.48rem;
  border-radius: 13px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.98), rgba(255, 248, 237, 0.92));
}

body[data-page="admin"] .thin-member-row .avatar,
body[data-page="admin"] .thin-member-row .avatar-fallback {
  width: 34px;
  height: 34px;
  border-width: 2px;
  font-size: 0.7rem;
}

body[data-page="admin"] .thin-member-copy {
  display: grid;
  grid-template-columns: minmax(130px, 0.8fr) minmax(120px, 1fr);
  align-items: center;
  gap: 0.55rem;
}

body[data-page="admin"] .thin-member-copy h3 {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body[data-page="admin"] .member-partner-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body[data-page="admin"] .member-partner-line span {
  color: var(--text);
  font-weight: 850;
}

body[data-page="admin"] .thin-member-row .member-row-actions {
  display: flex;
  grid-column: auto;
  gap: 0.32rem;
}

body[data-page="admin"] .thin-member-row .icon-button {
  min-height: 32px;
  padding: 0.32rem 0.58rem;
  font-size: 0.76rem;
}

@media (max-width: 840px) {
  body[data-page="tree"] .compact-tree-toolbar {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  body[data-page="tree"] .control-toolbar {
    justify-content: flex-start;
  }
}

@media (max-width: 600px) {
  body[data-page="tree"] .tree-app-header {
    padding: max(0.5rem, env(safe-area-inset-top)) 0.7rem 0.45rem;
  }

  body[data-page="tree"] .tree-title-block {
    display: grid;
    gap: 0.16rem;
  }

  body[data-page="tree"] .tree-app-header h1 {
    font-size: 1.22rem;
  }

  body[data-page="tree"] .tree-app-header .header-copy {
    font-size: 0.75rem;
  }

  body[data-page="tree"] .tree-page-main {
    padding: 0.45rem 0.55rem max(0.5rem, env(safe-area-inset-bottom));
    gap: 0.42rem;
  }

  body[data-page="tree"] .compact-tree-toolbar {
    position: relative;
    top: auto;
    padding: 0.5rem;
    border-radius: 15px;
  }

  body[data-page="tree"] .tree-toolbar-title .helper-text {
    display: none;
  }

  body[data-page="tree"] .tree-control-stack {
    gap: 0.32rem;
  }

  body[data-page="tree"] .search-box {
    grid-template-columns: 1fr auto;
    gap: 0.36rem;
  }

  body[data-page="tree"] .search-box input,
  body[data-page="tree"] .compact-tree-toolbar .button,
  body[data-page="tree"] .compact-tree-toolbar .icon-button {
    min-height: 36px;
    font-size: 0.82rem;
  }

  body[data-page="tree"] .control-toolbar {
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 0.35rem;
  }

  body[data-page="tree"] .zoom-controls {
    grid-column: auto;
    display: flex;
    min-width: 0;
    overflow: auto;
    scrollbar-width: none;
  }

  body[data-page="tree"] .zoom-controls::-webkit-scrollbar {
    display: none;
  }

  body[data-page="tree"] .tree-stage {
    height: auto;
    min-height: 0;
    border-radius: 16px;
  }

  body[data-page="tree"] .tree-stage::after {
    content: "Drag to explore";
    right: 0.5rem;
    bottom: 0.45rem;
    font-size: 0.64rem;
  }

  body[data-page="tree"] .tree-scale-shell {
    padding: 1.2rem 1rem 2rem;
  }

  body[data-page="admin"] .thin-member-row {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
  }

  body[data-page="admin"] .thin-member-copy {
    grid-template-columns: 1fr;
    gap: 0.08rem;
  }

  body[data-page="admin"] .thin-member-row .member-row-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Latest requested refinements: single-line controls, stronger modern visuals, fit-centered canvas, import under preview. */
@keyframes softGradientShift {
  0% { background-position: 0% 50%, 100% 0%, 50% 100%, 0% 50%; }
  50% { background-position: 100% 50%, 0% 100%, 70% 20%, 100% 50%; }
  100% { background-position: 0% 50%, 100% 0%, 50% 100%, 0% 50%; }
}

@keyframes toolbarFloatIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes cardRiseIn {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes ambientGlow {
  0%, 100% { transform: translate3d(-4%, -3%, 0) scale(1); opacity: 0.56; }
  50% { transform: translate3d(4%, 3%, 0) scale(1.05); opacity: 0.86; }
}

body[data-page="tree"] {
  background:
    radial-gradient(circle at 8% 10%, rgba(255, 183, 3, 0.34), transparent 22rem),
    radial-gradient(circle at 92% 4%, rgba(0, 184, 169, 0.3), transparent 26rem),
    radial-gradient(circle at 45% 100%, rgba(109, 93, 252, 0.26), transparent 28rem),
    linear-gradient(135deg, #fff7ed 0%, #f7fbff 42%, #fff0f6 100%);
  background-size: 120% 120%, 130% 130%, 140% 140%, 140% 140%;
  animation: softGradientShift 18s ease-in-out infinite;
}

body[data-page="tree"] .tree-app-header {
  padding: max(0.42rem, env(safe-area-inset-top)) clamp(0.7rem, 1.6vw, 1.05rem) 0.38rem;
}

body[data-page="tree"] .tree-app-header h1 {
  font-size: clamp(1.02rem, 2.4vw, 1.55rem);
}

body[data-page="tree"] .tree-app-header .header-copy {
  font-size: 0.78rem;
}

body[data-page="tree"] .tree-page-main {
  gap: 0.42rem;
  padding-top: 0.42rem;
}

body[data-page="tree"] .compact-tree-toolbar {
  width: max-content;
  max-width: 100%;
  min-width: 0;
  align-self: flex-start;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.48rem;
  padding: 0.34rem 0.42rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 14px 34px rgba(23, 32, 51, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.92);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(255, 247, 237, 0.88)) padding-box,
    linear-gradient(135deg, rgba(255, 77, 46, 0.75), rgba(109, 93, 252, 0.65), rgba(0, 184, 169, 0.65)) border-box;
  animation: toolbarFloatIn 420ms ease both;
}

body[data-page="tree"] .tree-toolbar-title {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}

body[data-page="tree"] .tree-toolbar-title h2 {
  font-size: 0.92rem;
  line-height: 1;
  padding: 0 0.26rem;
  white-space: nowrap;
  background: linear-gradient(90deg, var(--primary), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

body[data-page="tree"] .tree-control-stack {
  width: auto;
  min-width: 0;
  display: grid;
  gap: 0.14rem;
}

body[data-page="tree"] .tree-control-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.32rem;
  max-width: calc(100vw - 1.5rem);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  white-space: nowrap;
  padding: 0.02rem;
}

body[data-page="tree"] .tree-control-row::-webkit-scrollbar {
  display: none;
}

body[data-page="tree"] .search-box {
  flex: 0 0 clamp(210px, 24vw, 310px);
  width: auto;
  display: flex;
  flex-direction: row;
  gap: 0.28rem;
}

body[data-page="tree"] .search-box input {
  min-width: 0;
  min-height: 32px;
  height: 32px;
  padding: 0.36rem 0.68rem;
  font-size: 0.78rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
}

body[data-page="tree"] .compact-tree-toolbar .button,
body[data-page="tree"] .compact-tree-toolbar .icon-button {
  flex: 0 0 auto;
  min-height: 32px;
  height: 32px;
  padding: 0.34rem 0.58rem;
  font-size: 0.74rem;
  line-height: 1;
  box-shadow: 0 7px 16px rgba(23, 32, 51, 0.1);
}

body[data-page="tree"] .compact-tree-toolbar .button:hover,
body[data-page="tree"] .compact-tree-toolbar .icon-button:hover {
  transform: translateY(-2px) scale(1.02);
}

body[data-page="tree"] .zoom-controls {
  flex: 0 0 auto;
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.18rem;
  padding: 0.16rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

body[data-page="tree"] .zoom-value {
  min-width: 2.45rem;
  font-size: 0.72rem;
}

body[data-page="tree"] .search-message {
  justify-self: end;
  min-height: 0;
  max-width: 100%;
  margin: 0;
  padding: 0 0.24rem;
  font-size: 0.68rem;
  line-height: 1.08;
  text-align: right;
}

body[data-page="tree"] .search-message:empty {
  display: none;
}

body[data-page="tree"] .tree-stage {
  border-radius: 26px;
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 22px 55px rgba(23, 32, 51, 0.13);
  background:
    linear-gradient(90deg, rgba(255, 138, 61, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(109, 93, 252, 0.075) 1px, transparent 1px),
    radial-gradient(circle at 14% 12%, rgba(255, 183, 3, 0.22), transparent 16rem),
    radial-gradient(circle at 86% 78%, rgba(0, 184, 169, 0.2), transparent 20rem),
    linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(255, 247, 237, 0.78));
  background-size: 34px 34px, 34px 34px, auto, auto, auto;
}

body[data-page="tree"] .tree-stage::before {
  content: "";
  position: absolute;
  inset: -20%;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(circle at 50% 50%, rgba(109, 93, 252, 0.13), transparent 34rem);
  animation: ambientGlow 9s ease-in-out infinite;
}

body[data-page="tree"] .tree-canvas {
  position: relative;
  z-index: 1;
}

body[data-page="tree"] .member-card {
  animation: cardRiseIn 420ms ease both;
  box-shadow: 0 18px 34px rgba(23, 32, 51, 0.12), 0 7px 18px rgba(255, 77, 46, 0.08);
}

body[data-page="tree"] .member-card:hover,
body[data-page="tree"] .member-card:focus-visible {
  transform: translateY(-4px) scale(1.03);
  box-shadow: 0 24px 45px rgba(23, 32, 51, 0.16), 0 10px 24px rgba(109, 93, 252, 0.14);
}

body[data-page="tree"] .generation-label {
  background: linear-gradient(135deg, #ff4d2e, #6d5dfc 56%, #00b8a9);
  box-shadow: 0 10px 22px rgba(109, 93, 252, 0.18);
}

body[data-page="admin"] .preview-import-box {
  margin-top: 1rem;
  padding-top: 0.8rem;
}

body[data-page="admin"] .json-file-field {
  margin-top: 0.75rem;
}

body[data-page="admin"] .json-file-field input {
  padding: 0.55rem 0.75rem;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(247, 251, 255, 0.92));
}

body[data-page="admin"] .import-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.55rem;
  align-items: center;
  margin: 0.85rem 0 0.3rem;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

body[data-page="admin"] .import-divider::before,
body[data-page="admin"] .import-divider::after {
  content: "";
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 138, 61, 0.62), transparent);
}

@media (max-width: 840px) {
  body[data-page="tree"] .compact-tree-toolbar {
    display: flex;
    grid-template-columns: none;
    width: 100%;
    border-radius: 18px;
  }

  body[data-page="tree"] .tree-control-row {
    max-width: 100%;
  }
}

@media (max-width: 600px) {
  body[data-page="tree"] .tree-app-header .header-copy {
    display: none;
  }

  body[data-page="tree"] .compact-tree-toolbar {
    position: relative;
    width: 100%;
    padding: 0.34rem;
    gap: 0.3rem;
    border-radius: 16px;
  }

  body[data-page="tree"] .tree-toolbar-title h2 {
    font-size: 0.78rem;
    padding-inline: 0.12rem;
  }

  body[data-page="tree"] .tree-control-stack {
    overflow: hidden;
  }

  body[data-page="tree"] .tree-control-row {
    display: flex;
    grid-template-columns: none;
    gap: 0.25rem;
  }

  body[data-page="tree"] .search-box {
    flex: 0 0 190px;
    display: flex;
    grid-template-columns: none;
    flex-direction: row;
    gap: 0.24rem;
  }

  body[data-page="tree"] .search-box input {
    font-size: 16px;
    height: 31px;
    min-height: 31px;
    padding: 0.28rem 0.52rem;
  }

  body[data-page="tree"] .compact-tree-toolbar .button,
  body[data-page="tree"] .compact-tree-toolbar .icon-button {
    width: auto;
    min-height: 31px;
    height: 31px;
    padding: 0.28rem 0.48rem;
    font-size: 0.68rem;
  }

  body[data-page="tree"] .zoom-controls {
    width: auto;
    display: inline-flex;
    grid-template-columns: none;
    overflow: visible;
  }

  body[data-page="tree"] .zoom-value {
    min-width: 2.25rem;
    font-size: 0.66rem;
  }

  body[data-page="tree"] .tree-stage {
    border-radius: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body[data-page="tree"],
  body[data-page="tree"] .tree-stage::before,
  body[data-page="tree"] .compact-tree-toolbar,
  body[data-page="tree"] .member-card,
  .member-card.search-hit {
    animation: none !important;
  }

  .button,
  .icon-button,
  .member-card,
  .member-row-editable {
    transition: none !important;
  }
}

/* Search suggestions and member details popup */
body[data-page="tree"] .tree-app-header h1 {
  background: linear-gradient(90deg, #ff4d2e, #6d5dfc 52%, #00b8a9);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
}

body[data-page="tree"] .compact-tree-toolbar,
body[data-page="tree"] .tree-control-stack {
  overflow: visible;
}

body[data-page="tree"] .tree-control-stack {
  position: relative;
}

body[data-page="tree"] .search-box {
  position: relative;
}

.search-suggestions {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  z-index: 60;
  width: min(410px, calc(100vw - 1.6rem));
  max-height: min(330px, 50vh);
  overflow: auto;
  display: grid;
  gap: 0.34rem;
  padding: 0.46rem;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(247, 251, 255, 0.92)) padding-box,
    linear-gradient(135deg, rgba(255, 77, 46, 0.78), rgba(109, 93, 252, 0.72), rgba(0, 184, 169, 0.72)) border-box;
  box-shadow: 0 22px 54px rgba(23, 32, 51, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.95);
  animation: suggestionDrop 180ms ease both;
}

.search-suggestion {
  border: 0;
  width: 100%;
  display: grid;
  grid-template-columns: 2rem 1fr;
  align-items: center;
  gap: 0.55rem;
  padding: 0.42rem 0.48rem;
  border-radius: 14px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.search-suggestion:hover,
.search-suggestion:focus-visible {
  background: #ffffff;
  box-shadow: 0 10px 22px rgba(109, 93, 252, 0.14);
  transform: translateY(-1px);
  outline: none;
}

.suggestion-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 950;
  background: linear-gradient(135deg, #ff4d2e, #6d5dfc);
  box-shadow: 0 8px 16px rgba(255, 77, 46, 0.18);
}

.suggestion-copy {
  min-width: 0;
  display: grid;
  gap: 0.05rem;
}

.suggestion-copy strong,
.suggestion-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggestion-copy strong {
  font-size: 0.82rem;
}

.suggestion-copy small,
.search-suggestion-empty {
  color: var(--muted);
  font-size: 0.72rem;
}

.search-suggestion-empty {
  padding: 0.65rem 0.8rem;
  font-weight: 800;
}

body[data-page="tree"] .member-card {
  cursor: pointer;
}

.member-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.44);
  backdrop-filter: blur(10px);
  animation: modalFade 170ms ease both;
}

.member-modal-card {
  position: relative;
  width: min(420px, calc(100vw - 2rem));
  border-radius: 28px;
  padding: 1rem;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 183, 3, 0.26), transparent 11rem),
    radial-gradient(circle at 90% 18%, rgba(0, 184, 169, 0.2), transparent 12rem),
    linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(255, 247, 237, 0.95));
  box-shadow: 0 32px 90px rgba(15, 23, 42, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.96);
  animation: modalPop 220ms cubic-bezier(0.2, 0.9, 0.25, 1.1) both;
}

.member-modal-close {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  z-index: 2;
  width: 2.15rem;
  height: 2.15rem;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  color: #ffffff;
  font-size: 1.35rem;
  line-height: 1;
  background: linear-gradient(135deg, #ff4d2e, #ec4899);
  box-shadow: 0 10px 22px rgba(236, 72, 153, 0.25);
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.member-modal-close:hover,
.member-modal-close:focus-visible {
  transform: rotate(4deg) scale(1.05);
  box-shadow: 0 14px 28px rgba(236, 72, 153, 0.3);
  outline: none;
}

.member-detail-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 0.7rem;
  padding: 1.25rem 0.6rem 0.45rem;
  text-align: center;
}

.detail-status-dot {
  position: absolute;
  top: 0.12rem;
  right: 2.95rem;
  width: 0.82rem;
  height: 0.82rem;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.96);
  box-shadow: 0 0 0 5px rgba(15, 23, 42, 0.06), 0 8px 18px rgba(15, 23, 42, 0.16);
}

.detail-status-dot.alive {
  background: #00c853;
}

.detail-status-dot.dead {
  background: #8b95a5;
}

.detail-hero {
  width: 7.2rem;
  height: 7.2rem;
  padding: 0.25rem;
  border-radius: 34px;
  background: linear-gradient(135deg, #ff4d2e, #ffb703, #00b8a9, #6d5dfc);
  box-shadow: 0 18px 36px rgba(109, 93, 252, 0.18);
}

.detail-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 29px;
  display: grid;
  place-items: center;
  border: 3px solid rgba(255, 255, 255, 0.94);
}

.detail-avatar-fallback {
  color: #ffffff;
  font-size: 2rem;
  font-weight: 950;
  background: linear-gradient(135deg, #6d5dfc, #00b8a9);
}

.member-detail-card h2 {
  margin: 0;
  max-width: 100%;
  color: var(--text);
  font-size: clamp(1.45rem, 4vw, 2.1rem);
  line-height: 1.02;
  letter-spacing: -0.04em;
}

.detail-age {
  margin: -0.25rem 0 0;
  padding: 0.38rem 0.75rem;
  color: #ffffff;
  font-size: 0.86rem;
  font-weight: 900;
  border-radius: 999px;
  background: linear-gradient(135deg, #6d5dfc, #3b82f6);
  box-shadow: 0 10px 22px rgba(59, 130, 246, 0.18);
}

.detail-list {
  width: 100%;
  display: grid;
  gap: 0.48rem;
  margin: 0.3rem 0 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 5.1rem 1fr;
  gap: 0.75rem;
  align-items: center;
  padding: 0.58rem 0.72rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid rgba(255, 138, 61, 0.2);
}

.detail-list dt,
.detail-list dd {
  margin: 0;
}

.detail-list dt {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: left;
}

.detail-list dd {
  color: var(--text);
  font-weight: 850;
  text-align: right;
}

@keyframes suggestionDrop {
  from { opacity: 0; transform: translateY(-5px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes modalFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalPop {
  from { opacity: 0; transform: translateY(16px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 600px) {
  .search-suggestions {
    width: calc(100vw - 1rem);
    max-height: 45vh;
  }

  .member-modal-card {
    border-radius: 22px;
    padding: 0.75rem;
  }

  .detail-hero {
    width: 6rem;
    height: 6rem;
    border-radius: 28px;
  }

  .detail-avatar {
    border-radius: 23px;
  }

  .detail-list div {
    grid-template-columns: 1fr;
    gap: 0.16rem;
    text-align: center;
  }

  .detail-list dt,
  .detail-list dd {
    text-align: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .search-suggestions,
  .member-modal,
  .member-modal-card {
    animation: none !important;
  }
}

/* Keep live search results above the family tree canvas. */
body[data-page="tree"] .compact-tree-toolbar {
  position: relative;
  z-index: 3000;
}

body[data-page="tree"] .search-suggestions {
  position: fixed !important;
  top: var(--search-popover-top, 4.5rem) !important;
  left: var(--search-popover-left, 0.75rem) !important;
  z-index: 20000 !important;
  width: var(--search-popover-width, min(460px, calc(100vw - 1rem))) !important;
  max-height: var(--search-popover-max-height, min(360px, 56vh)) !important;
  overflow: auto;
  padding: 0.55rem;
  border: 2px solid transparent;
  border-radius: 20px;
  background:
    linear-gradient(135deg, #ffffff, #f8fbff) padding-box,
    linear-gradient(135deg, #ff4d2e, #6d5dfc 54%, #00b8a9) border-box;
  box-shadow:
    0 30px 80px rgba(15, 23, 42, 0.34),
    0 8px 22px rgba(109, 93, 252, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.98);
  opacity: 1;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  pointer-events: auto;
}

body[data-page="tree"] .search-suggestion {
  background: #ffffff;
  border: 1px solid rgba(109, 93, 252, 0.12);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

body[data-page="tree"] .search-suggestion:hover,
body[data-page="tree"] .search-suggestion:focus-visible {
  background: linear-gradient(135deg, #fff7ed, #eef2ff);
  border-color: rgba(109, 93, 252, 0.32);
}

body[data-page="tree"] .search-suggestion-empty {
  color: #334155;
  background: #ffffff;
  border-radius: 14px;
}
