* {
  box-sizing: border-box;
}

:root {
  --bg: #f6f8fc;
  --card: rgba(255, 255, 255, 0.96);
  --line: #b8c4d6;
  --text: #0f172a;
  --subtext: #64748b;
  --primary: #1d4ed8;

  --male-bg: linear-gradient(180deg, #eef6ff 0%, #dceeff 100%);
  --male-border: #60a5fa;

  --female-bg: linear-gradient(180deg, #fff2f8 0%, #ffe0f0 100%);
  --female-border: #f472b6;

  --dead-male-bg: linear-gradient(180deg, #eef2f7 0%, #dde5ef 100%);
  --dead-female-bg: linear-gradient(180deg, #f6eef2 0%, #ecdee6 100%);
  --dead-border: #94a3b8;

  --shadow: 0 14px 34px rgba(15, 23, 42, 0.08);
  --radius: 20px;
  --gold: #d4a017;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(
    circle at top left,
    #ffffff 0%,
    #eef4ff 28%,
    #f8fafc 100%
  );
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
  font-family: "Inter", sans-serif;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(80px);
  opacity: 0.2;
  z-index: 0;
  pointer-events: none;
}

.orb-1 {
  width: 320px;
  height: 320px;
  background: #93c5fd;
  top: -60px;
  left: -80px;
}

.orb-2 {
  width: 280px;
  height: 280px;
  background: #f9a8d4;
  right: -60px;
  top: 120px;
}

.orb-3 {
  width: 360px;
  height: 360px;
  background: #c4b5fd;
  bottom: -120px;
  left: 20%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(226, 232, 240, 0.9);
  padding: 18px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.04);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
  z-index: 2;
}

.brand-icon {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #1d4ed8 0%, #3b82f6 100%);
  color: white;
  font-size: 24px;
  box-shadow: 0 10px 24px rgba(29, 78, 216, 0.24);
}

.brand h1 {
  margin: 0;
  font-size: 30px;
  font-family: "Cormorant Garamond", serif;
  font-weight: 700;
  color: #0f172a;
  line-height: 1;
}

.brand p {
  margin: 6px 0 0;
  color: var(--subtext);
  font-size: 14px;
  letter-spacing: 0.2px;
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.controls button {
  border: 1px solid rgba(255, 255, 255, 0.7);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.92) 0%,
    rgba(241, 245, 249, 0.95) 100%
  );
  color: #0f172a;
  padding: 11px 15px;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
  transition: 0.2s ease;
}

.controls button i {
  margin-right: 7px;
  color: var(--primary);
}

.controls button:hover {
  transform: translateY(-2px);
  background: white;
}

.main-layout {
  display: flex;
  min-height: calc(100vh - 98px);
  position: relative;
  z-index: 1;
}

.tree-section {
  flex: 1;
  overflow: hidden;
}

.tree-scroll {
  width: 100%;
  height: calc(100vh - 98px);
  overflow: auto;
  padding: 40px 36px 130px;
}

.tree-wrapper {
  min-width: max-content;
  min-height: max-content;
}

.tree {
  display: inline-block;
  transform-origin: top left;
  transition: transform 0.2s ease;
}

/* TREE */
ul {
  position: relative;
  padding-top: 48px;
  white-space: nowrap;
}

li {
  list-style-type: none;
  position: relative;
  padding: 48px 18px 0 18px;
  text-align: center;
  float: left;
}

li::before,
li::after {
  content: "";
  position: absolute;
  top: 0;
  right: 50%;
  border-top: 2px solid var(--line);
  width: 50%;
  height: 48px;
}

li::after {
  right: auto;
  left: 50%;
  border-left: 2px solid var(--line);
}

li:only-child::before,
li:only-child::after {
  display: none;
}

li:only-child {
  padding-top: 0;
}

li:first-child::before,
li:last-child::after {
  border: 0 none;
}

li:last-child::before {
  border-right: 2px solid var(--line);
  border-radius: 0 14px 0 0;
}

li:first-child::after {
  border-radius: 14px 0 0 0;
}

ul ul::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  border-left: 2px solid var(--line);
  width: 0;
  height: 48px;
}

