/* Modern Design System with Light/Dark Mode Variables */
:root {
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);

  --font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  
  /* Light Mode Palette */
  --bg-app: #f1f5f9;
  --bg-board: #ffffff;
  --bg-card-male: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  --border-card-male: rgba(59, 130, 246, 0.4);
  --bg-card-female: linear-gradient(135deg, #fdf2f8 0%, #fce7f3 100%);
  --border-card-female: rgba(236, 72, 153, 0.4);
  --bg-card-prophet: linear-gradient(135deg, #f5edff 0%, #cd9dfd 100%);
  --border-card-prophet: rgba(186, 115, 250, 0.75);
  --bg-card-main: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  --border-card-main: #f59e0b;
  --shadow-card-main: 0 0 15px rgba(245, 158, 11, 0.25);
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-accent: #2563eb;
  
  --bg-panel: rgba(255, 255, 255, 0.60);
  --bg-panel-solid: #ffffff;
  --border-panel: rgba(226, 232, 240, 0.8);
  --shadow-panel: 0 10px 30px rgba(0, 0, 0, 0.08);
  --glass-blur: blur(12px);

  --line-color: #ff7800;
  --line-main-color: #ff7800;
  --spouse-line-color: #ef4444;
  --line-width: 3px;
}

[data-theme="dark"] {
  /* Dark Mode Palette */
  --bg-app: #0f172a;
  --bg-board: #1e293b;
  --bg-card-male: linear-gradient(135deg, #1e3a8a 0%, #0f172a 100%);
  --border-card-male: rgba(59, 130, 246, 0.5);
  --bg-card-female: linear-gradient(135deg, #831843 0%, #0f172a 100%);
  --border-card-female: rgba(236, 72, 153, 0.5);
  --bg-card-prophet: linear-gradient(135deg, #8028ca 0%, #470878 100%);
  --border-card-prophet: rgba(216, 180, 254, 0.75);
  --bg-card-main: linear-gradient(135deg, #78350f 0%, #1e293b 100%);
  --border-card-main: #fbbf24;
  --shadow-card-main: 0 0 20px rgba(251, 191, 36, 0.35);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-accent: #60a5fa;
  
  --bg-panel: rgba(15, 23, 42, 0.60);
  --bg-panel-solid: #1e293b;
  --border-panel: rgba(51, 65, 85, 0.8);
  --shadow-panel: 0 10px 35px rgba(0, 0, 0, 0.3);

  --line-color: #f97316;
  --line-main-color: #f97316;
  --spouse-line-color: #f87171;
}

/* Reset and Layout Base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed;
  overscroll-behavior: none;
  font-family: var(--font-family);
  background-color: var(--bg-board);
  color: var(--text-main);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Prevent landing page flash in app environments */
.is-app-env #landing-page {
  display: none !important;
}

/* Enable instant touch response and remove iOS gray tap highlight overlay */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Snappy click-delay bypass */
button,
a,
.person-card,
.control-btn,
.layer-marker {
  touch-action: manipulation;
}

/* Instantly animate button depression on touch */
button:active,
a:active,
.control-btn:active,
.clickable-item:active,
#bottom-control-panel button:active,
#filter-panel button:active,
#study-panel button:active {
  transform: scale(0.95) !important;
  opacity: 0.85;
  transition: transform 0.04s ease-out !important;
}

.person-card:active {
  opacity: 0.75 !important;
}

#app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

/* Header Panel styling */
header {
  position: fixed;
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow-panel);
  backdrop-filter: var(--glass-blur);
  z-index: 3000;
  transition: all 0.3s ease;
}

header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

header .subtitle {
  font-size: 12px;
  color: var(--text-muted);
  border-left: 1px solid var(--text-muted);
  padding-left: 12px;
  margin-left: 4px;
}

/* Control Panel (Zoom and Utilities) */
#control-panel {
  position: absolute;
  bottom: 16px;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  padding: 4px 8px;
  border-radius: 50px;
  box-shadow: var(--shadow-panel);
  backdrop-filter: var(--glass-blur);
  z-index: 3000;
  transition: all 0.3s ease;
}

#style-editor-toggle {
  display: none;
}

.control-btn {
  background: transparent;
  border: none;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  font-size: 11px;
  transition: all 0.2s ease;
}

.control-btn:hover {
  background: rgba(148, 163, 184, 0.15);
  transform: scale(1.05);
}

.control-btn.active {
  background: rgba(147, 51, 234, 0.18) !important;
  color: #a855f7 !important;
}

.control-btn.active:hover {
  background: rgba(147, 51, 234, 0.28) !important;
}

.control-divider {
  width: 1px;
  height: 16px;
  background-color: var(--border-panel);
  margin: 0 2px;
}

.zoom-indicator {
  font-size: 10px;
  font-weight: 600;
  min-width: 35px;
  text-align: center;
  color: var(--text-muted);
}

/* Search Box Panel */
#search-panel {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 3000;
}

.search-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  padding: 10px 16px;
  border-radius: 12px;
  width: 250px;
  font-family: var(--font-family);
  font-size: 14px;
  color: var(--text-main);
  box-shadow: var(--shadow-panel);
  backdrop-filter: var(--glass-blur);
  outline: none;
  transition: all 0.3s ease;
}

.search-box:focus {
  border-color: var(--text-accent);
  width: 300px;
}

#viewer-container {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  z-index: 1;
  cursor: grab;
  outline: none;
  touch-action: none;
  background-color: var(--bg-board);
  user-select: none;
  -webkit-user-select: none;
}

#viewer-container:active {
  cursor: grabbing;
}

#zoom-wrapper {
  transform-origin: 0 0;
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  user-select: none;
  -webkit-user-select: none;
  will-change: transform;
}

#tree-board {
  position: relative;
  background-color: transparent;
  overflow: visible;
}

/* SVG Line Layer */
#svg-polygons-layer {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none !important;
  max-height: none !important;
  overflow: visible !important;
  pointer-events: none;
  z-index: 1; /* Render behind everything else, below locations */
  will-change: transform;
  transform: translateZ(0);
}
#svg-layer {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none !important;
  max-height: none !important;
  overflow: visible !important;
  pointer-events: none;
  z-index: 3;
  will-change: transform;
  transform: translateZ(0);
}

.connector-line {
  fill: none;
  stroke: var(--line-color);
  stroke-width: var(--line-width);
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.3s ease;
  pointer-events: stroke;
  cursor: default;
}

.admin-mode-active .connector-line {
  cursor: crosshair;
}

.admin-mode-active .connector-line:hover {
  stroke-width: calc(var(--line-width) + 3px) !important;
  stroke: var(--text-accent) !important;
}

.connector-line.main-line {
  stroke: var(--line-main-color);
  stroke-width: calc(var(--line-width) + 1px);
  stroke-dasharray: 4 2;
  animation: march 25s linear infinite;
}

.connector-line.preacher-line {
  stroke: var(--preacher-line-color);
  stroke-width: calc(var(--line-width) + 1.2px);
  transition: stroke 0.3s ease, stroke-width 0.3s ease;
}

@keyframes march {
  to {
    stroke-dashoffset: -100;
  }
}

.spouse-connector {
  fill: none;
  stroke: var(--spouse-line-color);
  stroke-width: var(--line-width);
  stroke-dasharray: 4 4;
  pointer-events: stroke;
  cursor: pointer;
}

/* Node/Card Styling */
.person-card {
  position: absolute;
  width: 152px;
  height: 62px;
  border-radius: 10px;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: 0 4px 8px rgba(0,0,0,0.04);
  z-index: 10;
  cursor: pointer;
  user-select: none;
  transition: box-shadow 0.2s ease, border-color 0.3s ease;
}

/* Disable card transitions during zoom animations, wheel zoom, gesture zoom, and touch zoom to prevent size bouncing/lag */
.zooming .person-card,
.zooming .layer-marker {
  transition: none !important;
}

.person-card:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 8px 16px rgba(0,0,0,0.08);
}

.person-card.admin-editable {
  cursor: grab;
}

.person-card.dragging {
  cursor: grabbing !important;
  opacity: 0.85;
  box-shadow: 0 12px 24px rgba(0,0,0,0.15) !important;
  z-index: 1000 !important;
  transition: none !important;
}

.person-card.selected-for-edit {
  outline: 3px solid var(--primary-color) !important;
  box-shadow: 0 0 15px rgba(255, 120, 0, 0.6) !important;
}

.person-card.male {
  background: var(--bg-card-male);
  border: 1.5px solid var(--border-card-male);
}

.person-card.female {
  background: var(--bg-card-female);
  border: 1.5px solid var(--border-card-female);
}

.person-card.male.main-line {
  background: var(--bg-card-main);
  border: 2px solid var(--border-card-main);
  box-shadow: var(--shadow-card-main);
}

.person-card.female.main-line {
  background: var(--bg-card-female);
  border: 2.5px solid var(--border-card-female);
  box-shadow: var(--shadow-card-main);
}

