vars: {
  d2-config: {
    theme-overrides: {
      N1: "#e0e0e0"
      N2: "#a0a0a0"
      N3: "#707070"
      N4: "#404040"
      N5: "#5d5d5d"
      N6: "#151515"
      N7: "#0a0a0a"

      B1: "#0a0a0a"
      B2: "#111111"
      B3: "#181818"
      B4: "#222222"
      B5: "#5d5d5d"
      B6: "#404040"

      AA2: "#76b900"
      AA4: "#3d7ab5"
      AA5: "#c4a035"

      AB4: "#7a3050"
      AB5: "#2a6b55"
    }
  }
}

grid-rows: 3
grid-gap: 20

# Row 1: Lead agent prefix + thinking
row1: "" {
  direction: right
  style: { fill: transparent; stroke: transparent }

  prefix: "System Prompt + Tools + History" {
    style: {
      fill: "#0f1e30"
      stroke: "#3d7ab5"
      stroke-width: 2
      font-color: "#e0e0e0"
      font-size: 13
      bold: true
      border-radius: 0
    }
  }

  think1: "<think> reasoning" {
    style: {
      fill: "#2a1a1a"
      stroke: "#7a3050"
      stroke-width: 2
      font-color: "#e0e0e0"
      font-size: 13
      bold: true
      border-radius: 0
    }
  }

  handoff: "Tool Call (handoff)" {
    style: {
      fill: "#1a1a2e"
      stroke: "#5d5d5d"
      stroke-width: 2
      font-color: "#a0a0a0"
      font-size: 13
      bold: true
      border-radius: 0
    }
  }

  prefix -> think1: {
    style: { stroke: "#5d5d5d"; stroke-width: 1 }
  }
  think1 -> handoff: {
    style: { stroke: "#5d5d5d"; stroke-width: 1 }
  }
}

# Row 2: Subagent branch
row2: "" {
  direction: right
  style: { fill: transparent; stroke: transparent }

  sub_prefix: "Shared Prefix + Task" {
    style: {
      fill: "#1a2a1a"
      stroke: "#76b900"
      stroke-width: 1
      font-color: "#e0e0e0"
      font-size: 13
      bold: true
      border-radius: 0
      stroke-dash: 5
    }
  }

  sub_think: "<think>" {
    style: {
      fill: "#2a1a1a"
      stroke: "#7a3050"
      stroke-width: 1
      font-color: "#e0e0e0"
      font-size: 13
      bold: true
      border-radius: 0
      stroke-dash: 5
    }
  }

  sub_result: "Result" {
    style: {
      fill: "#1a2a1a"
      stroke: "#76b900"
      stroke-width: 1
      font-color: "#e0e0e0"
      font-size: 13
      bold: true
      border-radius: 0
      stroke-dash: 5
    }
  }

  sub_prefix -> sub_think: {
    style: { stroke: "#5d5d5d"; stroke-width: 1; stroke-dash: 5 }
  }
  sub_think -> sub_result: {
    style: { stroke: "#5d5d5d"; stroke-width: 1; stroke-dash: 5 }
  }
}

# Row 3: Resume
row3: "" {
  direction: right
  style: { fill: transparent; stroke: transparent }

  resume: "Lead Agent Resumes" {
    style: {
      fill: "#2a4a10"
      stroke: "#76b900"
      stroke-width: 2
      font-color: "#e0e0e0"
      font-size: 13
      bold: true
      border-radius: 0
    }
  }
}

# Cross-row connections
row1.handoff -> row2.sub_prefix: "spawn" {
  style: {
    stroke: "#c4a035"
    stroke-width: 2
    font-color: "#c4a035"
    font-size: 12
  }
}

row2.sub_result -> row3.resume: "end (evict ephemeral KV)" {
  style: {
    stroke: "#76b900"
    stroke-width: 2
    font-color: "#76b900"
    font-size: 12
  }
}

row1.handoff -> row3.resume: {
  style: {
    stroke: "#5d5d5d"
    stroke-width: 1
  }
}
