:root {
  --bg-deep: #050a14;
  --bg-dark: #0f172a;
  --panel-bg: rgba(15, 23, 42, 0.75);
  --panel-border: rgba(255, 255, 255, 0.12);
  --glass-border: rgba(255, 255, 255, 0.15);
  --glass-highlight: rgba(255, 255, 255, 0.05);

  --text-primary: rgba(255, 255, 255, 0.92);
  --text-secondary: rgba(255, 255, 255, 0.60);

  --accent-primary: #38bdf8;
  /* Sky blue */
  --accent-secondary: #818cf8;
  /* Indigo */
  --accent-glow: rgba(56, 189, 248, 0.3);

  --warn: #fbbf24;
  --err: #fb7185;
  --ok: #34d399;

  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  font-family: var(--font-sans);
  background:
    radial-gradient(circle at 10% 20%, rgba(56, 189, 248, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(129, 140, 248, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(52, 211, 153, 0.05) 0%, transparent 60%),
    var(--bg-deep);
  background-attachment: fixed;
  color: var(--text-primary);
  overflow: hidden;
  /* App handles scrolling */
}

/* ... existing styles ... */

/* Global Cursor Glow */
#cursor-glow {
  position: fixed;
  top: 0;
  left: 0;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.15) 0%, transparent 70%);
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
  transition: opacity 0.3s;
  mix-blend-mode: screen;
}

/* Panel Styles */
.panel {
  display: flex;
  flex-direction: column;
  /* Spotlight effect background */
  background:
    radial-gradient(800px circle at var(--mouse-x, 50%) var(--mouse-y, 50%), rgba(56, 189, 248, 0.06), transparent 40%),
    var(--panel-bg);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  transition: border-color 0.3s, transform 0.3s;
}

/* Background Particles Canvas */
#bg-particles {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* App Container */
#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Glassmorphism Utilities */
/* Glassmorphism Utilities */
.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(5, 10, 20, 0.85);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border-bottom: 1px solid var(--glass-border);
  z-index: 10;
  height: 64px;
}

.branding {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.5));
  animation: float 6s ease-in-out infinite;
}

@keyframes float {
  0% {
    transform: translateY(0px);
  }

  50% {
    transform: translateY(-3px);
  }

  100% {
    transform: translateY(0px);
  }
}

.app-name {
  font-weight: 800;
  font-size: 1.25rem;
  background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.01em;
}

.search-container {
  position: relative;
}

input[type="search"] {
  width: 300px;
  padding: 10px 16px;
  padding-left: 40px;
  /* Space for icon if we had one */
  border-radius: 99px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

input[type="search"]:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
  width: 340px;
}

/* correction */
.correction {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
}

.waLink {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 99px;
  border: 1px solid rgba(52, 211, 153, 0.2);
  background: rgba(52, 211, 153, 0.08);
  /* Low opacity green */
  color: var(--ok);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.2s;
}

.waLink:hover {
  background: rgba(52, 211, 153, 0.15);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(52, 211, 153, 0.2);
}

/* Layout Main */
.layout {
  display: grid;
  grid-template-columns: 320px minmax(500px, 1fr) 340px;
  gap: 16px;
  padding: 16px;
  /* flex: 1 combined with min-height: 0 allows this to grow/shrink to fill space */
  flex: 1;
  min-height: 0;
  opacity: 0;
  animation: fadeIn 0.8s ease-out forwards 0.2s;
}

@keyframes fadeIn {
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

#issuesPanel {
  animation: slideUp 0.3s ease-out;
  border-top: 1px solid var(--glass-border);
}

.detailsCollapsed .layout {
  grid-template-columns: 60px minmax(500px, 1fr) 340px;
}

.outlineCollapsed .layout {
  grid-template-columns: 320px minmax(500px, 1fr) 60px;
}

.detailsCollapsed.outlineCollapsed .layout {
  grid-template-columns: 60px minmax(500px, 1fr) 60px;
}

/* Panel Styles */
.panel {
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.panel:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.panelTitle {
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--glass-border);
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Collapsed Panel Behavior */
.detailsCollapsed #detailsPanel .panelTitle span,
.outlineCollapsed #outlinePanel .panelTitle span {
  display: none;
}

.detailsCollapsed #detailsPanel .panelTitle,
.outlineCollapsed #outlinePanel .panelTitle {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.detailsCollapsed #detailsPanel .panelBody,
.outlineCollapsed #outlinePanel .panelBody {
  display: none;
}

.panelBody {
  padding: 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.rightColumn {
  display: grid;
  grid-template-rows: 1fr;
  gap: 16px;
  height: 100%;
  min-height: 0;
}

/* Graph Area */
.graphBody {
  padding: 4px;
  background: rgba(0, 0, 0, 0.2);
  /* slightly darker for contrast with nodes */
  position: relative;
  overflow: hidden;
}

#graph {
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#graph:active {
  cursor: grabbing;
}