.person-card.main-line:hover {
  box-shadow: 0 0 25px rgba(245, 158, 11, 0.45);
}

/* Prophet Card General Styles (always purple background) */
.person-card.prophet {
  background: var(--bg-card-prophet) !important;
  border: 1.5px solid var(--border-card-prophet) !important;
}
.person-card.prophet .card-title {
  color: #4a044e !important;
}
.person-card.prophet .card-eng {
  color: #701a75 !important;
}
[data-theme="dark"] .person-card.prophet {
  background: var(--bg-card-prophet) !important;
  border: 1.5px solid var(--border-card-prophet) !important;
}
[data-theme="dark"] .person-card.prophet .card-title {
  color: #fdf4ff !important;
}
[data-theme="dark"] .person-card.prophet .card-eng {
  color: #e9d5ff !important;
}

/* Card Inner Content */
.card-name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
}

.card-title {
  font-size: 18.7px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.card-eng {
  font-size: 12.65px;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 5px;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-desc {
  font-size: 8.65px;
  font-weight: 400;
  opacity: 0.85;
}

.card-gender-icon {
  font-size: 11px;
  font-weight: bold;
}

.card-gender-icon.male {
  color: #2563eb;
}

.card-gender-icon.female {
  color: #db2777;
}

.card-note-badge {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 9px;
}

/* Highlighted Node during Search */
.person-card.highlight {
  animation: pulse-border 1.5s infinite alternate;
  z-index: 20;
}

@keyframes pulse-border {
  from {
    transform: scale(1.04);
    box-shadow: 0 0 10px var(--text-accent);
  }
  to {
    transform: scale(1.08);
    box-shadow: 0 0 25px var(--text-accent);
  }
}

#study-panel {
  position: absolute;
  top: 80px;
  right: -380px;
  width: 360px;
  max-width: 60vw;
  height: calc(100% - 96px);
  background: var(--bg-panel-solid);
  border: 1px solid var(--border-panel);
  border-radius: 16px;
  box-shadow: var(--shadow-panel);
  z-index: 200;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  pointer-events: auto !important;
}

#study-panel.active {
  right: 16px;
}

.expand-btn {
  background: transparent;
  border: none;
  font-size: 16px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s ease, transform 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0;
}

.expand-btn:hover {
  color: var(--text-main);
  transform: scale(1.2);
}

@media (min-width: 769px) {
  #study-panel.expanded {
    position: fixed;
    width: 800px;
    height: 80%;
    max-width: 60vw;
    max-height: 85vh;
    z-index: 5000;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
  }
  
  #study-panel.expanded .panel-header {
    cursor: move;
  }
  
  #study-panel.expanded .note-textarea {
    height: 350px;
  }
}

.panel-header {
  padding: 24px;
  border-bottom: 1px solid var(--border-panel);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-title h2 {
  font-size: 20px;
  font-weight: 700;
}

.panel-title p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s ease, transform 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0 0 2px 0;
  margin: 0;
  line-height: 1;
}

.close-btn:hover {
  color: var(--text-main);
  transform: scale(1.2);
}

.panel-body {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-sec-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.desc-text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-main);
  background: rgba(148, 163, 184, 0.08);
  padding: 12px;
  border-radius: 8px;
}

.note-textarea {
  width: 100%;
  height: 160px;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border-panel);
  border-radius: 8px;
  padding: 12px;
  font-family: var(--font-family);
  font-size: 14px;
  color: var(--text-main);
  resize: none;
  outline: none;
  transition: border-color 0.2s ease;
  -webkit-user-select: auto !important;
  user-select: auto !important;
  pointer-events: auto !important;
}

.note-textarea:focus {
  border-color: var(--text-accent);
}

.resource-input-wrapper {
  display: flex;
  gap: 8px;
  width: 100%;
}

.resource-input {
  min-width: 0;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border-panel);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--font-family);
  font-size: 13px;
  color: var(--text-main);
  outline: none;
  -webkit-user-select: auto !important;
  user-select: auto !important;
  pointer-events: auto !important;
}

#resource-title {
  flex: 1;
}

#resource-url {
  flex: 2;
}

.add-resource-btn {
  background: var(--text-accent);
  color: #fff;
  border: none;
  padding: 0 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: opacity 0.2s ease;
  flex-shrink: 0;
  white-space: nowrap;
}

.add-resource-btn:hover {
  opacity: 0.9;
}

.resources-list {
  list-style: none;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.resource-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(148, 163, 184, 0.05);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
}

.resource-item a {
  color: var(--text-accent);
  text-decoration: none;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resource-item a:hover {
  text-decoration: underline;
}

.delete-resource-btn {
  background: transparent;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 11px;
}

.panel-footer {
  padding: 20px 24px;
  border-top: 1px solid var(--border-panel);
  display: flex;
  gap: 12px;
}

.save-btn {
  flex: 1;
  background: var(--text-accent);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.save-btn:hover {
  opacity: 0.9;
}

.cancel-btn {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-main);
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

/* Generation labels on the left of the board */
.generation-label {
  position: absolute;
  left: 24px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: bold;
  transform: translateY(-50%);
  pointer-events: none;
  background: var(--bg-board);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-panel);
}

/* Media Queries for Mobile responsiveness */
@media (max-width: 768px) {
  header {
    position: absolute !important;
    box-sizing: border-box !important;
    height: 32px !important;
    width: 175px !important;
    padding: 0 10px !important;
    border-radius: 12px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    top: calc(-7px + env(safe-area-inset-top, 0px)) !important;
    left: calc(8px + env(safe-area-inset-left)) !important;
    z-index: 12000 !important;
  }
  header h1 {
    font-size: 13px !important;
    font-weight: 700 !important;
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    margin: 0 !important;
  }
  header h1 small {
    display: inline-block !important;
    font-size: 9px !important;
    color: var(--text-muted) !important;
    opacity: 0.5 !important;
    margin-left: 2px !important;
    vertical-align: middle !important;
  }
  header img {
    height: 20px !important;
    width: 20px !important;
    margin: 0 !important;
    border-radius: 6px !important;
    object-fit: cover !important;
  }
  header .subtitle {
    display: none;
  }
  #search-panel {
    position: absolute !important;
    top: calc(-4px + env(safe-area-inset-top, 0px)) !important;
    right: calc(8px + env(safe-area-inset-right)) !important;
    z-index: 12000 !important;
    width: 112px !important;
    height: 26px !important;
  }
  .search-box {
    box-sizing: border-box !important;
    width: 100% !important;
    height: 100% !important;
    padding: 0 10px !important;
    font-size: 10.5px !important;
    border-radius: 12px !important;
  }
  .search-box::placeholder {
    font-size: 10px !important;
  }
  .search-box:focus {
    width: 100% !important;
  }
  .layer-control-panel {
    position: absolute !important;
    top: calc(28px + env(safe-area-inset-top, 0px)) !important;
    left: calc(8px + env(safe-area-inset-left)) !important;
    padding: 8px 12px;
    gap: 4px;
    z-index: 12000 !important;
  }
  .panel-header {
    padding-top: 0px;
  }
  #control-panel {
    bottom: calc(-28px + env(safe-area-inset-bottom)) !important;
  }
  #study-panel {
    width: 55% !important;
    max-width: 60% !important;
    right: -55% !important;
    top: calc(28px + env(safe-area-inset-top, 0px)) !important;
    bottom: calc(17px + env(safe-area-inset-bottom)) !important;
    height: auto;
    border-radius: 16px 0 0 16px;
    border: none;
    border-left: 1px solid var(--border-panel);
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.15);
    z-index: 11000 !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
  #study-panel.active {
    right: 0 !important;
  }
  
  /* iOS Device Specific Overrides - safely positioned absolute below status bar */
  .ios-device header {
    top: calc(-7px + env(safe-area-inset-top, 0px)) !important;
    left: calc(8px + env(safe-area-inset-left)) !important;
  }
  .ios-device #search-panel {
    top: calc(-4px + env(safe-area-inset-top, 0px)) !important;
  }
  .ios-device .layer-control-panel {
    top: calc(28px + env(safe-area-inset-top, 0px)) !important;
    left: calc(8px + env(safe-area-inset-left)) !important;
  }
  .ios-device #study-panel {
    top: calc(28px + env(safe-area-inset-top, 0px)) !important;
  }
  
  /* Settings Modal mobile scrolling adjustments */
  #settings-modal .modal-content {
    max-height: 80vh !important;
    display: flex !important;
    flex-direction: column !important;
  }
  #settings-modal .settings-body {
    max-height: 60vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
  /* Spacing (여백) 2.2px inner left/right padding in study panel (reduced by 1/3 of 3.3px) */
  #study-panel .panel-header {
    padding: 15px 2.2px !important;
    border-bottom: none !important;
    position: relative !important;
  }
  #study-panel .panel-header::after {
    content: '' !important;
    position: absolute !important;
    bottom: 0 !important;
    left: 2.2px !important;
    right: 2.2px !important;
    height: 1px !important;
    background: var(--border-panel) !important;
  }
  #study-panel .panel-body {
    padding: 15px 2.2px !important;
    gap: 12px !important;
  }
  #study-panel .panel-footer {
    padding: 15px 2.2px !important;
    border-top: none !important;
    position: relative !important;
  }
  #study-panel .panel-footer::before {
    content: '' !important;
    position: absolute !important;
    top: 0 !important;
    left: 2.2px !important;
    right: 2.2px !important;
    height: 1px !important;
    background: var(--border-panel) !important;
  }
  #study-panel .desc-text {
    padding: 12px 2.2px !important;
    font-size: 11.5px !important;
  }
  #study-panel .note-textarea {
    padding: 12px 2.2px !important;
    height: 180px !important; /* 50% height increase (120px -> 180px) */
    font-size: 11.5px !important;
  }
  #study-panel .resource-input {
    padding: 5px 2.2px !important;
    font-size: 11.5px !important;
  }
  #study-panel .resource-item {
    padding: 5px 2.2px !important;
    font-size: 11.5px !important;
  }
  
  /* Button height (높이) 30% reduction in study panel */
  #study-panel .save-btn {
    padding: 8px 12px;
    font-size: 11.5px !important;
  }
  #study-panel .cancel-btn {
    padding: 8px 16px;
    font-size: 11.5px !important;
  }
  #study-panel .add-resource-btn {
    padding: 5px 14px !important;
    font-size: 11.5px !important;
  }
  
  .copyright-notice {
    display: none !important;
  }
}

