
:root {
  --paper: #efe4c5;
  --paper-light: #f8f0da;
  --paper-deep: #decba1;
  --ink: #3b2d20;
  --ink-soft: #6e5b43;
  --leather: #593c27;
  --leather-dark: #382419;
  --brass: #9b7336;
  --brass-light: #c7a35c;
  --patina: #48665d;
  --patina-light: #71877c;
  --male-accent: #416675;
  --male-soft: #d9e2dc;
  --female-accent: #8b4f5c;
  --female-soft: #ead1cb;
  --line: #8c7655;
  --danger: #8d2f27;
  --cream: #fffaf0;
  --shadow: 0 18px 55px rgba(69, 48, 28, .22);
  --node-font-size: 31px;
  --font-main: "Amiri", "Noto Naskh Arabic", "IBM Plex Sans Arabic", "Noto Sans Arabic", Tahoma, serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; }

body {
  font-family: var(--font-main);
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 8%, rgba(255,255,255,.48), transparent 30rem),
    radial-gradient(circle at 86% 90%, rgba(89,60,39,.12), transparent 32rem),
    repeating-linear-gradient(0deg, rgba(91,68,41,.025) 0 1px, transparent 1px 4px),
    linear-gradient(135deg, var(--paper-light), var(--paper));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .24;
  z-index: 999;
  background:
    radial-gradient(circle at 20% 25%, rgba(75,49,28,.22) 0 1px, transparent 1.5px),
    radial-gradient(circle at 70% 65%, rgba(75,49,28,.18) 0 1px, transparent 1.5px);
  background-size: 13px 15px, 17px 19px;
  mix-blend-mode: multiply;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.site-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.masthead {
  position: relative;
  z-index: 20;
  min-height: 88px;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background:
    linear-gradient(180deg, rgba(255,250,240,.96), rgba(239,228,197,.92)),
    var(--paper-light);
  border-bottom: 1px solid rgba(91,60,39,.22);
  box-shadow: 0 8px 30px rgba(69,48,28,.12);
}

.masthead::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -3px;
  left: 0;
  height: 6px;
  background: repeating-linear-gradient(90deg, var(--brass) 0 28px, transparent 28px 42px);
  opacity: .55;
}

.brand {
  display: flex;
  align-items: center;
  gap: 15px;
  min-width: 290px;
}

.logo-frame {
  width: 88px;
  height: 68px;
  border-radius: 16px 16px 28px 28px;
  padding: 4px;
  background: linear-gradient(145deg, var(--brass-light), var(--leather));
  box-shadow:
    0 8px 20px rgba(69,48,28,.25),
    inset 0 0 0 1px rgba(255,255,255,.45);
  overflow: hidden;
  flex: 0 0 auto;
}

.logo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px 12px 24px 24px;
  filter: sepia(.18) saturate(.82) contrast(1.04);
  display: block;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: .1px;
}

.brand-subtitle {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.55;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.control,
.button {
  border: 1px solid rgba(89,60,39,.25);
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255,255,255,.88), rgba(239,228,197,.74));
  border-radius: 12px;
  padding: 10px 13px;
  box-shadow: 0 4px 12px rgba(69,48,28,.08);
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.control:hover,
.button:hover {
  transform: translateY(-2px);
  border-color: var(--brass);
  box-shadow: 0 8px 18px rgba(69,48,28,.14);
}

.button.primary {
  color: #fffaf0;
  border-color: var(--leather-dark);
  background: linear-gradient(145deg, var(--leather), var(--leather-dark));
}

.button.secondary {
  color: var(--cream);
  border-color: #344e47;
  background: linear-gradient(145deg, var(--patina-light), var(--patina));
}

.button.danger {
  color: var(--danger);
  border-color: rgba(141,47,39,.35);
  background: #fff5ef;
}

.button.small { padding: 7px 10px; font-size: 12px; }

.back-home {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  border: 1px solid rgba(89,60,39,.25);
  color: var(--ink);
  background: linear-gradient(180deg, rgba(255,255,255,.88), rgba(239,228,197,.74));
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(69,48,28,.08);
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.back-home:hover {
  transform: translateY(-2px);
  border-color: var(--brass);
  box-shadow: 0 8px 18px rgba(69,48,28,.14);
}
.back-home__icon { font-size: 17px; color: var(--brass); line-height: 1; }
@media (max-width: 560px) { .back-home__text { display: none; } }

.search-wrap {
  position: relative;
  width: min(320px, 38vw);
}

.search-wrap input {
  width: 100%;
  padding: 11px 41px 11px 14px;
  border: 1px solid rgba(89,60,39,.28);
  border-radius: 13px;
  color: var(--ink);
  background: rgba(255,250,240,.9);
  outline: none;
  box-shadow: inset 0 1px 5px rgba(69,48,28,.08);
}

.search-wrap input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(155,115,54,.16);
}

.search-icon {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-soft);
}

/* Viewer */
.viewer-workspace {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

#treeSvg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  background:
    linear-gradient(rgba(91,60,39,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91,60,39,.035) 1px, transparent 1px),
    radial-gradient(circle at center, rgba(255,255,255,.28), transparent 52%);
  background-size: 34px 34px, 34px 34px, auto;
}

#treeSvg.dragging { cursor: grabbing; }

.tree-link {
  fill: none;
  stroke: var(--line);
  stroke-width: 2.2;
  vector-effect: non-scaling-stroke;
  opacity: .88;
}

.tree-node {
  cursor: pointer;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  transition: opacity .55s ease, filter .22s ease;
}

.tree-node.revealed { opacity: 1; }

