:root {
    --rootNode-ring-color: rgba(255, 205, 60, 0.9);
    --rootNode-ring-width: 1.3px;
    --graph-editor-bg: color-mix(in srgb, var(--bg-base, #121214) 94%, transparent);
    --graph-editor-border: var(--border-subtle, rgba(255,255,255,.2));
    --graph-selection: #4da3ff;
    --graph-locked: #8b9299;
    --graph-danger: #dc3545;
}


.graph-edit-toolbar {
  line-height: 1; 
}

.graph-edit-toolbar button[aria-pressed="true"] {
  background: var(--graph-selection);
  border-color: color-mix(in srgb, var(--graph-selection) 70%, #fff);
}

.graph-editor {
  position: fixed;
  z-index: 1100;
  inset: 0 0 0 auto;
  width: min(550px, 100vw);
  padding: calc(18px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
  color: var(--text-primary, #f8f9fa);
  background: var(--graph-editor-bg);
  backdrop-filter: blur(16px);
  border-left: 1px solid var(--graph-editor-border);
  box-shadow: -14px 0 38px rgba(0,0,0,.35);
  transform: translateX(105%);
  transition: transform .22s ease;
}

.graph-editor.is-open { transform: translateX(0); }
.graph-editor-header { display: flex; justify-content: space-between; gap: 1rem; align-items: start; }
.graph-editor-header h2 { margin: 0; font-size: 1.35rem; }
.graph-editor-eyebrow { color: var(--text-secondary, #adb5bd); text-transform: uppercase; letter-spacing: .08em; }
.graph-editor-close { border: 0; background: transparent; color: inherit; font-size: 2rem; line-height: 1; }
.graph-editor-message { min-height: 1.5rem; margin: .75rem 0; color: var(--text-secondary, #adb5bd); }
.graph-editor-message.is-error { color: #ff8d98; }
.graph-editor-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .75rem; }
.graph-editor-form label { display: grid; gap: .3rem; font-size: .82rem; color: var(--text-secondary, #adb5bd); }
.graph-editor input, .graph-editor select {
  width: 100%; min-height: 42px; padding: .55rem .65rem; color: var(--text-primary, #f8f9fa);
  background: color-mix(in srgb, var(--bg-base, #121214) 80%, #fff 4%);
  border: 1px solid var(--graph-editor-border); border-radius: .45rem;
}
.graph-portrait-field { margin-top: .75rem; }
.graph-editor-actions { display: flex; gap: .5rem; margin-top: 1rem; }
.graph-relations { margin-top: 1.4rem; padding-top: 1rem; border-top: 1px solid var(--graph-editor-border); }
.graph-relations h3 { font-size: 1rem; }
.graph-inline-form { display: grid; gap: .55rem; margin: .75rem 0 1rem; }
.graph-search-results { display: grid; gap: .25rem; max-height: 180px; overflow: auto; }
.graph-search-result, .graph-relationship-item { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .55rem; border: 1px solid var(--graph-editor-border); border-radius: .45rem; }
.graph-search-result { cursor: pointer; color: inherit; background: transparent; text-align: left; }
.graph-search-result[aria-selected="true"] { border-color: var(--graph-selection); box-shadow: 0 0 0 2px color-mix(in srgb, var(--graph-selection) 25%, transparent); }
.graph-relationship-item button { color: #fff; background: var(--graph-danger); border: 0; border-radius: .35rem; padding: .3rem .5rem; }
.graph-neighborhood-lock { padding: .65rem; color: var(--graph-locked); border: 1px dashed var(--graph-locked); border-radius: .5rem; }
.graph-edit-selected { outline: 3px solid var(--graph-selection); }

.graph-tooltip {
  padding: .35rem .55rem;
  border: 1px solid var(--graph-editor-border);
  border-radius: .35rem;
  color: var(--text-primary, #f8f9fa);
  background: color-mix(in srgb, var(--bg-base, #121214) 92%, #fff 8%);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  font: 600 .8rem/1.2 'Open Sans', sans-serif;
  visibility: hidden;
  pointer-events: none;
}

/* --- EDIT MODE VISUALS --- */


#graph {
    background-color: var(--bg-base);
    transition: background-color var(--transition-speed);
}

#graph canvas {
  background-color: transparent !important;
}

body.graph-edit-active #graph {
    /* blueprint grid background for edit mode*/ 
    /* cursor: crosshair !important; */
    background-size: 50px 50px;
    background-image: radial-gradient(
        circle, 
        color-mix(in srgb, var(--text-primary) 15%, transparent) 1.5px, 
        transparent 1.5px
    );
    /* background-image: 
        linear-gradient(to right, color-mix(in srgb, var(--text-primary) 8%, transparent) 1px, transparent 1px),
        linear-gradient(to bottom, color-mix(in srgb, var(--text-primary) 8%, transparent) 1px, transparent 1px); */
    transition: background-image 0.3s ease-in-out;
}

body.graph-edit-active::after {
    content: '';
    position: fixed;
    top: 0; 
    right: 0; 
    bottom: 0;
    left: var(--sidebar-width, 0px);
    border: 3px solid color-mix(in srgb, var(--accent-primary) 40%, transparent); 
    pointer-events: none; 
    z-index: 999;
}

.btn-edit-active {
    background-color: var(--bg-hover) !important;
    border-color: var(--accent-primary) !important;
    color: var(--accent-primary) !important;
    box-shadow: 0 0 8px color-mix(in srgb, var(--accent-primary) 30%, transparent);
}

.graph-settings-button {
  line-height: 1;
}

.graph-settings-icon {
  line-height: 1;
  height: 20px;
  display: block;
  width: 20px;
}

/* --- END EDIT MODE VISUALS --- */

@media (max-width: 680px) {
  .graph-editor { inset: auto 0 0; width: 100%; max-height: min(82vh, 720px); border-left: 0; border-top: 1px solid var(--graph-editor-border); border-radius: 18px 18px 0 0; transform: translateY(105%); }
  .graph-editor.is-open { transform: translateY(0); }
  .graph-editor-grid { grid-template-columns: 1fr; }
  .graph-editor input, .graph-editor select, .graph-editor button { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) { .graph-editor { transition: none; } }

/* Graph filter control and its toolbar movement beside the editor drawer. */
#toolbar-container {
  transition: right .22s ease;
}

body.graph-editor-open #toolbar-container {
  right: min(565px, calc(100vw - 15px)) !important;
}

.graph-filter-panel {
  display: flex;
  align-items: center;
  width: min(280px, calc(100vw - 30px));
  padding: .3rem;
  border: 1px solid var(--graph-editor-border);
  border-radius: .45rem;
  color: var(--text-primary, #f8f9fa);
  background: color-mix(in srgb, var(--bg-base, #121214) 92%, #fff 8%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}

.graph-filter-panel[hidden] { display: none; }

.graph-filter-panel input {
  min-width: 0;
  flex: 1;
  padding: .35rem .45rem;
  color: inherit;
  background: transparent;
  border: 0;
  outline: 0;
}

.graph-filter-panel button {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: .3rem;
  color: inherit;
  background: transparent;
  font-size: 1.25rem;
  line-height: 1;
}

.graph-filter-panel button:hover,
#graph-filter-btn[aria-pressed="true"] {
  color: var(--accent-primary, #4da3ff);
  background: color-mix(in srgb, var(--accent-primary, #4da3ff) 16%, transparent);
}

@media (max-width: 680px) {
  body.graph-editor-open #toolbar-container { right: 15px !important; }
}

.rootnode-icon {
    width: 32px; 
    height: 32px;
    flex-shrink: 0; 
    background-color: rgba(100, 100, 100, 1);
    border-radius: 50%;
    position: relative;
    margin-top: 2px; 
}

.rootnode-icon::after {
    content: ''; 
    position: absolute;
    top: -8px; 
    left: -8px;
    right: -8px;
    bottom: -8px;
    border: calc(var(--root-ring-width, 1.5px) * 3) dotted var(--root-ring-color, rgba(255, 205, 60, 0.9));
    border-radius: 50%;
    box-sizing: border-box;
}

.force-graph-container .graph-tooltip {
    position: absolute;
    transform: translate(-50%, 25px);
    font-family: 'Merriweather', serif;
    font-size: 16px;
    padding: 0.3em 0.6em;
    border-radius: 6px;
    color: currentColor;
    background: rgba(0,0,0,0.75);
    visibility: hidden; /* by default */
    }

  .personinfo-modal {
    display: none;
    position: fixed;
    z-index: 1; 
    width: 100%;
    height: 100%;
    overflow: auto; 
    background-color: rgba(255, 255, 255, 0.1); 
  }

  .personinfo-content {
  background: rgba(15, 15, 15, 0.95); /* Slightly darker for better contrast */
  color: #eee;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.1);
  }

  /* Floating 'X' on top of the image */
  .personinfo-close {
      position: absolute;
      top: 8px;
      right: 12px;
      z-index: 10;
      cursor: pointer;
      font-size: 28px;
      color: white;
      text-shadow: 0 0 10px rgba(0,0,0,0.9); /* Makes it pop on light photos */
      transition: transform 0.2s ease;
  }

  .personinfo-close:hover, .personinfo-close:focus {
      opacity: 1;
      transform: scale(1.2);
      color: #ff4d4d;
  } 

  .modalportrait {
      display: none;
      width: auto;
      height: 100%; /* Fills the vertical height of the text column */
      max-width: 300px; /* Allows it to be wider for tall modals */
      min-width: 200px;
      object-fit: cover; /* This is key: it crops the photo to fill the area without stretching */
      margin: 0;
      /* Round the right corners to match the modal */
      border-radius: 0 8px 8px 0; 
      transition: all 0.3s;
  }

  .modallink{
    
    bottom: 10px;
    left: 10px;
  }
  #modalbirth, #modaldeath{
    font-size: 0.8em; 
  }
  #modalname{
    margin-bottom: 0.25rem;
  }

  #modalevents::-webkit-scrollbar {
    width: 6px;
  }
  #modalevents::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
  }
  #modalevents::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
  }
  #modalevents::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 215, 0, 0.4); /* Faint gold on hover */
  }

  #modalevents ul {
      padding-left: 18px; 
      margin-left: 0;
      margin-top: 10px;
  }

  #modalevents li {
      margin-bottom: 8px; 
  }

.term-tooltip {
    text-decoration: underline dotted;
    text-underline-offset: 3px;
    cursor: help;
    position: relative;
    color: inherit;
}

.tooltip-content {
    position: absolute;
    top: 130%; 
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    
    background-color: rgba(20, 20, 20, 0.95);
    color: #fff;
    padding: 12px 16px; 
    border-radius: 6px;
    border: 1px solid #444;
    
    font-size: 13px;
    font-weight: normal;
    white-space: normal; 
    max-width: 260px; 
    width: max-content; 
    line-height: 1.5;
    text-align: left;
    
    display: flex;
    align-items: flex-start;
    gap: 16px;

    /* Animation states */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.term-tooltip:hover .tooltip-content {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(2px);
}