.relation-map.relation-graph {
  position: relative;
  isolation: isolate;
  height: clamp(27rem, 56vw, 34rem);
  min-height: 27rem;
  overflow: hidden;
  border-radius: var(--lt-radius-sm, 0.25rem);
  background-color: color-mix(in srgb, var(--lt-sea-850, #081215) 88%, transparent);
  background-image:
    linear-gradient(rgba(115, 157, 153, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(115, 157, 153, 0.045) 1px, transparent 1px);
  background-size: 2.5rem 2.5rem;
  contain: layout paint;
}

.relation-graph-filters {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.65rem;
  padding: 0.35rem;
  overflow-x: auto;
  border: 1px solid var(--lt-divider, rgba(223, 211, 181, 0.16));
  border-radius: var(--lt-radius-sm, 0.25rem);
  background: color-mix(in srgb, var(--lt-sea-850, #091417) 88%, transparent);
  scrollbar-width: thin;
}

.relation-graph-filters__group {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.2rem;
}

.relation-graph-filters__group + .relation-graph-filters__group {
  padding-left: 0.55rem;
  border-left: 1px solid rgba(223, 211, 181, 0.14);
}

.relation-graph-filters__label {
  padding-inline: 0.35rem 0.2rem;
  color: var(--muted);
  font: 650 var(--lt-text-xs, 0.75rem)/1 var(--lt-font-sans, var(--font-sans));
  white-space: nowrap;
}

.relation-graph-filters button {
  display: inline-flex;
  min-width: 2.75rem;
  min-height: 2.75rem;
  align-items: center;
  justify-content: center;
  gap: 0.32rem;
  padding: 0 0.62rem;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  border-radius: var(--lt-radius-xs, 0.125rem);
  font: 650 var(--lt-text-sm, 0.875rem)/1 var(--lt-font-sans, var(--font-sans));
  cursor: pointer;
  white-space: nowrap;
}

.relation-graph-filters button small {
  min-width: 1.15rem;
  padding: 0.14rem 0.28rem;
  border-radius: 999px;
  background: rgba(126, 185, 194, 0.11);
  color: var(--muted);
  font-size: var(--lt-text-xs, 0.75rem);
  text-align: center;
}

.relation-graph-filters button:hover,
.relation-graph-filters button.is-active {
  border-color: rgba(126, 185, 194, 0.38);
  background: rgba(126, 185, 194, 0.09);
  color: var(--paper-50);
}

.relation-graph-filters button:focus-visible {
  outline: 2px solid var(--lt-brass-bright, var(--copper-300));
  outline-offset: 2px;
}

.relation-graph-filters button.is-active {
  border-color: var(--copper-300);
  box-shadow: inset 0 -2px var(--copper-300);
}

.relation-graph-filters__count {
  flex: 0 0 auto;
  margin: 0 0 0 auto;
  padding-inline: 0.45rem;
  color: var(--muted);
  font-size: var(--lt-text-xs, 0.75rem);
  white-space: nowrap;
}

.relation-map.relation-graph.is-empty {
  display: grid;
  min-height: 10rem;
  place-items: center;
  color: var(--muted);
  font-size: var(--lt-text-sm, 0.875rem);
}

.relation-map.relation-graph .relation-graph__surface {
  display: block;
  width: 100%;
  min-width: 0;
  height: 100%;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.relation-map.relation-graph .relation-graph__surface.is-panning {
  cursor: grabbing;
}

.relation-graph__background {
  fill: transparent;
}

.relation-map .relation-graph__edge {
  stroke: rgba(218, 224, 213, 0.27);
  stroke-width: 1.15;
  transition: opacity 160ms ease, stroke 160ms ease, stroke-width 160ms ease;
}

.relation-map .relation-graph__edge[data-stance="positive"] {
  stroke: color-mix(in srgb, var(--sea-300) 74%, transparent);
}

.relation-map .relation-graph__edge[data-stance="strained"],
.relation-map .relation-graph__edge[data-stance="hostile"] {
  stroke: color-mix(in srgb, var(--scarlet) 76%, transparent);
  stroke-dasharray: 5 5;
}

.relation-graph__edge-label {
  pointer-events: none;
  transition: opacity 160ms ease;
}

.relation-graph__edge-label rect {
  fill: rgba(11, 24, 27, 0.94);
  stroke: rgba(223, 211, 181, 0.14);
  stroke-width: 0.8;
}

.relation-graph__edge-label text {
  fill: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-anchor: middle;
}

.relation-graph__node {
  cursor: grab;
  outline: none;
  touch-action: none;
  transition: opacity 160ms ease;
}

.relation-graph__node.is-dragging {
  cursor: grabbing;
}

.relation-graph__node-touch {
  fill: transparent;
}

.relation-graph__node-body {
  fill: rgba(19, 38, 41, 0.96);
  stroke: rgba(179, 196, 186, 0.42);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.relation-graph__node-halo {
  fill: rgba(110, 166, 162, 0.13);
  stroke: rgba(126, 185, 194, 0.24);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.relation-graph__node-dot {
  fill: var(--sea-300);
  stroke: rgba(240, 232, 211, 0.58);
  stroke-width: 0.8;
  vector-effect: non-scaling-stroke;
}

.relation-graph__node-name {
  fill: var(--paper-50);
  font-family: var(--lt-font-sans, var(--font-sans));
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: 0.025em;
  pointer-events: none;
  text-anchor: start;
}

.relation-graph__node.is-focus .relation-graph__node-body {
  fill: rgba(33, 43, 39, 0.98);
  stroke: var(--copper-300);
  stroke-width: 1.75;
}

.relation-graph__node.is-focus .relation-graph__node-halo {
  fill: rgba(205, 155, 88, 0.15);
  stroke: rgba(217, 171, 103, 0.4);
}

.relation-graph__node.is-focus .relation-graph__node-dot {
  fill: var(--copper-300);
}

.relation-graph.is-global .relation-graph__node-body {
  fill: rgba(14, 30, 33, 0.18);
  stroke: transparent;
}

.relation-graph.is-global:not(.has-node-preview) .relation-graph__edge-label {
  opacity: 0;
}

.relation-graph.is-global.has-node-preview .relation-graph__node.is-preview-muted,
.relation-graph.is-global.has-node-preview .relation-graph__edge.is-preview-muted {
  opacity: 0.2;
}

.relation-graph.is-global.has-node-preview .relation-graph__edge-label {
  opacity: 0;
}

.relation-graph.is-global.has-node-preview .relation-graph__edge-label.is-preview-related {
  opacity: 1;
}

.relation-graph.is-global .relation-graph__edge.is-preview-related {
  opacity: 1;
  stroke-width: 2;
}

.relation-graph.is-global .relation-graph__node.is-preview-source .relation-graph__node-body {
  fill: rgba(38, 42, 34, 0.86);
  stroke: var(--copper-300);
  stroke-width: 1.8;
}

.relation-graph.is-global .relation-graph__node.is-preview-source .relation-graph__node-dot {
  fill: var(--copper-300);
}

.relation-graph.is-global .relation-graph__node.is-preview-neighbor .relation-graph__node-body {
  fill: rgba(17, 38, 41, 0.82);
  stroke: var(--sea-300);
  stroke-width: 1.5;
}

.relation-graph__node:hover .relation-graph__node-body,
.relation-graph__node:focus-visible .relation-graph__node-body,
.relation-graph__node.is-dragging .relation-graph__node-body {
  stroke: var(--paper-50);
  stroke-width: 1.8;
}

.relation-graph__node:focus-visible .relation-graph__node-halo {
  fill: rgba(231, 218, 185, 0.24);
  stroke: var(--paper-50);
  stroke-width: 1.6;
}

.relation-graph__toolbar {
  position: absolute;
  z-index: 3;
  top: 0.65rem;
  right: 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.22rem;
  border: 1px solid var(--lt-divider, rgba(223, 211, 181, 0.18));
  border-radius: var(--lt-radius-sm, 0.25rem);
  background: color-mix(in srgb, var(--lt-sea-850, #091417) 92%, transparent);
  box-shadow: 0 0.4rem 1rem rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(10px);
}

.relation-graph__toolbar button {
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0 0.55rem;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  border-radius: var(--lt-radius-xs, 0.125rem);
  font: 650 var(--lt-text-xs, 0.75rem)/1 var(--lt-font-sans, var(--font-sans));
  cursor: pointer;
}

.relation-graph__toolbar button:hover,
.relation-graph__toolbar button:focus-visible {
  border-color: var(--border-strong);
  background: rgba(126, 185, 194, 0.1);
  color: var(--paper-50);
}

.relation-graph__toolbar button:focus-visible {
  outline: 2px solid var(--lt-brass-bright, var(--copper-300));
  outline-offset: 2px;
}

.relation-graph__help {
  position: absolute;
  z-index: 2;
  left: 0.7rem;
  bottom: 0.55rem;
  margin: 0;
  max-width: calc(100% - 1.4rem);
  background: var(--lt-sea-900, #091417);
  color: var(--muted);
  border-radius: var(--lt-radius-xs, 0.125rem);
  font-size: var(--lt-text-sm, 0.875rem);
  line-height: 1.6;
}

.relation-graph__help > summary {
  min-width: 2.75rem;
  min-height: 2.75rem;
  align-content: center;
  padding-inline: 0.6rem;
  cursor: pointer;
}

.relation-graph__help > p {
  max-width: 30rem;
  margin: 0;
  padding: 0 0.75rem 0.75rem;
}

.relation-graph__status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 680px) {
  .relation-graph-filters {
    align-items: stretch;
    gap: 0.35rem;
  }

  .relation-graph-filters__count {
    display: flex;
    align-items: center;
  }

  .relation-map.relation-graph {
    height: min(78svh, 38rem);
    min-height: 31rem;
    background-size: 2rem 2rem;
  }

  .relation-map.relation-graph.is-global {
    height: max(38rem, var(--relation-global-mobile-height, 38rem));
    max-height: none;
  }

  .relation-map.relation-graph .relation-graph__surface {
    touch-action: pan-y;
  }

  /* Touch screens have no hover preview. Keep the all-people view legible and
     reveal relationship names after the player opens a one-hop focus graph. */
  .relation-graph.is-global .relation-graph__edge-label {
    display: none;
  }

  .relation-graph__toolbar {
    top: 0.45rem;
    right: 0.45rem;
  }

  .relation-graph__toolbar button {
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding-inline: 0.48rem;
  }

}

@media (prefers-reduced-motion: reduce) {
  .relation-graph__node,
  .relation-graph__edge,
  .relation-graph__edge-label,
  .relation-graph__toolbar button {
    scroll-behavior: auto;
    transition: none !important;
  }
}

@media (forced-colors: active) {
  .relation-graph__node-body,
  .relation-graph__node-dot,
  .relation-graph__edge-label rect,
  .relation-graph__toolbar {
    forced-color-adjust: auto;
  }

  .relation-map .relation-graph__edge {
    stroke: CanvasText;
  }
}