/* ==========================================
   Admin Mode & Modal UI Styles
   ========================================== */

/* Floating Admin Database Action Panel (Top Left) */
#admin-actions-bar {
  position: absolute;
  top: 210px; /* Positioned below the layer control panel */
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  padding: 7px;
  border-radius: 12px;
  box-shadow: var(--shadow-panel);
  backdrop-filter: var(--glass-blur);
  z-index: 100;
  transition: all 0.3s ease;
}

.admin-action-btn {
  font-family: var(--font-family);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 11px;
  border: 1px solid var(--border-panel);
  border-radius: 8px;
  background: var(--bg-board);
  color: var(--text-main);
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.admin-action-btn:hover {
  background: rgba(148, 163, 184, 0.12);
}

.admin-action-btn.primary {
  background: var(--text-accent);
  color: #fff;
  border-color: var(--text-accent);
}

.admin-action-btn.primary:hover {
  opacity: 0.9;
}

.admin-action-btn.danger {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}

.admin-action-btn.danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

#admin-save-btn {
  background: #10b981 !important;
  border-color: #10b981 !important;
  font-weight: bold !important;
  color: #ffffff !important;
  border-radius: 8px !important;
  cursor: pointer !important;
  height: 48px !important; /* 1.5x height of standard 32px button */
  font-size: 13px !important;
  padding: 0 16px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Edit Trigger Button on Cards (In Admin Mode) */
.card-edit-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 10px; /* Match person-card border-radius */
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  z-index: 15;
  transition: opacity 0.2s ease;
  box-sizing: border-box;
  transform: translateZ(0);
}

.person-card.admin-editable:hover .card-edit-overlay,
.person-card.admin-editable.selected-for-edit .card-edit-overlay {
  opacity: 1;
  pointer-events: none;
}

.card-edit-btn {
  pointer-events: auto;
  background: #ffffff;
  color: #0f172a;
  border: none;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
  transition: transform 0.15s ease;
}

.card-edit-btn:hover {
  transform: scale(1.05);
}

/* Modal Overlay & Card CRUD Form Dialog */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30000 !important;
}

.modal-content {
  background: var(--bg-board);
  border: 1px solid var(--border-panel);
  border-radius: 16px;
  width: 500px;
  max-width: 90%;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  animation: modal-pop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modal-pop {
  from {
    transform: scale(0.9) translateY(20px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-panel);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.form-grid {
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-height: 70vh;
  overflow-y: auto;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.full-width {
  grid-column: span 2;
}

.form-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.form-group input, 
.form-group select, 
.form-group textarea {
  font-family: var(--font-family);
  font-size: 13px;
  padding: 8px 12px;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border-panel);
  border-radius: 8px;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s ease;
}

.form-group input:focus, 
.form-group select:focus, 
.form-group textarea:focus {
  border-color: var(--text-accent);
}

.checkbox-group {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.checkbox-group input {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.checkbox-group label {
  text-transform: none;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-panel);
  display: flex;
  gap: 12px;
  align-items: center;
}

.modal-btn {
  font-family: var(--font-family);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--border-panel);
  background: var(--bg-board);
  color: var(--text-main);
  transition: all 0.2s ease;
}

.modal-btn:hover {
  background: rgba(148, 163, 184, 0.1);
}

.modal-btn.primary {
  background: var(--text-accent);
  color: #fff;
  border-color: var(--text-accent);
}

.modal-btn.primary:hover {
  opacity: 0.9;
}

.modal-btn.danger-outline {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.4);
}

.modal-btn.danger-outline:hover {
  background: rgba(239, 68, 68, 0.1);
}

@media (max-width: 768px) {
  #admin-actions-bar {
    top: 70px;
    left: 8px;
    padding: 6px;
    gap: 6px;
  }
  .admin-action-btn {
    padding: 6px 10px;
    font-size: 11px;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .form-group.full-width {
    grid-column: span 1;
  }
}

/* Left Sliding Design Style Editor Panel */
#style-editor-panel {
  position: absolute;
  top: 80px;
  left: -380px; /* Initially hidden on the left */
  width: 360px;
  height: calc(100% - 96px);
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  border-radius: 16px;
  box-shadow: var(--shadow-panel);
  backdrop-filter: var(--glass-blur);
  z-index: 200;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

#style-editor-panel.active {
  left: 16px;
}

.style-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: rgba(148, 163, 184, 0.04);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border-panel);
}

.style-control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.style-control-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
}

.style-control-group input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border-panel);
  border-radius: 8px;
  padding: 2px;
  cursor: pointer;
  background: transparent;
}

.slider-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.slider-label-row span {
  font-size: 11px;
  font-weight: bold;
  color: var(--text-accent);
}

.style-control-group input[type="range"] {
  width: 100%;
  cursor: pointer;
  accent-color: var(--text-accent);
}

.style-select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border-panel);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--bg-board);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s ease;
}

.style-select:focus {
  border-color: var(--text-accent);
}

/* Left Sliding Branch Filter Panel */
#filter-panel {
  position: absolute;
  top: 80px;
  left: -380px; /* Initially hidden on the left */
  width: 360px;
  height: calc(100% - 96px);
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  border-radius: 16px;
  box-shadow: var(--shadow-panel);
  backdrop-filter: var(--glass-blur);
  z-index: 200;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

#filter-panel.active {
  left: 16px;
}

.filter-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(148, 163, 184, 0.04);
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border-panel);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 6px;
  transition: background-color 0.2s ease;
}

.filter-item:hover {
  background-color: rgba(148, 163, 184, 0.08);
}

.filter-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  margin: 0;
}

.filter-label {
  font-size: 14px;
  color: var(--text-main);
  font-weight: 500;
}