.tree-card {
  fill: url(#paperCardGradient);
  stroke: rgba(89,60,39,.37);
  stroke-width: 1.6;
  filter: url(#nodeShadow);
  transition: stroke .2s ease, stroke-width .2s ease, filter .2s ease;
}

.tree-node.gender-male .tree-card {
  fill: url(#maleCardGradient);
  stroke: rgba(65,102,117,.72);
}

.tree-node.gender-female .tree-card {
  fill: url(#femaleCardGradient);
  stroke: rgba(139,79,92,.72);
}

.gender-marker {
  stroke: var(--paper-light);
  stroke-width: 1.5;
  pointer-events: none;
}
.tree-node.gender-male .gender-marker { fill: var(--male-accent); }
.tree-node.gender-female .gender-marker { fill: var(--female-accent); }
.tree-node.gender-unknown .gender-marker { fill: var(--brass); }
.gender-marker-text {
  fill: #fffaf0;
  font-family: var(--font-main);
  font-size: 16px;
  font-weight: 800;
  pointer-events: none;
}

.gender-legend {
  position: absolute;
  z-index: 7;
  top: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid rgba(89,60,39,.2);
  border-radius: 13px;
  background: rgba(255,250,240,.9);
  box-shadow: 0 8px 24px rgba(69,48,28,.13);
  backdrop-filter: blur(7px);
  font-size: 11px;
}
.gender-legend-title { color: var(--ink-soft); font-weight: 700; }
.gender-chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 7px; border-radius: 999px; font-weight: 800; }
.gender-chip.male { color: #294d5c; background: rgba(65,102,117,.13); }
.gender-chip.female { color: #713744; background: rgba(139,79,92,.13); }
.gender-chip.male-only { color: var(--leather); background: rgba(199,163,92,.2); }
.gender-legend.male-only-mode .gender-chip.female { display: none; }

.tree-node:hover .tree-card,
.tree-node:focus .tree-card {
  stroke: var(--brass);
  stroke-width: 3;
  filter: url(#nodeHoverShadow);
}

.tree-node.selected .tree-card {
  stroke: var(--patina);
  stroke-width: 4;
}

.tree-node.search-hit .tree-card {
  stroke: #b14b2f;
  stroke-width: 4;
}

.node-name {
  fill: var(--ink);
  font-family: var(--font-main);
  font-size: var(--node-font-size);
  font-weight: 800;
  pointer-events: none;
}

.node-birth {
  fill: var(--ink-soft);
  font-family: var(--font-main);
  font-size: 13px;
  pointer-events: none;
}

.info-pill {
  fill: rgba(72,102,93,.11);
  stroke: rgba(72,102,93,.35);
  stroke-width: 1;
}

.info-pill-text {
  fill: var(--patina);
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
}

.generation-badge {
  fill: rgba(199,163,92,.18);
  stroke: rgba(155,115,54,.48);
}

.generation-text {
  fill: var(--leather);
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
}

.toggle-circle {
  fill: var(--leather);
  stroke: var(--paper-light);
  stroke-width: 2;
}

.toggle-text {
  fill: var(--paper-light);
  font-family: var(--font-main);
  font-size: 19px;
  font-weight: 800;
  pointer-events: none;
}

.unplaced-heading {
  fill: var(--leather);
  font-family: var(--font-main);
  font-size: 18px;
  font-weight: 800;
}

.unplaced-note {
  fill: var(--ink-soft);
  font-family: var(--font-main);
  font-size: 12px;
}

.details-panel {
  position: absolute;
  left: 20px;
  top: 20px;
  z-index: 9;
  width: min(430px, calc(100% - 40px));
  max-height: calc(100% - 40px);
  overflow: auto;
  padding: 22px;
  border: 1px solid rgba(89,60,39,.27);
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255,250,240,.97), rgba(239,228,197,.95));
  box-shadow: var(--shadow);
  transform: translateX(calc(-100% - 36px)) rotate(-1deg);
  transition: transform .34s cubic-bezier(.2,.8,.2,1);
}

.details-panel.open { transform: translateX(0) rotate(0deg); }

.details-panel::before,
.paper-card::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(155,115,54,.28);
  border-radius: 14px;
  pointer-events: none;
}

.panel-close {
  position: absolute;
  left: 13px;
  top: 13px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  color: var(--cream);
  background: var(--leather);
}

.details-panel h2 {
  margin: 2px 0 6px;
  padding-left: 38px;
  text-align: center;
  font-size: 25px;
}

.details-lineage {
  text-align: center;
  color: var(--patina);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.8;
  margin-bottom: 18px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 12px 14px;
  line-height: 1.7;
  font-size: 14px;
}

.detail-label { color: var(--ink-soft); font-weight: 700; }
.detail-value { font-weight: 650; word-break: break-word; }

.viewer-hint {
  position: absolute;
  right: 20px;
  bottom: 18px;
  z-index: 6;
  padding: 10px 13px;
  border-radius: 12px;
  color: var(--cream);
  background: rgba(56,36,25,.9);
  box-shadow: var(--shadow);
  font-size: 12px;
}

.intro-veil {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at center, rgba(255,255,255,.28), transparent 50%),
    linear-gradient(145deg, #f8efd5, #d6c08c);
  transition: opacity .9s ease, visibility .9s ease;
}

.intro-veil.done {
  opacity: 0;
  visibility: hidden;
}

.intro-card {
  width: min(680px, calc(100% - 38px));
  max-height: calc(100vh - 36px);
  overflow: auto;
  text-align: center;
  padding: 30px 34px;
  border: 1px solid rgba(89,60,39,.28);
  border-radius: 28px;
  background: rgba(255,250,240,.8);
  box-shadow: var(--shadow);
  animation: introFloat 1.8s ease-in-out infinite alternate;
}

.intro-logo {
  width: 220px;
  max-width: 70vw;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 22px 22px 42px 42px;
  border: 5px solid var(--brass-light);
  box-shadow: 0 15px 35px rgba(69,48,28,.27);
  filter: sepia(.12) saturate(.9);
}

.intro-kicker { margin-top: 18px; color: var(--brass-dark); font-size: 12px; font-weight: 800; letter-spacing: .08em; }
.intro-title { margin: 5px 0 10px; font-size: clamp(28px, 5vw, 40px); }
.intro-copy { color: var(--ink-soft); font-size: 16px; line-height: 2; text-align: right; white-space: pre-line; max-width: 58ch; margin: 0 auto; }
.intro-admin-textarea { min-height: 180px; }

@keyframes introFloat {
  from { transform: translateY(4px) scale(.99); }
  to { transform: translateY(-5px) scale(1.01); }
}

/* Admin auth */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  position: relative;
  width: min(520px, 100%);
  padding: 28px;
  border-radius: 24px;
  border: 1px solid rgba(89,60,39,.28);
  background: linear-gradient(180deg, rgba(255,250,240,.97), rgba(239,228,197,.96));
  box-shadow: var(--shadow);
}

.auth-card::before {
  content: "";
  position: absolute;
  inset: 9px;
  border: 1px solid rgba(155,115,54,.28);
  border-radius: 17px;
  pointer-events: none;
}

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

.auth-logo {
  width: 105px;
  height: 80px;
  object-fit: cover;
  border-radius: 15px 15px 30px 30px;
  border: 3px solid var(--brass-light);
}

.auth-head h1 { margin: 0 0 5px; font-size: 23px; }
.auth-head p { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.6; }

.auth-message {
  display: none;
  margin: 0 0 13px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--danger);
  background: rgba(141,47,39,.08);
  border: 1px solid rgba(141,47,39,.22);
  font-size: 13px;
}

.auth-message.show { display: block; }

/* Admin app */
.admin-page {
  min-height: 100vh;
  overflow: auto;
}

.admin-layout {
  max-width: 1580px;
  margin: 0 auto;
  padding: 18px;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.admin-tab {
  border: 1px solid rgba(89,60,39,.25);
  background: rgba(255,250,240,.72);
  color: var(--ink);
  border-radius: 12px 12px 4px 4px;
  padding: 11px 16px;
}

.admin-tab.active {
  color: var(--cream);
  background: var(--leather);
  border-color: var(--leather);
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(310px, 390px) 1fr;
  gap: 18px;
}

.paper-card {
  position: relative;
  border: 1px solid rgba(89,60,39,.26);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255,250,240,.96), rgba(239,228,197,.93));
  box-shadow: var(--shadow);
}

