:root {
  color-scheme: dark;
  --bg: #1e1e1e;
  --panel: rgba(37, 37, 37, 0.96);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #dcddde;
  --muted: #999999;
  --faint: #666666;
  --accent: #a882ff;
  --link: rgba(70, 70, 70, 0.9);
  --node: #8c8e92;
  --node-hot: #cfd1d4;
  --color-texts: #4da6ff;
  --color-concepts: #98c379;
  --color-people: #e06c75;
  --color-places: #d19a66;
  --color-glossary: #e5c07b;
  --color-taxonomies: #c678dd;
}

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

* { box-sizing: border-box; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  user-select: none;
}

.graph-app {
  position: fixed;
  inset: 0;
  background: var(--bg);
}

#graph-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#graph-canvas.is-grabbing {
  cursor: grabbing;
}

.graph-topbar {
  position: absolute;
  inset: 0 0 auto 0;
  height: 56px;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 0 18px;
  pointer-events: none;
  z-index: 3;
  background: var(--bg);
  border-bottom: 1px solid var(--panel-border);
}

.graph-title {
  justify-self: center;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.graph-nav {
  display: flex;
  align-items: center;
  gap: 14px;
  pointer-events: auto;
}

.graph-search-box {
  justify-self: end;
  min-width: 0;
  pointer-events: auto;
}

.graph-language-switcher {
  display: flex;
  align-items: center;
  gap: 2px;
  pointer-events: auto;
  white-space: nowrap;
}

.graph-language-switcher .language-option {
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 12px;
  text-decoration: none;
}

.graph-language-switcher .language-option.active {
  background: #303030;
  color: var(--text);
}

.graph-search-box input {
  width: min(220px, 100%);
  padding: 6px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  background: rgba(22, 22, 22, 0.9);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease;
}

.graph-search-box input::placeholder {
  color: var(--faint);
}

.graph-search-box input:focus {
  border-color: var(--accent);
  background: #161616;
}

@media (max-width: 640px) {
  .graph-topbar {
    height: 48px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    padding: 0 10px;
  }

  .graph-title {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .graph-nav {
    gap: 8px;
  }

  .graph-search-box input {
    width: 100%;
    padding: 5px 10px;
    font-size: 12px;
  }
  .graph-search-box {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .graph-language-switcher .language-option {
    padding: 6px;
    font-size: 11px;
  }
}

.icon-link,
.graph-toolbar button,
.button {
  color: var(--muted);
  border: 0;
  background: transparent;
  font: inherit;
  cursor: pointer;
  padding: 6px;
  border-radius: 7px;
  text-decoration: none;
}

.icon-link:hover,
.graph-toolbar button:hover,
.button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.graph-toolbar {
  position: absolute;
  top: 68px;
  right: 12px;
  z-index: 4;
  display: grid;
  gap: 2px;
  pointer-events: none;
}

.graph-toolbar button {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  font-size: 18px;
  line-height: 1;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.graph-panel {
  position: absolute;
  z-index: 5;
  top: 74px;
  right: 64px;
  width: min(330px, calc(100vw - 32px));
  max-height: calc(100vh - 96px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

.graph-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.graph-panel h2 {
  margin: 0 0 12px;
  font-size: 15px;
}

.graph-panel details {
  border-top: 1px solid var(--panel-border);
  padding-top: 10px;
  margin-top: 10px;
}

.server-query-panel {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px;
  margin-top: 14px;
  background: rgba(255, 255, 255, 0.02);
}

.graph-panel .server-query-panel summary {
  color: var(--muted);
  font-size: 12px;
}

.graph-panel summary {
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  list-style: none;
}

.graph-panel summary::-webkit-details-marker {
  display: none;
}

.graph-panel summary::before {
  content: '›';
  display: inline-block;
  margin-right: 8px;
  color: var(--muted);
  transition: transform 0.15s;
}

.graph-panel details[open] > summary::before {
  transform: rotate(90deg);
}

.graph-panel label {
  display: grid;
  gap: 6px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 12px;
}

.graph-panel select,
.graph-panel input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  background: #161616;
  color: var(--text);
  padding: 8px;
}

.graph-panel input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

.graph-panel input[type="checkbox"] {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}

.graph-panel input[type="color"] {
  height: 34px;
  padding: 4px;
}

.graph-field-status {
  min-height: 1.25em;
  margin: -6px 0 8px;
  color: var(--faint);
  font-size: 11px;
  line-height: 1.35;
}

.graph-field-status[data-state="valid"] {
  color: #98c379;
}

.graph-field-status[data-state="invalid"],
.graph-field-status[data-state="ambiguous"] {
  color: #e5c07b;
}

#graph-canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -4px;
}

.graph-check {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.group-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.group-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.dynamic-group-item {
  display: grid;
  grid-template-columns: 24px 1fr 44px 28px;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
}

.dynamic-group-item input[type="checkbox"] {
  margin: 0;
}

.dynamic-group-item input[type="text"] {
  min-width: 0;
}

.dynamic-group-item input[type="color"] {
  width: 44px;
  height: 28px;
  padding: 2px;
}

.dynamic-group-item .group-remove {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.dynamic-group-item .group-remove:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.group-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 4px rgba(0,0,0,0.5);
}

.group-label {
  text-transform: capitalize;
}

.graph-panel .button {
  display: inline-block;
  margin-top: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: #2f2f2f;
  color: var(--text);
  padding: 8px 10px;
  text-decoration: none;
}

.graph-panel .graph-action-button {
  width: 100%;
  margin: 10px 0 4px;
  text-align: center;
}

.graph-count {
  position: absolute;
  left: 18px;
  bottom: 14px;
  z-index: 3;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

.graph-count .local-clear {
  pointer-events: auto;
  background: transparent;
  border: 0;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  margin-left: 2px;
  text-decoration: underline;
}

.graph-count .local-clear:hover {
  color: var(--text);
}

.graph-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
}

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

.graph-selected-panel {
  position: absolute;
  z-index: 5;
  bottom: 18px;
  right: 22px;
  width: min(280px, calc(100vw - 32px));
  padding: 14px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

.graph-selected-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.graph-selected-panel h3 {
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--text);
}

.graph-selected-panel .selected-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 10px;
}

.graph-selected-panel .button {
  display: inline-block;
  margin-top: 6px;
  margin-right: 6px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: #2f2f2f;
  color: var(--text);
  padding: 7px 10px;
  text-decoration: none;
  font-size: 12px;
  cursor: pointer;
}

.graph-selected-panel .button:hover {
  background: #3a3a3a;
}

.graph-selected-panel .button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.graph-context-menu {
  position: absolute;
  z-index: 7;
  min-width: 160px;
  padding: 6px 0;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, visibility 0.15s ease, transform 0.15s ease;
}

.graph-context-menu.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.graph-context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.graph-context-menu button:hover {
  background: rgba(255, 255, 255, 0.06);
}

@media (max-width: 400px) {
  .graph-panel {
    right: 16px;
    left: 16px;
    width: auto;
  }
  .graph-selected-panel {
    right: 16px;
    left: 16px;
    width: auto;
  }
}
