.graph-stage {
  --graph-ink: var(--ink, #24312c);
  --graph-muted: var(--muted, #6c7872);
  --graph-line: var(--line, #e6e1d6);
  --graph-stage: var(--stage, #f7f4ee);
  --graph-dot: var(--dot, #ddd6c8);
  --graph-card: var(--card, #fffcf8);
  --graph-accent: var(--accent, #2f6f5e);
  --graph-field: var(--field-line, #e6e1d6);
  --graph-shadow: var(--shadow, rgba(36, 49, 44, 0.06));
  --tone-space: #2f6f5e;
  --tone-interactions: #3d8f78;
  position: relative;
  height: min(70vh, 640px);
  overflow: hidden;
  border: 1px solid var(--graph-line);
  border-radius: 18px;
  background-color: var(--graph-stage);
  background-image: radial-gradient(var(--graph-dot) 1.1px, transparent 1.1px);
  background-size: 18px 18px;
  color: var(--graph-ink);
  cursor: grab;
  touch-action: none;
}

.graph-world {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

.graph-edges {
  position: absolute;
  overflow: visible;
  pointer-events: none;
}

.graph-edges path {
  fill: none;
  stroke: var(--graph-muted);
  stroke-width: 1.5;
}

.graph-edges path[data-conflict="true"] { stroke: #8d3b32; }
.graph-edges path[data-lit="true"] { stroke: var(--graph-accent); stroke-width: 2.4; }
.graph-edges path[data-warm="true"] { stroke-dasharray: 5 4; }

.graph-nodes { position: absolute; inset: 0; }

.graph-node {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0.35rem 0.55rem 0.35rem 0.55rem;
  border: 1px solid var(--graph-field);
  border-left: 3px solid var(--node-tone, var(--graph-accent));
  border-radius: 8px;
  background: var(--graph-card);
  box-shadow: 0 4px 12px var(--graph-shadow);
  cursor: grab;
  overflow: hidden;
}

.graph-node.is-compact {
  padding: 0.3rem 0.5rem 0.3rem 0.45rem;
}

.graph-node.has-children {
  padding-left: 0.3rem;
}

.graph-node.is-content-expanded {
  align-items: flex-start;
  padding: 0.45rem 0.4rem 0.45rem 0.5rem;
  overflow: hidden;
  box-shadow: 0 8px 20px var(--graph-shadow);
}

.graph-node-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.graph-node-meta {
  margin: 0;
  color: var(--graph-muted);
  font: 500 0.68rem/1.25 Georgia, "Iowan Old Style", serif;
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.graph-node[data-tone="space"] { --node-tone: var(--tone-space); }
.graph-node[data-tone="interactions"] { --node-tone: var(--tone-interactions); }
.graph-node.is-empty { opacity: 0.55; box-shadow: none; }
.graph-node.is-selected { outline: 2px solid var(--graph-accent); outline-offset: 2px; }
.graph-node.is-dim { opacity: 0.35; }
.graph-node.is-lit { box-shadow: 0 0 0 2px var(--graph-accent); }
.graph-node.is-warm { border-style: dashed; }
.graph-node.is-collapsed {
  border-style: solid;
  background: color-mix(in srgb, var(--graph-card) 88%, var(--graph-accent) 12%);
}

/* T38: shape encodes status — not color alone */
.graph-node[data-shape="rect"] { border-radius: 8px; }
.graph-node[data-shape="diamond"] {
  border-radius: 2px;
  border-style: solid;
  outline: 1px dashed var(--graph-accent);
  outline-offset: 2px;
}
.graph-node[data-shape="triangle"] {
  border-radius: 4px 4px 8px 8px;
  border-top-width: 3px;
  border-top-color: #8d3b32;
}
.graph-node[data-shape="dashed"] {
  border-style: dashed;
  opacity: 0.7;
}

.graph-toggle,
.graph-content-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  padding: 0;
  border: 1px solid var(--graph-field);
  border-radius: 4px;
  background: transparent;
  color: var(--graph-muted);
  font: 600 0.7rem/1 sans-serif;
  cursor: pointer;
}

.graph-toggle:hover,
.graph-content-toggle:hover {
  color: var(--graph-ink);
  border-color: var(--graph-accent);
}

.graph-content-toggle {
  align-self: flex-start;
  margin-top: 0.05rem;
  letter-spacing: 0.02em;
}

.graph-node.is-content-expanded .graph-content-toggle {
  color: var(--graph-accent);
  border-color: color-mix(in srgb, var(--graph-accent) 45%, var(--graph-field));
}

.graph-stage.is-expanded {
  position: fixed;
  inset: 16px;
  z-index: 50;
  height: auto;
  margin: 0;
  box-shadow: 0 24px 80px rgba(20, 28, 26, 0.28);
}

.graph-chrome {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--graph-line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--graph-card) 92%, transparent);
  backdrop-filter: blur(6px);
}

.graph-chrome-btn {
  min-width: 30px;
  min-height: 30px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--graph-ink);
  font: 600 14px/1 sans-serif;
  cursor: pointer;
}

.graph-chrome-btn:hover {
  background: color-mix(in srgb, var(--graph-accent) 18%, transparent);
}

.graph-chrome-fit {
  font-size: 12px;
  letter-spacing: 0.02em;
}

.graph-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  padding: 8px 14px;
  border: 1px solid var(--graph-line);
  border-radius: 999px;
  background: var(--graph-card);
  color: var(--graph-ink);
  font: 600 14px sans-serif;
  cursor: pointer;
}

.graph-stage.is-expanded .graph-close {
  right: auto;
  left: 12px;
}

.graph-wait {
  position: relative;
  z-index: 2;
  max-width: 36rem;
  margin: 22px;
  color: var(--graph-ink);
  font: 18px/1.45 Georgia, "Iowan Old Style", serif;
  pointer-events: none;
}

.graph-stage[data-ready="true"] .graph-wait { display: none; }

.graph-node h2 {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font: 600 0.8rem/1.2 Georgia, "Iowan Old Style", serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.graph-node.is-content-expanded h2 {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  line-height: 1.25;
  word-break: break-word;
}

.graph-stage.is-dense .graph-node h2 {
  font-size: 0.74rem;
}

.graph-summary,
.graph-kind,
.graph-pill,
.graph-when {
  display: none;
}

/* M09-04 — maintenance move / create pulse (real journal-driven marks) */
@keyframes graph-maint-pulse {
  0% { box-shadow: 0 0 0 0 rgba(47, 111, 94, 0.45); transform: scale(1); }
  40% { box-shadow: 0 0 0 10px rgba(47, 111, 94, 0); transform: scale(1.04); }
  100% { box-shadow: 0 0 0 0 rgba(47, 111, 94, 0); transform: scale(1); }
}

.graph-node.is-maint-pulse {
  animation: graph-maint-pulse 0.9s ease-out 2;
  z-index: 4;
}

.graph-node.is-maint-created {
  outline: 2px solid #2f6f5e;
}

.graph-node.is-maint-moved {
  outline: 2px solid #b7791f;
}

.graph-node.is-maint-parent {
  outline: 2px dashed #5b6b9a;
}

@media (prefers-color-scheme: dark) {
  .graph-stage {
    --graph-ink: var(--ink, #f3f4ef);
    --graph-muted: var(--muted, #a3b0aa);
    --graph-line: var(--line, #31403b);
    --graph-stage: var(--stage, #17201e);
    --graph-dot: var(--dot, #2c3a36);
    --graph-card: var(--card, #1c2422);
    --graph-accent: var(--accent, #8dcebb);
    --graph-field: var(--field-line, #3d4d47);
    --tone-space: #8dcebb;
    --tone-interactions: #b7e4d6;
  }
}