.member-panel {
  height: calc(100vh - 175px);
  min-height: 520px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  overflow: hidden;
}

.panel-heading {
  padding: 18px 18px 12px;
  border-bottom: 1px solid rgba(89,60,39,.14);
}

.panel-heading h2 { margin: 0 0 5px; font-size: 19px; }
.panel-heading p { margin: 0; color: var(--ink-soft); font-size: 12px; line-height: 1.55; }

.member-actions {
  padding: 12px 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-bottom: 1px solid rgba(89,60,39,.14);
}

.member-list {
  position: relative;
  z-index: 2;
  overflow: auto;
  padding: 10px;
}

.branch-label {
  margin: 8px 0;
  padding: 9px 11px;
  border-radius: 11px;
  color: var(--leather);
  background: rgba(199,163,92,.18);
  font-size: 13px;
  font-weight: 800;
}

.member-row {
  width: 100%;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: right;
  padding: 9px 10px;
  margin-bottom: 3px;
}

.member-row:hover { background: rgba(199,163,92,.14); }
.member-row.active { color: var(--cream); background: var(--leather); }
.member-row small { opacity: .7; }

.editor-panel {
  min-height: calc(100vh - 175px);
  padding: 22px;
}

.editor-empty {
  min-height: 430px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--ink-soft);
}

.editor-empty strong {
  display: block;
  color: var(--ink);
  font-size: 22px;
  margin-bottom: 7px;
}

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 15px;
  padding-bottom: 15px;
  margin-bottom: 18px;
  border-bottom: 1px solid rgba(89,60,39,.16);
}

.editor-header h2 { margin: 0 0 4px; font-size: 23px; }
.editor-header p { margin: 0; color: var(--ink-soft); font-size: 13px; }

.notice {
  padding: 11px 13px;
  margin-bottom: 16px;
  border: 1px solid rgba(72,102,93,.25);
  border-radius: 11px;
  color: #354e47;
  background: rgba(72,102,93,.08);
  font-size: 12px;
  line-height: 1.65;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.field { display: flex; flex-direction: column; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 800; }
.field small { color: var(--ink-soft); font-size: 11px; line-height: 1.5; }

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid rgba(89,60,39,.27);
  border-radius: 11px;
  outline: none;
  color: var(--ink);
  background: rgba(255,250,240,.9);
}

.field textarea {
  min-height: 125px;
  resize: vertical;
  line-height: 1.7;
}

.form-footer {
  margin-top: 20px;
  padding-top: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 1px solid rgba(89,60,39,.16);
}

.button-group { display: flex; gap: 8px; flex-wrap: wrap; }
.path-note { color: var(--ink-soft); font-size: 12px; }

/* Visual admin graph */
.graph-layout {
  display: grid;
  grid-template-columns: 1fr 330px;
  gap: 18px;
}

.graph-card {
  min-height: calc(100vh - 175px);
  overflow: hidden;
}

.graph-toolbar {
  position: relative;
  z-index: 4;
  padding: 13px 15px;
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  border-bottom: 1px solid rgba(89,60,39,.16);
  background: rgba(255,250,240,.78);
}

.range-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 11px;
  border: 1px solid rgba(89,60,39,.22);
  background: rgba(255,250,240,.72);
  font-size: 12px;
}

.range-wrap input { accent-color: var(--leather); }

.graph-scroll {
  height: calc(100vh - 244px);
  min-height: 480px;
  overflow: auto;
  position: relative;
  background:
    linear-gradient(rgba(89,60,39,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(89,60,39,.04) 1px, transparent 1px),
    radial-gradient(circle at center, rgba(255,255,255,.2), transparent 60%);
  background-size: 38px 38px, 38px 38px, auto;
}

.graph-board {
  position: relative;
  min-width: 1800px;
  min-height: 1100px;
}

.graph-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.member-row.gender-male { border-right: 4px solid var(--male-accent); }
.member-row.gender-female { border-right: 4px solid var(--female-accent); }
.member-gender-icon { display: inline-block; width: 20px; margin-left: 4px; text-align: center; }
.member-row.gender-male .member-gender-icon { color: var(--male-accent); }
.member-row.gender-female .member-gender-icon { color: var(--female-accent); }
.member-row.active .member-gender-icon { color: inherit; }

.graph-line {
  fill: none;
  stroke: var(--line);
  stroke-width: 2;
}

.graph-node {
  position: absolute;
  width: 190px;
  min-height: 76px;
  padding: 13px 12px 10px;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(89,60,39,.34);
  border-radius: 15px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255,250,240,.98), rgba(239,228,197,.96));
  box-shadow: 0 10px 22px rgba(69,48,28,.15);
  text-align: center;
  user-select: none;
  touch-action: none;
  cursor: grab;
  transition: border-color .18s ease, box-shadow .18s ease, transform .12s ease;
}

