/* Graph stage: dotted canvas, floating toolbar and stats, node cards, ports, edges, minimap
   and the target picker overlay. */
.stage {
  position: relative;
  overflow: hidden;
  background: var(--color-canvas);
  container: stage / inline-size;
}
.graph-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  background-image: radial-gradient(var(--color-canvas-dot) 1px, transparent 1px);
  background-size: 20px 20px;
}
.graph-viewport:active {
  cursor: grabbing;
}
.graph-viewport:focus-visible {
  outline-offset: -3px;
}
.graph-toolbar {
  position: absolute;
  z-index: var(--z-canvas-ui);
  top: var(--space-7);
  left: var(--space-7);
  right: var(--space-7);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  pointer-events: none;
}
.graph-toolbar > *,
.graph-toolbar-end > * {
  pointer-events: auto;
}
.graph-toolbar-end {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-4);
  margin-left: auto;
  pointer-events: none;
}
.stats-pill {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  background: var(--color-floating);
  box-shadow: var(--shadow-floating);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  white-space: nowrap;
}
.stats-pill b {
  font: 500 var(--font-size-base) var(--font-mono);
  color: var(--color-text);
}
.stats-pill b.accent {
  color: var(--color-accent-text);
}
.stats-sync,
.stats-unavailable {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 30px;
  color: var(--color-attention);
  font-size: var(--font-size-xs);
  font-weight: 700;
}
.stats-sync .icon,
.stats-unavailable .icon {
  width: 14px;
  height: 14px;
}
.stats-sync:hover span {
  text-decoration: underline;
}
.zoom-group {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px;
  border-radius: var(--radius-md);
  background: var(--color-floating);
  box-shadow: var(--shadow-floating);
}
.zoom-group .icon-button.tool {
  width: 32px;
  height: 32px;
  color: var(--color-text);
}
.zoom-group [data-tooltip]::after {
  left: auto;
  right: 0;
  transform: none;
}
.zoom-level {
  width: 46px;
  text-align: center;
  font: var(--font-size-xs) var(--font-mono);
}
@container stage (max-width: 620px) {
  .stats-pill {
    order: 2;
    gap: var(--space-5);
    padding: 0 var(--space-5);
  }
}
/* Phone-width canvases keep the controls only; the same totals are in 故事設定, the route
   sheet (所有路線) and the 結局 catalog. */
@container stage (max-width: 480px) {
  .stats-pill {
    display: none;
  }
}

.graph-world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}
.graph-edges {
  position: absolute;
  overflow: visible;
  pointer-events: none;
}
.graph-edges path {
  fill: none;
  stroke: var(--color-edge);
  stroke-width: 2;
}
.graph-edges path.choice {
  stroke: var(--color-edge-choice);
}
.graph-edges path.active {
  stroke: var(--color-accent);
  stroke-width: 2.5;
}
.graph-card {
  position: absolute;
  width: 210px;
  min-height: 88px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
  color: var(--color-text);
  cursor: move;
}
.graph-card.overview {
  width: 100px;
  min-height: 54px;
  cursor: pointer;
}
.graph-card.overview .graph-card-head {
  display: block;
  padding: 7px var(--space-4) var(--space-2);
  line-height: 1.35;
}
.graph-card.overview .graph-card-head small {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font: var(--font-size-2xs) var(--font-ui);
}
.graph-card.ending {
  border-color: var(--color-positive-border);
  background: color-mix(in srgb, var(--fp-positive) 10%, var(--fp-ground));
}
.graph-card.ending .graph-card-head {
  color: var(--color-positive);
}
/* Selection keeps the normal surface and front text so long passages stay readable; copper
   marks it with a doubled border (inset, no layout shift), an outer ring and a copper ID. */