.tree ul::after {
  content: "";
  display: block;
  clear: both;
}

/* PERSON CARD */
.person {
  display: inline-block;
  min-width: 170px;
  max-width: 190px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 2px solid;
  background: var(--card);
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  transition: 0.22s ease;
  position: relative;
  backdrop-filter: blur(8px);
  overflow: hidden;
}

.person:hover {
  transform: translateY(-3px) scale(1.01);
  box-shadow: 0 18px 38px rgba(15, 23, 42, 0.12);
}

.person::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    circle at top right,
    rgba(255, 255, 255, 0.42),
    transparent 42%
  );
  pointer-events: none;
}

.person::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.male {
  background: var(--male-bg);
  border-color: var(--male-border);
}

.female {
  background: var(--female-bg);
  border-color: var(--female-border);
}

.dead-male {
  background: var(--dead-male-bg) !important;
  border-color: var(--dead-border) !important;
}

.dead-female {
  background: var(--dead-female-bg) !important;
  border-color: var(--dead-border) !important;
}

.top-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-icon {
  width: 38px;
  height: 38px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 17px;
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.male .avatar-icon {
  background: rgba(37, 99, 235, 0.12);
  color: #2563eb;
}

.female .avatar-icon {
  background: rgba(219, 39, 119, 0.12);
  color: #db2777;
}

.dead-male .avatar-icon,
.dead-female .avatar-icon {
  background: rgba(71, 85, 105, 0.1) !important;
  color: #334155 !important;
}

.person-main {
  flex: 1;
  text-align: left;
  min-width: 0;
}

.name {
  font-size: 15px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.35;
  margin: 0;
  word-break: break-word;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.mini-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 800;
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
  color: #334155;
  border: 1px solid rgba(255, 255, 255, 0.7);
}

.dead-badge-male {
  background: rgba(51, 65, 85, 0.08);
  color: #334155;
  border: 1px solid rgba(51, 65, 85, 0.14);
}

.dead-badge-female {
  background: rgba(131, 24, 67, 0.08);
  color: #831843;
  border: 1px solid rgba(131, 24, 67, 0.14);
}

/* SIDEBAR */
.sidebar {
  width: 360px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
  border-left: 1px solid rgba(226, 232, 240, 0.9);
  padding: 24px;
  overflow-y: auto;
  box-shadow: -14px 0 36px rgba(15, 23, 42, 0.08);
}

.sidebar.hidden {
  display: none;
}

.sidebar-mini {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
}

.sidebar h2 {
  margin: 0;
  font-size: 28px;
  font-family: "Cormorant Garamond", serif;
  color: #0f172a;
}

.detail-card {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.96) 0%,
    rgba(248, 250, 252, 0.96) 100%
  );
  border: 1px solid #e2e8f0;
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.06);
}

.detail-top {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.detail-avatar {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 24px;
  flex-shrink: 0;
}

.detail-card h3 {
  margin: 0;
  font-size: 26px;
  color: #0f172a;
  line-height: 1.2;
}

.detail-sub {
  color: #64748b;
  font-weight: 600;
  margin-top: 6px;
  font-size: 14px;
}

.detail-grid {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.detail-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 14px 15px;
}

.detail-label {
  font-size: 12px;
  font-weight: 800;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 6px;
}

.detail-value {
  font-size: 15px;
  font-weight: 700;
  color: #0f172a;
}

.close-btn {
  border: none;
  background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%);
  color: white;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  box-shadow: 0 10px 24px rgba(220, 38, 38, 0.24);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 12px;
}

.badge.male-badge {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge.female-badge {
  background: #fce7f3;
  color: #be185d;
}

.badge.dead-male-badge {
  background: rgba(51, 65, 85, 0.08);
  color: #334155;
}

.badge.dead-female-badge {
  background: rgba(131, 24, 67, 0.08);
  color: #831843;
}

@media (max-width: 1100px) {
  .main-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -12px 32px rgba(15, 23, 42, 0.06);
  }

  .tree-scroll {
    height: auto;
    min-height: 65vh;
  }

  html,
  body {
    overflow: auto;
  }
}