.graph-node.gender-male { border-color: rgba(65,102,117,.72); background: linear-gradient(180deg, #f6f4e9, #d9e2dc); }
.graph-node.gender-female { border-color: rgba(139,79,92,.72); background: linear-gradient(180deg, #fff6ef, #ead1cb); }
.graph-gender-icon { display: inline-block; margin-left: 6px; font-size: .72em; opacity: .86; }

.graph-node:hover {
  border-color: var(--brass);
  box-shadow: 0 14px 26px rgba(69,48,28,.2);
}

.graph-node.active {
  border-color: var(--patina);
  box-shadow: 0 0 0 4px rgba(72,102,93,.12), 0 14px 28px rgba(69,48,28,.2);
}

.graph-node.drop-target {
  border-color: #8d2f27;
  box-shadow: 0 0 0 5px rgba(141,47,39,.13);
}

.graph-node.dragging {
  cursor: grabbing;
  z-index: 20;
  transform: translate(-50%, -50%) scale(1.04);
}

.graph-node-name {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.35;
}

.graph-node-caption {
  margin-top: 5px;
  color: var(--ink-soft);
  font-size: 10px;
}

.graph-section-label {
  position: absolute;
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--leather);
  background: rgba(199,163,92,.17);
  font-size: 13px;
  font-weight: 800;
}

.graph-inspector {
  min-height: calc(100vh - 175px);
  padding: 19px;
}

.graph-inspector h2 { margin: 0 0 5px; font-size: 20px; }
.graph-inspector p { margin: 0 0 16px; color: var(--ink-soft); font-size: 12px; line-height: 1.6; }

.status-toast {
  position: fixed;
  z-index: 1200;
  bottom: 20px;
  left: 50%;
  transform: translate(-50%, 120px);
  padding: 11px 17px;
  border-radius: 12px;
  color: var(--cream);
  background: var(--leather-dark);
  box-shadow: var(--shadow);
  font-size: 13px;
  transition: transform .25s ease;
}

.status-toast.show { transform: translate(-50%, 0); }

.security-note {
  padding: 11px 13px;
  border-radius: 11px;
  background: rgba(155,115,54,.12);
  border: 1px solid rgba(155,115,54,.25);
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.65;
  margin-top: 14px;
}

@media (max-width: 980px) {
  .masthead { align-items: flex-start; flex-direction: column; }
  .toolbar { width: 100%; justify-content: flex-start; }
  .search-wrap { width: min(100%, 420px); flex: 1; }
  .viewer-workspace { height: calc(100vh - 180px); }
  .admin-grid,
  .graph-layout { grid-template-columns: 1fr; }
  .member-panel { height: 440px; min-height: 440px; }
  .editor-panel,
  .graph-card,
  .graph-inspector { min-height: auto; }
  .graph-scroll { height: 620px; }
}

@media (max-width: 650px) {
  .brand { min-width: 0; }
  .logo-frame { width: 75px; height: 59px; }
  .brand h1 { font-size: 19px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .details-panel { left: 12px; top: 12px; width: calc(100% - 24px); }
  .viewer-hint { display: none; }
  .detail-grid { grid-template-columns: 94px 1fr; }
  .auth-head { align-items: flex-start; }
  .auth-logo { width: 86px; height: 66px; }
}

/* PHP administration additions */
.inline-form { display: inline-flex; margin: 0; }

.content-settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr);
  gap: 18px;
}

.settings-card {
  padding: 22px;
  min-height: 520px;
}

.settings-card .panel-heading {
  margin: -22px -22px 20px;
  position: relative;
  z-index: 2;
}

.compact-textarea { min-height: 88px !important; }

.setting-range {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 190px 1fr;
  align-items: center;
  gap: 18px;
  padding: 17px 0;
  border-bottom: 1px solid rgba(89,60,39,.14);
}

.setting-range label {
  display: block;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.setting-range small {
  display: block;
  margin-top: 5px;
  color: var(--ink-soft);
  font-size: 11px;
}

.setting-range input[type="range"] {
  width: 100%;
  accent-color: var(--leather);
}

.check-row {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 13px 14px;
  border: 1px solid rgba(89,60,39,.18);
  border-radius: 12px;
  background: rgba(255,250,240,.54);
  font-size: 13px;
  font-weight: 700;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--leather);
}

@media (max-width: 1050px) {
  .content-settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 650px) {
  .setting-range { grid-template-columns: 1fr; gap: 9px; }
}

/* ==================================================================
   تحديثات النسخة الثانية
   خطوط، وضع ليلي، أدوات تكبير، بحث متعدد النتائج، ودعم كامل للجوال
   ================================================================== */

:root {
  /* خط العناوين وأسماء البطاقات: نسخي دافئ يناسب طابع الأسرة */
  --font-display: "Amiri", "Noto Naskh Arabic", Tahoma, serif;
  /* خط الواجهة: أوضح في الأحجام الصغيرة */
  --font-main: "Amiri", "Noto Naskh Arabic", "IBM Plex Sans Arabic", "Noto Sans Arabic", Tahoma, serif;

  --card-top: #fffaf0;
  --card-bottom: #eadab7;
  --card-stroke: rgba(89,60,39,.37);
  --panel-bg: linear-gradient(180deg, rgba(255,250,240,.97), rgba(239,228,197,.95));
  --surface-bg: linear-gradient(180deg, rgba(255,255,255,.88), rgba(239,228,197,.74));
  --grain-opacity: .16;
  --tap: 44px;
}

body::before { opacity: var(--grain-opacity); }

.site-shell { min-height: 100vh; min-height: 100dvh; }

h1, h2, .intro-title, .details-panel h2 { font-family: var(--font-display); }

.card-stop-top { stop-color: var(--card-top); }
.card-stop-bottom { stop-color: var(--card-bottom); }
.tree-card { fill: url(#paperCardGradient); stroke: var(--card-stroke); }
.node-name { font-family: var(--font-display); font-weight: 700; }

/* طبقة القياس المخفية المستخدمة لحساب عرض البطاقات */
#measureLayer { visibility: hidden; pointer-events: none; }

/* ---------- الصور الشخصية ---------- */
.avatar-ring {
  fill: none;
  stroke: var(--brass);
  stroke-width: 2.4;
  opacity: .75;
}

.details-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  padding-left: 38px;
}

.details-head > div { flex: 1; min-width: 0; }
.details-head h2 { margin: 0 0 4px; padding-left: 0; text-align: right; font-size: 24px; }
.details-head .details-lineage { margin-bottom: 0; text-align: right; }

.detail-photo {
  width: 76px;
  height: 76px;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--brass);
  box-shadow: 0 6px 16px rgba(69,48,28,.28);
}

/* ---------- زر الوضع الليلي ---------- */
.theme-toggle {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  align-self: flex-start;
  margin-top: 4px;
  border: 1px solid rgba(89,60,39,.25);
  border-radius: 11px;
  font-size: 17px;
  line-height: 1;
  color: var(--ink);
  background: var(--surface-bg);
  transition: transform .18s ease, border-color .18s ease;
}

.theme-toggle:hover { transform: translateY(-2px); border-color: var(--brass); }
.brand-text { min-width: 0; }

/* ---------- تنقّل نتائج البحث ---------- */
.search-wrap { display: flex; align-items: center; }
.search-wrap input { padding-left: 74px; }

.search-nav {
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
}

.search-nav[hidden] { display: none; }

.search-count {
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 0 3px;
}

.search-nav button {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid rgba(89,60,39,.2);
  border-radius: 7px;
  font-size: 10px;
  line-height: 1;
  color: var(--ink);
  background: rgba(255,250,240,.9);
}

.search-nav button:hover { border-color: var(--brass); }

/* ---------- أدوات التكبير ---------- */
.zoom-controls {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.zoom-controls button {
  width: var(--tap);
  height: var(--tap);
  border: 1px solid rgba(89,60,39,.26);
  border-radius: 13px;
  font-size: 18px;
  line-height: 1;
  color: var(--ink);
  background: var(--surface-bg);
  box-shadow: 0 6px 16px rgba(69,48,28,.16);
  -webkit-tap-highlight-color: transparent;
}

.zoom-controls button:hover { border-color: var(--brass); }
.zoom-controls button:active { transform: scale(.94); }

/* ---------- البطاقات ---------- */
#treeSvg { touch-action: none; -webkit-tap-highlight-color: transparent; }
.node-toggle { cursor: pointer; }
.toggle-hit { fill: transparent; }
.toggle-text { font-size: 16px; }

.tree-node.search-other .tree-card {
  stroke: #c08a4a;
  stroke-width: 2.6;
  stroke-dasharray: 7 5;
}

.tree-node:focus { outline: none; }
.tree-node:focus-visible .tree-card { stroke: var(--patina); stroke-width: 4; }

/* ---------- زر تخطي المقدمة ---------- */
.intro-skip {
  margin-top: 22px;
  padding: 9px 18px;
  border: 1px solid rgba(199,163,92,.5);
  border-radius: 12px;
  color: var(--cream);
  font-size: 13px;
  background: rgba(255,255,255,.08);
}

.intro-skip:hover { border-color: var(--brass-light); background: rgba(255,255,255,.16); }

/* ---------- مقبض اللوحة على الجوال ---------- */
.panel-grip { display: none; }

/* ==================================================================
   الجوال واللمس
   ================================================================== */
@media (pointer: coarse) {
  .control,
  .button { min-height: var(--tap); }
  .search-wrap input { min-height: var(--tap); }
  .search-nav button { width: 30px; height: 30px; font-size: 12px; }
}

@media (max-width: 980px) {
  .viewer-workspace { height: auto; }
}

@media (max-width: 760px) {
  body::before { display: none; }

  .masthead {
    min-height: 0;
    padding: 9px 12px calc(9px + env(safe-area-inset-bottom, 0px));
    gap: 9px;
  }

  .brand { gap: 10px; min-width: 0; width: 100%; align-items: flex-start; }
  .logo-frame { width: 52px; height: 42px; border-radius: 11px 11px 18px 18px; }
  .brand h1 { font-size: 17px; }
  .brand-subtitle { font-size: 11px; -webkit-line-clamp: 2; }

  .toolbar {
    width: 100%;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 7px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar .control,
  .toolbar .button { flex: 0 0 auto; font-size: 13px; padding: 9px 12px; }

  .search-wrap { width: auto; flex: 1 1 190px; min-width: 170px; }
  .viewer-hint { display: none; }

  .zoom-controls {
    left: 12px;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }

  /* لوحة المعلومات تصبح ورقة تنزلق من الأسفل */
  .details-panel {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    max-height: 62dvh;
    padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0px));
    border-radius: 22px 22px 0 0;
    border-width: 1px 0 0;
    transform: translateY(105%) rotate(0deg);
    transition: transform .3s cubic-bezier(.2,.8,.2,1);
    overscroll-behavior: contain;
  }

  .details-panel.open { transform: translateY(0); }
  .details-panel::before { inset: 10px 7px 7px; border-radius: 16px; }

  .panel-grip {
    display: block;
    width: 44px;
    height: 4px;
    margin: 4px auto 12px;
    border-radius: 99px;
    background: rgba(89,60,39,.3);
  }

  .panel-close {
    left: 10px;
    top: 14px;
    width: var(--tap);
    height: var(--tap);
    border-radius: 12px;
    font-size: 20px;
  }

  .details-head { padding-left: 50px; gap: 11px; }
  .details-head h2 { font-size: 20px; }
  .detail-photo { width: 60px; height: 60px; }
  .detail-grid { grid-template-columns: 92px 1fr; gap: 9px 11px; font-size: 13.5px; }
}

@media (max-width: 420px) {
  .brand-subtitle { display: none; }
  .toolbar .control { font-size: 12px; padding: 9px 10px; }
}

/* ==================================================================
   الوضع الليلي
   ================================================================== */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) { color-scheme: dark; }
}