.graph-card.selected {
  border-color: var(--color-accent);
  box-shadow: inset 0 0 0 1px var(--color-accent), 0 0 0 4px var(--color-accent-ring);
}
.graph-card.selected .graph-card-head {
  color: var(--color-accent-text);
  font-weight: 700;
}
.graph-card.ending.selected {
  background: color-mix(in srgb, var(--fp-positive) 10%, var(--fp-ground));
}
.graph-card-head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-6) var(--space-2);
  color: var(--color-text-muted);
  font: 500 var(--font-size-2xs) var(--font-mono);
}
.graph-card-head small {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: inherit;
  font-weight: 400;
  white-space: nowrap;
}
.graph-card-head .icon {
  width: 12px;
  height: 12px;
}
.graph-card p {
  margin: 0;
  padding: 0 var(--space-6) var(--space-6);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.graph-card.choice p {
  padding-bottom: var(--space-4);
}
.graph-card .graph-option-row {
  position: relative;
  min-height: 26px;
  padding: var(--space-2) 27px var(--space-2) var(--space-6);
  color: var(--color-accent-text);
  font: var(--font-size-2xs)/18px var(--font-mono);
  overflow-wrap: anywhere;
}
.graph-card .graph-option-row .wire-port {
  top: 5px;
}
.graph-measure {
  position: absolute;
  left: -10000px;
  top: 0;
  width: 210px;
  visibility: hidden;
  pointer-events: none;
}
.graph-measure .graph-card {
  position: relative;
  left: auto;
  top: auto;
}
.graph-card .score-chip {
  position: absolute;
  right: 10px;
  bottom: -11px;
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--color-surface-2);
  color: var(--color-text);
  font: var(--font-size-2xs) var(--font-mono);
}
.graph-card .score-chip .icon {
  width: 12px;
  height: 12px;
}
.wire-port,
.input-port {
  position: absolute;
  z-index: var(--z-canvas-ui);
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  aspect-ratio: 1;
  padding: 0;
  appearance: none;
  background: var(--color-surface);
  border: 3px solid var(--color-accent);
  border-radius: 50%;
  touch-action: none;
}
.input-port {
  left: -9px;
  top: 35px;
  border-color: var(--color-edge);
}
.wire-port {
  right: -9px;
  top: 35px;
  cursor: crosshair;
}

/* Minimap: whole scene with the visible viewport outlined; click or drag to pan. */
.minimap {
  position: absolute;
  z-index: var(--z-canvas-ui);
  right: var(--space-7);
  bottom: 80px;
  width: 200px;
  height: 120px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-floating);
  overflow: hidden;
  cursor: pointer;
  touch-action: none;
}
.minimap-svg {
  display: block;
  width: 100%;
  height: 100%;
}
.minimap-node {
  fill: var(--color-edge);
}
.minimap-node.choice {
  fill: var(--color-accent-range);
}
.minimap-node.ending {
  fill: var(--color-positive-border);
}
.minimap-node.selected {
  fill: var(--color-accent);
}
.minimap-track {
  fill: var(--color-surface-2);
  stroke: var(--color-border);
}
.minimap-track-slice {
  fill: var(--color-accent-tint);
  stroke: var(--color-accent-range);
}
.minimap-track-view {
  fill: var(--color-accent);
}
.minimap-view {
  fill: var(--color-accent-tint);
  stroke: var(--color-accent);
  stroke-width: 2;
}

.graph-overlay {
  position: absolute;
  z-index: var(--z-dock);
  inset: 64px var(--space-7) var(--space-7);
  max-width: 560px;
  margin-inline: auto;
  overflow: auto;
  padding: var(--space-8);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-menu);
}
.graph-overlay .card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.graph-overlay h2 {
  font: 700 var(--font-size-xl) var(--font-serif);
}
.graph-overlay .search-input {
  margin-bottom: var(--space-4);
}
.side-link {
  display: block;
  width: 100%;
  padding: var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  text-align: left;
  font: 500 var(--font-size-sm) var(--font-mono);
}
.side-link:hover {
  background: var(--color-hover);
}
.side-link small {
  display: block;
  color: var(--color-text-muted);
  font: var(--font-size-xs) var(--font-ui);
}