@media (max-width: 768px) {
  #style-editor-panel {
    width: 100%;
    left: -100%;
    top: 0;
    height: 100%;
    border-radius: 0;
    border: none;
  }
  #style-editor-panel.active {
    left: 0;
  }
  #filter-panel {
    width: 75%;
    left: -75%;
    top: 0;
    height: 100%;
    border-radius: 0 16px 16px 0;
    border: none;
    border-right: 1px solid var(--border-panel);
    box-shadow: 5px 0 25px rgba(0, 0, 0, 0.15);
    z-index: 4000;
  }
  #filter-panel.active {
    left: 0;
  }
}/* Floating Annotation/Text Box Styling */
.canvas-annotation {
  position: absolute;
  min-width: 100px;
  min-height: 40px;
  background: var(--bg-panel);
  border: 1px dashed var(--border-panel);
  border-radius: 8px;
  padding: 8px;
  box-sizing: border-box;
  z-index: 95;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
  cursor: default;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.canvas-annotation:hover {
  box-shadow: 0 6px 16px rgba(0,0,0,0.1);
}

.admin-mode-active .canvas-annotation {
  resize: both;
  overflow: visible; /* To allow control bar to extend above note */
  cursor: move; /* Drag to move */
  border: 1.5px dashed var(--text-accent);
}

.annotation-text {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-main);
  resize: none;
  outline: none;
  word-break: break-word;
  pointer-events: none;
  overflow: hidden;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.admin-mode-active .canvas-annotation.editing .annotation-text {
  pointer-events: auto !important;
  cursor: text !important;
}

.admin-mode-active .canvas-annotation:not(.editing) .annotation-text {
  pointer-events: none !important;
  cursor: move !important;
}

/* Floating Toolbar for Editing Annotation properties */
.annotation-toolbar {
  display: none;
  position: absolute;
  top: -40px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  border-radius: 8px;
  padding: 4px 8px;
  gap: 8px;
  align-items: center;
  box-shadow: var(--shadow-panel);
  z-index: 150;
  white-space: nowrap;
}

.admin-mode-active .canvas-annotation:hover .annotation-toolbar,
.admin-mode-active .canvas-annotation.selected .annotation-toolbar,
.admin-mode-active .annotation-toolbar:hover {
  display: flex;
}

.annot-size-input {
  width: 50px;
  height: 24px;
  border: 1px solid var(--border-panel);
  border-radius: 4px;
  background: var(--bg-board);
  color: var(--text-main);
  text-align: center;
  font-size: 12px;
  outline: none;
}

.annot-btn {
  background: transparent;
  border: none;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 13px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  transition: background 0.2s ease;
}

.annot-btn:hover {
  background: var(--bg-board);
  color: var(--text-accent);
}

.annot-btn.active {
  background: var(--text-accent);
  color: #ffffff;
}

.annot-color-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.annot-color-wrapper label {
  font-size: 10px;
  color: var(--text-muted);
}

.annot-color-picker {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: transparent;
  padding: 0;
}

.annot-color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.annot-color-picker::-webkit-color-swatch {
  border: 1px solid var(--border-panel);
  border-radius: 50%;
}

/* Ancestry Lineage Highlighting & Glowing Halo Effect */
.person-card.ancestor-highlight {
  border-color: var(--text-accent) !important;
  box-shadow: 0 0 20px var(--text-accent), 0 0 6px var(--text-accent) !important;
  transform: scale(1.05);
  z-index: 120;
}

/* Dim everything else when highlighting is active */
.tree-highlight-active .person-card:not(.ancestor-highlight) {
  opacity: 0.09 !important;
  filter: grayscale(85%) !important;
  pointer-events: none;
  transition: opacity 0.3s ease, filter 0.3s ease;
}

.tree-highlight-active .connector-line:not(.line-highlight),
.tree-highlight-active .spouse-connector:not(.line-highlight) {
  opacity: 0.05 !important;
  stroke: #cbd5e1 !important;
  transition: opacity 0.3s ease;
}

.tree-highlight-active .canvas-junction-node {
  opacity: 0.05 !important;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.tree-highlight-active .canvas-annotation {
  opacity: 0.05 !important;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.tree-highlight-active .layer-marker {
  opacity: 0.05 !important;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* Highlight connection paths with animated glowing pulse */
.connector-line.line-highlight,
.spouse-connector.line-highlight {
  stroke: var(--text-accent) !important;
  stroke-width: 4.5px !important;
  stroke-dasharray: 8 4;
  animation: line-pulse-dash 1.2s linear infinite;
  z-index: 100;
  opacity: 1 !important;
}

@keyframes line-pulse-dash {
  from {
    stroke-dashoffset: 12;
  }
  to {
    stroke-dashoffset: 0;
  }
}

/* Family Group Shaded Panels */
.family-group-panel {
  position: absolute;
  border-radius: 16px;
  border: 2px dashed rgba(148, 163, 184, 0.2);
  pointer-events: none;
  z-index: 1;
  transition: all 0.3s ease;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.01);
}

.family-group-label {
  position: absolute;
  top: -12px;
  left: 20px;
  background: var(--bg-card-main, #ffffff);
  padding: 2px 12px;
  border-radius: 20px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-muted, #64748b);
  border: 1px solid var(--border-panel, #e2e8f0);
  box-shadow: 0 2px 4px rgba(0,0,0,0.03);
  letter-spacing: 0.5px;
  white-space: nowrap;
  z-index: 4;
}

.family-group-panel.cain { background-color: rgba(239, 68, 68, 0.03); border-color: rgba(239, 68, 68, 0.15); }
.family-group-panel.cain .family-group-label { color: #ef4444; border-color: rgba(239, 68, 68, 0.25); }

.family-group-panel.japheth { background-color: rgba(34, 197, 94, 0.03); border-color: rgba(34, 197, 94, 0.15); }
.family-group-panel.japheth .family-group-label { color: #22c55e; border-color: rgba(34, 197, 94, 0.25); }

.family-group-panel.ham { background-color: rgba(249, 115, 22, 0.03); border-color: rgba(249, 115, 22, 0.15); }
.family-group-panel.ham .family-group-label { color: #f97316; border-color: rgba(249, 115, 22, 0.25); }

.family-group-panel.joktan { background-color: rgba(59, 130, 246, 0.03); border-color: rgba(59, 130, 246, 0.15); }
.family-group-panel.joktan .family-group-label { color: #3b82f6; border-color: rgba(59, 130, 246, 0.25); }

.family-group-panel.keturah { background-color: rgba(236, 72, 153, 0.03); border-color: rgba(236, 72, 153, 0.15); }
.family-group-panel.keturah .family-group-label { color: #ec4899; border-color: rgba(236, 72, 153, 0.25); }

.family-group-panel.ishmael { background-color: rgba(168, 85, 247, 0.03); border-color: rgba(168, 85, 247, 0.15); }
.family-group-panel.ishmael .family-group-label { color: #a855f7; border-color: rgba(168, 85, 247, 0.25); }

.family-group-panel.esau { background-color: rgba(234, 179, 8, 0.03); border-color: rgba(234, 179, 8, 0.15); }
.family-group-panel.esau .family-group-label { color: #eab308; border-color: rgba(234, 179, 8, 0.25); }

.family-group-panel.mary { background-color: rgba(6, 182, 212, 0.03); border-color: rgba(6, 182, 212, 0.15); }
.family-group-panel.mary .family-group-label { color: #06b6d4; border-color: rgba(6, 182, 212, 0.25); }

/* Generation Divider Badge at bottom-left of Noah */
.generation-divider-badge {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.generation-divider-badge span {
  background: var(--bg-card-main, #ffffff);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.25);
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.08);
  white-space: nowrap;
  letter-spacing: 0.5px;
}

/* Autocomplete suggestions dropdown styling */
.autocomplete-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  max-height: 150px;
  overflow-y: auto;
  background: var(--bg-card-main, #ffffff);
  border: 1px solid var(--border-panel, #cbd5e1);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1001;
  display: none;
}

.suggestion-item {
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-color, #1e293b);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover {
  background: var(--primary-color, #ff7800);
  color: white !important;
}

.suggestion-item span.sug-id {
  font-size: 10px;
  color: var(--text-muted, #64748b);
  font-family: monospace;
}

.suggestion-item:hover span.sug-id {
  color: rgba(255, 255, 255, 0.8);
}

/* Card Edit Overlay Extended Dashboard styling */
.card-edit-overlay {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
}

.card-edit-overlay-btns {
  display: flex;
  gap: 4px;
  justify-content: center;
  width: 100%;
}

.card-edit-btn.delete {
  background: #ef4444 !important;
  color: white !important;
}

.card-edit-btn.delete:hover {
  background: #dc2626 !important;
}

.card-nudge-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  width: 100%;
  max-width: 140px;
  margin-top: 2px;
}

.nudge-btn {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.95);
  color: #0f172a;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 4px;
  padding: 2px 0;
  font-size: 10px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  height: 20px;
}

.nudge-btn:hover {
  background: var(--primary-color, #ff7800);
  color: white !important;
  border-color: transparent;
}

/* Custom Line Bend Handles (Admin Mode Only) */
.line-bend-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #3b82f6;
  border: 2px solid #ffffff;
  cursor: move;
  transform: translate(-50%, -50%);
  z-index: 1002;
  box-shadow: 0 2px 5px rgba(0,0,0,0.25);
  transition: background-color 0.2s, transform 0.2s;
}

.line-bend-handle:hover {
  background: #2563eb;
  transform: translate(-50%, -50%) scale(1.3);
}

.line-bend-handle.selected {
  border-color: #ff7800 !important;
  box-shadow: 0 0 0 4px rgba(255, 120, 0, 0.5) !important;
}

/* Logos-style custom free-form visual connection lines */
.custom-visual-line {
  stroke: var(--line-color) !important;
  stroke-dasharray: 6 4;
  cursor: crosshair;
}

.custom-visual-line:hover {
  stroke: var(--text-accent) !important;
  stroke-width: calc(var(--line-width) + 3px) !important;
}

.custom-visual-line.line-highlight {
  stroke: var(--text-accent) !important;
  stroke-width: calc(var(--line-width) + 2px) !important;
}

/* Visual highlights for adding connection lines */
.link-source-highlight {
  outline: 3px solid #ff7800 !important;
  box-shadow: 0 0 15px rgba(255, 120, 0, 0.6) !important;
}

/* Drag-and-drop link port handle */
.card-link-port {
  display: none;
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #3b82f6;
  border: 1.5px solid #ffffff;
  cursor: crosshair;
  z-index: 1005;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: background-color 0.2s, transform 0.2s;
  bottom: auto;
  left: auto;
  transform: none;
}

.card-link-port:hover {
  background: #ff7800;
}

/* Side center ports positioning */
.card-link-port.port-top {
  top: -5px;
  left: calc(50% + 15px);
  transform: translateX(-50%);
}
.card-link-port.port-top:hover {
  transform: translateX(-50%) scale(1.3);
}

.card-link-port.port-bottom {
  bottom: -5px;
  left: calc(50% + 15px);
  transform: translateX(-50%);
}
.card-link-port.port-bottom:hover {
  transform: translateX(-50%) scale(1.3);
}

.card-link-port.port-left {
  left: -5px;
  top: 50%;
  transform: translateY(-50%);
}
.card-link-port.port-left:hover {
  transform: translateY(-50%) scale(1.3);
}

.card-link-port.port-right {
  right: -5px;
  top: 50%;
  transform: translateY(-50%);
}
.card-link-port.port-right:hover {
  transform: translateY(-50%) scale(1.3);
}

/* 4 Corners (Quadrants) ports positioning */
.card-link-port.port-top-left {
  top: -5px;
  left: -5px;
}
.card-link-port.port-top-left:hover {
  transform: scale(1.3);
}

.card-link-port.port-top-right {
  top: -5px;
  right: -5px;
}
.card-link-port.port-top-right:hover {
  transform: scale(1.3);
}

.card-link-port.port-bottom-left {
  bottom: -5px;
  left: -5px;
}
.card-link-port.port-bottom-left:hover {
  transform: scale(1.3);
}

.card-link-port.port-bottom-right {
  bottom: -5px;
  right: -5px;
}
.card-link-port.port-bottom-right:hover {
  transform: scale(1.3);
}

/* Target hover highlight during dragging */
.card-link-port.port-target-hover {
  background: #ff7800 !important;
  transform: scale(1.5) !important;
  box-shadow: 0 0 8px rgba(255, 120, 0, 0.8) !important;
}

.admin-mode-active .person-card:hover .card-link-port,
.admin-mode-active .canvas-annotation:hover .card-link-port {
  display: block;
}

/* Target hover highlight during dragging */
.person-card.link-target-hover,
.canvas-annotation.link-target-hover {
  outline: 3px solid #ff7800 !important;
  box-shadow: 0 0 15px rgba(255, 120, 0, 0.6) !important;
}

/* Temporary dragging path line */
.temp-drag-line {
  fill: none;
  stroke: #ff7800;
  stroke-width: 3px;
  stroke-dasharray: 6 4;
  pointer-events: none;
}

/* Custom Visual Line Styles (normal, main, spouse) */
.custom-visual-line.line-normal {
  stroke: var(--line-color) !important;
  stroke-width: var(--line-width) !important;
  stroke-dasharray: 6 4 !important;
}

.custom-visual-line.line-main {
  stroke: var(--line-main-color) !important;
  stroke-width: calc(var(--line-width) + 1.5px) !important;
  stroke-dasharray: none !important;
}

.custom-visual-line.line-spouse {
  stroke: var(--spouse-line-color) !important;
  stroke-width: var(--line-width) !important;
  stroke-dasharray: none !important;
}

.custom-visual-line.line-highlight {
  stroke: var(--text-accent) !important;
  stroke-width: calc(var(--line-width) + 2px) !important;
}

/* Custom Visual Line endpoint drag handles */
.line-drag-handle {
  fill: #ffffff !important;
  stroke: #ff7800 !important;
  stroke-width: 2.5px !important;
  cursor: move !important;
  pointer-events: auto !important;
  filter: drop-shadow(0px 1px 3px rgba(0,0,0,0.3)) !important;
  transition: fill 0.2s, stroke-width 0.2s;
}

.line-drag-handle:hover {
  fill: #ff7800 !important;
  stroke: #ffffff !important;
  r: 8px !important;
}

/* Force-display ports of the currently approached box during drag connection */
.person-card.link-hovered-target .card-link-port,
.canvas-annotation.link-hovered-target .card-link-port {
  display: block !important;
}

/* Pulsing animation for long press wait */
@keyframes pulse-orange {
  0% { r: 5px; fill: #ffffff; }
  50% { r: 9px; fill: #ff7800; }
  100% { r: 5px; fill: #ffffff; }
}

.line-drag-handle.long-press-waiting {
  animation: pulse-orange 1s infinite ease-in-out !important;
  stroke: #ff7800 !important;
  stroke-width: 3px !important;
}

.line-drag-handle.long-press-detached {
  fill: #ff7800 !important;
  stroke: #ffffff !important;
  r: 9px !important;
  filter: drop-shadow(0px 2px 5px rgba(255, 120, 0, 0.5)) !important;
}

/* Canvas Junction Node (meet point from image: green inside red ring) */
.canvas-junction-node {
  position: absolute;
  border-radius: 50%;
  background: #10b981 !important; /* Emerald green */
  border: 3.5px solid #ef4444 !important; /* Bright red outer ring */
  box-shadow: 0 1.5px 4px rgba(0,0,0,0.3);
  z-index: 2000;
  cursor: default;
  pointer-events: none;
  box-sizing: border-box;
  transform: translate(-50%, -50%); /* Centered layout placement */
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.3s ease;
}

.admin-mode-active .canvas-junction-node {
  cursor: move;
  pointer-events: auto;
}

/* Expanded transparent grab hitbox for easy mouse targeting, especially when zoomed out */
.canvas-junction-node::before {
  content: "";
  position: absolute;
  top: -10px;
  left: -10px;
  right: -10px;
  bottom: -10px;
  border-radius: 50%;
  background: transparent;
  z-index: -1;
}

.canvas-junction-node:hover {
  transform: translate(-50%, -50%) scale(1.3);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.7);
  z-index: 2001;
}

.canvas-junction-node.selected-junction {
  outline: 2.5px solid #ff7800;
  outline-offset: 3px;
  z-index: 2002;
}

/* Make sure ports appear when dragging near junction */
.canvas-junction-node.link-active-dragging:hover .card-link-port,
.canvas-junction-node.link-hovered-target .card-link-port {
  display: block !important;
}

.spouse-node-circle {
  pointer-events: auto !important;
  cursor: ew-resize !important;
}

/* Custom Polygon Vertex Handles (Admin Mode Only) */
.poly-vertex-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ea580c;
  border: 2px solid #ffffff;
  cursor: move;
  transform: translate(-50%, -50%);
  z-index: 1003;
  box-shadow: 0 1.5px 4px rgba(0,0,0,0.3);
  transition: background-color 0.2s, transform 0.2s;
}

.poly-vertex-handle:hover {
  background: #c2410c;
  transform: translate(-50%, -50%) scale(1.3);
}

/* Custom Polygon selection highlighting */
.family-group-panel-poly {
  transition: fill-opacity 0.2s, stroke-width 0.2s;
  pointer-events: visiblePainted;
}

.family-group-panel-poly.poly-selected {
  stroke-width: inherit;
  fill-opacity: 0.08 !important;
  filter: drop-shadow(0 0 5px rgba(249, 115, 22, 0.8));
}

/* Search Results Dropdown */
.search-results-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 5px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-height: 300px;
  overflow-y: auto;
  z-index: 1000;
  list-style: none;
  padding: 0;
  display: none;
}
.search-result-item {
  padding: 10px 15px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  text-align: left;
  font-size: 14px;
  color: #333;
}
.search-result-item:last-child {
  border-bottom: none;
}
.search-result-item:hover {
  background-color: #f8f9fa;
}
.search-result-item .parent-info {
  font-size: 12px;
  color: #888;
  margin-left: 8px;
}

/* Layer Control Panel */
.layer-control-panel {
  position: fixed;
  top: 70px;
  left: 20px;
  background: var(--bg-panel);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-panel);
  border-radius: 12px;
  padding: 10px;
  box-shadow: var(--shadow-panel);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-family: 'Inter', sans-serif;
  transition: opacity 0.3s ease;
}
.layer-control-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  user-select: none;
}
.layer-control-panel input[type="checkbox"] {
  accent-color: #3b82f6;
  width: 16px;
  height: 16px;
  cursor: pointer;
  margin: 0;
}

/* Transparent Layers */
.transparent-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  overflow: visible;
  pointer-events: none; /* Let clicks pass through empty areas */
}

#layer-locations {
  z-index: 4; /* Locations placed above polygons and labels */
}

#svg-layer {
  z-index: 3; /* Connection lines below locations */
}

#layer-events {
  z-index: 5; /* Events above locations, below person cards */
}

/* Markers */
.layer-marker {
  position: absolute;
  pointer-events: auto; /* Enable clicks on the marker itself */
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translate(-50%, -50%); /* Center on coordinate */
  cursor: pointer;
}
.marker-location {
  z-index: 4; /* Locations placed above polygons and labels, below cards */
}
.marker-event {
  z-index: 5; /* Events placed above locations, below cards */
}
.layer-marker:hover {
  transform: translate(-50%, -50%) scale(1.15);
  z-index: 20;
}

.marker-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  border: 2px solid white;
}

/* Event Marker */
.marker-event .marker-icon {
  background: linear-gradient(135deg, #fef08a, #f59e0b);
  color: #78350f;
}
.marker-event .marker-label {
  background: rgba(254, 240, 138, 0.9);
  color: #78350f;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Location Marker */
.marker-location .marker-icon {
  background: linear-gradient(135deg, #bbf7d0, #22c55e);
  color: #14532d;
}
.marker-location .marker-label {
  background: rgba(187, 247, 208, 0.9);
  color: #14532d;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.marker-label {
  margin-top: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  backdrop-filter: blur(4px);
  pointer-events: none;
}

/* Highlighted Layer Markers */
.layer-marker.highlight .marker-icon {
  animation: pulse-marker-icon 1.5s infinite alternate;
  border-color: #ff7800 !important;
  box-shadow: 0 0 15px rgba(255, 120, 0, 0.8) !important;
}

@keyframes pulse-marker-icon {
  from {
    box-shadow: 0 0 10px rgba(255, 120, 0, 0.6);
  }
  to {
    box-shadow: 0 0 25px rgba(255, 120, 0, 1), 0 0 10px rgba(255, 120, 0, 0.5);
  }
}

/* Relation Searchable Checklist Box */
.relation-selector-box {
  border: 1px solid var(--border-panel);
  border-radius: 8px;
  background: rgba(148, 163, 184, 0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-top: 4px;
}

.relation-search {
  border: none !important;
  border-bottom: 1px solid var(--border-panel) !important;
  border-radius: 0 !important;
  background: transparent !important;
  padding: 8px 12px !important;
  font-size: 13px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}

.relation-checklist {
  max-height: 120px;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.relation-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  transition: background 0.15s ease;
  color: var(--text-main);
}

.relation-item:hover {
  background: rgba(148, 163, 184, 0.08);
}

.relation-item.checked {
  background: rgba(37, 99, 235, 0.15);
  color: var(--text-accent);
  font-weight: 600;
}

.relation-item input[type="checkbox"] {
  margin: 0;
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: var(--text-accent);
}

/* Selected Relation Tags/Badges */
.selected-relation-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(148, 163, 184, 0.02);
  border-bottom: 1px dashed var(--border-panel);
  min-height: 0;
}

.selected-relation-tags:empty {
  display: none;
}

.relation-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(37, 99, 235, 0.1);
  color: var(--text-accent);
  border: 1px solid rgba(37, 99, 235, 0.25);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.relation-tag:hover {
  background: rgba(37, 99, 235, 0.15);
}

.relation-tag-remove {
  cursor: pointer;
  font-weight: 800;
  color: var(--text-accent);
  opacity: 0.6;
  transition: opacity 0.15s ease;
}

.relation-tag-remove:hover {
  opacity: 1;
}

/* Relationship Highlighting and Dimming Engine */
.relationship-highlight-active .person-card:not(.highlight) {
  opacity: 0.09 !important;
  filter: grayscale(85%) !important;
  pointer-events: none;
  transition: opacity 0.3s ease, filter 0.3s ease;
}

.relationship-highlight-active .layer-marker:not(.highlight) {
  opacity: 0.09 !important;
  filter: grayscale(85%) !important;
  pointer-events: none;
  transition: opacity 0.3s ease, filter 0.3s ease;
}

.relationship-highlight-active .connector-line:not(.line-highlight),
.relationship-highlight-active .spouse-connector:not(.line-highlight),
.relationship-highlight-active .custom-visual-line:not(.line-highlight) {
  opacity: 0.05 !important;
  transition: opacity 0.3s ease;
}

/* Beautiful custom glow aura (no scaling/enlargement) */
.relationship-highlight-active .person-card.highlight {
  animation: pulse-aura-only 1.5s infinite alternate !important;
  /* NO transform override here so the natural size/hover size stays fixed! */
  z-index: 100 !important;
  opacity: 1 !important;
  transition: opacity 0.3s ease;
}

/* Specific glowing colors per card theme */
.relationship-highlight-active .person-card.highlight.male:not(.main-line) {
  --glow-color: rgba(59, 130, 246, 0.7);
  border-color: rgba(59, 130, 246, 0.95) !important;
}

.relationship-highlight-active .person-card.highlight.female:not(.main-line) {
  --glow-color: rgba(236, 72, 153, 0.7);
  border-color: rgba(236, 72, 153, 0.95) !important;
}

.relationship-highlight-active .person-card.highlight.main-line {
  --glow-color: rgba(245, 158, 11, 0.8);
  border-color: rgba(245, 158, 11, 1) !important;
}
/* Glowing aura for markers (locations/events) */
.relationship-highlight-active .layer-marker.highlight {
  opacity: 1 !important;
  z-index: 100 !important;
  /* NO transform override here so the inline translate & scale remain intact! */
  transition: opacity 0.3s ease;
}

/* Event marker aura: icon and text box */
.relationship-highlight-active .layer-marker.highlight.marker-event .marker-icon {
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.8), 0 0 30px rgba(245, 158, 11, 0.5) !important;
  border-color: rgba(245, 158, 11, 1) !important;
  animation: pulse-marker-icon-orange 1.5s infinite alternate !important;
}

.relationship-highlight-active .layer-marker.highlight.marker-event .marker-label {
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.7), 0 0 24px rgba(245, 158, 11, 0.4) !important;
  border-color: rgba(245, 158, 11, 0.8) !important;
}

/* Location marker aura: icon and text box */
.relationship-highlight-active .layer-marker.highlight.marker-location .marker-icon {
  box-shadow: 0 0 15px rgba(34, 197, 94, 0.8), 0 0 30px rgba(34, 197, 94, 0.5) !important;
  border-color: rgba(34, 197, 94, 1) !important;
  animation: pulse-marker-icon-green 1.5s infinite alternate !important;
}

.relationship-highlight-active .layer-marker.highlight.marker-location .marker-label {
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.7), 0 0 24px rgba(34, 197, 94, 0.4) !important;
  border-color: rgba(34, 197, 94, 0.8) !important;
}

.relationship-highlight-active .canvas-annotation:not(.highlight) {
  opacity: 0.09 !important;
  filter: grayscale(85%) !important;
  pointer-events: none;
  transition: opacity 0.3s ease, filter 0.3s ease;
}

.relationship-highlight-active .canvas-annotation.highlight {
  opacity: 1 !important;
  box-shadow: 0 0 20px rgba(168, 85, 247, 0.7), 0 0 35px rgba(168, 85, 247, 0.4) !important;
  z-index: 100 !important;
  transition: opacity 0.3s ease, box-shadow 0.3s ease;
}

.relationship-highlight-active .canvas-junction-node:not(.highlight) {
  opacity: 0.06 !important;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.relationship-highlight-active .canvas-junction-node.highlight {
  opacity: 1 !important;
}

@keyframes pulse-aura-only {
  from {
    box-shadow: 0 0 10px var(--glow-color);
  }
  to {
    box-shadow: 0 0 25px var(--glow-color), 0 0 40px var(--glow-color);
  }
}

@keyframes pulse-marker-icon-orange {
  from {
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
  }
  to {
    box-shadow: 0 0 20px rgba(245, 158, 11, 1), 0 0 30px rgba(245, 158, 11, 0.4);
  }
}

@keyframes pulse-marker-icon-green {
  from {
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
  }
  to {
    box-shadow: 0 0 20px rgba(34, 197, 94, 1), 0 0 30px rgba(34, 197, 94, 0.4);
  }
}

/* Floating toggle button for spawner toolkit bar */
.spawner-panel-toggle-btn {
  position: fixed;
  bottom: 24px;
  left: 20px;
  width: 42px;
  height: 42px;
  background: #38bdf8; /* sky blue theme color */
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: #0f172a; /* dark text/icon */
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(56, 189, 248, 0.3);
  z-index: 1400;
  transition: all 0.2s ease;
  outline: none;
}
.spawner-panel-toggle-btn:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 6px 20px rgba(56, 189, 248, 0.5);
  background: #0ea5e9;
  color: #ffffff;
}

/* Bottom Spawner Panel (Admin Palette) */
.bottom-spawner-panel {
  position: fixed;
  bottom: calc(60px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 1200px;
  background: rgba(20, 20, 30, 0.92);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 1500;
  color: #ffffff;
  font-family: 'Inter', sans-serif;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  transition: all 0.3s ease;
}

.spawner-header {
  height: 32px; /* Reduced from 36px */
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: 11px; /* Reduced from 12px */
  font-weight: 600;
  color: #38bdf8;
}

.spawner-content {
  height: 75px; /* Reduced from 120px to save 45px vertical space */
  display: flex;
  padding: 6px 12px; /* Reduced padding */
  gap: 12px;
  box-sizing: border-box;
}

.spawner-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.spawner-section h5 {
  margin: 0 0 2px 0; /* Reduced from 6px */
  font-size: 9px; /* Reduced from 11px */
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(255, 255, 255, 0.5);
}

.spawner-section-divider {
  width: 1px;
  background: rgba(255, 255, 255, 0.1);
  height: 100%;
}

.spawner-chips-container {
  flex: 1;
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 8px;
  padding: 4px 16px 8px 16px; /* Added left/right padding and bottom breathing room */
  align-items: center;
}

.spawner-chip {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  user-select: none;
}

.spawner-chip:hover {
  background: #38bdf8;
  border-color: #38bdf8;
  color: #000000;
  transform: translateY(-1px);
  box-shadow: 0 2px 10px rgba(56, 189, 248, 0.3);
}

.spawner-chip.active-tool {
  background: #f59e0b;
  border-color: #f59e0b;
  color: #000000;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.5);
  animation: pulse-spawner-active 1.5s infinite alternate;
}

@keyframes pulse-spawner-active {
  from { box-shadow: 0 0 6px rgba(245, 158, 11, 0.4); }
  to { box-shadow: 0 0 16px rgba(245, 158, 11, 0.8); }
}

.spawner-chips-container::-webkit-scrollbar {
  height: 8px; /* Thickened for much easier cursor grabbing */
}
.spawner-chips-container::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05); /* Dark track background for guidance */
  border-radius: 4px;
}
.spawner-chips-container::-webkit-scrollbar-thumb {
  background: rgba(56, 189, 248, 0.4); /* Premium sky blue scrollbar matching theme */
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.spawner-chips-container::-webkit-scrollbar-thumb:hover {
  background: rgba(56, 189, 248, 0.8); /* Glow brighter on hover */
}

.placement-mode-active {
  cursor: crosshair !important;
}

/* Release grab/grabbing cursor during relationship/aura highlight and return to default */
.relationship-highlight-active,
.relationship-highlight-active #viewer-container,
.relationship-highlight-active #tree-board {
  cursor: default !important;
}
.relationship-highlight-active #viewer-container:active,
.relationship-highlight-active #tree-board:active {
  cursor: default !important;
}

/* Fade out spouse circles, family group polygons, and polygon labels in focus/aura modes */
.relationship-highlight-active .spouse-node-circle:not(.line-highlight) {
  opacity: 0.05 !important;
  transition: opacity 0.3s ease;
}
.relationship-highlight-active .spouse-node-circle.line-highlight {
  opacity: 1 !important;
  transition: opacity 0.3s ease;
}
.relationship-highlight-active .family-group-panel-poly {
  opacity: 0.05 !important;
  transition: opacity 0.3s ease;
}
.relationship-highlight-active .family-group-panel-poly.highlight {
  opacity: 0.28 !important;
  stroke-width: 4px !important;
}
/* Ensure the Prophets area box fades out when relationship highlight is active */
.relationship-highlight-active #svg-poly-poly-custom-1785777570404:not(.highlight):not(.poly-selected),
.relationship-highlight-active #svg-poly-custom-1785777570404:not(.highlight):not(.poly-selected) {
  opacity: 0.05 !important;
}
.relationship-highlight-active #label-poly-poly-custom-1785777570404:not(.highlight),
.relationship-highlight-active #label-poly-custom-1785777570404:not(.highlight) {
  opacity: 0.09 !important;
}
.relationship-highlight-active .family-group-label {
  opacity: 0.09 !important;
  transition: opacity 0.3s ease;
}
.relationship-highlight-active .family-group-label.highlight {
  opacity: 1 !important;
  z-index: 100 !important;
}

.tree-highlight-active .spouse-node-circle:not(.line-highlight) {
  opacity: 0.05 !important;
  transition: opacity 0.3s ease;
}
.tree-highlight-active .spouse-node-circle.line-highlight {
  opacity: 1 !important;
  transition: opacity 0.3s ease;
}
.tree-highlight-active .family-group-panel-poly {
  opacity: 0.05 !important;
  transition: opacity 0.3s ease;
}
/* Ensure the Prophets area box fades out when tree highlight is active */
.tree-highlight-active #svg-poly-poly-custom-1785777570404:not(.highlight):not(.poly-selected),
.tree-highlight-active #svg-poly-custom-1785777570404:not(.highlight):not(.poly-selected) {
  opacity: 0.05 !important;
}
.tree-highlight-active #label-poly-poly-custom-1785777570404:not(.highlight),
.tree-highlight-active #label-poly-custom-1785777570404:not(.highlight) {
  opacity: 0.09 !important;
}
.tree-highlight-active .family-group-label {
  opacity: 0.09 !important;
  transition: opacity 0.3s ease;
}

/* Filter inactive styles */
.filter-inactive {
  pointer-events: none !important;
  transition: opacity 0.3s ease, filter 0.3s ease;
}
.person-card.filter-inactive,
.canvas-annotation.filter-inactive,
.family-group-label.filter-inactive,
.layer-marker.filter-inactive {
  opacity: 0.09 !important;
  filter: grayscale(85%) !important;
}
.connector-line.filter-inactive,
.spouse-connector.filter-inactive,
.spouse-node-circle.filter-inactive,
.family-group-panel-poly.filter-inactive {
  opacity: 0.05 !important;
}
.canvas-junction-node.filter-inactive {
  opacity: 0.06 !important;
}

/* Block Print / PDF Saving */
@media print {
  html, body {
    display: none !important;
  }
}

.copyright-notice {
  position: fixed;
  bottom: 10px;
  right: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  padding: 3px 7px;
  border-radius: 4px;
  font-size: 10px;
  color: var(--text-muted);
  z-index: 9999;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

/* Mobile SVG Animation Optimization */
@media (max-width: 768px) {
  .connector-line.main-line {
    animation: none !important;
  }
}

/* Hide connection lines & spouse node circles completely under prophets filter */
.prophets-hide {
  display: none !important;
}

/* Samuel and Prophet Card Visibility and Styling Rules */

.prophets-filter-active .person-card.samuel,
.prophets-filter-active .person-card.prophet:not(.main-line) {
  display: flex !important;
  /* Light purple color (Light Mode) */
  background: var(--bg-card-prophet) !important;
  border: 2.5px solid var(--border-card-prophet) !important;
  box-shadow: none !important;
}

.prophets-filter-active .person-card.samuel:hover,
.prophets-filter-active .person-card.prophet:not(.main-line):hover {
  box-shadow: 0 0 15px rgba(168, 85, 247, 0.45) !important;
}

/* Selected states for prophet cards */
.prophets-filter-active .person-card.samuel.selected-for-edit,
.prophets-filter-active .person-card.prophet:not(.main-line).selected-for-edit {
  box-shadow: 0 0 15px rgba(255, 120, 0, 0.6) !important;
}
.prophets-filter-active .person-card.samuel.selected-for-edit:hover,
.prophets-filter-active .person-card.prophet:not(.main-line).selected-for-edit:hover {
  box-shadow: 0 0 15px rgba(255, 120, 0, 0.75) !important;
}

.prophets-filter-active .person-card.samuel .card-title,
.prophets-filter-active .person-card.prophet:not(.main-line) .card-title {
  color: #4a044e !important;
}

.prophets-filter-active .person-card.samuel .card-eng,
.prophets-filter-active .person-card.prophet:not(.main-line) .card-eng {
  color: #701a75 !important;
}

[data-theme="dark"] .prophets-filter-active .person-card.samuel,
[data-theme="dark"] .prophets-filter-active .person-card.prophet:not(.main-line) {
  background: var(--bg-card-prophet) !important;
  border: 2.5px solid var(--border-card-prophet) !important;
  box-shadow: none !important;
}

[data-theme="dark"] .prophets-filter-active .person-card.samuel:hover,
[data-theme="dark"] .prophets-filter-active .person-card.prophet:not(.main-line):hover {
  box-shadow: 0 0 20px rgba(192, 132, 252, 0.5) !important;
}

[data-theme="dark"] .prophets-filter-active .person-card.samuel.selected-for-edit,
[data-theme="dark"] .prophets-filter-active .person-card.prophet:not(.main-line).selected-for-edit {
  box-shadow: 0 0 20px rgba(255, 120, 0, 0.8) !important;
}
[data-theme="dark"] .prophets-filter-active .person-card.samuel.selected-for-edit:hover,
[data-theme="dark"] .prophets-filter-active .person-card.prophet:not(.main-line).selected-for-edit:hover {
  box-shadow: 0 0 25px rgba(255, 120, 0, 0.95) !important;
}

[data-theme="dark"] .prophets-filter-active .person-card.samuel .card-title,
[data-theme="dark"] .prophets-filter-active .person-card.prophet:not(.main-line) .card-title {
  color: #fdf4ff !important;
}

[data-theme="dark"] .prophets-filter-active .person-card.samuel .card-eng,
[data-theme="dark"] .prophets-filter-active .person-card.prophet:not(.main-line) .card-eng {
  color: #e9d5ff !important;
}

/* Enable aura highlight glow for Samuel and Prophets under prophets filter active */
.prophets-filter-active.relationship-highlight-active .person-card.highlight.samuel,
.prophets-filter-active.relationship-highlight-active .person-card.highlight.prophet:not(.main-line) {
  animation: pulse-aura-only 1.5s infinite alternate !important;
  --glow-color: rgba(168, 85, 247, 0.75);
  border-color: rgba(168, 85, 247, 0.95) !important;
}

[data-theme="dark"] .prophets-filter-active.relationship-highlight-active .person-card.highlight.samuel,
[data-theme="dark"] .prophets-filter-active.relationship-highlight-active .person-card.highlight.prophet:not(.main-line) {
  animation: pulse-aura-only 1.5s infinite alternate !important;
  --glow-color: rgba(192, 132, 252, 0.8);
  border-color: rgba(192, 132, 252, 0.95) !important;
}

/* Related People Checkbox List Styles */
.related-people-checkbox-list {
  max-height: 120px;
  overflow-y: auto;
  border: 1px solid var(--border-panel);
  border-radius: 8px;
  padding: 8px;
  background: rgba(148, 163, 184, 0.04);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.related-person-checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-main);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  transition: background 0.15s ease;
}

.related-person-checkbox-item:hover {
  background: rgba(148, 163, 184, 0.08);
}

.related-person-checkbox-item input[type="checkbox"] {
  cursor: pointer;
  width: 14px;
  height: 14px;
  margin: 0;
}

.related-person-checkbox-item .person-id-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
}

/* Prophets Aura Glow Effect */
.person-card.prophets-aura {
  animation: prophets-aura-glow 2s infinite alternate !important;
  border-width: 2.5px !important;
  box-shadow: 0 0 15px rgba(236, 72, 153, 0.6), inset 0 0 10px rgba(236, 72, 153, 0.3) !important;
}

[data-theme="dark"] .person-card.prophets-aura {
  animation: prophets-aura-glow-dark 2s infinite alternate !important;
  box-shadow: 0 0 20px rgba(236, 72, 153, 0.8), inset 0 0 12px rgba(236, 72, 153, 0.4) !important;
}

@keyframes prophets-aura-glow {
  0% {
    border-color: rgba(236, 72, 153, 0.8) !important;
    box-shadow: 0 0 15px rgba(236, 72, 153, 0.6), inset 0 0 8px rgba(236, 72, 153, 0.3) !important;
  }
  100% {
    border-color: rgba(168, 85, 247, 0.9) !important;
    box-shadow: 0 0 25px rgba(168, 85, 247, 0.9), inset 0 0 15px rgba(168, 85, 247, 0.5) !important;
  }
}

@keyframes prophets-aura-glow-dark {
  0% {
    border-color: rgba(236, 72, 153, 0.9) !important;
    box-shadow: 0 0 20px rgba(236, 72, 153, 0.7), inset 0 0 10px rgba(236, 72, 153, 0.4) !important;
  }
  100% {
    border-color: rgba(192, 132, 252, 1) !important;
    box-shadow: 0 0 35px rgba(192, 132, 252, 1), inset 0 0 20px rgba(192, 132, 252, 0.6) !important;
  }
}

/* SVG Polygon Glow Animation */
svg path.prophets-aura {
  animation: svg-poly-glow 3s infinite alternate !important;
  stroke: #db2777 !important;
  stroke-width: 4px !important;
  fill-opacity: 0.12 !important;
  stroke-dasharray: none !important;
}

@keyframes svg-poly-glow {
  0% {
    stroke: #db2777 !important;
    fill: rgba(219, 39, 119, 0.12) !important;
    filter: drop-shadow(0 0 5px rgba(219, 39, 119, 0.5));
  }
  100% {
    stroke: #9333ea !important;
    fill: rgba(147, 51, 234, 0.18) !important;
    filter: drop-shadow(0 0 15px rgba(147, 51, 234, 0.8));
  }
}

/* Label / Name Box Prophets Aura Glow Style */
.family-group-label.prophets-aura {
  animation: prophets-label-aura-glow 2s infinite alternate !important;
  border-width: 2px !important;
  font-weight: 800 !important;
  box-shadow: 0 0 15px rgba(236, 72, 153, 0.6), 0 2px 4px rgba(0, 0, 0, 0.05) !important;
}

@keyframes prophets-label-aura-glow {
  0% {
    border-color: rgba(236, 72, 153, 0.8) !important;
    box-shadow: 0 0 12px rgba(236, 72, 153, 0.6) !important;
  }
  100% {
    border-color: rgba(168, 85, 247, 0.9) !important;
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.9) !important;
  }
}