[data-theme="dark"] {
  --paper: #2a2018;
  --paper-light: #33271d;
  --paper-deep: #1d1610;
  --ink: #f2e5cd;
  --ink-soft: #b9a482;
  --leather: #8a6136;
  --leather-dark: #5d4023;
  --brass: #c9a469;
  --brass-light: #e0c391;
  --patina: #8fb3a6;
  --patina-light: #6f9186;
  --line: #7d6849;
  --cream: #fdf6e6;
  --danger: #e08b7f;

  --card-top: #40311f;
  --card-bottom: #2f2418;
  --card-stroke: rgba(226,199,150,.35);
  --panel-bg: linear-gradient(180deg, rgba(52,40,29,.98), rgba(36,27,19,.97));
  --surface-bg: linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.03));
  --grain-opacity: .08;
  --shadow: 0 18px 55px rgba(0,0,0,.5);

  color-scheme: dark;
}

[data-theme="dark"] body {
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 8%, rgba(201,164,105,.10), transparent 30rem),
    radial-gradient(circle at 86% 90%, rgba(0,0,0,.35), transparent 32rem),
    linear-gradient(135deg, #2b2118, #1c1510);
}

[data-theme="dark"] .masthead {
  background: linear-gradient(180deg, rgba(58,45,32,.97), rgba(38,29,20,.95));
  border-bottom-color: rgba(226,199,150,.18);
}