/* Buttons & Interactions */
.iconBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s var(--ease-spring);
}

.iconBtn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  transform: translateY(-1px);
}

.iconBtn:active {
  transform: translateY(1px);
}

.iconBtn.active {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.3);
}

#resetGraph {
  width: auto;
  padding: 0 10px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Tree List Items */
.treeItem,
.issueItem,
.personRow {
  padding: 10px 12px;
  margin-bottom: 4px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
  font-size: 0.95rem;
}

.treeItem:hover,
.personRow:hover {
  background: rgba(255, 255, 255, 0.08);
}

.treeItem.active,
.personRow.active {
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.3);
  color: #fff;
}

/* Outline Specifics */
.outline ul {
  list-style: none;
  margin: 0;
  padding-left: 10px;
  /* Reduced tab length */
}

.outline li {
  margin: 1px 0;
  /* Reduced bullet spacing */
}

.outline .personRow,
.outline .marriageRow {
  padding: 4px 8px;
  /* More compact rows */
  margin-bottom: 2px;
  font-size: 0.85rem;
}

/* Issues */
.issueItem {
  background: rgba(251, 113, 133, 0.1);
  border-color: rgba(251, 113, 133, 0.2);
  cursor: default;
}

.issueItem .sev {
  font-weight: 700;
  margin-right: 6px;
}

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  margin-left: 6px;
  vertical-align: middle;
}

.pill.ok {
  color: var(--ok);
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.2);
}

/* SVG Graph Nodes */
/* We style these via CSS where possible, but D3/JS often sets inline styles. 
   These target the classes we expect. */

text {
  font-family: var(--font-sans);
}

#graph .nodeName {
  fill: #fff;
  font-weight: 600;
  font-size: 14px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

#graph .nodeMeta {
  fill: var(--text-secondary);
  font-size: 11px;
}

#graph .nodeAka {
  fill: var(--warn);
  font-weight: 700;
  font-style: italic;
}

/* Media Queries for responsive */
@media (max-width: 980px) {
  .layout {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    /* Allow page logic scroll if min-heights exceed screen */
    padding: 8px;
    /* Reduce padding */
    gap: 8px;
  }

  /* Hide panels user doesn't want on mobile */
  #toggleIssues {
    display: none !important;
  }

  #detailsPanel,
  #graphPanel .panelTitle .panelActions #zoomIn,
  #graphPanel .panelTitle .panelActions #zoomOut,
  #graphPanel .panelTitle .panelActions #panLeft,
  #graphPanel .panelTitle .panelActions #panRight,
  #graphPanel .panelTitle .panelActions #panUp,
  #graphPanel .panelTitle .panelActions #panDown,
  #graphPanel .panelTitle span:first-child,
  /* Hide "Subtree" title text to save space */
  #graphPanel .panelTitle+.panelBody+.panelTitle,
  /* Details header */
  #details {
    display: none !important;
  }

  /* Ensure Graph and Outline are visible and sized well */
  #graphPanel {
    flex: 2;
    /* Graph takes 2/3 space */
    min-height: 50vh;
    margin-bottom: 0;
  }

  #outlinePanel {
    flex: 1;
    /* Outline takes 1/3 space */
    min-height: 200px;
  }

  .panel {
    border-radius: 12px;
  }

  .graphBody {
    height: 100%;
    /* Fill flex parent */
  }

  /* Compact topbar */
  .topbar {
    padding: 8px 12px;
    height: auto;
    flex-wrap: wrap;
    gap: 8px;
  }

  .branding {
    transform: scale(0.9);
    transform-origin: left center;
  }

  .controls {
    order: 3;
    width: 100%;
    margin-top: 4px;
  }

  .correction {
    display: none;
    /* Hide correction link on mobile to save space */
  }

  input[type="search"] {
    width: 100%;
    font-size: 16px;
    /* Prevent IOS zoom on focus */
  }
}

/* Graph Node Interactions */
.node-group {
  transition: transform 0.5s var(--ease-spring), opacity 0.3s;
}

.edge-path {
  transition: opacity 0.3s;
}

#graph rect {
  transition: all 0.3s var(--ease-spring);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.2));
}

#graph g:hover rect {
  stroke: var(--accent-primary);
  stroke-width: 2px;
  filter: drop-shadow(0 0 15px var(--accent-glow));
}

#graph g:hover .nodeName {
  fill: #fff;
  text-shadow: 0 0 10px rgba(56, 189, 248, 0.8);
}

#graph path {
  transition: stroke-width 0.3s;
}

#graph path:hover {
  stroke-width: 3px;
  filter: drop-shadow(0 0 5px var(--accent-primary));
}