/* Settings Modal Specific Styles */
.settings-body {
  padding: 24px;
  max-height: 60vh !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
}

.settings-group {
  margin-bottom: 24px;
}

.settings-group h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-panel);
  padding-bottom: 6px;
}

.settings-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 12px 0;
}

.settings-info {
  flex: 1;
}

.settings-info label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: block;
  margin-bottom: 4px;
}

.settings-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Switch Toggle UI Component */
.switch-toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-round {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-panel);
  transition: .3s;
  border-radius: 24px;
}

.slider-round:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  transition: .3s;
  border-radius: 50%;
}

.switch-toggle input:checked + .slider-round {
  background-color: #3b82f6;
}

.switch-toggle input:checked + .slider-round:before {
  transform: translateX(20px);
}

/* Settings Modal Button Styles */
.settings-btn {
  background: transparent;
  border: 1px solid var(--border-panel);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.settings-btn svg {
  stroke: currentColor;
}

.settings-btn.primary-outline {
  border-color: #3b82f6;
  color: #3b82f6;
}

.settings-btn.primary-outline:hover {
  background: rgba(59, 130, 246, 0.08);
  border-color: #2563eb;
  color: #2563eb;
}

/* Mobile-mode & Bezel-less Phones Optimization Overrides */
@media (max-width: 1024px), .mobile-mode {
  /* Prevent iOS Safari zooming on focus by enforcing 16px font-size */
  input[type="text"],
  input[type="password"],
  input[type="search"],
  select,
  textarea,
  .search-box {
    font-size: 16px !important;
  }

  /* Responsive Modal Dialog Boxes (prevents horizontal overflow on phones) & Scroll Fix */
  #help-guide-modal,
  #install-guide-modal,
  #desktop-license-modal {
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important; /* Top-aligned so it scrolls down naturally */
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important; /* Smooth momentum scrolling on iOS */
    padding: 40px 10px !important;
    box-sizing: border-box !important;
  }

  #help-guide-modal > div,
  #install-guide-modal > div,
  #desktop-license-modal > div {
    width: 92% !important;
    max-width: 500px !important;
    margin: 0 auto !important; /* Center horizontally */
    padding: 24px 20px !important;
    box-sizing: border-box !important;
    max-height: none !important; /* Let it grow naturally */
    overflow-y: visible !important; /* Disable inner scroll */
  }

  /* Optimize search-panel position with safe areas */
  #search-panel {
    top: calc(-4px + env(safe-area-inset-top, 0px)) !important;
    right: calc(8px + env(safe-area-inset-right, 0px)) !important;
  }

  /* Optimize study-panel width and safe-area paddings */
  #study-panel {
    width: 55% !important;
    max-width: 60% !important;
    right: -55% !important;
    bottom: calc(17px + env(safe-area-inset-bottom, 0px)) !important;
    padding-right: calc(15px + env(safe-area-inset-right, 0px)) !important;
    padding-left: calc(15px + env(safe-area-inset-left, 0px)) !important;
  }
  #study-panel.active {
    right: 0 !important;
  }
  
  /* Optimize control panel (zoom & buttons) position for bottom indicator */
  #control-panel {
    bottom: calc(-28px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* iPhone SE & home-button devices height optimization (where env(safe-area-inset-bottom) is 0) */
@media (max-width: 768px) and (max-height: 750px) {
  #control-panel {
    bottom: 4px !important;
  }
  #study-panel {
    bottom: 49px !important;
  }
  
  /* Lower title and search by 3px, and layer control panel by 2px */
  header, .ios-device header {
    top: calc(-4px + env(safe-area-inset-top, 0px)) !important;
  }
  #search-panel, .ios-device #search-panel {
    top: calc(-1px + env(safe-area-inset-top, 0px)) !important;
  }
  .layer-control-panel, .ios-device .layer-control-panel {
    top: calc(30px + env(safe-area-inset-top, 0px)) !important;
  }
  
  #study-panel .panel-header {
    padding-left: 1.6px !important;
    padding-right: 1.6px !important;
  }
  #study-panel .panel-header::after {
    left: 1.6px !important;
    right: 1.6px !important;
  }
  #study-panel .panel-body {
    padding-left: 1.6px !important;
    padding-right: 1.6px !important;
  }
  #study-panel .panel-footer {
    padding-left: 1.6px !important;
    padding-right: 1.6px !important;
  }
  #study-panel .panel-footer::before {
    left: 1.6px !important;
    right: 1.6px !important;
  }
  #study-panel .desc-text {
    padding-left: 1.6px !important;
    padding-right: 1.6px !important;
  }
  #study-panel .note-textarea {
    padding-left: 1.6px !important;
    padding-right: 1.6px !important;
  }
  #study-panel .resource-input {
    padding-left: 1.6px !important;
    padding-right: 1.6px !important;
  }
  #study-panel .resource-item {
    padding-left: 1.6px !important;
    padding-right: 1.6px !important;
  }
}