[data-theme="dark"] #treeSvg {
  background:
    linear-gradient(rgba(226,199,150,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(226,199,150,.05) 1px, transparent 1px),
    radial-gradient(circle at center, rgba(255,235,200,.05), transparent 55%);
  background-size: 34px 34px, 34px 34px, auto;
}

[data-theme="dark"] .control,
[data-theme="dark"] .button,
[data-theme="dark"] .theme-toggle,
[data-theme="dark"] .zoom-controls button {
  color: var(--ink);
  border-color: rgba(226,199,150,.24);
  background: var(--surface-bg);
}

[data-theme="dark"] .button.primary {
  color: #1c1510;
  border-color: var(--brass);
  background: linear-gradient(145deg, var(--brass-light), var(--brass));
}

[data-theme="dark"] .button.danger { color: var(--danger); background: rgba(224,139,127,.1); }

[data-theme="dark"] .search-wrap input,
[data-theme="dark"] .search-nav button,
[data-theme="dark"] .field input,
[data-theme="dark"] .field select,
[data-theme="dark"] .field textarea {
  color: var(--ink);
  border-color: rgba(226,199,150,.22);
  background: rgba(255,255,255,.05);
}

[data-theme="dark"] .details-panel,
[data-theme="dark"] .paper-card,
[data-theme="dark"] .auth-card {
  color: var(--ink);
  border-color: rgba(226,199,150,.2);
  background: var(--panel-bg);
}

[data-theme="dark"] .details-panel::before,
[data-theme="dark"] .paper-card::before { border-color: rgba(226,199,150,.18); }

[data-theme="dark"] .info-pill { fill: rgba(143,179,166,.14); stroke: rgba(143,179,166,.4); }
[data-theme="dark"] .generation-badge { fill: rgba(201,164,105,.16); stroke: rgba(201,164,105,.45); }
[data-theme="dark"] .generation-text { fill: var(--brass-light); }
[data-theme="dark"] .toggle-circle { fill: var(--brass); stroke: #2b2118; }
[data-theme="dark"] .toggle-text { fill: #221a12; }
[data-theme="dark"] .tree-node.search-hit .tree-card { stroke: #e2895f; }

/* ==================================================================
   احترام تقليل الحركة
   ================================================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }

  .tree-node { opacity: 1; }
  .intro-card { animation: none !important; }
}

/* تباين أوضح لمؤشر لوحة المفاتيح */
:focus-visible {
  outline: 3px solid var(--brass);
  outline-offset: 2px;
}

/* ---------- عناصر الإدارة الجديدة ---------- */
.photo-row { display: flex; align-items: center; gap: 14px; }

.photo-preview {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--brass);
  background: rgba(255,255,255,.5);
}

.photo-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.photo-actions small { flex: 1 1 100%; color: var(--ink-soft); font-size: 11px; }

.backup-list {
  margin-top: 14px;
  max-height: 430px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13px;
  color: var(--ink-soft);
}

.backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border: 1px solid rgba(89,60,39,.16);
  border-radius: 11px;
  background: rgba(255,255,255,.42);
}

.backup-row strong { display: block; color: var(--ink); font-size: 13px; font-weight: 700; }
.backup-row small { color: var(--ink-soft); font-size: 11px; }

[data-theme="dark"] .backup-row { border-color: rgba(226,199,150,.18); background: rgba(255,255,255,.04); }

@media (max-width: 760px) {
  .admin-tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .admin-tabs::-webkit-scrollbar { display: none; }
  .admin-tab { flex: 0 0 auto; }
  .content-settings-grid { grid-template-columns: 1fr; }
  .settings-card { min-height: auto; padding: 16px; }
  .settings-card .panel-heading { margin: -16px -16px 16px; }
  .setting-range { grid-template-columns: 1fr; gap: 8px; }
  .photo-row { flex-direction: column; align-items: flex-start; }
  .graph-scroll { height: 460px; }
  .member-panel { height: 320px; min-height: 320px; }
  .backup-row { flex-direction: column; align-items: stretch; }
}


[data-theme="dark"] .gender-legend { background: rgba(42,31,22,.92); border-color: rgba(226,199,141,.2); }
[data-theme="dark"] .tree-node.gender-male .tree-card { fill: #30434a; stroke: #7ea7b5; }
[data-theme="dark"] .tree-node.gender-female .tree-card { fill: #55343b; stroke: #c58b97; }
[data-theme="dark"] .tree-node.gender-male .node-name,
[data-theme="dark"] .tree-node.gender-female .node-name { fill: #fff5dd; }

@media (max-width: 700px) {
  .gender-legend { top: 10px; left: 10px; flex-wrap: wrap; max-width: calc(100% - 82px); }
  .gender-legend-title { display: none; }
}


/* ================================================================
   Version 6 — centered header introduction and male-only gold mode
================================================================ */
.masthead {
  display: grid;
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 0;
  padding: 0;
}

.masthead-main {
  min-height: 88px;
  width: 100%;
  padding: 12px clamp(14px, 2.4vw, 26px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.header-introduction {
  width: 100%;
  padding: clamp(14px, 2vw, 22px) clamp(18px, 5vw, 72px);
  border-top: 1px solid rgba(91,60,39,.14);
  background:
    radial-gradient(circle at 50% 0%, rgba(199,163,92,.15), transparent 32rem),
    linear-gradient(90deg, rgba(155,115,54,.07), rgba(255,250,240,.55), rgba(72,102,93,.07));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-align: center;
}

.header-introduction-title {
  margin: 0;
  color: var(--leather-dark);
  font-family: var(--font-display);
  font-size: clamp(18px, 2.2vw, 26px);
  font-weight: 700;
  line-height: 1.4;
}

.header-introduction-text {
  width: min(100%, 1050px);
  margin: 0 auto;
  color: var(--ink-soft);
  font-size: clamp(12px, 1.15vw, 15px);
  line-height: 1.9;
  text-align: center;
  text-wrap: balance;
}

.family-intro-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: min(100%, 480px);
  min-height: 42px;
  margin: 5px auto 0;
  padding: 9px 18px;
  border: 1px solid rgba(89,60,39,.3);
  border-radius: 999px;
  color: var(--leather-dark);
  background: linear-gradient(180deg, rgba(255,251,241,.96), rgba(231,213,174,.9));
  box-shadow: 0 7px 18px rgba(69,48,28,.12);
  font-size: clamp(12px, 1vw, 14px);
  font-weight: 800;
  line-height: 1.5;
  text-align: center;
  white-space: normal;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.family-intro-button:hover,
.family-intro-button:focus-visible {
  transform: translateY(-2px);
  border-color: var(--brass);
  box-shadow: 0 11px 24px rgba(69,48,28,.18);
}

.intro-veil.static-disabled {
  display: none !important;
}

/* When females are hidden, every visible card adopts the root gold-paper style. */
.male-only-tree .tree-node .tree-card {
  fill: url(#paperCardGradient) !important;
  stroke: rgba(142,102,43,.7) !important;
}

.male-only-tree .tree-node .gender-marker {
  fill: var(--brass) !important;
}

.male-only-tree .tree-node .node-name {
  fill: var(--ink) !important;
}

[data-theme="dark"].male-only-tree .tree-node .tree-card {
  fill: #5a4528 !important;
  stroke: #d5af67 !important;
}

[data-theme="dark"].male-only-tree .tree-node .node-name {
  fill: #fff2cf !important;
}

@media (max-width: 900px) {
  .masthead-main {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-introduction {
    padding: 14px 16px 17px;
  }
}

@media (max-width: 620px) {
  .header-introduction {
    gap: 6px;
  }

  .header-introduction-text {
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.75;
  }

  .family-intro-button {
    width: min(100%, 360px);
  }
}


/* ================================================================
   Version 7 — light-only interface refinements
================================================================ */

/* Light theme is the only supported theme in this version. */
html,
html[data-theme="light"] {
  color-scheme: light;
}

/* The top toolbar now contains only the search field. */
.masthead-main .toolbar {
  justify-content: center;
  margin-inline-start: auto;
}

.masthead-main .search-wrap input {
  font-size: 12px;
  line-height: 1.35;
  padding-top: 9px;
  padding-bottom: 9px;
}

.masthead-main .search-count,
.masthead-main .search-nav button {
  font-size: 10px;
}

/* Centered and responsive family introduction. */
.header-introduction {
  position: relative;
  width: 100%;
  min-height: 0;
  padding: clamp(12px, 1.7vw, 19px) clamp(46px, 6vw, 84px);
  transition:
    padding .22s ease,
    min-height .22s ease,
    background-color .22s ease;
}

.header-introduction-body {
  width: min(100%, 1080px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-align: center;
}

.header-introduction-title,
.header-introduction-text,
.family-intro-button {
  margin-inline: auto;
  text-align: center;
}

.intro-minimize-button {
  position: absolute;
  inset-inline-start: clamp(10px, 2vw, 20px);
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(89,60,39,.28);
  border-radius: 50%;
  color: var(--leather-dark);
  background: rgba(255,250,240,.88);
  box-shadow: 0 5px 14px rgba(69,48,28,.1);
  font-size: 17px;
  font-weight: 900;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.intro-minimize-button:hover,
.intro-minimize-button:focus-visible {
  transform: translateY(-50%) scale(1.06);
  background: #fffaf0;
  box-shadow: 0 8px 18px rgba(69,48,28,.16);
}

.header-introduction-collapsed-label {
  display: none;
  width: 100%;
  text-align: center;
  color: var(--leather-dark);
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
}

.header-introduction.is-collapsed {
  min-height: 42px;
  padding-top: 8px;
  padding-bottom: 8px;
}

.header-introduction.is-collapsed .header-introduction-body {
  display: none;
}

.header-introduction.is-collapsed .header-introduction-collapsed-label {
  display: block;
}

/* The legend was deliberately removed. */
.gender-legend {
  display: none !important;
}

/* Male-only mode: gold cards and no gender marker/icon. */
.male-only-tree .tree-node .gender-marker,
.male-only-tree .tree-node .gender-marker-text {
  display: none !important;
}

/* Any obsolete public theme toggle remains hidden if cached markup is used. */
.theme-toggle {
  display: none !important;
}

@media (max-width: 900px) {
  .masthead-main .toolbar {
    width: 100%;
    margin-inline-start: 0;
  }

  .masthead-main .search-wrap {
    width: min(100%, 440px);
    margin-inline: auto;
  }

  .header-introduction {
    padding-inline: 46px;
  }
}

@media (max-width: 620px) {
  .masthead-main .search-wrap input {
    font-size: 11px;
  }

  .header-introduction {
    padding: 11px 43px 14px;
  }

  .intro-minimize-button {
    inset-inline-start: 8px;
    width: 31px;
    height: 31px;
    font-size: 15px;
  }

  .header-introduction.is-collapsed {
    min-height: 39px;
    padding-block: 7px;
  }

  .header-introduction-collapsed-label {
    font-size: 13px;
  }
}


/* ================================================================
   Version 8 — captain identity and icons
================================================================ */

/* Gender icons are removed everywhere. */
.gender-marker,
.gender-marker-text,
.member-gender-icon,
.graph-gender-icon {
  display: none !important;
}

.tree-node.captain-node .tree-card {
  stroke: #b8892f !important;
  stroke-width: 4.5px !important;
}

.tree-node.captain-node:hover .tree-card,
.tree-node.captain-node:focus .tree-card,
.tree-node.captain-node.selected .tree-card {
  stroke: #d2a64c !important;
  stroke-width: 5.5px !important;
}

.captain-icon {
  pointer-events: none;
}

.captain-icon path,
.captain-icon line,
.captain-icon circle {
  stroke: #97671c;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.captain-icon-wheel circle:last-of-type {
  fill: #97671c;
  stroke: none;
}

.captain-icon-anchor circle {
  fill: none;
}

.male-only-tree .tree-node.captain-node .tree-card {
  stroke: #c79535 !important;
  stroke-width: 5px !important;
}

.captain-toggle-field {
  justify-content: center;
  padding: 10px 12px;
  border: 1px solid rgba(159,116,48,.28);
  border-radius: 13px;
  background: rgba(238,221,181,.2);
}

.captain-check-row {
  margin: 0;
  font-weight: 800;
  color: var(--leather-dark);
}

#captainIconFieldWrap[hidden] {
  display: none !important;
}

.member-captain-icon,
.graph-captain-icon {
  display: inline-grid;
  place-items: center;
  min-width: 1.35em;
  margin-inline-end: 5px;
  color: #9b6c1e;
  font-size: .92em;
}

.graph-node.captain-node {
  border-color: #b8892f !important;
  border-width: 4px;
}


/* ================================================================
   Version 9 — optional generation side-tab and supplied wheel icon
================================================================ */

/* Clear, conventional minimize / expand control. */
.intro-minimize-button {
  width: auto;
  min-width: 76px;
  height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.intro-minimize-symbol {
  display: inline-grid;
  place-items: center;
  min-width: 17px;
  font-family: Arial, sans-serif;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}

.intro-minimize-text {
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

/* Generation badge becomes a protruding tab on the physical right side. */
.generation-side-tab {
  fill: #d5ad58;
  stroke: #8d6225;
  stroke-width: 1.8px;
  filter: drop-shadow(2px 3px 3px rgba(72, 48, 27, .18));
}

.generation-side-text {
  fill: #3e2918;
  font-size: 13px;
  font-weight: 900;
  pointer-events: none;
}

/* User-supplied wheel asset. */
.captain-wheel-image {
  pointer-events: none;
}

.member-captain-image,
.graph-captain-image {
  width: 20px;
  height: 20px;
  object-fit: contain;
  vertical-align: middle;
  margin-inline-end: 6px;
}

.graph-captain-image {
  width: 18px;
  height: 18px;
}

.member-captain-anchor {
  display: inline-block;
  margin-inline-end: 6px;
  color: #9b6c1e;
}

@media (max-width: 620px) {
  .intro-minimize-button {
    min-width: 34px;
    width: 34px;
    padding: 0;
  }

  .intro-minimize-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}


/* ================================================================
   Version 10 — internal generation badge and smoother interaction
================================================================ */

/* The generation pill remains inside the member card, at its right side. */
.generation-inside-badge {
  fill: rgba(199, 163, 92, .2);
  stroke: rgba(155, 115, 54, .56);
  stroke-width: 1.2px;
  filter: none;
  pointer-events: none;
}

.generation-inside-text {
  fill: var(--leather);
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
}

/* Avoid accidental text selection while touch-panning. */
#treeSvg,
.tree-node {
  -webkit-user-select: none;
  user-select: none;
}

#treeSvg.dragging .tree-node {
  cursor: grabbing;
}


/* ================================================================
   Version 11 — familytree subfolder, compact mobile chrome, male-only
================================================================ */

/* The family introduction is now on the root home page, not this tree page. */
.header-introduction,
.intro-veil,
.brand-subtitle {
  display: none !important;
}

/* All cards use the same gold paper style. */
.tree-card,
.male-only-tree .tree-node .tree-card {
  fill: url(#paperCardGradient) !important;
  stroke: rgba(142,102,43,.7) !important;
}

.member-row {
  border-right: 4px solid rgba(155,115,54,.55);
}

.graph-node {
  border-color: rgba(155,115,54,.72);
  background: linear-gradient(180deg, #fffaf0, #eadab7);
}

/* Compact single-line masthead. */
.masthead {
  padding: 0;
  min-height: 0;
  transition: transform .22s ease, box-shadow .22s ease;
  will-change: transform;
}

.masthead-main {
  min-height: 64px;
  padding: 7px clamp(10px, 2vw, 18px);
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  flex: 0 1 auto;
  width: auto !important;
  min-width: 0;
  align-items: center !important;
  gap: 9px;
}

.logo-frame {
  width: 54px;
  height: 44px;
  border-radius: 11px 11px 18px 18px;
}

.brand-text {
  min-width: 0;
}

.brand h1 {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}

.masthead-main .toolbar {
  width: auto;
  min-width: 0;
  flex: 1 1 360px;
  margin: 0;
  justify-content: flex-end;
  overflow: visible;
  padding: 0;
}

.masthead-main .search-wrap {
  width: min(100%, 430px);
  min-width: 0;
  flex: 1 1 auto;
}

.masthead-main .search-wrap input {
  min-height: 40px;
  padding-block: 7px;
}

/* On phones the header floats above the tree and slides away while panning/pinching.
   Fixed positioning avoids the empty grid-row gap caused by transform alone. */
@media (max-width: 760px) {
  .site-shell {
    display: block;
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .masthead {
    position: fixed;
    inset: 0 0 auto;
    z-index: 40;
    padding: env(safe-area-inset-top, 0px) 0 0;
    transform: translateY(0);
    pointer-events: auto;
  }

  .masthead.is-hidden {
    transform: translateY(calc(-100% - 5px));
    pointer-events: none;
  }

  .masthead-main {
    min-height: 54px;
    padding: 5px 8px;
    gap: 8px;
  }

  .brand {
    gap: 7px;
    flex: 0 1 auto;
  }

  .logo-frame {
    width: 42px;
    height: 36px;
    border-radius: 9px 9px 14px 14px;
    padding: 3px;
  }

  .brand h1 {
    max-width: 105px;
    font-size: 14px;
    line-height: 1.25;
  }

  .masthead-main .toolbar {
    width: auto !important;
    flex: 1 1 170px;
    gap: 0;
  }

  .masthead-main .search-wrap {
    width: 100%;
    min-width: 0;
  }

  .masthead-main .search-wrap input {
    min-height: 38px;
    padding-block: 6px;
    padding-inline-start: 34px;
    font-size: 12px;
  }

  .search-icon {
    right: 11px;
  }

  .viewer-workspace {
    width: 100%;
    height: 100vh !important;
    height: 100dvh !important;
    min-height: 100vh;
    min-height: 100dvh;
  }
}

@media (max-width: 410px) {
  .brand h1 {
    display: none;
  }
}
